1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This module provides subroutines used for creating and adding to
21 the symbol table. These routines are called from various symbol-
22 file-reading routines.
24 They originated in dbxread.c of gdb-4.2, and were split out to
25 make xcoffread.c more maintainable by sharing code. */
31 #include "breakpoint.h"
32 #include "gdbcore.h" /* for bfd stuff for symfile.h */
33 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "stab.gnu.h" /* We always use GNU stabs, not native */
38 /* Ask buildsym.h to define the vars it normally declares `extern'. */
40 #include "buildsym.h" /* Our own declarations */
44 extern double atof ();
46 /* Things we export from outside, and probably shouldn't. FIXME. */
47 extern void new_object_header_files ();
48 extern char *next_symbol_text ();
49 extern int hashname ();
50 extern void patch_block_stabs (); /* AIX xcoffread.c */
51 extern struct type
*builtin_type (); /* AIX xcoffread.c */
54 static void cleanup_undefined_types ();
55 static void fix_common_block ();
57 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
58 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
60 /* Define this as 1 if a pcc declaration of a char or short argument
61 gives the correct address. Otherwise assume pcc gives the
62 address of the corresponding int, which is not the same on a
63 big-endian machine. */
65 #ifndef BELIEVE_PCC_PROMOTION
66 #define BELIEVE_PCC_PROMOTION 0
69 /* Make a list of forward references which haven't been defined. */
70 static struct type
**undef_types
;
71 static int undef_types_allocated
, undef_types_length
;
73 /* Initial sizes of data structures. These are realloc'd larger if needed,
74 and realloc'd down to the size actually used, when completed. */
76 #define INITIAL_CONTEXT_STACK_SIZE 10
77 #define INITIAL_TYPE_VECTOR_LENGTH 160
78 #define INITIAL_LINE_VECTOR_LENGTH 1000
80 /* Complaints about the symbols we have encountered. */
82 struct complaint innerblock_complaint
=
83 {"inner block not inside outer block in %s", 0, 0};
85 struct complaint blockvector_complaint
=
86 {"block at %x out of order", 0, 0};
89 struct complaint dbx_class_complaint
=
90 {"encountered DBX-style class variable debugging information.\n\
91 You seem to have compiled your program with \
92 \"g++ -g0\" instead of \"g++ -g\".\n\
93 Therefore GDB will not know about your class variables", 0, 0};
96 struct complaint invalid_cpp_abbrev_complaint
=
97 {"invalid C++ abbreviation `%s'", 0, 0};
99 struct complaint invalid_cpp_type_complaint
=
100 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
102 struct complaint member_fn_complaint
=
103 {"member function type missing, got '%c'", 0, 0};
105 struct complaint const_vol_complaint
=
106 {"const/volatile indicator missing, got '%c'", 0, 0};
108 struct complaint error_type_complaint
=
109 {"debug info mismatch between compiler and debugger", 0, 0};
111 struct complaint invalid_member_complaint
=
112 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
114 struct complaint range_type_base_complaint
=
115 {"base type %d of range type is not defined", 0, 0};
117 /* Look up a dbx type-number pair. Return the address of the slot
118 where the type for that number-pair is stored.
119 The number-pair is in TYPENUMS.
121 This can be used for finding the type associated with that pair
122 or for associating a new type with the pair. */
125 dbx_lookup_type (typenums
)
128 register int filenum
= typenums
[0], index
= typenums
[1];
131 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
132 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
133 filenum
, index
, symnum
);
137 /* Type is defined outside of header files.
138 Find it in this object file's type vector. */
139 if (index
>= type_vector_length
)
141 old_len
= type_vector_length
;
143 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
144 type_vector
= (struct type
**)
145 malloc (type_vector_length
* sizeof (struct type
*));
147 while (index
>= type_vector_length
)
148 type_vector_length
*= 2;
149 type_vector
= (struct type
**)
150 xrealloc (type_vector
,
151 (type_vector_length
* sizeof (struct type
*)));
152 bzero (&type_vector
[old_len
],
153 (type_vector_length
- old_len
) * sizeof (struct type
*));
155 return &type_vector
[index
];
159 register int real_filenum
= this_object_header_files
[filenum
];
160 register struct header_file
*f
;
163 if (real_filenum
>= n_header_files
)
166 f
= &header_files
[real_filenum
];
168 f_orig_length
= f
->length
;
169 if (index
>= f_orig_length
)
171 while (index
>= f
->length
)
173 f
->vector
= (struct type
**)
174 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
175 bzero (&f
->vector
[f_orig_length
],
176 (f
->length
- f_orig_length
) * sizeof (struct type
*));
178 return &f
->vector
[index
];
182 /* Create a type object. Occaisionally used when you need a type
183 which isn't going to be given a type number. */
188 register struct type
*type
=
189 (struct type
*) obstack_alloc (symbol_obstack
, sizeof (struct type
));
191 bzero (type
, sizeof (struct type
));
192 TYPE_VPTR_FIELDNO (type
) = -1;
193 TYPE_VPTR_BASETYPE (type
) = 0;
197 /* Make sure there is a type allocated for type numbers TYPENUMS
198 and return the type object.
199 This can create an empty (zeroed) type object.
200 TYPENUMS may be (-1, -1) to return a new type object that is not
201 put into the type vector, and so may not be referred to by number. */
204 dbx_alloc_type (typenums
)
207 register struct type
**type_addr
;
208 register struct type
*type
;
210 if (typenums
[0] != -1)
212 type_addr
= dbx_lookup_type (typenums
);
221 /* If we are referring to a type not known at all yet,
222 allocate an empty type for it.
223 We will fill it in later if we find out how. */
226 type
= dbx_create_type ();
234 /* maintain the lists of symbols and blocks */
236 /* Add a symbol to one of the lists of symbols. */
238 add_symbol_to_list (symbol
, listhead
)
239 struct symbol
*symbol
;
240 struct pending
**listhead
;
242 /* We keep PENDINGSIZE symbols in each link of the list.
243 If we don't have a link with room in it, add a new link. */
244 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
246 register struct pending
*link
;
249 link
= free_pendings
;
250 free_pendings
= link
->next
;
253 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
255 link
->next
= *listhead
;
260 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
263 /* Find a symbol on a pending list. */
265 find_symbol_in_list (list
, name
, length
)
266 struct pending
*list
;
273 for (j
= list
->nsyms
; --j
>= 0; ) {
274 char *pp
= SYMBOL_NAME (list
->symbol
[j
]);
275 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 && pp
[length
] == '\0')
276 return list
->symbol
[j
];
283 /* At end of reading syms, or in case of quit,
284 really free as many `struct pending's as we can easily find. */
288 really_free_pendings (foo
)
291 struct pending
*next
, *next1
;
293 struct pending_block
*bnext
, *bnext1
;
296 for (next
= free_pendings
; next
; next
= next1
)
303 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
304 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
306 bnext1
= bnext
->next
;
312 for (next
= file_symbols
; next
; next
= next1
)
319 for (next
= global_symbols
; next
; next
= next1
)
327 /* Take one of the lists of symbols and make a block from it.
328 Keep the order the symbols have in the list (reversed from the input file).
329 Put the block on the list of pending blocks. */
332 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
333 struct symbol
*symbol
;
334 struct pending
**listhead
;
335 struct pending_block
*old_blocks
;
336 CORE_ADDR start
, end
;
338 register struct pending
*next
, *next1
;
339 register struct block
*block
;
340 register struct pending_block
*pblock
;
341 struct pending_block
*opblock
;
344 /* Count the length of the list of symbols. */
346 for (next
= *listhead
, i
= 0;
348 i
+= next
->nsyms
, next
= next
->next
)
351 block
= (struct block
*) obstack_alloc (symbol_obstack
,
352 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
354 /* Copy the symbols into the block. */
356 BLOCK_NSYMS (block
) = i
;
357 for (next
= *listhead
; next
; next
= next
->next
)
360 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
361 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
364 BLOCK_START (block
) = start
;
365 BLOCK_END (block
) = end
;
366 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
367 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
369 /* Put the block in as the value of the symbol that names it. */
373 SYMBOL_BLOCK_VALUE (symbol
) = block
;
374 BLOCK_FUNCTION (block
) = symbol
;
377 BLOCK_FUNCTION (block
) = 0;
379 /* Now "free" the links of the list, and empty the list. */
381 for (next
= *listhead
; next
; next
= next1
)
384 next
->next
= free_pendings
;
385 free_pendings
= next
;
389 /* Install this block as the superblock
390 of all blocks made since the start of this scope
391 that don't have superblocks yet. */
394 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
396 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
398 /* Check to be sure the blocks are nested as we receive them.
399 If the compiler/assembler/linker work, this just burns a small
401 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
402 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
403 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
405 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
406 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
409 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
414 /* Record this block on the list of all blocks in the file.
415 Put it after opblock, or at the beginning if opblock is 0.
416 This puts the block in the list after all its subblocks. */
418 /* Allocate in the symbol_obstack to save time.
419 It wastes a little space. */
420 pblock
= (struct pending_block
*)
421 obstack_alloc (symbol_obstack
,
422 sizeof (struct pending_block
));
423 pblock
->block
= block
;
426 pblock
->next
= opblock
->next
;
427 opblock
->next
= pblock
;
431 pblock
->next
= pending_blocks
;
432 pending_blocks
= pblock
;
439 register struct pending_block
*next
;
440 register struct blockvector
*blockvector
;
443 /* Count the length of the list of blocks. */
445 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
447 blockvector
= (struct blockvector
*)
448 obstack_alloc (symbol_obstack
,
449 (sizeof (struct blockvector
)
450 + (i
- 1) * sizeof (struct block
*)));
452 /* Copy the blocks into the blockvector.
453 This is done in reverse order, which happens to put
454 the blocks into the proper order (ascending starting address).
455 finish_block has hair to insert each block into the list
456 after its subblocks in order to make sure this is true. */
458 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
459 for (next
= pending_blocks
; next
; next
= next
->next
) {
460 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
463 #if 0 /* Now we make the links in the obstack, so don't free them. */
464 /* Now free the links of the list, and empty the list. */
466 for (next
= pending_blocks
; next
; next
= next1
)
474 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
475 /* Some compilers output blocks in the wrong order, but we depend
476 on their being in the right order so we can binary search.
477 Check the order and moan about it. FIXME. */
478 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
479 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
480 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
481 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
482 complain (&blockvector_complaint
,
483 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
491 /* Start recording information about source code that came from an included
492 (or otherwise merged-in) source file with a different name. */
495 start_subfile (name
, dirname
)
499 register struct subfile
*subfile
;
501 /* See if this subfile is already known as a subfile of the
502 current main source file. */
504 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
506 if (!strcmp (subfile
->name
, name
))
508 current_subfile
= subfile
;
513 /* This subfile is not known. Add an entry for it.
514 Make an entry for this subfile in the list of all subfiles
515 of the current main source file. */
517 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
518 subfile
->next
= subfiles
;
520 current_subfile
= subfile
;
522 /* Save its name and compilation directory name */
523 subfile
->name
= obsavestring (name
, strlen (name
));
525 subfile
->dirname
= NULL
;
527 subfile
->dirname
= obsavestring (dirname
, strlen (dirname
));
529 /* Initialize line-number recording for this subfile. */
530 subfile
->line_vector
= 0;
533 /* Handle the N_BINCL and N_EINCL symbol types
534 that act like N_SOL for switching source files
535 (different subfiles, as we call them) within one object file,
536 but using a stack rather than in an arbitrary order. */
541 register struct subfile_stack
*tem
542 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
544 tem
->next
= subfile_stack
;
546 if (current_subfile
== 0 || current_subfile
->name
== 0)
548 tem
->name
= current_subfile
->name
;
549 tem
->prev_index
= header_file_prev_index
;
556 register struct subfile_stack
*link
= subfile_stack
;
562 subfile_stack
= link
->next
;
563 header_file_prev_index
= link
->prev_index
;
569 /* Manage the vector of line numbers for each subfile. */
572 record_line (subfile
, line
, pc
)
573 register struct subfile
*subfile
;
577 struct linetable_entry
*e
;
578 /* Ignore the dummy line number in libg.o */
583 /* Make sure line vector exists and is big enough. */
584 if (!subfile
->line_vector
) {
585 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
586 subfile
->line_vector
= (struct linetable
*)
587 xmalloc (sizeof (struct linetable
)
588 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
589 subfile
->line_vector
->nitems
= 0;
592 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
594 subfile
->line_vector_length
*= 2;
595 subfile
->line_vector
= (struct linetable
*)
596 xrealloc (subfile
->line_vector
, (sizeof (struct linetable
)
597 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
600 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
601 e
->line
= line
; e
->pc
= pc
;
605 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
609 compare_line_numbers (ln1
, ln2
)
610 struct linetable_entry
*ln1
, *ln2
;
612 return ln1
->line
- ln2
->line
;
615 /* Start a new symtab for a new source file.
616 This is called when a dbx symbol of type N_SO is seen;
617 it indicates the start of data for one original source file. */
620 start_symtab (name
, dirname
, start_addr
)
623 CORE_ADDR start_addr
;
626 last_source_file
= name
;
627 last_source_start_addr
= start_addr
;
630 global_stabs
= 0; /* AIX COFF */
631 file_stabs
= 0; /* AIX COFF */
634 /* Context stack is initially empty. Allocate first one with room for
635 10 levels; reuse it forever afterward. */
636 if (context_stack
== 0) {
637 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
638 context_stack
= (struct context_stack
*)
639 xmalloc (context_stack_size
* sizeof (struct context_stack
));
641 context_stack_depth
= 0;
643 new_object_header_files ();
645 type_vector_length
= 0;
646 type_vector
= (struct type
**) 0;
648 /* Initialize the list of sub source files with one entry
649 for this file (the top-level source file). */
653 start_subfile (name
, dirname
);
656 /* Finish the symbol definitions for one main source file,
657 close off all the lexical contexts for that file
658 (creating struct block's for them), then make the struct symtab
659 for that file and put it in the list of all such.
661 END_ADDR is the address of the end of the file's text. */
664 end_symtab (end_addr
, sort_pending
, sort_linevec
, objfile
)
668 struct objfile
*objfile
;
670 register struct symtab
*symtab
;
671 register struct blockvector
*blockvector
;
672 register struct subfile
*subfile
;
673 struct subfile
*nextsub
;
675 /* Finish the lexical context of the last function in the file;
676 pop the context stack. */
678 if (context_stack_depth
> 0)
680 register struct context_stack
*cstk
;
681 context_stack_depth
--;
682 cstk
= &context_stack
[context_stack_depth
];
683 /* Make a block for the local symbols within. */
684 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
685 cstk
->start_addr
, end_addr
);
687 /* Debug: if context stack still has something in it, we are in
689 if (context_stack_depth
> 0)
693 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
694 in this stage. Especially, blocks for static functions will show up at
695 the end. We need to sort them, so tools like `find_pc_function' and
696 `find_pc_block' can work reliably. */
697 if (sort_pending
&& pending_blocks
) {
698 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
701 struct pending_block
*pb
, *pbnext
;
703 pb
= pending_blocks
, pbnext
= pb
->next
;
708 /* swap blocks if unordered! */
710 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
)) {
711 struct block
*tmp
= pb
->block
;
712 pb
->block
= pbnext
->block
;
717 pbnext
= pbnext
->next
;
722 /* Cleanup any undefined types that have been left hanging around
723 (this needs to be done before the finish_blocks so that
724 file_symbols is still good). */
725 cleanup_undefined_types ();
727 /* Hooks for xcoffread.c */
729 patch_block_stabs (file_symbols
, file_stabs
);
735 patch_block_stabs (global_symbols
, global_stabs
);
740 if (pending_blocks
== 0
742 && global_symbols
== 0) {
743 /* Ignore symtabs that have no functions with real debugging info */
746 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
747 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
);
748 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
);
749 blockvector
= make_blockvector ();
752 /* Now create the symtab objects proper, one for each subfile. */
753 /* (The main file is the last one on the chain.) */
755 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
757 /* If we have blocks of symbols, make a symtab.
758 Otherwise, just ignore this file and any line number info in it. */
761 if (subfile
->line_vector
) {
762 /* First, shrink the linetable to make more memory. */
763 subfile
->line_vector
= (struct linetable
*)
764 xrealloc (subfile
->line_vector
, (sizeof (struct linetable
)
765 + subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
)));
768 qsort (subfile
->line_vector
->item
, subfile
->line_vector
->nitems
,
769 sizeof (struct linetable_entry
), compare_line_numbers
);
772 /* Now, allocate a symbol table. */
773 symtab
= allocate_symtab (subfile
->name
, objfile
);
775 /* Fill in its components. */
776 symtab
->blockvector
= blockvector
;
777 symtab
->linetable
= subfile
->line_vector
;
778 symtab
->dirname
= subfile
->dirname
;
779 symtab
->free_code
= free_linetable
;
780 symtab
->free_ptr
= 0;
782 /* Link the new symtab into the list of such. */
783 symtab
->next
= symtab_list
;
784 symtab_list
= symtab
;
786 /* No blocks for this file. Delete any line number info we have
788 if (subfile
->line_vector
)
789 free (subfile
->line_vector
);
792 nextsub
= subfile
->next
;
797 free ((char *) type_vector
);
799 type_vector_length
= 0;
801 last_source_file
= 0;
808 /* Push a context block. Args are an identifying nesting level (checkable
809 when you pop it), and the starting PC address of this context. */
811 struct context_stack
*
812 push_context (desc
, valu
)
816 register struct context_stack
*new;
818 if (context_stack_depth
== context_stack_size
)
820 context_stack_size
*= 2;
821 context_stack
= (struct context_stack
*)
822 xrealloc (context_stack
,
824 * sizeof (struct context_stack
)));
827 new = &context_stack
[context_stack_depth
++];
829 new->locals
= local_symbols
;
830 new->old_blocks
= pending_blocks
;
831 new->start_addr
= valu
;
839 /* Initialize anything that needs initializing when starting to read
840 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
852 /* Initialize anything that needs initializing when a completely new
853 symbol file is specified (not just adding some symbols from another
854 file, e.g. a shared library). */
859 /* Empty the hash table of global syms looking for values. */
860 bzero (global_sym_chain
, sizeof global_sym_chain
);
865 /* Scan through all of the global symbols defined in the object file,
866 assigning values to the debugging symbols that need to be assigned
867 to. Get these symbols from the misc function list. */
875 for (mf
= 0; mf
< misc_function_count
; mf
++)
877 char *namestring
= misc_function_vector
[mf
].name
;
878 struct symbol
*sym
, *prev
;
882 prev
= (struct symbol
*) 0;
884 /* Get the hash index and check all the symbols
885 under that hash index. */
887 hash
= hashname (namestring
);
889 for (sym
= global_sym_chain
[hash
]; sym
;)
891 if (*namestring
== SYMBOL_NAME (sym
)[0]
892 && !strcmp(namestring
+ 1, SYMBOL_NAME (sym
) + 1))
894 /* Splice this symbol out of the hash chain and
895 assign the value we have to it. */
897 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
899 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
901 /* Check to see whether we need to fix up a common block. */
902 /* Note: this code might be executed several times for
903 the same symbol if there are multiple references. */
904 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
905 fix_common_block (sym
, misc_function_vector
[mf
].address
);
907 SYMBOL_VALUE_ADDRESS (sym
) = misc_function_vector
[mf
].address
;
910 sym
= SYMBOL_VALUE_CHAIN (prev
);
912 sym
= global_sym_chain
[hash
];
917 sym
= SYMBOL_VALUE_CHAIN (sym
);
924 /* Read a number by which a type is referred to in dbx data,
925 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
926 Just a single number N is equivalent to (0,N).
927 Return the two numbers by storing them in the vector TYPENUMS.
928 TYPENUMS will then be used as an argument to dbx_lookup_type. */
931 read_type_number (pp
, typenums
)
933 register int *typenums
;
938 typenums
[0] = read_number (pp
, ',');
939 typenums
[1] = read_number (pp
, ')');
944 typenums
[1] = read_number (pp
, 0);
948 /* To handle GNU C++ typename abbreviation, we need to be able to
949 fill in a type's name as soon as space for that type is allocated.
950 `type_synonym_name' is the name of the type being allocated.
951 It is cleared as soon as it is used (lest all allocated types
953 static char *type_synonym_name
;
957 define_symbol (valu
, string
, desc
, type
)
963 register struct symbol
*sym
;
964 char *p
= (char *) strchr (string
, ':');
969 /* Ignore syms with empty names. */
973 /* Ignore old-style symbols from cc -go */
977 sym
= (struct symbol
*)obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
979 if (processing_gcc_compilation
) {
980 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
981 number of bytes occupied by a type or object, which we ignore. */
982 SYMBOL_LINE(sym
) = desc
;
984 SYMBOL_LINE(sym
) = 0; /* unknown */
987 if (string
[0] == CPLUS_MARKER
)
989 /* Special GNU C++ names. */
993 SYMBOL_NAME (sym
) = "this";
995 case 'v': /* $vtbl_ptr_type */
996 /* Was: SYMBOL_NAME (sym) = "vptr"; */
999 SYMBOL_NAME (sym
) = "eh_throw";
1003 /* This was an anonymous type that was never fixed up. */
1014 = (char *) obstack_alloc (symbol_obstack
, ((p
- string
) + 1));
1015 /* Open-coded bcopy--saves function call time. */
1017 register char *p1
= string
;
1018 register char *p2
= SYMBOL_NAME (sym
);
1025 /* Determine the type of name being defined. */
1026 /* The Acorn RISC machine's compiler can put out locals that don't
1027 start with "234=" or "(3,4)=", so assume anything other than the
1028 deftypes we know how to handle is a local. */
1029 /* (Peter Watkins @ Computervision)
1030 Handle Sun-style local fortran array types 'ar...' .
1031 (gnu@cygnus.com) -- this strchr() handles them properly?
1032 (tiemann@cygnus.com) -- 'C' is for catch. */
1033 if (!strchr ("cfFGpPrStTvVXC", *p
))
1038 /* c is a special case, not followed by a type-number.
1039 SYMBOL:c=iVALUE for an integer constant symbol.
1040 SYMBOL:c=rVALUE for a floating constant symbol.
1041 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1042 e.g. "b:c=e6,0" for "const b = blob1"
1043 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1047 error ("Invalid symbol data at symtab pos %d.", symnum
);
1052 double d
= atof (p
);
1055 SYMBOL_TYPE (sym
) = builtin_type_double
;
1057 (char *) obstack_alloc (symbol_obstack
, sizeof (double));
1058 bcopy (&d
, dbl_valu
, sizeof (double));
1059 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
1060 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1061 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1066 SYMBOL_TYPE (sym
) = builtin_type_int
;
1067 SYMBOL_VALUE (sym
) = atoi (p
);
1068 SYMBOL_CLASS (sym
) = LOC_CONST
;
1072 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1073 e.g. "b:c=e6,0" for "const b = blob1"
1074 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1078 read_type_number (&p
, typenums
);
1080 error ("Invalid symbol data: no comma in enum const symbol");
1082 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
1083 SYMBOL_VALUE (sym
) = atoi (p
);
1084 SYMBOL_CLASS (sym
) = LOC_CONST
;
1088 error ("Invalid symbol data at symtab pos %d.", symnum
);
1090 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1091 add_symbol_to_list (sym
, &file_symbols
);
1095 /* Now usually comes a number that says which data type,
1096 and possibly more stuff to define the type
1097 (all of which is handled by read_type) */
1099 if (deftype
== 'p' && *p
== 'F')
1100 /* pF is a two-letter code that means a function parameter in Fortran.
1101 The type-number specifies the type of the return value.
1102 Translate it into a pointer-to-function type. */
1106 = lookup_pointer_type (lookup_function_type (read_type (&p
)));
1110 struct type
*type_read
;
1111 synonym
= *p
== 't';
1116 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1117 strlen (SYMBOL_NAME (sym
)));
1120 type_read
= read_type (&p
);
1122 if ((deftype
== 'F' || deftype
== 'f')
1123 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
1126 /* This code doesn't work -- it needs to realloc and can't. */
1127 struct type
*new = (struct type
*)
1128 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1130 /* Generate a template for the type of this function. The
1131 types of the arguments will be added as we read the symbol
1133 *new = *lookup_function_type (type_read
);
1134 SYMBOL_TYPE(sym
) = new;
1135 in_function_type
= new;
1137 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
1141 SYMBOL_TYPE (sym
) = type_read
;
1147 /* The name of a caught exception. */
1148 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1149 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1150 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1151 add_symbol_to_list (sym
, &local_symbols
);
1155 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1156 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1157 add_symbol_to_list (sym
, &file_symbols
);
1161 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1162 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1163 add_symbol_to_list (sym
, &global_symbols
);
1167 /* For a class G (global) symbol, it appears that the
1168 value is not correct. It is necessary to search for the
1169 corresponding linker definition to find the value.
1170 These definitions appear at the end of the namelist. */
1171 i
= hashname (SYMBOL_NAME (sym
));
1172 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1173 global_sym_chain
[i
] = sym
;
1174 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1175 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1176 add_symbol_to_list (sym
, &global_symbols
);
1179 /* This case is faked by a conditional above,
1180 when there is no code letter in the dbx data.
1181 Dbx data never actually contains 'l'. */
1183 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1184 SYMBOL_VALUE (sym
) = valu
;
1185 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1186 add_symbol_to_list (sym
, &local_symbols
);
1190 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1191 can also be a LOC_LOCAL_ARG depending on symbol type. */
1192 #ifndef DBX_PARM_SYMBOL_CLASS
1193 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1195 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1196 SYMBOL_VALUE (sym
) = valu
;
1197 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1199 /* This doesn't work yet. */
1200 add_param_to_type (&in_function_type
, sym
);
1202 add_symbol_to_list (sym
, &local_symbols
);
1204 /* If it's gcc-compiled, if it says `short', believe it. */
1205 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1208 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1209 /* This macro is defined on machines (e.g. sparc) where
1210 we should believe the type of a PCC 'short' argument,
1211 but shouldn't believe the address (the address is
1212 the address of the corresponding int). Note that
1213 this is only different from the BELIEVE_PCC_PROMOTION
1214 case on big-endian machines.
1216 My guess is that this correction, as opposed to changing
1217 the parameter to an 'int' (as done below, for PCC
1218 on most machines), is the right thing to do
1219 on all machines, but I don't want to risk breaking
1220 something that already works. On most PCC machines,
1221 the sparc problem doesn't come up because the calling
1222 function has to zero the top bytes (not knowing whether
1223 the called function wants an int or a short), so there
1224 is no practical difference between an int and a short
1225 (except perhaps what happens when the GDB user types
1226 "print short_arg = 0x10000;").
1228 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1229 actually produces the correct address (we don't need to fix it
1230 up). I made this code adapt so that it will offset the symbol
1231 if it was pointing at an int-aligned location and not
1232 otherwise. This way you can use the same gdb for 4.0.x and
1235 if (0 == SYMBOL_VALUE (sym
) % sizeof (int))
1237 if (SYMBOL_TYPE (sym
) == builtin_type_char
1238 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
)
1239 SYMBOL_VALUE (sym
) += 3;
1240 else if (SYMBOL_TYPE (sym
) == builtin_type_short
1241 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1242 SYMBOL_VALUE (sym
) += 2;
1246 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1248 /* If PCC says a parameter is a short or a char,
1249 it is really an int. */
1250 if (SYMBOL_TYPE (sym
) == builtin_type_char
1251 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1252 SYMBOL_TYPE (sym
) = builtin_type_int
;
1253 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1254 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1255 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1258 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1261 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1262 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1263 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1264 add_symbol_to_list (sym
, &local_symbols
);
1268 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1269 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1270 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1271 add_symbol_to_list (sym
, &local_symbols
);
1275 /* Static symbol at top level of file */
1276 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1277 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1278 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1279 add_symbol_to_list (sym
, &file_symbols
);
1283 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1284 SYMBOL_VALUE (sym
) = valu
;
1285 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1286 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1287 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1288 TYPE_NAME (SYMBOL_TYPE (sym
)) =
1289 obsavestring (SYMBOL_NAME (sym
),
1290 strlen (SYMBOL_NAME (sym
)));
1291 /* C++ vagaries: we may have a type which is derived from
1292 a base type which did not have its name defined when the
1293 derived class was output. We fill in the derived class's
1294 base part member's name here in that case. */
1295 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1296 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1297 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1300 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1301 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1302 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1303 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1306 add_symbol_to_list (sym
, &file_symbols
);
1310 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1311 SYMBOL_VALUE (sym
) = valu
;
1312 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1313 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1314 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1315 TYPE_NAME (SYMBOL_TYPE (sym
))
1317 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1319 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1320 ? "struct " : "union ")),
1322 add_symbol_to_list (sym
, &file_symbols
);
1326 register struct symbol
*typedef_sym
1327 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1328 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1329 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1331 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1332 SYMBOL_VALUE (typedef_sym
) = valu
;
1333 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1334 add_symbol_to_list (typedef_sym
, &file_symbols
);
1339 /* Static symbol of local scope */
1340 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1341 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1342 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1343 add_symbol_to_list (sym
, &local_symbols
);
1347 /* Reference parameter */
1348 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1349 SYMBOL_VALUE (sym
) = valu
;
1350 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1351 add_symbol_to_list (sym
, &local_symbols
);
1355 /* This is used by Sun FORTRAN for "function result value".
1356 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1357 that Pascal uses it too, but when I tried it Pascal used
1358 "x:3" (local symbol) instead. */
1359 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1360 SYMBOL_VALUE (sym
) = valu
;
1361 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1362 add_symbol_to_list (sym
, &local_symbols
);
1366 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1371 /* What about types defined as forward references inside of a small lexical
1373 /* Add a type to the list of undefined types to be checked through
1374 once this file has been read in. */
1376 add_undefined_type (type
)
1379 if (undef_types_length
== undef_types_allocated
)
1381 undef_types_allocated
*= 2;
1382 undef_types
= (struct type
**)
1383 xrealloc (undef_types
,
1384 undef_types_allocated
* sizeof (struct type
*));
1386 undef_types
[undef_types_length
++] = type
;
1389 /* Add here something to go through each undefined type, see if it's
1390 still undefined, and do a full lookup if so. */
1392 cleanup_undefined_types ()
1396 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
1398 /* Reasonable test to see if it's been defined since. */
1399 if (TYPE_NFIELDS (*type
) == 0)
1401 struct pending
*ppt
;
1403 /* Name of the type, without "struct" or "union" */
1404 char *typename
= TYPE_NAME (*type
);
1406 if (!strncmp (typename
, "struct ", 7))
1408 if (!strncmp (typename
, "union ", 6))
1411 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1412 for (i
= 0; i
< ppt
->nsyms
; i
++)
1414 struct symbol
*sym
= ppt
->symbol
[i
];
1416 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1417 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1418 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1420 && !strcmp (SYMBOL_NAME (sym
), typename
))
1421 bcopy (SYMBOL_TYPE (sym
), *type
, sizeof (struct type
));
1425 /* It has been defined; don't mark it as a stub. */
1426 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1428 undef_types_length
= 0;
1431 /* Skip rest of this symbol and return an error type.
1433 General notes on error recovery: error_type always skips to the
1434 end of the symbol (modulo cretinous dbx symbol name continuation).
1435 Thus code like this:
1437 if (*(*pp)++ != ';')
1438 return error_type (pp);
1440 is wrong because if *pp starts out pointing at '\0' (typically as the
1441 result of an earlier error), it will be incremented to point to the
1442 start of the next symbol, which might produce strange results, at least
1443 if you run off the end of the string table. Instead use
1446 return error_type (pp);
1452 foo = error_type (pp);
1456 And in case it isn't obvious, the point of all this hair is so the compiler
1457 can define new types and new syntaxes, and old versions of the
1458 debugger will be able to read the new symbol tables. */
1464 complain (&error_type_complaint
, 0);
1467 /* Skip to end of symbol. */
1468 while (**pp
!= '\0')
1471 /* Check for and handle cretinous dbx symbol name continuation! */
1472 if ((*pp
)[-1] == '\\')
1473 *pp
= next_symbol_text ();
1477 return builtin_type_error
;
1480 /* Read a dbx type reference or definition;
1481 return the type that is meant.
1482 This can be just a number, in which case it references
1483 a type already defined and placed in type_vector.
1484 Or the number can be followed by an =, in which case
1485 it means to define a new type according to the text that
1492 register struct type
*type
= 0;
1497 /* Read type number if present. The type number may be omitted.
1498 for instance in a two-dimensional array declared with type
1499 "ar1;1;10;ar1;1;10;4". */
1500 if ((**pp
>= '0' && **pp
<= '9')
1503 read_type_number (pp
, typenums
);
1505 /* Type is not being defined here. Either it already exists,
1506 or this is a forward reference to it. dbx_alloc_type handles
1509 return dbx_alloc_type (typenums
);
1511 /* Type is being defined here. */
1512 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1516 /* if such a type already exists, this is an unnecessary duplication
1517 of the stab string, which is common in (RS/6000) xlc generated
1518 objects. In that case, simply return NULL and let the caller take
1521 tt
= *dbx_lookup_type (typenums
);
1522 if (tt
&& tt
->length
&& tt
->code
)
1531 /* 'typenums=' not present, type is anonymous. Read and return
1532 the definition, but don't put it in the type vector. */
1533 typenums
[0] = typenums
[1] = -1;
1541 enum type_code code
;
1543 /* Used to index through file_symbols. */
1544 struct pending
*ppt
;
1547 /* Name including "struct", etc. */
1550 /* Name without "struct", etc. */
1551 char *type_name_only
;
1557 /* Set the type code according to the following letter. */
1561 code
= TYPE_CODE_STRUCT
;
1565 code
= TYPE_CODE_UNION
;
1569 code
= TYPE_CODE_ENUM
;
1573 return error_type (pp
);
1576 to
= type_name
= (char *)
1577 obstack_alloc (symbol_obstack
,
1579 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1581 /* Copy the prefix. */
1583 while (*to
++ = *from
++)
1587 type_name_only
= to
;
1589 /* Copy the name. */
1591 while ((*to
++ = *from
++) != ':')
1595 /* Set the pointer ahead of the name which we just read. */
1599 /* The following hack is clearly wrong, because it doesn't
1600 check whether we are in a baseclass. I tried to reproduce
1601 the case that it is trying to fix, but I couldn't get
1602 g++ to put out a cross reference to a basetype. Perhaps
1603 it doesn't do it anymore. */
1604 /* Note: for C++, the cross reference may be to a base type which
1605 has not yet been seen. In this case, we skip to the comma,
1606 which will mark the end of the base class name. (The ':'
1607 at the end of the base class name will be skipped as well.)
1608 But sometimes (ie. when the cross ref is the last thing on
1609 the line) there will be no ','. */
1610 from
= (char *) strchr (*pp
, ',');
1616 /* Now check to see whether the type has already been declared. */
1617 /* This is necessary at least in the case where the
1618 program says something like
1620 The compiler puts out a cross-reference; we better find
1621 set the length of the structure correctly so we can
1622 set the length of the array. */
1623 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1624 for (i
= 0; i
< ppt
->nsyms
; i
++)
1626 struct symbol
*sym
= ppt
->symbol
[i
];
1628 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1629 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1630 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1631 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1633 obstack_free (symbol_obstack
, type_name
);
1634 type
= SYMBOL_TYPE (sym
);
1639 /* Didn't find the type to which this refers, so we must
1640 be dealing with a forward reference. Allocate a type
1641 structure for it, and keep track of it so we can
1642 fill in the rest of the fields when we get the full
1644 type
= dbx_alloc_type (typenums
);
1645 TYPE_CODE (type
) = code
;
1646 TYPE_NAME (type
) = type_name
;
1647 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1649 TYPE_CPLUS_SPECIFIC (type
)
1650 = (struct cplus_struct_type
*) obstack_alloc (symbol_obstack
, sizeof (struct cplus_struct_type
));
1651 bzero (TYPE_CPLUS_SPECIFIC (type
), sizeof (struct cplus_struct_type
));
1654 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1656 add_undefined_type (type
);
1660 case '-': /* RS/6000 built-in type */
1662 type
= builtin_type (pp
); /* (in xcoffread.c) */
1677 read_type_number (pp
, xtypenums
);
1678 type
= *dbx_lookup_type (xtypenums
);
1683 type
= builtin_type_void
;
1684 if (typenums
[0] != -1)
1685 *dbx_lookup_type (typenums
) = type
;
1689 type1
= read_type (pp
);
1690 /* FIXME -- we should be doing smash_to_XXX types here. */
1692 /* postponed type decoration should be allowed. */
1693 if (typenums
[1] > 0 && typenums
[1] < type_vector_length
&&
1694 (type
= type_vector
[typenums
[1]])) {
1695 smash_to_pointer_type (type
, type1
);
1699 type
= lookup_pointer_type (type1
);
1700 if (typenums
[0] != -1)
1701 *dbx_lookup_type (typenums
) = type
;
1706 struct type
*domain
= read_type (pp
);
1707 struct type
*memtype
;
1710 /* Invalid member type data format. */
1711 return error_type (pp
);
1714 memtype
= read_type (pp
);
1715 type
= dbx_alloc_type (typenums
);
1716 smash_to_member_type (type
, domain
, memtype
);
1721 if ((*pp
)[0] == '#')
1723 /* We'll get the parameter types from the name. */
1724 struct type
*return_type
;
1727 return_type
= read_type (pp
);
1728 if (*(*pp
)++ != ';')
1729 complain (&invalid_member_complaint
, symnum
);
1730 type
= allocate_stub_method (return_type
);
1731 if (typenums
[0] != -1)
1732 *dbx_lookup_type (typenums
) = type
;
1736 struct type
*domain
= read_type (pp
);
1737 struct type
*return_type
;
1740 if (*(*pp
)++ != ',')
1741 error ("invalid member type data format, at symtab pos %d.",
1744 return_type
= read_type (pp
);
1745 args
= read_args (pp
, ';');
1746 type
= dbx_alloc_type (typenums
);
1747 smash_to_method_type (type
, domain
, return_type
, args
);
1752 type1
= read_type (pp
);
1753 type
= lookup_reference_type (type1
);
1754 if (typenums
[0] != -1)
1755 *dbx_lookup_type (typenums
) = type
;
1759 type1
= read_type (pp
);
1760 type
= lookup_function_type (type1
);
1761 if (typenums
[0] != -1)
1762 *dbx_lookup_type (typenums
) = type
;
1766 type
= read_range_type (pp
, typenums
);
1767 if (typenums
[0] != -1)
1768 *dbx_lookup_type (typenums
) = type
;
1772 type
= dbx_alloc_type (typenums
);
1773 type
= read_enum_type (pp
, type
);
1774 *dbx_lookup_type (typenums
) = type
;
1778 type
= dbx_alloc_type (typenums
);
1779 TYPE_NAME (type
) = type_synonym_name
;
1780 type_synonym_name
= 0;
1781 type
= read_struct_type (pp
, type
);
1785 type
= dbx_alloc_type (typenums
);
1786 TYPE_NAME (type
) = type_synonym_name
;
1787 type_synonym_name
= 0;
1788 type
= read_struct_type (pp
, type
);
1789 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1794 return error_type (pp
);
1797 type
= dbx_alloc_type (typenums
);
1798 type
= read_array_type (pp
, type
);
1802 --*pp
; /* Go back to the symbol in error */
1803 /* Particularly important if it was \0! */
1804 return error_type (pp
);
1811 /* If this is an overriding temporary alteration for a header file's
1812 contents, and this type number is unknown in the global definition,
1813 put this type into the global definition at this type number. */
1814 if (header_file_prev_index
>= 0)
1816 register struct type
**tp
1817 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
1825 /* This page contains subroutines of read_type. */
1827 /* Read the description of a structure (or union type)
1828 and return an object describing the type. */
1831 read_struct_type (pp
, type
)
1833 register struct type
*type
;
1835 /* Total number of methods defined in this class.
1836 If the class defines two `f' methods, and one `g' method,
1837 then this will have the value 3. */
1838 int total_length
= 0;
1842 struct nextfield
*next
;
1843 int visibility
; /* 0=public, 1=protected, 2=public */
1849 struct next_fnfield
*next
;
1850 int visibility
; /* 0=public, 1=protected, 2=public */
1851 struct fn_field fn_field
;
1854 struct next_fnfieldlist
1856 struct next_fnfieldlist
*next
;
1857 struct fn_fieldlist fn_fieldlist
;
1860 register struct nextfield
*list
= 0;
1861 struct nextfield
*new;
1866 register struct next_fnfieldlist
*mainlist
= 0;
1869 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1870 TYPE_CPLUS_SPECIFIC (type
)
1871 = (struct cplus_struct_type
*) obstack_alloc (symbol_obstack
, sizeof (struct cplus_struct_type
));
1872 bzero (TYPE_CPLUS_SPECIFIC (type
), sizeof (struct cplus_struct_type
));
1874 /* First comes the total size in bytes. */
1876 TYPE_LENGTH (type
) = read_number (pp
, 0);
1878 /* C++: Now, if the class is a derived class, then the next character
1879 will be a '!', followed by the number of base classes derived from.
1880 Each element in the list contains visibility information,
1881 the offset of this base class in the derived structure,
1882 and then the base type. */
1885 int i
, n_baseclasses
, offset
;
1886 struct type
*baseclass
;
1889 /* Nonzero if it is a virtual baseclass, i.e.,
1893 struct C : public B, public virtual A {};
1895 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1896 2.0 language feature. */
1901 n_baseclasses
= read_number (pp
, ',');
1902 TYPE_FIELD_VIRTUAL_BITS (type
) =
1903 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (n_baseclasses
));
1904 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
1906 for (i
= 0; i
< n_baseclasses
; i
++)
1909 *pp
= next_symbol_text ();
1920 /* Bad visibility format. */
1921 return error_type (pp
);
1934 /* Bad visibility format. */
1935 return error_type (pp
);
1938 SET_TYPE_FIELD_VIRTUAL (type
, i
);
1941 /* Offset of the portion of the object corresponding to
1942 this baseclass. Always zero in the absence of
1943 multiple inheritance. */
1944 offset
= read_number (pp
, ',');
1945 baseclass
= read_type (pp
);
1946 *pp
+= 1; /* skip trailing ';' */
1948 /* Make this baseclass visible for structure-printing purposes. */
1949 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1952 list
->visibility
= via_public
;
1953 list
->field
.type
= baseclass
;
1954 list
->field
.name
= type_name_no_tag (baseclass
);
1955 list
->field
.bitpos
= offset
;
1956 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
1959 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
1962 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1963 At the end, we see a semicolon instead of a field.
1965 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1968 The `?' is a placeholder for one of '/2' (public visibility),
1969 '/1' (protected visibility), '/0' (private visibility), or nothing
1970 (C style symbol table, public visibility). */
1972 /* We better set p right now, in case there are no fields at all... */
1977 /* Check for and handle cretinous dbx symbol name continuation! */
1978 if (**pp
== '\\') *pp
= next_symbol_text ();
1980 /* Get space to record the next field's data. */
1981 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1985 /* Get the field name. */
1987 if (*p
== CPLUS_MARKER
)
1989 /* Special GNU C++ name. */
1994 struct type
*context
;
2005 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2006 prefix
= "INVALID_C++_ABBREV";
2010 context
= read_type (pp
);
2011 name
= type_name_no_tag (context
);
2014 complain (&invalid_cpp_type_complaint
, symnum
);
2015 TYPE_NAME (context
) = name
;
2017 list
->field
.name
= obconcat (prefix
, name
, "");
2020 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2021 list
->field
.type
= read_type (pp
);
2022 (*pp
)++; /* Skip the comma. */
2023 list
->field
.bitpos
= read_number (pp
, ';');
2024 /* This field is unpacked. */
2025 list
->field
.bitsize
= 0;
2027 /* GNU C++ anonymous type. */
2031 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2037 while (*p
!= ':') p
++;
2038 list
->field
.name
= obsavestring (*pp
, p
- *pp
);
2040 /* C++: Check to see if we have hit the methods yet. */
2046 /* This means we have a visibility for a field coming. */
2052 list
->visibility
= 0; /* private */
2057 list
->visibility
= 1; /* protected */
2062 list
->visibility
= 2; /* public */
2067 else /* normal dbx-style format. */
2068 list
->visibility
= 2; /* public */
2070 list
->field
.type
= read_type (pp
);
2073 /* Static class member. */
2074 list
->field
.bitpos
= (long)-1;
2076 while (*p
!= ';') p
++;
2077 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2082 else if (**pp
!= ',')
2083 /* Bad structure-type format. */
2084 return error_type (pp
);
2086 (*pp
)++; /* Skip the comma. */
2087 list
->field
.bitpos
= read_number (pp
, ',');
2088 list
->field
.bitsize
= read_number (pp
, ';');
2091 /* FIXME-tiemann: Can't the compiler put out something which
2092 lets us distinguish these? (or maybe just not put out anything
2093 for the field). What is the story here? What does the compiler
2094 really do? Also, patch gdb.texinfo for this case; I document
2095 it as a possible problem there. Search for "DBX-style". */
2097 /* This is wrong because this is identical to the symbols
2098 produced for GCC 0-size arrays. For example:
2103 The code which dumped core in such circumstances should be
2104 fixed not to dump core. */
2106 /* g++ -g0 can put out bitpos & bitsize zero for a static
2107 field. This does not give us any way of getting its
2108 class, so we can't know its name. But we can just
2109 ignore the field so we don't dump core and other nasty
2111 if (list
->field
.bitpos
== 0
2112 && list
->field
.bitsize
== 0)
2114 complain (&dbx_class_complaint
, 0);
2115 /* Ignore this field. */
2121 /* Detect an unpacked field and mark it as such.
2122 dbx gives a bit size for all fields.
2123 Note that forward refs cannot be packed,
2124 and treat enums as if they had the width of ints. */
2125 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
2126 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
2127 list
->field
.bitsize
= 0;
2128 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2129 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2130 && (list
->field
.bitsize
2131 == 8 * TYPE_LENGTH (builtin_type_int
))
2135 list
->field
.bitpos
% 8 == 0)
2136 list
->field
.bitsize
= 0;
2142 /* chill the list of fields: the last entry (at the head)
2143 is a partially constructed entry which we now scrub. */
2146 /* Now create the vector of fields, and record how big it is.
2147 We need this info to record proper virtual function table information
2148 for this class's virtual functions. */
2150 TYPE_NFIELDS (type
) = nfields
;
2151 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
,
2152 sizeof (struct field
) * nfields
);
2154 TYPE_FIELD_PRIVATE_BITS (type
) =
2155 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
2156 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2158 TYPE_FIELD_PROTECTED_BITS (type
) =
2159 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
2160 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2162 /* Copy the saved-up fields into the field vector. */
2164 for (n
= nfields
; list
; list
= list
->next
)
2167 TYPE_FIELD (type
, n
) = list
->field
;
2168 if (list
->visibility
== 0)
2169 SET_TYPE_FIELD_PRIVATE (type
, n
);
2170 else if (list
->visibility
== 1)
2171 SET_TYPE_FIELD_PROTECTED (type
, n
);
2174 /* Now come the method fields, as NAME::methods
2175 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2176 At the end, we see a semicolon instead of a field.
2178 For the case of overloaded operators, the format is
2179 OPERATOR::*.methods, where OPERATOR is the string "operator",
2180 `*' holds the place for an operator name (such as `+=')
2181 and `.' marks the end of the operator name. */
2184 /* Now, read in the methods. To simplify matters, we
2185 "unread" the name that has been read, so that we can
2186 start from the top. */
2188 /* For each list of method lists... */
2192 struct next_fnfield
*sublist
= 0;
2193 struct type
*look_ahead_type
= NULL
;
2195 struct next_fnfieldlist
*new_mainlist
=
2196 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2201 /* read in the name. */
2202 while (*p
!= ':') p
++;
2203 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2205 /* This is a completely wierd case. In order to stuff in the
2206 names that might contain colons (the usual name delimiter),
2207 Mike Tiemann defined a different name format which is
2208 signalled if the identifier is "op$". In that case, the
2209 format is "op$::XXXX." where XXXX is the name. This is
2210 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2211 /* This lets the user type "break operator+".
2212 We could just put in "+" as the name, but that wouldn't
2214 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2215 char *o
= opname
+ 3;
2217 /* Skip past '::'. */
2219 if (**pp
== '\\') *pp
= next_symbol_text ();
2223 main_fn_name
= savestring (opname
, o
- opname
);
2228 main_fn_name
= savestring (*pp
, p
- *pp
);
2229 /* Skip past '::'. */
2231 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
2235 struct next_fnfield
*new_sublist
=
2236 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2238 /* Check for and handle cretinous dbx symbol name continuation! */
2239 if (look_ahead_type
== NULL
) /* Normal case. */
2241 if (**pp
== '\\') *pp
= next_symbol_text ();
2243 new_sublist
->fn_field
.type
= read_type (pp
);
2245 /* Invalid symtab info for method. */
2246 return error_type (pp
);
2249 { /* g++ version 1 kludge */
2250 new_sublist
->fn_field
.type
= look_ahead_type
;
2251 look_ahead_type
= NULL
;
2256 while (*p
!= ';') p
++;
2257 /* If this is just a stub, then we don't have the
2259 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2261 new_sublist
->visibility
= *(*pp
)++ - '0';
2262 if (**pp
== '\\') *pp
= next_symbol_text ();
2265 case 'A': /* Normal functions. */
2266 new_sublist
->fn_field
.is_const
= 0;
2267 new_sublist
->fn_field
.is_volatile
= 0;
2270 case 'B': /* `const' member functions. */
2271 new_sublist
->fn_field
.is_const
= 1;
2272 new_sublist
->fn_field
.is_volatile
= 0;
2275 case 'C': /* `volatile' member function. */
2276 new_sublist
->fn_field
.is_const
= 0;
2277 new_sublist
->fn_field
.is_volatile
= 1;
2280 case 'D': /* `const volatile' member function. */
2281 new_sublist
->fn_field
.is_const
= 1;
2282 new_sublist
->fn_field
.is_volatile
= 1;
2285 case '*': /* File compiled with g++ version 1 -- no info */
2290 complain(&const_vol_complaint
, **pp
);
2297 /* virtual member function, followed by index. */
2298 /* The sign bit is set to distinguish pointers-to-methods
2299 from virtual function indicies. Since the array is
2300 in words, the quantity must be shifted left by 1
2301 on 16 bit machine, and by 2 on 32 bit machine, forcing
2302 the sign bit out, and usable as a valid index into
2303 the array. Remove the sign bit here. */
2304 new_sublist
->fn_field
.voffset
=
2305 (0x7fffffff & read_number (pp
, ';')) + 2;
2307 if (**pp
== '\\') *pp
= next_symbol_text ();
2309 if (**pp
== ';' || **pp
== '\0')
2310 /* Must be g++ version 1. */
2311 new_sublist
->fn_field
.fcontext
= 0;
2314 /* Figure out from whence this virtual function came.
2315 It may belong to virtual function table of
2316 one of its baseclasses. */
2317 look_ahead_type
= read_type (pp
);
2319 { /* g++ version 1 overloaded methods. */ }
2322 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2324 return error_type (pp
);
2327 look_ahead_type
= NULL
;
2333 /* static member function. */
2334 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2339 complain (&member_fn_complaint
, (*pp
)[-1]);
2340 /* Fall through into normal member function. */
2343 /* normal member function. */
2344 new_sublist
->fn_field
.voffset
= 0;
2345 new_sublist
->fn_field
.fcontext
= 0;
2349 new_sublist
->next
= sublist
;
2350 sublist
= new_sublist
;
2352 if (**pp
== '\\') *pp
= next_symbol_text ();
2354 while (**pp
!= ';' && **pp
!= '\0');
2358 new_mainlist
->fn_fieldlist
.fn_fields
=
2359 (struct fn_field
*) obstack_alloc (symbol_obstack
,
2360 sizeof (struct fn_field
) * length
);
2361 TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
) =
2362 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
2363 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
), length
);
2365 TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
) =
2366 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
2367 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
), length
);
2369 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2371 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2372 if (sublist
->visibility
== 0)
2373 B_SET (new_mainlist
->fn_fieldlist
.private_fn_field_bits
, i
);
2374 else if (sublist
->visibility
== 1)
2375 B_SET (new_mainlist
->fn_fieldlist
.protected_fn_field_bits
, i
);
2378 new_mainlist
->fn_fieldlist
.length
= length
;
2379 new_mainlist
->next
= mainlist
;
2380 mainlist
= new_mainlist
;
2382 total_length
+= length
;
2384 while (**pp
!= ';');
2389 TYPE_FN_FIELDLISTS (type
) =
2390 (struct fn_fieldlist
*) obstack_alloc (symbol_obstack
,
2391 sizeof (struct fn_fieldlist
) * nfn_fields
);
2393 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2394 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2398 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2399 TYPE_NFN_FIELDS_TOTAL (type
) +=
2400 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2403 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
)
2404 TYPE_FN_FIELDLISTS (type
)[--n
] = mainlist
->fn_fieldlist
;
2410 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2412 /* Obsolete flags that used to indicate the presence
2413 of constructors and/or destructors. */
2417 /* Read either a '%' or the final ';'. */
2418 if (*(*pp
)++ == '%')
2420 /* We'd like to be able to derive the vtable pointer field
2421 from the type information, but when it's inherited, that's
2422 hard. A reason it's hard is because we may read in the
2423 info about a derived class before we read in info about
2424 the base class that provides the vtable pointer field.
2425 Once the base info has been read, we could fill in the info
2426 for the derived classes, but for the fact that by then,
2427 we don't remember who needs what. */
2429 int predicted_fieldno
= -1;
2431 /* Now we must record the virtual function table pointer's
2432 field information. */
2440 /* In version 2, we derive the vfield ourselves. */
2441 for (n
= 0; n
< nfields
; n
++)
2443 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2444 sizeof (vptr_name
) -1))
2446 predicted_fieldno
= n
;
2450 if (predicted_fieldno
< 0)
2451 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2452 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2453 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2455 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2463 while (*p
!= '\0' && *p
!= ';')
2466 /* Premature end of symbol. */
2467 return error_type (pp
);
2469 TYPE_VPTR_BASETYPE (type
) = t
;
2472 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2474 /* FIXME-tiemann: what's this? */
2476 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2481 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2482 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2483 sizeof (vptr_name
) -1))
2485 TYPE_VPTR_FIELDNO (type
) = i
;
2489 /* Virtual function table field not found. */
2490 return error_type (pp
);
2493 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2496 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2497 error ("TYPE_VPTR_FIELDNO miscalculated");
2507 /* Read a definition of an array type,
2508 and create and return a suitable type object.
2509 Also creates a range type which represents the bounds of that
2512 read_array_type (pp
, type
)
2514 register struct type
*type
;
2516 struct type
*index_type
, *element_type
, *range_type
;
2520 /* Format of an array type:
2521 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2524 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2525 for these, produce a type like float[][]. */
2527 index_type
= read_type (pp
);
2529 /* Improper format of array type decl. */
2530 return error_type (pp
);
2533 if (!(**pp
>= '0' && **pp
<= '9'))
2538 lower
= read_number (pp
, ';');
2540 if (!(**pp
>= '0' && **pp
<= '9'))
2545 upper
= read_number (pp
, ';');
2547 element_type
= read_type (pp
);
2556 /* Create range type. */
2557 range_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2558 sizeof (struct type
));
2559 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2560 TYPE_TARGET_TYPE (range_type
) = index_type
;
2562 /* This should never be needed. */
2563 TYPE_LENGTH (range_type
) = sizeof (int);
2565 TYPE_NFIELDS (range_type
) = 2;
2566 TYPE_FIELDS (range_type
) =
2567 (struct field
*) obstack_alloc (symbol_obstack
,
2568 2 * sizeof (struct field
));
2569 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2570 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2573 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2574 TYPE_TARGET_TYPE (type
) = element_type
;
2575 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2576 TYPE_NFIELDS (type
) = 1;
2577 TYPE_FIELDS (type
) =
2578 (struct field
*) obstack_alloc (symbol_obstack
,
2579 sizeof (struct field
));
2580 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2586 /* Read a definition of an enumeration type,
2587 and create and return a suitable type object.
2588 Also defines the symbols that represent the values of the type. */
2591 read_enum_type (pp
, type
)
2593 register struct type
*type
;
2598 register struct symbol
*sym
;
2600 struct pending
**symlist
;
2601 struct pending
*osyms
, *syms
;
2604 if (within_function
)
2605 symlist
= &local_symbols
;
2607 symlist
= &file_symbols
;
2609 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2611 /* Read the value-names and their values.
2612 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2613 A semicolon or comman instead of a NAME means the end. */
2614 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2616 /* Check for and handle cretinous dbx symbol name continuation! */
2617 if (**pp
== '\\') *pp
= next_symbol_text ();
2620 while (*p
!= ':') p
++;
2621 name
= obsavestring (*pp
, p
- *pp
);
2623 n
= read_number (pp
, ',');
2625 sym
= (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2626 bzero (sym
, sizeof (struct symbol
));
2627 SYMBOL_NAME (sym
) = name
;
2628 SYMBOL_CLASS (sym
) = LOC_CONST
;
2629 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2630 SYMBOL_VALUE (sym
) = n
;
2631 add_symbol_to_list (sym
, symlist
);
2636 (*pp
)++; /* Skip the semicolon. */
2638 /* Now fill in the fields of the type-structure. */
2640 TYPE_LENGTH (type
) = sizeof (int);
2641 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2642 TYPE_NFIELDS (type
) = nsyms
;
2643 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2645 /* Find the symbols for the values and put them into the type.
2646 The symbols can be found in the symlist that we put them on
2647 to cause them to be defined. osyms contains the old value
2648 of that symlist; everything up to there was defined by us. */
2649 /* Note that we preserve the order of the enum constants, so
2650 that in something like "enum {FOO, LAST_THING=FOO}" we print
2651 FOO, not LAST_THING. */
2653 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2658 for (; j
< syms
->nsyms
; j
++,n
++)
2660 struct symbol
*xsym
= syms
->symbol
[j
];
2661 SYMBOL_TYPE (xsym
) = type
;
2662 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2663 TYPE_FIELD_VALUE (type
, n
) = 0;
2664 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2665 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2672 /* This screws up perfectly good C programs with enums. FIXME. */
2673 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2674 if(TYPE_NFIELDS(type
) == 2 &&
2675 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2676 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2677 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2678 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2679 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2685 /* Read a number from the string pointed to by *PP.
2686 The value of *PP is advanced over the number.
2687 If END is nonzero, the character that ends the
2688 number must match END, or an error happens;
2689 and that character is skipped if it does match.
2690 If END is zero, *PP is left pointing to that character.
2692 If the number fits in a long, set *VALUE and set *BITS to 0.
2693 If not, set *BITS to be the number of bits in the number.
2695 If encounter garbage, set *BITS to -1. */
2698 read_huge_number (pp
, end
, valu
, bits
)
2719 /* Leading zero means octal. GCC uses this to output values larger
2720 than an int (because that would be hard in decimal). */
2727 upper_limit
= LONG_MAX
/ radix
;
2728 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2730 if (n
<= upper_limit
)
2733 n
+= c
- '0'; /* FIXME this overflows anyway */
2738 /* This depends on large values being output in octal, which is
2745 /* Ignore leading zeroes. */
2749 else if (c
== '2' || c
== '3')
2775 /* Large decimal constants are an error (because it is hard to
2776 count how many bits are in them). */
2782 /* -0x7f is the same as 0x80. So deal with it by adding one to
2783 the number of bits. */
2798 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2799 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
2802 read_range_type (pp
, typenums
)
2810 struct type
*result_type
;
2812 /* First comes a type we are a subrange of.
2813 In C it is usually 0, 1 or the type being defined. */
2814 read_type_number (pp
, rangenums
);
2815 self_subrange
= (rangenums
[0] == typenums
[0] &&
2816 rangenums
[1] == typenums
[1]);
2818 /* A semicolon should now follow; skip it. */
2822 /* The remaining two operands are usually lower and upper bounds
2823 of the range. But in some special cases they mean something else. */
2824 read_huge_number (pp
, ';', &n2
, &n2bits
);
2825 read_huge_number (pp
, ';', &n3
, &n3bits
);
2827 if (n2bits
== -1 || n3bits
== -1)
2828 return error_type (pp
);
2830 /* If limits are huge, must be large integral type. */
2831 if (n2bits
!= 0 || n3bits
!= 0)
2833 char got_signed
= 0;
2834 char got_unsigned
= 0;
2835 /* Number of bits in the type. */
2838 /* Range from 0 to <large number> is an unsigned large integral type. */
2839 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2844 /* Range from <large number> to <large number>-1 is a large signed
2846 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2852 /* Check for "long long". */
2853 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2854 return builtin_type_long_long
;
2855 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2856 return builtin_type_unsigned_long_long
;
2858 if (got_signed
|| got_unsigned
)
2860 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2861 sizeof (struct type
));
2862 bzero (result_type
, sizeof (struct type
));
2863 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2864 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2866 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2870 return error_type (pp
);
2873 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2874 if (self_subrange
&& n2
== 0 && n3
== 0)
2875 return builtin_type_void
;
2877 /* If n3 is zero and n2 is not, we want a floating type,
2878 and n2 is the width in bytes.
2880 Fortran programs appear to use this for complex types also,
2881 and they give no way to distinguish between double and single-complex!
2882 We don't have complex types, so we would lose on all fortran files!
2883 So return type `double' for all of those. It won't work right
2884 for the complex values, but at least it makes the file loadable. */
2886 if (n3
== 0 && n2
> 0)
2888 if (n2
== sizeof (float))
2889 return builtin_type_float
;
2890 return builtin_type_double
;
2893 /* If the upper bound is -1, it must really be an unsigned int. */
2895 else if (n2
== 0 && n3
== -1)
2897 /* FIXME -- this confuses host and target type sizes. */
2898 if (sizeof (int) == sizeof (long))
2899 return builtin_type_unsigned_int
;
2901 return builtin_type_unsigned_long
;
2904 /* Special case: char is defined (Who knows why) as a subrange of
2905 itself with range 0-127. */
2906 else if (self_subrange
&& n2
== 0 && n3
== 127)
2907 return builtin_type_char
;
2909 /* Assumptions made here: Subrange of self is equivalent to subrange
2910 of int. FIXME: Host and target type-sizes assumed the same. */
2912 && (self_subrange
||
2913 *dbx_lookup_type (rangenums
) == builtin_type_int
))
2915 /* an unsigned type */
2917 if (n3
== - sizeof (long long))
2918 return builtin_type_unsigned_long_long
;
2920 if (n3
== (unsigned int)~0L)
2921 return builtin_type_unsigned_int
;
2922 if (n3
== (unsigned long)~0L)
2923 return builtin_type_unsigned_long
;
2924 if (n3
== (unsigned short)~0L)
2925 return builtin_type_unsigned_short
;
2926 if (n3
== (unsigned char)~0L)
2927 return builtin_type_unsigned_char
;
2930 else if (n3
== 0 && n2
== -sizeof (long long))
2931 return builtin_type_long_long
;
2933 else if (n2
== -n3
-1)
2936 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
2937 return builtin_type_int
;
2938 if (n3
== (1 << (8 * sizeof (long) - 1)) - 1)
2939 return builtin_type_long
;
2940 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
2941 return builtin_type_short
;
2942 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
2943 return builtin_type_char
;
2946 /* We have a real range type on our hands. Allocate space and
2947 return a real pointer. */
2949 /* At this point I don't have the faintest idea how to deal with
2950 a self_subrange type; I'm going to assume that this is used
2951 as an idiom, and that all of them are special cases. So . . . */
2953 return error_type (pp
);
2955 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2956 sizeof (struct type
));
2957 bzero (result_type
, sizeof (struct type
));
2959 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
2961 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
2962 if (TYPE_TARGET_TYPE (result_type
) == 0) {
2963 complain (&range_type_base_complaint
, rangenums
[1]);
2964 TYPE_TARGET_TYPE (result_type
) = builtin_type_int
;
2967 TYPE_NFIELDS (result_type
) = 2;
2968 TYPE_FIELDS (result_type
) =
2969 (struct field
*) obstack_alloc (symbol_obstack
,
2970 2 * sizeof (struct field
));
2971 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
2972 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
2973 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
2976 /* Note that TYPE_LENGTH (result_type) is just overridden a few
2977 statements down. What do we really need here? */
2978 /* We have to figure out how many bytes it takes to hold this
2979 range type. I'm going to assume that anything that is pushing
2980 the bounds of a long was taken care of above. */
2981 if (n2
>= MIN_OF_C_TYPE(char) && n3
<= MAX_OF_C_TYPE(char))
2982 TYPE_LENGTH (result_type
) = 1;
2983 else if (n2
>= MIN_OF_C_TYPE(short) && n3
<= MAX_OF_C_TYPE(short))
2984 TYPE_LENGTH (result_type
) = sizeof (short);
2985 else if (n2
>= MIN_OF_C_TYPE(int) && n3
<= MAX_OF_C_TYPE(int))
2986 TYPE_LENGTH (result_type
) = sizeof (int);
2987 else if (n2
>= MIN_OF_C_TYPE(long) && n3
<= MAX_OF_C_TYPE(long))
2988 TYPE_LENGTH (result_type
) = sizeof (long);
2990 /* Ranged type doesn't fit within known sizes. */
2991 /* FIXME -- use "long long" here. */
2992 return error_type (pp
);
2995 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
3000 /* Read a number from the string pointed to by *PP.
3001 The value of *PP is advanced over the number.
3002 If END is nonzero, the character that ends the
3003 number must match END, or an error happens;
3004 and that character is skipped if it does match.
3005 If END is zero, *PP is left pointing to that character. */
3008 read_number (pp
, end
)
3012 register char *p
= *pp
;
3013 register long n
= 0;
3017 /* Handle an optional leading minus sign. */
3025 /* Read the digits, as far as they go. */
3027 while ((c
= *p
++) >= '0' && c
<= '9')
3035 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3044 /* Read in an argument list. This is a list of types, separated by commas
3045 and terminated with END. Return the list of types read in, or (struct type
3046 **)-1 if there is an error. */
3052 /* FIXME! Remove this arbitrary limit! */
3053 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3059 /* Invalid argument list: no ','. */
3060 return (struct type
**)-1;
3063 /* Check for and handle cretinous dbx symbol name continuation! */
3065 *pp
= next_symbol_text ();
3067 types
[n
++] = read_type (pp
);
3069 *pp
+= 1; /* get past `end' (the ':' character) */
3073 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3075 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3077 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3078 bzero (rval
+ n
, sizeof (struct type
*));
3082 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3084 bcopy (types
, rval
, n
* sizeof (struct type
*));
3088 /* Add a common block's start address to the offset of each symbol
3089 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3090 the common block name). */
3093 fix_common_block (sym
, valu
)
3097 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3098 for ( ; next
; next
= next
->next
)
3101 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3102 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3106 /* Initializer for this module */
3108 _initialize_buildsym ()
3110 undef_types_allocated
= 20;
3111 undef_types_length
= 0;
3112 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
3113 sizeof (struct type
*));