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 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
992 prev
= (struct symbol
*) 0;
994 /* Get the hash index and check all the symbols
995 under that hash index. */
997 hash
= hashname (msymbol
-> name
);
999 for (sym
= global_sym_chain
[hash
]; sym
;)
1001 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
1002 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
1004 /* Splice this symbol out of the hash chain and
1005 assign the value we have to it. */
1007 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1009 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1011 /* Check to see whether we need to fix up a common block. */
1012 /* Note: this code might be executed several times for
1013 the same symbol if there are multiple references. */
1014 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1015 fix_common_block (sym
, msymbol
-> address
);
1017 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
1020 sym
= SYMBOL_VALUE_CHAIN (prev
);
1022 sym
= global_sym_chain
[hash
];
1027 sym
= SYMBOL_VALUE_CHAIN (sym
);
1034 /* Read a number by which a type is referred to in dbx data,
1035 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1036 Just a single number N is equivalent to (0,N).
1037 Return the two numbers by storing them in the vector TYPENUMS.
1038 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1041 read_type_number (pp
, typenums
)
1043 register int *typenums
;
1048 typenums
[0] = read_number (pp
, ',');
1049 typenums
[1] = read_number (pp
, ')');
1054 typenums
[1] = read_number (pp
, 0);
1058 /* To handle GNU C++ typename abbreviation, we need to be able to
1059 fill in a type's name as soon as space for that type is allocated.
1060 `type_synonym_name' is the name of the type being allocated.
1061 It is cleared as soon as it is used (lest all allocated types
1063 static char *type_synonym_name
;
1067 define_symbol (valu
, string
, desc
, type
, objfile
)
1072 struct objfile
*objfile
;
1074 register struct symbol
*sym
;
1075 char *p
= (char *) strchr (string
, ':');
1079 struct type
*temptype
;
1081 /* We would like to eliminate nameless symbols, but keep their types.
1082 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1083 to type 2, but, should not creat a symbol to address that type. Since
1084 the symbol will be nameless, there is no way any user can refer to it. */
1088 /* Ignore syms with empty names. */
1092 /* Ignore old-style symbols from cc -go */
1096 /* If a nameless stab entry, all we need is the type, not the symbol.
1098 nameless
= (p
== string
);
1100 sym
= (struct symbol
*)obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1102 if (processing_gcc_compilation
) {
1103 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1104 number of bytes occupied by a type or object, which we ignore. */
1105 SYMBOL_LINE(sym
) = desc
;
1107 SYMBOL_LINE(sym
) = 0; /* unknown */
1110 if (string
[0] == CPLUS_MARKER
)
1112 /* Special GNU C++ names. */
1116 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1117 &objfile
-> symbol_obstack
);
1119 case 'v': /* $vtbl_ptr_type */
1120 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1123 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1124 &objfile
-> symbol_obstack
);
1128 /* This was an anonymous type that was never fixed up. */
1139 = (char *) obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1140 /* Open-coded bcopy--saves function call time. */
1142 register char *p1
= string
;
1143 register char *p2
= SYMBOL_NAME (sym
);
1150 /* Determine the type of name being defined. */
1151 /* The Acorn RISC machine's compiler can put out locals that don't
1152 start with "234=" or "(3,4)=", so assume anything other than the
1153 deftypes we know how to handle is a local. */
1154 /* (Peter Watkins @ Computervision)
1155 Handle Sun-style local fortran array types 'ar...' .
1156 (gnu@cygnus.com) -- this strchr() handles them properly?
1157 (tiemann@cygnus.com) -- 'C' is for catch. */
1159 #ifdef IBM6000_TARGET
1161 /* 'R' is for register parameters. */
1163 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1166 if (!strchr ("cfFGpPrStTvVXC", *p
))
1172 /* c is a special case, not followed by a type-number.
1173 SYMBOL:c=iVALUE for an integer constant symbol.
1174 SYMBOL:c=rVALUE for a floating constant symbol.
1175 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1176 e.g. "b:c=e6,0" for "const b = blob1"
1177 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1181 error ("Invalid symbol data at symtab pos %d.", symnum
);
1186 double d
= atof (p
);
1189 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1192 obstack_alloc (&objfile
-> type_obstack
,
1194 memcpy (dbl_valu
, &d
, sizeof (double));
1195 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1196 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1197 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1202 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1204 SYMBOL_VALUE (sym
) = atoi (p
);
1205 SYMBOL_CLASS (sym
) = LOC_CONST
;
1209 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1210 e.g. "b:c=e6,0" for "const b = blob1"
1211 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1215 read_type_number (&p
, typenums
);
1217 error ("Invalid symbol data: no comma in enum const symbol");
1219 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1220 SYMBOL_VALUE (sym
) = atoi (p
);
1221 SYMBOL_CLASS (sym
) = LOC_CONST
;
1225 error ("Invalid symbol data at symtab pos %d.", symnum
);
1227 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1228 add_symbol_to_list (sym
, &file_symbols
);
1232 /* Now usually comes a number that says which data type,
1233 and possibly more stuff to define the type
1234 (all of which is handled by read_type) */
1236 if (deftype
== 'p' && *p
== 'F')
1237 /* pF is a two-letter code that means a function parameter in Fortran.
1238 The type-number specifies the type of the return value.
1239 Translate it into a pointer-to-function type. */
1243 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
1246 #ifdef IBM6000_TARGET
1247 else if (deftype
== 'R')
1248 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1253 struct type
*type_read
;
1254 synonym
= *p
== 't';
1259 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1260 strlen (SYMBOL_NAME (sym
)),
1261 &objfile
-> symbol_obstack
);
1264 /* Here we save the name of the symbol for read_range_type, which
1265 ends up reading in the basic types. In stabs, unfortunately there
1266 is no distinction between "int" and "long" types except their
1267 names. Until we work out a saner type policy (eliminating most
1268 builtin types and using the names specified in the files), we
1269 save away the name so that far away from here in read_range_type,
1270 we can examine it to decide between "int" and "long". FIXME. */
1271 long_kludge_name
= SYMBOL_NAME (sym
);
1273 type_read
= read_type (&p
, objfile
);
1275 if ((deftype
== 'F' || deftype
== 'f') && *p
== ';') {
1276 /* Sun acc puts declared types of aguments here. We don't care
1277 about their actual types (FIXME -- we should remember the whole
1278 function prototype), but the list
1279 may define some new types that we have to remember, so we must
1283 read_type (&p
, objfile
);
1287 if ((deftype
== 'F' || deftype
== 'f')
1288 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
1291 /* This code doesn't work -- it needs to realloc and can't. */
1292 /* Attempt to set up to record a function prototype... */
1293 struct type
*new = (struct type
*)
1294 obstack_alloc (&objfile
-> type_obstack
,
1295 sizeof (struct type
));
1297 /* Generate a template for the type of this function. The
1298 types of the arguments will be added as we read the symbol
1300 *new = *lookup_function_type (type_read
);
1301 SYMBOL_TYPE(sym
) = new;
1302 TYPE_OBJFILE (new) = objfile
;
1303 in_function_type
= new;
1305 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
1309 SYMBOL_TYPE (sym
) = type_read
;
1315 /* The name of a caught exception. */
1316 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1317 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1318 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1319 add_symbol_to_list (sym
, &local_symbols
);
1323 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1324 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1325 add_symbol_to_list (sym
, &file_symbols
);
1329 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1330 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1331 add_symbol_to_list (sym
, &global_symbols
);
1335 /* For a class G (global) symbol, it appears that the
1336 value is not correct. It is necessary to search for the
1337 corresponding linker definition to find the value.
1338 These definitions appear at the end of the namelist. */
1339 i
= hashname (SYMBOL_NAME (sym
));
1340 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1341 global_sym_chain
[i
] = sym
;
1342 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1343 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1344 add_symbol_to_list (sym
, &global_symbols
);
1347 /* This case is faked by a conditional above,
1348 when there is no code letter in the dbx data.
1349 Dbx data never actually contains 'l'. */
1351 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1352 SYMBOL_VALUE (sym
) = valu
;
1353 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1354 add_symbol_to_list (sym
, &local_symbols
);
1358 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1359 can also be a LOC_LOCAL_ARG depending on symbol type. */
1360 #ifndef DBX_PARM_SYMBOL_CLASS
1361 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1363 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1364 SYMBOL_VALUE (sym
) = valu
;
1365 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1367 /* This doesn't work yet. */
1368 add_param_to_type (&in_function_type
, sym
);
1370 add_symbol_to_list (sym
, &local_symbols
);
1372 /* If it's gcc-compiled, if it says `short', believe it. */
1373 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1376 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1377 /* This macro is defined on machines (e.g. sparc) where
1378 we should believe the type of a PCC 'short' argument,
1379 but shouldn't believe the address (the address is
1380 the address of the corresponding int). Note that
1381 this is only different from the BELIEVE_PCC_PROMOTION
1382 case on big-endian machines.
1384 My guess is that this correction, as opposed to changing
1385 the parameter to an 'int' (as done below, for PCC
1386 on most machines), is the right thing to do
1387 on all machines, but I don't want to risk breaking
1388 something that already works. On most PCC machines,
1389 the sparc problem doesn't come up because the calling
1390 function has to zero the top bytes (not knowing whether
1391 the called function wants an int or a short), so there
1392 is no practical difference between an int and a short
1393 (except perhaps what happens when the GDB user types
1394 "print short_arg = 0x10000;").
1396 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1397 actually produces the correct address (we don't need to fix it
1398 up). I made this code adapt so that it will offset the symbol
1399 if it was pointing at an int-aligned location and not
1400 otherwise. This way you can use the same gdb for 4.0.x and
1403 If the parameter is shorter than an int, and is integral
1404 (e.g. char, short, or unsigned equivalent), and is claimed to
1405 be passed on an integer boundary, don't believe it! Offset the
1406 parameter's address to the tail-end of that integer. */
1408 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1409 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1410 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1411 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
1413 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
1414 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1418 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1420 /* If PCC says a parameter is a short or a char,
1421 it is really an int. */
1422 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1423 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1424 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1426 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1427 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
1432 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1435 /* Parameter which is in a register. */
1437 /* acc seems to use P to delare the types of functions that
1438 are called by this file. gdb is not prepared to deal
1439 with this extra information. */
1440 if (processing_acc_compilation
)
1443 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1444 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1445 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1447 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1448 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1450 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1451 add_symbol_to_list (sym
, &local_symbols
);
1454 #ifdef IBM6000_TARGET
1458 /* Register variable (either global or local). */
1459 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1460 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1461 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1463 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1464 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1466 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1467 if (within_function
)
1468 add_symbol_to_list (sym
, &local_symbols
);
1470 add_symbol_to_list (sym
, &file_symbols
);
1474 /* Static symbol at top level of file */
1475 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1476 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1477 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1478 add_symbol_to_list (sym
, &file_symbols
);
1482 /* For a nameless type, we don't want a create a symbol, thus we
1483 did not use `sym'. Return without further processing. */
1484 if (nameless
) return NULL
;
1486 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1487 SYMBOL_VALUE (sym
) = valu
;
1488 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1489 /* C++ vagaries: we may have a type which is derived from
1490 a base type which did not have its name defined when the
1491 derived class was output. We fill in the derived class's
1492 base part member's name here in that case. */
1493 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1494 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1495 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1496 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1499 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1500 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1501 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1502 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1505 add_symbol_to_list (sym
, &file_symbols
);
1509 /* For a nameless type, we don't want a create a symbol, thus we
1510 did not use `sym'. Return without further processing. */
1511 if (nameless
) return NULL
;
1513 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1514 SYMBOL_VALUE (sym
) = valu
;
1515 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1516 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1517 TYPE_NAME (SYMBOL_TYPE (sym
))
1518 = obconcat (&objfile
-> type_obstack
, "",
1519 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1521 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1522 ? "struct " : "union ")),
1524 add_symbol_to_list (sym
, &file_symbols
);
1528 register struct symbol
*typedef_sym
= (struct symbol
*)
1529 obstack_alloc (&objfile
-> type_obstack
,
1530 sizeof (struct symbol
));
1531 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1532 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1534 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1535 SYMBOL_VALUE (typedef_sym
) = valu
;
1536 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1537 add_symbol_to_list (typedef_sym
, &file_symbols
);
1542 /* Static symbol of local scope */
1543 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1544 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1545 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1546 add_symbol_to_list (sym
, &local_symbols
);
1550 /* Reference parameter */
1551 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1552 SYMBOL_VALUE (sym
) = valu
;
1553 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1554 add_symbol_to_list (sym
, &local_symbols
);
1558 /* This is used by Sun FORTRAN for "function result value".
1559 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1560 that Pascal uses it too, but when I tried it Pascal used
1561 "x:3" (local symbol) instead. */
1562 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1563 SYMBOL_VALUE (sym
) = valu
;
1564 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1565 add_symbol_to_list (sym
, &local_symbols
);
1569 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1574 /* What about types defined as forward references inside of a small lexical
1576 /* Add a type to the list of undefined types to be checked through
1577 once this file has been read in. */
1579 add_undefined_type (type
)
1582 if (undef_types_length
== undef_types_allocated
)
1584 undef_types_allocated
*= 2;
1585 undef_types
= (struct type
**)
1586 xrealloc ((char *) undef_types
,
1587 undef_types_allocated
* sizeof (struct type
*));
1589 undef_types
[undef_types_length
++] = type
;
1592 /* Go through each undefined type, see if it's still undefined, and fix it
1593 up if possible. We have two kinds of undefined types:
1595 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1596 Fix: update array length using the element bounds
1597 and the target type's length.
1598 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1599 yet defined at the time a pointer to it was made.
1600 Fix: Do a full lookup on the struct/union tag. */
1602 cleanup_undefined_types ()
1606 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1607 switch (TYPE_CODE (*type
)) {
1609 case TYPE_CODE_STRUCT
:
1610 case TYPE_CODE_UNION
:
1611 case TYPE_CODE_ENUM
:
1613 /* Reasonable test to see if it's been defined since. */
1614 if (TYPE_NFIELDS (*type
) == 0)
1616 struct pending
*ppt
;
1618 /* Name of the type, without "struct" or "union" */
1619 char *typename
= TYPE_NAME (*type
);
1621 if (!strncmp (typename
, "struct ", 7))
1623 if (!strncmp (typename
, "union ", 6))
1625 if (!strncmp (typename
, "enum ", 5))
1628 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1629 for (i
= 0; i
< ppt
->nsyms
; i
++)
1631 struct symbol
*sym
= ppt
->symbol
[i
];
1633 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1634 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1635 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1637 && !strcmp (SYMBOL_NAME (sym
), typename
))
1638 memcpy (*type
, SYMBOL_TYPE (sym
), sizeof (struct type
));
1642 /* It has been defined; don't mark it as a stub. */
1643 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1647 case TYPE_CODE_ARRAY
:
1649 struct type
*range_type
;
1652 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1654 if (TYPE_NFIELDS (*type
) != 1)
1656 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1657 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1660 /* Now recompute the length of the array type, based on its
1661 number of elements and the target type's length. */
1662 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1663 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1664 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1665 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1671 error ("GDB internal error. cleanup_undefined_types with bad\
1672 type %d.", TYPE_CODE (*type
));
1676 undef_types_length
= 0;
1679 /* Skip rest of this symbol and return an error type.
1681 General notes on error recovery: error_type always skips to the
1682 end of the symbol (modulo cretinous dbx symbol name continuation).
1683 Thus code like this:
1685 if (*(*pp)++ != ';')
1686 return error_type (pp);
1688 is wrong because if *pp starts out pointing at '\0' (typically as the
1689 result of an earlier error), it will be incremented to point to the
1690 start of the next symbol, which might produce strange results, at least
1691 if you run off the end of the string table. Instead use
1694 return error_type (pp);
1700 foo = error_type (pp);
1704 And in case it isn't obvious, the point of all this hair is so the compiler
1705 can define new types and new syntaxes, and old versions of the
1706 debugger will be able to read the new symbol tables. */
1712 complain (&error_type_complaint
, 0);
1715 /* Skip to end of symbol. */
1716 while (**pp
!= '\0')
1719 /* Check for and handle cretinous dbx symbol name continuation! */
1720 if ((*pp
)[-1] == '\\')
1721 *pp
= next_symbol_text ();
1725 return builtin_type_error
;
1728 /* Read a dbx type reference or definition;
1729 return the type that is meant.
1730 This can be just a number, in which case it references
1731 a type already defined and placed in type_vector.
1732 Or the number can be followed by an =, in which case
1733 it means to define a new type according to the text that
1737 read_type (pp
, objfile
)
1739 struct objfile
*objfile
;
1741 register struct type
*type
= 0;
1746 /* Read type number if present. The type number may be omitted.
1747 for instance in a two-dimensional array declared with type
1748 "ar1;1;10;ar1;1;10;4". */
1749 if ((**pp
>= '0' && **pp
<= '9')
1752 read_type_number (pp
, typenums
);
1754 /* Type is not being defined here. Either it already exists,
1755 or this is a forward reference to it. dbx_alloc_type handles
1758 return dbx_alloc_type (typenums
, objfile
);
1760 /* Type is being defined here. */
1761 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1765 /* if such a type already exists, this is an unnecessary duplication
1766 of the stab string, which is common in (RS/6000) xlc generated
1767 objects. In that case, simply return NULL and let the caller take
1770 tt
= *dbx_lookup_type (typenums
);
1771 if (tt
&& tt
->length
&& tt
->code
)
1780 /* 'typenums=' not present, type is anonymous. Read and return
1781 the definition, but don't put it in the type vector. */
1782 typenums
[0] = typenums
[1] = -1;
1790 enum type_code code
;
1792 /* Used to index through file_symbols. */
1793 struct pending
*ppt
;
1796 /* Name including "struct", etc. */
1799 /* Name without "struct", etc. */
1800 char *type_name_only
;
1806 /* Set the type code according to the following letter. */
1810 code
= TYPE_CODE_STRUCT
;
1814 code
= TYPE_CODE_UNION
;
1818 code
= TYPE_CODE_ENUM
;
1822 return error_type (pp
);
1825 to
= type_name
= (char *)
1826 obstack_alloc (&objfile
-> type_obstack
,
1828 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1830 /* Copy the prefix. */
1832 while (*to
++ = *from
++)
1836 type_name_only
= to
;
1838 /* Copy the name. */
1840 while ((*to
++ = *from
++) != ':')
1844 /* Set the pointer ahead of the name which we just read. */
1848 /* The following hack is clearly wrong, because it doesn't
1849 check whether we are in a baseclass. I tried to reproduce
1850 the case that it is trying to fix, but I couldn't get
1851 g++ to put out a cross reference to a basetype. Perhaps
1852 it doesn't do it anymore. */
1853 /* Note: for C++, the cross reference may be to a base type which
1854 has not yet been seen. In this case, we skip to the comma,
1855 which will mark the end of the base class name. (The ':'
1856 at the end of the base class name will be skipped as well.)
1857 But sometimes (ie. when the cross ref is the last thing on
1858 the line) there will be no ','. */
1859 from
= (char *) strchr (*pp
, ',');
1865 /* Now check to see whether the type has already been declared. */
1866 /* This is necessary at least in the case where the
1867 program says something like
1869 The compiler puts out a cross-reference; we better find
1870 set the length of the structure correctly so we can
1871 set the length of the array. */
1872 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1873 for (i
= 0; i
< ppt
->nsyms
; i
++)
1875 struct symbol
*sym
= ppt
->symbol
[i
];
1877 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1878 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1879 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1880 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1882 obstack_free (&objfile
-> type_obstack
, type_name
);
1883 type
= SYMBOL_TYPE (sym
);
1888 /* Didn't find the type to which this refers, so we must
1889 be dealing with a forward reference. Allocate a type
1890 structure for it, and keep track of it so we can
1891 fill in the rest of the fields when we get the full
1893 type
= dbx_alloc_type (typenums
, objfile
);
1894 TYPE_CODE (type
) = code
;
1895 TYPE_NAME (type
) = type_name
;
1896 INIT_CPLUS_SPECIFIC(type
);
1897 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1899 add_undefined_type (type
);
1903 case '-': /* RS/6000 built-in type */
1905 type
= builtin_type (pp
); /* (in xcoffread.c) */
1920 read_type_number (pp
, xtypenums
);
1921 type
= *dbx_lookup_type (xtypenums
);
1926 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1927 if (typenums
[0] != -1)
1928 *dbx_lookup_type (typenums
) = type
;
1931 /* In the following types, we must be sure to overwrite any existing
1932 type that the typenums refer to, rather than allocating a new one
1933 and making the typenums point to the new one. This is because there
1934 may already be pointers to the existing type (if it had been
1935 forward-referenced), and we must change it to a pointer, function,
1936 reference, or whatever, *in-place*. */
1939 type1
= read_type (pp
, objfile
);
1940 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1943 case '&': /* Reference to another type */
1944 type1
= read_type (pp
, objfile
);
1945 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1948 case 'f': /* Function returning another type */
1949 type1
= read_type (pp
, objfile
);
1950 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1953 /* FIXME -- we should be doing smash_to_XXX types here. */
1954 case '@': /* Member (class & variable) type */
1956 struct type
*domain
= read_type (pp
, objfile
);
1957 struct type
*memtype
;
1960 /* Invalid member type data format. */
1961 return error_type (pp
);
1964 memtype
= read_type (pp
, objfile
);
1965 type
= dbx_alloc_type (typenums
, objfile
);
1966 smash_to_member_type (type
, domain
, memtype
);
1970 case '#': /* Method (class & fn) type */
1971 if ((*pp
)[0] == '#')
1973 /* We'll get the parameter types from the name. */
1974 struct type
*return_type
;
1977 return_type
= read_type (pp
, objfile
);
1978 if (*(*pp
)++ != ';')
1979 complain (&invalid_member_complaint
, (char *) symnum
);
1980 type
= allocate_stub_method (return_type
);
1981 if (typenums
[0] != -1)
1982 *dbx_lookup_type (typenums
) = type
;
1986 struct type
*domain
= read_type (pp
, objfile
);
1987 struct type
*return_type
;
1990 if (*(*pp
)++ != ',')
1991 error ("invalid member type data format, at symtab pos %d.",
1994 return_type
= read_type (pp
, objfile
);
1995 args
= read_args (pp
, ';', objfile
);
1996 type
= dbx_alloc_type (typenums
, objfile
);
1997 smash_to_method_type (type
, domain
, return_type
, args
);
2001 case 'r': /* Range type */
2002 type
= read_range_type (pp
, typenums
, objfile
);
2003 if (typenums
[0] != -1)
2004 *dbx_lookup_type (typenums
) = type
;
2007 case 'b': /* Sun ACC builtin int type */
2008 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2009 if (typenums
[0] != -1)
2010 *dbx_lookup_type (typenums
) = type
;
2013 case 'R': /* Sun ACC builtin float type */
2014 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2015 if (typenums
[0] != -1)
2016 *dbx_lookup_type (typenums
) = type
;
2019 case 'e': /* Enumeration type */
2020 type
= dbx_alloc_type (typenums
, objfile
);
2021 type
= read_enum_type (pp
, type
, objfile
);
2022 *dbx_lookup_type (typenums
) = type
;
2025 case 's': /* Struct type */
2026 type
= dbx_alloc_type (typenums
, objfile
);
2027 if (!TYPE_NAME (type
))
2028 TYPE_NAME (type
) = type_synonym_name
;
2029 type_synonym_name
= 0;
2030 type
= read_struct_type (pp
, type
, objfile
);
2033 case 'u': /* Union type */
2034 type
= dbx_alloc_type (typenums
, objfile
);
2035 if (!TYPE_NAME (type
))
2036 TYPE_NAME (type
) = type_synonym_name
;
2037 type_synonym_name
= 0;
2038 type
= read_struct_type (pp
, type
, objfile
);
2039 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2042 case 'a': /* Array type */
2044 return error_type (pp
);
2047 type
= dbx_alloc_type (typenums
, objfile
);
2048 type
= read_array_type (pp
, type
, objfile
);
2052 --*pp
; /* Go back to the symbol in error */
2053 /* Particularly important if it was \0! */
2054 return error_type (pp
);
2063 /* This page contains subroutines of read_type. */
2065 /* Read the description of a structure (or union type)
2066 and return an object describing the type. */
2068 static struct type
*
2069 read_struct_type (pp
, type
, objfile
)
2071 register struct type
*type
;
2072 struct objfile
*objfile
;
2074 /* Total number of methods defined in this class.
2075 If the class defines two `f' methods, and one `g' method,
2076 then this will have the value 3. */
2077 int total_length
= 0;
2081 struct nextfield
*next
;
2082 int visibility
; /* 0=public, 1=protected, 2=public */
2088 struct next_fnfield
*next
;
2089 struct fn_field fn_field
;
2092 struct next_fnfieldlist
2094 struct next_fnfieldlist
*next
;
2095 struct fn_fieldlist fn_fieldlist
;
2098 register struct nextfield
*list
= 0;
2099 struct nextfield
*new;
2102 int non_public_fields
= 0;
2105 register struct next_fnfieldlist
*mainlist
= 0;
2108 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2109 INIT_CPLUS_SPECIFIC(type
);
2111 /* First comes the total size in bytes. */
2113 TYPE_LENGTH (type
) = read_number (pp
, 0);
2115 /* C++: Now, if the class is a derived class, then the next character
2116 will be a '!', followed by the number of base classes derived from.
2117 Each element in the list contains visibility information,
2118 the offset of this base class in the derived structure,
2119 and then the base type. */
2122 int i
, n_baseclasses
, offset
;
2123 struct type
*baseclass
;
2126 /* Nonzero if it is a virtual baseclass, i.e.,
2130 struct C : public B, public virtual A {};
2132 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2133 2.0 language feature. */
2138 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
2140 n_baseclasses
= read_number (pp
, ',');
2141 TYPE_FIELD_VIRTUAL_BITS (type
) =
2142 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2143 B_BYTES (n_baseclasses
));
2144 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
2146 for (i
= 0; i
< n_baseclasses
; i
++)
2149 *pp
= next_symbol_text ();
2160 /* Bad visibility format. */
2161 return error_type (pp
);
2169 non_public_fields
++;
2175 /* Bad visibility format. */
2176 return error_type (pp
);
2179 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2182 /* Offset of the portion of the object corresponding to
2183 this baseclass. Always zero in the absence of
2184 multiple inheritance. */
2185 offset
= read_number (pp
, ',');
2186 baseclass
= read_type (pp
, objfile
);
2187 *pp
+= 1; /* skip trailing ';' */
2189 /* Make this baseclass visible for structure-printing purposes. */
2190 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2193 list
->visibility
= via_public
;
2194 list
->field
.type
= baseclass
;
2195 list
->field
.name
= type_name_no_tag (baseclass
);
2196 list
->field
.bitpos
= offset
;
2197 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2200 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
2203 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2204 At the end, we see a semicolon instead of a field.
2206 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2209 The `?' is a placeholder for one of '/2' (public visibility),
2210 '/1' (protected visibility), '/0' (private visibility), or nothing
2211 (C style symbol table, public visibility). */
2213 /* We better set p right now, in case there are no fields at all... */
2218 /* Check for and handle cretinous dbx symbol name continuation! */
2219 if (**pp
== '\\') *pp
= next_symbol_text ();
2221 /* Get space to record the next field's data. */
2222 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2226 /* Get the field name. */
2228 if (*p
== CPLUS_MARKER
)
2230 /* Special GNU C++ name. */
2235 struct type
*context
;
2246 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2247 prefix
= "INVALID_C++_ABBREV";
2251 context
= read_type (pp
, objfile
);
2252 name
= type_name_no_tag (context
);
2255 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
2258 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
2262 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2263 list
->field
.type
= read_type (pp
, objfile
);
2264 (*pp
)++; /* Skip the comma. */
2265 list
->field
.bitpos
= read_number (pp
, ';');
2266 /* This field is unpacked. */
2267 list
->field
.bitsize
= 0;
2268 list
->visibility
= 0; /* private */
2269 non_public_fields
++;
2271 /* GNU C++ anonymous type. */
2275 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2281 while (*p
!= ':') p
++;
2282 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
2283 &objfile
-> type_obstack
);
2285 /* C++: Check to see if we have hit the methods yet. */
2291 /* This means we have a visibility for a field coming. */
2297 list
->visibility
= 0; /* private */
2298 non_public_fields
++;
2303 list
->visibility
= 1; /* protected */
2304 non_public_fields
++;
2309 list
->visibility
= 2; /* public */
2314 else /* normal dbx-style format. */
2315 list
->visibility
= 2; /* public */
2317 list
->field
.type
= read_type (pp
, objfile
);
2320 /* Static class member. */
2321 list
->field
.bitpos
= (long)-1;
2323 while (*p
!= ';') p
++;
2324 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2329 else if (**pp
!= ',')
2330 /* Bad structure-type format. */
2331 return error_type (pp
);
2333 (*pp
)++; /* Skip the comma. */
2334 list
->field
.bitpos
= read_number (pp
, ',');
2335 list
->field
.bitsize
= read_number (pp
, ';');
2338 /* FIXME-tiemann: Can't the compiler put out something which
2339 lets us distinguish these? (or maybe just not put out anything
2340 for the field). What is the story here? What does the compiler
2341 really do? Also, patch gdb.texinfo for this case; I document
2342 it as a possible problem there. Search for "DBX-style". */
2344 /* This is wrong because this is identical to the symbols
2345 produced for GCC 0-size arrays. For example:
2350 The code which dumped core in such circumstances should be
2351 fixed not to dump core. */
2353 /* g++ -g0 can put out bitpos & bitsize zero for a static
2354 field. This does not give us any way of getting its
2355 class, so we can't know its name. But we can just
2356 ignore the field so we don't dump core and other nasty
2358 if (list
->field
.bitpos
== 0
2359 && list
->field
.bitsize
== 0)
2361 complain (&dbx_class_complaint
, 0);
2362 /* Ignore this field. */
2368 /* Detect an unpacked field and mark it as such.
2369 dbx gives a bit size for all fields.
2370 Note that forward refs cannot be packed,
2371 and treat enums as if they had the width of ints. */
2372 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2373 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2374 list
->field
.bitsize
= 0;
2375 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2376 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2377 && (list
->field
.bitsize
2378 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
2382 list
->field
.bitpos
% 8 == 0)
2383 list
->field
.bitsize
= 0;
2389 /* chill the list of fields: the last entry (at the head)
2390 is a partially constructed entry which we now scrub. */
2393 /* Now create the vector of fields, and record how big it is.
2394 We need this info to record proper virtual function table information
2395 for this class's virtual functions. */
2397 TYPE_NFIELDS (type
) = nfields
;
2398 TYPE_FIELDS (type
) = (struct field
*)
2399 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
2401 if (non_public_fields
)
2403 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2405 TYPE_FIELD_PRIVATE_BITS (type
) =
2406 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2408 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2410 TYPE_FIELD_PROTECTED_BITS (type
) =
2411 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2413 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2416 /* Copy the saved-up fields into the field vector. */
2418 for (n
= nfields
; list
; list
= list
->next
)
2421 TYPE_FIELD (type
, n
) = list
->field
;
2422 if (list
->visibility
== 0)
2423 SET_TYPE_FIELD_PRIVATE (type
, n
);
2424 else if (list
->visibility
== 1)
2425 SET_TYPE_FIELD_PROTECTED (type
, n
);
2428 /* Now come the method fields, as NAME::methods
2429 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2430 At the end, we see a semicolon instead of a field.
2432 For the case of overloaded operators, the format is
2433 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2434 `*' holds the place for an operator name (such as `+=')
2435 and `.' marks the end of the operator name. */
2438 /* Now, read in the methods. To simplify matters, we
2439 "unread" the name that has been read, so that we can
2440 start from the top. */
2442 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2443 /* For each list of method lists... */
2447 struct next_fnfield
*sublist
= 0;
2448 struct type
*look_ahead_type
= NULL
;
2450 struct next_fnfieldlist
*new_mainlist
=
2451 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2456 /* read in the name. */
2457 while (*p
!= ':') p
++;
2458 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2460 /* This is a completely wierd case. In order to stuff in the
2461 names that might contain colons (the usual name delimiter),
2462 Mike Tiemann defined a different name format which is
2463 signalled if the identifier is "op$". In that case, the
2464 format is "op$::XXXX." where XXXX is the name. This is
2465 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2466 /* This lets the user type "break operator+".
2467 We could just put in "+" as the name, but that wouldn't
2469 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2470 char *o
= opname
+ 3;
2472 /* Skip past '::'. */
2474 if (**pp
== '\\') *pp
= next_symbol_text ();
2478 main_fn_name
= savestring (opname
, o
- opname
);
2484 main_fn_name
= savestring (*pp
, p
- *pp
);
2485 /* Skip past '::'. */
2488 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2492 struct next_fnfield
*new_sublist
=
2493 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2495 /* Check for and handle cretinous dbx symbol name continuation! */
2496 if (look_ahead_type
== NULL
) /* Normal case. */
2498 if (**pp
== '\\') *pp
= next_symbol_text ();
2500 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2502 /* Invalid symtab info for method. */
2503 return error_type (pp
);
2506 { /* g++ version 1 kludge */
2507 new_sublist
->fn_field
.type
= look_ahead_type
;
2508 look_ahead_type
= NULL
;
2513 while (*p
!= ';') p
++;
2515 /* If this is just a stub, then we don't have the
2517 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
2518 new_sublist
->fn_field
.is_stub
= 1;
2519 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2522 /* Set this method's visibility fields. */
2523 switch (*(*pp
)++ - '0')
2526 new_sublist
->fn_field
.is_private
= 1;
2529 new_sublist
->fn_field
.is_protected
= 1;
2533 if (**pp
== '\\') *pp
= next_symbol_text ();
2536 case 'A': /* Normal functions. */
2537 new_sublist
->fn_field
.is_const
= 0;
2538 new_sublist
->fn_field
.is_volatile
= 0;
2541 case 'B': /* `const' member functions. */
2542 new_sublist
->fn_field
.is_const
= 1;
2543 new_sublist
->fn_field
.is_volatile
= 0;
2546 case 'C': /* `volatile' member function. */
2547 new_sublist
->fn_field
.is_const
= 0;
2548 new_sublist
->fn_field
.is_volatile
= 1;
2551 case 'D': /* `const volatile' member function. */
2552 new_sublist
->fn_field
.is_const
= 1;
2553 new_sublist
->fn_field
.is_volatile
= 1;
2556 case '*': /* File compiled with g++ version 1 -- no info */
2561 complain (&const_vol_complaint
, (char *) (long) **pp
);
2568 /* virtual member function, followed by index. */
2569 /* The sign bit is set to distinguish pointers-to-methods
2570 from virtual function indicies. Since the array is
2571 in words, the quantity must be shifted left by 1
2572 on 16 bit machine, and by 2 on 32 bit machine, forcing
2573 the sign bit out, and usable as a valid index into
2574 the array. Remove the sign bit here. */
2575 new_sublist
->fn_field
.voffset
=
2576 (0x7fffffff & read_number (pp
, ';')) + 2;
2578 if (**pp
== '\\') *pp
= next_symbol_text ();
2580 if (**pp
== ';' || **pp
== '\0')
2581 /* Must be g++ version 1. */
2582 new_sublist
->fn_field
.fcontext
= 0;
2585 /* Figure out from whence this virtual function came.
2586 It may belong to virtual function table of
2587 one of its baseclasses. */
2588 look_ahead_type
= read_type (pp
, objfile
);
2590 { /* g++ version 1 overloaded methods. */ }
2593 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2595 return error_type (pp
);
2598 look_ahead_type
= NULL
;
2604 /* static member function. */
2605 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2606 if (strncmp (new_sublist
->fn_field
.physname
,
2607 main_fn_name
, strlen (main_fn_name
)))
2608 new_sublist
->fn_field
.is_stub
= 1;
2613 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
2614 /* Fall through into normal member function. */
2617 /* normal member function. */
2618 new_sublist
->fn_field
.voffset
= 0;
2619 new_sublist
->fn_field
.fcontext
= 0;
2623 new_sublist
->next
= sublist
;
2624 sublist
= new_sublist
;
2626 if (**pp
== '\\') *pp
= next_symbol_text ();
2628 while (**pp
!= ';' && **pp
!= '\0');
2632 new_mainlist
->fn_fieldlist
.fn_fields
=
2633 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
2634 sizeof (struct fn_field
) * length
);
2635 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2636 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2638 new_mainlist
->fn_fieldlist
.length
= length
;
2639 new_mainlist
->next
= mainlist
;
2640 mainlist
= new_mainlist
;
2642 total_length
+= length
;
2643 if (**pp
== '\\') *pp
= next_symbol_text ();
2645 while (**pp
!= ';');
2653 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2654 obstack_alloc (&objfile
-> type_obstack
,
2655 sizeof (struct fn_fieldlist
) * nfn_fields
);
2656 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2657 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2662 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2663 TYPE_NFN_FIELDS_TOTAL (type
) +=
2664 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2667 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
2668 --n
; /* Circumvent Sun3 compiler bug */
2669 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
2676 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2678 /* Obsolete flags that used to indicate the presence
2679 of constructors and/or destructors. */
2683 /* Read either a '%' or the final ';'. */
2684 if (*(*pp
)++ == '%')
2686 /* We'd like to be able to derive the vtable pointer field
2687 from the type information, but when it's inherited, that's
2688 hard. A reason it's hard is because we may read in the
2689 info about a derived class before we read in info about
2690 the base class that provides the vtable pointer field.
2691 Once the base info has been read, we could fill in the info
2692 for the derived classes, but for the fact that by then,
2693 we don't remember who needs what. */
2696 int predicted_fieldno
= -1;
2699 /* Now we must record the virtual function table pointer's
2700 field information. */
2708 /* In version 2, we derive the vfield ourselves. */
2709 for (n
= 0; n
< nfields
; n
++)
2711 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2712 sizeof (vptr_name
) -1))
2714 predicted_fieldno
= n
;
2718 if (predicted_fieldno
< 0)
2719 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2720 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2721 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2723 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2729 t
= read_type (pp
, objfile
);
2731 while (*p
!= '\0' && *p
!= ';')
2734 /* Premature end of symbol. */
2735 return error_type (pp
);
2737 TYPE_VPTR_BASETYPE (type
) = t
;
2740 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2742 /* FIXME-tiemann: what's this? */
2744 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2749 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2750 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2751 sizeof (vptr_name
) -1))
2753 TYPE_VPTR_FIELDNO (type
) = i
;
2757 /* Virtual function table field not found. */
2758 return error_type (pp
);
2761 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2764 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2765 error ("TYPE_VPTR_FIELDNO miscalculated");
2775 /* Read a definition of an array type,
2776 and create and return a suitable type object.
2777 Also creates a range type which represents the bounds of that
2779 static struct type
*
2780 read_array_type (pp
, type
, objfile
)
2782 register struct type
*type
;
2783 struct objfile
*objfile
;
2785 struct type
*index_type
, *element_type
, *range_type
;
2789 /* Format of an array type:
2790 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2793 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2794 for these, produce a type like float[][]. */
2796 index_type
= read_type (pp
, objfile
);
2798 /* Improper format of array type decl. */
2799 return error_type (pp
);
2802 if (!(**pp
>= '0' && **pp
<= '9'))
2807 lower
= read_number (pp
, ';');
2809 if (!(**pp
>= '0' && **pp
<= '9'))
2814 upper
= read_number (pp
, ';');
2816 element_type
= read_type (pp
, objfile
);
2825 /* Create range type. */
2826 range_type
= (struct type
*)
2827 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2828 (void) memset (range_type
, 0, sizeof (struct type
));
2829 TYPE_OBJFILE (range_type
) = objfile
;
2830 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2831 TYPE_TARGET_TYPE (range_type
) = index_type
;
2833 /* This should never be needed. */
2834 TYPE_LENGTH (range_type
) = sizeof (int);
2836 TYPE_NFIELDS (range_type
) = 2;
2837 TYPE_FIELDS (range_type
) =
2838 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2839 2 * sizeof (struct field
));
2840 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2841 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2844 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2845 TYPE_TARGET_TYPE (type
) = element_type
;
2846 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2847 TYPE_NFIELDS (type
) = 1;
2848 TYPE_FIELDS (type
) =
2849 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2850 sizeof (struct field
));
2851 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2853 /* If we have an array whose element type is not yet known, but whose
2854 bounds *are* known, record it to be adjusted at the end of the file. */
2855 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2856 add_undefined_type (type
);
2862 /* Read a definition of an enumeration type,
2863 and create and return a suitable type object.
2864 Also defines the symbols that represent the values of the type. */
2866 static struct type
*
2867 read_enum_type (pp
, type
, objfile
)
2869 register struct type
*type
;
2870 struct objfile
*objfile
;
2875 register struct symbol
*sym
;
2877 struct pending
**symlist
;
2878 struct pending
*osyms
, *syms
;
2882 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2883 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2884 to do? For now, force all enum values to file scope. */
2885 if (within_function
)
2886 symlist
= &local_symbols
;
2889 symlist
= &file_symbols
;
2891 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2893 /* Read the value-names and their values.
2894 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2895 A semicolon or comma instead of a NAME means the end. */
2896 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2898 /* Check for and handle cretinous dbx symbol name continuation! */
2899 if (**pp
== '\\') *pp
= next_symbol_text ();
2902 while (*p
!= ':') p
++;
2903 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2905 n
= read_number (pp
, ',');
2907 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2908 (void) memset (sym
, 0, sizeof (struct symbol
));
2909 SYMBOL_NAME (sym
) = name
;
2910 SYMBOL_CLASS (sym
) = LOC_CONST
;
2911 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2912 SYMBOL_VALUE (sym
) = n
;
2913 add_symbol_to_list (sym
, symlist
);
2918 (*pp
)++; /* Skip the semicolon. */
2920 /* Now fill in the fields of the type-structure. */
2922 TYPE_LENGTH (type
) = sizeof (int);
2923 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2924 TYPE_NFIELDS (type
) = nsyms
;
2925 TYPE_FIELDS (type
) = (struct field
*)
2926 obstack_alloc (&objfile
-> type_obstack
,
2927 sizeof (struct field
) * nsyms
);
2929 /* Find the symbols for the values and put them into the type.
2930 The symbols can be found in the symlist that we put them on
2931 to cause them to be defined. osyms contains the old value
2932 of that symlist; everything up to there was defined by us. */
2933 /* Note that we preserve the order of the enum constants, so
2934 that in something like "enum {FOO, LAST_THING=FOO}" we print
2935 FOO, not LAST_THING. */
2937 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2942 for (; j
< syms
->nsyms
; j
++,n
++)
2944 struct symbol
*xsym
= syms
->symbol
[j
];
2945 SYMBOL_TYPE (xsym
) = type
;
2946 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2947 TYPE_FIELD_VALUE (type
, n
) = 0;
2948 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2949 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2956 /* This screws up perfectly good C programs with enums. FIXME. */
2957 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2958 if(TYPE_NFIELDS(type
) == 2 &&
2959 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2960 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2961 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2962 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2963 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2969 /* this is for the initial typedefs in every file (for int, long, etc) */
2970 static struct type
*
2971 read_sun_builtin_type (pp
, typenums
, objfile
)
2974 struct objfile
*objfile
;
2987 return error_type (pp
);
2991 /* For some odd reason, all forms of char put a c here. This is strange
2992 because no other type has this honor. We can safely ignore this because
2993 we actually determine 'char'acterness by the number of bits specified in
2999 /* The first number appears to be the number of bytes occupied
3000 by this type, except that unsigned short is 4 instead of 2.
3001 Since this information is redundant with the third number,
3002 we will ignore it. */
3003 read_number (pp
, ';');
3005 /* The second number is always 0, so ignore it too. */
3006 read_number (pp
, ';');
3008 /* The third number is the number of bits for this type. */
3009 nbits
= read_number (pp
, 0);
3011 /* FIXME. Here we should just be able to make a type of the right
3012 number of bits and signedness. FIXME. */
3014 if (nbits
== TARGET_LONG_LONG_BIT
)
3015 return (lookup_fundamental_type (objfile
,
3016 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
3018 if (nbits
== TARGET_INT_BIT
) {
3019 /* FIXME -- the only way to distinguish `int' from `long'
3020 is to look at its name! */
3022 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3023 return lookup_fundamental_type (objfile
, FT_LONG
);
3025 return lookup_fundamental_type (objfile
, FT_INTEGER
);
3027 if (long_kludge_name
3028 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3029 long_kludge_name
[9] == 'l' /* long */)
3030 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3031 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
3033 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
3037 if (nbits
== TARGET_SHORT_BIT
)
3038 return (lookup_fundamental_type (objfile
,
3039 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
3041 if (nbits
== TARGET_CHAR_BIT
)
3042 return (lookup_fundamental_type (objfile
,
3043 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
3046 return lookup_fundamental_type (objfile
, FT_VOID
);
3048 return error_type (pp
);
3051 static struct type
*
3052 read_sun_floating_type (pp
, typenums
, objfile
)
3055 struct objfile
*objfile
;
3059 /* The first number has more details about the type, for example
3060 FN_COMPLEX. See the sun stab.h. */
3061 read_number (pp
, ';');
3063 /* The second number is the number of bytes occupied by this type */
3064 nbytes
= read_number (pp
, ';');
3067 return error_type (pp
);
3069 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
3070 return lookup_fundamental_type (objfile
, FT_FLOAT
);
3072 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3073 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3075 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3076 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3078 return error_type (pp
);
3081 /* Read a number from the string pointed to by *PP.
3082 The value of *PP is advanced over the number.
3083 If END is nonzero, the character that ends the
3084 number must match END, or an error happens;
3085 and that character is skipped if it does match.
3086 If END is zero, *PP is left pointing to that character.
3088 If the number fits in a long, set *VALUE and set *BITS to 0.
3089 If not, set *BITS to be the number of bits in the number.
3091 If encounter garbage, set *BITS to -1. */
3094 read_huge_number (pp
, end
, valu
, bits
)
3115 /* Leading zero means octal. GCC uses this to output values larger
3116 than an int (because that would be hard in decimal). */
3123 upper_limit
= LONG_MAX
/ radix
;
3124 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
3126 if (n
<= upper_limit
)
3129 n
+= c
- '0'; /* FIXME this overflows anyway */
3134 /* This depends on large values being output in octal, which is
3141 /* Ignore leading zeroes. */
3145 else if (c
== '2' || c
== '3')
3171 /* Large decimal constants are an error (because it is hard to
3172 count how many bits are in them). */
3178 /* -0x7f is the same as 0x80. So deal with it by adding one to
3179 the number of bits. */
3194 static struct type
*
3195 read_range_type (pp
, typenums
, objfile
)
3198 struct objfile
*objfile
;
3204 struct type
*result_type
;
3206 /* First comes a type we are a subrange of.
3207 In C it is usually 0, 1 or the type being defined. */
3208 read_type_number (pp
, rangenums
);
3209 self_subrange
= (rangenums
[0] == typenums
[0] &&
3210 rangenums
[1] == typenums
[1]);
3212 /* A semicolon should now follow; skip it. */
3216 /* The remaining two operands are usually lower and upper bounds
3217 of the range. But in some special cases they mean something else. */
3218 read_huge_number (pp
, ';', &n2
, &n2bits
);
3219 read_huge_number (pp
, ';', &n3
, &n3bits
);
3221 if (n2bits
== -1 || n3bits
== -1)
3222 return error_type (pp
);
3224 /* If limits are huge, must be large integral type. */
3225 if (n2bits
!= 0 || n3bits
!= 0)
3227 char got_signed
= 0;
3228 char got_unsigned
= 0;
3229 /* Number of bits in the type. */
3232 /* Range from 0 to <large number> is an unsigned large integral type. */
3233 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3238 /* Range from <large number> to <large number>-1 is a large signed
3240 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3246 /* Check for "long long". */
3247 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
3248 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3249 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
3250 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3252 if (got_signed
|| got_unsigned
)
3254 result_type
= (struct type
*)
3255 obstack_alloc (&objfile
-> type_obstack
,
3256 sizeof (struct type
));
3257 (void) memset (result_type
, 0, sizeof (struct type
));
3258 TYPE_OBJFILE (result_type
) = objfile
;
3259 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
3260 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
3262 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
3266 return error_type (pp
);
3269 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3270 if (self_subrange
&& n2
== 0 && n3
== 0)
3271 return (lookup_fundamental_type (objfile
, FT_VOID
));
3273 /* If n3 is zero and n2 is not, we want a floating type,
3274 and n2 is the width in bytes.
3276 Fortran programs appear to use this for complex types also,
3277 and they give no way to distinguish between double and single-complex!
3278 We don't have complex types, so we would lose on all fortran files!
3279 So return type `double' for all of those. It won't work right
3280 for the complex values, but at least it makes the file loadable.
3282 FIXME, we may be able to distinguish these by their names. FIXME. */
3284 if (n3
== 0 && n2
> 0)
3286 if (n2
== sizeof (float))
3287 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
3288 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
3291 /* If the upper bound is -1, it must really be an unsigned int. */
3293 else if (n2
== 0 && n3
== -1)
3295 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3296 long' is to look at its name! */
3298 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3299 long_kludge_name
[9] == 'l' /* long */)
3300 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3301 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3303 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3306 /* Special case: char is defined (Who knows why) as a subrange of
3307 itself with range 0-127. */
3308 else if (self_subrange
&& n2
== 0 && n3
== 127)
3309 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3311 /* Assumptions made here: Subrange of self is equivalent to subrange
3312 of int. FIXME: Host and target type-sizes assumed the same. */
3313 /* FIXME: This is the *only* place in GDB that depends on comparing
3314 some type to a builtin type with ==. Fix it! */
3316 && (self_subrange
||
3317 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
3319 /* an unsigned type */
3321 if (n3
== - sizeof (long long))
3322 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3324 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3325 long' is to look at its name! */
3326 if (n3
== (unsigned long)~0L &&
3327 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3328 long_kludge_name
[9] == 'l' /* long */)
3329 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3330 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3331 if (n3
== (unsigned int)~0L)
3332 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3333 if (n3
== (unsigned short)~0L)
3334 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
3335 if (n3
== (unsigned char)~0L)
3336 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
3339 else if (n3
== 0 && n2
== -sizeof (long long))
3340 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3342 else if (n2
== -n3
-1)
3345 /* FIXME -- the only way to distinguish `int' from `long' is to look
3347 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
3348 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3349 return (lookup_fundamental_type (objfile
, FT_LONG
));
3350 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
3351 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
3352 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
3353 return (lookup_fundamental_type (objfile
, FT_SHORT
));
3354 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
3355 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
3358 /* We have a real range type on our hands. Allocate space and
3359 return a real pointer. */
3361 /* At this point I don't have the faintest idea how to deal with
3362 a self_subrange type; I'm going to assume that this is used
3363 as an idiom, and that all of them are special cases. So . . . */
3365 return error_type (pp
);
3367 result_type
= (struct type
*)
3368 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
3369 (void) memset (result_type
, 0, sizeof (struct type
));
3370 TYPE_OBJFILE (result_type
) = objfile
;
3372 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3374 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3375 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3376 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
3377 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
3380 TYPE_NFIELDS (result_type
) = 2;
3381 TYPE_FIELDS (result_type
) =
3382 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
3383 2 * sizeof (struct field
));
3384 (void) memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
3385 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3386 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3388 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3393 /* Read a number from the string pointed to by *PP.
3394 The value of *PP is advanced over the number.
3395 If END is nonzero, the character that ends the
3396 number must match END, or an error happens;
3397 and that character is skipped if it does match.
3398 If END is zero, *PP is left pointing to that character. */
3401 read_number (pp
, end
)
3405 register char *p
= *pp
;
3406 register long n
= 0;
3410 /* Handle an optional leading minus sign. */
3418 /* Read the digits, as far as they go. */
3420 while ((c
= *p
++) >= '0' && c
<= '9')
3428 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3437 /* Read in an argument list. This is a list of types, separated by commas
3438 and terminated with END. Return the list of types read in, or (struct type
3439 **)-1 if there is an error. */
3440 static struct type
**
3441 read_args (pp
, end
, objfile
)
3444 struct objfile
*objfile
;
3446 /* FIXME! Remove this arbitrary limit! */
3447 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3453 /* Invalid argument list: no ','. */
3454 return (struct type
**)-1;
3457 /* Check for and handle cretinous dbx symbol name continuation! */
3459 *pp
= next_symbol_text ();
3461 types
[n
++] = read_type (pp
, objfile
);
3463 *pp
+= 1; /* get past `end' (the ':' character) */
3467 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3469 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3471 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3472 (void) memset (rval
+ n
, 0, sizeof (struct type
*));
3476 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3478 memcpy (rval
, types
, n
* sizeof (struct type
*));
3482 /* Add a common block's start address to the offset of each symbol
3483 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3484 the common block name). */
3487 fix_common_block (sym
, valu
)
3491 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3492 for ( ; next
; next
= next
->next
)
3495 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3496 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3500 /* Initializer for this module */
3502 _initialize_buildsym ()
3504 undef_types_allocated
= 20;
3505 undef_types_length
= 0;
3506 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3507 sizeof (struct type
*));