Initial revision
[deliverable/binutils-gdb.git] / gdb / dbxread.c
CommitLineData
bd5635a1
RP
1/* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
c3a21801 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
c3a21801
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
c3a21801 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
c3a21801
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
9404978d
MT
19
20/* This module provides three functions: dbx_symfile_init,
21 which initializes to read a symbol file; dbx_new_init, which
22 discards existing cached information when all symbols are being
23 discarded; and dbx_symfile_read, which reads a symbol table
24 from a file.
25
26 dbx_symfile_read only does the minimum work necessary for letting the
27 user "name" things symbolically; it does not read the entire symtab.
28 Instead, it reads the external and static symbols and puts them in partial
29 symbol tables. When more extensive information is requested of a
30 file, the corresponding partial symbol table is mutated into a full
31 fledged symbol table by going back and reading the symbols
32 for real. dbx_psymtab_to_symtab() is the function that does this */
bd5635a1 33
bd5635a1
RP
34#include <stdio.h>
35#include <string.h>
36#include "defs.h"
bd5635a1
RP
37
38#ifdef USG
39#include <sys/types.h>
40#include <fcntl.h>
41#define L_SET 0
42#define L_INCR 1
43#endif
44
afe4ca15
JG
45#include <obstack.h>
46#include <sys/param.h>
47#include <sys/file.h>
48#include <sys/stat.h>
bd5635a1 49#include <ctype.h>
afe4ca15
JG
50#include "symtab.h"
51#include "breakpoint.h"
52#include "command.h"
53#include "target.h"
54#include "gdbcore.h" /* for bfd stuff */
55#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
56#include "symfile.h"
c0302457 57#include "buildsym.h"
afe4ca15
JG
58
59#include "aout64.h"
60#include "stab.gnu.h" /* We always use GNU stabs, not native, now */
bd5635a1 61
c0302457
JG
62/* Information is passed among various dbxread routines for accessing
63 symbol files. A pointer to this structure is kept in the sym_private
64 field of the struct sym_fns passed in by symfile.h. */
65
bd5635a1
RP
66struct dbx_symfile_info {
67 asection *text_sect; /* Text section accessor */
68 int symcount; /* How many symbols are there in the file */
69 char *stringtab; /* The actual string table */
70 int stringtab_size; /* Its size */
71 off_t symtab_offset; /* Offset in file to symbol table */
bd5635a1
RP
72};
73
c0302457 74
4a35d6e9
FF
75/* Each partial symbol table entry contains a pointer to private data for the
76 read_symtab() function to use when expanding a partial symbol table entry
77 to a full symbol table entry.
78
79 For dbxread this structure contains the offset within the file symbol table
80 of first local symbol for this file, and length (in bytes) of the section
81 of the symbol table devoted to this file's symbols (actually, the section
82 bracketed may contain more than just this file's symbols). If ldsymlen is
83 0, the only reason for this thing's existence is the dependency list.
84 Nothing else will happen when it is read in. */
85
86#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
87#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
88
89struct symloc {
90 int ldsymoff;
91 int ldsymlen;
92};
93
bd5635a1
RP
94extern void qsort ();
95extern double atof ();
bd5635a1
RP
96
97/* Forward declarations */
98
bd5635a1
RP
99static void read_dbx_symtab ();
100static void init_psymbol_list ();
101static void process_one_symbol ();
c0302457
JG
102void start_subfile ();
103int hashname ();
bd5635a1 104static struct pending *copy_pending ();
9404978d 105static struct symtab *read_ofile_symtab ();
bd5635a1
RP
106static void dbx_psymtab_to_symtab ();
107
bd5635a1
RP
108/* Macro to determine which symbols to ignore when reading the first symbol
109 of a file. Some machines override this definition. */
110#ifndef IGNORE_SYMBOL
111/* This code is used on Ultrix systems. Ignore it */
112#define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
113#endif
114
115/* Macro for name of symbol to indicate a file compiled with gcc. */
116#ifndef GCC_COMPILED_FLAG_SYMBOL
117#define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
118#endif
119
bd5635a1
RP
120/* Define this as 1 if a pcc declaration of a char or short argument
121 gives the correct address. Otherwise assume pcc gives the
122 address of the corresponding int, which is not the same on a
123 big-endian machine. */
124
125#ifndef BELIEVE_PCC_PROMOTION
126#define BELIEVE_PCC_PROMOTION 0
127#endif
c0302457 128
bd5635a1
RP
129/* Nonzero means give verbose info on gdb action. From main.c. */
130extern int info_verbose;
131
7d9884b9 132/* The BFD for this file -- implicit parameter to next_symbol_text. */
bd5635a1 133
c0302457 134static bfd *symfile_bfd;
bd5635a1 135
7d9884b9
JG
136/* The objfile for this file -- only good in process_one_symbol(). */
137
138static struct objfile *our_objfile;
139
bd5635a1
RP
140/* String table for the main symbol file. It is kept in memory
141 permanently, to speed up symbol reading. Other files' symbol tables
142 are read in on demand. FIXME, this should be cleaner. */
143
144static char *symfile_string_table;
145static int symfile_string_table_size;
146
afe4ca15
JG
147/* The size of each symbol in the symbol file (in external form).
148 This is set by dbx_symfile_read when building psymtabs, and by
149 dbx_psymtab_to_symtab when building symtabs. */
150
151static unsigned symbol_size;
152
bd5635a1
RP
153/* Complaints about the symbols we have encountered. */
154
bd5635a1
RP
155struct complaint lbrac_complaint =
156 {"bad block start address patched", 0, 0};
157
bd5635a1
RP
158struct complaint string_table_offset_complaint =
159 {"bad string table offset in symbol %d", 0, 0};
160
161struct complaint unknown_symtype_complaint =
0c4d2cc2 162 {"unknown symbol type %s", 0, 0};
bd5635a1
RP
163
164struct complaint lbrac_rbrac_complaint =
165 {"block start larger than block end", 0, 0};
7d9884b9
JG
166
167struct complaint lbrac_unmatched_complaint =
168 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
169
170struct complaint lbrac_mismatch_complaint =
171 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
bd5635a1 172\f
bd5635a1
RP
173/* During initial symbol readin, we need to have a structure to keep
174 track of which psymtabs have which bincls in them. This structure
175 is used during readin to setup the list of dependencies within each
176 partial symbol table. */
177
178struct header_file_location
179{
180 char *name; /* Name of header file */
181 int instance; /* See above */
182 struct partial_symtab *pst; /* Partial symtab that has the
183 BINCL/EINCL defs for this file */
184};
185
186/* The actual list and controling variables */
187static struct header_file_location *bincl_list, *next_bincl;
188static int bincls_allocated;
189
bd5635a1
RP
190/* Free up old header file tables, and allocate new ones.
191 We're reading a new symbol file now. */
192
c0302457 193void
bd5635a1
RP
194free_and_init_header_files ()
195{
196 register int i;
197 for (i = 0; i < n_header_files; i++)
198 free (header_files[i].name);
199 if (header_files) /* First time null */
200 free (header_files);
201 if (this_object_header_files) /* First time null */
202 free (this_object_header_files);
203
204 n_allocated_header_files = 10;
205 header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file));
206 n_header_files = 0;
207
208 n_allocated_this_object_header_files = 10;
209 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
210}
211
212/* Called at the start of each object file's symbols.
213 Clear out the mapping of header file numbers to header files. */
214
c0302457 215void
bd5635a1
RP
216new_object_header_files ()
217{
218 /* Leave FILENUM of 0 free for builtin types and this file's types. */
219 n_this_object_header_files = 1;
220 header_file_prev_index = -1;
221}
222
223/* Add header file number I for this object file
224 at the next successive FILENUM. */
225
226static void
227add_this_object_header_file (i)
228 int i;
229{
230 if (n_this_object_header_files == n_allocated_this_object_header_files)
231 {
232 n_allocated_this_object_header_files *= 2;
233 this_object_header_files
234 = (int *) xrealloc (this_object_header_files,
235 n_allocated_this_object_header_files * sizeof (int));
236 }
237
238 this_object_header_files[n_this_object_header_files++] = i;
239}
240
241/* Add to this file an "old" header file, one already seen in
242 a previous object file. NAME is the header file's name.
243 INSTANCE is its instance code, to select among multiple
244 symbol tables for the same header file. */
245
246static void
247add_old_header_file (name, instance)
248 char *name;
249 int instance;
250{
251 register struct header_file *p = header_files;
252 register int i;
253
254 for (i = 0; i < n_header_files; i++)
255 if (!strcmp (p[i].name, name) && instance == p[i].instance)
256 {
257 add_this_object_header_file (i);
258 return;
259 }
260 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
261 symnum);
262}
263
264/* Add to this file a "new" header file: definitions for its types follow.
265 NAME is the header file's name.
266 Most often this happens only once for each distinct header file,
267 but not necessarily. If it happens more than once, INSTANCE has
268 a different value each time, and references to the header file
269 use INSTANCE values to select among them.
270
271 dbx output contains "begin" and "end" markers for each new header file,
272 but at this level we just need to know which files there have been;
273 so we record the file when its "begin" is seen and ignore the "end". */
274
275static void
276add_new_header_file (name, instance)
277 char *name;
278 int instance;
279{
280 register int i;
281 header_file_prev_index = -1;
282
283 /* Make sure there is room for one more header file. */
284
285 if (n_header_files == n_allocated_header_files)
286 {
287 n_allocated_header_files *= 2;
288 header_files = (struct header_file *)
289 xrealloc (header_files,
290 (n_allocated_header_files
291 * sizeof (struct header_file)));
292 }
293
294 /* Create an entry for this header file. */
295
296 i = n_header_files++;
297 header_files[i].name = savestring (name, strlen(name));
298 header_files[i].instance = instance;
299 header_files[i].length = 10;
300 header_files[i].vector
301 = (struct type **) xmalloc (10 * sizeof (struct type *));
302 bzero (header_files[i].vector, 10 * sizeof (struct type *));
303
304 add_this_object_header_file (i);
305}
306
bd5635a1
RP
307#if 0
308static struct type **
309explicit_lookup_type (real_filenum, index)
310 int real_filenum, index;
311{
312 register struct header_file *f = &header_files[real_filenum];
313
314 if (index >= f->length)
315 {
316 f->length *= 2;
317 f->vector = (struct type **)
318 xrealloc (f->vector, f->length * sizeof (struct type *));
319 bzero (&f->vector[f->length / 2],
320 f->length * sizeof (struct type *) / 2);
321 }
322 return &f->vector[index];
323}
324#endif
325\f
9bba3334 326static void
bd5635a1
RP
327record_misc_function (name, address, type)
328 char *name;
329 CORE_ADDR address;
330 int type;
331{
0c4d2cc2
JG
332 enum misc_function_type misc_type;
333
334 switch (type &~ N_EXT) {
335 case N_TEXT: misc_type = mf_text; break;
336 case N_DATA: misc_type = mf_data; break;
337 case N_BSS: misc_type = mf_bss; break;
338 case N_ABS: misc_type = mf_abs; break;
339#ifdef N_SETV
340 case N_SETV: misc_type = mf_data; break;
341#endif
342 default: misc_type = mf_unknown; break;
343 }
bd5635a1
RP
344
345 prim_record_misc_function (obsavestring (name, strlen (name)),
346 address, misc_type);
347}
348\f
349/* Scan and build partial symbols for a symbol file.
350 We have been initialized by a call to dbx_symfile_init, which
351 put all the relevant info into a "struct dbx_symfile_info"
352 hung off the struct sym_fns SF.
353
354 ADDR is the address relative to which the symbols in it are (e.g.
355 the base address of the text segment).
356 MAINLINE is true if we are reading the main symbol
357 table (as opposed to a shared lib or dynamically loaded file). */
358
9bba3334 359static void
bd5635a1
RP
360dbx_symfile_read (sf, addr, mainline)
361 struct sym_fns *sf;
362 CORE_ADDR addr;
363 int mainline; /* FIXME comments above */
364{
365 struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private);
7d9884b9 366 bfd *sym_bfd = sf->objfile->obfd;
bd5635a1 367 int val;
bd5635a1 368
7d9884b9 369 val = bfd_seek (sf->objfile->obfd, info->symtab_offset, L_SET);
bd5635a1 370 if (val < 0)
7d9884b9 371 perror_with_name (sf->objfile->name);
bd5635a1
RP
372
373 /* If mainline, set global string table pointers, and reinitialize global
374 partial symbol list. */
375 if (mainline) {
376 symfile_string_table = info->stringtab;
377 symfile_string_table_size = info->stringtab_size;
bd5635a1
RP
378 }
379
66eeea27
JG
380 /* If we are reinitializing, or if we have never loaded syms yet, init */
381 if (mainline || global_psymbols.size == 0 || static_psymbols.size == 0)
382 init_psymbol_list (info->symcount);
383
afe4ca15
JG
384 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
385 symbol_size = obj_symbol_entry_size (sym_bfd);
386
bd5635a1
RP
387 pending_blocks = 0;
388 make_cleanup (really_free_pendings, 0);
389
390 init_misc_bunches ();
391 make_cleanup (discard_misc_bunches, 0);
392
393 /* Now that the symbol table data of the executable file are all in core,
394 process them and define symbols accordingly. */
395
7d9884b9
JG
396 read_dbx_symtab (addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
397 sf->objfile, info->stringtab, info->stringtab_size,
bd5635a1
RP
398 info->symcount,
399 bfd_section_vma (sym_bfd, info->text_sect),
400 bfd_section_size (sym_bfd, info->text_sect));
401
402 /* Go over the misc symbol bunches and install them in vector. */
403
404 condense_misc_bunches (!mainline);
405
406 /* Free up any memory we allocated for ourselves. */
407
408 if (!mainline) {
409 free (info->stringtab); /* Stringtab is only saved for mainline */
410 }
411 free (info);
412 sf->sym_private = 0; /* Zap pointer to our (now gone) info struct */
413
9404978d
MT
414 if (!partial_symtab_list) {
415 wrap_here ("");
416 printf_filtered ("(no debugging symbols found)...");
417 wrap_here ("");
418 }
bd5635a1
RP
419}
420
9404978d
MT
421/* Initialize anything that needs initializing when a completely new
422 symbol file is specified (not just adding some symbols from another
423 file, e.g. a shared library). */
bd5635a1 424
9bba3334 425static void
9404978d 426dbx_new_init ()
bd5635a1 427{
c0302457 428 buildsym_new_init ();
bd5635a1 429
bd5635a1 430 /* Don't put these on the cleanup chain; they need to stick around
9404978d 431 until the next call to dbx_new_init. *Then* we'll free them. */
bd5635a1
RP
432 if (symfile_string_table)
433 {
434 free (symfile_string_table);
435 symfile_string_table = 0;
436 symfile_string_table_size = 0;
437 }
438 free_and_init_header_files ();
439}
440
441
442/* dbx_symfile_init ()
443 is the dbx-specific initialization routine for reading symbols.
444 It is passed a struct sym_fns which contains, among other things,
445 the BFD for the file whose symbols are being read, and a slot for a pointer
446 to "private data" which we fill with goodies.
447
448 We read the string table into malloc'd space and stash a pointer to it.
449
450 Since BFD doesn't know how to read debug symbols in a format-independent
451 way (and may never do so...), we have to do it ourselves. We will never
452 be called unless this is an a.out (or very similar) file.
453 FIXME, there should be a cleaner peephole into the BFD environment here. */
454
9bba3334 455static void
bd5635a1
RP
456dbx_symfile_init (sf)
457 struct sym_fns *sf;
458{
459 int val;
7d9884b9 460 bfd *sym_bfd = sf->objfile->obfd;
bd5635a1
RP
461 char *name = bfd_get_filename (sym_bfd);
462 struct dbx_symfile_info *info;
463 unsigned char size_temp[4];
464
465 /* Allocate struct to keep track of the symfile */
c0302457 466 sf->sym_private = xmalloc (sizeof (*info));
bd5635a1
RP
467 info = (struct dbx_symfile_info *)sf->sym_private;
468
469 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
bd5635a1
RP
470#define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
471#define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
472 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
473
bd5635a1
RP
474 info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
475 if (!info->text_sect)
476 abort();
63989338 477 info->symcount = bfd_get_symcount (sym_bfd);
bd5635a1
RP
478
479 /* Read the string table size and check it for bogosity. */
7d9884b9 480 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
bd5635a1
RP
481 if (val < 0)
482 perror_with_name (name);
bd5635a1 483
7d9884b9 484 val = bfd_read (size_temp, sizeof (long), 1, sym_bfd);
bd5635a1
RP
485 if (val < 0)
486 perror_with_name (name);
dcc35536 487 info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
bd5635a1 488
7d9884b9 489 if (info->stringtab_size >= 0)
bd5635a1
RP
490 {
491 info->stringtab = (char *) xmalloc (info->stringtab_size);
492 /* Caller is responsible for freeing the string table. No cleanup. */
493 }
494 else
495 info->stringtab = NULL;
496 if (info->stringtab == NULL && info->stringtab_size != 0)
497 error ("ridiculous string table size: %d bytes", info->stringtab_size);
498
499 /* Now read in the string table in one big gulp. */
500
7d9884b9 501 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
bd5635a1
RP
502 if (val < 0)
503 perror_with_name (name);
7d9884b9
JG
504 val = bfd_read (info->stringtab, info->stringtab_size, 1, sym_bfd);
505 if (val != info->stringtab_size)
bd5635a1
RP
506 perror_with_name (name);
507
508 /* Record the position of the symbol table for later use. */
509
510 info->symtab_offset = SYMBOL_TABLE_OFFSET;
511}
512\f
513/* Buffer for reading the symbol table entries. */
afe4ca15 514static struct internal_nlist symbuf[4096];
bd5635a1
RP
515static int symbuf_idx;
516static int symbuf_end;
517
bd5635a1
RP
518/* The address in memory of the string table of the object file we are
519 reading (which might not be the "main" object file, but might be a
520 shared library or some other dynamically loaded thing). This is set
521 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
522 when building symtabs, and is used only by next_symbol_text. */
523static char *stringtab_global;
524
525/* Refill the symbol table input buffer
526 and set the variables that control fetching entries from it.
527 Reports an error if no data available.
528 This function can read past the end of the symbol table
529 (into the string table) but this does no harm. */
530
7d9884b9
JG
531static void
532fill_symbuf (sym_bfd)
533 bfd *sym_bfd;
bd5635a1 534{
7d9884b9 535 int nbytes = bfd_read (symbuf, sizeof (symbuf), 1, sym_bfd);
bd5635a1 536 if (nbytes < 0)
7d9884b9 537 perror_with_name (bfd_get_filename (sym_bfd));
bd5635a1
RP
538 else if (nbytes == 0)
539 error ("Premature end of file reading symbol table");
afe4ca15 540 symbuf_end = nbytes / symbol_size;
bd5635a1 541 symbuf_idx = 0;
bd5635a1
RP
542}
543
7d9884b9 544#define SWAP_SYMBOL(symp, abfd) \
bd5635a1 545 { \
7d9884b9 546 (symp)->n_strx = bfd_h_get_32(abfd, \
afe4ca15 547 (unsigned char *)&(symp)->n_strx); \
7d9884b9 548 (symp)->n_desc = bfd_h_get_16 (abfd, \
bd5635a1 549 (unsigned char *)&(symp)->n_desc); \
7d9884b9 550 (symp)->n_value = bfd_h_get_32 (abfd, \
bd5635a1
RP
551 (unsigned char *)&(symp)->n_value); \
552 }
553
554/* Invariant: The symbol pointed to by symbuf_idx is the first one
555 that hasn't been swapped. Swap the symbol at the same time
556 that symbuf_idx is incremented. */
557
558/* dbx allows the text of a symbol name to be continued into the
559 next symbol name! When such a continuation is encountered
560 (a \ at the end of the text of a name)
561 call this function to get the continuation. */
562
c0302457 563char *
bd5635a1
RP
564next_symbol_text ()
565{
566 if (symbuf_idx == symbuf_end)
7d9884b9 567 fill_symbuf (symfile_bfd);
bd5635a1 568 symnum++;
7d9884b9 569 SWAP_SYMBOL(&symbuf[symbuf_idx], symfile_bfd);
afe4ca15 570 return symbuf[symbuf_idx++].n_strx + stringtab_global;
bd5635a1
RP
571}
572\f
573/* Initializes storage for all of the partial symbols that will be
574 created by read_dbx_symtab and subsidiaries. */
575
576static void
577init_psymbol_list (total_symbols)
578 int total_symbols;
579{
580 /* Free any previously allocated psymbol lists. */
581 if (global_psymbols.list)
582 free (global_psymbols.list);
583 if (static_psymbols.list)
584 free (static_psymbols.list);
585
586 /* Current best guess is that there are approximately a twentieth
587 of the total symbols (in a debugging file) are global or static
588 oriented symbols */
589 global_psymbols.size = total_symbols / 10;
590 static_psymbols.size = total_symbols / 10;
591 global_psymbols.next = global_psymbols.list = (struct partial_symbol *)
592 xmalloc (global_psymbols.size * sizeof (struct partial_symbol));
593 static_psymbols.next = static_psymbols.list = (struct partial_symbol *)
594 xmalloc (static_psymbols.size * sizeof (struct partial_symbol));
595}
596
597/* Initialize the list of bincls to contain none and have some
598 allocated. */
599
600static void
601init_bincl_list (number)
602 int number;
603{
604 bincls_allocated = number;
605 next_bincl = bincl_list = (struct header_file_location *)
606 xmalloc (bincls_allocated * sizeof(struct header_file_location));
607}
608
609/* Add a bincl to the list. */
610
611static void
612add_bincl_to_list (pst, name, instance)
613 struct partial_symtab *pst;
614 char *name;
615 int instance;
616{
617 if (next_bincl >= bincl_list + bincls_allocated)
618 {
619 int offset = next_bincl - bincl_list;
620 bincls_allocated *= 2;
621 bincl_list = (struct header_file_location *)
622 xrealloc ((char *)bincl_list,
623 bincls_allocated * sizeof (struct header_file_location));
624 next_bincl = bincl_list + offset;
625 }
626 next_bincl->pst = pst;
627 next_bincl->instance = instance;
628 next_bincl++->name = name;
629}
630
631/* Given a name, value pair, find the corresponding
632 bincl in the list. Return the partial symtab associated
633 with that header_file_location. */
634
9bba3334 635static struct partial_symtab *
bd5635a1
RP
636find_corresponding_bincl_psymtab (name, instance)
637 char *name;
638 int instance;
639{
640 struct header_file_location *bincl;
641
642 for (bincl = bincl_list; bincl < next_bincl; bincl++)
643 if (bincl->instance == instance
644 && !strcmp (name, bincl->name))
645 return bincl->pst;
646
647 return (struct partial_symtab *) 0;
648}
649
650/* Free the storage allocated for the bincl list. */
651
652static void
653free_bincl_list ()
654{
655 free (bincl_list);
656 bincls_allocated = 0;
657}
658
659static struct partial_symtab *start_psymtab ();
660static void end_psymtab();
661
662#ifdef DEBUG
663/* This is normally a macro defined in read_dbx_symtab, but this
664 is a lot easier to debug. */
665
666ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, PLIST, VALUE)
667 char *NAME;
668 int NAMELENGTH;
669 enum namespace NAMESPACE;
670 enum address_class CLASS;
671 struct psymbol_allocation_list *PLIST;
672 unsigned long VALUE;
673{
674 register struct partial_symbol *psym;
675
676#define LIST *PLIST
677 do {
678 if ((LIST).next >=
679 (LIST).list + (LIST).size)
680 {
681 (LIST).list = (struct partial_symbol *)
682 xrealloc ((LIST).list,
683 ((LIST).size * 2
684 * sizeof (struct partial_symbol)));
685 /* Next assumes we only went one over. Should be good if
686 program works correctly */
687 (LIST).next =
688 (LIST).list + (LIST).size;
689 (LIST).size *= 2;
690 }
691 psym = (LIST).next++;
692#undef LIST
693
694 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack,
695 (NAMELENGTH) + 1);
696 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH));
697 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0';
698 SYMBOL_NAMESPACE (psym) = (NAMESPACE);
699 SYMBOL_CLASS (psym) = (CLASS);
700 SYMBOL_VALUE (psym) = (VALUE);
701 } while (0);
702}
703
704/* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
705#define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
706 ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
707
708#endif /* DEBUG */
709
710/* Given pointers to an a.out symbol table in core containing dbx
711 style data, setup partial_symtab's describing each source file for
712 which debugging information is available. NLISTLEN is the number
713 of symbols in the symbol table. All symbol names are given as
714 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
715 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
716 and ADDR is its relocated address (if incremental) or 0 (if not). */
717
718static void
7d9884b9 719read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
bd5635a1 720 text_addr, text_size)
bd5635a1 721 CORE_ADDR addr;
7d9884b9 722 struct objfile *objfile;
bd5635a1
RP
723 register char *stringtab;
724 register long stringtab_size;
725 register int nlistlen;
726 CORE_ADDR text_addr;
727 int text_size;
728{
afe4ca15 729 register struct internal_nlist *bufp;
bd5635a1
RP
730 register char *namestring;
731 register struct partial_symbol *psym;
732 int nsl;
733 int past_first_source_file = 0;
734 CORE_ADDR last_o_file_start = 0;
735 struct cleanup *old_chain;
736 char *p;
7d9884b9 737 bfd *abfd;
bd5635a1
RP
738
739 /* End of the text segment of the executable file. */
740 CORE_ADDR end_of_text_addr;
741
742 /* Current partial symtab */
743 struct partial_symtab *pst;
744
745 /* List of current psymtab's include files */
746 char **psymtab_include_list;
747 int includes_allocated;
748 int includes_used;
749
750 /* Index within current psymtab dependency list */
751 struct partial_symtab **dependency_list;
752 int dependencies_used, dependencies_allocated;
753
754 stringtab_global = stringtab;
755
756 pst = (struct partial_symtab *) 0;
757
758 includes_allocated = 30;
759 includes_used = 0;
760 psymtab_include_list = (char **) alloca (includes_allocated *
761 sizeof (char *));
762
763 dependencies_allocated = 30;
764 dependencies_used = 0;
765 dependency_list =
766 (struct partial_symtab **) alloca (dependencies_allocated *
767 sizeof (struct partial_symtab *));
768
7d9884b9 769 old_chain = make_cleanup (free_objfile, objfile);
bd5635a1
RP
770
771 /* Init bincl list */
772 init_bincl_list (20);
773 make_cleanup (free_bincl_list, 0);
774
775 last_source_file = 0;
776
777#ifdef END_OF_TEXT_DEFAULT
778 end_of_text_addr = END_OF_TEXT_DEFAULT;
779#else
5bc757e2 780 end_of_text_addr = text_addr + addr + text_size; /* Relocate */
bd5635a1
RP
781#endif
782
7d9884b9
JG
783 symfile_bfd = objfile->obfd; /* For next_text_symbol */
784 abfd = objfile->obfd;
bd5635a1
RP
785 symbuf_end = symbuf_idx = 0;
786
787 for (symnum = 0; symnum < nlistlen; symnum++)
788 {
789 /* Get the symbol for this run and pull out some info */
790 QUIT; /* allow this to be interruptable */
791 if (symbuf_idx == symbuf_end)
7d9884b9 792 fill_symbuf (abfd);
bd5635a1
RP
793 bufp = &symbuf[symbuf_idx++];
794
795 /*
796 * Special case to speed up readin.
797 */
798 if (bufp->n_type == (unsigned char)N_SLINE) continue;
799
7d9884b9 800 SWAP_SYMBOL (bufp, abfd);
bd5635a1
RP
801
802 /* Ok. There is a lot of code duplicated in the rest of this
803 switch statement (for efficiency reasons). Since I don't
804 like duplicating code, I will do my penance here, and
805 describe the code which is duplicated:
806
807 *) The assignment to namestring.
808 *) The call to strchr.
809 *) The addition of a partial symbol the the two partial
810 symbol lists. This last is a large section of code, so
811 I've imbedded it in the following macro.
812 */
813
814/* Set namestring based on bufp. If the string table index is invalid,
815 give a fake name, and print a single error message per symbol file read,
816 rather than abort the symbol reading or flood the user with messages. */
817#define SET_NAMESTRING()\
7d9884b9 818 if (((unsigned)bufp->n_strx) >= stringtab_size) { \
bd5635a1
RP
819 complain (&string_table_offset_complaint, symnum); \
820 namestring = "foo"; \
821 } else \
afe4ca15 822 namestring = bufp->n_strx + stringtab
bd5635a1
RP
823
824/* Add a symbol with an integer value to a psymtab. */
825/* This is a macro unless we're debugging. See above this function. */
826#ifndef DEBUG
827# define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
828 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
829 SYMBOL_VALUE)
830#endif /* DEBUG */
831
832/* Add a symbol with a CORE_ADDR value to a psymtab. */
833#define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
834 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
835 SYMBOL_VALUE_ADDRESS)
836
837/* Add any kind of symbol to a psymtab. */
838#define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
839 do { \
840 if ((LIST).next >= \
841 (LIST).list + (LIST).size) \
842 { \
843 (LIST).list = (struct partial_symbol *) \
844 xrealloc ((LIST).list, \
845 ((LIST).size * 2 \
846 * sizeof (struct partial_symbol))); \
847 /* Next assumes we only went one over. Should be good if \
848 program works correctly */ \
849 (LIST).next = \
850 (LIST).list + (LIST).size; \
851 (LIST).size *= 2; \
852 } \
853 psym = (LIST).next++; \
854 \
855 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
856 (NAMELENGTH) + 1); \
857 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
858 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
859 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
860 SYMBOL_CLASS (psym) = (CLASS); \
861 VT (psym) = (VALUE); \
862 } while (0);
863
864/* End of macro definitions, now let's handle them symbols! */
865
866 switch (bufp->n_type)
867 {
868 /*
869 * Standard, external, non-debugger, symbols
870 */
871
872 case N_TEXT | N_EXT:
873 case N_NBTEXT | N_EXT:
874 case N_NBDATA | N_EXT:
875 case N_NBBSS | N_EXT:
876 case N_SETV | N_EXT:
877 case N_ABS | N_EXT:
878 case N_DATA | N_EXT:
879 case N_BSS | N_EXT:
880
881 bufp->n_value += addr; /* Relocate */
882
883 SET_NAMESTRING();
884
885 bss_ext_symbol:
886 record_misc_function (namestring, bufp->n_value,
887 bufp->n_type); /* Always */
888
889 continue;
890
891 /* Standard, local, non-debugger, symbols */
892
893 case N_NBTEXT:
894
895 /* We need to be able to deal with both N_FN or N_TEXT,
896 because we have no way of knowing whether the sys-supplied ld
6150cc73
JG
897 or GNU ld was used to make the executable. Sequents throw
898 in another wrinkle -- they renumbered N_FN. */
bd5635a1 899 case N_FN:
6150cc73 900 case N_FN_SEQ:
bd5635a1
RP
901 case N_TEXT:
902 bufp->n_value += addr; /* Relocate */
903 SET_NAMESTRING();
904 if ((namestring[0] == '-' && namestring[1] == 'l')
905 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
906 && namestring [nsl - 2] == '.'))
907 {
908 if (entry_point < bufp->n_value
909 && entry_point >= last_o_file_start
910 && addr == 0) /* FIXME nogood nomore */
911 {
912 startup_file_start = last_o_file_start;
913 startup_file_end = bufp->n_value;
914 }
915 if (past_first_source_file && pst
916 /* The gould NP1 uses low values for .o and -l symbols
917 which are not the address. */
918 && bufp->n_value > pst->textlow)
919 {
920 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 921 symnum * symbol_size, bufp->n_value,
bd5635a1
RP
922 dependency_list, dependencies_used,
923 global_psymbols.next, static_psymbols.next);
924 pst = (struct partial_symtab *) 0;
925 includes_used = 0;
926 dependencies_used = 0;
927 }
928 else
929 past_first_source_file = 1;
930 last_o_file_start = bufp->n_value;
931 }
932 continue;
933
934 case N_DATA:
935 bufp->n_value += addr; /* Relocate */
936 SET_NAMESTRING ();
937 /* Check for __DYNAMIC, which is used by Sun shared libraries.
62c4f98b
JK
938 Record it even if it's local, not global, so we can find it.
939 Same with virtual function tables, both global and static. */
940 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
941 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
bd5635a1
RP
942 {
943 /* Not really a function here, but... */
944 record_misc_function (namestring, bufp->n_value,
945 bufp->n_type); /* Always */
946 }
947 continue;
948
949 case N_UNDF | N_EXT:
950 if (bufp->n_value != 0) {
951 /* This is a "Fortran COMMON" symbol. See if the target
952 environment knows where it has been relocated to. */
953
954 CORE_ADDR reladdr;
955
956 SET_NAMESTRING();
957 if (target_lookup_symbol (namestring, &reladdr)) {
958 continue; /* Error in lookup; ignore symbol for now. */
959 }
960 bufp->n_type ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
961 bufp->n_value = reladdr;
962 goto bss_ext_symbol;
963 }
964 continue; /* Just undefined, not COMMON */
965
966 /* Lots of symbol types we can just ignore. */
967
968 case N_UNDF:
969 case N_ABS:
970 case N_BSS:
971 case N_NBDATA:
972 case N_NBBSS:
973 continue;
974
975 /* Keep going . . .*/
976
977 /*
978 * Special symbol types for GNU
979 */
980 case N_INDR:
981 case N_INDR | N_EXT:
982 case N_SETA:
983 case N_SETA | N_EXT:
984 case N_SETT:
985 case N_SETT | N_EXT:
986 case N_SETD:
987 case N_SETD | N_EXT:
988 case N_SETB:
989 case N_SETB | N_EXT:
990 case N_SETV:
991 continue;
992
993 /*
994 * Debugger symbols
995 */
996
997 case N_SO: {
998 unsigned long valu = bufp->n_value;
999 /* Symbol number of the first symbol of this file (i.e. the N_SO
1000 if there is just one, or the first if we have a pair). */
1001 int first_symnum = symnum;
1002
1003 /* End the current partial symtab and start a new one */
1004
1005 SET_NAMESTRING();
1006
1007 /* Peek at the next symbol. If it is also an N_SO, the
1008 first one just indicates the directory. */
1009 if (symbuf_idx == symbuf_end)
7d9884b9 1010 fill_symbuf (abfd);
bd5635a1
RP
1011 bufp = &symbuf[symbuf_idx];
1012 /* n_type is only a char, so swapping swapping is irrelevant. */
1013 if (bufp->n_type == (unsigned char)N_SO)
1014 {
7d9884b9 1015 SWAP_SYMBOL (bufp, abfd);
bd5635a1
RP
1016 SET_NAMESTRING ();
1017 valu = bufp->n_value;
1018 symbuf_idx++;
1019 symnum++;
1020 }
1021 valu += addr; /* Relocate */
1022
1023 if (pst && past_first_source_file)
1024 {
1025 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 1026 first_symnum * symbol_size, valu,
bd5635a1
RP
1027 dependency_list, dependencies_used,
1028 global_psymbols.next, static_psymbols.next);
1029 pst = (struct partial_symtab *) 0;
1030 includes_used = 0;
1031 dependencies_used = 0;
1032 }
1033 else
1034 past_first_source_file = 1;
1035
7d9884b9 1036 pst = start_psymtab (objfile, addr,
bd5635a1 1037 namestring, valu,
afe4ca15 1038 first_symnum * symbol_size,
bd5635a1 1039 global_psymbols.next, static_psymbols.next);
bd5635a1
RP
1040 continue;
1041 }
1042
1043 case N_BINCL:
1044 /* Add this bincl to the bincl_list for future EXCLs. No
1045 need to save the string; it'll be around until
1046 read_dbx_symtab function returns */
1047
1048 SET_NAMESTRING();
1049
1050 add_bincl_to_list (pst, namestring, bufp->n_value);
1051
1052 /* Mark down an include file in the current psymtab */
1053
1054 psymtab_include_list[includes_used++] = namestring;
1055 if (includes_used >= includes_allocated)
1056 {
1057 char **orig = psymtab_include_list;
1058
1059 psymtab_include_list = (char **)
1060 alloca ((includes_allocated *= 2) *
1061 sizeof (char *));
1062 bcopy (orig, psymtab_include_list,
1063 includes_used * sizeof (char *));
1064 }
1065
1066 continue;
1067
1068 case N_SOL:
1069 /* Mark down an include file in the current psymtab */
1070
1071 SET_NAMESTRING();
1072
1073 /* In C++, one may expect the same filename to come round many
1074 times, when code is coming alternately from the main file
1075 and from inline functions in other files. So I check to see
f9623881
JG
1076 if this is a file we've seen before -- either the main
1077 source file, or a previously included file.
bd5635a1
RP
1078
1079 This seems to be a lot of time to be spending on N_SOL, but
9bb30452 1080 things like "break c-exp.y:435" need to work (I
bd5635a1
RP
1081 suppose the psymtab_include_list could be hashed or put
1082 in a binary tree, if profiling shows this is a major hog). */
4a35d6e9 1083 if (pst && !strcmp (namestring, pst->filename))
f9623881 1084 continue;
bd5635a1
RP
1085 {
1086 register int i;
1087 for (i = 0; i < includes_used; i++)
1088 if (!strcmp (namestring, psymtab_include_list[i]))
1089 {
1090 i = -1;
1091 break;
1092 }
1093 if (i == -1)
1094 continue;
1095 }
1096
1097 psymtab_include_list[includes_used++] = namestring;
1098 if (includes_used >= includes_allocated)
1099 {
1100 char **orig = psymtab_include_list;
1101
1102 psymtab_include_list = (char **)
1103 alloca ((includes_allocated *= 2) *
1104 sizeof (char *));
1105 bcopy (orig, psymtab_include_list,
1106 includes_used * sizeof (char *));
1107 }
1108 continue;
1109
1110 case N_LSYM: /* Typedef or automatic variable. */
9bb30452
JG
1111 case N_STSYM: /* Data seg var -- static */
1112 case N_LCSYM: /* BSS " */
1113 case N_NBSTS: /* Gould nobase. */
1114 case N_NBLCS: /* symbols. */
1115
bd5635a1
RP
1116 SET_NAMESTRING();
1117
1118 p = (char *) strchr (namestring, ':');
1119
1120 /* Skip if there is no :. */
1121 if (!p) continue;
1122
1123 switch (p[1])
1124 {
1125 case 'T':
1126 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1127 STRUCT_NAMESPACE, LOC_TYPEDEF,
1128 static_psymbols, bufp->n_value);
1129 if (p[2] == 't')
1130 {
1131 /* Also a typedef with the same name. */
1132 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1133 VAR_NAMESPACE, LOC_TYPEDEF,
1134 static_psymbols, bufp->n_value);
1135 p += 1;
1136 }
1137 goto check_enum;
1138 case 't':
1139 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1140 VAR_NAMESPACE, LOC_TYPEDEF,
1141 static_psymbols, bufp->n_value);
1142 check_enum:
1143 /* If this is an enumerated type, we need to
1144 add all the enum constants to the partial symbol
1145 table. This does not cover enums without names, e.g.
1146 "enum {a, b} c;" in C, but fortunately those are
1147 rare. There is no way for GDB to find those from the
1148 enum type without spending too much time on it. Thus
1149 to solve this problem, the compiler needs to put out separate
1150 constant symbols ('c' N_LSYMS) for enum constants in
1151 enums without names, or put out a dummy type. */
1152
1153 /* We are looking for something of the form
1154 <name> ":" ("t" | "T") [<number> "="] "e"
1155 {<constant> ":" <value> ","} ";". */
1156
1157 /* Skip over the colon and the 't' or 'T'. */
1158 p += 2;
1159 /* This type may be given a number. Skip over it. */
1160 while ((*p >= '0' && *p <= '9')
1161 || *p == '=')
1162 p++;
1163
1164 if (*p++ == 'e')
1165 {
1166 /* We have found an enumerated type. */
1167 /* According to comments in read_enum_type
1168 a comma could end it instead of a semicolon.
1169 I don't know where that happens.
1170 Accept either. */
1171 while (*p && *p != ';' && *p != ',')
1172 {
1173 char *q;
1174
1175 /* Check for and handle cretinous dbx symbol name
1176 continuation! */
1177 if (*p == '\\')
1178 p = next_symbol_text ();
1179
1180 /* Point to the character after the name
1181 of the enum constant. */
1182 for (q = p; *q && *q != ':'; q++)
1183 ;
1184 /* Note that the value doesn't matter for
1185 enum constants in psymtabs, just in symtabs. */
1186 ADD_PSYMBOL_TO_LIST (p, q - p,
1187 VAR_NAMESPACE, LOC_CONST,
1188 static_psymbols, 0);
1189 /* Point past the name. */
1190 p = q;
1191 /* Skip over the value. */
1192 while (*p && *p != ',')
1193 p++;
1194 /* Advance past the comma. */
1195 if (*p)
1196 p++;
1197 }
1198 }
1199
1200 continue;
1201 case 'c':
1202 /* Constant, e.g. from "const" in Pascal. */
1203 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1204 VAR_NAMESPACE, LOC_CONST,
1205 static_psymbols, bufp->n_value);
1206 continue;
1207 default:
1208 /* Skip if the thing following the : is
1209 not a letter (which indicates declaration of a local
1210 variable, which we aren't interested in). */
1211 continue;
1212 }
1213
1214 case N_FUN:
1215 case N_GSYM: /* Global (extern) variable; can be
1216 data or bss (sigh). */
bd5635a1
RP
1217
1218 /* Following may probably be ignored; I'll leave them here
1219 for now (until I do Pascal and Modula 2 extensions). */
1220
1221 case N_PC: /* I may or may not need this; I
1222 suspect not. */
1223 case N_M2C: /* I suspect that I can ignore this here. */
1224 case N_SCOPE: /* Same. */
1225
1226 SET_NAMESTRING();
1227
1228 p = (char *) strchr (namestring, ':');
1229 if (!p)
1230 continue; /* Not a debugging symbol. */
1231
1232
1233
1234 /* Main processing section for debugging symbols which
1235 the initial read through the symbol tables needs to worry
1236 about. If we reach this point, the symbol which we are
1237 considering is definitely one we are interested in.
1238 p must also contain the (valid) index into the namestring
1239 which indicates the debugging type symbol. */
1240
1241 switch (p[1])
1242 {
1243 case 'c':
1244 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1245 VAR_NAMESPACE, LOC_CONST,
1246 static_psymbols, bufp->n_value);
1247 continue;
1248 case 'S':
1249 bufp->n_value += addr; /* Relocate */
1250 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
1251 VAR_NAMESPACE, LOC_STATIC,
1252 static_psymbols, bufp->n_value);
1253 continue;
1254 case 'G':
1255 bufp->n_value += addr; /* Relocate */
c3a21801
JG
1256 /* The addresses in these entries are reported to be
1257 wrong. See the code that reads 'G's for symtabs. */
bd5635a1 1258 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
c3a21801 1259 VAR_NAMESPACE, LOC_STATIC,
bd5635a1
RP
1260 global_psymbols, bufp->n_value);
1261 continue;
1262
1263 case 't':
1264 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1265 VAR_NAMESPACE, LOC_TYPEDEF,
9bb30452 1266 static_psymbols, bufp->n_value);
bd5635a1
RP
1267 continue;
1268
1269 case 'f':
1270 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1271 VAR_NAMESPACE, LOC_BLOCK,
1272 static_psymbols, bufp->n_value);
1273 continue;
1274
f9623881
JG
1275 /* Global functions were ignored here, but now they
1276 are put into the global psymtab like one would expect.
1277 They're also in the misc fn vector...
1278 FIXME, why did it used to ignore these? That broke
1279 "i fun" on these functions. */
1280 case 'F':
1281 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1282 VAR_NAMESPACE, LOC_BLOCK,
1283 global_psymbols, bufp->n_value);
1284 continue;
1285
bd5635a1
RP
1286 /* Two things show up here (hopefully); static symbols of
1287 local scope (static used inside braces) or extensions
1288 of structure symbols. We can ignore both. */
1289 case 'V':
1290 case '(':
1291 case '0':
1292 case '1':
1293 case '2':
1294 case '3':
1295 case '4':
1296 case '5':
1297 case '6':
1298 case '7':
1299 case '8':
1300 case '9':
bd5635a1
RP
1301 continue;
1302
1303 default:
1304 /* Unexpected symbol. Ignore it; perhaps it is an extension
1305 that we don't know about.
1306
1307 Someone says sun cc puts out symbols like
1308 /foo/baz/maclib::/usr/local/bin/maclib,
1309 which would get here with a symbol type of ':'. */
1310 continue;
1311 }
1312
1313 case N_EXCL:
1314
1315 SET_NAMESTRING();
1316
1317 /* Find the corresponding bincl and mark that psymtab on the
1318 psymtab dependency list */
1319 {
1320 struct partial_symtab *needed_pst =
1321 find_corresponding_bincl_psymtab (namestring, bufp->n_value);
1322
1323 /* If this include file was defined earlier in this file,
1324 leave it alone. */
1325 if (needed_pst == pst) continue;
1326
1327 if (needed_pst)
1328 {
1329 int i;
1330 int found = 0;
1331
1332 for (i = 0; i < dependencies_used; i++)
1333 if (dependency_list[i] == needed_pst)
1334 {
1335 found = 1;
1336 break;
1337 }
1338
1339 /* If it's already in the list, skip the rest. */
1340 if (found) continue;
1341
1342 dependency_list[dependencies_used++] = needed_pst;
1343 if (dependencies_used >= dependencies_allocated)
1344 {
1345 struct partial_symtab **orig = dependency_list;
1346 dependency_list =
1347 (struct partial_symtab **)
1348 alloca ((dependencies_allocated *= 2)
1349 * sizeof (struct partial_symtab *));
1350 bcopy (orig, dependency_list,
1351 (dependencies_used
1352 * sizeof (struct partial_symtab *)));
1353#ifdef DEBUG_INFO
1354 fprintf (stderr, "Had to reallocate dependency list.\n");
1355 fprintf (stderr, "New dependencies allocated: %d\n",
1356 dependencies_allocated);
1357#endif
1358 }
1359 }
1360 else
1361 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
1362 symnum);
1363 }
1364 continue;
1365
1366 case N_EINCL:
1367 case N_DSLINE:
1368 case N_BSLINE:
1369 case N_SSYM: /* Claim: Structure or union element.
1370 Hopefully, I can ignore this. */
1371 case N_ENTRY: /* Alternate entry point; can ignore. */
1372 case N_MAIN: /* Can definitely ignore this. */
1373 case N_CATCH: /* These are GNU C++ extensions */
1374 case N_EHDECL: /* that can safely be ignored here. */
1375 case N_LENG:
1376 case N_BCOMM:
1377 case N_ECOMM:
1378 case N_ECOML:
1379 case N_FNAME:
1380 case N_SLINE:
1381 case N_RSYM:
1382 case N_PSYM:
1383 case N_LBRAC:
1384 case N_RBRAC:
1385 case N_NSYMS: /* Ultrix 4.0: symbol count */
0c4d2cc2 1386 case N_DEFD: /* GNU Modula-2 */
bd5635a1
RP
1387 /* These symbols aren't interesting; don't worry about them */
1388
1389 continue;
1390
1391 default:
1392 /* If we haven't found it yet, ignore it. It's probably some
1393 new type we don't know about yet. */
0c4d2cc2 1394 complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type));
bd5635a1
RP
1395 continue;
1396 }
1397 }
1398
1399 /* If there's stuff to be cleaned up, clean it up. */
63989338
JG
1400 if (nlistlen > 0 /* We have some syms */
1401 && entry_point < bufp->n_value
bd5635a1
RP
1402 && entry_point >= last_o_file_start)
1403 {
1404 startup_file_start = last_o_file_start;
1405 startup_file_end = bufp->n_value;
1406 }
1407
1408 if (pst)
1409 {
1410 end_psymtab (pst, psymtab_include_list, includes_used,
afe4ca15 1411 symnum * symbol_size, end_of_text_addr,
bd5635a1
RP
1412 dependency_list, dependencies_used,
1413 global_psymbols.next, static_psymbols.next);
1414 includes_used = 0;
1415 dependencies_used = 0;
1416 pst = (struct partial_symtab *) 0;
1417 }
1418
1419 free_bincl_list ();
1420 discard_cleanups (old_chain);
1421}
1422
4a35d6e9
FF
1423/* Allocate and partially fill a partial symtab. It will be
1424 completely filled at the end of the symbol list.
1425
1426 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1427 is the address relative to which its symbols are (incremental) or 0
1428 (normal). */
1429
bd5635a1 1430
bd5635a1 1431static struct partial_symtab *
7d9884b9 1432start_psymtab (objfile, addr,
bd5635a1 1433 filename, textlow, ldsymoff, global_syms, static_syms)
7d9884b9 1434 struct objfile *objfile;
bd5635a1
RP
1435 CORE_ADDR addr;
1436 char *filename;
1437 CORE_ADDR textlow;
1438 int ldsymoff;
1439 struct partial_symbol *global_syms;
1440 struct partial_symbol *static_syms;
1441{
1442 struct partial_symtab *result =
1443 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
1444 sizeof (struct partial_symtab));
1445
1446 result->addr = addr;
1447
bd5635a1
RP
1448 result->filename =
1449 (char *) obstack_alloc (psymbol_obstack,
1450 strlen (filename) + 1);
1451 strcpy (result->filename, filename);
1452
1453 result->textlow = textlow;
4a35d6e9
FF
1454 result->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
1455 sizeof (struct symloc));
1456 LDSYMOFF(result) = ldsymoff;
bd5635a1
RP
1457
1458 result->readin = 0;
1459 result->symtab = 0;
1460 result->read_symtab = dbx_psymtab_to_symtab;
1461
1462 result->globals_offset = global_syms - global_psymbols.list;
1463 result->statics_offset = static_syms - static_psymbols.list;
1464
1465 result->n_global_syms = 0;
1466 result->n_static_syms = 0;
1467
7d9884b9
JG
1468 /* Chain it to the list owned by the current object file. */
1469 result->objfile = objfile;
1470 result->objfile_chain = objfile->psymtabs;
1471 objfile->psymtabs = result;
bd5635a1
RP
1472
1473 return result;
1474}
1475
1476static int
1477compare_psymbols (s1, s2)
1478 register struct partial_symbol *s1, *s2;
1479{
1480 register char
1481 *st1 = SYMBOL_NAME (s1),
1482 *st2 = SYMBOL_NAME (s2);
1483
0c4d2cc2
JG
1484 if (st1[0] - st2[0])
1485 return st1[0] - st2[0];
1486 if (st1[1] - st2[1])
1487 return st1[1] - st2[1];
1488 return strcmp (st1 + 1, st2 + 1);
bd5635a1
RP
1489}
1490
1491
1492/* Close off the current usage of a partial_symbol table entry. This
1493 involves setting the correct number of includes (with a realloc),
1494 setting the high text mark, setting the symbol length in the
1495 executable, and setting the length of the global and static lists
1496 of psymbols.
1497
1498 The global symbols and static symbols are then seperately sorted.
1499
1500 Then the partial symtab is put on the global list.
1501 *** List variables and peculiarities of same. ***
1502 */
1503static void
1504end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
1505 capping_text, dependency_list, number_dependencies,
1506 capping_global, capping_static)
1507 struct partial_symtab *pst;
1508 char **include_list;
1509 int num_includes;
1510 int capping_symbol_offset;
1511 CORE_ADDR capping_text;
1512 struct partial_symtab **dependency_list;
1513 int number_dependencies;
1514 struct partial_symbol *capping_global, *capping_static;
1515{
1516 int i;
1517
4a35d6e9 1518 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
bd5635a1
RP
1519 pst->texthigh = capping_text;
1520
1521 pst->n_global_syms =
1522 capping_global - (global_psymbols.list + pst->globals_offset);
1523 pst->n_static_syms =
1524 capping_static - (static_psymbols.list + pst->statics_offset);
1525
1526 pst->number_of_dependencies = number_dependencies;
1527 if (number_dependencies)
1528 {
1529 pst->dependencies = (struct partial_symtab **)
1530 obstack_alloc (psymbol_obstack,
1531 number_dependencies * sizeof (struct partial_symtab *));
1532 bcopy (dependency_list, pst->dependencies,
1533 number_dependencies * sizeof (struct partial_symtab *));
1534 }
1535 else
1536 pst->dependencies = 0;
1537
1538 for (i = 0; i < num_includes; i++)
1539 {
bd5635a1
RP
1540 struct partial_symtab *subpst =
1541 (struct partial_symtab *)
1542 obstack_alloc (psymbol_obstack,
1543 sizeof (struct partial_symtab));
1544
1545 subpst->filename =
1546 (char *) obstack_alloc (psymbol_obstack,
1547 strlen (include_list[i]) + 1);
1548 strcpy (subpst->filename, include_list[i]);
1549
7d9884b9
JG
1550 /* Chain it to the list that this object file owns. */
1551 subpst->objfile = pst->objfile;
1552 subpst->objfile_chain = pst->objfile->psymtabs;
1553 pst->objfile->psymtabs = subpst;
1554
bd5635a1 1555 subpst->addr = pst->addr;
4a35d6e9
FF
1556 subpst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
1557 sizeof (struct symloc));
1558 LDSYMOFF(subpst) =
1559 LDSYMLEN(subpst) =
bd5635a1
RP
1560 subpst->textlow =
1561 subpst->texthigh = 0;
1562
3f83182d
JG
1563 /* We could save slight bits of space by only making one of these,
1564 shared by the entire set of include files. FIXME-someday. */
bd5635a1
RP
1565 subpst->dependencies = (struct partial_symtab **)
1566 obstack_alloc (psymbol_obstack,
1567 sizeof (struct partial_symtab *));
1568 subpst->dependencies[0] = pst;
1569 subpst->number_of_dependencies = 1;
1570
1571 subpst->globals_offset =
1572 subpst->n_global_syms =
1573 subpst->statics_offset =
1574 subpst->n_static_syms = 0;
1575
1576 subpst->readin = 0;
9a822037 1577 subpst->symtab = 0;
bd5635a1
RP
1578 subpst->read_symtab = dbx_psymtab_to_symtab;
1579
1580 subpst->next = partial_symtab_list;
1581 partial_symtab_list = subpst;
1582 }
1583
1584 /* Sort the global list; don't sort the static list */
1585 qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms,
1586 sizeof (struct partial_symbol), compare_psymbols);
1587
f9623881
JG
1588 /* If there is already a psymtab or symtab for a file of this name, remove it.
1589 (If there is a symtab, more drastic things also happen.)
1590 This happens in VxWorks. */
1591 free_named_symtabs (pst->filename);
1592
7d9884b9
JG
1593 if (num_includes == 0
1594 && number_dependencies == 0
1595 && pst->n_global_syms == 0
1596 && pst->n_static_syms == 0) {
1597 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1598 it is on the obstack, but we can forget to chain it on the list. */
1599 ;
1600 } else {
1601 /* Put the psymtab on the psymtab list */
1602 pst->next = partial_symtab_list;
1603 partial_symtab_list = pst;
1604 }
bd5635a1
RP
1605}
1606\f
1607static void
7d9884b9 1608psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset)
bd5635a1 1609 struct partial_symtab *pst;
bd5635a1
RP
1610 char *stringtab;
1611 int stringtab_size;
1612 int sym_offset;
1613{
1614 struct cleanup *old_chain;
1615 int i;
1616
1617 if (!pst)
1618 return;
1619
1620 if (pst->readin)
1621 {
1622 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1623 pst->filename);
1624 return;
1625 }
1626
afe4ca15 1627 /* Read in all partial symtabs on which this one is dependent */
bd5635a1
RP
1628 for (i = 0; i < pst->number_of_dependencies; i++)
1629 if (!pst->dependencies[i]->readin)
1630 {
1631 /* Inform about additional files that need to be read in. */
1632 if (info_verbose)
1633 {
1634 fputs_filtered (" ", stdout);
1635 wrap_here ("");
1636 fputs_filtered ("and ", stdout);
1637 wrap_here ("");
1638 printf_filtered ("%s...", pst->dependencies[i]->filename);
1639 wrap_here (""); /* Flush output */
1640 fflush (stdout);
1641 }
7d9884b9 1642 psymtab_to_symtab_1 (pst->dependencies[i],
bd5635a1
RP
1643 stringtab, stringtab_size, sym_offset);
1644 }
1645
4a35d6e9 1646 if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
bd5635a1
RP
1647 {
1648 /* Init stuff necessary for reading in symbols */
c0302457 1649 buildsym_init ();
bd5635a1
RP
1650 old_chain = make_cleanup (really_free_pendings, 0);
1651
1652 /* Read in this files symbols */
7d9884b9 1653 bfd_seek (pst->objfile->obfd, sym_offset, L_SET);
9404978d 1654 pst->symtab =
7d9884b9 1655 read_ofile_symtab (pst->objfile, stringtab, stringtab_size,
4a35d6e9
FF
1656 LDSYMOFF(pst),
1657 LDSYMLEN(pst), pst->textlow,
9404978d
MT
1658 pst->texthigh - pst->textlow, pst->addr);
1659 sort_symtab_syms (pst->symtab);
bd5635a1
RP
1660
1661 do_cleanups (old_chain);
1662 }
1663
1664 pst->readin = 1;
1665}
1666
1667/*
1668 * Read in all of the symbols for a given psymtab for real.
1669 * Be verbose about it if the user wants that.
1670 */
1671static void
1672dbx_psymtab_to_symtab (pst)
1673 struct partial_symtab *pst;
1674{
bd5635a1
RP
1675 char *stringtab;
1676 int stsize, val;
bd5635a1
RP
1677 bfd *sym_bfd;
1678 long st_temp;
1679
1680 if (!pst)
1681 return;
1682
1683 if (pst->readin)
1684 {
1685 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1686 pst->filename);
1687 return;
1688 }
1689
4a35d6e9 1690 if (LDSYMLEN(pst) || pst->number_of_dependencies)
bd5635a1
RP
1691 {
1692 /* Print the message now, before reading the string table,
1693 to avoid disconcerting pauses. */
1694 if (info_verbose)
1695 {
1696 printf_filtered ("Reading in symbols for %s...", pst->filename);
1697 fflush (stdout);
1698 }
1699
7d9884b9 1700 sym_bfd = pst->objfile->obfd;
bd5635a1 1701
7d9884b9 1702 /* We keep the string table for the main symfile resident in memory, but
bd5635a1 1703 not the string table for any other symbol files. */
7d9884b9 1704 if (symfile_objfile != pst->objfile)
bd5635a1
RP
1705 {
1706 /* Read in the string table */
1707
1708 /* FIXME, this uses internal BFD variables. See above in
1709 dbx_symbol_file_open where the macro is defined! */
7d9884b9 1710 bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
bd5635a1 1711
7d9884b9 1712 val = bfd_read (&st_temp, sizeof st_temp, 1, sym_bfd);
bd5635a1 1713 if (val < 0)
7d9884b9 1714 perror_with_name (pst->objfile->name);
dcc35536 1715 stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
7d9884b9
JG
1716#if 0
1717 /* BFD doesn't provide a way to know the total file size, sigh */
1718 struct stat statbuf;
bd5635a1 1719 if (fstat (desc, &statbuf) < 0)
7d9884b9 1720 perror_with_name (pst->objfile->name);
bd5635a1
RP
1721
1722 if (stsize >= 0 && stsize < statbuf.st_size)
7d9884b9
JG
1723#else
1724 if (stsize >= 0)
1725#endif
bd5635a1
RP
1726 {
1727#ifdef BROKEN_LARGE_ALLOCA
1728 stringtab = (char *) xmalloc (stsize);
1729 make_cleanup (free, stringtab);
1730#else
1731 stringtab = (char *) alloca (stsize);
1732#endif
1733 }
1734 else
1735 stringtab = NULL;
1736 if (stringtab == NULL && stsize != 0)
1737 error ("ridiculous string table size: %d bytes", stsize);
1738
1739 /* FIXME, this uses internal BFD variables. See above in
1740 dbx_symbol_file_open where the macro is defined! */
7d9884b9 1741 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
bd5635a1 1742 if (val < 0)
7d9884b9
JG
1743 perror_with_name (pst->objfile->name);
1744 val = bfd_read (stringtab, stsize, 1, sym_bfd);
bd5635a1 1745 if (val < 0)
7d9884b9 1746 perror_with_name (pst->objfile->name);
bd5635a1
RP
1747 }
1748 else
1749 {
1750 stringtab = symfile_string_table;
1751 stsize = symfile_string_table_size;
1752 }
1753
afe4ca15
JG
1754 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1755 symbol_size = obj_symbol_entry_size (sym_bfd);
bd5635a1
RP
1756
1757 /* FIXME, this uses internal BFD variables. See above in
1758 dbx_symbol_file_open where the macro is defined! */
7d9884b9 1759 psymtab_to_symtab_1 (pst, stringtab, stsize,
bd5635a1
RP
1760 SYMBOL_TABLE_OFFSET);
1761
1762 /* Match with global symbols. This only needs to be done once,
1763 after all of the symtabs and dependencies have been read in. */
1764 scan_file_globals ();
1765
bd5635a1
RP
1766 /* Finish up the debug error message. */
1767 if (info_verbose)
1768 printf_filtered ("done.\n");
1769 }
1770}
1771
bd5635a1
RP
1772/*
1773 * Read in a defined section of a specific object file's symbols.
1774 *
1775 * DESC is the file descriptor for the file, positioned at the
1776 * beginning of the symtab
1777 * STRINGTAB is a pointer to the files string
1778 * table, already read in
1779 * SYM_OFFSET is the offset within the file of
1780 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
1781 * number of symbols to read
1782 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1783 * TEXT_SIZE is the size of the text segment read in.
1784 * OFFSET is a relocation offset which gets added to each symbol
1785 */
1786
9404978d 1787static struct symtab *
7d9884b9 1788read_ofile_symtab (objfile, stringtab, stringtab_size, sym_offset,
bd5635a1 1789 sym_size, text_offset, text_size, offset)
7d9884b9 1790 struct objfile *objfile;
bd5635a1
RP
1791 register char *stringtab;
1792 unsigned int stringtab_size;
1793 int sym_offset;
1794 int sym_size;
1795 CORE_ADDR text_offset;
1796 int text_size;
1797 int offset;
1798{
1799 register char *namestring;
7d9884b9 1800 register struct internal_nlist *bufp;
bd5635a1 1801 unsigned char type;
afe4ca15 1802 unsigned max_symnum;
7d9884b9
JG
1803 register bfd *abfd;
1804
bd5635a1
RP
1805 subfile_stack = 0;
1806
1807 stringtab_global = stringtab;
1808 last_source_file = 0;
1809
7d9884b9
JG
1810 abfd = objfile->obfd;
1811 symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */
1812 our_objfile = objfile; /* For end_symtab calls in process_one_symbol */
bd5635a1
RP
1813 symbuf_end = symbuf_idx = 0;
1814
1815 /* It is necessary to actually read one symbol *before* the start
1816 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1817 occurs before the N_SO symbol.
1818
1819 Detecting this in read_dbx_symtab
1820 would slow down initial readin, so we look for it here instead. */
afe4ca15 1821 if (sym_offset >= (int)symbol_size)
bd5635a1 1822 {
7d9884b9
JG
1823 bfd_seek (symfile_bfd, sym_offset - symbol_size, L_INCR);
1824 fill_symbuf (abfd);
bd5635a1 1825 bufp = &symbuf[symbuf_idx++];
7d9884b9 1826 SWAP_SYMBOL (bufp, abfd);
bd5635a1 1827
afe4ca15 1828 SET_NAMESTRING ();
bd5635a1
RP
1829
1830 processing_gcc_compilation =
1831 (bufp->n_type == N_TEXT
1832 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL));
afe4ca15 1833 /* FIXME!!! Check for gcc2_compiled... */
bd5635a1
RP
1834 }
1835 else
1836 {
1837 /* The N_SO starting this symtab is the first symbol, so we
1838 better not check the symbol before it. I'm not this can
1839 happen, but it doesn't hurt to check for it. */
7d9884b9 1840 bfd_seek (symfile_bfd, sym_offset, L_INCR);
bd5635a1
RP
1841 processing_gcc_compilation = 0;
1842 }
1843
1844 if (symbuf_idx == symbuf_end)
7d9884b9 1845 fill_symbuf (abfd);
bd5635a1
RP
1846 bufp = &symbuf[symbuf_idx];
1847 if (bufp->n_type != (unsigned char)N_SO)
1848 error("First symbol in segment of executable not a source symbol");
1849
afe4ca15
JG
1850 max_symnum = sym_size / symbol_size;
1851
bd5635a1 1852 for (symnum = 0;
afe4ca15 1853 symnum < max_symnum;
bd5635a1
RP
1854 symnum++)
1855 {
1856 QUIT; /* Allow this to be interruptable */
1857 if (symbuf_idx == symbuf_end)
7d9884b9 1858 fill_symbuf(abfd);
bd5635a1 1859 bufp = &symbuf[symbuf_idx++];
7d9884b9 1860 SWAP_SYMBOL (bufp, abfd);
bd5635a1 1861
c0302457 1862 type = bufp->n_type;
bd5635a1
RP
1863 if (type == (unsigned char)N_CATCH)
1864 {
1865 /* N_CATCH is not fixed up by the linker, and unfortunately,
1866 there's no other place to put it in the .stab map. */
62c4f98b 1867 bufp->n_value += text_offset + offset;
bd5635a1 1868 }
c0302457
JG
1869 else {
1870 type &= ~N_EXT; /* Ignore external-bit */
1871 if (type == N_TEXT || type == N_DATA || type == N_BSS)
1872 bufp->n_value += offset;
1873 type = bufp->n_type;
1874 }
bd5635a1 1875
afe4ca15 1876 SET_NAMESTRING ();
bd5635a1 1877
7d9884b9
JG
1878 if (type & N_STAB) {
1879 /* Check for a pair of N_SO symbols, which give both a new
1880 source file name (second) and its directory (first). */
1881 if (type == (unsigned char)N_SO) {
1882 /* Save the outer values */
e1ce8aa5 1883 short bufp_n_desc = bufp->n_desc;
bd5635a1
RP
1884 unsigned long valu = bufp->n_value;
1885
7d9884b9
JG
1886 if (symbuf_idx == symbuf_end)
1887 fill_symbuf (abfd);
1888 bufp = &symbuf[symbuf_idx];
1889 if (bufp->n_type == (unsigned char)N_SO) {
1890 char *namestring1 = namestring;
1891
1892 SWAP_SYMBOL (bufp, abfd);
1893 bufp->n_value += offset; /* Relocate */
1894 symbuf_idx++;
1895 symnum++;
1896 SET_NAMESTRING ();
1897
1898 /* No need to check PCC_SOL_BROKEN, on the assumption that
1899 such broken PCC's don't put out N_SO pairs. */
1900 if (last_source_file)
1901 (void)end_symtab (bufp->n_value, 0, 0, objfile);
1902 start_symtab (namestring, namestring1, bufp->n_value);
1903 } else {
1904 /* N_SO without a following N_SO */
1905 process_one_symbol(type, bufp_n_desc, valu, namestring);
1906 /* our_objfile is an implicit parameter. */
1907 }
1908 } else {
bd5635a1 1909
7d9884b9
JG
1910 /* Ordinary symbol
1911
1912 HERE IS WHERE THE REAL WORK GETS DONE!
1913 */
1914 process_one_symbol (type, bufp->n_desc, bufp->n_value,
1915 namestring);
1916 /* our_objfile is an implicit parameter. */
bd5635a1 1917
bd5635a1 1918 }
7d9884b9 1919 }
bd5635a1
RP
1920 /* We skip checking for a new .o or -l file; that should never
1921 happen in this routine. */
1922 else if (type == N_TEXT
1923 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
1924 /* I don't think this code will ever be executed, because
1925 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1926 the N_SO symbol which starts this source file.
1927 However, there is no reason not to accept
1928 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1929 processing_gcc_compilation = 1;
1930 else if (type & N_EXT || type == (unsigned char)N_TEXT
1931 || type == (unsigned char)N_NBTEXT
0c4d2cc2 1932 ) {
bd5635a1
RP
1933 /* Global symbol: see if we came across a dbx defintion for
1934 a corresponding symbol. If so, store the value. Remove
1935 syms from the chain when their values are stored, but
1936 search the whole chain, as there may be several syms from
1937 different files with the same name. */
1938 /* This is probably not true. Since the files will be read
1939 in one at a time, each reference to a global symbol will
1940 be satisfied in each file as it appears. So we skip this
1941 section. */
1942 ;
0c4d2cc2 1943 }
bd5635a1 1944 }
9404978d 1945
7d9884b9 1946 return end_symtab (text_offset + text_size, 0, 0, objfile);
bd5635a1
RP
1947}
1948\f
c0302457 1949int
bd5635a1
RP
1950hashname (name)
1951 char *name;
1952{
1953 register char *p = name;
1954 register int total = p[0];
1955 register int c;
1956
1957 c = p[1];
1958 total += c << 2;
1959 if (c)
1960 {
1961 c = p[2];
1962 total += c << 4;
1963 if (c)
1964 total += p[3] << 6;
1965 }
1966
1967 /* Ensure result is positive. */
1968 if (total < 0) total += (1000 << 6);
1969 return total % HASHSIZE;
1970}
1971
1972\f
1973static void
1974process_one_symbol (type, desc, valu, name)
1975 int type, desc;
1976 CORE_ADDR valu;
1977 char *name;
1978{
1979#ifndef SUN_FIXED_LBRAC_BUG
1980 /* This records the last pc address we've seen. We depend on their being
1981 an SLINE or FUN or SO before the first LBRAC, since the variable does
1982 not get reset in between reads of different symbol files. */
1983 static CORE_ADDR last_pc_address;
1984#endif
1985 register struct context_stack *new;
1986 char *colon_pos;
1987
1988 /* Something is wrong if we see real data before
1989 seeing a source file name. */
1990
1991 if (last_source_file == 0 && type != (unsigned char)N_SO)
1992 {
1993 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
1994 where that code is defined. */
1995 if (IGNORE_SYMBOL (type))
1996 return;
1997
1998 /* FIXME, this should not be an error, since it precludes extending
1999 the symbol table information in this way... */
2000 error ("Invalid symbol data: does not start by identifying a source file.");
2001 }
2002
2003 switch (type)
2004 {
2005 case N_FUN:
2006 case N_FNAME:
2007 /* Either of these types of symbols indicates the start of
2008 a new function. We must process its "name" normally for dbx,
2009 but also record the start of a new lexical context, and possibly
2010 also the end of the lexical context for the previous function. */
2011 /* This is not always true. This type of symbol may indicate a
2012 text segment variable. */
2013
2014#ifndef SUN_FIXED_LBRAC_BUG
2015 last_pc_address = valu; /* Save for SunOS bug circumcision */
2016#endif
2017
2018 colon_pos = strchr (name, ':');
2019 if (!colon_pos++
2020 || (*colon_pos != 'f' && *colon_pos != 'F'))
2021 {
2022 define_symbol (valu, name, desc, type);
2023 break;
2024 }
2025
2026 within_function = 1;
2027 if (context_stack_depth > 0)
2028 {
7d9884b9 2029 new = pop_context ();
bd5635a1
RP
2030 /* Make a block for the local symbols within. */
2031 finish_block (new->name, &local_symbols, new->old_blocks,
2032 new->start_addr, valu);
2033 }
2034 /* Stack must be empty now. */
2035 if (context_stack_depth != 0)
7d9884b9 2036 complain (lbrac_unmatched_complaint, symnum);
bd5635a1 2037
7d9884b9 2038 new = push_context (0, valu);
bd5635a1 2039 new->name = define_symbol (valu, name, desc, type);
bd5635a1
RP
2040 break;
2041
2042 case N_CATCH:
2043 /* Record the address at which this catch takes place. */
2044 define_symbol (valu, name, desc, type);
2045 break;
2046
2047 case N_EHDECL:
2048 /* Don't know what to do with these yet. */
2049 error ("action uncertain for eh extensions");
2050 break;
2051
2052 case N_LBRAC:
2053 /* This "symbol" just indicates the start of an inner lexical
2054 context within a function. */
2055
2056#if !defined (BLOCK_ADDRESS_ABSOLUTE)
2057 /* On most machines, the block addresses are relative to the
2058 N_SO, the linker did not relocate them (sigh). */
2059 valu += last_source_start_addr;
2060#endif
2061
2062#ifndef SUN_FIXED_LBRAC_BUG
2063 if (valu < last_pc_address) {
2064 /* Patch current LBRAC pc value to match last handy pc value */
2065 complain (&lbrac_complaint, 0);
2066 valu = last_pc_address;
2067 }
2068#endif
7d9884b9 2069 new = push_context (desc, valu);
bd5635a1
RP
2070 break;
2071
2072 case N_RBRAC:
2073 /* This "symbol" just indicates the end of an inner lexical
2074 context that was started with N_LBRAC. */
2075
2076#if !defined (BLOCK_ADDRESS_ABSOLUTE)
2077 /* On most machines, the block addresses are relative to the
2078 N_SO, the linker did not relocate them (sigh). */
2079 valu += last_source_start_addr;
2080#endif
2081
7d9884b9 2082 new = pop_context();
bd5635a1 2083 if (desc != new->depth)
7d9884b9 2084 complain (lbrac_mismatch_complaint, symnum);
bd5635a1
RP
2085
2086 /* Some compilers put the variable decls inside of an
2087 LBRAC/RBRAC block. This macro should be nonzero if this
2088 is true. DESC is N_DESC from the N_RBRAC symbol.
2089 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL. */
2090#if !defined (VARIABLES_INSIDE_BLOCK)
2091#define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
2092#endif
2093
2094 /* Can only use new->locals as local symbols here if we're in
2095 gcc or on a machine that puts them before the lbrack. */
2096 if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
2097 local_symbols = new->locals;
2098
2099 /* If this is not the outermost LBRAC...RBRAC pair in the
2100 function, its local symbols preceded it, and are the ones
2101 just recovered from the context stack. Defined the block for them.
2102
2103 If this is the outermost LBRAC...RBRAC pair, there is no
2104 need to do anything; leave the symbols that preceded it
2105 to be attached to the function's own block. However, if
2106 it is so, we need to indicate that we just moved outside
2107 of the function. */
2108 if (local_symbols
2109 && (context_stack_depth
2110 > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)))
2111 {
2112 /* FIXME Muzzle a compiler bug that makes end < start. */
2113 if (new->start_addr > valu)
2114 {
2115 complain(&lbrac_rbrac_complaint, 0);
2116 new->start_addr = valu;
2117 }
2118 /* Make a block for the local symbols within. */
2119 finish_block (0, &local_symbols, new->old_blocks,
2120 new->start_addr, valu);
2121 }
2122 else
2123 {
2124 within_function = 0;
2125 }
2126 if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
2127 /* Now pop locals of block just finished. */
2128 local_symbols = new->locals;
2129 break;
2130
9bb30452 2131 case N_FN:
6150cc73 2132 case N_FN_SEQ:
9bb30452 2133 /* This kind of symbol indicates the start of an object file. */
bd5635a1
RP
2134 break;
2135
2136 case N_SO:
2137 /* This type of symbol indicates the start of data
2138 for one source file.
2139 Finish the symbol table of the previous source file
2140 (if any) and start accumulating a new symbol table. */
2141#ifndef SUN_FIXED_LBRAC_BUG
2142 last_pc_address = valu; /* Save for SunOS bug circumcision */
2143#endif
2144
2145#ifdef PCC_SOL_BROKEN
2146 /* pcc bug, occasionally puts out SO for SOL. */
2147 if (context_stack_depth > 0)
2148 {
2149 start_subfile (name, NULL);
2150 break;
2151 }
2152#endif
2153 if (last_source_file)
4137c5fc 2154 (void)end_symtab (valu, 0, 0);
bd5635a1
RP
2155 start_symtab (name, NULL, valu);
2156 break;
2157
2158 case N_SOL:
2159 /* This type of symbol indicates the start of data for
2160 a sub-source-file, one whose contents were copied or
2161 included in the compilation of the main source file
2162 (whose name was given in the N_SO symbol.) */
2163 start_subfile (name, NULL);
2164 break;
2165
2166 case N_BINCL:
2167 push_subfile ();
2168 add_new_header_file (name, valu);
2169 start_subfile (name, NULL);
2170 break;
2171
2172 case N_EINCL:
2173 start_subfile (pop_subfile (), NULL);
2174 break;
2175
2176 case N_EXCL:
2177 add_old_header_file (name, valu);
2178 break;
2179
2180 case N_SLINE:
2181 /* This type of "symbol" really just records
2182 one line-number -- core-address correspondence.
2183 Enter it in the line list for this symbol table. */
2184#ifndef SUN_FIXED_LBRAC_BUG
2185 last_pc_address = valu; /* Save for SunOS bug circumcision */
2186#endif
4137c5fc 2187 record_line (current_subfile, desc, valu);
bd5635a1
RP
2188 break;
2189
2190 case N_BCOMM:
2191 if (common_block)
2192 error ("Invalid symbol data: common within common at symtab pos %d",
2193 symnum);
2194 common_block = local_symbols;
2195 common_block_i = local_symbols ? local_symbols->nsyms : 0;
2196 break;
2197
2198 case N_ECOMM:
2199 /* Symbols declared since the BCOMM are to have the common block
2200 start address added in when we know it. common_block points to
2201 the first symbol after the BCOMM in the local_symbols list;
2202 copy the list and hang it off the symbol for the common block name
2203 for later fixup. */
2204 {
2205 int i;
2206 struct symbol *sym =
2207 (struct symbol *) xmalloc (sizeof (struct symbol));
2208 bzero (sym, sizeof *sym);
2209 SYMBOL_NAME (sym) = savestring (name, strlen (name));
2210 SYMBOL_CLASS (sym) = LOC_BLOCK;
2211 SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
2212 copy_pending (local_symbols, common_block_i, common_block));
2213 i = hashname (SYMBOL_NAME (sym));
2214 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
2215 global_sym_chain[i] = sym;
2216 common_block = 0;
2217 break;
2218 }
2219
2220 case N_ECOML:
2221 case N_LENG:
0c4d2cc2 2222 case N_DEFD: /* GNU Modula-2 symbol */
bd5635a1
RP
2223 break;
2224
2225 default:
2226 if (name)
2227 define_symbol (valu, name, desc, type);
2228 }
2229}
2230\f
bd5635a1
RP
2231/* Copy a pending list, used to record the contents of a common
2232 block for later fixup. */
2233static struct pending *
2234copy_pending (beg, begi, end)
2235 struct pending *beg, *end;
2236 int begi;
2237{
2238 struct pending *new = 0;
2239 struct pending *next;
2240
2241 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
2242 next = next->next, begi = 0)
2243 {
2244 register int j;
2245 for (j = begi; j < next->nsyms; j++)
2246 add_symbol_to_list (next->symbol[j], &new);
2247 }
2248 return new;
2249}
bd5635a1
RP
2250\f
2251/* Register our willingness to decode symbols for SunOS and a.out and
2252 b.out files handled by BFD... */
2253static struct sym_fns sunos_sym_fns = {"sunOs", 6,
9404978d 2254 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
2255
2256static struct sym_fns aout_sym_fns = {"a.out", 5,
9404978d 2257 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
2258
2259static struct sym_fns bout_sym_fns = {"b.out", 5,
9404978d 2260 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
bd5635a1
RP
2261
2262void
2263_initialize_dbxread ()
2264{
2265 add_symtab_fns(&sunos_sym_fns);
2266 add_symtab_fns(&aout_sym_fns);
2267 add_symtab_fns(&bout_sym_fns);
bd5635a1 2268}
This page took 0.148055 seconds and 4 git commands to generate.