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
)) {
453 complain(symbol
? &innerblock_complaint
: &innerblock_anon_complaint
,
454 SYMBOL_NAME (symbol
));
455 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
456 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
459 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
464 /* Record this block on the list of all blocks in the file.
465 Put it after opblock, or at the beginning if opblock is 0.
466 This puts the block in the list after all its subblocks. */
468 /* Allocate in the symbol_obstack to save time.
469 It wastes a little space. */
470 pblock
= (struct pending_block
*)
471 obstack_alloc (&objfile
-> symbol_obstack
,
472 sizeof (struct pending_block
));
473 pblock
->block
= block
;
476 pblock
->next
= opblock
->next
;
477 opblock
->next
= pblock
;
481 pblock
->next
= pending_blocks
;
482 pending_blocks
= pblock
;
486 static struct blockvector
*
487 make_blockvector (objfile
)
488 struct objfile
*objfile
;
490 register struct pending_block
*next
;
491 register struct blockvector
*blockvector
;
494 /* Count the length of the list of blocks. */
496 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
498 blockvector
= (struct blockvector
*)
499 obstack_alloc (&objfile
-> symbol_obstack
,
500 (sizeof (struct blockvector
)
501 + (i
- 1) * sizeof (struct block
*)));
503 /* Copy the blocks into the blockvector.
504 This is done in reverse order, which happens to put
505 the blocks into the proper order (ascending starting address).
506 finish_block has hair to insert each block into the list
507 after its subblocks in order to make sure this is true. */
509 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
510 for (next
= pending_blocks
; next
; next
= next
->next
) {
511 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
514 #if 0 /* Now we make the links in the obstack, so don't free them. */
515 /* Now free the links of the list, and empty the list. */
517 for (next
= pending_blocks
; next
; next
= next1
)
525 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
526 /* Some compilers output blocks in the wrong order, but we depend
527 on their being in the right order so we can binary search.
528 Check the order and moan about it. FIXME. */
529 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
530 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
531 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
532 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
533 complain (&blockvector_complaint
,
534 (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
542 /* Start recording information about source code that came from an included
543 (or otherwise merged-in) source file with a different name. */
546 start_subfile (name
, dirname
)
550 register struct subfile
*subfile
;
552 /* See if this subfile is already known as a subfile of the
553 current main source file. */
555 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
557 if (!strcmp (subfile
->name
, name
))
559 current_subfile
= subfile
;
564 /* This subfile is not known. Add an entry for it.
565 Make an entry for this subfile in the list of all subfiles
566 of the current main source file. */
568 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
569 subfile
->next
= subfiles
;
571 current_subfile
= subfile
;
573 /* Save its name and compilation directory name */
574 subfile
->name
= strdup (name
);
576 subfile
->dirname
= NULL
;
578 subfile
->dirname
= strdup (dirname
);
580 /* Initialize line-number recording for this subfile. */
581 subfile
->line_vector
= 0;
584 /* Handle the N_BINCL and N_EINCL symbol types
585 that act like N_SOL for switching source files
586 (different subfiles, as we call them) within one object file,
587 but using a stack rather than in an arbitrary order. */
592 register struct subfile_stack
*tem
593 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
595 tem
->next
= subfile_stack
;
597 if (current_subfile
== 0 || current_subfile
->name
== 0)
599 tem
->name
= current_subfile
->name
;
606 register struct subfile_stack
*link
= subfile_stack
;
612 subfile_stack
= link
->next
;
618 /* Manage the vector of line numbers for each subfile. */
621 record_line (subfile
, line
, pc
)
622 register struct subfile
*subfile
;
626 struct linetable_entry
*e
;
627 /* Ignore the dummy line number in libg.o */
632 /* Make sure line vector exists and is big enough. */
633 if (!subfile
->line_vector
) {
634 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
635 subfile
->line_vector
= (struct linetable
*)
636 xmalloc (sizeof (struct linetable
)
637 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
638 subfile
->line_vector
->nitems
= 0;
641 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
643 subfile
->line_vector_length
*= 2;
644 subfile
->line_vector
= (struct linetable
*)
645 xrealloc ((char *) subfile
->line_vector
, (sizeof (struct linetable
)
646 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
649 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
650 e
->line
= line
; e
->pc
= pc
;
654 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
657 compare_line_numbers (ln1p
, ln2p
)
661 return (((struct linetable_entry
*) ln1p
) -> line
-
662 ((struct linetable_entry
*) ln2p
) -> line
);
666 /* Start a new symtab for a new source file.
667 This is called when a dbx symbol of type N_SO is seen;
668 it indicates the start of data for one original source file. */
671 start_symtab (name
, dirname
, start_addr
)
674 CORE_ADDR start_addr
;
677 last_source_file
= name
;
678 last_source_start_addr
= start_addr
;
681 global_stabs
= 0; /* AIX COFF */
684 /* Context stack is initially empty. Allocate first one with room for
685 10 levels; reuse it forever afterward. */
686 if (context_stack
== 0) {
687 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
688 context_stack
= (struct context_stack
*)
689 xmalloc (context_stack_size
* sizeof (struct context_stack
));
691 context_stack_depth
= 0;
693 /* Leave FILENUM of 0 free for builtin types and this file's types. */
694 n_this_object_header_files
= 1;
696 type_vector_length
= 0;
697 type_vector
= (struct type
**) 0;
699 /* Initialize the list of sub source files with one entry
700 for this file (the top-level source file). */
704 start_subfile (name
, dirname
);
707 /* for all the stabs in a given stab vector, build appropriate types
708 and fix their symbols in given symbol vector. */
711 patch_block_stabs (symbols
, stabs
, objfile
)
712 struct pending
*symbols
;
713 struct pending_stabs
*stabs
;
714 struct objfile
*objfile
;
721 /* for all the stab entries, find their corresponding symbols and
722 patch their types! */
724 for (ii
= 0; ii
< stabs
->count
; ++ii
)
726 char *name
= stabs
->stab
[ii
];
727 char *pp
= (char*) strchr (name
, ':');
728 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
731 #ifndef IBM6000_TARGET
732 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
738 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
741 lookup_function_type (read_type (&pp
, objfile
));
745 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
752 /* Finish the symbol definitions for one main source file,
753 close off all the lexical contexts for that file
754 (creating struct block's for them), then make the struct symtab
755 for that file and put it in the list of all such.
757 END_ADDR is the address of the end of the file's text. */
760 end_symtab (end_addr
, sort_pending
, sort_linevec
, objfile
)
764 struct objfile
*objfile
;
766 register struct symtab
*symtab
;
767 register struct blockvector
*blockvector
;
768 register struct subfile
*subfile
;
769 struct subfile
*nextsub
;
771 /* Finish the lexical context of the last function in the file;
772 pop the context stack. */
774 if (context_stack_depth
> 0)
776 register struct context_stack
*cstk
;
777 context_stack_depth
--;
778 cstk
= &context_stack
[context_stack_depth
];
779 /* Make a block for the local symbols within. */
780 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
781 cstk
->start_addr
, end_addr
, objfile
);
783 /* Debug: if context stack still has something in it, we are in
785 if (context_stack_depth
> 0)
789 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
790 in this stage. Especially, blocks for static functions will show up at
791 the end. We need to sort them, so tools like `find_pc_function' and
792 `find_pc_block' can work reliably. */
793 if (sort_pending
&& pending_blocks
) {
794 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
797 struct pending_block
*pb
, *pbnext
;
799 pb
= pending_blocks
, pbnext
= pb
->next
;
804 /* swap blocks if unordered! */
806 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
)) {
807 struct block
*tmp
= pb
->block
;
808 pb
->block
= pbnext
->block
;
813 pbnext
= pbnext
->next
;
818 /* Cleanup any undefined types that have been left hanging around
819 (this needs to be done before the finish_blocks so that
820 file_symbols is still good). */
821 cleanup_undefined_types ();
824 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
825 free ((PTR
)global_stabs
);
829 if (pending_blocks
== 0
831 && global_symbols
== 0) {
832 /* Ignore symtabs that have no functions with real debugging info */
835 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
836 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
837 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
, objfile
);
838 blockvector
= make_blockvector (objfile
);
841 #ifdef PROCESS_LINENUMBER_HOOK
842 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
845 /* Now create the symtab objects proper, one for each subfile. */
846 /* (The main file is the last one on the chain.) */
848 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
851 /* If we have blocks of symbols, make a symtab.
852 Otherwise, just ignore this file and any line number info in it. */
855 if (subfile
->line_vector
) {
856 /* First, shrink the linetable to make more memory. */
857 linetablesize
= sizeof (struct linetable
) +
858 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
859 subfile
->line_vector
= (struct linetable
*)
860 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
863 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
864 sizeof (struct linetable_entry
), compare_line_numbers
);
867 /* Now, allocate a symbol table. */
868 symtab
= allocate_symtab (subfile
->name
, objfile
);
870 /* Fill in its components. */
871 symtab
->blockvector
= blockvector
;
872 if (subfile
->line_vector
)
874 /* Reallocate the line table on the symbol obstack */
875 symtab
->linetable
= (struct linetable
*)
876 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
877 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
881 symtab
->linetable
= NULL
;
883 symtab
->dirname
= subfile
->dirname
;
884 symtab
->free_code
= free_linetable
;
885 symtab
->free_ptr
= 0;
887 #ifdef IBM6000_TARGET
888 /* In case we need to duplicate symbol tables (to represent include
889 files), and in case our system needs relocation, we want to
890 relocate the main symbol table node only (for the main file,
891 not for the include files). */
893 symtab
->nonreloc
= TRUE
;
896 if (subfile
->line_vector
)
897 free ((PTR
)subfile
->line_vector
);
899 nextsub
= subfile
->next
;
903 #ifdef IBM6000_TARGET
904 /* all include symbol tables are non-relocatable, except the main source
907 symtab
->nonreloc
= FALSE
;
911 free ((char *) type_vector
);
913 type_vector_length
= 0;
915 last_source_file
= 0;
917 previous_stab_code
= 0;
923 /* Push a context block. Args are an identifying nesting level (checkable
924 when you pop it), and the starting PC address of this context. */
926 struct context_stack
*
927 push_context (desc
, valu
)
931 register struct context_stack
*new;
933 if (context_stack_depth
== context_stack_size
)
935 context_stack_size
*= 2;
936 context_stack
= (struct context_stack
*)
937 xrealloc ((char *) context_stack
,
938 (context_stack_size
* sizeof (struct context_stack
)));
941 new = &context_stack
[context_stack_depth
++];
943 new->locals
= local_symbols
;
944 new->old_blocks
= pending_blocks
;
945 new->start_addr
= valu
;
953 /* Initialize anything that needs initializing when starting to read
954 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
966 /* Initialize anything that needs initializing when a completely new
967 symbol file is specified (not just adding some symbols from another
968 file, e.g. a shared library). */
973 /* Empty the hash table of global syms looking for values. */
974 memset (global_sym_chain
, 0, sizeof global_sym_chain
);
979 /* Scan through all of the global symbols defined in the object file,
980 assigning values to the debugging symbols that need to be assigned
981 to. Get these symbols from the minimal symbol table. */
984 scan_file_globals (objfile
)
985 struct objfile
*objfile
;
988 struct minimal_symbol
*msymbol
;
989 struct symbol
*sym
, *prev
;
991 if (objfile
->msymbols
== 0) /* Beware the null file. */
994 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
998 prev
= (struct symbol
*) 0;
1000 /* Get the hash index and check all the symbols
1001 under that hash index. */
1003 hash
= hashname (msymbol
-> name
);
1005 for (sym
= global_sym_chain
[hash
]; sym
;)
1007 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
1008 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
1010 /* Splice this symbol out of the hash chain and
1011 assign the value we have to it. */
1013 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1015 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1017 /* Check to see whether we need to fix up a common block. */
1018 /* Note: this code might be executed several times for
1019 the same symbol if there are multiple references. */
1020 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1021 fix_common_block (sym
, msymbol
-> address
);
1023 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
1026 sym
= SYMBOL_VALUE_CHAIN (prev
);
1028 sym
= global_sym_chain
[hash
];
1033 sym
= SYMBOL_VALUE_CHAIN (sym
);
1040 /* Read a number by which a type is referred to in dbx data,
1041 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1042 Just a single number N is equivalent to (0,N).
1043 Return the two numbers by storing them in the vector TYPENUMS.
1044 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1047 read_type_number (pp
, typenums
)
1049 register int *typenums
;
1054 typenums
[0] = read_number (pp
, ',');
1055 typenums
[1] = read_number (pp
, ')');
1060 typenums
[1] = read_number (pp
, 0);
1064 /* To handle GNU C++ typename abbreviation, we need to be able to
1065 fill in a type's name as soon as space for that type is allocated.
1066 `type_synonym_name' is the name of the type being allocated.
1067 It is cleared as soon as it is used (lest all allocated types
1069 static char *type_synonym_name
;
1073 define_symbol (valu
, string
, desc
, type
, objfile
)
1078 struct objfile
*objfile
;
1080 register struct symbol
*sym
;
1081 char *p
= (char *) strchr (string
, ':');
1085 struct type
*temptype
;
1087 /* We would like to eliminate nameless symbols, but keep their types.
1088 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1089 to type 2, but, should not creat a symbol to address that type. Since
1090 the symbol will be nameless, there is no way any user can refer to it. */
1094 /* Ignore syms with empty names. */
1098 /* Ignore old-style symbols from cc -go */
1102 /* If a nameless stab entry, all we need is the type, not the symbol.
1104 nameless
= (p
== string
);
1106 sym
= (struct symbol
*)obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1108 if (processing_gcc_compilation
) {
1109 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1110 number of bytes occupied by a type or object, which we ignore. */
1111 SYMBOL_LINE(sym
) = desc
;
1113 SYMBOL_LINE(sym
) = 0; /* unknown */
1116 if (string
[0] == CPLUS_MARKER
)
1118 /* Special GNU C++ names. */
1122 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1123 &objfile
-> symbol_obstack
);
1125 case 'v': /* $vtbl_ptr_type */
1126 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1129 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1130 &objfile
-> symbol_obstack
);
1134 /* This was an anonymous type that was never fixed up. */
1145 = (char *) obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1146 /* Open-coded bcopy--saves function call time. */
1148 register char *p1
= string
;
1149 register char *p2
= SYMBOL_NAME (sym
);
1156 /* Determine the type of name being defined. */
1157 /* The Acorn RISC machine's compiler can put out locals that don't
1158 start with "234=" or "(3,4)=", so assume anything other than the
1159 deftypes we know how to handle is a local. */
1160 /* (Peter Watkins @ Computervision)
1161 Handle Sun-style local fortran array types 'ar...' .
1162 (gnu@cygnus.com) -- this strchr() handles them properly?
1163 (tiemann@cygnus.com) -- 'C' is for catch. */
1165 #ifdef IBM6000_TARGET
1167 /* 'R' is for register parameters. */
1169 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1172 if (!strchr ("cfFGpPrStTvVXC", *p
))
1178 /* c is a special case, not followed by a type-number.
1179 SYMBOL:c=iVALUE for an integer constant symbol.
1180 SYMBOL:c=rVALUE for a floating constant symbol.
1181 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1182 e.g. "b:c=e6,0" for "const b = blob1"
1183 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1187 error ("Invalid symbol data at symtab pos %d.", symnum
);
1192 double d
= atof (p
);
1195 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1198 obstack_alloc (&objfile
-> type_obstack
,
1200 memcpy (dbl_valu
, &d
, sizeof (double));
1201 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1202 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1203 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1208 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1210 SYMBOL_VALUE (sym
) = atoi (p
);
1211 SYMBOL_CLASS (sym
) = LOC_CONST
;
1215 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1216 e.g. "b:c=e6,0" for "const b = blob1"
1217 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1221 read_type_number (&p
, typenums
);
1223 error ("Invalid symbol data: no comma in enum const symbol");
1225 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1226 SYMBOL_VALUE (sym
) = atoi (p
);
1227 SYMBOL_CLASS (sym
) = LOC_CONST
;
1231 error ("Invalid symbol data at symtab pos %d.", symnum
);
1233 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1234 add_symbol_to_list (sym
, &file_symbols
);
1238 /* Now usually comes a number that says which data type,
1239 and possibly more stuff to define the type
1240 (all of which is handled by read_type) */
1242 if (deftype
== 'p' && *p
== 'F')
1243 /* pF is a two-letter code that means a function parameter in Fortran.
1244 The type-number specifies the type of the return value.
1245 Translate it into a pointer-to-function type. */
1249 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
1252 #ifdef IBM6000_TARGET
1253 else if (deftype
== 'R')
1254 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1259 /* The symbol class letter is followed by a type (typically the
1260 type of the symbol, or its return-type, or etc). Read it. */
1262 synonym
= *p
== 't';
1267 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1268 strlen (SYMBOL_NAME (sym
)),
1269 &objfile
-> symbol_obstack
);
1272 /* Here we save the name of the symbol for read_range_type, which
1273 ends up reading in the basic types. In stabs, unfortunately there
1274 is no distinction between "int" and "long" types except their
1275 names. Until we work out a saner type policy (eliminating most
1276 builtin types and using the names specified in the files), we
1277 save away the name so that far away from here in read_range_type,
1278 we can examine it to decide between "int" and "long". FIXME. */
1279 long_kludge_name
= SYMBOL_NAME (sym
);
1281 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1287 /* The name of a caught exception. */
1288 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1289 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1290 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1291 add_symbol_to_list (sym
, &local_symbols
);
1295 /* A static function definition. */
1296 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1297 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1298 add_symbol_to_list (sym
, &file_symbols
);
1299 /* fall into process_function_types. */
1301 process_function_types
:
1302 /* Function result types are described as the result type in stabs.
1303 We need to convert this to the function-returning-type-X type
1304 in GDB. E.g. "int" is converted to "function returning int". */
1305 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1308 /* This code doesn't work -- it needs to realloc and can't. */
1309 /* Attempt to set up to record a function prototype... */
1310 struct type
*new = (struct type
*)
1311 obstack_alloc (&objfile
-> type_obstack
,
1312 sizeof (struct type
));
1314 /* Generate a template for the type of this function. The
1315 types of the arguments will be added as we read the symbol
1317 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
1318 SYMBOL_TYPE(sym
) = new;
1319 TYPE_OBJFILE (new) = objfile
;
1320 in_function_type
= new;
1322 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1325 /* fall into process_prototype_types */
1327 process_prototype_types
:
1328 /* Sun acc puts declared types of arguments here. We don't care
1329 about their actual types (FIXME -- we should remember the whole
1330 function prototype), but the list may define some new types
1331 that we have to remember, so we must scan it now. */
1334 read_type (&p
, objfile
);
1339 /* A global function definition. */
1340 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1341 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1342 add_symbol_to_list (sym
, &global_symbols
);
1343 goto process_function_types
;
1346 /* For a class G (global) symbol, it appears that the
1347 value is not correct. It is necessary to search for the
1348 corresponding linker definition to find the value.
1349 These definitions appear at the end of the namelist. */
1350 i
= hashname (SYMBOL_NAME (sym
));
1351 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1352 global_sym_chain
[i
] = sym
;
1353 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1354 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1355 add_symbol_to_list (sym
, &global_symbols
);
1358 /* This case is faked by a conditional above,
1359 when there is no code letter in the dbx data.
1360 Dbx data never actually contains 'l'. */
1362 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1363 SYMBOL_VALUE (sym
) = valu
;
1364 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1365 add_symbol_to_list (sym
, &local_symbols
);
1369 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1370 can also be a LOC_LOCAL_ARG depending on symbol type. */
1371 #ifndef DBX_PARM_SYMBOL_CLASS
1372 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1374 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1375 SYMBOL_VALUE (sym
) = valu
;
1376 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1378 /* This doesn't work yet. */
1379 add_param_to_type (&in_function_type
, sym
);
1381 add_symbol_to_list (sym
, &local_symbols
);
1383 /* If it's gcc-compiled, if it says `short', believe it. */
1384 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1387 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1388 /* This macro is defined on machines (e.g. sparc) where
1389 we should believe the type of a PCC 'short' argument,
1390 but shouldn't believe the address (the address is
1391 the address of the corresponding int). Note that
1392 this is only different from the BELIEVE_PCC_PROMOTION
1393 case on big-endian machines.
1395 My guess is that this correction, as opposed to changing
1396 the parameter to an 'int' (as done below, for PCC
1397 on most machines), is the right thing to do
1398 on all machines, but I don't want to risk breaking
1399 something that already works. On most PCC machines,
1400 the sparc problem doesn't come up because the calling
1401 function has to zero the top bytes (not knowing whether
1402 the called function wants an int or a short), so there
1403 is no practical difference between an int and a short
1404 (except perhaps what happens when the GDB user types
1405 "print short_arg = 0x10000;").
1407 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1408 actually produces the correct address (we don't need to fix it
1409 up). I made this code adapt so that it will offset the symbol
1410 if it was pointing at an int-aligned location and not
1411 otherwise. This way you can use the same gdb for 4.0.x and
1414 If the parameter is shorter than an int, and is integral
1415 (e.g. char, short, or unsigned equivalent), and is claimed to
1416 be passed on an integer boundary, don't believe it! Offset the
1417 parameter's address to the tail-end of that integer. */
1419 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1420 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1421 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1422 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
1424 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
1425 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1429 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1431 /* If PCC says a parameter is a short or a char,
1432 it is really an int. */
1433 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
1434 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
1435 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1437 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1438 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
1443 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1446 /* acc seems to use P to delare the prototypes of functions that
1447 are referenced by this file. gdb is not prepared to deal
1448 with this extra information. FIXME, it ought to. */
1450 goto process_prototype_types
;
1452 /* Parameter which is in a register. */
1453 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1454 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1455 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1457 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1458 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1460 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1461 add_symbol_to_list (sym
, &local_symbols
);
1464 #ifdef IBM6000_TARGET
1468 /* Register variable (either global or local). */
1469 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1470 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1471 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1473 complain (®_value_complaint
, SYMBOL_NAME (sym
));
1474 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1476 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1477 if (within_function
)
1478 add_symbol_to_list (sym
, &local_symbols
);
1480 add_symbol_to_list (sym
, &file_symbols
);
1484 /* Static symbol at top level of file */
1485 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1486 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1487 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1488 add_symbol_to_list (sym
, &file_symbols
);
1492 /* For a nameless type, we don't want a create a symbol, thus we
1493 did not use `sym'. Return without further processing. */
1494 if (nameless
) return NULL
;
1496 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1497 SYMBOL_VALUE (sym
) = valu
;
1498 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1499 /* C++ vagaries: we may have a type which is derived from
1500 a base type which did not have its name defined when the
1501 derived class was output. We fill in the derived class's
1502 base part member's name here in that case. */
1503 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1504 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1505 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1506 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1509 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1510 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1511 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1512 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1515 add_symbol_to_list (sym
, &file_symbols
);
1519 /* For a nameless type, we don't want a create a symbol, thus we
1520 did not use `sym'. Return without further processing. */
1521 if (nameless
) return NULL
;
1523 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1524 SYMBOL_VALUE (sym
) = valu
;
1525 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1526 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1527 TYPE_NAME (SYMBOL_TYPE (sym
))
1528 = obconcat (&objfile
-> type_obstack
, "",
1529 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1531 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1532 ? "struct " : "union ")),
1534 add_symbol_to_list (sym
, &file_symbols
);
1538 register struct symbol
*typedef_sym
= (struct symbol
*)
1539 obstack_alloc (&objfile
-> type_obstack
,
1540 sizeof (struct symbol
));
1541 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1542 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1544 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1545 SYMBOL_VALUE (typedef_sym
) = valu
;
1546 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1547 add_symbol_to_list (typedef_sym
, &file_symbols
);
1552 /* Static symbol of local scope */
1553 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1554 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1555 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1556 add_symbol_to_list (sym
, &local_symbols
);
1560 /* Reference parameter */
1561 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1562 SYMBOL_VALUE (sym
) = valu
;
1563 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1564 add_symbol_to_list (sym
, &local_symbols
);
1568 /* This is used by Sun FORTRAN for "function result value".
1569 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1570 that Pascal uses it too, but when I tried it Pascal used
1571 "x:3" (local symbol) instead. */
1572 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1573 SYMBOL_VALUE (sym
) = valu
;
1574 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1575 add_symbol_to_list (sym
, &local_symbols
);
1579 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1584 /* What about types defined as forward references inside of a small lexical
1586 /* Add a type to the list of undefined types to be checked through
1587 once this file has been read in. */
1589 add_undefined_type (type
)
1592 if (undef_types_length
== undef_types_allocated
)
1594 undef_types_allocated
*= 2;
1595 undef_types
= (struct type
**)
1596 xrealloc ((char *) undef_types
,
1597 undef_types_allocated
* sizeof (struct type
*));
1599 undef_types
[undef_types_length
++] = type
;
1602 /* Go through each undefined type, see if it's still undefined, and fix it
1603 up if possible. We have two kinds of undefined types:
1605 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1606 Fix: update array length using the element bounds
1607 and the target type's length.
1608 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1609 yet defined at the time a pointer to it was made.
1610 Fix: Do a full lookup on the struct/union tag. */
1612 cleanup_undefined_types ()
1616 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++) {
1617 switch (TYPE_CODE (*type
)) {
1619 case TYPE_CODE_STRUCT
:
1620 case TYPE_CODE_UNION
:
1621 case TYPE_CODE_ENUM
:
1623 /* Reasonable test to see if it's been defined since. */
1624 if (TYPE_NFIELDS (*type
) == 0)
1626 struct pending
*ppt
;
1628 /* Name of the type, without "struct" or "union" */
1629 char *typename
= TYPE_NAME (*type
);
1631 if (!strncmp (typename
, "struct ", 7))
1633 if (!strncmp (typename
, "union ", 6))
1635 if (!strncmp (typename
, "enum ", 5))
1638 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1639 for (i
= 0; i
< ppt
->nsyms
; i
++)
1641 struct symbol
*sym
= ppt
->symbol
[i
];
1643 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1644 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1645 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1647 && !strcmp (SYMBOL_NAME (sym
), typename
))
1648 memcpy (*type
, SYMBOL_TYPE (sym
), sizeof (struct type
));
1652 /* It has been defined; don't mark it as a stub. */
1653 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1657 case TYPE_CODE_ARRAY
:
1659 struct type
*range_type
;
1662 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
1664 if (TYPE_NFIELDS (*type
) != 1)
1666 range_type
= TYPE_FIELD_TYPE (*type
, 0);
1667 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
1670 /* Now recompute the length of the array type, based on its
1671 number of elements and the target type's length. */
1672 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
1673 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
1674 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
1675 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
1681 error ("GDB internal error. cleanup_undefined_types with bad\
1682 type %d.", TYPE_CODE (*type
));
1686 undef_types_length
= 0;
1689 /* Skip rest of this symbol and return an error type.
1691 General notes on error recovery: error_type always skips to the
1692 end of the symbol (modulo cretinous dbx symbol name continuation).
1693 Thus code like this:
1695 if (*(*pp)++ != ';')
1696 return error_type (pp);
1698 is wrong because if *pp starts out pointing at '\0' (typically as the
1699 result of an earlier error), it will be incremented to point to the
1700 start of the next symbol, which might produce strange results, at least
1701 if you run off the end of the string table. Instead use
1704 return error_type (pp);
1710 foo = error_type (pp);
1714 And in case it isn't obvious, the point of all this hair is so the compiler
1715 can define new types and new syntaxes, and old versions of the
1716 debugger will be able to read the new symbol tables. */
1722 complain (&error_type_complaint
, 0);
1725 /* Skip to end of symbol. */
1726 while (**pp
!= '\0')
1729 /* Check for and handle cretinous dbx symbol name continuation! */
1730 if ((*pp
)[-1] == '\\')
1731 *pp
= next_symbol_text ();
1735 return builtin_type_error
;
1738 /* Read a dbx type reference or definition;
1739 return the type that is meant.
1740 This can be just a number, in which case it references
1741 a type already defined and placed in type_vector.
1742 Or the number can be followed by an =, in which case
1743 it means to define a new type according to the text that
1747 read_type (pp
, objfile
)
1749 struct objfile
*objfile
;
1751 register struct type
*type
= 0;
1756 /* Read type number if present. The type number may be omitted.
1757 for instance in a two-dimensional array declared with type
1758 "ar1;1;10;ar1;1;10;4". */
1759 if ((**pp
>= '0' && **pp
<= '9')
1762 read_type_number (pp
, typenums
);
1764 /* Type is not being defined here. Either it already exists,
1765 or this is a forward reference to it. dbx_alloc_type handles
1768 return dbx_alloc_type (typenums
, objfile
);
1770 /* Type is being defined here. */
1771 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1775 /* if such a type already exists, this is an unnecessary duplication
1776 of the stab string, which is common in (RS/6000) xlc generated
1777 objects. In that case, simply return NULL and let the caller take
1780 tt
= *dbx_lookup_type (typenums
);
1781 if (tt
&& tt
->length
&& tt
->code
)
1790 /* 'typenums=' not present, type is anonymous. Read and return
1791 the definition, but don't put it in the type vector. */
1792 typenums
[0] = typenums
[1] = -1;
1800 enum type_code code
;
1802 /* Used to index through file_symbols. */
1803 struct pending
*ppt
;
1806 /* Name including "struct", etc. */
1809 /* Name without "struct", etc. */
1810 char *type_name_only
;
1816 /* Set the type code according to the following letter. */
1820 code
= TYPE_CODE_STRUCT
;
1824 code
= TYPE_CODE_UNION
;
1828 code
= TYPE_CODE_ENUM
;
1832 return error_type (pp
);
1835 to
= type_name
= (char *)
1836 obstack_alloc (&objfile
-> type_obstack
,
1838 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1840 /* Copy the prefix. */
1842 while (*to
++ = *from
++)
1846 type_name_only
= to
;
1848 /* Copy the name. */
1850 while ((*to
++ = *from
++) != ':')
1854 /* Set the pointer ahead of the name which we just read. */
1858 /* The following hack is clearly wrong, because it doesn't
1859 check whether we are in a baseclass. I tried to reproduce
1860 the case that it is trying to fix, but I couldn't get
1861 g++ to put out a cross reference to a basetype. Perhaps
1862 it doesn't do it anymore. */
1863 /* Note: for C++, the cross reference may be to a base type which
1864 has not yet been seen. In this case, we skip to the comma,
1865 which will mark the end of the base class name. (The ':'
1866 at the end of the base class name will be skipped as well.)
1867 But sometimes (ie. when the cross ref is the last thing on
1868 the line) there will be no ','. */
1869 from
= (char *) strchr (*pp
, ',');
1875 /* Now check to see whether the type has already been declared. */
1876 /* This is necessary at least in the case where the
1877 program says something like
1879 The compiler puts out a cross-reference; we better find
1880 set the length of the structure correctly so we can
1881 set the length of the array. */
1882 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1883 for (i
= 0; i
< ppt
->nsyms
; i
++)
1885 struct symbol
*sym
= ppt
->symbol
[i
];
1887 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1888 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1889 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1890 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1892 obstack_free (&objfile
-> type_obstack
, type_name
);
1893 type
= SYMBOL_TYPE (sym
);
1898 /* Didn't find the type to which this refers, so we must
1899 be dealing with a forward reference. Allocate a type
1900 structure for it, and keep track of it so we can
1901 fill in the rest of the fields when we get the full
1903 type
= dbx_alloc_type (typenums
, objfile
);
1904 TYPE_CODE (type
) = code
;
1905 TYPE_NAME (type
) = type_name
;
1906 INIT_CPLUS_SPECIFIC(type
);
1907 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1909 add_undefined_type (type
);
1913 case '-': /* RS/6000 built-in type */
1915 type
= builtin_type (pp
); /* (in xcoffread.c) */
1930 read_type_number (pp
, xtypenums
);
1931 type
= *dbx_lookup_type (xtypenums
);
1936 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1937 if (typenums
[0] != -1)
1938 *dbx_lookup_type (typenums
) = type
;
1941 /* In the following types, we must be sure to overwrite any existing
1942 type that the typenums refer to, rather than allocating a new one
1943 and making the typenums point to the new one. This is because there
1944 may already be pointers to the existing type (if it had been
1945 forward-referenced), and we must change it to a pointer, function,
1946 reference, or whatever, *in-place*. */
1949 type1
= read_type (pp
, objfile
);
1950 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1953 case '&': /* Reference to another type */
1954 type1
= read_type (pp
, objfile
);
1955 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1958 case 'f': /* Function returning another type */
1959 type1
= read_type (pp
, objfile
);
1960 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1963 case 'k': /* Const qualifier on some type (Sun) */
1964 type
= read_type (pp
, objfile
);
1965 /* FIXME! For now, we ignore const and volatile qualifiers. */
1968 case 'B': /* Volatile qual on some type (Sun) */
1969 type
= read_type (pp
, objfile
);
1970 /* FIXME! For now, we ignore const and volatile qualifiers. */
1973 /* FIXME -- we should be doing smash_to_XXX types here. */
1974 case '@': /* Member (class & variable) type */
1976 struct type
*domain
= read_type (pp
, objfile
);
1977 struct type
*memtype
;
1980 /* Invalid member type data format. */
1981 return error_type (pp
);
1984 memtype
= read_type (pp
, objfile
);
1985 type
= dbx_alloc_type (typenums
, objfile
);
1986 smash_to_member_type (type
, domain
, memtype
);
1990 case '#': /* Method (class & fn) type */
1991 if ((*pp
)[0] == '#')
1993 /* We'll get the parameter types from the name. */
1994 struct type
*return_type
;
1997 return_type
= read_type (pp
, objfile
);
1998 if (*(*pp
)++ != ';')
1999 complain (&invalid_member_complaint
, (char *) symnum
);
2000 type
= allocate_stub_method (return_type
);
2001 if (typenums
[0] != -1)
2002 *dbx_lookup_type (typenums
) = type
;
2006 struct type
*domain
= read_type (pp
, objfile
);
2007 struct type
*return_type
;
2010 if (*(*pp
)++ != ',')
2011 error ("invalid member type data format, at symtab pos %d.",
2014 return_type
= read_type (pp
, objfile
);
2015 args
= read_args (pp
, ';', objfile
);
2016 type
= dbx_alloc_type (typenums
, objfile
);
2017 smash_to_method_type (type
, domain
, return_type
, args
);
2021 case 'r': /* Range type */
2022 type
= read_range_type (pp
, typenums
, objfile
);
2023 if (typenums
[0] != -1)
2024 *dbx_lookup_type (typenums
) = type
;
2027 case 'b': /* Sun ACC builtin int type */
2028 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2029 if (typenums
[0] != -1)
2030 *dbx_lookup_type (typenums
) = type
;
2033 case 'R': /* Sun ACC builtin float type */
2034 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2035 if (typenums
[0] != -1)
2036 *dbx_lookup_type (typenums
) = type
;
2039 case 'e': /* Enumeration type */
2040 type
= dbx_alloc_type (typenums
, objfile
);
2041 type
= read_enum_type (pp
, type
, objfile
);
2042 *dbx_lookup_type (typenums
) = type
;
2045 case 's': /* Struct type */
2046 type
= dbx_alloc_type (typenums
, objfile
);
2047 if (!TYPE_NAME (type
))
2048 TYPE_NAME (type
) = type_synonym_name
;
2049 type_synonym_name
= 0;
2050 type
= read_struct_type (pp
, type
, objfile
);
2053 case 'u': /* Union type */
2054 type
= dbx_alloc_type (typenums
, objfile
);
2055 if (!TYPE_NAME (type
))
2056 TYPE_NAME (type
) = type_synonym_name
;
2057 type_synonym_name
= 0;
2058 type
= read_struct_type (pp
, type
, objfile
);
2059 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2062 case 'a': /* Array type */
2064 return error_type (pp
);
2067 type
= dbx_alloc_type (typenums
, objfile
);
2068 type
= read_array_type (pp
, type
, objfile
);
2072 --*pp
; /* Go back to the symbol in error */
2073 /* Particularly important if it was \0! */
2074 return error_type (pp
);
2083 /* This page contains subroutines of read_type. */
2085 /* Read the description of a structure (or union type)
2086 and return an object describing the type. */
2088 static struct type
*
2089 read_struct_type (pp
, type
, objfile
)
2091 register struct type
*type
;
2092 struct objfile
*objfile
;
2094 /* Total number of methods defined in this class.
2095 If the class defines two `f' methods, and one `g' method,
2096 then this will have the value 3. */
2097 int total_length
= 0;
2101 struct nextfield
*next
;
2102 int visibility
; /* 0=public, 1=protected, 2=public */
2108 struct next_fnfield
*next
;
2109 struct fn_field fn_field
;
2112 struct next_fnfieldlist
2114 struct next_fnfieldlist
*next
;
2115 struct fn_fieldlist fn_fieldlist
;
2118 register struct nextfield
*list
= 0;
2119 struct nextfield
*new;
2122 int non_public_fields
= 0;
2125 register struct next_fnfieldlist
*mainlist
= 0;
2128 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2129 INIT_CPLUS_SPECIFIC(type
);
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
);
2340 /* Static class member. */
2341 list
->field
.bitpos
= (long)-1;
2343 while (*p
!= ';') p
++;
2344 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2349 else if (**pp
!= ',')
2350 /* Bad structure-type format. */
2351 return error_type (pp
);
2353 (*pp
)++; /* Skip the comma. */
2354 list
->field
.bitpos
= read_number (pp
, ',');
2355 list
->field
.bitsize
= read_number (pp
, ';');
2358 /* FIXME-tiemann: Can't the compiler put out something which
2359 lets us distinguish these? (or maybe just not put out anything
2360 for the field). What is the story here? What does the compiler
2361 really do? Also, patch gdb.texinfo for this case; I document
2362 it as a possible problem there. Search for "DBX-style". */
2364 /* This is wrong because this is identical to the symbols
2365 produced for GCC 0-size arrays. For example:
2370 The code which dumped core in such circumstances should be
2371 fixed not to dump core. */
2373 /* g++ -g0 can put out bitpos & bitsize zero for a static
2374 field. This does not give us any way of getting its
2375 class, so we can't know its name. But we can just
2376 ignore the field so we don't dump core and other nasty
2378 if (list
->field
.bitpos
== 0
2379 && list
->field
.bitsize
== 0)
2381 complain (&dbx_class_complaint
, 0);
2382 /* Ignore this field. */
2388 /* Detect an unpacked field and mark it as such.
2389 dbx gives a bit size for all fields.
2390 Note that forward refs cannot be packed,
2391 and treat enums as if they had the width of ints. */
2392 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2393 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2394 list
->field
.bitsize
= 0;
2395 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2396 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2397 && (list
->field
.bitsize
2398 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
2402 list
->field
.bitpos
% 8 == 0)
2403 list
->field
.bitsize
= 0;
2409 /* chill the list of fields: the last entry (at the head)
2410 is a partially constructed entry which we now scrub. */
2413 /* Now create the vector of fields, and record how big it is.
2414 We need this info to record proper virtual function table information
2415 for this class's virtual functions. */
2417 TYPE_NFIELDS (type
) = nfields
;
2418 TYPE_FIELDS (type
) = (struct field
*)
2419 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
2421 if (non_public_fields
)
2423 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2425 TYPE_FIELD_PRIVATE_BITS (type
) =
2426 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2428 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2430 TYPE_FIELD_PROTECTED_BITS (type
) =
2431 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
2433 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2436 /* Copy the saved-up fields into the field vector. */
2438 for (n
= nfields
; list
; list
= list
->next
)
2441 TYPE_FIELD (type
, n
) = list
->field
;
2442 if (list
->visibility
== 0)
2443 SET_TYPE_FIELD_PRIVATE (type
, n
);
2444 else if (list
->visibility
== 1)
2445 SET_TYPE_FIELD_PROTECTED (type
, n
);
2448 /* Now come the method fields, as NAME::methods
2449 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2450 At the end, we see a semicolon instead of a field.
2452 For the case of overloaded operators, the format is
2453 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2454 `*' holds the place for an operator name (such as `+=')
2455 and `.' marks the end of the operator name. */
2458 /* Now, read in the methods. To simplify matters, we
2459 "unread" the name that has been read, so that we can
2460 start from the top. */
2462 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2463 /* For each list of method lists... */
2467 struct next_fnfield
*sublist
= 0;
2468 struct type
*look_ahead_type
= NULL
;
2470 struct next_fnfieldlist
*new_mainlist
=
2471 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2476 /* read in the name. */
2477 while (*p
!= ':') p
++;
2478 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2480 /* This is a completely wierd case. In order to stuff in the
2481 names that might contain colons (the usual name delimiter),
2482 Mike Tiemann defined a different name format which is
2483 signalled if the identifier is "op$". In that case, the
2484 format is "op$::XXXX." where XXXX is the name. This is
2485 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2486 /* This lets the user type "break operator+".
2487 We could just put in "+" as the name, but that wouldn't
2489 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2490 char *o
= opname
+ 3;
2492 /* Skip past '::'. */
2494 if (**pp
== '\\') *pp
= next_symbol_text ();
2498 main_fn_name
= savestring (opname
, o
- opname
);
2504 main_fn_name
= savestring (*pp
, p
- *pp
);
2505 /* Skip past '::'. */
2508 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2512 struct next_fnfield
*new_sublist
=
2513 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2515 /* Check for and handle cretinous dbx symbol name continuation! */
2516 if (look_ahead_type
== NULL
) /* Normal case. */
2518 if (**pp
== '\\') *pp
= next_symbol_text ();
2520 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2522 /* Invalid symtab info for method. */
2523 return error_type (pp
);
2526 { /* g++ version 1 kludge */
2527 new_sublist
->fn_field
.type
= look_ahead_type
;
2528 look_ahead_type
= NULL
;
2533 while (*p
!= ';') p
++;
2535 /* If this is just a stub, then we don't have the
2537 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
2538 new_sublist
->fn_field
.is_stub
= 1;
2539 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2542 /* Set this method's visibility fields. */
2543 switch (*(*pp
)++ - '0')
2546 new_sublist
->fn_field
.is_private
= 1;
2549 new_sublist
->fn_field
.is_protected
= 1;
2553 if (**pp
== '\\') *pp
= next_symbol_text ();
2556 case 'A': /* Normal functions. */
2557 new_sublist
->fn_field
.is_const
= 0;
2558 new_sublist
->fn_field
.is_volatile
= 0;
2561 case 'B': /* `const' member functions. */
2562 new_sublist
->fn_field
.is_const
= 1;
2563 new_sublist
->fn_field
.is_volatile
= 0;
2566 case 'C': /* `volatile' member function. */
2567 new_sublist
->fn_field
.is_const
= 0;
2568 new_sublist
->fn_field
.is_volatile
= 1;
2571 case 'D': /* `const volatile' member function. */
2572 new_sublist
->fn_field
.is_const
= 1;
2573 new_sublist
->fn_field
.is_volatile
= 1;
2576 case '*': /* File compiled with g++ version 1 -- no info */
2581 complain (&const_vol_complaint
, (char *) (long) **pp
);
2588 /* virtual member function, followed by index. */
2589 /* The sign bit is set to distinguish pointers-to-methods
2590 from virtual function indicies. Since the array is
2591 in words, the quantity must be shifted left by 1
2592 on 16 bit machine, and by 2 on 32 bit machine, forcing
2593 the sign bit out, and usable as a valid index into
2594 the array. Remove the sign bit here. */
2595 new_sublist
->fn_field
.voffset
=
2596 (0x7fffffff & read_number (pp
, ';')) + 2;
2598 if (**pp
== '\\') *pp
= next_symbol_text ();
2600 if (**pp
== ';' || **pp
== '\0')
2601 /* Must be g++ version 1. */
2602 new_sublist
->fn_field
.fcontext
= 0;
2605 /* Figure out from whence this virtual function came.
2606 It may belong to virtual function table of
2607 one of its baseclasses. */
2608 look_ahead_type
= read_type (pp
, objfile
);
2610 { /* g++ version 1 overloaded methods. */ }
2613 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2615 return error_type (pp
);
2618 look_ahead_type
= NULL
;
2624 /* static member function. */
2625 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2626 if (strncmp (new_sublist
->fn_field
.physname
,
2627 main_fn_name
, strlen (main_fn_name
)))
2628 new_sublist
->fn_field
.is_stub
= 1;
2633 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
2634 /* Fall through into normal member function. */
2637 /* normal member function. */
2638 new_sublist
->fn_field
.voffset
= 0;
2639 new_sublist
->fn_field
.fcontext
= 0;
2643 new_sublist
->next
= sublist
;
2644 sublist
= new_sublist
;
2646 if (**pp
== '\\') *pp
= next_symbol_text ();
2648 while (**pp
!= ';' && **pp
!= '\0');
2652 new_mainlist
->fn_fieldlist
.fn_fields
=
2653 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
2654 sizeof (struct fn_field
) * length
);
2655 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2656 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2658 new_mainlist
->fn_fieldlist
.length
= length
;
2659 new_mainlist
->next
= mainlist
;
2660 mainlist
= new_mainlist
;
2662 total_length
+= length
;
2663 if (**pp
== '\\') *pp
= next_symbol_text ();
2665 while (**pp
!= ';');
2673 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2674 obstack_alloc (&objfile
-> type_obstack
,
2675 sizeof (struct fn_fieldlist
) * nfn_fields
);
2676 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2677 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2682 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2683 TYPE_NFN_FIELDS_TOTAL (type
) +=
2684 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2687 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
2688 --n
; /* Circumvent Sun3 compiler bug */
2689 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
2696 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2698 /* Obsolete flags that used to indicate the presence
2699 of constructors and/or destructors. */
2703 /* Read either a '%' or the final ';'. */
2704 if (*(*pp
)++ == '%')
2706 /* We'd like to be able to derive the vtable pointer field
2707 from the type information, but when it's inherited, that's
2708 hard. A reason it's hard is because we may read in the
2709 info about a derived class before we read in info about
2710 the base class that provides the vtable pointer field.
2711 Once the base info has been read, we could fill in the info
2712 for the derived classes, but for the fact that by then,
2713 we don't remember who needs what. */
2716 int predicted_fieldno
= -1;
2719 /* Now we must record the virtual function table pointer's
2720 field information. */
2728 /* In version 2, we derive the vfield ourselves. */
2729 for (n
= 0; n
< nfields
; n
++)
2731 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2732 sizeof (vptr_name
) -1))
2734 predicted_fieldno
= n
;
2738 if (predicted_fieldno
< 0)
2739 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2740 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2741 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2743 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2749 t
= read_type (pp
, objfile
);
2751 while (*p
!= '\0' && *p
!= ';')
2754 /* Premature end of symbol. */
2755 return error_type (pp
);
2757 TYPE_VPTR_BASETYPE (type
) = t
;
2760 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2762 /* FIXME-tiemann: what's this? */
2764 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2769 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2770 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2771 sizeof (vptr_name
) -1))
2773 TYPE_VPTR_FIELDNO (type
) = i
;
2777 /* Virtual function table field not found. */
2778 return error_type (pp
);
2781 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2784 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2785 error ("TYPE_VPTR_FIELDNO miscalculated");
2795 /* Read a definition of an array type,
2796 and create and return a suitable type object.
2797 Also creates a range type which represents the bounds of that
2799 static struct type
*
2800 read_array_type (pp
, type
, objfile
)
2802 register struct type
*type
;
2803 struct objfile
*objfile
;
2805 struct type
*index_type
, *element_type
, *range_type
;
2809 /* Format of an array type:
2810 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2813 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2814 for these, produce a type like float[][]. */
2816 index_type
= read_type (pp
, objfile
);
2818 /* Improper format of array type decl. */
2819 return error_type (pp
);
2822 if (!(**pp
>= '0' && **pp
<= '9'))
2827 lower
= read_number (pp
, ';');
2829 if (!(**pp
>= '0' && **pp
<= '9'))
2834 upper
= read_number (pp
, ';');
2836 element_type
= read_type (pp
, objfile
);
2845 /* Create range type. */
2846 range_type
= (struct type
*)
2847 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2848 memset (range_type
, 0, sizeof (struct type
));
2849 TYPE_OBJFILE (range_type
) = objfile
;
2850 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2851 TYPE_TARGET_TYPE (range_type
) = index_type
;
2853 /* This should never be needed. */
2854 TYPE_LENGTH (range_type
) = sizeof (int);
2856 TYPE_NFIELDS (range_type
) = 2;
2857 TYPE_FIELDS (range_type
) =
2858 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2859 2 * sizeof (struct field
));
2860 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2861 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2864 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2865 TYPE_TARGET_TYPE (type
) = element_type
;
2866 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2867 TYPE_NFIELDS (type
) = 1;
2868 TYPE_FIELDS (type
) =
2869 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2870 sizeof (struct field
));
2871 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2873 /* If we have an array whose element type is not yet known, but whose
2874 bounds *are* known, record it to be adjusted at the end of the file. */
2875 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2876 add_undefined_type (type
);
2882 /* Read a definition of an enumeration type,
2883 and create and return a suitable type object.
2884 Also defines the symbols that represent the values of the type. */
2886 static struct type
*
2887 read_enum_type (pp
, type
, objfile
)
2889 register struct type
*type
;
2890 struct objfile
*objfile
;
2895 register struct symbol
*sym
;
2897 struct pending
**symlist
;
2898 struct pending
*osyms
, *syms
;
2902 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2903 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2904 to do? For now, force all enum values to file scope. */
2905 if (within_function
)
2906 symlist
= &local_symbols
;
2909 symlist
= &file_symbols
;
2911 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2913 /* Read the value-names and their values.
2914 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2915 A semicolon or comma instead of a NAME means the end. */
2916 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2918 /* Check for and handle cretinous dbx symbol name continuation! */
2919 if (**pp
== '\\') *pp
= next_symbol_text ();
2922 while (*p
!= ':') p
++;
2923 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2925 n
= read_number (pp
, ',');
2927 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2928 memset (sym
, 0, sizeof (struct symbol
));
2929 SYMBOL_NAME (sym
) = name
;
2930 SYMBOL_CLASS (sym
) = LOC_CONST
;
2931 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2932 SYMBOL_VALUE (sym
) = n
;
2933 add_symbol_to_list (sym
, symlist
);
2938 (*pp
)++; /* Skip the semicolon. */
2940 /* Now fill in the fields of the type-structure. */
2942 TYPE_LENGTH (type
) = sizeof (int);
2943 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2944 TYPE_NFIELDS (type
) = nsyms
;
2945 TYPE_FIELDS (type
) = (struct field
*)
2946 obstack_alloc (&objfile
-> type_obstack
,
2947 sizeof (struct field
) * nsyms
);
2949 /* Find the symbols for the values and put them into the type.
2950 The symbols can be found in the symlist that we put them on
2951 to cause them to be defined. osyms contains the old value
2952 of that symlist; everything up to there was defined by us. */
2953 /* Note that we preserve the order of the enum constants, so
2954 that in something like "enum {FOO, LAST_THING=FOO}" we print
2955 FOO, not LAST_THING. */
2957 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2962 for (; j
< syms
->nsyms
; j
++,n
++)
2964 struct symbol
*xsym
= syms
->symbol
[j
];
2965 SYMBOL_TYPE (xsym
) = type
;
2966 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2967 TYPE_FIELD_VALUE (type
, n
) = 0;
2968 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2969 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2976 /* This screws up perfectly good C programs with enums. FIXME. */
2977 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2978 if(TYPE_NFIELDS(type
) == 2 &&
2979 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2980 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2981 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2982 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2983 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2989 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2990 typedefs in every file (for int, long, etc):
2992 type = b <signed> <width>; <offset>; <nbits>
2993 signed = u or s. Possible c in addition to u or s (for char?).
2994 offset = offset from high order bit to start bit of type.
2995 width is # bytes in object of this type, nbits is # bits in type.
2997 The width/offset stuff appears to be for small objects stored in
2998 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3001 static struct type
*
3002 read_sun_builtin_type (pp
, typenums
, objfile
)
3005 struct objfile
*objfile
;
3018 return error_type (pp
);
3022 /* For some odd reason, all forms of char put a c here. This is strange
3023 because no other type has this honor. We can safely ignore this because
3024 we actually determine 'char'acterness by the number of bits specified in
3030 /* The first number appears to be the number of bytes occupied
3031 by this type, except that unsigned short is 4 instead of 2.
3032 Since this information is redundant with the third number,
3033 we will ignore it. */
3034 read_number (pp
, ';');
3036 /* The second number is always 0, so ignore it too. */
3037 read_number (pp
, ';');
3039 /* The third number is the number of bits for this type. */
3040 nbits
= read_number (pp
, 0);
3042 /* FIXME. Here we should just be able to make a type of the right
3043 number of bits and signedness. FIXME. */
3045 if (nbits
== TARGET_LONG_LONG_BIT
)
3046 return (lookup_fundamental_type (objfile
,
3047 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
3049 if (nbits
== TARGET_INT_BIT
) {
3050 /* FIXME -- the only way to distinguish `int' from `long'
3051 is to look at its name! */
3053 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3054 return lookup_fundamental_type (objfile
, FT_LONG
);
3056 return lookup_fundamental_type (objfile
, FT_INTEGER
);
3058 if (long_kludge_name
3059 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3060 long_kludge_name
[9] == 'l' /* long */)
3061 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3062 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
3064 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
3068 if (nbits
== TARGET_SHORT_BIT
)
3069 return (lookup_fundamental_type (objfile
,
3070 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
3072 if (nbits
== TARGET_CHAR_BIT
)
3073 return (lookup_fundamental_type (objfile
,
3074 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
3077 return lookup_fundamental_type (objfile
, FT_VOID
);
3079 return error_type (pp
);
3082 static struct type
*
3083 read_sun_floating_type (pp
, typenums
, objfile
)
3086 struct objfile
*objfile
;
3090 /* The first number has more details about the type, for example
3091 FN_COMPLEX. See the sun stab.h. */
3092 read_number (pp
, ';');
3094 /* The second number is the number of bytes occupied by this type */
3095 nbytes
= read_number (pp
, ';');
3098 return error_type (pp
);
3100 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
3101 return lookup_fundamental_type (objfile
, FT_FLOAT
);
3103 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3104 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3106 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
3107 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3109 return error_type (pp
);
3112 /* Read a number from the string pointed to by *PP.
3113 The value of *PP is advanced over the number.
3114 If END is nonzero, the character that ends the
3115 number must match END, or an error happens;
3116 and that character is skipped if it does match.
3117 If END is zero, *PP is left pointing to that character.
3119 If the number fits in a long, set *VALUE and set *BITS to 0.
3120 If not, set *BITS to be the number of bits in the number.
3122 If encounter garbage, set *BITS to -1. */
3125 read_huge_number (pp
, end
, valu
, bits
)
3146 /* Leading zero means octal. GCC uses this to output values larger
3147 than an int (because that would be hard in decimal). */
3154 upper_limit
= LONG_MAX
/ radix
;
3155 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
3157 if (n
<= upper_limit
)
3160 n
+= c
- '0'; /* FIXME this overflows anyway */
3165 /* This depends on large values being output in octal, which is
3172 /* Ignore leading zeroes. */
3176 else if (c
== '2' || c
== '3')
3202 /* Large decimal constants are an error (because it is hard to
3203 count how many bits are in them). */
3209 /* -0x7f is the same as 0x80. So deal with it by adding one to
3210 the number of bits. */
3225 static struct type
*
3226 read_range_type (pp
, typenums
, objfile
)
3229 struct objfile
*objfile
;
3235 struct type
*result_type
;
3237 /* First comes a type we are a subrange of.
3238 In C it is usually 0, 1 or the type being defined. */
3239 read_type_number (pp
, rangenums
);
3240 self_subrange
= (rangenums
[0] == typenums
[0] &&
3241 rangenums
[1] == typenums
[1]);
3243 /* A semicolon should now follow; skip it. */
3247 /* The remaining two operands are usually lower and upper bounds
3248 of the range. But in some special cases they mean something else. */
3249 read_huge_number (pp
, ';', &n2
, &n2bits
);
3250 read_huge_number (pp
, ';', &n3
, &n3bits
);
3252 if (n2bits
== -1 || n3bits
== -1)
3253 return error_type (pp
);
3255 /* If limits are huge, must be large integral type. */
3256 if (n2bits
!= 0 || n3bits
!= 0)
3258 char got_signed
= 0;
3259 char got_unsigned
= 0;
3260 /* Number of bits in the type. */
3263 /* Range from 0 to <large number> is an unsigned large integral type. */
3264 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3269 /* Range from <large number> to <large number>-1 is a large signed
3271 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3277 /* Check for "long long". */
3278 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
3279 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3280 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
3281 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3283 if (got_signed
|| got_unsigned
)
3285 result_type
= (struct type
*)
3286 obstack_alloc (&objfile
-> type_obstack
,
3287 sizeof (struct type
));
3288 memset (result_type
, 0, sizeof (struct type
));
3289 TYPE_OBJFILE (result_type
) = objfile
;
3290 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
3291 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
3293 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
3297 return error_type (pp
);
3300 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3301 if (self_subrange
&& n2
== 0 && n3
== 0)
3302 return (lookup_fundamental_type (objfile
, FT_VOID
));
3304 /* If n3 is zero and n2 is not, we want a floating type,
3305 and n2 is the width in bytes.
3307 Fortran programs appear to use this for complex types also,
3308 and they give no way to distinguish between double and single-complex!
3309 We don't have complex types, so we would lose on all fortran files!
3310 So return type `double' for all of those. It won't work right
3311 for the complex values, but at least it makes the file loadable.
3313 FIXME, we may be able to distinguish these by their names. FIXME. */
3315 if (n3
== 0 && n2
> 0)
3317 if (n2
== sizeof (float))
3318 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
3319 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
3322 /* If the upper bound is -1, it must really be an unsigned int. */
3324 else if (n2
== 0 && n3
== -1)
3326 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3327 long' is to look at its name! */
3329 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3330 long_kludge_name
[9] == 'l' /* long */)
3331 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3332 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3334 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3337 /* Special case: char is defined (Who knows why) as a subrange of
3338 itself with range 0-127. */
3339 else if (self_subrange
&& n2
== 0 && n3
== 127)
3340 return (lookup_fundamental_type (objfile
, FT_CHAR
));
3342 /* Assumptions made here: Subrange of self is equivalent to subrange
3343 of int. FIXME: Host and target type-sizes assumed the same. */
3344 /* FIXME: This is the *only* place in GDB that depends on comparing
3345 some type to a builtin type with ==. Fix it! */
3347 && (self_subrange
||
3348 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
3350 /* an unsigned type */
3352 if (n3
== - sizeof (long long))
3353 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
3355 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3356 long' is to look at its name! */
3357 if (n3
== (unsigned long)~0L &&
3358 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3359 long_kludge_name
[9] == 'l' /* long */)
3360 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3361 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
3362 if (n3
== (unsigned int)~0L)
3363 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
3364 if (n3
== (unsigned short)~0L)
3365 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
3366 if (n3
== (unsigned char)~0L)
3367 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
3370 else if (n3
== 0 && n2
== -sizeof (long long))
3371 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
3373 else if (n2
== -n3
-1)
3376 /* FIXME -- the only way to distinguish `int' from `long' is to look
3378 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
3379 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3380 return (lookup_fundamental_type (objfile
, FT_LONG
));
3381 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
3382 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
3383 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
3384 return (lookup_fundamental_type (objfile
, FT_SHORT
));
3385 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
3386 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
3389 /* We have a real range type on our hands. Allocate space and
3390 return a real pointer. */
3392 /* At this point I don't have the faintest idea how to deal with
3393 a self_subrange type; I'm going to assume that this is used
3394 as an idiom, and that all of them are special cases. So . . . */
3396 return error_type (pp
);
3398 result_type
= (struct type
*)
3399 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
3400 memset (result_type
, 0, sizeof (struct type
));
3401 TYPE_OBJFILE (result_type
) = objfile
;
3403 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
3405 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
3406 if (TYPE_TARGET_TYPE (result_type
) == 0) {
3407 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
3408 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
3411 TYPE_NFIELDS (result_type
) = 2;
3412 TYPE_FIELDS (result_type
) =
3413 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
3414 2 * sizeof (struct field
));
3415 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
3416 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
3417 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
3419 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3424 /* Read a number from the string pointed to by *PP.
3425 The value of *PP is advanced over the number.
3426 If END is nonzero, the character that ends the
3427 number must match END, or an error happens;
3428 and that character is skipped if it does match.
3429 If END is zero, *PP is left pointing to that character. */
3432 read_number (pp
, end
)
3436 register char *p
= *pp
;
3437 register long n
= 0;
3441 /* Handle an optional leading minus sign. */
3449 /* Read the digits, as far as they go. */
3451 while ((c
= *p
++) >= '0' && c
<= '9')
3459 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3468 /* Read in an argument list. This is a list of types, separated by commas
3469 and terminated with END. Return the list of types read in, or (struct type
3470 **)-1 if there is an error. */
3471 static struct type
**
3472 read_args (pp
, end
, objfile
)
3475 struct objfile
*objfile
;
3477 /* FIXME! Remove this arbitrary limit! */
3478 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3484 /* Invalid argument list: no ','. */
3485 return (struct type
**)-1;
3488 /* Check for and handle cretinous dbx symbol name continuation! */
3490 *pp
= next_symbol_text ();
3492 types
[n
++] = read_type (pp
, objfile
);
3494 *pp
+= 1; /* get past `end' (the ':' character) */
3498 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3500 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3502 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3503 memset (rval
+ n
, 0, sizeof (struct type
*));
3507 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3509 memcpy (rval
, types
, n
* sizeof (struct type
*));
3513 /* Add a common block's start address to the offset of each symbol
3514 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3515 the common block name). */
3518 fix_common_block (sym
, valu
)
3522 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3523 for ( ; next
; next
= next
->next
)
3526 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3527 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3531 /* Initializer for this module */
3533 _initialize_buildsym ()
3535 undef_types_allocated
= 20;
3536 undef_types_length
= 0;
3537 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3538 sizeof (struct type
*));