1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
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
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 */
39 #include <sys/types.h>
46 #include <sys/param.h>
51 #include "breakpoint.h"
54 #include "gdbcore.h" /* for bfd stuff */
55 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
60 #include "stab.gnu.h" /* We always use GNU stabs, not native, now */
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. */
66 struct 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 */
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.
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. */
86 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
87 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
95 extern double atof ();
97 /* Forward declarations */
99 static void read_dbx_symtab ();
100 static void init_psymbol_list ();
101 static void process_one_symbol ();
102 void start_subfile ();
104 static struct pending
*copy_pending ();
105 static struct symtab
*read_ofile_symtab ();
106 static void dbx_psymtab_to_symtab ();
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)
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."
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. */
125 #ifndef BELIEVE_PCC_PROMOTION
126 #define BELIEVE_PCC_PROMOTION 0
129 /* Nonzero means give verbose info on gdb action. From main.c. */
130 extern int info_verbose
;
132 /* The BFD for this file -- implicit parameter to next_symbol_text. */
134 static bfd
*symfile_bfd
;
136 /* The objfile for this file -- only good in process_one_symbol(). */
138 static struct objfile
*our_objfile
;
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. */
144 static char *symfile_string_table
;
145 static int symfile_string_table_size
;
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. */
151 static unsigned symbol_size
;
153 /* Complaints about the symbols we have encountered. */
155 struct complaint lbrac_complaint
=
156 {"bad block start address patched", 0, 0};
158 struct complaint string_table_offset_complaint
=
159 {"bad string table offset in symbol %d", 0, 0};
161 struct complaint unknown_symtype_complaint
=
162 {"unknown symbol type %s", 0, 0};
164 struct complaint lbrac_rbrac_complaint
=
165 {"block start larger than block end", 0, 0};
167 struct complaint lbrac_unmatched_complaint
=
168 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
170 struct complaint lbrac_mismatch_complaint
=
171 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
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. */
178 struct header_file_location
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 */
186 /* The actual list and controling variables */
187 static struct header_file_location
*bincl_list
, *next_bincl
;
188 static int bincls_allocated
;
190 /* Free up old header file tables, and allocate new ones.
191 We're reading a new symbol file now. */
194 free_and_init_header_files ()
197 for (i
= 0; i
< n_header_files
; i
++)
198 free (header_files
[i
].name
);
199 if (header_files
) /* First time null */
201 if (this_object_header_files
) /* First time null */
202 free (this_object_header_files
);
204 n_allocated_header_files
= 10;
205 header_files
= (struct header_file
*) xmalloc (10 * sizeof (struct header_file
));
208 n_allocated_this_object_header_files
= 10;
209 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
212 /* Called at the start of each object file's symbols.
213 Clear out the mapping of header file numbers to header files. */
216 new_object_header_files ()
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;
223 /* Add header file number I for this object file
224 at the next successive FILENUM. */
227 add_this_object_header_file (i
)
230 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
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));
238 this_object_header_files
[n_this_object_header_files
++] = i
;
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. */
247 add_old_header_file (name
, instance
)
251 register struct header_file
*p
= header_files
;
254 for (i
= 0; i
< n_header_files
; i
++)
255 if (!strcmp (p
[i
].name
, name
) && instance
== p
[i
].instance
)
257 add_this_object_header_file (i
);
260 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
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.
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". */
276 add_new_header_file (name
, instance
)
281 header_file_prev_index
= -1;
283 /* Make sure there is room for one more header file. */
285 if (n_header_files
== n_allocated_header_files
)
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
)));
294 /* Create an entry for this header file. */
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
*));
304 add_this_object_header_file (i
);
308 static struct type
**
309 explicit_lookup_type (real_filenum
, index
)
310 int real_filenum
, index
;
312 register struct header_file
*f
= &header_files
[real_filenum
];
314 if (index
>= f
->length
)
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);
322 return &f
->vector
[index
];
327 record_misc_function (name
, address
, type
)
332 enum misc_function_type misc_type
;
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;
340 case N_SETV
: misc_type
= mf_data
; break;
342 default: misc_type
= mf_unknown
; break;
345 prim_record_misc_function (obsavestring (name
, strlen (name
)),
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.
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). */
360 dbx_symfile_read (sf
, addr
, mainline
)
363 int mainline
; /* FIXME comments above */
365 struct dbx_symfile_info
*info
= (struct dbx_symfile_info
*) (sf
->sym_private
);
366 bfd
*sym_bfd
= sf
->objfile
->obfd
;
369 val
= bfd_seek (sf
->objfile
->obfd
, info
->symtab_offset
, L_SET
);
371 perror_with_name (sf
->objfile
->name
);
373 /* If mainline, set global string table pointers, and reinitialize global
374 partial symbol list. */
376 symfile_string_table
= info
->stringtab
;
377 symfile_string_table_size
= info
->stringtab_size
;
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
);
384 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
385 symbol_size
= obj_symbol_entry_size (sym_bfd
);
388 make_cleanup (really_free_pendings
, 0);
390 init_misc_bunches ();
391 make_cleanup (discard_misc_bunches
, 0);
393 /* Now that the symbol table data of the executable file are all in core,
394 process them and define symbols accordingly. */
396 read_dbx_symtab (addr
- bfd_section_vma (sym_bfd
, info
->text_sect
), /*offset*/
397 sf
->objfile
, info
->stringtab
, info
->stringtab_size
,
399 bfd_section_vma (sym_bfd
, info
->text_sect
),
400 bfd_section_size (sym_bfd
, info
->text_sect
));
402 /* Go over the misc symbol bunches and install them in vector. */
404 condense_misc_bunches (!mainline
);
406 /* Free up any memory we allocated for ourselves. */
409 free (info
->stringtab
); /* Stringtab is only saved for mainline */
412 sf
->sym_private
= 0; /* Zap pointer to our (now gone) info struct */
414 if (!partial_symtab_list
) {
416 printf_filtered ("(no debugging symbols found)...");
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). */
428 buildsym_new_init ();
430 /* Don't put these on the cleanup chain; they need to stick around
431 until the next call to dbx_new_init. *Then* we'll free them. */
432 if (symfile_string_table
)
434 free (symfile_string_table
);
435 symfile_string_table
= 0;
436 symfile_string_table_size
= 0;
438 free_and_init_header_files ();
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.
448 We read the string table into malloc'd space and stash a pointer to it.
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. */
456 dbx_symfile_init (sf
)
460 bfd
*sym_bfd
= sf
->objfile
->obfd
;
461 char *name
= bfd_get_filename (sym_bfd
);
462 struct dbx_symfile_info
*info
;
463 unsigned char size_temp
[4];
465 /* Allocate struct to keep track of the symfile */
466 sf
->sym_private
= xmalloc (sizeof (*info
));
467 info
= (struct dbx_symfile_info
*)sf
->sym_private
;
469 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
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 */
474 info
->text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
475 if (!info
->text_sect
)
477 info
->symcount
= bfd_get_symcount (sym_bfd
);
479 /* Read the string table size and check it for bogosity. */
480 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
482 perror_with_name (name
);
484 val
= bfd_read (size_temp
, sizeof (long), 1, sym_bfd
);
486 perror_with_name (name
);
487 info
->stringtab_size
= bfd_h_get_32 (sym_bfd
, size_temp
);
489 if (info
->stringtab_size
>= 0)
491 info
->stringtab
= (char *) xmalloc (info
->stringtab_size
);
492 /* Caller is responsible for freeing the string table. No cleanup. */
495 info
->stringtab
= NULL
;
496 if (info
->stringtab
== NULL
&& info
->stringtab_size
!= 0)
497 error ("ridiculous string table size: %d bytes", info
->stringtab_size
);
499 /* Now read in the string table in one big gulp. */
501 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
503 perror_with_name (name
);
504 val
= bfd_read (info
->stringtab
, info
->stringtab_size
, 1, sym_bfd
);
505 if (val
!= info
->stringtab_size
)
506 perror_with_name (name
);
508 /* Record the position of the symbol table for later use. */
510 info
->symtab_offset
= SYMBOL_TABLE_OFFSET
;
513 /* Buffer for reading the symbol table entries. */
514 static struct internal_nlist symbuf
[4096];
515 static int symbuf_idx
;
516 static int symbuf_end
;
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. */
523 static char *stringtab_global
;
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. */
532 fill_symbuf (sym_bfd
)
535 int nbytes
= bfd_read (symbuf
, sizeof (symbuf
), 1, sym_bfd
);
537 perror_with_name (bfd_get_filename (sym_bfd
));
538 else if (nbytes
== 0)
539 error ("Premature end of file reading symbol table");
540 symbuf_end
= nbytes
/ symbol_size
;
544 #define SWAP_SYMBOL(symp, abfd) \
546 (symp)->n_strx = bfd_h_get_32(abfd, \
547 (unsigned char *)&(symp)->n_strx); \
548 (symp)->n_desc = bfd_h_get_16 (abfd, \
549 (unsigned char *)&(symp)->n_desc); \
550 (symp)->n_value = bfd_h_get_32 (abfd, \
551 (unsigned char *)&(symp)->n_value); \
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. */
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. */
566 if (symbuf_idx
== symbuf_end
)
567 fill_symbuf (symfile_bfd
);
569 SWAP_SYMBOL(&symbuf
[symbuf_idx
], symfile_bfd
);
570 return symbuf
[symbuf_idx
++].n_strx
+ stringtab_global
;
573 /* Initializes storage for all of the partial symbols that will be
574 created by read_dbx_symtab and subsidiaries. */
577 init_psymbol_list (total_symbols
)
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
);
586 /* Current best guess is that there are approximately a twentieth
587 of the total symbols (in a debugging file) are global or static
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
));
597 /* Initialize the list of bincls to contain none and have some
601 init_bincl_list (number
)
604 bincls_allocated
= number
;
605 next_bincl
= bincl_list
= (struct header_file_location
*)
606 xmalloc (bincls_allocated
* sizeof(struct header_file_location
));
609 /* Add a bincl to the list. */
612 add_bincl_to_list (pst
, name
, instance
)
613 struct partial_symtab
*pst
;
617 if (next_bincl
>= bincl_list
+ bincls_allocated
)
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
;
626 next_bincl
->pst
= pst
;
627 next_bincl
->instance
= instance
;
628 next_bincl
++->name
= name
;
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. */
635 static struct partial_symtab
*
636 find_corresponding_bincl_psymtab (name
, instance
)
640 struct header_file_location
*bincl
;
642 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
643 if (bincl
->instance
== instance
644 && !strcmp (name
, bincl
->name
))
647 return (struct partial_symtab
*) 0;
650 /* Free the storage allocated for the bincl list. */
656 bincls_allocated
= 0;
659 static struct partial_symtab
*start_psymtab ();
660 static void end_psymtab();
663 /* This is normally a macro defined in read_dbx_symtab, but this
664 is a lot easier to debug. */
666 ADD_PSYMBOL_TO_PLIST(NAME
, NAMELENGTH
, NAMESPACE
, CLASS
, PLIST
, VALUE
)
669 enum namespace NAMESPACE
;
670 enum address_class CLASS
;
671 struct psymbol_allocation_list
*PLIST
;
674 register struct partial_symbol
*psym
;
679 (LIST
).list
+ (LIST
).size
)
681 (LIST
).list
= (struct partial_symbol
*)
682 xrealloc ((LIST
).list
,
684 * sizeof (struct partial_symbol
)));
685 /* Next assumes we only went one over. Should be good if
686 program works correctly */
688 (LIST
).list
+ (LIST
).size
;
691 psym
= (LIST
).next
++;
694 SYMBOL_NAME (psym
) = (char *) obstack_alloc (psymbol_obstack
,
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
);
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)
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). */
719 read_dbx_symtab (addr
, objfile
, stringtab
, stringtab_size
, nlistlen
,
720 text_addr
, text_size
)
722 struct objfile
*objfile
;
723 register char *stringtab
;
724 register long stringtab_size
;
725 register int nlistlen
;
729 register struct internal_nlist
*bufp
;
730 register char *namestring
;
731 register struct partial_symbol
*psym
;
733 int past_first_source_file
= 0;
734 CORE_ADDR last_o_file_start
= 0;
735 struct cleanup
*old_chain
;
739 /* End of the text segment of the executable file. */
740 CORE_ADDR end_of_text_addr
;
742 /* Current partial symtab */
743 struct partial_symtab
*pst
;
745 /* List of current psymtab's include files */
746 char **psymtab_include_list
;
747 int includes_allocated
;
750 /* Index within current psymtab dependency list */
751 struct partial_symtab
**dependency_list
;
752 int dependencies_used
, dependencies_allocated
;
754 stringtab_global
= stringtab
;
756 pst
= (struct partial_symtab
*) 0;
758 includes_allocated
= 30;
760 psymtab_include_list
= (char **) alloca (includes_allocated
*
763 dependencies_allocated
= 30;
764 dependencies_used
= 0;
766 (struct partial_symtab
**) alloca (dependencies_allocated
*
767 sizeof (struct partial_symtab
*));
769 old_chain
= make_cleanup (free_objfile
, objfile
);
771 /* Init bincl list */
772 init_bincl_list (20);
773 make_cleanup (free_bincl_list
, 0);
775 last_source_file
= 0;
777 #ifdef END_OF_TEXT_DEFAULT
778 end_of_text_addr
= END_OF_TEXT_DEFAULT
;
780 end_of_text_addr
= text_addr
+ addr
+ text_size
; /* Relocate */
783 symfile_bfd
= objfile
->obfd
; /* For next_text_symbol */
784 abfd
= objfile
->obfd
;
785 symbuf_end
= symbuf_idx
= 0;
787 for (symnum
= 0; symnum
< nlistlen
; symnum
++)
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
)
793 bufp
= &symbuf
[symbuf_idx
++];
796 * Special case to speed up readin.
798 if (bufp
->n_type
== (unsigned char)N_SLINE
) continue;
800 SWAP_SYMBOL (bufp
, abfd
);
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:
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.
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()\
818 if (((unsigned)bufp->n_strx) >= stringtab_size) { \
819 complain (&string_table_offset_complaint, symnum); \
820 namestring = "foo"; \
822 namestring = bufp->n_strx + stringtab
824 /* Add a symbol with an integer value to a psymtab. */
825 /* This is a macro unless we're debugging. See above this function. */
827 # define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
828 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
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)
837 /* Add any kind of symbol to a psymtab. */
838 #define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
841 (LIST).list + (LIST).size) \
843 (LIST).list = (struct partial_symbol *) \
844 xrealloc ((LIST).list, \
846 * sizeof (struct partial_symbol))); \
847 /* Next assumes we only went one over. Should be good if \
848 program works correctly */ \
850 (LIST).list + (LIST).size; \
853 psym = (LIST).next++; \
855 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
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); \
864 /* End of macro definitions, now let's handle them symbols! */
866 switch (bufp
->n_type
)
869 * Standard, external, non-debugger, symbols
873 case N_NBTEXT
| N_EXT
:
874 case N_NBDATA
| N_EXT
:
875 case N_NBBSS
| N_EXT
:
881 bufp
->n_value
+= addr
; /* Relocate */
886 record_misc_function (namestring
, bufp
->n_value
,
887 bufp
->n_type
); /* Always */
891 /* Standard, local, non-debugger, symbols */
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
897 or GNU ld was used to make the executable. Sequents throw
898 in another wrinkle -- they renumbered N_FN. */
902 bufp
->n_value
+= addr
; /* Relocate */
904 if ((namestring
[0] == '-' && namestring
[1] == 'l')
905 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
906 && namestring
[nsl
- 2] == '.'))
908 if (entry_point
< bufp
->n_value
909 && entry_point
>= last_o_file_start
910 && addr
== 0) /* FIXME nogood nomore */
912 startup_file_start
= last_o_file_start
;
913 startup_file_end
= bufp
->n_value
;
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
)
920 end_psymtab (pst
, psymtab_include_list
, includes_used
,
921 symnum
* symbol_size
, bufp
->n_value
,
922 dependency_list
, dependencies_used
,
923 global_psymbols
.next
, static_psymbols
.next
);
924 pst
= (struct partial_symtab
*) 0;
926 dependencies_used
= 0;
929 past_first_source_file
= 1;
930 last_o_file_start
= bufp
->n_value
;
935 bufp
->n_value
+= addr
; /* Relocate */
937 /* Check for __DYNAMIC, which is used by Sun shared libraries.
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
)))
943 /* Not really a function here, but... */
944 record_misc_function (namestring
, bufp
->n_value
,
945 bufp
->n_type
); /* Always */
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. */
957 if (target_lookup_symbol (namestring
, &reladdr
)) {
958 continue; /* Error in lookup; ignore symbol for now. */
960 bufp
->n_type
^= (N_BSS
^N_UNDF
); /* Define it as a bss-symbol */
961 bufp
->n_value
= reladdr
;
964 continue; /* Just undefined, not COMMON */
966 /* Lots of symbol types we can just ignore. */
975 /* Keep going . . .*/
978 * Special symbol types for GNU
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
;
1003 /* End the current partial symtab and start a new one */
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
)
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
)
1015 SWAP_SYMBOL (bufp
, abfd
);
1017 valu
= bufp
->n_value
;
1021 valu
+= addr
; /* Relocate */
1023 if (pst
&& past_first_source_file
)
1025 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1026 first_symnum
* symbol_size
, valu
,
1027 dependency_list
, dependencies_used
,
1028 global_psymbols
.next
, static_psymbols
.next
);
1029 pst
= (struct partial_symtab
*) 0;
1031 dependencies_used
= 0;
1034 past_first_source_file
= 1;
1036 pst
= start_psymtab (objfile
, addr
,
1038 first_symnum
* symbol_size
,
1039 global_psymbols
.next
, static_psymbols
.next
);
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 */
1050 add_bincl_to_list (pst
, namestring
, bufp
->n_value
);
1052 /* Mark down an include file in the current psymtab */
1054 psymtab_include_list
[includes_used
++] = namestring
;
1055 if (includes_used
>= includes_allocated
)
1057 char **orig
= psymtab_include_list
;
1059 psymtab_include_list
= (char **)
1060 alloca ((includes_allocated
*= 2) *
1062 bcopy (orig
, psymtab_include_list
,
1063 includes_used
* sizeof (char *));
1069 /* Mark down an include file in the current psymtab */
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
1076 if this is a file we've seen before -- either the main
1077 source file, or a previously included file.
1079 This seems to be a lot of time to be spending on N_SOL, but
1080 things like "break c-exp.y:435" need to work (I
1081 suppose the psymtab_include_list could be hashed or put
1082 in a binary tree, if profiling shows this is a major hog). */
1083 if (pst
&& !strcmp (namestring
, pst
->filename
))
1087 for (i
= 0; i
< includes_used
; i
++)
1088 if (!strcmp (namestring
, psymtab_include_list
[i
]))
1097 psymtab_include_list
[includes_used
++] = namestring
;
1098 if (includes_used
>= includes_allocated
)
1100 char **orig
= psymtab_include_list
;
1102 psymtab_include_list
= (char **)
1103 alloca ((includes_allocated
*= 2) *
1105 bcopy (orig
, psymtab_include_list
,
1106 includes_used
* sizeof (char *));
1110 case N_LSYM
: /* Typedef or automatic variable. */
1111 case N_STSYM
: /* Data seg var -- static */
1112 case N_LCSYM
: /* BSS " */
1113 case N_NBSTS
: /* Gould nobase. */
1114 case N_NBLCS
: /* symbols. */
1118 p
= (char *) strchr (namestring
, ':');
1120 /* Skip if there is no :. */
1126 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
1127 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1128 static_psymbols
, bufp
->n_value
);
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
);
1139 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
1140 VAR_NAMESPACE
, LOC_TYPEDEF
,
1141 static_psymbols
, bufp
->n_value
);
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. */
1153 /* We are looking for something of the form
1154 <name> ":" ("t" | "T") [<number> "="] "e"
1155 {<constant> ":" <value> ","} ";". */
1157 /* Skip over the colon and the 't' or 'T'. */
1159 /* This type may be given a number. Skip over it. */
1160 while ((*p
>= '0' && *p
<= '9')
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.
1171 while (*p
&& *p
!= ';' && *p
!= ',')
1175 /* Check for and handle cretinous dbx symbol name
1178 p
= next_symbol_text ();
1180 /* Point to the character after the name
1181 of the enum constant. */
1182 for (q
= p
; *q
&& *q
!= ':'; q
++)
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. */
1191 /* Skip over the value. */
1192 while (*p
&& *p
!= ',')
1194 /* Advance past the comma. */
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
);
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). */
1215 case N_GSYM
: /* Global (extern) variable; can be
1216 data or bss (sigh). */
1218 /* Following may probably be ignored; I'll leave them here
1219 for now (until I do Pascal and Modula 2 extensions). */
1221 case N_PC
: /* I may or may not need this; I
1223 case N_M2C
: /* I suspect that I can ignore this here. */
1224 case N_SCOPE
: /* Same. */
1228 p
= (char *) strchr (namestring
, ':');
1230 continue; /* Not a debugging symbol. */
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. */
1244 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
1245 VAR_NAMESPACE
, LOC_CONST
,
1246 static_psymbols
, bufp
->n_value
);
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
);
1255 bufp
->n_value
+= addr
; /* Relocate */
1256 /* The addresses in these entries are reported to be
1257 wrong. See the code that reads 'G's for symtabs. */
1258 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
1259 VAR_NAMESPACE
, LOC_STATIC
,
1260 global_psymbols
, bufp
->n_value
);
1264 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
1265 VAR_NAMESPACE
, LOC_TYPEDEF
,
1266 static_psymbols
, bufp
->n_value
);
1270 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
1271 VAR_NAMESPACE
, LOC_BLOCK
,
1272 static_psymbols
, bufp
->n_value
);
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. */
1281 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
1282 VAR_NAMESPACE
, LOC_BLOCK
,
1283 global_psymbols
, bufp
->n_value
);
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. */
1304 /* Unexpected symbol. Ignore it; perhaps it is an extension
1305 that we don't know about.
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 ':'. */
1317 /* Find the corresponding bincl and mark that psymtab on the
1318 psymtab dependency list */
1320 struct partial_symtab
*needed_pst
=
1321 find_corresponding_bincl_psymtab (namestring
, bufp
->n_value
);
1323 /* If this include file was defined earlier in this file,
1325 if (needed_pst
== pst
) continue;
1332 for (i
= 0; i
< dependencies_used
; i
++)
1333 if (dependency_list
[i
] == needed_pst
)
1339 /* If it's already in the list, skip the rest. */
1340 if (found
) continue;
1342 dependency_list
[dependencies_used
++] = needed_pst
;
1343 if (dependencies_used
>= dependencies_allocated
)
1345 struct partial_symtab
**orig
= dependency_list
;
1347 (struct partial_symtab
**)
1348 alloca ((dependencies_allocated
*= 2)
1349 * sizeof (struct partial_symtab
*));
1350 bcopy (orig
, dependency_list
,
1352 * sizeof (struct partial_symtab
*)));
1354 fprintf (stderr
, "Had to reallocate dependency list.\n");
1355 fprintf (stderr
, "New dependencies allocated: %d\n",
1356 dependencies_allocated
);
1361 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
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. */
1385 case N_NSYMS
: /* Ultrix 4.0: symbol count */
1386 case N_DEFD
: /* GNU Modula-2 */
1387 /* These symbols aren't interesting; don't worry about them */
1392 /* If we haven't found it yet, ignore it. It's probably some
1393 new type we don't know about yet. */
1394 complain (&unknown_symtype_complaint
, local_hex_string(bufp
->n_type
));
1399 /* If there's stuff to be cleaned up, clean it up. */
1400 if (nlistlen
> 0 /* We have some syms */
1401 && entry_point
< bufp
->n_value
1402 && entry_point
>= last_o_file_start
)
1404 startup_file_start
= last_o_file_start
;
1405 startup_file_end
= bufp
->n_value
;
1410 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1411 symnum
* symbol_size
, end_of_text_addr
,
1412 dependency_list
, dependencies_used
,
1413 global_psymbols
.next
, static_psymbols
.next
);
1415 dependencies_used
= 0;
1416 pst
= (struct partial_symtab
*) 0;
1420 discard_cleanups (old_chain
);
1423 /* Allocate and partially fill a partial symtab. It will be
1424 completely filled at the end of the symbol list.
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
1431 static struct partial_symtab
*
1432 start_psymtab (objfile
, addr
,
1433 filename
, textlow
, ldsymoff
, global_syms
, static_syms
)
1434 struct objfile
*objfile
;
1439 struct partial_symbol
*global_syms
;
1440 struct partial_symbol
*static_syms
;
1442 struct partial_symtab
*result
=
1443 (struct partial_symtab
*) obstack_alloc (psymbol_obstack
,
1444 sizeof (struct partial_symtab
));
1446 result
->addr
= addr
;
1449 (char *) obstack_alloc (psymbol_obstack
,
1450 strlen (filename
) + 1);
1451 strcpy (result
->filename
, filename
);
1453 result
->textlow
= textlow
;
1454 result
->read_symtab_private
= (char *) obstack_alloc (psymbol_obstack
,
1455 sizeof (struct symloc
));
1456 LDSYMOFF(result
) = ldsymoff
;
1460 result
->read_symtab
= dbx_psymtab_to_symtab
;
1462 result
->globals_offset
= global_syms
- global_psymbols
.list
;
1463 result
->statics_offset
= static_syms
- static_psymbols
.list
;
1465 result
->n_global_syms
= 0;
1466 result
->n_static_syms
= 0;
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
;
1477 compare_psymbols (s1
, s2
)
1478 register struct partial_symbol
*s1
, *s2
;
1481 *st1
= SYMBOL_NAME (s1
),
1482 *st2
= SYMBOL_NAME (s2
);
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);
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
1498 The global symbols and static symbols are then seperately sorted.
1500 Then the partial symtab is put on the global list.
1501 *** List variables and peculiarities of same. ***
1504 end_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
;
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
;
1518 LDSYMLEN(pst
) = capping_symbol_offset
- LDSYMOFF(pst
);
1519 pst
->texthigh
= capping_text
;
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
);
1526 pst
->number_of_dependencies
= number_dependencies
;
1527 if (number_dependencies
)
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
*));
1536 pst
->dependencies
= 0;
1538 for (i
= 0; i
< num_includes
; i
++)
1540 struct partial_symtab
*subpst
=
1541 (struct partial_symtab
*)
1542 obstack_alloc (psymbol_obstack
,
1543 sizeof (struct partial_symtab
));
1546 (char *) obstack_alloc (psymbol_obstack
,
1547 strlen (include_list
[i
]) + 1);
1548 strcpy (subpst
->filename
, include_list
[i
]);
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
;
1555 subpst
->addr
= pst
->addr
;
1556 subpst
->read_symtab_private
= (char *) obstack_alloc (psymbol_obstack
,
1557 sizeof (struct symloc
));
1561 subpst
->texthigh
= 0;
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. */
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;
1571 subpst
->globals_offset
=
1572 subpst
->n_global_syms
=
1573 subpst
->statics_offset
=
1574 subpst
->n_static_syms
= 0;
1578 subpst
->read_symtab
= dbx_psymtab_to_symtab
;
1580 subpst
->next
= partial_symtab_list
;
1581 partial_symtab_list
= subpst
;
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
);
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
);
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. */
1601 /* Put the psymtab on the psymtab list */
1602 pst
->next
= partial_symtab_list
;
1603 partial_symtab_list
= pst
;
1608 psymtab_to_symtab_1 (pst
, stringtab
, stringtab_size
, sym_offset
)
1609 struct partial_symtab
*pst
;
1614 struct cleanup
*old_chain
;
1622 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1627 /* Read in all partial symtabs on which this one is dependent */
1628 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1629 if (!pst
->dependencies
[i
]->readin
)
1631 /* Inform about additional files that need to be read in. */
1634 fputs_filtered (" ", stdout
);
1636 fputs_filtered ("and ", stdout
);
1638 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1639 wrap_here (""); /* Flush output */
1642 psymtab_to_symtab_1 (pst
->dependencies
[i
],
1643 stringtab
, stringtab_size
, sym_offset
);
1646 if (LDSYMLEN(pst
)) /* Otherwise it's a dummy */
1648 /* Init stuff necessary for reading in symbols */
1650 old_chain
= make_cleanup (really_free_pendings
, 0);
1652 /* Read in this files symbols */
1653 bfd_seek (pst
->objfile
->obfd
, sym_offset
, L_SET
);
1655 read_ofile_symtab (pst
->objfile
, stringtab
, stringtab_size
,
1657 LDSYMLEN(pst
), pst
->textlow
,
1658 pst
->texthigh
- pst
->textlow
, pst
->addr
);
1659 sort_symtab_syms (pst
->symtab
);
1661 do_cleanups (old_chain
);
1668 * Read in all of the symbols for a given psymtab for real.
1669 * Be verbose about it if the user wants that.
1672 dbx_psymtab_to_symtab (pst
)
1673 struct partial_symtab
*pst
;
1685 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1690 if (LDSYMLEN(pst
) || pst
->number_of_dependencies
)
1692 /* Print the message now, before reading the string table,
1693 to avoid disconcerting pauses. */
1696 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1700 sym_bfd
= pst
->objfile
->obfd
;
1702 /* We keep the string table for the main symfile resident in memory, but
1703 not the string table for any other symbol files. */
1704 if (symfile_objfile
!= pst
->objfile
)
1706 /* Read in the string table */
1708 /* FIXME, this uses internal BFD variables. See above in
1709 dbx_symbol_file_open where the macro is defined! */
1710 bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
1712 val
= bfd_read (&st_temp
, sizeof st_temp
, 1, sym_bfd
);
1714 perror_with_name (pst
->objfile
->name
);
1715 stsize
= bfd_h_get_32 (sym_bfd
, (unsigned char *)&st_temp
);
1717 /* BFD doesn't provide a way to know the total file size, sigh */
1718 struct stat statbuf
;
1719 if (fstat (desc
, &statbuf
) < 0)
1720 perror_with_name (pst
->objfile
->name
);
1722 if (stsize
>= 0 && stsize
< statbuf
.st_size
)
1727 #ifdef BROKEN_LARGE_ALLOCA
1728 stringtab
= (char *) xmalloc (stsize
);
1729 make_cleanup (free
, stringtab
);
1731 stringtab
= (char *) alloca (stsize
);
1736 if (stringtab
== NULL
&& stsize
!= 0)
1737 error ("ridiculous string table size: %d bytes", stsize
);
1739 /* FIXME, this uses internal BFD variables. See above in
1740 dbx_symbol_file_open where the macro is defined! */
1741 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
1743 perror_with_name (pst
->objfile
->name
);
1744 val
= bfd_read (stringtab
, stsize
, 1, sym_bfd
);
1746 perror_with_name (pst
->objfile
->name
);
1750 stringtab
= symfile_string_table
;
1751 stsize
= symfile_string_table_size
;
1754 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1755 symbol_size
= obj_symbol_entry_size (sym_bfd
);
1757 /* FIXME, this uses internal BFD variables. See above in
1758 dbx_symbol_file_open where the macro is defined! */
1759 psymtab_to_symtab_1 (pst
, stringtab
, stsize
,
1760 SYMBOL_TABLE_OFFSET
);
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 ();
1766 /* Finish up the debug error message. */
1768 printf_filtered ("done.\n");
1773 * Read in a defined section of a specific object file's symbols.
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
1787 static struct symtab
*
1788 read_ofile_symtab (objfile
, stringtab
, stringtab_size
, sym_offset
,
1789 sym_size
, text_offset
, text_size
, offset
)
1790 struct objfile
*objfile
;
1791 register char *stringtab
;
1792 unsigned int stringtab_size
;
1795 CORE_ADDR text_offset
;
1799 register char *namestring
;
1800 register struct internal_nlist
*bufp
;
1802 unsigned max_symnum
;
1807 stringtab_global
= stringtab
;
1808 last_source_file
= 0;
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 */
1813 symbuf_end
= symbuf_idx
= 0;
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.
1819 Detecting this in read_dbx_symtab
1820 would slow down initial readin, so we look for it here instead. */
1821 if (sym_offset
>= (int)symbol_size
)
1823 bfd_seek (symfile_bfd
, sym_offset
- symbol_size
, L_INCR
);
1825 bufp
= &symbuf
[symbuf_idx
++];
1826 SWAP_SYMBOL (bufp
, abfd
);
1830 processing_gcc_compilation
=
1831 (bufp
->n_type
== N_TEXT
1832 && !strcmp (namestring
, GCC_COMPILED_FLAG_SYMBOL
));
1833 /* FIXME!!! Check for gcc2_compiled... */
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. */
1840 bfd_seek (symfile_bfd
, sym_offset
, L_INCR
);
1841 processing_gcc_compilation
= 0;
1844 if (symbuf_idx
== symbuf_end
)
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");
1850 max_symnum
= sym_size
/ symbol_size
;
1853 symnum
< max_symnum
;
1856 QUIT
; /* Allow this to be interruptable */
1857 if (symbuf_idx
== symbuf_end
)
1859 bufp
= &symbuf
[symbuf_idx
++];
1860 SWAP_SYMBOL (bufp
, abfd
);
1862 type
= bufp
->n_type
;
1863 if (type
== (unsigned char)N_CATCH
)
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. */
1867 bufp
->n_value
+= text_offset
+ offset
;
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
;
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 */
1883 short bufp_n_desc
= bufp
->n_desc
;
1884 unsigned long valu
= bufp
->n_value
;
1886 if (symbuf_idx
== symbuf_end
)
1888 bufp
= &symbuf
[symbuf_idx
];
1889 if (bufp
->n_type
== (unsigned char)N_SO
) {
1890 char *namestring1
= namestring
;
1892 SWAP_SYMBOL (bufp
, abfd
);
1893 bufp
->n_value
+= offset
; /* Relocate */
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
);
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. */
1912 HERE IS WHERE THE REAL WORK GETS DONE!
1914 process_one_symbol (type
, bufp
->n_desc
, bufp
->n_value
,
1916 /* our_objfile is an implicit parameter. */
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
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
1946 return end_symtab (text_offset
+ text_size
, 0, 0, objfile
);
1953 register char *p
= name
;
1954 register int total
= p
[0];
1967 /* Ensure result is positive. */
1968 if (total
< 0) total
+= (1000 << 6);
1969 return total
% HASHSIZE
;
1974 process_one_symbol (type
, desc
, valu
, name
)
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
;
1985 register struct context_stack
*new;
1988 /* Something is wrong if we see real data before
1989 seeing a source file name. */
1991 if (last_source_file
== 0 && type
!= (unsigned char)N_SO
)
1993 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
1994 where that code is defined. */
1995 if (IGNORE_SYMBOL (type
))
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.");
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. */
2014 #ifndef SUN_FIXED_LBRAC_BUG
2015 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
2018 colon_pos
= strchr (name
, ':');
2020 || (*colon_pos
!= 'f' && *colon_pos
!= 'F'))
2022 define_symbol (valu
, name
, desc
, type
);
2026 within_function
= 1;
2027 if (context_stack_depth
> 0)
2029 new = pop_context ();
2030 /* Make a block for the local symbols within. */
2031 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2032 new->start_addr
, valu
);
2034 /* Stack must be empty now. */
2035 if (context_stack_depth
!= 0)
2036 complain (lbrac_unmatched_complaint
, symnum
);
2038 new = push_context (0, valu
);
2039 new->name
= define_symbol (valu
, name
, desc
, type
);
2043 /* Record the address at which this catch takes place. */
2044 define_symbol (valu
, name
, desc
, type
);
2048 /* Don't know what to do with these yet. */
2049 error ("action uncertain for eh extensions");
2053 /* This "symbol" just indicates the start of an inner lexical
2054 context within a function. */
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
;
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
;
2069 new = push_context (desc
, valu
);
2073 /* This "symbol" just indicates the end of an inner lexical
2074 context that was started with N_LBRAC. */
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
;
2082 new = pop_context();
2083 if (desc
!= new->depth
)
2084 complain (lbrac_mismatch_complaint
, symnum
);
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
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
;
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.
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
2109 && (context_stack_depth
2110 > !VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
)))
2112 /* FIXME Muzzle a compiler bug that makes end < start. */
2113 if (new->start_addr
> valu
)
2115 complain(&lbrac_rbrac_complaint
, 0);
2116 new->start_addr
= valu
;
2118 /* Make a block for the local symbols within. */
2119 finish_block (0, &local_symbols
, new->old_blocks
,
2120 new->start_addr
, valu
);
2124 within_function
= 0;
2126 if (VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
2127 /* Now pop locals of block just finished. */
2128 local_symbols
= new->locals
;
2133 /* This kind of symbol indicates the start of an object file. */
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 */
2145 #ifdef PCC_SOL_BROKEN
2146 /* pcc bug, occasionally puts out SO for SOL. */
2147 if (context_stack_depth
> 0)
2149 start_subfile (name
, NULL
);
2153 if (last_source_file
)
2154 (void)end_symtab (valu
, 0, 0);
2155 start_symtab (name
, NULL
, valu
);
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
);
2168 add_new_header_file (name
, valu
);
2169 start_subfile (name
, NULL
);
2173 start_subfile (pop_subfile (), NULL
);
2177 add_old_header_file (name
, valu
);
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 */
2187 record_line (current_subfile
, desc
, valu
);
2192 error ("Invalid symbol data: common within common at symtab pos %d",
2194 common_block
= local_symbols
;
2195 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
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
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
;
2222 case N_DEFD
: /* GNU Modula-2 symbol */
2227 define_symbol (valu
, name
, desc
, type
);
2231 /* Copy a pending list, used to record the contents of a common
2232 block for later fixup. */
2233 static struct pending
*
2234 copy_pending (beg
, begi
, end
)
2235 struct pending
*beg
, *end
;
2238 struct pending
*new = 0;
2239 struct pending
*next
;
2241 for (next
= beg
; next
!= 0 && (next
!= end
|| begi
< end
->nsyms
);
2242 next
= next
->next
, begi
= 0)
2245 for (j
= begi
; j
< next
->nsyms
; j
++)
2246 add_symbol_to_list (next
->symbol
[j
], &new);
2251 /* Register our willingness to decode symbols for SunOS and a.out and
2252 b.out files handled by BFD... */
2253 static struct sym_fns sunos_sym_fns
= {"sunOs", 6,
2254 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
2256 static struct sym_fns aout_sym_fns
= {"a.out", 5,
2257 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
2259 static struct sym_fns bout_sym_fns
= {"b.out", 5,
2260 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
2263 _initialize_dbxread ()
2265 add_symtab_fns(&sunos_sym_fns
);
2266 add_symtab_fns(&aout_sym_fns
);
2267 add_symtab_fns(&bout_sym_fns
);