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 innerblock_anon_complaint
=
127 {"inner block not inside outer block", 0, 0};
129 struct complaint blockvector_complaint
=
130 {"block at 0x%x out of order", 0, 0};
133 struct complaint dbx_class_complaint
=
134 {"encountered DBX-style class variable debugging information.\n\
135 You seem to have compiled your program with \
136 \"g++ -g0\" instead of \"g++ -g\".\n\
137 Therefore GDB will not know about your class variables", 0, 0};
140 struct complaint invalid_cpp_abbrev_complaint
=
141 {"invalid C++ abbreviation `%s'", 0, 0};
143 struct complaint invalid_cpp_type_complaint
=
144 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
146 struct complaint member_fn_complaint
=
147 {"member function type missing, got '%c'", 0, 0};
149 struct complaint const_vol_complaint
=
150 {"const/volatile indicator missing, got '%c'", 0, 0};
152 struct complaint error_type_complaint
=
153 {"debug info mismatch between compiler and debugger", 0, 0};
155 struct complaint invalid_member_complaint
=
156 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
158 struct complaint range_type_base_complaint
=
159 {"base type %d of range type is not defined", 0, 0};
161 struct complaint reg_value_complaint
=
162 {"register number too large in symbol %s", 0, 0};
168 register char *p
= name
;
169 register int total
= p
[0];
182 /* Ensure result is positive. */
183 if (total
< 0) total
+= (1000 << 6);
184 return total
% HASHSIZE
;
188 /* Look up a dbx type-number pair. Return the address of the slot
189 where the type for that number-pair is stored.
190 The number-pair is in TYPENUMS.
192 This can be used for finding the type associated with that pair
193 or for associating a new type with the pair. */
196 dbx_lookup_type (typenums
)
199 register int filenum
= typenums
[0], index
= typenums
[1];
202 if (filenum
== -1) /* -1,-1 is for temporary types. */
205 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
206 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
207 filenum
, index
, symnum
);
211 /* Type is defined outside of header files.
212 Find it in this object file's type vector. */
213 if (index
>= type_vector_length
)
215 old_len
= type_vector_length
;
217 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
218 type_vector
= (struct type
**)
219 malloc (type_vector_length
* sizeof (struct type
*));
221 while (index
>= type_vector_length
)
222 type_vector_length
*= 2;
223 type_vector
= (struct type
**)
224 xrealloc ((char *) type_vector
,
225 (type_vector_length
* sizeof (struct type
*)));
226 memset (&type_vector
[old_len
], 0,
227 (type_vector_length
- old_len
) * sizeof (struct type
*));
229 return &type_vector
[index
];
233 register int real_filenum
= this_object_header_files
[filenum
];
234 register struct header_file
*f
;
237 if (real_filenum
>= n_header_files
)
240 f
= &header_files
[real_filenum
];
242 f_orig_length
= f
->length
;
243 if (index
>= f_orig_length
)
245 while (index
>= f
->length
)
247 f
->vector
= (struct type
**)
248 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
249 memset (&f
->vector
[f_orig_length
], 0,
250 (f
->length
- f_orig_length
) * sizeof (struct type
*));
252 return &f
->vector
[index
];
256 /* Make sure there is a type allocated for type numbers TYPENUMS
257 and return the type object.
258 This can create an empty (zeroed) type object.
259 TYPENUMS may be (-1, -1) to return a new type object that is not
260 put into the type vector, and so may not be referred to by number. */
263 dbx_alloc_type (typenums
, objfile
)
265 struct objfile
*objfile
;
267 register struct type
**type_addr
;
269 if (typenums
[0] == -1)
270 return alloc_type (objfile
);
272 type_addr
= dbx_lookup_type (typenums
);
274 /* If we are referring to a type not known at all yet,
275 allocate an empty type for it.
276 We will fill it in later if we find out how. */
278 *type_addr
= alloc_type (objfile
);
283 /* maintain the lists of symbols and blocks */
285 /* Add a symbol to one of the lists of symbols. */
287 add_symbol_to_list (symbol
, listhead
)
288 struct symbol
*symbol
;
289 struct pending
**listhead
;
291 /* We keep PENDINGSIZE symbols in each link of the list.
292 If we don't have a link with room in it, add a new link. */
293 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
295 register struct pending
*link
;
298 link
= free_pendings
;
299 free_pendings
= link
->next
;
302 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
304 link
->next
= *listhead
;
309 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
312 /* Find a symbol on a pending list. */
314 find_symbol_in_list (list
, name
, length
)
315 struct pending
*list
;
322 for (j
= list
->nsyms
; --j
>= 0; ) {
323 char *pp
= SYMBOL_NAME (list
->symbol
[j
]);
324 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 && pp
[length
] == '\0')
325 return list
->symbol
[j
];
332 /* At end of reading syms, or in case of quit,
333 really free as many `struct pending's as we can easily find. */
337 really_free_pendings (foo
)
340 struct pending
*next
, *next1
;
342 struct pending_block
*bnext
, *bnext1
;
345 for (next
= free_pendings
; next
; next
= next1
)
352 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
353 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
355 bnext1
= bnext
->next
;
361 for (next
= file_symbols
; next
; next
= next1
)
368 for (next
= global_symbols
; next
; next
= next1
)
376 /* Take one of the lists of symbols and make a block from it.
377 Keep the order the symbols have in the list (reversed from the input file).
378 Put the block on the list of pending blocks. */
381 finish_block (symbol
, listhead
, old_blocks
, start
, end
, objfile
)
382 struct symbol
*symbol
;
383 struct pending
**listhead
;
384 struct pending_block
*old_blocks
;
385 CORE_ADDR start
, end
;
386 struct objfile
*objfile
;
388 register struct pending
*next
, *next1
;
389 register struct block
*block
;
390 register struct pending_block
*pblock
;
391 struct pending_block
*opblock
;
394 /* Count the length of the list of symbols. */
396 for (next
= *listhead
, i
= 0;
398 i
+= next
->nsyms
, next
= next
->next
)
401 block
= (struct block
*) obstack_alloc (&objfile
-> symbol_obstack
,
402 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
404 /* Copy the symbols into the block. */
406 BLOCK_NSYMS (block
) = i
;
407 for (next
= *listhead
; next
; next
= next
->next
)
410 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
411 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
414 BLOCK_START (block
) = start
;
415 BLOCK_END (block
) = end
;
416 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
417 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
419 /* Put the block in as the value of the symbol that names it. */
423 SYMBOL_BLOCK_VALUE (symbol
) = block
;
424 BLOCK_FUNCTION (block
) = symbol
;
427 BLOCK_FUNCTION (block
) = 0;
429 /* Now "free" the links of the list, and empty the list. */
431 for (next
= *listhead
; next
; next
= next1
)
434 next
->next
= free_pendings
;
435 free_pendings
= next
;
439 /* Install this block as the superblock
440 of all blocks made since the start of this scope
441 that don't have superblocks yet. */
444 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
446 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
448 /* Check to be sure the blocks are nested as we receive them.
449 If the compiler/assembler/linker work, this just burns a small
451 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
452 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
454 complain(&innerblock_complaint
, SYMBOL_NAME (symbol
));
456 complain(&innerblock_anon_complaint
, 0);
457 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
458 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
461 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
466 /* Record this block on the list of all blocks in the file.
467 Put it after opblock, or at the beginning if opblock is 0.
468 This puts the block in the list after all its subblocks. */
470 /* Allocate in the symbol_obstack to save time.
471 It wastes a little space. */
472 pblock
= (struct pending_block
*)
473 obstack_alloc (&objfile
-> symbol_obstack
,
474 sizeof (struct pending_block
));
475 pblock
->block
= block
;
478 pblock
->next
= opblock
->next
;
479 opblock
->next
= pblock
;
483 pblock
->next
= pending_blocks
;
484 pending_blocks
= pblock
;
488 static struct blockvector
*
489 make_blockvector (objfile
)
490 struct objfile
*objfile
;
492 register struct pending_block
*next
;
493 register struct blockvector
*blockvector
;
496 /* Count the length of the list of blocks. */
498 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
500 blockvector
= (struct blockvector
*)
501 obstack_alloc (&objfile
-> symbol_obstack
,
502 (sizeof (struct blockvector
)
503 + (i
- 1) * sizeof (struct block
*)));
505 /* Copy the blocks into the blockvector.
506 This is done in reverse order, which happens to put
507 the blocks into the proper order (ascending starting address).
508 finish_block has hair to insert each block into the list
509 after its subblocks in order to make sure this is true. */
511 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
512 for (next
= pending_blocks
; next
; next
= next
->next
) {
513 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
516 #if 0 /* Now we make the links in the obstack, so don't free them. */
517 /* Now free the links of the list, and empty the list. */
519 for (next
= pending_blocks
; next
; next
= next1
)
527 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
528 /* Some compilers output blocks in the wrong order, but we depend
529 on their being in the right order so we can binary search.
530 Check the order and moan about it. FIXME. */
531 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
532 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
533 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
534 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
535 complain (&blockvector_complaint
,
536 (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
544 /* Start recording information about source code that came from an included
545 (or otherwise merged-in) source file with a different name. */
548 start_subfile (name
, dirname
)
552 register struct subfile
*subfile
;
554 /* See if this subfile is already known as a subfile of the
555 current main source file. */
557 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
559 if (!strcmp (subfile
->name
, name
))
561 current_subfile
= subfile
;
566 /* This subfile is not known. Add an entry for it.
567 Make an entry for this subfile in the list of all subfiles
568 of the current main source file. */
570 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
571 subfile
->next
= subfiles
;
573 current_subfile
= subfile
;
575 /* Save its name and compilation directory name */
576 subfile
->name
= strdup (name
);
578 subfile
->dirname
= NULL
;
580 subfile
->dirname
= strdup (dirname
);
582 /* Initialize line-number recording for this subfile. */
583 subfile
->line_vector
= 0;
586 /* Handle the N_BINCL and N_EINCL symbol types
587 that act like N_SOL for switching source files
588 (different subfiles, as we call them) within one object file,
589 but using a stack rather than in an arbitrary order. */
594 register struct subfile_stack
*tem
595 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
597 tem
->next
= subfile_stack
;
599 if (current_subfile
== 0 || current_subfile
->name
== 0)
601 tem
->name
= current_subfile
->name
;
608 register struct subfile_stack
*link
= subfile_stack
;
614 subfile_stack
= link
->next
;
620 /* Manage the vector of line numbers for each subfile. */
623 record_line (subfile
, line
, pc
)
624 register struct subfile
*subfile
;
628 struct linetable_entry
*e
;
629 /* Ignore the dummy line number in libg.o */
634 /* Make sure line vector exists and is big enough. */
635 if (!subfile
->line_vector
) {
636 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
637 subfile
->line_vector
= (struct linetable
*)
638 xmalloc (sizeof (struct linetable
)
639 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
640 subfile
->line_vector
->nitems
= 0;
643 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
645 subfile
->line_vector_length
*= 2;
646 subfile
->line_vector
= (struct linetable
*)
647 xrealloc ((char *) subfile
->line_vector
, (sizeof (struct linetable
)
648 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
651 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
652 e
->line
= line
; e
->pc
= pc
;
656 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
659 compare_line_numbers (ln1p
, ln2p
)
663 return (((struct linetable_entry
*) ln1p
) -> line
-
664 ((struct linetable_entry
*) ln2p
) -> line
);
668 /* Start a new symtab for a new source file.
669 This is called when a dbx symbol of type N_SO is seen;
670 it indicates the start of data for one original source file. */
673 start_symtab (name
, dirname
, start_addr
)
676 CORE_ADDR start_addr
;
679 last_source_file
= name
;
680 last_source_start_addr
= start_addr
;
683 global_stabs
= 0; /* AIX COFF */
686 /* Context stack is initially empty. Allocate first one with room for
687 10 levels; reuse it forever afterward. */
688 if (context_stack
== 0) {
689 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
690 context_stack
= (struct context_stack
*)
691 xmalloc (context_stack_size
* sizeof (struct context_stack
));
693 context_stack_depth
= 0;
695 /* Leave FILENUM of 0 free for builtin types and this file's types. */
696 n_this_object_header_files
= 1;
698 type_vector_length
= 0;
699 type_vector
= (struct type
**) 0;
701 /* Initialize the list of sub source files with one entry
702 for this file (the top-level source file). */
706 start_subfile (name
, dirname
);
709 /* for all the stabs in a given stab vector, build appropriate types
710 and fix their symbols in given symbol vector. */
713 patch_block_stabs (symbols
, stabs
, objfile
)
714 struct pending
*symbols
;
715 struct pending_stabs
*stabs
;
716 struct objfile
*objfile
;
723 /* for all the stab entries, find their corresponding symbols and
724 patch their types! */
726 for (ii
= 0; ii
< stabs
->count
; ++ii
)
728 char *name
= stabs
->stab
[ii
];
729 char *pp
= (char*) strchr (name
, ':');
730 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
733 #ifndef IBM6000_TARGET
734 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
740 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
743 lookup_function_type (read_type (&pp
, objfile
));
747 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
754 /* Finish the symbol definitions for one main source file,
755 close off all the lexical contexts for that file
756 (creating struct block's for them), then make the struct symtab
757 for that file and put it in the list of all such.
759 END_ADDR is the address of the end of the file's text. */
762 end_symtab (end_addr
, sort_pending
, sort_linevec
, objfile
)
766 struct objfile
*objfile
;
768 register struct symtab
*symtab
;
769 register struct blockvector
*blockvector
;
770 register struct subfile
*subfile
;
771 struct subfile
*nextsub
;
773 /* Finish the lexical context of the last function in the file;
774 pop the context stack. */
776 if (context_stack_depth
> 0)
778 register struct context_stack
*cstk
;
779 context_stack_depth
--;
780 cstk
= &context_stack
[context_stack_depth
];
781 /* Make a block for the local symbols within. */
782 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
783 cstk
->start_addr
, end_addr
, objfile
);
785 /* Debug: if context stack still has something in it, we are in
787 if (context_stack_depth
> 0)
791 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
792 in this stage. Especially, blocks for static functions will show up at
793 the end. We need to sort them, so tools like `find_pc_function' and
794 `find_pc_block' can work reliably. */
795 if (sort_pending
&& pending_blocks
) {
796 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
799 struct pending_block
*pb
, *pbnext
;
801 pb
= pending_blocks
, pbnext
= pb
->next
;
806 /* swap blocks if unordered! */
808 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
)) {
809 struct block
*tmp
= pb
->block
;
810 pb
->block
= pbnext
->block
;
815 pbnext
= pbnext
->next
;
820 /* Cleanup any undefined types that have been left hanging around
821 (this needs to be done before the finish_blocks so that
822 file_symbols is still good). */
823 cleanup_undefined_types ();
826 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
827 free ((PTR
)global_stabs
);
831 if (pending_blocks
== 0
833 && global_symbols
== 0) {
834 /* Ignore symtabs that have no functions with real debugging info */
837 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
838 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
839 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
840 blockvector
= make_blockvector (objfile
);
843 #ifdef PROCESS_LINENUMBER_HOOK
844 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
847 /* Now create the symtab objects proper, one for each subfile. */
848 /* (The main file is the last one on the chain.) */
850 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
853 /* If we have blocks of symbols, make a symtab.
854 Otherwise, just ignore this file and any line number info in it. */
857 if (subfile
->line_vector
) {
858 /* First, shrink the linetable to make more memory. */
859 linetablesize
= sizeof (struct linetable
) +
860 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
861 subfile
->line_vector
= (struct linetable
*)
862 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
865 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
866 sizeof (struct linetable_entry
), compare_line_numbers
);
869 /* Now, allocate a symbol table. */
870 symtab
= allocate_symtab (subfile
->name
, objfile
);
872 /* Fill in its components. */
873 symtab
->blockvector
= blockvector
;
874 if (subfile
->line_vector
)
876 /* Reallocate the line table on the symbol obstack */
877 symtab
->linetable
= (struct linetable
*)
878 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
879 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
883 symtab
->linetable
= NULL
;
885 symtab
->dirname
= subfile
->dirname
;
886 symtab
->free_code
= free_linetable
;
887 symtab
->free_ptr
= 0;
889 #ifdef IBM6000_TARGET
890 /* In case we need to duplicate symbol tables (to represent include
891 files), and in case our system needs relocation, we want to
892 relocate the main symbol table node only (for the main file,
893 not for the include files). */
895 symtab
->nonreloc
= TRUE
;
898 if (subfile
->line_vector
)
899 free ((PTR
)subfile
->line_vector
);
901 nextsub
= subfile
->next
;
905 #ifdef IBM6000_TARGET
906 /* all include symbol tables are non-relocatable, except the main source
909 symtab
->nonreloc
= FALSE
;
913 free ((char *) type_vector
);
915 type_vector_length
= 0;
917 last_source_file
= 0;
919 previous_stab_code
= 0;
925 /* Push a context block. Args are an identifying nesting level (checkable
926 when you pop it), and the starting PC address of this context. */
928 struct context_stack
*
929 push_context (desc
, valu
)
933 register struct context_stack
*new;
935 if (context_stack_depth
== context_stack_size
)
937 context_stack_size
*= 2;
938 context_stack
= (struct context_stack
*)
939 xrealloc ((char *) context_stack
,
940 (context_stack_size
* sizeof (struct context_stack
)));
943 new = &context_stack
[context_stack_depth
++];
945 new->locals
= local_symbols
;
946 new->old_blocks
= pending_blocks
;
947 new->start_addr
= valu
;
955 /* Initialize anything that needs initializing when starting to read
956 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
968 /* Initialize anything that needs initializing when a completely new
969 symbol file is specified (not just adding some symbols from another
970 file, e.g. a shared library). */
975 /* Empty the hash table of global syms looking for values. */
976 memset (global_sym_chain
, 0, sizeof global_sym_chain
);
981 /* Scan through all of the global symbols defined in the object file,
982 assigning values to the debugging symbols that need to be assigned
983 to. Get these symbols from the minimal symbol table. */
986 scan_file_globals (objfile
)
987 struct objfile
*objfile
;
990 struct minimal_symbol
*msymbol
;
991 struct symbol
*sym
, *prev
;
993 if (objfile
->msymbols
== 0) /* Beware the null file. */
996 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
1000 prev
= (struct symbol
*) 0;
1002 /* Get the hash index and check all the symbols
1003 under that hash index. */
1005 hash
= hashname (msymbol
-> name
);
1007 for (sym
= global_sym_chain
[hash
]; sym
;)
1009 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
1010 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
1012 /* Splice this symbol out of the hash chain and
1013 assign the value we have to it. */
1015 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1017 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1019 /* Check to see whether we need to fix up a common block. */
1020 /* Note: this code might be executed several times for
1021 the same symbol if there are multiple references. */
1022 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1023 fix_common_block (sym
, msymbol
-> address
);
1025 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
1028 sym
= SYMBOL_VALUE_CHAIN (prev
);
1030 sym
= global_sym_chain
[hash
];
1035 sym
= SYMBOL_VALUE_CHAIN (sym
);
1042 /* Read a number by which a type is referred to in dbx data,
1043 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1044 Just a single number N is equivalent to (0,N).
1045 Return the two numbers by storing them in the vector TYPENUMS.
1046 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1049 read_type_number (pp
, typenums
)
1051 register int *typenums
;
1056 typenums
[0] = read_number (pp
, ',');
1057 typenums
[1] = read_number (pp
, ')');
1062 typenums
[1] = read_number (pp
, 0);
1066 /* To handle GNU C++ typename abbreviation, we need to be able to
1067 fill in a type's name as soon as space for that type is allocated.
1068 `type_synonym_name' is the name of the type being allocated.
1069 It is cleared as soon as it is used (lest all allocated types
1071 static char *type_synonym_name
;
1075 define_symbol (valu
, string
, desc
, type
, objfile
)
1080 struct objfile
*objfile
;
1082 register struct symbol
*sym
;
1083 char *p
= (char *) strchr (string
, ':');
1087 struct type
*temptype
;
1089 /* We would like to eliminate nameless symbols, but keep their types.
1090 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1091 to type 2, but, should not creat a symbol to address that type. Since
1092 the symbol will be nameless, there is no way any user can refer to it. */
1096 /* Ignore syms with empty names. */
1100 /* Ignore old-style symbols from cc -go */
1104 /* If a nameless stab entry, all we need is the type, not the symbol.
1106 nameless
= (p
== string
);
1108 sym
= (struct symbol
*)obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1110 if (processing_gcc_compilation
) {
1111 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1112 number of bytes occupied by a type or object, which we ignore. */
1113 SYMBOL_LINE(sym
) = desc
;
1115 SYMBOL_LINE(sym
) = 0; /* unknown */
1118 if (string
[0] == CPLUS_MARKER
)
1120 /* Special GNU C++ names. */
1124 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1125 &objfile
-> symbol_obstack
);
1127 case 'v': /* $vtbl_ptr_type */
1128 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1131 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1132 &objfile
-> symbol_obstack
);
1136 /* This was an anonymous type that was never fixed up. */
1147 = (char *) obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1148 /* Open-coded bcopy--saves function call time. */
1150 register char *p1
= string
;
1151 register char *p2
= SYMBOL_NAME (sym
);
1158 /* Determine the type of name being defined. */
1159 /* The Acorn RISC machine's compiler can put out locals that don't
1160 start with "234=" or "(3,4)=", so assume anything other than the
1161 deftypes we know how to handle is a local. */
1162 /* (Peter Watkins @ Computervision)
1163 Handle Sun-style local fortran array types 'ar...' .
1164 (gnu@cygnus.com) -- this strchr() handles them properly?
1165 (tiemann@cygnus.com) -- 'C' is for catch. */
1167 #ifdef IBM6000_TARGET
1169 /* 'R' is for register parameters. */
1171 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1174 if (!strchr ("cfFGpPrStTvVXC", *p
))
1180 /* c is a special case, not followed by a type-number.
1181 SYMBOL:c=iVALUE for an integer constant symbol.
1182 SYMBOL:c=rVALUE for a floating constant symbol.
1183 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1184 e.g. "b:c=e6,0" for "const b = blob1"
1185 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1189 error ("Invalid symbol data at symtab pos %d.", symnum
);
1194 double d
= atof (p
);
1197 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1200 obstack_alloc (&objfile
-> type_obstack
,
1202 memcpy (dbl_valu
, &d
, sizeof (double));
1203 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1204 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1205 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1210 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1212 SYMBOL_VALUE (sym
) = atoi (p
);
1213 SYMBOL_CLASS (sym
) = LOC_CONST
;
1217 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1218 e.g. "b:c=e6,0" for "const b = blob1"
1219 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1223 read_type_number (&p
, typenums
);
1225 error ("Invalid symbol data: no comma in enum const symbol");
1227 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1228 SYMBOL_VALUE (sym
) = atoi (p
);
1229 SYMBOL_CLASS (sym
) = LOC_CONST
;
1233 error ("Invalid symbol data at symtab pos %d.", symnum
);
1235 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1236 add_symbol_to_list (sym
, &file_symbols
);
1240 /* Now usually comes a number that says which data type,
1241 and possibly more stuff to define the type
1242 (all of which is handled by read_type) */
1244 if (deftype
== 'p' && *p
== 'F')
1245 /* pF is a two-letter code that means a function parameter in Fortran.
1246 The type-number specifies the type of the return value.
1247 Translate it into a pointer-to-function type. */
1251 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
1254 #ifdef IBM6000_TARGET
1255 else if (deftype
== 'R')
1256 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1261 /* The symbol class letter is followed by a type (typically the
1262 type of the symbol, or its return-type, or etc). Read it. */
1264 synonym
= *p
== 't';
1269 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1270 strlen (SYMBOL_NAME (sym
)),
1271 &objfile
-> symbol_obstack
);
1274 /* Here we save the name of the symbol for read_range_type, which
1275 ends up reading in the basic types. In stabs, unfortunately there
1276 is no distinction between "int" and "long" types except their
1277 names. Until we work out a saner type policy (eliminating most
1278 builtin types and using the names specified in the files), we
1279 save away the name so that far away from here in read_range_type,
1280 we can examine it to decide between "int" and "long". FIXME. */
1281 long_kludge_name
= SYMBOL_NAME (sym
);
1283 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1289 /* The name of a caught exception. */
1290 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1291 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1292 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1293 add_symbol_to_list (sym
, &local_symbols
);
1297 /* A static function definition. */
1298 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1299 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1300 add_symbol_to_list (sym
, &file_symbols
);
1301 /* fall into process_function_types. */
1303 process_function_types
:
1304 /* Function result types are described as the result type in stabs.
1305 We need to convert this to the function-returning-type-X type
1306 in GDB. E.g. "int" is converted to "function returning int". */
1307 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1310 /* This code doesn't work -- it needs to realloc and can't. */
1311 /* Attempt to set up to record a function prototype... */
1312 struct type
*new = (struct type
*)
1313 obstack_alloc (&objfile
-> type_obstack
,
1314 sizeof (struct type
));
1316 /* Generate a template for the type of this function. The
1317 types of the arguments will be added as we read the symbol
1319 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
1320 SYMBOL_TYPE(sym
) = new;
1321 TYPE_OBJFILE (new) = objfile
;
1322 in_function_type
= new;
1324 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1327 /* fall into process_prototype_types */
1329 process_prototype_types
:
1330 /* Sun acc puts declared types of arguments here. We don't care
1331 about their actual types (FIXME -- we should remember the whole
1332 function prototype), but the list may define some new types
1333 that we have to remember, so we must scan it now. */
1336 read_type (&p
, objfile
);
1341 /* A global function definition. */
1342 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1343 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1344 add_symbol_to_list (sym
, &global_symbols
);
1345 goto process_function_types
;
1348 /* For a class G (global) symbol, it appears that the
1349 value is not correct. It is necessary to search for the
1350 corresponding linker definition to find the value.
1351 These definitions appear at the end of the namelist. */
1352 i
= hashname (SYMBOL_NAME (sym
));
1353 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1354 global_sym_chain
[i
] = sym
;
1355 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1356 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1357 add_symbol_to_list (sym
, &global_symbols
);
1360 /* This case is faked by a conditional above,
1361 when there is no code letter in the dbx data.
1362 Dbx data never actually contains 'l'. */
1364 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1365 SYMBOL_VALUE (sym
) = valu
;
1366 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1367 add_symbol_to_list (sym
, &local_symbols
);
1371 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1372 can also be a LOC_LOCAL_ARG depending on symbol type. */
1373 #ifndef DBX_PARM_SYMBOL_CLASS
1374 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1376 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1377 SYMBOL_VALUE (sym
) = valu
;
1378 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1380 /* This doesn't work yet. */
1381 add_param_to_type (&in_function_type
, sym
);
1383 add_symbol_to_list (sym
, &local_symbols
);
1385 /* If it's gcc-compiled, if it says `short', believe it. */
1386 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1389 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1390 /* This macro is defined on machines (e.g. sparc) where
1391 we should believe the type of a PCC 'short' argument,
1392 but shouldn't believe the address (the address is
1393 the address of the corresponding int). Note that
1394 this is only different from the BELIEVE_PCC_PROMOTION
1395 case on big-endian machines.
1397 My guess is that this correction, as opposed to changing
1398 the parameter to an 'int' (as done below, for PCC
1399 on most machines), is the right thing to do
1400 on all machines, but I don't want to risk breaking
1401 something that already works. On most PCC machines,
1402 the sparc problem doesn't come up because the calling
1403 function has to zero the top bytes (not knowing whether
1404 the called function wants an int or a short), so there
1405 is no practical difference between an int and a short
1406 (except perhaps what happens when the GDB user types
1407 "print short_arg = 0x10000;").
1409 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1410 actually produces the correct address (we don't need to fix it
1411 up). I made this code adapt so that it will offset the symbol
1412 if it was pointing at an int-aligned location and not
1413 otherwise. This way you can use the same gdb for 4.0.x and
1416 If the parameter is shorter than an int, and is integral
1417 (e.g. char, short, or unsigned equivalent), and is claimed to
1418 be passed on an integer boundary, don't believe it! Offset the
1419 parameter's address to the tail-end of that integer. */
1421 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1422 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1423 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1424 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
1426 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
1427 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1431 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1433 /* If PCC says a parameter is a short or a char,
1434 it is really an int. */
1435 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1436 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1437 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1439 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1440 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
1445 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1448 /* acc seems to use P to delare the prototypes of functions that
1449 are referenced by this file. gdb is not prepared to deal
1450 with this extra information. FIXME, it ought to. */
1452 goto process_prototype_types
;
1454 /* Parameter which is in a register. */
1455 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1456 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1457 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1459 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1460 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1462 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1463 add_symbol_to_list (sym
, &local_symbols
);
1466 #ifdef IBM6000_TARGET
1470 /* Register variable (either global or local). */
1471 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1472 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1473 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1475 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1476 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1478 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1479 if (within_function
)
1480 add_symbol_to_list (sym
, &local_symbols
);
1482 add_symbol_to_list (sym
, &file_symbols
);
1486 /* Static symbol at top level of file */
1487 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1488 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1489 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1490 add_symbol_to_list (sym
, &file_symbols
);
1494 /* For a nameless type, we don't want a create a symbol, thus we
1495 did not use `sym'. Return without further processing. */
1496 if (nameless
) return NULL
;
1498 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1499 SYMBOL_VALUE (sym
) = valu
;
1500 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1501 /* C++ vagaries: we may have a type which is derived from
1502 a base type which did not have its name defined when the
1503 derived class was output. We fill in the derived class's
1504 base part member's name here in that case. */
1505 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1506 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1507 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1508 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1511 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1512 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1513 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1514 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1517 add_symbol_to_list (sym
, &file_symbols
);
1521 /* For a nameless type, we don't want a create a symbol, thus we
1522 did not use `sym'. Return without further processing. */
1523 if (nameless
) return NULL
;
1525 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1526 SYMBOL_VALUE (sym
) = valu
;
1527 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1528 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1529 TYPE_NAME (SYMBOL_TYPE (sym
))
1530 = obconcat (&objfile
-> type_obstack
, "",
1531 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1533 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1534 ? "struct " : "union ")),
1536 add_symbol_to_list (sym
, &file_symbols
);
1540 register struct symbol
*typedef_sym
= (struct symbol
*)
1541 obstack_alloc (&objfile
-> type_obstack
,
1542 sizeof (struct symbol
));
1543 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1544 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1546 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1547 SYMBOL_VALUE (typedef_sym
) = valu
;
1548 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1549 add_symbol_to_list (typedef_sym
, &file_symbols
);
1554 /* Static symbol of local scope */
1555 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1556 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1557 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1558 add_symbol_to_list (sym
, &local_symbols
);
1562 /* Reference parameter */
1563 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1564 SYMBOL_VALUE (sym
) = valu
;
1565 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1566 add_symbol_to_list (sym
, &local_symbols
);
1570 /* This is used by Sun FORTRAN for "function result value".
1571 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1572 that Pascal uses it too, but when I tried it Pascal used
1573 "x:3" (local symbol) instead. */
1574 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1575 SYMBOL_VALUE (sym
) = valu
;
1576 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1577 add_symbol_to_list (sym
, &local_symbols
);
1581 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1586 /* What about types defined as forward references inside of a small lexical
1588 /* Add a type to the list of undefined types to be checked through
1589 once this file has been read in. */
1591 add_undefined_type (type
)
1594 if (undef_types_length
== undef_types_allocated
)
1596 undef_types_allocated
*= 2;
1597 undef_types
= (struct type
**)
1598 xrealloc ((char *) undef_types
,
1599 undef_types_allocated
* sizeof (struct type
*));
1601 undef_types
[undef_types_length
++] = type
;
1604 /* Go through each undefined type, see if it's still undefined, and fix it
1605 up if possible. We have two kinds of undefined types:
1607 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1608 Fix: update array length using the element bounds
1609 and the target type's length.
1610 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1611 yet defined at the time a pointer to it was made.
1612 Fix: Do a full lookup on the struct/union tag. */
1614 cleanup_undefined_types ()
1618 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1619 switch (TYPE_CODE (*type
)) {
1621 case TYPE_CODE_STRUCT
:
1622 case TYPE_CODE_UNION
:
1623 case TYPE_CODE_ENUM
:
1625 /* Check if it has been defined since. */
1626 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
1628 struct pending
*ppt
;
1630 /* Name of the type, without "struct" or "union" */
1631 char *typename
= TYPE_NAME (*type
);
1633 if (!strncmp (typename
, "struct ", 7))
1635 if (!strncmp (typename
, "union ", 6))
1637 if (!strncmp (typename
, "enum ", 5))
1640 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1641 for (i
= 0; i
< ppt
->nsyms
; i
++)
1643 struct symbol
*sym
= ppt
->symbol
[i
];
1645 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1646 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1647 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1649 && !strcmp (SYMBOL_NAME (sym
), typename
))
1650 memcpy (*type
, SYMBOL_TYPE (sym
), sizeof (struct type
));
1656 case TYPE_CODE_ARRAY
:
1658 struct type
*range_type
;
1661 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1663 if (TYPE_NFIELDS (*type
) != 1)
1665 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1666 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1669 /* Now recompute the length of the array type, based on its
1670 number of elements and the target type's length. */
1671 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1672 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1673 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1674 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1680 error ("GDB internal error. cleanup_undefined_types with bad\
1681 type %d.", TYPE_CODE (*type
));
1685 undef_types_length
= 0;
1688 /* Skip rest of this symbol and return an error type.
1690 General notes on error recovery: error_type always skips to the
1691 end of the symbol (modulo cretinous dbx symbol name continuation).
1692 Thus code like this:
1694 if (*(*pp)++ != ';')
1695 return error_type (pp);
1697 is wrong because if *pp starts out pointing at '\0' (typically as the
1698 result of an earlier error), it will be incremented to point to the
1699 start of the next symbol, which might produce strange results, at least
1700 if you run off the end of the string table. Instead use
1703 return error_type (pp);
1709 foo = error_type (pp);
1713 And in case it isn't obvious, the point of all this hair is so the compiler
1714 can define new types and new syntaxes, and old versions of the
1715 debugger will be able to read the new symbol tables. */
1721 complain (&error_type_complaint
, 0);
1724 /* Skip to end of symbol. */
1725 while (**pp
!= '\0')
1728 /* Check for and handle cretinous dbx symbol name continuation! */
1729 if ((*pp
)[-1] == '\\')
1730 *pp
= next_symbol_text ();
1734 return builtin_type_error
;
1737 /* Read a dbx type reference or definition;
1738 return the type that is meant.
1739 This can be just a number, in which case it references
1740 a type already defined and placed in type_vector.
1741 Or the number can be followed by an =, in which case
1742 it means to define a new type according to the text that
1746 read_type (pp
, objfile
)
1748 struct objfile
*objfile
;
1750 register struct type
*type
= 0;
1755 /* Read type number if present. The type number may be omitted.
1756 for instance in a two-dimensional array declared with type
1757 "ar1;1;10;ar1;1;10;4". */
1758 if ((**pp
>= '0' && **pp
<= '9')
1761 read_type_number (pp
, typenums
);
1763 /* Type is not being defined here. Either it already exists,
1764 or this is a forward reference to it. dbx_alloc_type handles
1767 return dbx_alloc_type (typenums
, objfile
);
1769 /* Type is being defined here. */
1770 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1774 /* if such a type already exists, this is an unnecessary duplication
1775 of the stab string, which is common in (RS/6000) xlc generated
1776 objects. In that case, simply return NULL and let the caller take
1779 tt
= *dbx_lookup_type (typenums
);
1780 if (tt
&& tt
->length
&& tt
->code
)
1789 /* 'typenums=' not present, type is anonymous. Read and return
1790 the definition, but don't put it in the type vector. */
1791 typenums
[0] = typenums
[1] = -1;
1799 enum type_code code
;
1801 /* Used to index through file_symbols. */
1802 struct pending
*ppt
;
1805 /* Name including "struct", etc. */
1808 /* Name without "struct", etc. */
1809 char *type_name_only
;
1815 /* Set the type code according to the following letter. */
1819 code
= TYPE_CODE_STRUCT
;
1823 code
= TYPE_CODE_UNION
;
1827 code
= TYPE_CODE_ENUM
;
1831 return error_type (pp
);
1834 to
= type_name
= (char *)
1835 obstack_alloc (&objfile
-> type_obstack
,
1837 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1839 /* Copy the prefix. */
1841 while (*to
++ = *from
++)
1845 type_name_only
= to
;
1847 /* Copy the name. */
1849 while ((*to
++ = *from
++) != ':')
1853 /* Set the pointer ahead of the name which we just read. */
1857 /* The following hack is clearly wrong, because it doesn't
1858 check whether we are in a baseclass. I tried to reproduce
1859 the case that it is trying to fix, but I couldn't get
1860 g++ to put out a cross reference to a basetype. Perhaps
1861 it doesn't do it anymore. */
1862 /* Note: for C++, the cross reference may be to a base type which
1863 has not yet been seen. In this case, we skip to the comma,
1864 which will mark the end of the base class name. (The ':'
1865 at the end of the base class name will be skipped as well.)
1866 But sometimes (ie. when the cross ref is the last thing on
1867 the line) there will be no ','. */
1868 from
= (char *) strchr (*pp
, ',');
1874 /* Now check to see whether the type has already been declared. */
1875 /* This is necessary at least in the case where the
1876 program says something like
1878 The compiler puts out a cross-reference; we better find
1879 set the length of the structure correctly so we can
1880 set the length of the array. */
1881 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1882 for (i
= 0; i
< ppt
->nsyms
; i
++)
1884 struct symbol
*sym
= ppt
->symbol
[i
];
1886 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1887 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1888 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1889 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1891 obstack_free (&objfile
-> type_obstack
, type_name
);
1892 type
= SYMBOL_TYPE (sym
);
1897 /* Didn't find the type to which this refers, so we must
1898 be dealing with a forward reference. Allocate a type
1899 structure for it, and keep track of it so we can
1900 fill in the rest of the fields when we get the full
1902 type
= dbx_alloc_type (typenums
, objfile
);
1903 TYPE_CODE (type
) = code
;
1904 TYPE_NAME (type
) = type_name
;
1905 INIT_CPLUS_SPECIFIC(type
);
1906 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1908 add_undefined_type (type
);
1912 case '-': /* RS/6000 built-in type */
1914 type
= builtin_type (pp
); /* (in xcoffread.c) */
1929 read_type_number (pp
, xtypenums
);
1930 type
= *dbx_lookup_type (xtypenums
);
1935 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1936 if (typenums
[0] != -1)
1937 *dbx_lookup_type (typenums
) = type
;
1940 /* In the following types, we must be sure to overwrite any existing
1941 type that the typenums refer to, rather than allocating a new one
1942 and making the typenums point to the new one. This is because there
1943 may already be pointers to the existing type (if it had been
1944 forward-referenced), and we must change it to a pointer, function,
1945 reference, or whatever, *in-place*. */
1948 type1
= read_type (pp
, objfile
);
1949 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1952 case '&': /* Reference to another type */
1953 type1
= read_type (pp
, objfile
);
1954 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1957 case 'f': /* Function returning another type */
1958 type1
= read_type (pp
, objfile
);
1959 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1962 case 'k': /* Const qualifier on some type (Sun) */
1963 type
= read_type (pp
, objfile
);
1964 /* FIXME! For now, we ignore const and volatile qualifiers. */
1967 case 'B': /* Volatile qual on some type (Sun) */
1968 type
= read_type (pp
, objfile
);
1969 /* FIXME! For now, we ignore const and volatile qualifiers. */
1972 /* FIXME -- we should be doing smash_to_XXX types here. */
1973 case '@': /* Member (class & variable) type */
1975 struct type
*domain
= read_type (pp
, objfile
);
1976 struct type
*memtype
;
1979 /* Invalid member type data format. */
1980 return error_type (pp
);
1983 memtype
= read_type (pp
, objfile
);
1984 type
= dbx_alloc_type (typenums
, objfile
);
1985 smash_to_member_type (type
, domain
, memtype
);
1989 case '#': /* Method (class & fn) type */
1990 if ((*pp
)[0] == '#')
1992 /* We'll get the parameter types from the name. */
1993 struct type
*return_type
;
1996 return_type
= read_type (pp
, objfile
);
1997 if (*(*pp
)++ != ';')
1998 complain (&invalid_member_complaint
, (char *) symnum
);
1999 type
= allocate_stub_method (return_type
);
2000 if (typenums
[0] != -1)
2001 *dbx_lookup_type (typenums
) = type
;
2005 struct type
*domain
= read_type (pp
, objfile
);
2006 struct type
*return_type
;
2009 if (*(*pp
)++ != ',')
2010 error ("invalid member type data format, at symtab pos %d.",
2013 return_type
= read_type (pp
, objfile
);
2014 args
= read_args (pp
, ';', objfile
);
2015 type
= dbx_alloc_type (typenums
, objfile
);
2016 smash_to_method_type (type
, domain
, return_type
, args
);
2020 case 'r': /* Range type */
2021 type
= read_range_type (pp
, typenums
, objfile
);
2022 if (typenums
[0] != -1)
2023 *dbx_lookup_type (typenums
) = type
;
2026 case 'b': /* Sun ACC builtin int type */
2027 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2028 if (typenums
[0] != -1)
2029 *dbx_lookup_type (typenums
) = type
;
2032 case 'R': /* Sun ACC builtin float type */
2033 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2034 if (typenums
[0] != -1)
2035 *dbx_lookup_type (typenums
) = type
;
2038 case 'e': /* Enumeration type */
2039 type
= dbx_alloc_type (typenums
, objfile
);
2040 type
= read_enum_type (pp
, type
, objfile
);
2041 *dbx_lookup_type (typenums
) = type
;
2044 case 's': /* Struct type */
2045 type
= dbx_alloc_type (typenums
, objfile
);
2046 if (!TYPE_NAME (type
))
2047 TYPE_NAME (type
) = type_synonym_name
;
2048 type_synonym_name
= 0;
2049 type
= read_struct_type (pp
, type
, objfile
);
2052 case 'u': /* Union type */
2053 type
= dbx_alloc_type (typenums
, objfile
);
2054 if (!TYPE_NAME (type
))
2055 TYPE_NAME (type
) = type_synonym_name
;
2056 type_synonym_name
= 0;
2057 type
= read_struct_type (pp
, type
, objfile
);
2058 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2061 case 'a': /* Array type */
2063 return error_type (pp
);
2066 type
= dbx_alloc_type (typenums
, objfile
);
2067 type
= read_array_type (pp
, type
, objfile
);
2071 --*pp
; /* Go back to the symbol in error */
2072 /* Particularly important if it was \0! */
2073 return error_type (pp
);
2082 /* This page contains subroutines of read_type. */
2084 /* Read the description of a structure (or union type)
2085 and return an object describing the type. */
2087 static struct type
*
2088 read_struct_type (pp
, type
, objfile
)
2090 register struct type
*type
;
2091 struct objfile
*objfile
;
2093 /* Total number of methods defined in this class.
2094 If the class defines two `f' methods, and one `g' method,
2095 then this will have the value 3. */
2096 int total_length
= 0;
2100 struct nextfield
*next
;
2101 int visibility
; /* 0=public, 1=protected, 2=public */
2107 struct next_fnfield
*next
;
2108 struct fn_field fn_field
;
2111 struct next_fnfieldlist
2113 struct next_fnfieldlist
*next
;
2114 struct fn_fieldlist fn_fieldlist
;
2117 register struct nextfield
*list
= 0;
2118 struct nextfield
*new;
2121 int non_public_fields
= 0;
2124 register struct next_fnfieldlist
*mainlist
= 0;
2127 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2128 INIT_CPLUS_SPECIFIC(type
);
2129 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2131 /* First comes the total size in bytes. */
2133 TYPE_LENGTH (type
) = read_number (pp
, 0);
2135 /* C++: Now, if the class is a derived class, then the next character
2136 will be a '!', followed by the number of base classes derived from.
2137 Each element in the list contains visibility information,
2138 the offset of this base class in the derived structure,
2139 and then the base type. */
2142 int i
, n_baseclasses
, offset
;
2143 struct type
*baseclass
;
2146 /* Nonzero if it is a virtual baseclass, i.e.,
2150 struct C : public B, public virtual A {};
2152 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2153 2.0 language feature. */
2158 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
2160 n_baseclasses
= read_number (pp
, ',');
2161 TYPE_FIELD_VIRTUAL_BITS (type
) =
2162 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2163 B_BYTES (n_baseclasses
));
2164 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
2166 for (i
= 0; i
< n_baseclasses
; i
++)
2169 *pp
= next_symbol_text ();
2180 /* Bad visibility format. */
2181 return error_type (pp
);
2189 non_public_fields
++;
2195 /* Bad visibility format. */
2196 return error_type (pp
);
2199 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2202 /* Offset of the portion of the object corresponding to
2203 this baseclass. Always zero in the absence of
2204 multiple inheritance. */
2205 offset
= read_number (pp
, ',');
2206 baseclass
= read_type (pp
, objfile
);
2207 *pp
+= 1; /* skip trailing ';' */
2209 /* Make this baseclass visible for structure-printing purposes. */
2210 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2213 list
->visibility
= via_public
;
2214 list
->field
.type
= baseclass
;
2215 list
->field
.name
= type_name_no_tag (baseclass
);
2216 list
->field
.bitpos
= offset
;
2217 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2220 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
2223 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2224 At the end, we see a semicolon instead of a field.
2226 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2229 The `?' is a placeholder for one of '/2' (public visibility),
2230 '/1' (protected visibility), '/0' (private visibility), or nothing
2231 (C style symbol table, public visibility). */
2233 /* We better set p right now, in case there are no fields at all... */
2238 /* Check for and handle cretinous dbx symbol name continuation! */
2239 if (**pp
== '\\') *pp
= next_symbol_text ();
2241 /* Get space to record the next field's data. */
2242 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2246 /* Get the field name. */
2248 if (*p
== CPLUS_MARKER
)
2250 /* Special GNU C++ name. */
2255 struct type
*context
;
2266 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2267 prefix
= "INVALID_C++_ABBREV";
2271 context
= read_type (pp
, objfile
);
2272 name
= type_name_no_tag (context
);
2275 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
2278 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
2282 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2283 list
->field
.type
= read_type (pp
, objfile
);
2284 (*pp
)++; /* Skip the comma. */
2285 list
->field
.bitpos
= read_number (pp
, ';');
2286 /* This field is unpacked. */
2287 list
->field
.bitsize
= 0;
2288 list
->visibility
= 0; /* private */
2289 non_public_fields
++;
2291 /* GNU C++ anonymous type. */
2295 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2301 while (*p
!= ':') p
++;
2302 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
2303 &objfile
-> type_obstack
);
2305 /* C++: Check to see if we have hit the methods yet. */
2311 /* This means we have a visibility for a field coming. */
2317 list
->visibility
= 0; /* private */
2318 non_public_fields
++;
2323 list
->visibility
= 1; /* protected */
2324 non_public_fields
++;
2329 list
->visibility
= 2; /* public */
2334 else /* normal dbx-style format. */
2335 list
->visibility
= 2; /* public */
2337 list
->field
.type
= read_type (pp
, objfile
);
2342 /* Possible future hook for nested types. */
2345 list
->field
.bitpos
= (long)-2; /* nested type */
2350 { /* Static class member. */
2351 list
->field
.bitpos
= (long)-1;
2353 while (*p
!= ';') p
++;
2354 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2359 else if (**pp
!= ',')
2360 /* Bad structure-type format. */
2361 return error_type (pp
);
2363 (*pp
)++; /* Skip the comma. */
2364 list
->field
.bitpos
= read_number (pp
, ',');
2365 list
->field
.bitsize
= read_number (pp
, ';');
2368 /* FIXME-tiemann: Can't the compiler put out something which
2369 lets us distinguish these? (or maybe just not put out anything
2370 for the field). What is the story here? What does the compiler
2371 really do? Also, patch gdb.texinfo for this case; I document
2372 it as a possible problem there. Search for "DBX-style". */
2374 /* This is wrong because this is identical to the symbols
2375 produced for GCC 0-size arrays. For example:
2380 The code which dumped core in such circumstances should be
2381 fixed not to dump core. */
2383 /* g++ -g0 can put out bitpos & bitsize zero for a static
2384 field. This does not give us any way of getting its
2385 class, so we can't know its name. But we can just
2386 ignore the field so we don't dump core and other nasty
2388 if (list
->field
.bitpos
== 0
2389 && list
->field
.bitsize
== 0)
2391 complain (&dbx_class_complaint
, 0);
2392 /* Ignore this field. */
2398 /* Detect an unpacked field and mark it as such.
2399 dbx gives a bit size for all fields.
2400 Note that forward refs cannot be packed,
2401 and treat enums as if they had the width of ints. */
2402 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2403 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2404 list
->field
.bitsize
= 0;
2405 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2406 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2407 && (list
->field
.bitsize
2408 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
2412 list
->field
.bitpos
% 8 == 0)
2413 list
->field
.bitsize
= 0;
2419 /* chill the list of fields: the last entry (at the head)
2420 is a partially constructed entry which we now scrub. */
2423 /* Now create the vector of fields, and record how big it is.
2424 We need this info to record proper virtual function table information
2425 for this class's virtual functions. */
2427 TYPE_NFIELDS (type
) = nfields
;
2428 TYPE_FIELDS (type
) = (struct field
*)
2429 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
2431 if (non_public_fields
)
2433 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2435 TYPE_FIELD_PRIVATE_BITS (type
) =
2436 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2438 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2440 TYPE_FIELD_PROTECTED_BITS (type
) =
2441 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2443 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2446 /* Copy the saved-up fields into the field vector. */
2448 for (n
= nfields
; list
; list
= list
->next
)
2451 TYPE_FIELD (type
, n
) = list
->field
;
2452 if (list
->visibility
== 0)
2453 SET_TYPE_FIELD_PRIVATE (type
, n
);
2454 else if (list
->visibility
== 1)
2455 SET_TYPE_FIELD_PROTECTED (type
, n
);
2458 /* Now come the method fields, as NAME::methods
2459 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2460 At the end, we see a semicolon instead of a field.
2462 For the case of overloaded operators, the format is
2463 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2464 `*' holds the place for an operator name (such as `+=')
2465 and `.' marks the end of the operator name. */
2468 /* Now, read in the methods. To simplify matters, we
2469 "unread" the name that has been read, so that we can
2470 start from the top. */
2472 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2473 /* For each list of method lists... */
2477 struct next_fnfield
*sublist
= 0;
2478 struct type
*look_ahead_type
= NULL
;
2480 struct next_fnfieldlist
*new_mainlist
=
2481 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2486 /* read in the name. */
2487 while (*p
!= ':') p
++;
2488 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2490 /* This is a completely wierd case. In order to stuff in the
2491 names that might contain colons (the usual name delimiter),
2492 Mike Tiemann defined a different name format which is
2493 signalled if the identifier is "op$". In that case, the
2494 format is "op$::XXXX." where XXXX is the name. This is
2495 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2496 /* This lets the user type "break operator+".
2497 We could just put in "+" as the name, but that wouldn't
2499 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2500 char *o
= opname
+ 3;
2502 /* Skip past '::'. */
2504 if (**pp
== '\\') *pp
= next_symbol_text ();
2508 main_fn_name
= savestring (opname
, o
- opname
);
2514 main_fn_name
= savestring (*pp
, p
- *pp
);
2515 /* Skip past '::'. */
2518 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2522 struct next_fnfield
*new_sublist
=
2523 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2525 /* Check for and handle cretinous dbx symbol name continuation! */
2526 if (look_ahead_type
== NULL
) /* Normal case. */
2528 if (**pp
== '\\') *pp
= next_symbol_text ();
2530 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2532 /* Invalid symtab info for method. */
2533 return error_type (pp
);
2536 { /* g++ version 1 kludge */
2537 new_sublist
->fn_field
.type
= look_ahead_type
;
2538 look_ahead_type
= NULL
;
2543 while (*p
!= ';') p
++;
2545 /* If this is just a stub, then we don't have the
2547 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
2548 new_sublist
->fn_field
.is_stub
= 1;
2549 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2552 /* Set this method's visibility fields. */
2553 switch (*(*pp
)++ - '0')
2556 new_sublist
->fn_field
.is_private
= 1;
2559 new_sublist
->fn_field
.is_protected
= 1;
2563 if (**pp
== '\\') *pp
= next_symbol_text ();
2566 case 'A': /* Normal functions. */
2567 new_sublist
->fn_field
.is_const
= 0;
2568 new_sublist
->fn_field
.is_volatile
= 0;
2571 case 'B': /* `const' member functions. */
2572 new_sublist
->fn_field
.is_const
= 1;
2573 new_sublist
->fn_field
.is_volatile
= 0;
2576 case 'C': /* `volatile' member function. */
2577 new_sublist
->fn_field
.is_const
= 0;
2578 new_sublist
->fn_field
.is_volatile
= 1;
2581 case 'D': /* `const volatile' member function. */
2582 new_sublist
->fn_field
.is_const
= 1;
2583 new_sublist
->fn_field
.is_volatile
= 1;
2586 case '*': /* File compiled with g++ version 1 -- no info */
2591 complain (&const_vol_complaint
, (char *) (long) **pp
);
2598 /* virtual member function, followed by index. */
2599 /* The sign bit is set to distinguish pointers-to-methods
2600 from virtual function indicies. Since the array is
2601 in words, the quantity must be shifted left by 1
2602 on 16 bit machine, and by 2 on 32 bit machine, forcing
2603 the sign bit out, and usable as a valid index into
2604 the array. Remove the sign bit here. */
2605 new_sublist
->fn_field
.voffset
=
2606 (0x7fffffff & read_number (pp
, ';')) + 2;
2608 if (**pp
== '\\') *pp
= next_symbol_text ();
2610 if (**pp
== ';' || **pp
== '\0')
2611 /* Must be g++ version 1. */
2612 new_sublist
->fn_field
.fcontext
= 0;
2615 /* Figure out from whence this virtual function came.
2616 It may belong to virtual function table of
2617 one of its baseclasses. */
2618 look_ahead_type
= read_type (pp
, objfile
);
2620 { /* g++ version 1 overloaded methods. */ }
2623 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2625 return error_type (pp
);
2628 look_ahead_type
= NULL
;
2634 /* static member function. */
2635 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2636 if (strncmp (new_sublist
->fn_field
.physname
,
2637 main_fn_name
, strlen (main_fn_name
)))
2638 new_sublist
->fn_field
.is_stub
= 1;
2643 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
2644 /* Fall through into normal member function. */
2647 /* normal member function. */
2648 new_sublist
->fn_field
.voffset
= 0;
2649 new_sublist
->fn_field
.fcontext
= 0;
2653 new_sublist
->next
= sublist
;
2654 sublist
= new_sublist
;
2656 if (**pp
== '\\') *pp
= next_symbol_text ();
2658 while (**pp
!= ';' && **pp
!= '\0');
2662 new_mainlist
->fn_fieldlist
.fn_fields
=
2663 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
2664 sizeof (struct fn_field
) * length
);
2665 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2666 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2668 new_mainlist
->fn_fieldlist
.length
= length
;
2669 new_mainlist
->next
= mainlist
;
2670 mainlist
= new_mainlist
;
2672 total_length
+= length
;
2673 if (**pp
== '\\') *pp
= next_symbol_text ();
2675 while (**pp
!= ';');
2683 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2684 obstack_alloc (&objfile
-> type_obstack
,
2685 sizeof (struct fn_fieldlist
) * nfn_fields
);
2686 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2687 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2692 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2693 TYPE_NFN_FIELDS_TOTAL (type
) +=
2694 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2697 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
2698 --n
; /* Circumvent Sun3 compiler bug */
2699 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
2706 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2708 /* Obsolete flags that used to indicate the presence
2709 of constructors and/or destructors. */
2713 /* Read either a '%' or the final ';'. */
2714 if (*(*pp
)++ == '%')
2716 /* We'd like to be able to derive the vtable pointer field
2717 from the type information, but when it's inherited, that's
2718 hard. A reason it's hard is because we may read in the
2719 info about a derived class before we read in info about
2720 the base class that provides the vtable pointer field.
2721 Once the base info has been read, we could fill in the info
2722 for the derived classes, but for the fact that by then,
2723 we don't remember who needs what. */
2726 int predicted_fieldno
= -1;
2729 /* Now we must record the virtual function table pointer's
2730 field information. */
2738 /* In version 2, we derive the vfield ourselves. */
2739 for (n
= 0; n
< nfields
; n
++)
2741 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2742 sizeof (vptr_name
) -1))
2744 predicted_fieldno
= n
;
2748 if (predicted_fieldno
< 0)
2749 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2750 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2751 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2753 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2759 t
= read_type (pp
, objfile
);
2761 while (*p
!= '\0' && *p
!= ';')
2764 /* Premature end of symbol. */
2765 return error_type (pp
);
2767 TYPE_VPTR_BASETYPE (type
) = t
;
2770 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2772 /* FIXME-tiemann: what's this? */
2774 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2779 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2780 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2781 sizeof (vptr_name
) - 1))
2783 TYPE_VPTR_FIELDNO (type
) = i
;
2787 /* Virtual function table field not found. */
2788 return error_type (pp
);
2791 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2794 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2795 error ("TYPE_VPTR_FIELDNO miscalculated");
2805 /* Read a definition of an array type,
2806 and create and return a suitable type object.
2807 Also creates a range type which represents the bounds of that
2809 static struct type
*
2810 read_array_type (pp
, type
, objfile
)
2812 register struct type
*type
;
2813 struct objfile
*objfile
;
2815 struct type
*index_type
, *element_type
, *range_type
;
2819 /* Format of an array type:
2820 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2823 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2824 for these, produce a type like float[][]. */
2826 index_type
= read_type (pp
, objfile
);
2828 /* Improper format of array type decl. */
2829 return error_type (pp
);
2832 if (!(**pp
>= '0' && **pp
<= '9'))
2837 lower
= read_number (pp
, ';');
2839 if (!(**pp
>= '0' && **pp
<= '9'))
2844 upper
= read_number (pp
, ';');
2846 element_type
= read_type (pp
, objfile
);
2855 /* Create range type. */
2856 range_type
= (struct type
*)
2857 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2858 memset (range_type
, 0, sizeof (struct type
));
2859 TYPE_OBJFILE (range_type
) = objfile
;
2860 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2861 TYPE_TARGET_TYPE (range_type
) = index_type
;
2863 /* This should never be needed. */
2864 TYPE_LENGTH (range_type
) = sizeof (int);
2866 TYPE_NFIELDS (range_type
) = 2;
2867 TYPE_FIELDS (range_type
) =
2868 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2869 2 * sizeof (struct field
));
2870 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2871 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2874 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2875 TYPE_TARGET_TYPE (type
) = element_type
;
2876 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2877 TYPE_NFIELDS (type
) = 1;
2878 TYPE_FIELDS (type
) =
2879 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2880 sizeof (struct field
));
2881 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2883 /* If we have an array whose element type is not yet known, but whose
2884 bounds *are* known, record it to be adjusted at the end of the file. */
2885 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2886 add_undefined_type (type
);
2892 /* Read a definition of an enumeration type,
2893 and create and return a suitable type object.
2894 Also defines the symbols that represent the values of the type. */
2896 static struct type
*
2897 read_enum_type (pp
, type
, objfile
)
2899 register struct type
*type
;
2900 struct objfile
*objfile
;
2905 register struct symbol
*sym
;
2907 struct pending
**symlist
;
2908 struct pending
*osyms
, *syms
;
2912 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2913 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2914 to do? For now, force all enum values to file scope. */
2915 if (within_function
)
2916 symlist
= &local_symbols
;
2919 symlist
= &file_symbols
;
2921 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2923 /* Read the value-names and their values.
2924 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2925 A semicolon or comma instead of a NAME means the end. */
2926 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2928 /* Check for and handle cretinous dbx symbol name continuation! */
2929 if (**pp
== '\\') *pp
= next_symbol_text ();
2932 while (*p
!= ':') p
++;
2933 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2935 n
= read_number (pp
, ',');
2937 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2938 memset (sym
, 0, sizeof (struct symbol
));
2939 SYMBOL_NAME (sym
) = name
;
2940 SYMBOL_CLASS (sym
) = LOC_CONST
;
2941 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2942 SYMBOL_VALUE (sym
) = n
;
2943 add_symbol_to_list (sym
, symlist
);
2948 (*pp
)++; /* Skip the semicolon. */
2950 /* Now fill in the fields of the type-structure. */
2952 TYPE_LENGTH (type
) = sizeof (int);
2953 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2954 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2955 TYPE_NFIELDS (type
) = nsyms
;
2956 TYPE_FIELDS (type
) = (struct field
*)
2957 obstack_alloc (&objfile
-> type_obstack
,
2958 sizeof (struct field
) * nsyms
);
2960 /* Find the symbols for the values and put them into the type.
2961 The symbols can be found in the symlist that we put them on
2962 to cause them to be defined. osyms contains the old value
2963 of that symlist; everything up to there was defined by us. */
2964 /* Note that we preserve the order of the enum constants, so
2965 that in something like "enum {FOO, LAST_THING=FOO}" we print
2966 FOO, not LAST_THING. */
2968 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2973 for (; j
< syms
->nsyms
; j
++,n
++)
2975 struct symbol
*xsym
= syms
->symbol
[j
];
2976 SYMBOL_TYPE (xsym
) = type
;
2977 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2978 TYPE_FIELD_VALUE (type
, n
) = 0;
2979 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2980 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2987 /* This screws up perfectly good C programs with enums. FIXME. */
2988 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2989 if(TYPE_NFIELDS(type
) == 2 &&
2990 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2991 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2992 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2993 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2994 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
3000 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3001 typedefs in every file (for int, long, etc):
3003 type = b <signed> <width>; <offset>; <nbits>
3004 signed = u or s. Possible c in addition to u or s (for char?).
3005 offset = offset from high order bit to start bit of type.
3006 width is # bytes in object of this type, nbits is # bits in type.
3008 The width/offset stuff appears to be for small objects stored in
3009 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3012 static struct type
*
3013 read_sun_builtin_type (pp
, typenums
, objfile
)
3016 struct objfile
*objfile
;
3029 return error_type (pp
);
3033 /* For some odd reason, all forms of char put a c here. This is strange
3034 because no other type has this honor. We can safely ignore this because
3035 we actually determine 'char'acterness by the number of bits specified in
3041 /* The first number appears to be the number of bytes occupied
3042 by this type, except that unsigned short is 4 instead of 2.
3043 Since this information is redundant with the third number,
3044 we will ignore it. */
3045 read_number (pp
, ';');
3047 /* The second number is always 0, so ignore it too. */
3048 read_number (pp
, ';');
3050 /* The third number is the number of bits for this type. */
3051 nbits
= read_number (pp
, 0);
3053 /* FIXME. Here we should just be able to make a type of the right
3054 number of bits and signedness. FIXME. */
3056 if (nbits
== TARGET_LONG_LONG_BIT
)
3057 return (lookup_fundamental_type (objfile
,
3058 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
3060 if (nbits
== TARGET_INT_BIT
) {
3061 /* FIXME -- the only way to distinguish `int' from `long'
3062 is to look at its name! */
3064 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3065 return lookup_fundamental_type (objfile
, FT_LONG
);
3067 return lookup_fundamental_type (objfile
, FT_INTEGER
);
3069 if (long_kludge_name
3070 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3071 long_kludge_name
[9] == 'l' /* long */)
3072 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3073 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
3075 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
3079 if (nbits
== TARGET_SHORT_BIT
)
3080 return (lookup_fundamental_type (objfile
,
3081 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
3083 if (nbits
== TARGET_CHAR_BIT
)
3084 return (lookup_fundamental_type (objfile
,
3085 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
3088 return lookup_fundamental_type (objfile
, FT_VOID
);
3090 return error_type (pp
);
3093 static struct type
*
3094 read_sun_floating_type (pp
, typenums
, objfile
)
3097 struct objfile
*objfile
;
3101 /* The first number has more details about the type, for example
3102 FN_COMPLEX. See the sun stab.h. */
3103 read_number (pp
, ';');
3105 /* The second number is the number of bytes occupied by this type */
3106 nbytes
= read_number (pp
, ';');
3109 return error_type (pp
);
3111 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
3112 return lookup_fundamental_type (objfile
, FT_FLOAT
);
3114 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3115 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3117 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3118 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3120 return error_type (pp
);
3123 /* Read a number from the string pointed to by *PP.
3124 The value of *PP is advanced over the number.
3125 If END is nonzero, the character that ends the
3126 number must match END, or an error happens;
3127 and that character is skipped if it does match.
3128 If END is zero, *PP is left pointing to that character.
3130 If the number fits in a long, set *VALUE and set *BITS to 0.
3131 If not, set *BITS to be the number of bits in the number.
3133 If encounter garbage, set *BITS to -1. */
3136 read_huge_number (pp
, end
, valu
, bits
)
3157 /* Leading zero means octal. GCC uses this to output values larger
3158 than an int (because that would be hard in decimal). */
3165 upper_limit
= LONG_MAX
/ radix
;
3166 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
3168 if (n
<= upper_limit
)
3171 n
+= c
- '0'; /* FIXME this overflows anyway */
3176 /* This depends on large values being output in octal, which is
3183 /* Ignore leading zeroes. */
3187 else if (c
== '2' || c
== '3')
3213 /* Large decimal constants are an error (because it is hard to
3214 count how many bits are in them). */
3220 /* -0x7f is the same as 0x80. So deal with it by adding one to
3221 the number of bits. */
3236 static struct type
*
3237 read_range_type (pp
, typenums
, objfile
)
3240 struct objfile
*objfile
;
3246 struct type
*result_type
;
3248 /* First comes a type we are a subrange of.
3249 In C it is usually 0, 1 or the type being defined. */
3250 read_type_number (pp
, rangenums
);
3251 self_subrange
= (rangenums
[0] == typenums
[0] &&
3252 rangenums
[1] == typenums
[1]);
3254 /* A semicolon should now follow; skip it. */
3258 /* The remaining two operands are usually lower and upper bounds
3259 of the range. But in some special cases they mean something else. */
3260 read_huge_number (pp
, ';', &n2
, &n2bits
);
3261 read_huge_number (pp
, ';', &n3
, &n3bits
);
3263 if (n2bits
== -1 || n3bits
== -1)
3264 return error_type (pp
);
3266 /* If limits are huge, must be large integral type. */
3267 if (n2bits
!= 0 || n3bits
!= 0)
3269 char got_signed
= 0;
3270 char got_unsigned
= 0;
3271 /* Number of bits in the type. */
3274 /* Range from 0 to <large number> is an unsigned large integral type. */
3275 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3280 /* Range from <large number> to <large number>-1 is a large signed
3282 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3288 /* Check for "long long". */
3289 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
3290 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3291 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
3292 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3294 if (got_signed
|| got_unsigned
)
3296 result_type
= (struct type
*)
3297 obstack_alloc (&objfile
-> type_obstack
,
3298 sizeof (struct type
));
3299 memset (result_type
, 0, sizeof (struct type
));
3300 TYPE_OBJFILE (result_type
) = objfile
;
3301 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
3302 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
3304 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
3308 return error_type (pp
);
3311 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3312 if (self_subrange
&& n2
== 0 && n3
== 0)
3313 return (lookup_fundamental_type (objfile
, FT_VOID
));
3315 /* If n3 is zero and n2 is not, we want a floating type,
3316 and n2 is the width in bytes.
3318 Fortran programs appear to use this for complex types also,
3319 and they give no way to distinguish between double and single-complex!
3320 We don't have complex types, so we would lose on all fortran files!
3321 So return type `double' for all of those. It won't work right
3322 for the complex values, but at least it makes the file loadable.
3324 FIXME, we may be able to distinguish these by their names. FIXME. */
3326 if (n3
== 0 && n2
> 0)
3328 if (n2
== sizeof (float))
3329 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
3330 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
3333 /* If the upper bound is -1, it must really be an unsigned int. */
3335 else if (n2
== 0 && n3
== -1)
3337 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3338 long' is to look at its name! */
3340 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3341 long_kludge_name
[9] == 'l' /* long */)
3342 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3343 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3345 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3348 /* Special case: char is defined (Who knows why) as a subrange of
3349 itself with range 0-127. */
3350 else if (self_subrange
&& n2
== 0 && n3
== 127)
3351 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3353 /* Assumptions made here: Subrange of self is equivalent to subrange
3354 of int. FIXME: Host and target type-sizes assumed the same. */
3355 /* FIXME: This is the *only* place in GDB that depends on comparing
3356 some type to a builtin type with ==. Fix it! */
3358 && (self_subrange
||
3359 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
3361 /* an unsigned type */
3363 if (n3
== - sizeof (long long))
3364 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3366 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3367 long' is to look at its name! */
3368 if (n3
== (unsigned long)~0L &&
3369 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3370 long_kludge_name
[9] == 'l' /* long */)
3371 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3372 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3373 if (n3
== (unsigned int)~0L)
3374 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3375 if (n3
== (unsigned short)~0L)
3376 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
3377 if (n3
== (unsigned char)~0L)
3378 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
3381 else if (n3
== 0 && n2
== -sizeof (long long))
3382 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3384 else if (n2
== -n3
-1)
3387 /* FIXME -- the only way to distinguish `int' from `long' is to look
3389 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
3390 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3391 return (lookup_fundamental_type (objfile
, FT_LONG
));
3392 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
3393 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
3394 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
3395 return (lookup_fundamental_type (objfile
, FT_SHORT
));
3396 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
3397 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
3400 /* We have a real range type on our hands. Allocate space and
3401 return a real pointer. */
3403 /* At this point I don't have the faintest idea how to deal with
3404 a self_subrange type; I'm going to assume that this is used
3405 as an idiom, and that all of them are special cases. So . . . */
3407 return error_type (pp
);
3409 result_type
= (struct type
*)
3410 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
3411 memset (result_type
, 0, sizeof (struct type
));
3412 TYPE_OBJFILE (result_type
) = objfile
;
3414 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3416 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3417 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3418 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
3419 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
3422 TYPE_NFIELDS (result_type
) = 2;
3423 TYPE_FIELDS (result_type
) =
3424 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
3425 2 * sizeof (struct field
));
3426 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
3427 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3428 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3430 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3435 /* Read a number from the string pointed to by *PP.
3436 The value of *PP is advanced over the number.
3437 If END is nonzero, the character that ends the
3438 number must match END, or an error happens;
3439 and that character is skipped if it does match.
3440 If END is zero, *PP is left pointing to that character. */
3443 read_number (pp
, end
)
3447 register char *p
= *pp
;
3448 register long n
= 0;
3452 /* Handle an optional leading minus sign. */
3460 /* Read the digits, as far as they go. */
3462 while ((c
= *p
++) >= '0' && c
<= '9')
3470 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3479 /* Read in an argument list. This is a list of types, separated by commas
3480 and terminated with END. Return the list of types read in, or (struct type
3481 **)-1 if there is an error. */
3482 static struct type
**
3483 read_args (pp
, end
, objfile
)
3486 struct objfile
*objfile
;
3488 /* FIXME! Remove this arbitrary limit! */
3489 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3495 /* Invalid argument list: no ','. */
3496 return (struct type
**)-1;
3499 /* Check for and handle cretinous dbx symbol name continuation! */
3501 *pp
= next_symbol_text ();
3503 types
[n
++] = read_type (pp
, objfile
);
3505 *pp
+= 1; /* get past `end' (the ':' character) */
3509 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3511 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3513 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3514 memset (rval
+ n
, 0, sizeof (struct type
*));
3518 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3520 memcpy (rval
, types
, n
* sizeof (struct type
*));
3524 /* Add a common block's start address to the offset of each symbol
3525 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3526 the common block name). */
3529 fix_common_block (sym
, valu
)
3533 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3534 for ( ; next
; next
= next
->next
)
3537 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3538 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3542 /* Initializer for this module */
3544 _initialize_buildsym ()
3546 undef_types_allocated
= 20;
3547 undef_types_length
= 0;
3548 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3549 sizeof (struct type
*));