1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc.
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
23 #ifdef READ_DBX_FORMAT
26 #include <sys/types.h>
32 #ifdef COFF_ENCAPSULATE
33 #include "a.out.encap.h"
41 * Define specifically gnu symbols here.
44 /* The following type indicates the definition of a symbol as being
45 an indirect reference to another symbol. The other symbol
46 appears as an undefined reference, immediately following this symbol.
48 Indirection is asymmetrical. The other symbol's value will be used
49 to satisfy requests for the indirect symbol, but not vice versa.
50 If the other symbol does not have a definition, libraries will
51 be searched to find a definition. */
56 /* The following symbols refer to set elements.
57 All the N_SET[ATDB] symbols with the same name form one set.
58 Space is allocated for the set in the text section, and each set
59 element's value is stored into one word of the space.
60 The first word of the space is the length of the set (number of elements).
62 The address of the set is made into an N_SETV symbol
63 whose name is the same as the name of the set.
64 This symbol acts like a N_DATA global symbol
65 in that it can satisfy undefined external references. */
68 #define N_SETA 0x14 /* Absolute set element symbol */
69 #endif /* This is input to LD, in a .o file. */
72 #define N_SETT 0x16 /* Text set element symbol */
73 #endif /* This is input to LD, in a .o file. */
76 #define N_SETD 0x18 /* Data set element symbol */
77 #endif /* This is input to LD, in a .o file. */
80 #define N_SETB 0x1A /* Bss set element symbol */
81 #endif /* This is input to LD, in a .o file. */
83 /* Macros dealing with the set element symbols defined in a.out.h */
84 #define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
85 #define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS)
88 #define N_SETV 0x1C /* Pointer to set vector in data area. */
89 #endif /* This is output from LD. */
92 #define N_WARNING 0x1E /* Warning message to print if file included */
93 #endif /* This is input to ld */
97 /* Line number for the data section. This is to be used to describe
98 the source location of a variable declaration. */
100 #define N_DSLINE (N_SLINE+N_DATA-N_TEXT)
103 /* Line number for the bss section. This is to be used to describe
104 the source location of a variable declaration. */
106 #define N_BSLINE (N_SLINE+N_BSS-N_TEXT)
109 #endif /* not __GNU_STAB__ */
113 #include <sys/param.h>
114 #include <sys/file.h>
115 #include <sys/stat.h>
120 #define AOUTHDR struct exec
123 static void add_symbol_to_list ();
124 static void read_dbx_symtab ();
125 static void process_one_symbol ();
126 static void free_all_psymbols ();
127 static struct type *read_type ();
128 static struct type *read_range_type ();
129 static struct type *read_enum_type ();
130 static struct type *read_struct_type ();
131 static struct type *read_array_type ();
132 static long read_number ();
133 static void finish_block ();
134 static struct blockvector *make_blockvector ();
135 static struct symbol *define_symbol ();
136 static void start_subfile ();
137 static int hashname ();
138 static void hash_symsegs ();
140 extern struct symtab *read_symsegs ();
141 extern void free_all_symtabs ();
142 extern void free_all_psymtabs ();
143 extern void free_inclink_symtabs ();
146 static struct type **read_args();
148 /* Macro to determine which symbols to ignore when reading the first symbol
149 of a file. Some machines override this definition. */
151 #ifndef IGNORE_SYMBOL
152 /* This code is used on Ultrix systems. Ignore it */
153 #define IGNORE_SYMBOL(type) (type == N_NSYMS)
156 #ifndef IGNORE_SYMBOL
157 /* Don't ignore any symbols. */
158 #define IGNORE_SYMBOL(type) (0)
160 #endif /* not N_NSYMS */
162 /* Macro for number of symbol table entries (in usual a.out format).
163 Some machines override this definition. */
164 #ifndef NUMBER_OF_SYMBOLS
166 #define NUMBER_OF_SYMBOLS \
167 ((COFF_HEADER(hdr) ? hdr.coffhdr.filehdr.f_nsyms : hdr.a_syms) / \
168 sizeof (struct nlist))
170 #define NUMBER_OF_SYMBOLS (hdr.a_syms / sizeof (struct nlist))
174 /* Macro for file-offset of symbol table (in usual a.out format). */
175 #ifndef SYMBOL_TABLE_OFFSET
176 #define SYMBOL_TABLE_OFFSET N_SYMOFF (hdr)
179 /* Macro for file-offset of string table (in usual a.out format). */
180 #ifndef STRING_TABLE_OFFSET
181 #define STRING_TABLE_OFFSET (N_SYMOFF (hdr) + hdr.a_syms)
184 /* Macro to store the length of the string table data in INTO. */
185 #ifndef READ_STRING_TABLE_SIZE
186 #define READ_STRING_TABLE_SIZE(INTO) \
187 { val = myread (desc, &INTO, sizeof INTO); \
188 if (val < 0) perror_with_name (name); }
191 /* Macro to declare variables to hold the file's header data. */
192 #ifndef DECLARE_FILE_HEADERS
193 #define DECLARE_FILE_HEADERS AOUTHDR hdr
196 /* Macro to read the header data from descriptor DESC and validate it.
197 NAME is the file name, for error messages. */
198 #ifndef READ_FILE_HEADERS
199 #ifdef HEADER_SEEK_FD
200 #define READ_FILE_HEADERS(DESC, NAME) \
201 { HEADER_SEEK_FD (DESC); \
202 val = myread (DESC, &hdr, sizeof hdr); \
203 if (val < 0) perror_with_name (NAME); \
204 if (N_BADMAG (hdr)) \
205 error ("File \"%s\" not in executable format.", NAME); }
207 #define READ_FILE_HEADERS(DESC, NAME) \
208 { val = myread (DESC, &hdr, sizeof hdr); \
209 if (val < 0) perror_with_name (NAME); \
210 if (N_BADMAG (hdr)) \
211 error ("File \"%s\" not in executable format.", NAME); }
215 /* Macro for size of text segment */
216 #ifndef SIZE_OF_TEXT_SEGMENT
217 #define SIZE_OF_TEXT_SEGMENT hdr.a_text
220 /* Macro for name of symbol to indicate a file compiled with gcc. */
221 #ifndef GCC_COMPILED_FLAG_SYMBOL
222 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
225 /* Chain of symtabs made from reading the file's symsegs.
226 These symtabs do not go into symtab_list themselves,
227 but the information is copied from them when appropriate
228 to make the symtabs that will exist permanently. */
230 static struct symtab *symseg_chain;
232 /* Symseg symbol table for the file whose data we are now processing.
233 It is one of those in symseg_chain. Or 0, for a compilation that
236 static struct symtab *current_symseg;
238 /* Name of source file whose symbol data we are now processing.
239 This comes from a symbol of type N_SO. */
241 static char *last_source_file;
243 /* Core address of start of text of current source file.
244 This too comes from the N_SO symbol. */
246 static CORE_ADDR last_source_start_addr;
248 /* End of the text segment of the executable file,
249 as found in the symbol _etext. */
251 static CORE_ADDR end_of_text_addr;
253 /* The list of sub-source-files within the current individual compilation.
254 Each file gets its own symtab with its own linetable and associated info,
255 but they all share one blockvector. */
259 struct subfile *next;
261 struct linetable *line_vector;
262 int line_vector_length;
263 int line_vector_index;
264 int prev_line_number;
267 static struct subfile *subfiles;
269 static struct subfile *current_subfile;
271 /* Count symbols as they are processed, for error messages. */
275 /* Vector of types defined so far, indexed by their dbx type numbers.
276 (In newer sun systems, dbx uses a pair of numbers in parens,
277 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
278 translated through the type_translations hash table to get
279 the index into the type vector.) */
281 static struct typevector *type_vector;
283 /* Number of elements allocated for type_vector currently. */
285 static int type_vector_length;
287 /* Vector of line number information. */
289 static struct linetable *line_vector;
291 /* Index of next entry to go in line_vector_index. */
293 static int line_vector_index;
295 /* Last line number recorded in the line vector. */
297 static int prev_line_number;
299 /* Number of elements allocated for line_vector currently. */
301 static int line_vector_length;
303 /* Hash table of global symbols whose values are not known yet.
304 They are chained thru the SYMBOL_VALUE, since we don't
305 have the correct data for that slot yet. */
308 static struct symbol *global_sym_chain[HASHSIZE];
310 /* Record the symbols defined for each context in a list.
311 We don't create a struct block for the context until we
312 know how long to make it. */
314 #define PENDINGSIZE 100
318 struct pending *next;
320 struct symbol *symbol[PENDINGSIZE];
323 /* List of free `struct pending' structures for reuse. */
324 struct pending *free_pendings;
326 /* Here are the three lists that symbols are put on. */
328 struct pending *file_symbols; /* static at top level, and types */
330 struct pending *global_symbols; /* global functions and variables */
332 struct pending *local_symbols; /* everything local to lexical context */
334 /* Stack representing unclosed lexical contexts
335 (that will become blocks, eventually). */
339 struct pending *locals;
340 struct pending_block *old_blocks;
342 CORE_ADDR start_addr;
346 struct context_stack *context_stack;
348 /* Index of first unused entry in context stack. */
349 int context_stack_depth;
351 /* Currently allocated size of context stack. */
353 int context_stack_size;
355 /* Nonzero if within a function (so symbols should be local,
356 if nothing says specifically). */
360 /* List of blocks already made (lexical contexts already closed).
361 This is used at the end to make the blockvector. */
365 struct pending_block *next;
369 struct pending_block *pending_blocks;
371 extern CORE_ADDR first_object_file_end; /* From blockframe.c */
373 /* File name symbols were loaded from. */
375 static char *symfile;
377 /* Low and high symbol values (inclusive) for the global variable
378 entries in the symbol file. */
380 static int first_global_sym, last_global_sym;
382 /* Partial symbol list for all of the global and static symbols found
385 struct partial_symbol *global_psymbols, *static_psymbols;
386 int global_psymbols_allocated, static_psymbols_allocated;
388 /* Position for next psymbol to be added */
390 struct partial_symbol *next_ps_global, *next_ps_static;
392 /* Global variable which, when set, indicates that we are processing a
393 .o file compiled with gcc */
395 static unsigned char processing_gcc_compilation;
406 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
407 (and add a null character at the end in the copy).
408 Returns the address of the copy. */
411 obsavestring (ptr, size)
415 register char *p = (char *) obstack_alloc (symbol_obstack, size + 1);
416 /* Open-coded bcopy--saves function call time.
417 These strings are usually short. */
419 register char *p1 = ptr;
420 register char *p2 = p;
421 char *end = ptr + size;
429 /* Concatenate strings S1, S2 and S3; return the new string.
430 Space is found in the symbol_obstack. */
433 obconcat (s1, s2, s3)
436 register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
437 register char *val = (char *) obstack_alloc (symbol_obstack, len);
444 /* Support for Sun changes to dbx symbol format */
446 /* For each identified header file, we have a table of types defined
449 header_files maps header file names to their type tables.
450 It is a vector of n_header_files elements.
451 Each element describes one header file.
452 It contains a vector of types.
454 Sometimes it can happen that the same header file produces
455 different results when included in different places.
456 This can result from conditionals or from different
457 things done before including the file.
458 When this happens, there are multiple entries for the file in this table,
459 one entry for each distinct set of results.
460 The entries are distinguished by the INSTANCE field.
461 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
462 used to match header-file references to their corresponding data. */
466 char *name; /* Name of header file */
467 int instance; /* Numeric code distinguishing instances
468 of one header file that produced
469 different results when included.
470 It comes from the N_BINCL or N_EXCL. */
471 struct type **vector; /* Pointer to vector of types */
472 int length; /* Allocated length (# elts) of that vector */
475 static struct header_file *header_files;
477 static int n_header_files;
479 static int n_allocated_header_files;
481 /* During initial symbol readin, we need to have a structure to keep
482 track of which psymtabs have which bincls in them. This structure
483 is used during readin to setup the list of dependencies within each
484 partial symbol table. */
486 struct header_file_location
488 char *name; /* Name of header file */
489 int instance; /* See above */
490 struct partial_symtab *pst; /* Partial symtab that has the
491 BINCL/EINCL defs for this file */
494 /* The actual list and controling variables */
495 static struct header_file_location *bincl_list, *next_bincl;
496 static int bincls_allocated;
498 /* Within each object file, various header files are assigned numbers.
499 A type is defined or referred to with a pair of numbers
500 (FILENUM,TYPENUM) where FILENUM is the number of the header file
501 and TYPENUM is the number within that header file.
502 TYPENUM is the index within the vector of types for that header file.
504 FILENUM == 1 is special; it refers to the main source of the object file,
505 and not to any header file. FILENUM != 1 is interpreted by looking it up
506 in the following table, which contains indices in header_files. */
508 static int *this_object_header_files;
510 static int n_this_object_header_files;
512 static int n_allocated_this_object_header_files;
514 /* When a header file is getting special overriding definitions
515 for one source file, record here the header_files index
516 of its normal definition vector.
517 At other times, this is -1. */
519 static int header_file_prev_index;
521 /* At the start of reading dbx symbols, allocate our tables. */
526 n_allocated_header_files = 10;
527 header_files = (struct header_file *) xxmalloc (10 * sizeof (struct header_file));
530 n_allocated_this_object_header_files = 10;
531 this_object_header_files = (int *) xxmalloc (10 * sizeof (int));
534 /* At the end of reading dbx symbols, free our tables. */
540 for (i = 0; i < n_header_files; i++)
541 free (header_files[i].name);
542 if (header_files) free (header_files);
543 if (this_object_header_files)
544 free (this_object_header_files);
547 /* Called at the start of each object file's symbols.
548 Clear out the mapping of header file numbers to header files. */
551 new_object_header_files ()
553 /* Leave FILENUM of 0 free for builtin types and this file's types. */
554 n_this_object_header_files = 1;
555 header_file_prev_index = -1;
558 /* Add header file number I for this object file
559 at the next successive FILENUM. */
562 add_this_object_header_file (i)
565 if (n_this_object_header_files == n_allocated_this_object_header_files)
567 n_allocated_this_object_header_files *= 2;
568 this_object_header_files
569 = (int *) xrealloc (this_object_header_files,
570 n_allocated_this_object_header_files * sizeof (int));
573 this_object_header_files[n_this_object_header_files++] = i;
576 /* Add to this file an "old" header file, one already seen in
577 a previous object file. NAME is the header file's name.
578 INSTANCE is its instance code, to select among multiple
579 symbol tables for the same header file. */
582 add_old_header_file (name, instance)
586 register struct header_file *p = header_files;
589 for (i = 0; i < n_header_files; i++)
590 if (!strcmp (p[i].name, name) && instance == p[i].instance)
592 add_this_object_header_file (i);
595 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
599 /* Add to this file a "new" header file: definitions for its types follow.
600 NAME is the header file's name.
601 Most often this happens only once for each distinct header file,
602 but not necessarily. If it happens more than once, INSTANCE has
603 a different value each time, and references to the header file
604 use INSTANCE values to select among them.
606 dbx output contains "begin" and "end" markers for each new header file,
607 but at this level we just need to know which files there have been;
608 so we record the file when its "begin" is seen and ignore the "end". */
611 add_new_header_file (name, instance)
616 register struct header_file *p = header_files;
617 header_file_prev_index = -1;
620 /* This code was used before I knew about the instance codes.
621 My first hypothesis is that it is not necessary now
622 that instance codes are handled. */
624 /* Has this header file a previous definition?
625 If so, make a new entry anyway so that this use in this source file
626 gets a separate entry. Later source files get the old entry.
627 Record here the index of the old entry, so that any type indices
628 not previously defined can get defined in the old entry as
629 well as in the new one. */
631 for (i = 0; i < n_header_files; i++)
632 if (!strcmp (p[i].name, name))
634 header_file_prev_index = i;
639 /* Make sure there is room for one more header file. */
641 if (n_header_files == n_allocated_header_files)
643 n_allocated_header_files *= 2;
644 header_files = (struct header_file *)
645 xrealloc (header_files,
646 (n_allocated_header_files
647 * sizeof (struct header_file)));
650 /* Create an entry for this header file. */
652 i = n_header_files++;
653 header_files[i].name = savestring (name, strlen(name));
654 header_files[i].instance = instance;
655 header_files[i].length = 10;
656 header_files[i].vector
657 = (struct type **) xxmalloc (10 * sizeof (struct type *));
658 bzero (header_files[i].vector, 10 * sizeof (struct type *));
660 add_this_object_header_file (i);
663 /* Look up a dbx type-number pair. Return the address of the slot
664 where the type for that number-pair is stored.
665 The number-pair is in TYPENUMS.
667 This can be used for finding the type associated with that pair
668 or for associating a new type with the pair. */
670 static struct type **
671 dbx_lookup_type (typenums)
674 register int filenum = typenums[0], index = typenums[1];
676 if (filenum < 0 || filenum >= n_this_object_header_files)
677 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
678 filenum, index, symnum);
682 /* Type is defined outside of header files.
683 Find it in this object file's type vector. */
684 if (index >= type_vector_length)
686 type_vector_length *= 2;
687 type_vector = (struct typevector *)
688 xrealloc (type_vector,
689 (sizeof (struct typevector)
690 + type_vector_length * sizeof (struct type *)));
691 bzero (&type_vector->type[type_vector_length / 2],
692 type_vector_length * sizeof (struct type *) / 2);
694 return &type_vector->type[index];
698 register int real_filenum = this_object_header_files[filenum];
699 register struct header_file *f;
701 if (real_filenum >= n_header_files)
704 f = &header_files[real_filenum];
706 if (index >= f->length)
709 f->vector = (struct type **)
710 xrealloc (f->vector, f->length * sizeof (struct type *));
711 bzero (&f->vector[f->length / 2],
712 f->length * sizeof (struct type *) / 2);
714 return &f->vector[index];
718 /* Make sure there is a type allocated for type numbers TYPENUMS
719 and return the type object.
720 This can create an empty (zeroed) type object. */
723 dbx_alloc_type (typenums)
726 register struct type **type_addr = dbx_lookup_type (typenums);
727 register struct type *type = *type_addr;
729 /* If we are referring to a type not known at all yet,
730 allocate an empty type for it.
731 We will fill it in later if we find out how. */
734 type = (struct type *) obstack_alloc (symbol_obstack,
735 sizeof (struct type));
736 bzero (type, sizeof (struct type));
737 TYPE_VPTR_FIELDNO (type) = -1;
744 static struct type **
745 explicit_lookup_type (real_filenum, index)
746 int real_filenum, index;
748 register struct header_file *f = &header_files[real_filenum];
750 if (index >= f->length)
753 f->vector = (struct type **)
754 xrealloc (f->vector, f->length * sizeof (struct type *));
755 bzero (&f->vector[f->length / 2],
756 f->length * sizeof (struct type *) / 2);
758 return &f->vector[index];
762 /* maintain the lists of symbols and blocks */
764 /* Add a symbol to one of the lists of symbols. */
766 add_symbol_to_list (symbol, listhead)
767 struct symbol *symbol;
768 struct pending **listhead;
770 /* We keep PENDINGSIZE symbols in each link of the list.
771 If we don't have a link with room in it, add a new link. */
772 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
774 register struct pending *link;
777 link = free_pendings;
778 free_pendings = link->next;
781 link = (struct pending *) xxmalloc (sizeof (struct pending));
783 link->next = *listhead;
788 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
791 /* At end of reading syms, or in case of quit,
792 really free as many `struct pending's as we can easily find. */
795 really_free_pendings ()
797 struct pending *next, *next1;
798 struct pending_block *bnext, *bnext1;
800 for (next = free_pendings; next; next = next1)
807 for (bnext = pending_blocks; bnext; bnext = bnext1)
809 bnext1 = bnext->next;
814 for (next = file_symbols; next; next = next1)
819 for (next = global_symbols; next; next = next1)
826 /* Take one of the lists of symbols and make a block from it.
827 Keep the order the symbols have in the list (reversed from the input file).
828 Put the block on the list of pending blocks. */
831 finish_block (symbol, listhead, old_blocks, start, end)
832 struct symbol *symbol;
833 struct pending **listhead;
834 struct pending_block *old_blocks;
835 CORE_ADDR start, end;
837 register struct pending *next, *next1;
838 register struct block *block;
839 register struct pending_block *pblock;
840 struct pending_block *opblock;
843 /* Count the length of the list of symbols. */
845 for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next);
847 block = (struct block *) obstack_alloc (symbol_obstack,
848 (sizeof (struct block)
850 * sizeof (struct symbol *))));
852 /* Copy the symbols into the block. */
854 BLOCK_NSYMS (block) = i;
855 for (next = *listhead; next; next = next->next)
858 for (j = next->nsyms - 1; j >= 0; j--)
859 BLOCK_SYM (block, --i) = next->symbol[j];
862 BLOCK_START (block) = start;
863 BLOCK_END (block) = end;
864 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
865 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
867 /* Put the block in as the value of the symbol that names it. */
871 SYMBOL_BLOCK_VALUE (symbol) = block;
872 BLOCK_FUNCTION (block) = symbol;
875 BLOCK_FUNCTION (block) = 0;
877 /* Now "free" the links of the list, and empty the list. */
879 for (next = *listhead; next; next = next1)
882 next->next = free_pendings;
883 free_pendings = next;
887 /* Install this block as the superblock
888 of all blocks made since the start of this scope
889 that don't have superblocks yet. */
892 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
894 if (BLOCK_SUPERBLOCK (pblock->block) == 0)
895 BLOCK_SUPERBLOCK (pblock->block) = block;
899 /* Record this block on the list of all blocks in the file.
900 Put it after opblock, or at the beginning if opblock is 0.
901 This puts the block in the list after all its subblocks. */
903 /* Allocate in the symbol_obstack to save time.
904 It wastes a little space. */
905 pblock = (struct pending_block *)
906 obstack_alloc (symbol_obstack,
907 sizeof (struct pending_block));
908 pblock->block = block;
911 pblock->next = opblock->next;
912 opblock->next = pblock;
916 pblock->next = pending_blocks;
917 pending_blocks = pblock;
921 static struct blockvector *
924 register struct pending_block *next, *next1;
925 register struct blockvector *blockvector;
928 /* Count the length of the list of blocks. */
930 for (next = pending_blocks, i = 0; next; next = next->next, i++);
932 blockvector = (struct blockvector *)
933 obstack_alloc (symbol_obstack,
934 (sizeof (struct blockvector)
935 + (i - 1) * sizeof (struct block *)));
937 /* Copy the blocks into the blockvector.
938 This is done in reverse order, which happens to put
939 the blocks into the proper order (ascending starting address).
940 finish_block has hair to insert each block into the list
941 after its subblocks in order to make sure this is true. */
943 BLOCKVECTOR_NBLOCKS (blockvector) = i;
944 for (next = pending_blocks; next; next = next->next)
945 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
947 #if 0 /* Now we make the links in the obstack, so don't free them. */
948 /* Now free the links of the list, and empty the list. */
950 for (next = pending_blocks; next; next = next1)
961 /* Manage the vector of line numbers. */
964 record_line (line, pc)
968 struct linetable_entry *e;
969 /* Ignore the dummy line number in libg.o */
974 /* Make sure line vector is big enough. */
976 if (line_vector_index + 1 >= line_vector_length)
978 line_vector_length *= 2;
979 line_vector = (struct linetable *)
980 xrealloc (line_vector,
981 (sizeof (struct linetable)
982 + line_vector_length * sizeof (struct linetable_entry)));
983 current_subfile->line_vector = line_vector;
986 e = line_vector->item + line_vector_index++;
987 e->line = line; e->pc = pc;
990 /* Start a new symtab for a new source file.
991 This is called when a dbx symbol of type N_SO is seen;
992 it indicates the start of data for one original source file. */
995 start_symtab (name, start_addr)
997 CORE_ADDR start_addr;
999 register struct symtab *s;
1001 last_source_file = name;
1002 last_source_start_addr = start_addr;
1005 within_function = 0;
1007 /* Context stack is initially empty, with room for 10 levels. */
1009 = (struct context_stack *) xxmalloc (10 * sizeof (struct context_stack));
1010 context_stack_size = 10;
1011 context_stack_depth = 0;
1013 new_object_header_files ();
1015 for (s = symseg_chain; s; s = s->next)
1016 if (s->ldsymoff == symnum * sizeof (struct nlist))
1022 type_vector_length = 160;
1023 type_vector = (struct typevector *)
1024 xxmalloc (sizeof (struct typevector)
1025 + type_vector_length * sizeof (struct type *));
1026 bzero (type_vector->type, type_vector_length * sizeof (struct type *));
1028 /* Initialize the list of sub source files with one entry
1029 for this file (the top-level source file). */
1032 current_subfile = 0;
1033 start_subfile (name);
1035 /* Set default for compiler to pcc; assume that we aren't processing
1036 a gcc compiled file until proved otherwise. */
1038 processing_gcc_compilation = 0;
1041 /* Handle an N_SOL symbol, which indicates the start of
1042 code that came from an included (or otherwise merged-in)
1043 source file with a different name. */
1046 start_subfile (name)
1049 register struct subfile *subfile;
1051 /* Save the current subfile's line vector data. */
1053 if (current_subfile)
1055 current_subfile->line_vector_index = line_vector_index;
1056 current_subfile->line_vector_length = line_vector_length;
1057 current_subfile->prev_line_number = prev_line_number;
1060 /* See if this subfile is already known as a subfile of the
1061 current main source file. */
1063 for (subfile = subfiles; subfile; subfile = subfile->next)
1065 if (!strcmp (subfile->name, name))
1067 line_vector = subfile->line_vector;
1068 line_vector_index = subfile->line_vector_index;
1069 line_vector_length = subfile->line_vector_length;
1070 prev_line_number = subfile->prev_line_number;
1071 current_subfile = subfile;
1076 /* This subfile is not known. Add an entry for it. */
1078 line_vector_index = 0;
1079 line_vector_length = 1000;
1080 prev_line_number = -2; /* Force first line number to be explicit */
1081 line_vector = (struct linetable *)
1082 xxmalloc (sizeof (struct linetable)
1083 + line_vector_length * sizeof (struct linetable_entry));
1085 /* Make an entry for this subfile in the list of all subfiles
1086 of the current main source file. */
1088 subfile = (struct subfile *) xxmalloc (sizeof (struct subfile));
1089 subfile->next = subfiles;
1090 subfile->name = savestring (name, strlen (name));
1091 subfile->line_vector = line_vector;
1093 current_subfile = subfile;
1096 /* Finish the symbol definitions for one main source file,
1097 close off all the lexical contexts for that file
1098 (creating struct block's for them), then make the struct symtab
1099 for that file and put it in the list of all such.
1101 END_ADDR is the address of the end of the file's text. */
1104 end_symtab (end_addr)
1107 register struct symtab *symtab;
1108 register struct blockvector *blockvector;
1109 register struct subfile *subfile;
1110 register struct linetable *lv;
1111 struct subfile *nextsub;
1113 if (current_symseg != 0)
1115 last_source_file = 0;
1120 /* Finish the lexical context of the last function in the file;
1121 pop the context stack. */
1123 if (context_stack_depth > 0)
1125 register struct context_stack *cstk;
1126 context_stack_depth--;
1127 cstk = &context_stack[context_stack_depth];
1128 /* Make a block for the local symbols within. */
1129 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
1130 cstk->start_addr, end_addr);
1133 /* Finish defining all the blocks of this symtab. */
1134 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
1135 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
1136 blockvector = make_blockvector ();
1138 current_subfile->line_vector_index = line_vector_index;
1140 /* Now create the symtab objects proper, one for each subfile. */
1141 /* (The main file is one of them.) */
1143 for (subfile = subfiles; subfile; subfile = nextsub)
1145 symtab = (struct symtab *) xxmalloc (sizeof (struct symtab));
1146 symtab->free_ptr = 0;
1148 /* Fill in its components. */
1149 symtab->blockvector = blockvector;
1150 type_vector->length = type_vector_length;
1151 symtab->typevector = type_vector;
1152 symtab->free_code = free_linetable;
1153 if (subfile->next == 0)
1154 symtab->free_ptr = (char *) type_vector;
1156 symtab->filename = subfile->name;
1157 lv = subfile->line_vector;
1158 lv->nitems = subfile->line_vector_index;
1159 symtab->linetable = (struct linetable *)
1160 xrealloc (lv, (sizeof (struct linetable)
1161 + lv->nitems * sizeof (struct linetable_entry)));
1163 symtab->line_charpos = 0;
1165 /* Link the new symtab into the list of such. */
1166 symtab->next = symtab_list;
1167 symtab_list = symtab;
1169 nextsub = subfile->next;
1174 type_vector_length = -1;
1176 line_vector_length = -1;
1177 last_source_file = 0;
1182 /* Handle the N_BINCL and N_EINCL symbol types
1183 that act like N_SOL for switching source files
1184 (different subfiles, as we call them) within one object file,
1185 but using a stack rather than in an arbitrary order. */
1187 struct subfile_stack
1189 struct subfile_stack *next;
1194 struct subfile_stack *subfile_stack;
1199 register struct subfile_stack *tem
1200 = (struct subfile_stack *) xxmalloc (sizeof (struct subfile_stack));
1202 tem->next = subfile_stack;
1203 subfile_stack = tem;
1204 if (current_subfile == 0 || current_subfile->name == 0)
1206 tem->name = current_subfile->name;
1207 tem->prev_index = header_file_prev_index;
1213 register char *name;
1214 register struct subfile_stack *link = subfile_stack;
1220 subfile_stack = link->next;
1221 header_file_prev_index = link->prev_index;
1226 #endif /* Have N_BINCL */
1228 /* Accumulate the misc functions in bunches of 127.
1229 At the end, copy them all into one newly allocated structure. */
1231 #define MISC_BUNCH_SIZE 127
1235 struct misc_bunch *next;
1236 struct misc_function contents[MISC_BUNCH_SIZE];
1239 /* Bunch currently being filled up.
1240 The next field points to chain of filled bunches. */
1242 static struct misc_bunch *misc_bunch;
1244 /* Number of slots filled in current bunch. */
1246 static int misc_bunch_index;
1248 /* Total number of misc functions recorded so far. */
1250 static int misc_count;
1253 init_misc_functions ()
1257 misc_bunch_index = MISC_BUNCH_SIZE;
1261 record_misc_function (name, address)
1265 register struct misc_bunch *new;
1267 if (misc_bunch_index == MISC_BUNCH_SIZE)
1269 new = (struct misc_bunch *) xxmalloc (sizeof (struct misc_bunch));
1270 misc_bunch_index = 0;
1271 new->next = misc_bunch;
1274 misc_bunch->contents[misc_bunch_index].name = name;
1275 misc_bunch->contents[misc_bunch_index].address = address;
1281 compare_misc_functions (fn1, fn2)
1282 struct misc_function *fn1, *fn2;
1284 /* Return a signed result based on unsigned comparisons
1285 so that we sort into unsigned numeric order. */
1286 if (fn1->address < fn2->address)
1288 if (fn1->address > fn2->address)
1294 discard_misc_bunches ()
1296 register struct misc_bunch *next;
1300 next = misc_bunch->next;
1306 /* INCLINK nonzero means bunches are from an incrementally-linked file.
1307 Add them to the existing bunches.
1308 Otherwise INCLINK is zero, and we start from scratch. */
1310 condense_misc_bunches (inclink)
1314 register struct misc_bunch *bunch;
1315 #ifdef NAMES_HAVE_UNDERSCORE
1323 misc_function_vector
1324 = (struct misc_function *)
1325 xrealloc (misc_function_vector, (misc_count + misc_function_count)
1326 * sizeof (struct misc_function));
1327 j = misc_function_count;
1331 misc_function_vector
1332 = (struct misc_function *)
1333 xxmalloc (misc_count * sizeof (struct misc_function));
1340 for (i = 0; i < misc_bunch_index; i++)
1342 misc_function_vector[j] = bunch->contents[i];
1343 misc_function_vector[j].name
1344 = obconcat (misc_function_vector[j].name
1345 + (misc_function_vector[j].name[0] == '_' ? offset : 0),
1349 bunch = bunch->next;
1350 misc_bunch_index = MISC_BUNCH_SIZE;
1354 misc_function_count += misc_count;
1356 misc_function_count = j;
1358 /* Sort the misc functions by address. */
1360 qsort (misc_function_vector, misc_function_count,
1361 sizeof (struct misc_function),
1362 compare_misc_functions);
1365 /* Call sort_syms to sort alphabetically
1366 the symbols of each block of each symtab. */
1369 compare_symbols (s1, s2)
1370 struct symbol **s1, **s2;
1372 register int namediff;
1374 /* Compare the initial characters. */
1375 namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0];
1376 if (namediff != 0) return namediff;
1378 /* If they match, compare the rest of the names. */
1379 namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
1380 if (namediff != 0) return namediff;
1382 /* For symbols of the same name, registers should come first. */
1383 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
1384 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
1387 static void sort_symtab_syms ();
1392 register struct symtab *s;
1394 for (s = symtab_list; s; s = s->next)
1395 sort_symtab_syms (s);
1399 sort_symtab_syms (s)
1400 register struct symtab *s;
1402 register struct blockvector *bv = BLOCKVECTOR (s);
1403 int nbl = BLOCKVECTOR_NBLOCKS (bv);
1405 register struct block *b;
1407 /* Note that in the following sort, we always make sure that
1408 register debug symbol declarations always come before regular
1409 debug symbol declarations (as might happen when parameters are
1410 then put into registers by the compiler). We do this by a
1411 correct compare in compare_symbols, and by the reversal of the
1412 symbols if we don't sort. This works as long as a register debug
1413 symbol always comes after a parameter debug symbol. */
1415 /* This is no longer necessary; lookup_block_symbol now always
1416 prefers some other declaration over a parameter declaration. We
1417 still sort the thing (that is necessary), but we don't reverse it
1418 if we shouldn't sort it. */
1420 for (i = 0; i < nbl; i++)
1422 b = BLOCKVECTOR_BLOCK (bv, i);
1423 if (BLOCK_SHOULD_SORT (b))
1424 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
1425 sizeof (struct symbol *), compare_symbols);
1430 extern struct symtab *psymtab_to_symtab ();
1432 /* This is the symbol-file command. Read the file, analyze its symbols,
1433 and add a struct symtab to symtab_list. */
1436 symbol_file_command (name)
1440 DECLARE_FILE_HEADERS;
1441 struct nlist *nlist;
1445 extern void close ();
1446 struct cleanup *old_chain;
1447 struct symtab *symseg;
1448 struct stat statbuf;
1454 if ((symtab_list || partial_symtab_list)
1455 && !query ("Discard symbol table? ", 0))
1456 error ("Not confirmed.");
1460 free_all_symtabs ();
1461 free_all_psymtabs ();
1465 if ((symtab_list || partial_symtab_list)
1466 && !query ("Load new symbol table from \"%s\"? ", name))
1467 error ("Not confirmed.");
1470 char *absolute_name;
1471 desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);
1473 perror_with_name (name);
1475 name = absolute_name;
1478 old_chain = make_cleanup (close, desc);
1479 make_cleanup (free_current_contents, &name);
1481 READ_FILE_HEADERS (desc, name);
1483 if (NUMBER_OF_SYMBOLS == 0)
1488 free_all_symtabs ();
1489 free_all_psymtabs ();
1490 printf ("%s has no symbol-table; symbols discarded.\n", name);
1492 do_cleanups (old_chain);
1496 printf ("Reading symbol data from %s...", name);
1499 /* Now read the string table, all at once. */
1500 val = lseek (desc, STRING_TABLE_OFFSET, 0);
1502 perror_with_name (name);
1503 stat (name, &statbuf);
1504 READ_STRING_TABLE_SIZE (buffer);
1505 if (buffer >= 0 && buffer < statbuf.st_size)
1506 stringtab = (char *) alloca (buffer);
1509 if (stringtab == NULL)
1510 error ("ridiculous string table size: %d bytes", name, buffer);
1512 bcopy (&buffer, stringtab, sizeof buffer);
1513 val = myread (desc, stringtab + sizeof buffer, buffer - sizeof buffer);
1515 perror_with_name (name);
1517 /* Throw away the old symbol table. */
1522 free_all_symtabs ();
1523 free_all_psymtabs ();
1525 /* Empty the hash table of global syms looking for values. */
1526 bzero (global_sym_chain, sizeof global_sym_chain);
1528 #ifdef READ_GDB_SYMSEGS
1529 /* That puts us at the symsegs. Read them. */
1530 symseg_chain = read_symsegs (desc, name);
1533 /* Free the symtabs made by read_symsegs, but not their contents,
1534 which have been copied into symtabs on symtab_list. */
1535 for (symseg = symseg_chain; symseg; symseg = symseg->next)
1538 struct sourcevector *sv = (struct sourcevector *) symseg->linetable;
1540 for (i = 0; i < sv->length; i++)
1543 struct source *source = sv->source[i];
1545 = (struct symtab *) xxmalloc (sizeof (struct symtab));
1547 bcopy (symseg, sp1, sizeof (struct symtab));
1548 sp1->filename = savestring (source->name, strlen (source->name));
1549 sp1->linetable = &source->contents;
1550 sp1->free_code = free_nothing;
1551 sp1->free_ptr = (i == 0) ? (char *) symseg : 0;
1553 sp1->next = symtab_list;
1558 /* Where people are using the 4.2 ld program, must not check for
1559 symsegs, because that ld puts randonm garbage at the end of
1560 the output file and that would trigger an error message. */
1564 /* Position to read the symbol table. Do not read it all at once. */
1565 val = lseek (desc, SYMBOL_TABLE_OFFSET, 0);
1567 perror_with_name (name);
1569 /* Don't put these on the cleanup chain; they need to stick around
1570 until the next call to symbol_file_command. *Then* we'll free
1572 free_header_files ();
1573 init_header_files ();
1575 init_misc_functions ();
1576 make_cleanup (discard_misc_bunches, 0);
1582 make_cleanup (really_free_pendings, 0);
1584 /* Now that the symbol table data of the executable file are all in core,
1585 process them and define symbols accordingly. Closes desc. */
1587 read_dbx_symtab (desc, stringtab, NUMBER_OF_SYMBOLS, 0, 0, 0);
1589 /* Go over the misc functions and install them in vector. */
1591 condense_misc_bunches (0);
1593 /* Don't allow char * to have a typename (else would get caddr_t.) */
1595 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
1597 /* Make a default for file to list. */
1599 symfile = savestring (name, strlen (name));
1601 /* Call to select_source_symtab used to be here; it was using too
1602 much time. I'll make sure that list_sources can handle the lack
1603 of current_source_symtab */
1605 do_cleanups (old_chain); /* Descriptor closed here */
1607 /* Free the symtabs made by read_symsegs, but not their contents,
1608 which have been copied into symtabs on symtab_list. */
1609 while (symseg_chain)
1611 register struct symtab *s = symseg_chain->next;
1612 free (symseg_chain);
1616 if (!partial_symtab_list)
1617 printf ("\n(no debugging symbols found)...");
1623 /* Return name of file symbols were loaded from, or 0 if none.. */
1631 /* Buffer for reading the symbol table entries. */
1632 static struct nlist symbuf[4096];
1633 static int symbuf_idx;
1634 static int symbuf_end;
1636 /* I/O descriptor for reading the symbol table. */
1637 static int symtab_input_desc;
1639 /* The address of the string table
1640 of the object file we are reading (as copied into core). */
1641 static char *stringtab_global;
1643 /* Refill the symbol table input buffer
1644 and set the variables that control fetching entries from it.
1645 Reports an error if no data available.
1646 This function can read past the end of the symbol table
1647 (into the string table) but this does no harm. */
1652 int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf));
1654 error ("error or end of file reading symbol table");
1655 symbuf_end = nbytes / sizeof (struct nlist);
1660 /* dbx allows the text of a symbol name to be continued into the
1661 next symbol name! When such a continuation is encountered
1662 (a \ at the end of the text of a name)
1663 call this function to get the continuation. */
1668 if (symbuf_idx == symbuf_end)
1671 return symbuf[symbuf_idx++].n_un.n_strx + stringtab_global;
1675 * Initializes storage for all of the partial symbols that will be
1676 * created by read_dbx_symtab and subsidiaries.
1679 init_psymbol_list (total_symbols)
1682 /* Current best guess is that there are approximately a twentieth
1683 of the total symbols (in a debugging file) are global or static
1685 global_psymbols_allocated = total_symbols / 10;
1686 static_psymbols_allocated = total_symbols / 10;
1687 next_ps_global = global_psymbols = (struct partial_symbol *)
1688 xmalloc (global_psymbols_allocated * sizeof (struct partial_symbol));
1689 next_ps_static = static_psymbols = (struct partial_symbol *)
1690 xmalloc (static_psymbols_allocated * sizeof (struct partial_symbol));
1694 * Initialize the list of bincls to contain none and have some
1698 init_bincl_list (number)
1701 bincls_allocated = number;
1702 next_bincl = bincl_list = (struct header_file_location *)
1703 xmalloc (bincls_allocated * sizeof(struct header_file_location));
1707 * Add a bincl to the list.
1710 add_bincl_to_list (pst, name, instance)
1711 struct partial_symtab *pst;
1715 if (next_bincl >= bincl_list + bincls_allocated)
1717 int offset = next_bincl - bincl_list;
1718 bincls_allocated *= 2;
1719 bincl_list = (struct header_file_location *)
1720 xrealloc (bincl_list,
1721 bincls_allocated * sizeof (struct header_file_location));
1722 next_bincl = bincl_list + offset;
1724 next_bincl->pst = pst;
1725 next_bincl->instance = instance;
1726 next_bincl++->name = name;
1730 * Given a name, value pair, find the corresponding
1731 * bincl in the list. Return the partial symtab associated
1732 * with that header_file_location.
1734 struct partial_symtab *
1735 find_corresponding_bincl_psymtab (name, instance)
1739 struct header_file_location *bincl;
1741 for (bincl = bincl_list; bincl < next_bincl; bincl++)
1742 if (bincl->instance == instance
1743 && !strcmp (name, bincl->name))
1746 return (struct partial_symtab *) 0;
1750 * Free the storage allocated for the bincl list.
1756 bincls_allocated = 0;
1759 static struct partial_symtab *start_psymtab ();
1760 static void add_psymtab_dependency ();
1761 static void end_psymtab();
1763 /* Given pointers to an a.out symbol table in core containing dbx
1764 style data, setup partial_symtab's describing each source file for
1765 which debugging information is available. NLISTLEN is the number
1766 of symbols in the symbol table. All symbol names are given as
1767 offsets relative to STRINGTAB.
1769 I have no idea whether or not this routine should be setup to deal
1770 with inclinks. It seems reasonable to me that they be dealt with
1771 standardly, so I am not going to make a strong effort to deal with
1775 static void process_symbol_for_psymtab ();
1778 read_dbx_symtab (desc, stringtab, nlistlen, inclink, text_addr, text_size)
1780 register char *stringtab;
1781 register int nlistlen;
1786 register char *namestring;
1787 register struct symbol *sym, *prev;
1789 int num_object_files = 0;
1790 int past_first_source_file = 0;
1791 struct cleanup *old_chain;
1792 int current_text_start, current_file_symbol_start;
1793 struct pending *global_symbols, *static_symbols;
1794 int nsl; /* Length of namestring, when needed */
1796 /* Current partial symtab */
1797 struct partial_symtab *pst;
1799 /* List of current psymtab's include files */
1800 char **psymtab_include_list;
1801 int includes_allocated;
1804 /* Index within current psymtab dependency list */
1805 struct partial_symtab **dependency_list;
1806 int dependencies_used, dependencies_allocated;
1808 /* Setup a define to deal cleanly with the underscore problem */
1810 #ifdef NAMES_HAVE_UNDERSCORE
1811 #define HASH_OFFSET 1
1813 #define HASH_OFFSET 0
1816 global_symbols = static_symbols =
1817 (struct pending *) 0;
1818 pst = (struct partial_symtab *) 0;
1820 includes_allocated = 30;
1822 psymtab_include_list = (char **) alloca (includes_allocated *
1825 dependencies_allocated = 30;
1826 dependencies_used = 0;
1828 (struct partial_symtab **) alloca (dependencies_allocated *
1829 sizeof (struct partial_symtab *));
1831 old_chain = make_cleanup (free_all_psymtabs, 0);
1833 /* Init bincl list */
1834 init_bincl_list (20);
1835 make_cleanup (free_bincl_list, 0);
1837 /* Setup global partial symbol list */
1838 init_psymbol_list (nlistlen);
1840 last_source_file = 0;
1842 #ifdef END_OF_TEXT_DEFAULT
1843 end_of_text_addr = END_OF_TEXT_DEFAULT;
1846 symtab_input_desc = desc; /* This is needed for fill_symbuf below */
1847 symbuf_end = symbuf_idx = 0;
1849 for (symnum = 0; symnum < nlistlen; symnum++)
1854 /* Get the symbol for this run and pull out some info */
1855 QUIT; /* allow this to be interruptable */
1856 if (symbuf_idx == symbuf_end)
1858 bufp = &symbuf[symbuf_idx++];
1859 type = bufp->n_type;
1862 * Special cases to speed up readin.
1864 if (type == N_SLINE) continue;
1866 namestring = bufp->n_un.n_strx ? bufp->n_un.n_strx + stringtab : "";
1871 * Standard, non-debugger, symbols
1874 case N_TEXT | N_EXT:
1877 if (!strcmp (namestring, "_etext"))
1878 end_of_text_addr = bufp->n_value;
1882 case N_NBTEXT | N_EXT:
1885 case N_NBDATA | N_EXT:
1888 case N_NBBSS | N_EXT:
1891 case N_DATA | N_EXT:
1893 /* Figure out beginning and end of global linker symbol
1894 section and put non-debugger specified symbols on
1897 last_global_sym = symnum;
1898 if (!first_global_sym) first_global_sym = symnum;
1900 record_misc_function (namestring, bufp->n_value); /* Always */
1908 if (!strcmp (namestring + strlen (namestring) - 2, ".o")
1909 || !strncmp (namestring, "-l", 2))
1911 if (num_object_files++ == 1)
1912 first_object_file_end = bufp->n_value;
1913 if (past_first_source_file && pst)
1915 end_psymtab (pst, psymtab_include_list, includes_used,
1916 symnum * sizeof (struct nlist), bufp->n_value,
1917 dependency_list, dependencies_used,
1918 next_ps_global, next_ps_static);
1919 pst = (struct partial_symtab *) 0;
1921 dependencies_used = 0;
1924 past_first_source_file = 1;
1929 case N_UNDF | N_EXT:
1940 /* Keep going . . .*/
1943 * Special symbol types for GNU
1947 case N_INDR | N_EXT:
1951 case N_SETA | N_EXT:
1953 case N_SETT | N_EXT:
1955 case N_SETD | N_EXT:
1957 case N_SETB | N_EXT:
1959 case N_SETV | N_EXT:
1968 /* End the current partial symtab and start a new one */
1970 if (past_first_source_file && pst)
1972 end_psymtab (pst, psymtab_include_list, includes_used,
1973 symnum * sizeof (struct nlist), bufp->n_value,
1974 dependency_list, dependencies_used,
1975 next_ps_global, next_ps_static);
1976 pst = (struct partial_symtab *) 0;
1978 dependencies_used = 0;
1981 past_first_source_file = 1;
1983 pst = start_psymtab (namestring, bufp->n_value,
1984 symnum * sizeof (struct nlist),
1985 next_ps_global, next_ps_static);
1991 /* Add this bincl to the bincl_list for future EXCLs. No
1992 need to save the string; it'll be around until
1993 read_dbx_symtab function return */
1994 add_bincl_to_list (pst, namestring, bufp->n_value);
2000 /* Mark down an include file in the current psymtab */
2002 psymtab_include_list[includes_used++] = namestring;
2003 if (includes_used >= includes_allocated)
2005 char **orig = psymtab_include_list;
2007 psymtab_include_list = (char **)
2008 alloca ((includes_allocated *= 2) *
2010 bcopy (orig, psymtab_include_list,
2011 includes_used * sizeof (char *));
2013 fprintf (stderr, "Had to realloc includes. New size: %d\n",
2014 includes_allocated);
2037 /* Process a symbol as appropriate for the type (this
2038 information is contained in the name of the symbol) */
2040 if (namestring[0] != '\0')
2042 process_symbol_for_psymtab (namestring);
2044 process_symbol_for_psymtab (namestring, tmp_symchain);
2050 /* Find the corresponding bincl and mark that psymtab on the
2051 psymtab dependency list */
2053 struct partial_symtab *needed_pst =
2054 find_corresponding_bincl_psymtab (namestring, bufp->n_value);
2056 /* If this include file was defined earlier in this file,
2058 if (needed_pst == pst) continue;
2065 for (i = 0; i < dependencies_used; i++)
2066 if (dependency_list[i] == needed_pst)
2072 /* If it's already in the list, skip the rest. */
2073 if (found) continue;
2075 dependency_list[dependencies_used++] = needed_pst;
2076 if (dependencies_used >= dependencies_allocated)
2078 struct partial_symtab **orig = dependency_list;
2080 (struct partial_symtab **)
2081 alloca ((dependencies_allocated *= 2)
2082 * sizeof (struct partial_symtab *));
2083 bcopy (orig, dependency_list,
2085 * sizeof (struct partial_symtab *)));
2087 fprintf (stderr, "Had to reallocate dependency list.\n");
2088 fprintf (stderr, "New dependencies allocated: %d\n",
2089 dependencies_allocated);
2094 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
2114 /* These symbols aren't interesting; don't worry about them */
2119 /* If we haven't found it yet, we've got problems */
2121 if (IGNORE_SYMBOL (type))
2124 fatal ("Bad symbol type 0x%x encountered in gdb scan", type);
2128 if (last_source_file)
2130 end_psymtab (pst, psymtab_include_list, includes_used,
2131 symnum * sizeof (struct nlist), end_of_text_addr,
2132 dependency_list, dependencies_used,
2133 next_ps_global, next_ps_static);
2135 dependencies_used = 0;
2136 pst = (struct partial_symtab *) 0;
2140 discard_cleanups (old_chain);
2144 * Take a single symbol (name: NAME) and process it (add it to the
2145 * app psymbol list or not).
2148 process_symbol_for_psymtab (name)
2151 char *p = (char *) index(name, ':') + 1;
2153 struct partial_symbol *sym;
2154 enum { T_IGNORE, T_STATIC, T_GLOBAL } symbol_type;
2155 enum namespace ns = UNDEF_NAMESPACE;
2156 enum address_class class;
2159 if (p == (char *) 0x1)
2160 /* No ":" ; I guess it's not a debuggging symbol */
2163 if ((*p >= '0' && *p <= '9') || *p == '(')
2168 /* Figure out how to handle this symbol */
2171 /* T is a struct/union/enum, t is a typedef */
2173 symbol_type = T_STATIC;
2174 ns = STRUCT_NAMESPACE;
2175 class = LOC_TYPEDEF;
2178 symbol_type = T_STATIC;
2180 class = LOC_TYPEDEF;
2183 symbol_type = T_STATIC;
2188 symbol_type = T_STATIC;
2193 symbol_type = T_STATIC;
2198 symbol_type = T_GLOBAL;
2203 symbol_type = T_GLOBAL;
2211 /* Create the symbol and store it on the list */
2212 /* There's a better algorithm possible for the allocation; figure
2213 out how far through the symbol table we are and do a reestimate */
2214 if (symbol_type == T_STATIC)
2216 if (next_ps_static >= static_psymbols + static_psymbols_allocated)
2218 static_psymbols = (struct partial_symbol *)
2219 xrealloc (static_psymbols,
2220 (static_psymbols_allocated * 2
2221 * sizeof (struct partial_symbol)));
2222 /* Next assumes we only went one over. Should be good if
2223 program works correctly */
2224 next_ps_static = static_psymbols + static_psymbols_allocated;
2225 static_psymbols_allocated *= 2;
2227 fprintf(stderr, "debuginfo: Had to realloc statics\n");
2230 sym = next_ps_static++;
2234 if (next_ps_global >= global_psymbols + global_psymbols_allocated)
2236 global_psymbols = (struct partial_symbol *)
2237 xrealloc (global_psymbols,
2238 (global_psymbols_allocated * 2
2239 * sizeof (struct partial_symbol)));
2240 next_ps_global = global_psymbols + global_psymbols_allocated;
2241 global_psymbols_allocated *= 2;
2243 fprintf(stderr, "debuginfo: Had to realloc globals\n");
2246 sym = next_ps_global++;
2249 SYMBOL_NAME(sym) = (char *) obstack_alloc (psymbol_obstack,
2251 strncpy(SYMBOL_NAME(sym), name, p - name - 1);
2252 SYMBOL_NAME(sym)[p - name - 1] = '\0';
2253 SYMBOL_NAMESPACE(sym) = ns;
2254 SYMBOL_CLASS(sym) = class;
2259 * Allocate and partially fill a partial symtab. It will be
2260 * completely filled at the end of the symbol list.
2262 static struct partial_symtab *
2263 start_psymtab (filename, textlow, ldsymoff, global_syms, static_syms)
2267 struct partial_symbol *global_syms;
2268 struct partial_symbol *static_syms;
2270 struct partial_symtab *result =
2271 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
2272 sizeof (struct partial_symtab));
2275 (char *) obstack_alloc (psymbol_obstack,
2276 strlen (filename) + 1);
2277 strcpy (result->filename, filename);
2279 result->textlow = textlow;
2280 result->ldsymoff = ldsymoff;
2284 result->globals_offset = global_syms - global_psymbols;
2285 result->statics_offset = static_syms - static_psymbols;
2287 result->n_global_syms = 0;
2288 result->n_static_syms = 0;
2294 compare_psymbols (s1, s2)
2295 register struct partial_symbol *s1, *s2;
2298 *st1 = SYMBOL_NAME (s1),
2299 *st2 = SYMBOL_NAME (s2);
2301 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2302 strcmp (st1 + 1, st2 + 1));
2306 /* Close off the current usage of a partial_symbol table entry. This
2307 involves setting the correct number of includes (with a realloc),
2308 setting the high text mark, setting the symbol length in the
2309 executable, and setting the length of the global and static lists
2312 The global symbols and static symbols are then seperately sorted.
2314 Then the partial symtab is put on the global list.
2315 *** List variables and peculiarities of same. ***
2318 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2319 capping_text, dependency_list, number_dependencies,
2320 capping_global, capping_static)
2321 struct partial_symtab *pst;
2322 char **include_list;
2324 int capping_symbol_offset;
2326 struct partial_symtab **dependency_list;
2327 int number_dependencies;
2328 struct partial_symbol *capping_global, *capping_static;
2332 pst->ldsymlen = capping_symbol_offset - pst->ldsymoff;
2333 pst->texthigh = capping_text;
2335 pst->n_global_syms =
2336 capping_global - (global_psymbols + pst->globals_offset);
2337 pst->n_static_syms =
2338 capping_static - (static_psymbols + pst->statics_offset);
2340 pst->dependencies = (struct partial_symtab **)
2341 obstack_alloc (psymbol_obstack,
2342 number_dependencies * sizeof (struct partial_symtab *));
2343 bcopy (dependency_list, pst->dependencies,
2344 number_dependencies * sizeof (struct partial_symtab *));
2345 pst->number_of_dependencies = number_dependencies;
2347 for (i = 0; i < num_includes; i++)
2349 /* Eventually, put this on obstack */
2350 struct partial_symtab *subpst =
2351 (struct partial_symtab *)
2352 obstack_alloc (psymbol_obstack,
2353 sizeof (struct partial_symtab));
2356 (char *) obstack_alloc (psymbol_obstack,
2357 strlen (include_list[i]) + 1);
2358 strcpy (subpst->filename, include_list[i]);
2363 subpst->texthigh = 0;
2366 subpst->dependencies = (struct partial_symtab **)
2367 obstack_alloc (psymbol_obstack,
2368 sizeof (struct partial_symtab *));
2369 subpst->dependencies[0] = pst;
2370 subpst->number_of_dependencies = 1;
2372 subpst->globals_offset =
2373 subpst->n_global_syms =
2374 subpst->statics_offset =
2375 subpst->n_static_syms = 0;
2377 subpst->next = partial_symtab_list;
2378 partial_symtab_list = subpst;
2381 /* Sort the global list; don't sort the static list */
2382 qsort (global_psymbols + pst->globals_offset, pst->n_global_syms,
2383 sizeof (struct partial_symbol), compare_psymbols);
2385 /* Put the psymtab on the psymtab list */
2386 pst->next = partial_symtab_list;
2387 partial_symtab_list = pst;
2391 * Read in all of the symbols for a given psymtab for real. Return
2392 * the value of the symtab you create. Do not free the storage
2393 * allocated to the psymtab; it may have pointers to it.
2395 static void scan_file_globals ();
2396 static void read_ofile_symtab ();
2399 psymtab_to_symtab(pst)
2400 struct partial_symtab *pst;
2403 DECLARE_FILE_HEADERS;
2405 struct partial_symtab **list_patch;
2407 struct stat statbuf;
2408 struct cleanup *old_chain;
2409 extern void close ();
2411 struct symtab *result;
2412 char *name = symfile; /* Some of the macros require the */
2413 /* variable "name" to be defined in */
2414 /* the context in which they execute */
2422 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2428 error("No symbol file currently specified; use command symbol-file");
2430 /* Read in all partial symbtabs on which this one is dependent */
2431 for (i = 0; i < pst->number_of_dependencies; i++)
2432 if (!pst->dependencies[i]->readin)
2433 psymtab_to_symtab (pst->dependencies[i]);
2435 if (pst->ldsymlen) /* Otherwise it's a dummy */
2437 /* Open symbol file and read in string table */
2438 stat (name, &statbuf);
2439 desc = open(name, O_RDONLY, 0); /* symbol_file_command
2440 guarrantees that the symbol file name
2441 will be absolute, so there is no
2444 old_chain = make_cleanup (close, desc);
2447 error("Symbol file not readable");
2449 READ_FILE_HEADERS (desc, name);
2451 /* Read in the string table */
2452 lseek (desc, STRING_TABLE_OFFSET, L_SET);
2453 READ_STRING_TABLE_SIZE (stsize);
2454 if (stsize >= 0 && stsize < statbuf.st_size)
2455 stringtab = (char *) alloca (stsize);
2458 if (stringtab == NULL)
2459 error ("ridiculous string table size: %d bytes", name, stsize);
2461 bcopy (&stsize, stringtab, sizeof stsize);
2462 val = myread (desc, stringtab + sizeof stsize, stsize - sizeof stsize);
2464 perror_with_name (name);
2466 /* Init stuff necessary for reading in symbols */
2471 make_cleanup (really_free_pendings, 0);
2473 /* Read in this files symbols */
2474 lseek (desc, SYMBOL_TABLE_OFFSET, L_SET);
2475 read_ofile_symtab (desc, stringtab, pst->ldsymoff,
2476 pst->ldsymlen, pst->textlow,
2477 pst->texthigh - pst->textlow, 0);
2478 sort_symtab_syms (symtab_list); /* At beginning since just added */
2480 /* Match with global symbols */
2481 lseek (desc, SYMBOL_TABLE_OFFSET, L_SET);
2482 scan_file_globals (desc, stringtab,
2483 first_global_sym * sizeof(struct nlist),
2484 last_global_sym - first_global_sym + 1);
2486 do_cleanups (old_chain);
2489 /* Find pst in list, prune it, and free it's storage */
2490 for (list_patch = &partial_symtab_list;
2491 *list_patch && *list_patch != pst;
2492 list_patch = &((*list_patch)->next))
2495 if (!(*list_patch)) /* pst not in list. Don't worry about it? */
2496 fatal ("internal: psymtab_to_symtab called with non-listed pst");
2498 *list_patch = (*list_patch)->next; /* Prune */
2500 pst->readin = 1; /* Mark as read in */
2502 /* It's the last one if we actually read something in */
2506 /* Search through list for correct name. */
2507 for (result = symtab_list; result; result = result->next)
2508 if (!strcmp (result->filename, pst->filename))
2515 * Scan through all of the global symbols defined in the object file,
2516 * assigning values to the debugging symbols that need to be assigned
2519 * DESC is the file descriptor of the symbol file, with the seek
2520 * pointer pointing at the beginning of the symbol table.
2521 * STRINGTAB is the file's string table, already read in.
2522 * OFFSET is the offset (in bytes) of the beginning of the global
2523 * symbols from the beginning of the symbol table.
2524 * NUMSYMS is the number of symbols that have to be checked.
2527 scan_file_globals (desc, stringtab, offset, numsyms)
2535 lseek(desc, offset, L_INCR);
2536 symtab_input_desc = desc;
2537 symbuf_end = symbuf_idx = 0;
2539 for (symnum = 0; symnum < numsyms; symnum++)
2546 if (symbuf_idx == symbuf_end)
2549 bufp = &symbuf[symbuf_idx++];
2550 type = bufp->n_type;
2552 if (type & N_EXT && type != N_EXT)
2554 struct symbol *sym, *prev;
2556 namestring = bufp->n_un.n_strx ?
2557 bufp->n_un.n_strx + stringtab : "";
2558 prev = (struct symbol *) 0;
2560 /* Get the hash index and check all the symbols
2561 under that hash index. */
2563 #ifdef NAMES_HAVE_UNDERSCORE
2564 hash = hashname (namestring + 1);
2565 #else /* ! NAMES_HAVE_UNDERSCORE */
2566 hash = hashname (namestring);
2567 #endif /* ! NAMES_HAVE_UNDERSCORE */
2568 for (sym = global_sym_chain[hash]; sym;)
2571 #ifdef NAMES_HAVE_UNDERSCORE
2573 && namestring[1] == SYMBOL_NAME (sym)[0]
2574 && !strcmp(namestring + 2, SYMBOL_NAME (sym) + 1)
2575 #else /* ! NAMES_HAVE_UNDERSCORE */
2576 namestring[0] == SYMBOL_NAME (sym) [0]
2577 && !strcmp(namestring + 1, SYMBOL_NAME(sym) + 1)
2578 #endif /* ! NAMES_HAVE_UNDERSCORE */
2581 /* Splice this symbol out of the hash chain and
2582 assign the value we have to it. */
2584 SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym);
2586 global_sym_chain[hash]
2587 = (struct symbol *) SYMBOL_VALUE (sym);
2588 SYMBOL_VALUE (sym) = bufp->n_value;
2590 sym = (struct symbol *) SYMBOL_VALUE (prev);
2592 sym = global_sym_chain[hash];
2593 break; /* Only one reference per file */
2598 sym = (struct symbol *) SYMBOL_VALUE (sym);
2603 /* There shouldn't be anything left on the hash list at this point.
2604 If there is, we have done something wrong. For right now it's
2605 worth checking, until I get the bugs out. */
2606 /* Sigh. Unfortunately, the above is not true. If an extern
2607 variable is mentioned in an include file (or a program) and the
2608 variable is never either referenced or defined, there will be a
2609 debugger symbol with no "real" symbol. Oh well. */
2613 * Read in a defined section of a specific object file's symbols.
2615 * DESC is the file descriptor for the file, positioned at the
2616 * beginning of the symtab
2617 * STRINGTAB is a pointer to the files string
2618 * table, already read in
2619 * SYM_OFFSET is the offset within the file of
2620 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
2621 * number of symbols to read
2622 * TEXT_OFFSET is the offset to be added to
2623 * all values of symbols coming in and
2624 * TEXT_SIZE is the size of the text segment read in.
2625 * OFFSET is a flag which indicates that the value of all of the
2626 * symbols should be offset by TEXT_OFFSET (for the purposes of
2627 * incremental linking).
2631 read_ofile_symtab (desc, stringtab, sym_offset,
2632 sym_size, text_offset, text_size, offset)
2634 register char *stringtab;
2641 register char *namestring;
2642 register struct symbol *sym, *prev;
2644 struct cleanup *old_chain;
2651 stringtab_global = stringtab;
2652 last_source_file = 0;
2654 symtab_input_desc = desc;
2655 symbuf_end = symbuf_idx = 0;
2656 lseek(desc, sym_offset, L_INCR);
2659 bufp = &symbuf[symbuf_idx];
2660 if ((unsigned char) bufp->n_type != N_SO)
2661 fatal("First symbol in segment of executable not a source symbol");
2664 symnum < sym_size / sizeof(struct nlist);
2667 QUIT; /* Allow this to be interruptable */
2668 if (symbuf_idx == symbuf_end)
2670 bufp = &symbuf[symbuf_idx++];
2671 type = bufp->n_type;
2674 (type == N_TEXT || type == N_DATA || type == N_BSS))
2675 bufp->n_value += text_offset;
2677 namestring = bufp->n_un.n_strx ? bufp->n_un.n_strx + stringtab : "";
2680 process_one_symbol(type, bufp->n_desc,
2681 bufp->n_value, namestring);
2682 /* We skip checking for a new .o or -l file; that should never
2683 happen in this routine. */
2684 else if (type == N_TEXT
2685 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
2686 processing_gcc_compilation = 1;
2687 else if (type & N_EXT || type == N_TEXT
2692 /* Global symbol: see if we came across a dbx defintion for
2693 a corresponding symbol. If so, store the value. Remove
2694 syms from the chain when their values are stored, but
2695 search the whole chain, as there may be several syms from
2696 different files with the same name. */
2697 /* This is probably not true. Since the files will be read
2698 in one at a time, each reference to a global symbol will
2699 be satisfied in each file as it appears. So we skip this
2701 &stringtab_global; /* For debugger; am I right? */
2703 end_symtab (text_offset + text_size);
2710 register char *p = name;
2711 register int total = p[0];
2724 /* Ensure result is positive. */
2725 if (total < 0) total += (1000 << 6);
2726 return total % HASHSIZE;
2729 /* Put all appropriate global symbols in the symseg data
2730 onto the hash chains so that their addresses will be stored
2731 when seen later in loader global symbols. */
2736 /* Look at each symbol in each block in each symseg symtab. */
2738 for (s = symseg_chain; s; s = s->next)
2741 for (n = BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)) - 1; n >= 0; n--)
2743 register struct block *b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), n);
2745 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
2747 register struct symbol *sym = BLOCK_SYM (b, i);
2749 /* Put the symbol on a chain if its value is an address
2750 that is figured out by the loader. */
2752 if (SYMBOL_CLASS (sym) == LOC_EXTERNAL)
2754 register int hash = hashname (SYMBOL_NAME (sym));
2755 SYMBOL_VALUE (sym) = (int) global_sym_chain[hash];
2756 global_sym_chain[hash] = sym;
2757 SYMBOL_CLASS (sym) = LOC_STATIC;
2765 process_one_symbol (type, desc, value, name)
2770 register struct context_stack *new;
2772 /* Something is wrong if we see real data before
2773 seeing a source file name. */
2775 if (last_source_file == 0 && type != N_SO)
2777 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
2778 where that code is defined, and all symbols on the Convex. */
2779 if (IGNORE_SYMBOL (type))
2782 error ("Invalid symbol data: does not start by identifying a source file.");
2789 /* Either of these types of symbols indicates the start of
2790 a new function. We must process its "name" normally for dbx,
2791 but also record the start of a new lexical context, and possibly
2792 also the end of the lexical context for the previous function. */
2794 within_function = 1;
2795 if (context_stack_depth > 0)
2797 new = &context_stack[--context_stack_depth];
2798 /* Make a block for the local symbols within. */
2799 finish_block (new->name, &local_symbols, new->old_blocks,
2800 new->start_addr, value);
2802 /* Stack must be empty now. */
2803 if (context_stack_depth != 0)
2804 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
2807 new = &context_stack[context_stack_depth++];
2808 new->old_blocks = pending_blocks;
2809 new->start_addr = value;
2810 new->name = define_symbol (value, name, desc);
2815 /* This "symbol" just indicates the start of an inner lexical
2816 context within a function. */
2818 if (context_stack_depth == context_stack_size)
2820 context_stack_size *= 2;
2821 context_stack = (struct context_stack *)
2822 xrealloc (context_stack,
2824 * sizeof (struct context_stack)));
2827 new = &context_stack[context_stack_depth++];
2829 new->locals = local_symbols;
2830 new->old_blocks = pending_blocks;
2831 new->start_addr = value;
2837 /* This "symbol" just indicates the end of an inner lexical
2838 context that was started with N_RBRAC. */
2839 new = &context_stack[--context_stack_depth];
2840 if (desc != new->depth)
2841 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum);
2842 local_symbols = new->locals;
2844 /* If this is not the outermost LBRAC...RBRAC pair in the
2845 function, its local symbols preceded it, and are the ones
2846 just recovered from the context stack. Defined the block for them.
2848 If this is the outermost LBRAC...RBRAC pair, there is no
2849 need to do anything; leave the symbols that preceded it
2850 to be attached to the function's own block. */
2851 if (local_symbols && context_stack_depth > 1)
2853 /* Muzzle a compiler bug that makes end > start. */
2854 if (new->start_addr > value)
2855 new->start_addr = value;
2856 /* Make a block for the local symbols within. */
2857 finish_block (0, &local_symbols, new->old_blocks,
2858 new->start_addr + last_source_start_addr,
2859 value + last_source_start_addr);
2864 /* This kind of symbol supposedly indicates the start
2865 of an object file. In fact this type does not appear. */
2869 /* This type of symbol indicates the start of data
2870 for one source file.
2871 Finish the symbol table of the previous source file
2872 (if any) and start accumulating a new symbol table. */
2873 if (last_source_file)
2875 start_symtab (name, value);
2879 /* This type of symbol indicates the start of data for
2880 a sub-source-file, one whose contents were copied or
2881 included in the compilation of the main source file
2882 (whose name was given in the N_SO symbol.) */
2883 start_subfile (name);
2889 add_new_header_file (name, value);
2890 start_subfile (name);
2894 start_subfile (pop_subfile ());
2898 add_old_header_file (name, value);
2900 #endif /* have N_BINCL */
2903 /* This type of "symbol" really just records
2904 one line-number -- core-address correspondence.
2905 Enter it in the line list for this symbol table. */
2906 record_line (desc, value);
2917 define_symbol (value, name, desc);
2921 /* This function was added for C++ functionality. I presume that it
2922 condenses the bunches formed by reading in an additional .o file
2923 (incremental linking). */
2926 condense_addl_misc_bunches ()
2929 register struct misc_bunch *bunch;
2930 #ifdef NAMES_HAVE_UNDERSCORE
2936 misc_function_vector
2937 = (struct misc_function *) xrealloc (misc_function_vector,
2938 (misc_count + misc_function_count) * sizeof (struct misc_function));
2940 j = misc_function_count;
2944 for (i = 0; i < misc_bunch_index; i++)
2946 misc_function_vector[j] = bunch->contents[i];
2947 misc_function_vector[j].name
2948 = concat (misc_function_vector[j].name
2949 + (misc_function_vector[j].name[0] == '_' ? offset : 0),
2953 bunch = bunch->next;
2954 misc_bunch_index = MISC_BUNCH_SIZE;
2957 misc_function_count += misc_count;
2959 /* Sort the misc functions by address. */
2961 qsort (misc_function_vector, misc_function_count,
2962 sizeof (struct misc_function), compare_misc_functions);
2966 /* Read in another .o file and create a symtab entry for it.*/
2969 read_addl_syms (desc, stringtab, nlistlen, text_addr, text_size)
2971 register char *stringtab;
2972 register int nlistlen;
2976 FILE *stream = fdopen (desc, "r");
2977 register char *namestring;
2978 register struct symbol *sym, *prev;
2980 int num_object_files = 0;
2986 last_source_file = 0;
2987 bzero (global_sym_chain, sizeof global_sym_chain);
2988 symtab_input_desc = desc;
2989 stringtab_global = stringtab;
2992 for (symnum = 0; symnum < nlistlen; symnum++)
2997 QUIT; /* allow this to be interruptable */
2998 if (symbuf_idx == symbuf_end)
3000 bufp = &symbuf[symbuf_idx++];
3001 type = bufp->n_type & N_TYPE;
3002 namestring = bufp->n_un.n_strx ? bufp->n_un.n_strx + stringtab : "";
3004 if( (type == N_TEXT) || (type == N_DATA) || (type == N_BSS) )
3006 /* Relocate this file's symbol table information
3007 to the address it has been loaded into. */
3008 bufp->n_value += text_addr;
3011 type = bufp->n_type;
3014 process_one_symbol (type, bufp->n_desc,
3015 bufp->n_value, namestring);
3016 /* A static text symbol whose name ends in ".o"
3017 can only mean the start of another object file.
3018 So end the symtab of the source file we have been processing.
3019 This is how we avoid counting the libraries as part
3020 or the last source file.
3021 Also this way we find end of first object file (crt0). */
3022 else if ((type == N_TEXT
3027 && (!strcmp (namestring + strlen (namestring) - 2, ".o"))
3028 || ! strcmp (namestring, "-l", 2))
3030 if (num_object_files++ == 1)
3031 first_object_file_end = bufp->n_value;
3032 if (last_source_file)
3033 end_symtab (bufp->n_value);
3035 else if (type & N_EXT || type == N_TEXT
3043 /* Record the location of _etext. */
3044 if (type == (N_TEXT | N_EXT)
3045 && !strcmp (namestring, "_etext"))
3046 end_of_text_addr = bufp->n_value;
3048 /* Global symbol: see if we came across a dbx definition
3049 for a corresponding symbol. If so, store the value.
3050 Remove syms from the chain when their values are stored,
3051 but search the whole chain, as there may be several syms
3052 from different files with the same name. */
3056 #ifdef NAMES_HAVE_UNDERSCORE
3057 hash = hashname (namestring + 1);
3058 #else /* not NAMES_HAVE_UNDERSCORE */
3059 hash = hashname (namestring);
3060 #endif /* not NAMES_HAVE_UNDERSCORE */
3061 for (sym = global_sym_chain[hash];
3065 #ifdef NAMES_HAVE_UNDERSCORE
3067 && namestring[1] == SYMBOL_NAME (sym)[0]
3069 !strcmp (namestring + 2, SYMBOL_NAME (sym) + 1)
3070 #else /* NAMES_HAVE_UNDERSCORE */
3071 namestring[0] == SYMBOL_NAME (sym)[0]
3073 !strcmp (namestring + 1, SYMBOL_NAME (sym) + 1)
3074 #endif /* NAMES_HAVE_UNDERSCORE */
3078 SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym);
3080 global_sym_chain[hash]
3081 = (struct symbol *) SYMBOL_VALUE (sym);
3082 SYMBOL_VALUE (sym) = bufp->n_value;
3084 sym = (struct symbol *) SYMBOL_VALUE (prev);
3086 sym = global_sym_chain[hash];
3093 sym = (struct symbol *) SYMBOL_VALUE (sym);
3098 /* Defined global or text symbol: record as a misc function
3099 if it didn't give its address to a debugger symbol above. */
3100 if (type <= (N_TYPE | N_EXT)
3103 record_misc_function (namestring, bufp->n_value);
3107 if (last_source_file)
3108 end_symtab (text_addr + text_size);
3114 This function allows the addition of incrementally linked object files.
3115 Since this has a fair amount of code in common with symbol_file_command,
3116 it might be worthwhile to consolidate things, as was done with
3117 read_dbx_symtab and condense_misc_bunches. */
3120 add_file_command (arg_string)
3124 DECLARE_FILE_HEADERS;
3125 struct nlist *nlist;
3129 extern void close ();
3130 struct cleanup *old_chain;
3131 struct symtab *symseg;
3132 struct stat statbuf;
3136 if (arg_string == 0)
3137 error ("add-file takes a file name and an address");
3139 for( ; *arg_string == ' '; arg_string++ );
3141 for( ; *arg_string && *arg_string != ' ' ; arg_string++ );
3142 *arg_string++ = (char) 0;
3145 error ("add-file takes a file name and an address");
3147 text_addr = parse_and_eval_address (arg_string);
3151 if (!query ("add symbol table from filename \"%s\" at text_addr = 0x%x\n",
3153 error ("Not confirmed.");
3155 desc = open (name, O_RDONLY);
3157 perror_with_name (name);
3159 old_chain = make_cleanup (close, desc);
3160 make_cleanup (free_current_contents, &name);
3162 READ_FILE_HEADERS (desc, name);
3164 if (NUMBER_OF_SYMBOLS == 0)
3166 printf ("%s does not have a symbol-table.\n", name);
3171 printf ("Reading symbol data from %s...", name);
3174 /* Now read the string table, all at once. */
3175 val = lseek (desc, STRING_TABLE_OFFSET, 0);
3177 perror_with_name (name);
3178 stat (name, &statbuf);
3179 READ_STRING_TABLE_SIZE (buffer);
3180 if (buffer >= 0 && buffer < statbuf.st_size)
3181 stringtab = (char *) alloca (buffer);
3184 if (stringtab == NULL)
3185 error ("ridiculous string table size: %d bytes", name, buffer);
3187 bcopy (&buffer, stringtab, sizeof buffer);
3188 val = myread (desc, stringtab + sizeof buffer, buffer - sizeof buffer);
3190 perror_with_name (name);
3192 #ifdef READ_GDB_SYMSEGS
3193 /* That puts us at the symsegs. Read them. */
3194 symseg_chain = read_symsegs (desc, name);
3197 /* Free the symtabs made by read_symsegs, but not their contents,
3198 which have been copied into symtabs on symtab_list. */
3199 for (symseg = symseg_chain; symseg; symseg = symseg->next)
3202 struct sourcevector *sv = (struct sourcevector *) symseg->linetable;
3204 for (i = 0; i < sv->length; i++)
3207 struct source *source = sv->source[i];
3209 = (struct symtab *) xxmalloc (sizeof (struct symtab));
3211 bcopy (symseg, sp1, sizeof (struct symtab));
3212 sp1->filename = savestring (source->name, strlen (source->name));
3213 sp1->linetable = &source->contents;
3214 sp1->free_code = free_nothing;
3215 sp1->free_ptr = (i == 0) ? (char *) symseg : 0;
3217 sp1->next = symtab_list;
3222 /* Where people are using the 4.2 ld program, must not check for
3223 symsegs, because that ld puts randonm garbage at the end of
3224 the output file and that would trigger an error message. */
3228 /* Position to read the symbol table. Do not read it all at once. */
3229 val = lseek (desc, SYMBOL_TABLE_OFFSET, 0);
3231 perror_with_name (name);
3233 init_misc_functions ();
3234 make_cleanup (discard_misc_bunches, 0);
3235 init_header_files ();
3236 make_cleanup (free_header_files, 0);
3241 make_cleanup (really_free_pendings, 0);
3243 read_addl_syms (desc, stringtab, NUMBER_OF_SYMBOLS, text_addr,
3244 SIZE_OF_TEXT_SEGMENT);
3247 /* Sort symbols alphabetically within each block. */
3251 /* Go over the misc functions and install them in vector. */
3253 condense_addl_misc_bunches (1);
3255 /* Don't allow char * to have a typename (else would get caddr_t.) */
3257 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
3259 /* Make a default for file to list. */
3260 /* Hmmm. I'd say we don't want this in add_file_command, but . . . */
3262 select_source_symtab (symtab_list);
3264 do_cleanups (old_chain);
3266 /* Free the symtabs made by read_symsegs, but not their contents,
3267 which have been copied into symtabs on symtab_list. */
3268 while (symseg_chain)
3270 register struct symtab *s = symseg_chain->next;
3271 free (symseg_chain);
3279 static struct symbol *
3280 define_symbol (value, string, desc)
3285 register struct symbol *sym
3286 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
3287 char *p = (char *) index (string, ':');
3291 /* Ignore syms with empty names. */
3296 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
3297 /* Open-coded bcopy--saves function call time. */
3299 register char *p1 = string;
3300 register char *p2 = SYMBOL_NAME (sym);
3306 /* Determine the type of name being defined. */
3307 if ((*p >= '0' && *p <= '9') || *p == '(')
3312 /* c is a special case, not followed by a type-number.
3313 SYMBOL:c=iVALUE for an integer constant symbol.
3314 SYMBOL:c=rVALUE for a floating constant symbol. */
3318 error ("Invalid symbol data at symtab pos %d.", symnum);
3323 double d = atof (p);
3326 SYMBOL_TYPE (sym) = builtin_type_double;
3327 value = (char *) obstack_alloc (symbol_obstack, sizeof (double));
3328 bcopy (&d, value, sizeof (double));
3329 SYMBOL_VALUE_BYTES (sym) = value;
3330 SYMBOL_CLASS (sym) = LOC_CONST;
3335 SYMBOL_TYPE (sym) = builtin_type_int;
3336 SYMBOL_VALUE (sym) = atoi (p);
3337 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
3341 error ("Invalid symbol data at symtab pos %d.", symnum);
3343 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3344 add_symbol_to_list (sym, &file_symbols);
3348 /* Now usually comes a number that says which data type,
3349 and possibly more stuff to define the type
3350 (all of which is handled by read_type) */
3352 if (deftype == 'p' && *p == 'F')
3353 /* pF is a two-letter code that means a function parameter in Fortran.
3354 The type-number specifies the type of the return value.
3355 Translate it into a pointer-to-function type. */
3359 = lookup_pointer_type (lookup_function_type (read_type (&p)));
3363 struct type *type = read_type (&p);
3365 if ((deftype == 'F' || deftype == 'f')
3366 && TYPE_CODE (type) != TYPE_CODE_FUNC)
3367 SYMBOL_TYPE (sym) = lookup_function_type (type);
3369 SYMBOL_TYPE (sym) = type;
3375 SYMBOL_CLASS (sym) = LOC_BLOCK;
3376 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3377 add_symbol_to_list (sym, &file_symbols);
3381 SYMBOL_CLASS (sym) = LOC_BLOCK;
3382 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3383 add_symbol_to_list (sym, &global_symbols);
3387 /* For a class G (global) symbol, it appears that the
3388 value is not correct. It is necessary to search for the
3389 corresponding linker definition to find the value.
3390 These definitions appear at the end of the namelist. */
3391 i = hashname (SYMBOL_NAME (sym));
3392 SYMBOL_VALUE (sym) = (int) global_sym_chain[i];
3393 global_sym_chain[i] = sym;
3394 SYMBOL_CLASS (sym) = LOC_STATIC;
3395 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3396 add_symbol_to_list (sym, &global_symbols);
3399 /* This case is faked by a conditional above,
3400 when there is no code letter in the dbx data.
3401 Dbx data never actually contains 'l'. */
3403 SYMBOL_CLASS (sym) = LOC_LOCAL;
3404 SYMBOL_VALUE (sym) = value;
3405 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3406 add_symbol_to_list (sym, &local_symbols);
3410 SYMBOL_CLASS (sym) = LOC_ARG;
3411 SYMBOL_VALUE (sym) = value;
3412 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3413 add_symbol_to_list (sym, &local_symbols);
3414 /* DESC == 0 implies compiled with GCC.
3415 In this case, if it says `short', believe it. */
3418 /* If PCC says a parameter is a short or a char,
3419 it is really an int. */
3420 if (SYMBOL_TYPE (sym) == builtin_type_char
3421 || SYMBOL_TYPE (sym) == builtin_type_short)
3422 SYMBOL_TYPE (sym) = builtin_type_int;
3423 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
3424 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
3425 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
3429 SYMBOL_CLASS (sym) = LOC_REGPARM;
3430 SYMBOL_VALUE (sym) = value;
3431 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3432 add_symbol_to_list (sym, &local_symbols);
3436 SYMBOL_CLASS (sym) = LOC_REGISTER;
3437 SYMBOL_VALUE (sym) = value;
3438 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3439 add_symbol_to_list (sym, &local_symbols);
3443 /* Static symbol at top level of file */
3444 SYMBOL_CLASS (sym) = LOC_STATIC;
3445 SYMBOL_VALUE (sym) = value;
3446 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3447 add_symbol_to_list (sym, &file_symbols);
3451 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3452 SYMBOL_VALUE (sym) = value;
3453 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3454 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
3455 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
3456 TYPE_NAME (SYMBOL_TYPE (sym)) =
3457 obsavestring (SYMBOL_NAME (sym),
3458 strlen (SYMBOL_NAME (sym)));
3459 /* C++ vagaries: we may have a type which is derived from
3460 a base type which did not have its name defined when the
3461 derived class was output. We fill in the derived class's
3462 base part member's name here in that case. */
3463 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
3464 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
3465 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
3468 for (i = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)); i > 0; i--)
3469 if (TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) == 0)
3470 TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) =
3471 TYPE_NAME (TYPE_BASECLASS (SYMBOL_TYPE (sym), i));
3474 add_symbol_to_list (sym, &file_symbols);
3478 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3479 SYMBOL_VALUE (sym) = value;
3480 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
3481 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
3482 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
3483 TYPE_NAME (SYMBOL_TYPE (sym))
3485 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
3487 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
3488 ? "struct " : "union ")),
3490 add_symbol_to_list (sym, &file_symbols);
3495 /* Static symbol of local scope */
3496 SYMBOL_CLASS (sym) = LOC_STATIC;
3497 SYMBOL_VALUE (sym) = value;
3498 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3499 add_symbol_to_list (sym, &local_symbols);
3503 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
3508 /* Read a number by which a type is referred to in dbx data,
3509 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
3510 Just a single number N is equivalent to (0,N).
3511 Return the two numbers by storing them in the vector TYPENUMS.
3512 TYPENUMS will then be used as an argument to dbx_lookup_type. */
3515 read_type_number (pp, typenums)
3517 register int *typenums;
3522 typenums[0] = read_number (pp, ',');
3523 typenums[1] = read_number (pp, ')');
3528 typenums[1] = read_number (pp, 0);
3532 /* Read a dbx type reference or definition;
3533 return the type that is meant.
3534 This can be just a number, in which case it references
3535 a type already defined and placed in type_vector.
3536 Or the number can be followed by an =, in which case
3537 it means to define a new type according to the text that
3545 register struct type *type = 0;
3551 read_type_number (pp, typenums);
3553 /* Detect random reference to type not yet defined.
3554 Allocate a type object but leave it zeroed. */
3556 return dbx_alloc_type (typenums);
3562 type = dbx_alloc_type (typenums);
3563 /* Set the type code according to the following letter. */
3567 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3570 TYPE_CODE (type) = TYPE_CODE_UNION;
3573 TYPE_CODE (type) = TYPE_CODE_ENUM;
3576 /* Skip the name the cross-ref points to. */
3577 /* Note: for C++, the cross reference may be to a base type which
3578 has not yet been seen. In this case, we skip to the comma,
3579 which will mark the end of the base class name. (The ':'
3580 at the end of the base class name will be skipped as well.) */
3581 *pp = (char *) index (*pp, ',');
3582 /* Just allocate the type and leave it zero if nothing known */
3583 return dbx_alloc_type (typenums);
3597 read_type_number (pp, xtypenums);
3598 type = *dbx_lookup_type (xtypenums);
3600 type = builtin_type_void;
3601 *dbx_lookup_type (typenums) = type;
3605 type1 = read_type (pp);
3606 if (TYPE_POINTER_TYPE (type1))
3608 type = TYPE_POINTER_TYPE (type1);
3609 *dbx_lookup_type (typenums) = type;
3613 type = dbx_alloc_type (typenums);
3614 smash_to_pointer_type (type, type1);
3620 struct type *domain = read_type (pp);
3622 struct type *memtype;
3624 if (*(*pp)++ != ',')
3625 error ("invalid member type data format, at symtab pos %d.",
3628 memtype = read_type (pp);
3629 type = dbx_alloc_type (typenums);
3630 smash_to_member_type (type, domain, memtype);
3635 type1 = read_type (pp);
3636 if (TYPE_REFERENCE_TYPE (type1))
3638 type = TYPE_REFERENCE_TYPE (type1);
3639 *dbx_lookup_type (typenums) = type;
3643 type = dbx_alloc_type (typenums);
3644 smash_to_reference_type (type, type1);
3649 type1 = read_type (pp);
3650 if (TYPE_FUNCTION_TYPE (type1))
3652 type = TYPE_FUNCTION_TYPE (type1);
3653 *dbx_lookup_type (typenums) = type;
3657 type = dbx_alloc_type (typenums);
3658 smash_to_function_type (type, type1);
3663 type = read_range_type (pp, typenums);
3664 *dbx_lookup_type (typenums) = type;
3668 type = dbx_alloc_type (typenums);
3669 type = read_enum_type (pp, type);
3670 *dbx_lookup_type (typenums) = type;
3674 type = dbx_alloc_type (typenums);
3675 type = read_struct_type (pp, type);
3679 type = dbx_alloc_type (typenums);
3680 type = read_struct_type (pp, type);
3681 TYPE_CODE (type) = TYPE_CODE_UNION;
3685 if (*(*pp)++ != 'r')
3686 error ("Invalid symbol data: unrecognized type-code `a%c' %s %d.",
3687 (*pp)[-1], "at symtab position", symnum);
3689 type = dbx_alloc_type (typenums);
3690 type = read_array_type (pp, type);
3694 /* Format of an array type:
3695 "ar<index type>;lower;upper;<array_contents_type>". Put code
3696 in to handle this. */
3698 /* dbx expresses array types in terms of a range type for the index,
3699 and that range type is specified right inside the array type spec
3700 making ar1;MIN;MAX;VALTYPE */
3701 if (!strncmp (*pp, "r1;0;", 5))
3703 else if (!strncmp (*pp, "r(0,1);0;", 9))
3707 TYPE_CODE (type) = TYPE_CODE_ARRAY;
3708 /* In Fortran, an upper bound may be T... meaning a parameter specifies
3709 the length of the data. In this case, just pretend the bound is 1.
3710 This happens only for array parameters, which are really passed
3711 as pointers anyway, and we will translate them into such. */
3719 n = read_number (pp, ';') + 1;
3720 TYPE_TARGET_TYPE (type) = read_type (pp);
3721 TYPE_LENGTH (type) = TYPE_LENGTH (TYPE_TARGET_TYPE (type)) * n;
3726 error ("Invalid symbol data: unrecognized type-code `%c' at symtab pos %d.",
3734 /* If this is an overriding temporary alteration for a header file's
3735 contents, and this type number is unknown in the global definition,
3736 put this type into the global definition at this type number. */
3737 if (header_file_prev_index >= 0)
3739 register struct type **tp
3740 = explicit_lookup_type (header_file_prev_index, typenums[1]);
3748 /* This page contains subroutines of read_type. */
3750 /* Read the description of a structure (or union type)
3751 and return an object describing the type. */
3753 static struct type *
3754 read_struct_type (pp, type)
3756 register struct type *type;
3760 struct nextfield *next;
3767 struct next_fnfield *next;
3769 struct fn_field fn_field;
3772 struct next_fnfieldlist
3774 struct next_fnfieldlist *next;
3775 struct fn_fieldlist fn_fieldlist;
3778 register struct nextfield *list = 0;
3779 struct nextfield *new;
3786 register struct next_fnfieldlist *mainlist = 0;
3788 struct type *baseclass = NULL;
3789 int read_possible_virtual_info = 0;
3791 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3793 /* First comes the total size in bytes. */
3795 TYPE_LENGTH (type) = read_number (pp, 0);
3797 /* C++: Now, if the class is a derived class, then the next character
3798 will be a '!', followed by the number of base classes derived from.
3799 Each element in the list contains visibility information,
3800 the offset of this base class in the derived structure,
3801 and then the base type. */
3804 int i, n_baseclasses, offset;
3805 struct type **baseclass_vec;
3806 struct type *baseclass;
3807 int via_public, via_virtual;
3811 n_baseclasses = read_number (pp, ',');
3812 baseclass_vec = (struct type **)
3813 obstack_alloc (symbol_obstack,
3814 (n_baseclasses) * sizeof (struct type **)) - 1;
3816 for (i = 1; i <= n_baseclasses; i++)
3819 *pp = next_symbol_text ();
3830 error ("Invalid symbol data: bad visibility format at symtab pos %d",
3843 error ("Invalid symbol data: bad visibility format at symtab pos %d.",
3846 offset = read_number (pp, ',');
3847 baseclass = read_type (pp);
3848 *pp += 1; /* skip trailing ';' */
3849 baseclass_vec[i] = lookup_basetype_type (baseclass, offset, via_virtual, via_public);
3851 /* Make this baseclass visible for structure-printing purposes. */
3852 new = (struct nextfield *) alloca (sizeof (struct nextfield));
3855 list->field.type = baseclass_vec[i];
3856 list->field.name = TYPE_NAME (baseclass_vec[i]);
3857 list->field.bitpos = offset;
3858 list->field.bitsize = 0; /* this should be an unpacked field! */
3861 TYPE_N_BASECLASSES (type) = n_baseclasses;
3862 TYPE_BASECLASSES (type) = baseclass_vec;
3865 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
3866 At the end, we see a semicolon instead of a field.
3868 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3871 The `?' is a placeholder for one of '+' (public visibility),
3872 '0' (protected visibility), and '-' (private visibility). */
3878 /* Check for and handle cretinous dbx symbol name continuation! */
3879 if (**pp == '\\') *pp = next_symbol_text ();
3881 /* Get space to record the next field's data. */
3882 new = (struct nextfield *) alloca (sizeof (struct nextfield));
3886 /* Read the data. */
3888 while (*p != ':') p++;
3889 list->field.name = obsavestring (*pp, p - *pp);
3891 /* C++: Check to see if we have hit the methods yet. */
3897 /* This means we have a visibility for a field coming. */
3918 /* else normal dbx-style format. */
3920 list->field.type = read_type (pp);
3923 list->field.bitpos = (long)-1;
3925 while (*p != ';') p++;
3926 list->field.bitsize = (long) savestring (*pp, p - *pp);
3931 else if (**pp != ',')
3932 error ("Invalid symbol data: bad structure-type format at symtab pos %d.",
3934 (*pp)++; /* Skip the comma. */
3935 list->field.bitpos = read_number (pp, ',');
3936 list->field.bitsize = read_number (pp, ';');
3937 /* Detect an unpacked field and mark it as such.
3938 dbx gives a bit size for all fields.
3939 Note that forward refs cannot be packed,
3940 and treat enums as if they had the width of ints. */
3941 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
3942 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
3943 list->field.bitsize = 0;
3944 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
3945 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
3946 && list->field.bitsize == 8 * TYPE_LENGTH (builtin_type_int)))
3948 list->field.bitpos % 8 == 0)
3949 list->field.bitsize = 0;
3953 /* Now come the method fields, as NAME::methods
3954 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
3955 At the end, we see a semicolon instead of a field.
3957 For the case of overloaded operators, the format is
3958 OPERATOR::*.methods, where OPERATOR is the string "operator",
3959 `*' holds the place for an operator name (such as `+=')
3960 and `.' marks the end of the operator name. */
3963 /* Now, read in the methods. To simplify matters, we
3964 "unread" the name that has been read, so that we can
3965 start from the top. */
3969 /* chill the list of fields: the last entry (at the head)
3970 is a partially constructed entry which we now scrub. */
3973 /* For each list of method lists... */
3977 struct next_fnfield *sublist = 0;
3978 struct fn_field *fn_fields = 0;
3980 struct next_fnfieldlist *new_mainlist =
3981 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
3983 /* read in the name. */
3984 while (*p != ':') p++;
3985 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == '$')
3987 static char opname[32] = "operator ";
3988 char *o = opname + 9;
3990 /* Skip past '::'. */
3994 new_mainlist->fn_fieldlist.name = savestring (opname, o - opname);
4001 new_mainlist->fn_fieldlist.name = savestring (*pp, p - *pp);
4002 /* Skip past '::'. */
4008 struct next_fnfield *new_sublist =
4009 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
4011 /* Check for and handle cretinous dbx symbol name continuation! */
4012 if (**pp == '\\') *pp = next_symbol_text ();
4014 new_sublist->fn_field.type = read_type (pp);
4015 new_sublist->fn_field.args = read_args (pp, ':');
4017 while (*p != ';') p++;
4018 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
4020 new_sublist->visibility = *(*pp)++ - '0';
4021 if (**pp == '\\') *pp = next_symbol_text ();
4023 if (*(*pp)++ == '*')
4024 new_sublist->fn_field.voffset = read_number (pp, ';') + 1;
4026 new_sublist->fn_field.voffset = 0;
4028 new_sublist->next = sublist;
4029 sublist = new_sublist;
4032 while (**pp != ';');
4036 new_mainlist->fn_fieldlist.fn_fields =
4037 (struct fn_field *) obstack_alloc (symbol_obstack,
4038 sizeof (struct fn_field) * length);
4039 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
4040 (int *) obstack_alloc (symbol_obstack,
4041 sizeof (int) * (1 + (length >> 5)));
4043 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
4044 (int *) obstack_alloc (symbol_obstack,
4045 sizeof (int) * (1 + (length >> 5)));
4047 for (i = length; sublist; sublist = sublist->next)
4049 new_mainlist->fn_fieldlist.fn_fields[--i] = sublist->fn_field;
4050 if (sublist->visibility == 0)
4051 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
4052 else if (sublist->visibility == 1)
4053 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
4056 new_mainlist->fn_fieldlist.length = length;
4057 new_mainlist->next = mainlist;
4058 mainlist = new_mainlist;
4061 while (**pp != ';');
4066 /* Now create the vector of fields, and record how big it is. */
4068 TYPE_NFIELDS (type) = nfields;
4069 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
4070 sizeof (struct field) * nfields);
4071 TYPE_FIELD_PRIVATE_BITS (type) =
4072 (int *) obstack_alloc (symbol_obstack,
4073 sizeof (int) * (1 + (nfields >> 5)));
4074 TYPE_FIELD_PROTECTED_BITS (type) =
4075 (int *) obstack_alloc (symbol_obstack,
4076 sizeof (int) * (1 + (nfields >> 5)));
4078 TYPE_NFN_FIELDS (type) = nfn_fields;
4079 TYPE_NFN_FIELDS_TOTAL (type) = nfn_fields;
4081 TYPE_NFN_FIELDS_TOTAL (type) += TYPE_NFN_FIELDS_TOTAL (baseclass);
4083 TYPE_FN_FIELDLISTS (type) =
4084 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
4085 sizeof (struct fn_fieldlist) * nfn_fields);
4087 /* Copy the saved-up fields into the field vector. */
4089 for (n = nfields; list; list = list->next)
4091 TYPE_FIELD (type, --n) = list->field;
4092 if (list->visibility == 0)
4093 SET_TYPE_FIELD_PRIVATE (type, n);
4094 else if (list->visibility == 1)
4095 SET_TYPE_FIELD_PROTECTED (type, n);
4098 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
4099 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
4108 |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
4111 else if (**pp == '+')
4113 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
4116 else if (**pp == '-')
4118 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
4122 /* Read either a '%' or the final ';'. */
4123 if (*(*pp)++ == '%')
4125 /* Now we must record the virtual function table pointer's
4126 field information. */
4133 while (*p != ';') p++;
4134 TYPE_VPTR_BASETYPE (type) = t;
4137 if (TYPE_FIELD_NAME (t, 0) == 0)
4138 TYPE_VPTR_FIELDNO (type) = i = 0;
4139 else for (i = TYPE_NFIELDS (t) - 1; i >= 0; --i)
4140 if (! strncmp (TYPE_FIELD_NAME (t, i), *pp,
4141 strlen (TYPE_FIELD_NAME (t, i))))
4143 TYPE_VPTR_FIELDNO (type) = i;
4147 error ("virtual function table field not found");
4150 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, 1));
4155 TYPE_VPTR_BASETYPE (type) = 0;
4156 TYPE_VPTR_FIELDNO (type) = -1;
4161 TYPE_VPTR_BASETYPE (type) = 0;
4162 TYPE_VPTR_FIELDNO (type) = -1;
4168 /* Read a definition of an enumberation type,
4169 and create and return a suitable type object.
4170 Also creates a range type which represents the bounds of that
4172 static struct type *
4173 read_array_type (pp, type)
4175 register struct type *type;
4177 struct type *index_type, *element_type, *range_type;
4180 /* Format of an array type:
4181 "ar<index type>;lower;upper;<array_contents_type>". Put code in
4184 index_type = read_type (pp);
4185 if (*(*pp)++ != ';')
4186 error ("Invalid symbol data; improper format of array type decl.");
4187 lower = read_number (pp, ';');
4188 upper = read_number (pp, ';');
4189 element_type = read_type (pp);
4192 /* Create range type. */
4193 range_type = (struct type *) obstack_alloc (symbol_obstack,
4194 sizeof (struct type));
4195 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
4196 TYPE_TARGET_TYPE (range_type) = index_type;
4198 /* This should never be needed. */
4199 TYPE_LENGTH (range_type) = sizeof (int);
4201 TYPE_NFIELDS (range_type) = 2;
4202 TYPE_FIELDS (range_type) =
4203 (struct field *) obstack_alloc (symbol_obstack,
4204 2 * sizeof (struct field));
4205 TYPE_FIELD_BITPOS (range_type, 0) = lower;
4206 TYPE_FIELD_BITPOS (range_type, 1) = upper;
4209 TYPE_CODE (type) = TYPE_CODE_ARRAY;
4210 TYPE_TARGET_TYPE (type) = element_type;
4211 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
4212 TYPE_NFIELDS (type) = 1;
4213 TYPE_FIELDS (type) =
4214 (struct field *) obstack_alloc (symbol_obstack,
4215 sizeof (struct field));
4216 TYPE_FIELD_TYPE (type, 0) = range_type;
4222 /* Read a definition of an enumeration type,
4223 and create and return a suitable type object.
4224 Also defines the symbols that represent the values of the type. */
4226 static struct type *
4227 read_enum_type (pp, type)
4229 register struct type *type;
4234 register struct symbol *sym;
4236 struct pending **symlist;
4237 struct pending *osyms, *syms;
4240 if (within_function)
4241 symlist = &local_symbols;
4243 symlist = &file_symbols;
4245 o_nsyms = osyms ? osyms->nsyms : 0;
4247 /* Read the value-names and their values.
4248 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4249 A semicolon instead of a NAME means the end. */
4250 while (**pp && **pp != ';')
4252 /* Check for and handle cretinous dbx symbol name continuation! */
4253 if (**pp == '\\') *pp = next_symbol_text ();
4256 while (*p != ':') p++;
4257 name = obsavestring (*pp, p - *pp);
4259 n = read_number (pp, ',');
4261 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
4262 bzero (sym, sizeof (struct symbol));
4263 SYMBOL_NAME (sym) = name;
4264 SYMBOL_CLASS (sym) = LOC_CONST;
4265 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4266 SYMBOL_VALUE (sym) = n;
4267 add_symbol_to_list (sym, symlist);
4271 (*pp)++; /* Skip the semicolon. */
4273 /* Now fill in the fields of the type-structure. */
4275 TYPE_LENGTH (type) = sizeof (int);
4276 TYPE_CODE (type) = TYPE_CODE_ENUM;
4277 TYPE_NFIELDS (type) = nsyms;
4278 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
4280 /* Find the symbols for the values and put them into the type.
4281 The symbols can be found in the symlist that we put them on
4282 to cause them to be defined. osyms contains the old value
4283 of that symlist; everything up to there was defined by us. */
4285 for (syms = *symlist, n = nsyms; syms; syms = syms->next)
4290 for (; j < syms->nsyms; j++)
4292 struct symbol *sym = syms->symbol[j];
4293 SYMBOL_TYPE (sym) = type;
4294 TYPE_FIELD_NAME (type, --n) = SYMBOL_NAME (sym);
4295 TYPE_FIELD_VALUE (type, n) = 0;
4296 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (sym);
4297 TYPE_FIELD_BITSIZE (type, n) = 0;
4306 #define MAX_OF_TYPE(t) ((1 << (sizeof (t) - 1)) - 1)
4307 #define MIN_OF_TYPE(t) (-(1 << (sizeof (t) - 1)))
4309 static struct type *
4310 read_range_type (pp, typenums)
4318 struct type *result_type;
4320 /* First comes a type we are a subrange of.
4321 In C it is usually 0, 1 or the type being defined. */
4322 read_type_number (pp, rangenums);
4323 self_subrange = (rangenums[0] == typenums[0] &&
4324 rangenums[1] == typenums[1]);
4326 /* A semicolon should now follow; skip it. */
4330 /* The remaining two operands are usually lower and upper bounds
4331 of the range. But in some special cases they mean something else. */
4332 n2 = read_number (pp, ';');
4333 n3 = read_number (pp, ';');
4335 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4336 if (self_subrange && n2 == 0 && n3 == 0)
4337 return builtin_type_void;
4339 /* If n3 is zero and n2 is not, we want a floating type,
4340 and n2 is the width in bytes.
4342 Fortran programs appear to use this for complex types also,
4343 and they give no way to distinguish between double and single-complex!
4344 We don't have complex types, so we would lose on all fortran files!
4345 So return type `double' for all of those. It won't work right
4346 for the complex values, but at least it makes the file loadable. */
4348 if (n3 == 0 && n2 > 0)
4350 if (n2 == sizeof (float))
4351 return builtin_type_float;
4352 return builtin_type_double;
4355 /* If the upper bound is -1, it must really be an unsigned int. */
4357 else if (n2 == 0 && n3 == -1)
4359 if (sizeof (int) == sizeof (long))
4360 return builtin_type_unsigned_int;
4362 return builtin_type_unsigned_long;
4365 /* Special case: char is defined (Who knows why) as a subrange of
4366 itself with range 0-127. */
4367 else if (self_subrange && n2 == 0 && n3 == 127)
4368 return builtin_type_char;
4370 /* Assumptions made here: Subrange of self is equivalent to subrange
4373 && (self_subrange ||
4374 *dbx_lookup_type (rangenums) == builtin_type_int))
4376 /* an unsigned type */
4377 if (n3 == (1 << (8 * sizeof (int))) - 1)
4378 return builtin_type_unsigned_int;
4379 if (n3 == (1 << (8 * sizeof (short))) - 1)
4380 return builtin_type_unsigned_short;
4381 if (n3 == (1 << (8 * sizeof (char))) - 1)
4382 return builtin_type_unsigned_char;
4384 else if (n2 == -n3 -1)
4387 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
4388 return builtin_type_int;
4389 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
4390 return builtin_type_long;
4391 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
4392 return builtin_type_short;
4393 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
4394 return builtin_type_char;
4397 /* We have a real range type on our hands. Allocate space and
4398 return a real pointer. */
4400 /* At this point I don't have the faintest idea how to deal with
4401 a self_subrange type; I'm going to assume that this is used
4402 as an idiom, and that all of them are special cases. So . . . */
4404 error ("Type defined as subrange of itself.");
4406 result_type = (struct type *) obstack_alloc (symbol_obstack,
4407 sizeof (struct type));
4408 bzero (result_type, sizeof (struct type));
4410 TYPE_TARGET_TYPE (result_type) = (self_subrange ?
4412 *dbx_lookup_type(rangenums));
4414 /* We have to figure out how many bytes it takes to hold this
4415 range type. I'm going to assume that anything that is pushing
4416 the bounds of a long was taken care of above. */
4417 if (n2 >= MIN_OF_TYPE(char) && n3 <= MAX_OF_TYPE(char))
4418 TYPE_LENGTH (result_type) = 1;
4419 else if (n2 >= MIN_OF_TYPE(short) && n3 <= MAX_OF_TYPE(short))
4420 TYPE_LENGTH (result_type) = sizeof (short);
4421 else if (n2 >= MIN_OF_TYPE(int) && n3 <= MAX_OF_TYPE(int))
4422 TYPE_LENGTH (result_type) = sizeof (int);
4423 else if (n2 >= MIN_OF_TYPE(long) && n3 <= MAX_OF_TYPE(long))
4424 TYPE_LENGTH (result_type) = sizeof (long);
4426 error ("Ranged type doesn't fit within known sizes.");
4428 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
4429 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
4430 TYPE_NFIELDS (result_type) = 2;
4431 TYPE_FIELDS (result_type) =
4432 (struct field *) obstack_alloc (symbol_obstack,
4433 2 * sizeof (struct field));
4434 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
4435 TYPE_FIELD_BITPOS (result_type, 0) = n2;
4436 TYPE_FIELD_BITPOS (result_type, 1) = n3;
4441 /* Read a number from the string pointed to by *PP.
4442 The value of *PP is advanced over the number.
4443 If END is nonzero, the character that ends the
4444 number must match END, or an error happens;
4445 and that character is skipped if it does match.
4446 If END is zero, *PP is left pointing to that character. */
4449 read_number (pp, end)
4453 register char *p = *pp;
4454 register long n = 0;
4458 /* Handle an optional leading minus sign. */
4466 /* Read the digits, as far as they go. */
4468 while ((c = *p++) >= '0' && c <= '9')
4476 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
4485 /* Read in an argument list. This is a list of types. It is terminated with
4486 a ':', FYI. Return the list of types read in. */
4487 static struct type **
4492 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
4498 error ("Invalid argument list: no ',', at symtab pos %d", symnum);
4501 /* Check for and handle cretinous dbx symbol name continuation! */
4503 *pp = next_symbol_text ();
4505 types[n++] = read_type (pp);
4507 *pp += 1; /* get past `end' (the ':' character) */
4511 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
4513 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
4515 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
4516 bzero (rval + n, sizeof (struct type *));
4520 rval = (struct type **) xmalloc (n * sizeof (struct type *));
4522 bcopy (types, rval, n * sizeof (struct type *));
4526 /* This function is really horrible, but to avoid it, there would need
4527 to be more filling in of forward references. THIS SHOULD BE MOVED OUT
4528 OF COFFREAD.C AND DBXREAD.C TO SOME PLACE WHERE IT CAN BE SHARED */
4530 fill_in_vptr_fieldno (type)
4533 if (TYPE_VPTR_FIELDNO (type) < 0)
4534 TYPE_VPTR_FIELDNO (type) =
4535 fill_in_vptr_fieldno (TYPE_BASECLASS (type, 1));
4536 return TYPE_VPTR_FIELDNO (type);
4540 _initialize_dbxread ()
4543 header_files = (struct header_file *) 0;
4544 this_object_header_files = (int *) 0;
4546 add_com ("symbol-file", class_files, symbol_file_command,
4547 "Load symbol table (in dbx format) from executable file FILE.");
4549 add_com ("add-file", class_files, add_file_command,
4550 "Load the symbols from FILE, assuming its code is at TEXT_START.") ;
4553 #endif /* READ_DBX_FORMAT */