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};
155 register char *p
= name
;
156 register int total
= p
[0];
169 /* Ensure result is positive. */
170 if (total
< 0) total
+= (1000 << 6);
171 return total
% HASHSIZE
;
175 /* Look up a dbx type-number pair. Return the address of the slot
176 where the type for that number-pair is stored.
177 The number-pair is in TYPENUMS.
179 This can be used for finding the type associated with that pair
180 or for associating a new type with the pair. */
183 dbx_lookup_type (typenums
)
186 register int filenum
= typenums
[0], index
= typenums
[1];
189 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
190 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
191 filenum
, index
, symnum
);
195 /* Type is defined outside of header files.
196 Find it in this object file's type vector. */
197 if (index
>= type_vector_length
)
199 old_len
= type_vector_length
;
201 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
202 type_vector
= (struct type
**)
203 malloc (type_vector_length
* sizeof (struct type
*));
205 while (index
>= type_vector_length
)
206 type_vector_length
*= 2;
207 type_vector
= (struct type
**)
208 xrealloc ((char *) type_vector
,
209 (type_vector_length
* sizeof (struct type
*)));
210 bzero (&type_vector
[old_len
],
211 (type_vector_length
- old_len
) * sizeof (struct type
*));
213 return &type_vector
[index
];
217 register int real_filenum
= this_object_header_files
[filenum
];
218 register struct header_file
*f
;
221 if (real_filenum
>= n_header_files
)
224 f
= &header_files
[real_filenum
];
226 f_orig_length
= f
->length
;
227 if (index
>= f_orig_length
)
229 while (index
>= f
->length
)
231 f
->vector
= (struct type
**)
232 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
233 bzero (&f
->vector
[f_orig_length
],
234 (f
->length
- f_orig_length
) * sizeof (struct type
*));
236 return &f
->vector
[index
];
240 /* Make sure there is a type allocated for type numbers TYPENUMS
241 and return the type object.
242 This can create an empty (zeroed) type object.
243 TYPENUMS may be (-1, -1) to return a new type object that is not
244 put into the type vector, and so may not be referred to by number. */
247 dbx_alloc_type (typenums
, objfile
)
249 struct objfile
*objfile
;
251 register struct type
**type_addr
;
252 register struct type
*type
;
254 if (typenums
[0] != -1)
256 type_addr
= dbx_lookup_type (typenums
);
265 /* If we are referring to a type not known at all yet,
266 allocate an empty type for it.
267 We will fill it in later if we find out how. */
270 type
= alloc_type (objfile
);
278 /* maintain the lists of symbols and blocks */
280 /* Add a symbol to one of the lists of symbols. */
282 add_symbol_to_list (symbol
, listhead
)
283 struct symbol
*symbol
;
284 struct pending
**listhead
;
286 /* We keep PENDINGSIZE symbols in each link of the list.
287 If we don't have a link with room in it, add a new link. */
288 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
290 register struct pending
*link
;
293 link
= free_pendings
;
294 free_pendings
= link
->next
;
297 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
299 link
->next
= *listhead
;
304 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
307 /* Find a symbol on a pending list. */
309 find_symbol_in_list (list
, name
, length
)
310 struct pending
*list
;
317 for (j
= list
->nsyms
; --j
>= 0; ) {
318 char *pp
= SYMBOL_NAME (list
->symbol
[j
]);
319 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 && pp
[length
] == '\0')
320 return list
->symbol
[j
];
327 /* At end of reading syms, or in case of quit,
328 really free as many `struct pending's as we can easily find. */
332 really_free_pendings (foo
)
335 struct pending
*next
, *next1
;
337 struct pending_block
*bnext
, *bnext1
;
340 for (next
= free_pendings
; next
; next
= next1
)
347 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
348 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
350 bnext1
= bnext
->next
;
356 for (next
= file_symbols
; next
; next
= next1
)
363 for (next
= global_symbols
; next
; next
= next1
)
371 /* Take one of the lists of symbols and make a block from it.
372 Keep the order the symbols have in the list (reversed from the input file).
373 Put the block on the list of pending blocks. */
376 finish_block (symbol
, listhead
, old_blocks
, start
, end
, objfile
)
377 struct symbol
*symbol
;
378 struct pending
**listhead
;
379 struct pending_block
*old_blocks
;
380 CORE_ADDR start
, end
;
381 struct objfile
*objfile
;
383 register struct pending
*next
, *next1
;
384 register struct block
*block
;
385 register struct pending_block
*pblock
;
386 struct pending_block
*opblock
;
389 /* Count the length of the list of symbols. */
391 for (next
= *listhead
, i
= 0;
393 i
+= next
->nsyms
, next
= next
->next
)
396 block
= (struct block
*) obstack_alloc (&objfile
-> symbol_obstack
,
397 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
399 /* Copy the symbols into the block. */
401 BLOCK_NSYMS (block
) = i
;
402 for (next
= *listhead
; next
; next
= next
->next
)
405 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
406 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
409 BLOCK_START (block
) = start
;
410 BLOCK_END (block
) = end
;
411 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
412 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
414 /* Put the block in as the value of the symbol that names it. */
418 SYMBOL_BLOCK_VALUE (symbol
) = block
;
419 BLOCK_FUNCTION (block
) = symbol
;
422 BLOCK_FUNCTION (block
) = 0;
424 /* Now "free" the links of the list, and empty the list. */
426 for (next
= *listhead
; next
; next
= next1
)
429 next
->next
= free_pendings
;
430 free_pendings
= next
;
434 /* Install this block as the superblock
435 of all blocks made since the start of this scope
436 that don't have superblocks yet. */
439 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
441 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
443 /* Check to be sure the blocks are nested as we receive them.
444 If the compiler/assembler/linker work, this just burns a small
446 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
447 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
448 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
450 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
451 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
454 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
459 /* Record this block on the list of all blocks in the file.
460 Put it after opblock, or at the beginning if opblock is 0.
461 This puts the block in the list after all its subblocks. */
463 /* Allocate in the symbol_obstack to save time.
464 It wastes a little space. */
465 pblock
= (struct pending_block
*)
466 obstack_alloc (&objfile
-> symbol_obstack
,
467 sizeof (struct pending_block
));
468 pblock
->block
= block
;
471 pblock
->next
= opblock
->next
;
472 opblock
->next
= pblock
;
476 pblock
->next
= pending_blocks
;
477 pending_blocks
= pblock
;
481 static struct blockvector
*
482 make_blockvector (objfile
)
483 struct objfile
*objfile
;
485 register struct pending_block
*next
;
486 register struct blockvector
*blockvector
;
489 /* Count the length of the list of blocks. */
491 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
493 blockvector
= (struct blockvector
*)
494 obstack_alloc (&objfile
-> symbol_obstack
,
495 (sizeof (struct blockvector
)
496 + (i
- 1) * sizeof (struct block
*)));
498 /* Copy the blocks into the blockvector.
499 This is done in reverse order, which happens to put
500 the blocks into the proper order (ascending starting address).
501 finish_block has hair to insert each block into the list
502 after its subblocks in order to make sure this is true. */
504 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
505 for (next
= pending_blocks
; next
; next
= next
->next
) {
506 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
509 #if 0 /* Now we make the links in the obstack, so don't free them. */
510 /* Now free the links of the list, and empty the list. */
512 for (next
= pending_blocks
; next
; next
= next1
)
520 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
521 /* Some compilers output blocks in the wrong order, but we depend
522 on their being in the right order so we can binary search.
523 Check the order and moan about it. FIXME. */
524 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
525 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
526 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
527 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
528 complain (&blockvector_complaint
,
529 (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
537 /* Start recording information about source code that came from an included
538 (or otherwise merged-in) source file with a different name. */
541 start_subfile (name
, dirname
)
545 register struct subfile
*subfile
;
547 /* See if this subfile is already known as a subfile of the
548 current main source file. */
550 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
552 if (!strcmp (subfile
->name
, name
))
554 current_subfile
= subfile
;
559 /* This subfile is not known. Add an entry for it.
560 Make an entry for this subfile in the list of all subfiles
561 of the current main source file. */
563 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
564 subfile
->next
= subfiles
;
566 current_subfile
= subfile
;
568 /* Save its name and compilation directory name */
569 subfile
->name
= strdup (name
);
571 subfile
->dirname
= NULL
;
573 subfile
->dirname
= strdup (dirname
);
575 /* Initialize line-number recording for this subfile. */
576 subfile
->line_vector
= 0;
579 /* Handle the N_BINCL and N_EINCL symbol types
580 that act like N_SOL for switching source files
581 (different subfiles, as we call them) within one object file,
582 but using a stack rather than in an arbitrary order. */
587 register struct subfile_stack
*tem
588 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
590 tem
->next
= subfile_stack
;
592 if (current_subfile
== 0 || current_subfile
->name
== 0)
594 tem
->name
= current_subfile
->name
;
595 tem
->prev_index
= header_file_prev_index
;
602 register struct subfile_stack
*link
= subfile_stack
;
608 subfile_stack
= link
->next
;
609 header_file_prev_index
= link
->prev_index
;
615 /* Manage the vector of line numbers for each subfile. */
618 record_line (subfile
, line
, pc
)
619 register struct subfile
*subfile
;
623 struct linetable_entry
*e
;
624 /* Ignore the dummy line number in libg.o */
629 /* Make sure line vector exists and is big enough. */
630 if (!subfile
->line_vector
) {
631 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
632 subfile
->line_vector
= (struct linetable
*)
633 xmalloc (sizeof (struct linetable
)
634 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
635 subfile
->line_vector
->nitems
= 0;
638 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
640 subfile
->line_vector_length
*= 2;
641 subfile
->line_vector
= (struct linetable
*)
642 xrealloc ((char *) subfile
->line_vector
, (sizeof (struct linetable
)
643 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
646 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
647 e
->line
= line
; e
->pc
= pc
;
651 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
654 compare_line_numbers (ln1p
, ln2p
)
658 return (((struct linetable_entry
*) ln1p
) -> line
-
659 ((struct linetable_entry
*) ln2p
) -> line
);
663 /* Start a new symtab for a new source file.
664 This is called when a dbx symbol of type N_SO is seen;
665 it indicates the start of data for one original source file. */
668 start_symtab (name
, dirname
, start_addr
)
671 CORE_ADDR start_addr
;
674 last_source_file
= name
;
675 last_source_start_addr
= start_addr
;
678 global_stabs
= 0; /* AIX COFF */
681 /* Context stack is initially empty. Allocate first one with room for
682 10 levels; reuse it forever afterward. */
683 if (context_stack
== 0) {
684 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
685 context_stack
= (struct context_stack
*)
686 xmalloc (context_stack_size
* sizeof (struct context_stack
));
688 context_stack_depth
= 0;
690 /* Leave FILENUM of 0 free for builtin types and this file's types. */
691 n_this_object_header_files
= 1;
692 header_file_prev_index
= -1;
694 type_vector_length
= 0;
695 type_vector
= (struct type
**) 0;
697 /* Initialize the list of sub source files with one entry
698 for this file (the top-level source file). */
702 start_subfile (name
, dirname
);
705 /* for all the stabs in a given stab vector, build appropriate types
706 and fix their symbols in given symbol vector. */
709 patch_block_stabs (symbols
, stabs
, objfile
)
710 struct pending
*symbols
;
711 struct pending_stabs
*stabs
;
712 struct objfile
*objfile
;
719 /* for all the stab entries, find their corresponding symbols and
720 patch their types! */
722 for (ii
= 0; ii
< stabs
->count
; ++ii
)
724 char *name
= stabs
->stab
[ii
];
725 char *pp
= (char*) strchr (name
, ':');
726 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
730 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
736 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
739 lookup_function_type (read_type (&pp
, objfile
));
743 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
750 /* Finish the symbol definitions for one main source file,
751 close off all the lexical contexts for that file
752 (creating struct block's for them), then make the struct symtab
753 for that file and put it in the list of all such.
755 END_ADDR is the address of the end of the file's text. */
758 end_symtab (end_addr
, sort_pending
, sort_linevec
, objfile
)
762 struct objfile
*objfile
;
764 register struct symtab
*symtab
;
765 register struct blockvector
*blockvector
;
766 register struct subfile
*subfile
;
767 struct subfile
*nextsub
;
769 /* Finish the lexical context of the last function in the file;
770 pop the context stack. */
772 if (context_stack_depth
> 0)
774 register struct context_stack
*cstk
;
775 context_stack_depth
--;
776 cstk
= &context_stack
[context_stack_depth
];
777 /* Make a block for the local symbols within. */
778 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
779 cstk
->start_addr
, end_addr
, objfile
);
781 /* Debug: if context stack still has something in it, we are in
783 if (context_stack_depth
> 0)
787 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
788 in this stage. Especially, blocks for static functions will show up at
789 the end. We need to sort them, so tools like `find_pc_function' and
790 `find_pc_block' can work reliably. */
791 if (sort_pending
&& pending_blocks
) {
792 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
795 struct pending_block
*pb
, *pbnext
;
797 pb
= pending_blocks
, pbnext
= pb
->next
;
802 /* swap blocks if unordered! */
804 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
)) {
805 struct block
*tmp
= pb
->block
;
806 pb
->block
= pbnext
->block
;
811 pbnext
= pbnext
->next
;
816 /* Cleanup any undefined types that have been left hanging around
817 (this needs to be done before the finish_blocks so that
818 file_symbols is still good). */
819 cleanup_undefined_types ();
822 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
827 if (pending_blocks
== 0
829 && global_symbols
== 0) {
830 /* Ignore symtabs that have no functions with real debugging info */
833 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
834 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
835 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
836 blockvector
= make_blockvector (objfile
);
839 #ifdef PROCESS_LINENUMBER_HOOK
840 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
843 /* Now create the symtab objects proper, one for each subfile. */
844 /* (The main file is the last one on the chain.) */
846 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
849 /* If we have blocks of symbols, make a symtab.
850 Otherwise, just ignore this file and any line number info in it. */
853 if (subfile
->line_vector
) {
854 /* First, shrink the linetable to make more memory. */
855 linetablesize
= sizeof (struct linetable
) +
856 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
857 subfile
->line_vector
= (struct linetable
*)
858 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
861 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
862 sizeof (struct linetable_entry
), compare_line_numbers
);
865 /* Now, allocate a symbol table. */
866 symtab
= allocate_symtab (subfile
->name
, objfile
);
868 /* Fill in its components. */
869 symtab
->blockvector
= blockvector
;
870 if (subfile
->line_vector
)
872 /* Reallocate the line table on the symbol obstack */
873 symtab
->linetable
= (struct linetable
*)
874 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
875 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
879 symtab
->linetable
= NULL
;
881 symtab
->dirname
= subfile
->dirname
;
882 symtab
->free_code
= free_linetable
;
883 symtab
->free_ptr
= 0;
885 #if 0 /* defined(IBM6000) */
886 /* In case we need to duplicate symbol tables (to represent include
887 files), and in case our system needs relocation, we want to
888 relocate the main symbol table node only (for the main file,
889 not for the include files). */
891 symtab
->nonreloc
= TRUE
;
894 if (subfile
->line_vector
)
895 free (subfile
->line_vector
);
897 nextsub
= subfile
->next
;
901 #if 0 /* defined(IBM6000) */
902 /* all include symbol tables are non-relocatable, except the main source
905 symtab_list
->nonreloc
= FALSE
;
909 free ((char *) type_vector
);
911 type_vector_length
= 0;
913 last_source_file
= 0;
915 previous_stab_code
= 0;
921 /* Push a context block. Args are an identifying nesting level (checkable
922 when you pop it), and the starting PC address of this context. */
924 struct context_stack
*
925 push_context (desc
, valu
)
929 register struct context_stack
*new;
931 if (context_stack_depth
== context_stack_size
)
933 context_stack_size
*= 2;
934 context_stack
= (struct context_stack
*)
935 xrealloc ((char *) context_stack
,
936 (context_stack_size
* sizeof (struct context_stack
)));
939 new = &context_stack
[context_stack_depth
++];
941 new->locals
= local_symbols
;
942 new->old_blocks
= pending_blocks
;
943 new->start_addr
= valu
;
951 /* Initialize anything that needs initializing when starting to read
952 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
964 /* Initialize anything that needs initializing when a completely new
965 symbol file is specified (not just adding some symbols from another
966 file, e.g. a shared library). */
971 /* Empty the hash table of global syms looking for values. */
972 bzero (global_sym_chain
, sizeof global_sym_chain
);
977 /* Scan through all of the global symbols defined in the object file,
978 assigning values to the debugging symbols that need to be assigned
979 to. Get these symbols from the minimal symbol table. */
982 scan_file_globals (objfile
)
983 struct objfile
*objfile
;
986 struct minimal_symbol
*msymbol
;
987 struct symbol
*sym
, *prev
;
989 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
993 prev
= (struct symbol
*) 0;
995 /* Get the hash index and check all the symbols
996 under that hash index. */
998 hash
= hashname (msymbol
-> name
);
1000 for (sym
= global_sym_chain
[hash
]; sym
;)
1002 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
1003 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
1005 /* Splice this symbol out of the hash chain and
1006 assign the value we have to it. */
1008 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1010 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1012 /* Check to see whether we need to fix up a common block. */
1013 /* Note: this code might be executed several times for
1014 the same symbol if there are multiple references. */
1015 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1016 fix_common_block (sym
, msymbol
-> address
);
1018 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
1021 sym
= SYMBOL_VALUE_CHAIN (prev
);
1023 sym
= global_sym_chain
[hash
];
1028 sym
= SYMBOL_VALUE_CHAIN (sym
);
1035 /* Read a number by which a type is referred to in dbx data,
1036 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1037 Just a single number N is equivalent to (0,N).
1038 Return the two numbers by storing them in the vector TYPENUMS.
1039 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1042 read_type_number (pp
, typenums
)
1044 register int *typenums
;
1049 typenums
[0] = read_number (pp
, ',');
1050 typenums
[1] = read_number (pp
, ')');
1055 typenums
[1] = read_number (pp
, 0);
1059 /* To handle GNU C++ typename abbreviation, we need to be able to
1060 fill in a type's name as soon as space for that type is allocated.
1061 `type_synonym_name' is the name of the type being allocated.
1062 It is cleared as soon as it is used (lest all allocated types
1064 static char *type_synonym_name
;
1068 define_symbol (valu
, string
, desc
, type
, objfile
)
1073 struct objfile
*objfile
;
1075 register struct symbol
*sym
;
1076 char *p
= (char *) strchr (string
, ':');
1080 struct type
*temptype
;
1082 /* Ignore syms with empty names. */
1086 /* Ignore old-style symbols from cc -go */
1090 sym
= (struct symbol
*)obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1092 if (processing_gcc_compilation
) {
1093 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1094 number of bytes occupied by a type or object, which we ignore. */
1095 SYMBOL_LINE(sym
) = desc
;
1097 SYMBOL_LINE(sym
) = 0; /* unknown */
1100 if (string
[0] == CPLUS_MARKER
)
1102 /* Special GNU C++ names. */
1106 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1107 &objfile
-> symbol_obstack
);
1109 case 'v': /* $vtbl_ptr_type */
1110 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1113 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1114 &objfile
-> symbol_obstack
);
1118 /* This was an anonymous type that was never fixed up. */
1129 = (char *) obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1130 /* Open-coded bcopy--saves function call time. */
1132 register char *p1
= string
;
1133 register char *p2
= SYMBOL_NAME (sym
);
1140 /* Determine the type of name being defined. */
1141 /* The Acorn RISC machine's compiler can put out locals that don't
1142 start with "234=" or "(3,4)=", so assume anything other than the
1143 deftypes we know how to handle is a local. */
1144 /* (Peter Watkins @ Computervision)
1145 Handle Sun-style local fortran array types 'ar...' .
1146 (gnu@cygnus.com) -- this strchr() handles them properly?
1147 (tiemann@cygnus.com) -- 'C' is for catch. */
1148 if (!strchr ("cfFGpPrStTvVXC", *p
))
1153 /* c is a special case, not followed by a type-number.
1154 SYMBOL:c=iVALUE for an integer constant symbol.
1155 SYMBOL:c=rVALUE for a floating constant symbol.
1156 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1157 e.g. "b:c=e6,0" for "const b = blob1"
1158 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1162 error ("Invalid symbol data at symtab pos %d.", symnum
);
1167 double d
= atof (p
);
1170 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1173 obstack_alloc (&objfile
-> type_obstack
,
1175 memcpy (dbl_valu
, &d
, sizeof (double));
1176 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1177 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1178 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1183 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1185 SYMBOL_VALUE (sym
) = atoi (p
);
1186 SYMBOL_CLASS (sym
) = LOC_CONST
;
1190 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1191 e.g. "b:c=e6,0" for "const b = blob1"
1192 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1196 read_type_number (&p
, typenums
);
1198 error ("Invalid symbol data: no comma in enum const symbol");
1200 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1201 SYMBOL_VALUE (sym
) = atoi (p
);
1202 SYMBOL_CLASS (sym
) = LOC_CONST
;
1206 error ("Invalid symbol data at symtab pos %d.", symnum
);
1208 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1209 add_symbol_to_list (sym
, &file_symbols
);
1213 /* Now usually comes a number that says which data type,
1214 and possibly more stuff to define the type
1215 (all of which is handled by read_type) */
1217 if (deftype
== 'p' && *p
== 'F')
1218 /* pF is a two-letter code that means a function parameter in Fortran.
1219 The type-number specifies the type of the return value.
1220 Translate it into a pointer-to-function type. */
1224 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
1228 struct type
*type_read
;
1229 synonym
= *p
== 't';
1234 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1235 strlen (SYMBOL_NAME (sym
)),
1236 &objfile
-> symbol_obstack
);
1239 /* Here we save the name of the symbol for read_range_type, which
1240 ends up reading in the basic types. In stabs, unfortunately there
1241 is no distinction between "int" and "long" types except their
1242 names. Until we work out a saner type policy (eliminating most
1243 builtin types and using the names specified in the files), we
1244 save away the name so that far away from here in read_range_type,
1245 we can examine it to decide between "int" and "long". FIXME. */
1246 long_kludge_name
= SYMBOL_NAME (sym
);
1247 type_read
= read_type (&p
, objfile
);
1249 if ((deftype
== 'F' || deftype
== 'f')
1250 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
1253 /* This code doesn't work -- it needs to realloc and can't. */
1254 struct type
*new = (struct type
*)
1255 obstack_alloc (&objfile
-> type_obstack
,
1256 sizeof (struct type
));
1258 /* Generate a template for the type of this function. The
1259 types of the arguments will be added as we read the symbol
1261 *new = *lookup_function_type (type_read
);
1262 SYMBOL_TYPE(sym
) = new;
1263 TYPE_OBJFILE (new) = objfile
;
1264 in_function_type
= new;
1266 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
1270 SYMBOL_TYPE (sym
) = type_read
;
1276 /* The name of a caught exception. */
1277 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1278 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1279 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1280 add_symbol_to_list (sym
, &local_symbols
);
1284 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1285 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1286 add_symbol_to_list (sym
, &file_symbols
);
1290 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1291 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1292 add_symbol_to_list (sym
, &global_symbols
);
1296 /* For a class G (global) symbol, it appears that the
1297 value is not correct. It is necessary to search for the
1298 corresponding linker definition to find the value.
1299 These definitions appear at the end of the namelist. */
1300 i
= hashname (SYMBOL_NAME (sym
));
1301 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1302 global_sym_chain
[i
] = sym
;
1303 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1304 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1305 add_symbol_to_list (sym
, &global_symbols
);
1308 /* This case is faked by a conditional above,
1309 when there is no code letter in the dbx data.
1310 Dbx data never actually contains 'l'. */
1312 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1313 SYMBOL_VALUE (sym
) = valu
;
1314 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1315 add_symbol_to_list (sym
, &local_symbols
);
1319 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1320 can also be a LOC_LOCAL_ARG depending on symbol type. */
1321 #ifndef DBX_PARM_SYMBOL_CLASS
1322 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1324 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1325 SYMBOL_VALUE (sym
) = valu
;
1326 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1328 /* This doesn't work yet. */
1329 add_param_to_type (&in_function_type
, sym
);
1331 add_symbol_to_list (sym
, &local_symbols
);
1333 /* If it's gcc-compiled, if it says `short', believe it. */
1334 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1337 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1338 /* This macro is defined on machines (e.g. sparc) where
1339 we should believe the type of a PCC 'short' argument,
1340 but shouldn't believe the address (the address is
1341 the address of the corresponding int). Note that
1342 this is only different from the BELIEVE_PCC_PROMOTION
1343 case on big-endian machines.
1345 My guess is that this correction, as opposed to changing
1346 the parameter to an 'int' (as done below, for PCC
1347 on most machines), is the right thing to do
1348 on all machines, but I don't want to risk breaking
1349 something that already works. On most PCC machines,
1350 the sparc problem doesn't come up because the calling
1351 function has to zero the top bytes (not knowing whether
1352 the called function wants an int or a short), so there
1353 is no practical difference between an int and a short
1354 (except perhaps what happens when the GDB user types
1355 "print short_arg = 0x10000;").
1357 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1358 actually produces the correct address (we don't need to fix it
1359 up). I made this code adapt so that it will offset the symbol
1360 if it was pointing at an int-aligned location and not
1361 otherwise. This way you can use the same gdb for 4.0.x and
1364 If the parameter is shorter than an int, and is integral
1365 (e.g. char, short, or unsigned equivalent), and is claimed to
1366 be passed on an integer boundary, don't believe it! Offset the
1367 parameter's address to the tail-end of that integer. */
1369 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1370 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1371 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1372 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
1374 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
1375 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1379 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1381 /* If PCC says a parameter is a short or a char,
1382 it is really an int. */
1383 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1384 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1385 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1387 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1388 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
1393 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1396 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1397 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1398 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1399 add_symbol_to_list (sym
, &local_symbols
);
1403 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1404 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1405 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1406 add_symbol_to_list (sym
, &local_symbols
);
1410 /* Static symbol at top level of file */
1411 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1412 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1413 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1414 add_symbol_to_list (sym
, &file_symbols
);
1418 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1419 SYMBOL_VALUE (sym
) = valu
;
1420 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1421 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1422 TYPE_NAME (SYMBOL_TYPE (sym
)) =
1423 obsavestring (SYMBOL_NAME (sym
),
1424 strlen (SYMBOL_NAME (sym
)),
1425 &objfile
-> symbol_obstack
);
1426 /* C++ vagaries: we may have a type which is derived from
1427 a base type which did not have its name defined when the
1428 derived class was output. We fill in the derived class's
1429 base part member's name here in that case. */
1430 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1431 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1432 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1435 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1436 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1437 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1438 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1441 add_symbol_to_list (sym
, &file_symbols
);
1445 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1446 SYMBOL_VALUE (sym
) = valu
;
1447 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1448 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1449 TYPE_NAME (SYMBOL_TYPE (sym
))
1450 = obconcat (&objfile
-> type_obstack
, "",
1451 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1453 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1454 ? "struct " : "union ")),
1456 add_symbol_to_list (sym
, &file_symbols
);
1460 register struct symbol
*typedef_sym
= (struct symbol
*)
1461 obstack_alloc (&objfile
-> type_obstack
,
1462 sizeof (struct symbol
));
1463 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1464 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1466 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1467 SYMBOL_VALUE (typedef_sym
) = valu
;
1468 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1469 add_symbol_to_list (typedef_sym
, &file_symbols
);
1474 /* Static symbol of local scope */
1475 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1476 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1477 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1478 add_symbol_to_list (sym
, &local_symbols
);
1482 /* Reference parameter */
1483 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1484 SYMBOL_VALUE (sym
) = valu
;
1485 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1486 add_symbol_to_list (sym
, &local_symbols
);
1490 /* This is used by Sun FORTRAN for "function result value".
1491 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1492 that Pascal uses it too, but when I tried it Pascal used
1493 "x:3" (local symbol) instead. */
1494 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1495 SYMBOL_VALUE (sym
) = valu
;
1496 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1497 add_symbol_to_list (sym
, &local_symbols
);
1501 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1506 /* What about types defined as forward references inside of a small lexical
1508 /* Add a type to the list of undefined types to be checked through
1509 once this file has been read in. */
1511 add_undefined_type (type
)
1514 if (undef_types_length
== undef_types_allocated
)
1516 undef_types_allocated
*= 2;
1517 undef_types
= (struct type
**)
1518 xrealloc ((char *) undef_types
,
1519 undef_types_allocated
* sizeof (struct type
*));
1521 undef_types
[undef_types_length
++] = type
;
1524 /* Go through each undefined type, see if it's still undefined, and fix it
1525 up if possible. We have two kinds of undefined types:
1527 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1528 Fix: update array length using the element bounds
1529 and the target type's length.
1530 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1531 yet defined at the time a pointer to it was made.
1532 Fix: Do a full lookup on the struct/union tag. */
1534 cleanup_undefined_types ()
1538 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1539 switch (TYPE_CODE (*type
)) {
1541 case TYPE_CODE_STRUCT
:
1542 case TYPE_CODE_UNION
:
1543 case TYPE_CODE_ENUM
:
1545 /* Reasonable test to see if it's been defined since. */
1546 if (TYPE_NFIELDS (*type
) == 0)
1548 struct pending
*ppt
;
1550 /* Name of the type, without "struct" or "union" */
1551 char *typename
= TYPE_NAME (*type
);
1553 if (!strncmp (typename
, "struct ", 7))
1555 if (!strncmp (typename
, "union ", 6))
1557 if (!strncmp (typename
, "enum ", 5))
1560 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1561 for (i
= 0; i
< ppt
->nsyms
; i
++)
1563 struct symbol
*sym
= ppt
->symbol
[i
];
1565 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1566 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1567 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1569 && !strcmp (SYMBOL_NAME (sym
), typename
))
1570 memcpy (*type
, SYMBOL_TYPE (sym
), sizeof (struct type
));
1574 /* It has been defined; don't mark it as a stub. */
1575 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1579 case TYPE_CODE_ARRAY
:
1581 struct type
*range_type
;
1584 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1586 if (TYPE_NFIELDS (*type
) != 1)
1588 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1589 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1592 /* Now recompute the length of the array type, based on its
1593 number of elements and the target type's length. */
1594 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1595 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1596 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1597 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1603 error ("GDB internal error. cleanup_undefined_types with bad\
1604 type %d.", TYPE_CODE (*type
));
1608 undef_types_length
= 0;
1611 /* Skip rest of this symbol and return an error type.
1613 General notes on error recovery: error_type always skips to the
1614 end of the symbol (modulo cretinous dbx symbol name continuation).
1615 Thus code like this:
1617 if (*(*pp)++ != ';')
1618 return error_type (pp);
1620 is wrong because if *pp starts out pointing at '\0' (typically as the
1621 result of an earlier error), it will be incremented to point to the
1622 start of the next symbol, which might produce strange results, at least
1623 if you run off the end of the string table. Instead use
1626 return error_type (pp);
1632 foo = error_type (pp);
1636 And in case it isn't obvious, the point of all this hair is so the compiler
1637 can define new types and new syntaxes, and old versions of the
1638 debugger will be able to read the new symbol tables. */
1644 complain (&error_type_complaint
, 0);
1647 /* Skip to end of symbol. */
1648 while (**pp
!= '\0')
1651 /* Check for and handle cretinous dbx symbol name continuation! */
1652 if ((*pp
)[-1] == '\\')
1653 *pp
= next_symbol_text ();
1657 return builtin_type_error
;
1660 /* Read a dbx type reference or definition;
1661 return the type that is meant.
1662 This can be just a number, in which case it references
1663 a type already defined and placed in type_vector.
1664 Or the number can be followed by an =, in which case
1665 it means to define a new type according to the text that
1669 read_type (pp
, objfile
)
1671 struct objfile
*objfile
;
1673 register struct type
*type
= 0;
1678 /* Read type number if present. The type number may be omitted.
1679 for instance in a two-dimensional array declared with type
1680 "ar1;1;10;ar1;1;10;4". */
1681 if ((**pp
>= '0' && **pp
<= '9')
1684 read_type_number (pp
, typenums
);
1686 /* Type is not being defined here. Either it already exists,
1687 or this is a forward reference to it. dbx_alloc_type handles
1690 return dbx_alloc_type (typenums
, objfile
);
1692 /* Type is being defined here. */
1693 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1697 /* if such a type already exists, this is an unnecessary duplication
1698 of the stab string, which is common in (RS/6000) xlc generated
1699 objects. In that case, simply return NULL and let the caller take
1702 tt
= *dbx_lookup_type (typenums
);
1703 if (tt
&& tt
->length
&& tt
->code
)
1712 /* 'typenums=' not present, type is anonymous. Read and return
1713 the definition, but don't put it in the type vector. */
1714 typenums
[0] = typenums
[1] = -1;
1722 enum type_code code
;
1724 /* Used to index through file_symbols. */
1725 struct pending
*ppt
;
1728 /* Name including "struct", etc. */
1731 /* Name without "struct", etc. */
1732 char *type_name_only
;
1738 /* Set the type code according to the following letter. */
1742 code
= TYPE_CODE_STRUCT
;
1746 code
= TYPE_CODE_UNION
;
1750 code
= TYPE_CODE_ENUM
;
1754 return error_type (pp
);
1757 to
= type_name
= (char *)
1758 obstack_alloc (&objfile
-> type_obstack
,
1760 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1762 /* Copy the prefix. */
1764 while (*to
++ = *from
++)
1768 type_name_only
= to
;
1770 /* Copy the name. */
1772 while ((*to
++ = *from
++) != ':')
1776 /* Set the pointer ahead of the name which we just read. */
1780 /* The following hack is clearly wrong, because it doesn't
1781 check whether we are in a baseclass. I tried to reproduce
1782 the case that it is trying to fix, but I couldn't get
1783 g++ to put out a cross reference to a basetype. Perhaps
1784 it doesn't do it anymore. */
1785 /* Note: for C++, the cross reference may be to a base type which
1786 has not yet been seen. In this case, we skip to the comma,
1787 which will mark the end of the base class name. (The ':'
1788 at the end of the base class name will be skipped as well.)
1789 But sometimes (ie. when the cross ref is the last thing on
1790 the line) there will be no ','. */
1791 from
= (char *) strchr (*pp
, ',');
1797 /* Now check to see whether the type has already been declared. */
1798 /* This is necessary at least in the case where the
1799 program says something like
1801 The compiler puts out a cross-reference; we better find
1802 set the length of the structure correctly so we can
1803 set the length of the array. */
1804 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1805 for (i
= 0; i
< ppt
->nsyms
; i
++)
1807 struct symbol
*sym
= ppt
->symbol
[i
];
1809 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1810 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1811 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1812 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1814 obstack_free (&objfile
-> type_obstack
, type_name
);
1815 type
= SYMBOL_TYPE (sym
);
1820 /* Didn't find the type to which this refers, so we must
1821 be dealing with a forward reference. Allocate a type
1822 structure for it, and keep track of it so we can
1823 fill in the rest of the fields when we get the full
1825 type
= dbx_alloc_type (typenums
, objfile
);
1826 TYPE_CODE (type
) = code
;
1827 TYPE_NAME (type
) = type_name
;
1828 INIT_CPLUS_SPECIFIC(type
);
1829 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1831 add_undefined_type (type
);
1835 case '-': /* RS/6000 built-in type */
1837 type
= builtin_type (pp
); /* (in xcoffread.c) */
1852 read_type_number (pp
, xtypenums
);
1853 type
= *dbx_lookup_type (xtypenums
);
1858 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1859 if (typenums
[0] != -1)
1860 *dbx_lookup_type (typenums
) = type
;
1864 type1
= read_type (pp
, objfile
);
1865 /* FIXME -- we should be doing smash_to_XXX types here. */
1867 /* postponed type decoration should be allowed. */
1868 if (typenums
[1] > 0 && typenums
[1] < type_vector_length
&&
1869 (type
= type_vector
[typenums
[1]])) {
1870 smash_to_pointer_type (type
, type1
);
1874 type
= lookup_pointer_type (type1
);
1875 if (typenums
[0] != -1)
1876 *dbx_lookup_type (typenums
) = type
;
1881 struct type
*domain
= read_type (pp
, objfile
);
1882 struct type
*memtype
;
1885 /* Invalid member type data format. */
1886 return error_type (pp
);
1889 memtype
= read_type (pp
, objfile
);
1890 type
= dbx_alloc_type (typenums
, objfile
);
1891 smash_to_member_type (type
, domain
, memtype
);
1896 if ((*pp
)[0] == '#')
1898 /* We'll get the parameter types from the name. */
1899 struct type
*return_type
;
1902 return_type
= read_type (pp
, objfile
);
1903 if (*(*pp
)++ != ';')
1904 complain (&invalid_member_complaint
, (char *) symnum
);
1905 type
= allocate_stub_method (return_type
);
1906 if (typenums
[0] != -1)
1907 *dbx_lookup_type (typenums
) = type
;
1911 struct type
*domain
= read_type (pp
, objfile
);
1912 struct type
*return_type
;
1915 if (*(*pp
)++ != ',')
1916 error ("invalid member type data format, at symtab pos %d.",
1919 return_type
= read_type (pp
, objfile
);
1920 args
= read_args (pp
, ';', objfile
);
1921 type
= dbx_alloc_type (typenums
, objfile
);
1922 smash_to_method_type (type
, domain
, return_type
, args
);
1927 type1
= read_type (pp
, objfile
);
1928 type
= lookup_reference_type (type1
);
1929 if (typenums
[0] != -1)
1930 *dbx_lookup_type (typenums
) = type
;
1934 type1
= read_type (pp
, objfile
);
1935 type
= lookup_function_type (type1
);
1936 if (typenums
[0] != -1)
1937 *dbx_lookup_type (typenums
) = type
;
1941 type
= read_range_type (pp
, typenums
, objfile
);
1942 if (typenums
[0] != -1)
1943 *dbx_lookup_type (typenums
) = type
;
1947 type
= dbx_alloc_type (typenums
, objfile
);
1948 type
= read_enum_type (pp
, type
, objfile
);
1949 *dbx_lookup_type (typenums
) = type
;
1953 type
= dbx_alloc_type (typenums
, objfile
);
1954 if (!TYPE_NAME (type
))
1955 TYPE_NAME (type
) = type_synonym_name
;
1956 type_synonym_name
= 0;
1957 type
= read_struct_type (pp
, type
, objfile
);
1961 type
= dbx_alloc_type (typenums
, objfile
);
1962 if (!TYPE_NAME (type
))
1963 TYPE_NAME (type
) = type_synonym_name
;
1964 type_synonym_name
= 0;
1965 type
= read_struct_type (pp
, type
, objfile
);
1966 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1971 return error_type (pp
);
1974 type
= dbx_alloc_type (typenums
, objfile
);
1975 type
= read_array_type (pp
, type
, objfile
);
1979 --*pp
; /* Go back to the symbol in error */
1980 /* Particularly important if it was \0! */
1981 return error_type (pp
);
1988 /* If this is an overriding temporary alteration for a header file's
1989 contents, and this type number is unknown in the global definition,
1990 put this type into the global definition at this type number. */
1991 if (header_file_prev_index
>= 0)
1993 register struct type
**tp
1994 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
2002 /* This page contains subroutines of read_type. */
2004 /* Read the description of a structure (or union type)
2005 and return an object describing the type. */
2007 static struct type
*
2008 read_struct_type (pp
, type
, objfile
)
2010 register struct type
*type
;
2011 struct objfile
*objfile
;
2013 /* Total number of methods defined in this class.
2014 If the class defines two `f' methods, and one `g' method,
2015 then this will have the value 3. */
2016 int total_length
= 0;
2020 struct nextfield
*next
;
2021 int visibility
; /* 0=public, 1=protected, 2=public */
2027 struct next_fnfield
*next
;
2028 struct fn_field fn_field
;
2031 struct next_fnfieldlist
2033 struct next_fnfieldlist
*next
;
2034 struct fn_fieldlist fn_fieldlist
;
2037 register struct nextfield
*list
= 0;
2038 struct nextfield
*new;
2041 int non_public_fields
= 0;
2044 register struct next_fnfieldlist
*mainlist
= 0;
2047 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2048 INIT_CPLUS_SPECIFIC(type
);
2050 /* First comes the total size in bytes. */
2052 TYPE_LENGTH (type
) = read_number (pp
, 0);
2054 /* C++: Now, if the class is a derived class, then the next character
2055 will be a '!', followed by the number of base classes derived from.
2056 Each element in the list contains visibility information,
2057 the offset of this base class in the derived structure,
2058 and then the base type. */
2061 int i
, n_baseclasses
, offset
;
2062 struct type
*baseclass
;
2065 /* Nonzero if it is a virtual baseclass, i.e.,
2069 struct C : public B, public virtual A {};
2071 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2072 2.0 language feature. */
2077 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
2079 n_baseclasses
= read_number (pp
, ',');
2080 TYPE_FIELD_VIRTUAL_BITS (type
) =
2081 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2082 B_BYTES (n_baseclasses
));
2083 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
2085 for (i
= 0; i
< n_baseclasses
; i
++)
2088 *pp
= next_symbol_text ();
2099 /* Bad visibility format. */
2100 return error_type (pp
);
2108 non_public_fields
++;
2114 /* Bad visibility format. */
2115 return error_type (pp
);
2118 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2121 /* Offset of the portion of the object corresponding to
2122 this baseclass. Always zero in the absence of
2123 multiple inheritance. */
2124 offset
= read_number (pp
, ',');
2125 baseclass
= read_type (pp
, objfile
);
2126 *pp
+= 1; /* skip trailing ';' */
2128 /* Make this baseclass visible for structure-printing purposes. */
2129 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2132 list
->visibility
= via_public
;
2133 list
->field
.type
= baseclass
;
2134 list
->field
.name
= type_name_no_tag (baseclass
);
2135 list
->field
.bitpos
= offset
;
2136 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2139 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
2142 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2143 At the end, we see a semicolon instead of a field.
2145 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2148 The `?' is a placeholder for one of '/2' (public visibility),
2149 '/1' (protected visibility), '/0' (private visibility), or nothing
2150 (C style symbol table, public visibility). */
2152 /* We better set p right now, in case there are no fields at all... */
2157 /* Check for and handle cretinous dbx symbol name continuation! */
2158 if (**pp
== '\\') *pp
= next_symbol_text ();
2160 /* Get space to record the next field's data. */
2161 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2165 /* Get the field name. */
2167 if (*p
== CPLUS_MARKER
)
2169 /* Special GNU C++ name. */
2174 struct type
*context
;
2185 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2186 prefix
= "INVALID_C++_ABBREV";
2190 context
= read_type (pp
, objfile
);
2191 name
= type_name_no_tag (context
);
2194 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
2195 TYPE_NAME (context
) = name
;
2197 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
2201 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2202 list
->field
.type
= read_type (pp
, objfile
);
2203 (*pp
)++; /* Skip the comma. */
2204 list
->field
.bitpos
= read_number (pp
, ';');
2205 /* This field is unpacked. */
2206 list
->field
.bitsize
= 0;
2207 list
->visibility
= 0; /* private */
2208 non_public_fields
++;
2210 /* GNU C++ anonymous type. */
2214 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2220 while (*p
!= ':') p
++;
2221 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
2222 &objfile
-> type_obstack
);
2224 /* C++: Check to see if we have hit the methods yet. */
2230 /* This means we have a visibility for a field coming. */
2236 list
->visibility
= 0; /* private */
2237 non_public_fields
++;
2242 list
->visibility
= 1; /* protected */
2243 non_public_fields
++;
2248 list
->visibility
= 2; /* public */
2253 else /* normal dbx-style format. */
2254 list
->visibility
= 2; /* public */
2256 list
->field
.type
= read_type (pp
, objfile
);
2259 /* Static class member. */
2260 list
->field
.bitpos
= (long)-1;
2262 while (*p
!= ';') p
++;
2263 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2268 else if (**pp
!= ',')
2269 /* Bad structure-type format. */
2270 return error_type (pp
);
2272 (*pp
)++; /* Skip the comma. */
2273 list
->field
.bitpos
= read_number (pp
, ',');
2274 list
->field
.bitsize
= read_number (pp
, ';');
2277 /* FIXME-tiemann: Can't the compiler put out something which
2278 lets us distinguish these? (or maybe just not put out anything
2279 for the field). What is the story here? What does the compiler
2280 really do? Also, patch gdb.texinfo for this case; I document
2281 it as a possible problem there. Search for "DBX-style". */
2283 /* This is wrong because this is identical to the symbols
2284 produced for GCC 0-size arrays. For example:
2289 The code which dumped core in such circumstances should be
2290 fixed not to dump core. */
2292 /* g++ -g0 can put out bitpos & bitsize zero for a static
2293 field. This does not give us any way of getting its
2294 class, so we can't know its name. But we can just
2295 ignore the field so we don't dump core and other nasty
2297 if (list
->field
.bitpos
== 0
2298 && list
->field
.bitsize
== 0)
2300 complain (&dbx_class_complaint
, 0);
2301 /* Ignore this field. */
2307 /* Detect an unpacked field and mark it as such.
2308 dbx gives a bit size for all fields.
2309 Note that forward refs cannot be packed,
2310 and treat enums as if they had the width of ints. */
2311 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2312 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2313 list
->field
.bitsize
= 0;
2314 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2315 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2316 && (list
->field
.bitsize
2317 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
2321 list
->field
.bitpos
% 8 == 0)
2322 list
->field
.bitsize
= 0;
2328 /* chill the list of fields: the last entry (at the head)
2329 is a partially constructed entry which we now scrub. */
2332 /* Now create the vector of fields, and record how big it is.
2333 We need this info to record proper virtual function table information
2334 for this class's virtual functions. */
2336 TYPE_NFIELDS (type
) = nfields
;
2337 TYPE_FIELDS (type
) = (struct field
*)
2338 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
2340 if (non_public_fields
)
2342 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2344 TYPE_FIELD_PRIVATE_BITS (type
) =
2345 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2347 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2349 TYPE_FIELD_PROTECTED_BITS (type
) =
2350 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2352 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2355 /* Copy the saved-up fields into the field vector. */
2357 for (n
= nfields
; list
; list
= list
->next
)
2360 TYPE_FIELD (type
, n
) = list
->field
;
2361 if (list
->visibility
== 0)
2362 SET_TYPE_FIELD_PRIVATE (type
, n
);
2363 else if (list
->visibility
== 1)
2364 SET_TYPE_FIELD_PROTECTED (type
, n
);
2367 /* Now come the method fields, as NAME::methods
2368 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2369 At the end, we see a semicolon instead of a field.
2371 For the case of overloaded operators, the format is
2372 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2373 `*' holds the place for an operator name (such as `+=')
2374 and `.' marks the end of the operator name. */
2377 /* Now, read in the methods. To simplify matters, we
2378 "unread" the name that has been read, so that we can
2379 start from the top. */
2381 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2382 /* For each list of method lists... */
2386 struct next_fnfield
*sublist
= 0;
2387 struct type
*look_ahead_type
= NULL
;
2389 struct next_fnfieldlist
*new_mainlist
=
2390 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2395 /* read in the name. */
2396 while (*p
!= ':') p
++;
2397 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2399 /* This is a completely wierd case. In order to stuff in the
2400 names that might contain colons (the usual name delimiter),
2401 Mike Tiemann defined a different name format which is
2402 signalled if the identifier is "op$". In that case, the
2403 format is "op$::XXXX." where XXXX is the name. This is
2404 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2405 /* This lets the user type "break operator+".
2406 We could just put in "+" as the name, but that wouldn't
2408 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2409 char *o
= opname
+ 3;
2411 /* Skip past '::'. */
2413 if (**pp
== '\\') *pp
= next_symbol_text ();
2417 main_fn_name
= savestring (opname
, o
- opname
);
2423 main_fn_name
= savestring (*pp
, p
- *pp
);
2424 /* Skip past '::'. */
2427 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2431 struct next_fnfield
*new_sublist
=
2432 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2434 /* Check for and handle cretinous dbx symbol name continuation! */
2435 if (look_ahead_type
== NULL
) /* Normal case. */
2437 if (**pp
== '\\') *pp
= next_symbol_text ();
2439 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2441 /* Invalid symtab info for method. */
2442 return error_type (pp
);
2445 { /* g++ version 1 kludge */
2446 new_sublist
->fn_field
.type
= look_ahead_type
;
2447 look_ahead_type
= NULL
;
2452 while (*p
!= ';') p
++;
2454 /* If this is just a stub, then we don't have the
2456 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
2457 new_sublist
->fn_field
.is_stub
= 1;
2458 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2461 /* Set this method's visibility fields. */
2462 switch (*(*pp
)++ - '0')
2465 new_sublist
->fn_field
.is_private
= 1;
2468 new_sublist
->fn_field
.is_protected
= 1;
2472 if (**pp
== '\\') *pp
= next_symbol_text ();
2475 case 'A': /* Normal functions. */
2476 new_sublist
->fn_field
.is_const
= 0;
2477 new_sublist
->fn_field
.is_volatile
= 0;
2480 case 'B': /* `const' member functions. */
2481 new_sublist
->fn_field
.is_const
= 1;
2482 new_sublist
->fn_field
.is_volatile
= 0;
2485 case 'C': /* `volatile' member function. */
2486 new_sublist
->fn_field
.is_const
= 0;
2487 new_sublist
->fn_field
.is_volatile
= 1;
2490 case 'D': /* `const volatile' member function. */
2491 new_sublist
->fn_field
.is_const
= 1;
2492 new_sublist
->fn_field
.is_volatile
= 1;
2495 case '*': /* File compiled with g++ version 1 -- no info */
2500 complain (&const_vol_complaint
, (char *) (long) **pp
);
2507 /* virtual member function, followed by index. */
2508 /* The sign bit is set to distinguish pointers-to-methods
2509 from virtual function indicies. Since the array is
2510 in words, the quantity must be shifted left by 1
2511 on 16 bit machine, and by 2 on 32 bit machine, forcing
2512 the sign bit out, and usable as a valid index into
2513 the array. Remove the sign bit here. */
2514 new_sublist
->fn_field
.voffset
=
2515 (0x7fffffff & read_number (pp
, ';')) + 2;
2517 if (**pp
== '\\') *pp
= next_symbol_text ();
2519 if (**pp
== ';' || **pp
== '\0')
2520 /* Must be g++ version 1. */
2521 new_sublist
->fn_field
.fcontext
= 0;
2524 /* Figure out from whence this virtual function came.
2525 It may belong to virtual function table of
2526 one of its baseclasses. */
2527 look_ahead_type
= read_type (pp
, objfile
);
2529 { /* g++ version 1 overloaded methods. */ }
2532 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2534 return error_type (pp
);
2537 look_ahead_type
= NULL
;
2543 /* static member function. */
2544 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2545 if (strncmp (new_sublist
->fn_field
.physname
,
2546 main_fn_name
, strlen (main_fn_name
)))
2547 new_sublist
->fn_field
.is_stub
= 1;
2552 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
2553 /* Fall through into normal member function. */
2556 /* normal member function. */
2557 new_sublist
->fn_field
.voffset
= 0;
2558 new_sublist
->fn_field
.fcontext
= 0;
2562 new_sublist
->next
= sublist
;
2563 sublist
= new_sublist
;
2565 if (**pp
== '\\') *pp
= next_symbol_text ();
2567 while (**pp
!= ';' && **pp
!= '\0');
2571 new_mainlist
->fn_fieldlist
.fn_fields
=
2572 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
2573 sizeof (struct fn_field
) * length
);
2574 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2575 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2577 new_mainlist
->fn_fieldlist
.length
= length
;
2578 new_mainlist
->next
= mainlist
;
2579 mainlist
= new_mainlist
;
2581 total_length
+= length
;
2582 if (**pp
== '\\') *pp
= next_symbol_text ();
2584 while (**pp
!= ';');
2592 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2593 obstack_alloc (&objfile
-> type_obstack
,
2594 sizeof (struct fn_fieldlist
) * nfn_fields
);
2595 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2596 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2601 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2602 TYPE_NFN_FIELDS_TOTAL (type
) +=
2603 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2606 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
2607 --n
; /* Circumvent Sun3 compiler bug */
2608 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
2615 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2617 /* Obsolete flags that used to indicate the presence
2618 of constructors and/or destructors. */
2622 /* Read either a '%' or the final ';'. */
2623 if (*(*pp
)++ == '%')
2625 /* We'd like to be able to derive the vtable pointer field
2626 from the type information, but when it's inherited, that's
2627 hard. A reason it's hard is because we may read in the
2628 info about a derived class before we read in info about
2629 the base class that provides the vtable pointer field.
2630 Once the base info has been read, we could fill in the info
2631 for the derived classes, but for the fact that by then,
2632 we don't remember who needs what. */
2634 int predicted_fieldno
= -1;
2636 /* Now we must record the virtual function table pointer's
2637 field information. */
2645 /* In version 2, we derive the vfield ourselves. */
2646 for (n
= 0; n
< nfields
; n
++)
2648 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2649 sizeof (vptr_name
) -1))
2651 predicted_fieldno
= n
;
2655 if (predicted_fieldno
< 0)
2656 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2657 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2658 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2660 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2666 t
= read_type (pp
, objfile
);
2668 while (*p
!= '\0' && *p
!= ';')
2671 /* Premature end of symbol. */
2672 return error_type (pp
);
2674 TYPE_VPTR_BASETYPE (type
) = t
;
2677 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2679 /* FIXME-tiemann: what's this? */
2681 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2686 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2687 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2688 sizeof (vptr_name
) -1))
2690 TYPE_VPTR_FIELDNO (type
) = i
;
2694 /* Virtual function table field not found. */
2695 return error_type (pp
);
2698 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2701 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2702 error ("TYPE_VPTR_FIELDNO miscalculated");
2712 /* Read a definition of an array type,
2713 and create and return a suitable type object.
2714 Also creates a range type which represents the bounds of that
2716 static struct type
*
2717 read_array_type (pp
, type
, objfile
)
2719 register struct type
*type
;
2720 struct objfile
*objfile
;
2722 struct type
*index_type
, *element_type
, *range_type
;
2726 /* Format of an array type:
2727 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2730 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2731 for these, produce a type like float[][]. */
2733 index_type
= read_type (pp
, objfile
);
2735 /* Improper format of array type decl. */
2736 return error_type (pp
);
2739 if (!(**pp
>= '0' && **pp
<= '9'))
2744 lower
= read_number (pp
, ';');
2746 if (!(**pp
>= '0' && **pp
<= '9'))
2751 upper
= read_number (pp
, ';');
2753 element_type
= read_type (pp
, objfile
);
2762 /* Create range type. */
2763 range_type
= (struct type
*)
2764 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2765 bzero (range_type
, sizeof (struct type
));
2766 TYPE_OBJFILE (range_type
) = objfile
;
2767 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2768 TYPE_TARGET_TYPE (range_type
) = index_type
;
2770 /* This should never be needed. */
2771 TYPE_LENGTH (range_type
) = sizeof (int);
2773 TYPE_NFIELDS (range_type
) = 2;
2774 TYPE_FIELDS (range_type
) =
2775 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2776 2 * sizeof (struct field
));
2777 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2778 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2781 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2782 TYPE_TARGET_TYPE (type
) = element_type
;
2783 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2784 TYPE_NFIELDS (type
) = 1;
2785 TYPE_FIELDS (type
) =
2786 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2787 sizeof (struct field
));
2788 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2790 /* If we have an array whose element type is not yet known, but whose
2791 bounds *are* known, record it to be adjusted at the end of the file. */
2792 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2793 add_undefined_type (type
);
2799 /* Read a definition of an enumeration type,
2800 and create and return a suitable type object.
2801 Also defines the symbols that represent the values of the type. */
2803 static struct type
*
2804 read_enum_type (pp
, type
, objfile
)
2806 register struct type
*type
;
2807 struct objfile
*objfile
;
2812 register struct symbol
*sym
;
2814 struct pending
**symlist
;
2815 struct pending
*osyms
, *syms
;
2818 if (within_function
)
2819 symlist
= &local_symbols
;
2821 symlist
= &file_symbols
;
2823 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2825 /* Read the value-names and their values.
2826 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2827 A semicolon or comma instead of a NAME means the end. */
2828 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2830 /* Check for and handle cretinous dbx symbol name continuation! */
2831 if (**pp
== '\\') *pp
= next_symbol_text ();
2834 while (*p
!= ':') p
++;
2835 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2837 n
= read_number (pp
, ',');
2839 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2840 bzero (sym
, sizeof (struct symbol
));
2841 SYMBOL_NAME (sym
) = name
;
2842 SYMBOL_CLASS (sym
) = LOC_CONST
;
2843 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2844 SYMBOL_VALUE (sym
) = n
;
2845 add_symbol_to_list (sym
, symlist
);
2850 (*pp
)++; /* Skip the semicolon. */
2852 /* Now fill in the fields of the type-structure. */
2854 TYPE_LENGTH (type
) = sizeof (int);
2855 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2856 TYPE_NFIELDS (type
) = nsyms
;
2857 TYPE_FIELDS (type
) = (struct field
*)
2858 obstack_alloc (&objfile
-> type_obstack
,
2859 sizeof (struct field
) * nsyms
);
2861 /* Find the symbols for the values and put them into the type.
2862 The symbols can be found in the symlist that we put them on
2863 to cause them to be defined. osyms contains the old value
2864 of that symlist; everything up to there was defined by us. */
2865 /* Note that we preserve the order of the enum constants, so
2866 that in something like "enum {FOO, LAST_THING=FOO}" we print
2867 FOO, not LAST_THING. */
2869 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2874 for (; j
< syms
->nsyms
; j
++,n
++)
2876 struct symbol
*xsym
= syms
->symbol
[j
];
2877 SYMBOL_TYPE (xsym
) = type
;
2878 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2879 TYPE_FIELD_VALUE (type
, n
) = 0;
2880 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2881 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2888 /* This screws up perfectly good C programs with enums. FIXME. */
2889 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2890 if(TYPE_NFIELDS(type
) == 2 &&
2891 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2892 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2893 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2894 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2895 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2901 /* Read a number from the string pointed to by *PP.
2902 The value of *PP is advanced over the number.
2903 If END is nonzero, the character that ends the
2904 number must match END, or an error happens;
2905 and that character is skipped if it does match.
2906 If END is zero, *PP is left pointing to that character.
2908 If the number fits in a long, set *VALUE and set *BITS to 0.
2909 If not, set *BITS to be the number of bits in the number.
2911 If encounter garbage, set *BITS to -1. */
2914 read_huge_number (pp
, end
, valu
, bits
)
2935 /* Leading zero means octal. GCC uses this to output values larger
2936 than an int (because that would be hard in decimal). */
2943 upper_limit
= LONG_MAX
/ radix
;
2944 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2946 if (n
<= upper_limit
)
2949 n
+= c
- '0'; /* FIXME this overflows anyway */
2954 /* This depends on large values being output in octal, which is
2961 /* Ignore leading zeroes. */
2965 else if (c
== '2' || c
== '3')
2991 /* Large decimal constants are an error (because it is hard to
2992 count how many bits are in them). */
2998 /* -0x7f is the same as 0x80. So deal with it by adding one to
2999 the number of bits. */
3014 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
3015 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
3017 static struct type
*
3018 read_range_type (pp
, typenums
, objfile
)
3021 struct objfile
*objfile
;
3027 struct type
*result_type
;
3029 /* First comes a type we are a subrange of.
3030 In C it is usually 0, 1 or the type being defined. */
3031 read_type_number (pp
, rangenums
);
3032 self_subrange
= (rangenums
[0] == typenums
[0] &&
3033 rangenums
[1] == typenums
[1]);
3035 /* A semicolon should now follow; skip it. */
3039 /* The remaining two operands are usually lower and upper bounds
3040 of the range. But in some special cases they mean something else. */
3041 read_huge_number (pp
, ';', &n2
, &n2bits
);
3042 read_huge_number (pp
, ';', &n3
, &n3bits
);
3044 if (n2bits
== -1 || n3bits
== -1)
3045 return error_type (pp
);
3047 /* If limits are huge, must be large integral type. */
3048 if (n2bits
!= 0 || n3bits
!= 0)
3050 char got_signed
= 0;
3051 char got_unsigned
= 0;
3052 /* Number of bits in the type. */
3055 /* Range from 0 to <large number> is an unsigned large integral type. */
3056 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3061 /* Range from <large number> to <large number>-1 is a large signed
3063 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3069 /* Check for "long long". */
3070 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
3071 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3072 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
3073 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3075 if (got_signed
|| got_unsigned
)
3077 result_type
= (struct type
*)
3078 obstack_alloc (&objfile
-> type_obstack
,
3079 sizeof (struct type
));
3080 bzero (result_type
, sizeof (struct type
));
3081 TYPE_OBJFILE (result_type
) = objfile
;
3082 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
3083 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
3085 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
3089 return error_type (pp
);
3092 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3093 if (self_subrange
&& n2
== 0 && n3
== 0)
3094 return (lookup_fundamental_type (objfile
, FT_VOID
));
3096 /* If n3 is zero and n2 is not, we want a floating type,
3097 and n2 is the width in bytes.
3099 Fortran programs appear to use this for complex types also,
3100 and they give no way to distinguish between double and single-complex!
3101 We don't have complex types, so we would lose on all fortran files!
3102 So return type `double' for all of those. It won't work right
3103 for the complex values, but at least it makes the file loadable.
3105 FIXME, we may be able to distinguish these by their names. FIXME. */
3107 if (n3
== 0 && n2
> 0)
3109 if (n2
== sizeof (float))
3110 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
3111 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
3114 /* If the upper bound is -1, it must really be an unsigned int. */
3116 else if (n2
== 0 && n3
== -1)
3118 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3119 long' is to look at its name! */
3121 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3122 long_kludge_name
[9] == 'l' /* long */)
3123 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3124 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3126 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3129 /* Special case: char is defined (Who knows why) as a subrange of
3130 itself with range 0-127. */
3131 else if (self_subrange
&& n2
== 0 && n3
== 127)
3132 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3134 /* Assumptions made here: Subrange of self is equivalent to subrange
3135 of int. FIXME: Host and target type-sizes assumed the same. */
3136 /* FIXME: This is the *only* place in GDB that depends on comparing
3137 some type to a builtin type with ==. Fix it! */
3139 && (self_subrange
||
3140 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
3142 /* an unsigned type */
3144 if (n3
== - sizeof (long long))
3145 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3147 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3148 long' is to look at its name! */
3149 if (n3
== (unsigned long)~0L &&
3150 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3151 long_kludge_name
[9] == 'l' /* long */)
3152 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3153 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3154 if (n3
== (unsigned int)~0L)
3155 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3156 if (n3
== (unsigned short)~0L)
3157 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
3158 if (n3
== (unsigned char)~0L)
3159 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
3162 else if (n3
== 0 && n2
== -sizeof (long long))
3163 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3165 else if (n2
== -n3
-1)
3168 /* FIXME -- the only way to distinguish `int' from `long' is to look
3170 if ((n3
== (1 << (8 * sizeof (long) - 1)) - 1) &&
3171 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3172 return (lookup_fundamental_type (objfile
, FT_LONG
));
3173 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
3174 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
3175 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
3176 return (lookup_fundamental_type (objfile
, FT_SHORT
));
3177 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
3178 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3181 /* We have a real range type on our hands. Allocate space and
3182 return a real pointer. */
3184 /* At this point I don't have the faintest idea how to deal with
3185 a self_subrange type; I'm going to assume that this is used
3186 as an idiom, and that all of them are special cases. So . . . */
3188 return error_type (pp
);
3190 result_type
= (struct type
*)
3191 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
3192 bzero (result_type
, sizeof (struct type
));
3193 TYPE_OBJFILE (result_type
) = objfile
;
3195 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3197 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3198 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3199 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
3200 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
3203 TYPE_NFIELDS (result_type
) = 2;
3204 TYPE_FIELDS (result_type
) =
3205 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
3206 2 * sizeof (struct field
));
3207 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
3208 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3209 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3211 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3216 /* Read a number from the string pointed to by *PP.
3217 The value of *PP is advanced over the number.
3218 If END is nonzero, the character that ends the
3219 number must match END, or an error happens;
3220 and that character is skipped if it does match.
3221 If END is zero, *PP is left pointing to that character. */
3224 read_number (pp
, end
)
3228 register char *p
= *pp
;
3229 register long n
= 0;
3233 /* Handle an optional leading minus sign. */
3241 /* Read the digits, as far as they go. */
3243 while ((c
= *p
++) >= '0' && c
<= '9')
3251 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3260 /* Read in an argument list. This is a list of types, separated by commas
3261 and terminated with END. Return the list of types read in, or (struct type
3262 **)-1 if there is an error. */
3263 static struct type
**
3264 read_args (pp
, end
, objfile
)
3267 struct objfile
*objfile
;
3269 /* FIXME! Remove this arbitrary limit! */
3270 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3276 /* Invalid argument list: no ','. */
3277 return (struct type
**)-1;
3280 /* Check for and handle cretinous dbx symbol name continuation! */
3282 *pp
= next_symbol_text ();
3284 types
[n
++] = read_type (pp
, objfile
);
3286 *pp
+= 1; /* get past `end' (the ':' character) */
3290 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3292 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3294 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3295 bzero (rval
+ n
, sizeof (struct type
*));
3299 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3301 memcpy (rval
, types
, n
* sizeof (struct type
*));
3305 /* Add a common block's start address to the offset of each symbol
3306 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3307 the common block name). */
3310 fix_common_block (sym
, valu
)
3314 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3315 for ( ; next
; next
= next
->next
)
3318 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3319 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3323 /* Initializer for this module */
3325 _initialize_buildsym ()
3327 undef_types_allocated
= 20;
3328 undef_types_length
= 0;
3329 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3330 sizeof (struct type
*));