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. */
32 #include "breakpoint.h"
33 #include "gdbcore.h" /* for bfd stuff for symfile.h */
34 #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 */
679 file_stabs
= 0; /* AIX COFF */
682 /* Context stack is initially empty. Allocate first one with room for
683 10 levels; reuse it forever afterward. */
684 if (context_stack
== 0) {
685 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
686 context_stack
= (struct context_stack
*)
687 xmalloc (context_stack_size
* sizeof (struct context_stack
));
689 context_stack_depth
= 0;
691 /* Leave FILENUM of 0 free for builtin types and this file's types. */
692 n_this_object_header_files
= 1;
693 header_file_prev_index
= -1;
695 type_vector_length
= 0;
696 type_vector
= (struct type
**) 0;
698 /* Initialize the list of sub source files with one entry
699 for this file (the top-level source file). */
703 start_subfile (name
, dirname
);
706 /* for all the stabs in a given stab vector, build appropriate types
707 and fix their symbols in given symbol vector. */
710 patch_block_stabs (symbols
, stabs
, objfile
)
711 struct pending
*symbols
;
712 struct pending_stabs
*stabs
;
713 struct objfile
*objfile
;
720 /* for all the stab entries, find their corresponding symbols and
721 patch their types! */
723 for (ii
= 0; ii
< stabs
->count
; ++ii
)
725 char *name
= stabs
->stab
[ii
];
726 char *pp
= (char*) strchr (name
, ':');
727 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
730 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
735 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
738 lookup_function_type (read_type (&pp
, objfile
));
742 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
749 /* Finish the symbol definitions for one main source file,
750 close off all the lexical contexts for that file
751 (creating struct block's for them), then make the struct symtab
752 for that file and put it in the list of all such.
754 END_ADDR is the address of the end of the file's text. */
757 end_symtab (end_addr
, sort_pending
, sort_linevec
, objfile
)
761 struct objfile
*objfile
;
763 register struct symtab
*symtab
;
764 register struct blockvector
*blockvector
;
765 register struct subfile
*subfile
;
766 struct subfile
*nextsub
;
768 /* Finish the lexical context of the last function in the file;
769 pop the context stack. */
771 if (context_stack_depth
> 0)
773 register struct context_stack
*cstk
;
774 context_stack_depth
--;
775 cstk
= &context_stack
[context_stack_depth
];
776 /* Make a block for the local symbols within. */
777 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
778 cstk
->start_addr
, end_addr
, objfile
);
780 /* Debug: if context stack still has something in it, we are in
782 if (context_stack_depth
> 0)
786 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
787 in this stage. Especially, blocks for static functions will show up at
788 the end. We need to sort them, so tools like `find_pc_function' and
789 `find_pc_block' can work reliably. */
790 if (sort_pending
&& pending_blocks
) {
791 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
794 struct pending_block
*pb
, *pbnext
;
796 pb
= pending_blocks
, pbnext
= pb
->next
;
801 /* swap blocks if unordered! */
803 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
)) {
804 struct block
*tmp
= pb
->block
;
805 pb
->block
= pbnext
->block
;
810 pbnext
= pbnext
->next
;
815 /* Cleanup any undefined types that have been left hanging around
816 (this needs to be done before the finish_blocks so that
817 file_symbols is still good). */
818 cleanup_undefined_types ();
820 /* Hooks for xcoffread.c */
822 patch_block_stabs (file_symbols
, file_stabs
, objfile
);
828 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
833 if (pending_blocks
== 0
835 && global_symbols
== 0) {
836 /* Ignore symtabs that have no functions with real debugging info */
839 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
840 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
841 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
842 blockvector
= make_blockvector (objfile
);
845 /* Now create the symtab objects proper, one for each subfile. */
846 /* (The main file is the last one on the chain.) */
848 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
851 /* If we have blocks of symbols, make a symtab.
852 Otherwise, just ignore this file and any line number info in it. */
855 if (subfile
->line_vector
) {
856 /* First, shrink the linetable to make more memory. */
857 linetablesize
= sizeof (struct linetable
) +
858 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
859 subfile
->line_vector
= (struct linetable
*)
860 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
863 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
864 sizeof (struct linetable_entry
), compare_line_numbers
);
867 /* Now, allocate a symbol table. */
868 symtab
= allocate_symtab (subfile
->name
, objfile
);
870 /* Fill in its components. */
871 symtab
->blockvector
= blockvector
;
872 if (subfile
->line_vector
)
874 /* Reallocate the line table on the symbol obstack */
875 symtab
->linetable
= (struct linetable
*)
876 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
877 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
881 symtab
->linetable
= NULL
;
883 symtab
->dirname
= subfile
->dirname
;
884 symtab
->free_code
= free_linetable
;
885 symtab
->free_ptr
= 0;
887 if (subfile
->line_vector
)
888 free (subfile
->line_vector
);
890 nextsub
= subfile
->next
;
895 free ((char *) type_vector
);
897 type_vector_length
= 0;
899 last_source_file
= 0;
901 previous_stab_code
= 0;
907 /* Push a context block. Args are an identifying nesting level (checkable
908 when you pop it), and the starting PC address of this context. */
910 struct context_stack
*
911 push_context (desc
, valu
)
915 register struct context_stack
*new;
917 if (context_stack_depth
== context_stack_size
)
919 context_stack_size
*= 2;
920 context_stack
= (struct context_stack
*)
921 xrealloc ((char *) context_stack
,
922 (context_stack_size
* sizeof (struct context_stack
)));
925 new = &context_stack
[context_stack_depth
++];
927 new->locals
= local_symbols
;
928 new->old_blocks
= pending_blocks
;
929 new->start_addr
= valu
;
937 /* Initialize anything that needs initializing when starting to read
938 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
950 /* Initialize anything that needs initializing when a completely new
951 symbol file is specified (not just adding some symbols from another
952 file, e.g. a shared library). */
957 /* Empty the hash table of global syms looking for values. */
958 bzero (global_sym_chain
, sizeof global_sym_chain
);
963 /* Scan through all of the global symbols defined in the object file,
964 assigning values to the debugging symbols that need to be assigned
965 to. Get these symbols from the minimal symbol table. */
968 scan_file_globals (objfile
)
969 struct objfile
*objfile
;
973 struct minimal_symbol
*msymbol
;
974 struct symbol
*sym
, *prev
;
976 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
980 prev
= (struct symbol
*) 0;
982 /* Get the hash index and check all the symbols
983 under that hash index. */
985 hash
= hashname (msymbol
-> name
);
987 for (sym
= global_sym_chain
[hash
]; sym
;)
989 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
990 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
992 /* Splice this symbol out of the hash chain and
993 assign the value we have to it. */
995 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
997 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
999 /* Check to see whether we need to fix up a common block. */
1000 /* Note: this code might be executed several times for
1001 the same symbol if there are multiple references. */
1002 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1003 fix_common_block (sym
, msymbol
-> address
);
1005 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
1008 sym
= SYMBOL_VALUE_CHAIN (prev
);
1010 sym
= global_sym_chain
[hash
];
1015 sym
= SYMBOL_VALUE_CHAIN (sym
);
1022 /* Read a number by which a type is referred to in dbx data,
1023 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1024 Just a single number N is equivalent to (0,N).
1025 Return the two numbers by storing them in the vector TYPENUMS.
1026 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1029 read_type_number (pp
, typenums
)
1031 register int *typenums
;
1036 typenums
[0] = read_number (pp
, ',');
1037 typenums
[1] = read_number (pp
, ')');
1042 typenums
[1] = read_number (pp
, 0);
1046 /* To handle GNU C++ typename abbreviation, we need to be able to
1047 fill in a type's name as soon as space for that type is allocated.
1048 `type_synonym_name' is the name of the type being allocated.
1049 It is cleared as soon as it is used (lest all allocated types
1051 static char *type_synonym_name
;
1055 define_symbol (valu
, string
, desc
, type
, objfile
)
1060 struct objfile
*objfile
;
1062 register struct symbol
*sym
;
1063 char *p
= (char *) strchr (string
, ':');
1067 struct type
*temptype
;
1069 /* Ignore syms with empty names. */
1073 /* Ignore old-style symbols from cc -go */
1077 sym
= (struct symbol
*)obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1079 if (processing_gcc_compilation
) {
1080 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1081 number of bytes occupied by a type or object, which we ignore. */
1082 SYMBOL_LINE(sym
) = desc
;
1084 SYMBOL_LINE(sym
) = 0; /* unknown */
1087 if (string
[0] == CPLUS_MARKER
)
1089 /* Special GNU C++ names. */
1093 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1094 &objfile
-> symbol_obstack
);
1096 case 'v': /* $vtbl_ptr_type */
1097 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1100 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1101 &objfile
-> symbol_obstack
);
1105 /* This was an anonymous type that was never fixed up. */
1116 = (char *) obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1117 /* Open-coded bcopy--saves function call time. */
1119 register char *p1
= string
;
1120 register char *p2
= SYMBOL_NAME (sym
);
1127 /* Determine the type of name being defined. */
1128 /* The Acorn RISC machine's compiler can put out locals that don't
1129 start with "234=" or "(3,4)=", so assume anything other than the
1130 deftypes we know how to handle is a local. */
1131 /* (Peter Watkins @ Computervision)
1132 Handle Sun-style local fortran array types 'ar...' .
1133 (gnu@cygnus.com) -- this strchr() handles them properly?
1134 (tiemann@cygnus.com) -- 'C' is for catch. */
1135 if (!strchr ("cfFGpPrStTvVXC", *p
))
1140 /* c is a special case, not followed by a type-number.
1141 SYMBOL:c=iVALUE for an integer constant symbol.
1142 SYMBOL:c=rVALUE for a floating constant symbol.
1143 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1144 e.g. "b:c=e6,0" for "const b = blob1"
1145 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1149 error ("Invalid symbol data at symtab pos %d.", symnum
);
1154 double d
= atof (p
);
1157 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1160 obstack_alloc (&objfile
-> type_obstack
,
1162 memcpy (dbl_valu
, &d
, sizeof (double));
1163 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1164 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1165 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1170 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1172 SYMBOL_VALUE (sym
) = atoi (p
);
1173 SYMBOL_CLASS (sym
) = LOC_CONST
;
1177 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1178 e.g. "b:c=e6,0" for "const b = blob1"
1179 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1183 read_type_number (&p
, typenums
);
1185 error ("Invalid symbol data: no comma in enum const symbol");
1187 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1188 SYMBOL_VALUE (sym
) = atoi (p
);
1189 SYMBOL_CLASS (sym
) = LOC_CONST
;
1193 error ("Invalid symbol data at symtab pos %d.", symnum
);
1195 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1196 add_symbol_to_list (sym
, &file_symbols
);
1200 /* Now usually comes a number that says which data type,
1201 and possibly more stuff to define the type
1202 (all of which is handled by read_type) */
1204 if (deftype
== 'p' && *p
== 'F')
1205 /* pF is a two-letter code that means a function parameter in Fortran.
1206 The type-number specifies the type of the return value.
1207 Translate it into a pointer-to-function type. */
1211 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
1215 struct type
*type_read
;
1216 synonym
= *p
== 't';
1221 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1222 strlen (SYMBOL_NAME (sym
)),
1223 &objfile
-> symbol_obstack
);
1226 /* Here we save the name of the symbol for read_range_type, which
1227 ends up reading in the basic types. In stabs, unfortunately there
1228 is no distinction between "int" and "long" types except their
1229 names. Until we work out a saner type policy (eliminating most
1230 builtin types and using the names specified in the files), we
1231 save away the name so that far away from here in read_range_type,
1232 we can examine it to decide between "int" and "long". FIXME. */
1233 long_kludge_name
= SYMBOL_NAME (sym
);
1234 type_read
= read_type (&p
, objfile
);
1236 if ((deftype
== 'F' || deftype
== 'f')
1237 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
1240 /* This code doesn't work -- it needs to realloc and can't. */
1241 struct type
*new = (struct type
*)
1242 obstack_alloc (&objfile
-> type_obstack
,
1243 sizeof (struct type
));
1245 /* Generate a template for the type of this function. The
1246 types of the arguments will be added as we read the symbol
1248 *new = *lookup_function_type (type_read
);
1249 SYMBOL_TYPE(sym
) = new;
1250 TYPE_OBJFILE (new) = objfile
;
1251 in_function_type
= new;
1253 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
1257 SYMBOL_TYPE (sym
) = type_read
;
1263 /* The name of a caught exception. */
1264 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1265 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1266 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1267 add_symbol_to_list (sym
, &local_symbols
);
1271 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1272 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1273 add_symbol_to_list (sym
, &file_symbols
);
1277 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1278 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1279 add_symbol_to_list (sym
, &global_symbols
);
1283 /* For a class G (global) symbol, it appears that the
1284 value is not correct. It is necessary to search for the
1285 corresponding linker definition to find the value.
1286 These definitions appear at the end of the namelist. */
1287 i
= hashname (SYMBOL_NAME (sym
));
1288 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1289 global_sym_chain
[i
] = sym
;
1290 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1291 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1292 add_symbol_to_list (sym
, &global_symbols
);
1295 /* This case is faked by a conditional above,
1296 when there is no code letter in the dbx data.
1297 Dbx data never actually contains 'l'. */
1299 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1300 SYMBOL_VALUE (sym
) = valu
;
1301 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1302 add_symbol_to_list (sym
, &local_symbols
);
1306 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1307 can also be a LOC_LOCAL_ARG depending on symbol type. */
1308 #ifndef DBX_PARM_SYMBOL_CLASS
1309 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1311 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1312 SYMBOL_VALUE (sym
) = valu
;
1313 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1315 /* This doesn't work yet. */
1316 add_param_to_type (&in_function_type
, sym
);
1318 add_symbol_to_list (sym
, &local_symbols
);
1320 /* If it's gcc-compiled, if it says `short', believe it. */
1321 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1324 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1325 /* This macro is defined on machines (e.g. sparc) where
1326 we should believe the type of a PCC 'short' argument,
1327 but shouldn't believe the address (the address is
1328 the address of the corresponding int). Note that
1329 this is only different from the BELIEVE_PCC_PROMOTION
1330 case on big-endian machines.
1332 My guess is that this correction, as opposed to changing
1333 the parameter to an 'int' (as done below, for PCC
1334 on most machines), is the right thing to do
1335 on all machines, but I don't want to risk breaking
1336 something that already works. On most PCC machines,
1337 the sparc problem doesn't come up because the calling
1338 function has to zero the top bytes (not knowing whether
1339 the called function wants an int or a short), so there
1340 is no practical difference between an int and a short
1341 (except perhaps what happens when the GDB user types
1342 "print short_arg = 0x10000;").
1344 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1345 actually produces the correct address (we don't need to fix it
1346 up). I made this code adapt so that it will offset the symbol
1347 if it was pointing at an int-aligned location and not
1348 otherwise. This way you can use the same gdb for 4.0.x and
1351 If the parameter is shorter than an int, and is integral
1352 (e.g. char, short, or unsigned equivalent), and is claimed to
1353 be passed on an integer boundary, don't believe it! Offset the
1354 parameter's address to the tail-end of that integer. */
1356 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1357 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1358 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1359 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
1361 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
1362 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1366 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1368 /* If PCC says a parameter is a short or a char,
1369 it is really an int. */
1370 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1371 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1372 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1374 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1375 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
1380 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1383 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1384 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1385 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1386 add_symbol_to_list (sym
, &local_symbols
);
1390 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1391 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1392 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1393 add_symbol_to_list (sym
, &local_symbols
);
1397 /* Static symbol at top level of file */
1398 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1399 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1400 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1401 add_symbol_to_list (sym
, &file_symbols
);
1405 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1406 SYMBOL_VALUE (sym
) = valu
;
1407 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1408 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1409 TYPE_NAME (SYMBOL_TYPE (sym
)) =
1410 obsavestring (SYMBOL_NAME (sym
),
1411 strlen (SYMBOL_NAME (sym
)),
1412 &objfile
-> symbol_obstack
);
1413 /* C++ vagaries: we may have a type which is derived from
1414 a base type which did not have its name defined when the
1415 derived class was output. We fill in the derived class's
1416 base part member's name here in that case. */
1417 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1418 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1419 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1422 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1423 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1424 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1425 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1428 add_symbol_to_list (sym
, &file_symbols
);
1432 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1433 SYMBOL_VALUE (sym
) = valu
;
1434 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1435 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1436 TYPE_NAME (SYMBOL_TYPE (sym
))
1437 = obconcat (&objfile
-> type_obstack
, "",
1438 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1440 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1441 ? "struct " : "union ")),
1443 add_symbol_to_list (sym
, &file_symbols
);
1447 register struct symbol
*typedef_sym
= (struct symbol
*)
1448 obstack_alloc (&objfile
-> type_obstack
,
1449 sizeof (struct symbol
));
1450 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1451 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1453 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1454 SYMBOL_VALUE (typedef_sym
) = valu
;
1455 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1456 add_symbol_to_list (typedef_sym
, &file_symbols
);
1461 /* Static symbol of local scope */
1462 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1463 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1464 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1465 add_symbol_to_list (sym
, &local_symbols
);
1469 /* Reference parameter */
1470 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1471 SYMBOL_VALUE (sym
) = valu
;
1472 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1473 add_symbol_to_list (sym
, &local_symbols
);
1477 /* This is used by Sun FORTRAN for "function result value".
1478 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1479 that Pascal uses it too, but when I tried it Pascal used
1480 "x:3" (local symbol) instead. */
1481 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1482 SYMBOL_VALUE (sym
) = valu
;
1483 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1484 add_symbol_to_list (sym
, &local_symbols
);
1488 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1493 /* What about types defined as forward references inside of a small lexical
1495 /* Add a type to the list of undefined types to be checked through
1496 once this file has been read in. */
1498 add_undefined_type (type
)
1501 if (undef_types_length
== undef_types_allocated
)
1503 undef_types_allocated
*= 2;
1504 undef_types
= (struct type
**)
1505 xrealloc ((char *) undef_types
,
1506 undef_types_allocated
* sizeof (struct type
*));
1508 undef_types
[undef_types_length
++] = type
;
1511 /* Go through each undefined type, see if it's still undefined, and fix it
1512 up if possible. We have two kinds of undefined types:
1514 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1515 Fix: update array length using the element bounds
1516 and the target type's length.
1517 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1518 yet defined at the time a pointer to it was made.
1519 Fix: Do a full lookup on the struct/union tag. */
1521 cleanup_undefined_types ()
1525 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1526 switch (TYPE_CODE (*type
)) {
1528 case TYPE_CODE_STRUCT
:
1529 case TYPE_CODE_UNION
:
1530 case TYPE_CODE_ENUM
:
1532 /* Reasonable test to see if it's been defined since. */
1533 if (TYPE_NFIELDS (*type
) == 0)
1535 struct pending
*ppt
;
1537 /* Name of the type, without "struct" or "union" */
1538 char *typename
= TYPE_NAME (*type
);
1540 if (!strncmp (typename
, "struct ", 7))
1542 if (!strncmp (typename
, "union ", 6))
1544 if (!strncmp (typename
, "enum ", 5))
1547 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1548 for (i
= 0; i
< ppt
->nsyms
; i
++)
1550 struct symbol
*sym
= ppt
->symbol
[i
];
1552 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1553 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1554 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1556 && !strcmp (SYMBOL_NAME (sym
), typename
))
1557 memcpy (*type
, SYMBOL_TYPE (sym
), sizeof (struct type
));
1561 /* It has been defined; don't mark it as a stub. */
1562 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1566 case TYPE_CODE_ARRAY
:
1568 struct type
*range_type
;
1571 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1573 if (TYPE_NFIELDS (*type
) != 1)
1575 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1576 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1579 /* Now recompute the length of the array type, based on its
1580 number of elements and the target type's length. */
1581 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1582 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1583 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1584 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1590 error ("GDB internal error. cleanup_undefined_types with bad\
1591 type %d.", TYPE_CODE (*type
));
1595 undef_types_length
= 0;
1598 /* Skip rest of this symbol and return an error type.
1600 General notes on error recovery: error_type always skips to the
1601 end of the symbol (modulo cretinous dbx symbol name continuation).
1602 Thus code like this:
1604 if (*(*pp)++ != ';')
1605 return error_type (pp);
1607 is wrong because if *pp starts out pointing at '\0' (typically as the
1608 result of an earlier error), it will be incremented to point to the
1609 start of the next symbol, which might produce strange results, at least
1610 if you run off the end of the string table. Instead use
1613 return error_type (pp);
1619 foo = error_type (pp);
1623 And in case it isn't obvious, the point of all this hair is so the compiler
1624 can define new types and new syntaxes, and old versions of the
1625 debugger will be able to read the new symbol tables. */
1631 complain (&error_type_complaint
, 0);
1634 /* Skip to end of symbol. */
1635 while (**pp
!= '\0')
1638 /* Check for and handle cretinous dbx symbol name continuation! */
1639 if ((*pp
)[-1] == '\\')
1640 *pp
= next_symbol_text ();
1644 return builtin_type_error
;
1647 /* Read a dbx type reference or definition;
1648 return the type that is meant.
1649 This can be just a number, in which case it references
1650 a type already defined and placed in type_vector.
1651 Or the number can be followed by an =, in which case
1652 it means to define a new type according to the text that
1656 read_type (pp
, objfile
)
1658 struct objfile
*objfile
;
1660 register struct type
*type
= 0;
1665 /* Read type number if present. The type number may be omitted.
1666 for instance in a two-dimensional array declared with type
1667 "ar1;1;10;ar1;1;10;4". */
1668 if ((**pp
>= '0' && **pp
<= '9')
1671 read_type_number (pp
, typenums
);
1673 /* Type is not being defined here. Either it already exists,
1674 or this is a forward reference to it. dbx_alloc_type handles
1677 return dbx_alloc_type (typenums
, objfile
);
1679 /* Type is being defined here. */
1680 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1684 /* if such a type already exists, this is an unnecessary duplication
1685 of the stab string, which is common in (RS/6000) xlc generated
1686 objects. In that case, simply return NULL and let the caller take
1689 tt
= *dbx_lookup_type (typenums
);
1690 if (tt
&& tt
->length
&& tt
->code
)
1699 /* 'typenums=' not present, type is anonymous. Read and return
1700 the definition, but don't put it in the type vector. */
1701 typenums
[0] = typenums
[1] = -1;
1709 enum type_code code
;
1711 /* Used to index through file_symbols. */
1712 struct pending
*ppt
;
1715 /* Name including "struct", etc. */
1718 /* Name without "struct", etc. */
1719 char *type_name_only
;
1725 /* Set the type code according to the following letter. */
1729 code
= TYPE_CODE_STRUCT
;
1733 code
= TYPE_CODE_UNION
;
1737 code
= TYPE_CODE_ENUM
;
1741 return error_type (pp
);
1744 to
= type_name
= (char *)
1745 obstack_alloc (&objfile
-> type_obstack
,
1747 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1749 /* Copy the prefix. */
1751 while (*to
++ = *from
++)
1755 type_name_only
= to
;
1757 /* Copy the name. */
1759 while ((*to
++ = *from
++) != ':')
1763 /* Set the pointer ahead of the name which we just read. */
1767 /* The following hack is clearly wrong, because it doesn't
1768 check whether we are in a baseclass. I tried to reproduce
1769 the case that it is trying to fix, but I couldn't get
1770 g++ to put out a cross reference to a basetype. Perhaps
1771 it doesn't do it anymore. */
1772 /* Note: for C++, the cross reference may be to a base type which
1773 has not yet been seen. In this case, we skip to the comma,
1774 which will mark the end of the base class name. (The ':'
1775 at the end of the base class name will be skipped as well.)
1776 But sometimes (ie. when the cross ref is the last thing on
1777 the line) there will be no ','. */
1778 from
= (char *) strchr (*pp
, ',');
1784 /* Now check to see whether the type has already been declared. */
1785 /* This is necessary at least in the case where the
1786 program says something like
1788 The compiler puts out a cross-reference; we better find
1789 set the length of the structure correctly so we can
1790 set the length of the array. */
1791 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1792 for (i
= 0; i
< ppt
->nsyms
; i
++)
1794 struct symbol
*sym
= ppt
->symbol
[i
];
1796 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1797 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1798 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1799 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1801 obstack_free (&objfile
-> type_obstack
, type_name
);
1802 type
= SYMBOL_TYPE (sym
);
1807 /* Didn't find the type to which this refers, so we must
1808 be dealing with a forward reference. Allocate a type
1809 structure for it, and keep track of it so we can
1810 fill in the rest of the fields when we get the full
1812 type
= dbx_alloc_type (typenums
, objfile
);
1813 TYPE_CODE (type
) = code
;
1814 TYPE_NAME (type
) = type_name
;
1815 INIT_CPLUS_SPECIFIC(type
);
1816 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1818 add_undefined_type (type
);
1822 case '-': /* RS/6000 built-in type */
1824 type
= builtin_type (pp
); /* (in xcoffread.c) */
1839 read_type_number (pp
, xtypenums
);
1840 type
= *dbx_lookup_type (xtypenums
);
1845 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1846 if (typenums
[0] != -1)
1847 *dbx_lookup_type (typenums
) = type
;
1851 type1
= read_type (pp
, objfile
);
1852 /* FIXME -- we should be doing smash_to_XXX types here. */
1854 /* postponed type decoration should be allowed. */
1855 if (typenums
[1] > 0 && typenums
[1] < type_vector_length
&&
1856 (type
= type_vector
[typenums
[1]])) {
1857 smash_to_pointer_type (type
, type1
);
1861 type
= lookup_pointer_type (type1
);
1862 if (typenums
[0] != -1)
1863 *dbx_lookup_type (typenums
) = type
;
1868 struct type
*domain
= read_type (pp
, objfile
);
1869 struct type
*memtype
;
1872 /* Invalid member type data format. */
1873 return error_type (pp
);
1876 memtype
= read_type (pp
, objfile
);
1877 type
= dbx_alloc_type (typenums
, objfile
);
1878 smash_to_member_type (type
, domain
, memtype
);
1883 if ((*pp
)[0] == '#')
1885 /* We'll get the parameter types from the name. */
1886 struct type
*return_type
;
1889 return_type
= read_type (pp
, objfile
);
1890 if (*(*pp
)++ != ';')
1891 complain (&invalid_member_complaint
, (char *) symnum
);
1892 type
= allocate_stub_method (return_type
);
1893 if (typenums
[0] != -1)
1894 *dbx_lookup_type (typenums
) = type
;
1898 struct type
*domain
= read_type (pp
, objfile
);
1899 struct type
*return_type
;
1902 if (*(*pp
)++ != ',')
1903 error ("invalid member type data format, at symtab pos %d.",
1906 return_type
= read_type (pp
, objfile
);
1907 args
= read_args (pp
, ';', objfile
);
1908 type
= dbx_alloc_type (typenums
, objfile
);
1909 smash_to_method_type (type
, domain
, return_type
, args
);
1914 type1
= read_type (pp
, objfile
);
1915 type
= lookup_reference_type (type1
);
1916 if (typenums
[0] != -1)
1917 *dbx_lookup_type (typenums
) = type
;
1921 type1
= read_type (pp
, objfile
);
1922 type
= lookup_function_type (type1
);
1923 if (typenums
[0] != -1)
1924 *dbx_lookup_type (typenums
) = type
;
1928 type
= read_range_type (pp
, typenums
, objfile
);
1929 if (typenums
[0] != -1)
1930 *dbx_lookup_type (typenums
) = type
;
1934 type
= dbx_alloc_type (typenums
, objfile
);
1935 type
= read_enum_type (pp
, type
, objfile
);
1936 *dbx_lookup_type (typenums
) = type
;
1940 type
= dbx_alloc_type (typenums
, objfile
);
1941 TYPE_NAME (type
) = type_synonym_name
;
1942 type_synonym_name
= 0;
1943 type
= read_struct_type (pp
, type
, objfile
);
1947 type
= dbx_alloc_type (typenums
, objfile
);
1948 TYPE_NAME (type
) = type_synonym_name
;
1949 type_synonym_name
= 0;
1950 type
= read_struct_type (pp
, type
, objfile
);
1951 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1956 return error_type (pp
);
1959 type
= dbx_alloc_type (typenums
, objfile
);
1960 type
= read_array_type (pp
, type
, objfile
);
1964 --*pp
; /* Go back to the symbol in error */
1965 /* Particularly important if it was \0! */
1966 return error_type (pp
);
1973 /* If this is an overriding temporary alteration for a header file's
1974 contents, and this type number is unknown in the global definition,
1975 put this type into the global definition at this type number. */
1976 if (header_file_prev_index
>= 0)
1978 register struct type
**tp
1979 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
1987 /* This page contains subroutines of read_type. */
1989 /* Read the description of a structure (or union type)
1990 and return an object describing the type. */
1992 static struct type
*
1993 read_struct_type (pp
, type
, objfile
)
1995 register struct type
*type
;
1996 struct objfile
*objfile
;
1998 /* Total number of methods defined in this class.
1999 If the class defines two `f' methods, and one `g' method,
2000 then this will have the value 3. */
2001 int total_length
= 0;
2005 struct nextfield
*next
;
2006 int visibility
; /* 0=public, 1=protected, 2=public */
2012 struct next_fnfield
*next
;
2013 struct fn_field fn_field
;
2016 struct next_fnfieldlist
2018 struct next_fnfieldlist
*next
;
2019 struct fn_fieldlist fn_fieldlist
;
2022 register struct nextfield
*list
= 0;
2023 struct nextfield
*new;
2026 int non_public_fields
= 0;
2029 register struct next_fnfieldlist
*mainlist
= 0;
2032 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2033 INIT_CPLUS_SPECIFIC(type
);
2035 /* First comes the total size in bytes. */
2037 TYPE_LENGTH (type
) = read_number (pp
, 0);
2039 /* C++: Now, if the class is a derived class, then the next character
2040 will be a '!', followed by the number of base classes derived from.
2041 Each element in the list contains visibility information,
2042 the offset of this base class in the derived structure,
2043 and then the base type. */
2046 int i
, n_baseclasses
, offset
;
2047 struct type
*baseclass
;
2050 /* Nonzero if it is a virtual baseclass, i.e.,
2054 struct C : public B, public virtual A {};
2056 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2057 2.0 language feature. */
2062 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
2064 n_baseclasses
= read_number (pp
, ',');
2065 TYPE_FIELD_VIRTUAL_BITS (type
) =
2066 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2067 B_BYTES (n_baseclasses
));
2068 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
2070 for (i
= 0; i
< n_baseclasses
; i
++)
2073 *pp
= next_symbol_text ();
2084 /* Bad visibility format. */
2085 return error_type (pp
);
2093 non_public_fields
++;
2099 /* Bad visibility format. */
2100 return error_type (pp
);
2103 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2106 /* Offset of the portion of the object corresponding to
2107 this baseclass. Always zero in the absence of
2108 multiple inheritance. */
2109 offset
= read_number (pp
, ',');
2110 baseclass
= read_type (pp
, objfile
);
2111 *pp
+= 1; /* skip trailing ';' */
2113 /* Make this baseclass visible for structure-printing purposes. */
2114 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2117 list
->visibility
= via_public
;
2118 list
->field
.type
= baseclass
;
2119 list
->field
.name
= type_name_no_tag (baseclass
);
2120 list
->field
.bitpos
= offset
;
2121 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2124 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
2127 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2128 At the end, we see a semicolon instead of a field.
2130 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2133 The `?' is a placeholder for one of '/2' (public visibility),
2134 '/1' (protected visibility), '/0' (private visibility), or nothing
2135 (C style symbol table, public visibility). */
2137 /* We better set p right now, in case there are no fields at all... */
2142 /* Check for and handle cretinous dbx symbol name continuation! */
2143 if (**pp
== '\\') *pp
= next_symbol_text ();
2145 /* Get space to record the next field's data. */
2146 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2150 /* Get the field name. */
2152 if (*p
== CPLUS_MARKER
)
2154 /* Special GNU C++ name. */
2159 struct type
*context
;
2170 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2171 prefix
= "INVALID_C++_ABBREV";
2175 context
= read_type (pp
, objfile
);
2176 name
= type_name_no_tag (context
);
2179 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
2180 TYPE_NAME (context
) = name
;
2182 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
2186 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2187 list
->field
.type
= read_type (pp
, objfile
);
2188 (*pp
)++; /* Skip the comma. */
2189 list
->field
.bitpos
= read_number (pp
, ';');
2190 /* This field is unpacked. */
2191 list
->field
.bitsize
= 0;
2192 list
->visibility
= 0; /* private */
2193 non_public_fields
++;
2195 /* GNU C++ anonymous type. */
2199 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2205 while (*p
!= ':') p
++;
2206 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
2207 &objfile
-> type_obstack
);
2209 /* C++: Check to see if we have hit the methods yet. */
2215 /* This means we have a visibility for a field coming. */
2221 list
->visibility
= 0; /* private */
2222 non_public_fields
++;
2227 list
->visibility
= 1; /* protected */
2228 non_public_fields
++;
2233 list
->visibility
= 2; /* public */
2238 else /* normal dbx-style format. */
2239 list
->visibility
= 2; /* public */
2241 list
->field
.type
= read_type (pp
, objfile
);
2244 /* Static class member. */
2245 list
->field
.bitpos
= (long)-1;
2247 while (*p
!= ';') p
++;
2248 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2253 else if (**pp
!= ',')
2254 /* Bad structure-type format. */
2255 return error_type (pp
);
2257 (*pp
)++; /* Skip the comma. */
2258 list
->field
.bitpos
= read_number (pp
, ',');
2259 list
->field
.bitsize
= read_number (pp
, ';');
2262 /* FIXME-tiemann: Can't the compiler put out something which
2263 lets us distinguish these? (or maybe just not put out anything
2264 for the field). What is the story here? What does the compiler
2265 really do? Also, patch gdb.texinfo for this case; I document
2266 it as a possible problem there. Search for "DBX-style". */
2268 /* This is wrong because this is identical to the symbols
2269 produced for GCC 0-size arrays. For example:
2274 The code which dumped core in such circumstances should be
2275 fixed not to dump core. */
2277 /* g++ -g0 can put out bitpos & bitsize zero for a static
2278 field. This does not give us any way of getting its
2279 class, so we can't know its name. But we can just
2280 ignore the field so we don't dump core and other nasty
2282 if (list
->field
.bitpos
== 0
2283 && list
->field
.bitsize
== 0)
2285 complain (&dbx_class_complaint
, 0);
2286 /* Ignore this field. */
2292 /* Detect an unpacked field and mark it as such.
2293 dbx gives a bit size for all fields.
2294 Note that forward refs cannot be packed,
2295 and treat enums as if they had the width of ints. */
2296 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2297 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2298 list
->field
.bitsize
= 0;
2299 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2300 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2301 && (list
->field
.bitsize
2302 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
2306 list
->field
.bitpos
% 8 == 0)
2307 list
->field
.bitsize
= 0;
2313 /* chill the list of fields: the last entry (at the head)
2314 is a partially constructed entry which we now scrub. */
2317 /* Now create the vector of fields, and record how big it is.
2318 We need this info to record proper virtual function table information
2319 for this class's virtual functions. */
2321 TYPE_NFIELDS (type
) = nfields
;
2322 TYPE_FIELDS (type
) = (struct field
*)
2323 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
2325 if (non_public_fields
)
2327 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2329 TYPE_FIELD_PRIVATE_BITS (type
) =
2330 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2332 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2334 TYPE_FIELD_PROTECTED_BITS (type
) =
2335 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2337 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2340 /* Copy the saved-up fields into the field vector. */
2342 for (n
= nfields
; list
; list
= list
->next
)
2345 TYPE_FIELD (type
, n
) = list
->field
;
2346 if (list
->visibility
== 0)
2347 SET_TYPE_FIELD_PRIVATE (type
, n
);
2348 else if (list
->visibility
== 1)
2349 SET_TYPE_FIELD_PROTECTED (type
, n
);
2352 /* Now come the method fields, as NAME::methods
2353 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2354 At the end, we see a semicolon instead of a field.
2356 For the case of overloaded operators, the format is
2357 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2358 `*' holds the place for an operator name (such as `+=')
2359 and `.' marks the end of the operator name. */
2362 /* Now, read in the methods. To simplify matters, we
2363 "unread" the name that has been read, so that we can
2364 start from the top. */
2366 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2367 /* For each list of method lists... */
2371 struct next_fnfield
*sublist
= 0;
2372 struct type
*look_ahead_type
= NULL
;
2374 struct next_fnfieldlist
*new_mainlist
=
2375 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2380 /* read in the name. */
2381 while (*p
!= ':') p
++;
2382 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2384 /* This is a completely wierd case. In order to stuff in the
2385 names that might contain colons (the usual name delimiter),
2386 Mike Tiemann defined a different name format which is
2387 signalled if the identifier is "op$". In that case, the
2388 format is "op$::XXXX." where XXXX is the name. This is
2389 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2390 /* This lets the user type "break operator+".
2391 We could just put in "+" as the name, but that wouldn't
2393 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2394 char *o
= opname
+ 3;
2396 /* Skip past '::'. */
2398 if (**pp
== '\\') *pp
= next_symbol_text ();
2402 main_fn_name
= savestring (opname
, o
- opname
);
2408 main_fn_name
= savestring (*pp
, p
- *pp
);
2409 /* Skip past '::'. */
2412 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2416 struct next_fnfield
*new_sublist
=
2417 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2419 /* Check for and handle cretinous dbx symbol name continuation! */
2420 if (look_ahead_type
== NULL
) /* Normal case. */
2422 if (**pp
== '\\') *pp
= next_symbol_text ();
2424 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2426 /* Invalid symtab info for method. */
2427 return error_type (pp
);
2430 { /* g++ version 1 kludge */
2431 new_sublist
->fn_field
.type
= look_ahead_type
;
2432 look_ahead_type
= NULL
;
2437 while (*p
!= ';') p
++;
2439 /* If this is just a stub, then we don't have the
2441 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
2442 new_sublist
->fn_field
.is_stub
= 1;
2443 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2446 /* Set this method's visibility fields. */
2447 switch (*(*pp
)++ - '0')
2450 new_sublist
->fn_field
.is_private
= 1;
2453 new_sublist
->fn_field
.is_protected
= 1;
2457 if (**pp
== '\\') *pp
= next_symbol_text ();
2460 case 'A': /* Normal functions. */
2461 new_sublist
->fn_field
.is_const
= 0;
2462 new_sublist
->fn_field
.is_volatile
= 0;
2465 case 'B': /* `const' member functions. */
2466 new_sublist
->fn_field
.is_const
= 1;
2467 new_sublist
->fn_field
.is_volatile
= 0;
2470 case 'C': /* `volatile' member function. */
2471 new_sublist
->fn_field
.is_const
= 0;
2472 new_sublist
->fn_field
.is_volatile
= 1;
2475 case 'D': /* `const volatile' member function. */
2476 new_sublist
->fn_field
.is_const
= 1;
2477 new_sublist
->fn_field
.is_volatile
= 1;
2480 case '*': /* File compiled with g++ version 1 -- no info */
2485 complain (&const_vol_complaint
, (char *) (long) **pp
);
2492 /* virtual member function, followed by index. */
2493 /* The sign bit is set to distinguish pointers-to-methods
2494 from virtual function indicies. Since the array is
2495 in words, the quantity must be shifted left by 1
2496 on 16 bit machine, and by 2 on 32 bit machine, forcing
2497 the sign bit out, and usable as a valid index into
2498 the array. Remove the sign bit here. */
2499 new_sublist
->fn_field
.voffset
=
2500 (0x7fffffff & read_number (pp
, ';')) + 2;
2502 if (**pp
== '\\') *pp
= next_symbol_text ();
2504 if (**pp
== ';' || **pp
== '\0')
2505 /* Must be g++ version 1. */
2506 new_sublist
->fn_field
.fcontext
= 0;
2509 /* Figure out from whence this virtual function came.
2510 It may belong to virtual function table of
2511 one of its baseclasses. */
2512 look_ahead_type
= read_type (pp
, objfile
);
2514 { /* g++ version 1 overloaded methods. */ }
2517 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2519 return error_type (pp
);
2522 look_ahead_type
= NULL
;
2528 /* static member function. */
2529 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2530 if (strncmp (new_sublist
->fn_field
.physname
,
2531 main_fn_name
, strlen (main_fn_name
)))
2532 new_sublist
->fn_field
.is_stub
= 1;
2537 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
2538 /* Fall through into normal member function. */
2541 /* normal member function. */
2542 new_sublist
->fn_field
.voffset
= 0;
2543 new_sublist
->fn_field
.fcontext
= 0;
2547 new_sublist
->next
= sublist
;
2548 sublist
= new_sublist
;
2550 if (**pp
== '\\') *pp
= next_symbol_text ();
2552 while (**pp
!= ';' && **pp
!= '\0');
2556 new_mainlist
->fn_fieldlist
.fn_fields
=
2557 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
2558 sizeof (struct fn_field
) * length
);
2559 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2560 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2562 new_mainlist
->fn_fieldlist
.length
= length
;
2563 new_mainlist
->next
= mainlist
;
2564 mainlist
= new_mainlist
;
2566 total_length
+= length
;
2568 while (**pp
!= ';');
2576 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2577 obstack_alloc (&objfile
-> type_obstack
,
2578 sizeof (struct fn_fieldlist
) * nfn_fields
);
2579 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2580 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2585 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2586 TYPE_NFN_FIELDS_TOTAL (type
) +=
2587 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2590 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
2591 --n
; /* Circumvent Sun3 compiler bug */
2592 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
2599 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2601 /* Obsolete flags that used to indicate the presence
2602 of constructors and/or destructors. */
2606 /* Read either a '%' or the final ';'. */
2607 if (*(*pp
)++ == '%')
2609 /* We'd like to be able to derive the vtable pointer field
2610 from the type information, but when it's inherited, that's
2611 hard. A reason it's hard is because we may read in the
2612 info about a derived class before we read in info about
2613 the base class that provides the vtable pointer field.
2614 Once the base info has been read, we could fill in the info
2615 for the derived classes, but for the fact that by then,
2616 we don't remember who needs what. */
2618 int predicted_fieldno
= -1;
2620 /* Now we must record the virtual function table pointer's
2621 field information. */
2629 /* In version 2, we derive the vfield ourselves. */
2630 for (n
= 0; n
< nfields
; n
++)
2632 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2633 sizeof (vptr_name
) -1))
2635 predicted_fieldno
= n
;
2639 if (predicted_fieldno
< 0)
2640 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2641 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2642 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2644 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2650 t
= read_type (pp
, objfile
);
2652 while (*p
!= '\0' && *p
!= ';')
2655 /* Premature end of symbol. */
2656 return error_type (pp
);
2658 TYPE_VPTR_BASETYPE (type
) = t
;
2661 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2663 /* FIXME-tiemann: what's this? */
2665 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2670 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2671 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2672 sizeof (vptr_name
) -1))
2674 TYPE_VPTR_FIELDNO (type
) = i
;
2678 /* Virtual function table field not found. */
2679 return error_type (pp
);
2682 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2685 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2686 error ("TYPE_VPTR_FIELDNO miscalculated");
2696 /* Read a definition of an array type,
2697 and create and return a suitable type object.
2698 Also creates a range type which represents the bounds of that
2700 static struct type
*
2701 read_array_type (pp
, type
, objfile
)
2703 register struct type
*type
;
2704 struct objfile
*objfile
;
2706 struct type
*index_type
, *element_type
, *range_type
;
2710 /* Format of an array type:
2711 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2714 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2715 for these, produce a type like float[][]. */
2717 index_type
= read_type (pp
, objfile
);
2719 /* Improper format of array type decl. */
2720 return error_type (pp
);
2723 if (!(**pp
>= '0' && **pp
<= '9'))
2728 lower
= read_number (pp
, ';');
2730 if (!(**pp
>= '0' && **pp
<= '9'))
2735 upper
= read_number (pp
, ';');
2737 element_type
= read_type (pp
, objfile
);
2746 /* Create range type. */
2747 range_type
= (struct type
*)
2748 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2749 bzero (range_type
, sizeof (struct type
));
2750 TYPE_OBJFILE (range_type
) = objfile
;
2751 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2752 TYPE_TARGET_TYPE (range_type
) = index_type
;
2754 /* This should never be needed. */
2755 TYPE_LENGTH (range_type
) = sizeof (int);
2757 TYPE_NFIELDS (range_type
) = 2;
2758 TYPE_FIELDS (range_type
) =
2759 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2760 2 * sizeof (struct field
));
2761 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2762 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2765 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2766 TYPE_TARGET_TYPE (type
) = element_type
;
2767 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2768 TYPE_NFIELDS (type
) = 1;
2769 TYPE_FIELDS (type
) =
2770 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2771 sizeof (struct field
));
2772 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2774 /* If we have an array whose element type is not yet known, but whose
2775 bounds *are* known, record it to be adjusted at the end of the file. */
2776 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2777 add_undefined_type (type
);
2783 /* Read a definition of an enumeration type,
2784 and create and return a suitable type object.
2785 Also defines the symbols that represent the values of the type. */
2787 static struct type
*
2788 read_enum_type (pp
, type
, objfile
)
2790 register struct type
*type
;
2791 struct objfile
*objfile
;
2796 register struct symbol
*sym
;
2798 struct pending
**symlist
;
2799 struct pending
*osyms
, *syms
;
2802 if (within_function
)
2803 symlist
= &local_symbols
;
2805 symlist
= &file_symbols
;
2807 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2809 /* Read the value-names and their values.
2810 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2811 A semicolon or comma instead of a NAME means the end. */
2812 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2814 /* Check for and handle cretinous dbx symbol name continuation! */
2815 if (**pp
== '\\') *pp
= next_symbol_text ();
2818 while (*p
!= ':') p
++;
2819 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2821 n
= read_number (pp
, ',');
2823 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2824 bzero (sym
, sizeof (struct symbol
));
2825 SYMBOL_NAME (sym
) = name
;
2826 SYMBOL_CLASS (sym
) = LOC_CONST
;
2827 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2828 SYMBOL_VALUE (sym
) = n
;
2829 add_symbol_to_list (sym
, symlist
);
2834 (*pp
)++; /* Skip the semicolon. */
2836 /* Now fill in the fields of the type-structure. */
2838 TYPE_LENGTH (type
) = sizeof (int);
2839 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2840 TYPE_NFIELDS (type
) = nsyms
;
2841 TYPE_FIELDS (type
) = (struct field
*)
2842 obstack_alloc (&objfile
-> type_obstack
,
2843 sizeof (struct field
) * nsyms
);
2845 /* Find the symbols for the values and put them into the type.
2846 The symbols can be found in the symlist that we put them on
2847 to cause them to be defined. osyms contains the old value
2848 of that symlist; everything up to there was defined by us. */
2849 /* Note that we preserve the order of the enum constants, so
2850 that in something like "enum {FOO, LAST_THING=FOO}" we print
2851 FOO, not LAST_THING. */
2853 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2858 for (; j
< syms
->nsyms
; j
++,n
++)
2860 struct symbol
*xsym
= syms
->symbol
[j
];
2861 SYMBOL_TYPE (xsym
) = type
;
2862 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2863 TYPE_FIELD_VALUE (type
, n
) = 0;
2864 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2865 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2872 /* This screws up perfectly good C programs with enums. FIXME. */
2873 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2874 if(TYPE_NFIELDS(type
) == 2 &&
2875 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2876 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2877 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2878 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2879 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2885 /* Read a number from the string pointed to by *PP.
2886 The value of *PP is advanced over the number.
2887 If END is nonzero, the character that ends the
2888 number must match END, or an error happens;
2889 and that character is skipped if it does match.
2890 If END is zero, *PP is left pointing to that character.
2892 If the number fits in a long, set *VALUE and set *BITS to 0.
2893 If not, set *BITS to be the number of bits in the number.
2895 If encounter garbage, set *BITS to -1. */
2898 read_huge_number (pp
, end
, valu
, bits
)
2919 /* Leading zero means octal. GCC uses this to output values larger
2920 than an int (because that would be hard in decimal). */
2927 upper_limit
= LONG_MAX
/ radix
;
2928 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2930 if (n
<= upper_limit
)
2933 n
+= c
- '0'; /* FIXME this overflows anyway */
2938 /* This depends on large values being output in octal, which is
2945 /* Ignore leading zeroes. */
2949 else if (c
== '2' || c
== '3')
2975 /* Large decimal constants are an error (because it is hard to
2976 count how many bits are in them). */
2982 /* -0x7f is the same as 0x80. So deal with it by adding one to
2983 the number of bits. */
2998 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2999 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
3001 static struct type
*
3002 read_range_type (pp
, typenums
, objfile
)
3005 struct objfile
*objfile
;
3011 struct type
*result_type
;
3013 /* First comes a type we are a subrange of.
3014 In C it is usually 0, 1 or the type being defined. */
3015 read_type_number (pp
, rangenums
);
3016 self_subrange
= (rangenums
[0] == typenums
[0] &&
3017 rangenums
[1] == typenums
[1]);
3019 /* A semicolon should now follow; skip it. */
3023 /* The remaining two operands are usually lower and upper bounds
3024 of the range. But in some special cases they mean something else. */
3025 read_huge_number (pp
, ';', &n2
, &n2bits
);
3026 read_huge_number (pp
, ';', &n3
, &n3bits
);
3028 if (n2bits
== -1 || n3bits
== -1)
3029 return error_type (pp
);
3031 /* If limits are huge, must be large integral type. */
3032 if (n2bits
!= 0 || n3bits
!= 0)
3034 char got_signed
= 0;
3035 char got_unsigned
= 0;
3036 /* Number of bits in the type. */
3039 /* Range from 0 to <large number> is an unsigned large integral type. */
3040 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3045 /* Range from <large number> to <large number>-1 is a large signed
3047 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3053 /* Check for "long long". */
3054 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
3055 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3056 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
3057 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3059 if (got_signed
|| got_unsigned
)
3061 result_type
= (struct type
*)
3062 obstack_alloc (&objfile
-> type_obstack
,
3063 sizeof (struct type
));
3064 bzero (result_type
, sizeof (struct type
));
3065 TYPE_OBJFILE (result_type
) = objfile
;
3066 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
3067 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
3069 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
3073 return error_type (pp
);
3076 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3077 if (self_subrange
&& n2
== 0 && n3
== 0)
3078 return (lookup_fundamental_type (objfile
, FT_VOID
));
3080 /* If n3 is zero and n2 is not, we want a floating type,
3081 and n2 is the width in bytes.
3083 Fortran programs appear to use this for complex types also,
3084 and they give no way to distinguish between double and single-complex!
3085 We don't have complex types, so we would lose on all fortran files!
3086 So return type `double' for all of those. It won't work right
3087 for the complex values, but at least it makes the file loadable.
3089 FIXME, we may be able to distinguish these by their names. FIXME. */
3091 if (n3
== 0 && n2
> 0)
3093 if (n2
== sizeof (float))
3094 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
3095 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
3098 /* If the upper bound is -1, it must really be an unsigned int. */
3100 else if (n2
== 0 && n3
== -1)
3102 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3103 long' is to look at its name! */
3105 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3106 long_kludge_name
[9] == 'l' /* long */)
3107 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3108 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3110 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3113 /* Special case: char is defined (Who knows why) as a subrange of
3114 itself with range 0-127. */
3115 else if (self_subrange
&& n2
== 0 && n3
== 127)
3116 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3118 /* Assumptions made here: Subrange of self is equivalent to subrange
3119 of int. FIXME: Host and target type-sizes assumed the same. */
3120 /* FIXME: This is the *only* place in GDB that depends on comparing
3121 some type to a builtin type with ==. Fix it! */
3123 && (self_subrange
||
3124 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
3126 /* an unsigned type */
3128 if (n3
== - sizeof (long long))
3129 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3131 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3132 long' is to look at its name! */
3133 if (n3
== (unsigned long)~0L &&
3134 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3135 long_kludge_name
[9] == 'l' /* long */)
3136 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3137 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3138 if (n3
== (unsigned int)~0L)
3139 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3140 if (n3
== (unsigned short)~0L)
3141 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
3142 if (n3
== (unsigned char)~0L)
3143 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
3146 else if (n3
== 0 && n2
== -sizeof (long long))
3147 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3149 else if (n2
== -n3
-1)
3152 /* FIXME -- the only way to distinguish `int' from `long' is to look
3154 if ((n3
== (1 << (8 * sizeof (long) - 1)) - 1) &&
3155 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3156 return (lookup_fundamental_type (objfile
, FT_LONG
));
3157 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
3158 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
3159 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
3160 return (lookup_fundamental_type (objfile
, FT_SHORT
));
3161 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
3162 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3165 /* We have a real range type on our hands. Allocate space and
3166 return a real pointer. */
3168 /* At this point I don't have the faintest idea how to deal with
3169 a self_subrange type; I'm going to assume that this is used
3170 as an idiom, and that all of them are special cases. So . . . */
3172 return error_type (pp
);
3174 result_type
= (struct type
*)
3175 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
3176 bzero (result_type
, sizeof (struct type
));
3177 TYPE_OBJFILE (result_type
) = objfile
;
3179 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3181 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3182 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3183 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
3184 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
3187 TYPE_NFIELDS (result_type
) = 2;
3188 TYPE_FIELDS (result_type
) =
3189 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
3190 2 * sizeof (struct field
));
3191 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
3192 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3193 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3195 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3200 /* Read a number from the string pointed to by *PP.
3201 The value of *PP is advanced over the number.
3202 If END is nonzero, the character that ends the
3203 number must match END, or an error happens;
3204 and that character is skipped if it does match.
3205 If END is zero, *PP is left pointing to that character. */
3208 read_number (pp
, end
)
3212 register char *p
= *pp
;
3213 register long n
= 0;
3217 /* Handle an optional leading minus sign. */
3225 /* Read the digits, as far as they go. */
3227 while ((c
= *p
++) >= '0' && c
<= '9')
3235 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3244 /* Read in an argument list. This is a list of types, separated by commas
3245 and terminated with END. Return the list of types read in, or (struct type
3246 **)-1 if there is an error. */
3247 static struct type
**
3248 read_args (pp
, end
, objfile
)
3251 struct objfile
*objfile
;
3253 /* FIXME! Remove this arbitrary limit! */
3254 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3260 /* Invalid argument list: no ','. */
3261 return (struct type
**)-1;
3264 /* Check for and handle cretinous dbx symbol name continuation! */
3266 *pp
= next_symbol_text ();
3268 types
[n
++] = read_type (pp
, objfile
);
3270 *pp
+= 1; /* get past `end' (the ':' character) */
3274 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3276 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3278 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3279 bzero (rval
+ n
, sizeof (struct type
*));
3283 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3285 memcpy (rval
, types
, n
* sizeof (struct type
*));
3289 /* Add a common block's start address to the offset of each symbol
3290 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3291 the common block name). */
3294 fix_common_block (sym
, valu
)
3298 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3299 for ( ; next
; next
= next
->next
)
3302 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3303 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3307 /* Initializer for this module */
3309 _initialize_buildsym ()
3311 undef_types_allocated
= 20;
3312 undef_types_length
= 0;
3313 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3314 sizeof (struct type
*));