1 /* Build symbol tables in GDB's internal format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This module provides subroutines used for creating and adding to
22 the symbol table. These routines are called from various symbol-
23 file-reading routines.
25 They originated in dbxread.c of gdb-4.2, and were split out to
26 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" */
36 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
40 /* Ask buildsym.h to define the vars it normally declares `extern'. */
42 #include "buildsym.h" /* Our own declarations */
46 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
50 read_huge_number
PARAMS ((char **, int, long *, int *));
53 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
56 compare_line_numbers
PARAMS ((const void *, const void *));
58 static struct blockvector
*
59 make_blockvector
PARAMS ((struct objfile
*));
62 fix_common_block
PARAMS ((struct symbol
*, int));
65 cleanup_undefined_types
PARAMS ((void));
68 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
71 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
74 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
77 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
80 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
83 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
86 read_args
PARAMS ((char **, int, struct objfile
*));
90 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
91 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
93 /* Define this as 1 if a pcc declaration of a char or short argument
94 gives the correct address. Otherwise assume pcc gives the
95 address of the corresponding int, which is not the same on a
96 big-endian machine. */
98 #ifndef BELIEVE_PCC_PROMOTION
99 #define BELIEVE_PCC_PROMOTION 0
102 /* During some calls to read_type (and thus to read_range_type), this
103 contains the name of the type being defined. Range types are only
104 used in C as basic types. We use the name to distinguish the otherwise
105 identical basic types "int" and "long" and their unsigned versions.
106 FIXME, this should disappear with better type management. */
108 static char *long_kludge_name
;
110 /* Make a list of forward references which haven't been defined. */
111 static struct type
**undef_types
;
112 static int undef_types_allocated
, undef_types_length
;
114 /* Initial sizes of data structures. These are realloc'd larger if needed,
115 and realloc'd down to the size actually used, when completed. */
117 #define INITIAL_CONTEXT_STACK_SIZE 10
118 #define INITIAL_TYPE_VECTOR_LENGTH 160
119 #define INITIAL_LINE_VECTOR_LENGTH 1000
121 /* Complaints about the symbols we have encountered. */
123 struct complaint innerblock_complaint
=
124 {"inner block not inside outer block in %s", 0, 0};
126 struct complaint blockvector_complaint
=
127 {"block at %x out of order", 0, 0};
130 struct complaint dbx_class_complaint
=
131 {"encountered DBX-style class variable debugging information.\n\
132 You seem to have compiled your program with \
133 \"g++ -g0\" instead of \"g++ -g\".\n\
134 Therefore GDB will not know about your class variables", 0, 0};
137 struct complaint invalid_cpp_abbrev_complaint
=
138 {"invalid C++ abbreviation `%s'", 0, 0};
140 struct complaint invalid_cpp_type_complaint
=
141 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
143 struct complaint member_fn_complaint
=
144 {"member function type missing, got '%c'", 0, 0};
146 struct complaint const_vol_complaint
=
147 {"const/volatile indicator missing, got '%c'", 0, 0};
149 struct complaint error_type_complaint
=
150 {"debug info mismatch between compiler and debugger", 0, 0};
152 struct complaint invalid_member_complaint
=
153 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
155 struct complaint range_type_base_complaint
=
156 {"base type %d of range type is not defined", 0, 0};
158 struct complaint reg_value_complaint
=
159 {"register number too large in symbol %s", 0, 0};
165 register char *p
= name
;
166 register int total
= p
[0];
179 /* Ensure result is positive. */
180 if (total
< 0) total
+= (1000 << 6);
181 return total
% HASHSIZE
;
185 /* Look up a dbx type-number pair. Return the address of the slot
186 where the type for that number-pair is stored.
187 The number-pair is in TYPENUMS.
189 This can be used for finding the type associated with that pair
190 or for associating a new type with the pair. */
193 dbx_lookup_type (typenums
)
196 register int filenum
= typenums
[0], index
= typenums
[1];
199 if (filenum
== -1) /* -1,-1 is for temporary types. */
202 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
203 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
204 filenum
, index
, symnum
);
208 /* Type is defined outside of header files.
209 Find it in this object file's type vector. */
210 if (index
>= type_vector_length
)
212 old_len
= type_vector_length
;
214 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
215 type_vector
= (struct type
**)
216 malloc (type_vector_length
* sizeof (struct type
*));
218 while (index
>= type_vector_length
)
219 type_vector_length
*= 2;
220 type_vector
= (struct type
**)
221 xrealloc ((char *) type_vector
,
222 (type_vector_length
* sizeof (struct type
*)));
223 (void) memset (&type_vector
[old_len
], 0,
224 (type_vector_length
- old_len
) * sizeof (struct type
*));
226 return &type_vector
[index
];
230 register int real_filenum
= this_object_header_files
[filenum
];
231 register struct header_file
*f
;
234 if (real_filenum
>= n_header_files
)
237 f
= &header_files
[real_filenum
];
239 f_orig_length
= f
->length
;
240 if (index
>= f_orig_length
)
242 while (index
>= f
->length
)
244 f
->vector
= (struct type
**)
245 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
246 (void) memset (&f
->vector
[f_orig_length
], 0,
247 (f
->length
- f_orig_length
) * sizeof (struct type
*));
249 return &f
->vector
[index
];
253 /* Make sure there is a type allocated for type numbers TYPENUMS
254 and return the type object.
255 This can create an empty (zeroed) type object.
256 TYPENUMS may be (-1, -1) to return a new type object that is not
257 put into the type vector, and so may not be referred to by number. */
260 dbx_alloc_type (typenums
, objfile
)
262 struct objfile
*objfile
;
264 register struct type
**type_addr
;
266 if (typenums
[0] == -1)
267 return alloc_type (objfile
);
269 type_addr
= dbx_lookup_type (typenums
);
271 /* If we are referring to a type not known at all yet,
272 allocate an empty type for it.
273 We will fill it in later if we find out how. */
275 *type_addr
= alloc_type (objfile
);
280 /* maintain the lists of symbols and blocks */
282 /* Add a symbol to one of the lists of symbols. */
284 add_symbol_to_list (symbol
, listhead
)
285 struct symbol
*symbol
;
286 struct pending
**listhead
;
288 /* We keep PENDINGSIZE symbols in each link of the list.
289 If we don't have a link with room in it, add a new link. */
290 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
292 register struct pending
*link
;
295 link
= free_pendings
;
296 free_pendings
= link
->next
;
299 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
301 link
->next
= *listhead
;
306 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
309 /* Find a symbol on a pending list. */
311 find_symbol_in_list (list
, name
, length
)
312 struct pending
*list
;
319 for (j
= list
->nsyms
; --j
>= 0; ) {
320 char *pp
= SYMBOL_NAME (list
->symbol
[j
]);
321 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 && pp
[length
] == '\0')
322 return list
->symbol
[j
];
329 /* At end of reading syms, or in case of quit,
330 really free as many `struct pending's as we can easily find. */
334 really_free_pendings (foo
)
337 struct pending
*next
, *next1
;
339 struct pending_block
*bnext
, *bnext1
;
342 for (next
= free_pendings
; next
; next
= next1
)
349 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
350 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
352 bnext1
= bnext
->next
;
358 for (next
= file_symbols
; next
; next
= next1
)
365 for (next
= global_symbols
; next
; next
= next1
)
373 /* Take one of the lists of symbols and make a block from it.
374 Keep the order the symbols have in the list (reversed from the input file).
375 Put the block on the list of pending blocks. */
378 finish_block (symbol
, listhead
, old_blocks
, start
, end
, objfile
)
379 struct symbol
*symbol
;
380 struct pending
**listhead
;
381 struct pending_block
*old_blocks
;
382 CORE_ADDR start
, end
;
383 struct objfile
*objfile
;
385 register struct pending
*next
, *next1
;
386 register struct block
*block
;
387 register struct pending_block
*pblock
;
388 struct pending_block
*opblock
;
391 /* Count the length of the list of symbols. */
393 for (next
= *listhead
, i
= 0;
395 i
+= next
->nsyms
, next
= next
->next
)
398 block
= (struct block
*) obstack_alloc (&objfile
-> symbol_obstack
,
399 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
401 /* Copy the symbols into the block. */
403 BLOCK_NSYMS (block
) = i
;
404 for (next
= *listhead
; next
; next
= next
->next
)
407 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
408 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
411 BLOCK_START (block
) = start
;
412 BLOCK_END (block
) = end
;
413 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
414 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
416 /* Put the block in as the value of the symbol that names it. */
420 SYMBOL_BLOCK_VALUE (symbol
) = block
;
421 BLOCK_FUNCTION (block
) = symbol
;
424 BLOCK_FUNCTION (block
) = 0;
426 /* Now "free" the links of the list, and empty the list. */
428 for (next
= *listhead
; next
; next
= next1
)
431 next
->next
= free_pendings
;
432 free_pendings
= next
;
436 /* Install this block as the superblock
437 of all blocks made since the start of this scope
438 that don't have superblocks yet. */
441 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
443 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
445 /* Check to be sure the blocks are nested as we receive them.
446 If the compiler/assembler/linker work, this just burns a small
448 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
449 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
450 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
452 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
453 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
456 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
461 /* Record this block on the list of all blocks in the file.
462 Put it after opblock, or at the beginning if opblock is 0.
463 This puts the block in the list after all its subblocks. */
465 /* Allocate in the symbol_obstack to save time.
466 It wastes a little space. */
467 pblock
= (struct pending_block
*)
468 obstack_alloc (&objfile
-> symbol_obstack
,
469 sizeof (struct pending_block
));
470 pblock
->block
= block
;
473 pblock
->next
= opblock
->next
;
474 opblock
->next
= pblock
;
478 pblock
->next
= pending_blocks
;
479 pending_blocks
= pblock
;
483 static struct blockvector
*
484 make_blockvector (objfile
)
485 struct objfile
*objfile
;
487 register struct pending_block
*next
;
488 register struct blockvector
*blockvector
;
491 /* Count the length of the list of blocks. */
493 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
495 blockvector
= (struct blockvector
*)
496 obstack_alloc (&objfile
-> symbol_obstack
,
497 (sizeof (struct blockvector
)
498 + (i
- 1) * sizeof (struct block
*)));
500 /* Copy the blocks into the blockvector.
501 This is done in reverse order, which happens to put
502 the blocks into the proper order (ascending starting address).
503 finish_block has hair to insert each block into the list
504 after its subblocks in order to make sure this is true. */
506 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
507 for (next
= pending_blocks
; next
; next
= next
->next
) {
508 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
511 #if 0 /* Now we make the links in the obstack, so don't free them. */
512 /* Now free the links of the list, and empty the list. */
514 for (next
= pending_blocks
; next
; next
= next1
)
522 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
523 /* Some compilers output blocks in the wrong order, but we depend
524 on their being in the right order so we can binary search.
525 Check the order and moan about it. FIXME. */
526 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
527 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
528 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
529 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
530 complain (&blockvector_complaint
,
531 (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
539 /* Start recording information about source code that came from an included
540 (or otherwise merged-in) source file with a different name. */
543 start_subfile (name
, dirname
)
547 register struct subfile
*subfile
;
549 /* See if this subfile is already known as a subfile of the
550 current main source file. */
552 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
554 if (!strcmp (subfile
->name
, name
))
556 current_subfile
= subfile
;
561 /* This subfile is not known. Add an entry for it.
562 Make an entry for this subfile in the list of all subfiles
563 of the current main source file. */
565 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
566 subfile
->next
= subfiles
;
568 current_subfile
= subfile
;
570 /* Save its name and compilation directory name */
571 subfile
->name
= strdup (name
);
573 subfile
->dirname
= NULL
;
575 subfile
->dirname
= strdup (dirname
);
577 /* Initialize line-number recording for this subfile. */
578 subfile
->line_vector
= 0;
581 /* Handle the N_BINCL and N_EINCL symbol types
582 that act like N_SOL for switching source files
583 (different subfiles, as we call them) within one object file,
584 but using a stack rather than in an arbitrary order. */
589 register struct subfile_stack
*tem
590 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
592 tem
->next
= subfile_stack
;
594 if (current_subfile
== 0 || current_subfile
->name
== 0)
596 tem
->name
= current_subfile
->name
;
603 register struct subfile_stack
*link
= subfile_stack
;
609 subfile_stack
= link
->next
;
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;
693 type_vector_length
= 0;
694 type_vector
= (struct type
**) 0;
696 /* Initialize the list of sub source files with one entry
697 for this file (the top-level source file). */
701 start_subfile (name
, dirname
);
704 /* for all the stabs in a given stab vector, build appropriate types
705 and fix their symbols in given symbol vector. */
708 patch_block_stabs (symbols
, stabs
, objfile
)
709 struct pending
*symbols
;
710 struct pending_stabs
*stabs
;
711 struct objfile
*objfile
;
718 /* for all the stab entries, find their corresponding symbols and
719 patch their types! */
721 for (ii
= 0; ii
< stabs
->count
; ++ii
)
723 char *name
= stabs
->stab
[ii
];
724 char *pp
= (char*) strchr (name
, ':');
725 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
728 #ifndef IBM6000_TARGET
729 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 ();
821 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
822 free ((PTR
)global_stabs
);
826 if (pending_blocks
== 0
828 && global_symbols
== 0) {
829 /* Ignore symtabs that have no functions with real debugging info */
832 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
833 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
834 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
835 blockvector
= make_blockvector (objfile
);
838 #ifdef PROCESS_LINENUMBER_HOOK
839 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
842 /* Now create the symtab objects proper, one for each subfile. */
843 /* (The main file is the last one on the chain.) */
845 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
848 /* If we have blocks of symbols, make a symtab.
849 Otherwise, just ignore this file and any line number info in it. */
852 if (subfile
->line_vector
) {
853 /* First, shrink the linetable to make more memory. */
854 linetablesize
= sizeof (struct linetable
) +
855 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
856 subfile
->line_vector
= (struct linetable
*)
857 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
860 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
861 sizeof (struct linetable_entry
), compare_line_numbers
);
864 /* Now, allocate a symbol table. */
865 symtab
= allocate_symtab (subfile
->name
, objfile
);
867 /* Fill in its components. */
868 symtab
->blockvector
= blockvector
;
869 if (subfile
->line_vector
)
871 /* Reallocate the line table on the symbol obstack */
872 symtab
->linetable
= (struct linetable
*)
873 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
874 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
878 symtab
->linetable
= NULL
;
880 symtab
->dirname
= subfile
->dirname
;
881 symtab
->free_code
= free_linetable
;
882 symtab
->free_ptr
= 0;
884 #ifdef IBM6000_TARGET
885 /* In case we need to duplicate symbol tables (to represent include
886 files), and in case our system needs relocation, we want to
887 relocate the main symbol table node only (for the main file,
888 not for the include files). */
890 symtab
->nonreloc
= TRUE
;
893 if (subfile
->line_vector
)
894 free ((PTR
)subfile
->line_vector
);
896 nextsub
= subfile
->next
;
900 #ifdef IBM6000_TARGET
901 /* all include symbol tables are non-relocatable, except the main source
904 symtab
->nonreloc
= FALSE
;
908 free ((char *) type_vector
);
910 type_vector_length
= 0;
912 last_source_file
= 0;
914 previous_stab_code
= 0;
920 /* Push a context block. Args are an identifying nesting level (checkable
921 when you pop it), and the starting PC address of this context. */
923 struct context_stack
*
924 push_context (desc
, valu
)
928 register struct context_stack
*new;
930 if (context_stack_depth
== context_stack_size
)
932 context_stack_size
*= 2;
933 context_stack
= (struct context_stack
*)
934 xrealloc ((char *) context_stack
,
935 (context_stack_size
* sizeof (struct context_stack
)));
938 new = &context_stack
[context_stack_depth
++];
940 new->locals
= local_symbols
;
941 new->old_blocks
= pending_blocks
;
942 new->start_addr
= valu
;
950 /* Initialize anything that needs initializing when starting to read
951 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
963 /* Initialize anything that needs initializing when a completely new
964 symbol file is specified (not just adding some symbols from another
965 file, e.g. a shared library). */
970 /* Empty the hash table of global syms looking for values. */
971 (void) memset (global_sym_chain
, 0, sizeof global_sym_chain
);
976 /* Scan through all of the global symbols defined in the object file,
977 assigning values to the debugging symbols that need to be assigned
978 to. Get these symbols from the minimal symbol table. */
981 scan_file_globals (objfile
)
982 struct objfile
*objfile
;
985 struct minimal_symbol
*msymbol
;
986 struct symbol
*sym
, *prev
;
988 if (objfile
->msymbols
== 0) /* Beware the null file. */
991 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
995 prev
= (struct symbol
*) 0;
997 /* Get the hash index and check all the symbols
998 under that hash index. */
1000 hash
= hashname (msymbol
-> name
);
1002 for (sym
= global_sym_chain
[hash
]; sym
;)
1004 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
1005 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
1007 /* Splice this symbol out of the hash chain and
1008 assign the value we have to it. */
1010 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1012 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1014 /* Check to see whether we need to fix up a common block. */
1015 /* Note: this code might be executed several times for
1016 the same symbol if there are multiple references. */
1017 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1018 fix_common_block (sym
, msymbol
-> address
);
1020 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
1023 sym
= SYMBOL_VALUE_CHAIN (prev
);
1025 sym
= global_sym_chain
[hash
];
1030 sym
= SYMBOL_VALUE_CHAIN (sym
);
1037 /* Read a number by which a type is referred to in dbx data,
1038 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1039 Just a single number N is equivalent to (0,N).
1040 Return the two numbers by storing them in the vector TYPENUMS.
1041 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1044 read_type_number (pp
, typenums
)
1046 register int *typenums
;
1051 typenums
[0] = read_number (pp
, ',');
1052 typenums
[1] = read_number (pp
, ')');
1057 typenums
[1] = read_number (pp
, 0);
1061 /* To handle GNU C++ typename abbreviation, we need to be able to
1062 fill in a type's name as soon as space for that type is allocated.
1063 `type_synonym_name' is the name of the type being allocated.
1064 It is cleared as soon as it is used (lest all allocated types
1066 static char *type_synonym_name
;
1070 define_symbol (valu
, string
, desc
, type
, objfile
)
1075 struct objfile
*objfile
;
1077 register struct symbol
*sym
;
1078 char *p
= (char *) strchr (string
, ':');
1082 struct type
*temptype
;
1084 /* We would like to eliminate nameless symbols, but keep their types.
1085 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1086 to type 2, but, should not creat a symbol to address that type. Since
1087 the symbol will be nameless, there is no way any user can refer to it. */
1091 /* Ignore syms with empty names. */
1095 /* Ignore old-style symbols from cc -go */
1099 /* If a nameless stab entry, all we need is the type, not the symbol.
1101 nameless
= (p
== string
);
1103 sym
= (struct symbol
*)obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1105 if (processing_gcc_compilation
) {
1106 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1107 number of bytes occupied by a type or object, which we ignore. */
1108 SYMBOL_LINE(sym
) = desc
;
1110 SYMBOL_LINE(sym
) = 0; /* unknown */
1113 if (string
[0] == CPLUS_MARKER
)
1115 /* Special GNU C++ names. */
1119 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1120 &objfile
-> symbol_obstack
);
1122 case 'v': /* $vtbl_ptr_type */
1123 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1126 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1127 &objfile
-> symbol_obstack
);
1131 /* This was an anonymous type that was never fixed up. */
1142 = (char *) obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1143 /* Open-coded bcopy--saves function call time. */
1145 register char *p1
= string
;
1146 register char *p2
= SYMBOL_NAME (sym
);
1153 /* Determine the type of name being defined. */
1154 /* The Acorn RISC machine's compiler can put out locals that don't
1155 start with "234=" or "(3,4)=", so assume anything other than the
1156 deftypes we know how to handle is a local. */
1157 /* (Peter Watkins @ Computervision)
1158 Handle Sun-style local fortran array types 'ar...' .
1159 (gnu@cygnus.com) -- this strchr() handles them properly?
1160 (tiemann@cygnus.com) -- 'C' is for catch. */
1162 #ifdef IBM6000_TARGET
1164 /* 'R' is for register parameters. */
1166 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1169 if (!strchr ("cfFGpPrStTvVXC", *p
))
1175 /* c is a special case, not followed by a type-number.
1176 SYMBOL:c=iVALUE for an integer constant symbol.
1177 SYMBOL:c=rVALUE for a floating constant symbol.
1178 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1179 e.g. "b:c=e6,0" for "const b = blob1"
1180 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1184 error ("Invalid symbol data at symtab pos %d.", symnum
);
1189 double d
= atof (p
);
1192 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1195 obstack_alloc (&objfile
-> type_obstack
,
1197 memcpy (dbl_valu
, &d
, sizeof (double));
1198 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1199 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1200 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1205 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1207 SYMBOL_VALUE (sym
) = atoi (p
);
1208 SYMBOL_CLASS (sym
) = LOC_CONST
;
1212 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1213 e.g. "b:c=e6,0" for "const b = blob1"
1214 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1218 read_type_number (&p
, typenums
);
1220 error ("Invalid symbol data: no comma in enum const symbol");
1222 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1223 SYMBOL_VALUE (sym
) = atoi (p
);
1224 SYMBOL_CLASS (sym
) = LOC_CONST
;
1228 error ("Invalid symbol data at symtab pos %d.", symnum
);
1230 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1231 add_symbol_to_list (sym
, &file_symbols
);
1235 /* Now usually comes a number that says which data type,
1236 and possibly more stuff to define the type
1237 (all of which is handled by read_type) */
1239 if (deftype
== 'p' && *p
== 'F')
1240 /* pF is a two-letter code that means a function parameter in Fortran.
1241 The type-number specifies the type of the return value.
1242 Translate it into a pointer-to-function type. */
1246 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
1249 #ifdef IBM6000_TARGET
1250 else if (deftype
== 'R')
1251 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1256 /* The symbol class letter is followed by a type (typically the
1257 type of the symbol, or its return-type, or etc). Read it. */
1259 synonym
= *p
== 't';
1264 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1265 strlen (SYMBOL_NAME (sym
)),
1266 &objfile
-> symbol_obstack
);
1269 /* Here we save the name of the symbol for read_range_type, which
1270 ends up reading in the basic types. In stabs, unfortunately there
1271 is no distinction between "int" and "long" types except their
1272 names. Until we work out a saner type policy (eliminating most
1273 builtin types and using the names specified in the files), we
1274 save away the name so that far away from here in read_range_type,
1275 we can examine it to decide between "int" and "long". FIXME. */
1276 long_kludge_name
= SYMBOL_NAME (sym
);
1278 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1284 /* The name of a caught exception. */
1285 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1286 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1287 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1288 add_symbol_to_list (sym
, &local_symbols
);
1292 /* A static function definition. */
1293 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1294 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1295 add_symbol_to_list (sym
, &file_symbols
);
1296 /* fall into process_function_types. */
1298 process_function_types
:
1299 /* Function result types are described as the result type in stabs.
1300 We need to convert this to the function-returning-type-X type
1301 in GDB. E.g. "int" is converted to "function returning int". */
1302 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1305 /* This code doesn't work -- it needs to realloc and can't. */
1306 /* Attempt to set up to record a function prototype... */
1307 struct type
*new = (struct type
*)
1308 obstack_alloc (&objfile
-> type_obstack
,
1309 sizeof (struct type
));
1311 /* Generate a template for the type of this function. The
1312 types of the arguments will be added as we read the symbol
1314 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
1315 SYMBOL_TYPE(sym
) = new;
1316 TYPE_OBJFILE (new) = objfile
;
1317 in_function_type
= new;
1319 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1322 /* fall into process_prototype_types */
1324 process_prototype_types
:
1325 /* Sun acc puts declared types of arguments here. We don't care
1326 about their actual types (FIXME -- we should remember the whole
1327 function prototype), but the list may define some new types
1328 that we have to remember, so we must scan it now. */
1331 read_type (&p
, objfile
);
1336 /* A global function definition. */
1337 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1338 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1339 add_symbol_to_list (sym
, &global_symbols
);
1340 goto process_function_types
;
1343 /* For a class G (global) symbol, it appears that the
1344 value is not correct. It is necessary to search for the
1345 corresponding linker definition to find the value.
1346 These definitions appear at the end of the namelist. */
1347 i
= hashname (SYMBOL_NAME (sym
));
1348 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1349 global_sym_chain
[i
] = sym
;
1350 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1351 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1352 add_symbol_to_list (sym
, &global_symbols
);
1355 /* This case is faked by a conditional above,
1356 when there is no code letter in the dbx data.
1357 Dbx data never actually contains 'l'. */
1359 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1360 SYMBOL_VALUE (sym
) = valu
;
1361 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1362 add_symbol_to_list (sym
, &local_symbols
);
1366 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1367 can also be a LOC_LOCAL_ARG depending on symbol type. */
1368 #ifndef DBX_PARM_SYMBOL_CLASS
1369 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1371 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1372 SYMBOL_VALUE (sym
) = valu
;
1373 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1375 /* This doesn't work yet. */
1376 add_param_to_type (&in_function_type
, sym
);
1378 add_symbol_to_list (sym
, &local_symbols
);
1380 /* If it's gcc-compiled, if it says `short', believe it. */
1381 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1384 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1385 /* This macro is defined on machines (e.g. sparc) where
1386 we should believe the type of a PCC 'short' argument,
1387 but shouldn't believe the address (the address is
1388 the address of the corresponding int). Note that
1389 this is only different from the BELIEVE_PCC_PROMOTION
1390 case on big-endian machines.
1392 My guess is that this correction, as opposed to changing
1393 the parameter to an 'int' (as done below, for PCC
1394 on most machines), is the right thing to do
1395 on all machines, but I don't want to risk breaking
1396 something that already works. On most PCC machines,
1397 the sparc problem doesn't come up because the calling
1398 function has to zero the top bytes (not knowing whether
1399 the called function wants an int or a short), so there
1400 is no practical difference between an int and a short
1401 (except perhaps what happens when the GDB user types
1402 "print short_arg = 0x10000;").
1404 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1405 actually produces the correct address (we don't need to fix it
1406 up). I made this code adapt so that it will offset the symbol
1407 if it was pointing at an int-aligned location and not
1408 otherwise. This way you can use the same gdb for 4.0.x and
1411 If the parameter is shorter than an int, and is integral
1412 (e.g. char, short, or unsigned equivalent), and is claimed to
1413 be passed on an integer boundary, don't believe it! Offset the
1414 parameter's address to the tail-end of that integer. */
1416 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1417 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1418 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1419 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
1421 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
1422 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1426 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1428 /* If PCC says a parameter is a short or a char,
1429 it is really an int. */
1430 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1431 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1432 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1434 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1435 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
1440 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1443 /* acc seems to use P to delare the prototypes of functions that
1444 are referenced by this file. gdb is not prepared to deal
1445 with this extra information. FIXME, it ought to. */
1447 goto process_prototype_types
;
1449 /* Parameter which is in a register. */
1450 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1451 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1452 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1454 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1455 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1457 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1458 add_symbol_to_list (sym
, &local_symbols
);
1461 #ifdef IBM6000_TARGET
1465 /* Register variable (either global or local). */
1466 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1467 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1468 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1470 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1471 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1473 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1474 if (within_function
)
1475 add_symbol_to_list (sym
, &local_symbols
);
1477 add_symbol_to_list (sym
, &file_symbols
);
1481 /* Static symbol at top level of file */
1482 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1483 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1484 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1485 add_symbol_to_list (sym
, &file_symbols
);
1489 /* For a nameless type, we don't want a create a symbol, thus we
1490 did not use `sym'. Return without further processing. */
1491 if (nameless
) return NULL
;
1493 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1494 SYMBOL_VALUE (sym
) = valu
;
1495 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1496 /* C++ vagaries: we may have a type which is derived from
1497 a base type which did not have its name defined when the
1498 derived class was output. We fill in the derived class's
1499 base part member's name here in that case. */
1500 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1501 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1502 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1503 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1506 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1507 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1508 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1509 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1512 add_symbol_to_list (sym
, &file_symbols
);
1516 /* For a nameless type, we don't want a create a symbol, thus we
1517 did not use `sym'. Return without further processing. */
1518 if (nameless
) return NULL
;
1520 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1521 SYMBOL_VALUE (sym
) = valu
;
1522 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1523 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1524 TYPE_NAME (SYMBOL_TYPE (sym
))
1525 = obconcat (&objfile
-> type_obstack
, "",
1526 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1528 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1529 ? "struct " : "union ")),
1531 add_symbol_to_list (sym
, &file_symbols
);
1535 register struct symbol
*typedef_sym
= (struct symbol
*)
1536 obstack_alloc (&objfile
-> type_obstack
,
1537 sizeof (struct symbol
));
1538 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1539 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1541 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1542 SYMBOL_VALUE (typedef_sym
) = valu
;
1543 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1544 add_symbol_to_list (typedef_sym
, &file_symbols
);
1549 /* Static symbol of local scope */
1550 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1551 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1552 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1553 add_symbol_to_list (sym
, &local_symbols
);
1557 /* Reference parameter */
1558 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1559 SYMBOL_VALUE (sym
) = valu
;
1560 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1561 add_symbol_to_list (sym
, &local_symbols
);
1565 /* This is used by Sun FORTRAN for "function result value".
1566 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1567 that Pascal uses it too, but when I tried it Pascal used
1568 "x:3" (local symbol) instead. */
1569 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1570 SYMBOL_VALUE (sym
) = valu
;
1571 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1572 add_symbol_to_list (sym
, &local_symbols
);
1576 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1581 /* What about types defined as forward references inside of a small lexical
1583 /* Add a type to the list of undefined types to be checked through
1584 once this file has been read in. */
1586 add_undefined_type (type
)
1589 if (undef_types_length
== undef_types_allocated
)
1591 undef_types_allocated
*= 2;
1592 undef_types
= (struct type
**)
1593 xrealloc ((char *) undef_types
,
1594 undef_types_allocated
* sizeof (struct type
*));
1596 undef_types
[undef_types_length
++] = type
;
1599 /* Go through each undefined type, see if it's still undefined, and fix it
1600 up if possible. We have two kinds of undefined types:
1602 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1603 Fix: update array length using the element bounds
1604 and the target type's length.
1605 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1606 yet defined at the time a pointer to it was made.
1607 Fix: Do a full lookup on the struct/union tag. */
1609 cleanup_undefined_types ()
1613 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1614 switch (TYPE_CODE (*type
)) {
1616 case TYPE_CODE_STRUCT
:
1617 case TYPE_CODE_UNION
:
1618 case TYPE_CODE_ENUM
:
1620 /* Reasonable test to see if it's been defined since. */
1621 if (TYPE_NFIELDS (*type
) == 0)
1623 struct pending
*ppt
;
1625 /* Name of the type, without "struct" or "union" */
1626 char *typename
= TYPE_NAME (*type
);
1628 if (!strncmp (typename
, "struct ", 7))
1630 if (!strncmp (typename
, "union ", 6))
1632 if (!strncmp (typename
, "enum ", 5))
1635 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1636 for (i
= 0; i
< ppt
->nsyms
; i
++)
1638 struct symbol
*sym
= ppt
->symbol
[i
];
1640 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1641 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1642 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1644 && !strcmp (SYMBOL_NAME (sym
), typename
))
1645 memcpy (*type
, SYMBOL_TYPE (sym
), sizeof (struct type
));
1649 /* It has been defined; don't mark it as a stub. */
1650 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1654 case TYPE_CODE_ARRAY
:
1656 struct type
*range_type
;
1659 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1661 if (TYPE_NFIELDS (*type
) != 1)
1663 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1664 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1667 /* Now recompute the length of the array type, based on its
1668 number of elements and the target type's length. */
1669 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1670 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1671 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1672 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1678 error ("GDB internal error. cleanup_undefined_types with bad\
1679 type %d.", TYPE_CODE (*type
));
1683 undef_types_length
= 0;
1686 /* Skip rest of this symbol and return an error type.
1688 General notes on error recovery: error_type always skips to the
1689 end of the symbol (modulo cretinous dbx symbol name continuation).
1690 Thus code like this:
1692 if (*(*pp)++ != ';')
1693 return error_type (pp);
1695 is wrong because if *pp starts out pointing at '\0' (typically as the
1696 result of an earlier error), it will be incremented to point to the
1697 start of the next symbol, which might produce strange results, at least
1698 if you run off the end of the string table. Instead use
1701 return error_type (pp);
1707 foo = error_type (pp);
1711 And in case it isn't obvious, the point of all this hair is so the compiler
1712 can define new types and new syntaxes, and old versions of the
1713 debugger will be able to read the new symbol tables. */
1719 complain (&error_type_complaint
, 0);
1722 /* Skip to end of symbol. */
1723 while (**pp
!= '\0')
1726 /* Check for and handle cretinous dbx symbol name continuation! */
1727 if ((*pp
)[-1] == '\\')
1728 *pp
= next_symbol_text ();
1732 return builtin_type_error
;
1735 /* Read a dbx type reference or definition;
1736 return the type that is meant.
1737 This can be just a number, in which case it references
1738 a type already defined and placed in type_vector.
1739 Or the number can be followed by an =, in which case
1740 it means to define a new type according to the text that
1744 read_type (pp
, objfile
)
1746 struct objfile
*objfile
;
1748 register struct type
*type
= 0;
1753 /* Read type number if present. The type number may be omitted.
1754 for instance in a two-dimensional array declared with type
1755 "ar1;1;10;ar1;1;10;4". */
1756 if ((**pp
>= '0' && **pp
<= '9')
1759 read_type_number (pp
, typenums
);
1761 /* Type is not being defined here. Either it already exists,
1762 or this is a forward reference to it. dbx_alloc_type handles
1765 return dbx_alloc_type (typenums
, objfile
);
1767 /* Type is being defined here. */
1768 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1772 /* if such a type already exists, this is an unnecessary duplication
1773 of the stab string, which is common in (RS/6000) xlc generated
1774 objects. In that case, simply return NULL and let the caller take
1777 tt
= *dbx_lookup_type (typenums
);
1778 if (tt
&& tt
->length
&& tt
->code
)
1787 /* 'typenums=' not present, type is anonymous. Read and return
1788 the definition, but don't put it in the type vector. */
1789 typenums
[0] = typenums
[1] = -1;
1797 enum type_code code
;
1799 /* Used to index through file_symbols. */
1800 struct pending
*ppt
;
1803 /* Name including "struct", etc. */
1806 /* Name without "struct", etc. */
1807 char *type_name_only
;
1813 /* Set the type code according to the following letter. */
1817 code
= TYPE_CODE_STRUCT
;
1821 code
= TYPE_CODE_UNION
;
1825 code
= TYPE_CODE_ENUM
;
1829 return error_type (pp
);
1832 to
= type_name
= (char *)
1833 obstack_alloc (&objfile
-> type_obstack
,
1835 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1837 /* Copy the prefix. */
1839 while (*to
++ = *from
++)
1843 type_name_only
= to
;
1845 /* Copy the name. */
1847 while ((*to
++ = *from
++) != ':')
1851 /* Set the pointer ahead of the name which we just read. */
1855 /* The following hack is clearly wrong, because it doesn't
1856 check whether we are in a baseclass. I tried to reproduce
1857 the case that it is trying to fix, but I couldn't get
1858 g++ to put out a cross reference to a basetype. Perhaps
1859 it doesn't do it anymore. */
1860 /* Note: for C++, the cross reference may be to a base type which
1861 has not yet been seen. In this case, we skip to the comma,
1862 which will mark the end of the base class name. (The ':'
1863 at the end of the base class name will be skipped as well.)
1864 But sometimes (ie. when the cross ref is the last thing on
1865 the line) there will be no ','. */
1866 from
= (char *) strchr (*pp
, ',');
1872 /* Now check to see whether the type has already been declared. */
1873 /* This is necessary at least in the case where the
1874 program says something like
1876 The compiler puts out a cross-reference; we better find
1877 set the length of the structure correctly so we can
1878 set the length of the array. */
1879 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1880 for (i
= 0; i
< ppt
->nsyms
; i
++)
1882 struct symbol
*sym
= ppt
->symbol
[i
];
1884 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1885 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1886 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1887 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1889 obstack_free (&objfile
-> type_obstack
, type_name
);
1890 type
= SYMBOL_TYPE (sym
);
1895 /* Didn't find the type to which this refers, so we must
1896 be dealing with a forward reference. Allocate a type
1897 structure for it, and keep track of it so we can
1898 fill in the rest of the fields when we get the full
1900 type
= dbx_alloc_type (typenums
, objfile
);
1901 TYPE_CODE (type
) = code
;
1902 TYPE_NAME (type
) = type_name
;
1903 INIT_CPLUS_SPECIFIC(type
);
1904 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1906 add_undefined_type (type
);
1910 case '-': /* RS/6000 built-in type */
1912 type
= builtin_type (pp
); /* (in xcoffread.c) */
1927 read_type_number (pp
, xtypenums
);
1928 type
= *dbx_lookup_type (xtypenums
);
1933 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1934 if (typenums
[0] != -1)
1935 *dbx_lookup_type (typenums
) = type
;
1938 /* In the following types, we must be sure to overwrite any existing
1939 type that the typenums refer to, rather than allocating a new one
1940 and making the typenums point to the new one. This is because there
1941 may already be pointers to the existing type (if it had been
1942 forward-referenced), and we must change it to a pointer, function,
1943 reference, or whatever, *in-place*. */
1946 type1
= read_type (pp
, objfile
);
1947 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1950 case '&': /* Reference to another type */
1951 type1
= read_type (pp
, objfile
);
1952 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1955 case 'f': /* Function returning another type */
1956 type1
= read_type (pp
, objfile
);
1957 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1960 case 'k': /* Const qualifier on some type (Sun) */
1961 type
= read_type (pp
, objfile
);
1962 /* FIXME! For now, we ignore const and volatile qualifiers. */
1965 case 'B': /* Volatile qual on some type (Sun) */
1966 type
= read_type (pp
, objfile
);
1967 /* FIXME! For now, we ignore const and volatile qualifiers. */
1970 /* FIXME -- we should be doing smash_to_XXX types here. */
1971 case '@': /* Member (class & variable) type */
1973 struct type
*domain
= read_type (pp
, objfile
);
1974 struct type
*memtype
;
1977 /* Invalid member type data format. */
1978 return error_type (pp
);
1981 memtype
= read_type (pp
, objfile
);
1982 type
= dbx_alloc_type (typenums
, objfile
);
1983 smash_to_member_type (type
, domain
, memtype
);
1987 case '#': /* Method (class & fn) type */
1988 if ((*pp
)[0] == '#')
1990 /* We'll get the parameter types from the name. */
1991 struct type
*return_type
;
1994 return_type
= read_type (pp
, objfile
);
1995 if (*(*pp
)++ != ';')
1996 complain (&invalid_member_complaint
, (char *) symnum
);
1997 type
= allocate_stub_method (return_type
);
1998 if (typenums
[0] != -1)
1999 *dbx_lookup_type (typenums
) = type
;
2003 struct type
*domain
= read_type (pp
, objfile
);
2004 struct type
*return_type
;
2007 if (*(*pp
)++ != ',')
2008 error ("invalid member type data format, at symtab pos %d.",
2011 return_type
= read_type (pp
, objfile
);
2012 args
= read_args (pp
, ';', objfile
);
2013 type
= dbx_alloc_type (typenums
, objfile
);
2014 smash_to_method_type (type
, domain
, return_type
, args
);
2018 case 'r': /* Range type */
2019 type
= read_range_type (pp
, typenums
, objfile
);
2020 if (typenums
[0] != -1)
2021 *dbx_lookup_type (typenums
) = type
;
2024 case 'b': /* Sun ACC builtin int type */
2025 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2026 if (typenums
[0] != -1)
2027 *dbx_lookup_type (typenums
) = type
;
2030 case 'R': /* Sun ACC builtin float type */
2031 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2032 if (typenums
[0] != -1)
2033 *dbx_lookup_type (typenums
) = type
;
2036 case 'e': /* Enumeration type */
2037 type
= dbx_alloc_type (typenums
, objfile
);
2038 type
= read_enum_type (pp
, type
, objfile
);
2039 *dbx_lookup_type (typenums
) = type
;
2042 case 's': /* Struct type */
2043 type
= dbx_alloc_type (typenums
, objfile
);
2044 if (!TYPE_NAME (type
))
2045 TYPE_NAME (type
) = type_synonym_name
;
2046 type_synonym_name
= 0;
2047 type
= read_struct_type (pp
, type
, objfile
);
2050 case 'u': /* Union type */
2051 type
= dbx_alloc_type (typenums
, objfile
);
2052 if (!TYPE_NAME (type
))
2053 TYPE_NAME (type
) = type_synonym_name
;
2054 type_synonym_name
= 0;
2055 type
= read_struct_type (pp
, type
, objfile
);
2056 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2059 case 'a': /* Array type */
2061 return error_type (pp
);
2064 type
= dbx_alloc_type (typenums
, objfile
);
2065 type
= read_array_type (pp
, type
, objfile
);
2069 --*pp
; /* Go back to the symbol in error */
2070 /* Particularly important if it was \0! */
2071 return error_type (pp
);
2080 /* This page contains subroutines of read_type. */
2082 /* Read the description of a structure (or union type)
2083 and return an object describing the type. */
2085 static struct type
*
2086 read_struct_type (pp
, type
, objfile
)
2088 register struct type
*type
;
2089 struct objfile
*objfile
;
2091 /* Total number of methods defined in this class.
2092 If the class defines two `f' methods, and one `g' method,
2093 then this will have the value 3. */
2094 int total_length
= 0;
2098 struct nextfield
*next
;
2099 int visibility
; /* 0=public, 1=protected, 2=public */
2105 struct next_fnfield
*next
;
2106 struct fn_field fn_field
;
2109 struct next_fnfieldlist
2111 struct next_fnfieldlist
*next
;
2112 struct fn_fieldlist fn_fieldlist
;
2115 register struct nextfield
*list
= 0;
2116 struct nextfield
*new;
2119 int non_public_fields
= 0;
2122 register struct next_fnfieldlist
*mainlist
= 0;
2125 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2126 INIT_CPLUS_SPECIFIC(type
);
2128 /* First comes the total size in bytes. */
2130 TYPE_LENGTH (type
) = read_number (pp
, 0);
2132 /* C++: Now, if the class is a derived class, then the next character
2133 will be a '!', followed by the number of base classes derived from.
2134 Each element in the list contains visibility information,
2135 the offset of this base class in the derived structure,
2136 and then the base type. */
2139 int i
, n_baseclasses
, offset
;
2140 struct type
*baseclass
;
2143 /* Nonzero if it is a virtual baseclass, i.e.,
2147 struct C : public B, public virtual A {};
2149 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2150 2.0 language feature. */
2155 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
2157 n_baseclasses
= read_number (pp
, ',');
2158 TYPE_FIELD_VIRTUAL_BITS (type
) =
2159 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2160 B_BYTES (n_baseclasses
));
2161 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
2163 for (i
= 0; i
< n_baseclasses
; i
++)
2166 *pp
= next_symbol_text ();
2177 /* Bad visibility format. */
2178 return error_type (pp
);
2186 non_public_fields
++;
2192 /* Bad visibility format. */
2193 return error_type (pp
);
2196 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2199 /* Offset of the portion of the object corresponding to
2200 this baseclass. Always zero in the absence of
2201 multiple inheritance. */
2202 offset
= read_number (pp
, ',');
2203 baseclass
= read_type (pp
, objfile
);
2204 *pp
+= 1; /* skip trailing ';' */
2206 /* Make this baseclass visible for structure-printing purposes. */
2207 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2210 list
->visibility
= via_public
;
2211 list
->field
.type
= baseclass
;
2212 list
->field
.name
= type_name_no_tag (baseclass
);
2213 list
->field
.bitpos
= offset
;
2214 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2217 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
2220 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2221 At the end, we see a semicolon instead of a field.
2223 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2226 The `?' is a placeholder for one of '/2' (public visibility),
2227 '/1' (protected visibility), '/0' (private visibility), or nothing
2228 (C style symbol table, public visibility). */
2230 /* We better set p right now, in case there are no fields at all... */
2235 /* Check for and handle cretinous dbx symbol name continuation! */
2236 if (**pp
== '\\') *pp
= next_symbol_text ();
2238 /* Get space to record the next field's data. */
2239 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2243 /* Get the field name. */
2245 if (*p
== CPLUS_MARKER
)
2247 /* Special GNU C++ name. */
2252 struct type
*context
;
2263 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2264 prefix
= "INVALID_C++_ABBREV";
2268 context
= read_type (pp
, objfile
);
2269 name
= type_name_no_tag (context
);
2272 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
2275 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
2279 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2280 list
->field
.type
= read_type (pp
, objfile
);
2281 (*pp
)++; /* Skip the comma. */
2282 list
->field
.bitpos
= read_number (pp
, ';');
2283 /* This field is unpacked. */
2284 list
->field
.bitsize
= 0;
2285 list
->visibility
= 0; /* private */
2286 non_public_fields
++;
2288 /* GNU C++ anonymous type. */
2292 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2298 while (*p
!= ':') p
++;
2299 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
2300 &objfile
-> type_obstack
);
2302 /* C++: Check to see if we have hit the methods yet. */
2308 /* This means we have a visibility for a field coming. */
2314 list
->visibility
= 0; /* private */
2315 non_public_fields
++;
2320 list
->visibility
= 1; /* protected */
2321 non_public_fields
++;
2326 list
->visibility
= 2; /* public */
2331 else /* normal dbx-style format. */
2332 list
->visibility
= 2; /* public */
2334 list
->field
.type
= read_type (pp
, objfile
);
2337 /* Static class member. */
2338 list
->field
.bitpos
= (long)-1;
2340 while (*p
!= ';') p
++;
2341 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2346 else if (**pp
!= ',')
2347 /* Bad structure-type format. */
2348 return error_type (pp
);
2350 (*pp
)++; /* Skip the comma. */
2351 list
->field
.bitpos
= read_number (pp
, ',');
2352 list
->field
.bitsize
= read_number (pp
, ';');
2355 /* FIXME-tiemann: Can't the compiler put out something which
2356 lets us distinguish these? (or maybe just not put out anything
2357 for the field). What is the story here? What does the compiler
2358 really do? Also, patch gdb.texinfo for this case; I document
2359 it as a possible problem there. Search for "DBX-style". */
2361 /* This is wrong because this is identical to the symbols
2362 produced for GCC 0-size arrays. For example:
2367 The code which dumped core in such circumstances should be
2368 fixed not to dump core. */
2370 /* g++ -g0 can put out bitpos & bitsize zero for a static
2371 field. This does not give us any way of getting its
2372 class, so we can't know its name. But we can just
2373 ignore the field so we don't dump core and other nasty
2375 if (list
->field
.bitpos
== 0
2376 && list
->field
.bitsize
== 0)
2378 complain (&dbx_class_complaint
, 0);
2379 /* Ignore this field. */
2385 /* Detect an unpacked field and mark it as such.
2386 dbx gives a bit size for all fields.
2387 Note that forward refs cannot be packed,
2388 and treat enums as if they had the width of ints. */
2389 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2390 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2391 list
->field
.bitsize
= 0;
2392 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2393 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2394 && (list
->field
.bitsize
2395 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
2399 list
->field
.bitpos
% 8 == 0)
2400 list
->field
.bitsize
= 0;
2406 /* chill the list of fields: the last entry (at the head)
2407 is a partially constructed entry which we now scrub. */
2410 /* Now create the vector of fields, and record how big it is.
2411 We need this info to record proper virtual function table information
2412 for this class's virtual functions. */
2414 TYPE_NFIELDS (type
) = nfields
;
2415 TYPE_FIELDS (type
) = (struct field
*)
2416 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
2418 if (non_public_fields
)
2420 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2422 TYPE_FIELD_PRIVATE_BITS (type
) =
2423 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2425 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2427 TYPE_FIELD_PROTECTED_BITS (type
) =
2428 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2430 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2433 /* Copy the saved-up fields into the field vector. */
2435 for (n
= nfields
; list
; list
= list
->next
)
2438 TYPE_FIELD (type
, n
) = list
->field
;
2439 if (list
->visibility
== 0)
2440 SET_TYPE_FIELD_PRIVATE (type
, n
);
2441 else if (list
->visibility
== 1)
2442 SET_TYPE_FIELD_PROTECTED (type
, n
);
2445 /* Now come the method fields, as NAME::methods
2446 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2447 At the end, we see a semicolon instead of a field.
2449 For the case of overloaded operators, the format is
2450 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2451 `*' holds the place for an operator name (such as `+=')
2452 and `.' marks the end of the operator name. */
2455 /* Now, read in the methods. To simplify matters, we
2456 "unread" the name that has been read, so that we can
2457 start from the top. */
2459 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2460 /* For each list of method lists... */
2464 struct next_fnfield
*sublist
= 0;
2465 struct type
*look_ahead_type
= NULL
;
2467 struct next_fnfieldlist
*new_mainlist
=
2468 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2473 /* read in the name. */
2474 while (*p
!= ':') p
++;
2475 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2477 /* This is a completely wierd case. In order to stuff in the
2478 names that might contain colons (the usual name delimiter),
2479 Mike Tiemann defined a different name format which is
2480 signalled if the identifier is "op$". In that case, the
2481 format is "op$::XXXX." where XXXX is the name. This is
2482 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2483 /* This lets the user type "break operator+".
2484 We could just put in "+" as the name, but that wouldn't
2486 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2487 char *o
= opname
+ 3;
2489 /* Skip past '::'. */
2491 if (**pp
== '\\') *pp
= next_symbol_text ();
2495 main_fn_name
= savestring (opname
, o
- opname
);
2501 main_fn_name
= savestring (*pp
, p
- *pp
);
2502 /* Skip past '::'. */
2505 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2509 struct next_fnfield
*new_sublist
=
2510 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2512 /* Check for and handle cretinous dbx symbol name continuation! */
2513 if (look_ahead_type
== NULL
) /* Normal case. */
2515 if (**pp
== '\\') *pp
= next_symbol_text ();
2517 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2519 /* Invalid symtab info for method. */
2520 return error_type (pp
);
2523 { /* g++ version 1 kludge */
2524 new_sublist
->fn_field
.type
= look_ahead_type
;
2525 look_ahead_type
= NULL
;
2530 while (*p
!= ';') p
++;
2532 /* If this is just a stub, then we don't have the
2534 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
2535 new_sublist
->fn_field
.is_stub
= 1;
2536 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2539 /* Set this method's visibility fields. */
2540 switch (*(*pp
)++ - '0')
2543 new_sublist
->fn_field
.is_private
= 1;
2546 new_sublist
->fn_field
.is_protected
= 1;
2550 if (**pp
== '\\') *pp
= next_symbol_text ();
2553 case 'A': /* Normal functions. */
2554 new_sublist
->fn_field
.is_const
= 0;
2555 new_sublist
->fn_field
.is_volatile
= 0;
2558 case 'B': /* `const' member functions. */
2559 new_sublist
->fn_field
.is_const
= 1;
2560 new_sublist
->fn_field
.is_volatile
= 0;
2563 case 'C': /* `volatile' member function. */
2564 new_sublist
->fn_field
.is_const
= 0;
2565 new_sublist
->fn_field
.is_volatile
= 1;
2568 case 'D': /* `const volatile' member function. */
2569 new_sublist
->fn_field
.is_const
= 1;
2570 new_sublist
->fn_field
.is_volatile
= 1;
2573 case '*': /* File compiled with g++ version 1 -- no info */
2578 complain (&const_vol_complaint
, (char *) (long) **pp
);
2585 /* virtual member function, followed by index. */
2586 /* The sign bit is set to distinguish pointers-to-methods
2587 from virtual function indicies. Since the array is
2588 in words, the quantity must be shifted left by 1
2589 on 16 bit machine, and by 2 on 32 bit machine, forcing
2590 the sign bit out, and usable as a valid index into
2591 the array. Remove the sign bit here. */
2592 new_sublist
->fn_field
.voffset
=
2593 (0x7fffffff & read_number (pp
, ';')) + 2;
2595 if (**pp
== '\\') *pp
= next_symbol_text ();
2597 if (**pp
== ';' || **pp
== '\0')
2598 /* Must be g++ version 1. */
2599 new_sublist
->fn_field
.fcontext
= 0;
2602 /* Figure out from whence this virtual function came.
2603 It may belong to virtual function table of
2604 one of its baseclasses. */
2605 look_ahead_type
= read_type (pp
, objfile
);
2607 { /* g++ version 1 overloaded methods. */ }
2610 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2612 return error_type (pp
);
2615 look_ahead_type
= NULL
;
2621 /* static member function. */
2622 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2623 if (strncmp (new_sublist
->fn_field
.physname
,
2624 main_fn_name
, strlen (main_fn_name
)))
2625 new_sublist
->fn_field
.is_stub
= 1;
2630 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
2631 /* Fall through into normal member function. */
2634 /* normal member function. */
2635 new_sublist
->fn_field
.voffset
= 0;
2636 new_sublist
->fn_field
.fcontext
= 0;
2640 new_sublist
->next
= sublist
;
2641 sublist
= new_sublist
;
2643 if (**pp
== '\\') *pp
= next_symbol_text ();
2645 while (**pp
!= ';' && **pp
!= '\0');
2649 new_mainlist
->fn_fieldlist
.fn_fields
=
2650 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
2651 sizeof (struct fn_field
) * length
);
2652 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2653 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2655 new_mainlist
->fn_fieldlist
.length
= length
;
2656 new_mainlist
->next
= mainlist
;
2657 mainlist
= new_mainlist
;
2659 total_length
+= length
;
2660 if (**pp
== '\\') *pp
= next_symbol_text ();
2662 while (**pp
!= ';');
2670 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2671 obstack_alloc (&objfile
-> type_obstack
,
2672 sizeof (struct fn_fieldlist
) * nfn_fields
);
2673 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2674 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2679 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2680 TYPE_NFN_FIELDS_TOTAL (type
) +=
2681 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2684 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
2685 --n
; /* Circumvent Sun3 compiler bug */
2686 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
2693 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2695 /* Obsolete flags that used to indicate the presence
2696 of constructors and/or destructors. */
2700 /* Read either a '%' or the final ';'. */
2701 if (*(*pp
)++ == '%')
2703 /* We'd like to be able to derive the vtable pointer field
2704 from the type information, but when it's inherited, that's
2705 hard. A reason it's hard is because we may read in the
2706 info about a derived class before we read in info about
2707 the base class that provides the vtable pointer field.
2708 Once the base info has been read, we could fill in the info
2709 for the derived classes, but for the fact that by then,
2710 we don't remember who needs what. */
2713 int predicted_fieldno
= -1;
2716 /* Now we must record the virtual function table pointer's
2717 field information. */
2725 /* In version 2, we derive the vfield ourselves. */
2726 for (n
= 0; n
< nfields
; n
++)
2728 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2729 sizeof (vptr_name
) -1))
2731 predicted_fieldno
= n
;
2735 if (predicted_fieldno
< 0)
2736 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2737 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2738 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2740 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2746 t
= read_type (pp
, objfile
);
2748 while (*p
!= '\0' && *p
!= ';')
2751 /* Premature end of symbol. */
2752 return error_type (pp
);
2754 TYPE_VPTR_BASETYPE (type
) = t
;
2757 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2759 /* FIXME-tiemann: what's this? */
2761 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2766 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2767 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2768 sizeof (vptr_name
) -1))
2770 TYPE_VPTR_FIELDNO (type
) = i
;
2774 /* Virtual function table field not found. */
2775 return error_type (pp
);
2778 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2781 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2782 error ("TYPE_VPTR_FIELDNO miscalculated");
2792 /* Read a definition of an array type,
2793 and create and return a suitable type object.
2794 Also creates a range type which represents the bounds of that
2796 static struct type
*
2797 read_array_type (pp
, type
, objfile
)
2799 register struct type
*type
;
2800 struct objfile
*objfile
;
2802 struct type
*index_type
, *element_type
, *range_type
;
2806 /* Format of an array type:
2807 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2810 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2811 for these, produce a type like float[][]. */
2813 index_type
= read_type (pp
, objfile
);
2815 /* Improper format of array type decl. */
2816 return error_type (pp
);
2819 if (!(**pp
>= '0' && **pp
<= '9'))
2824 lower
= read_number (pp
, ';');
2826 if (!(**pp
>= '0' && **pp
<= '9'))
2831 upper
= read_number (pp
, ';');
2833 element_type
= read_type (pp
, objfile
);
2842 /* Create range type. */
2843 range_type
= (struct type
*)
2844 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2845 (void) memset (range_type
, 0, sizeof (struct type
));
2846 TYPE_OBJFILE (range_type
) = objfile
;
2847 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2848 TYPE_TARGET_TYPE (range_type
) = index_type
;
2850 /* This should never be needed. */
2851 TYPE_LENGTH (range_type
) = sizeof (int);
2853 TYPE_NFIELDS (range_type
) = 2;
2854 TYPE_FIELDS (range_type
) =
2855 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2856 2 * sizeof (struct field
));
2857 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2858 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2861 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2862 TYPE_TARGET_TYPE (type
) = element_type
;
2863 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2864 TYPE_NFIELDS (type
) = 1;
2865 TYPE_FIELDS (type
) =
2866 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2867 sizeof (struct field
));
2868 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2870 /* If we have an array whose element type is not yet known, but whose
2871 bounds *are* known, record it to be adjusted at the end of the file. */
2872 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2873 add_undefined_type (type
);
2879 /* Read a definition of an enumeration type,
2880 and create and return a suitable type object.
2881 Also defines the symbols that represent the values of the type. */
2883 static struct type
*
2884 read_enum_type (pp
, type
, objfile
)
2886 register struct type
*type
;
2887 struct objfile
*objfile
;
2892 register struct symbol
*sym
;
2894 struct pending
**symlist
;
2895 struct pending
*osyms
, *syms
;
2899 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2900 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2901 to do? For now, force all enum values to file scope. */
2902 if (within_function
)
2903 symlist
= &local_symbols
;
2906 symlist
= &file_symbols
;
2908 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2910 /* Read the value-names and their values.
2911 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2912 A semicolon or comma instead of a NAME means the end. */
2913 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2915 /* Check for and handle cretinous dbx symbol name continuation! */
2916 if (**pp
== '\\') *pp
= next_symbol_text ();
2919 while (*p
!= ':') p
++;
2920 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2922 n
= read_number (pp
, ',');
2924 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2925 (void) memset (sym
, 0, sizeof (struct symbol
));
2926 SYMBOL_NAME (sym
) = name
;
2927 SYMBOL_CLASS (sym
) = LOC_CONST
;
2928 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2929 SYMBOL_VALUE (sym
) = n
;
2930 add_symbol_to_list (sym
, symlist
);
2935 (*pp
)++; /* Skip the semicolon. */
2937 /* Now fill in the fields of the type-structure. */
2939 TYPE_LENGTH (type
) = sizeof (int);
2940 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2941 TYPE_NFIELDS (type
) = nsyms
;
2942 TYPE_FIELDS (type
) = (struct field
*)
2943 obstack_alloc (&objfile
-> type_obstack
,
2944 sizeof (struct field
) * nsyms
);
2946 /* Find the symbols for the values and put them into the type.
2947 The symbols can be found in the symlist that we put them on
2948 to cause them to be defined. osyms contains the old value
2949 of that symlist; everything up to there was defined by us. */
2950 /* Note that we preserve the order of the enum constants, so
2951 that in something like "enum {FOO, LAST_THING=FOO}" we print
2952 FOO, not LAST_THING. */
2954 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2959 for (; j
< syms
->nsyms
; j
++,n
++)
2961 struct symbol
*xsym
= syms
->symbol
[j
];
2962 SYMBOL_TYPE (xsym
) = type
;
2963 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2964 TYPE_FIELD_VALUE (type
, n
) = 0;
2965 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2966 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2973 /* This screws up perfectly good C programs with enums. FIXME. */
2974 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2975 if(TYPE_NFIELDS(type
) == 2 &&
2976 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2977 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2978 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2979 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2980 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2986 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2987 typedefs in every file (for int, long, etc):
2989 type = b <signed> <width>; <offset>; <nbits>
2990 signed = u or s. Possible c in addition to u or s (for char?).
2991 offset = offset from high order bit to start bit of type.
2992 width is # bytes in object of this type, nbits is # bits in type.
2994 The width/offset stuff appears to be for small objects stored in
2995 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2998 static struct type
*
2999 read_sun_builtin_type (pp
, typenums
, objfile
)
3002 struct objfile
*objfile
;
3015 return error_type (pp
);
3019 /* For some odd reason, all forms of char put a c here. This is strange
3020 because no other type has this honor. We can safely ignore this because
3021 we actually determine 'char'acterness by the number of bits specified in
3027 /* The first number appears to be the number of bytes occupied
3028 by this type, except that unsigned short is 4 instead of 2.
3029 Since this information is redundant with the third number,
3030 we will ignore it. */
3031 read_number (pp
, ';');
3033 /* The second number is always 0, so ignore it too. */
3034 read_number (pp
, ';');
3036 /* The third number is the number of bits for this type. */
3037 nbits
= read_number (pp
, 0);
3039 /* FIXME. Here we should just be able to make a type of the right
3040 number of bits and signedness. FIXME. */
3042 if (nbits
== TARGET_LONG_LONG_BIT
)
3043 return (lookup_fundamental_type (objfile
,
3044 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
3046 if (nbits
== TARGET_INT_BIT
) {
3047 /* FIXME -- the only way to distinguish `int' from `long'
3048 is to look at its name! */
3050 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3051 return lookup_fundamental_type (objfile
, FT_LONG
);
3053 return lookup_fundamental_type (objfile
, FT_INTEGER
);
3055 if (long_kludge_name
3056 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3057 long_kludge_name
[9] == 'l' /* long */)
3058 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3059 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
3061 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
3065 if (nbits
== TARGET_SHORT_BIT
)
3066 return (lookup_fundamental_type (objfile
,
3067 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
3069 if (nbits
== TARGET_CHAR_BIT
)
3070 return (lookup_fundamental_type (objfile
,
3071 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
3074 return lookup_fundamental_type (objfile
, FT_VOID
);
3076 return error_type (pp
);
3079 static struct type
*
3080 read_sun_floating_type (pp
, typenums
, objfile
)
3083 struct objfile
*objfile
;
3087 /* The first number has more details about the type, for example
3088 FN_COMPLEX. See the sun stab.h. */
3089 read_number (pp
, ';');
3091 /* The second number is the number of bytes occupied by this type */
3092 nbytes
= read_number (pp
, ';');
3095 return error_type (pp
);
3097 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
3098 return lookup_fundamental_type (objfile
, FT_FLOAT
);
3100 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3101 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3103 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3104 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3106 return error_type (pp
);
3109 /* Read a number from the string pointed to by *PP.
3110 The value of *PP is advanced over the number.
3111 If END is nonzero, the character that ends the
3112 number must match END, or an error happens;
3113 and that character is skipped if it does match.
3114 If END is zero, *PP is left pointing to that character.
3116 If the number fits in a long, set *VALUE and set *BITS to 0.
3117 If not, set *BITS to be the number of bits in the number.
3119 If encounter garbage, set *BITS to -1. */
3122 read_huge_number (pp
, end
, valu
, bits
)
3143 /* Leading zero means octal. GCC uses this to output values larger
3144 than an int (because that would be hard in decimal). */
3151 upper_limit
= LONG_MAX
/ radix
;
3152 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
3154 if (n
<= upper_limit
)
3157 n
+= c
- '0'; /* FIXME this overflows anyway */
3162 /* This depends on large values being output in octal, which is
3169 /* Ignore leading zeroes. */
3173 else if (c
== '2' || c
== '3')
3199 /* Large decimal constants are an error (because it is hard to
3200 count how many bits are in them). */
3206 /* -0x7f is the same as 0x80. So deal with it by adding one to
3207 the number of bits. */
3222 static struct type
*
3223 read_range_type (pp
, typenums
, objfile
)
3226 struct objfile
*objfile
;
3232 struct type
*result_type
;
3234 /* First comes a type we are a subrange of.
3235 In C it is usually 0, 1 or the type being defined. */
3236 read_type_number (pp
, rangenums
);
3237 self_subrange
= (rangenums
[0] == typenums
[0] &&
3238 rangenums
[1] == typenums
[1]);
3240 /* A semicolon should now follow; skip it. */
3244 /* The remaining two operands are usually lower and upper bounds
3245 of the range. But in some special cases they mean something else. */
3246 read_huge_number (pp
, ';', &n2
, &n2bits
);
3247 read_huge_number (pp
, ';', &n3
, &n3bits
);
3249 if (n2bits
== -1 || n3bits
== -1)
3250 return error_type (pp
);
3252 /* If limits are huge, must be large integral type. */
3253 if (n2bits
!= 0 || n3bits
!= 0)
3255 char got_signed
= 0;
3256 char got_unsigned
= 0;
3257 /* Number of bits in the type. */
3260 /* Range from 0 to <large number> is an unsigned large integral type. */
3261 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3266 /* Range from <large number> to <large number>-1 is a large signed
3268 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3274 /* Check for "long long". */
3275 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
3276 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3277 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
3278 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3280 if (got_signed
|| got_unsigned
)
3282 result_type
= (struct type
*)
3283 obstack_alloc (&objfile
-> type_obstack
,
3284 sizeof (struct type
));
3285 (void) memset (result_type
, 0, sizeof (struct type
));
3286 TYPE_OBJFILE (result_type
) = objfile
;
3287 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
3288 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
3290 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
3294 return error_type (pp
);
3297 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3298 if (self_subrange
&& n2
== 0 && n3
== 0)
3299 return (lookup_fundamental_type (objfile
, FT_VOID
));
3301 /* If n3 is zero and n2 is not, we want a floating type,
3302 and n2 is the width in bytes.
3304 Fortran programs appear to use this for complex types also,
3305 and they give no way to distinguish between double and single-complex!
3306 We don't have complex types, so we would lose on all fortran files!
3307 So return type `double' for all of those. It won't work right
3308 for the complex values, but at least it makes the file loadable.
3310 FIXME, we may be able to distinguish these by their names. FIXME. */
3312 if (n3
== 0 && n2
> 0)
3314 if (n2
== sizeof (float))
3315 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
3316 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
3319 /* If the upper bound is -1, it must really be an unsigned int. */
3321 else if (n2
== 0 && n3
== -1)
3323 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3324 long' is to look at its name! */
3326 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3327 long_kludge_name
[9] == 'l' /* long */)
3328 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3329 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3331 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3334 /* Special case: char is defined (Who knows why) as a subrange of
3335 itself with range 0-127. */
3336 else if (self_subrange
&& n2
== 0 && n3
== 127)
3337 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3339 /* Assumptions made here: Subrange of self is equivalent to subrange
3340 of int. FIXME: Host and target type-sizes assumed the same. */
3341 /* FIXME: This is the *only* place in GDB that depends on comparing
3342 some type to a builtin type with ==. Fix it! */
3344 && (self_subrange
||
3345 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
3347 /* an unsigned type */
3349 if (n3
== - sizeof (long long))
3350 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3352 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3353 long' is to look at its name! */
3354 if (n3
== (unsigned long)~0L &&
3355 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3356 long_kludge_name
[9] == 'l' /* long */)
3357 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3358 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3359 if (n3
== (unsigned int)~0L)
3360 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3361 if (n3
== (unsigned short)~0L)
3362 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
3363 if (n3
== (unsigned char)~0L)
3364 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
3367 else if (n3
== 0 && n2
== -sizeof (long long))
3368 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3370 else if (n2
== -n3
-1)
3373 /* FIXME -- the only way to distinguish `int' from `long' is to look
3375 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
3376 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3377 return (lookup_fundamental_type (objfile
, FT_LONG
));
3378 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
3379 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
3380 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
3381 return (lookup_fundamental_type (objfile
, FT_SHORT
));
3382 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
3383 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
3386 /* We have a real range type on our hands. Allocate space and
3387 return a real pointer. */
3389 /* At this point I don't have the faintest idea how to deal with
3390 a self_subrange type; I'm going to assume that this is used
3391 as an idiom, and that all of them are special cases. So . . . */
3393 return error_type (pp
);
3395 result_type
= (struct type
*)
3396 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
3397 (void) memset (result_type
, 0, sizeof (struct type
));
3398 TYPE_OBJFILE (result_type
) = objfile
;
3400 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3402 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3403 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3404 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
3405 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
3408 TYPE_NFIELDS (result_type
) = 2;
3409 TYPE_FIELDS (result_type
) =
3410 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
3411 2 * sizeof (struct field
));
3412 (void) memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
3413 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3414 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3416 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3421 /* Read a number from the string pointed to by *PP.
3422 The value of *PP is advanced over the number.
3423 If END is nonzero, the character that ends the
3424 number must match END, or an error happens;
3425 and that character is skipped if it does match.
3426 If END is zero, *PP is left pointing to that character. */
3429 read_number (pp
, end
)
3433 register char *p
= *pp
;
3434 register long n
= 0;
3438 /* Handle an optional leading minus sign. */
3446 /* Read the digits, as far as they go. */
3448 while ((c
= *p
++) >= '0' && c
<= '9')
3456 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3465 /* Read in an argument list. This is a list of types, separated by commas
3466 and terminated with END. Return the list of types read in, or (struct type
3467 **)-1 if there is an error. */
3468 static struct type
**
3469 read_args (pp
, end
, objfile
)
3472 struct objfile
*objfile
;
3474 /* FIXME! Remove this arbitrary limit! */
3475 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3481 /* Invalid argument list: no ','. */
3482 return (struct type
**)-1;
3485 /* Check for and handle cretinous dbx symbol name continuation! */
3487 *pp
= next_symbol_text ();
3489 types
[n
++] = read_type (pp
, objfile
);
3491 *pp
+= 1; /* get past `end' (the ':' character) */
3495 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3497 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3499 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3500 (void) memset (rval
+ n
, 0, sizeof (struct type
*));
3504 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3506 memcpy (rval
, types
, n
* sizeof (struct type
*));
3510 /* Add a common block's start address to the offset of each symbol
3511 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3512 the common block name). */
3515 fix_common_block (sym
, valu
)
3519 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3520 for ( ; next
; next
= next
->next
)
3523 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3524 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3528 /* Initializer for this module */
3530 _initialize_buildsym ()
3532 undef_types_allocated
= 20;
3533 undef_types_length
= 0;
3534 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3535 sizeof (struct type
*));