1 /* Build symbol tables in GDB's internal format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This module provides subroutines used for creating and adding to
21 the symbol table. These routines are called from various symbol-
22 file-reading routines.
24 They originated in dbxread.c of gdb-4.2, and were split out to
25 make xcoffread.c more maintainable by sharing code. */
31 #include "breakpoint.h"
32 #include "gdbcore.h" /* for bfd stuff for symfile.h */
33 #include "symfile.h" /* Needed for "struct complaint" */
35 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
39 /* Ask buildsym.h to define the vars it normally declares `extern'. */
41 #include "buildsym.h" /* Our own declarations */
45 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
49 read_huge_number PARAMS ((char **, int, long *, int *));
52 dbx_alloc_type PARAMS ((int [2], struct objfile *));
55 compare_line_numbers PARAMS ((const void *, const void *));
57 static struct blockvector *
58 make_blockvector PARAMS ((struct objfile *));
61 fix_common_block PARAMS ((struct symbol *, int));
64 cleanup_undefined_types PARAMS ((void));
67 read_range_type PARAMS ((char **, int [2], struct objfile *));
70 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
73 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
76 read_array_type PARAMS ((char **, struct type *, struct objfile *));
79 read_args PARAMS ((char **, int, struct objfile *));
83 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
84 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
86 /* Define this as 1 if a pcc declaration of a char or short argument
87 gives the correct address. Otherwise assume pcc gives the
88 address of the corresponding int, which is not the same on a
89 big-endian machine. */
91 #ifndef BELIEVE_PCC_PROMOTION
92 #define BELIEVE_PCC_PROMOTION 0
95 /* During some calls to read_type (and thus to read_range_type), this
96 contains the name of the type being defined. Range types are only
97 used in C as basic types. We use the name to distinguish the otherwise
98 identical basic types "int" and "long" and their unsigned versions.
99 FIXME, this should disappear with better type management. */
101 static char *long_kludge_name;
103 /* Make a list of forward references which haven't been defined. */
104 static struct type **undef_types;
105 static int undef_types_allocated, undef_types_length;
107 /* Initial sizes of data structures. These are realloc'd larger if needed,
108 and realloc'd down to the size actually used, when completed. */
110 #define INITIAL_CONTEXT_STACK_SIZE 10
111 #define INITIAL_TYPE_VECTOR_LENGTH 160
112 #define INITIAL_LINE_VECTOR_LENGTH 1000
114 /* Complaints about the symbols we have encountered. */
116 struct complaint innerblock_complaint =
117 {"inner block not inside outer block in %s", 0, 0};
119 struct complaint blockvector_complaint =
120 {"block at %x out of order", 0, 0};
123 struct complaint dbx_class_complaint =
124 {"encountered DBX-style class variable debugging information.\n\
125 You seem to have compiled your program with \
126 \"g++ -g0\" instead of \"g++ -g\".\n\
127 Therefore GDB will not know about your class variables", 0, 0};
130 struct complaint invalid_cpp_abbrev_complaint =
131 {"invalid C++ abbreviation `%s'", 0, 0};
133 struct complaint invalid_cpp_type_complaint =
134 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
136 struct complaint member_fn_complaint =
137 {"member function type missing, got '%c'", 0, 0};
139 struct complaint const_vol_complaint =
140 {"const/volatile indicator missing, got '%c'", 0, 0};
142 struct complaint error_type_complaint =
143 {"debug info mismatch between compiler and debugger", 0, 0};
145 struct complaint invalid_member_complaint =
146 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
148 struct complaint range_type_base_complaint =
149 {"base type %d of range type is not defined", 0, 0};
151 struct complaint reg_value_complaint =
152 {"register number too large in symbol %s", 0, 0};
158 register char *p = name;
159 register int total = p[0];
172 /* Ensure result is positive. */
173 if (total < 0) total += (1000 << 6);
174 return total % HASHSIZE;
178 /* Look up a dbx type-number pair. Return the address of the slot
179 where the type for that number-pair is stored.
180 The number-pair is in TYPENUMS.
182 This can be used for finding the type associated with that pair
183 or for associating a new type with the pair. */
186 dbx_lookup_type (typenums)
189 register int filenum = typenums[0], index = typenums[1];
192 if (filenum == -1) /* -1,-1 is for temporary types. */
195 if (filenum < 0 || filenum >= n_this_object_header_files)
196 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
197 filenum, index, symnum);
201 /* Type is defined outside of header files.
202 Find it in this object file's type vector. */
203 if (index >= type_vector_length)
205 old_len = type_vector_length;
207 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
208 type_vector = (struct type **)
209 malloc (type_vector_length * sizeof (struct type *));
211 while (index >= type_vector_length)
212 type_vector_length *= 2;
213 type_vector = (struct type **)
214 xrealloc ((char *) type_vector,
215 (type_vector_length * sizeof (struct type *)));
216 bzero (&type_vector[old_len],
217 (type_vector_length - old_len) * sizeof (struct type *));
219 return &type_vector[index];
223 register int real_filenum = this_object_header_files[filenum];
224 register struct header_file *f;
227 if (real_filenum >= n_header_files)
230 f = &header_files[real_filenum];
232 f_orig_length = f->length;
233 if (index >= f_orig_length)
235 while (index >= f->length)
237 f->vector = (struct type **)
238 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
239 bzero (&f->vector[f_orig_length],
240 (f->length - f_orig_length) * sizeof (struct type *));
242 return &f->vector[index];
246 /* Make sure there is a type allocated for type numbers TYPENUMS
247 and return the type object.
248 This can create an empty (zeroed) type object.
249 TYPENUMS may be (-1, -1) to return a new type object that is not
250 put into the type vector, and so may not be referred to by number. */
253 dbx_alloc_type (typenums, objfile)
255 struct objfile *objfile;
257 register struct type **type_addr;
259 if (typenums[0] == -1)
260 return alloc_type (objfile);
262 type_addr = dbx_lookup_type (typenums);
264 /* If we are referring to a type not known at all yet,
265 allocate an empty type for it.
266 We will fill it in later if we find out how. */
268 *type_addr = alloc_type (objfile);
273 /* maintain the lists of symbols and blocks */
275 /* Add a symbol to one of the lists of symbols. */
277 add_symbol_to_list (symbol, listhead)
278 struct symbol *symbol;
279 struct pending **listhead;
281 /* We keep PENDINGSIZE symbols in each link of the list.
282 If we don't have a link with room in it, add a new link. */
283 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
285 register struct pending *link;
288 link = free_pendings;
289 free_pendings = link->next;
292 link = (struct pending *) xmalloc (sizeof (struct pending));
294 link->next = *listhead;
299 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
302 /* Find a symbol on a pending list. */
304 find_symbol_in_list (list, name, length)
305 struct pending *list;
312 for (j = list->nsyms; --j >= 0; ) {
313 char *pp = SYMBOL_NAME (list->symbol[j]);
314 if (*pp == *name && strncmp (pp, name, length) == 0 && pp[length] == '\0')
315 return list->symbol[j];
322 /* At end of reading syms, or in case of quit,
323 really free as many `struct pending's as we can easily find. */
327 really_free_pendings (foo)
330 struct pending *next, *next1;
332 struct pending_block *bnext, *bnext1;
335 for (next = free_pendings; next; next = next1)
342 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
343 for (bnext = pending_blocks; bnext; bnext = bnext1)
345 bnext1 = bnext->next;
351 for (next = file_symbols; next; next = next1)
358 for (next = global_symbols; next; next = next1)
366 /* Take one of the lists of symbols and make a block from it.
367 Keep the order the symbols have in the list (reversed from the input file).
368 Put the block on the list of pending blocks. */
371 finish_block (symbol, listhead, old_blocks, start, end, objfile)
372 struct symbol *symbol;
373 struct pending **listhead;
374 struct pending_block *old_blocks;
375 CORE_ADDR start, end;
376 struct objfile *objfile;
378 register struct pending *next, *next1;
379 register struct block *block;
380 register struct pending_block *pblock;
381 struct pending_block *opblock;
384 /* Count the length of the list of symbols. */
386 for (next = *listhead, i = 0;
388 i += next->nsyms, next = next->next)
391 block = (struct block *) obstack_alloc (&objfile -> symbol_obstack,
392 (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
394 /* Copy the symbols into the block. */
396 BLOCK_NSYMS (block) = i;
397 for (next = *listhead; next; next = next->next)
400 for (j = next->nsyms - 1; j >= 0; j--)
401 BLOCK_SYM (block, --i) = next->symbol[j];
404 BLOCK_START (block) = start;
405 BLOCK_END (block) = end;
406 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
407 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
409 /* Put the block in as the value of the symbol that names it. */
413 SYMBOL_BLOCK_VALUE (symbol) = block;
414 BLOCK_FUNCTION (block) = symbol;
417 BLOCK_FUNCTION (block) = 0;
419 /* Now "free" the links of the list, and empty the list. */
421 for (next = *listhead; next; next = next1)
424 next->next = free_pendings;
425 free_pendings = next;
429 /* Install this block as the superblock
430 of all blocks made since the start of this scope
431 that don't have superblocks yet. */
434 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
436 if (BLOCK_SUPERBLOCK (pblock->block) == 0) {
438 /* Check to be sure the blocks are nested as we receive them.
439 If the compiler/assembler/linker work, this just burns a small
441 if (BLOCK_START (pblock->block) < BLOCK_START (block)
442 || BLOCK_END (pblock->block) > BLOCK_END (block)) {
443 complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol):
445 BLOCK_START (pblock->block) = BLOCK_START (block);
446 BLOCK_END (pblock->block) = BLOCK_END (block);
449 BLOCK_SUPERBLOCK (pblock->block) = block;
454 /* Record this block on the list of all blocks in the file.
455 Put it after opblock, or at the beginning if opblock is 0.
456 This puts the block in the list after all its subblocks. */
458 /* Allocate in the symbol_obstack to save time.
459 It wastes a little space. */
460 pblock = (struct pending_block *)
461 obstack_alloc (&objfile -> symbol_obstack,
462 sizeof (struct pending_block));
463 pblock->block = block;
466 pblock->next = opblock->next;
467 opblock->next = pblock;
471 pblock->next = pending_blocks;
472 pending_blocks = pblock;
476 static struct blockvector *
477 make_blockvector (objfile)
478 struct objfile *objfile;
480 register struct pending_block *next;
481 register struct blockvector *blockvector;
484 /* Count the length of the list of blocks. */
486 for (next = pending_blocks, i = 0; next; next = next->next, i++);
488 blockvector = (struct blockvector *)
489 obstack_alloc (&objfile -> symbol_obstack,
490 (sizeof (struct blockvector)
491 + (i - 1) * sizeof (struct block *)));
493 /* Copy the blocks into the blockvector.
494 This is done in reverse order, which happens to put
495 the blocks into the proper order (ascending starting address).
496 finish_block has hair to insert each block into the list
497 after its subblocks in order to make sure this is true. */
499 BLOCKVECTOR_NBLOCKS (blockvector) = i;
500 for (next = pending_blocks; next; next = next->next) {
501 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
504 #if 0 /* Now we make the links in the obstack, so don't free them. */
505 /* Now free the links of the list, and empty the list. */
507 for (next = pending_blocks; next; next = next1)
515 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
516 /* Some compilers output blocks in the wrong order, but we depend
517 on their being in the right order so we can binary search.
518 Check the order and moan about it. FIXME. */
519 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
520 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) {
521 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
522 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) {
523 complain (&blockvector_complaint,
524 (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
532 /* Start recording information about source code that came from an included
533 (or otherwise merged-in) source file with a different name. */
536 start_subfile (name, dirname)
540 register struct subfile *subfile;
542 /* See if this subfile is already known as a subfile of the
543 current main source file. */
545 for (subfile = subfiles; subfile; subfile = subfile->next)
547 if (!strcmp (subfile->name, name))
549 current_subfile = subfile;
554 /* This subfile is not known. Add an entry for it.
555 Make an entry for this subfile in the list of all subfiles
556 of the current main source file. */
558 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
559 subfile->next = subfiles;
561 current_subfile = subfile;
563 /* Save its name and compilation directory name */
564 subfile->name = strdup (name);
566 subfile->dirname = NULL;
568 subfile->dirname = strdup (dirname);
570 /* Initialize line-number recording for this subfile. */
571 subfile->line_vector = 0;
574 /* Handle the N_BINCL and N_EINCL symbol types
575 that act like N_SOL for switching source files
576 (different subfiles, as we call them) within one object file,
577 but using a stack rather than in an arbitrary order. */
582 register struct subfile_stack *tem
583 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
585 tem->next = subfile_stack;
587 if (current_subfile == 0 || current_subfile->name == 0)
589 tem->name = current_subfile->name;
596 register struct subfile_stack *link = subfile_stack;
602 subfile_stack = link->next;
608 /* Manage the vector of line numbers for each subfile. */
611 record_line (subfile, line, pc)
612 register struct subfile *subfile;
616 struct linetable_entry *e;
617 /* Ignore the dummy line number in libg.o */
622 /* Make sure line vector exists and is big enough. */
623 if (!subfile->line_vector) {
624 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
625 subfile->line_vector = (struct linetable *)
626 xmalloc (sizeof (struct linetable)
627 + subfile->line_vector_length * sizeof (struct linetable_entry));
628 subfile->line_vector->nitems = 0;
631 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
633 subfile->line_vector_length *= 2;
634 subfile->line_vector = (struct linetable *)
635 xrealloc ((char *) subfile->line_vector, (sizeof (struct linetable)
636 + subfile->line_vector_length * sizeof (struct linetable_entry)));
639 e = subfile->line_vector->item + subfile->line_vector->nitems++;
640 e->line = line; e->pc = pc;
644 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
647 compare_line_numbers (ln1p, ln2p)
651 return (((struct linetable_entry *) ln1p) -> line -
652 ((struct linetable_entry *) ln2p) -> line);
656 /* Start a new symtab for a new source file.
657 This is called when a dbx symbol of type N_SO is seen;
658 it indicates the start of data for one original source file. */
661 start_symtab (name, dirname, start_addr)
664 CORE_ADDR start_addr;
667 last_source_file = name;
668 last_source_start_addr = start_addr;
671 global_stabs = 0; /* AIX COFF */
674 /* Context stack is initially empty. Allocate first one with room for
675 10 levels; reuse it forever afterward. */
676 if (context_stack == 0) {
677 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
678 context_stack = (struct context_stack *)
679 xmalloc (context_stack_size * sizeof (struct context_stack));
681 context_stack_depth = 0;
683 /* Leave FILENUM of 0 free for builtin types and this file's types. */
684 n_this_object_header_files = 1;
686 type_vector_length = 0;
687 type_vector = (struct type **) 0;
689 /* Initialize the list of sub source files with one entry
690 for this file (the top-level source file). */
694 start_subfile (name, dirname);
697 /* for all the stabs in a given stab vector, build appropriate types
698 and fix their symbols in given symbol vector. */
701 patch_block_stabs (symbols, stabs, objfile)
702 struct pending *symbols;
703 struct pending_stabs *stabs;
704 struct objfile *objfile;
711 /* for all the stab entries, find their corresponding symbols and
712 patch their types! */
714 for (ii = 0; ii < stabs->count; ++ii)
716 char *name = stabs->stab[ii];
717 char *pp = (char*) strchr (name, ':');
718 struct symbol *sym = find_symbol_in_list (symbols, name, pp-name);
721 #ifndef IBM6000_TARGET
722 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
728 if (*(pp-1) == 'F' || *(pp-1) == 'f')
731 lookup_function_type (read_type (&pp, objfile));
735 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
742 /* Finish the symbol definitions for one main source file,
743 close off all the lexical contexts for that file
744 (creating struct block's for them), then make the struct symtab
745 for that file and put it in the list of all such.
747 END_ADDR is the address of the end of the file's text. */
750 end_symtab (end_addr, sort_pending, sort_linevec, objfile)
754 struct objfile *objfile;
756 register struct symtab *symtab;
757 register struct blockvector *blockvector;
758 register struct subfile *subfile;
759 struct subfile *nextsub;
761 /* Finish the lexical context of the last function in the file;
762 pop the context stack. */
764 if (context_stack_depth > 0)
766 register struct context_stack *cstk;
767 context_stack_depth--;
768 cstk = &context_stack[context_stack_depth];
769 /* Make a block for the local symbols within. */
770 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
771 cstk->start_addr, end_addr, objfile);
773 /* Debug: if context stack still has something in it, we are in
775 if (context_stack_depth > 0)
779 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
780 in this stage. Especially, blocks for static functions will show up at
781 the end. We need to sort them, so tools like `find_pc_function' and
782 `find_pc_block' can work reliably. */
783 if (sort_pending && pending_blocks) {
784 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
787 struct pending_block *pb, *pbnext;
789 pb = pending_blocks, pbnext = pb->next;
794 /* swap blocks if unordered! */
796 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) {
797 struct block *tmp = pb->block;
798 pb->block = pbnext->block;
803 pbnext = pbnext->next;
808 /* Cleanup any undefined types that have been left hanging around
809 (this needs to be done before the finish_blocks so that
810 file_symbols is still good). */
811 cleanup_undefined_types ();
814 patch_block_stabs (global_symbols, global_stabs, objfile);
815 free ((PTR)global_stabs);
819 if (pending_blocks == 0
821 && global_symbols == 0) {
822 /* Ignore symtabs that have no functions with real debugging info */
825 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
826 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr, objfile);
827 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr, objfile);
828 blockvector = make_blockvector (objfile);
831 #ifdef PROCESS_LINENUMBER_HOOK
832 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
835 /* Now create the symtab objects proper, one for each subfile. */
836 /* (The main file is the last one on the chain.) */
838 for (subfile = subfiles; subfile; subfile = nextsub)
841 /* If we have blocks of symbols, make a symtab.
842 Otherwise, just ignore this file and any line number info in it. */
845 if (subfile->line_vector) {
846 /* First, shrink the linetable to make more memory. */
847 linetablesize = sizeof (struct linetable) +
848 subfile->line_vector->nitems * sizeof (struct linetable_entry);
849 subfile->line_vector = (struct linetable *)
850 xrealloc ((char *) subfile->line_vector, linetablesize);
853 qsort (subfile->line_vector->item, subfile->line_vector->nitems,
854 sizeof (struct linetable_entry), compare_line_numbers);
857 /* Now, allocate a symbol table. */
858 symtab = allocate_symtab (subfile->name, objfile);
860 /* Fill in its components. */
861 symtab->blockvector = blockvector;
862 if (subfile->line_vector)
864 /* Reallocate the line table on the symbol obstack */
865 symtab->linetable = (struct linetable *)
866 obstack_alloc (&objfile -> symbol_obstack, linetablesize);
867 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
871 symtab->linetable = NULL;
873 symtab->dirname = subfile->dirname;
874 symtab->free_code = free_linetable;
875 symtab->free_ptr = 0;
877 #ifdef IBM6000_TARGET
878 /* In case we need to duplicate symbol tables (to represent include
879 files), and in case our system needs relocation, we want to
880 relocate the main symbol table node only (for the main file,
881 not for the include files). */
883 symtab->nonreloc = TRUE;
886 if (subfile->line_vector)
887 free ((PTR)subfile->line_vector);
889 nextsub = subfile->next;
893 #ifdef IBM6000_TARGET
894 /* all include symbol tables are non-relocatable, except the main source
897 symtab->nonreloc = FALSE;
901 free ((char *) type_vector);
903 type_vector_length = 0;
905 last_source_file = 0;
907 previous_stab_code = 0;
913 /* Push a context block. Args are an identifying nesting level (checkable
914 when you pop it), and the starting PC address of this context. */
916 struct context_stack *
917 push_context (desc, valu)
921 register struct context_stack *new;
923 if (context_stack_depth == context_stack_size)
925 context_stack_size *= 2;
926 context_stack = (struct context_stack *)
927 xrealloc ((char *) context_stack,
928 (context_stack_size * sizeof (struct context_stack)));
931 new = &context_stack[context_stack_depth++];
933 new->locals = local_symbols;
934 new->old_blocks = pending_blocks;
935 new->start_addr = valu;
943 /* Initialize anything that needs initializing when starting to read
944 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
956 /* Initialize anything that needs initializing when a completely new
957 symbol file is specified (not just adding some symbols from another
958 file, e.g. a shared library). */
963 /* Empty the hash table of global syms looking for values. */
964 bzero (global_sym_chain, sizeof global_sym_chain);
969 /* Scan through all of the global symbols defined in the object file,
970 assigning values to the debugging symbols that need to be assigned
971 to. Get these symbols from the minimal symbol table. */
974 scan_file_globals (objfile)
975 struct objfile *objfile;
978 struct minimal_symbol *msymbol;
979 struct symbol *sym, *prev;
981 for (msymbol = objfile -> msymbols; msymbol -> name != NULL; msymbol++)
985 prev = (struct symbol *) 0;
987 /* Get the hash index and check all the symbols
988 under that hash index. */
990 hash = hashname (msymbol -> name);
992 for (sym = global_sym_chain[hash]; sym;)
994 if (*(msymbol -> name) == SYMBOL_NAME (sym)[0]
995 && !strcmp(msymbol -> name + 1, SYMBOL_NAME (sym) + 1))
997 /* Splice this symbol out of the hash chain and
998 assign the value we have to it. */
1000 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1002 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1004 /* Check to see whether we need to fix up a common block. */
1005 /* Note: this code might be executed several times for
1006 the same symbol if there are multiple references. */
1007 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
1008 fix_common_block (sym, msymbol -> address);
1010 SYMBOL_VALUE_ADDRESS (sym) = msymbol -> address;
1013 sym = SYMBOL_VALUE_CHAIN (prev);
1015 sym = global_sym_chain[hash];
1020 sym = SYMBOL_VALUE_CHAIN (sym);
1027 /* Read a number by which a type is referred to in dbx data,
1028 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1029 Just a single number N is equivalent to (0,N).
1030 Return the two numbers by storing them in the vector TYPENUMS.
1031 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1034 read_type_number (pp, typenums)
1036 register int *typenums;
1041 typenums[0] = read_number (pp, ',');
1042 typenums[1] = read_number (pp, ')');
1047 typenums[1] = read_number (pp, 0);
1051 /* To handle GNU C++ typename abbreviation, we need to be able to
1052 fill in a type's name as soon as space for that type is allocated.
1053 `type_synonym_name' is the name of the type being allocated.
1054 It is cleared as soon as it is used (lest all allocated types
1056 static char *type_synonym_name;
1060 define_symbol (valu, string, desc, type, objfile)
1065 struct objfile *objfile;
1067 register struct symbol *sym;
1068 char *p = (char *) strchr (string, ':');
1072 struct type *temptype;
1074 #ifdef IBM6000_TARGET
1075 /* We would like to eliminate nameless symbols, but keep their types.
1076 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1077 to type 2, but, should not creat a symbol to address that type. Since
1078 the symbol will be nameless, there is no way any user can refer to it. */
1083 /* Ignore syms with empty names. */
1087 /* Ignore old-style symbols from cc -go */
1091 #ifdef IBM6000_TARGET
1092 /* If a nameless stab entry, all we need is the type, not the symbol.
1094 nameless = (p == string);
1097 sym = (struct symbol *)obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
1099 if (processing_gcc_compilation) {
1100 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1101 number of bytes occupied by a type or object, which we ignore. */
1102 SYMBOL_LINE(sym) = desc;
1104 SYMBOL_LINE(sym) = 0; /* unknown */
1107 if (string[0] == CPLUS_MARKER)
1109 /* Special GNU C++ names. */
1113 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1114 &objfile -> symbol_obstack);
1116 case 'v': /* $vtbl_ptr_type */
1117 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1120 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1121 &objfile -> symbol_obstack);
1125 /* This was an anonymous type that was never fixed up. */
1136 = (char *) obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
1137 /* Open-coded bcopy--saves function call time. */
1139 register char *p1 = string;
1140 register char *p2 = SYMBOL_NAME (sym);
1147 /* Determine the type of name being defined. */
1148 /* The Acorn RISC machine's compiler can put out locals that don't
1149 start with "234=" or "(3,4)=", so assume anything other than the
1150 deftypes we know how to handle is a local. */
1151 /* (Peter Watkins @ Computervision)
1152 Handle Sun-style local fortran array types 'ar...' .
1153 (gnu@cygnus.com) -- this strchr() handles them properly?
1154 (tiemann@cygnus.com) -- 'C' is for catch. */
1156 #ifdef IBM6000_TARGET
1158 /* 'R' is for register parameters. */
1160 if (!strchr ("cfFGpPrStTvVXCR", *p))
1163 if (!strchr ("cfFGpPrStTvVXC", *p))
1169 /* c is a special case, not followed by a type-number.
1170 SYMBOL:c=iVALUE for an integer constant symbol.
1171 SYMBOL:c=rVALUE for a floating constant symbol.
1172 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1173 e.g. "b:c=e6,0" for "const b = blob1"
1174 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1178 error ("Invalid symbol data at symtab pos %d.", symnum);
1183 double d = atof (p);
1186 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1189 obstack_alloc (&objfile -> type_obstack,
1191 memcpy (dbl_valu, &d, sizeof (double));
1192 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
1193 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1194 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1199 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1201 SYMBOL_VALUE (sym) = atoi (p);
1202 SYMBOL_CLASS (sym) = LOC_CONST;
1206 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1207 e.g. "b:c=e6,0" for "const b = blob1"
1208 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1212 read_type_number (&p, typenums);
1214 error ("Invalid symbol data: no comma in enum const symbol");
1216 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
1217 SYMBOL_VALUE (sym) = atoi (p);
1218 SYMBOL_CLASS (sym) = LOC_CONST;
1222 error ("Invalid symbol data at symtab pos %d.", symnum);
1224 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1225 add_symbol_to_list (sym, &file_symbols);
1229 /* Now usually comes a number that says which data type,
1230 and possibly more stuff to define the type
1231 (all of which is handled by read_type) */
1233 if (deftype == 'p' && *p == 'F')
1234 /* pF is a two-letter code that means a function parameter in Fortran.
1235 The type-number specifies the type of the return value.
1236 Translate it into a pointer-to-function type. */
1240 = lookup_pointer_type (lookup_function_type (read_type (&p, objfile)));
1243 #ifdef IBM6000_TARGET
1244 else if (deftype == 'R')
1245 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1250 struct type *type_read;
1251 synonym = *p == 't';
1256 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1257 strlen (SYMBOL_NAME (sym)),
1258 &objfile -> symbol_obstack);
1261 /* Here we save the name of the symbol for read_range_type, which
1262 ends up reading in the basic types. In stabs, unfortunately there
1263 is no distinction between "int" and "long" types except their
1264 names. Until we work out a saner type policy (eliminating most
1265 builtin types and using the names specified in the files), we
1266 save away the name so that far away from here in read_range_type,
1267 we can examine it to decide between "int" and "long". FIXME. */
1268 long_kludge_name = SYMBOL_NAME (sym);
1270 type_read = read_type (&p, objfile);
1272 if ((deftype == 'F' || deftype == 'f')
1273 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
1276 /* This code doesn't work -- it needs to realloc and can't. */
1277 struct type *new = (struct type *)
1278 obstack_alloc (&objfile -> type_obstack,
1279 sizeof (struct type));
1281 /* Generate a template for the type of this function. The
1282 types of the arguments will be added as we read the symbol
1284 *new = *lookup_function_type (type_read);
1285 SYMBOL_TYPE(sym) = new;
1286 TYPE_OBJFILE (new) = objfile;
1287 in_function_type = new;
1289 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
1293 SYMBOL_TYPE (sym) = type_read;
1299 /* The name of a caught exception. */
1300 SYMBOL_CLASS (sym) = LOC_LABEL;
1301 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1302 SYMBOL_VALUE_ADDRESS (sym) = valu;
1303 add_symbol_to_list (sym, &local_symbols);
1307 SYMBOL_CLASS (sym) = LOC_BLOCK;
1308 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1309 add_symbol_to_list (sym, &file_symbols);
1313 SYMBOL_CLASS (sym) = LOC_BLOCK;
1314 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1315 add_symbol_to_list (sym, &global_symbols);
1319 /* For a class G (global) symbol, it appears that the
1320 value is not correct. It is necessary to search for the
1321 corresponding linker definition to find the value.
1322 These definitions appear at the end of the namelist. */
1323 i = hashname (SYMBOL_NAME (sym));
1324 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1325 global_sym_chain[i] = sym;
1326 SYMBOL_CLASS (sym) = LOC_STATIC;
1327 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1328 add_symbol_to_list (sym, &global_symbols);
1331 /* This case is faked by a conditional above,
1332 when there is no code letter in the dbx data.
1333 Dbx data never actually contains 'l'. */
1335 SYMBOL_CLASS (sym) = LOC_LOCAL;
1336 SYMBOL_VALUE (sym) = valu;
1337 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1338 add_symbol_to_list (sym, &local_symbols);
1342 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1343 can also be a LOC_LOCAL_ARG depending on symbol type. */
1344 #ifndef DBX_PARM_SYMBOL_CLASS
1345 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1347 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1348 SYMBOL_VALUE (sym) = valu;
1349 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1351 /* This doesn't work yet. */
1352 add_param_to_type (&in_function_type, sym);
1354 add_symbol_to_list (sym, &local_symbols);
1356 /* If it's gcc-compiled, if it says `short', believe it. */
1357 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1360 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1361 /* This macro is defined on machines (e.g. sparc) where
1362 we should believe the type of a PCC 'short' argument,
1363 but shouldn't believe the address (the address is
1364 the address of the corresponding int). Note that
1365 this is only different from the BELIEVE_PCC_PROMOTION
1366 case on big-endian machines.
1368 My guess is that this correction, as opposed to changing
1369 the parameter to an 'int' (as done below, for PCC
1370 on most machines), is the right thing to do
1371 on all machines, but I don't want to risk breaking
1372 something that already works. On most PCC machines,
1373 the sparc problem doesn't come up because the calling
1374 function has to zero the top bytes (not knowing whether
1375 the called function wants an int or a short), so there
1376 is no practical difference between an int and a short
1377 (except perhaps what happens when the GDB user types
1378 "print short_arg = 0x10000;").
1380 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1381 actually produces the correct address (we don't need to fix it
1382 up). I made this code adapt so that it will offset the symbol
1383 if it was pointing at an int-aligned location and not
1384 otherwise. This way you can use the same gdb for 4.0.x and
1387 If the parameter is shorter than an int, and is integral
1388 (e.g. char, short, or unsigned equivalent), and is claimed to
1389 be passed on an integer boundary, don't believe it! Offset the
1390 parameter's address to the tail-end of that integer. */
1392 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
1393 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1394 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1395 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1397 SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype)
1398 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1402 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1404 /* If PCC says a parameter is a short or a char,
1405 it is really an int. */
1406 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
1407 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1408 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1410 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1411 ? lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER)
1416 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1419 /* Parameter which is in a register. */
1420 SYMBOL_CLASS (sym) = LOC_REGPARM;
1421 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1422 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1424 complain (®_value_complaint, SYMBOL_NAME (sym));
1425 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1427 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1428 add_symbol_to_list (sym, &local_symbols);
1431 #ifdef IBM6000_TARGET
1435 /* Register variable (either global or local). */
1436 SYMBOL_CLASS (sym) = LOC_REGISTER;
1437 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1438 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1440 complain (®_value_complaint, SYMBOL_NAME (sym));
1441 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1443 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1444 if (within_function)
1445 add_symbol_to_list (sym, &local_symbols);
1447 add_symbol_to_list (sym, &file_symbols);
1451 /* Static symbol at top level of file */
1452 SYMBOL_CLASS (sym) = LOC_STATIC;
1453 SYMBOL_VALUE_ADDRESS (sym) = valu;
1454 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1455 add_symbol_to_list (sym, &file_symbols);
1459 #ifdef IBM6000_TARGET
1460 /* For a nameless type, we don't want a create a symbol, thus we
1461 did not use `sym'. Return without further processing. */
1463 if (nameless) return NULL;
1465 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1466 SYMBOL_VALUE (sym) = valu;
1467 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1468 /* C++ vagaries: we may have a type which is derived from
1469 a base type which did not have its name defined when the
1470 derived class was output. We fill in the derived class's
1471 base part member's name here in that case. */
1472 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1473 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1474 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1475 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1478 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1479 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1480 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1481 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1484 add_symbol_to_list (sym, &file_symbols);
1488 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1489 SYMBOL_VALUE (sym) = valu;
1490 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1491 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1492 TYPE_NAME (SYMBOL_TYPE (sym))
1493 = obconcat (&objfile -> type_obstack, "",
1494 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
1496 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1497 ? "struct " : "union ")),
1499 add_symbol_to_list (sym, &file_symbols);
1503 register struct symbol *typedef_sym = (struct symbol *)
1504 obstack_alloc (&objfile -> type_obstack,
1505 sizeof (struct symbol));
1506 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
1507 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
1509 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1510 SYMBOL_VALUE (typedef_sym) = valu;
1511 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1512 add_symbol_to_list (typedef_sym, &file_symbols);
1517 /* Static symbol of local scope */
1518 SYMBOL_CLASS (sym) = LOC_STATIC;
1519 SYMBOL_VALUE_ADDRESS (sym) = valu;
1520 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1521 add_symbol_to_list (sym, &local_symbols);
1525 /* Reference parameter */
1526 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1527 SYMBOL_VALUE (sym) = valu;
1528 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1529 add_symbol_to_list (sym, &local_symbols);
1533 /* This is used by Sun FORTRAN for "function result value".
1534 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1535 that Pascal uses it too, but when I tried it Pascal used
1536 "x:3" (local symbol) instead. */
1537 SYMBOL_CLASS (sym) = LOC_LOCAL;
1538 SYMBOL_VALUE (sym) = valu;
1539 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1540 add_symbol_to_list (sym, &local_symbols);
1544 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
1549 /* What about types defined as forward references inside of a small lexical
1551 /* Add a type to the list of undefined types to be checked through
1552 once this file has been read in. */
1554 add_undefined_type (type)
1557 if (undef_types_length == undef_types_allocated)
1559 undef_types_allocated *= 2;
1560 undef_types = (struct type **)
1561 xrealloc ((char *) undef_types,
1562 undef_types_allocated * sizeof (struct type *));
1564 undef_types[undef_types_length++] = type;
1567 /* Go through each undefined type, see if it's still undefined, and fix it
1568 up if possible. We have two kinds of undefined types:
1570 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1571 Fix: update array length using the element bounds
1572 and the target type's length.
1573 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1574 yet defined at the time a pointer to it was made.
1575 Fix: Do a full lookup on the struct/union tag. */
1577 cleanup_undefined_types ()
1581 for (type = undef_types; type < undef_types + undef_types_length; type++) {
1582 switch (TYPE_CODE (*type)) {
1584 case TYPE_CODE_STRUCT:
1585 case TYPE_CODE_UNION:
1586 case TYPE_CODE_ENUM:
1588 /* Reasonable test to see if it's been defined since. */
1589 if (TYPE_NFIELDS (*type) == 0)
1591 struct pending *ppt;
1593 /* Name of the type, without "struct" or "union" */
1594 char *typename = TYPE_NAME (*type);
1596 if (!strncmp (typename, "struct ", 7))
1598 if (!strncmp (typename, "union ", 6))
1600 if (!strncmp (typename, "enum ", 5))
1603 for (ppt = file_symbols; ppt; ppt = ppt->next)
1604 for (i = 0; i < ppt->nsyms; i++)
1606 struct symbol *sym = ppt->symbol[i];
1608 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1609 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1610 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
1612 && !strcmp (SYMBOL_NAME (sym), typename))
1613 memcpy (*type, SYMBOL_TYPE (sym), sizeof (struct type));
1617 /* It has been defined; don't mark it as a stub. */
1618 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
1622 case TYPE_CODE_ARRAY:
1624 struct type *range_type;
1627 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
1629 if (TYPE_NFIELDS (*type) != 1)
1631 range_type = TYPE_FIELD_TYPE (*type, 0);
1632 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
1635 /* Now recompute the length of the array type, based on its
1636 number of elements and the target type's length. */
1637 lower = TYPE_FIELD_BITPOS (range_type, 0);
1638 upper = TYPE_FIELD_BITPOS (range_type, 1);
1639 TYPE_LENGTH (*type) = (upper - lower + 1)
1640 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
1646 error ("GDB internal error. cleanup_undefined_types with bad\
1647 type %d.", TYPE_CODE (*type));
1651 undef_types_length = 0;
1654 /* Skip rest of this symbol and return an error type.
1656 General notes on error recovery: error_type always skips to the
1657 end of the symbol (modulo cretinous dbx symbol name continuation).
1658 Thus code like this:
1660 if (*(*pp)++ != ';')
1661 return error_type (pp);
1663 is wrong because if *pp starts out pointing at '\0' (typically as the
1664 result of an earlier error), it will be incremented to point to the
1665 start of the next symbol, which might produce strange results, at least
1666 if you run off the end of the string table. Instead use
1669 return error_type (pp);
1675 foo = error_type (pp);
1679 And in case it isn't obvious, the point of all this hair is so the compiler
1680 can define new types and new syntaxes, and old versions of the
1681 debugger will be able to read the new symbol tables. */
1687 complain (&error_type_complaint, 0);
1690 /* Skip to end of symbol. */
1691 while (**pp != '\0')
1694 /* Check for and handle cretinous dbx symbol name continuation! */
1695 if ((*pp)[-1] == '\\')
1696 *pp = next_symbol_text ();
1700 return builtin_type_error;
1703 /* Read a dbx type reference or definition;
1704 return the type that is meant.
1705 This can be just a number, in which case it references
1706 a type already defined and placed in type_vector.
1707 Or the number can be followed by an =, in which case
1708 it means to define a new type according to the text that
1712 read_type (pp, objfile)
1714 struct objfile *objfile;
1716 register struct type *type = 0;
1721 /* Read type number if present. The type number may be omitted.
1722 for instance in a two-dimensional array declared with type
1723 "ar1;1;10;ar1;1;10;4". */
1724 if ((**pp >= '0' && **pp <= '9')
1727 read_type_number (pp, typenums);
1729 /* Type is not being defined here. Either it already exists,
1730 or this is a forward reference to it. dbx_alloc_type handles
1733 return dbx_alloc_type (typenums, objfile);
1735 /* Type is being defined here. */
1736 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1740 /* if such a type already exists, this is an unnecessary duplication
1741 of the stab string, which is common in (RS/6000) xlc generated
1742 objects. In that case, simply return NULL and let the caller take
1745 tt = *dbx_lookup_type (typenums);
1746 if (tt && tt->length && tt->code)
1755 /* 'typenums=' not present, type is anonymous. Read and return
1756 the definition, but don't put it in the type vector. */
1757 typenums[0] = typenums[1] = -1;
1765 enum type_code code;
1767 /* Used to index through file_symbols. */
1768 struct pending *ppt;
1771 /* Name including "struct", etc. */
1774 /* Name without "struct", etc. */
1775 char *type_name_only;
1781 /* Set the type code according to the following letter. */
1785 code = TYPE_CODE_STRUCT;
1789 code = TYPE_CODE_UNION;
1793 code = TYPE_CODE_ENUM;
1797 return error_type (pp);
1800 to = type_name = (char *)
1801 obstack_alloc (&objfile -> type_obstack,
1803 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1805 /* Copy the prefix. */
1807 while (*to++ = *from++)
1811 type_name_only = to;
1813 /* Copy the name. */
1815 while ((*to++ = *from++) != ':')
1819 /* Set the pointer ahead of the name which we just read. */
1823 /* The following hack is clearly wrong, because it doesn't
1824 check whether we are in a baseclass. I tried to reproduce
1825 the case that it is trying to fix, but I couldn't get
1826 g++ to put out a cross reference to a basetype. Perhaps
1827 it doesn't do it anymore. */
1828 /* Note: for C++, the cross reference may be to a base type which
1829 has not yet been seen. In this case, we skip to the comma,
1830 which will mark the end of the base class name. (The ':'
1831 at the end of the base class name will be skipped as well.)
1832 But sometimes (ie. when the cross ref is the last thing on
1833 the line) there will be no ','. */
1834 from = (char *) strchr (*pp, ',');
1840 /* Now check to see whether the type has already been declared. */
1841 /* This is necessary at least in the case where the
1842 program says something like
1844 The compiler puts out a cross-reference; we better find
1845 set the length of the structure correctly so we can
1846 set the length of the array. */
1847 for (ppt = file_symbols; ppt; ppt = ppt->next)
1848 for (i = 0; i < ppt->nsyms; i++)
1850 struct symbol *sym = ppt->symbol[i];
1852 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1853 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1854 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1855 && !strcmp (SYMBOL_NAME (sym), type_name_only))
1857 obstack_free (&objfile -> type_obstack, type_name);
1858 type = SYMBOL_TYPE (sym);
1863 /* Didn't find the type to which this refers, so we must
1864 be dealing with a forward reference. Allocate a type
1865 structure for it, and keep track of it so we can
1866 fill in the rest of the fields when we get the full
1868 type = dbx_alloc_type (typenums, objfile);
1869 TYPE_CODE (type) = code;
1870 TYPE_NAME (type) = type_name;
1871 INIT_CPLUS_SPECIFIC(type);
1872 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1874 add_undefined_type (type);
1878 case '-': /* RS/6000 built-in type */
1880 type = builtin_type (pp); /* (in xcoffread.c) */
1895 read_type_number (pp, xtypenums);
1896 type = *dbx_lookup_type (xtypenums);
1901 type = lookup_fundamental_type (objfile, FT_VOID);
1902 if (typenums[0] != -1)
1903 *dbx_lookup_type (typenums) = type;
1906 /* In the following types, we must be sure to overwrite any existing
1907 type that the typenums refer to, rather than allocating a new one
1908 and making the typenums point to the new one. This is because there
1909 may already be pointers to the existing type (if it had been
1910 forward-referenced), and we must change it to a pointer, function,
1911 reference, or whatever, *in-place*. */
1914 type1 = read_type (pp, objfile);
1915 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1918 case '&': /* Reference to another type */
1919 type1 = read_type (pp, objfile);
1920 type = make_reference_type (type1, dbx_lookup_type (typenums));
1923 case 'f': /* Function returning another type */
1924 type1 = read_type (pp, objfile);
1925 type = make_function_type (type1, dbx_lookup_type (typenums));
1928 /* FIXME -- we should be doing smash_to_XXX types here. */
1929 case '@': /* Member (class & variable) type */
1931 struct type *domain = read_type (pp, objfile);
1932 struct type *memtype;
1935 /* Invalid member type data format. */
1936 return error_type (pp);
1939 memtype = read_type (pp, objfile);
1940 type = dbx_alloc_type (typenums, objfile);
1941 smash_to_member_type (type, domain, memtype);
1945 case '#': /* Method (class & fn) type */
1946 if ((*pp)[0] == '#')
1948 /* We'll get the parameter types from the name. */
1949 struct type *return_type;
1952 return_type = read_type (pp, objfile);
1953 if (*(*pp)++ != ';')
1954 complain (&invalid_member_complaint, (char *) symnum);
1955 type = allocate_stub_method (return_type);
1956 if (typenums[0] != -1)
1957 *dbx_lookup_type (typenums) = type;
1961 struct type *domain = read_type (pp, objfile);
1962 struct type *return_type;
1965 if (*(*pp)++ != ',')
1966 error ("invalid member type data format, at symtab pos %d.",
1969 return_type = read_type (pp, objfile);
1970 args = read_args (pp, ';', objfile);
1971 type = dbx_alloc_type (typenums, objfile);
1972 smash_to_method_type (type, domain, return_type, args);
1976 case 'r': /* Range type */
1977 type = read_range_type (pp, typenums, objfile);
1978 if (typenums[0] != -1)
1979 *dbx_lookup_type (typenums) = type;
1982 case 'e': /* Enumeration type */
1983 type = dbx_alloc_type (typenums, objfile);
1984 type = read_enum_type (pp, type, objfile);
1985 *dbx_lookup_type (typenums) = type;
1988 case 's': /* Struct type */
1989 type = dbx_alloc_type (typenums, objfile);
1990 if (!TYPE_NAME (type))
1991 TYPE_NAME (type) = type_synonym_name;
1992 type_synonym_name = 0;
1993 type = read_struct_type (pp, type, objfile);
1996 case 'u': /* Union type */
1997 type = dbx_alloc_type (typenums, objfile);
1998 if (!TYPE_NAME (type))
1999 TYPE_NAME (type) = type_synonym_name;
2000 type_synonym_name = 0;
2001 type = read_struct_type (pp, type, objfile);
2002 TYPE_CODE (type) = TYPE_CODE_UNION;
2005 case 'a': /* Array type */
2007 return error_type (pp);
2010 type = dbx_alloc_type (typenums, objfile);
2011 type = read_array_type (pp, type, objfile);
2015 --*pp; /* Go back to the symbol in error */
2016 /* Particularly important if it was \0! */
2017 return error_type (pp);
2026 /* This page contains subroutines of read_type. */
2028 /* Read the description of a structure (or union type)
2029 and return an object describing the type. */
2031 static struct type *
2032 read_struct_type (pp, type, objfile)
2034 register struct type *type;
2035 struct objfile *objfile;
2037 /* Total number of methods defined in this class.
2038 If the class defines two `f' methods, and one `g' method,
2039 then this will have the value 3. */
2040 int total_length = 0;
2044 struct nextfield *next;
2045 int visibility; /* 0=public, 1=protected, 2=public */
2051 struct next_fnfield *next;
2052 struct fn_field fn_field;
2055 struct next_fnfieldlist
2057 struct next_fnfieldlist *next;
2058 struct fn_fieldlist fn_fieldlist;
2061 register struct nextfield *list = 0;
2062 struct nextfield *new;
2065 int non_public_fields = 0;
2068 register struct next_fnfieldlist *mainlist = 0;
2071 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2072 INIT_CPLUS_SPECIFIC(type);
2074 /* First comes the total size in bytes. */
2076 TYPE_LENGTH (type) = read_number (pp, 0);
2078 /* C++: Now, if the class is a derived class, then the next character
2079 will be a '!', followed by the number of base classes derived from.
2080 Each element in the list contains visibility information,
2081 the offset of this base class in the derived structure,
2082 and then the base type. */
2085 int i, n_baseclasses, offset;
2086 struct type *baseclass;
2089 /* Nonzero if it is a virtual baseclass, i.e.,
2093 struct C : public B, public virtual A {};
2095 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2096 2.0 language feature. */
2101 ALLOCATE_CPLUS_STRUCT_TYPE(type);
2103 n_baseclasses = read_number (pp, ',');
2104 TYPE_FIELD_VIRTUAL_BITS (type) =
2105 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2106 B_BYTES (n_baseclasses));
2107 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
2109 for (i = 0; i < n_baseclasses; i++)
2112 *pp = next_symbol_text ();
2123 /* Bad visibility format. */
2124 return error_type (pp);
2132 non_public_fields++;
2138 /* Bad visibility format. */
2139 return error_type (pp);
2142 SET_TYPE_FIELD_VIRTUAL (type, i);
2145 /* Offset of the portion of the object corresponding to
2146 this baseclass. Always zero in the absence of
2147 multiple inheritance. */
2148 offset = read_number (pp, ',');
2149 baseclass = read_type (pp, objfile);
2150 *pp += 1; /* skip trailing ';' */
2152 /* Make this baseclass visible for structure-printing purposes. */
2153 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2156 list->visibility = via_public;
2157 list->field.type = baseclass;
2158 list->field.name = type_name_no_tag (baseclass);
2159 list->field.bitpos = offset;
2160 list->field.bitsize = 0; /* this should be an unpacked field! */
2163 TYPE_N_BASECLASSES (type) = n_baseclasses;
2166 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2167 At the end, we see a semicolon instead of a field.
2169 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2172 The `?' is a placeholder for one of '/2' (public visibility),
2173 '/1' (protected visibility), '/0' (private visibility), or nothing
2174 (C style symbol table, public visibility). */
2176 /* We better set p right now, in case there are no fields at all... */
2181 /* Check for and handle cretinous dbx symbol name continuation! */
2182 if (**pp == '\\') *pp = next_symbol_text ();
2184 /* Get space to record the next field's data. */
2185 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2189 /* Get the field name. */
2191 if (*p == CPLUS_MARKER)
2193 /* Special GNU C++ name. */
2198 struct type *context;
2209 complain (&invalid_cpp_abbrev_complaint, *pp);
2210 prefix = "INVALID_C++_ABBREV";
2214 context = read_type (pp, objfile);
2215 name = type_name_no_tag (context);
2218 complain (&invalid_cpp_type_complaint, (char *) symnum);
2221 list->field.name = obconcat (&objfile -> type_obstack,
2225 complain (&invalid_cpp_abbrev_complaint, *pp);
2226 list->field.type = read_type (pp, objfile);
2227 (*pp)++; /* Skip the comma. */
2228 list->field.bitpos = read_number (pp, ';');
2229 /* This field is unpacked. */
2230 list->field.bitsize = 0;
2231 list->visibility = 0; /* private */
2232 non_public_fields++;
2234 /* GNU C++ anonymous type. */
2238 complain (&invalid_cpp_abbrev_complaint, *pp);
2244 while (*p != ':') p++;
2245 list->field.name = obsavestring (*pp, p - *pp,
2246 &objfile -> type_obstack);
2248 /* C++: Check to see if we have hit the methods yet. */
2254 /* This means we have a visibility for a field coming. */
2260 list->visibility = 0; /* private */
2261 non_public_fields++;
2266 list->visibility = 1; /* protected */
2267 non_public_fields++;
2272 list->visibility = 2; /* public */
2277 else /* normal dbx-style format. */
2278 list->visibility = 2; /* public */
2280 list->field.type = read_type (pp, objfile);
2283 /* Static class member. */
2284 list->field.bitpos = (long)-1;
2286 while (*p != ';') p++;
2287 list->field.bitsize = (long) savestring (*pp, p - *pp);
2292 else if (**pp != ',')
2293 /* Bad structure-type format. */
2294 return error_type (pp);
2296 (*pp)++; /* Skip the comma. */
2297 list->field.bitpos = read_number (pp, ',');
2298 list->field.bitsize = read_number (pp, ';');
2301 /* FIXME-tiemann: Can't the compiler put out something which
2302 lets us distinguish these? (or maybe just not put out anything
2303 for the field). What is the story here? What does the compiler
2304 really do? Also, patch gdb.texinfo for this case; I document
2305 it as a possible problem there. Search for "DBX-style". */
2307 /* This is wrong because this is identical to the symbols
2308 produced for GCC 0-size arrays. For example:
2313 The code which dumped core in such circumstances should be
2314 fixed not to dump core. */
2316 /* g++ -g0 can put out bitpos & bitsize zero for a static
2317 field. This does not give us any way of getting its
2318 class, so we can't know its name. But we can just
2319 ignore the field so we don't dump core and other nasty
2321 if (list->field.bitpos == 0
2322 && list->field.bitsize == 0)
2324 complain (&dbx_class_complaint, 0);
2325 /* Ignore this field. */
2331 /* Detect an unpacked field and mark it as such.
2332 dbx gives a bit size for all fields.
2333 Note that forward refs cannot be packed,
2334 and treat enums as if they had the width of ints. */
2335 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
2336 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
2337 list->field.bitsize = 0;
2338 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
2339 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
2340 && (list->field.bitsize
2341 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile, FT_INTEGER)))
2345 list->field.bitpos % 8 == 0)
2346 list->field.bitsize = 0;
2352 /* chill the list of fields: the last entry (at the head)
2353 is a partially constructed entry which we now scrub. */
2356 /* Now create the vector of fields, and record how big it is.
2357 We need this info to record proper virtual function table information
2358 for this class's virtual functions. */
2360 TYPE_NFIELDS (type) = nfields;
2361 TYPE_FIELDS (type) = (struct field *)
2362 obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nfields);
2364 if (non_public_fields)
2366 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2368 TYPE_FIELD_PRIVATE_BITS (type) =
2369 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2371 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2373 TYPE_FIELD_PROTECTED_BITS (type) =
2374 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2376 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2379 /* Copy the saved-up fields into the field vector. */
2381 for (n = nfields; list; list = list->next)
2384 TYPE_FIELD (type, n) = list->field;
2385 if (list->visibility == 0)
2386 SET_TYPE_FIELD_PRIVATE (type, n);
2387 else if (list->visibility == 1)
2388 SET_TYPE_FIELD_PROTECTED (type, n);
2391 /* Now come the method fields, as NAME::methods
2392 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2393 At the end, we see a semicolon instead of a field.
2395 For the case of overloaded operators, the format is
2396 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2397 `*' holds the place for an operator name (such as `+=')
2398 and `.' marks the end of the operator name. */
2401 /* Now, read in the methods. To simplify matters, we
2402 "unread" the name that has been read, so that we can
2403 start from the top. */
2405 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2406 /* For each list of method lists... */
2410 struct next_fnfield *sublist = 0;
2411 struct type *look_ahead_type = NULL;
2413 struct next_fnfieldlist *new_mainlist =
2414 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2419 /* read in the name. */
2420 while (*p != ':') p++;
2421 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2423 /* This is a completely wierd case. In order to stuff in the
2424 names that might contain colons (the usual name delimiter),
2425 Mike Tiemann defined a different name format which is
2426 signalled if the identifier is "op$". In that case, the
2427 format is "op$::XXXX." where XXXX is the name. This is
2428 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2429 /* This lets the user type "break operator+".
2430 We could just put in "+" as the name, but that wouldn't
2432 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2433 char *o = opname + 3;
2435 /* Skip past '::'. */
2437 if (**pp == '\\') *pp = next_symbol_text ();
2441 main_fn_name = savestring (opname, o - opname);
2447 main_fn_name = savestring (*pp, p - *pp);
2448 /* Skip past '::'. */
2451 new_mainlist->fn_fieldlist.name = main_fn_name;
2455 struct next_fnfield *new_sublist =
2456 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2458 /* Check for and handle cretinous dbx symbol name continuation! */
2459 if (look_ahead_type == NULL) /* Normal case. */
2461 if (**pp == '\\') *pp = next_symbol_text ();
2463 new_sublist->fn_field.type = read_type (pp, objfile);
2465 /* Invalid symtab info for method. */
2466 return error_type (pp);
2469 { /* g++ version 1 kludge */
2470 new_sublist->fn_field.type = look_ahead_type;
2471 look_ahead_type = NULL;
2476 while (*p != ';') p++;
2478 /* If this is just a stub, then we don't have the
2480 if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
2481 new_sublist->fn_field.is_stub = 1;
2482 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2485 /* Set this method's visibility fields. */
2486 switch (*(*pp)++ - '0')
2489 new_sublist->fn_field.is_private = 1;
2492 new_sublist->fn_field.is_protected = 1;
2496 if (**pp == '\\') *pp = next_symbol_text ();
2499 case 'A': /* Normal functions. */
2500 new_sublist->fn_field.is_const = 0;
2501 new_sublist->fn_field.is_volatile = 0;
2504 case 'B': /* `const' member functions. */
2505 new_sublist->fn_field.is_const = 1;
2506 new_sublist->fn_field.is_volatile = 0;
2509 case 'C': /* `volatile' member function. */
2510 new_sublist->fn_field.is_const = 0;
2511 new_sublist->fn_field.is_volatile = 1;
2514 case 'D': /* `const volatile' member function. */
2515 new_sublist->fn_field.is_const = 1;
2516 new_sublist->fn_field.is_volatile = 1;
2519 case '*': /* File compiled with g++ version 1 -- no info */
2524 complain (&const_vol_complaint, (char *) (long) **pp);
2531 /* virtual member function, followed by index. */
2532 /* The sign bit is set to distinguish pointers-to-methods
2533 from virtual function indicies. Since the array is
2534 in words, the quantity must be shifted left by 1
2535 on 16 bit machine, and by 2 on 32 bit machine, forcing
2536 the sign bit out, and usable as a valid index into
2537 the array. Remove the sign bit here. */
2538 new_sublist->fn_field.voffset =
2539 (0x7fffffff & read_number (pp, ';')) + 2;
2541 if (**pp == '\\') *pp = next_symbol_text ();
2543 if (**pp == ';' || **pp == '\0')
2544 /* Must be g++ version 1. */
2545 new_sublist->fn_field.fcontext = 0;
2548 /* Figure out from whence this virtual function came.
2549 It may belong to virtual function table of
2550 one of its baseclasses. */
2551 look_ahead_type = read_type (pp, objfile);
2553 { /* g++ version 1 overloaded methods. */ }
2556 new_sublist->fn_field.fcontext = look_ahead_type;
2558 return error_type (pp);
2561 look_ahead_type = NULL;
2567 /* static member function. */
2568 new_sublist->fn_field.voffset = VOFFSET_STATIC;
2569 if (strncmp (new_sublist->fn_field.physname,
2570 main_fn_name, strlen (main_fn_name)))
2571 new_sublist->fn_field.is_stub = 1;
2576 complain (&member_fn_complaint, (char *) (long) (*pp)[-1]);
2577 /* Fall through into normal member function. */
2580 /* normal member function. */
2581 new_sublist->fn_field.voffset = 0;
2582 new_sublist->fn_field.fcontext = 0;
2586 new_sublist->next = sublist;
2587 sublist = new_sublist;
2589 if (**pp == '\\') *pp = next_symbol_text ();
2591 while (**pp != ';' && **pp != '\0');
2595 new_mainlist->fn_fieldlist.fn_fields =
2596 (struct fn_field *) obstack_alloc (&objfile -> type_obstack,
2597 sizeof (struct fn_field) * length);
2598 for (i = length; (i--, sublist); sublist = sublist->next)
2599 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2601 new_mainlist->fn_fieldlist.length = length;
2602 new_mainlist->next = mainlist;
2603 mainlist = new_mainlist;
2605 total_length += length;
2606 if (**pp == '\\') *pp = next_symbol_text ();
2608 while (**pp != ';');
2616 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2617 obstack_alloc (&objfile -> type_obstack,
2618 sizeof (struct fn_fieldlist) * nfn_fields);
2619 TYPE_NFN_FIELDS (type) = nfn_fields;
2620 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2625 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2626 TYPE_NFN_FIELDS_TOTAL (type) +=
2627 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2630 for (n = nfn_fields; mainlist; mainlist = mainlist->next) {
2631 --n; /* Circumvent Sun3 compiler bug */
2632 TYPE_FN_FIELDLISTS (type)[n] = mainlist->fn_fieldlist;
2639 if (**pp == '=' || **pp == '+' || **pp == '-')
2641 /* Obsolete flags that used to indicate the presence
2642 of constructors and/or destructors. */
2646 /* Read either a '%' or the final ';'. */
2647 if (*(*pp)++ == '%')
2649 /* We'd like to be able to derive the vtable pointer field
2650 from the type information, but when it's inherited, that's
2651 hard. A reason it's hard is because we may read in the
2652 info about a derived class before we read in info about
2653 the base class that provides the vtable pointer field.
2654 Once the base info has been read, we could fill in the info
2655 for the derived classes, but for the fact that by then,
2656 we don't remember who needs what. */
2659 int predicted_fieldno = -1;
2662 /* Now we must record the virtual function table pointer's
2663 field information. */
2671 /* In version 2, we derive the vfield ourselves. */
2672 for (n = 0; n < nfields; n++)
2674 if (! strncmp (TYPE_FIELD_NAME (type, n), vptr_name,
2675 sizeof (vptr_name) -1))
2677 predicted_fieldno = n;
2681 if (predicted_fieldno < 0)
2682 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2683 if (! TYPE_FIELD_VIRTUAL (type, n)
2684 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n)) >= 0)
2686 predicted_fieldno = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n));
2692 t = read_type (pp, objfile);
2694 while (*p != '\0' && *p != ';')
2697 /* Premature end of symbol. */
2698 return error_type (pp);
2700 TYPE_VPTR_BASETYPE (type) = t;
2703 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2705 /* FIXME-tiemann: what's this? */
2707 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2712 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2713 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2714 sizeof (vptr_name) -1))
2716 TYPE_VPTR_FIELDNO (type) = i;
2720 /* Virtual function table field not found. */
2721 return error_type (pp);
2724 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2727 if (TYPE_VPTR_FIELDNO (type) != predicted_fieldno)
2728 error ("TYPE_VPTR_FIELDNO miscalculated");
2738 /* Read a definition of an array type,
2739 and create and return a suitable type object.
2740 Also creates a range type which represents the bounds of that
2742 static struct type *
2743 read_array_type (pp, type, objfile)
2745 register struct type *type;
2746 struct objfile *objfile;
2748 struct type *index_type, *element_type, *range_type;
2752 /* Format of an array type:
2753 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2756 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2757 for these, produce a type like float[][]. */
2759 index_type = read_type (pp, objfile);
2761 /* Improper format of array type decl. */
2762 return error_type (pp);
2765 if (!(**pp >= '0' && **pp <= '9'))
2770 lower = read_number (pp, ';');
2772 if (!(**pp >= '0' && **pp <= '9'))
2777 upper = read_number (pp, ';');
2779 element_type = read_type (pp, objfile);
2788 /* Create range type. */
2789 range_type = (struct type *)
2790 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
2791 bzero (range_type, sizeof (struct type));
2792 TYPE_OBJFILE (range_type) = objfile;
2793 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2794 TYPE_TARGET_TYPE (range_type) = index_type;
2796 /* This should never be needed. */
2797 TYPE_LENGTH (range_type) = sizeof (int);
2799 TYPE_NFIELDS (range_type) = 2;
2800 TYPE_FIELDS (range_type) =
2801 (struct field *) obstack_alloc (&objfile -> type_obstack,
2802 2 * sizeof (struct field));
2803 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2804 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2807 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2808 TYPE_TARGET_TYPE (type) = element_type;
2809 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2810 TYPE_NFIELDS (type) = 1;
2811 TYPE_FIELDS (type) =
2812 (struct field *) obstack_alloc (&objfile -> type_obstack,
2813 sizeof (struct field));
2814 TYPE_FIELD_TYPE (type, 0) = range_type;
2816 /* If we have an array whose element type is not yet known, but whose
2817 bounds *are* known, record it to be adjusted at the end of the file. */
2818 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2819 add_undefined_type (type);
2825 /* Read a definition of an enumeration type,
2826 and create and return a suitable type object.
2827 Also defines the symbols that represent the values of the type. */
2829 static struct type *
2830 read_enum_type (pp, type, objfile)
2832 register struct type *type;
2833 struct objfile *objfile;
2838 register struct symbol *sym;
2840 struct pending **symlist;
2841 struct pending *osyms, *syms;
2845 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2846 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2847 to do? For now, force all enum values to file scope. */
2848 if (within_function)
2849 symlist = &local_symbols;
2852 symlist = &file_symbols;
2854 o_nsyms = osyms ? osyms->nsyms : 0;
2856 /* Read the value-names and their values.
2857 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2858 A semicolon or comma instead of a NAME means the end. */
2859 while (**pp && **pp != ';' && **pp != ',')
2861 /* Check for and handle cretinous dbx symbol name continuation! */
2862 if (**pp == '\\') *pp = next_symbol_text ();
2865 while (*p != ':') p++;
2866 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2868 n = read_number (pp, ',');
2870 sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2871 bzero (sym, sizeof (struct symbol));
2872 SYMBOL_NAME (sym) = name;
2873 SYMBOL_CLASS (sym) = LOC_CONST;
2874 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2875 SYMBOL_VALUE (sym) = n;
2876 add_symbol_to_list (sym, symlist);
2881 (*pp)++; /* Skip the semicolon. */
2883 /* Now fill in the fields of the type-structure. */
2885 TYPE_LENGTH (type) = sizeof (int);
2886 TYPE_CODE (type) = TYPE_CODE_ENUM;
2887 TYPE_NFIELDS (type) = nsyms;
2888 TYPE_FIELDS (type) = (struct field *)
2889 obstack_alloc (&objfile -> type_obstack,
2890 sizeof (struct field) * nsyms);
2892 /* Find the symbols for the values and put them into the type.
2893 The symbols can be found in the symlist that we put them on
2894 to cause them to be defined. osyms contains the old value
2895 of that symlist; everything up to there was defined by us. */
2896 /* Note that we preserve the order of the enum constants, so
2897 that in something like "enum {FOO, LAST_THING=FOO}" we print
2898 FOO, not LAST_THING. */
2900 for (syms = *symlist, n = 0; syms; syms = syms->next)
2905 for (; j < syms->nsyms; j++,n++)
2907 struct symbol *xsym = syms->symbol[j];
2908 SYMBOL_TYPE (xsym) = type;
2909 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2910 TYPE_FIELD_VALUE (type, n) = 0;
2911 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2912 TYPE_FIELD_BITSIZE (type, n) = 0;
2919 /* This screws up perfectly good C programs with enums. FIXME. */
2920 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2921 if(TYPE_NFIELDS(type) == 2 &&
2922 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2923 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2924 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2925 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2926 TYPE_CODE(type) = TYPE_CODE_BOOL;
2932 /* Read a number from the string pointed to by *PP.
2933 The value of *PP is advanced over the number.
2934 If END is nonzero, the character that ends the
2935 number must match END, or an error happens;
2936 and that character is skipped if it does match.
2937 If END is zero, *PP is left pointing to that character.
2939 If the number fits in a long, set *VALUE and set *BITS to 0.
2940 If not, set *BITS to be the number of bits in the number.
2942 If encounter garbage, set *BITS to -1. */
2945 read_huge_number (pp, end, valu, bits)
2966 /* Leading zero means octal. GCC uses this to output values larger
2967 than an int (because that would be hard in decimal). */
2974 upper_limit = LONG_MAX / radix;
2975 while ((c = *p++) >= '0' && c <= ('0' + radix))
2977 if (n <= upper_limit)
2980 n += c - '0'; /* FIXME this overflows anyway */
2985 /* This depends on large values being output in octal, which is
2992 /* Ignore leading zeroes. */
2996 else if (c == '2' || c == '3')
3022 /* Large decimal constants are an error (because it is hard to
3023 count how many bits are in them). */
3029 /* -0x7f is the same as 0x80. So deal with it by adding one to
3030 the number of bits. */
3045 static struct type *
3046 read_range_type (pp, typenums, objfile)
3049 struct objfile *objfile;
3055 struct type *result_type;
3057 /* First comes a type we are a subrange of.
3058 In C it is usually 0, 1 or the type being defined. */
3059 read_type_number (pp, rangenums);
3060 self_subrange = (rangenums[0] == typenums[0] &&
3061 rangenums[1] == typenums[1]);
3063 /* A semicolon should now follow; skip it. */
3067 /* The remaining two operands are usually lower and upper bounds
3068 of the range. But in some special cases they mean something else. */
3069 read_huge_number (pp, ';', &n2, &n2bits);
3070 read_huge_number (pp, ';', &n3, &n3bits);
3072 if (n2bits == -1 || n3bits == -1)
3073 return error_type (pp);
3075 /* If limits are huge, must be large integral type. */
3076 if (n2bits != 0 || n3bits != 0)
3078 char got_signed = 0;
3079 char got_unsigned = 0;
3080 /* Number of bits in the type. */
3083 /* Range from 0 to <large number> is an unsigned large integral type. */
3084 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3089 /* Range from <large number> to <large number>-1 is a large signed
3091 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3097 /* Check for "long long". */
3098 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
3099 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
3100 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
3101 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
3103 if (got_signed || got_unsigned)
3105 result_type = (struct type *)
3106 obstack_alloc (&objfile -> type_obstack,
3107 sizeof (struct type));
3108 bzero (result_type, sizeof (struct type));
3109 TYPE_OBJFILE (result_type) = objfile;
3110 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
3111 TYPE_CODE (result_type) = TYPE_CODE_INT;
3113 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
3117 return error_type (pp);
3120 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3121 if (self_subrange && n2 == 0 && n3 == 0)
3122 return (lookup_fundamental_type (objfile, FT_VOID));
3124 /* If n3 is zero and n2 is not, we want a floating type,
3125 and n2 is the width in bytes.
3127 Fortran programs appear to use this for complex types also,
3128 and they give no way to distinguish between double and single-complex!
3129 We don't have complex types, so we would lose on all fortran files!
3130 So return type `double' for all of those. It won't work right
3131 for the complex values, but at least it makes the file loadable.
3133 FIXME, we may be able to distinguish these by their names. FIXME. */
3135 if (n3 == 0 && n2 > 0)
3137 if (n2 == sizeof (float))
3138 return (lookup_fundamental_type (objfile, FT_FLOAT));
3139 return (lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT));
3142 /* If the upper bound is -1, it must really be an unsigned int. */
3144 else if (n2 == 0 && n3 == -1)
3146 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3147 long' is to look at its name! */
3149 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3150 long_kludge_name[9] == 'l' /* long */)
3151 || (long_kludge_name[0] == 'l' /* long unsigned */)))
3152 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
3154 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
3157 /* Special case: char is defined (Who knows why) as a subrange of
3158 itself with range 0-127. */
3159 else if (self_subrange && n2 == 0 && n3 == 127)
3160 return (lookup_fundamental_type (objfile, FT_CHAR));
3162 /* Assumptions made here: Subrange of self is equivalent to subrange
3163 of int. FIXME: Host and target type-sizes assumed the same. */
3164 /* FIXME: This is the *only* place in GDB that depends on comparing
3165 some type to a builtin type with ==. Fix it! */
3167 && (self_subrange ||
3168 *dbx_lookup_type (rangenums) == lookup_fundamental_type (objfile, FT_INTEGER)))
3170 /* an unsigned type */
3172 if (n3 == - sizeof (long long))
3173 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
3175 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3176 long' is to look at its name! */
3177 if (n3 == (unsigned long)~0L &&
3178 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3179 long_kludge_name[9] == 'l' /* long */)
3180 || (long_kludge_name[0] == 'l' /* long unsigned */)))
3181 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
3182 if (n3 == (unsigned int)~0L)
3183 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
3184 if (n3 == (unsigned short)~0L)
3185 return (lookup_fundamental_type (objfile, FT_UNSIGNED_SHORT));
3186 if (n3 == (unsigned char)~0L)
3187 return (lookup_fundamental_type (objfile, FT_UNSIGNED_CHAR));
3190 else if (n3 == 0 && n2 == -sizeof (long long))
3191 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
3193 else if (n2 == -n3 -1)
3196 /* FIXME -- the only way to distinguish `int' from `long' is to look
3198 if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
3199 long_kludge_name && long_kludge_name[0] == 'l' /* long */)
3200 return (lookup_fundamental_type (objfile, FT_LONG));
3201 if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
3202 return (lookup_fundamental_type (objfile, FT_INTEGER));
3203 if (n3 == ( 1 << (8 * sizeof (short) - 1)) - 1)
3204 return (lookup_fundamental_type (objfile, FT_SHORT));
3205 if (n3 == ( 1 << (8 * sizeof (char) - 1)) - 1)
3206 return (lookup_fundamental_type (objfile, FT_CHAR));
3209 /* We have a real range type on our hands. Allocate space and
3210 return a real pointer. */
3212 /* At this point I don't have the faintest idea how to deal with
3213 a self_subrange type; I'm going to assume that this is used
3214 as an idiom, and that all of them are special cases. So . . . */
3216 return error_type (pp);
3218 result_type = (struct type *)
3219 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
3220 bzero (result_type, sizeof (struct type));
3221 TYPE_OBJFILE (result_type) = objfile;
3223 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
3225 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
3226 if (TYPE_TARGET_TYPE (result_type) == 0) {
3227 complain (&range_type_base_complaint, (char *) rangenums[1]);
3228 TYPE_TARGET_TYPE (result_type) = lookup_fundamental_type (objfile, FT_INTEGER);
3231 TYPE_NFIELDS (result_type) = 2;
3232 TYPE_FIELDS (result_type) =
3233 (struct field *) obstack_alloc (&objfile -> type_obstack,
3234 2 * sizeof (struct field));
3235 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
3236 TYPE_FIELD_BITPOS (result_type, 0) = n2;
3237 TYPE_FIELD_BITPOS (result_type, 1) = n3;
3239 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
3244 /* Read a number from the string pointed to by *PP.
3245 The value of *PP is advanced over the number.
3246 If END is nonzero, the character that ends the
3247 number must match END, or an error happens;
3248 and that character is skipped if it does match.
3249 If END is zero, *PP is left pointing to that character. */
3252 read_number (pp, end)
3256 register char *p = *pp;
3257 register long n = 0;
3261 /* Handle an optional leading minus sign. */
3269 /* Read the digits, as far as they go. */
3271 while ((c = *p++) >= '0' && c <= '9')
3279 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
3288 /* Read in an argument list. This is a list of types, separated by commas
3289 and terminated with END. Return the list of types read in, or (struct type
3290 **)-1 if there is an error. */
3291 static struct type **
3292 read_args (pp, end, objfile)
3295 struct objfile *objfile;
3297 /* FIXME! Remove this arbitrary limit! */
3298 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3304 /* Invalid argument list: no ','. */
3305 return (struct type **)-1;
3308 /* Check for and handle cretinous dbx symbol name continuation! */
3310 *pp = next_symbol_text ();
3312 types[n++] = read_type (pp, objfile);
3314 *pp += 1; /* get past `end' (the ':' character) */
3318 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3320 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3322 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3323 bzero (rval + n, sizeof (struct type *));
3327 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3329 memcpy (rval, types, n * sizeof (struct type *));
3333 /* Add a common block's start address to the offset of each symbol
3334 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3335 the common block name). */
3338 fix_common_block (sym, valu)
3342 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3343 for ( ; next; next = next->next)
3346 for (j = next->nsyms - 1; j >= 0; j--)
3347 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3351 /* Initializer for this module */
3353 _initialize_buildsym ()
3355 undef_types_allocated = 20;
3356 undef_types_length = 0;
3357 undef_types = (struct type **) xmalloc (undef_types_allocated *
3358 sizeof (struct type *));