1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GDB is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Symbol read-in occurs in two phases:
21 1. A scan (read_dbx_symtab()) of the entire executable, whose sole
22 purpose is to make a list of symbols (partial symbol table)
23 which will cause symbols
24 to be read in if referenced. This scan happens when the
25 "symbol-file" command is given (symbol_file_command()).
26 2. Full read-in of symbols. (psymtab_to_symtab()). This happens
27 when a symbol in a file for which symbols have not yet been
28 read in is referenced.
29 2a. The "add-file" command. Similar to #2. */
34 #ifdef READ_DBX_FORMAT
37 #include <sys/types.h>
43 #ifdef COFF_ENCAPSULATE
44 #include "a.out.encap.h"
54 * Define specifically gnu symbols here.
57 /* The following type indicates the definition of a symbol as being
58 an indirect reference to another symbol. The other symbol
59 appears as an undefined reference, immediately following this symbol.
61 Indirection is asymmetrical. The other symbol's value will be used
62 to satisfy requests for the indirect symbol, but not vice versa.
63 If the other symbol does not have a definition, libraries will
64 be searched to find a definition. */
69 /* The following symbols refer to set elements.
70 All the N_SET[ATDB] symbols with the same name form one set.
71 Space is allocated for the set in the text section, and each set
72 element's value is stored into one word of the space.
73 The first word of the space is the length of the set (number of elements).
75 The address of the set is made into an N_SETV symbol
76 whose name is the same as the name of the set.
77 This symbol acts like a N_DATA global symbol
78 in that it can satisfy undefined external references. */
81 #define N_SETA 0x14 /* Absolute set element symbol */
82 #endif /* This is input to LD, in a .o file. */
85 #define N_SETT 0x16 /* Text set element symbol */
86 #endif /* This is input to LD, in a .o file. */
89 #define N_SETD 0x18 /* Data set element symbol */
90 #endif /* This is input to LD, in a .o file. */
93 #define N_SETB 0x1A /* Bss set element symbol */
94 #endif /* This is input to LD, in a .o file. */
96 /* Macros dealing with the set element symbols defined in a.out.h */
97 #define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
98 #define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS)
101 #define N_SETV 0x1C /* Pointer to set vector in data area. */
102 #endif /* This is output from LD. */
105 #define N_WARNING 0x1E /* Warning message to print if file included */
106 #endif /* This is input to ld */
110 /* Line number for the data section. This is to be used to describe
111 the source location of a variable declaration. */
113 #define N_DSLINE (N_SLINE+N_DATA-N_TEXT)
116 /* Line number for the bss section. This is to be used to describe
117 the source location of a variable declaration. */
119 #define N_BSLINE (N_SLINE+N_BSS-N_TEXT)
122 #endif /* not __GNU_STAB__ */
123 #endif /* NO_GNU_STABS */
126 #include <sys/param.h>
127 #include <sys/file.h>
128 #include <sys/stat.h>
134 #define AOUTHDR struct exec
138 static void add_symbol_to_list ();
139 static void read_dbx_symtab ();
140 static void process_one_symbol ();
141 static void free_all_psymbols ();
142 static struct type *read_type ();
143 static struct type *read_range_type ();
144 static struct type *read_enum_type ();
145 static struct type *read_struct_type ();
146 static struct type *read_array_type ();
147 static long read_number ();
148 static void finish_block ();
149 static struct blockvector *make_blockvector ();
150 static struct symbol *define_symbol ();
151 static void start_subfile ();
152 static int hashname ();
153 static void hash_symsegs ();
154 static struct pending *copy_pending ();
155 static void fix_common_block ();
157 static void add_undefined_type ();
158 static void cleanup_undefined_types ();
160 extern char *index();
162 extern struct symtab *read_symsegs ();
163 extern void free_all_symtabs ();
164 extern void free_all_psymtabs ();
165 extern void free_inclink_symtabs ();
168 static struct type **read_args ();
170 /* Macro to determine which symbols to ignore when reading the first symbol
171 of a file. Some machines override this definition. */
173 #ifndef IGNORE_SYMBOL
174 /* This code is used on Ultrix systems. Ignore it */
175 #define IGNORE_SYMBOL(type) (type == N_NSYMS)
178 #ifndef IGNORE_SYMBOL
179 /* Don't ignore any symbols. */
180 #define IGNORE_SYMBOL(type) (0)
182 #endif /* not N_NSYMS */
184 /* Macro for number of symbol table entries (in usual a.out format).
185 Some machines override this definition. */
186 #ifndef NUMBER_OF_SYMBOLS
188 #define NUMBER_OF_SYMBOLS \
189 ((COFF_HEADER(hdr) ? hdr.coffhdr.filehdr.f_nsyms : hdr.a_syms) / \
190 sizeof (struct nlist))
192 #define NUMBER_OF_SYMBOLS (hdr.a_syms / sizeof (struct nlist))
196 /* Macro for file-offset of symbol table (in usual a.out format). */
197 #ifndef SYMBOL_TABLE_OFFSET
198 #define SYMBOL_TABLE_OFFSET N_SYMOFF (hdr)
201 /* Macro for file-offset of string table (in usual a.out format). */
202 #ifndef STRING_TABLE_OFFSET
203 #define STRING_TABLE_OFFSET (N_SYMOFF (hdr) + hdr.a_syms)
206 /* Macro to store the length of the string table data in INTO. */
207 #ifndef READ_STRING_TABLE_SIZE
208 #define READ_STRING_TABLE_SIZE(INTO) \
209 { val = myread (desc, &INTO, sizeof INTO); \
210 if (val < 0) perror_with_name (name); }
213 /* Macro to declare variables to hold the file's header data. */
214 #ifndef DECLARE_FILE_HEADERS
215 #define DECLARE_FILE_HEADERS AOUTHDR hdr
218 /* Macro to read the header data from descriptor DESC and validate it.
219 NAME is the file name, for error messages. */
220 #ifndef READ_FILE_HEADERS
221 #ifdef HEADER_SEEK_FD
222 #define READ_FILE_HEADERS(DESC, NAME) \
223 { HEADER_SEEK_FD (DESC); \
224 val = myread (DESC, &hdr, sizeof hdr); \
225 if (val < 0) perror_with_name (NAME); \
226 if (N_BADMAG (hdr)) \
227 error ("File \"%s\" not in executable format.", NAME); }
229 #define READ_FILE_HEADERS(DESC, NAME) \
230 { val = myread (DESC, &hdr, sizeof hdr); \
231 if (val < 0) perror_with_name (NAME); \
232 if (N_BADMAG (hdr)) \
233 error ("File \"%s\" not in executable format.", NAME); }
237 /* Non-zero if this is an object (.o) file, rather than an executable.
238 Distinguishing between the two is rarely necessary (and seems like
239 a hack, but there is no other way to do ADDR_OF_TEXT_SEGMENT
241 #if !defined (IS_OBJECT_FILE)
242 /* This will not work
243 if someone decides to make ld preserve relocation info. */
244 #define IS_OBJECT_FILE (hdr.a_trsize != 0)
247 /* Macro for size of text segment */
248 #ifndef SIZE_OF_TEXT_SEGMENT
249 #define SIZE_OF_TEXT_SEGMENT hdr.a_text
252 /* Get the address in debugged memory of the start
253 of the text segment. */
254 #if !defined (ADDR_OF_TEXT_SEGMENT)
255 #if defined (N_TXTADDR)
256 #define ADDR_OF_TEXT_SEGMENT (IS_OBJECT_FILE ? 0 : N_TXTADDR (hdr))
257 #else /* no N_TXTADDR */
258 #define ADDR_OF_TEXT_SEGMENT 0
259 #endif /* no N_TXTADDR */
260 #endif /* no ADDR_OF_TEXT_SEGMENT */
262 /* Macro to get entry point from headers. */
264 #define ENTRY_POINT hdr.a_entry
267 /* Macro for name of symbol to indicate a file compiled with gcc. */
268 #ifndef GCC_COMPILED_FLAG_SYMBOL
269 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
272 /* Convert stab register number (from `r' declaration) to a gdb REGNUM. */
274 #ifndef STAB_REG_TO_REGNUM
275 #define STAB_REG_TO_REGNUM(VALUE) (VALUE)
278 /* Define this as 1 if a pcc declaration of a char or short argument
279 gives the correct address. Otherwise assume pcc gives the
280 address of the corresponding int, which is not the same on a
281 big-endian machine. */
283 #ifndef BELIEVE_PCC_PROMOTION
284 #define BELIEVE_PCC_PROMOTION 0
287 /* Nonzero means give verbose info on gdb action. From main.c. */
288 extern int info_verbose;
290 /* Chain of symtabs made from reading the file's symsegs.
291 These symtabs do not go into symtab_list themselves,
292 but the information is copied from them when appropriate
293 to make the symtabs that will exist permanently. */
295 static struct symtab *symseg_chain;
297 /* Symseg symbol table for the file whose data we are now processing.
298 It is one of those in symseg_chain. Or 0, for a compilation that
301 static struct symtab *current_symseg;
303 /* Name of source file whose symbol data we are now processing.
304 This comes from a symbol of type N_SO. */
306 static char *last_source_file;
308 /* Core address of start of text of current source file.
309 This too comes from the N_SO symbol. */
311 static CORE_ADDR last_source_start_addr;
313 /* End of the text segment of the executable file,
314 as found in the symbol _etext. */
316 static CORE_ADDR end_of_text_addr;
318 /* The list of sub-source-files within the current individual compilation.
319 Each file gets its own symtab with its own linetable and associated info,
320 but they all share one blockvector. */
324 struct subfile *next;
326 struct linetable *line_vector;
327 int line_vector_length;
328 int line_vector_index;
329 int prev_line_number;
332 static struct subfile *subfiles;
334 static struct subfile *current_subfile;
336 /* Count symbols as they are processed, for error messages. */
340 /* Vector of types defined so far, indexed by their dbx type numbers.
341 (In newer sun systems, dbx uses a pair of numbers in parens,
342 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
343 translated through the type_translations hash table to get
344 the index into the type vector.) */
346 static struct typevector *type_vector;
348 /* Number of elements allocated for type_vector currently. */
350 static int type_vector_length;
352 /* Vector of line number information. */
354 static struct linetable *line_vector;
356 /* Index of next entry to go in line_vector_index. */
358 static int line_vector_index;
360 /* Last line number recorded in the line vector. */
362 static int prev_line_number;
364 /* Number of elements allocated for line_vector currently. */
366 static int line_vector_length;
368 /* Hash table of global symbols whose values are not known yet.
369 They are chained thru the SYMBOL_VALUE, since we don't
370 have the correct data for that slot yet. */
371 /* The use of the LOC_BLOCK code in this chain is nonstandard--
372 it refers to a FORTRAN common block rather than the usual meaning. */
375 static struct symbol *global_sym_chain[HASHSIZE];
377 /* Record the symbols defined for each context in a list.
378 We don't create a struct block for the context until we
379 know how long to make it. */
381 #define PENDINGSIZE 100
385 struct pending *next;
387 struct symbol *symbol[PENDINGSIZE];
390 /* List of free `struct pending' structures for reuse. */
391 struct pending *free_pendings;
393 /* Here are the three lists that symbols are put on. */
395 struct pending *file_symbols; /* static at top level, and types */
397 struct pending *global_symbols; /* global functions and variables */
399 struct pending *local_symbols; /* everything local to lexical context */
401 /* List of symbols declared since the last BCOMM. This list is a tail
402 of local_symbols. When ECOMM is seen, the symbols on the list
403 are noted so their proper addresses can be filled in later,
404 using the common block base address gotten from the assembler
407 struct pending *common_block;
410 /* Stack representing unclosed lexical contexts
411 (that will become blocks, eventually). */
415 struct pending *locals;
416 struct pending_block *old_blocks;
418 CORE_ADDR start_addr;
422 struct context_stack *context_stack;
424 /* Index of first unused entry in context stack. */
425 int context_stack_depth;
427 /* Currently allocated size of context stack. */
429 int context_stack_size;
431 /* Nonzero if within a function (so symbols should be local,
432 if nothing says specifically). */
436 /* List of blocks already made (lexical contexts already closed).
437 This is used at the end to make the blockvector. */
441 struct pending_block *next;
445 struct pending_block *pending_blocks;
447 extern CORE_ADDR startup_file_start; /* From blockframe.c */
448 extern CORE_ADDR startup_file_end; /* From blockframe.c */
450 /* File name symbols were loaded from. */
452 static char *symfile;
454 /* Low and high symbol values (inclusive) for the global variable
455 entries in the symbol file. */
457 static int first_global_sym, last_global_sym;
459 /* Structures with which to manage partial symbol allocation. */
461 struct psymbol_allocation_list global_psymbols, static_psymbols;
463 /* Global variable which, when set, indicates that we are processing a
464 .o file compiled with gcc */
466 static unsigned char processing_gcc_compilation;
468 /* Make a list of forward references which haven't been defined. */
469 static struct type **undef_types;
470 static int undef_types_allocated, undef_types_length;
472 /* Setup a define to deal cleanly with the underscore problem */
474 #ifdef NAMES_HAVE_UNDERSCORE
475 #define HASH_OFFSET 1
477 #define HASH_OFFSET 0
481 /* I'm not sure why this is here. To debug bugs which cause
482 an infinite loop of allocations, I suppose. In any event,
483 dumping core when out of memory isn't usually right. */
490 fprintf (stderr, "Virtual memory exhausted.\n");
496 #define xxmalloc xmalloc
499 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
500 (and add a null character at the end in the copy).
501 Returns the address of the copy. */
504 obsavestring (ptr, size)
508 register char *p = (char *) obstack_alloc (symbol_obstack, size + 1);
509 /* Open-coded bcopy--saves function call time.
510 These strings are usually short. */
512 register char *p1 = ptr;
513 register char *p2 = p;
514 char *end = ptr + size;
522 /* Concatenate strings S1, S2 and S3; return the new string.
523 Space is found in the symbol_obstack. */
526 obconcat (s1, s2, s3)
529 register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
530 register char *val = (char *) obstack_alloc (symbol_obstack, len);
537 /* Support for Sun changes to dbx symbol format */
539 /* For each identified header file, we have a table of types defined
542 header_files maps header file names to their type tables.
543 It is a vector of n_header_files elements.
544 Each element describes one header file.
545 It contains a vector of types.
547 Sometimes it can happen that the same header file produces
548 different results when included in different places.
549 This can result from conditionals or from different
550 things done before including the file.
551 When this happens, there are multiple entries for the file in this table,
552 one entry for each distinct set of results.
553 The entries are distinguished by the INSTANCE field.
554 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
555 used to match header-file references to their corresponding data. */
559 char *name; /* Name of header file */
560 int instance; /* Numeric code distinguishing instances
561 of one header file that produced
562 different results when included.
563 It comes from the N_BINCL or N_EXCL. */
564 struct type **vector; /* Pointer to vector of types */
565 int length; /* Allocated length (# elts) of that vector */
568 static struct header_file *header_files;
570 static int n_header_files;
572 static int n_allocated_header_files;
574 /* During initial symbol readin, we need to have a structure to keep
575 track of which psymtabs have which bincls in them. This structure
576 is used during readin to setup the list of dependencies within each
577 partial symbol table. */
579 struct header_file_location
581 char *name; /* Name of header file */
582 int instance; /* See above */
583 struct partial_symtab *pst; /* Partial symtab that has the
584 BINCL/EINCL defs for this file */
587 /* The actual list and controling variables */
588 static struct header_file_location *bincl_list, *next_bincl;
589 static int bincls_allocated;
591 /* Within each object file, various header files are assigned numbers.
592 A type is defined or referred to with a pair of numbers
593 (FILENUM,TYPENUM) where FILENUM is the number of the header file
594 and TYPENUM is the number within that header file.
595 TYPENUM is the index within the vector of types for that header file.
597 FILENUM == 1 is special; it refers to the main source of the object file,
598 and not to any header file. FILENUM != 1 is interpreted by looking it up
599 in the following table, which contains indices in header_files. */
601 static int *this_object_header_files;
603 static int n_this_object_header_files;
605 static int n_allocated_this_object_header_files;
607 /* When a header file is getting special overriding definitions
608 for one source file, record here the header_files index
609 of its normal definition vector.
610 At other times, this is -1. */
612 static int header_file_prev_index;
614 /* At the start of reading dbx symbols, allocate our tables. */
619 n_allocated_header_files = 10;
620 header_files = (struct header_file *) xxmalloc (10 * sizeof (struct header_file));
623 n_allocated_this_object_header_files = 10;
624 this_object_header_files = (int *) xxmalloc (10 * sizeof (int));
627 /* At the end of reading dbx symbols, free our tables. */
633 for (i = 0; i < n_header_files; i++)
634 free (header_files[i].name);
635 if (header_files) free (header_files);
636 if (this_object_header_files)
637 free (this_object_header_files);
640 /* Called at the start of each object file's symbols.
641 Clear out the mapping of header file numbers to header files. */
644 new_object_header_files ()
646 /* Leave FILENUM of 0 free for builtin types and this file's types. */
647 n_this_object_header_files = 1;
648 header_file_prev_index = -1;
651 /* Add header file number I for this object file
652 at the next successive FILENUM. */
655 add_this_object_header_file (i)
658 if (n_this_object_header_files == n_allocated_this_object_header_files)
660 n_allocated_this_object_header_files *= 2;
661 this_object_header_files
662 = (int *) xrealloc (this_object_header_files,
663 n_allocated_this_object_header_files * sizeof (int));
666 this_object_header_files[n_this_object_header_files++] = i;
669 /* Add to this file an "old" header file, one already seen in
670 a previous object file. NAME is the header file's name.
671 INSTANCE is its instance code, to select among multiple
672 symbol tables for the same header file. */
675 add_old_header_file (name, instance)
679 register struct header_file *p = header_files;
682 for (i = 0; i < n_header_files; i++)
683 if (!strcmp (p[i].name, name) && instance == p[i].instance)
685 add_this_object_header_file (i);
688 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
692 /* Add to this file a "new" header file: definitions for its types follow.
693 NAME is the header file's name.
694 Most often this happens only once for each distinct header file,
695 but not necessarily. If it happens more than once, INSTANCE has
696 a different value each time, and references to the header file
697 use INSTANCE values to select among them.
699 dbx output contains "begin" and "end" markers for each new header file,
700 but at this level we just need to know which files there have been;
701 so we record the file when its "begin" is seen and ignore the "end". */
704 add_new_header_file (name, instance)
709 register struct header_file *p = header_files;
710 header_file_prev_index = -1;
713 /* This code was used before I knew about the instance codes.
714 My first hypothesis is that it is not necessary now
715 that instance codes are handled. */
717 /* Has this header file a previous definition?
718 If so, make a new entry anyway so that this use in this source file
719 gets a separate entry. Later source files get the old entry.
720 Record here the index of the old entry, so that any type indices
721 not previously defined can get defined in the old entry as
722 well as in the new one. */
724 for (i = 0; i < n_header_files; i++)
725 if (!strcmp (p[i].name, name))
727 header_file_prev_index = i;
732 /* Make sure there is room for one more header file. */
734 if (n_header_files == n_allocated_header_files)
736 n_allocated_header_files *= 2;
737 header_files = (struct header_file *)
738 xrealloc (header_files,
739 (n_allocated_header_files
740 * sizeof (struct header_file)));
743 /* Create an entry for this header file. */
745 i = n_header_files++;
746 header_files[i].name = savestring (name, strlen(name));
747 header_files[i].instance = instance;
748 header_files[i].length = 10;
749 header_files[i].vector
750 = (struct type **) xxmalloc (10 * sizeof (struct type *));
751 bzero (header_files[i].vector, 10 * sizeof (struct type *));
753 add_this_object_header_file (i);
756 /* Look up a dbx type-number pair. Return the address of the slot
757 where the type for that number-pair is stored.
758 The number-pair is in TYPENUMS.
760 This can be used for finding the type associated with that pair
761 or for associating a new type with the pair. */
763 static struct type **
764 dbx_lookup_type (typenums)
767 register int filenum = typenums[0], index = typenums[1];
769 if (filenum < 0 || filenum >= n_this_object_header_files)
770 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
771 filenum, index, symnum);
775 /* Type is defined outside of header files.
776 Find it in this object file's type vector. */
777 if (index >= type_vector_length)
779 type_vector_length *= 2;
780 type_vector = (struct typevector *)
781 xrealloc (type_vector,
782 (sizeof (struct typevector)
783 + type_vector_length * sizeof (struct type *)));
784 bzero (&type_vector->type[type_vector_length / 2],
785 type_vector_length * sizeof (struct type *) / 2);
787 return &type_vector->type[index];
791 register int real_filenum = this_object_header_files[filenum];
792 register struct header_file *f;
794 if (real_filenum >= n_header_files)
797 f = &header_files[real_filenum];
799 if (index >= f->length)
802 f->vector = (struct type **)
803 xrealloc (f->vector, f->length * sizeof (struct type *));
804 bzero (&f->vector[f->length / 2],
805 f->length * sizeof (struct type *) / 2);
807 return &f->vector[index];
811 /* Create a type object. Occaisionally used when you need a type
812 which isn't going to be given a type number. */
817 register struct type *type =
818 (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type));
820 bzero (type, sizeof (struct type));
821 TYPE_VPTR_FIELDNO (type) = -1;
825 /* Make sure there is a type allocated for type numbers TYPENUMS
826 and return the type object.
827 This can create an empty (zeroed) type object.
828 TYPENUMS may be (-1, -1) to return a new type object that is not
829 put into the type vector, and so may not be referred to by number. */
832 dbx_alloc_type (typenums)
835 register struct type **type_addr;
836 register struct type *type;
838 if (typenums[1] != -1)
840 type_addr = dbx_lookup_type (typenums);
849 /* If we are referring to a type not known at all yet,
850 allocate an empty type for it.
851 We will fill it in later if we find out how. */
854 type = dbx_create_type ();
863 static struct type **
864 explicit_lookup_type (real_filenum, index)
865 int real_filenum, index;
867 register struct header_file *f = &header_files[real_filenum];
869 if (index >= f->length)
872 f->vector = (struct type **)
873 xrealloc (f->vector, f->length * sizeof (struct type *));
874 bzero (&f->vector[f->length / 2],
875 f->length * sizeof (struct type *) / 2);
877 return &f->vector[index];
881 /* maintain the lists of symbols and blocks */
883 /* Add a symbol to one of the lists of symbols. */
885 add_symbol_to_list (symbol, listhead)
886 struct symbol *symbol;
887 struct pending **listhead;
889 /* We keep PENDINGSIZE symbols in each link of the list.
890 If we don't have a link with room in it, add a new link. */
891 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
893 register struct pending *link;
896 link = free_pendings;
897 free_pendings = link->next;
900 link = (struct pending *) xxmalloc (sizeof (struct pending));
902 link->next = *listhead;
907 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
910 /* At end of reading syms, or in case of quit,
911 really free as many `struct pending's as we can easily find. */
914 really_free_pendings ()
916 struct pending *next, *next1;
917 struct pending_block *bnext, *bnext1;
919 for (next = free_pendings; next; next = next1)
926 for (bnext = pending_blocks; bnext; bnext = bnext1)
928 bnext1 = bnext->next;
933 for (next = file_symbols; next; next = next1)
938 for (next = global_symbols; next; next = next1)
945 /* Take one of the lists of symbols and make a block from it.
946 Keep the order the symbols have in the list (reversed from the input file).
947 Put the block on the list of pending blocks. */
950 finish_block (symbol, listhead, old_blocks, start, end)
951 struct symbol *symbol;
952 struct pending **listhead;
953 struct pending_block *old_blocks;
954 CORE_ADDR start, end;
956 register struct pending *next, *next1;
957 register struct block *block;
958 register struct pending_block *pblock;
959 struct pending_block *opblock;
962 /* Count the length of the list of symbols. */
964 for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next);
966 block = (struct block *) obstack_alloc (symbol_obstack,
967 (sizeof (struct block)
969 * sizeof (struct symbol *))));
971 /* Copy the symbols into the block. */
973 BLOCK_NSYMS (block) = i;
974 for (next = *listhead; next; next = next->next)
977 for (j = next->nsyms - 1; j >= 0; j--)
978 BLOCK_SYM (block, --i) = next->symbol[j];
981 BLOCK_START (block) = start;
982 BLOCK_END (block) = end;
983 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
984 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
986 /* Put the block in as the value of the symbol that names it. */
990 SYMBOL_BLOCK_VALUE (symbol) = block;
991 BLOCK_FUNCTION (block) = symbol;
994 BLOCK_FUNCTION (block) = 0;
996 /* Now "free" the links of the list, and empty the list. */
998 for (next = *listhead; next; next = next1)
1001 next->next = free_pendings;
1002 free_pendings = next;
1006 /* Install this block as the superblock
1007 of all blocks made since the start of this scope
1008 that don't have superblocks yet. */
1011 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
1013 if (BLOCK_SUPERBLOCK (pblock->block) == 0)
1014 BLOCK_SUPERBLOCK (pblock->block) = block;
1018 /* Record this block on the list of all blocks in the file.
1019 Put it after opblock, or at the beginning if opblock is 0.
1020 This puts the block in the list after all its subblocks. */
1022 /* Allocate in the symbol_obstack to save time.
1023 It wastes a little space. */
1024 pblock = (struct pending_block *)
1025 obstack_alloc (symbol_obstack,
1026 sizeof (struct pending_block));
1027 pblock->block = block;
1030 pblock->next = opblock->next;
1031 opblock->next = pblock;
1035 pblock->next = pending_blocks;
1036 pending_blocks = pblock;
1040 static struct blockvector *
1043 register struct pending_block *next, *next1;
1044 register struct blockvector *blockvector;
1047 /* Count the length of the list of blocks. */
1049 for (next = pending_blocks, i = 0; next; next = next->next, i++);
1051 blockvector = (struct blockvector *)
1052 obstack_alloc (symbol_obstack,
1053 (sizeof (struct blockvector)
1054 + (i - 1) * sizeof (struct block *)));
1056 /* Copy the blocks into the blockvector.
1057 This is done in reverse order, which happens to put
1058 the blocks into the proper order (ascending starting address).
1059 finish_block has hair to insert each block into the list
1060 after its subblocks in order to make sure this is true. */
1062 BLOCKVECTOR_NBLOCKS (blockvector) = i;
1063 for (next = pending_blocks; next; next = next->next)
1064 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
1066 #if 0 /* Now we make the links in the obstack, so don't free them. */
1067 /* Now free the links of the list, and empty the list. */
1069 for (next = pending_blocks; next; next = next1)
1080 /* Manage the vector of line numbers. */
1083 record_line (line, pc)
1087 struct linetable_entry *e;
1088 /* Ignore the dummy line number in libg.o */
1093 /* Make sure line vector is big enough. */
1095 if (line_vector_index + 1 >= line_vector_length)
1097 line_vector_length *= 2;
1098 line_vector = (struct linetable *)
1099 xrealloc (line_vector,
1100 (sizeof (struct linetable)
1101 + line_vector_length * sizeof (struct linetable_entry)));
1102 current_subfile->line_vector = line_vector;
1105 e = line_vector->item + line_vector_index++;
1106 e->line = line; e->pc = pc;
1109 /* Start a new symtab for a new source file.
1110 This is called when a dbx symbol of type N_SO is seen;
1111 it indicates the start of data for one original source file. */
1114 start_symtab (name, start_addr)
1116 CORE_ADDR start_addr;
1118 register struct symtab *s;
1120 last_source_file = name;
1121 last_source_start_addr = start_addr;
1124 within_function = 0;
1126 /* Context stack is initially empty, with room for 10 levels. */
1128 = (struct context_stack *) xxmalloc (10 * sizeof (struct context_stack));
1129 context_stack_size = 10;
1130 context_stack_depth = 0;
1132 new_object_header_files ();
1134 for (s = symseg_chain; s; s = s->next)
1135 if (s->ldsymoff == symnum * sizeof (struct nlist))
1141 type_vector_length = 160;
1142 type_vector = (struct typevector *)
1143 xxmalloc (sizeof (struct typevector)
1144 + type_vector_length * sizeof (struct type *));
1145 bzero (type_vector->type, type_vector_length * sizeof (struct type *));
1147 /* Initialize the list of sub source files with one entry
1148 for this file (the top-level source file). */
1151 current_subfile = 0;
1152 start_subfile (name);
1154 #if 0 /* This is now set at the beginning of read_ofile_symtab */
1155 /* Set default for compiler to pcc; assume that we aren't processing
1156 a gcc compiled file until proved otherwise. */
1158 processing_gcc_compilation = 0;
1162 /* Handle an N_SOL symbol, which indicates the start of
1163 code that came from an included (or otherwise merged-in)
1164 source file with a different name. */
1167 start_subfile (name)
1170 register struct subfile *subfile;
1172 /* Save the current subfile's line vector data. */
1174 if (current_subfile)
1176 current_subfile->line_vector_index = line_vector_index;
1177 current_subfile->line_vector_length = line_vector_length;
1178 current_subfile->prev_line_number = prev_line_number;
1181 /* See if this subfile is already known as a subfile of the
1182 current main source file. */
1184 for (subfile = subfiles; subfile; subfile = subfile->next)
1186 if (!strcmp (subfile->name, name))
1188 line_vector = subfile->line_vector;
1189 line_vector_index = subfile->line_vector_index;
1190 line_vector_length = subfile->line_vector_length;
1191 prev_line_number = subfile->prev_line_number;
1192 current_subfile = subfile;
1197 /* This subfile is not known. Add an entry for it. */
1199 line_vector_index = 0;
1200 line_vector_length = 1000;
1201 prev_line_number = -2; /* Force first line number to be explicit */
1202 line_vector = (struct linetable *)
1203 xxmalloc (sizeof (struct linetable)
1204 + line_vector_length * sizeof (struct linetable_entry));
1206 /* Make an entry for this subfile in the list of all subfiles
1207 of the current main source file. */
1209 subfile = (struct subfile *) xxmalloc (sizeof (struct subfile));
1210 subfile->next = subfiles;
1211 subfile->name = savestring (name, strlen (name));
1212 subfile->line_vector = line_vector;
1214 current_subfile = subfile;
1217 /* Finish the symbol definitions for one main source file,
1218 close off all the lexical contexts for that file
1219 (creating struct block's for them), then make the struct symtab
1220 for that file and put it in the list of all such.
1222 END_ADDR is the address of the end of the file's text. */
1225 end_symtab (end_addr)
1228 register struct symtab *symtab;
1229 register struct blockvector *blockvector;
1230 register struct subfile *subfile;
1231 register struct linetable *lv;
1232 struct subfile *nextsub;
1234 if (current_symseg != 0)
1236 last_source_file = 0;
1241 /* Finish the lexical context of the last function in the file;
1242 pop the context stack. */
1244 if (context_stack_depth > 0)
1246 register struct context_stack *cstk;
1247 context_stack_depth--;
1248 cstk = &context_stack[context_stack_depth];
1249 /* Make a block for the local symbols within. */
1250 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
1251 cstk->start_addr, end_addr);
1254 /* Cleanup any undefined types that have been left hanging around
1255 (this needs to be done before the finish_blocks so that
1256 file_symbols is still good). */
1257 cleanup_undefined_types ();
1259 /* Finish defining all the blocks of this symtab. */
1260 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
1261 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
1262 blockvector = make_blockvector ();
1264 current_subfile->line_vector_index = line_vector_index;
1266 /* Now create the symtab objects proper, one for each subfile. */
1267 /* (The main file is one of them.) */
1269 for (subfile = subfiles; subfile; subfile = nextsub)
1271 symtab = (struct symtab *) xxmalloc (sizeof (struct symtab));
1272 symtab->free_ptr = 0;
1274 /* Fill in its components. */
1275 symtab->blockvector = blockvector;
1276 type_vector->length = type_vector_length;
1277 symtab->typevector = type_vector;
1278 symtab->free_code = free_linetable;
1279 if (subfile->next == 0)
1280 symtab->free_ptr = (char *) type_vector;
1282 symtab->filename = subfile->name;
1283 lv = subfile->line_vector;
1284 lv->nitems = subfile->line_vector_index;
1285 symtab->linetable = (struct linetable *)
1286 xrealloc (lv, (sizeof (struct linetable)
1287 + lv->nitems * sizeof (struct linetable_entry)));
1289 symtab->line_charpos = 0;
1291 /* Link the new symtab into the list of such. */
1292 symtab->next = symtab_list;
1293 symtab_list = symtab;
1295 nextsub = subfile->next;
1300 type_vector_length = -1;
1302 line_vector_length = -1;
1303 last_source_file = 0;
1308 /* Handle the N_BINCL and N_EINCL symbol types
1309 that act like N_SOL for switching source files
1310 (different subfiles, as we call them) within one object file,
1311 but using a stack rather than in an arbitrary order. */
1313 struct subfile_stack
1315 struct subfile_stack *next;
1320 struct subfile_stack *subfile_stack;
1325 register struct subfile_stack *tem
1326 = (struct subfile_stack *) xxmalloc (sizeof (struct subfile_stack));
1328 tem->next = subfile_stack;
1329 subfile_stack = tem;
1330 if (current_subfile == 0 || current_subfile->name == 0)
1332 tem->name = current_subfile->name;
1333 tem->prev_index = header_file_prev_index;
1339 register char *name;
1340 register struct subfile_stack *link = subfile_stack;
1346 subfile_stack = link->next;
1347 header_file_prev_index = link->prev_index;
1352 #endif /* Have N_BINCL */
1354 /* Accumulate the misc functions in bunches of 127.
1355 At the end, copy them all into one newly allocated structure. */
1357 #define MISC_BUNCH_SIZE 127
1361 struct misc_bunch *next;
1362 struct misc_function contents[MISC_BUNCH_SIZE];
1365 /* Bunch currently being filled up.
1366 The next field points to chain of filled bunches. */
1368 static struct misc_bunch *misc_bunch;
1370 /* Number of slots filled in current bunch. */
1372 static int misc_bunch_index;
1374 /* Total number of misc functions recorded so far. */
1376 static int misc_count;
1379 init_misc_functions ()
1383 misc_bunch_index = MISC_BUNCH_SIZE;
1387 record_misc_function (name, address, type)
1392 register struct misc_bunch *new;
1394 if (misc_bunch_index == MISC_BUNCH_SIZE)
1396 new = (struct misc_bunch *) xxmalloc (sizeof (struct misc_bunch));
1397 misc_bunch_index = 0;
1398 new->next = misc_bunch;
1401 misc_bunch->contents[misc_bunch_index].name = name;
1402 misc_bunch->contents[misc_bunch_index].address = address;
1403 misc_bunch->contents[misc_bunch_index].type = (unsigned char)
1404 (type == (N_TEXT | N_EXT) ? mf_text :
1405 (type == (N_DATA | N_EXT)
1407 || type == (N_SETV | N_EXT)
1410 type == (N_BSS | N_EXT) ? mf_bss :
1411 type == (N_ABS | N_EXT) ? mf_abs : mf_unknown);
1417 compare_misc_functions (fn1, fn2)
1418 struct misc_function *fn1, *fn2;
1420 /* Return a signed result based on unsigned comparisons
1421 so that we sort into unsigned numeric order. */
1422 if (fn1->address < fn2->address)
1424 if (fn1->address > fn2->address)
1430 discard_misc_bunches ()
1432 register struct misc_bunch *next;
1436 next = misc_bunch->next;
1442 /* INCLINK nonzero means bunches are from an incrementally-linked file.
1443 Add them to the existing bunches.
1444 Otherwise INCLINK is zero, and we start from scratch. */
1446 condense_misc_bunches (inclink)
1450 register struct misc_bunch *bunch;
1451 #ifdef NAMES_HAVE_UNDERSCORE
1459 misc_function_vector
1460 = (struct misc_function *)
1461 xrealloc (misc_function_vector, (misc_count + misc_function_count)
1462 * sizeof (struct misc_function));
1463 j = misc_function_count;
1467 misc_function_vector
1468 = (struct misc_function *)
1469 xxmalloc (misc_count * sizeof (struct misc_function));
1476 for (i = 0; i < misc_bunch_index; i++)
1478 misc_function_vector[j] = bunch->contents[i];
1479 misc_function_vector[j].name
1480 = obconcat (misc_function_vector[j].name
1481 + (misc_function_vector[j].name[0] == '_' ? offset : 0),
1485 bunch = bunch->next;
1486 misc_bunch_index = MISC_BUNCH_SIZE;
1490 misc_function_count += misc_count;
1492 misc_function_count = j;
1494 /* Sort the misc functions by address. */
1496 qsort (misc_function_vector, misc_function_count,
1497 sizeof (struct misc_function),
1498 compare_misc_functions);
1501 /* Call sort_syms to sort alphabetically
1502 the symbols of each block of each symtab. */
1505 compare_symbols (s1, s2)
1506 struct symbol **s1, **s2;
1508 register int namediff;
1510 /* Compare the initial characters. */
1511 namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0];
1512 if (namediff != 0) return namediff;
1514 /* If they match, compare the rest of the names. */
1515 namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
1516 if (namediff != 0) return namediff;
1518 /* For symbols of the same name, registers should come first. */
1519 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
1520 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
1523 static void sort_symtab_syms ();
1528 register struct symtab *s;
1530 for (s = symtab_list; s; s = s->next)
1531 sort_symtab_syms (s);
1535 sort_symtab_syms (s)
1536 register struct symtab *s;
1538 register struct blockvector *bv = BLOCKVECTOR (s);
1539 int nbl = BLOCKVECTOR_NBLOCKS (bv);
1541 register struct block *b;
1543 /* Note that in the following sort, we always make sure that
1544 register debug symbol declarations always come before regular
1545 debug symbol declarations (as might happen when parameters are
1546 then put into registers by the compiler). We do this by a
1547 correct compare in compare_symbols, and by the reversal of the
1548 symbols if we don't sort. This works as long as a register debug
1549 symbol always comes after a parameter debug symbol. */
1551 /* This is no longer necessary; lookup_block_symbol now always
1552 prefers some other declaration over a parameter declaration. We
1553 still sort the thing (that is necessary), but we don't reverse it
1554 if we shouldn't sort it. */
1556 for (i = 0; i < nbl; i++)
1558 b = BLOCKVECTOR_BLOCK (bv, i);
1559 if (BLOCK_SHOULD_SORT (b))
1560 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
1561 sizeof (struct symbol *), compare_symbols);
1566 extern struct symtab *psymtab_to_symtab ();
1568 /* The entry point. */
1569 static CORE_ADDR entry_point;
1571 /* This is the symbol-file command. Read the file, analyze its symbols,
1572 and add a struct symtab to symtab_list. */
1575 symbol_file_command (name, from_tty)
1580 DECLARE_FILE_HEADERS;
1581 struct nlist *nlist;
1583 /* The string table. */
1586 /* The size of the string table (buffer is a bizarre name...). */
1590 extern void close ();
1591 struct cleanup *old_chain;
1592 struct symtab *symseg;
1593 struct stat statbuf;
1599 if ((symtab_list || partial_symtab_list)
1601 && !query ("Discard symbol table? ", 0))
1602 error ("Not confirmed.");
1606 free_all_symtabs ();
1607 free_all_psymtabs ();
1611 name = tilde_expand (name);
1612 make_cleanup (free, name);
1614 if ((symtab_list || partial_symtab_list)
1615 && !query ("Load new symbol table from \"%s\"? ", name))
1616 error ("Not confirmed.");
1619 char *absolute_name;
1620 desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);
1622 perror_with_name (name);
1624 name = absolute_name;
1627 old_chain = make_cleanup (close, desc);
1628 make_cleanup (free_current_contents, &name);
1630 READ_FILE_HEADERS (desc, name);
1632 entry_point = ENTRY_POINT;
1634 if (NUMBER_OF_SYMBOLS == 0)
1639 free_all_symtabs ();
1640 free_all_psymtabs ();
1641 printf ("%s has no symbol-table; symbols discarded.\n", name);
1643 do_cleanups (old_chain);
1647 printf ("Reading symbol data from %s...", name);
1650 /* Now read the string table, all at once. */
1651 val = lseek (desc, STRING_TABLE_OFFSET, 0);
1653 perror_with_name (name);
1654 if (stat (name, &statbuf) == -1)
1655 perror_with_name (name);
1656 READ_STRING_TABLE_SIZE (buffer);
1657 if (buffer >= 0 && buffer < statbuf.st_size)
1659 #ifdef BROKEN_LARGE_ALLOCA
1660 stringtab = (char *) xmalloc (buffer);
1661 make_cleanup (free, stringtab);
1663 stringtab = (char *) alloca (buffer);
1668 if (stringtab == NULL)
1669 error ("ridiculous string table size: %d bytes", buffer);
1671 /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer.
1672 Occaisionally, it won't. */
1673 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
1675 perror_with_name (name);
1676 val = myread (desc, stringtab, buffer);
1678 perror_with_name (name);
1680 /* Throw away the old symbol table. */
1685 free_all_symtabs ();
1686 free_all_psymtabs ();
1688 /* Empty the hash table of global syms looking for values. */
1689 bzero (global_sym_chain, sizeof global_sym_chain);
1691 /* Symsegs are no longer supported by GDB. Setting symseg_chain to
1692 0 is easier than finding all the symseg code and eliminating it. */
1695 /* Position to read the symbol table. Do not read it all at once. */
1696 val = lseek (desc, SYMBOL_TABLE_OFFSET, 0);
1698 perror_with_name (name);
1700 /* Don't put these on the cleanup chain; they need to stick around
1701 until the next call to symbol_file_command. *Then* we'll free
1703 free_header_files ();
1704 init_header_files ();
1706 init_misc_functions ();
1707 make_cleanup (discard_misc_bunches, 0);
1713 make_cleanup (really_free_pendings, 0);
1715 /* Now that the symbol table data of the executable file are all in core,
1716 process them and define symbols accordingly. Closes desc. */
1718 read_dbx_symtab (desc, stringtab, buffer, NUMBER_OF_SYMBOLS, 0,
1719 ADDR_OF_TEXT_SEGMENT, SIZE_OF_TEXT_SEGMENT);
1721 /* Go over the misc functions and install them in vector. */
1723 condense_misc_bunches (0);
1725 /* Don't allow char * to have a typename (else would get caddr_t.) */
1727 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
1729 /* Make a default for file to list. */
1731 symfile = savestring (name, strlen (name));
1733 /* Call to select_source_symtab used to be here; it was using too
1734 much time. I'll make sure that list_sources can handle the lack
1735 of current_source_symtab */
1737 do_cleanups (old_chain); /* Descriptor closed here */
1739 /* Free the symtabs made by read_symsegs, but not their contents,
1740 which have been copied into symtabs on symtab_list. */
1741 while (symseg_chain)
1743 register struct symtab *s = symseg_chain->next;
1744 free (symseg_chain);
1748 if (!partial_symtab_list)
1749 printf ("\n(no debugging symbols found)...");
1755 /* Return name of file symbols were loaded from, or 0 if none.. */
1763 /* Buffer for reading the symbol table entries. */
1764 static struct nlist symbuf[4096];
1765 static int symbuf_idx;
1766 static int symbuf_end;
1768 /* I/O descriptor for reading the symbol table. */
1769 static int symtab_input_desc;
1771 /* The address of the string table
1772 of the object file we are reading (as copied into core). */
1773 static char *stringtab_global;
1775 /* Refill the symbol table input buffer
1776 and set the variables that control fetching entries from it.
1777 Reports an error if no data available.
1778 This function can read past the end of the symbol table
1779 (into the string table) but this does no harm. */
1784 int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf));
1786 error ("error or end of file reading symbol table");
1787 symbuf_end = nbytes / sizeof (struct nlist);
1792 /* dbx allows the text of a symbol name to be continued into the
1793 next symbol name! When such a continuation is encountered
1794 (a \ at the end of the text of a name)
1795 call this function to get the continuation. */
1800 if (symbuf_idx == symbuf_end)
1803 return symbuf[symbuf_idx++].n_un.n_strx + stringtab_global;
1807 * Initializes storage for all of the partial symbols that will be
1808 * created by read_dbx_symtab and subsidiaries.
1811 init_psymbol_list (total_symbols)
1814 /* Current best guess is that there are approximately a twentieth
1815 of the total symbols (in a debugging file) are global or static
1817 global_psymbols.size = total_symbols / 10;
1818 static_psymbols.size = total_symbols / 10;
1819 global_psymbols.next = global_psymbols.list = (struct partial_symbol *)
1820 xmalloc (global_psymbols.size * sizeof (struct partial_symbol));
1821 static_psymbols.next = static_psymbols.list = (struct partial_symbol *)
1822 xmalloc (static_psymbols.size * sizeof (struct partial_symbol));
1826 * Initialize the list of bincls to contain none and have some
1830 init_bincl_list (number)
1833 bincls_allocated = number;
1834 next_bincl = bincl_list = (struct header_file_location *)
1835 xmalloc (bincls_allocated * sizeof(struct header_file_location));
1839 * Add a bincl to the list.
1842 add_bincl_to_list (pst, name, instance)
1843 struct partial_symtab *pst;
1847 if (next_bincl >= bincl_list + bincls_allocated)
1849 int offset = next_bincl - bincl_list;
1850 bincls_allocated *= 2;
1851 bincl_list = (struct header_file_location *)
1852 xrealloc (bincl_list,
1853 bincls_allocated * sizeof (struct header_file_location));
1854 next_bincl = bincl_list + offset;
1856 next_bincl->pst = pst;
1857 next_bincl->instance = instance;
1858 next_bincl++->name = name;
1862 * Given a name, value pair, find the corresponding
1863 * bincl in the list. Return the partial symtab associated
1864 * with that header_file_location.
1866 struct partial_symtab *
1867 find_corresponding_bincl_psymtab (name, instance)
1871 struct header_file_location *bincl;
1873 for (bincl = bincl_list; bincl < next_bincl; bincl++)
1874 if (bincl->instance == instance
1875 && !strcmp (name, bincl->name))
1878 return (struct partial_symtab *) 0;
1882 * Free the storage allocated for the bincl list.
1888 bincls_allocated = 0;
1891 static struct partial_symtab *start_psymtab ();
1892 static void add_psymtab_dependency ();
1893 static void end_psymtab();
1895 /* Given pointers to an a.out symbol table in core containing dbx
1896 style data, setup partial_symtab's describing each source file for
1897 which debugging information is available. NLISTLEN is the number
1898 of symbols in the symbol table. All symbol names are given as
1899 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
1902 I have no idea whether or not this routine should be setup to deal
1903 with inclinks. It seems reasonable to me that they be dealt with
1904 standardly, so I am not going to make a strong effort to deal with
1909 read_dbx_symtab (desc, stringtab, stringtab_size, nlistlen, inclink,
1910 text_addr, text_size)
1912 register char *stringtab;
1913 register long stringtab_size;
1914 register int nlistlen;
1919 register struct nlist *bufp;
1920 register char *namestring;
1921 register struct partial_symbol *psym;
1922 register struct psymbol_allocation_list *psymbol_struct;
1925 int past_first_source_file = 0;
1926 CORE_ADDR last_o_file_start = 0;
1927 struct cleanup *old_chain;
1930 enum address_class class;
1932 #ifdef PROFILE_TYPES
1934 int profile_types [256];
1935 int strcmp_called = 0;
1937 int global_funs = 0;
1940 /* Current partial symtab */
1941 struct partial_symtab *pst;
1943 /* List of current psymtab's include files */
1944 char **psymtab_include_list;
1945 int includes_allocated;
1948 /* Index within current psymtab dependency list */
1949 struct partial_symtab **dependency_list;
1950 int dependencies_used, dependencies_allocated;
1952 #ifdef PROFILE_TYPES
1953 for (i = 0; i < 256; i++)
1954 profile_types[i] = 0;
1957 stringtab_global = stringtab;
1959 pst = (struct partial_symtab *) 0;
1961 includes_allocated = 30;
1963 psymtab_include_list = (char **) alloca (includes_allocated *
1966 dependencies_allocated = 30;
1967 dependencies_used = 0;
1969 (struct partial_symtab **) alloca (dependencies_allocated *
1970 sizeof (struct partial_symtab *));
1972 old_chain = make_cleanup (free_all_psymtabs, 0);
1974 /* Init bincl list */
1975 init_bincl_list (20);
1976 make_cleanup (free_bincl_list, 0);
1978 /* Setup global partial symbol list */
1979 init_psymbol_list (nlistlen);
1981 last_source_file = 0;
1983 #ifdef END_OF_TEXT_DEFAULT
1984 end_of_text_addr = END_OF_TEXT_DEFAULT;
1986 end_of_text_addr = text_addr + text_size;
1989 symtab_input_desc = desc; /* This is needed for fill_symbuf below */
1990 symbuf_end = symbuf_idx = 0;
1992 for (symnum = 0; symnum < nlistlen; symnum++)
1994 /* Get the symbol for this run and pull out some info */
1995 QUIT; /* allow this to be interruptable */
1996 if (symbuf_idx == symbuf_end)
1998 bufp = &symbuf[symbuf_idx++];
2000 #ifdef PROFILE_TYPES
2001 profile_types[bufp->n_type]++;
2005 * Special case to speed up readin.
2007 if (bufp->n_type == N_SLINE) continue;
2009 /* Ok. There is a lot of code duplicated in the rest of this
2010 switch statiement (for efficiency reasons). Since I don't
2011 like duplicating code, I will do my penance here, and
2012 describe the code which is duplicated:
2014 *) The assignment to namestring.
2015 *) The call to index.
2016 *) The addition of a partial symbol the the two partial
2017 symbol lists. This last is a large section of code, so
2018 I've imbedded it in the following macro.
2021 /* Set namestring based on bufp. */
2022 #define SET_NAMESTRING()\
2023 if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) \
2024 error ("Invalid symbol data: bad string table offset: %d", \
2025 bufp->n_un.n_strx); \
2026 namestring = bufp->n_un.n_strx + stringtab
2028 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE)\
2030 if ((LIST).next >= \
2031 (LIST).list + (LIST).size) \
2033 (LIST).list = (struct partial_symbol *) \
2034 xrealloc ((LIST).list, \
2036 * sizeof (struct partial_symbol))); \
2037 /* Next assumes we only went one over. Should be good if \
2038 program works correctly */ \
2040 (LIST).list + (LIST).size; \
2043 psym = (LIST).next++; \
2045 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
2046 (NAMELENGTH) + 1); \
2047 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
2048 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
2049 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
2050 SYMBOL_CLASS (psym) = (CLASS); \
2051 SYMBOL_VALUE (psym) = (VALUE); \
2055 switch (bufp->n_type)
2058 * Standard, non-debugger, symbols
2061 case N_TEXT | N_EXT:
2066 if (namestring[6] == '\0' && namestring[5] == 't'
2067 && namestring[4] == 'x' && namestring[3] == 'e'
2068 && namestring[2] == 't' && namestring[1] == 'e'
2069 && namestring[0] == '_')
2070 end_of_text_addr = bufp->n_value;
2072 /* Figure out beginning and end of global linker symbol
2073 section and put non-debugger specified symbols on
2076 last_global_sym = symnum;
2077 if (!first_global_sym) first_global_sym = symnum;
2079 record_misc_function (namestring, bufp->n_value,
2080 bufp->n_type); /* Always */
2085 case N_NBTEXT | N_EXT:
2088 case N_NBDATA | N_EXT:
2091 case N_NBBSS | N_EXT:
2094 case N_SETV | N_EXT:
2097 case N_DATA | N_EXT:
2099 /* Figure out beginning and end of global linker symbol
2100 section and put non-debugger specified symbols on
2105 last_global_sym = symnum;
2106 if (!first_global_sym) first_global_sym = symnum;
2108 /* Not really a function here, but... */
2109 record_misc_function (namestring, bufp->n_value,
2110 bufp->n_type); /* Always */
2118 /* We need to be able to deal with both N_FN or N_TEXT,
2119 because we have no way of knowing whether the sys-supplied ld
2120 or GNU ld was used to make the executable. */
2121 /* #ifdef OFILE_FN_FLAGGED */
2122 #if ! (N_FN & N_EXT)
2130 if ((namestring[0] == '-' && namestring[1] == 'l')
2131 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
2132 && namestring [nsl - 2] == '.'))
2134 if (entry_point < bufp->n_value
2135 && entry_point >= last_o_file_start)
2137 startup_file_start = last_o_file_start;
2138 startup_file_end = bufp->n_value;
2140 if (past_first_source_file && pst)
2142 end_psymtab (pst, psymtab_include_list, includes_used,
2143 symnum * sizeof (struct nlist), bufp->n_value,
2144 dependency_list, dependencies_used,
2145 global_psymbols.next, static_psymbols.next);
2146 pst = (struct partial_symtab *) 0;
2148 dependencies_used = 0;
2151 past_first_source_file = 1;
2152 last_o_file_start = bufp->n_value;
2157 /* See comments at N_FN above. */
2158 #ifdef OFILE_FN_FLAGGED
2161 #if ! (N_FN & N_EXT)
2168 case N_UNDF | N_EXT:
2179 /* Keep going . . .*/
2182 * Special symbol types for GNU
2186 case N_INDR | N_EXT:
2190 case N_SETA | N_EXT:
2192 case N_SETT | N_EXT:
2194 case N_SETD | N_EXT:
2196 case N_SETB | N_EXT:
2206 /* End the current partial symtab and start a new one */
2210 if (pst && past_first_source_file)
2212 end_psymtab (pst, psymtab_include_list, includes_used,
2213 symnum * sizeof (struct nlist), bufp->n_value,
2214 dependency_list, dependencies_used,
2215 global_psymbols.next, static_psymbols.next);
2216 pst = (struct partial_symtab *) 0;
2218 dependencies_used = 0;
2221 past_first_source_file = 1;
2223 pst = start_psymtab (namestring, bufp->n_value,
2224 symnum * sizeof (struct nlist),
2225 global_psymbols.next, static_psymbols.next);
2231 /* Add this bincl to the bincl_list for future EXCLs. No
2232 need to save the string; it'll be around until
2233 read_dbx_symtab function return */
2237 add_bincl_to_list (pst, namestring, bufp->n_value);
2239 /* Mark down an include file in the current psymtab */
2241 psymtab_include_list[includes_used++] = namestring;
2242 if (includes_used >= includes_allocated)
2244 char **orig = psymtab_include_list;
2246 psymtab_include_list = (char **)
2247 alloca ((includes_allocated *= 2) *
2249 bcopy (orig, psymtab_include_list,
2250 includes_used * sizeof (char *));
2257 /* Mark down an include file in the current psymtab */
2261 /* In C++, one may expect the same filename to come round many
2262 times, when code is coming alternately from the main file
2263 and from inline functions in other files. So I check to see
2264 if this is a file we've seen before.
2266 This seems to be a lot of time to be spending on N_SOL, but
2267 things like "break expread.y:435" need to work (I
2268 suppose the psymtab_include_list could be hashed or put
2269 in a binary tree, if profiling shows this is a major hog). */
2272 for (i = 0; i < includes_used; i++)
2273 if (!strcmp (namestring, psymtab_include_list[i]))
2282 psymtab_include_list[includes_used++] = namestring;
2283 if (includes_used >= includes_allocated)
2285 char **orig = psymtab_include_list;
2287 psymtab_include_list = (char **)
2288 alloca ((includes_allocated *= 2) *
2290 bcopy (orig, psymtab_include_list,
2291 includes_used * sizeof (char *));
2295 case N_LSYM: /* Typedef or automatic variable. */
2298 p = (char *) index (namestring, ':');
2300 /* Skip if there is no :. */
2306 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2307 STRUCT_NAMESPACE, LOC_TYPEDEF,
2308 static_psymbols, bufp->n_value);
2311 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2312 VAR_NAMESPACE, LOC_TYPEDEF,
2313 static_psymbols, bufp->n_value);
2315 /* If this is an enumerated type, we need to
2316 add all the enum constants to the partial symbol
2317 table. This does not cover enums without names, e.g.
2318 "enum {a, b} c;" in C, but fortunately those are
2319 rare. There is no way for GDB to find those from the
2320 enum type without spending too much time on it. Thus
2321 to solve this problem, the compiler needs to put out separate
2322 constant symbols ('c' N_LSYMS) for enum constants in
2323 enums without names. */
2325 /* We are looking for something of the form
2326 <name> ":" ("t" | "T") [<number> "="] "e"
2327 {<constant> ":" <value> ","} ";". */
2329 /* Skip over the colon and the 't' or 'T'. */
2331 /* This type may be given a number. Skip over it. */
2332 while ((*p >= '0' && *p <= '9')
2338 /* We have found an enumerated type. */
2339 /* According to comments in read_enum_type
2340 a comma could end it instead of a semicolon.
2341 I don't know where that happens.
2343 while (*p && *p != ';' && *p != ',')
2347 /* Check for and handle cretinous dbx symbol name
2350 p = next_symbol_text ();
2352 /* Point to the character after the name
2353 of the enum constant. */
2354 for (q = p; *q && *q != ':'; q++)
2356 /* Note that the value doesn't matter for
2357 enum constants in psymtabs, just in symtabs. */
2358 ADD_PSYMBOL_TO_LIST (p, q - p,
2359 VAR_NAMESPACE, LOC_CONST,
2360 static_psymbols, 0);
2361 /* Point past the name. */
2363 /* Skip over the value. */
2364 while (*p && *p != ',')
2366 /* Advance past the comma. */
2374 /* Constant, e.g. from "const" in Pascal. */
2375 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2376 VAR_NAMESPACE, LOC_CONST,
2377 static_psymbols, bufp->n_value);
2380 #ifdef PROFILE_TYPES
2382 printf ("Funny...LSYM with a letter that isn't a type\n");
2385 /* Skip if the thing following the : is
2386 not a letter (which indicates declaration of a local
2387 variable, which we aren't interested in). */
2393 /* This special-casing of N_FUN is just wrong; N_FUN
2394 does not mean "function"; it means "text segment".
2395 So N_FUN can go with 'V', etc. as well as 'f' or 'F'. */
2399 p = (char *) index (namestring, ':');
2401 if (!p || p[1] == 'F') continue;
2403 #ifdef PROFILE_TYPES
2405 printf ("Funny...FUN with a letter that isn't 'F' or 'f'.\n");
2409 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2410 VAR_NAMESPACE, LOC_BLOCK,
2411 static_psymbols, bufp->n_value);
2415 case N_GSYM: /* Global (extern) variable; can be
2416 data or bss (sigh). */
2417 case N_STSYM: /* Data seg var -- static */
2418 case N_LCSYM: /* BSS " */
2420 /* Following may probably be ignored; I'll leave them here
2421 for now (until I do Pascal and Modula 2 extensions). */
2423 case N_PC: /* I may or may not need this; I
2426 case N_M2C: /* I suspect that I can ignore this here. */
2427 case N_SCOPE: /* Same. */
2432 p = (char *) index (namestring, ':');
2434 continue; /* Not a debugging symbol. */
2436 process_symbol_for_psymtab:
2438 /* Main processing section for debugging symbols which
2439 the initial read through the symbol tables needs to worry
2440 about. If we reach this point, the symbol which we are
2441 considering is definitely one we are interested in.
2442 p must also contain the (valid) index into the namestring
2443 which indicates the debugging type symbol. */
2448 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2449 VAR_NAMESPACE, LOC_CONST,
2450 static_psymbols, bufp->n_value);
2453 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2454 VAR_NAMESPACE, LOC_STATIC,
2455 static_psymbols, bufp->n_value);
2458 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2459 VAR_NAMESPACE, LOC_EXTERNAL,
2460 global_psymbols, bufp->n_value);
2464 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2465 VAR_NAMESPACE, LOC_TYPEDEF,
2466 global_psymbols, bufp->n_value);
2470 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2471 VAR_NAMESPACE, LOC_BLOCK,
2472 static_psymbols, bufp->n_value);
2475 /* Two things show up here (hopefully); static symbols of
2476 local scope (static used inside braces) or extensions
2477 of structure symbols. We can ignore both. */
2490 /* Global functions are ignored here. I'm not
2491 sure what psymtab they go into (or just the misc
2492 function vector). */
2497 fatal ("Internal error: Unexpected debugging symbol type '%c' at symnum %d.\n",
2506 /* Find the corresponding bincl and mark that psymtab on the
2507 psymtab dependency list */
2509 struct partial_symtab *needed_pst =
2510 find_corresponding_bincl_psymtab (namestring, bufp->n_value);
2512 /* If this include file was defined earlier in this file,
2514 if (needed_pst == pst) continue;
2521 for (i = 0; i < dependencies_used; i++)
2522 if (dependency_list[i] == needed_pst)
2528 /* If it's already in the list, skip the rest. */
2529 if (found) continue;
2531 dependency_list[dependencies_used++] = needed_pst;
2532 if (dependencies_used >= dependencies_allocated)
2534 struct partial_symtab **orig = dependency_list;
2536 (struct partial_symtab **)
2537 alloca ((dependencies_allocated *= 2)
2538 * sizeof (struct partial_symtab *));
2539 bcopy (orig, dependency_list,
2541 * sizeof (struct partial_symtab *)));
2543 fprintf (stderr, "Had to reallocate dependency list.\n");
2544 fprintf (stderr, "New dependencies allocated: %d\n",
2545 dependencies_allocated);
2550 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
2563 case N_SSYM: /* Claim: Structure or union element.
2564 Hopefully, I can ignore this. */
2565 case N_ENTRY: /* Alternate entry point; can ignore. */
2567 case N_MAIN: /* Can definitely ignore this. */
2579 /* These symbols aren't interesting; don't worry about them */
2584 /* If we haven't found it yet, we've got problems */
2586 if (IGNORE_SYMBOL (bufp->n_type))
2589 fatal ("Bad symbol type 0x%x encountered in gdb scan", bufp->n_type);
2593 /* If there's stuff to be cleaned up, clean it up. */
2594 if (entry_point < bufp->n_value
2595 && entry_point >= last_o_file_start)
2597 startup_file_start = last_o_file_start;
2598 startup_file_end = bufp->n_value;
2603 end_psymtab (pst, psymtab_include_list, includes_used,
2604 symnum * sizeof (struct nlist), end_of_text_addr,
2605 dependency_list, dependencies_used,
2606 global_psymbols.next, static_psymbols.next);
2608 dependencies_used = 0;
2609 pst = (struct partial_symtab *) 0;
2613 discard_cleanups (old_chain);
2614 #ifdef PROFILE_TYPES
2617 #define __define_stab(SYM, NUMBER, NAME) {NUMBER, NAME},
2618 static struct xyzzy {
2619 unsigned char symnum;
2637 for (i = 0; i < 256; i++)
2639 for (j = 0; j < (sizeof (tmp_list) / sizeof (struct xyzzy)) - 1; j++)
2640 if (tmp_list[j].symnum == i)
2642 printf ("Symbol \"%s\" (0x%x) occured %d times.\n",
2643 tmp_list[j].name, i, profile_types[i]);
2645 printf ("Auto vars (under LSYM): %d\n", autovars);
2646 printf ("Global funs (under FUN): %d\n", global_funs);
2652 * Allocate and partially fill a partial symtab. It will be
2653 * completely filled at the end of the symbol list.
2655 static struct partial_symtab *
2656 start_psymtab (filename, textlow, ldsymoff, global_syms, static_syms)
2660 struct partial_symbol *global_syms;
2661 struct partial_symbol *static_syms;
2663 struct partial_symtab *result =
2664 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
2665 sizeof (struct partial_symtab));
2668 (char *) obstack_alloc (psymbol_obstack,
2669 strlen (filename) + 1);
2670 strcpy (result->filename, filename);
2672 result->textlow = textlow;
2673 result->ldsymoff = ldsymoff;
2677 result->globals_offset = global_syms - global_psymbols.list;
2678 result->statics_offset = static_syms - static_psymbols.list;
2680 result->n_global_syms = 0;
2681 result->n_static_syms = 0;
2687 compare_psymbols (s1, s2)
2688 register struct partial_symbol *s1, *s2;
2691 *st1 = SYMBOL_NAME (s1),
2692 *st2 = SYMBOL_NAME (s2);
2694 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2695 strcmp (st1 + 1, st2 + 1));
2699 /* Close off the current usage of a partial_symbol table entry. This
2700 involves setting the correct number of includes (with a realloc),
2701 setting the high text mark, setting the symbol length in the
2702 executable, and setting the length of the global and static lists
2705 The global symbols and static symbols are then seperately sorted.
2707 Then the partial symtab is put on the global list.
2708 *** List variables and peculiarities of same. ***
2711 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2712 capping_text, dependency_list, number_dependencies,
2713 capping_global, capping_static)
2714 struct partial_symtab *pst;
2715 char **include_list;
2717 int capping_symbol_offset;
2719 struct partial_symtab **dependency_list;
2720 int number_dependencies;
2721 struct partial_symbol *capping_global, *capping_static;
2725 pst->ldsymlen = capping_symbol_offset - pst->ldsymoff;
2726 pst->texthigh = capping_text;
2728 pst->n_global_syms =
2729 capping_global - (global_psymbols.list + pst->globals_offset);
2730 pst->n_static_syms =
2731 capping_static - (static_psymbols.list + pst->statics_offset);
2733 pst->dependencies = (struct partial_symtab **)
2734 obstack_alloc (psymbol_obstack,
2735 number_dependencies * sizeof (struct partial_symtab *));
2736 bcopy (dependency_list, pst->dependencies,
2737 number_dependencies * sizeof (struct partial_symtab *));
2738 pst->number_of_dependencies = number_dependencies;
2740 for (i = 0; i < num_includes; i++)
2742 /* Eventually, put this on obstack */
2743 struct partial_symtab *subpst =
2744 (struct partial_symtab *)
2745 obstack_alloc (psymbol_obstack,
2746 sizeof (struct partial_symtab));
2749 (char *) obstack_alloc (psymbol_obstack,
2750 strlen (include_list[i]) + 1);
2751 strcpy (subpst->filename, include_list[i]);
2756 subpst->texthigh = 0;
2759 subpst->dependencies = (struct partial_symtab **)
2760 obstack_alloc (psymbol_obstack,
2761 sizeof (struct partial_symtab *));
2762 subpst->dependencies[0] = pst;
2763 subpst->number_of_dependencies = 1;
2765 subpst->globals_offset =
2766 subpst->n_global_syms =
2767 subpst->statics_offset =
2768 subpst->n_static_syms = 0;
2770 subpst->next = partial_symtab_list;
2771 partial_symtab_list = subpst;
2774 /* Sort the global list; don't sort the static list */
2775 qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms,
2776 sizeof (struct partial_symbol), compare_psymbols);
2778 /* Put the psymtab on the psymtab list */
2779 pst->next = partial_symtab_list;
2780 partial_symtab_list = pst;
2784 /* Helper routines for psymtab_to_symtab. */
2785 static void scan_file_globals ();
2786 static void read_ofile_symtab ();
2789 psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset)
2790 struct partial_symtab *pst;
2796 struct cleanup *old_chain;
2804 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2809 /* Read in all partial symbtabs on which this one is dependent */
2810 for (i = 0; i < pst->number_of_dependencies; i++)
2811 if (!pst->dependencies[i]->readin)
2813 /* Inform about additional files that need to be read in. */
2816 printf_filtered (" and %s...", pst->dependencies[i]->filename);
2819 psymtab_to_symtab_1 (pst->dependencies[i], desc,
2820 stringtab, stringtab_size, sym_offset);
2823 if (pst->ldsymlen) /* Otherwise it's a dummy */
2825 /* Init stuff necessary for reading in symbols */
2830 old_chain = make_cleanup (really_free_pendings, 0);
2832 /* Read in this files symbols */
2833 lseek (desc, sym_offset, L_SET);
2834 read_ofile_symtab (desc, stringtab, stringtab_size,
2836 pst->ldsymlen, pst->textlow,
2837 pst->texthigh - pst->textlow, 0);
2838 sort_symtab_syms (symtab_list); /* At beginning since just added */
2840 do_cleanups (old_chain);
2847 * Read in all of the symbols for a given psymtab for real. Return
2848 * the value of the symtab you create. Do not free the storage
2849 * allocated to the psymtab; it may have pointers to it.
2852 psymtab_to_symtab(pst)
2853 struct partial_symtab *pst;
2856 DECLARE_FILE_HEADERS;
2858 struct partial_symtab **list_patch;
2860 struct stat statbuf;
2861 struct cleanup *old_chain;
2862 extern void close ();
2864 struct symtab *result;
2865 char *name = symfile; /* Some of the macros require the */
2866 /* variable "name" to be defined in */
2867 /* the context in which they execute */
2875 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2881 error("No symbol file currently specified; use command symbol-file");
2883 if (pst->ldsymlen || pst->number_of_dependencies)
2885 /* Print the message now, before reading the string table,
2886 to avoid disconcerting pauses. */
2889 printf_filtered ("Reading in symbols for %s...", pst->filename);
2893 /* Open symbol file and read in string table */
2894 if (stat (name, &statbuf) < 0)
2895 perror_with_name (name);
2896 desc = open(name, O_RDONLY, 0); /* symbol_file_command
2897 guarrantees that the symbol file name
2898 will be absolute, so there is no
2901 old_chain = make_cleanup (close, desc);
2904 error("Symbol file not readable");
2906 READ_FILE_HEADERS (desc, name);
2908 /* Read in the string table */
2909 lseek (desc, STRING_TABLE_OFFSET, L_SET);
2910 READ_STRING_TABLE_SIZE (stsize);
2911 if (stsize >= 0 && stsize < statbuf.st_size)
2913 #ifdef BROKEN_LARGE_ALLOCA
2914 stringtab = (char *) xmalloc (stsize);
2915 make_cleanup (free, stringtab);
2917 stringtab = (char *) alloca (stsize);
2922 if (stringtab == NULL)
2923 error ("ridiculous string table size: %d bytes", stsize);
2925 /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer.
2926 Occaisionally, it won't. */
2927 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
2929 perror_with_name (name);
2930 val = myread (desc, stringtab, stsize);
2932 perror_with_name (name);
2934 psymtab_to_symtab_1 (pst, desc, stringtab, stsize,
2935 SYMBOL_TABLE_OFFSET);
2937 /* Match with global symbols. This only needs to be done once,
2938 after all of the symtabs and dependencies have been read in. */
2939 scan_file_globals ();
2941 do_cleanups (old_chain);
2943 /* Finish up the debug error message. */
2945 printf_filtered ("done.\n");
2948 /* Search through list for correct name. */
2949 for (result = symtab_list; result; result = result->next)
2950 if (!strcmp (result->filename, pst->filename))
2957 * Scan through all of the global symbols defined in the object file,
2958 * assigning values to the debugging symbols that need to be assigned
2959 * to. Get these symbols from the misc function list.
2962 scan_file_globals ()
2967 for (mf = 0; mf < misc_function_count; mf++)
2969 char *namestring = misc_function_vector[mf].name;
2970 struct symbol *sym, *prev;
2974 prev = (struct symbol *) 0;
2976 /* Get the hash index and check all the symbols
2977 under that hash index. */
2979 hash = hashname (namestring);
2981 for (sym = global_sym_chain[hash]; sym;)
2983 if (*namestring == SYMBOL_NAME (sym)[0]
2984 && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1))
2986 /* Splice this symbol out of the hash chain and
2987 assign the value we have to it. */
2989 SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym);
2991 global_sym_chain[hash]
2992 = (struct symbol *) SYMBOL_VALUE (sym);
2994 /* Check to see whether we need to fix up a common block. */
2995 /* Note: this code might be executed several times for
2996 the same symbol if there are multiple references. */
2997 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2998 fix_common_block (sym, misc_function_vector[mf].address);
3000 SYMBOL_VALUE (sym) = misc_function_vector[mf].address;
3003 sym = (struct symbol *) SYMBOL_VALUE (prev);
3005 sym = global_sym_chain[hash];
3010 sym = (struct symbol *) SYMBOL_VALUE (sym);
3017 * Read in a defined section of a specific object file's symbols.
3019 * DESC is the file descriptor for the file, positioned at the
3020 * beginning of the symtab
3021 * STRINGTAB is a pointer to the files string
3022 * table, already read in
3023 * SYM_OFFSET is the offset within the file of
3024 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
3025 * number of symbols to read
3026 * TEXT_OFFSET is the offset to be added to
3027 * all values of symbols coming in and
3028 * TEXT_SIZE is the size of the text segment read in.
3029 * OFFSET is a flag which indicates that the value of all of the
3030 * symbols should be offset by TEXT_OFFSET (for the purposes of
3031 * incremental linking).
3035 read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
3036 sym_size, text_offset, text_size, offset)
3038 register char *stringtab;
3045 register char *namestring;
3046 register struct symbol *sym, *prev;
3048 struct cleanup *old_chain;
3055 stringtab_global = stringtab;
3056 last_source_file = 0;
3058 symtab_input_desc = desc;
3059 symbuf_end = symbuf_idx = 0;
3061 /* It is necessary to actually read one symbol *before* the start
3062 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
3063 occurs before the N_SO symbol.
3065 Detecting this in read_dbx_symtab
3066 would slow down initial readin, so we look for it here instead. */
3067 if (sym_offset >= sizeof (struct nlist))
3069 lseek (desc, sym_offset - sizeof (struct nlist), L_INCR);
3071 bufp = &symbuf[symbuf_idx++];
3073 if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size)
3074 error ("Invalid symbol data: bad string table offset: %d",
3076 namestring = bufp->n_un.n_strx + stringtab;
3078 processing_gcc_compilation =
3079 (bufp->n_type == N_TEXT
3080 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL));
3084 /* The N_SO starting this symtab is the first symbol, so we
3085 better not check the symbol before it. I'm not this can
3086 happen, but it doesn't hurt to check for it. */
3087 lseek(desc, sym_offset, L_INCR);
3088 processing_gcc_compilation = 0;
3091 if (symbuf_idx == symbuf_end)
3093 bufp = &symbuf[symbuf_idx];
3094 if ((unsigned char) bufp->n_type != N_SO)
3095 fatal("First symbol in segment of executable not a source symbol");
3098 symnum < sym_size / sizeof(struct nlist);
3101 QUIT; /* Allow this to be interruptable */
3102 if (symbuf_idx == symbuf_end)
3104 bufp = &symbuf[symbuf_idx++];
3105 type = bufp->n_type;
3108 (type == N_TEXT || type == N_DATA || type == N_BSS))
3109 bufp->n_value += text_offset;
3111 if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size)
3112 error ("Invalid symbol data: bad string table offset: %d",
3114 namestring = bufp->n_un.n_strx + stringtab;
3117 process_one_symbol(type, bufp->n_desc,
3118 bufp->n_value, namestring);
3119 /* We skip checking for a new .o or -l file; that should never
3120 happen in this routine. */
3121 else if (type == N_TEXT
3122 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
3123 /* I don't think this code will ever be executed, because
3124 the GCC_COMPILED_FLAG_SYMBOL usually is right before
3125 the N_SO symbol which starts this source file.
3126 However, there is no reason not to accept
3127 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
3128 processing_gcc_compilation = 1;
3129 else if (type & N_EXT || type == N_TEXT
3134 /* Global symbol: see if we came across a dbx defintion for
3135 a corresponding symbol. If so, store the value. Remove
3136 syms from the chain when their values are stored, but
3137 search the whole chain, as there may be several syms from
3138 different files with the same name. */
3139 /* This is probably not true. Since the files will be read
3140 in one at a time, each reference to a global symbol will
3141 be satisfied in each file as it appears. So we skip this
3143 &stringtab_global; /* For debugger; am I right? */
3145 end_symtab (text_offset + text_size);
3152 register char *p = name;
3153 register int total = p[0];
3166 /* Ensure result is positive. */
3167 if (total < 0) total += (1000 << 6);
3168 return total % HASHSIZE;
3171 /* Put all appropriate global symbols in the symseg data
3172 onto the hash chains so that their addresses will be stored
3173 when seen later in loader global symbols. */
3178 /* Look at each symbol in each block in each symseg symtab. */
3180 for (s = symseg_chain; s; s = s->next)
3183 for (n = BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)) - 1; n >= 0; n--)
3185 register struct block *b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), n);
3187 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
3189 register struct symbol *sym = BLOCK_SYM (b, i);
3191 /* Put the symbol on a chain if its value is an address
3192 that is figured out by the loader. */
3194 if (SYMBOL_CLASS (sym) == LOC_EXTERNAL)
3196 register int hash = hashname (SYMBOL_NAME (sym));
3197 SYMBOL_VALUE (sym) = (int) global_sym_chain[hash];
3198 global_sym_chain[hash] = sym;
3199 SYMBOL_CLASS (sym) = LOC_STATIC;
3207 process_one_symbol (type, desc, value, name)
3212 register struct context_stack *new;
3215 /* Something is wrong if we see real data before
3216 seeing a source file name. */
3218 if (last_source_file == 0 && type != N_SO)
3220 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
3221 where that code is defined. */
3222 if (IGNORE_SYMBOL (type))
3225 error ("Invalid symbol data: does not start by identifying a source file.");
3232 /* Either of these types of symbols indicates the start of
3233 a new function. We must process its "name" normally for dbx,
3234 but also record the start of a new lexical context, and possibly
3235 also the end of the lexical context for the previous function. */
3236 /* This is not always true. This type of symbol may indicate a
3237 text segment variable. */
3239 colon_pos = index (name, ':');
3241 || (*colon_pos != 'f' && *colon_pos != 'F'))
3243 define_symbol (value, name, desc);
3247 within_function = 1;
3248 if (context_stack_depth > 0)
3250 new = &context_stack[--context_stack_depth];
3251 /* Make a block for the local symbols within. */
3252 finish_block (new->name, &local_symbols, new->old_blocks,
3253 new->start_addr, value);
3255 /* Stack must be empty now. */
3256 if (context_stack_depth != 0)
3257 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
3260 new = &context_stack[context_stack_depth++];
3261 new->old_blocks = pending_blocks;
3262 new->start_addr = value;
3263 new->name = define_symbol (value, name, desc);
3268 /* This "symbol" just indicates the start of an inner lexical
3269 context within a function. */
3271 if (context_stack_depth == context_stack_size)
3273 context_stack_size *= 2;
3274 context_stack = (struct context_stack *)
3275 xrealloc (context_stack,
3277 * sizeof (struct context_stack)));
3280 new = &context_stack[context_stack_depth++];
3282 new->locals = local_symbols;
3283 new->old_blocks = pending_blocks;
3284 new->start_addr = value;
3290 /* This "symbol" just indicates the end of an inner lexical
3291 context that was started with N_LBRAC. */
3292 new = &context_stack[--context_stack_depth];
3293 if (desc != new->depth)
3294 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum);
3296 /* Some native compilers put the variable decls inside of an
3297 LBRAC/RBRAC block. This macro should be nonzero if this
3298 is true. DESC is N_DESC from the N_RBRAC symbol. */
3299 #if !defined (VARIABLES_INSIDE_BLOCK)
3300 #define VARIABLES_INSIDE_BLOCK(desc) 0
3303 /* Can only use new->locals as local symbols here if we're in
3304 gcc or on a machine that puts them before the lbrack. */
3305 if (!VARIABLES_INSIDE_BLOCK(desc))
3306 local_symbols = new->locals;
3308 /* If this is not the outermost LBRAC...RBRAC pair in the
3309 function, its local symbols preceded it, and are the ones
3310 just recovered from the context stack. Defined the block for them.
3312 If this is the outermost LBRAC...RBRAC pair, there is no
3313 need to do anything; leave the symbols that preceded it
3314 to be attached to the function's own block. However, if
3315 it is so, we need to indicate that we just moved outside
3318 && context_stack_depth > !VARIABLES_INSIDE_BLOCK(desc))
3320 /* Muzzle a compiler bug that makes end < start. */
3321 if (new->start_addr > value)
3322 new->start_addr = value;
3323 /* Make a block for the local symbols within. */
3324 finish_block (0, &local_symbols, new->old_blocks,
3325 new->start_addr + last_source_start_addr,
3326 value + last_source_start_addr);
3330 within_function = 0;
3332 if (VARIABLES_INSIDE_BLOCK(desc))
3333 /* Now pop locals of block just finished. */
3334 local_symbols = new->locals;
3338 /* This kind of symbol supposedly indicates the start
3339 of an object file. In fact this type does not appear. */
3343 /* This type of symbol indicates the start of data
3344 for one source file.
3345 Finish the symbol table of the previous source file
3346 (if any) and start accumulating a new symbol table. */
3347 #ifdef PCC_SOL_BROKEN
3348 /* pcc bug, occasionally puts out SO for SOL. */
3349 if (context_stack_depth > 0)
3351 start_subfile (name);
3355 if (last_source_file)
3357 start_symtab (name, value);
3361 /* This type of symbol indicates the start of data for
3362 a sub-source-file, one whose contents were copied or
3363 included in the compilation of the main source file
3364 (whose name was given in the N_SO symbol.) */
3365 start_subfile (name);
3371 add_new_header_file (name, value);
3372 start_subfile (name);
3376 start_subfile (pop_subfile ());
3380 add_old_header_file (name, value);
3382 #endif /* have N_BINCL */
3385 /* This type of "symbol" really just records
3386 one line-number -- core-address correspondence.
3387 Enter it in the line list for this symbol table. */
3388 record_line (desc, value);
3393 error ("Invalid symbol data: common within common at symtab pos %d",
3395 common_block = local_symbols;
3396 common_block_i = local_symbols ? local_symbols->nsyms : 0;
3400 /* Symbols declared since the BCOMM are to have the common block
3401 start address added in when we know it. common_block points to
3402 the first symbol after the BCOMM in the local_symbols list;
3403 copy the list and hang it off the symbol for the common block name
3407 struct pending *link = local_symbols;
3408 struct symbol *sym =
3409 (struct symbol *) xmalloc (sizeof (struct symbol));
3410 bzero (sym, sizeof *sym);
3411 SYMBOL_NAME (sym) = savestring (name, strlen (name));
3412 SYMBOL_CLASS (sym) = LOC_BLOCK;
3413 SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
3414 copy_pending (local_symbols, common_block_i, common_block));
3415 i = hashname (SYMBOL_NAME (sym));
3416 SYMBOL_VALUE (sym) = (int) global_sym_chain[i];
3417 global_sym_chain[i] = sym;
3428 define_symbol (value, name, desc);
3432 /* This function was added for C++ functionality. I presume that it
3433 condenses the bunches formed by reading in an additional .o file
3434 (incremental linking). */
3437 condense_addl_misc_bunches ()
3440 register struct misc_bunch *bunch;
3441 #ifdef NAMES_HAVE_UNDERSCORE
3447 misc_function_vector
3448 = (struct misc_function *) xrealloc (misc_function_vector,
3449 (misc_count + misc_function_count) * sizeof (struct misc_function));
3451 j = misc_function_count;
3455 for (i = 0; i < misc_bunch_index; i++)
3457 misc_function_vector[j] = bunch->contents[i];
3458 misc_function_vector[j].name
3459 = concat (misc_function_vector[j].name
3460 + (misc_function_vector[j].name[0] == '_' ? offset : 0),
3464 bunch = bunch->next;
3465 misc_bunch_index = MISC_BUNCH_SIZE;
3468 misc_function_count += misc_count;
3470 /* Sort the misc functions by address. */
3472 qsort (misc_function_vector, misc_function_count,
3473 sizeof (struct misc_function), compare_misc_functions);
3477 /* Read in another .o file and create a symtab entry for it.*/
3480 read_addl_syms (desc, stringtab, nlistlen, text_addr, text_size)
3482 register char *stringtab;
3483 register int nlistlen;
3487 FILE *stream = fdopen (desc, "r");
3488 register char *namestring;
3489 register struct symbol *sym, *prev;
3496 last_source_file = 0;
3497 bzero (global_sym_chain, sizeof global_sym_chain);
3498 symtab_input_desc = desc;
3499 stringtab_global = stringtab;
3502 for (symnum = 0; symnum < nlistlen; symnum++)
3507 QUIT; /* allow this to be interruptable */
3508 if (symbuf_idx == symbuf_end)
3510 bufp = &symbuf[symbuf_idx++];
3511 type = bufp->n_type & N_TYPE;
3512 namestring = bufp->n_un.n_strx + stringtab;
3514 if( (type == N_TEXT) || (type == N_DATA) || (type == N_BSS) )
3516 /* Relocate this file's symbol table information
3517 to the address it has been loaded into. */
3518 bufp->n_value += text_addr;
3521 type = bufp->n_type;
3524 process_one_symbol (type, bufp->n_desc,
3525 bufp->n_value, namestring);
3526 /* A static text symbol whose name ends in ".o"
3527 can only mean the start of another object file.
3528 So end the symtab of the source file we have been processing.
3529 This is how we avoid counting the libraries as part
3530 or the last source file.
3531 Also this way we find end of first object file (crt0). */
3532 else if ((type == N_TEXT
3537 && (!strcmp (namestring + strlen (namestring) - 2, ".o"))
3538 || ! strncmp (namestring, "-l", 2))
3540 if (last_source_file)
3541 end_symtab (bufp->n_value);
3543 else if (type & N_EXT || type == N_TEXT
3551 /* Record the location of _etext. */
3552 if (type == (N_TEXT | N_EXT)
3553 && !strcmp (namestring, "_etext"))
3554 end_of_text_addr = bufp->n_value;
3557 /* 25 Sep 89: The following seems to be stolen from
3558 read_ofile_symtab, and is wrong here (i.e. there was no
3559 first pass for add-file symbols). */
3560 /* This shouldn't be necessary, as we now do all of this work
3561 in scan_global syms and all misc functions should have been
3562 recorded on the first pass. */
3563 /* Global symbol: see if we came across a dbx definition
3564 for a corresponding symbol. If so, store the value.
3565 Remove syms from the chain when their values are stored,
3566 but search the whole chain, as there may be several syms
3567 from different files with the same name. */
3571 #ifdef NAMES_HAVE_UNDERSCORE
3572 hash = hashname (namestring + 1);
3573 #else /* not NAMES_HAVE_UNDERSCORE */
3574 hash = hashname (namestring);
3575 #endif /* not NAMES_HAVE_UNDERSCORE */
3576 for (sym = global_sym_chain[hash];
3580 #ifdef NAMES_HAVE_UNDERSCORE
3582 && namestring[1] == SYMBOL_NAME (sym)[0]
3584 !strcmp (namestring + 2, SYMBOL_NAME (sym) + 1)
3585 #else /* NAMES_HAVE_UNDERSCORE */
3586 namestring[0] == SYMBOL_NAME (sym)[0]
3588 !strcmp (namestring + 1, SYMBOL_NAME (sym) + 1)
3589 #endif /* NAMES_HAVE_UNDERSCORE */
3593 SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym);
3595 global_sym_chain[hash]
3596 = (struct symbol *) SYMBOL_VALUE (sym);
3597 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3598 fix_common_block (sym, bufp->n_value);
3600 SYMBOL_VALUE (sym) = bufp->n_value;
3602 sym = (struct symbol *) SYMBOL_VALUE (prev);
3604 sym = global_sym_chain[hash];
3611 sym = (struct symbol *) SYMBOL_VALUE (sym);
3616 /* Defined global or text symbol: record as a misc function
3617 if it didn't give its address to a debugger symbol above. */
3618 if (type <= (N_TYPE | N_EXT)
3621 record_misc_function (namestring, bufp->n_value,
3627 if (last_source_file)
3628 end_symtab (text_addr + text_size);
3634 This function allows the addition of incrementally linked object files.
3635 Since this has a fair amount of code in common with symbol_file_command,
3636 it might be worthwhile to consolidate things, as was done with
3637 read_dbx_symtab and condense_misc_bunches. */
3640 add_file_command (arg_string)
3644 DECLARE_FILE_HEADERS;
3645 struct nlist *nlist;
3649 extern void close ();
3650 struct cleanup *old_chain;
3651 struct symtab *symseg;
3652 struct stat statbuf;
3656 if (arg_string == 0)
3657 error ("add-file takes a file name and an address");
3659 arg_string = tilde_expand (arg_string);
3660 make_cleanup (free, arg_string);
3662 for( ; *arg_string == ' '; arg_string++ );
3664 for( ; *arg_string && *arg_string != ' ' ; arg_string++ );
3665 *arg_string++ = (char) 0;
3668 error ("add-file takes a file name and an address");
3670 text_addr = parse_and_eval_address (arg_string);
3674 if (!query ("add symbol table from filename \"%s\" at text_addr = 0x%x\n",
3676 error ("Not confirmed.");
3678 desc = open (name, O_RDONLY);
3680 perror_with_name (name);
3682 old_chain = make_cleanup (close, desc);
3684 READ_FILE_HEADERS (desc, name);
3686 if (NUMBER_OF_SYMBOLS == 0)
3688 printf ("%s does not have a symbol-table.\n", name);
3693 printf ("Reading symbol data from %s...", name);
3696 /* Now read the string table, all at once. */
3697 val = lseek (desc, STRING_TABLE_OFFSET, 0);
3699 perror_with_name (name);
3700 if (stat (name, &statbuf) < 0)
3701 perror_with_name (name);
3702 READ_STRING_TABLE_SIZE (buffer);
3703 if (buffer >= 0 && buffer < statbuf.st_size)
3705 #ifdef BROKEN_LARGE_ALLOCA
3706 stringtab = (char *) xmalloc (buffer);
3707 make_cleanup (free, stringtab);
3709 stringtab = (char *) alloca (buffer);
3714 if (stringtab == NULL)
3715 error ("ridiculous string table size: %d bytes", buffer);
3717 /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer.
3718 Occaisionally, it won't. */
3719 val = lseek (desc, STRING_TABLE_OFFSET, 0);
3721 perror_with_name (name);
3722 val = myread (desc, stringtab, buffer);
3724 perror_with_name (name);
3726 /* Symsegs are no longer supported by GDB. Setting symseg_chain to
3727 0 is easier than finding all the symseg code and eliminating it. */
3730 /* Position to read the symbol table. Do not read it all at once. */
3731 val = lseek (desc, SYMBOL_TABLE_OFFSET, 0);
3733 perror_with_name (name);
3735 init_misc_functions ();
3736 make_cleanup (discard_misc_bunches, 0);
3737 init_header_files ();
3738 make_cleanup (free_header_files, 0);
3743 make_cleanup (really_free_pendings, 0);
3745 read_addl_syms (desc, stringtab, NUMBER_OF_SYMBOLS, text_addr,
3746 SIZE_OF_TEXT_SEGMENT);
3749 /* Sort symbols alphabetically within each block. */
3753 /* Go over the misc functions and install them in vector. */
3755 condense_addl_misc_bunches (1);
3757 /* Don't allow char * to have a typename (else would get caddr_t.) */
3759 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
3761 do_cleanups (old_chain);
3763 /* Free the symtabs made by read_symsegs, but not their contents,
3764 which have been copied into symtabs on symtab_list. */
3765 while (symseg_chain)
3767 register struct symtab *s = symseg_chain->next;
3768 free (symseg_chain);
3776 /* Read a number by which a type is referred to in dbx data,
3777 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
3778 Just a single number N is equivalent to (0,N).
3779 Return the two numbers by storing them in the vector TYPENUMS.
3780 TYPENUMS will then be used as an argument to dbx_lookup_type. */
3783 read_type_number (pp, typenums)
3785 register int *typenums;
3790 typenums[0] = read_number (pp, ',');
3791 typenums[1] = read_number (pp, ')');
3796 typenums[1] = read_number (pp, 0);
3802 static struct symbol *
3803 define_symbol (value, string, desc)
3808 register struct symbol *sym
3809 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
3810 char *p = (char *) index (string, ':');
3814 /* Ignore syms with empty names. */
3818 /* Ignore old-style symbols from cc -go */
3823 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
3824 /* Open-coded bcopy--saves function call time. */
3826 register char *p1 = string;
3827 register char *p2 = SYMBOL_NAME (sym);
3833 /* Determine the type of name being defined. */
3834 if ((*p >= '0' && *p <= '9') || *p == '(')
3839 /* c is a special case, not followed by a type-number.
3840 SYMBOL:c=iVALUE for an integer constant symbol.
3841 SYMBOL:c=rVALUE for a floating constant symbol.
3842 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3843 e.g. "b:c=e6,0" for "const b = blob1"
3844 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3848 error ("Invalid symbol data at symtab pos %d.", symnum);
3853 double d = atof (p);
3856 SYMBOL_TYPE (sym) = builtin_type_double;
3857 value = (char *) obstack_alloc (symbol_obstack, sizeof (double));
3858 bcopy (&d, value, sizeof (double));
3859 SYMBOL_VALUE_BYTES (sym) = value;
3860 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
3865 SYMBOL_TYPE (sym) = builtin_type_int;
3866 SYMBOL_VALUE (sym) = atoi (p);
3867 SYMBOL_CLASS (sym) = LOC_CONST;
3871 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3872 e.g. "b:c=e6,0" for "const b = blob1"
3873 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3877 read_type_number (&p, typenums);
3879 error ("Invalid symbol data: no comma in enum const symbol");
3881 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
3882 SYMBOL_VALUE (sym) = atoi (p);
3883 SYMBOL_CLASS (sym) = LOC_CONST;
3887 error ("Invalid symbol data at symtab pos %d.", symnum);
3889 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3890 add_symbol_to_list (sym, &file_symbols);
3894 /* Now usually comes a number that says which data type,
3895 and possibly more stuff to define the type
3896 (all of which is handled by read_type) */
3898 if (deftype == 'p' && *p == 'F')
3899 /* pF is a two-letter code that means a function parameter in Fortran.
3900 The type-number specifies the type of the return value.
3901 Translate it into a pointer-to-function type. */
3905 = lookup_pointer_type (lookup_function_type (read_type (&p)));
3909 struct type *type = read_type (&p);
3911 if ((deftype == 'F' || deftype == 'f')
3912 && TYPE_CODE (type) != TYPE_CODE_FUNC)
3913 SYMBOL_TYPE (sym) = lookup_function_type (type);
3915 SYMBOL_TYPE (sym) = type;
3921 SYMBOL_CLASS (sym) = LOC_BLOCK;
3922 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3923 add_symbol_to_list (sym, &file_symbols);
3927 SYMBOL_CLASS (sym) = LOC_BLOCK;
3928 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3929 add_symbol_to_list (sym, &global_symbols);
3933 /* For a class G (global) symbol, it appears that the
3934 value is not correct. It is necessary to search for the
3935 corresponding linker definition to find the value.
3936 These definitions appear at the end of the namelist. */
3937 i = hashname (SYMBOL_NAME (sym));
3938 SYMBOL_VALUE (sym) = (int) global_sym_chain[i];
3939 global_sym_chain[i] = sym;
3940 SYMBOL_CLASS (sym) = LOC_STATIC;
3941 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3942 add_symbol_to_list (sym, &global_symbols);
3945 /* This case is faked by a conditional above,
3946 when there is no code letter in the dbx data.
3947 Dbx data never actually contains 'l'. */
3949 SYMBOL_CLASS (sym) = LOC_LOCAL;
3950 SYMBOL_VALUE (sym) = value;
3951 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3952 add_symbol_to_list (sym, &local_symbols);
3956 SYMBOL_CLASS (sym) = LOC_ARG;
3957 SYMBOL_VALUE (sym) = value;
3958 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3959 add_symbol_to_list (sym, &local_symbols);
3961 /* If it's compiled, if it says `short', believe it. */
3962 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
3965 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
3966 /* This macro is defined on machines (e.g. sparc) where
3967 we should believe the type of a PCC 'short' argument,
3968 but shouldn't believe the address (the address is
3969 the address of the corresponding int). Note that
3970 this is only different from the BELIEVE_PCC_PROMOTION
3971 case on big-endian machines.
3973 My guess is that this correction, as opposed to changing
3974 the parameter to an 'int' (as done below, for PCC
3975 on most machines), is the right thing to do
3976 on all machines, but I don't want to risk breaking
3977 something that already works. On most PCC machines,
3978 the sparc problem doesn't come up because the calling
3979 function has to zero the top bytes (not knowing whether
3980 the called function wants an int or a short), so there
3981 is no practical difference between an int and a short
3982 (except perhaps what happens when the GDB user types
3983 "print short_arg = 0x10000;"). */
3984 if (SYMBOL_TYPE (sym) == builtin_type_char
3985 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
3986 SYMBOL_VALUE (sym) += 3;
3987 if (SYMBOL_TYPE (sym) == builtin_type_short
3988 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
3989 SYMBOL_VALUE (sym) += 2;
3992 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
3994 /* If PCC says a parameter is a short or a char,
3995 it is really an int. */
3996 if (SYMBOL_TYPE (sym) == builtin_type_char
3997 || SYMBOL_TYPE (sym) == builtin_type_short)
3998 SYMBOL_TYPE (sym) = builtin_type_int;
3999 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
4000 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
4001 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
4004 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
4007 SYMBOL_CLASS (sym) = LOC_REGPARM;
4008 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (value);
4009 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4010 add_symbol_to_list (sym, &local_symbols);
4014 SYMBOL_CLASS (sym) = LOC_REGISTER;
4015 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (value);
4016 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4017 add_symbol_to_list (sym, &local_symbols);
4021 /* Static symbol at top level of file */
4022 SYMBOL_CLASS (sym) = LOC_STATIC;
4023 SYMBOL_VALUE (sym) = value;
4024 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4025 add_symbol_to_list (sym, &file_symbols);
4029 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4030 SYMBOL_VALUE (sym) = value;
4031 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4032 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
4033 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
4034 TYPE_NAME (SYMBOL_TYPE (sym)) =
4035 obsavestring (SYMBOL_NAME (sym),
4036 strlen (SYMBOL_NAME (sym)));
4037 /* C++ vagaries: we may have a type which is derived from
4038 a base type which did not have its name defined when the
4039 derived class was output. We fill in the derived class's
4040 base part member's name here in that case. */
4041 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
4042 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
4043 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
4046 for (i = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)); i > 0; i--)
4047 if (TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) == 0)
4048 TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) =
4049 TYPE_NAME (TYPE_BASECLASS (SYMBOL_TYPE (sym), i));
4052 add_symbol_to_list (sym, &file_symbols);
4056 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4057 SYMBOL_VALUE (sym) = value;
4058 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
4059 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
4060 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
4061 TYPE_NAME (SYMBOL_TYPE (sym))
4063 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
4065 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
4066 ? "struct " : "union ")),
4068 add_symbol_to_list (sym, &file_symbols);
4072 /* Static symbol of local scope */
4073 SYMBOL_CLASS (sym) = LOC_STATIC;
4074 SYMBOL_VALUE (sym) = value;
4075 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4076 add_symbol_to_list (sym, &local_symbols);
4080 /* Reference parameter */
4081 SYMBOL_CLASS (sym) = LOC_REF_ARG;
4082 SYMBOL_VALUE (sym) = value;
4083 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4084 add_symbol_to_list (sym, &local_symbols);
4088 /* This is used by Sun FORTRAN for "function result value".
4089 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
4090 that Pascal uses it too, but when I tried it Pascal used
4091 "x:3" (local symbol) instead. */
4092 SYMBOL_CLASS (sym) = LOC_LOCAL;
4093 SYMBOL_VALUE (sym) = value;
4094 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4095 add_symbol_to_list (sym, &local_symbols);
4099 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
4104 /* What about types defined as forward references inside of a small lexical
4106 /* Add a type to the list of undefined types to be checked through
4107 once this file has been read in. */
4109 add_undefined_type (type)
4112 if (undef_types_length == undef_types_allocated)
4114 undef_types_allocated *= 2;
4115 undef_types = (struct type **)
4116 xrealloc (undef_types,
4117 undef_types_allocated * sizeof (struct type *));
4119 undef_types[undef_types_length++] = type;
4122 /* Add here something to go through each undefined type, see if it's
4123 still undefined, and do a full lookup if so. */
4125 cleanup_undefined_types ()
4127 struct type **type, *ntype;
4130 for (type = undef_types; type < undef_types + undef_types_length; type++)
4132 struct type *ntype = 0;
4133 /* Reasonable test to see if it's been defined since. */
4134 if (TYPE_NFIELDS (*type) == 0)
4136 struct pending *ppt;
4138 /* Name of the type, without "struct" or "union" */
4139 char *typename = TYPE_NAME (*type);
4141 if (!strncmp (typename, "struct ", 7))
4143 if (!strncmp (typename, "union ", 6))
4146 for (ppt = file_symbols; ppt; ppt = ppt->next)
4147 for (i = 0; i < ppt->nsyms; i++)
4149 struct symbol *sym = ppt->symbol[i];
4151 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4152 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4153 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
4155 && !strcmp (SYMBOL_NAME (sym), typename))
4156 bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type));
4160 /* It has been defined; don't mark it as a stub. */
4161 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
4163 undef_types_length = 0;
4168 /* Read a dbx type reference or definition;
4169 return the type that is meant.
4170 This can be just a number, in which case it references
4171 a type already defined and placed in type_vector.
4172 Or the number can be followed by an =, in which case
4173 it means to define a new type according to the text that
4181 register struct type *type = 0;
4188 /* Read type number if present. The type number may be omitted.
4189 for instance in a two-dimensional array declared with type
4190 "ar1;1;10;ar1;1;10;4". */
4191 if ((**pp >= '0' && **pp <= '9')
4194 read_type_number (pp, typenums);
4196 /* Detect random reference to type not yet defined.
4197 Allocate a type object but leave it zeroed. */
4199 return dbx_alloc_type (typenums);
4205 /* 'typenums=' not present, type is anonymous. Read and return
4206 the definition, but don't put it in the type vector. */
4207 typenums[0] = typenums[1] = -1;
4215 enum type_code code;
4217 /* Used to index through file_symbols. */
4218 struct pending *ppt;
4221 /* Name including "struct", etc. */
4224 /* Name without "struct", etc. */
4225 char *type_name_only;
4231 /* Set the type code according to the following letter. */
4235 code = TYPE_CODE_STRUCT;
4239 code = TYPE_CODE_UNION;
4243 code = TYPE_CODE_ENUM;
4247 error ("Bad type cross reference at symnum: %d.", symnum);
4250 to = type_name = (char *)
4251 obstack_alloc (symbol_obstack,
4253 ((char *) index (*pp, ':') - (*pp)) + 1));
4255 /* Copy the prefix. */
4257 while (*to++ = *from++)
4261 type_name_only = to;
4263 /* Copy the name. */
4265 while ((*to++ = *from++) != ':')
4269 /* Set the pointer ahead of the name which we just read. */
4273 /* The following hack is clearly wrong, because it doesn't
4274 check whether we are in a baseclass. I tried to reproduce
4275 the case that it is trying to fix, but I couldn't get
4276 g++ to put out a cross reference to a basetype. Perhaps
4277 it doesn't do it anymore. */
4278 /* Note: for C++, the cross reference may be to a base type which
4279 has not yet been seen. In this case, we skip to the comma,
4280 which will mark the end of the base class name. (The ':'
4281 at the end of the base class name will be skipped as well.)
4282 But sometimes (ie. when the cross ref is the last thing on
4283 the line) there will be no ','. */
4284 from = (char *) index (*pp, ',');
4290 /* Now check to see whether the type has already been declared. */
4291 /* This is necessary at least in the case where the
4292 program says something like
4294 The compiler puts out a cross-reference; we better find
4295 set the length of the structure correctly so we can
4296 set the length of the array. */
4297 for (ppt = file_symbols; ppt; ppt = ppt->next)
4298 for (i = 0; i < ppt->nsyms; i++)
4300 struct symbol *sym = ppt->symbol[i];
4302 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4303 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4304 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
4305 && !strcmp (SYMBOL_NAME (sym), type_name_only))
4307 obstack_free (symbol_obstack, type_name);
4308 type = SYMBOL_TYPE (sym);
4313 /* Didn't find the type to which this refers, so we must
4314 be dealing with a forward reference. Allocate a type
4315 structure for it, and keep track of it so we can
4316 fill in the rest of the fields when we get the full
4318 type = dbx_alloc_type (typenums);
4319 TYPE_CODE (type) = code;
4320 TYPE_NAME (type) = type_name;
4322 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
4324 add_undefined_type (type);
4340 read_type_number (pp, xtypenums);
4341 type = *dbx_lookup_type (xtypenums);
4343 type = builtin_type_void;
4344 if (typenums[0] != -1)
4345 *dbx_lookup_type (typenums) = type;
4349 type1 = read_type (pp);
4350 if (TYPE_POINTER_TYPE (type1))
4352 type = TYPE_POINTER_TYPE (type1);
4353 if (typenums[0] != -1)
4354 *dbx_lookup_type (typenums) = type;
4358 type = dbx_alloc_type (typenums);
4359 smash_to_pointer_type (type, type1);
4365 struct type *domain = read_type (pp);
4367 struct type *memtype;
4369 if (*(*pp)++ != ',')
4370 error ("invalid member type data format, at symtab pos %d.",
4373 memtype = read_type (pp);
4374 type = dbx_alloc_type (typenums);
4375 smash_to_member_type (type, domain, memtype);
4381 struct type *domain = read_type (pp);
4383 struct type *return_type;
4386 if (*(*pp)++ != ',')
4387 error ("invalid member type data format, at symtab pos %d.",
4390 return_type = read_type (pp);
4391 args = read_args (pp, ';');
4392 type = dbx_alloc_type (typenums);
4393 smash_to_method_type (type, domain, return_type, args);
4398 type1 = read_type (pp);
4399 if (TYPE_REFERENCE_TYPE (type1))
4401 type = TYPE_REFERENCE_TYPE (type1);
4402 if (typenums[0] != -1)
4403 *dbx_lookup_type (typenums) = type;
4407 type = dbx_alloc_type (typenums);
4408 smash_to_reference_type (type, type1);
4413 type1 = read_type (pp);
4414 if (TYPE_FUNCTION_TYPE (type1))
4416 type = TYPE_FUNCTION_TYPE (type1);
4417 if (typenums[0] != -1)
4418 *dbx_lookup_type (typenums) = type;
4422 type = dbx_alloc_type (typenums);
4423 smash_to_function_type (type, type1);
4428 type = read_range_type (pp, typenums);
4429 if (typenums[0] != -1)
4430 *dbx_lookup_type (typenums) = type;
4434 type = dbx_alloc_type (typenums);
4435 type = read_enum_type (pp, type);
4436 *dbx_lookup_type (typenums) = type;
4440 type = dbx_alloc_type (typenums);
4441 type = read_struct_type (pp, type);
4445 type = dbx_alloc_type (typenums);
4446 type = read_struct_type (pp, type);
4447 TYPE_CODE (type) = TYPE_CODE_UNION;
4451 if (*(*pp)++ != 'r')
4452 error ("Invalid symbol data: unrecognized type-code `a%c' %s %d.",
4453 (*pp)[-1], "at symtab position", symnum);
4455 type = dbx_alloc_type (typenums);
4456 type = read_array_type (pp, type);
4460 error ("Invalid symbol data: unrecognized type-code `%c' at symtab pos %d.",
4468 /* If this is an overriding temporary alteration for a header file's
4469 contents, and this type number is unknown in the global definition,
4470 put this type into the global definition at this type number. */
4471 if (header_file_prev_index >= 0)
4473 register struct type **tp
4474 = explicit_lookup_type (header_file_prev_index, typenums[1]);
4482 /* This page contains subroutines of read_type. */
4484 /* Read the description of a structure (or union type)
4485 and return an object describing the type. */
4487 static struct type *
4488 read_struct_type (pp, type)
4490 register struct type *type;
4494 struct nextfield *next;
4501 struct next_fnfield *next;
4503 struct fn_field fn_field;
4506 struct next_fnfieldlist
4508 struct next_fnfieldlist *next;
4509 struct fn_fieldlist fn_fieldlist;
4512 register struct nextfield *list = 0;
4513 struct nextfield *new;
4520 register struct next_fnfieldlist *mainlist = 0;
4522 int read_possible_virtual_info = 0;
4524 if (TYPE_MAIN_VARIANT (type) == 0)
4526 TYPE_MAIN_VARIANT (type) = type;
4529 TYPE_CODE (type) = TYPE_CODE_STRUCT;
4531 /* First comes the total size in bytes. */
4533 TYPE_LENGTH (type) = read_number (pp, 0);
4535 /* C++: Now, if the class is a derived class, then the next character
4536 will be a '!', followed by the number of base classes derived from.
4537 Each element in the list contains visibility information,
4538 the offset of this base class in the derived structure,
4539 and then the base type. */
4542 int i, n_baseclasses, offset;
4543 struct type **baseclass_vec;
4544 struct type *baseclass;
4547 /* Nonzero if it is a virtual baseclass, i.e.,
4551 struct C : public B, public virtual A {};
4553 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
4554 2.0 language feature. */
4559 n_baseclasses = read_number (pp, ',');
4560 baseclass_vec = (struct type **)
4561 obstack_alloc (symbol_obstack,
4562 (n_baseclasses) * sizeof (struct type **)) - 1;
4564 for (i = 1; i <= n_baseclasses; i++)
4567 *pp = next_symbol_text ();
4578 error ("Invalid symbol data: bad visibility format at symtab pos %d",
4591 error ("Invalid symbol data: bad visibility format at symtab pos %d.",
4595 /* Offset of the portion of the object corresponding to
4596 this baseclass. Always zero in the absence of
4597 multiple inheritance. */
4598 offset = read_number (pp, ',');
4599 baseclass = read_type (pp);
4600 *pp += 1; /* skip trailing ';' */
4604 static int error_printed = 0;
4609 "\nWarning: GDB has limited understanding of multiple inheritance...");
4615 baseclass_vec[i] = lookup_basetype_type (baseclass, offset, via_virtual, via_public);
4617 /* Since lookup_basetype_type can copy the type,
4618 it might copy a stub type (complete with stub flag).
4619 If so, we need to add it to the list of undefined types
4620 to clean up later. Even if lookup_basetype_type
4621 didn't copy the type, adding it to the undefined list
4622 will not do any harm. */
4623 if (TYPE_FLAGS(baseclass_vec[i]) & TYPE_FLAG_STUB)
4624 add_undefined_type (baseclass_vec[i]);
4626 /* Make this baseclass visible for structure-printing purposes. */
4627 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4630 list->field.type = baseclass_vec[i];
4631 list->field.name = TYPE_NAME (baseclass_vec[i]);
4632 list->field.bitpos = offset;
4633 list->field.bitsize = 0; /* this should be an unpacked field! */
4636 TYPE_N_BASECLASSES (type) = n_baseclasses;
4637 TYPE_BASECLASSES (type) = baseclass_vec;
4640 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
4641 At the end, we see a semicolon instead of a field.
4643 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
4646 The `?' is a placeholder for one of '+' (public visibility),
4647 '0' (protected visibility), and '-' (private visibility). */
4649 /* We better set p right now, in case there are no fields at all... */
4656 /* Check for and handle cretinous dbx symbol name continuation! */
4657 if (**pp == '\\') *pp = next_symbol_text ();
4659 /* Get space to record the next field's data. */
4660 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4664 /* Get the field name. */
4666 while (*p != ':') p++;
4667 list->field.name = obsavestring (*pp, p - *pp);
4669 /* C++: Check to see if we have hit the methods yet. */
4675 /* This means we have a visibility for a field coming. */
4696 /* else normal dbx-style format. */
4698 list->field.type = read_type (pp);
4701 list->field.bitpos = (long)-1;
4703 while (*p != ';') p++;
4704 list->field.bitsize = (long) savestring (*pp, p - *pp);
4709 else if (**pp != ',')
4710 error ("Invalid symbol data: bad structure-type format at symtab pos %d.",
4712 (*pp)++; /* Skip the comma. */
4713 list->field.bitpos = read_number (pp, ',');
4714 list->field.bitsize = read_number (pp, ';');
4717 /* This is wrong because this is identical to the symbols
4718 produced for GCC 0-size arrays. For example:
4723 The code which dumped core in such circumstances should be
4724 fixed not to dump core. */
4726 /* g++ -g0 can put out bitpos & bitsize zero for a static
4727 field. This does not give us any way of getting its
4728 class, so we can't know its name. But we can just
4729 ignore the field so we don't dump core and other nasty
4731 if (list->field.bitpos == 0
4732 && list->field.bitsize == 0)
4734 /* Have we given the warning yet? */
4735 static int warning_given = 0;
4737 /* Only give the warning once, no matter how many class
4738 variables there are. */
4742 fprintf_filtered (stderr, "\n\
4743 Warning: DBX-style class variable debugging information encountered.\n\
4744 You seem to have compiled your program with \
4745 \"g++ -g0\" instead of \"g++ -g\".\n\
4746 Therefore GDB will not know about your class variables.\n\
4750 /* Ignore this field. */
4756 /* Detect an unpacked field and mark it as such.
4757 dbx gives a bit size for all fields.
4758 Note that forward refs cannot be packed,
4759 and treat enums as if they had the width of ints. */
4760 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
4761 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
4762 list->field.bitsize = 0;
4763 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
4764 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
4765 && (list->field.bitsize
4766 == 8 * TYPE_LENGTH (builtin_type_int))
4770 list->field.bitpos % 8 == 0)
4771 list->field.bitsize = 0;
4776 /* Now come the method fields, as NAME::methods
4777 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
4778 At the end, we see a semicolon instead of a field.
4780 For the case of overloaded operators, the format is
4781 OPERATOR::*.methods, where OPERATOR is the string "operator",
4782 `*' holds the place for an operator name (such as `+=')
4783 and `.' marks the end of the operator name. */
4786 /* Now, read in the methods. To simplify matters, we
4787 "unread" the name that has been read, so that we can
4788 start from the top. */
4792 /* chill the list of fields: the last entry (at the head)
4793 is a partially constructed entry which we now scrub. */
4796 /* For each list of method lists... */
4800 struct next_fnfield *sublist = 0;
4801 struct fn_field *fn_fields = 0;
4803 struct next_fnfieldlist *new_mainlist =
4804 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
4806 /* read in the name. */
4807 while (*p != ':') p++;
4808 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == '$')
4810 static char opname[32] = "operator ";
4811 char *o = opname + 9;
4813 /* Skip past '::'. */
4817 new_mainlist->fn_fieldlist.name = savestring (opname, o - opname);
4824 new_mainlist->fn_fieldlist.name = savestring (*pp, p - *pp);
4825 /* Skip past '::'. */
4831 struct next_fnfield *new_sublist =
4832 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
4834 /* Check for and handle cretinous dbx symbol name continuation! */
4835 if (**pp == '\\') *pp = next_symbol_text ();
4837 new_sublist->fn_field.type = read_type (pp);
4839 error ("invalid symtab info for method at symbol number %d.",
4842 new_sublist->fn_field.args =
4843 TYPE_ARG_TYPES (new_sublist->fn_field.type);
4845 while (*p != ';') p++;
4846 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
4848 new_sublist->visibility = *(*pp)++ - '0';
4849 if (**pp == '\\') *pp = next_symbol_text ();
4854 /* virtual member function, followed by index. */
4855 new_sublist->fn_field.voffset = read_number (pp, ';') + 1;
4858 /* static member function. */
4859 new_sublist->fn_field.voffset = 1;
4863 /* normal member function. */
4864 new_sublist->fn_field.voffset = 0;
4868 new_sublist->next = sublist;
4869 sublist = new_sublist;
4872 while (**pp != ';');
4876 new_mainlist->fn_fieldlist.fn_fields =
4877 (struct fn_field *) obstack_alloc (symbol_obstack,
4878 sizeof (struct fn_field) * length);
4879 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
4880 (int *) obstack_alloc (symbol_obstack,
4881 sizeof (int) * (1 + (length >> 5)));
4883 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
4884 (int *) obstack_alloc (symbol_obstack,
4885 sizeof (int) * (1 + (length >> 5)));
4887 for (i = length; sublist; sublist = sublist->next)
4889 new_mainlist->fn_fieldlist.fn_fields[--i] = sublist->fn_field;
4890 if (sublist->visibility == 0)
4891 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
4892 else if (sublist->visibility == 1)
4893 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
4896 new_mainlist->fn_fieldlist.length = length;
4897 new_mainlist->next = mainlist;
4898 mainlist = new_mainlist;
4901 while (**pp != ';');
4906 /* Now create the vector of fields, and record how big it is. */
4908 TYPE_NFIELDS (type) = nfields;
4909 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
4910 sizeof (struct field) * nfields);
4911 TYPE_FIELD_PRIVATE_BITS (type) =
4912 (int *) obstack_alloc (symbol_obstack,
4913 sizeof (int) * (1 + (nfields >> 5)));
4914 TYPE_FIELD_PROTECTED_BITS (type) =
4915 (int *) obstack_alloc (symbol_obstack,
4916 sizeof (int) * (1 + (nfields >> 5)));
4918 TYPE_NFN_FIELDS (type) = nfn_fields;
4919 TYPE_NFN_FIELDS_TOTAL (type) = nfn_fields;
4923 for (i = 1; i <= TYPE_N_BASECLASSES (type); ++i)
4924 TYPE_NFN_FIELDS_TOTAL (type) +=
4925 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
4928 TYPE_FN_FIELDLISTS (type) =
4929 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
4930 sizeof (struct fn_fieldlist) * nfn_fields);
4932 /* Copy the saved-up fields into the field vector. */
4934 for (n = nfields; list; list = list->next)
4936 TYPE_FIELD (type, --n) = list->field;
4937 if (list->visibility == 0)
4938 SET_TYPE_FIELD_PRIVATE (type, n);
4939 else if (list->visibility == 1)
4940 SET_TYPE_FIELD_PROTECTED (type, n);
4943 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
4944 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
4953 |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
4956 else if (**pp == '+')
4958 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
4961 else if (**pp == '-')
4963 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
4967 /* Read either a '%' or the final ';'. */
4968 if (*(*pp)++ == '%')
4970 /* Now we must record the virtual function table pointer's
4971 field information. */
4978 while (*p != ';') p++;
4979 TYPE_VPTR_BASETYPE (type) = t;
4982 if (TYPE_FIELD_NAME (t, 0) == 0)
4983 TYPE_VPTR_FIELDNO (type) = i = 0;
4984 else for (i = TYPE_NFIELDS (t) - 1; i >= 0; --i)
4985 if (! strncmp (TYPE_FIELD_NAME (t, i), *pp,
4986 strlen (TYPE_FIELD_NAME (t, i))))
4988 TYPE_VPTR_FIELDNO (type) = i;
4992 error ("virtual function table field not found");
4995 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, 1));
5000 TYPE_VPTR_BASETYPE (type) = 0;
5001 TYPE_VPTR_FIELDNO (type) = -1;
5006 TYPE_VPTR_BASETYPE (type) = 0;
5007 TYPE_VPTR_FIELDNO (type) = -1;
5013 /* Read a definition of an array type,
5014 and create and return a suitable type object.
5015 Also creates a range type which represents the bounds of that
5017 static struct type *
5018 read_array_type (pp, type)
5020 register struct type *type;
5022 struct type *index_type, *element_type, *range_type;
5026 /* Format of an array type:
5027 "ar<index type>;lower;upper;<array_contents_type>". Put code in
5030 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
5031 for these, produce a type like float[][]. */
5033 index_type = read_type (pp);
5034 if (*(*pp)++ != ';')
5035 error ("Invalid symbol data; improper format of array type decl.");
5037 if (!(**pp >= '0' && **pp <= '9'))
5042 lower = read_number (pp, ';');
5044 if (!(**pp >= '0' && **pp <= '9'))
5049 upper = read_number (pp, ';');
5051 element_type = read_type (pp);
5060 /* Create range type. */
5061 range_type = (struct type *) obstack_alloc (symbol_obstack,
5062 sizeof (struct type));
5063 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
5064 TYPE_TARGET_TYPE (range_type) = index_type;
5066 /* This should never be needed. */
5067 TYPE_LENGTH (range_type) = sizeof (int);
5069 TYPE_NFIELDS (range_type) = 2;
5070 TYPE_FIELDS (range_type) =
5071 (struct field *) obstack_alloc (symbol_obstack,
5072 2 * sizeof (struct field));
5073 TYPE_FIELD_BITPOS (range_type, 0) = lower;
5074 TYPE_FIELD_BITPOS (range_type, 1) = upper;
5077 TYPE_CODE (type) = TYPE_CODE_ARRAY;
5078 TYPE_TARGET_TYPE (type) = element_type;
5079 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
5080 TYPE_NFIELDS (type) = 1;
5081 TYPE_FIELDS (type) =
5082 (struct field *) obstack_alloc (symbol_obstack,
5083 sizeof (struct field));
5084 TYPE_FIELD_TYPE (type, 0) = range_type;
5090 /* Read a definition of an enumeration type,
5091 and create and return a suitable type object.
5092 Also defines the symbols that represent the values of the type. */
5094 static struct type *
5095 read_enum_type (pp, type)
5097 register struct type *type;
5102 register struct symbol *sym;
5104 struct pending **symlist;
5105 struct pending *osyms, *syms;
5108 if (within_function)
5109 symlist = &local_symbols;
5111 symlist = &file_symbols;
5113 o_nsyms = osyms ? osyms->nsyms : 0;
5115 /* Read the value-names and their values.
5116 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
5117 A semicolon or comman instead of a NAME means the end. */
5118 while (**pp && **pp != ';' && **pp != ',')
5120 /* Check for and handle cretinous dbx symbol name continuation! */
5121 if (**pp == '\\') *pp = next_symbol_text ();
5124 while (*p != ':') p++;
5125 name = obsavestring (*pp, p - *pp);
5127 n = read_number (pp, ',');
5129 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
5130 bzero (sym, sizeof (struct symbol));
5131 SYMBOL_NAME (sym) = name;
5132 SYMBOL_CLASS (sym) = LOC_CONST;
5133 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
5134 SYMBOL_VALUE (sym) = n;
5135 add_symbol_to_list (sym, symlist);
5140 (*pp)++; /* Skip the semicolon. */
5142 /* Now fill in the fields of the type-structure. */
5144 TYPE_LENGTH (type) = sizeof (int);
5145 TYPE_CODE (type) = TYPE_CODE_ENUM;
5146 TYPE_NFIELDS (type) = nsyms;
5147 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
5149 /* Find the symbols for the values and put them into the type.
5150 The symbols can be found in the symlist that we put them on
5151 to cause them to be defined. osyms contains the old value
5152 of that symlist; everything up to there was defined by us. */
5153 /* Note that we preserve the order of the enum constants, so
5154 that in something like "enum {FOO, LAST_THING=FOO}" we print
5155 FOO, not LAST_THING. */
5157 for (syms = *symlist, n = 0; syms; syms = syms->next)
5162 for (; j < syms->nsyms; j++)
5164 struct symbol *sym = syms->symbol[j];
5165 SYMBOL_TYPE (sym) = type;
5166 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (sym);
5167 TYPE_FIELD_VALUE (type, n) = 0;
5168 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (sym);
5169 TYPE_FIELD_BITSIZE (type, n++) = 0;
5178 #define MAX_OF_TYPE(t) ((1 << (sizeof (t) - 1)) - 1)
5179 #define MIN_OF_TYPE(t) (-(1 << (sizeof (t) - 1)))
5181 static struct type *
5182 read_range_type (pp, typenums)
5190 struct type *result_type;
5192 /* First comes a type we are a subrange of.
5193 In C it is usually 0, 1 or the type being defined. */
5194 read_type_number (pp, rangenums);
5195 self_subrange = (rangenums[0] == typenums[0] &&
5196 rangenums[1] == typenums[1]);
5198 /* A semicolon should now follow; skip it. */
5202 /* The remaining two operands are usually lower and upper bounds
5203 of the range. But in some special cases they mean something else. */
5204 n2 = read_number (pp, ';');
5205 n3 = read_number (pp, ';');
5207 /* A type defined as a subrange of itself, with bounds both 0, is void. */
5208 if (self_subrange && n2 == 0 && n3 == 0)
5209 return builtin_type_void;
5211 /* If n3 is zero and n2 is not, we want a floating type,
5212 and n2 is the width in bytes.
5214 Fortran programs appear to use this for complex types also,
5215 and they give no way to distinguish between double and single-complex!
5216 We don't have complex types, so we would lose on all fortran files!
5217 So return type `double' for all of those. It won't work right
5218 for the complex values, but at least it makes the file loadable. */
5220 if (n3 == 0 && n2 > 0)
5222 if (n2 == sizeof (float))
5223 return builtin_type_float;
5224 return builtin_type_double;
5227 /* If the upper bound is -1, it must really be an unsigned int. */
5229 else if (n2 == 0 && n3 == -1)
5231 if (sizeof (int) == sizeof (long))
5232 return builtin_type_unsigned_int;
5234 return builtin_type_unsigned_long;
5237 /* Special case: char is defined (Who knows why) as a subrange of
5238 itself with range 0-127. */
5239 else if (self_subrange && n2 == 0 && n3 == 127)
5240 return builtin_type_char;
5242 /* Assumptions made here: Subrange of self is equivalent to subrange
5245 && (self_subrange ||
5246 *dbx_lookup_type (rangenums) == builtin_type_int))
5248 /* an unsigned type */
5250 if (n3 == - sizeof (long long))
5251 return builtin_type_unsigned_long_long;
5253 if (n3 == (1 << (8 * sizeof (int))) - 1)
5254 return builtin_type_unsigned_int;
5255 if (n3 == (1 << (8 * sizeof (short))) - 1)
5256 return builtin_type_unsigned_short;
5257 if (n3 == (1 << (8 * sizeof (char))) - 1)
5258 return builtin_type_unsigned_char;
5261 else if (n3 == 0 && n2 == -sizeof (long long))
5262 return builtin_type_long_long;
5264 else if (n2 == -n3 -1)
5267 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
5268 return builtin_type_int;
5269 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
5270 return builtin_type_long;
5271 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
5272 return builtin_type_short;
5273 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
5274 return builtin_type_char;
5277 /* We have a real range type on our hands. Allocate space and
5278 return a real pointer. */
5280 /* At this point I don't have the faintest idea how to deal with
5281 a self_subrange type; I'm going to assume that this is used
5282 as an idiom, and that all of them are special cases. So . . . */
5284 error ("Type defined as subrange of itself.");
5286 result_type = (struct type *) obstack_alloc (symbol_obstack,
5287 sizeof (struct type));
5288 bzero (result_type, sizeof (struct type));
5290 TYPE_TARGET_TYPE (result_type) = (self_subrange ?
5292 *dbx_lookup_type(rangenums));
5294 /* We have to figure out how many bytes it takes to hold this
5295 range type. I'm going to assume that anything that is pushing
5296 the bounds of a long was taken care of above. */
5297 if (n2 >= MIN_OF_TYPE(char) && n3 <= MAX_OF_TYPE(char))
5298 TYPE_LENGTH (result_type) = 1;
5299 else if (n2 >= MIN_OF_TYPE(short) && n3 <= MAX_OF_TYPE(short))
5300 TYPE_LENGTH (result_type) = sizeof (short);
5301 else if (n2 >= MIN_OF_TYPE(int) && n3 <= MAX_OF_TYPE(int))
5302 TYPE_LENGTH (result_type) = sizeof (int);
5303 else if (n2 >= MIN_OF_TYPE(long) && n3 <= MAX_OF_TYPE(long))
5304 TYPE_LENGTH (result_type) = sizeof (long);
5306 error ("Ranged type doesn't fit within known sizes.");
5308 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
5309 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
5310 TYPE_NFIELDS (result_type) = 2;
5311 TYPE_FIELDS (result_type) =
5312 (struct field *) obstack_alloc (symbol_obstack,
5313 2 * sizeof (struct field));
5314 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
5315 TYPE_FIELD_BITPOS (result_type, 0) = n2;
5316 TYPE_FIELD_BITPOS (result_type, 1) = n3;
5321 /* Read a number from the string pointed to by *PP.
5322 The value of *PP is advanced over the number.
5323 If END is nonzero, the character that ends the
5324 number must match END, or an error happens;
5325 and that character is skipped if it does match.
5326 If END is zero, *PP is left pointing to that character. */
5329 read_number (pp, end)
5333 register char *p = *pp;
5334 register long n = 0;
5338 /* Handle an optional leading minus sign. */
5346 /* Read the digits, as far as they go. */
5348 while ((c = *p++) >= '0' && c <= '9')
5356 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
5365 /* Read in an argument list. This is a list of types. It is terminated with
5366 a ':', FYI. Return the list of types read in. */
5367 static struct type **
5372 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
5378 error ("Invalid argument list: no ',', at symtab pos %d", symnum);
5381 /* Check for and handle cretinous dbx symbol name continuation! */
5383 *pp = next_symbol_text ();
5385 types[n++] = read_type (pp);
5387 *pp += 1; /* get past `end' (the ':' character) */
5391 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
5393 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
5395 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
5396 bzero (rval + n, sizeof (struct type *));
5400 rval = (struct type **) xmalloc (n * sizeof (struct type *));
5402 bcopy (types, rval, n * sizeof (struct type *));
5406 /* This function is really horrible, but to avoid it, there would need
5407 to be more filling in of forward references. THIS SHOULD BE MOVED OUT
5408 OF COFFREAD.C AND DBXREAD.C TO SOME PLACE WHERE IT CAN BE SHARED */
5410 fill_in_vptr_fieldno (type)
5413 if (TYPE_VPTR_FIELDNO (type) < 0)
5414 TYPE_VPTR_FIELDNO (type) =
5415 fill_in_vptr_fieldno (TYPE_BASECLASS (type, 1));
5416 return TYPE_VPTR_FIELDNO (type);
5419 /* Copy a pending list, used to record the contents of a common
5420 block for later fixup. */
5421 static struct pending *
5422 copy_pending (beg, begi, end)
5423 struct pending *beg, *end;
5426 struct pending *new = 0;
5427 struct pending *next;
5429 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
5430 next = next->next, begi = 0)
5433 for (j = begi; j < next->nsyms; j++)
5434 add_symbol_to_list (next->symbol[j], &new);
5439 /* Add a common block's start address to the offset of each symbol
5440 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5441 the common block name). */
5444 fix_common_block (sym, value)
5448 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
5449 for ( ; next; next = next->next)
5452 for (j = next->nsyms - 1; j >= 0; j--)
5453 SYMBOL_VALUE (next->symbol[j]) += value;
5458 _initialize_dbxread ()
5461 header_files = (struct header_file *) 0;
5462 this_object_header_files = (int *) 0;
5464 undef_types_allocated = 20;
5465 undef_types_length = 0;
5466 undef_types = (struct type **) xmalloc (undef_types_allocated *
5467 sizeof (struct type *));
5469 add_com ("symbol-file", class_files, symbol_file_command,
5470 "Load symbol table (in dbx format) from executable file FILE.");
5472 add_com ("add-file", class_files, add_file_command,
5473 "Load the symbols from FILE, assuming its code is at TEXT_START.") ;
5476 #endif /* READ_DBX_FORMAT */