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
< 0 || filenum
>= n_this_object_header_files
)
193 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
194 filenum
, index
, symnum
);
198 /* Type is defined outside of header files.
199 Find it in this object file's type vector. */
200 if (index
>= type_vector_length
)
202 old_len
= type_vector_length
;
204 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
205 type_vector
= (struct type
**)
206 malloc (type_vector_length
* sizeof (struct type
*));
208 while (index
>= type_vector_length
)
209 type_vector_length
*= 2;
210 type_vector
= (struct type
**)
211 xrealloc ((char *) type_vector
,
212 (type_vector_length
* sizeof (struct type
*)));
213 bzero (&type_vector
[old_len
],
214 (type_vector_length
- old_len
) * sizeof (struct type
*));
216 return &type_vector
[index
];
220 register int real_filenum
= this_object_header_files
[filenum
];
221 register struct header_file
*f
;
224 if (real_filenum
>= n_header_files
)
227 f
= &header_files
[real_filenum
];
229 f_orig_length
= f
->length
;
230 if (index
>= f_orig_length
)
232 while (index
>= f
->length
)
234 f
->vector
= (struct type
**)
235 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
236 bzero (&f
->vector
[f_orig_length
],
237 (f
->length
- f_orig_length
) * sizeof (struct type
*));
239 return &f
->vector
[index
];
243 /* Make sure there is a type allocated for type numbers TYPENUMS
244 and return the type object.
245 This can create an empty (zeroed) type object.
246 TYPENUMS may be (-1, -1) to return a new type object that is not
247 put into the type vector, and so may not be referred to by number. */
250 dbx_alloc_type (typenums
, objfile
)
252 struct objfile
*objfile
;
254 register struct type
**type_addr
;
255 register struct type
*type
;
257 if (typenums
[0] != -1)
259 type_addr
= dbx_lookup_type (typenums
);
268 /* If we are referring to a type not known at all yet,
269 allocate an empty type for it.
270 We will fill it in later if we find out how. */
273 type
= alloc_type (objfile
);
281 /* maintain the lists of symbols and blocks */
283 /* Add a symbol to one of the lists of symbols. */
285 add_symbol_to_list (symbol
, listhead
)
286 struct symbol
*symbol
;
287 struct pending
**listhead
;
289 /* We keep PENDINGSIZE symbols in each link of the list.
290 If we don't have a link with room in it, add a new link. */
291 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
293 register struct pending
*link
;
296 link
= free_pendings
;
297 free_pendings
= link
->next
;
300 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
302 link
->next
= *listhead
;
307 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
310 /* Find a symbol on a pending list. */
312 find_symbol_in_list (list
, name
, length
)
313 struct pending
*list
;
320 for (j
= list
->nsyms
; --j
>= 0; ) {
321 char *pp
= SYMBOL_NAME (list
->symbol
[j
]);
322 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 && pp
[length
] == '\0')
323 return list
->symbol
[j
];
330 /* At end of reading syms, or in case of quit,
331 really free as many `struct pending's as we can easily find. */
335 really_free_pendings (foo
)
338 struct pending
*next
, *next1
;
340 struct pending_block
*bnext
, *bnext1
;
343 for (next
= free_pendings
; next
; next
= next1
)
350 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
351 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
353 bnext1
= bnext
->next
;
359 for (next
= file_symbols
; next
; next
= next1
)
366 for (next
= global_symbols
; next
; next
= next1
)
374 /* Take one of the lists of symbols and make a block from it.
375 Keep the order the symbols have in the list (reversed from the input file).
376 Put the block on the list of pending blocks. */
379 finish_block (symbol
, listhead
, old_blocks
, start
, end
, objfile
)
380 struct symbol
*symbol
;
381 struct pending
**listhead
;
382 struct pending_block
*old_blocks
;
383 CORE_ADDR start
, end
;
384 struct objfile
*objfile
;
386 register struct pending
*next
, *next1
;
387 register struct block
*block
;
388 register struct pending_block
*pblock
;
389 struct pending_block
*opblock
;
392 /* Count the length of the list of symbols. */
394 for (next
= *listhead
, i
= 0;
396 i
+= next
->nsyms
, next
= next
->next
)
399 block
= (struct block
*) obstack_alloc (&objfile
-> symbol_obstack
,
400 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
402 /* Copy the symbols into the block. */
404 BLOCK_NSYMS (block
) = i
;
405 for (next
= *listhead
; next
; next
= next
->next
)
408 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
409 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
412 BLOCK_START (block
) = start
;
413 BLOCK_END (block
) = end
;
414 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
415 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
417 /* Put the block in as the value of the symbol that names it. */
421 SYMBOL_BLOCK_VALUE (symbol
) = block
;
422 BLOCK_FUNCTION (block
) = symbol
;
425 BLOCK_FUNCTION (block
) = 0;
427 /* Now "free" the links of the list, and empty the list. */
429 for (next
= *listhead
; next
; next
= next1
)
432 next
->next
= free_pendings
;
433 free_pendings
= next
;
437 /* Install this block as the superblock
438 of all blocks made since the start of this scope
439 that don't have superblocks yet. */
442 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
444 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
446 /* Check to be sure the blocks are nested as we receive them.
447 If the compiler/assembler/linker work, this just burns a small
449 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
450 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
451 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
453 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
454 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
457 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
462 /* Record this block on the list of all blocks in the file.
463 Put it after opblock, or at the beginning if opblock is 0.
464 This puts the block in the list after all its subblocks. */
466 /* Allocate in the symbol_obstack to save time.
467 It wastes a little space. */
468 pblock
= (struct pending_block
*)
469 obstack_alloc (&objfile
-> symbol_obstack
,
470 sizeof (struct pending_block
));
471 pblock
->block
= block
;
474 pblock
->next
= opblock
->next
;
475 opblock
->next
= pblock
;
479 pblock
->next
= pending_blocks
;
480 pending_blocks
= pblock
;
484 static struct blockvector
*
485 make_blockvector (objfile
)
486 struct objfile
*objfile
;
488 register struct pending_block
*next
;
489 register struct blockvector
*blockvector
;
492 /* Count the length of the list of blocks. */
494 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
496 blockvector
= (struct blockvector
*)
497 obstack_alloc (&objfile
-> symbol_obstack
,
498 (sizeof (struct blockvector
)
499 + (i
- 1) * sizeof (struct block
*)));
501 /* Copy the blocks into the blockvector.
502 This is done in reverse order, which happens to put
503 the blocks into the proper order (ascending starting address).
504 finish_block has hair to insert each block into the list
505 after its subblocks in order to make sure this is true. */
507 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
508 for (next
= pending_blocks
; next
; next
= next
->next
) {
509 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
512 #if 0 /* Now we make the links in the obstack, so don't free them. */
513 /* Now free the links of the list, and empty the list. */
515 for (next
= pending_blocks
; next
; next
= next1
)
523 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
524 /* Some compilers output blocks in the wrong order, but we depend
525 on their being in the right order so we can binary search.
526 Check the order and moan about it. FIXME. */
527 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
528 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
529 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
530 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
531 complain (&blockvector_complaint
,
532 (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
540 /* Start recording information about source code that came from an included
541 (or otherwise merged-in) source file with a different name. */
544 start_subfile (name
, dirname
)
548 register struct subfile
*subfile
;
550 /* See if this subfile is already known as a subfile of the
551 current main source file. */
553 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
555 if (!strcmp (subfile
->name
, name
))
557 current_subfile
= subfile
;
562 /* This subfile is not known. Add an entry for it.
563 Make an entry for this subfile in the list of all subfiles
564 of the current main source file. */
566 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
567 subfile
->next
= subfiles
;
569 current_subfile
= subfile
;
571 /* Save its name and compilation directory name */
572 subfile
->name
= strdup (name
);
574 subfile
->dirname
= NULL
;
576 subfile
->dirname
= strdup (dirname
);
578 /* Initialize line-number recording for this subfile. */
579 subfile
->line_vector
= 0;
582 /* Handle the N_BINCL and N_EINCL symbol types
583 that act like N_SOL for switching source files
584 (different subfiles, as we call them) within one object file,
585 but using a stack rather than in an arbitrary order. */
590 register struct subfile_stack
*tem
591 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
593 tem
->next
= subfile_stack
;
595 if (current_subfile
== 0 || current_subfile
->name
== 0)
597 tem
->name
= current_subfile
->name
;
598 tem
->prev_index
= header_file_prev_index
;
605 register struct subfile_stack
*link
= subfile_stack
;
611 subfile_stack
= link
->next
;
612 header_file_prev_index
= link
->prev_index
;
618 /* Manage the vector of line numbers for each subfile. */
621 record_line (subfile
, line
, pc
)
622 register struct subfile
*subfile
;
626 struct linetable_entry
*e
;
627 /* Ignore the dummy line number in libg.o */
632 /* Make sure line vector exists and is big enough. */
633 if (!subfile
->line_vector
) {
634 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
635 subfile
->line_vector
= (struct linetable
*)
636 xmalloc (sizeof (struct linetable
)
637 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
638 subfile
->line_vector
->nitems
= 0;
641 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
643 subfile
->line_vector_length
*= 2;
644 subfile
->line_vector
= (struct linetable
*)
645 xrealloc ((char *) subfile
->line_vector
, (sizeof (struct linetable
)
646 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
649 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
650 e
->line
= line
; e
->pc
= pc
;
654 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
657 compare_line_numbers (ln1p
, ln2p
)
661 return (((struct linetable_entry
*) ln1p
) -> line
-
662 ((struct linetable_entry
*) ln2p
) -> line
);
666 /* Start a new symtab for a new source file.
667 This is called when a dbx symbol of type N_SO is seen;
668 it indicates the start of data for one original source file. */
671 start_symtab (name
, dirname
, start_addr
)
674 CORE_ADDR start_addr
;
677 last_source_file
= name
;
678 last_source_start_addr
= start_addr
;
681 global_stabs
= 0; /* AIX COFF */
684 /* Context stack is initially empty. Allocate first one with room for
685 10 levels; reuse it forever afterward. */
686 if (context_stack
== 0) {
687 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
688 context_stack
= (struct context_stack
*)
689 xmalloc (context_stack_size
* sizeof (struct context_stack
));
691 context_stack_depth
= 0;
693 /* Leave FILENUM of 0 free for builtin types and this file's types. */
694 n_this_object_header_files
= 1;
695 header_file_prev_index
= -1;
697 type_vector_length
= 0;
698 type_vector
= (struct type
**) 0;
700 /* Initialize the list of sub source files with one entry
701 for this file (the top-level source file). */
705 start_subfile (name
, dirname
);
708 /* for all the stabs in a given stab vector, build appropriate types
709 and fix their symbols in given symbol vector. */
712 patch_block_stabs (symbols
, stabs
, objfile
)
713 struct pending
*symbols
;
714 struct pending_stabs
*stabs
;
715 struct objfile
*objfile
;
722 /* for all the stab entries, find their corresponding symbols and
723 patch their types! */
725 for (ii
= 0; ii
< stabs
->count
; ++ii
)
727 char *name
= stabs
->stab
[ii
];
728 char *pp
= (char*) strchr (name
, ':');
729 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
732 #ifndef IBM6000_TARGET
733 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
739 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
742 lookup_function_type (read_type (&pp
, objfile
));
746 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
753 /* Finish the symbol definitions for one main source file,
754 close off all the lexical contexts for that file
755 (creating struct block's for them), then make the struct symtab
756 for that file and put it in the list of all such.
758 END_ADDR is the address of the end of the file's text. */
761 end_symtab (end_addr
, sort_pending
, sort_linevec
, objfile
)
765 struct objfile
*objfile
;
767 register struct symtab
*symtab
;
768 register struct blockvector
*blockvector
;
769 register struct subfile
*subfile
;
770 struct subfile
*nextsub
;
772 /* Finish the lexical context of the last function in the file;
773 pop the context stack. */
775 if (context_stack_depth
> 0)
777 register struct context_stack
*cstk
;
778 context_stack_depth
--;
779 cstk
= &context_stack
[context_stack_depth
];
780 /* Make a block for the local symbols within. */
781 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
782 cstk
->start_addr
, end_addr
, objfile
);
784 /* Debug: if context stack still has something in it, we are in
786 if (context_stack_depth
> 0)
790 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
791 in this stage. Especially, blocks for static functions will show up at
792 the end. We need to sort them, so tools like `find_pc_function' and
793 `find_pc_block' can work reliably. */
794 if (sort_pending
&& pending_blocks
) {
795 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
798 struct pending_block
*pb
, *pbnext
;
800 pb
= pending_blocks
, pbnext
= pb
->next
;
805 /* swap blocks if unordered! */
807 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
)) {
808 struct block
*tmp
= pb
->block
;
809 pb
->block
= pbnext
->block
;
814 pbnext
= pbnext
->next
;
819 /* Cleanup any undefined types that have been left hanging around
820 (this needs to be done before the finish_blocks so that
821 file_symbols is still good). */
822 cleanup_undefined_types ();
825 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
826 free ((PTR
)global_stabs
);
830 if (pending_blocks
== 0
832 && global_symbols
== 0) {
833 /* Ignore symtabs that have no functions with real debugging info */
836 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
837 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
838 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
839 blockvector
= make_blockvector (objfile
);
842 #ifdef PROCESS_LINENUMBER_HOOK
843 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
846 /* Now create the symtab objects proper, one for each subfile. */
847 /* (The main file is the last one on the chain.) */
849 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
852 /* If we have blocks of symbols, make a symtab.
853 Otherwise, just ignore this file and any line number info in it. */
856 if (subfile
->line_vector
) {
857 /* First, shrink the linetable to make more memory. */
858 linetablesize
= sizeof (struct linetable
) +
859 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
860 subfile
->line_vector
= (struct linetable
*)
861 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
864 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
865 sizeof (struct linetable_entry
), compare_line_numbers
);
868 /* Now, allocate a symbol table. */
869 symtab
= allocate_symtab (subfile
->name
, objfile
);
871 /* Fill in its components. */
872 symtab
->blockvector
= blockvector
;
873 if (subfile
->line_vector
)
875 /* Reallocate the line table on the symbol obstack */
876 symtab
->linetable
= (struct linetable
*)
877 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
878 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
882 symtab
->linetable
= NULL
;
884 symtab
->dirname
= subfile
->dirname
;
885 symtab
->free_code
= free_linetable
;
886 symtab
->free_ptr
= 0;
888 #ifdef IBM6000_TARGET
889 /* In case we need to duplicate symbol tables (to represent include
890 files), and in case our system needs relocation, we want to
891 relocate the main symbol table node only (for the main file,
892 not for the include files). */
894 symtab
->nonreloc
= TRUE
;
897 if (subfile
->line_vector
)
898 free ((PTR
)subfile
->line_vector
);
900 nextsub
= subfile
->next
;
904 #ifdef IBM6000_TARGET
905 /* all include symbol tables are non-relocatable, except the main source
908 symtab
->nonreloc
= FALSE
;
912 free ((char *) type_vector
);
914 type_vector_length
= 0;
916 last_source_file
= 0;
918 previous_stab_code
= 0;
924 /* Push a context block. Args are an identifying nesting level (checkable
925 when you pop it), and the starting PC address of this context. */
927 struct context_stack
*
928 push_context (desc
, valu
)
932 register struct context_stack
*new;
934 if (context_stack_depth
== context_stack_size
)
936 context_stack_size
*= 2;
937 context_stack
= (struct context_stack
*)
938 xrealloc ((char *) context_stack
,
939 (context_stack_size
* sizeof (struct context_stack
)));
942 new = &context_stack
[context_stack_depth
++];
944 new->locals
= local_symbols
;
945 new->old_blocks
= pending_blocks
;
946 new->start_addr
= valu
;
954 /* Initialize anything that needs initializing when starting to read
955 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
967 /* Initialize anything that needs initializing when a completely new
968 symbol file is specified (not just adding some symbols from another
969 file, e.g. a shared library). */
974 /* Empty the hash table of global syms looking for values. */
975 bzero (global_sym_chain
, sizeof global_sym_chain
);
980 /* Scan through all of the global symbols defined in the object file,
981 assigning values to the debugging symbols that need to be assigned
982 to. Get these symbols from the minimal symbol table. */
985 scan_file_globals (objfile
)
986 struct objfile
*objfile
;
989 struct minimal_symbol
*msymbol
;
990 struct symbol
*sym
, *prev
;
992 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
996 prev
= (struct symbol
*) 0;
998 /* Get the hash index and check all the symbols
999 under that hash index. */
1001 hash
= hashname (msymbol
-> name
);
1003 for (sym
= global_sym_chain
[hash
]; sym
;)
1005 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
1006 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
1008 /* Splice this symbol out of the hash chain and
1009 assign the value we have to it. */
1011 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1013 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1015 /* Check to see whether we need to fix up a common block. */
1016 /* Note: this code might be executed several times for
1017 the same symbol if there are multiple references. */
1018 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1019 fix_common_block (sym
, msymbol
-> address
);
1021 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
1024 sym
= SYMBOL_VALUE_CHAIN (prev
);
1026 sym
= global_sym_chain
[hash
];
1031 sym
= SYMBOL_VALUE_CHAIN (sym
);
1038 /* Read a number by which a type is referred to in dbx data,
1039 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1040 Just a single number N is equivalent to (0,N).
1041 Return the two numbers by storing them in the vector TYPENUMS.
1042 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1045 read_type_number (pp
, typenums
)
1047 register int *typenums
;
1052 typenums
[0] = read_number (pp
, ',');
1053 typenums
[1] = read_number (pp
, ')');
1058 typenums
[1] = read_number (pp
, 0);
1062 /* To handle GNU C++ typename abbreviation, we need to be able to
1063 fill in a type's name as soon as space for that type is allocated.
1064 `type_synonym_name' is the name of the type being allocated.
1065 It is cleared as soon as it is used (lest all allocated types
1067 static char *type_synonym_name
;
1071 define_symbol (valu
, string
, desc
, type
, objfile
)
1076 struct objfile
*objfile
;
1078 register struct symbol
*sym
;
1079 char *p
= (char *) strchr (string
, ':');
1083 struct type
*temptype
;
1085 /* Ignore syms with empty names. */
1089 /* Ignore old-style symbols from cc -go */
1093 sym
= (struct symbol
*)obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1095 if (processing_gcc_compilation
) {
1096 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1097 number of bytes occupied by a type or object, which we ignore. */
1098 SYMBOL_LINE(sym
) = desc
;
1100 SYMBOL_LINE(sym
) = 0; /* unknown */
1103 if (string
[0] == CPLUS_MARKER
)
1105 /* Special GNU C++ names. */
1109 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1110 &objfile
-> symbol_obstack
);
1112 case 'v': /* $vtbl_ptr_type */
1113 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1116 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1117 &objfile
-> symbol_obstack
);
1121 /* This was an anonymous type that was never fixed up. */
1132 = (char *) obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1133 /* Open-coded bcopy--saves function call time. */
1135 register char *p1
= string
;
1136 register char *p2
= SYMBOL_NAME (sym
);
1143 /* Determine the type of name being defined. */
1144 /* The Acorn RISC machine's compiler can put out locals that don't
1145 start with "234=" or "(3,4)=", so assume anything other than the
1146 deftypes we know how to handle is a local. */
1147 /* (Peter Watkins @ Computervision)
1148 Handle Sun-style local fortran array types 'ar...' .
1149 (gnu@cygnus.com) -- this strchr() handles them properly?
1150 (tiemann@cygnus.com) -- 'C' is for catch. */
1151 if (!strchr ("cfFGpPrStTvVXC", *p
))
1156 /* c is a special case, not followed by a type-number.
1157 SYMBOL:c=iVALUE for an integer constant symbol.
1158 SYMBOL:c=rVALUE for a floating constant symbol.
1159 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1160 e.g. "b:c=e6,0" for "const b = blob1"
1161 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1165 error ("Invalid symbol data at symtab pos %d.", symnum
);
1170 double d
= atof (p
);
1173 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1176 obstack_alloc (&objfile
-> type_obstack
,
1178 memcpy (dbl_valu
, &d
, sizeof (double));
1179 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1180 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1181 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1186 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1188 SYMBOL_VALUE (sym
) = atoi (p
);
1189 SYMBOL_CLASS (sym
) = LOC_CONST
;
1193 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1194 e.g. "b:c=e6,0" for "const b = blob1"
1195 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1199 read_type_number (&p
, typenums
);
1201 error ("Invalid symbol data: no comma in enum const symbol");
1203 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1204 SYMBOL_VALUE (sym
) = atoi (p
);
1205 SYMBOL_CLASS (sym
) = LOC_CONST
;
1209 error ("Invalid symbol data at symtab pos %d.", symnum
);
1211 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1212 add_symbol_to_list (sym
, &file_symbols
);
1216 /* Now usually comes a number that says which data type,
1217 and possibly more stuff to define the type
1218 (all of which is handled by read_type) */
1220 if (deftype
== 'p' && *p
== 'F')
1221 /* pF is a two-letter code that means a function parameter in Fortran.
1222 The type-number specifies the type of the return value.
1223 Translate it into a pointer-to-function type. */
1227 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
1231 struct type
*type_read
;
1232 synonym
= *p
== 't';
1237 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1238 strlen (SYMBOL_NAME (sym
)),
1239 &objfile
-> symbol_obstack
);
1242 /* Here we save the name of the symbol for read_range_type, which
1243 ends up reading in the basic types. In stabs, unfortunately there
1244 is no distinction between "int" and "long" types except their
1245 names. Until we work out a saner type policy (eliminating most
1246 builtin types and using the names specified in the files), we
1247 save away the name so that far away from here in read_range_type,
1248 we can examine it to decide between "int" and "long". FIXME. */
1249 long_kludge_name
= SYMBOL_NAME (sym
);
1250 type_read
= read_type (&p
, objfile
);
1252 if ((deftype
== 'F' || deftype
== 'f')
1253 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
1256 /* This code doesn't work -- it needs to realloc and can't. */
1257 struct type
*new = (struct type
*)
1258 obstack_alloc (&objfile
-> type_obstack
,
1259 sizeof (struct type
));
1261 /* Generate a template for the type of this function. The
1262 types of the arguments will be added as we read the symbol
1264 *new = *lookup_function_type (type_read
);
1265 SYMBOL_TYPE(sym
) = new;
1266 TYPE_OBJFILE (new) = objfile
;
1267 in_function_type
= new;
1269 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
1273 SYMBOL_TYPE (sym
) = type_read
;
1279 /* The name of a caught exception. */
1280 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1281 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1282 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1283 add_symbol_to_list (sym
, &local_symbols
);
1287 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1288 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1289 add_symbol_to_list (sym
, &file_symbols
);
1293 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1294 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1295 add_symbol_to_list (sym
, &global_symbols
);
1299 /* For a class G (global) symbol, it appears that the
1300 value is not correct. It is necessary to search for the
1301 corresponding linker definition to find the value.
1302 These definitions appear at the end of the namelist. */
1303 i
= hashname (SYMBOL_NAME (sym
));
1304 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1305 global_sym_chain
[i
] = sym
;
1306 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1307 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1308 add_symbol_to_list (sym
, &global_symbols
);
1311 /* This case is faked by a conditional above,
1312 when there is no code letter in the dbx data.
1313 Dbx data never actually contains 'l'. */
1315 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1316 SYMBOL_VALUE (sym
) = valu
;
1317 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1318 add_symbol_to_list (sym
, &local_symbols
);
1322 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1323 can also be a LOC_LOCAL_ARG depending on symbol type. */
1324 #ifndef DBX_PARM_SYMBOL_CLASS
1325 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1327 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1328 SYMBOL_VALUE (sym
) = valu
;
1329 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1331 /* This doesn't work yet. */
1332 add_param_to_type (&in_function_type
, sym
);
1334 add_symbol_to_list (sym
, &local_symbols
);
1336 /* If it's gcc-compiled, if it says `short', believe it. */
1337 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1340 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1341 /* This macro is defined on machines (e.g. sparc) where
1342 we should believe the type of a PCC 'short' argument,
1343 but shouldn't believe the address (the address is
1344 the address of the corresponding int). Note that
1345 this is only different from the BELIEVE_PCC_PROMOTION
1346 case on big-endian machines.
1348 My guess is that this correction, as opposed to changing
1349 the parameter to an 'int' (as done below, for PCC
1350 on most machines), is the right thing to do
1351 on all machines, but I don't want to risk breaking
1352 something that already works. On most PCC machines,
1353 the sparc problem doesn't come up because the calling
1354 function has to zero the top bytes (not knowing whether
1355 the called function wants an int or a short), so there
1356 is no practical difference between an int and a short
1357 (except perhaps what happens when the GDB user types
1358 "print short_arg = 0x10000;").
1360 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1361 actually produces the correct address (we don't need to fix it
1362 up). I made this code adapt so that it will offset the symbol
1363 if it was pointing at an int-aligned location and not
1364 otherwise. This way you can use the same gdb for 4.0.x and
1367 If the parameter is shorter than an int, and is integral
1368 (e.g. char, short, or unsigned equivalent), and is claimed to
1369 be passed on an integer boundary, don't believe it! Offset the
1370 parameter's address to the tail-end of that integer. */
1372 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1373 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1374 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1375 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
1377 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
1378 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1382 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1384 /* If PCC says a parameter is a short or a char,
1385 it is really an int. */
1386 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1387 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1388 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1390 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1391 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
1396 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1399 /* Parameter which is in a register. */
1400 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1401 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1402 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1404 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1405 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1407 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1408 add_symbol_to_list (sym
, &local_symbols
);
1412 /* Register variable (either global or local). */
1413 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1414 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1415 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1417 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1418 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1420 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1421 if (within_function
)
1422 add_symbol_to_list (sym
, &local_symbols
);
1424 add_symbol_to_list (sym
, &file_symbols
);
1428 /* Static symbol at top level of file */
1429 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1430 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1431 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1432 add_symbol_to_list (sym
, &file_symbols
);
1436 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1437 SYMBOL_VALUE (sym
) = valu
;
1438 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1439 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1440 TYPE_NAME (SYMBOL_TYPE (sym
)) =
1441 obsavestring (SYMBOL_NAME (sym
),
1442 strlen (SYMBOL_NAME (sym
)),
1443 &objfile
-> symbol_obstack
);
1444 /* C++ vagaries: we may have a type which is derived from
1445 a base type which did not have its name defined when the
1446 derived class was output. We fill in the derived class's
1447 base part member's name here in that case. */
1448 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1449 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1450 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1453 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1454 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1455 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1456 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1459 add_symbol_to_list (sym
, &file_symbols
);
1463 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1464 SYMBOL_VALUE (sym
) = valu
;
1465 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1466 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1467 TYPE_NAME (SYMBOL_TYPE (sym
))
1468 = obconcat (&objfile
-> type_obstack
, "",
1469 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1471 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1472 ? "struct " : "union ")),
1474 add_symbol_to_list (sym
, &file_symbols
);
1478 register struct symbol
*typedef_sym
= (struct symbol
*)
1479 obstack_alloc (&objfile
-> type_obstack
,
1480 sizeof (struct symbol
));
1481 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1482 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1484 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1485 SYMBOL_VALUE (typedef_sym
) = valu
;
1486 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1487 add_symbol_to_list (typedef_sym
, &file_symbols
);
1492 /* Static symbol of local scope */
1493 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1494 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1495 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1496 add_symbol_to_list (sym
, &local_symbols
);
1500 /* Reference parameter */
1501 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1502 SYMBOL_VALUE (sym
) = valu
;
1503 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1504 add_symbol_to_list (sym
, &local_symbols
);
1508 /* This is used by Sun FORTRAN for "function result value".
1509 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1510 that Pascal uses it too, but when I tried it Pascal used
1511 "x:3" (local symbol) instead. */
1512 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1513 SYMBOL_VALUE (sym
) = valu
;
1514 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1515 add_symbol_to_list (sym
, &local_symbols
);
1519 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1524 /* What about types defined as forward references inside of a small lexical
1526 /* Add a type to the list of undefined types to be checked through
1527 once this file has been read in. */
1529 add_undefined_type (type
)
1532 if (undef_types_length
== undef_types_allocated
)
1534 undef_types_allocated
*= 2;
1535 undef_types
= (struct type
**)
1536 xrealloc ((char *) undef_types
,
1537 undef_types_allocated
* sizeof (struct type
*));
1539 undef_types
[undef_types_length
++] = type
;
1542 /* Go through each undefined type, see if it's still undefined, and fix it
1543 up if possible. We have two kinds of undefined types:
1545 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1546 Fix: update array length using the element bounds
1547 and the target type's length.
1548 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1549 yet defined at the time a pointer to it was made.
1550 Fix: Do a full lookup on the struct/union tag. */
1552 cleanup_undefined_types ()
1556 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1557 switch (TYPE_CODE (*type
)) {
1559 case TYPE_CODE_STRUCT
:
1560 case TYPE_CODE_UNION
:
1561 case TYPE_CODE_ENUM
:
1563 /* Reasonable test to see if it's been defined since. */
1564 if (TYPE_NFIELDS (*type
) == 0)
1566 struct pending
*ppt
;
1568 /* Name of the type, without "struct" or "union" */
1569 char *typename
= TYPE_NAME (*type
);
1571 if (!strncmp (typename
, "struct ", 7))
1573 if (!strncmp (typename
, "union ", 6))
1575 if (!strncmp (typename
, "enum ", 5))
1578 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1579 for (i
= 0; i
< ppt
->nsyms
; i
++)
1581 struct symbol
*sym
= ppt
->symbol
[i
];
1583 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1584 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1585 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1587 && !strcmp (SYMBOL_NAME (sym
), typename
))
1588 memcpy (*type
, SYMBOL_TYPE (sym
), sizeof (struct type
));
1592 /* It has been defined; don't mark it as a stub. */
1593 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1597 case TYPE_CODE_ARRAY
:
1599 struct type
*range_type
;
1602 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1604 if (TYPE_NFIELDS (*type
) != 1)
1606 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1607 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1610 /* Now recompute the length of the array type, based on its
1611 number of elements and the target type's length. */
1612 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1613 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1614 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1615 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1621 error ("GDB internal error. cleanup_undefined_types with bad\
1622 type %d.", TYPE_CODE (*type
));
1626 undef_types_length
= 0;
1629 /* Skip rest of this symbol and return an error type.
1631 General notes on error recovery: error_type always skips to the
1632 end of the symbol (modulo cretinous dbx symbol name continuation).
1633 Thus code like this:
1635 if (*(*pp)++ != ';')
1636 return error_type (pp);
1638 is wrong because if *pp starts out pointing at '\0' (typically as the
1639 result of an earlier error), it will be incremented to point to the
1640 start of the next symbol, which might produce strange results, at least
1641 if you run off the end of the string table. Instead use
1644 return error_type (pp);
1650 foo = error_type (pp);
1654 And in case it isn't obvious, the point of all this hair is so the compiler
1655 can define new types and new syntaxes, and old versions of the
1656 debugger will be able to read the new symbol tables. */
1662 complain (&error_type_complaint
, 0);
1665 /* Skip to end of symbol. */
1666 while (**pp
!= '\0')
1669 /* Check for and handle cretinous dbx symbol name continuation! */
1670 if ((*pp
)[-1] == '\\')
1671 *pp
= next_symbol_text ();
1675 return builtin_type_error
;
1678 /* Read a dbx type reference or definition;
1679 return the type that is meant.
1680 This can be just a number, in which case it references
1681 a type already defined and placed in type_vector.
1682 Or the number can be followed by an =, in which case
1683 it means to define a new type according to the text that
1687 read_type (pp
, objfile
)
1689 struct objfile
*objfile
;
1691 register struct type
*type
= 0;
1696 /* Read type number if present. The type number may be omitted.
1697 for instance in a two-dimensional array declared with type
1698 "ar1;1;10;ar1;1;10;4". */
1699 if ((**pp
>= '0' && **pp
<= '9')
1702 read_type_number (pp
, typenums
);
1704 /* Type is not being defined here. Either it already exists,
1705 or this is a forward reference to it. dbx_alloc_type handles
1708 return dbx_alloc_type (typenums
, objfile
);
1710 /* Type is being defined here. */
1711 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1715 /* if such a type already exists, this is an unnecessary duplication
1716 of the stab string, which is common in (RS/6000) xlc generated
1717 objects. In that case, simply return NULL and let the caller take
1720 tt
= *dbx_lookup_type (typenums
);
1721 if (tt
&& tt
->length
&& tt
->code
)
1730 /* 'typenums=' not present, type is anonymous. Read and return
1731 the definition, but don't put it in the type vector. */
1732 typenums
[0] = typenums
[1] = -1;
1740 enum type_code code
;
1742 /* Used to index through file_symbols. */
1743 struct pending
*ppt
;
1746 /* Name including "struct", etc. */
1749 /* Name without "struct", etc. */
1750 char *type_name_only
;
1756 /* Set the type code according to the following letter. */
1760 code
= TYPE_CODE_STRUCT
;
1764 code
= TYPE_CODE_UNION
;
1768 code
= TYPE_CODE_ENUM
;
1772 return error_type (pp
);
1775 to
= type_name
= (char *)
1776 obstack_alloc (&objfile
-> type_obstack
,
1778 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1780 /* Copy the prefix. */
1782 while (*to
++ = *from
++)
1786 type_name_only
= to
;
1788 /* Copy the name. */
1790 while ((*to
++ = *from
++) != ':')
1794 /* Set the pointer ahead of the name which we just read. */
1798 /* The following hack is clearly wrong, because it doesn't
1799 check whether we are in a baseclass. I tried to reproduce
1800 the case that it is trying to fix, but I couldn't get
1801 g++ to put out a cross reference to a basetype. Perhaps
1802 it doesn't do it anymore. */
1803 /* Note: for C++, the cross reference may be to a base type which
1804 has not yet been seen. In this case, we skip to the comma,
1805 which will mark the end of the base class name. (The ':'
1806 at the end of the base class name will be skipped as well.)
1807 But sometimes (ie. when the cross ref is the last thing on
1808 the line) there will be no ','. */
1809 from
= (char *) strchr (*pp
, ',');
1815 /* Now check to see whether the type has already been declared. */
1816 /* This is necessary at least in the case where the
1817 program says something like
1819 The compiler puts out a cross-reference; we better find
1820 set the length of the structure correctly so we can
1821 set the length of the array. */
1822 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1823 for (i
= 0; i
< ppt
->nsyms
; i
++)
1825 struct symbol
*sym
= ppt
->symbol
[i
];
1827 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1828 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1829 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1830 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1832 obstack_free (&objfile
-> type_obstack
, type_name
);
1833 type
= SYMBOL_TYPE (sym
);
1838 /* Didn't find the type to which this refers, so we must
1839 be dealing with a forward reference. Allocate a type
1840 structure for it, and keep track of it so we can
1841 fill in the rest of the fields when we get the full
1843 type
= dbx_alloc_type (typenums
, objfile
);
1844 TYPE_CODE (type
) = code
;
1845 TYPE_NAME (type
) = type_name
;
1846 INIT_CPLUS_SPECIFIC(type
);
1847 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1849 add_undefined_type (type
);
1853 case '-': /* RS/6000 built-in type */
1855 type
= builtin_type (pp
); /* (in xcoffread.c) */
1870 read_type_number (pp
, xtypenums
);
1871 type
= *dbx_lookup_type (xtypenums
);
1876 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1877 if (typenums
[0] != -1)
1878 *dbx_lookup_type (typenums
) = type
;
1882 type1
= read_type (pp
, objfile
);
1883 /* FIXME -- we should be doing smash_to_XXX types here. */
1884 #ifdef IBM6000_TARGET
1885 /* postponed type decoration should be allowed. */
1886 if (typenums
[1] > 0 && typenums
[1] < type_vector_length
&&
1887 (type
= type_vector
[typenums
[1]])) {
1888 smash_to_pointer_type (type
, type1
);
1892 type
= lookup_pointer_type (type1
);
1893 if (typenums
[0] != -1)
1894 *dbx_lookup_type (typenums
) = type
;
1899 struct type
*domain
= read_type (pp
, objfile
);
1900 struct type
*memtype
;
1903 /* Invalid member type data format. */
1904 return error_type (pp
);
1907 memtype
= read_type (pp
, objfile
);
1908 type
= dbx_alloc_type (typenums
, objfile
);
1909 smash_to_member_type (type
, domain
, memtype
);
1914 if ((*pp
)[0] == '#')
1916 /* We'll get the parameter types from the name. */
1917 struct type
*return_type
;
1920 return_type
= read_type (pp
, objfile
);
1921 if (*(*pp
)++ != ';')
1922 complain (&invalid_member_complaint
, (char *) symnum
);
1923 type
= allocate_stub_method (return_type
);
1924 if (typenums
[0] != -1)
1925 *dbx_lookup_type (typenums
) = type
;
1929 struct type
*domain
= read_type (pp
, objfile
);
1930 struct type
*return_type
;
1933 if (*(*pp
)++ != ',')
1934 error ("invalid member type data format, at symtab pos %d.",
1937 return_type
= read_type (pp
, objfile
);
1938 args
= read_args (pp
, ';', objfile
);
1939 type
= dbx_alloc_type (typenums
, objfile
);
1940 smash_to_method_type (type
, domain
, return_type
, args
);
1945 type1
= read_type (pp
, objfile
);
1946 type
= lookup_reference_type (type1
);
1947 if (typenums
[0] != -1)
1948 *dbx_lookup_type (typenums
) = type
;
1952 type1
= read_type (pp
, objfile
);
1953 type
= lookup_function_type (type1
);
1954 if (typenums
[0] != -1)
1955 *dbx_lookup_type (typenums
) = type
;
1959 type
= read_range_type (pp
, typenums
, objfile
);
1960 if (typenums
[0] != -1)
1961 *dbx_lookup_type (typenums
) = type
;
1965 type
= dbx_alloc_type (typenums
, objfile
);
1966 type
= read_enum_type (pp
, type
, objfile
);
1967 *dbx_lookup_type (typenums
) = type
;
1971 type
= dbx_alloc_type (typenums
, objfile
);
1972 if (!TYPE_NAME (type
))
1973 TYPE_NAME (type
) = type_synonym_name
;
1974 type_synonym_name
= 0;
1975 type
= read_struct_type (pp
, type
, objfile
);
1979 type
= dbx_alloc_type (typenums
, objfile
);
1980 if (!TYPE_NAME (type
))
1981 TYPE_NAME (type
) = type_synonym_name
;
1982 type_synonym_name
= 0;
1983 type
= read_struct_type (pp
, type
, objfile
);
1984 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1989 return error_type (pp
);
1992 type
= dbx_alloc_type (typenums
, objfile
);
1993 type
= read_array_type (pp
, type
, objfile
);
1997 --*pp
; /* Go back to the symbol in error */
1998 /* Particularly important if it was \0! */
1999 return error_type (pp
);
2006 /* If this is an overriding temporary alteration for a header file's
2007 contents, and this type number is unknown in the global definition,
2008 put this type into the global definition at this type number. */
2009 if (header_file_prev_index
>= 0)
2011 register struct type
**tp
2012 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
2020 /* This page contains subroutines of read_type. */
2022 /* Read the description of a structure (or union type)
2023 and return an object describing the type. */
2025 static struct type
*
2026 read_struct_type (pp
, type
, objfile
)
2028 register struct type
*type
;
2029 struct objfile
*objfile
;
2031 /* Total number of methods defined in this class.
2032 If the class defines two `f' methods, and one `g' method,
2033 then this will have the value 3. */
2034 int total_length
= 0;
2038 struct nextfield
*next
;
2039 int visibility
; /* 0=public, 1=protected, 2=public */
2045 struct next_fnfield
*next
;
2046 struct fn_field fn_field
;
2049 struct next_fnfieldlist
2051 struct next_fnfieldlist
*next
;
2052 struct fn_fieldlist fn_fieldlist
;
2055 register struct nextfield
*list
= 0;
2056 struct nextfield
*new;
2059 int non_public_fields
= 0;
2062 register struct next_fnfieldlist
*mainlist
= 0;
2065 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2066 INIT_CPLUS_SPECIFIC(type
);
2068 /* First comes the total size in bytes. */
2070 TYPE_LENGTH (type
) = read_number (pp
, 0);
2072 /* C++: Now, if the class is a derived class, then the next character
2073 will be a '!', followed by the number of base classes derived from.
2074 Each element in the list contains visibility information,
2075 the offset of this base class in the derived structure,
2076 and then the base type. */
2079 int i
, n_baseclasses
, offset
;
2080 struct type
*baseclass
;
2083 /* Nonzero if it is a virtual baseclass, i.e.,
2087 struct C : public B, public virtual A {};
2089 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2090 2.0 language feature. */
2095 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
2097 n_baseclasses
= read_number (pp
, ',');
2098 TYPE_FIELD_VIRTUAL_BITS (type
) =
2099 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2100 B_BYTES (n_baseclasses
));
2101 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
2103 for (i
= 0; i
< n_baseclasses
; i
++)
2106 *pp
= next_symbol_text ();
2117 /* Bad visibility format. */
2118 return error_type (pp
);
2126 non_public_fields
++;
2132 /* Bad visibility format. */
2133 return error_type (pp
);
2136 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2139 /* Offset of the portion of the object corresponding to
2140 this baseclass. Always zero in the absence of
2141 multiple inheritance. */
2142 offset
= read_number (pp
, ',');
2143 baseclass
= read_type (pp
, objfile
);
2144 *pp
+= 1; /* skip trailing ';' */
2146 /* Make this baseclass visible for structure-printing purposes. */
2147 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2150 list
->visibility
= via_public
;
2151 list
->field
.type
= baseclass
;
2152 list
->field
.name
= type_name_no_tag (baseclass
);
2153 list
->field
.bitpos
= offset
;
2154 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2157 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
2160 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2161 At the end, we see a semicolon instead of a field.
2163 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2166 The `?' is a placeholder for one of '/2' (public visibility),
2167 '/1' (protected visibility), '/0' (private visibility), or nothing
2168 (C style symbol table, public visibility). */
2170 /* We better set p right now, in case there are no fields at all... */
2175 /* Check for and handle cretinous dbx symbol name continuation! */
2176 if (**pp
== '\\') *pp
= next_symbol_text ();
2178 /* Get space to record the next field's data. */
2179 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2183 /* Get the field name. */
2185 if (*p
== CPLUS_MARKER
)
2187 /* Special GNU C++ name. */
2192 struct type
*context
;
2203 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2204 prefix
= "INVALID_C++_ABBREV";
2208 context
= read_type (pp
, objfile
);
2209 name
= type_name_no_tag (context
);
2212 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
2213 TYPE_NAME (context
) = name
;
2215 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
2219 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2220 list
->field
.type
= read_type (pp
, objfile
);
2221 (*pp
)++; /* Skip the comma. */
2222 list
->field
.bitpos
= read_number (pp
, ';');
2223 /* This field is unpacked. */
2224 list
->field
.bitsize
= 0;
2225 list
->visibility
= 0; /* private */
2226 non_public_fields
++;
2228 /* GNU C++ anonymous type. */
2232 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2238 while (*p
!= ':') p
++;
2239 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
2240 &objfile
-> type_obstack
);
2242 /* C++: Check to see if we have hit the methods yet. */
2248 /* This means we have a visibility for a field coming. */
2254 list
->visibility
= 0; /* private */
2255 non_public_fields
++;
2260 list
->visibility
= 1; /* protected */
2261 non_public_fields
++;
2266 list
->visibility
= 2; /* public */
2271 else /* normal dbx-style format. */
2272 list
->visibility
= 2; /* public */
2274 list
->field
.type
= read_type (pp
, objfile
);
2277 /* Static class member. */
2278 list
->field
.bitpos
= (long)-1;
2280 while (*p
!= ';') p
++;
2281 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2286 else if (**pp
!= ',')
2287 /* Bad structure-type format. */
2288 return error_type (pp
);
2290 (*pp
)++; /* Skip the comma. */
2291 list
->field
.bitpos
= read_number (pp
, ',');
2292 list
->field
.bitsize
= read_number (pp
, ';');
2295 /* FIXME-tiemann: Can't the compiler put out something which
2296 lets us distinguish these? (or maybe just not put out anything
2297 for the field). What is the story here? What does the compiler
2298 really do? Also, patch gdb.texinfo for this case; I document
2299 it as a possible problem there. Search for "DBX-style". */
2301 /* This is wrong because this is identical to the symbols
2302 produced for GCC 0-size arrays. For example:
2307 The code which dumped core in such circumstances should be
2308 fixed not to dump core. */
2310 /* g++ -g0 can put out bitpos & bitsize zero for a static
2311 field. This does not give us any way of getting its
2312 class, so we can't know its name. But we can just
2313 ignore the field so we don't dump core and other nasty
2315 if (list
->field
.bitpos
== 0
2316 && list
->field
.bitsize
== 0)
2318 complain (&dbx_class_complaint
, 0);
2319 /* Ignore this field. */
2325 /* Detect an unpacked field and mark it as such.
2326 dbx gives a bit size for all fields.
2327 Note that forward refs cannot be packed,
2328 and treat enums as if they had the width of ints. */
2329 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2330 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2331 list
->field
.bitsize
= 0;
2332 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2333 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2334 && (list
->field
.bitsize
2335 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
2339 list
->field
.bitpos
% 8 == 0)
2340 list
->field
.bitsize
= 0;
2346 /* chill the list of fields: the last entry (at the head)
2347 is a partially constructed entry which we now scrub. */
2350 /* Now create the vector of fields, and record how big it is.
2351 We need this info to record proper virtual function table information
2352 for this class's virtual functions. */
2354 TYPE_NFIELDS (type
) = nfields
;
2355 TYPE_FIELDS (type
) = (struct field
*)
2356 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
2358 if (non_public_fields
)
2360 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2362 TYPE_FIELD_PRIVATE_BITS (type
) =
2363 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2365 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2367 TYPE_FIELD_PROTECTED_BITS (type
) =
2368 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2370 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2373 /* Copy the saved-up fields into the field vector. */
2375 for (n
= nfields
; list
; list
= list
->next
)
2378 TYPE_FIELD (type
, n
) = list
->field
;
2379 if (list
->visibility
== 0)
2380 SET_TYPE_FIELD_PRIVATE (type
, n
);
2381 else if (list
->visibility
== 1)
2382 SET_TYPE_FIELD_PROTECTED (type
, n
);
2385 /* Now come the method fields, as NAME::methods
2386 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2387 At the end, we see a semicolon instead of a field.
2389 For the case of overloaded operators, the format is
2390 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2391 `*' holds the place for an operator name (such as `+=')
2392 and `.' marks the end of the operator name. */
2395 /* Now, read in the methods. To simplify matters, we
2396 "unread" the name that has been read, so that we can
2397 start from the top. */
2399 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2400 /* For each list of method lists... */
2404 struct next_fnfield
*sublist
= 0;
2405 struct type
*look_ahead_type
= NULL
;
2407 struct next_fnfieldlist
*new_mainlist
=
2408 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2413 /* read in the name. */
2414 while (*p
!= ':') p
++;
2415 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2417 /* This is a completely wierd case. In order to stuff in the
2418 names that might contain colons (the usual name delimiter),
2419 Mike Tiemann defined a different name format which is
2420 signalled if the identifier is "op$". In that case, the
2421 format is "op$::XXXX." where XXXX is the name. This is
2422 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2423 /* This lets the user type "break operator+".
2424 We could just put in "+" as the name, but that wouldn't
2426 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2427 char *o
= opname
+ 3;
2429 /* Skip past '::'. */
2431 if (**pp
== '\\') *pp
= next_symbol_text ();
2435 main_fn_name
= savestring (opname
, o
- opname
);
2441 main_fn_name
= savestring (*pp
, p
- *pp
);
2442 /* Skip past '::'. */
2445 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2449 struct next_fnfield
*new_sublist
=
2450 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2452 /* Check for and handle cretinous dbx symbol name continuation! */
2453 if (look_ahead_type
== NULL
) /* Normal case. */
2455 if (**pp
== '\\') *pp
= next_symbol_text ();
2457 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2459 /* Invalid symtab info for method. */
2460 return error_type (pp
);
2463 { /* g++ version 1 kludge */
2464 new_sublist
->fn_field
.type
= look_ahead_type
;
2465 look_ahead_type
= NULL
;
2470 while (*p
!= ';') p
++;
2472 /* If this is just a stub, then we don't have the
2474 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
2475 new_sublist
->fn_field
.is_stub
= 1;
2476 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2479 /* Set this method's visibility fields. */
2480 switch (*(*pp
)++ - '0')
2483 new_sublist
->fn_field
.is_private
= 1;
2486 new_sublist
->fn_field
.is_protected
= 1;
2490 if (**pp
== '\\') *pp
= next_symbol_text ();
2493 case 'A': /* Normal functions. */
2494 new_sublist
->fn_field
.is_const
= 0;
2495 new_sublist
->fn_field
.is_volatile
= 0;
2498 case 'B': /* `const' member functions. */
2499 new_sublist
->fn_field
.is_const
= 1;
2500 new_sublist
->fn_field
.is_volatile
= 0;
2503 case 'C': /* `volatile' member function. */
2504 new_sublist
->fn_field
.is_const
= 0;
2505 new_sublist
->fn_field
.is_volatile
= 1;
2508 case 'D': /* `const volatile' member function. */
2509 new_sublist
->fn_field
.is_const
= 1;
2510 new_sublist
->fn_field
.is_volatile
= 1;
2513 case '*': /* File compiled with g++ version 1 -- no info */
2518 complain (&const_vol_complaint
, (char *) (long) **pp
);
2525 /* virtual member function, followed by index. */
2526 /* The sign bit is set to distinguish pointers-to-methods
2527 from virtual function indicies. Since the array is
2528 in words, the quantity must be shifted left by 1
2529 on 16 bit machine, and by 2 on 32 bit machine, forcing
2530 the sign bit out, and usable as a valid index into
2531 the array. Remove the sign bit here. */
2532 new_sublist
->fn_field
.voffset
=
2533 (0x7fffffff & read_number (pp
, ';')) + 2;
2535 if (**pp
== '\\') *pp
= next_symbol_text ();
2537 if (**pp
== ';' || **pp
== '\0')
2538 /* Must be g++ version 1. */
2539 new_sublist
->fn_field
.fcontext
= 0;
2542 /* Figure out from whence this virtual function came.
2543 It may belong to virtual function table of
2544 one of its baseclasses. */
2545 look_ahead_type
= read_type (pp
, objfile
);
2547 { /* g++ version 1 overloaded methods. */ }
2550 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2552 return error_type (pp
);
2555 look_ahead_type
= NULL
;
2561 /* static member function. */
2562 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2563 if (strncmp (new_sublist
->fn_field
.physname
,
2564 main_fn_name
, strlen (main_fn_name
)))
2565 new_sublist
->fn_field
.is_stub
= 1;
2570 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
2571 /* Fall through into normal member function. */
2574 /* normal member function. */
2575 new_sublist
->fn_field
.voffset
= 0;
2576 new_sublist
->fn_field
.fcontext
= 0;
2580 new_sublist
->next
= sublist
;
2581 sublist
= new_sublist
;
2583 if (**pp
== '\\') *pp
= next_symbol_text ();
2585 while (**pp
!= ';' && **pp
!= '\0');
2589 new_mainlist
->fn_fieldlist
.fn_fields
=
2590 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
2591 sizeof (struct fn_field
) * length
);
2592 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2593 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2595 new_mainlist
->fn_fieldlist
.length
= length
;
2596 new_mainlist
->next
= mainlist
;
2597 mainlist
= new_mainlist
;
2599 total_length
+= length
;
2600 if (**pp
== '\\') *pp
= next_symbol_text ();
2602 while (**pp
!= ';');
2610 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2611 obstack_alloc (&objfile
-> type_obstack
,
2612 sizeof (struct fn_fieldlist
) * nfn_fields
);
2613 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2614 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2619 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2620 TYPE_NFN_FIELDS_TOTAL (type
) +=
2621 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2624 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
2625 --n
; /* Circumvent Sun3 compiler bug */
2626 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
2633 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2635 /* Obsolete flags that used to indicate the presence
2636 of constructors and/or destructors. */
2640 /* Read either a '%' or the final ';'. */
2641 if (*(*pp
)++ == '%')
2643 /* We'd like to be able to derive the vtable pointer field
2644 from the type information, but when it's inherited, that's
2645 hard. A reason it's hard is because we may read in the
2646 info about a derived class before we read in info about
2647 the base class that provides the vtable pointer field.
2648 Once the base info has been read, we could fill in the info
2649 for the derived classes, but for the fact that by then,
2650 we don't remember who needs what. */
2653 int predicted_fieldno
= -1;
2656 /* Now we must record the virtual function table pointer's
2657 field information. */
2665 /* In version 2, we derive the vfield ourselves. */
2666 for (n
= 0; n
< nfields
; n
++)
2668 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2669 sizeof (vptr_name
) -1))
2671 predicted_fieldno
= n
;
2675 if (predicted_fieldno
< 0)
2676 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2677 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2678 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2680 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2686 t
= read_type (pp
, objfile
);
2688 while (*p
!= '\0' && *p
!= ';')
2691 /* Premature end of symbol. */
2692 return error_type (pp
);
2694 TYPE_VPTR_BASETYPE (type
) = t
;
2697 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2699 /* FIXME-tiemann: what's this? */
2701 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2706 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2707 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2708 sizeof (vptr_name
) -1))
2710 TYPE_VPTR_FIELDNO (type
) = i
;
2714 /* Virtual function table field not found. */
2715 return error_type (pp
);
2718 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2721 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2722 error ("TYPE_VPTR_FIELDNO miscalculated");
2732 /* Read a definition of an array type,
2733 and create and return a suitable type object.
2734 Also creates a range type which represents the bounds of that
2736 static struct type
*
2737 read_array_type (pp
, type
, objfile
)
2739 register struct type
*type
;
2740 struct objfile
*objfile
;
2742 struct type
*index_type
, *element_type
, *range_type
;
2746 /* Format of an array type:
2747 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2750 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2751 for these, produce a type like float[][]. */
2753 index_type
= read_type (pp
, objfile
);
2755 /* Improper format of array type decl. */
2756 return error_type (pp
);
2759 if (!(**pp
>= '0' && **pp
<= '9'))
2764 lower
= read_number (pp
, ';');
2766 if (!(**pp
>= '0' && **pp
<= '9'))
2771 upper
= read_number (pp
, ';');
2773 element_type
= read_type (pp
, objfile
);
2782 /* Create range type. */
2783 range_type
= (struct type
*)
2784 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2785 bzero (range_type
, sizeof (struct type
));
2786 TYPE_OBJFILE (range_type
) = objfile
;
2787 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2788 TYPE_TARGET_TYPE (range_type
) = index_type
;
2790 /* This should never be needed. */
2791 TYPE_LENGTH (range_type
) = sizeof (int);
2793 TYPE_NFIELDS (range_type
) = 2;
2794 TYPE_FIELDS (range_type
) =
2795 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2796 2 * sizeof (struct field
));
2797 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2798 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2801 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2802 TYPE_TARGET_TYPE (type
) = element_type
;
2803 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2804 TYPE_NFIELDS (type
) = 1;
2805 TYPE_FIELDS (type
) =
2806 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2807 sizeof (struct field
));
2808 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2810 /* If we have an array whose element type is not yet known, but whose
2811 bounds *are* known, record it to be adjusted at the end of the file. */
2812 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2813 add_undefined_type (type
);
2819 /* Read a definition of an enumeration type,
2820 and create and return a suitable type object.
2821 Also defines the symbols that represent the values of the type. */
2823 static struct type
*
2824 read_enum_type (pp
, type
, objfile
)
2826 register struct type
*type
;
2827 struct objfile
*objfile
;
2832 register struct symbol
*sym
;
2834 struct pending
**symlist
;
2835 struct pending
*osyms
, *syms
;
2838 if (within_function
)
2839 symlist
= &local_symbols
;
2841 symlist
= &file_symbols
;
2843 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2845 /* Read the value-names and their values.
2846 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2847 A semicolon or comma instead of a NAME means the end. */
2848 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2850 /* Check for and handle cretinous dbx symbol name continuation! */
2851 if (**pp
== '\\') *pp
= next_symbol_text ();
2854 while (*p
!= ':') p
++;
2855 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2857 n
= read_number (pp
, ',');
2859 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2860 bzero (sym
, sizeof (struct symbol
));
2861 SYMBOL_NAME (sym
) = name
;
2862 SYMBOL_CLASS (sym
) = LOC_CONST
;
2863 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2864 SYMBOL_VALUE (sym
) = n
;
2865 add_symbol_to_list (sym
, symlist
);
2870 (*pp
)++; /* Skip the semicolon. */
2872 /* Now fill in the fields of the type-structure. */
2874 TYPE_LENGTH (type
) = sizeof (int);
2875 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2876 TYPE_NFIELDS (type
) = nsyms
;
2877 TYPE_FIELDS (type
) = (struct field
*)
2878 obstack_alloc (&objfile
-> type_obstack
,
2879 sizeof (struct field
) * nsyms
);
2881 /* Find the symbols for the values and put them into the type.
2882 The symbols can be found in the symlist that we put them on
2883 to cause them to be defined. osyms contains the old value
2884 of that symlist; everything up to there was defined by us. */
2885 /* Note that we preserve the order of the enum constants, so
2886 that in something like "enum {FOO, LAST_THING=FOO}" we print
2887 FOO, not LAST_THING. */
2889 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2894 for (; j
< syms
->nsyms
; j
++,n
++)
2896 struct symbol
*xsym
= syms
->symbol
[j
];
2897 SYMBOL_TYPE (xsym
) = type
;
2898 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2899 TYPE_FIELD_VALUE (type
, n
) = 0;
2900 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2901 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2908 /* This screws up perfectly good C programs with enums. FIXME. */
2909 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2910 if(TYPE_NFIELDS(type
) == 2 &&
2911 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2912 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2913 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2914 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2915 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2921 /* Read a number from the string pointed to by *PP.
2922 The value of *PP is advanced over the number.
2923 If END is nonzero, the character that ends the
2924 number must match END, or an error happens;
2925 and that character is skipped if it does match.
2926 If END is zero, *PP is left pointing to that character.
2928 If the number fits in a long, set *VALUE and set *BITS to 0.
2929 If not, set *BITS to be the number of bits in the number.
2931 If encounter garbage, set *BITS to -1. */
2934 read_huge_number (pp
, end
, valu
, bits
)
2955 /* Leading zero means octal. GCC uses this to output values larger
2956 than an int (because that would be hard in decimal). */
2963 upper_limit
= LONG_MAX
/ radix
;
2964 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2966 if (n
<= upper_limit
)
2969 n
+= c
- '0'; /* FIXME this overflows anyway */
2974 /* This depends on large values being output in octal, which is
2981 /* Ignore leading zeroes. */
2985 else if (c
== '2' || c
== '3')
3011 /* Large decimal constants are an error (because it is hard to
3012 count how many bits are in them). */
3018 /* -0x7f is the same as 0x80. So deal with it by adding one to
3019 the number of bits. */
3034 static struct type
*
3035 read_range_type (pp
, typenums
, objfile
)
3038 struct objfile
*objfile
;
3044 struct type
*result_type
;
3046 /* First comes a type we are a subrange of.
3047 In C it is usually 0, 1 or the type being defined. */
3048 read_type_number (pp
, rangenums
);
3049 self_subrange
= (rangenums
[0] == typenums
[0] &&
3050 rangenums
[1] == typenums
[1]);
3052 /* A semicolon should now follow; skip it. */
3056 /* The remaining two operands are usually lower and upper bounds
3057 of the range. But in some special cases they mean something else. */
3058 read_huge_number (pp
, ';', &n2
, &n2bits
);
3059 read_huge_number (pp
, ';', &n3
, &n3bits
);
3061 if (n2bits
== -1 || n3bits
== -1)
3062 return error_type (pp
);
3064 /* If limits are huge, must be large integral type. */
3065 if (n2bits
!= 0 || n3bits
!= 0)
3067 char got_signed
= 0;
3068 char got_unsigned
= 0;
3069 /* Number of bits in the type. */
3072 /* Range from 0 to <large number> is an unsigned large integral type. */
3073 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3078 /* Range from <large number> to <large number>-1 is a large signed
3080 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3086 /* Check for "long long". */
3087 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
3088 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3089 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
3090 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3092 if (got_signed
|| got_unsigned
)
3094 result_type
= (struct type
*)
3095 obstack_alloc (&objfile
-> type_obstack
,
3096 sizeof (struct type
));
3097 bzero (result_type
, sizeof (struct type
));
3098 TYPE_OBJFILE (result_type
) = objfile
;
3099 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
3100 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
3102 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
3106 return error_type (pp
);
3109 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3110 if (self_subrange
&& n2
== 0 && n3
== 0)
3111 return (lookup_fundamental_type (objfile
, FT_VOID
));
3113 /* If n3 is zero and n2 is not, we want a floating type,
3114 and n2 is the width in bytes.
3116 Fortran programs appear to use this for complex types also,
3117 and they give no way to distinguish between double and single-complex!
3118 We don't have complex types, so we would lose on all fortran files!
3119 So return type `double' for all of those. It won't work right
3120 for the complex values, but at least it makes the file loadable.
3122 FIXME, we may be able to distinguish these by their names. FIXME. */
3124 if (n3
== 0 && n2
> 0)
3126 if (n2
== sizeof (float))
3127 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
3128 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
3131 /* If the upper bound is -1, it must really be an unsigned int. */
3133 else if (n2
== 0 && n3
== -1)
3135 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3136 long' is to look at its name! */
3138 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3139 long_kludge_name
[9] == 'l' /* long */)
3140 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3141 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3143 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3146 /* Special case: char is defined (Who knows why) as a subrange of
3147 itself with range 0-127. */
3148 else if (self_subrange
&& n2
== 0 && n3
== 127)
3149 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3151 /* Assumptions made here: Subrange of self is equivalent to subrange
3152 of int. FIXME: Host and target type-sizes assumed the same. */
3153 /* FIXME: This is the *only* place in GDB that depends on comparing
3154 some type to a builtin type with ==. Fix it! */
3156 && (self_subrange
||
3157 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
3159 /* an unsigned type */
3161 if (n3
== - sizeof (long long))
3162 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3164 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3165 long' is to look at its name! */
3166 if (n3
== (unsigned long)~0L &&
3167 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3168 long_kludge_name
[9] == 'l' /* long */)
3169 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3170 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3171 if (n3
== (unsigned int)~0L)
3172 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3173 if (n3
== (unsigned short)~0L)
3174 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
3175 if (n3
== (unsigned char)~0L)
3176 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
3179 else if (n3
== 0 && n2
== -sizeof (long long))
3180 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3182 else if (n2
== -n3
-1)
3185 /* FIXME -- the only way to distinguish `int' from `long' is to look
3187 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
3188 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3189 return (lookup_fundamental_type (objfile
, FT_LONG
));
3190 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
3191 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
3192 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
3193 return (lookup_fundamental_type (objfile
, FT_SHORT
));
3194 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
3195 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3198 /* We have a real range type on our hands. Allocate space and
3199 return a real pointer. */
3201 /* At this point I don't have the faintest idea how to deal with
3202 a self_subrange type; I'm going to assume that this is used
3203 as an idiom, and that all of them are special cases. So . . . */
3205 return error_type (pp
);
3207 result_type
= (struct type
*)
3208 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
3209 bzero (result_type
, sizeof (struct type
));
3210 TYPE_OBJFILE (result_type
) = objfile
;
3212 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3214 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3215 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3216 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
3217 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
3220 TYPE_NFIELDS (result_type
) = 2;
3221 TYPE_FIELDS (result_type
) =
3222 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
3223 2 * sizeof (struct field
));
3224 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
3225 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3226 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3228 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3233 /* Read a number from the string pointed to by *PP.
3234 The value of *PP is advanced over the number.
3235 If END is nonzero, the character that ends the
3236 number must match END, or an error happens;
3237 and that character is skipped if it does match.
3238 If END is zero, *PP is left pointing to that character. */
3241 read_number (pp
, end
)
3245 register char *p
= *pp
;
3246 register long n
= 0;
3250 /* Handle an optional leading minus sign. */
3258 /* Read the digits, as far as they go. */
3260 while ((c
= *p
++) >= '0' && c
<= '9')
3268 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3277 /* Read in an argument list. This is a list of types, separated by commas
3278 and terminated with END. Return the list of types read in, or (struct type
3279 **)-1 if there is an error. */
3280 static struct type
**
3281 read_args (pp
, end
, objfile
)
3284 struct objfile
*objfile
;
3286 /* FIXME! Remove this arbitrary limit! */
3287 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3293 /* Invalid argument list: no ','. */
3294 return (struct type
**)-1;
3297 /* Check for and handle cretinous dbx symbol name continuation! */
3299 *pp
= next_symbol_text ();
3301 types
[n
++] = read_type (pp
, objfile
);
3303 *pp
+= 1; /* get past `end' (the ':' character) */
3307 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3309 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3311 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3312 bzero (rval
+ n
, sizeof (struct type
*));
3316 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3318 memcpy (rval
, types
, n
* sizeof (struct type
*));
3322 /* Add a common block's start address to the offset of each symbol
3323 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3324 the common block name). */
3327 fix_common_block (sym
, valu
)
3331 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3332 for ( ; next
; next
= next
->next
)
3335 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3336 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3340 /* Initializer for this module */
3342 _initialize_buildsym ()
3344 undef_types_allocated
= 20;
3345 undef_types_length
= 0;
3346 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3347 sizeof (struct type
*));