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" */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
38 /* Ask buildsym.h to define the vars it normally declares `extern'. */
40 #include "buildsym.h" /* Our own declarations */
44 extern double atof ();
46 /* Things we export from outside, and probably shouldn't. FIXME. */
47 extern void new_object_header_files ();
48 extern char *next_symbol_text ();
49 extern int hashname ();
50 extern void patch_block_stabs (); /* AIX xcoffread.c */
51 extern struct type
*builtin_type (); /* AIX xcoffread.c */
54 static void cleanup_undefined_types ();
55 static void fix_common_block ();
57 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
58 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
60 /* Define this as 1 if a pcc declaration of a char or short argument
61 gives the correct address. Otherwise assume pcc gives the
62 address of the corresponding int, which is not the same on a
63 big-endian machine. */
65 #ifndef BELIEVE_PCC_PROMOTION
66 #define BELIEVE_PCC_PROMOTION 0
69 /* During some calls to read_type (and thus to read_range_type), this
70 contains the name of the type being defined. Range types are only
71 used in C as basic types. We use the name to distinguish the otherwise
72 identical basic types "int" and "long" and their unsigned versions.
73 FIXME, this should disappear with better type management. */
75 static char *long_kludge_name
;
77 /* Make a list of forward references which haven't been defined. */
78 static struct type
**undef_types
;
79 static int undef_types_allocated
, undef_types_length
;
81 /* Initial sizes of data structures. These are realloc'd larger if needed,
82 and realloc'd down to the size actually used, when completed. */
84 #define INITIAL_CONTEXT_STACK_SIZE 10
85 #define INITIAL_TYPE_VECTOR_LENGTH 160
86 #define INITIAL_LINE_VECTOR_LENGTH 1000
88 /* Complaints about the symbols we have encountered. */
90 struct complaint innerblock_complaint
=
91 {"inner block not inside outer block in %s", 0, 0};
93 struct complaint blockvector_complaint
=
94 {"block at %x out of order", 0, 0};
97 struct complaint dbx_class_complaint
=
98 {"encountered DBX-style class variable debugging information.\n\
99 You seem to have compiled your program with \
100 \"g++ -g0\" instead of \"g++ -g\".\n\
101 Therefore GDB will not know about your class variables", 0, 0};
104 struct complaint invalid_cpp_abbrev_complaint
=
105 {"invalid C++ abbreviation `%s'", 0, 0};
107 struct complaint invalid_cpp_type_complaint
=
108 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
110 struct complaint member_fn_complaint
=
111 {"member function type missing, got '%c'", 0, 0};
113 struct complaint const_vol_complaint
=
114 {"const/volatile indicator missing, got '%c'", 0, 0};
116 struct complaint error_type_complaint
=
117 {"debug info mismatch between compiler and debugger", 0, 0};
119 struct complaint invalid_member_complaint
=
120 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
122 struct complaint range_type_base_complaint
=
123 {"base type %d of range type is not defined", 0, 0};
125 /* Look up a dbx type-number pair. Return the address of the slot
126 where the type for that number-pair is stored.
127 The number-pair is in TYPENUMS.
129 This can be used for finding the type associated with that pair
130 or for associating a new type with the pair. */
133 dbx_lookup_type (typenums
)
136 register int filenum
= typenums
[0], index
= typenums
[1];
139 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
140 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
141 filenum
, index
, symnum
);
145 /* Type is defined outside of header files.
146 Find it in this object file's type vector. */
147 if (index
>= type_vector_length
)
149 old_len
= type_vector_length
;
151 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
152 type_vector
= (struct type
**)
153 malloc (type_vector_length
* sizeof (struct type
*));
155 while (index
>= type_vector_length
)
156 type_vector_length
*= 2;
157 type_vector
= (struct type
**)
158 xrealloc (type_vector
,
159 (type_vector_length
* sizeof (struct type
*)));
160 bzero (&type_vector
[old_len
],
161 (type_vector_length
- old_len
) * sizeof (struct type
*));
163 return &type_vector
[index
];
167 register int real_filenum
= this_object_header_files
[filenum
];
168 register struct header_file
*f
;
171 if (real_filenum
>= n_header_files
)
174 f
= &header_files
[real_filenum
];
176 f_orig_length
= f
->length
;
177 if (index
>= f_orig_length
)
179 while (index
>= f
->length
)
181 f
->vector
= (struct type
**)
182 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
183 bzero (&f
->vector
[f_orig_length
],
184 (f
->length
- f_orig_length
) * sizeof (struct type
*));
186 return &f
->vector
[index
];
190 /* Create a type object. Occaisionally used when you need a type
191 which isn't going to be given a type number. */
196 register struct type
*type
=
197 (struct type
*) obstack_alloc (symbol_obstack
, sizeof (struct type
));
199 bzero (type
, sizeof (struct type
));
200 TYPE_VPTR_FIELDNO (type
) = -1;
201 TYPE_VPTR_BASETYPE (type
) = 0;
205 /* Make sure there is a type allocated for type numbers TYPENUMS
206 and return the type object.
207 This can create an empty (zeroed) type object.
208 TYPENUMS may be (-1, -1) to return a new type object that is not
209 put into the type vector, and so may not be referred to by number. */
212 dbx_alloc_type (typenums
)
215 register struct type
**type_addr
;
216 register struct type
*type
;
218 if (typenums
[0] != -1)
220 type_addr
= dbx_lookup_type (typenums
);
229 /* If we are referring to a type not known at all yet,
230 allocate an empty type for it.
231 We will fill it in later if we find out how. */
234 type
= dbx_create_type ();
242 /* maintain the lists of symbols and blocks */
244 /* Add a symbol to one of the lists of symbols. */
246 add_symbol_to_list (symbol
, listhead
)
247 struct symbol
*symbol
;
248 struct pending
**listhead
;
250 /* We keep PENDINGSIZE symbols in each link of the list.
251 If we don't have a link with room in it, add a new link. */
252 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
254 register struct pending
*link
;
257 link
= free_pendings
;
258 free_pendings
= link
->next
;
261 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
263 link
->next
= *listhead
;
268 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
271 /* Find a symbol on a pending list. */
273 find_symbol_in_list (list
, name
, length
)
274 struct pending
*list
;
281 for (j
= list
->nsyms
; --j
>= 0; ) {
282 char *pp
= SYMBOL_NAME (list
->symbol
[j
]);
283 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 && pp
[length
] == '\0')
284 return list
->symbol
[j
];
291 /* At end of reading syms, or in case of quit,
292 really free as many `struct pending's as we can easily find. */
296 really_free_pendings (foo
)
299 struct pending
*next
, *next1
;
301 struct pending_block
*bnext
, *bnext1
;
304 for (next
= free_pendings
; next
; next
= next1
)
311 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
312 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
314 bnext1
= bnext
->next
;
320 for (next
= file_symbols
; next
; next
= next1
)
327 for (next
= global_symbols
; next
; next
= next1
)
335 /* Take one of the lists of symbols and make a block from it.
336 Keep the order the symbols have in the list (reversed from the input file).
337 Put the block on the list of pending blocks. */
340 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
341 struct symbol
*symbol
;
342 struct pending
**listhead
;
343 struct pending_block
*old_blocks
;
344 CORE_ADDR start
, end
;
346 register struct pending
*next
, *next1
;
347 register struct block
*block
;
348 register struct pending_block
*pblock
;
349 struct pending_block
*opblock
;
352 /* Count the length of the list of symbols. */
354 for (next
= *listhead
, i
= 0;
356 i
+= next
->nsyms
, next
= next
->next
)
359 block
= (struct block
*) obstack_alloc (symbol_obstack
,
360 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
362 /* Copy the symbols into the block. */
364 BLOCK_NSYMS (block
) = i
;
365 for (next
= *listhead
; next
; next
= next
->next
)
368 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
369 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
372 BLOCK_START (block
) = start
;
373 BLOCK_END (block
) = end
;
374 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
375 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
377 /* Put the block in as the value of the symbol that names it. */
381 SYMBOL_BLOCK_VALUE (symbol
) = block
;
382 BLOCK_FUNCTION (block
) = symbol
;
385 BLOCK_FUNCTION (block
) = 0;
387 /* Now "free" the links of the list, and empty the list. */
389 for (next
= *listhead
; next
; next
= next1
)
392 next
->next
= free_pendings
;
393 free_pendings
= next
;
397 /* Install this block as the superblock
398 of all blocks made since the start of this scope
399 that don't have superblocks yet. */
402 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
404 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
406 /* Check to be sure the blocks are nested as we receive them.
407 If the compiler/assembler/linker work, this just burns a small
409 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
410 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
411 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
413 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
414 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
417 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
422 /* Record this block on the list of all blocks in the file.
423 Put it after opblock, or at the beginning if opblock is 0.
424 This puts the block in the list after all its subblocks. */
426 /* Allocate in the symbol_obstack to save time.
427 It wastes a little space. */
428 pblock
= (struct pending_block
*)
429 obstack_alloc (symbol_obstack
,
430 sizeof (struct pending_block
));
431 pblock
->block
= block
;
434 pblock
->next
= opblock
->next
;
435 opblock
->next
= pblock
;
439 pblock
->next
= pending_blocks
;
440 pending_blocks
= pblock
;
447 register struct pending_block
*next
;
448 register struct blockvector
*blockvector
;
451 /* Count the length of the list of blocks. */
453 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
455 blockvector
= (struct blockvector
*)
456 obstack_alloc (symbol_obstack
,
457 (sizeof (struct blockvector
)
458 + (i
- 1) * sizeof (struct block
*)));
460 /* Copy the blocks into the blockvector.
461 This is done in reverse order, which happens to put
462 the blocks into the proper order (ascending starting address).
463 finish_block has hair to insert each block into the list
464 after its subblocks in order to make sure this is true. */
466 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
467 for (next
= pending_blocks
; next
; next
= next
->next
) {
468 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
471 #if 0 /* Now we make the links in the obstack, so don't free them. */
472 /* Now free the links of the list, and empty the list. */
474 for (next
= pending_blocks
; next
; next
= next1
)
482 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
483 /* Some compilers output blocks in the wrong order, but we depend
484 on their being in the right order so we can binary search.
485 Check the order and moan about it. FIXME. */
486 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
487 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
488 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
489 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
490 complain (&blockvector_complaint
,
491 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
499 /* Start recording information about source code that came from an included
500 (or otherwise merged-in) source file with a different name. */
503 start_subfile (name
, dirname
)
507 register struct subfile
*subfile
;
509 /* See if this subfile is already known as a subfile of the
510 current main source file. */
512 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
514 if (!strcmp (subfile
->name
, name
))
516 current_subfile
= subfile
;
521 /* This subfile is not known. Add an entry for it.
522 Make an entry for this subfile in the list of all subfiles
523 of the current main source file. */
525 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
526 subfile
->next
= subfiles
;
528 current_subfile
= subfile
;
530 /* Save its name and compilation directory name */
531 subfile
->name
= obsavestring (name
, strlen (name
));
533 subfile
->dirname
= NULL
;
535 subfile
->dirname
= obsavestring (dirname
, strlen (dirname
));
537 /* Initialize line-number recording for this subfile. */
538 subfile
->line_vector
= 0;
541 /* Handle the N_BINCL and N_EINCL symbol types
542 that act like N_SOL for switching source files
543 (different subfiles, as we call them) within one object file,
544 but using a stack rather than in an arbitrary order. */
549 register struct subfile_stack
*tem
550 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
552 tem
->next
= subfile_stack
;
554 if (current_subfile
== 0 || current_subfile
->name
== 0)
556 tem
->name
= current_subfile
->name
;
557 tem
->prev_index
= header_file_prev_index
;
564 register struct subfile_stack
*link
= subfile_stack
;
570 subfile_stack
= link
->next
;
571 header_file_prev_index
= link
->prev_index
;
577 /* Manage the vector of line numbers for each subfile. */
580 record_line (subfile
, line
, pc
)
581 register struct subfile
*subfile
;
585 struct linetable_entry
*e
;
586 /* Ignore the dummy line number in libg.o */
591 /* Make sure line vector exists and is big enough. */
592 if (!subfile
->line_vector
) {
593 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
594 subfile
->line_vector
= (struct linetable
*)
595 xmalloc (sizeof (struct linetable
)
596 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
597 subfile
->line_vector
->nitems
= 0;
600 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
602 subfile
->line_vector_length
*= 2;
603 subfile
->line_vector
= (struct linetable
*)
604 xrealloc (subfile
->line_vector
, (sizeof (struct linetable
)
605 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
608 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
609 e
->line
= line
; e
->pc
= pc
;
613 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
617 compare_line_numbers (ln1
, ln2
)
618 struct linetable_entry
*ln1
, *ln2
;
620 return ln1
->line
- ln2
->line
;
623 /* Start a new symtab for a new source file.
624 This is called when a dbx symbol of type N_SO is seen;
625 it indicates the start of data for one original source file. */
628 start_symtab (name
, dirname
, start_addr
)
631 CORE_ADDR start_addr
;
634 last_source_file
= name
;
635 last_source_start_addr
= start_addr
;
638 global_stabs
= 0; /* AIX COFF */
639 file_stabs
= 0; /* AIX COFF */
642 /* Context stack is initially empty. Allocate first one with room for
643 10 levels; reuse it forever afterward. */
644 if (context_stack
== 0) {
645 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
646 context_stack
= (struct context_stack
*)
647 xmalloc (context_stack_size
* sizeof (struct context_stack
));
649 context_stack_depth
= 0;
651 new_object_header_files ();
653 type_vector_length
= 0;
654 type_vector
= (struct type
**) 0;
656 /* Initialize the list of sub source files with one entry
657 for this file (the top-level source file). */
661 start_subfile (name
, dirname
);
664 /* Finish the symbol definitions for one main source file,
665 close off all the lexical contexts for that file
666 (creating struct block's for them), then make the struct symtab
667 for that file and put it in the list of all such.
669 END_ADDR is the address of the end of the file's text. */
672 end_symtab (end_addr
, sort_pending
, sort_linevec
, objfile
)
676 struct objfile
*objfile
;
678 register struct symtab
*symtab
;
679 register struct blockvector
*blockvector
;
680 register struct subfile
*subfile
;
681 struct subfile
*nextsub
;
683 /* Finish the lexical context of the last function in the file;
684 pop the context stack. */
686 if (context_stack_depth
> 0)
688 register struct context_stack
*cstk
;
689 context_stack_depth
--;
690 cstk
= &context_stack
[context_stack_depth
];
691 /* Make a block for the local symbols within. */
692 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
693 cstk
->start_addr
, end_addr
);
695 /* Debug: if context stack still has something in it, we are in
697 if (context_stack_depth
> 0)
701 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
702 in this stage. Especially, blocks for static functions will show up at
703 the end. We need to sort them, so tools like `find_pc_function' and
704 `find_pc_block' can work reliably. */
705 if (sort_pending
&& pending_blocks
) {
706 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
709 struct pending_block
*pb
, *pbnext
;
711 pb
= pending_blocks
, pbnext
= pb
->next
;
716 /* swap blocks if unordered! */
718 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
)) {
719 struct block
*tmp
= pb
->block
;
720 pb
->block
= pbnext
->block
;
725 pbnext
= pbnext
->next
;
730 /* Cleanup any undefined types that have been left hanging around
731 (this needs to be done before the finish_blocks so that
732 file_symbols is still good). */
733 cleanup_undefined_types ();
735 /* Hooks for xcoffread.c */
737 patch_block_stabs (file_symbols
, file_stabs
);
743 patch_block_stabs (global_symbols
, global_stabs
);
748 if (pending_blocks
== 0
750 && global_symbols
== 0) {
751 /* Ignore symtabs that have no functions with real debugging info */
754 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
755 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
);
756 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
);
757 blockvector
= make_blockvector ();
760 /* Now create the symtab objects proper, one for each subfile. */
761 /* (The main file is the last one on the chain.) */
763 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
765 /* If we have blocks of symbols, make a symtab.
766 Otherwise, just ignore this file and any line number info in it. */
769 if (subfile
->line_vector
) {
770 /* First, shrink the linetable to make more memory. */
771 subfile
->line_vector
= (struct linetable
*)
772 xrealloc (subfile
->line_vector
, (sizeof (struct linetable
)
773 + subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
)));
776 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
777 sizeof (struct linetable_entry
), compare_line_numbers
);
780 /* Now, allocate a symbol table. */
781 symtab
= allocate_symtab (subfile
->name
, objfile
);
783 /* Fill in its components. */
784 symtab
->blockvector
= blockvector
;
785 symtab
->linetable
= subfile
->line_vector
;
786 symtab
->dirname
= subfile
->dirname
;
787 symtab
->free_code
= free_linetable
;
788 symtab
->free_ptr
= 0;
790 /* Link the new symtab into the list of such. */
791 symtab
->next
= symtab_list
;
792 symtab_list
= symtab
;
794 /* No blocks for this file. Delete any line number info we have
796 if (subfile
->line_vector
)
797 free (subfile
->line_vector
);
800 nextsub
= subfile
->next
;
805 free ((char *) type_vector
);
807 type_vector_length
= 0;
809 last_source_file
= 0;
816 /* Push a context block. Args are an identifying nesting level (checkable
817 when you pop it), and the starting PC address of this context. */
819 struct context_stack
*
820 push_context (desc
, valu
)
824 register struct context_stack
*new;
826 if (context_stack_depth
== context_stack_size
)
828 context_stack_size
*= 2;
829 context_stack
= (struct context_stack
*)
830 xrealloc (context_stack
,
832 * sizeof (struct context_stack
)));
835 new = &context_stack
[context_stack_depth
++];
837 new->locals
= local_symbols
;
838 new->old_blocks
= pending_blocks
;
839 new->start_addr
= valu
;
847 /* Initialize anything that needs initializing when starting to read
848 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
860 /* Initialize anything that needs initializing when a completely new
861 symbol file is specified (not just adding some symbols from another
862 file, e.g. a shared library). */
867 /* Empty the hash table of global syms looking for values. */
868 bzero (global_sym_chain
, sizeof global_sym_chain
);
873 /* Scan through all of the global symbols defined in the object file,
874 assigning values to the debugging symbols that need to be assigned
875 to. Get these symbols from the misc function list. */
883 for (mf
= 0; mf
< misc_function_count
; mf
++)
885 char *namestring
= misc_function_vector
[mf
].name
;
886 struct symbol
*sym
, *prev
;
890 prev
= (struct symbol
*) 0;
892 /* Get the hash index and check all the symbols
893 under that hash index. */
895 hash
= hashname (namestring
);
897 for (sym
= global_sym_chain
[hash
]; sym
;)
899 if (*namestring
== SYMBOL_NAME (sym
)[0]
900 && !strcmp(namestring
+ 1, SYMBOL_NAME (sym
) + 1))
902 /* Splice this symbol out of the hash chain and
903 assign the value we have to it. */
905 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
907 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
909 /* Check to see whether we need to fix up a common block. */
910 /* Note: this code might be executed several times for
911 the same symbol if there are multiple references. */
912 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
913 fix_common_block (sym
, misc_function_vector
[mf
].address
);
915 SYMBOL_VALUE_ADDRESS (sym
) = misc_function_vector
[mf
].address
;
918 sym
= SYMBOL_VALUE_CHAIN (prev
);
920 sym
= global_sym_chain
[hash
];
925 sym
= SYMBOL_VALUE_CHAIN (sym
);
932 /* Read a number by which a type is referred to in dbx data,
933 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
934 Just a single number N is equivalent to (0,N).
935 Return the two numbers by storing them in the vector TYPENUMS.
936 TYPENUMS will then be used as an argument to dbx_lookup_type. */
939 read_type_number (pp
, typenums
)
941 register int *typenums
;
946 typenums
[0] = read_number (pp
, ',');
947 typenums
[1] = read_number (pp
, ')');
952 typenums
[1] = read_number (pp
, 0);
956 /* To handle GNU C++ typename abbreviation, we need to be able to
957 fill in a type's name as soon as space for that type is allocated.
958 `type_synonym_name' is the name of the type being allocated.
959 It is cleared as soon as it is used (lest all allocated types
961 static char *type_synonym_name
;
965 define_symbol (valu
, string
, desc
, type
)
971 register struct symbol
*sym
;
972 char *p
= (char *) strchr (string
, ':');
977 /* Ignore syms with empty names. */
981 /* Ignore old-style symbols from cc -go */
985 sym
= (struct symbol
*)obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
987 if (processing_gcc_compilation
) {
988 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
989 number of bytes occupied by a type or object, which we ignore. */
990 SYMBOL_LINE(sym
) = desc
;
992 SYMBOL_LINE(sym
) = 0; /* unknown */
995 if (string
[0] == CPLUS_MARKER
)
997 /* Special GNU C++ names. */
1001 SYMBOL_NAME (sym
) = "this";
1003 case 'v': /* $vtbl_ptr_type */
1004 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1007 SYMBOL_NAME (sym
) = "eh_throw";
1011 /* This was an anonymous type that was never fixed up. */
1022 = (char *) obstack_alloc (symbol_obstack
, ((p
- string
) + 1));
1023 /* Open-coded bcopy--saves function call time. */
1025 register char *p1
= string
;
1026 register char *p2
= SYMBOL_NAME (sym
);
1033 /* Determine the type of name being defined. */
1034 /* The Acorn RISC machine's compiler can put out locals that don't
1035 start with "234=" or "(3,4)=", so assume anything other than the
1036 deftypes we know how to handle is a local. */
1037 /* (Peter Watkins @ Computervision)
1038 Handle Sun-style local fortran array types 'ar...' .
1039 (gnu@cygnus.com) -- this strchr() handles them properly?
1040 (tiemann@cygnus.com) -- 'C' is for catch. */
1041 if (!strchr ("cfFGpPrStTvVXC", *p
))
1046 /* c is a special case, not followed by a type-number.
1047 SYMBOL:c=iVALUE for an integer constant symbol.
1048 SYMBOL:c=rVALUE for a floating constant symbol.
1049 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1050 e.g. "b:c=e6,0" for "const b = blob1"
1051 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1055 error ("Invalid symbol data at symtab pos %d.", symnum
);
1060 double d
= atof (p
);
1063 SYMBOL_TYPE (sym
) = builtin_type_double
;
1065 (char *) obstack_alloc (symbol_obstack
, sizeof (double));
1066 bcopy (&d
, dbl_valu
, sizeof (double));
1067 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1068 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1069 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1074 SYMBOL_TYPE (sym
) = builtin_type_int
;
1075 SYMBOL_VALUE (sym
) = atoi (p
);
1076 SYMBOL_CLASS (sym
) = LOC_CONST
;
1080 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1081 e.g. "b:c=e6,0" for "const b = blob1"
1082 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1086 read_type_number (&p
, typenums
);
1088 error ("Invalid symbol data: no comma in enum const symbol");
1090 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1091 SYMBOL_VALUE (sym
) = atoi (p
);
1092 SYMBOL_CLASS (sym
) = LOC_CONST
;
1096 error ("Invalid symbol data at symtab pos %d.", symnum
);
1098 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1099 add_symbol_to_list (sym
, &file_symbols
);
1103 /* Now usually comes a number that says which data type,
1104 and possibly more stuff to define the type
1105 (all of which is handled by read_type) */
1107 if (deftype
== 'p' && *p
== 'F')
1108 /* pF is a two-letter code that means a function parameter in Fortran.
1109 The type-number specifies the type of the return value.
1110 Translate it into a pointer-to-function type. */
1114 = lookup_pointer_type (lookup_function_type (read_type (&p
)));
1118 struct type
*type_read
;
1119 synonym
= *p
== 't';
1124 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1125 strlen (SYMBOL_NAME (sym
)));
1128 /* Here we save the name of the symbol for read_range_type, which
1129 ends up reading in the basic types. In stabs, unfortunately there
1130 is no distinction between "int" and "long" types except their
1131 names. Until we work out a saner type policy (eliminating most
1132 builtin types and using the names specified in the files), we
1133 save away the name so that far away from here in read_range_type,
1134 we can examine it to decide between "int" and "long". FIXME. */
1135 long_kludge_name
= SYMBOL_NAME (sym
);
1136 type_read
= read_type (&p
);
1138 if ((deftype
== 'F' || deftype
== 'f')
1139 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
1142 /* This code doesn't work -- it needs to realloc and can't. */
1143 struct type
*new = (struct type
*)
1144 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1146 /* Generate a template for the type of this function. The
1147 types of the arguments will be added as we read the symbol
1149 *new = *lookup_function_type (type_read
);
1150 SYMBOL_TYPE(sym
) = new;
1151 in_function_type
= new;
1153 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
1157 SYMBOL_TYPE (sym
) = type_read
;
1163 /* The name of a caught exception. */
1164 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1165 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1166 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1167 add_symbol_to_list (sym
, &local_symbols
);
1171 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1172 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1173 add_symbol_to_list (sym
, &file_symbols
);
1177 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1178 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1179 add_symbol_to_list (sym
, &global_symbols
);
1183 /* For a class G (global) symbol, it appears that the
1184 value is not correct. It is necessary to search for the
1185 corresponding linker definition to find the value.
1186 These definitions appear at the end of the namelist. */
1187 i
= hashname (SYMBOL_NAME (sym
));
1188 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1189 global_sym_chain
[i
] = sym
;
1190 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1191 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1192 add_symbol_to_list (sym
, &global_symbols
);
1195 /* This case is faked by a conditional above,
1196 when there is no code letter in the dbx data.
1197 Dbx data never actually contains 'l'. */
1199 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1200 SYMBOL_VALUE (sym
) = valu
;
1201 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1202 add_symbol_to_list (sym
, &local_symbols
);
1206 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1207 can also be a LOC_LOCAL_ARG depending on symbol type. */
1208 #ifndef DBX_PARM_SYMBOL_CLASS
1209 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1211 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1212 SYMBOL_VALUE (sym
) = valu
;
1213 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1215 /* This doesn't work yet. */
1216 add_param_to_type (&in_function_type
, sym
);
1218 add_symbol_to_list (sym
, &local_symbols
);
1220 /* If it's gcc-compiled, if it says `short', believe it. */
1221 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1224 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1225 /* This macro is defined on machines (e.g. sparc) where
1226 we should believe the type of a PCC 'short' argument,
1227 but shouldn't believe the address (the address is
1228 the address of the corresponding int). Note that
1229 this is only different from the BELIEVE_PCC_PROMOTION
1230 case on big-endian machines.
1232 My guess is that this correction, as opposed to changing
1233 the parameter to an 'int' (as done below, for PCC
1234 on most machines), is the right thing to do
1235 on all machines, but I don't want to risk breaking
1236 something that already works. On most PCC machines,
1237 the sparc problem doesn't come up because the calling
1238 function has to zero the top bytes (not knowing whether
1239 the called function wants an int or a short), so there
1240 is no practical difference between an int and a short
1241 (except perhaps what happens when the GDB user types
1242 "print short_arg = 0x10000;").
1244 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1245 actually produces the correct address (we don't need to fix it
1246 up). I made this code adapt so that it will offset the symbol
1247 if it was pointing at an int-aligned location and not
1248 otherwise. This way you can use the same gdb for 4.0.x and
1251 If the parameter is shorter than an int, and is integral
1252 (e.g. char, short, or unsigned equivalent), and is claimed to
1253 be passed on an integer boundary, don't believe it! Offset the
1254 parameter's address to the tail-end of that integer. */
1256 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (builtin_type_int
)
1257 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1258 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (builtin_type_int
)) {
1259 SYMBOL_VALUE (sym
) += TYPE_LENGTH (builtin_type_int
)
1260 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1264 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1266 /* If PCC says a parameter is a short or a char,
1267 it is really an int. */
1268 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (builtin_type_int
)
1269 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
) {
1270 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))?
1271 builtin_type_unsigned_int
:
1276 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1279 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1280 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1281 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1282 add_symbol_to_list (sym
, &local_symbols
);
1286 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1287 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1288 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1289 add_symbol_to_list (sym
, &local_symbols
);
1293 /* Static symbol at top level of file */
1294 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1295 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1296 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1297 add_symbol_to_list (sym
, &file_symbols
);
1301 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1302 SYMBOL_VALUE (sym
) = valu
;
1303 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1304 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1305 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1306 TYPE_NAME (SYMBOL_TYPE (sym
)) =
1307 obsavestring (SYMBOL_NAME (sym
),
1308 strlen (SYMBOL_NAME (sym
)));
1309 /* C++ vagaries: we may have a type which is derived from
1310 a base type which did not have its name defined when the
1311 derived class was output. We fill in the derived class's
1312 base part member's name here in that case. */
1313 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1314 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1315 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1318 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1319 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1320 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1321 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1324 add_symbol_to_list (sym
, &file_symbols
);
1328 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1329 SYMBOL_VALUE (sym
) = valu
;
1330 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1331 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1332 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1333 TYPE_NAME (SYMBOL_TYPE (sym
))
1335 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1337 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1338 ? "struct " : "union ")),
1340 add_symbol_to_list (sym
, &file_symbols
);
1344 register struct symbol
*typedef_sym
1345 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1346 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1347 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1349 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1350 SYMBOL_VALUE (typedef_sym
) = valu
;
1351 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1352 add_symbol_to_list (typedef_sym
, &file_symbols
);
1357 /* Static symbol of local scope */
1358 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1359 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1360 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1361 add_symbol_to_list (sym
, &local_symbols
);
1365 /* Reference parameter */
1366 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1367 SYMBOL_VALUE (sym
) = valu
;
1368 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1369 add_symbol_to_list (sym
, &local_symbols
);
1373 /* This is used by Sun FORTRAN for "function result value".
1374 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1375 that Pascal uses it too, but when I tried it Pascal used
1376 "x:3" (local symbol) instead. */
1377 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1378 SYMBOL_VALUE (sym
) = valu
;
1379 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1380 add_symbol_to_list (sym
, &local_symbols
);
1384 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1389 /* What about types defined as forward references inside of a small lexical
1391 /* Add a type to the list of undefined types to be checked through
1392 once this file has been read in. */
1394 add_undefined_type (type
)
1397 if (undef_types_length
== undef_types_allocated
)
1399 undef_types_allocated
*= 2;
1400 undef_types
= (struct type
**)
1401 xrealloc (undef_types
,
1402 undef_types_allocated
* sizeof (struct type
*));
1404 undef_types
[undef_types_length
++] = type
;
1407 /* Go through each undefined type, see if it's still undefined, and fix it
1408 up if possible. We have two kinds of undefined types:
1410 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1411 Fix: update array length using the element bounds
1412 and the target type's length.
1413 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1414 yet defined at the time a pointer to it was made.
1415 Fix: Do a full lookup on the struct/union tag. */
1417 cleanup_undefined_types ()
1421 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1422 switch (TYPE_CODE (*type
)) {
1424 case TYPE_CODE_STRUCT
:
1425 case TYPE_CODE_UNION
:
1427 /* Reasonable test to see if it's been defined since. */
1428 if (TYPE_NFIELDS (*type
) == 0)
1430 struct pending
*ppt
;
1432 /* Name of the type, without "struct" or "union" */
1433 char *typename
= TYPE_NAME (*type
);
1435 if (!strncmp (typename
, "struct ", 7))
1437 if (!strncmp (typename
, "union ", 6))
1440 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1441 for (i
= 0; i
< ppt
->nsyms
; i
++)
1443 struct symbol
*sym
= ppt
->symbol
[i
];
1445 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1446 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1447 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1449 && !strcmp (SYMBOL_NAME (sym
), typename
))
1450 bcopy (SYMBOL_TYPE (sym
), *type
, sizeof (struct type
));
1454 /* It has been defined; don't mark it as a stub. */
1455 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1459 case TYPE_CODE_ARRAY
:
1461 struct type
*range_type
;
1464 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1466 if (TYPE_NFIELDS (*type
) != 1)
1468 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1469 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1472 /* Now recompute the length of the array type, based on its
1473 number of elements and the target type's length. */
1474 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1475 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1476 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1477 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1483 error ("GDB internal error. cleanup_undefined_types with bad type.");
1487 undef_types_length
= 0;
1490 /* Skip rest of this symbol and return an error type.
1492 General notes on error recovery: error_type always skips to the
1493 end of the symbol (modulo cretinous dbx symbol name continuation).
1494 Thus code like this:
1496 if (*(*pp)++ != ';')
1497 return error_type (pp);
1499 is wrong because if *pp starts out pointing at '\0' (typically as the
1500 result of an earlier error), it will be incremented to point to the
1501 start of the next symbol, which might produce strange results, at least
1502 if you run off the end of the string table. Instead use
1505 return error_type (pp);
1511 foo = error_type (pp);
1515 And in case it isn't obvious, the point of all this hair is so the compiler
1516 can define new types and new syntaxes, and old versions of the
1517 debugger will be able to read the new symbol tables. */
1523 complain (&error_type_complaint
, 0);
1526 /* Skip to end of symbol. */
1527 while (**pp
!= '\0')
1530 /* Check for and handle cretinous dbx symbol name continuation! */
1531 if ((*pp
)[-1] == '\\')
1532 *pp
= next_symbol_text ();
1536 return builtin_type_error
;
1539 /* Read a dbx type reference or definition;
1540 return the type that is meant.
1541 This can be just a number, in which case it references
1542 a type already defined and placed in type_vector.
1543 Or the number can be followed by an =, in which case
1544 it means to define a new type according to the text that
1551 register struct type
*type
= 0;
1556 /* Read type number if present. The type number may be omitted.
1557 for instance in a two-dimensional array declared with type
1558 "ar1;1;10;ar1;1;10;4". */
1559 if ((**pp
>= '0' && **pp
<= '9')
1562 read_type_number (pp
, typenums
);
1564 /* Type is not being defined here. Either it already exists,
1565 or this is a forward reference to it. dbx_alloc_type handles
1568 return dbx_alloc_type (typenums
);
1570 /* Type is being defined here. */
1571 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1575 /* if such a type already exists, this is an unnecessary duplication
1576 of the stab string, which is common in (RS/6000) xlc generated
1577 objects. In that case, simply return NULL and let the caller take
1580 tt
= *dbx_lookup_type (typenums
);
1581 if (tt
&& tt
->length
&& tt
->code
)
1590 /* 'typenums=' not present, type is anonymous. Read and return
1591 the definition, but don't put it in the type vector. */
1592 typenums
[0] = typenums
[1] = -1;
1600 enum type_code code
;
1602 /* Used to index through file_symbols. */
1603 struct pending
*ppt
;
1606 /* Name including "struct", etc. */
1609 /* Name without "struct", etc. */
1610 char *type_name_only
;
1616 /* Set the type code according to the following letter. */
1620 code
= TYPE_CODE_STRUCT
;
1624 code
= TYPE_CODE_UNION
;
1628 code
= TYPE_CODE_ENUM
;
1632 return error_type (pp
);
1635 to
= type_name
= (char *)
1636 obstack_alloc (symbol_obstack
,
1638 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1640 /* Copy the prefix. */
1642 while (*to
++ = *from
++)
1646 type_name_only
= to
;
1648 /* Copy the name. */
1650 while ((*to
++ = *from
++) != ':')
1654 /* Set the pointer ahead of the name which we just read. */
1658 /* The following hack is clearly wrong, because it doesn't
1659 check whether we are in a baseclass. I tried to reproduce
1660 the case that it is trying to fix, but I couldn't get
1661 g++ to put out a cross reference to a basetype. Perhaps
1662 it doesn't do it anymore. */
1663 /* Note: for C++, the cross reference may be to a base type which
1664 has not yet been seen. In this case, we skip to the comma,
1665 which will mark the end of the base class name. (The ':'
1666 at the end of the base class name will be skipped as well.)
1667 But sometimes (ie. when the cross ref is the last thing on
1668 the line) there will be no ','. */
1669 from
= (char *) strchr (*pp
, ',');
1675 /* Now check to see whether the type has already been declared. */
1676 /* This is necessary at least in the case where the
1677 program says something like
1679 The compiler puts out a cross-reference; we better find
1680 set the length of the structure correctly so we can
1681 set the length of the array. */
1682 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1683 for (i
= 0; i
< ppt
->nsyms
; i
++)
1685 struct symbol
*sym
= ppt
->symbol
[i
];
1687 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1688 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1689 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1690 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1692 obstack_free (symbol_obstack
, type_name
);
1693 type
= SYMBOL_TYPE (sym
);
1698 /* Didn't find the type to which this refers, so we must
1699 be dealing with a forward reference. Allocate a type
1700 structure for it, and keep track of it so we can
1701 fill in the rest of the fields when we get the full
1703 type
= dbx_alloc_type (typenums
);
1704 TYPE_CODE (type
) = code
;
1705 TYPE_NAME (type
) = type_name
;
1706 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1708 TYPE_CPLUS_SPECIFIC (type
)
1709 = (struct cplus_struct_type
*) obstack_alloc (symbol_obstack
, sizeof (struct cplus_struct_type
));
1710 bzero (TYPE_CPLUS_SPECIFIC (type
), sizeof (struct cplus_struct_type
));
1713 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1715 add_undefined_type (type
);
1719 case '-': /* RS/6000 built-in type */
1721 type
= builtin_type (pp
); /* (in xcoffread.c) */
1736 read_type_number (pp
, xtypenums
);
1737 type
= *dbx_lookup_type (xtypenums
);
1742 type
= builtin_type_void
;
1743 if (typenums
[0] != -1)
1744 *dbx_lookup_type (typenums
) = type
;
1748 type1
= read_type (pp
);
1749 /* FIXME -- we should be doing smash_to_XXX types here. */
1751 /* postponed type decoration should be allowed. */
1752 if (typenums
[1] > 0 && typenums
[1] < type_vector_length
&&
1753 (type
= type_vector
[typenums
[1]])) {
1754 smash_to_pointer_type (type
, type1
);
1758 type
= lookup_pointer_type (type1
);
1759 if (typenums
[0] != -1)
1760 *dbx_lookup_type (typenums
) = type
;
1765 struct type
*domain
= read_type (pp
);
1766 struct type
*memtype
;
1769 /* Invalid member type data format. */
1770 return error_type (pp
);
1773 memtype
= read_type (pp
);
1774 type
= dbx_alloc_type (typenums
);
1775 smash_to_member_type (type
, domain
, memtype
);
1780 if ((*pp
)[0] == '#')
1782 /* We'll get the parameter types from the name. */
1783 struct type
*return_type
;
1786 return_type
= read_type (pp
);
1787 if (*(*pp
)++ != ';')
1788 complain (&invalid_member_complaint
, symnum
);
1789 type
= allocate_stub_method (return_type
);
1790 if (typenums
[0] != -1)
1791 *dbx_lookup_type (typenums
) = type
;
1795 struct type
*domain
= read_type (pp
);
1796 struct type
*return_type
;
1799 if (*(*pp
)++ != ',')
1800 error ("invalid member type data format, at symtab pos %d.",
1803 return_type
= read_type (pp
);
1804 args
= read_args (pp
, ';');
1805 type
= dbx_alloc_type (typenums
);
1806 smash_to_method_type (type
, domain
, return_type
, args
);
1811 type1
= read_type (pp
);
1812 type
= lookup_reference_type (type1
);
1813 if (typenums
[0] != -1)
1814 *dbx_lookup_type (typenums
) = type
;
1818 type1
= read_type (pp
);
1819 type
= lookup_function_type (type1
);
1820 if (typenums
[0] != -1)
1821 *dbx_lookup_type (typenums
) = type
;
1825 type
= read_range_type (pp
, typenums
);
1826 if (typenums
[0] != -1)
1827 *dbx_lookup_type (typenums
) = type
;
1831 type
= dbx_alloc_type (typenums
);
1832 type
= read_enum_type (pp
, type
);
1833 *dbx_lookup_type (typenums
) = type
;
1837 type
= dbx_alloc_type (typenums
);
1838 TYPE_NAME (type
) = type_synonym_name
;
1839 type_synonym_name
= 0;
1840 type
= read_struct_type (pp
, type
);
1844 type
= dbx_alloc_type (typenums
);
1845 TYPE_NAME (type
) = type_synonym_name
;
1846 type_synonym_name
= 0;
1847 type
= read_struct_type (pp
, type
);
1848 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1853 return error_type (pp
);
1856 type
= dbx_alloc_type (typenums
);
1857 type
= read_array_type (pp
, type
);
1861 --*pp
; /* Go back to the symbol in error */
1862 /* Particularly important if it was \0! */
1863 return error_type (pp
);
1870 /* If this is an overriding temporary alteration for a header file's
1871 contents, and this type number is unknown in the global definition,
1872 put this type into the global definition at this type number. */
1873 if (header_file_prev_index
>= 0)
1875 register struct type
**tp
1876 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
1884 /* This page contains subroutines of read_type. */
1886 /* Read the description of a structure (or union type)
1887 and return an object describing the type. */
1890 read_struct_type (pp
, type
)
1892 register struct type
*type
;
1894 /* Total number of methods defined in this class.
1895 If the class defines two `f' methods, and one `g' method,
1896 then this will have the value 3. */
1897 int total_length
= 0;
1901 struct nextfield
*next
;
1902 int visibility
; /* 0=public, 1=protected, 2=public */
1908 struct next_fnfield
*next
;
1909 int visibility
; /* 0=public, 1=protected, 2=public */
1910 struct fn_field fn_field
;
1913 struct next_fnfieldlist
1915 struct next_fnfieldlist
*next
;
1916 struct fn_fieldlist fn_fieldlist
;
1919 register struct nextfield
*list
= 0;
1920 struct nextfield
*new;
1925 register struct next_fnfieldlist
*mainlist
= 0;
1928 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1929 TYPE_CPLUS_SPECIFIC (type
)
1930 = (struct cplus_struct_type
*) obstack_alloc (symbol_obstack
, sizeof (struct cplus_struct_type
));
1931 bzero (TYPE_CPLUS_SPECIFIC (type
), sizeof (struct cplus_struct_type
));
1933 /* First comes the total size in bytes. */
1935 TYPE_LENGTH (type
) = read_number (pp
, 0);
1937 /* C++: Now, if the class is a derived class, then the next character
1938 will be a '!', followed by the number of base classes derived from.
1939 Each element in the list contains visibility information,
1940 the offset of this base class in the derived structure,
1941 and then the base type. */
1944 int i
, n_baseclasses
, offset
;
1945 struct type
*baseclass
;
1948 /* Nonzero if it is a virtual baseclass, i.e.,
1952 struct C : public B, public virtual A {};
1954 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1955 2.0 language feature. */
1960 n_baseclasses
= read_number (pp
, ',');
1961 TYPE_FIELD_VIRTUAL_BITS (type
) =
1962 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (n_baseclasses
));
1963 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
1965 for (i
= 0; i
< n_baseclasses
; i
++)
1968 *pp
= next_symbol_text ();
1979 /* Bad visibility format. */
1980 return error_type (pp
);
1993 /* Bad visibility format. */
1994 return error_type (pp
);
1997 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2000 /* Offset of the portion of the object corresponding to
2001 this baseclass. Always zero in the absence of
2002 multiple inheritance. */
2003 offset
= read_number (pp
, ',');
2004 baseclass
= read_type (pp
);
2005 *pp
+= 1; /* skip trailing ';' */
2007 /* Make this baseclass visible for structure-printing purposes. */
2008 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2011 list
->visibility
= via_public
;
2012 list
->field
.type
= baseclass
;
2013 list
->field
.name
= type_name_no_tag (baseclass
);
2014 list
->field
.bitpos
= offset
;
2015 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2018 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
2021 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2022 At the end, we see a semicolon instead of a field.
2024 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2027 The `?' is a placeholder for one of '/2' (public visibility),
2028 '/1' (protected visibility), '/0' (private visibility), or nothing
2029 (C style symbol table, public visibility). */
2031 /* We better set p right now, in case there are no fields at all... */
2036 /* Check for and handle cretinous dbx symbol name continuation! */
2037 if (**pp
== '\\') *pp
= next_symbol_text ();
2039 /* Get space to record the next field's data. */
2040 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2044 /* Get the field name. */
2046 if (*p
== CPLUS_MARKER
)
2048 /* Special GNU C++ name. */
2053 struct type
*context
;
2064 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2065 prefix
= "INVALID_C++_ABBREV";
2069 context
= read_type (pp
);
2070 name
= type_name_no_tag (context
);
2073 complain (&invalid_cpp_type_complaint
, symnum
);
2074 TYPE_NAME (context
) = name
;
2076 list
->field
.name
= obconcat (prefix
, name
, "");
2079 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2080 list
->field
.type
= read_type (pp
);
2081 (*pp
)++; /* Skip the comma. */
2082 list
->field
.bitpos
= read_number (pp
, ';');
2083 /* This field is unpacked. */
2084 list
->field
.bitsize
= 0;
2086 /* GNU C++ anonymous type. */
2090 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2096 while (*p
!= ':') p
++;
2097 list
->field
.name
= obsavestring (*pp
, p
- *pp
);
2099 /* C++: Check to see if we have hit the methods yet. */
2105 /* This means we have a visibility for a field coming. */
2111 list
->visibility
= 0; /* private */
2116 list
->visibility
= 1; /* protected */
2121 list
->visibility
= 2; /* public */
2126 else /* normal dbx-style format. */
2127 list
->visibility
= 2; /* public */
2129 list
->field
.type
= read_type (pp
);
2132 /* Static class member. */
2133 list
->field
.bitpos
= (long)-1;
2135 while (*p
!= ';') p
++;
2136 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2141 else if (**pp
!= ',')
2142 /* Bad structure-type format. */
2143 return error_type (pp
);
2145 (*pp
)++; /* Skip the comma. */
2146 list
->field
.bitpos
= read_number (pp
, ',');
2147 list
->field
.bitsize
= read_number (pp
, ';');
2150 /* FIXME-tiemann: Can't the compiler put out something which
2151 lets us distinguish these? (or maybe just not put out anything
2152 for the field). What is the story here? What does the compiler
2153 really do? Also, patch gdb.texinfo for this case; I document
2154 it as a possible problem there. Search for "DBX-style". */
2156 /* This is wrong because this is identical to the symbols
2157 produced for GCC 0-size arrays. For example:
2162 The code which dumped core in such circumstances should be
2163 fixed not to dump core. */
2165 /* g++ -g0 can put out bitpos & bitsize zero for a static
2166 field. This does not give us any way of getting its
2167 class, so we can't know its name. But we can just
2168 ignore the field so we don't dump core and other nasty
2170 if (list
->field
.bitpos
== 0
2171 && list
->field
.bitsize
== 0)
2173 complain (&dbx_class_complaint
, 0);
2174 /* Ignore this field. */
2180 /* Detect an unpacked field and mark it as such.
2181 dbx gives a bit size for all fields.
2182 Note that forward refs cannot be packed,
2183 and treat enums as if they had the width of ints. */
2184 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2185 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2186 list
->field
.bitsize
= 0;
2187 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2188 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2189 && (list
->field
.bitsize
2190 == 8 * TYPE_LENGTH (builtin_type_int
))
2194 list
->field
.bitpos
% 8 == 0)
2195 list
->field
.bitsize
= 0;
2201 /* chill the list of fields: the last entry (at the head)
2202 is a partially constructed entry which we now scrub. */
2205 /* Now create the vector of fields, and record how big it is.
2206 We need this info to record proper virtual function table information
2207 for this class's virtual functions. */
2209 TYPE_NFIELDS (type
) = nfields
;
2210 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
,
2211 sizeof (struct field
) * nfields
);
2213 TYPE_FIELD_PRIVATE_BITS (type
) =
2214 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
2215 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2217 TYPE_FIELD_PROTECTED_BITS (type
) =
2218 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
2219 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2221 /* Copy the saved-up fields into the field vector. */
2223 for (n
= nfields
; list
; list
= list
->next
)
2226 TYPE_FIELD (type
, n
) = list
->field
;
2227 if (list
->visibility
== 0)
2228 SET_TYPE_FIELD_PRIVATE (type
, n
);
2229 else if (list
->visibility
== 1)
2230 SET_TYPE_FIELD_PROTECTED (type
, n
);
2233 /* Now come the method fields, as NAME::methods
2234 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2235 At the end, we see a semicolon instead of a field.
2237 For the case of overloaded operators, the format is
2238 OPERATOR::*.methods, where OPERATOR is the string "operator",
2239 `*' holds the place for an operator name (such as `+=')
2240 and `.' marks the end of the operator name. */
2243 /* Now, read in the methods. To simplify matters, we
2244 "unread" the name that has been read, so that we can
2245 start from the top. */
2247 /* For each list of method lists... */
2251 struct next_fnfield
*sublist
= 0;
2252 struct type
*look_ahead_type
= NULL
;
2254 struct next_fnfieldlist
*new_mainlist
=
2255 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2260 /* read in the name. */
2261 while (*p
!= ':') p
++;
2262 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2264 /* This is a completely wierd case. In order to stuff in the
2265 names that might contain colons (the usual name delimiter),
2266 Mike Tiemann defined a different name format which is
2267 signalled if the identifier is "op$". In that case, the
2268 format is "op$::XXXX." where XXXX is the name. This is
2269 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2270 /* This lets the user type "break operator+".
2271 We could just put in "+" as the name, but that wouldn't
2273 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2274 char *o
= opname
+ 3;
2276 /* Skip past '::'. */
2278 if (**pp
== '\\') *pp
= next_symbol_text ();
2282 main_fn_name
= savestring (opname
, o
- opname
);
2287 main_fn_name
= savestring (*pp
, p
- *pp
);
2288 /* Skip past '::'. */
2290 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2294 struct next_fnfield
*new_sublist
=
2295 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2297 /* Check for and handle cretinous dbx symbol name continuation! */
2298 if (look_ahead_type
== NULL
) /* Normal case. */
2300 if (**pp
== '\\') *pp
= next_symbol_text ();
2302 new_sublist
->fn_field
.type
= read_type (pp
);
2304 /* Invalid symtab info for method. */
2305 return error_type (pp
);
2308 { /* g++ version 1 kludge */
2309 new_sublist
->fn_field
.type
= look_ahead_type
;
2310 look_ahead_type
= NULL
;
2315 while (*p
!= ';') p
++;
2316 /* If this is just a stub, then we don't have the
2318 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2320 new_sublist
->visibility
= *(*pp
)++ - '0';
2321 if (**pp
== '\\') *pp
= next_symbol_text ();
2324 case 'A': /* Normal functions. */
2325 new_sublist
->fn_field
.is_const
= 0;
2326 new_sublist
->fn_field
.is_volatile
= 0;
2329 case 'B': /* `const' member functions. */
2330 new_sublist
->fn_field
.is_const
= 1;
2331 new_sublist
->fn_field
.is_volatile
= 0;
2334 case 'C': /* `volatile' member function. */
2335 new_sublist
->fn_field
.is_const
= 0;
2336 new_sublist
->fn_field
.is_volatile
= 1;
2339 case 'D': /* `const volatile' member function. */
2340 new_sublist
->fn_field
.is_const
= 1;
2341 new_sublist
->fn_field
.is_volatile
= 1;
2344 case '*': /* File compiled with g++ version 1 -- no info */
2349 complain(&const_vol_complaint
, **pp
);
2356 /* virtual member function, followed by index. */
2357 /* The sign bit is set to distinguish pointers-to-methods
2358 from virtual function indicies. Since the array is
2359 in words, the quantity must be shifted left by 1
2360 on 16 bit machine, and by 2 on 32 bit machine, forcing
2361 the sign bit out, and usable as a valid index into
2362 the array. Remove the sign bit here. */
2363 new_sublist
->fn_field
.voffset
=
2364 (0x7fffffff & read_number (pp
, ';')) + 2;
2366 if (**pp
== '\\') *pp
= next_symbol_text ();
2368 if (**pp
== ';' || **pp
== '\0')
2369 /* Must be g++ version 1. */
2370 new_sublist
->fn_field
.fcontext
= 0;
2373 /* Figure out from whence this virtual function came.
2374 It may belong to virtual function table of
2375 one of its baseclasses. */
2376 look_ahead_type
= read_type (pp
);
2378 { /* g++ version 1 overloaded methods. */ }
2381 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2383 return error_type (pp
);
2386 look_ahead_type
= NULL
;
2392 /* static member function. */
2393 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2398 complain (&member_fn_complaint
, (*pp
)[-1]);
2399 /* Fall through into normal member function. */
2402 /* normal member function. */
2403 new_sublist
->fn_field
.voffset
= 0;
2404 new_sublist
->fn_field
.fcontext
= 0;
2408 new_sublist
->next
= sublist
;
2409 sublist
= new_sublist
;
2411 if (**pp
== '\\') *pp
= next_symbol_text ();
2413 while (**pp
!= ';' && **pp
!= '\0');
2417 new_mainlist
->fn_fieldlist
.fn_fields
=
2418 (struct fn_field
*) obstack_alloc (symbol_obstack
,
2419 sizeof (struct fn_field
) * length
);
2420 TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
) =
2421 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
2422 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
), length
);
2424 TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
) =
2425 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
2426 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
), length
);
2428 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2430 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2431 if (sublist
->visibility
== 0)
2432 B_SET (new_mainlist
->fn_fieldlist
.private_fn_field_bits
, i
);
2433 else if (sublist
->visibility
== 1)
2434 B_SET (new_mainlist
->fn_fieldlist
.protected_fn_field_bits
, i
);
2437 new_mainlist
->fn_fieldlist
.length
= length
;
2438 new_mainlist
->next
= mainlist
;
2439 mainlist
= new_mainlist
;
2441 total_length
+= length
;
2443 while (**pp
!= ';');
2448 TYPE_FN_FIELDLISTS (type
) =
2449 (struct fn_fieldlist
*) obstack_alloc (symbol_obstack
,
2450 sizeof (struct fn_fieldlist
) * nfn_fields
);
2452 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2453 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2457 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2458 TYPE_NFN_FIELDS_TOTAL (type
) +=
2459 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2462 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
)
2463 TYPE_FN_FIELDLISTS (type
)[--n
] = mainlist
->fn_fieldlist
;
2469 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2471 /* Obsolete flags that used to indicate the presence
2472 of constructors and/or destructors. */
2476 /* Read either a '%' or the final ';'. */
2477 if (*(*pp
)++ == '%')
2479 /* We'd like to be able to derive the vtable pointer field
2480 from the type information, but when it's inherited, that's
2481 hard. A reason it's hard is because we may read in the
2482 info about a derived class before we read in info about
2483 the base class that provides the vtable pointer field.
2484 Once the base info has been read, we could fill in the info
2485 for the derived classes, but for the fact that by then,
2486 we don't remember who needs what. */
2488 int predicted_fieldno
= -1;
2490 /* Now we must record the virtual function table pointer's
2491 field information. */
2499 /* In version 2, we derive the vfield ourselves. */
2500 for (n
= 0; n
< nfields
; n
++)
2502 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2503 sizeof (vptr_name
) -1))
2505 predicted_fieldno
= n
;
2509 if (predicted_fieldno
< 0)
2510 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2511 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2512 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2514 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2522 while (*p
!= '\0' && *p
!= ';')
2525 /* Premature end of symbol. */
2526 return error_type (pp
);
2528 TYPE_VPTR_BASETYPE (type
) = t
;
2531 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2533 /* FIXME-tiemann: what's this? */
2535 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2540 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2541 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2542 sizeof (vptr_name
) -1))
2544 TYPE_VPTR_FIELDNO (type
) = i
;
2548 /* Virtual function table field not found. */
2549 return error_type (pp
);
2552 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2555 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2556 error ("TYPE_VPTR_FIELDNO miscalculated");
2566 /* Read a definition of an array type,
2567 and create and return a suitable type object.
2568 Also creates a range type which represents the bounds of that
2571 read_array_type (pp
, type
)
2573 register struct type
*type
;
2575 struct type
*index_type
, *element_type
, *range_type
;
2579 /* Format of an array type:
2580 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2583 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2584 for these, produce a type like float[][]. */
2586 index_type
= read_type (pp
);
2588 /* Improper format of array type decl. */
2589 return error_type (pp
);
2592 if (!(**pp
>= '0' && **pp
<= '9'))
2597 lower
= read_number (pp
, ';');
2599 if (!(**pp
>= '0' && **pp
<= '9'))
2604 upper
= read_number (pp
, ';');
2606 element_type
= read_type (pp
);
2615 /* Create range type. */
2616 range_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2617 sizeof (struct type
));
2618 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2619 TYPE_TARGET_TYPE (range_type
) = index_type
;
2621 /* This should never be needed. */
2622 TYPE_LENGTH (range_type
) = sizeof (int);
2624 TYPE_NFIELDS (range_type
) = 2;
2625 TYPE_FIELDS (range_type
) =
2626 (struct field
*) obstack_alloc (symbol_obstack
,
2627 2 * sizeof (struct field
));
2628 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2629 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2632 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2633 TYPE_TARGET_TYPE (type
) = element_type
;
2634 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2635 TYPE_NFIELDS (type
) = 1;
2636 TYPE_FIELDS (type
) =
2637 (struct field
*) obstack_alloc (symbol_obstack
,
2638 sizeof (struct field
));
2639 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2641 /* If we have an array whose element type is not yet known, but whose
2642 bounds *are* known, record it to be adjusted at the end of the file. */
2643 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2644 add_undefined_type (type
);
2650 /* Read a definition of an enumeration type,
2651 and create and return a suitable type object.
2652 Also defines the symbols that represent the values of the type. */
2655 read_enum_type (pp
, type
)
2657 register struct type
*type
;
2662 register struct symbol
*sym
;
2664 struct pending
**symlist
;
2665 struct pending
*osyms
, *syms
;
2668 if (within_function
)
2669 symlist
= &local_symbols
;
2671 symlist
= &file_symbols
;
2673 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2675 /* Read the value-names and their values.
2676 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2677 A semicolon or comman instead of a NAME means the end. */
2678 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2680 /* Check for and handle cretinous dbx symbol name continuation! */
2681 if (**pp
== '\\') *pp
= next_symbol_text ();
2684 while (*p
!= ':') p
++;
2685 name
= obsavestring (*pp
, p
- *pp
);
2687 n
= read_number (pp
, ',');
2689 sym
= (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2690 bzero (sym
, sizeof (struct symbol
));
2691 SYMBOL_NAME (sym
) = name
;
2692 SYMBOL_CLASS (sym
) = LOC_CONST
;
2693 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2694 SYMBOL_VALUE (sym
) = n
;
2695 add_symbol_to_list (sym
, symlist
);
2700 (*pp
)++; /* Skip the semicolon. */
2702 /* Now fill in the fields of the type-structure. */
2704 TYPE_LENGTH (type
) = sizeof (int);
2705 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2706 TYPE_NFIELDS (type
) = nsyms
;
2707 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2709 /* Find the symbols for the values and put them into the type.
2710 The symbols can be found in the symlist that we put them on
2711 to cause them to be defined. osyms contains the old value
2712 of that symlist; everything up to there was defined by us. */
2713 /* Note that we preserve the order of the enum constants, so
2714 that in something like "enum {FOO, LAST_THING=FOO}" we print
2715 FOO, not LAST_THING. */
2717 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2722 for (; j
< syms
->nsyms
; j
++,n
++)
2724 struct symbol
*xsym
= syms
->symbol
[j
];
2725 SYMBOL_TYPE (xsym
) = type
;
2726 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2727 TYPE_FIELD_VALUE (type
, n
) = 0;
2728 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2729 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2736 /* This screws up perfectly good C programs with enums. FIXME. */
2737 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2738 if(TYPE_NFIELDS(type
) == 2 &&
2739 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2740 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2741 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2742 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2743 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2749 /* Read a number from the string pointed to by *PP.
2750 The value of *PP is advanced over the number.
2751 If END is nonzero, the character that ends the
2752 number must match END, or an error happens;
2753 and that character is skipped if it does match.
2754 If END is zero, *PP is left pointing to that character.
2756 If the number fits in a long, set *VALUE and set *BITS to 0.
2757 If not, set *BITS to be the number of bits in the number.
2759 If encounter garbage, set *BITS to -1. */
2762 read_huge_number (pp
, end
, valu
, bits
)
2783 /* Leading zero means octal. GCC uses this to output values larger
2784 than an int (because that would be hard in decimal). */
2791 upper_limit
= LONG_MAX
/ radix
;
2792 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2794 if (n
<= upper_limit
)
2797 n
+= c
- '0'; /* FIXME this overflows anyway */
2802 /* This depends on large values being output in octal, which is
2809 /* Ignore leading zeroes. */
2813 else if (c
== '2' || c
== '3')
2839 /* Large decimal constants are an error (because it is hard to
2840 count how many bits are in them). */
2846 /* -0x7f is the same as 0x80. So deal with it by adding one to
2847 the number of bits. */
2862 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2863 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
2866 read_range_type (pp
, typenums
)
2874 struct type
*result_type
;
2876 /* First comes a type we are a subrange of.
2877 In C it is usually 0, 1 or the type being defined. */
2878 read_type_number (pp
, rangenums
);
2879 self_subrange
= (rangenums
[0] == typenums
[0] &&
2880 rangenums
[1] == typenums
[1]);
2882 /* A semicolon should now follow; skip it. */
2886 /* The remaining two operands are usually lower and upper bounds
2887 of the range. But in some special cases they mean something else. */
2888 read_huge_number (pp
, ';', &n2
, &n2bits
);
2889 read_huge_number (pp
, ';', &n3
, &n3bits
);
2891 if (n2bits
== -1 || n3bits
== -1)
2892 return error_type (pp
);
2894 /* If limits are huge, must be large integral type. */
2895 if (n2bits
!= 0 || n3bits
!= 0)
2897 char got_signed
= 0;
2898 char got_unsigned
= 0;
2899 /* Number of bits in the type. */
2902 /* Range from 0 to <large number> is an unsigned large integral type. */
2903 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2908 /* Range from <large number> to <large number>-1 is a large signed
2910 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2916 /* Check for "long long". */
2917 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2918 return builtin_type_long_long
;
2919 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2920 return builtin_type_unsigned_long_long
;
2922 if (got_signed
|| got_unsigned
)
2924 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2925 sizeof (struct type
));
2926 bzero (result_type
, sizeof (struct type
));
2927 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2928 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2930 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2934 return error_type (pp
);
2937 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2938 if (self_subrange
&& n2
== 0 && n3
== 0)
2939 return builtin_type_void
;
2941 /* If n3 is zero and n2 is not, we want a floating type,
2942 and n2 is the width in bytes.
2944 Fortran programs appear to use this for complex types also,
2945 and they give no way to distinguish between double and single-complex!
2946 We don't have complex types, so we would lose on all fortran files!
2947 So return type `double' for all of those. It won't work right
2948 for the complex values, but at least it makes the file loadable.
2950 FIXME, we may be able to distinguish these by their names. FIXME. */
2952 if (n3
== 0 && n2
> 0)
2954 if (n2
== sizeof (float))
2955 return builtin_type_float
;
2956 return builtin_type_double
;
2959 /* If the upper bound is -1, it must really be an unsigned int. */
2961 else if (n2
== 0 && n3
== -1)
2963 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2964 long' is to look at its name! */
2966 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2967 long_kludge_name
[9] == 'l' /* long */)
2968 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2969 return builtin_type_unsigned_long
;
2971 return builtin_type_unsigned_int
;
2974 /* Special case: char is defined (Who knows why) as a subrange of
2975 itself with range 0-127. */
2976 else if (self_subrange
&& n2
== 0 && n3
== 127)
2977 return builtin_type_char
;
2979 /* Assumptions made here: Subrange of self is equivalent to subrange
2980 of int. FIXME: Host and target type-sizes assumed the same. */
2981 /* FIXME: This is the *only* place in GDB that depends on comparing
2982 some type to a builtin type with ==. Fix it! */
2984 && (self_subrange
||
2985 *dbx_lookup_type (rangenums
) == builtin_type_int
))
2987 /* an unsigned type */
2989 if (n3
== - sizeof (long long))
2990 return builtin_type_unsigned_long_long
;
2992 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2993 long' is to look at its name! */
2994 if (n3
== (unsigned long)~0L &&
2995 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2996 long_kludge_name
[9] == 'l' /* long */)
2997 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2998 return builtin_type_unsigned_long
;
2999 if (n3
== (unsigned int)~0L)
3000 return builtin_type_unsigned_int
;
3001 if (n3
== (unsigned short)~0L)
3002 return builtin_type_unsigned_short
;
3003 if (n3
== (unsigned char)~0L)
3004 return builtin_type_unsigned_char
;
3007 else if (n3
== 0 && n2
== -sizeof (long long))
3008 return builtin_type_long_long
;
3010 else if (n2
== -n3
-1)
3013 /* FIXME -- the only way to distinguish `int' from `long' is to look
3015 if ((n3
== (1 << (8 * sizeof (long) - 1)) - 1) &&
3016 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3017 return builtin_type_long
;
3018 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
3019 return builtin_type_int
;
3020 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
3021 return builtin_type_short
;
3022 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
3023 return builtin_type_char
;
3026 /* We have a real range type on our hands. Allocate space and
3027 return a real pointer. */
3029 /* At this point I don't have the faintest idea how to deal with
3030 a self_subrange type; I'm going to assume that this is used
3031 as an idiom, and that all of them are special cases. So . . . */
3033 return error_type (pp
);
3035 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
3036 sizeof (struct type
));
3037 bzero (result_type
, sizeof (struct type
));
3039 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3041 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3042 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3043 complain (&range_type_base_complaint
, rangenums
[1]);
3044 TYPE_TARGET_TYPE (result_type
) = builtin_type_int
;
3047 TYPE_NFIELDS (result_type
) = 2;
3048 TYPE_FIELDS (result_type
) =
3049 (struct field
*) obstack_alloc (symbol_obstack
,
3050 2 * sizeof (struct field
));
3051 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
3052 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3053 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3055 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3060 /* Read a number from the string pointed to by *PP.
3061 The value of *PP is advanced over the number.
3062 If END is nonzero, the character that ends the
3063 number must match END, or an error happens;
3064 and that character is skipped if it does match.
3065 If END is zero, *PP is left pointing to that character. */
3068 read_number (pp
, end
)
3072 register char *p
= *pp
;
3073 register long n
= 0;
3077 /* Handle an optional leading minus sign. */
3085 /* Read the digits, as far as they go. */
3087 while ((c
= *p
++) >= '0' && c
<= '9')
3095 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3104 /* Read in an argument list. This is a list of types, separated by commas
3105 and terminated with END. Return the list of types read in, or (struct type
3106 **)-1 if there is an error. */
3112 /* FIXME! Remove this arbitrary limit! */
3113 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3119 /* Invalid argument list: no ','. */
3120 return (struct type
**)-1;
3123 /* Check for and handle cretinous dbx symbol name continuation! */
3125 *pp
= next_symbol_text ();
3127 types
[n
++] = read_type (pp
);
3129 *pp
+= 1; /* get past `end' (the ':' character) */
3133 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3135 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3137 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3138 bzero (rval
+ n
, sizeof (struct type
*));
3142 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3144 bcopy (types
, rval
, n
* sizeof (struct type
*));
3148 /* Add a common block's start address to the offset of each symbol
3149 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3150 the common block name). */
3153 fix_common_block (sym
, valu
)
3157 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3158 for ( ; next
; next
= next
->next
)
3161 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3162 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3166 /* Initializer for this module */
3168 _initialize_buildsym ()
3170 undef_types_allocated
= 20;
3171 undef_types_length
= 0;
3172 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3173 sizeof (struct type
*));