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. */
22 #ifdef READ_DBX_FORMAT
25 #include <sys/types.h>
31 #ifdef COFF_ENCAPSULATE
32 #include "a.out.encap.h"
42 * Define specifically gnu symbols here.
45 /* The following type indicates the definition of a symbol as being
46 an indirect reference to another symbol. The other symbol
47 appears as an undefined reference, immediately following this symbol.
49 Indirection is asymmetrical. The other symbol's value will be used
50 to satisfy requests for the indirect symbol, but not vice versa.
51 If the other symbol does not have a definition, libraries will
52 be searched to find a definition. */
57 /* The following symbols refer to set elements.
58 All the N_SET[ATDB] symbols with the same name form one set.
59 Space is allocated for the set in the text section, and each set
60 element's value is stored into one word of the space.
61 The first word of the space is the length of the set (number of elements).
63 The address of the set is made into an N_SETV symbol
64 whose name is the same as the name of the set.
65 This symbol acts like a N_DATA global symbol
66 in that it can satisfy undefined external references. */
69 #define N_SETA 0x14 /* Absolute set element symbol */
70 #endif /* This is input to LD, in a .o file. */
73 #define N_SETT 0x16 /* Text set element symbol */
74 #endif /* This is input to LD, in a .o file. */
77 #define N_SETD 0x18 /* Data set element symbol */
78 #endif /* This is input to LD, in a .o file. */
81 #define N_SETB 0x1A /* Bss set element symbol */
82 #endif /* This is input to LD, in a .o file. */
84 /* Macros dealing with the set element symbols defined in a.out.h */
85 #define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
86 #define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS)
89 #define N_SETV 0x1C /* Pointer to set vector in data area. */
90 #endif /* This is output from LD. */
93 #define N_WARNING 0x1E /* Warning message to print if file included */
94 #endif /* This is input to ld */
98 /* Line number for the data section. This is to be used to describe
99 the source location of a variable declaration. */
101 #define N_DSLINE (N_SLINE+N_DATA-N_TEXT)
104 /* Line number for the bss section. This is to be used to describe
105 the source location of a variable declaration. */
107 #define N_BSLINE (N_SLINE+N_BSS-N_TEXT)
110 #endif /* not __GNU_STAB__ */
111 #endif /* NO_GNU_STABS */
115 #include <sys/param.h>
116 #include <sys/file.h>
117 #include <sys/stat.h>
123 #define AOUTHDR struct exec
127 static void add_symbol_to_list ();
128 static void read_dbx_symtab ();
129 static void process_one_symbol ();
130 static void free_all_psymbols ();
131 static struct type *read_type ();
132 static struct type *read_range_type ();
133 static struct type *read_enum_type ();
134 static struct type *read_struct_type ();
135 static struct type *read_array_type ();
136 static long read_number ();
137 static void finish_block ();
138 static struct blockvector *make_blockvector ();
139 static struct symbol *define_symbol ();
140 static void start_subfile ();
141 static int hashname ();
142 static void hash_symsegs ();
143 static struct pending *copy_pending ();
144 static void fix_common_block ();
146 static void add_undefined_type ();
147 static void cleanup_undefined_types ();
149 extern char *index();
151 extern struct symtab *read_symsegs ();
152 extern void free_all_symtabs ();
153 extern void free_all_psymtabs ();
154 extern void free_inclink_symtabs ();
157 static struct type **read_args ();
159 /* Macro to determine which symbols to ignore when reading the first symbol
160 of a file. Some machines override this definition. */
162 #ifndef IGNORE_SYMBOL
163 /* This code is used on Ultrix systems. Ignore it */
164 #define IGNORE_SYMBOL(type) (type == N_NSYMS)
167 #ifndef IGNORE_SYMBOL
168 /* Don't ignore any symbols. */
169 #define IGNORE_SYMBOL(type) (0)
171 #endif /* not N_NSYMS */
173 /* Macro for number of symbol table entries (in usual a.out format).
174 Some machines override this definition. */
175 #ifndef NUMBER_OF_SYMBOLS
177 #define NUMBER_OF_SYMBOLS \
178 ((COFF_HEADER(hdr) ? hdr.coffhdr.filehdr.f_nsyms : hdr.a_syms) / \
179 sizeof (struct nlist))
181 #define NUMBER_OF_SYMBOLS (hdr.a_syms / sizeof (struct nlist))
185 /* Macro for file-offset of symbol table (in usual a.out format). */
186 #ifndef SYMBOL_TABLE_OFFSET
187 #define SYMBOL_TABLE_OFFSET N_SYMOFF (hdr)
190 /* Macro for file-offset of string table (in usual a.out format). */
191 #ifndef STRING_TABLE_OFFSET
192 #define STRING_TABLE_OFFSET (N_SYMOFF (hdr) + hdr.a_syms)
195 /* Macro to store the length of the string table data in INTO. */
196 #ifndef READ_STRING_TABLE_SIZE
197 #define READ_STRING_TABLE_SIZE(INTO) \
198 { val = myread (desc, &INTO, sizeof INTO); \
199 if (val < 0) perror_with_name (name); }
202 /* Macro to declare variables to hold the file's header data. */
203 #ifndef DECLARE_FILE_HEADERS
204 #define DECLARE_FILE_HEADERS AOUTHDR hdr
207 /* Macro to read the header data from descriptor DESC and validate it.
208 NAME is the file name, for error messages. */
209 #ifndef READ_FILE_HEADERS
210 #ifdef HEADER_SEEK_FD
211 #define READ_FILE_HEADERS(DESC, NAME) \
212 { HEADER_SEEK_FD (DESC); \
213 val = myread (DESC, &hdr, sizeof hdr); \
214 if (val < 0) perror_with_name (NAME); \
215 if (N_BADMAG (hdr)) \
216 error ("File \"%s\" not in executable format.", NAME); }
218 #define READ_FILE_HEADERS(DESC, NAME) \
219 { val = myread (DESC, &hdr, sizeof hdr); \
220 if (val < 0) perror_with_name (NAME); \
221 if (N_BADMAG (hdr)) \
222 error ("File \"%s\" not in executable format.", NAME); }
226 /* Non-zero if this is an object (.o) file, rather than an executable.
227 Distinguishing between the two is rarely necessary (and seems like
228 a hack, but there is no other way to do ADDR_OF_TEXT_SEGMENT
230 #if !defined (IS_OBJECT_FILE)
231 /* This will not work
232 if someone decides to make ld preserve relocation info. */
233 #define IS_OBJECT_FILE (hdr.a_trsize != 0)
236 /* Macro for size of text segment */
237 #ifndef SIZE_OF_TEXT_SEGMENT
238 #define SIZE_OF_TEXT_SEGMENT hdr.a_text
241 /* Get the address in debugged memory of the start
242 of the text segment. */
243 #if !defined (ADDR_OF_TEXT_SEGMENT)
244 #if defined (N_TXTADDR)
245 #define ADDR_OF_TEXT_SEGMENT (IS_OBJECT_FILE ? 0 : N_TXTADDR (hdr))
246 #else /* no N_TXTADDR */
247 #define ADDR_OF_TEXT_SEGMENT 0
248 #endif /* no N_TXTADDR */
249 #endif /* no ADDR_OF_TEXT_SEGMENT */
251 /* Macro to get entry point from headers. */
253 #define ENTRY_POINT hdr.a_entry
256 /* Macro for name of symbol to indicate a file compiled with gcc. */
257 #ifndef GCC_COMPILED_FLAG_SYMBOL
258 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
261 /* Convert stab register number (from `r' declaration) to a gdb REGNUM. */
263 #ifndef STAB_REG_TO_REGNUM
264 #define STAB_REG_TO_REGNUM(VALUE) (VALUE)
267 /* Define this as 1 if a pcc declaration of a char or short argument
268 gives the correct address. Otherwise assume pcc gives the
269 address of the corresponding int, which is not the same on a
270 big-endian machine. */
272 #ifndef BELIEVE_PCC_PROMOTION
273 #define BELIEVE_PCC_PROMOTION 0
276 /* Nonzero means give verbose info on gdb action. From main.c. */
277 extern int info_verbose;
279 /* Chain of symtabs made from reading the file's symsegs.
280 These symtabs do not go into symtab_list themselves,
281 but the information is copied from them when appropriate
282 to make the symtabs that will exist permanently. */
284 static struct symtab *symseg_chain;
286 /* Symseg symbol table for the file whose data we are now processing.
287 It is one of those in symseg_chain. Or 0, for a compilation that
290 static struct symtab *current_symseg;
292 /* Name of source file whose symbol data we are now processing.
293 This comes from a symbol of type N_SO. */
295 static char *last_source_file;
297 /* Core address of start of text of current source file.
298 This too comes from the N_SO symbol. */
300 static CORE_ADDR last_source_start_addr;
302 /* End of the text segment of the executable file,
303 as found in the symbol _etext. */
305 static CORE_ADDR end_of_text_addr;
307 /* The list of sub-source-files within the current individual compilation.
308 Each file gets its own symtab with its own linetable and associated info,
309 but they all share one blockvector. */
313 struct subfile *next;
315 struct linetable *line_vector;
316 int line_vector_length;
317 int line_vector_index;
318 int prev_line_number;
321 static struct subfile *subfiles;
323 static struct subfile *current_subfile;
325 /* Count symbols as they are processed, for error messages. */
329 /* Vector of types defined so far, indexed by their dbx type numbers.
330 (In newer sun systems, dbx uses a pair of numbers in parens,
331 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
332 translated through the type_translations hash table to get
333 the index into the type vector.) */
335 static struct typevector *type_vector;
337 /* Number of elements allocated for type_vector currently. */
339 static int type_vector_length;
341 /* Vector of line number information. */
343 static struct linetable *line_vector;
345 /* Index of next entry to go in line_vector_index. */
347 static int line_vector_index;
349 /* Last line number recorded in the line vector. */
351 static int prev_line_number;
353 /* Number of elements allocated for line_vector currently. */
355 static int line_vector_length;
357 /* Hash table of global symbols whose values are not known yet.
358 They are chained thru the SYMBOL_VALUE, since we don't
359 have the correct data for that slot yet. */
360 /* The use of the LOC_BLOCK code in this chain is nonstandard--
361 it refers to a FORTRAN common block rather than the usual meaning. */
364 static struct symbol *global_sym_chain[HASHSIZE];
366 /* Record the symbols defined for each context in a list.
367 We don't create a struct block for the context until we
368 know how long to make it. */
370 #define PENDINGSIZE 100
374 struct pending *next;
376 struct symbol *symbol[PENDINGSIZE];
379 /* List of free `struct pending' structures for reuse. */
380 struct pending *free_pendings;
382 /* Here are the three lists that symbols are put on. */
384 struct pending *file_symbols; /* static at top level, and types */
386 struct pending *global_symbols; /* global functions and variables */
388 struct pending *local_symbols; /* everything local to lexical context */
390 /* List of symbols declared since the last BCOMM. This list is a tail
391 of local_symbols. When ECOMM is seen, the symbols on the list
392 are noted so their proper addresses can be filled in later,
393 using the common block base address gotten from the assembler
396 struct pending *common_block;
399 /* Stack representing unclosed lexical contexts
400 (that will become blocks, eventually). */
404 struct pending *locals;
405 struct pending_block *old_blocks;
407 CORE_ADDR start_addr;
411 struct context_stack *context_stack;
413 /* Index of first unused entry in context stack. */
414 int context_stack_depth;
416 /* Currently allocated size of context stack. */
418 int context_stack_size;
420 /* Nonzero if within a function (so symbols should be local,
421 if nothing says specifically). */
425 /* List of blocks already made (lexical contexts already closed).
426 This is used at the end to make the blockvector. */
430 struct pending_block *next;
434 struct pending_block *pending_blocks;
436 extern CORE_ADDR startup_file_start; /* From blockframe.c */
437 extern CORE_ADDR startup_file_end; /* From blockframe.c */
439 /* File name symbols were loaded from. */
441 static char *symfile;
443 /* Low and high symbol values (inclusive) for the global variable
444 entries in the symbol file. */
446 static int first_global_sym, last_global_sym;
448 /* Structures with which to manage partial symbol allocation. */
450 struct psymbol_allocation_list global_psymbols, static_psymbols;
452 /* Global variable which, when set, indicates that we are processing a
453 .o file compiled with gcc */
455 static unsigned char processing_gcc_compilation;
457 /* Make a list of forward references which haven't been defined. */
458 static struct type **undef_types;
459 static int undef_types_allocated, undef_types_length;
461 /* Setup a define to deal cleanly with the underscore problem */
463 #ifdef NAMES_HAVE_UNDERSCORE
464 #define HASH_OFFSET 1
466 #define HASH_OFFSET 0
475 fprintf (stderr, "Virtual memory exhausted.\n");
481 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
482 (and add a null character at the end in the copy).
483 Returns the address of the copy. */
486 obsavestring (ptr, size)
490 register char *p = (char *) obstack_alloc (symbol_obstack, size + 1);
491 /* Open-coded bcopy--saves function call time.
492 These strings are usually short. */
494 register char *p1 = ptr;
495 register char *p2 = p;
496 char *end = ptr + size;
504 /* Concatenate strings S1, S2 and S3; return the new string.
505 Space is found in the symbol_obstack. */
508 obconcat (s1, s2, s3)
511 register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
512 register char *val = (char *) obstack_alloc (symbol_obstack, len);
519 /* Support for Sun changes to dbx symbol format */
521 /* For each identified header file, we have a table of types defined
524 header_files maps header file names to their type tables.
525 It is a vector of n_header_files elements.
526 Each element describes one header file.
527 It contains a vector of types.
529 Sometimes it can happen that the same header file produces
530 different results when included in different places.
531 This can result from conditionals or from different
532 things done before including the file.
533 When this happens, there are multiple entries for the file in this table,
534 one entry for each distinct set of results.
535 The entries are distinguished by the INSTANCE field.
536 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
537 used to match header-file references to their corresponding data. */
541 char *name; /* Name of header file */
542 int instance; /* Numeric code distinguishing instances
543 of one header file that produced
544 different results when included.
545 It comes from the N_BINCL or N_EXCL. */
546 struct type **vector; /* Pointer to vector of types */
547 int length; /* Allocated length (# elts) of that vector */
550 static struct header_file *header_files;
552 static int n_header_files;
554 static int n_allocated_header_files;
556 /* During initial symbol readin, we need to have a structure to keep
557 track of which psymtabs have which bincls in them. This structure
558 is used during readin to setup the list of dependencies within each
559 partial symbol table. */
561 struct header_file_location
563 char *name; /* Name of header file */
564 int instance; /* See above */
565 struct partial_symtab *pst; /* Partial symtab that has the
566 BINCL/EINCL defs for this file */
569 /* The actual list and controling variables */
570 static struct header_file_location *bincl_list, *next_bincl;
571 static int bincls_allocated;
573 /* Within each object file, various header files are assigned numbers.
574 A type is defined or referred to with a pair of numbers
575 (FILENUM,TYPENUM) where FILENUM is the number of the header file
576 and TYPENUM is the number within that header file.
577 TYPENUM is the index within the vector of types for that header file.
579 FILENUM == 1 is special; it refers to the main source of the object file,
580 and not to any header file. FILENUM != 1 is interpreted by looking it up
581 in the following table, which contains indices in header_files. */
583 static int *this_object_header_files;
585 static int n_this_object_header_files;
587 static int n_allocated_this_object_header_files;
589 /* When a header file is getting special overriding definitions
590 for one source file, record here the header_files index
591 of its normal definition vector.
592 At other times, this is -1. */
594 static int header_file_prev_index;
596 /* At the start of reading dbx symbols, allocate our tables. */
601 n_allocated_header_files = 10;
602 header_files = (struct header_file *) xxmalloc (10 * sizeof (struct header_file));
605 n_allocated_this_object_header_files = 10;
606 this_object_header_files = (int *) xxmalloc (10 * sizeof (int));
609 /* At the end of reading dbx symbols, free our tables. */
615 for (i = 0; i < n_header_files; i++)
616 free (header_files[i].name);
617 if (header_files) free (header_files);
618 if (this_object_header_files)
619 free (this_object_header_files);
622 /* Called at the start of each object file's symbols.
623 Clear out the mapping of header file numbers to header files. */
626 new_object_header_files ()
628 /* Leave FILENUM of 0 free for builtin types and this file's types. */
629 n_this_object_header_files = 1;
630 header_file_prev_index = -1;
633 /* Add header file number I for this object file
634 at the next successive FILENUM. */
637 add_this_object_header_file (i)
640 if (n_this_object_header_files == n_allocated_this_object_header_files)
642 n_allocated_this_object_header_files *= 2;
643 this_object_header_files
644 = (int *) xrealloc (this_object_header_files,
645 n_allocated_this_object_header_files * sizeof (int));
648 this_object_header_files[n_this_object_header_files++] = i;
651 /* Add to this file an "old" header file, one already seen in
652 a previous object file. NAME is the header file's name.
653 INSTANCE is its instance code, to select among multiple
654 symbol tables for the same header file. */
657 add_old_header_file (name, instance)
661 register struct header_file *p = header_files;
664 for (i = 0; i < n_header_files; i++)
665 if (!strcmp (p[i].name, name) && instance == p[i].instance)
667 add_this_object_header_file (i);
670 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
674 /* Add to this file a "new" header file: definitions for its types follow.
675 NAME is the header file's name.
676 Most often this happens only once for each distinct header file,
677 but not necessarily. If it happens more than once, INSTANCE has
678 a different value each time, and references to the header file
679 use INSTANCE values to select among them.
681 dbx output contains "begin" and "end" markers for each new header file,
682 but at this level we just need to know which files there have been;
683 so we record the file when its "begin" is seen and ignore the "end". */
686 add_new_header_file (name, instance)
691 register struct header_file *p = header_files;
692 header_file_prev_index = -1;
695 /* This code was used before I knew about the instance codes.
696 My first hypothesis is that it is not necessary now
697 that instance codes are handled. */
699 /* Has this header file a previous definition?
700 If so, make a new entry anyway so that this use in this source file
701 gets a separate entry. Later source files get the old entry.
702 Record here the index of the old entry, so that any type indices
703 not previously defined can get defined in the old entry as
704 well as in the new one. */
706 for (i = 0; i < n_header_files; i++)
707 if (!strcmp (p[i].name, name))
709 header_file_prev_index = i;
714 /* Make sure there is room for one more header file. */
716 if (n_header_files == n_allocated_header_files)
718 n_allocated_header_files *= 2;
719 header_files = (struct header_file *)
720 xrealloc (header_files,
721 (n_allocated_header_files
722 * sizeof (struct header_file)));
725 /* Create an entry for this header file. */
727 i = n_header_files++;
728 header_files[i].name = savestring (name, strlen(name));
729 header_files[i].instance = instance;
730 header_files[i].length = 10;
731 header_files[i].vector
732 = (struct type **) xxmalloc (10 * sizeof (struct type *));
733 bzero (header_files[i].vector, 10 * sizeof (struct type *));
735 add_this_object_header_file (i);
738 /* Look up a dbx type-number pair. Return the address of the slot
739 where the type for that number-pair is stored.
740 The number-pair is in TYPENUMS.
742 This can be used for finding the type associated with that pair
743 or for associating a new type with the pair. */
745 static struct type **
746 dbx_lookup_type (typenums)
749 register int filenum = typenums[0], index = typenums[1];
751 if (filenum < 0 || filenum >= n_this_object_header_files)
752 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
753 filenum, index, symnum);
757 /* Type is defined outside of header files.
758 Find it in this object file's type vector. */
759 if (index >= type_vector_length)
761 type_vector_length *= 2;
762 type_vector = (struct typevector *)
763 xrealloc (type_vector,
764 (sizeof (struct typevector)
765 + type_vector_length * sizeof (struct type *)));
766 bzero (&type_vector->type[type_vector_length / 2],
767 type_vector_length * sizeof (struct type *) / 2);
769 return &type_vector->type[index];
773 register int real_filenum = this_object_header_files[filenum];
774 register struct header_file *f;
776 if (real_filenum >= n_header_files)
779 f = &header_files[real_filenum];
781 if (index >= f->length)
784 f->vector = (struct type **)
785 xrealloc (f->vector, f->length * sizeof (struct type *));
786 bzero (&f->vector[f->length / 2],
787 f->length * sizeof (struct type *) / 2);
789 return &f->vector[index];
793 /* Create a type object. Occaisionally used when you need a type
794 which isn't going to be given a type number. */
799 register struct type *type =
800 (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type));
802 bzero (type, sizeof (struct type));
803 TYPE_VPTR_FIELDNO (type) = -1;
807 /* Make sure there is a type allocated for type numbers TYPENUMS
808 and return the type object.
809 This can create an empty (zeroed) type object.
810 TYPENUMS may be (-1, -1) to return a new type object that is not
811 put into the type vector, and so may not be referred to by number. */
814 dbx_alloc_type (typenums)
817 register struct type **type_addr;
818 register struct type *type;
820 if (typenums[1] != -1)
822 type_addr = dbx_lookup_type (typenums);
831 /* If we are referring to a type not known at all yet,
832 allocate an empty type for it.
833 We will fill it in later if we find out how. */
836 type = dbx_create_type ();
845 static struct type **
846 explicit_lookup_type (real_filenum, index)
847 int real_filenum, index;
849 register struct header_file *f = &header_files[real_filenum];
851 if (index >= f->length)
854 f->vector = (struct type **)
855 xrealloc (f->vector, f->length * sizeof (struct type *));
856 bzero (&f->vector[f->length / 2],
857 f->length * sizeof (struct type *) / 2);
859 return &f->vector[index];
863 /* maintain the lists of symbols and blocks */
865 /* Add a symbol to one of the lists of symbols. */
867 add_symbol_to_list (symbol, listhead)
868 struct symbol *symbol;
869 struct pending **listhead;
871 /* We keep PENDINGSIZE symbols in each link of the list.
872 If we don't have a link with room in it, add a new link. */
873 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
875 register struct pending *link;
878 link = free_pendings;
879 free_pendings = link->next;
882 link = (struct pending *) xxmalloc (sizeof (struct pending));
884 link->next = *listhead;
889 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
892 /* At end of reading syms, or in case of quit,
893 really free as many `struct pending's as we can easily find. */
896 really_free_pendings ()
898 struct pending *next, *next1;
899 struct pending_block *bnext, *bnext1;
901 for (next = free_pendings; next; next = next1)
908 for (bnext = pending_blocks; bnext; bnext = bnext1)
910 bnext1 = bnext->next;
915 for (next = file_symbols; next; next = next1)
920 for (next = global_symbols; next; next = next1)
927 /* Take one of the lists of symbols and make a block from it.
928 Keep the order the symbols have in the list (reversed from the input file).
929 Put the block on the list of pending blocks. */
932 finish_block (symbol, listhead, old_blocks, start, end)
933 struct symbol *symbol;
934 struct pending **listhead;
935 struct pending_block *old_blocks;
936 CORE_ADDR start, end;
938 register struct pending *next, *next1;
939 register struct block *block;
940 register struct pending_block *pblock;
941 struct pending_block *opblock;
944 /* Count the length of the list of symbols. */
946 for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next);
948 block = (struct block *) obstack_alloc (symbol_obstack,
949 (sizeof (struct block)
951 * sizeof (struct symbol *))));
953 /* Copy the symbols into the block. */
955 BLOCK_NSYMS (block) = i;
956 for (next = *listhead; next; next = next->next)
959 for (j = next->nsyms - 1; j >= 0; j--)
960 BLOCK_SYM (block, --i) = next->symbol[j];
963 BLOCK_START (block) = start;
964 BLOCK_END (block) = end;
965 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
966 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
968 /* Put the block in as the value of the symbol that names it. */
972 SYMBOL_BLOCK_VALUE (symbol) = block;
973 BLOCK_FUNCTION (block) = symbol;
976 BLOCK_FUNCTION (block) = 0;
978 /* Now "free" the links of the list, and empty the list. */
980 for (next = *listhead; next; next = next1)
983 next->next = free_pendings;
984 free_pendings = next;
988 /* Install this block as the superblock
989 of all blocks made since the start of this scope
990 that don't have superblocks yet. */
993 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
995 if (BLOCK_SUPERBLOCK (pblock->block) == 0)
996 BLOCK_SUPERBLOCK (pblock->block) = block;
1000 /* Record this block on the list of all blocks in the file.
1001 Put it after opblock, or at the beginning if opblock is 0.
1002 This puts the block in the list after all its subblocks. */
1004 /* Allocate in the symbol_obstack to save time.
1005 It wastes a little space. */
1006 pblock = (struct pending_block *)
1007 obstack_alloc (symbol_obstack,
1008 sizeof (struct pending_block));
1009 pblock->block = block;
1012 pblock->next = opblock->next;
1013 opblock->next = pblock;
1017 pblock->next = pending_blocks;
1018 pending_blocks = pblock;
1022 static struct blockvector *
1025 register struct pending_block *next, *next1;
1026 register struct blockvector *blockvector;
1029 /* Count the length of the list of blocks. */
1031 for (next = pending_blocks, i = 0; next; next = next->next, i++);
1033 blockvector = (struct blockvector *)
1034 obstack_alloc (symbol_obstack,
1035 (sizeof (struct blockvector)
1036 + (i - 1) * sizeof (struct block *)));
1038 /* Copy the blocks into the blockvector.
1039 This is done in reverse order, which happens to put
1040 the blocks into the proper order (ascending starting address).
1041 finish_block has hair to insert each block into the list
1042 after its subblocks in order to make sure this is true. */
1044 BLOCKVECTOR_NBLOCKS (blockvector) = i;
1045 for (next = pending_blocks; next; next = next->next)
1046 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
1048 #if 0 /* Now we make the links in the obstack, so don't free them. */
1049 /* Now free the links of the list, and empty the list. */
1051 for (next = pending_blocks; next; next = next1)
1062 /* Manage the vector of line numbers. */
1065 record_line (line, pc)
1069 struct linetable_entry *e;
1070 /* Ignore the dummy line number in libg.o */
1075 /* Make sure line vector is big enough. */
1077 if (line_vector_index + 1 >= line_vector_length)
1079 line_vector_length *= 2;
1080 line_vector = (struct linetable *)
1081 xrealloc (line_vector,
1082 (sizeof (struct linetable)
1083 + line_vector_length * sizeof (struct linetable_entry)));
1084 current_subfile->line_vector = line_vector;
1087 e = line_vector->item + line_vector_index++;
1088 e->line = line; e->pc = pc;
1091 /* Start a new symtab for a new source file.
1092 This is called when a dbx symbol of type N_SO is seen;
1093 it indicates the start of data for one original source file. */
1096 start_symtab (name, start_addr)
1098 CORE_ADDR start_addr;
1100 register struct symtab *s;
1102 last_source_file = name;
1103 last_source_start_addr = start_addr;
1106 within_function = 0;
1108 /* Context stack is initially empty, with room for 10 levels. */
1110 = (struct context_stack *) xxmalloc (10 * sizeof (struct context_stack));
1111 context_stack_size = 10;
1112 context_stack_depth = 0;
1114 new_object_header_files ();
1116 for (s = symseg_chain; s; s = s->next)
1117 if (s->ldsymoff == symnum * sizeof (struct nlist))
1123 type_vector_length = 160;
1124 type_vector = (struct typevector *)
1125 xxmalloc (sizeof (struct typevector)
1126 + type_vector_length * sizeof (struct type *));
1127 bzero (type_vector->type, type_vector_length * sizeof (struct type *));
1129 /* Initialize the list of sub source files with one entry
1130 for this file (the top-level source file). */
1133 current_subfile = 0;
1134 start_subfile (name);
1136 #if 0 /* This is now set at the beginning of read_ofile_symtab */
1137 /* Set default for compiler to pcc; assume that we aren't processing
1138 a gcc compiled file until proved otherwise. */
1140 processing_gcc_compilation = 0;
1144 /* Handle an N_SOL symbol, which indicates the start of
1145 code that came from an included (or otherwise merged-in)
1146 source file with a different name. */
1149 start_subfile (name)
1152 register struct subfile *subfile;
1154 /* Save the current subfile's line vector data. */
1156 if (current_subfile)
1158 current_subfile->line_vector_index = line_vector_index;
1159 current_subfile->line_vector_length = line_vector_length;
1160 current_subfile->prev_line_number = prev_line_number;
1163 /* See if this subfile is already known as a subfile of the
1164 current main source file. */
1166 for (subfile = subfiles; subfile; subfile = subfile->next)
1168 if (!strcmp (subfile->name, name))
1170 line_vector = subfile->line_vector;
1171 line_vector_index = subfile->line_vector_index;
1172 line_vector_length = subfile->line_vector_length;
1173 prev_line_number = subfile->prev_line_number;
1174 current_subfile = subfile;
1179 /* This subfile is not known. Add an entry for it. */
1181 line_vector_index = 0;
1182 line_vector_length = 1000;
1183 prev_line_number = -2; /* Force first line number to be explicit */
1184 line_vector = (struct linetable *)
1185 xxmalloc (sizeof (struct linetable)
1186 + line_vector_length * sizeof (struct linetable_entry));
1188 /* Make an entry for this subfile in the list of all subfiles
1189 of the current main source file. */
1191 subfile = (struct subfile *) xxmalloc (sizeof (struct subfile));
1192 subfile->next = subfiles;
1193 subfile->name = savestring (name, strlen (name));
1194 subfile->line_vector = line_vector;
1196 current_subfile = subfile;
1199 /* Finish the symbol definitions for one main source file,
1200 close off all the lexical contexts for that file
1201 (creating struct block's for them), then make the struct symtab
1202 for that file and put it in the list of all such.
1204 END_ADDR is the address of the end of the file's text. */
1207 end_symtab (end_addr)
1210 register struct symtab *symtab;
1211 register struct blockvector *blockvector;
1212 register struct subfile *subfile;
1213 register struct linetable *lv;
1214 struct subfile *nextsub;
1216 if (current_symseg != 0)
1218 last_source_file = 0;
1223 /* Finish the lexical context of the last function in the file;
1224 pop the context stack. */
1226 if (context_stack_depth > 0)
1228 register struct context_stack *cstk;
1229 context_stack_depth--;
1230 cstk = &context_stack[context_stack_depth];
1231 /* Make a block for the local symbols within. */
1232 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
1233 cstk->start_addr, end_addr);
1236 /* Cleanup any undefined types that have been left hanging around
1237 (this needs to be done before the finish_blocks so that
1238 file_symbols is still good). */
1239 cleanup_undefined_types ();
1241 /* Finish defining all the blocks of this symtab. */
1242 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
1243 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
1244 blockvector = make_blockvector ();
1246 current_subfile->line_vector_index = line_vector_index;
1248 /* Now create the symtab objects proper, one for each subfile. */
1249 /* (The main file is one of them.) */
1251 for (subfile = subfiles; subfile; subfile = nextsub)
1253 symtab = (struct symtab *) xxmalloc (sizeof (struct symtab));
1254 symtab->free_ptr = 0;
1256 /* Fill in its components. */
1257 symtab->blockvector = blockvector;
1258 type_vector->length = type_vector_length;
1259 symtab->typevector = type_vector;
1260 symtab->free_code = free_linetable;
1261 if (subfile->next == 0)
1262 symtab->free_ptr = (char *) type_vector;
1264 symtab->filename = subfile->name;
1265 lv = subfile->line_vector;
1266 lv->nitems = subfile->line_vector_index;
1267 symtab->linetable = (struct linetable *)
1268 xrealloc (lv, (sizeof (struct linetable)
1269 + lv->nitems * sizeof (struct linetable_entry)));
1271 symtab->line_charpos = 0;
1273 /* Link the new symtab into the list of such. */
1274 symtab->next = symtab_list;
1275 symtab_list = symtab;
1277 nextsub = subfile->next;
1282 type_vector_length = -1;
1284 line_vector_length = -1;
1285 last_source_file = 0;
1290 /* Handle the N_BINCL and N_EINCL symbol types
1291 that act like N_SOL for switching source files
1292 (different subfiles, as we call them) within one object file,
1293 but using a stack rather than in an arbitrary order. */
1295 struct subfile_stack
1297 struct subfile_stack *next;
1302 struct subfile_stack *subfile_stack;
1307 register struct subfile_stack *tem
1308 = (struct subfile_stack *) xxmalloc (sizeof (struct subfile_stack));
1310 tem->next = subfile_stack;
1311 subfile_stack = tem;
1312 if (current_subfile == 0 || current_subfile->name == 0)
1314 tem->name = current_subfile->name;
1315 tem->prev_index = header_file_prev_index;
1321 register char *name;
1322 register struct subfile_stack *link = subfile_stack;
1328 subfile_stack = link->next;
1329 header_file_prev_index = link->prev_index;
1334 #endif /* Have N_BINCL */
1336 /* Accumulate the misc functions in bunches of 127.
1337 At the end, copy them all into one newly allocated structure. */
1339 #define MISC_BUNCH_SIZE 127
1343 struct misc_bunch *next;
1344 struct misc_function contents[MISC_BUNCH_SIZE];
1347 /* Bunch currently being filled up.
1348 The next field points to chain of filled bunches. */
1350 static struct misc_bunch *misc_bunch;
1352 /* Number of slots filled in current bunch. */
1354 static int misc_bunch_index;
1356 /* Total number of misc functions recorded so far. */
1358 static int misc_count;
1361 init_misc_functions ()
1365 misc_bunch_index = MISC_BUNCH_SIZE;
1369 record_misc_function (name, address, type)
1374 register struct misc_bunch *new;
1376 if (misc_bunch_index == MISC_BUNCH_SIZE)
1378 new = (struct misc_bunch *) xxmalloc (sizeof (struct misc_bunch));
1379 misc_bunch_index = 0;
1380 new->next = misc_bunch;
1383 misc_bunch->contents[misc_bunch_index].name = name;
1384 misc_bunch->contents[misc_bunch_index].address = address;
1385 misc_bunch->contents[misc_bunch_index].type = (unsigned char)
1386 (type == (N_TEXT | N_EXT) ? mf_text :
1387 (type == (N_DATA | N_EXT)
1389 || type == (N_SETV | N_EXT)
1392 type == (N_BSS | N_EXT) ? mf_bss :
1393 type == (N_ABS | N_EXT) ? mf_abs : mf_unknown);
1399 compare_misc_functions (fn1, fn2)
1400 struct misc_function *fn1, *fn2;
1402 /* Return a signed result based on unsigned comparisons
1403 so that we sort into unsigned numeric order. */
1404 if (fn1->address < fn2->address)
1406 if (fn1->address > fn2->address)
1412 discard_misc_bunches ()
1414 register struct misc_bunch *next;
1418 next = misc_bunch->next;
1424 /* INCLINK nonzero means bunches are from an incrementally-linked file.
1425 Add them to the existing bunches.
1426 Otherwise INCLINK is zero, and we start from scratch. */
1428 condense_misc_bunches (inclink)
1432 register struct misc_bunch *bunch;
1433 #ifdef NAMES_HAVE_UNDERSCORE
1441 misc_function_vector
1442 = (struct misc_function *)
1443 xrealloc (misc_function_vector, (misc_count + misc_function_count)
1444 * sizeof (struct misc_function));
1445 j = misc_function_count;
1449 misc_function_vector
1450 = (struct misc_function *)
1451 xxmalloc (misc_count * sizeof (struct misc_function));
1458 for (i = 0; i < misc_bunch_index; i++)
1460 misc_function_vector[j] = bunch->contents[i];
1461 misc_function_vector[j].name
1462 = obconcat (misc_function_vector[j].name
1463 + (misc_function_vector[j].name[0] == '_' ? offset : 0),
1467 bunch = bunch->next;
1468 misc_bunch_index = MISC_BUNCH_SIZE;
1472 misc_function_count += misc_count;
1474 misc_function_count = j;
1476 /* Sort the misc functions by address. */
1478 qsort (misc_function_vector, misc_function_count,
1479 sizeof (struct misc_function),
1480 compare_misc_functions);
1483 /* Call sort_syms to sort alphabetically
1484 the symbols of each block of each symtab. */
1487 compare_symbols (s1, s2)
1488 struct symbol **s1, **s2;
1490 register int namediff;
1492 /* Compare the initial characters. */
1493 namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0];
1494 if (namediff != 0) return namediff;
1496 /* If they match, compare the rest of the names. */
1497 namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
1498 if (namediff != 0) return namediff;
1500 /* For symbols of the same name, registers should come first. */
1501 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
1502 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
1505 static void sort_symtab_syms ();
1510 register struct symtab *s;
1512 for (s = symtab_list; s; s = s->next)
1513 sort_symtab_syms (s);
1517 sort_symtab_syms (s)
1518 register struct symtab *s;
1520 register struct blockvector *bv = BLOCKVECTOR (s);
1521 int nbl = BLOCKVECTOR_NBLOCKS (bv);
1523 register struct block *b;
1525 /* Note that in the following sort, we always make sure that
1526 register debug symbol declarations always come before regular
1527 debug symbol declarations (as might happen when parameters are
1528 then put into registers by the compiler). We do this by a
1529 correct compare in compare_symbols, and by the reversal of the
1530 symbols if we don't sort. This works as long as a register debug
1531 symbol always comes after a parameter debug symbol. */
1533 /* This is no longer necessary; lookup_block_symbol now always
1534 prefers some other declaration over a parameter declaration. We
1535 still sort the thing (that is necessary), but we don't reverse it
1536 if we shouldn't sort it. */
1538 for (i = 0; i < nbl; i++)
1540 b = BLOCKVECTOR_BLOCK (bv, i);
1541 if (BLOCK_SHOULD_SORT (b))
1542 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
1543 sizeof (struct symbol *), compare_symbols);
1548 extern struct symtab *psymtab_to_symtab ();
1550 /* The entry point. */
1551 static CORE_ADDR entry_point;
1553 /* This is the symbol-file command. Read the file, analyze its symbols,
1554 and add a struct symtab to symtab_list. */
1557 symbol_file_command (name, from_tty)
1562 DECLARE_FILE_HEADERS;
1563 struct nlist *nlist;
1565 /* The string table. */
1568 /* The size of the string table (buffer is a bizarre name...). */
1572 extern void close ();
1573 struct cleanup *old_chain;
1574 struct symtab *symseg;
1575 struct stat statbuf;
1581 if ((symtab_list || partial_symtab_list)
1583 && !query ("Discard symbol table? ", 0))
1584 error ("Not confirmed.");
1588 free_all_symtabs ();
1589 free_all_psymtabs ();
1593 name = tilde_expand (name);
1594 make_cleanup (free, name);
1596 if ((symtab_list || partial_symtab_list)
1597 && !query ("Load new symbol table from \"%s\"? ", name))
1598 error ("Not confirmed.");
1601 char *absolute_name;
1602 desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);
1604 perror_with_name (name);
1606 name = absolute_name;
1609 old_chain = make_cleanup (close, desc);
1610 make_cleanup (free_current_contents, &name);
1612 READ_FILE_HEADERS (desc, name);
1614 entry_point = ENTRY_POINT;
1616 if (NUMBER_OF_SYMBOLS == 0)
1621 free_all_symtabs ();
1622 free_all_psymtabs ();
1623 printf ("%s has no symbol-table; symbols discarded.\n", name);
1625 do_cleanups (old_chain);
1629 printf ("Reading symbol data from %s...", name);
1632 /* Now read the string table, all at once. */
1633 val = lseek (desc, STRING_TABLE_OFFSET, 0);
1635 perror_with_name (name);
1636 if (stat (name, &statbuf) == -1)
1637 error ("internal: error in stat of already open file.");
1638 READ_STRING_TABLE_SIZE (buffer);
1639 if (buffer >= 0 && buffer < statbuf.st_size)
1641 #ifdef BROKEN_LARGE_ALLOCA
1642 stringtab = (char *) xmalloc (buffer);
1643 make_cleanup (free, stringtab);
1645 stringtab = (char *) alloca (buffer);
1650 if (stringtab == NULL)
1651 error ("ridiculous string table size: %d bytes", buffer);
1653 /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer.
1654 Occaisionally, it won't. */
1655 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
1657 perror_with_name (name);
1658 val = myread (desc, stringtab, buffer);
1660 perror_with_name (name);
1662 /* Throw away the old symbol table. */
1667 free_all_symtabs ();
1668 free_all_psymtabs ();
1670 /* Empty the hash table of global syms looking for values. */
1671 bzero (global_sym_chain, sizeof global_sym_chain);
1673 /* Symsegs are no longer supported by GDB. Setting symseg_chain to
1674 0 is easier than finding all the symseg code and eliminating it. */
1677 /* Position to read the symbol table. Do not read it all at once. */
1678 val = lseek (desc, SYMBOL_TABLE_OFFSET, 0);
1680 perror_with_name (name);
1682 /* Don't put these on the cleanup chain; they need to stick around
1683 until the next call to symbol_file_command. *Then* we'll free
1685 free_header_files ();
1686 init_header_files ();
1688 init_misc_functions ();
1689 make_cleanup (discard_misc_bunches, 0);
1695 make_cleanup (really_free_pendings, 0);
1697 /* Now that the symbol table data of the executable file are all in core,
1698 process them and define symbols accordingly. Closes desc. */
1700 read_dbx_symtab (desc, stringtab, buffer, NUMBER_OF_SYMBOLS, 0,
1701 ADDR_OF_TEXT_SEGMENT, SIZE_OF_TEXT_SEGMENT);
1703 /* Go over the misc functions and install them in vector. */
1705 condense_misc_bunches (0);
1707 /* Don't allow char * to have a typename (else would get caddr_t.) */
1709 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
1711 /* Make a default for file to list. */
1713 symfile = savestring (name, strlen (name));
1715 /* Call to select_source_symtab used to be here; it was using too
1716 much time. I'll make sure that list_sources can handle the lack
1717 of current_source_symtab */
1719 do_cleanups (old_chain); /* Descriptor closed here */
1721 /* Free the symtabs made by read_symsegs, but not their contents,
1722 which have been copied into symtabs on symtab_list. */
1723 while (symseg_chain)
1725 register struct symtab *s = symseg_chain->next;
1726 free (symseg_chain);
1730 if (!partial_symtab_list)
1731 printf ("\n(no debugging symbols found)...");
1737 /* Return name of file symbols were loaded from, or 0 if none.. */
1745 /* Buffer for reading the symbol table entries. */
1746 static struct nlist symbuf[4096];
1747 static int symbuf_idx;
1748 static int symbuf_end;
1750 /* I/O descriptor for reading the symbol table. */
1751 static int symtab_input_desc;
1753 /* The address of the string table
1754 of the object file we are reading (as copied into core). */
1755 static char *stringtab_global;
1757 /* Refill the symbol table input buffer
1758 and set the variables that control fetching entries from it.
1759 Reports an error if no data available.
1760 This function can read past the end of the symbol table
1761 (into the string table) but this does no harm. */
1766 int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf));
1768 error ("error or end of file reading symbol table");
1769 symbuf_end = nbytes / sizeof (struct nlist);
1774 /* dbx allows the text of a symbol name to be continued into the
1775 next symbol name! When such a continuation is encountered
1776 (a \ at the end of the text of a name)
1777 call this function to get the continuation. */
1782 if (symbuf_idx == symbuf_end)
1785 return symbuf[symbuf_idx++].n_un.n_strx + stringtab_global;
1789 * Initializes storage for all of the partial symbols that will be
1790 * created by read_dbx_symtab and subsidiaries.
1793 init_psymbol_list (total_symbols)
1796 /* Current best guess is that there are approximately a twentieth
1797 of the total symbols (in a debugging file) are global or static
1799 global_psymbols.size = total_symbols / 10;
1800 static_psymbols.size = total_symbols / 10;
1801 global_psymbols.next = global_psymbols.list = (struct partial_symbol *)
1802 xmalloc (global_psymbols.size * sizeof (struct partial_symbol));
1803 static_psymbols.next = static_psymbols.list = (struct partial_symbol *)
1804 xmalloc (static_psymbols.size * sizeof (struct partial_symbol));
1808 * Initialize the list of bincls to contain none and have some
1812 init_bincl_list (number)
1815 bincls_allocated = number;
1816 next_bincl = bincl_list = (struct header_file_location *)
1817 xmalloc (bincls_allocated * sizeof(struct header_file_location));
1821 * Add a bincl to the list.
1824 add_bincl_to_list (pst, name, instance)
1825 struct partial_symtab *pst;
1829 if (next_bincl >= bincl_list + bincls_allocated)
1831 int offset = next_bincl - bincl_list;
1832 bincls_allocated *= 2;
1833 bincl_list = (struct header_file_location *)
1834 xrealloc (bincl_list,
1835 bincls_allocated * sizeof (struct header_file_location));
1836 next_bincl = bincl_list + offset;
1838 next_bincl->pst = pst;
1839 next_bincl->instance = instance;
1840 next_bincl++->name = name;
1844 * Given a name, value pair, find the corresponding
1845 * bincl in the list. Return the partial symtab associated
1846 * with that header_file_location.
1848 struct partial_symtab *
1849 find_corresponding_bincl_psymtab (name, instance)
1853 struct header_file_location *bincl;
1855 for (bincl = bincl_list; bincl < next_bincl; bincl++)
1856 if (bincl->instance == instance
1857 && !strcmp (name, bincl->name))
1860 return (struct partial_symtab *) 0;
1864 * Free the storage allocated for the bincl list.
1870 bincls_allocated = 0;
1873 static struct partial_symtab *start_psymtab ();
1874 static void add_psymtab_dependency ();
1875 static void end_psymtab();
1877 /* Given pointers to an a.out symbol table in core containing dbx
1878 style data, setup partial_symtab's describing each source file for
1879 which debugging information is available. NLISTLEN is the number
1880 of symbols in the symbol table. All symbol names are given as
1881 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
1884 I have no idea whether or not this routine should be setup to deal
1885 with inclinks. It seems reasonable to me that they be dealt with
1886 standardly, so I am not going to make a strong effort to deal with
1891 read_dbx_symtab (desc, stringtab, stringtab_size, nlistlen, inclink,
1892 text_addr, text_size)
1894 register char *stringtab;
1895 register long stringtab_size;
1896 register int nlistlen;
1901 register struct nlist *bufp;
1902 register char *namestring;
1903 register struct partial_symbol *psym;
1904 register struct psymbol_allocation_list *psymbol_struct;
1907 int past_first_source_file = 0;
1908 CORE_ADDR last_o_file_start = 0;
1909 struct cleanup *old_chain;
1912 enum address_class class;
1914 #ifdef PROFILE_TYPES
1916 int profile_types [256];
1917 int strcmp_called = 0;
1919 int global_funs = 0;
1922 /* Current partial symtab */
1923 struct partial_symtab *pst;
1925 /* List of current psymtab's include files */
1926 char **psymtab_include_list;
1927 int includes_allocated;
1930 /* Index within current psymtab dependency list */
1931 struct partial_symtab **dependency_list;
1932 int dependencies_used, dependencies_allocated;
1934 #ifdef PROFILE_TYPES
1935 for (i = 0; i < 256; i++)
1936 profile_types[i] = 0;
1939 stringtab_global = stringtab;
1941 pst = (struct partial_symtab *) 0;
1943 includes_allocated = 30;
1945 psymtab_include_list = (char **) alloca (includes_allocated *
1948 dependencies_allocated = 30;
1949 dependencies_used = 0;
1951 (struct partial_symtab **) alloca (dependencies_allocated *
1952 sizeof (struct partial_symtab *));
1954 old_chain = make_cleanup (free_all_psymtabs, 0);
1956 /* Init bincl list */
1957 init_bincl_list (20);
1958 make_cleanup (free_bincl_list, 0);
1960 /* Setup global partial symbol list */
1961 init_psymbol_list (nlistlen);
1963 last_source_file = 0;
1965 #ifdef END_OF_TEXT_DEFAULT
1966 end_of_text_addr = END_OF_TEXT_DEFAULT;
1968 end_of_text_addr = text_addr + text_size;
1971 symtab_input_desc = desc; /* This is needed for fill_symbuf below */
1972 symbuf_end = symbuf_idx = 0;
1974 for (symnum = 0; symnum < nlistlen; symnum++)
1976 /* Get the symbol for this run and pull out some info */
1977 QUIT; /* allow this to be interruptable */
1978 if (symbuf_idx == symbuf_end)
1980 bufp = &symbuf[symbuf_idx++];
1982 #ifdef PROFILE_TYPES
1983 profile_types[bufp->n_type]++;
1987 * Special case to speed up readin.
1989 if (bufp->n_type == N_SLINE) continue;
1991 /* Ok. There is a lot of code duplicated in the rest of this
1992 switch statiement (for efficiency reasons). Since I don't
1993 like duplicating code, I will do my penance here, and
1994 describe the code which is duplicated:
1996 *) The assignment to namestring.
1997 *) The call to index.
1998 *) The addition of a partial symbol the the two partial
1999 symbol lists. This last is a large section of code, so
2000 I've imbedded it in the following macro.
2003 /* Set namestring based on bufp. */
2004 #define SET_NAMESTRING()\
2005 if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) \
2006 error ("Invalid symbol data: bad string table offset: %d", \
2007 bufp->n_un.n_strx); \
2008 namestring = bufp->n_un.n_strx + stringtab
2010 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE)\
2012 if ((LIST).next >= \
2013 (LIST).list + (LIST).size) \
2015 (LIST).list = (struct partial_symbol *) \
2016 xrealloc ((LIST).list, \
2018 * sizeof (struct partial_symbol))); \
2019 /* Next assumes we only went one over. Should be good if \
2020 program works correctly */ \
2022 (LIST).list + (LIST).size; \
2025 psym = (LIST).next++; \
2027 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
2028 (NAMELENGTH) + 1); \
2029 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
2030 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
2031 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
2032 SYMBOL_CLASS (psym) = (CLASS); \
2033 SYMBOL_VALUE (psym) = (VALUE); \
2037 switch (bufp->n_type)
2040 * Standard, non-debugger, symbols
2043 case N_TEXT | N_EXT:
2048 if (namestring[6] == '\0' && namestring[5] == 't'
2049 && namestring[4] == 'x' && namestring[3] == 'e'
2050 && namestring[2] == 't' && namestring[1] == 'e'
2051 && namestring[0] == '_')
2052 end_of_text_addr = bufp->n_value;
2054 /* Figure out beginning and end of global linker symbol
2055 section and put non-debugger specified symbols on
2058 last_global_sym = symnum;
2059 if (!first_global_sym) first_global_sym = symnum;
2061 record_misc_function (namestring, bufp->n_value,
2062 bufp->n_type); /* Always */
2067 case N_NBTEXT | N_EXT:
2070 case N_NBDATA | N_EXT:
2073 case N_NBBSS | N_EXT:
2076 case N_SETV | N_EXT:
2079 case N_DATA | N_EXT:
2081 /* Figure out beginning and end of global linker symbol
2082 section and put non-debugger specified symbols on
2087 last_global_sym = symnum;
2088 if (!first_global_sym) first_global_sym = symnum;
2090 /* Not really a function here, but... */
2091 record_misc_function (namestring, bufp->n_value,
2092 bufp->n_type); /* Always */
2099 #ifdef OFILE_FN_FLAGGED
2100 #if ! (N_FN & N_EXT)
2108 if ((namestring[0] == '-' && namestring[1] == 'l')
2109 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
2110 && namestring [nsl - 2] == '.'))
2112 if (entry_point < bufp->n_value
2113 && entry_point >= last_o_file_start)
2115 startup_file_start = last_o_file_start;
2116 startup_file_end = bufp->n_value;
2118 if (past_first_source_file && pst)
2120 end_psymtab (pst, psymtab_include_list, includes_used,
2121 symnum * sizeof (struct nlist), bufp->n_value,
2122 dependency_list, dependencies_used,
2123 global_psymbols.next, static_psymbols.next);
2124 pst = (struct partial_symtab *) 0;
2126 dependencies_used = 0;
2129 past_first_source_file = 1;
2130 last_o_file_start = bufp->n_value;
2134 #ifdef OFILE_FN_FLAGGED
2137 #if ! (N_FN & N_EXT)
2143 case N_UNDF | N_EXT:
2154 /* Keep going . . .*/
2157 * Special symbol types for GNU
2161 case N_INDR | N_EXT:
2165 case N_SETA | N_EXT:
2167 case N_SETT | N_EXT:
2169 case N_SETD | N_EXT:
2171 case N_SETB | N_EXT:
2181 /* End the current partial symtab and start a new one */
2185 if (pst && past_first_source_file)
2187 end_psymtab (pst, psymtab_include_list, includes_used,
2188 symnum * sizeof (struct nlist), bufp->n_value,
2189 dependency_list, dependencies_used,
2190 global_psymbols.next, static_psymbols.next);
2191 pst = (struct partial_symtab *) 0;
2193 dependencies_used = 0;
2196 past_first_source_file = 1;
2198 pst = start_psymtab (namestring, bufp->n_value,
2199 symnum * sizeof (struct nlist),
2200 global_psymbols.next, static_psymbols.next);
2206 /* Add this bincl to the bincl_list for future EXCLs. No
2207 need to save the string; it'll be around until
2208 read_dbx_symtab function return */
2212 add_bincl_to_list (pst, namestring, bufp->n_value);
2214 /* Mark down an include file in the current psymtab */
2216 psymtab_include_list[includes_used++] = namestring;
2217 if (includes_used >= includes_allocated)
2219 char **orig = psymtab_include_list;
2221 psymtab_include_list = (char **)
2222 alloca ((includes_allocated *= 2) *
2224 bcopy (orig, psymtab_include_list,
2225 includes_used * sizeof (char *));
2232 /* Mark down an include file in the current psymtab */
2236 /* In C++, one may expect the same filename to come round many
2237 times, when code is coming alternately from the main file
2238 and from inline functions in other files. So I check to see
2239 if this is a file we've seen before.
2241 This seems to be a lot of time to be spending on N_SOL, but
2242 things like "break expread.y:435" need to work (I
2243 suppose the psymtab_include_list could be hashed or put
2244 in a binary tree, if profiling shows this is a major hog). */
2247 for (i = 0; i < includes_used; i++)
2248 if (!strcmp (namestring, psymtab_include_list[i]))
2257 psymtab_include_list[includes_used++] = namestring;
2258 if (includes_used >= includes_allocated)
2260 char **orig = psymtab_include_list;
2262 psymtab_include_list = (char **)
2263 alloca ((includes_allocated *= 2) *
2265 bcopy (orig, psymtab_include_list,
2266 includes_used * sizeof (char *));
2270 case N_LSYM: /* Typedef or automatic variable. */
2273 p = (char *) index (namestring, ':');
2275 /* Skip if there is no :. */
2281 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2282 STRUCT_NAMESPACE, LOC_TYPEDEF,
2283 static_psymbols, bufp->n_value);
2286 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2287 VAR_NAMESPACE, LOC_TYPEDEF,
2288 static_psymbols, bufp->n_value);
2290 /* If this is an enumerated type, we need to
2291 add all the enum constants to the partial symbol
2292 table. This does not cover enums without names, e.g.
2293 "enum {a, b} c;" in C, but fortunately those are
2294 rare. There is no way for GDB to find those from the
2295 enum type without spending too much time on it. Thus
2296 to solve this problem, the compiler needs to put out separate
2297 constant symbols ('c' N_LSYMS) for enum constants in
2298 enums without names. */
2300 /* We are looking for something of the form
2301 <name> ":" ("t" | "T") [<number> "="] "e"
2302 {<constant> ":" <value> ","} ";". */
2304 /* Skip over the colon and the 't' or 'T'. */
2306 /* This type may be given a number. Skip over it. */
2307 while ((*p >= '0' && *p <= '9')
2313 /* We have found an enumerated type. */
2314 /* According to comments in read_enum_type
2315 a comma could end it instead of a semicolon.
2316 I don't know where that happens.
2318 while (*p && *p != ';' && *p != ',')
2322 /* Check for and handle cretinous dbx symbol name
2325 p = next_symbol_text ();
2327 /* Point to the character after the name
2328 of the enum constant. */
2329 for (q = p; *q && *q != ':'; q++)
2331 /* Note that the value doesn't matter for
2332 enum constants in psymtabs, just in symtabs. */
2333 ADD_PSYMBOL_TO_LIST (p, q - p,
2334 VAR_NAMESPACE, LOC_CONST,
2335 static_psymbols, 0);
2336 /* Point past the name. */
2338 /* Skip over the value. */
2339 while (*p && *p != ',')
2341 /* Advance past the comma. */
2349 /* Constant, e.g. from "const" in Pascal. */
2350 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2351 VAR_NAMESPACE, LOC_CONST,
2352 static_psymbols, bufp->n_value);
2355 #ifdef PROFILE_TYPES
2357 printf ("Funny...LSYM with a letter that isn't a type\n");
2360 /* Skip if the thing following the : is
2361 not a letter (which indicates declaration of a local
2362 variable, which we aren't interested in). */
2368 /* This special-casing of N_FUN is just wrong; N_FUN
2369 does not mean "function"; it means "text segment".
2370 So N_FUN can go with 'V', etc. as well as 'f' or 'F'. */
2374 p = (char *) index (namestring, ':');
2376 if (!p || p[1] == 'F') continue;
2378 #ifdef PROFILE_TYPES
2380 printf ("Funny...FUN with a letter that isn't 'F' or 'f'.\n");
2384 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2385 VAR_NAMESPACE, LOC_BLOCK,
2386 static_psymbols, bufp->n_value);
2390 case N_GSYM: /* Global (extern) variable; can be
2391 data or bss (sigh). */
2392 case N_STSYM: /* Data seg var -- static */
2393 case N_LCSYM: /* BSS " */
2395 /* Following may probably be ignored; I'll leave them here
2396 for now (until I do Pascal and Modula 2 extensions). */
2398 case N_PC: /* I may or may not need this; I
2401 case N_M2C: /* I suspect that I can ignore this here. */
2402 case N_SCOPE: /* Same. */
2407 p = (char *) index (namestring, ':');
2409 continue; /* Not a debugging symbol. */
2411 process_symbol_for_psymtab:
2413 /* Main processing section for debugging symbols which
2414 the initial read through the symbol tables needs to worry
2415 about. If we reach this point, the symbol which we are
2416 considering is definitely one we are interested in.
2417 p must also contain the (valid) index into the namestring
2418 which indicates the debugging type symbol. */
2423 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2424 VAR_NAMESPACE, LOC_CONST,
2425 static_psymbols, bufp->n_value);
2428 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2429 VAR_NAMESPACE, LOC_STATIC,
2430 static_psymbols, bufp->n_value);
2433 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2434 VAR_NAMESPACE, LOC_EXTERNAL,
2435 global_psymbols, bufp->n_value);
2439 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2440 VAR_NAMESPACE, LOC_TYPEDEF,
2441 global_psymbols, bufp->n_value);
2445 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
2446 VAR_NAMESPACE, LOC_BLOCK,
2447 static_psymbols, bufp->n_value);
2450 /* Two things show up here (hopefully); static symbols of
2451 local scope (static used inside braces) or extensions
2452 of structure symbols. We can ignore both. */
2465 /* Global functions are ignored here. I'm not
2466 sure what psymtab they go into (or just the misc
2467 function vector). */
2472 fatal ("Internal error: Unexpected debugging symbol type '%c' at symnum %d.\n",
2481 /* Find the corresponding bincl and mark that psymtab on the
2482 psymtab dependency list */
2484 struct partial_symtab *needed_pst =
2485 find_corresponding_bincl_psymtab (namestring, bufp->n_value);
2487 /* If this include file was defined earlier in this file,
2489 if (needed_pst == pst) continue;
2496 for (i = 0; i < dependencies_used; i++)
2497 if (dependency_list[i] == needed_pst)
2503 /* If it's already in the list, skip the rest. */
2504 if (found) continue;
2506 dependency_list[dependencies_used++] = needed_pst;
2507 if (dependencies_used >= dependencies_allocated)
2509 struct partial_symtab **orig = dependency_list;
2511 (struct partial_symtab **)
2512 alloca ((dependencies_allocated *= 2)
2513 * sizeof (struct partial_symtab *));
2514 bcopy (orig, dependency_list,
2516 * sizeof (struct partial_symtab *)));
2518 fprintf (stderr, "Had to reallocate dependency list.\n");
2519 fprintf (stderr, "New dependencies allocated: %d\n",
2520 dependencies_allocated);
2525 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
2538 case N_SSYM: /* Claim: Structure or union element.
2539 Hopefully, I can ignore this. */
2540 case N_ENTRY: /* Alternate entry point; can ignore. */
2542 case N_MAIN: /* Can definitely ignore this. */
2554 /* These symbols aren't interesting; don't worry about them */
2559 /* If we haven't found it yet, we've got problems */
2561 if (IGNORE_SYMBOL (bufp->n_type))
2564 fatal ("Bad symbol type 0x%x encountered in gdb scan", bufp->n_type);
2568 /* If there's stuff to be cleaned up, clean it up. */
2569 if (entry_point < bufp->n_value
2570 && entry_point >= last_o_file_start)
2572 startup_file_start = last_o_file_start;
2573 startup_file_end = bufp->n_value;
2578 end_psymtab (pst, psymtab_include_list, includes_used,
2579 symnum * sizeof (struct nlist), end_of_text_addr,
2580 dependency_list, dependencies_used,
2581 global_psymbols.next, static_psymbols.next);
2583 dependencies_used = 0;
2584 pst = (struct partial_symtab *) 0;
2588 discard_cleanups (old_chain);
2589 #ifdef PROFILE_TYPES
2592 #define __define_stab(SYM, NUMBER, NAME) {NUMBER, NAME},
2593 static struct xyzzy {
2594 unsigned char symnum;
2612 for (i = 0; i < 256; i++)
2614 for (j = 0; j < (sizeof (tmp_list) / sizeof (struct xyzzy)) - 1; j++)
2615 if (tmp_list[j].symnum == i)
2617 printf ("Symbol \"%s\" (0x%x) occured %d times.\n",
2618 tmp_list[j].name, i, profile_types[i]);
2620 printf ("Auto vars (under LSYM): %d\n", autovars);
2621 printf ("Global funs (under FUN): %d\n", global_funs);
2627 * Allocate and partially fill a partial symtab. It will be
2628 * completely filled at the end of the symbol list.
2630 static struct partial_symtab *
2631 start_psymtab (filename, textlow, ldsymoff, global_syms, static_syms)
2635 struct partial_symbol *global_syms;
2636 struct partial_symbol *static_syms;
2638 struct partial_symtab *result =
2639 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
2640 sizeof (struct partial_symtab));
2643 (char *) obstack_alloc (psymbol_obstack,
2644 strlen (filename) + 1);
2645 strcpy (result->filename, filename);
2647 result->textlow = textlow;
2648 result->ldsymoff = ldsymoff;
2652 result->globals_offset = global_syms - global_psymbols.list;
2653 result->statics_offset = static_syms - static_psymbols.list;
2655 result->n_global_syms = 0;
2656 result->n_static_syms = 0;
2662 compare_psymbols (s1, s2)
2663 register struct partial_symbol *s1, *s2;
2666 *st1 = SYMBOL_NAME (s1),
2667 *st2 = SYMBOL_NAME (s2);
2669 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2670 strcmp (st1 + 1, st2 + 1));
2674 /* Close off the current usage of a partial_symbol table entry. This
2675 involves setting the correct number of includes (with a realloc),
2676 setting the high text mark, setting the symbol length in the
2677 executable, and setting the length of the global and static lists
2680 The global symbols and static symbols are then seperately sorted.
2682 Then the partial symtab is put on the global list.
2683 *** List variables and peculiarities of same. ***
2686 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2687 capping_text, dependency_list, number_dependencies,
2688 capping_global, capping_static)
2689 struct partial_symtab *pst;
2690 char **include_list;
2692 int capping_symbol_offset;
2694 struct partial_symtab **dependency_list;
2695 int number_dependencies;
2696 struct partial_symbol *capping_global, *capping_static;
2700 pst->ldsymlen = capping_symbol_offset - pst->ldsymoff;
2701 pst->texthigh = capping_text;
2703 pst->n_global_syms =
2704 capping_global - (global_psymbols.list + pst->globals_offset);
2705 pst->n_static_syms =
2706 capping_static - (static_psymbols.list + pst->statics_offset);
2708 pst->dependencies = (struct partial_symtab **)
2709 obstack_alloc (psymbol_obstack,
2710 number_dependencies * sizeof (struct partial_symtab *));
2711 bcopy (dependency_list, pst->dependencies,
2712 number_dependencies * sizeof (struct partial_symtab *));
2713 pst->number_of_dependencies = number_dependencies;
2715 for (i = 0; i < num_includes; i++)
2717 /* Eventually, put this on obstack */
2718 struct partial_symtab *subpst =
2719 (struct partial_symtab *)
2720 obstack_alloc (psymbol_obstack,
2721 sizeof (struct partial_symtab));
2724 (char *) obstack_alloc (psymbol_obstack,
2725 strlen (include_list[i]) + 1);
2726 strcpy (subpst->filename, include_list[i]);
2731 subpst->texthigh = 0;
2734 subpst->dependencies = (struct partial_symtab **)
2735 obstack_alloc (psymbol_obstack,
2736 sizeof (struct partial_symtab *));
2737 subpst->dependencies[0] = pst;
2738 subpst->number_of_dependencies = 1;
2740 subpst->globals_offset =
2741 subpst->n_global_syms =
2742 subpst->statics_offset =
2743 subpst->n_static_syms = 0;
2745 subpst->next = partial_symtab_list;
2746 partial_symtab_list = subpst;
2749 /* Sort the global list; don't sort the static list */
2750 qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms,
2751 sizeof (struct partial_symbol), compare_psymbols);
2753 /* Put the psymtab on the psymtab list */
2754 pst->next = partial_symtab_list;
2755 partial_symtab_list = pst;
2759 /* Helper routines for psymtab_to_symtab. */
2760 static void scan_file_globals ();
2761 static void read_ofile_symtab ();
2764 psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset)
2765 struct partial_symtab *pst;
2771 struct cleanup *old_chain;
2779 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2784 /* Read in all partial symbtabs on which this one is dependent */
2785 for (i = 0; i < pst->number_of_dependencies; i++)
2786 if (!pst->dependencies[i]->readin)
2788 /* Inform about additional files that need to be read in. */
2791 printf_filtered (" and %s...", pst->dependencies[i]->filename);
2794 psymtab_to_symtab_1 (pst->dependencies[i], desc,
2795 stringtab, stringtab_size, sym_offset);
2798 if (pst->ldsymlen) /* Otherwise it's a dummy */
2800 /* Init stuff necessary for reading in symbols */
2805 old_chain = make_cleanup (really_free_pendings, 0);
2807 /* Read in this files symbols */
2808 lseek (desc, sym_offset, L_SET);
2809 read_ofile_symtab (desc, stringtab, stringtab_size,
2811 pst->ldsymlen, pst->textlow,
2812 pst->texthigh - pst->textlow, 0);
2813 sort_symtab_syms (symtab_list); /* At beginning since just added */
2815 do_cleanups (old_chain);
2822 * Read in all of the symbols for a given psymtab for real. Return
2823 * the value of the symtab you create. Do not free the storage
2824 * allocated to the psymtab; it may have pointers to it.
2827 psymtab_to_symtab(pst)
2828 struct partial_symtab *pst;
2831 DECLARE_FILE_HEADERS;
2833 struct partial_symtab **list_patch;
2835 struct stat statbuf;
2836 struct cleanup *old_chain;
2837 extern void close ();
2839 struct symtab *result;
2840 char *name = symfile; /* Some of the macros require the */
2841 /* variable "name" to be defined in */
2842 /* the context in which they execute */
2850 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2856 error("No symbol file currently specified; use command symbol-file");
2858 if (pst->ldsymlen || pst->number_of_dependencies)
2860 /* Print the message now, before reading the string table,
2861 to avoid disconcerting pauses. */
2864 printf_filtered ("Reading in symbols for %s...", pst->filename);
2868 /* Open symbol file and read in string table */
2869 stat (name, &statbuf);
2870 desc = open(name, O_RDONLY, 0); /* symbol_file_command
2871 guarrantees that the symbol file name
2872 will be absolute, so there is no
2875 old_chain = make_cleanup (close, desc);
2878 error("Symbol file not readable");
2880 READ_FILE_HEADERS (desc, name);
2882 /* Read in the string table */
2883 lseek (desc, STRING_TABLE_OFFSET, L_SET);
2884 READ_STRING_TABLE_SIZE (stsize);
2885 if (stsize >= 0 && stsize < statbuf.st_size)
2887 #ifdef BROKEN_LARGE_ALLOCA
2888 stringtab = (char *) xmalloc (stsize);
2889 make_cleanup (free, stringtab);
2891 stringtab = (char *) alloca (stsize);
2896 if (stringtab == NULL)
2897 error ("ridiculous string table size: %d bytes", stsize);
2899 /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer.
2900 Occaisionally, it won't. */
2901 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
2903 perror_with_name (name);
2904 val = myread (desc, stringtab, stsize);
2906 perror_with_name (name);
2908 psymtab_to_symtab_1 (pst, desc, stringtab, stsize,
2909 SYMBOL_TABLE_OFFSET);
2911 /* Match with global symbols. This only needs to be done once,
2912 after all of the symtabs and dependencies have been read in. */
2913 scan_file_globals ();
2915 do_cleanups (old_chain);
2917 /* Finish up the debug error message. */
2919 printf_filtered ("done.\n");
2922 /* Search through list for correct name. */
2923 for (result = symtab_list; result; result = result->next)
2924 if (!strcmp (result->filename, pst->filename))
2931 * Scan through all of the global symbols defined in the object file,
2932 * assigning values to the debugging symbols that need to be assigned
2933 * to. Get these symbols from the misc function list.
2936 scan_file_globals ()
2941 for (mf = 0; mf < misc_function_count; mf++)
2943 char *namestring = misc_function_vector[mf].name;
2944 struct symbol *sym, *prev;
2948 prev = (struct symbol *) 0;
2950 /* Get the hash index and check all the symbols
2951 under that hash index. */
2953 hash = hashname (namestring);
2955 for (sym = global_sym_chain[hash]; sym;)
2957 if (*namestring == SYMBOL_NAME (sym)[0]
2958 && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1))
2960 /* Splice this symbol out of the hash chain and
2961 assign the value we have to it. */
2963 SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym);
2965 global_sym_chain[hash]
2966 = (struct symbol *) SYMBOL_VALUE (sym);
2968 /* Check to see whether we need to fix up a common block. */
2969 /* Note: this code might be executed several times for
2970 the same symbol if there are multiple references. */
2971 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2972 fix_common_block (sym, misc_function_vector[mf].address);
2974 SYMBOL_VALUE (sym) = misc_function_vector[mf].address;
2977 sym = (struct symbol *) SYMBOL_VALUE (prev);
2979 sym = global_sym_chain[hash];
2984 sym = (struct symbol *) SYMBOL_VALUE (sym);
2991 * Read in a defined section of a specific object file's symbols.
2993 * DESC is the file descriptor for the file, positioned at the
2994 * beginning of the symtab
2995 * STRINGTAB is a pointer to the files string
2996 * table, already read in
2997 * SYM_OFFSET is the offset within the file of
2998 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
2999 * number of symbols to read
3000 * TEXT_OFFSET is the offset to be added to
3001 * all values of symbols coming in and
3002 * TEXT_SIZE is the size of the text segment read in.
3003 * OFFSET is a flag which indicates that the value of all of the
3004 * symbols should be offset by TEXT_OFFSET (for the purposes of
3005 * incremental linking).
3009 read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
3010 sym_size, text_offset, text_size, offset)
3012 register char *stringtab;
3019 register char *namestring;
3020 register struct symbol *sym, *prev;
3022 struct cleanup *old_chain;
3029 stringtab_global = stringtab;
3030 last_source_file = 0;
3032 symtab_input_desc = desc;
3033 symbuf_end = symbuf_idx = 0;
3035 /* It is necessary to actually read one symbol *before* the start
3036 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
3037 occurs before the N_SO symbol.
3039 Detecting this in read_dbx_symtab
3040 would slow down initial readin, so we look for it here instead. */
3041 if (sym_offset >= sizeof (struct nlist))
3043 lseek (desc, sym_offset - sizeof (struct nlist), L_INCR);
3045 bufp = &symbuf[symbuf_idx++];
3047 if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size)
3048 error ("Invalid symbol data: bad string table offset: %d",
3050 namestring = bufp->n_un.n_strx + stringtab;
3052 processing_gcc_compilation =
3053 (bufp->n_type == N_TEXT
3054 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL));
3058 /* The N_SO starting this symtab is the first symbol, so we
3059 better not check the symbol before it. I'm not this can
3060 happen, but it doesn't hurt to check for it. */
3061 lseek(desc, sym_offset, L_INCR);
3062 processing_gcc_compilation = 0;
3065 if (symbuf_idx == symbuf_end)
3067 bufp = &symbuf[symbuf_idx];
3068 if ((unsigned char) bufp->n_type != N_SO)
3069 fatal("First symbol in segment of executable not a source symbol");
3072 symnum < sym_size / sizeof(struct nlist);
3075 QUIT; /* Allow this to be interruptable */
3076 if (symbuf_idx == symbuf_end)
3078 bufp = &symbuf[symbuf_idx++];
3079 type = bufp->n_type;
3082 (type == N_TEXT || type == N_DATA || type == N_BSS))
3083 bufp->n_value += text_offset;
3085 if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size)
3086 error ("Invalid symbol data: bad string table offset: %d",
3088 namestring = bufp->n_un.n_strx + stringtab;
3091 process_one_symbol(type, bufp->n_desc,
3092 bufp->n_value, namestring);
3093 /* We skip checking for a new .o or -l file; that should never
3094 happen in this routine. */
3095 else if (type == N_TEXT
3096 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
3097 /* I don't think this code will ever be executed, because
3098 the GCC_COMPILED_FLAG_SYMBOL usually is right before
3099 the N_SO symbol which starts this source file.
3100 However, there is no reason not to accept
3101 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
3102 processing_gcc_compilation = 1;
3103 else if (type & N_EXT || type == N_TEXT
3108 /* Global symbol: see if we came across a dbx defintion for
3109 a corresponding symbol. If so, store the value. Remove
3110 syms from the chain when their values are stored, but
3111 search the whole chain, as there may be several syms from
3112 different files with the same name. */
3113 /* This is probably not true. Since the files will be read
3114 in one at a time, each reference to a global symbol will
3115 be satisfied in each file as it appears. So we skip this
3117 &stringtab_global; /* For debugger; am I right? */
3119 end_symtab (text_offset + text_size);
3126 register char *p = name;
3127 register int total = p[0];
3140 /* Ensure result is positive. */
3141 if (total < 0) total += (1000 << 6);
3142 return total % HASHSIZE;
3145 /* Put all appropriate global symbols in the symseg data
3146 onto the hash chains so that their addresses will be stored
3147 when seen later in loader global symbols. */
3152 /* Look at each symbol in each block in each symseg symtab. */
3154 for (s = symseg_chain; s; s = s->next)
3157 for (n = BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)) - 1; n >= 0; n--)
3159 register struct block *b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), n);
3161 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
3163 register struct symbol *sym = BLOCK_SYM (b, i);
3165 /* Put the symbol on a chain if its value is an address
3166 that is figured out by the loader. */
3168 if (SYMBOL_CLASS (sym) == LOC_EXTERNAL)
3170 register int hash = hashname (SYMBOL_NAME (sym));
3171 SYMBOL_VALUE (sym) = (int) global_sym_chain[hash];
3172 global_sym_chain[hash] = sym;
3173 SYMBOL_CLASS (sym) = LOC_STATIC;
3181 process_one_symbol (type, desc, value, name)
3186 register struct context_stack *new;
3189 /* Something is wrong if we see real data before
3190 seeing a source file name. */
3192 if (last_source_file == 0 && type != N_SO)
3194 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
3195 where that code is defined. */
3196 if (IGNORE_SYMBOL (type))
3199 error ("Invalid symbol data: does not start by identifying a source file.");
3206 /* Either of these types of symbols indicates the start of
3207 a new function. We must process its "name" normally for dbx,
3208 but also record the start of a new lexical context, and possibly
3209 also the end of the lexical context for the previous function. */
3210 /* This is not always true. This type of symbol may indicate a
3211 text segment variable. */
3213 colon_pos = index (name, ':');
3215 || (*colon_pos != 'f' && *colon_pos != 'F'))
3217 define_symbol (value, name, desc);
3221 within_function = 1;
3222 if (context_stack_depth > 0)
3224 new = &context_stack[--context_stack_depth];
3225 /* Make a block for the local symbols within. */
3226 finish_block (new->name, &local_symbols, new->old_blocks,
3227 new->start_addr, value);
3229 /* Stack must be empty now. */
3230 if (context_stack_depth != 0)
3231 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
3234 new = &context_stack[context_stack_depth++];
3235 new->old_blocks = pending_blocks;
3236 new->start_addr = value;
3237 new->name = define_symbol (value, name, desc);
3242 /* This "symbol" just indicates the start of an inner lexical
3243 context within a function. */
3245 if (context_stack_depth == context_stack_size)
3247 context_stack_size *= 2;
3248 context_stack = (struct context_stack *)
3249 xrealloc (context_stack,
3251 * sizeof (struct context_stack)));
3254 new = &context_stack[context_stack_depth++];
3256 new->locals = local_symbols;
3257 new->old_blocks = pending_blocks;
3258 new->start_addr = value;
3264 /* This "symbol" just indicates the end of an inner lexical
3265 context that was started with N_LBRAC. */
3266 new = &context_stack[--context_stack_depth];
3267 if (desc != new->depth)
3268 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum);
3270 /* Can only use new->locals as local symbols here if we're in
3271 gcc or on a machine that puts them before the lbrack. */
3272 /* Some native compilers put the variable decls inside of an
3273 LBRAC/RBRAC block. */
3274 #ifdef VARIABLES_INSIDE_BLOCK
3275 if (processing_gcc_compilation)
3277 local_symbols = new->locals;
3279 /* If this is not the outermost LBRAC...RBRAC pair in the
3280 function, its local symbols preceded it, and are the ones
3281 just recovered from the context stack. Defined the block for them.
3283 If this is the outermost LBRAC...RBRAC pair, there is no
3284 need to do anything; leave the symbols that preceded it
3285 to be attached to the function's own block. However, if
3286 it is so, we need to indicate that we just moved outside
3288 #ifdef VARIABLES_INSIDE_BLOCK
3289 if (local_symbols && context_stack_depth > processing_gcc_compilation)
3291 if (local_symbols && context_stack_depth > 1)
3294 /* Muzzle a compiler bug that makes end < start. */
3295 if (new->start_addr > value)
3296 new->start_addr = value;
3297 /* Make a block for the local symbols within. */
3298 finish_block (0, &local_symbols, new->old_blocks,
3299 new->start_addr + last_source_start_addr,
3300 value + last_source_start_addr);
3304 within_function = 0;
3306 #ifdef VARIABLES_INSIDE_BLOCK
3307 /* gcc: normal. pcc: now pop locals of block just finished. */
3308 if (!processing_gcc_compilation)
3309 local_symbols = new->locals;
3314 /* This kind of symbol supposedly indicates the start
3315 of an object file. In fact this type does not appear. */
3319 /* This type of symbol indicates the start of data
3320 for one source file.
3321 Finish the symbol table of the previous source file
3322 (if any) and start accumulating a new symbol table. */
3323 #ifdef PCC_SOL_BROKEN
3324 /* pcc bug, occasionally puts out SO for SOL. */
3325 if (context_stack_depth > 0)
3327 start_subfile (name);
3331 if (last_source_file)
3333 start_symtab (name, value);
3337 /* This type of symbol indicates the start of data for
3338 a sub-source-file, one whose contents were copied or
3339 included in the compilation of the main source file
3340 (whose name was given in the N_SO symbol.) */
3341 start_subfile (name);
3347 add_new_header_file (name, value);
3348 start_subfile (name);
3352 start_subfile (pop_subfile ());
3356 add_old_header_file (name, value);
3358 #endif /* have N_BINCL */
3361 /* This type of "symbol" really just records
3362 one line-number -- core-address correspondence.
3363 Enter it in the line list for this symbol table. */
3364 record_line (desc, value);
3369 error ("Invalid symbol data: common within common at symtab pos %d",
3371 common_block = local_symbols;
3372 common_block_i = local_symbols ? local_symbols->nsyms : 0;
3376 /* Symbols declared since the BCOMM are to have the common block
3377 start address added in when we know it. common_block points to
3378 the first symbol after the BCOMM in the local_symbols list;
3379 copy the list and hang it off the symbol for the common block name
3383 struct pending *link = local_symbols;
3384 struct symbol *sym =
3385 (struct symbol *) xmalloc (sizeof (struct symbol));
3386 bzero (sym, sizeof *sym);
3387 SYMBOL_NAME (sym) = savestring (name, strlen (name));
3388 SYMBOL_CLASS (sym) = LOC_BLOCK;
3389 SYMBOL_NAMESPACE (sym) = (enum namespace)
3390 copy_pending (local_symbols, common_block_i, common_block);
3391 i = hashname (SYMBOL_NAME (sym));
3392 SYMBOL_VALUE (sym) = (int) global_sym_chain[i];
3393 global_sym_chain[i] = sym;
3404 define_symbol (value, name, desc);
3408 /* This function was added for C++ functionality. I presume that it
3409 condenses the bunches formed by reading in an additional .o file
3410 (incremental linking). */
3413 condense_addl_misc_bunches ()
3416 register struct misc_bunch *bunch;
3417 #ifdef NAMES_HAVE_UNDERSCORE
3423 misc_function_vector
3424 = (struct misc_function *) xrealloc (misc_function_vector,
3425 (misc_count + misc_function_count) * sizeof (struct misc_function));
3427 j = misc_function_count;
3431 for (i = 0; i < misc_bunch_index; i++)
3433 misc_function_vector[j] = bunch->contents[i];
3434 misc_function_vector[j].name
3435 = concat (misc_function_vector[j].name
3436 + (misc_function_vector[j].name[0] == '_' ? offset : 0),
3440 bunch = bunch->next;
3441 misc_bunch_index = MISC_BUNCH_SIZE;
3444 misc_function_count += misc_count;
3446 /* Sort the misc functions by address. */
3448 qsort (misc_function_vector, misc_function_count,
3449 sizeof (struct misc_function), compare_misc_functions);
3453 /* Read in another .o file and create a symtab entry for it.*/
3456 read_addl_syms (desc, stringtab, nlistlen, text_addr, text_size)
3458 register char *stringtab;
3459 register int nlistlen;
3463 FILE *stream = fdopen (desc, "r");
3464 register char *namestring;
3465 register struct symbol *sym, *prev;
3472 last_source_file = 0;
3473 bzero (global_sym_chain, sizeof global_sym_chain);
3474 symtab_input_desc = desc;
3475 stringtab_global = stringtab;
3478 for (symnum = 0; symnum < nlistlen; symnum++)
3483 QUIT; /* allow this to be interruptable */
3484 if (symbuf_idx == symbuf_end)
3486 bufp = &symbuf[symbuf_idx++];
3487 type = bufp->n_type & N_TYPE;
3488 namestring = bufp->n_un.n_strx + stringtab;
3490 if( (type == N_TEXT) || (type == N_DATA) || (type == N_BSS) )
3492 /* Relocate this file's symbol table information
3493 to the address it has been loaded into. */
3494 bufp->n_value += text_addr;
3497 type = bufp->n_type;
3500 process_one_symbol (type, bufp->n_desc,
3501 bufp->n_value, namestring);
3502 /* A static text symbol whose name ends in ".o"
3503 can only mean the start of another object file.
3504 So end the symtab of the source file we have been processing.
3505 This is how we avoid counting the libraries as part
3506 or the last source file.
3507 Also this way we find end of first object file (crt0). */
3508 else if ((type == N_TEXT
3513 && (!strcmp (namestring + strlen (namestring) - 2, ".o"))
3514 || ! strncmp (namestring, "-l", 2))
3516 if (last_source_file)
3517 end_symtab (bufp->n_value);
3519 else if (type & N_EXT || type == N_TEXT
3527 /* Record the location of _etext. */
3528 if (type == (N_TEXT | N_EXT)
3529 && !strcmp (namestring, "_etext"))
3530 end_of_text_addr = bufp->n_value;
3533 /* 25 Sep 89: The following seems to be stolen from
3534 read_ofile_symtab, and is wrong here (i.e. there was no
3535 first pass for add-file symbols). */
3536 /* This shouldn't be necessary, as we now do all of this work
3537 in scan_global syms and all misc functions should have been
3538 recorded on the first pass. */
3539 /* Global symbol: see if we came across a dbx definition
3540 for a corresponding symbol. If so, store the value.
3541 Remove syms from the chain when their values are stored,
3542 but search the whole chain, as there may be several syms
3543 from different files with the same name. */
3547 #ifdef NAMES_HAVE_UNDERSCORE
3548 hash = hashname (namestring + 1);
3549 #else /* not NAMES_HAVE_UNDERSCORE */
3550 hash = hashname (namestring);
3551 #endif /* not NAMES_HAVE_UNDERSCORE */
3552 for (sym = global_sym_chain[hash];
3556 #ifdef NAMES_HAVE_UNDERSCORE
3558 && namestring[1] == SYMBOL_NAME (sym)[0]
3560 !strcmp (namestring + 2, SYMBOL_NAME (sym) + 1)
3561 #else /* NAMES_HAVE_UNDERSCORE */
3562 namestring[0] == SYMBOL_NAME (sym)[0]
3564 !strcmp (namestring + 1, SYMBOL_NAME (sym) + 1)
3565 #endif /* NAMES_HAVE_UNDERSCORE */
3569 SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym);
3571 global_sym_chain[hash]
3572 = (struct symbol *) SYMBOL_VALUE (sym);
3573 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3574 fix_common_block (sym, bufp->n_value);
3576 SYMBOL_VALUE (sym) = bufp->n_value;
3578 sym = (struct symbol *) SYMBOL_VALUE (prev);
3580 sym = global_sym_chain[hash];
3587 sym = (struct symbol *) SYMBOL_VALUE (sym);
3592 /* Defined global or text symbol: record as a misc function
3593 if it didn't give its address to a debugger symbol above. */
3594 if (type <= (N_TYPE | N_EXT)
3597 record_misc_function (namestring, bufp->n_value,
3603 if (last_source_file)
3604 end_symtab (text_addr + text_size);
3610 This function allows the addition of incrementally linked object files.
3611 Since this has a fair amount of code in common with symbol_file_command,
3612 it might be worthwhile to consolidate things, as was done with
3613 read_dbx_symtab and condense_misc_bunches. */
3616 add_file_command (arg_string)
3620 DECLARE_FILE_HEADERS;
3621 struct nlist *nlist;
3625 extern void close ();
3626 struct cleanup *old_chain;
3627 struct symtab *symseg;
3628 struct stat statbuf;
3632 if (arg_string == 0)
3633 error ("add-file takes a file name and an address");
3635 arg_string = tilde_expand (arg_string);
3636 make_cleanup (free, arg_string);
3638 for( ; *arg_string == ' '; arg_string++ );
3640 for( ; *arg_string && *arg_string != ' ' ; arg_string++ );
3641 *arg_string++ = (char) 0;
3644 error ("add-file takes a file name and an address");
3646 text_addr = parse_and_eval_address (arg_string);
3650 if (!query ("add symbol table from filename \"%s\" at text_addr = 0x%x\n",
3652 error ("Not confirmed.");
3654 desc = open (name, O_RDONLY);
3656 perror_with_name (name);
3658 old_chain = make_cleanup (close, desc);
3660 READ_FILE_HEADERS (desc, name);
3662 if (NUMBER_OF_SYMBOLS == 0)
3664 printf ("%s does not have a symbol-table.\n", name);
3669 printf ("Reading symbol data from %s...", name);
3672 /* Now read the string table, all at once. */
3673 val = lseek (desc, STRING_TABLE_OFFSET, 0);
3675 perror_with_name (name);
3676 stat (name, &statbuf);
3677 READ_STRING_TABLE_SIZE (buffer);
3678 if (buffer >= 0 && buffer < statbuf.st_size)
3680 #ifdef BROKEN_LARGE_ALLOCA
3681 stringtab = (char *) xmalloc (buffer);
3682 make_cleanup (free, stringtab);
3684 stringtab = (char *) alloca (buffer);
3689 if (stringtab == NULL)
3690 error ("ridiculous string table size: %d bytes", buffer);
3692 /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer.
3693 Occaisionally, it won't. */
3694 val = lseek (desc, STRING_TABLE_OFFSET, 0);
3696 perror_with_name (name);
3697 val = myread (desc, stringtab, buffer);
3699 perror_with_name (name);
3701 /* Symsegs are no longer supported by GDB. Setting symseg_chain to
3702 0 is easier than finding all the symseg code and eliminating it. */
3705 /* Position to read the symbol table. Do not read it all at once. */
3706 val = lseek (desc, SYMBOL_TABLE_OFFSET, 0);
3708 perror_with_name (name);
3710 init_misc_functions ();
3711 make_cleanup (discard_misc_bunches, 0);
3712 init_header_files ();
3713 make_cleanup (free_header_files, 0);
3718 make_cleanup (really_free_pendings, 0);
3720 read_addl_syms (desc, stringtab, NUMBER_OF_SYMBOLS, text_addr,
3721 SIZE_OF_TEXT_SEGMENT);
3724 /* Sort symbols alphabetically within each block. */
3728 /* Go over the misc functions and install them in vector. */
3730 condense_addl_misc_bunches (1);
3732 /* Don't allow char * to have a typename (else would get caddr_t.) */
3734 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
3736 do_cleanups (old_chain);
3738 /* Free the symtabs made by read_symsegs, but not their contents,
3739 which have been copied into symtabs on symtab_list. */
3740 while (symseg_chain)
3742 register struct symtab *s = symseg_chain->next;
3743 free (symseg_chain);
3751 /* Read a number by which a type is referred to in dbx data,
3752 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
3753 Just a single number N is equivalent to (0,N).
3754 Return the two numbers by storing them in the vector TYPENUMS.
3755 TYPENUMS will then be used as an argument to dbx_lookup_type. */
3758 read_type_number (pp, typenums)
3760 register int *typenums;
3765 typenums[0] = read_number (pp, ',');
3766 typenums[1] = read_number (pp, ')');
3771 typenums[1] = read_number (pp, 0);
3777 static struct symbol *
3778 define_symbol (value, string, desc)
3783 register struct symbol *sym
3784 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
3785 char *p = (char *) index (string, ':');
3789 /* Ignore syms with empty names. */
3793 /* Ignore old-style symbols from cc -go */
3798 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
3799 /* Open-coded bcopy--saves function call time. */
3801 register char *p1 = string;
3802 register char *p2 = SYMBOL_NAME (sym);
3808 /* Determine the type of name being defined. */
3809 if ((*p >= '0' && *p <= '9') || *p == '(')
3814 /* c is a special case, not followed by a type-number.
3815 SYMBOL:c=iVALUE for an integer constant symbol.
3816 SYMBOL:c=rVALUE for a floating constant symbol.
3817 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3818 e.g. "b:c=e6,0" for "const b = blob1"
3819 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3823 error ("Invalid symbol data at symtab pos %d.", symnum);
3828 double d = atof (p);
3831 SYMBOL_TYPE (sym) = builtin_type_double;
3832 value = (char *) obstack_alloc (symbol_obstack, sizeof (double));
3833 bcopy (&d, value, sizeof (double));
3834 SYMBOL_VALUE_BYTES (sym) = value;
3835 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
3840 SYMBOL_TYPE (sym) = builtin_type_int;
3841 SYMBOL_VALUE (sym) = atoi (p);
3842 SYMBOL_CLASS (sym) = LOC_CONST;
3846 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3847 e.g. "b:c=e6,0" for "const b = blob1"
3848 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3852 read_type_number (&p, typenums);
3854 error ("Invalid symbol data: no comma in enum const symbol");
3856 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
3857 SYMBOL_VALUE (sym) = atoi (p);
3858 SYMBOL_CLASS (sym) = LOC_CONST;
3862 error ("Invalid symbol data at symtab pos %d.", symnum);
3864 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3865 add_symbol_to_list (sym, &file_symbols);
3869 /* Now usually comes a number that says which data type,
3870 and possibly more stuff to define the type
3871 (all of which is handled by read_type) */
3873 if (deftype == 'p' && *p == 'F')
3874 /* pF is a two-letter code that means a function parameter in Fortran.
3875 The type-number specifies the type of the return value.
3876 Translate it into a pointer-to-function type. */
3880 = lookup_pointer_type (lookup_function_type (read_type (&p)));
3884 struct type *type = read_type (&p);
3886 if ((deftype == 'F' || deftype == 'f')
3887 && TYPE_CODE (type) != TYPE_CODE_FUNC)
3888 SYMBOL_TYPE (sym) = lookup_function_type (type);
3890 SYMBOL_TYPE (sym) = type;
3896 SYMBOL_CLASS (sym) = LOC_BLOCK;
3897 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3898 add_symbol_to_list (sym, &file_symbols);
3902 SYMBOL_CLASS (sym) = LOC_BLOCK;
3903 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3904 add_symbol_to_list (sym, &global_symbols);
3908 /* For a class G (global) symbol, it appears that the
3909 value is not correct. It is necessary to search for the
3910 corresponding linker definition to find the value.
3911 These definitions appear at the end of the namelist. */
3912 i = hashname (SYMBOL_NAME (sym));
3913 SYMBOL_VALUE (sym) = (int) global_sym_chain[i];
3914 global_sym_chain[i] = sym;
3915 SYMBOL_CLASS (sym) = LOC_STATIC;
3916 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3917 add_symbol_to_list (sym, &global_symbols);
3920 /* This case is faked by a conditional above,
3921 when there is no code letter in the dbx data.
3922 Dbx data never actually contains 'l'. */
3924 SYMBOL_CLASS (sym) = LOC_LOCAL;
3925 SYMBOL_VALUE (sym) = value;
3926 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3927 add_symbol_to_list (sym, &local_symbols);
3931 SYMBOL_CLASS (sym) = LOC_ARG;
3932 SYMBOL_VALUE (sym) = value;
3933 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3934 add_symbol_to_list (sym, &local_symbols);
3936 /* If it's compiled, if it says `short', believe it. */
3937 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
3940 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
3941 /* This macro is defined on machines (e.g. sparc) where
3942 we should believe the type of a PCC 'short' argument,
3943 but shouldn't believe the address (the address is
3944 the address of the corresponding int). Note that
3945 this is only different from the BELIEVE_PCC_PROMOTION
3946 case on big-endian machines.
3948 My guess is that this correction, as opposed to changing
3949 the parameter to an 'int' (as done below, for PCC
3950 on most machines), is the right thing to do
3951 on all machines, but I don't want to risk breaking
3952 something that already works. On most PCC machines,
3953 the sparc problem doesn't come up because the calling
3954 function has to zero the top bytes (not knowing whether
3955 the called function wants an int or a short), so there
3956 is no practical difference between an int and a short
3957 (except perhaps what happens when the GDB user types
3958 "print short_arg = 0x10000;"). */
3959 if (SYMBOL_TYPE (sym) == builtin_type_char
3960 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
3961 SYMBOL_VALUE (sym) += 3;
3962 if (SYMBOL_TYPE (sym) == builtin_type_short
3963 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
3964 SYMBOL_VALUE (sym) += 2;
3967 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
3969 /* If PCC says a parameter is a short or a char,
3970 it is really an int. */
3971 if (SYMBOL_TYPE (sym) == builtin_type_char
3972 || SYMBOL_TYPE (sym) == builtin_type_short)
3973 SYMBOL_TYPE (sym) = builtin_type_int;
3974 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
3975 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
3976 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
3979 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
3982 SYMBOL_CLASS (sym) = LOC_REGPARM;
3983 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (value);
3984 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3985 add_symbol_to_list (sym, &local_symbols);
3989 SYMBOL_CLASS (sym) = LOC_REGISTER;
3990 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (value);
3991 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3992 add_symbol_to_list (sym, &local_symbols);
3996 /* Static symbol at top level of file */
3997 SYMBOL_CLASS (sym) = LOC_STATIC;
3998 SYMBOL_VALUE (sym) = value;
3999 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4000 add_symbol_to_list (sym, &file_symbols);
4004 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4005 SYMBOL_VALUE (sym) = value;
4006 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4007 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
4008 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
4009 TYPE_NAME (SYMBOL_TYPE (sym)) =
4010 obsavestring (SYMBOL_NAME (sym),
4011 strlen (SYMBOL_NAME (sym)));
4012 /* C++ vagaries: we may have a type which is derived from
4013 a base type which did not have its name defined when the
4014 derived class was output. We fill in the derived class's
4015 base part member's name here in that case. */
4016 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
4017 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
4018 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
4021 for (i = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)); i > 0; i--)
4022 if (TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) == 0)
4023 TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) =
4024 TYPE_NAME (TYPE_BASECLASS (SYMBOL_TYPE (sym), i));
4027 add_symbol_to_list (sym, &file_symbols);
4031 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4032 SYMBOL_VALUE (sym) = value;
4033 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
4034 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
4035 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
4036 TYPE_NAME (SYMBOL_TYPE (sym))
4038 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
4040 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
4041 ? "struct " : "union ")),
4043 add_symbol_to_list (sym, &file_symbols);
4047 /* Static symbol of local scope */
4048 SYMBOL_CLASS (sym) = LOC_STATIC;
4049 SYMBOL_VALUE (sym) = value;
4050 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4051 add_symbol_to_list (sym, &local_symbols);
4055 /* Reference parameter */
4056 SYMBOL_CLASS (sym) = LOC_REF_ARG;
4057 SYMBOL_VALUE (sym) = value;
4058 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4059 add_symbol_to_list (sym, &local_symbols);
4063 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
4068 /* What about types defined as forward references inside of a small lexical
4070 /* Add a type to the list of undefined types to be checked through
4071 once this file has been read in. */
4073 add_undefined_type (type)
4076 if (undef_types_length == undef_types_allocated)
4078 undef_types_allocated *= 2;
4079 undef_types = (struct type **)
4080 xrealloc (undef_types,
4081 undef_types_allocated * sizeof (struct type *));
4083 undef_types[undef_types_length++] = type;
4086 /* Add here something to go through each undefined type, see if it's
4087 still undefined, and do a full lookup if so. */
4089 cleanup_undefined_types ()
4091 struct type **type, *ntype;
4094 for (type = undef_types; type < undef_types + undef_types_length; type++)
4096 struct type *ntype = 0;
4097 /* Reasonable test to see if it's been defined since. */
4098 if (TYPE_NFIELDS (*type) == 0)
4100 struct pending *ppt;
4102 /* Name of the type, without "struct" or "union" */
4103 char *typename = TYPE_NAME (*type);
4105 if (!strncmp (typename, "struct ", 7))
4107 if (!strncmp (typename, "union ", 6))
4110 for (ppt = file_symbols; ppt; ppt = ppt->next)
4111 for (i = 0; i < ppt->nsyms; i++)
4113 struct symbol *sym = ppt->symbol[i];
4115 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4116 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4117 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
4119 && !strcmp (SYMBOL_NAME (sym), typename))
4120 bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type));
4124 /* It has been defined; don't mark it as a stub. */
4125 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
4127 undef_types_length = 0;
4132 /* Read a dbx type reference or definition;
4133 return the type that is meant.
4134 This can be just a number, in which case it references
4135 a type already defined and placed in type_vector.
4136 Or the number can be followed by an =, in which case
4137 it means to define a new type according to the text that
4145 register struct type *type = 0;
4152 /* Read type number if present. The type number may be omitted.
4153 for instance in a two-dimensional array declared with type
4154 "ar1;1;10;ar1;1;10;4". */
4155 if ((**pp >= '0' && **pp <= '9')
4158 read_type_number (pp, typenums);
4160 /* Detect random reference to type not yet defined.
4161 Allocate a type object but leave it zeroed. */
4163 return dbx_alloc_type (typenums);
4169 /* 'typenums=' not present, type is anonymous. Read and return
4170 the definition, but don't put it in the type vector. */
4171 typenums[0] = typenums[1] = -1;
4179 enum type_code code;
4181 /* Used to index through file_symbols. */
4182 struct pending *ppt;
4185 /* Name including "struct", etc. */
4188 /* Name without "struct", etc. */
4189 char *type_name_only;
4195 /* Set the type code according to the following letter. */
4199 code = TYPE_CODE_STRUCT;
4203 code = TYPE_CODE_UNION;
4207 code = TYPE_CODE_ENUM;
4211 error ("Bad type cross reference at symnum: %d.", symnum);
4214 to = type_name = (char *)
4215 obstack_alloc (symbol_obstack,
4217 ((char *) index (*pp, ':') - (*pp)) + 1));
4219 /* Copy the prefix. */
4221 while (*to++ = *from++)
4225 type_name_only = to;
4227 /* Copy the name. */
4229 while ((*to++ = *from++) != ':')
4233 /* Set the pointer ahead of the name which we just read. */
4236 /* Note: for C++, the cross reference may be to a base type which
4237 has not yet been seen. In this case, we skip to the comma,
4238 which will mark the end of the base class name. (The ':'
4239 at the end of the base class name will be skipped as well.)
4240 But sometimes (ie. when the cross ref is the last thing on
4241 the line) there will be no ','. */
4242 from = (char *) index (*pp, ',');
4247 /* Now check to see whether the type has already been declared. */
4248 /* This is necessary at least in the case where the
4249 program says something like
4251 The compiler puts out a cross-reference; we better find
4252 set the length of the structure correctly so we can
4253 set the length of the array. */
4254 for (ppt = file_symbols; ppt; ppt = ppt->next)
4255 for (i = 0; i < ppt->nsyms; i++)
4257 struct symbol *sym = ppt->symbol[i];
4259 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4260 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4261 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
4262 && !strcmp (SYMBOL_NAME (sym), type_name_only))
4264 obstack_free (symbol_obstack, type_name);
4265 type = SYMBOL_TYPE (sym);
4270 /* Didn't find the type to which this refers, so we must
4271 be dealing with a forward reference. Allocate a type
4272 structure for it, and keep track of it so we can
4273 fill in the rest of the fields when we get the full
4275 type = dbx_alloc_type (typenums);
4276 TYPE_CODE (type) = code;
4277 TYPE_NAME (type) = type_name;
4279 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
4281 add_undefined_type (type);
4297 read_type_number (pp, xtypenums);
4298 type = *dbx_lookup_type (xtypenums);
4300 type = builtin_type_void;
4301 if (typenums[0] != -1)
4302 *dbx_lookup_type (typenums) = type;
4306 type1 = read_type (pp);
4307 if (TYPE_POINTER_TYPE (type1))
4309 type = TYPE_POINTER_TYPE (type1);
4310 if (typenums[0] != -1)
4311 *dbx_lookup_type (typenums) = type;
4315 type = dbx_alloc_type (typenums);
4316 smash_to_pointer_type (type, type1);
4322 struct type *domain = read_type (pp);
4324 struct type *memtype;
4326 if (*(*pp)++ != ',')
4327 error ("invalid member type data format, at symtab pos %d.",
4330 memtype = read_type (pp);
4331 type = dbx_alloc_type (typenums);
4332 smash_to_member_type (type, domain, memtype);
4338 struct type *domain = read_type (pp);
4340 struct type *return_type;
4343 if (*(*pp)++ != ',')
4344 error ("invalid member type data format, at symtab pos %d.",
4347 return_type = read_type (pp);
4348 args = read_args (pp, ';');
4349 type = dbx_alloc_type (typenums);
4350 smash_to_method_type (type, domain, return_type, args);
4355 type1 = read_type (pp);
4356 if (TYPE_REFERENCE_TYPE (type1))
4358 type = TYPE_REFERENCE_TYPE (type1);
4359 if (typenums[0] != -1)
4360 *dbx_lookup_type (typenums) = type;
4364 type = dbx_alloc_type (typenums);
4365 smash_to_reference_type (type, type1);
4370 type1 = read_type (pp);
4371 if (TYPE_FUNCTION_TYPE (type1))
4373 type = TYPE_FUNCTION_TYPE (type1);
4374 if (typenums[0] != -1)
4375 *dbx_lookup_type (typenums) = type;
4379 type = dbx_alloc_type (typenums);
4380 smash_to_function_type (type, type1);
4385 type = read_range_type (pp, typenums);
4386 if (typenums[0] != -1)
4387 *dbx_lookup_type (typenums) = type;
4391 type = dbx_alloc_type (typenums);
4392 type = read_enum_type (pp, type);
4393 *dbx_lookup_type (typenums) = type;
4397 type = dbx_alloc_type (typenums);
4398 type = read_struct_type (pp, type);
4402 type = dbx_alloc_type (typenums);
4403 type = read_struct_type (pp, type);
4404 TYPE_CODE (type) = TYPE_CODE_UNION;
4408 if (*(*pp)++ != 'r')
4409 error ("Invalid symbol data: unrecognized type-code `a%c' %s %d.",
4410 (*pp)[-1], "at symtab position", symnum);
4412 type = dbx_alloc_type (typenums);
4413 type = read_array_type (pp, type);
4417 error ("Invalid symbol data: unrecognized type-code `%c' at symtab pos %d.",
4425 /* If this is an overriding temporary alteration for a header file's
4426 contents, and this type number is unknown in the global definition,
4427 put this type into the global definition at this type number. */
4428 if (header_file_prev_index >= 0)
4430 register struct type **tp
4431 = explicit_lookup_type (header_file_prev_index, typenums[1]);
4439 /* This page contains subroutines of read_type. */
4441 /* Read the description of a structure (or union type)
4442 and return an object describing the type. */
4444 static struct type *
4445 read_struct_type (pp, type)
4447 register struct type *type;
4451 struct nextfield *next;
4458 struct next_fnfield *next;
4460 struct fn_field fn_field;
4463 struct next_fnfieldlist
4465 struct next_fnfieldlist *next;
4466 struct fn_fieldlist fn_fieldlist;
4469 register struct nextfield *list = 0;
4470 struct nextfield *new;
4477 register struct next_fnfieldlist *mainlist = 0;
4479 struct type *baseclass = NULL;
4480 int read_possible_virtual_info = 0;
4482 if (TYPE_MAIN_VARIANT (type) == 0)
4484 TYPE_MAIN_VARIANT (type) = type;
4487 TYPE_CODE (type) = TYPE_CODE_STRUCT;
4489 /* First comes the total size in bytes. */
4491 TYPE_LENGTH (type) = read_number (pp, 0);
4493 /* C++: Now, if the class is a derived class, then the next character
4494 will be a '!', followed by the number of base classes derived from.
4495 Each element in the list contains visibility information,
4496 the offset of this base class in the derived structure,
4497 and then the base type. */
4500 int i, n_baseclasses, offset;
4501 struct type **baseclass_vec;
4502 struct type *baseclass;
4505 /* Nonzero if it is a virtual baseclass, i.e.,
4509 struct C : public B, public virtual A {};
4511 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
4512 2.0 language feature. */
4517 n_baseclasses = read_number (pp, ',');
4518 baseclass_vec = (struct type **)
4519 obstack_alloc (symbol_obstack,
4520 (n_baseclasses) * sizeof (struct type **)) - 1;
4522 for (i = 1; i <= n_baseclasses; i++)
4525 *pp = next_symbol_text ();
4536 error ("Invalid symbol data: bad visibility format at symtab pos %d",
4549 error ("Invalid symbol data: bad visibility format at symtab pos %d.",
4552 offset = read_number (pp, ',');
4553 baseclass = read_type (pp);
4554 *pp += 1; /* skip trailing ';' */
4555 baseclass_vec[i] = lookup_basetype_type (baseclass, offset, via_virtual, via_public);
4557 /* Since lookup_basetype_type can copy the type,
4558 it might copy a stub type (complete with stub flag).
4559 If so, we need to add it to the list of undefined types
4560 to clean up later. Even if lookup_basetype_type
4561 didn't copy the type, adding it to the undefined list
4562 will not do any harm. */
4563 if (TYPE_FLAGS(baseclass_vec[i]) & TYPE_FLAG_STUB)
4564 add_undefined_type (baseclass_vec[i]);
4566 /* Make this baseclass visible for structure-printing purposes. */
4567 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4570 list->field.type = baseclass_vec[i];
4571 list->field.name = TYPE_NAME (baseclass_vec[i]);
4572 list->field.bitpos = offset;
4573 list->field.bitsize = 0; /* this should be an unpacked field! */
4576 TYPE_N_BASECLASSES (type) = n_baseclasses;
4577 TYPE_BASECLASSES (type) = baseclass_vec;
4580 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
4581 At the end, we see a semicolon instead of a field.
4583 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
4586 The `?' is a placeholder for one of '+' (public visibility),
4587 '0' (protected visibility), and '-' (private visibility). */
4589 /* We better set p right now, in case there are no fields at all... */
4596 /* Check for and handle cretinous dbx symbol name continuation! */
4597 if (**pp == '\\') *pp = next_symbol_text ();
4599 /* Get space to record the next field's data. */
4600 new = (struct nextfield *) alloca (sizeof (struct nextfield));
4604 /* Read the data. */
4606 while (*p != ':') p++;
4607 list->field.name = obsavestring (*pp, p - *pp);
4609 /* C++: Check to see if we have hit the methods yet. */
4615 /* This means we have a visibility for a field coming. */
4636 /* else normal dbx-style format. */
4638 list->field.type = read_type (pp);
4641 list->field.bitpos = (long)-1;
4643 while (*p != ';') p++;
4644 list->field.bitsize = (long) savestring (*pp, p - *pp);
4649 else if (**pp != ',')
4650 error ("Invalid symbol data: bad structure-type format at symtab pos %d.",
4652 (*pp)++; /* Skip the comma. */
4653 list->field.bitpos = read_number (pp, ',');
4654 list->field.bitsize = read_number (pp, ';');
4657 /* This is wrong because this is identical to the symbols
4658 produced for GCC 0-size arrays. For example:
4663 The code which dumped core in such circumstances should be
4664 fixed not to dump core. */
4666 /* g++ -g0 can put out bitpos & bitsize zero for a static
4667 field. This does not give us any way of getting its
4668 class, so we can't know its name. But we can just
4669 ignore the field so we don't dump core and other nasty
4671 if (list->field.bitpos == 0
4672 && list->field.bitsize == 0)
4674 /* Have we given the warning yet? */
4675 static int warning_given = 0;
4677 /* Only give the warning once, no matter how many class
4678 variables there are. */
4682 fprintf_filtered (stderr, "\n\
4683 Warning: DBX-style class variable debugging information encountered.\n\
4684 You seem to have compiled your program with \
4685 \"g++ -g0\" instead of \"g++ -g\".\n\
4686 Therefore GDB will not know about your class variables.\n\
4690 /* Ignore this field. */
4696 /* Detect an unpacked field and mark it as such.
4697 dbx gives a bit size for all fields.
4698 Note that forward refs cannot be packed,
4699 and treat enums as if they had the width of ints. */
4700 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
4701 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
4702 list->field.bitsize = 0;
4703 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
4704 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
4705 && (list->field.bitsize
4706 == 8 * TYPE_LENGTH (builtin_type_int))
4710 list->field.bitpos % 8 == 0)
4711 list->field.bitsize = 0;
4716 /* Now come the method fields, as NAME::methods
4717 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
4718 At the end, we see a semicolon instead of a field.
4720 For the case of overloaded operators, the format is
4721 OPERATOR::*.methods, where OPERATOR is the string "operator",
4722 `*' holds the place for an operator name (such as `+=')
4723 and `.' marks the end of the operator name. */
4726 /* Now, read in the methods. To simplify matters, we
4727 "unread" the name that has been read, so that we can
4728 start from the top. */
4732 /* chill the list of fields: the last entry (at the head)
4733 is a partially constructed entry which we now scrub. */
4736 /* For each list of method lists... */
4740 struct next_fnfield *sublist = 0;
4741 struct fn_field *fn_fields = 0;
4743 struct next_fnfieldlist *new_mainlist =
4744 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
4746 /* read in the name. */
4747 while (*p != ':') p++;
4748 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == '$')
4750 static char opname[32] = "operator ";
4751 char *o = opname + 9;
4753 /* Skip past '::'. */
4757 new_mainlist->fn_fieldlist.name = savestring (opname, o - opname);
4764 new_mainlist->fn_fieldlist.name = savestring (*pp, p - *pp);
4765 /* Skip past '::'. */
4771 struct next_fnfield *new_sublist =
4772 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
4774 /* Check for and handle cretinous dbx symbol name continuation! */
4775 if (**pp == '\\') *pp = next_symbol_text ();
4777 new_sublist->fn_field.type = read_type (pp);
4779 error ("invalid symtab info for method at symbol number %d.",
4782 new_sublist->fn_field.args =
4783 TYPE_ARG_TYPES (new_sublist->fn_field.type);
4785 while (*p != ';') p++;
4786 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
4788 new_sublist->visibility = *(*pp)++ - '0';
4789 if (**pp == '\\') *pp = next_symbol_text ();
4794 /* virtual member function, followed by index. */
4795 new_sublist->fn_field.voffset = read_number (pp, ';') + 1;
4798 /* static member function. */
4799 new_sublist->fn_field.voffset = 1;
4803 /* normal member function. */
4804 new_sublist->fn_field.voffset = 0;
4808 new_sublist->next = sublist;
4809 sublist = new_sublist;
4812 while (**pp != ';');
4816 new_mainlist->fn_fieldlist.fn_fields =
4817 (struct fn_field *) obstack_alloc (symbol_obstack,
4818 sizeof (struct fn_field) * length);
4819 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
4820 (int *) obstack_alloc (symbol_obstack,
4821 sizeof (int) * (1 + (length >> 5)));
4823 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
4824 (int *) obstack_alloc (symbol_obstack,
4825 sizeof (int) * (1 + (length >> 5)));
4827 for (i = length; sublist; sublist = sublist->next)
4829 new_mainlist->fn_fieldlist.fn_fields[--i] = sublist->fn_field;
4830 if (sublist->visibility == 0)
4831 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
4832 else if (sublist->visibility == 1)
4833 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
4836 new_mainlist->fn_fieldlist.length = length;
4837 new_mainlist->next = mainlist;
4838 mainlist = new_mainlist;
4841 while (**pp != ';');
4846 /* Now create the vector of fields, and record how big it is. */
4848 TYPE_NFIELDS (type) = nfields;
4849 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
4850 sizeof (struct field) * nfields);
4851 TYPE_FIELD_PRIVATE_BITS (type) =
4852 (int *) obstack_alloc (symbol_obstack,
4853 sizeof (int) * (1 + (nfields >> 5)));
4854 TYPE_FIELD_PROTECTED_BITS (type) =
4855 (int *) obstack_alloc (symbol_obstack,
4856 sizeof (int) * (1 + (nfields >> 5)));
4858 TYPE_NFN_FIELDS (type) = nfn_fields;
4859 TYPE_NFN_FIELDS_TOTAL (type) = nfn_fields;
4861 TYPE_NFN_FIELDS_TOTAL (type) += TYPE_NFN_FIELDS_TOTAL (baseclass);
4863 TYPE_FN_FIELDLISTS (type) =
4864 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
4865 sizeof (struct fn_fieldlist) * nfn_fields);
4867 /* Copy the saved-up fields into the field vector. */
4869 for (n = nfields; list; list = list->next)
4871 TYPE_FIELD (type, --n) = list->field;
4872 if (list->visibility == 0)
4873 SET_TYPE_FIELD_PRIVATE (type, n);
4874 else if (list->visibility == 1)
4875 SET_TYPE_FIELD_PROTECTED (type, n);
4878 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
4879 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
4888 |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
4891 else if (**pp == '+')
4893 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
4896 else if (**pp == '-')
4898 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
4902 /* Read either a '%' or the final ';'. */
4903 if (*(*pp)++ == '%')
4905 /* Now we must record the virtual function table pointer's
4906 field information. */
4913 while (*p != ';') p++;
4914 TYPE_VPTR_BASETYPE (type) = t;
4917 if (TYPE_FIELD_NAME (t, 0) == 0)
4918 TYPE_VPTR_FIELDNO (type) = i = 0;
4919 else for (i = TYPE_NFIELDS (t) - 1; i >= 0; --i)
4920 if (! strncmp (TYPE_FIELD_NAME (t, i), *pp,
4921 strlen (TYPE_FIELD_NAME (t, i))))
4923 TYPE_VPTR_FIELDNO (type) = i;
4927 error ("virtual function table field not found");
4930 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, 1));
4935 TYPE_VPTR_BASETYPE (type) = 0;
4936 TYPE_VPTR_FIELDNO (type) = -1;
4941 TYPE_VPTR_BASETYPE (type) = 0;
4942 TYPE_VPTR_FIELDNO (type) = -1;
4948 /* Read a definition of an array type,
4949 and create and return a suitable type object.
4950 Also creates a range type which represents the bounds of that
4952 static struct type *
4953 read_array_type (pp, type)
4955 register struct type *type;
4957 struct type *index_type, *element_type, *range_type;
4961 /* Format of an array type:
4962 "ar<index type>;lower;upper;<array_contents_type>". Put code in
4965 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4966 for these, produce a type like float[][]. */
4968 index_type = read_type (pp);
4969 if (*(*pp)++ != ';')
4970 error ("Invalid symbol data; improper format of array type decl.");
4972 if (!(**pp >= '0' && **pp <= '9'))
4977 lower = read_number (pp, ';');
4979 if (!(**pp >= '0' && **pp <= '9'))
4984 upper = read_number (pp, ';');
4986 element_type = read_type (pp);
4995 /* Create range type. */
4996 range_type = (struct type *) obstack_alloc (symbol_obstack,
4997 sizeof (struct type));
4998 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
4999 TYPE_TARGET_TYPE (range_type) = index_type;
5001 /* This should never be needed. */
5002 TYPE_LENGTH (range_type) = sizeof (int);
5004 TYPE_NFIELDS (range_type) = 2;
5005 TYPE_FIELDS (range_type) =
5006 (struct field *) obstack_alloc (symbol_obstack,
5007 2 * sizeof (struct field));
5008 TYPE_FIELD_BITPOS (range_type, 0) = lower;
5009 TYPE_FIELD_BITPOS (range_type, 1) = upper;
5012 TYPE_CODE (type) = TYPE_CODE_ARRAY;
5013 TYPE_TARGET_TYPE (type) = element_type;
5014 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
5015 TYPE_NFIELDS (type) = 1;
5016 TYPE_FIELDS (type) =
5017 (struct field *) obstack_alloc (symbol_obstack,
5018 sizeof (struct field));
5019 TYPE_FIELD_TYPE (type, 0) = range_type;
5025 /* Read a definition of an enumeration type,
5026 and create and return a suitable type object.
5027 Also defines the symbols that represent the values of the type. */
5029 static struct type *
5030 read_enum_type (pp, type)
5032 register struct type *type;
5037 register struct symbol *sym;
5039 struct pending **symlist;
5040 struct pending *osyms, *syms;
5043 if (within_function)
5044 symlist = &local_symbols;
5046 symlist = &file_symbols;
5048 o_nsyms = osyms ? osyms->nsyms : 0;
5050 /* Read the value-names and their values.
5051 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
5052 A semicolon or comman instead of a NAME means the end. */
5053 while (**pp && **pp != ';' && **pp != ',')
5055 /* Check for and handle cretinous dbx symbol name continuation! */
5056 if (**pp == '\\') *pp = next_symbol_text ();
5059 while (*p != ':') p++;
5060 name = obsavestring (*pp, p - *pp);
5062 n = read_number (pp, ',');
5064 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
5065 bzero (sym, sizeof (struct symbol));
5066 SYMBOL_NAME (sym) = name;
5067 SYMBOL_CLASS (sym) = LOC_CONST;
5068 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
5069 SYMBOL_VALUE (sym) = n;
5070 add_symbol_to_list (sym, symlist);
5075 (*pp)++; /* Skip the semicolon. */
5077 /* Now fill in the fields of the type-structure. */
5079 TYPE_LENGTH (type) = sizeof (int);
5080 TYPE_CODE (type) = TYPE_CODE_ENUM;
5081 TYPE_NFIELDS (type) = nsyms;
5082 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
5084 /* Find the symbols for the values and put them into the type.
5085 The symbols can be found in the symlist that we put them on
5086 to cause them to be defined. osyms contains the old value
5087 of that symlist; everything up to there was defined by us. */
5088 /* Note that we preserve the order of the enum constants, so
5089 that in something like "enum {FOO, LAST_THING=FOO}" we print
5090 FOO, not LAST_THING. */
5092 for (syms = *symlist, n = 0; syms; syms = syms->next)
5097 for (; j < syms->nsyms; j++)
5099 struct symbol *sym = syms->symbol[j];
5100 SYMBOL_TYPE (sym) = type;
5101 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (sym);
5102 TYPE_FIELD_VALUE (type, n) = 0;
5103 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (sym);
5104 TYPE_FIELD_BITSIZE (type, n++) = 0;
5113 #define MAX_OF_TYPE(t) ((1 << (sizeof (t) - 1)) - 1)
5114 #define MIN_OF_TYPE(t) (-(1 << (sizeof (t) - 1)))
5116 static struct type *
5117 read_range_type (pp, typenums)
5125 struct type *result_type;
5127 /* First comes a type we are a subrange of.
5128 In C it is usually 0, 1 or the type being defined. */
5129 read_type_number (pp, rangenums);
5130 self_subrange = (rangenums[0] == typenums[0] &&
5131 rangenums[1] == typenums[1]);
5133 /* A semicolon should now follow; skip it. */
5137 /* The remaining two operands are usually lower and upper bounds
5138 of the range. But in some special cases they mean something else. */
5139 n2 = read_number (pp, ';');
5140 n3 = read_number (pp, ';');
5142 /* A type defined as a subrange of itself, with bounds both 0, is void. */
5143 if (self_subrange && n2 == 0 && n3 == 0)
5144 return builtin_type_void;
5146 /* If n3 is zero and n2 is not, we want a floating type,
5147 and n2 is the width in bytes.
5149 Fortran programs appear to use this for complex types also,
5150 and they give no way to distinguish between double and single-complex!
5151 We don't have complex types, so we would lose on all fortran files!
5152 So return type `double' for all of those. It won't work right
5153 for the complex values, but at least it makes the file loadable. */
5155 if (n3 == 0 && n2 > 0)
5157 if (n2 == sizeof (float))
5158 return builtin_type_float;
5159 return builtin_type_double;
5162 /* If the upper bound is -1, it must really be an unsigned int. */
5164 else if (n2 == 0 && n3 == -1)
5166 if (sizeof (int) == sizeof (long))
5167 return builtin_type_unsigned_int;
5169 return builtin_type_unsigned_long;
5172 /* Special case: char is defined (Who knows why) as a subrange of
5173 itself with range 0-127. */
5174 else if (self_subrange && n2 == 0 && n3 == 127)
5175 return builtin_type_char;
5177 /* Assumptions made here: Subrange of self is equivalent to subrange
5180 && (self_subrange ||
5181 *dbx_lookup_type (rangenums) == builtin_type_int))
5183 /* an unsigned type */
5185 if (n3 == - sizeof (long long))
5186 return builtin_type_unsigned_long_long;
5188 if (n3 == (1 << (8 * sizeof (int))) - 1)
5189 return builtin_type_unsigned_int;
5190 if (n3 == (1 << (8 * sizeof (short))) - 1)
5191 return builtin_type_unsigned_short;
5192 if (n3 == (1 << (8 * sizeof (char))) - 1)
5193 return builtin_type_unsigned_char;
5196 else if (n3 == 0 && n2 == -sizeof (long long))
5197 return builtin_type_long_long;
5199 else if (n2 == -n3 -1)
5202 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
5203 return builtin_type_int;
5204 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
5205 return builtin_type_long;
5206 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
5207 return builtin_type_short;
5208 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
5209 return builtin_type_char;
5212 /* We have a real range type on our hands. Allocate space and
5213 return a real pointer. */
5215 /* At this point I don't have the faintest idea how to deal with
5216 a self_subrange type; I'm going to assume that this is used
5217 as an idiom, and that all of them are special cases. So . . . */
5219 error ("Type defined as subrange of itself.");
5221 result_type = (struct type *) obstack_alloc (symbol_obstack,
5222 sizeof (struct type));
5223 bzero (result_type, sizeof (struct type));
5225 TYPE_TARGET_TYPE (result_type) = (self_subrange ?
5227 *dbx_lookup_type(rangenums));
5229 /* We have to figure out how many bytes it takes to hold this
5230 range type. I'm going to assume that anything that is pushing
5231 the bounds of a long was taken care of above. */
5232 if (n2 >= MIN_OF_TYPE(char) && n3 <= MAX_OF_TYPE(char))
5233 TYPE_LENGTH (result_type) = 1;
5234 else if (n2 >= MIN_OF_TYPE(short) && n3 <= MAX_OF_TYPE(short))
5235 TYPE_LENGTH (result_type) = sizeof (short);
5236 else if (n2 >= MIN_OF_TYPE(int) && n3 <= MAX_OF_TYPE(int))
5237 TYPE_LENGTH (result_type) = sizeof (int);
5238 else if (n2 >= MIN_OF_TYPE(long) && n3 <= MAX_OF_TYPE(long))
5239 TYPE_LENGTH (result_type) = sizeof (long);
5241 error ("Ranged type doesn't fit within known sizes.");
5243 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
5244 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
5245 TYPE_NFIELDS (result_type) = 2;
5246 TYPE_FIELDS (result_type) =
5247 (struct field *) obstack_alloc (symbol_obstack,
5248 2 * sizeof (struct field));
5249 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
5250 TYPE_FIELD_BITPOS (result_type, 0) = n2;
5251 TYPE_FIELD_BITPOS (result_type, 1) = n3;
5256 /* Read a number from the string pointed to by *PP.
5257 The value of *PP is advanced over the number.
5258 If END is nonzero, the character that ends the
5259 number must match END, or an error happens;
5260 and that character is skipped if it does match.
5261 If END is zero, *PP is left pointing to that character. */
5264 read_number (pp, end)
5268 register char *p = *pp;
5269 register long n = 0;
5273 /* Handle an optional leading minus sign. */
5281 /* Read the digits, as far as they go. */
5283 while ((c = *p++) >= '0' && c <= '9')
5291 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
5300 /* Read in an argument list. This is a list of types. It is terminated with
5301 a ':', FYI. Return the list of types read in. */
5302 static struct type **
5307 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
5313 error ("Invalid argument list: no ',', at symtab pos %d", symnum);
5316 /* Check for and handle cretinous dbx symbol name continuation! */
5318 *pp = next_symbol_text ();
5320 types[n++] = read_type (pp);
5322 *pp += 1; /* get past `end' (the ':' character) */
5326 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
5328 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
5330 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
5331 bzero (rval + n, sizeof (struct type *));
5335 rval = (struct type **) xmalloc (n * sizeof (struct type *));
5337 bcopy (types, rval, n * sizeof (struct type *));
5341 /* This function is really horrible, but to avoid it, there would need
5342 to be more filling in of forward references. THIS SHOULD BE MOVED OUT
5343 OF COFFREAD.C AND DBXREAD.C TO SOME PLACE WHERE IT CAN BE SHARED */
5345 fill_in_vptr_fieldno (type)
5348 if (TYPE_VPTR_FIELDNO (type) < 0)
5349 TYPE_VPTR_FIELDNO (type) =
5350 fill_in_vptr_fieldno (TYPE_BASECLASS (type, 1));
5351 return TYPE_VPTR_FIELDNO (type);
5354 /* Copy a pending list, used to record the contents of a common
5355 block for later fixup. */
5356 static struct pending *
5357 copy_pending (beg, begi, end)
5358 struct pending *beg, *end;
5361 struct pending *new = 0;
5362 struct pending *next;
5364 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
5365 next = next->next, begi = 0)
5368 for (j = begi; j < next->nsyms; j++)
5369 add_symbol_to_list (next->symbol[j], &new);
5374 /* Add a common block's start address to the offset of each symbol
5375 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5376 the common block name). */
5379 fix_common_block (sym, value)
5383 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
5384 for ( ; next; next = next->next)
5387 for (j = next->nsyms - 1; j >= 0; j--)
5388 SYMBOL_VALUE (next->symbol[j]) += value;
5393 _initialize_dbxread ()
5396 header_files = (struct header_file *) 0;
5397 this_object_header_files = (int *) 0;
5399 undef_types_allocated = 20;
5400 undef_types_length = 0;
5401 undef_types = (struct type **) xmalloc (undef_types_allocated *
5402 sizeof (struct type *));
5404 add_com ("symbol-file", class_files, symbol_file_command,
5405 "Load symbol table (in dbx format) from executable file FILE.");
5407 add_com ("add-file", class_files, add_file_command,
5408 "Load the symbols from FILE, assuming its code is at TEXT_START.") ;
5411 #endif /* READ_DBX_FORMAT */