1 /* Support routines for decoding "stabs" debugging information format.
3 Copyright (C) 1986-2024 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 3 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, see <http://www.gnu.org/licenses/>. */
20 /* Support routines for reading and decoding debugging information in
21 the "stabs" format. This format is used by some systems that use
22 COFF or ELF where the stabs data is placed in a special section (as
23 well as with many old systems that used the a.out object file
24 format). Avoid placing any object file format specific code in
28 #include "event-top.h"
29 #include "gdbsupport/gdb_obstack.h"
32 #include "expression.h"
35 #include "aout/stab_gnu.h"
37 #include "aout/aout64.h"
38 #include "gdb-stabs.h"
39 #include "buildsym-legacy.h"
40 #include "complaints.h"
42 #include "gdb-demangle.h"
44 #include "target-float.h"
47 #include "cp-support.h"
50 #include "stabsread.h"
52 /* See stabsread.h for these globals. */
54 const char *(*next_symbol_text_func
) (struct objfile
*);
55 unsigned char processing_gcc_compilation
;
57 struct symbol
*global_sym_chain
[HASHSIZE
];
58 struct pending_stabs
*global_stabs
;
59 int previous_stab_code
;
60 int *this_object_header_files
;
61 int n_this_object_header_files
;
62 int n_allocated_this_object_header_files
;
64 struct stabs_nextfield
66 struct stabs_nextfield
*next
;
71 struct next_fnfieldlist
73 struct next_fnfieldlist
*next
;
74 struct fn_fieldlist fn_fieldlist
;
77 /* The routines that read and process a complete stabs for a C struct or
78 C++ class pass lists of data member fields and lists of member function
79 fields in an instance of a field_info structure, as defined below.
80 This is part of some reorganization of low level C++ support and is
81 expected to eventually go away... (FIXME) */
83 struct stab_field_info
85 struct stabs_nextfield
*list
= nullptr;
86 struct next_fnfieldlist
*fnlist
= nullptr;
92 read_one_struct_field (struct stab_field_info
*, const char **, const char *,
93 struct type
*, struct objfile
*);
95 static struct type
*dbx_alloc_type (int[2], struct objfile
*);
97 static long read_huge_number (const char **, int, int *, int);
99 static struct type
*error_type (const char **, struct objfile
*);
102 patch_block_stabs (struct pending
*, struct pending_stabs
*,
105 static int read_type_number (const char **, int *);
107 static struct type
*read_type (const char **, struct objfile
*);
109 static struct type
*read_range_type (const char **, int[2],
110 int, struct objfile
*);
112 static struct type
*read_sun_builtin_type (const char **,
113 int[2], struct objfile
*);
115 static struct type
*read_sun_floating_type (const char **, int[2],
118 static struct type
*read_enum_type (const char **, struct type
*, struct objfile
*);
120 static struct type
*rs6000_builtin_type (int, struct objfile
*);
123 read_member_functions (struct stab_field_info
*, const char **, struct type
*,
127 read_struct_fields (struct stab_field_info
*, const char **, struct type
*,
131 read_baseclasses (struct stab_field_info
*, const char **, struct type
*,
135 read_tilde_fields (struct stab_field_info
*, const char **, struct type
*,
138 static int attach_fn_fields_to_type (struct stab_field_info
*, struct type
*);
140 static int attach_fields_to_type (struct stab_field_info
*, struct type
*,
143 static struct type
*read_struct_type (const char **, struct type
*,
147 static struct type
*read_array_type (const char **, struct type
*,
150 static struct field
*read_args (const char **, int, struct objfile
*,
153 static void add_undefined_type (struct type
*, int[2]);
156 read_cpp_abbrev (struct stab_field_info
*, const char **, struct type
*,
159 static const char *find_name_end (const char *name
);
161 static int process_reference (const char **string
);
163 void stabsread_clear_cache (void);
165 static const char vptr_name
[] = "_vptr$";
166 static const char vb_name
[] = "_vb$";
169 invalid_cpp_abbrev_complaint (const char *arg1
)
171 complaint (_("invalid C++ abbreviation `%s'"), arg1
);
175 reg_value_complaint (int regnum
, int num_regs
, const char *sym
)
177 complaint (_("bad register number %d (max %d) in symbol %s"),
178 regnum
, num_regs
- 1, sym
);
182 stabs_general_complaint (const char *arg1
)
184 complaint ("%s", arg1
);
187 /* Make a list of forward references which haven't been defined. */
189 static struct type
**undef_types
;
190 static int undef_types_allocated
;
191 static int undef_types_length
;
192 static struct symbol
*current_symbol
= NULL
;
194 /* Make a list of nameless types that are undefined.
195 This happens when another type is referenced by its number
196 before this type is actually defined. For instance "t(0,1)=k(0,2)"
197 and type (0,2) is defined only later. */
204 static struct nat
*noname_undefs
;
205 static int noname_undefs_allocated
;
206 static int noname_undefs_length
;
208 /* Check for and handle cretinous stabs symbol name continuation! */
209 #define STABS_CONTINUE(pp,objfile) \
211 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
212 *(pp) = next_symbol_text (objfile); \
215 /* Vector of types defined so far, indexed by their type numbers.
216 (In newer sun systems, dbx uses a pair of numbers in parens,
217 as in "(SUBFILENUM,NUMWITHINSUBFILE)".
218 Then these numbers must be translated through the type_translations
219 hash table to get the index into the type vector.) */
221 static struct type
**type_vector
;
223 /* Number of elements allocated for type_vector currently. */
225 static int type_vector_length
;
227 /* Initial size of type vector. Is realloc'd larger if needed, and
228 realloc'd down to the size actually used, when completed. */
230 #define INITIAL_TYPE_VECTOR_LENGTH 160
233 /* Look up a dbx type-number pair. Return the address of the slot
234 where the type for that number-pair is stored.
235 The number-pair is in TYPENUMS.
237 This can be used for finding the type associated with that pair
238 or for associating a new type with the pair. */
240 static struct type
**
241 dbx_lookup_type (int typenums
[2], struct objfile
*objfile
)
243 int filenum
= typenums
[0];
244 int index
= typenums
[1];
247 struct header_file
*f
;
250 if (filenum
== -1) /* -1,-1 is for temporary types. */
253 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
255 complaint (_("Invalid symbol data: type number "
256 "(%d,%d) out of range at symtab pos %d."),
257 filenum
, index
, symnum
);
265 /* Caller wants address of address of type. We think
266 that negative (rs6k builtin) types will never appear as
267 "lvalues", (nor should they), so we stuff the real type
268 pointer into a temp, and return its address. If referenced,
269 this will do the right thing. */
270 static struct type
*temp_type
;
272 temp_type
= rs6000_builtin_type (index
, objfile
);
276 /* Type is defined outside of header files.
277 Find it in this object file's type vector. */
278 if (index
>= type_vector_length
)
280 old_len
= type_vector_length
;
283 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
284 type_vector
= XNEWVEC (struct type
*, type_vector_length
);
286 while (index
>= type_vector_length
)
288 type_vector_length
*= 2;
290 type_vector
= (struct type
**)
291 xrealloc ((char *) type_vector
,
292 (type_vector_length
* sizeof (struct type
*)));
293 memset (&type_vector
[old_len
], 0,
294 (type_vector_length
- old_len
) * sizeof (struct type
*));
296 return (&type_vector
[index
]);
300 real_filenum
= this_object_header_files
[filenum
];
302 if (real_filenum
>= N_HEADER_FILES (objfile
))
304 static struct type
*temp_type
;
306 warning (_("GDB internal error: bad real_filenum"));
309 temp_type
= builtin_type (objfile
)->builtin_error
;
313 f
= HEADER_FILES (objfile
) + real_filenum
;
315 f_orig_length
= f
->length
;
316 if (index
>= f_orig_length
)
318 while (index
>= f
->length
)
322 f
->vector
= (struct type
**)
323 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
324 memset (&f
->vector
[f_orig_length
], 0,
325 (f
->length
- f_orig_length
) * sizeof (struct type
*));
327 return (&f
->vector
[index
]);
331 /* Make sure there is a type allocated for type numbers TYPENUMS
332 and return the type object.
333 This can create an empty (zeroed) type object.
334 TYPENUMS may be (-1, -1) to return a new type object that is not
335 put into the type vector, and so may not be referred to by number. */
338 dbx_alloc_type (int typenums
[2], struct objfile
*objfile
)
340 struct type
**type_addr
;
342 if (typenums
[0] == -1)
344 return type_allocator (objfile
,
345 get_current_subfile ()->language
).new_type ();
348 type_addr
= dbx_lookup_type (typenums
, objfile
);
350 /* If we are referring to a type not known at all yet,
351 allocate an empty type for it.
352 We will fill it in later if we find out how. */
355 *type_addr
= type_allocator (objfile
,
356 get_current_subfile ()->language
).new_type ();
362 /* Allocate a floating-point type of size BITS. */
365 dbx_init_float_type (struct objfile
*objfile
, int bits
)
367 struct gdbarch
*gdbarch
= objfile
->arch ();
368 const struct floatformat
**format
;
371 format
= gdbarch_floatformat_for_type (gdbarch
, NULL
, bits
);
372 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
374 type
= init_float_type (alloc
, bits
, NULL
, format
);
376 type
= alloc
.new_type (TYPE_CODE_ERROR
, bits
, NULL
);
381 /* for all the stabs in a given stab vector, build appropriate types
382 and fix their symbols in given symbol vector. */
385 patch_block_stabs (struct pending
*symbols
, struct pending_stabs
*stabs
,
386 struct objfile
*objfile
)
395 /* for all the stab entries, find their corresponding symbols and
396 patch their types! */
398 for (ii
= 0; ii
< stabs
->count
; ++ii
)
400 name
= stabs
->stab
[ii
];
401 pp
= (char *) strchr (name
, ':');
402 gdb_assert (pp
); /* Must find a ':' or game's over. */
406 pp
= (char *) strchr (pp
, ':');
408 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
411 /* FIXME-maybe: it would be nice if we noticed whether
412 the variable was defined *anywhere*, not just whether
413 it is defined in this compilation unit. But neither
414 xlc or GCC seem to need such a definition, and until
415 we do psymtabs (so that the minimal symbols from all
416 compilation units are available now), I'm not sure
417 how to get the information. */
419 /* On xcoff, if a global is defined and never referenced,
420 ld will remove it from the executable. There is then
421 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
422 sym
= new (&objfile
->objfile_obstack
) symbol
;
423 sym
->set_domain (VAR_DOMAIN
);
424 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
425 sym
->set_linkage_name
426 (obstack_strndup (&objfile
->objfile_obstack
, name
, pp
- name
));
428 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
430 /* I don't think the linker does this with functions,
431 so as far as I know this is never executed.
432 But it doesn't hurt to check. */
434 (lookup_function_type (read_type (&pp
, objfile
)));
438 sym
->set_type (read_type (&pp
, objfile
));
440 add_symbol_to_list (sym
, get_global_symbols ());
445 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
448 (lookup_function_type (read_type (&pp
, objfile
)));
452 sym
->set_type (read_type (&pp
, objfile
));
460 /* Read a number by which a type is referred to in dbx data,
461 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
462 Just a single number N is equivalent to (0,N).
463 Return the two numbers by storing them in the vector TYPENUMS.
464 TYPENUMS will then be used as an argument to dbx_lookup_type.
466 Returns 0 for success, -1 for error. */
469 read_type_number (const char **pp
, int *typenums
)
476 typenums
[0] = read_huge_number (pp
, ',', &nbits
, 0);
479 typenums
[1] = read_huge_number (pp
, ')', &nbits
, 0);
486 typenums
[1] = read_huge_number (pp
, 0, &nbits
, 0);
494 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
495 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
496 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
497 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
499 /* Structure for storing pointers to reference definitions for fast lookup
500 during "process_later". */
509 #define MAX_CHUNK_REFS 100
510 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
511 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
513 static struct ref_map
*ref_map
;
515 /* Ptr to free cell in chunk's linked list. */
516 static int ref_count
= 0;
518 /* Number of chunks malloced. */
519 static int ref_chunk
= 0;
521 /* This file maintains a cache of stabs aliases found in the symbol
522 table. If the symbol table changes, this cache must be cleared
523 or we are left holding onto data in invalid obstacks. */
525 stabsread_clear_cache (void)
531 /* Create array of pointers mapping refids to symbols and stab strings.
532 Add pointers to reference definition symbols and/or their values as we
533 find them, using their reference numbers as our index.
534 These will be used later when we resolve references. */
536 ref_add (int refnum
, struct symbol
*sym
, const char *stabs
, CORE_ADDR value
)
540 if (refnum
>= ref_count
)
541 ref_count
= refnum
+ 1;
542 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
544 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
545 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
547 ref_map
= (struct ref_map
*)
548 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
549 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0,
550 new_chunks
* REF_CHUNK_SIZE
);
551 ref_chunk
+= new_chunks
;
553 ref_map
[refnum
].stabs
= stabs
;
554 ref_map
[refnum
].sym
= sym
;
555 ref_map
[refnum
].value
= value
;
558 /* Return defined sym for the reference REFNUM. */
560 ref_search (int refnum
)
562 if (refnum
< 0 || refnum
> ref_count
)
564 return ref_map
[refnum
].sym
;
567 /* Parse a reference id in STRING and return the resulting
568 reference number. Move STRING beyond the reference id. */
571 process_reference (const char **string
)
579 /* Advance beyond the initial '#'. */
582 /* Read number as reference id. */
583 while (*p
&& isdigit (*p
))
585 refnum
= refnum
* 10 + *p
- '0';
592 /* If STRING defines a reference, store away a pointer to the reference
593 definition for later use. Return the reference number. */
596 symbol_reference_defined (const char **string
)
598 const char *p
= *string
;
601 refnum
= process_reference (&p
);
603 /* Defining symbols end in '='. */
606 /* Symbol is being defined here. */
612 /* Must be a reference. Either the symbol has already been defined,
613 or this is a forward reference to it. */
620 stab_reg_to_regnum (struct symbol
*sym
, struct gdbarch
*gdbarch
)
622 int regno
= gdbarch_stab_reg_to_regnum (gdbarch
, sym
->value_longest ());
624 if (regno
< 0 || regno
>= gdbarch_num_cooked_regs (gdbarch
))
626 reg_value_complaint (regno
, gdbarch_num_cooked_regs (gdbarch
),
629 regno
= gdbarch_sp_regnum (gdbarch
); /* Known safe, though useless. */
635 static const struct symbol_register_ops stab_register_funcs
= {
639 /* The "aclass" indices for computed symbols. */
641 static int stab_register_index
;
642 static int stab_regparm_index
;
645 define_symbol (CORE_ADDR valu
, const char *string
, int desc
, int type
,
646 struct objfile
*objfile
)
648 struct gdbarch
*gdbarch
= objfile
->arch ();
650 const char *p
= find_name_end (string
);
655 /* We would like to eliminate nameless symbols, but keep their types.
656 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
657 to type 2, but, should not create a symbol to address that type. Since
658 the symbol will be nameless, there is no way any user can refer to it. */
662 /* Ignore syms with empty names. */
666 /* Ignore old-style symbols from cc -go. */
677 _("Bad stabs string '%s'"), string
);
682 /* If a nameless stab entry, all we need is the type, not the symbol.
683 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
684 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
686 current_symbol
= sym
= new (&objfile
->objfile_obstack
) symbol
;
688 if (processing_gcc_compilation
)
690 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
691 number of bytes occupied by a type or object, which we ignore. */
692 sym
->set_line (desc
);
696 sym
->set_line (0); /* unknown */
699 sym
->set_language (get_current_subfile ()->language
,
700 &objfile
->objfile_obstack
);
702 if (is_cplus_marker (string
[0]))
704 /* Special GNU C++ names. */
708 sym
->set_linkage_name ("this");
711 case 'v': /* $vtbl_ptr_type */
715 sym
->set_linkage_name ("eh_throw");
719 /* This was an anonymous type that was never fixed up. */
723 complaint (_("Unknown C++ symbol name `%s'"),
725 goto normal
; /* Do *something* with it. */
731 gdb::unique_xmalloc_ptr
<char> new_name
;
733 if (sym
->language () == language_cplus
)
735 std::string
name (string
, p
- string
);
736 new_name
= cp_canonicalize_string (name
.c_str ());
738 else if (sym
->language () == language_c
)
740 std::string
name (string
, p
- string
);
741 new_name
= c_canonicalize_name (name
.c_str ());
743 if (new_name
!= nullptr)
744 sym
->compute_and_set_names (new_name
.get (), true, objfile
->per_bfd
);
746 sym
->compute_and_set_names (std::string_view (string
, p
- string
), true,
749 if (sym
->language () == language_cplus
)
750 cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym
,
756 /* Determine the type of name being defined. */
758 /* Getting GDB to correctly skip the symbol on an undefined symbol
759 descriptor and not ever dump core is a very dodgy proposition if
760 we do things this way. I say the acorn RISC machine can just
761 fix their compiler. */
762 /* The Acorn RISC machine's compiler can put out locals that don't
763 start with "234=" or "(3,4)=", so assume anything other than the
764 deftypes we know how to handle is a local. */
765 if (!strchr ("cfFGpPrStTvVXCR", *p
))
767 if (isdigit (*p
) || *p
== '(' || *p
== '-')
776 /* c is a special case, not followed by a type-number.
777 SYMBOL:c=iVALUE for an integer constant symbol.
778 SYMBOL:c=rVALUE for a floating constant symbol.
779 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
780 e.g. "b:c=e6,0" for "const b = blob1"
781 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
784 sym
->set_aclass_index (LOC_CONST
);
785 sym
->set_type (error_type (&p
, objfile
));
786 sym
->set_domain (VAR_DOMAIN
);
787 add_symbol_to_list (sym
, get_file_symbols ());
796 struct type
*dbl_type
;
798 dbl_type
= builtin_type (objfile
)->builtin_double
;
800 = (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
,
801 dbl_type
->length ());
803 target_float_from_string (dbl_valu
, dbl_type
, std::string (p
));
805 sym
->set_type (dbl_type
);
806 sym
->set_value_bytes (dbl_valu
);
807 sym
->set_aclass_index (LOC_CONST_BYTES
);
812 /* Defining integer constants this way is kind of silly,
813 since 'e' constants allows the compiler to give not
814 only the value, but the type as well. C has at least
815 int, long, unsigned int, and long long as constant
816 types; other languages probably should have at least
817 unsigned as well as signed constants. */
819 sym
->set_type (builtin_type (objfile
)->builtin_long
);
820 sym
->set_value_longest (atoi (p
));
821 sym
->set_aclass_index (LOC_CONST
);
827 sym
->set_type (builtin_type (objfile
)->builtin_char
);
828 sym
->set_value_longest (atoi (p
));
829 sym
->set_aclass_index (LOC_CONST
);
835 struct type
*range_type
;
838 gdb_byte
*string_local
= (gdb_byte
*) alloca (strlen (p
));
839 gdb_byte
*string_value
;
841 if (quote
!= '\'' && quote
!= '"')
843 sym
->set_aclass_index (LOC_CONST
);
844 sym
->set_type (error_type (&p
, objfile
));
845 sym
->set_domain (VAR_DOMAIN
);
846 add_symbol_to_list (sym
, get_file_symbols ());
850 /* Find matching quote, rejecting escaped quotes. */
851 while (*p
&& *p
!= quote
)
853 if (*p
== '\\' && p
[1] == quote
)
855 string_local
[ind
] = (gdb_byte
) quote
;
861 string_local
[ind
] = (gdb_byte
) (*p
);
868 sym
->set_aclass_index (LOC_CONST
);
869 sym
->set_type (error_type (&p
, objfile
));
870 sym
->set_domain (VAR_DOMAIN
);
871 add_symbol_to_list (sym
, get_file_symbols ());
875 /* NULL terminate the string. */
876 string_local
[ind
] = 0;
877 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
879 = create_static_range_type (alloc
,
880 builtin_type (objfile
)->builtin_int
,
883 (create_array_type (alloc
, builtin_type (objfile
)->builtin_char
,
886 = (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, ind
+ 1);
887 memcpy (string_value
, string_local
, ind
+ 1);
890 sym
->set_value_bytes (string_value
);
891 sym
->set_aclass_index (LOC_CONST_BYTES
);
896 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
897 can be represented as integral.
898 e.g. "b:c=e6,0" for "const b = blob1"
899 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
901 sym
->set_aclass_index (LOC_CONST
);
902 sym
->set_type (read_type (&p
, objfile
));
906 sym
->set_type (error_type (&p
, objfile
));
911 /* If the value is too big to fit in an int (perhaps because
912 it is unsigned), or something like that, we silently get
913 a bogus value. The type and everything else about it is
914 correct. Ideally, we should be using whatever we have
915 available for parsing unsigned and long long values,
917 sym
->set_value_longest (atoi (p
));
922 sym
->set_aclass_index (LOC_CONST
);
923 sym
->set_type (error_type (&p
, objfile
));
926 sym
->set_domain (VAR_DOMAIN
);
927 add_symbol_to_list (sym
, get_file_symbols ());
931 /* The name of a caught exception. */
932 sym
->set_type (read_type (&p
, objfile
));
933 sym
->set_aclass_index (LOC_LABEL
);
934 sym
->set_domain (VAR_DOMAIN
);
935 sym
->set_value_address (valu
);
936 add_symbol_to_list (sym
, get_local_symbols ());
940 /* A static function definition. */
941 sym
->set_type (read_type (&p
, objfile
));
942 sym
->set_aclass_index (LOC_BLOCK
);
943 sym
->set_domain (FUNCTION_DOMAIN
);
944 add_symbol_to_list (sym
, get_file_symbols ());
945 /* fall into process_function_types. */
947 process_function_types
:
948 /* Function result types are described as the result type in stabs.
949 We need to convert this to the function-returning-type-X type
950 in GDB. E.g. "int" is converted to "function returning int". */
951 if (sym
->type ()->code () != TYPE_CODE_FUNC
)
952 sym
->set_type (lookup_function_type (sym
->type ()));
954 /* All functions in C++ have prototypes. Stabs does not offer an
955 explicit way to identify prototyped or unprototyped functions,
956 but both GCC and Sun CC emit stabs for the "call-as" type rather
957 than the "declared-as" type for unprototyped functions, so
958 we treat all functions as if they were prototyped. This is used
959 primarily for promotion when calling the function from GDB. */
960 sym
->type ()->set_is_prototyped (true);
962 /* fall into process_prototype_types. */
964 process_prototype_types
:
965 /* Sun acc puts declared types of arguments here. */
968 struct type
*ftype
= sym
->type ();
973 /* Obtain a worst case guess for the number of arguments
974 by counting the semicolons. */
981 /* Allocate parameter information fields and fill them in. */
982 ftype
->alloc_fields (nsemi
);
987 /* A type number of zero indicates the start of varargs.
988 FIXME: GDB currently ignores vararg functions. */
989 if (p
[0] == '0' && p
[1] == '\0')
991 ptype
= read_type (&p
, objfile
);
993 /* The Sun compilers mark integer arguments, which should
994 be promoted to the width of the calling conventions, with
995 a type which references itself. This type is turned into
996 a TYPE_CODE_VOID type by read_type, and we have to turn
997 it back into builtin_int here.
998 FIXME: Do we need a new builtin_promoted_int_arg ? */
999 if (ptype
->code () == TYPE_CODE_VOID
)
1000 ptype
= builtin_type (objfile
)->builtin_int
;
1001 ftype
->field (nparams
).set_type (ptype
);
1002 ftype
->field (nparams
).set_is_artificial (false);
1005 ftype
->set_num_fields (nparams
);
1006 ftype
->set_is_prototyped (true);
1011 /* A global function definition. */
1012 sym
->set_type (read_type (&p
, objfile
));
1013 sym
->set_aclass_index (LOC_BLOCK
);
1014 sym
->set_domain (FUNCTION_DOMAIN
);
1015 add_symbol_to_list (sym
, get_global_symbols ());
1016 goto process_function_types
;
1019 /* For a class G (global) symbol, it appears that the
1020 value is not correct. It is necessary to search for the
1021 corresponding linker definition to find the value.
1022 These definitions appear at the end of the namelist. */
1023 sym
->set_type (read_type (&p
, objfile
));
1024 sym
->set_aclass_index (LOC_STATIC
);
1025 sym
->set_domain (VAR_DOMAIN
);
1026 /* Don't add symbol references to global_sym_chain.
1027 Symbol references don't have valid names and wont't match up with
1028 minimal symbols when the global_sym_chain is relocated.
1029 We'll fixup symbol references when we fixup the defining symbol. */
1030 if (sym
->linkage_name () && sym
->linkage_name ()[0] != '#')
1032 i
= hashname (sym
->linkage_name ());
1033 sym
->set_value_chain (global_sym_chain
[i
]);
1034 global_sym_chain
[i
] = sym
;
1036 add_symbol_to_list (sym
, get_global_symbols ());
1039 /* This case is faked by a conditional above,
1040 when there is no code letter in the dbx data.
1041 Dbx data never actually contains 'l'. */
1044 sym
->set_type (read_type (&p
, objfile
));
1045 sym
->set_aclass_index (LOC_LOCAL
);
1046 sym
->set_value_longest (valu
);
1047 sym
->set_domain (VAR_DOMAIN
);
1048 add_symbol_to_list (sym
, get_local_symbols ());
1053 /* pF is a two-letter code that means a function parameter in Fortran.
1054 The type-number specifies the type of the return value.
1055 Translate it into a pointer-to-function type. */
1059 (lookup_pointer_type
1060 (lookup_function_type (read_type (&p
, objfile
))));
1063 sym
->set_type (read_type (&p
, objfile
));
1065 sym
->set_aclass_index (LOC_ARG
);
1066 sym
->set_value_longest (valu
);
1067 sym
->set_domain (VAR_DOMAIN
);
1068 sym
->set_is_argument (1);
1069 add_symbol_to_list (sym
, get_local_symbols ());
1071 if (gdbarch_byte_order (gdbarch
) != BFD_ENDIAN_BIG
)
1073 /* On little-endian machines, this crud is never necessary,
1074 and, if the extra bytes contain garbage, is harmful. */
1078 /* If it's gcc-compiled, if it says `short', believe it. */
1079 if (processing_gcc_compilation
1080 || gdbarch_believe_pcc_promotion (gdbarch
))
1083 if (!gdbarch_believe_pcc_promotion (gdbarch
))
1085 /* If PCC says a parameter is a short or a char, it is
1087 if (sym
->type ()->length ()
1088 < gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
1089 && sym
->type ()->code () == TYPE_CODE_INT
)
1092 (sym
->type ()->is_unsigned ()
1093 ? builtin_type (objfile
)->builtin_unsigned_int
1094 : builtin_type (objfile
)->builtin_int
);
1101 /* acc seems to use P to declare the prototypes of functions that
1102 are referenced by this file. gdb is not prepared to deal
1103 with this extra information. FIXME, it ought to. */
1106 sym
->set_type (read_type (&p
, objfile
));
1107 goto process_prototype_types
;
1112 /* Parameter which is in a register. */
1113 sym
->set_type (read_type (&p
, objfile
));
1114 sym
->set_aclass_index (stab_register_index
);
1115 sym
->set_is_argument (1);
1116 sym
->set_value_longest (valu
);
1117 sym
->set_domain (VAR_DOMAIN
);
1118 add_symbol_to_list (sym
, get_local_symbols ());
1122 /* Register variable (either global or local). */
1123 sym
->set_type (read_type (&p
, objfile
));
1124 sym
->set_aclass_index (stab_register_index
);
1125 sym
->set_value_longest (valu
);
1126 sym
->set_domain (VAR_DOMAIN
);
1127 if (within_function
)
1129 /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
1130 the same name to represent an argument passed in a
1131 register. GCC uses 'P' for the same case. So if we find
1132 such a symbol pair we combine it into one 'P' symbol.
1133 For Sun cc we need to do this regardless of stabs_argument_has_addr, because the compiler puts out
1134 the 'p' symbol even if it never saves the argument onto
1137 On most machines, we want to preserve both symbols, so
1138 that we can still get information about what is going on
1139 with the stack (VAX for computing args_printed, using
1140 stack slots instead of saved registers in backtraces,
1143 Note that this code illegally combines
1144 main(argc) struct foo argc; { register struct foo argc; }
1145 but this case is considered pathological and causes a warning
1146 from a decent compiler. */
1148 struct pending
*local_symbols
= *get_local_symbols ();
1150 && local_symbols
->nsyms
> 0
1151 && gdbarch_stabs_argument_has_addr (gdbarch
, sym
->type ()))
1153 struct symbol
*prev_sym
;
1155 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1156 if ((prev_sym
->aclass () == LOC_REF_ARG
1157 || prev_sym
->aclass () == LOC_ARG
)
1158 && strcmp (prev_sym
->linkage_name (),
1159 sym
->linkage_name ()) == 0)
1161 prev_sym
->set_aclass_index (stab_register_index
);
1162 /* Use the type from the LOC_REGISTER; that is the type
1163 that is actually in that register. */
1164 prev_sym
->set_type (sym
->type ());
1165 prev_sym
->set_value_longest (sym
->value_longest ());
1170 add_symbol_to_list (sym
, get_local_symbols ());
1173 add_symbol_to_list (sym
, get_file_symbols ());
1177 /* Static symbol at top level of file. */
1178 sym
->set_type (read_type (&p
, objfile
));
1179 sym
->set_aclass_index (LOC_STATIC
);
1180 sym
->set_value_address (valu
);
1181 sym
->set_domain (VAR_DOMAIN
);
1182 add_symbol_to_list (sym
, get_file_symbols ());
1186 /* In Ada, there is no distinction between typedef and non-typedef;
1187 any type declaration implicitly has the equivalent of a typedef,
1188 and thus 't' is in fact equivalent to 'Tt'.
1190 Therefore, for Ada units, we check the character immediately
1191 before the 't', and if we do not find a 'T', then make sure to
1192 create the associated symbol in the STRUCT_DOMAIN ('t' definitions
1193 will be stored in the VAR_DOMAIN). If the symbol was indeed
1194 defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
1195 elsewhere, so we don't need to take care of that.
1197 This is important to do, because of forward references:
1198 The cleanup of undefined types stored in undef_types only uses
1199 STRUCT_DOMAIN symbols to perform the replacement. */
1200 synonym
= (sym
->language () == language_ada
&& p
[-2] != 'T');
1203 sym
->set_type (read_type (&p
, objfile
));
1205 /* For a nameless type, we don't want a create a symbol, thus we
1206 did not use `sym'. Return without further processing. */
1210 sym
->set_aclass_index (LOC_TYPEDEF
);
1211 sym
->set_value_longest (valu
);
1212 sym
->set_domain (TYPE_DOMAIN
);
1213 /* C++ vagaries: we may have a type which is derived from
1214 a base type which did not have its name defined when the
1215 derived class was output. We fill in the derived class's
1216 base part member's name here in that case. */
1217 if (sym
->type ()->name () != NULL
)
1218 if ((sym
->type ()->code () == TYPE_CODE_STRUCT
1219 || sym
->type ()->code () == TYPE_CODE_UNION
)
1220 && TYPE_N_BASECLASSES (sym
->type ()))
1224 for (j
= TYPE_N_BASECLASSES (sym
->type ()) - 1; j
>= 0; j
--)
1225 if (TYPE_BASECLASS_NAME (sym
->type (), j
) == 0)
1226 sym
->type ()->field (j
).set_name
1227 (TYPE_BASECLASS (sym
->type (), j
)->name ());
1230 if (sym
->type ()->name () == NULL
)
1232 if ((sym
->type ()->code () == TYPE_CODE_PTR
1233 && strcmp (sym
->linkage_name (), vtbl_ptr_name
))
1234 || sym
->type ()->code () == TYPE_CODE_FUNC
)
1236 /* If we are giving a name to a type such as "pointer to
1237 foo" or "function returning foo", we better not set
1238 the TYPE_NAME. If the program contains "typedef char
1239 *caddr_t;", we don't want all variables of type char
1240 * to print as caddr_t. This is not just a
1241 consequence of GDB's type management; PCC and GCC (at
1242 least through version 2.4) both output variables of
1243 either type char * or caddr_t with the type number
1244 defined in the 't' symbol for caddr_t. If a future
1245 compiler cleans this up it GDB is not ready for it
1246 yet, but if it becomes ready we somehow need to
1247 disable this check (without breaking the PCC/GCC2.4
1252 Fortunately, this check seems not to be necessary
1253 for anything except pointers or functions. */
1254 /* ezannoni: 2000-10-26. This seems to apply for
1255 versions of gcc older than 2.8. This was the original
1256 problem: with the following code gdb would tell that
1257 the type for name1 is caddr_t, and func is char().
1259 typedef char *caddr_t;
1271 /* Pascal accepts names for pointer types. */
1272 if (get_current_subfile ()->language
== language_pascal
)
1273 sym
->type ()->set_name (sym
->linkage_name ());
1276 sym
->type ()->set_name (sym
->linkage_name ());
1279 add_symbol_to_list (sym
, get_file_symbols ());
1283 /* Create the STRUCT_DOMAIN clone. */
1284 struct symbol
*struct_sym
= new (&objfile
->objfile_obstack
) symbol
;
1287 struct_sym
->set_aclass_index (LOC_TYPEDEF
);
1288 struct_sym
->set_value_longest (valu
);
1289 struct_sym
->set_domain (STRUCT_DOMAIN
);
1290 if (sym
->type ()->name () == 0)
1291 sym
->type ()->set_name
1292 (obconcat (&objfile
->objfile_obstack
, sym
->linkage_name (),
1294 add_symbol_to_list (struct_sym
, get_file_symbols ());
1300 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1301 by 't' which means we are typedef'ing it as well. */
1302 synonym
= *p
== 't';
1307 sym
->set_type (read_type (&p
, objfile
));
1309 /* For a nameless type, we don't want a create a symbol, thus we
1310 did not use `sym'. Return without further processing. */
1314 sym
->set_aclass_index (LOC_TYPEDEF
);
1315 sym
->set_value_longest (valu
);
1316 sym
->set_domain (STRUCT_DOMAIN
);
1317 if (sym
->type ()->name () == 0)
1318 sym
->type ()->set_name
1319 (obconcat (&objfile
->objfile_obstack
, sym
->linkage_name (),
1321 add_symbol_to_list (sym
, get_file_symbols ());
1325 /* Clone the sym and then modify it. */
1326 struct symbol
*typedef_sym
= new (&objfile
->objfile_obstack
) symbol
;
1328 *typedef_sym
= *sym
;
1329 typedef_sym
->set_aclass_index (LOC_TYPEDEF
);
1330 typedef_sym
->set_value_longest (valu
);
1331 typedef_sym
->set_domain (TYPE_DOMAIN
);
1332 if (sym
->type ()->name () == 0)
1333 sym
->type ()->set_name
1334 (obconcat (&objfile
->objfile_obstack
, sym
->linkage_name (),
1336 add_symbol_to_list (typedef_sym
, get_file_symbols ());
1341 /* Static symbol of local scope. */
1342 sym
->set_type (read_type (&p
, objfile
));
1343 sym
->set_aclass_index (LOC_STATIC
);
1344 sym
->set_value_address (valu
);
1345 sym
->set_domain (VAR_DOMAIN
);
1346 add_symbol_to_list (sym
, get_local_symbols ());
1350 /* Reference parameter */
1351 sym
->set_type (read_type (&p
, objfile
));
1352 sym
->set_aclass_index (LOC_REF_ARG
);
1353 sym
->set_is_argument (1);
1354 sym
->set_value_longest (valu
);
1355 sym
->set_domain (VAR_DOMAIN
);
1356 add_symbol_to_list (sym
, get_local_symbols ());
1360 /* Reference parameter which is in a register. */
1361 sym
->set_type (read_type (&p
, objfile
));
1362 sym
->set_aclass_index (stab_regparm_index
);
1363 sym
->set_is_argument (1);
1364 sym
->set_value_longest (valu
);
1365 sym
->set_domain (VAR_DOMAIN
);
1366 add_symbol_to_list (sym
, get_local_symbols ());
1370 /* This is used by Sun FORTRAN for "function result value".
1371 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1372 that Pascal uses it too, but when I tried it Pascal used
1373 "x:3" (local symbol) instead. */
1374 sym
->set_type (read_type (&p
, objfile
));
1375 sym
->set_aclass_index (LOC_LOCAL
);
1376 sym
->set_value_longest (valu
);
1377 sym
->set_domain (VAR_DOMAIN
);
1378 add_symbol_to_list (sym
, get_local_symbols ());
1382 sym
->set_type (error_type (&p
, objfile
));
1383 sym
->set_aclass_index (LOC_CONST
);
1384 sym
->set_value_longest (0);
1385 sym
->set_domain (VAR_DOMAIN
);
1386 add_symbol_to_list (sym
, get_file_symbols ());
1390 /* Some systems pass variables of certain types by reference instead
1391 of by value, i.e. they will pass the address of a structure (in a
1392 register or on the stack) instead of the structure itself. */
1394 if (gdbarch_stabs_argument_has_addr (gdbarch
, sym
->type ())
1395 && sym
->is_argument ())
1397 /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
1398 variables passed in a register). */
1399 if (sym
->aclass () == LOC_REGISTER
)
1400 sym
->set_aclass_index (LOC_REGPARM_ADDR
);
1401 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
1402 and subsequent arguments on SPARC, for example). */
1403 else if (sym
->aclass () == LOC_ARG
)
1404 sym
->set_aclass_index (LOC_REF_ARG
);
1410 /* Skip rest of this symbol and return an error type.
1412 General notes on error recovery: error_type always skips to the
1413 end of the symbol (modulo cretinous dbx symbol name continuation).
1414 Thus code like this:
1416 if (*(*pp)++ != ';')
1417 return error_type (pp, objfile);
1419 is wrong because if *pp starts out pointing at '\0' (typically as the
1420 result of an earlier error), it will be incremented to point to the
1421 start of the next symbol, which might produce strange results, at least
1422 if you run off the end of the string table. Instead use
1425 return error_type (pp, objfile);
1431 foo = error_type (pp, objfile);
1435 And in case it isn't obvious, the point of all this hair is so the compiler
1436 can define new types and new syntaxes, and old versions of the
1437 debugger will be able to read the new symbol tables. */
1439 static struct type
*
1440 error_type (const char **pp
, struct objfile
*objfile
)
1442 complaint (_("couldn't parse type; debugger out of date?"));
1445 /* Skip to end of symbol. */
1446 while (**pp
!= '\0')
1451 /* Check for and handle cretinous dbx symbol name continuation! */
1452 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1454 *pp
= next_symbol_text (objfile
);
1461 return builtin_type (objfile
)->builtin_error
;
1465 /* Allocate a stub method whose return type is TYPE. This apparently
1466 happens for speed of symbol reading, since parsing out the
1467 arguments to the method is cpu-intensive, the way we are doing it.
1468 So, we will fill in arguments later. This always returns a fresh
1471 static struct type
*
1472 allocate_stub_method (struct type
*type
)
1476 mtype
= type_allocator (type
).new_type ();
1477 mtype
->set_code (TYPE_CODE_METHOD
);
1478 mtype
->set_length (1);
1479 mtype
->set_is_stub (true);
1480 mtype
->set_target_type (type
);
1481 /* TYPE_SELF_TYPE (mtype) = unknown yet */
1485 /* Read type information or a type definition; return the type. Even
1486 though this routine accepts either type information or a type
1487 definition, the distinction is relevant--some parts of stabsread.c
1488 assume that type information starts with a digit, '-', or '(' in
1489 deciding whether to call read_type. */
1491 static struct type
*
1492 read_type (const char **pp
, struct objfile
*objfile
)
1494 struct type
*type
= 0;
1497 char type_descriptor
;
1499 /* Size in bits of type if specified by a type attribute, or -1 if
1500 there is no size attribute. */
1503 /* Used to distinguish string and bitstring from char-array and set. */
1506 /* Used to distinguish vector from array. */
1509 /* Read type number if present. The type number may be omitted.
1510 for instance in a two-dimensional array declared with type
1511 "ar1;1;10;ar1;1;10;4". */
1512 if ((**pp
>= '0' && **pp
<= '9')
1516 if (read_type_number (pp
, typenums
) != 0)
1517 return error_type (pp
, objfile
);
1521 /* Type is not being defined here. Either it already
1522 exists, or this is a forward reference to it.
1523 dbx_alloc_type handles both cases. */
1524 type
= dbx_alloc_type (typenums
, objfile
);
1526 /* If this is a forward reference, arrange to complain if it
1527 doesn't get patched up by the time we're done
1529 if (type
->code () == TYPE_CODE_UNDEF
)
1530 add_undefined_type (type
, typenums
);
1535 /* Type is being defined here. */
1537 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1542 /* 'typenums=' not present, type is anonymous. Read and return
1543 the definition, but don't put it in the type vector. */
1544 typenums
[0] = typenums
[1] = -1;
1549 type_descriptor
= (*pp
)[-1];
1550 switch (type_descriptor
)
1554 enum type_code code
;
1556 /* Used to index through file_symbols. */
1557 struct pending
*ppt
;
1560 /* Name including "struct", etc. */
1564 const char *from
, *p
, *q1
, *q2
;
1566 /* Set the type code according to the following letter. */
1570 code
= TYPE_CODE_STRUCT
;
1573 code
= TYPE_CODE_UNION
;
1576 code
= TYPE_CODE_ENUM
;
1580 /* Complain and keep going, so compilers can invent new
1581 cross-reference types. */
1582 complaint (_("Unrecognized cross-reference type `%c'"),
1584 code
= TYPE_CODE_STRUCT
;
1589 q1
= strchr (*pp
, '<');
1590 p
= strchr (*pp
, ':');
1592 return error_type (pp
, objfile
);
1593 if (q1
&& p
> q1
&& p
[1] == ':')
1595 int nesting_level
= 0;
1597 for (q2
= q1
; *q2
; q2
++)
1601 else if (*q2
== '>')
1603 else if (*q2
== ':' && nesting_level
== 0)
1608 return error_type (pp
, objfile
);
1611 if (get_current_subfile ()->language
== language_cplus
)
1613 std::string
name (*pp
, p
- *pp
);
1614 gdb::unique_xmalloc_ptr
<char> new_name
1615 = cp_canonicalize_string (name
.c_str ());
1616 if (new_name
!= nullptr)
1617 type_name
= obstack_strdup (&objfile
->objfile_obstack
,
1620 else if (get_current_subfile ()->language
== language_c
)
1622 std::string
name (*pp
, p
- *pp
);
1623 gdb::unique_xmalloc_ptr
<char> new_name
1624 = c_canonicalize_name (name
.c_str ());
1625 if (new_name
!= nullptr)
1626 type_name
= obstack_strdup (&objfile
->objfile_obstack
,
1629 if (type_name
== NULL
)
1631 char *to
= type_name
= (char *)
1632 obstack_alloc (&objfile
->objfile_obstack
, p
- *pp
+ 1);
1634 /* Copy the name. */
1641 /* Set the pointer ahead of the name which we just read, and
1646 /* If this type has already been declared, then reuse the same
1647 type, rather than allocating a new one. This saves some
1650 for (ppt
= *get_file_symbols (); ppt
; ppt
= ppt
->next
)
1651 for (i
= 0; i
< ppt
->nsyms
; i
++)
1653 struct symbol
*sym
= ppt
->symbol
[i
];
1655 if (sym
->aclass () == LOC_TYPEDEF
1656 && sym
->domain () == STRUCT_DOMAIN
1657 && (sym
->type ()->code () == code
)
1658 && strcmp (sym
->linkage_name (), type_name
) == 0)
1660 obstack_free (&objfile
->objfile_obstack
, type_name
);
1661 type
= sym
->type ();
1662 if (typenums
[0] != -1)
1663 *dbx_lookup_type (typenums
, objfile
) = type
;
1668 /* Didn't find the type to which this refers, so we must
1669 be dealing with a forward reference. Allocate a type
1670 structure for it, and keep track of it so we can
1671 fill in the rest of the fields when we get the full
1673 type
= dbx_alloc_type (typenums
, objfile
);
1674 type
->set_code (code
);
1675 type
->set_name (type_name
);
1676 INIT_CPLUS_SPECIFIC (type
);
1677 type
->set_is_stub (true);
1679 add_undefined_type (type
, typenums
);
1683 case '-': /* RS/6000 built-in type */
1697 /* We deal with something like t(1,2)=(3,4)=... which
1698 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
1700 /* Allocate and enter the typedef type first.
1701 This handles recursive types. */
1702 type
= dbx_alloc_type (typenums
, objfile
);
1703 type
->set_code (TYPE_CODE_TYPEDEF
);
1705 struct type
*xtype
= read_type (pp
, objfile
);
1709 /* It's being defined as itself. That means it is "void". */
1710 type
->set_code (TYPE_CODE_VOID
);
1711 type
->set_length (1);
1713 else if (type_size
>= 0 || is_string
)
1715 /* This is the absolute wrong way to construct types. Every
1716 other debug format has found a way around this problem and
1717 the related problems with unnecessarily stubbed types;
1718 someone motivated should attempt to clean up the issue
1719 here as well. Once a type pointed to has been created it
1720 should not be modified.
1722 Well, it's not *absolutely* wrong. Constructing recursive
1723 types (trees, linked lists) necessarily entails modifying
1724 types after creating them. Constructing any loop structure
1725 entails side effects. The Dwarf 2 reader does handle this
1726 more gracefully (it never constructs more than once
1727 instance of a type object, so it doesn't have to copy type
1728 objects wholesale), but it still mutates type objects after
1729 other folks have references to them.
1731 Keep in mind that this circularity/mutation issue shows up
1732 at the source language level, too: C's "incomplete types",
1733 for example. So the proper cleanup, I think, would be to
1734 limit GDB's type smashing to match exactly those required
1735 by the source language. So GDB could have a
1736 "complete_this_type" function, but never create unnecessary
1737 copies of a type otherwise. */
1738 replace_type (type
, xtype
);
1739 type
->set_name (NULL
);
1743 type
->set_target_is_stub (true);
1744 type
->set_target_type (xtype
);
1749 /* In the following types, we must be sure to overwrite any existing
1750 type that the typenums refer to, rather than allocating a new one
1751 and making the typenums point to the new one. This is because there
1752 may already be pointers to the existing type (if it had been
1753 forward-referenced), and we must change it to a pointer, function,
1754 reference, or whatever, *in-place*. */
1756 case '*': /* Pointer to another type */
1757 type1
= read_type (pp
, objfile
);
1758 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
, objfile
));
1761 case '&': /* Reference to another type */
1762 type1
= read_type (pp
, objfile
);
1763 type
= make_reference_type (type1
, dbx_lookup_type (typenums
, objfile
),
1767 case 'f': /* Function returning another type */
1768 type1
= read_type (pp
, objfile
);
1769 type
= make_function_type (type1
, dbx_lookup_type (typenums
, objfile
));
1772 case 'g': /* Prototyped function. (Sun) */
1774 /* Unresolved questions:
1776 - According to Sun's ``STABS Interface Manual'', for 'f'
1777 and 'F' symbol descriptors, a `0' in the argument type list
1778 indicates a varargs function. But it doesn't say how 'g'
1779 type descriptors represent that info. Someone with access
1780 to Sun's toolchain should try it out.
1782 - According to the comment in define_symbol (search for
1783 `process_prototype_types:'), Sun emits integer arguments as
1784 types which ref themselves --- like `void' types. Do we
1785 have to deal with that here, too? Again, someone with
1786 access to Sun's toolchain should try it out and let us
1789 const char *type_start
= (*pp
) - 1;
1790 struct type
*return_type
= read_type (pp
, objfile
);
1791 struct type
*func_type
1792 = make_function_type (return_type
,
1793 dbx_lookup_type (typenums
, objfile
));
1796 struct type_list
*next
;
1800 while (**pp
&& **pp
!= '#')
1802 struct type
*arg_type
= read_type (pp
, objfile
);
1803 struct type_list
*newobj
= XALLOCA (struct type_list
);
1804 newobj
->type
= arg_type
;
1805 newobj
->next
= arg_types
;
1813 complaint (_("Prototyped function type didn't "
1814 "end arguments with `#':\n%s"),
1818 /* If there is just one argument whose type is `void', then
1819 that's just an empty argument list. */
1821 && ! arg_types
->next
1822 && arg_types
->type
->code () == TYPE_CODE_VOID
)
1825 func_type
->alloc_fields (num_args
);
1828 struct type_list
*t
;
1830 /* We stuck each argument type onto the front of the list
1831 when we read it, so the list is reversed. Build the
1832 fields array right-to-left. */
1833 for (t
= arg_types
, i
= num_args
- 1; t
; t
= t
->next
, i
--)
1834 func_type
->field (i
).set_type (t
->type
);
1836 func_type
->set_num_fields (num_args
);
1837 func_type
->set_is_prototyped (true);
1843 case 'k': /* Const qualifier on some type (Sun) */
1844 type
= read_type (pp
, objfile
);
1845 type
= make_cv_type (1, TYPE_VOLATILE (type
), type
,
1846 dbx_lookup_type (typenums
, objfile
));
1849 case 'B': /* Volatile qual on some type (Sun) */
1850 type
= read_type (pp
, objfile
);
1851 type
= make_cv_type (TYPE_CONST (type
), 1, type
,
1852 dbx_lookup_type (typenums
, objfile
));
1856 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
1857 { /* Member (class & variable) type */
1858 /* FIXME -- we should be doing smash_to_XXX types here. */
1860 struct type
*domain
= read_type (pp
, objfile
);
1861 struct type
*memtype
;
1864 /* Invalid member type data format. */
1865 return error_type (pp
, objfile
);
1868 memtype
= read_type (pp
, objfile
);
1869 type
= dbx_alloc_type (typenums
, objfile
);
1870 smash_to_memberptr_type (type
, domain
, memtype
);
1873 /* type attribute */
1875 const char *attr
= *pp
;
1877 /* Skip to the semicolon. */
1878 while (**pp
!= ';' && **pp
!= '\0')
1881 return error_type (pp
, objfile
);
1883 ++ * pp
; /* Skip the semicolon. */
1887 case 's': /* Size attribute */
1888 type_size
= atoi (attr
+ 1);
1893 case 'S': /* String attribute */
1894 /* FIXME: check to see if following type is array? */
1898 case 'V': /* Vector attribute */
1899 /* FIXME: check to see if following type is array? */
1904 /* Ignore unrecognized type attributes, so future compilers
1905 can invent new ones. */
1913 case '#': /* Method (class & fn) type */
1914 if ((*pp
)[0] == '#')
1916 /* We'll get the parameter types from the name. */
1917 struct type
*return_type
;
1920 return_type
= read_type (pp
, objfile
);
1921 if (*(*pp
)++ != ';')
1922 complaint (_("invalid (minimal) member type "
1923 "data format at symtab pos %d."),
1925 type
= allocate_stub_method (return_type
);
1926 if (typenums
[0] != -1)
1927 *dbx_lookup_type (typenums
, objfile
) = type
;
1931 struct type
*domain
= read_type (pp
, objfile
);
1932 struct type
*return_type
;
1937 /* Invalid member type data format. */
1938 return error_type (pp
, objfile
);
1942 return_type
= read_type (pp
, objfile
);
1943 args
= read_args (pp
, ';', objfile
, &nargs
, &varargs
);
1945 return error_type (pp
, objfile
);
1946 type
= dbx_alloc_type (typenums
, objfile
);
1947 smash_to_method_type (type
, domain
, return_type
, args
,
1952 case 'r': /* Range type */
1953 type
= read_range_type (pp
, typenums
, type_size
, objfile
);
1954 if (typenums
[0] != -1)
1955 *dbx_lookup_type (typenums
, objfile
) = type
;
1960 /* Sun ACC builtin int type */
1961 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1962 if (typenums
[0] != -1)
1963 *dbx_lookup_type (typenums
, objfile
) = type
;
1967 case 'R': /* Sun ACC builtin float type */
1968 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1969 if (typenums
[0] != -1)
1970 *dbx_lookup_type (typenums
, objfile
) = type
;
1973 case 'e': /* Enumeration type */
1974 type
= dbx_alloc_type (typenums
, objfile
);
1975 type
= read_enum_type (pp
, type
, objfile
);
1976 if (typenums
[0] != -1)
1977 *dbx_lookup_type (typenums
, objfile
) = type
;
1980 case 's': /* Struct type */
1981 case 'u': /* Union type */
1983 enum type_code type_code
= TYPE_CODE_UNDEF
;
1984 type
= dbx_alloc_type (typenums
, objfile
);
1985 switch (type_descriptor
)
1988 type_code
= TYPE_CODE_STRUCT
;
1991 type_code
= TYPE_CODE_UNION
;
1994 type
= read_struct_type (pp
, type
, type_code
, objfile
);
1998 case 'a': /* Array type */
2000 return error_type (pp
, objfile
);
2003 type
= dbx_alloc_type (typenums
, objfile
);
2004 type
= read_array_type (pp
, type
, objfile
);
2006 type
->set_code (TYPE_CODE_STRING
);
2008 make_vector_type (type
);
2011 case 'S': /* Set type */
2013 type1
= read_type (pp
, objfile
);
2014 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
2015 type
= create_set_type (alloc
, type1
);
2016 if (typenums
[0] != -1)
2017 *dbx_lookup_type (typenums
, objfile
) = type
;
2022 --*pp
; /* Go back to the symbol in error. */
2023 /* Particularly important if it was \0! */
2024 return error_type (pp
, objfile
);
2029 warning (_("GDB internal error, type is NULL in stabsread.c."));
2030 return error_type (pp
, objfile
);
2033 /* Size specified in a type attribute overrides any other size. */
2034 if (type_size
!= -1)
2035 type
->set_length ((type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
);
2040 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2041 Return the proper type node for a given builtin type number. */
2043 static const registry
<objfile
>::key
<struct type
*,
2044 gdb::noop_deleter
<struct type
*>>
2045 rs6000_builtin_type_data
;
2047 static struct type
*
2048 rs6000_builtin_type (int typenum
, struct objfile
*objfile
)
2050 struct type
**negative_types
= rs6000_builtin_type_data
.get (objfile
);
2052 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2053 #define NUMBER_RECOGNIZED 34
2054 struct type
*rettype
= NULL
;
2056 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2058 complaint (_("Unknown builtin type %d"), typenum
);
2059 return builtin_type (objfile
)->builtin_error
;
2062 if (!negative_types
)
2064 /* This includes an empty slot for type number -0. */
2065 negative_types
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2066 NUMBER_RECOGNIZED
+ 1, struct type
*);
2067 rs6000_builtin_type_data
.set (objfile
, negative_types
);
2070 if (negative_types
[-typenum
] != NULL
)
2071 return negative_types
[-typenum
];
2073 #if TARGET_CHAR_BIT != 8
2074 #error This code wrong for TARGET_CHAR_BIT not 8
2075 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2076 that if that ever becomes not true, the correct fix will be to
2077 make the size in the struct type to be in bits, not in units of
2081 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
2085 /* The size of this and all the other types are fixed, defined
2086 by the debugging format. If there is a type called "int" which
2087 is other than 32 bits, then it should use a new negative type
2088 number (or avoid negative type numbers for that case).
2089 See stabs.texinfo. */
2090 rettype
= init_integer_type (alloc
, 32, 0, "int");
2093 rettype
= init_integer_type (alloc
, 8, 0, "char");
2094 rettype
->set_has_no_signedness (true);
2097 rettype
= init_integer_type (alloc
, 16, 0, "short");
2100 rettype
= init_integer_type (alloc
, 32, 0, "long");
2103 rettype
= init_integer_type (alloc
, 8, 1, "unsigned char");
2106 rettype
= init_integer_type (alloc
, 8, 0, "signed char");
2109 rettype
= init_integer_type (alloc
, 16, 1, "unsigned short");
2112 rettype
= init_integer_type (alloc
, 32, 1, "unsigned int");
2115 rettype
= init_integer_type (alloc
, 32, 1, "unsigned");
2118 rettype
= init_integer_type (alloc
, 32, 1, "unsigned long");
2121 rettype
= alloc
.new_type (TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
2124 /* IEEE single precision (32 bit). */
2125 rettype
= init_float_type (alloc
, 32, "float",
2126 floatformats_ieee_single
);
2129 /* IEEE double precision (64 bit). */
2130 rettype
= init_float_type (alloc
, 64, "double",
2131 floatformats_ieee_double
);
2134 /* This is an IEEE double on the RS/6000, and different machines with
2135 different sizes for "long double" should use different negative
2136 type numbers. See stabs.texinfo. */
2137 rettype
= init_float_type (alloc
, 64, "long double",
2138 floatformats_ieee_double
);
2141 rettype
= init_integer_type (alloc
, 32, 0, "integer");
2144 rettype
= init_boolean_type (alloc
, 32, 1, "boolean");
2147 rettype
= init_float_type (alloc
, 32, "short real",
2148 floatformats_ieee_single
);
2151 rettype
= init_float_type (alloc
, 64, "real",
2152 floatformats_ieee_double
);
2155 rettype
= alloc
.new_type (TYPE_CODE_ERROR
, 0, "stringptr");
2158 rettype
= init_character_type (alloc
, 8, 1, "character");
2161 rettype
= init_boolean_type (alloc
, 8, 1, "logical*1");
2164 rettype
= init_boolean_type (alloc
, 16, 1, "logical*2");
2167 rettype
= init_boolean_type (alloc
, 32, 1, "logical*4");
2170 rettype
= init_boolean_type (alloc
, 32, 1, "logical");
2173 /* Complex type consisting of two IEEE single precision values. */
2174 rettype
= init_complex_type ("complex",
2175 rs6000_builtin_type (12, objfile
));
2178 /* Complex type consisting of two IEEE double precision values. */
2179 rettype
= init_complex_type ("double complex",
2180 rs6000_builtin_type (13, objfile
));
2183 rettype
= init_integer_type (alloc
, 8, 0, "integer*1");
2186 rettype
= init_integer_type (alloc
, 16, 0, "integer*2");
2189 rettype
= init_integer_type (alloc
, 32, 0, "integer*4");
2192 rettype
= init_character_type (alloc
, 16, 0, "wchar");
2195 rettype
= init_integer_type (alloc
, 64, 0, "long long");
2198 rettype
= init_integer_type (alloc
, 64, 1, "unsigned long long");
2201 rettype
= init_integer_type (alloc
, 64, 1, "logical*8");
2204 rettype
= init_integer_type (alloc
, 64, 0, "integer*8");
2207 negative_types
[-typenum
] = rettype
;
2211 /* This page contains subroutines of read_type. */
2213 /* Wrapper around method_name_from_physname to flag a complaint
2214 if there is an error. */
2217 stabs_method_name_from_physname (const char *physname
)
2221 method_name
= method_name_from_physname (physname
);
2223 if (method_name
== NULL
)
2225 complaint (_("Method has bad physname %s\n"), physname
);
2232 /* Read member function stabs info for C++ classes. The form of each member
2235 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2237 An example with two member functions is:
2239 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2241 For the case of overloaded operators, the format is op$::*.funcs, where
2242 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2243 name (such as `+=') and `.' marks the end of the operator name.
2245 Returns 1 for success, 0 for failure. */
2248 read_member_functions (struct stab_field_info
*fip
, const char **pp
,
2249 struct type
*type
, struct objfile
*objfile
)
2256 struct next_fnfield
*next
;
2257 struct fn_field fn_field
;
2260 struct type
*look_ahead_type
;
2261 struct next_fnfieldlist
*new_fnlist
;
2262 struct next_fnfield
*new_sublist
;
2266 /* Process each list until we find something that is not a member function
2267 or find the end of the functions. */
2271 /* We should be positioned at the start of the function name.
2272 Scan forward to find the first ':' and if it is not the
2273 first of a "::" delimiter, then this is not a member function. */
2285 look_ahead_type
= NULL
;
2288 new_fnlist
= OBSTACK_ZALLOC (&fip
->obstack
, struct next_fnfieldlist
);
2290 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2292 /* This is a completely wierd case. In order to stuff in the
2293 names that might contain colons (the usual name delimiter),
2294 Mike Tiemann defined a different name format which is
2295 signalled if the identifier is "op$". In that case, the
2296 format is "op$::XXXX." where XXXX is the name. This is
2297 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2298 /* This lets the user type "break operator+".
2299 We could just put in "+" as the name, but that wouldn't
2301 static char opname
[32] = "op$";
2302 char *o
= opname
+ 3;
2304 /* Skip past '::'. */
2307 STABS_CONTINUE (pp
, objfile
);
2313 main_fn_name
= savestring (opname
, o
- opname
);
2319 main_fn_name
= savestring (*pp
, p
- *pp
);
2320 /* Skip past '::'. */
2323 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
2327 new_sublist
= OBSTACK_ZALLOC (&fip
->obstack
, struct next_fnfield
);
2329 /* Check for and handle cretinous dbx symbol name continuation! */
2330 if (look_ahead_type
== NULL
)
2333 STABS_CONTINUE (pp
, objfile
);
2335 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2338 /* Invalid symtab info for member function. */
2344 /* g++ version 1 kludge */
2345 new_sublist
->fn_field
.type
= look_ahead_type
;
2346 look_ahead_type
= NULL
;
2356 /* These are methods, not functions. */
2357 if (new_sublist
->fn_field
.type
->code () == TYPE_CODE_FUNC
)
2358 new_sublist
->fn_field
.type
->set_code (TYPE_CODE_METHOD
);
2360 /* If this is just a stub, then we don't have the real name here. */
2361 if (new_sublist
->fn_field
.type
->is_stub ())
2363 if (!TYPE_SELF_TYPE (new_sublist
->fn_field
.type
))
2364 set_type_self_type (new_sublist
->fn_field
.type
, type
);
2365 new_sublist
->fn_field
.is_stub
= 1;
2368 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2371 /* Set this member function's visibility fields. */
2374 case VISIBILITY_PRIVATE
:
2375 new_sublist
->fn_field
.accessibility
= accessibility::PRIVATE
;
2377 case VISIBILITY_PROTECTED
:
2378 new_sublist
->fn_field
.accessibility
= accessibility::PROTECTED
;
2382 STABS_CONTINUE (pp
, objfile
);
2385 case 'A': /* Normal functions. */
2386 new_sublist
->fn_field
.is_const
= 0;
2387 new_sublist
->fn_field
.is_volatile
= 0;
2390 case 'B': /* `const' member functions. */
2391 new_sublist
->fn_field
.is_const
= 1;
2392 new_sublist
->fn_field
.is_volatile
= 0;
2395 case 'C': /* `volatile' member function. */
2396 new_sublist
->fn_field
.is_const
= 0;
2397 new_sublist
->fn_field
.is_volatile
= 1;
2400 case 'D': /* `const volatile' member function. */
2401 new_sublist
->fn_field
.is_const
= 1;
2402 new_sublist
->fn_field
.is_volatile
= 1;
2405 case '*': /* File compiled with g++ version 1 --
2411 complaint (_("const/volatile indicator missing, got '%c'"),
2421 /* virtual member function, followed by index.
2422 The sign bit is set to distinguish pointers-to-methods
2423 from virtual function indicies. Since the array is
2424 in words, the quantity must be shifted left by 1
2425 on 16 bit machine, and by 2 on 32 bit machine, forcing
2426 the sign bit out, and usable as a valid index into
2427 the array. Remove the sign bit here. */
2428 new_sublist
->fn_field
.voffset
=
2429 (0x7fffffff & read_huge_number (pp
, ';', &nbits
, 0)) + 2;
2433 STABS_CONTINUE (pp
, objfile
);
2434 if (**pp
== ';' || **pp
== '\0')
2436 /* Must be g++ version 1. */
2437 new_sublist
->fn_field
.fcontext
= 0;
2441 /* Figure out from whence this virtual function came.
2442 It may belong to virtual function table of
2443 one of its baseclasses. */
2444 look_ahead_type
= read_type (pp
, objfile
);
2447 /* g++ version 1 overloaded methods. */
2451 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2460 look_ahead_type
= NULL
;
2466 /* static member function. */
2468 int slen
= strlen (main_fn_name
);
2470 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2472 /* For static member functions, we can't tell if they
2473 are stubbed, as they are put out as functions, and not as
2475 GCC v2 emits the fully mangled name if
2476 dbxout.c:flag_minimal_debug is not set, so we have to
2477 detect a fully mangled physname here and set is_stub
2478 accordingly. Fully mangled physnames in v2 start with
2479 the member function name, followed by two underscores.
2480 GCC v3 currently always emits stubbed member functions,
2481 but with fully mangled physnames, which start with _Z. */
2482 if (!(strncmp (new_sublist
->fn_field
.physname
,
2483 main_fn_name
, slen
) == 0
2484 && new_sublist
->fn_field
.physname
[slen
] == '_'
2485 && new_sublist
->fn_field
.physname
[slen
+ 1] == '_'))
2487 new_sublist
->fn_field
.is_stub
= 1;
2494 complaint (_("member function type missing, got '%c'"),
2496 /* Normal member function. */
2500 /* normal member function. */
2501 new_sublist
->fn_field
.voffset
= 0;
2502 new_sublist
->fn_field
.fcontext
= 0;
2506 new_sublist
->next
= sublist
;
2507 sublist
= new_sublist
;
2509 STABS_CONTINUE (pp
, objfile
);
2511 while (**pp
!= ';' && **pp
!= '\0');
2514 STABS_CONTINUE (pp
, objfile
);
2516 /* Skip GCC 3.X member functions which are duplicates of the callable
2517 constructor/destructor. */
2518 if (strcmp_iw (main_fn_name
, "__base_ctor ") == 0
2519 || strcmp_iw (main_fn_name
, "__base_dtor ") == 0
2520 || strcmp (main_fn_name
, "__deleting_dtor") == 0)
2522 xfree (main_fn_name
);
2526 int has_destructor
= 0, has_other
= 0;
2528 struct next_fnfield
*tmp_sublist
;
2530 /* Various versions of GCC emit various mostly-useless
2531 strings in the name field for special member functions.
2533 For stub methods, we need to defer correcting the name
2534 until we are ready to unstub the method, because the current
2535 name string is used by gdb_mangle_name. The only stub methods
2536 of concern here are GNU v2 operators; other methods have their
2537 names correct (see caveat below).
2539 For non-stub methods, in GNU v3, we have a complete physname.
2540 Therefore we can safely correct the name now. This primarily
2541 affects constructors and destructors, whose name will be
2542 __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
2543 operators will also have incorrect names; for instance,
2544 "operator int" will be named "operator i" (i.e. the type is
2547 For non-stub methods in GNU v2, we have no easy way to
2548 know if we have a complete physname or not. For most
2549 methods the result depends on the platform (if CPLUS_MARKER
2550 can be `$' or `.', it will use minimal debug information, or
2551 otherwise the full physname will be included).
2553 Rather than dealing with this, we take a different approach.
2554 For v3 mangled names, we can use the full physname; for v2,
2555 we use cplus_demangle_opname (which is actually v2 specific),
2556 because the only interesting names are all operators - once again
2557 barring the caveat below. Skip this process if any method in the
2558 group is a stub, to prevent our fouling up the workings of
2561 The caveat: GCC 2.95.x (and earlier?) put constructors and
2562 destructors in the same method group. We need to split this
2563 into two groups, because they should have different names.
2564 So for each method group we check whether it contains both
2565 routines whose physname appears to be a destructor (the physnames
2566 for and destructors are always provided, due to quirks in v2
2567 mangling) and routines whose physname does not appear to be a
2568 destructor. If so then we break up the list into two halves.
2569 Even if the constructors and destructors aren't in the same group
2570 the destructor will still lack the leading tilde, so that also
2573 So, to summarize what we expect and handle here:
2575 Given Given Real Real Action
2576 method name physname physname method name
2578 __opi [none] __opi__3Foo operator int opname
2580 Foo _._3Foo _._3Foo ~Foo separate and
2582 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
2583 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
2586 tmp_sublist
= sublist
;
2587 while (tmp_sublist
!= NULL
)
2589 if (tmp_sublist
->fn_field
.physname
[0] == '_'
2590 && tmp_sublist
->fn_field
.physname
[1] == 'Z')
2593 if (is_destructor_name (tmp_sublist
->fn_field
.physname
))
2598 tmp_sublist
= tmp_sublist
->next
;
2601 if (has_destructor
&& has_other
)
2603 struct next_fnfieldlist
*destr_fnlist
;
2604 struct next_fnfield
*last_sublist
;
2606 /* Create a new fn_fieldlist for the destructors. */
2608 destr_fnlist
= OBSTACK_ZALLOC (&fip
->obstack
,
2609 struct next_fnfieldlist
);
2611 destr_fnlist
->fn_fieldlist
.name
2612 = obconcat (&objfile
->objfile_obstack
, "~",
2613 new_fnlist
->fn_fieldlist
.name
, (char *) NULL
);
2615 destr_fnlist
->fn_fieldlist
.fn_fields
=
2616 XOBNEWVEC (&objfile
->objfile_obstack
,
2617 struct fn_field
, has_destructor
);
2618 memset (destr_fnlist
->fn_fieldlist
.fn_fields
, 0,
2619 sizeof (struct fn_field
) * has_destructor
);
2620 tmp_sublist
= sublist
;
2621 last_sublist
= NULL
;
2623 while (tmp_sublist
!= NULL
)
2625 if (!is_destructor_name (tmp_sublist
->fn_field
.physname
))
2627 tmp_sublist
= tmp_sublist
->next
;
2631 destr_fnlist
->fn_fieldlist
.fn_fields
[i
++]
2632 = tmp_sublist
->fn_field
;
2634 last_sublist
->next
= tmp_sublist
->next
;
2636 sublist
= tmp_sublist
->next
;
2637 last_sublist
= tmp_sublist
;
2638 tmp_sublist
= tmp_sublist
->next
;
2641 destr_fnlist
->fn_fieldlist
.length
= has_destructor
;
2642 destr_fnlist
->next
= fip
->fnlist
;
2643 fip
->fnlist
= destr_fnlist
;
2645 length
-= has_destructor
;
2649 /* v3 mangling prevents the use of abbreviated physnames,
2650 so we can do this here. There are stubbed methods in v3
2652 - in -gstabs instead of -gstabs+
2653 - or for static methods, which are output as a function type
2654 instead of a method type. */
2655 char *new_method_name
=
2656 stabs_method_name_from_physname (sublist
->fn_field
.physname
);
2658 if (new_method_name
!= NULL
2659 && strcmp (new_method_name
,
2660 new_fnlist
->fn_fieldlist
.name
) != 0)
2662 new_fnlist
->fn_fieldlist
.name
= new_method_name
;
2663 xfree (main_fn_name
);
2666 xfree (new_method_name
);
2668 else if (has_destructor
&& new_fnlist
->fn_fieldlist
.name
[0] != '~')
2670 new_fnlist
->fn_fieldlist
.name
=
2671 obconcat (&objfile
->objfile_obstack
,
2672 "~", main_fn_name
, (char *)NULL
);
2673 xfree (main_fn_name
);
2676 new_fnlist
->fn_fieldlist
.fn_fields
2677 = OBSTACK_CALLOC (&objfile
->objfile_obstack
, length
, fn_field
);
2678 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2680 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2683 new_fnlist
->fn_fieldlist
.length
= length
;
2684 new_fnlist
->next
= fip
->fnlist
;
2685 fip
->fnlist
= new_fnlist
;
2692 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2693 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2694 TYPE_ZALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2695 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2701 /* Special GNU C++ name.
2703 Returns 1 for success, 0 for failure. "failure" means that we can't
2704 keep parsing and it's time for error_type(). */
2707 read_cpp_abbrev (struct stab_field_info
*fip
, const char **pp
,
2708 struct type
*type
, struct objfile
*objfile
)
2713 struct type
*context
;
2723 /* At this point, *pp points to something like "22:23=*22...",
2724 where the type number before the ':' is the "context" and
2725 everything after is a regular type definition. Lookup the
2726 type, find it's name, and construct the field name. */
2728 context
= read_type (pp
, objfile
);
2732 case 'f': /* $vf -- a virtual function table pointer */
2733 name
= context
->name ();
2738 fip
->list
->field
.set_name (obconcat (&objfile
->objfile_obstack
,
2739 vptr_name
, name
, (char *) NULL
));
2742 case 'b': /* $vb -- a virtual bsomethingorother */
2743 name
= context
->name ();
2746 complaint (_("C++ abbreviated type name "
2747 "unknown at symtab pos %d"),
2751 fip
->list
->field
.set_name (obconcat (&objfile
->objfile_obstack
,
2752 vb_name
, name
, (char *) NULL
));
2756 invalid_cpp_abbrev_complaint (*pp
);
2757 fip
->list
->field
.set_name (obconcat (&objfile
->objfile_obstack
,
2758 "INVALID_CPLUSPLUS_ABBREV",
2763 /* At this point, *pp points to the ':'. Skip it and read the
2769 invalid_cpp_abbrev_complaint (*pp
);
2772 fip
->list
->field
.set_type (read_type (pp
, objfile
));
2774 (*pp
)++; /* Skip the comma. */
2781 fip
->list
->field
.set_loc_bitpos (read_huge_number (pp
, ';', &nbits
, 0));
2785 /* This field is unpacked. */
2786 fip
->list
->field
.set_bitsize (0);
2787 fip
->list
->field
.set_accessibility (accessibility::PRIVATE
);
2791 invalid_cpp_abbrev_complaint (*pp
);
2792 /* We have no idea what syntax an unrecognized abbrev would have, so
2793 better return 0. If we returned 1, we would need to at least advance
2794 *pp to avoid an infinite loop. */
2801 read_one_struct_field (struct stab_field_info
*fip
, const char **pp
,
2802 const char *p
, struct type
*type
,
2803 struct objfile
*objfile
)
2805 struct gdbarch
*gdbarch
= objfile
->arch ();
2807 fip
->list
->field
.set_name
2808 (obstack_strndup (&objfile
->objfile_obstack
, *pp
, p
- *pp
));
2811 /* This means we have a visibility for a field coming. */
2816 visibility
= *(*pp
)++;
2820 /* normal dbx-style format, no explicit visibility */
2821 visibility
= VISIBILITY_PUBLIC
;
2826 case VISIBILITY_PRIVATE
:
2827 fip
->list
->field
.set_accessibility (accessibility::PRIVATE
);
2830 case VISIBILITY_PROTECTED
:
2831 fip
->list
->field
.set_accessibility (accessibility::PROTECTED
);
2834 case VISIBILITY_IGNORE
:
2835 fip
->list
->field
.set_ignored ();
2838 case VISIBILITY_PUBLIC
:
2842 /* Unknown visibility. Complain and treat it as public. */
2844 complaint (_("Unknown visibility `%c' for field"),
2850 fip
->list
->field
.set_type (read_type (pp
, objfile
));
2855 /* Possible future hook for nested types. */
2858 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
2868 /* Static class member. */
2869 fip
->list
->field
.set_loc_physname (savestring (*pp
, p
- *pp
));
2873 else if (**pp
!= ',')
2875 /* Bad structure-type format. */
2876 stabs_general_complaint ("bad structure-type format");
2880 (*pp
)++; /* Skip the comma. */
2885 fip
->list
->field
.set_loc_bitpos (read_huge_number (pp
, ',', &nbits
, 0));
2888 stabs_general_complaint ("bad structure-type format");
2891 fip
->list
->field
.set_bitsize (read_huge_number (pp
, ';', &nbits
, 0));
2894 stabs_general_complaint ("bad structure-type format");
2899 if (fip
->list
->field
.loc_bitpos () == 0
2900 && fip
->list
->field
.bitsize () == 0)
2902 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2903 it is a field which has been optimized out. The correct stab for
2904 this case is to use VISIBILITY_IGNORE, but that is a recent
2905 invention. (2) It is a 0-size array. For example
2906 union { int num; char str[0]; } foo. Printing _("<no value>" for
2907 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2908 will continue to work, and a 0-size array as a whole doesn't
2909 have any contents to print.
2911 I suspect this probably could also happen with gcc -gstabs (not
2912 -gstabs+) for static fields, and perhaps other C++ extensions.
2913 Hopefully few people use -gstabs with gdb, since it is intended
2914 for dbx compatibility. */
2916 /* Ignore this field. */
2917 fip
->list
->field
.set_ignored ();
2921 /* Detect an unpacked field and mark it as such.
2922 dbx gives a bit size for all fields.
2923 Note that forward refs cannot be packed,
2924 and treat enums as if they had the width of ints. */
2926 struct type
*field_type
= check_typedef (fip
->list
->field
.type ());
2928 if (field_type
->code () != TYPE_CODE_INT
2929 && field_type
->code () != TYPE_CODE_RANGE
2930 && field_type
->code () != TYPE_CODE_BOOL
2931 && field_type
->code () != TYPE_CODE_ENUM
)
2933 fip
->list
->field
.set_bitsize (0);
2935 if ((fip
->list
->field
.bitsize ()
2936 == TARGET_CHAR_BIT
* field_type
->length ()
2937 || (field_type
->code () == TYPE_CODE_ENUM
2938 && (fip
->list
->field
.bitsize ()
2939 == gdbarch_int_bit (gdbarch
)))
2942 fip
->list
->field
.loc_bitpos () % 8 == 0)
2944 fip
->list
->field
.set_bitsize (0);
2950 /* Read struct or class data fields. They have the form:
2952 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2954 At the end, we see a semicolon instead of a field.
2956 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2959 The optional VISIBILITY is one of:
2961 '/0' (VISIBILITY_PRIVATE)
2962 '/1' (VISIBILITY_PROTECTED)
2963 '/2' (VISIBILITY_PUBLIC)
2964 '/9' (VISIBILITY_IGNORE)
2966 or nothing, for C style fields with public visibility.
2968 Returns 1 for success, 0 for failure. */
2971 read_struct_fields (struct stab_field_info
*fip
, const char **pp
,
2972 struct type
*type
, struct objfile
*objfile
)
2975 struct stabs_nextfield
*newobj
;
2977 /* We better set p right now, in case there are no fields at all... */
2981 /* Read each data member type until we find the terminating ';' at the end of
2982 the data member list, or break for some other reason such as finding the
2983 start of the member function list. */
2984 /* Stab string for structure/union does not end with two ';' in
2985 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
2987 while (**pp
!= ';' && **pp
!= '\0')
2989 STABS_CONTINUE (pp
, objfile
);
2990 /* Get space to record the next field's data. */
2991 newobj
= OBSTACK_ZALLOC (&fip
->obstack
, struct stabs_nextfield
);
2993 newobj
->next
= fip
->list
;
2996 /* Get the field name. */
2999 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3000 unless the CPLUS_MARKER is followed by an underscore, in
3001 which case it is just the name of an anonymous type, which we
3002 should handle like any other type name. */
3004 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3006 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3011 /* Look for the ':' that separates the field name from the field
3012 values. Data members are delimited by a single ':', while member
3013 functions are delimited by a pair of ':'s. When we hit the member
3014 functions (if any), terminate scan loop and return. */
3016 while (*p
!= ':' && *p
!= '\0')
3023 /* Check to see if we have hit the member functions yet. */
3028 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3030 if (p
[0] == ':' && p
[1] == ':')
3032 /* (the deleted) chill the list of fields: the last entry (at
3033 the head) is a partially constructed entry which we now
3035 fip
->list
= fip
->list
->next
;
3039 /* The stabs for C++ derived classes contain baseclass information which
3040 is marked by a '!' character after the total size. This function is
3041 called when we encounter the baseclass marker, and slurps up all the
3042 baseclass information.
3044 Immediately following the '!' marker is the number of base classes that
3045 the class is derived from, followed by information for each base class.
3046 For each base class, there are two visibility specifiers, a bit offset
3047 to the base class information within the derived class, a reference to
3048 the type for the base class, and a terminating semicolon.
3050 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3052 Baseclass information marker __________________|| | | | | | |
3053 Number of baseclasses __________________________| | | | | | |
3054 Visibility specifiers (2) ________________________| | | | | |
3055 Offset in bits from start of class _________________| | | | |
3056 Type number for base class ___________________________| | | |
3057 Visibility specifiers (2) _______________________________| | |
3058 Offset in bits from start of class ________________________| |
3059 Type number of base class ____________________________________|
3061 Return 1 for success, 0 for (error-type-inducing) failure. */
3066 read_baseclasses (struct stab_field_info
*fip
, const char **pp
,
3067 struct type
*type
, struct objfile
*objfile
)
3070 struct stabs_nextfield
*newobj
;
3078 /* Skip the '!' baseclass information marker. */
3082 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3086 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
, 0);
3091 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3093 newobj
= OBSTACK_ZALLOC (&fip
->obstack
, struct stabs_nextfield
);
3095 newobj
->next
= fip
->list
;
3097 newobj
->field
.set_bitsize (0); /* This should be an unpacked
3100 STABS_CONTINUE (pp
, objfile
);
3104 /* Nothing to do. */
3107 newobj
->field
.set_virtual ();
3110 /* Unknown character. Complain and treat it as non-virtual. */
3112 complaint (_("Unknown virtual character `%c' for baseclass"),
3118 int visibility
= *(*pp
)++;
3121 case VISIBILITY_PRIVATE
:
3122 newobj
->field
.set_accessibility (accessibility::PRIVATE
);
3124 case VISIBILITY_PROTECTED
:
3125 newobj
->field
.set_accessibility (accessibility::PROTECTED
);
3127 case VISIBILITY_PUBLIC
:
3130 /* Bad visibility format. Complain and treat it as
3133 complaint (_("Unknown visibility `%c' for baseclass"),
3141 /* The remaining value is the bit offset of the portion of the object
3142 corresponding to this baseclass. Always zero in the absence of
3143 multiple inheritance. */
3145 newobj
->field
.set_loc_bitpos (read_huge_number (pp
, ',', &nbits
, 0));
3150 /* The last piece of baseclass information is the type of the
3151 base class. Read it, and remember it's type name as this
3154 newobj
->field
.set_type (read_type (pp
, objfile
));
3155 newobj
->field
.set_name (newobj
->field
.type ()->name ());
3157 /* Skip trailing ';' and bump count of number of fields seen. */
3166 /* The tail end of stabs for C++ classes that contain a virtual function
3167 pointer contains a tilde, a %, and a type number.
3168 The type number refers to the base class (possibly this class itself) which
3169 contains the vtable pointer for the current class.
3171 This function is called when we have parsed all the method declarations,
3172 so we can look for the vptr base class info. */
3175 read_tilde_fields (struct stab_field_info
*fip
, const char **pp
,
3176 struct type
*type
, struct objfile
*objfile
)
3180 STABS_CONTINUE (pp
, objfile
);
3182 /* If we are positioned at a ';', then skip it. */
3192 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3194 /* Obsolete flags that used to indicate the presence
3195 of constructors and/or destructors. */
3199 /* Read either a '%' or the final ';'. */
3200 if (*(*pp
)++ == '%')
3202 /* The next number is the type number of the base class
3203 (possibly our own class) which supplies the vtable for
3204 this class. Parse it out, and search that class to find
3205 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3206 and TYPE_VPTR_FIELDNO. */
3211 t
= read_type (pp
, objfile
);
3213 while (*p
!= '\0' && *p
!= ';')
3219 /* Premature end of symbol. */
3223 set_type_vptr_basetype (type
, t
);
3224 if (type
== t
) /* Our own class provides vtbl ptr. */
3226 for (i
= t
->num_fields () - 1;
3227 i
>= TYPE_N_BASECLASSES (t
);
3230 const char *name
= t
->field (i
).name ();
3232 if (!strncmp (name
, vptr_name
, sizeof (vptr_name
) - 2)
3233 && is_cplus_marker (name
[sizeof (vptr_name
) - 2]))
3235 set_type_vptr_fieldno (type
, i
);
3239 /* Virtual function table field not found. */
3240 complaint (_("virtual function table pointer "
3241 "not found when defining class `%s'"),
3247 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
3258 attach_fn_fields_to_type (struct stab_field_info
*fip
, struct type
*type
)
3262 for (n
= TYPE_NFN_FIELDS (type
);
3263 fip
->fnlist
!= NULL
;
3264 fip
->fnlist
= fip
->fnlist
->next
)
3266 --n
; /* Circumvent Sun3 compiler bug. */
3267 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3272 /* Create the vector of fields, and record how big it is.
3273 We need this info to record proper virtual function table information
3274 for this class's virtual functions. */
3277 attach_fields_to_type (struct stab_field_info
*fip
, struct type
*type
,
3278 struct objfile
*objfile
)
3281 struct stabs_nextfield
*scan
;
3283 /* Count up the number of fields that we have. */
3285 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
3288 /* Now we know how many fields there are, and whether or not there are any
3289 non-public fields. Record the field count, allocate space for the
3292 type
->alloc_fields (nfields
);
3294 /* Copy the saved-up fields into the field vector. Start from the
3295 head of the list, adding to the tail of the field array, so that
3296 they end up in the same order in the array in which they were
3297 added to the list. */
3299 while (nfields
-- > 0)
3301 type
->field (nfields
) = fip
->list
->field
;
3302 fip
->list
= fip
->list
->next
;
3308 /* Complain that the compiler has emitted more than one definition for the
3309 structure type TYPE. */
3311 complain_about_struct_wipeout (struct type
*type
)
3313 const char *name
= "";
3314 const char *kind
= "";
3318 name
= type
->name ();
3319 switch (type
->code ())
3321 case TYPE_CODE_STRUCT
: kind
= "struct "; break;
3322 case TYPE_CODE_UNION
: kind
= "union "; break;
3323 case TYPE_CODE_ENUM
: kind
= "enum "; break;
3333 complaint (_("struct/union type gets multiply defined: %s%s"), kind
, name
);
3336 /* Set the length for all variants of a same main_type, which are
3337 connected in the closed chain.
3339 This is something that needs to be done when a type is defined *after*
3340 some cross references to this type have already been read. Consider
3341 for instance the following scenario where we have the following two
3344 .stabs "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
3345 .stabs "dummy:T(0,23)=s16x:(0,1),0,3[...]"
3347 A stubbed version of type dummy is created while processing the first
3348 stabs entry. The length of that type is initially set to zero, since
3349 it is unknown at this point. Also, a "constant" variation of type
3350 "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
3353 The second stabs entry allows us to replace the stubbed definition
3354 with the real definition. However, we still need to adjust the length
3355 of the "constant" variation of that type, as its length was left
3356 untouched during the main type replacement... */
3359 set_length_in_type_chain (struct type
*type
)
3361 struct type
*ntype
= TYPE_CHAIN (type
);
3363 while (ntype
!= type
)
3365 if (ntype
->length () == 0)
3366 ntype
->set_length (type
->length ());
3368 complain_about_struct_wipeout (ntype
);
3369 ntype
= TYPE_CHAIN (ntype
);
3373 /* Read the description of a structure (or union type) and return an object
3374 describing the type.
3376 PP points to a character pointer that points to the next unconsumed token
3377 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3378 *PP will point to "4a:1,0,32;;".
3380 TYPE points to an incomplete type that needs to be filled in.
3382 OBJFILE points to the current objfile from which the stabs information is
3383 being read. (Note that it is redundant in that TYPE also contains a pointer
3384 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3387 static struct type
*
3388 read_struct_type (const char **pp
, struct type
*type
, enum type_code type_code
,
3389 struct objfile
*objfile
)
3391 struct stab_field_info fi
;
3393 /* When describing struct/union/class types in stabs, G++ always drops
3394 all qualifications from the name. So if you've got:
3395 struct A { ... struct B { ... }; ... };
3396 then G++ will emit stabs for `struct A::B' that call it simply
3397 `struct B'. Obviously, if you've got a real top-level definition for
3398 `struct B', or other nested definitions, this is going to cause
3401 Obviously, GDB can't fix this by itself, but it can at least avoid
3402 scribbling on existing structure type objects when new definitions
3404 if (! (type
->code () == TYPE_CODE_UNDEF
3405 || type
->is_stub ()))
3407 complain_about_struct_wipeout (type
);
3409 /* It's probably best to return the type unchanged. */
3413 INIT_CPLUS_SPECIFIC (type
);
3414 type
->set_code (type_code
);
3415 type
->set_is_stub (false);
3417 /* First comes the total size in bytes. */
3422 type
->set_length (read_huge_number (pp
, 0, &nbits
, 0));
3424 return error_type (pp
, objfile
);
3425 set_length_in_type_chain (type
);
3428 /* Now read the baseclasses, if any, read the regular C struct or C++
3429 class member fields, attach the fields to the type, read the C++
3430 member functions, attach them to the type, and then read any tilde
3431 field (baseclass specifier for the class holding the main vtable). */
3433 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3434 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3435 || !attach_fields_to_type (&fi
, type
, objfile
)
3436 || !read_member_functions (&fi
, pp
, type
, objfile
)
3437 || !attach_fn_fields_to_type (&fi
, type
)
3438 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3440 type
= error_type (pp
, objfile
);
3446 /* Read a definition of an array type,
3447 and create and return a suitable type object.
3448 Also creates a range type which represents the bounds of that
3451 static struct type
*
3452 read_array_type (const char **pp
, struct type
*type
,
3453 struct objfile
*objfile
)
3455 struct type
*index_type
, *element_type
, *range_type
;
3460 /* Format of an array type:
3461 "ar<index type>;lower;upper;<array_contents_type>".
3462 OS9000: "arlower,upper;<array_contents_type>".
3464 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3465 for these, produce a type like float[][]. */
3468 index_type
= read_type (pp
, objfile
);
3470 /* Improper format of array type decl. */
3471 return error_type (pp
, objfile
);
3475 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3480 lower
= read_huge_number (pp
, ';', &nbits
, 0);
3483 return error_type (pp
, objfile
);
3485 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3490 upper
= read_huge_number (pp
, ';', &nbits
, 0);
3492 return error_type (pp
, objfile
);
3494 element_type
= read_type (pp
, objfile
);
3502 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
3504 create_static_range_type (alloc
, index_type
, lower
, upper
);
3505 type_allocator
smash_alloc (type
, type_allocator::SMASH
);
3506 type
= create_array_type (smash_alloc
, element_type
, range_type
);
3512 /* Read a definition of an enumeration type,
3513 and create and return a suitable type object.
3514 Also defines the symbols that represent the values of the type. */
3516 static struct type
*
3517 read_enum_type (const char **pp
, struct type
*type
,
3518 struct objfile
*objfile
)
3520 struct gdbarch
*gdbarch
= objfile
->arch ();
3526 struct pending
**symlist
;
3527 struct pending
*osyms
, *syms
;
3530 int unsigned_enum
= 1;
3533 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3534 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3535 to do? For now, force all enum values to file scope. */
3536 if (within_function
)
3537 symlist
= get_local_symbols ();
3540 symlist
= get_file_symbols ();
3542 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3544 /* The aix4 compiler emits an extra field before the enum members;
3545 my guess is it's a type of some sort. Just ignore it. */
3548 /* Skip over the type. */
3552 /* Skip over the colon. */
3556 /* Read the value-names and their values.
3557 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3558 A semicolon or comma instead of a NAME means the end. */
3559 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3561 STABS_CONTINUE (pp
, objfile
);
3565 name
= obstack_strndup (&objfile
->objfile_obstack
, *pp
, p
- *pp
);
3567 n
= read_huge_number (pp
, ',', &nbits
, 0);
3569 return error_type (pp
, objfile
);
3571 sym
= new (&objfile
->objfile_obstack
) symbol
;
3572 sym
->set_linkage_name (name
);
3573 sym
->set_language (get_current_subfile ()->language
,
3574 &objfile
->objfile_obstack
);
3575 sym
->set_aclass_index (LOC_CONST
);
3576 sym
->set_domain (VAR_DOMAIN
);
3577 sym
->set_value_longest (n
);
3580 add_symbol_to_list (sym
, symlist
);
3585 (*pp
)++; /* Skip the semicolon. */
3587 /* Now fill in the fields of the type-structure. */
3589 type
->set_length (gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
);
3590 set_length_in_type_chain (type
);
3591 type
->set_code (TYPE_CODE_ENUM
);
3592 type
->set_is_stub (false);
3594 type
->set_is_unsigned (true);
3595 type
->alloc_fields (nsyms
);
3597 /* Find the symbols for the values and put them into the type.
3598 The symbols can be found in the symlist that we put them on
3599 to cause them to be defined. osyms contains the old value
3600 of that symlist; everything up to there was defined by us. */
3601 /* Note that we preserve the order of the enum constants, so
3602 that in something like "enum {FOO, LAST_THING=FOO}" we print
3603 FOO, not LAST_THING. */
3605 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3607 int last
= syms
== osyms
? o_nsyms
: 0;
3608 int j
= syms
->nsyms
;
3610 for (; --j
>= last
; --n
)
3612 struct symbol
*xsym
= syms
->symbol
[j
];
3614 xsym
->set_type (type
);
3615 type
->field (n
).set_name (xsym
->linkage_name ());
3616 type
->field (n
).set_loc_enumval (xsym
->value_longest ());
3617 type
->field (n
).set_bitsize (0);
3626 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3627 typedefs in every file (for int, long, etc):
3629 type = b <signed> <width> <format type>; <offset>; <nbits>
3631 optional format type = c or b for char or boolean.
3632 offset = offset from high order bit to start bit of type.
3633 width is # bytes in object of this type, nbits is # bits in type.
3635 The width/offset stuff appears to be for small objects stored in
3636 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3639 static struct type
*
3640 read_sun_builtin_type (const char **pp
, int typenums
[2], struct objfile
*objfile
)
3645 int boolean_type
= 0;
3656 return error_type (pp
, objfile
);
3660 /* For some odd reason, all forms of char put a c here. This is strange
3661 because no other type has this honor. We can safely ignore this because
3662 we actually determine 'char'acterness by the number of bits specified in
3664 Boolean forms, e.g Fortran logical*X, put a b here. */
3668 else if (**pp
== 'b')
3674 /* The first number appears to be the number of bytes occupied
3675 by this type, except that unsigned short is 4 instead of 2.
3676 Since this information is redundant with the third number,
3677 we will ignore it. */
3678 read_huge_number (pp
, ';', &nbits
, 0);
3680 return error_type (pp
, objfile
);
3682 /* The second number is always 0, so ignore it too. */
3683 read_huge_number (pp
, ';', &nbits
, 0);
3685 return error_type (pp
, objfile
);
3687 /* The third number is the number of bits for this type. */
3688 type_bits
= read_huge_number (pp
, 0, &nbits
, 0);
3690 return error_type (pp
, objfile
);
3691 /* The type *should* end with a semicolon. If it are embedded
3692 in a larger type the semicolon may be the only way to know where
3693 the type ends. If this type is at the end of the stabstring we
3694 can deal with the omitted semicolon (but we don't have to like
3695 it). Don't bother to complain(), Sun's compiler omits the semicolon
3700 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
3703 struct type
*type
= alloc
.new_type (TYPE_CODE_VOID
,
3704 TARGET_CHAR_BIT
, nullptr);
3706 type
->set_is_unsigned (true);
3712 return init_boolean_type (alloc
, type_bits
, unsigned_type
, NULL
);
3714 return init_integer_type (alloc
, type_bits
, unsigned_type
, NULL
);
3717 static struct type
*
3718 read_sun_floating_type (const char **pp
, int typenums
[2],
3719 struct objfile
*objfile
)
3724 struct type
*rettype
;
3726 /* The first number has more details about the type, for example
3728 details
= read_huge_number (pp
, ';', &nbits
, 0);
3730 return error_type (pp
, objfile
);
3732 /* The second number is the number of bytes occupied by this type. */
3733 nbytes
= read_huge_number (pp
, ';', &nbits
, 0);
3735 return error_type (pp
, objfile
);
3737 nbits
= nbytes
* TARGET_CHAR_BIT
;
3739 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3740 || details
== NF_COMPLEX32
)
3742 rettype
= dbx_init_float_type (objfile
, nbits
/ 2);
3743 return init_complex_type (NULL
, rettype
);
3746 return dbx_init_float_type (objfile
, nbits
);
3749 /* Read a number from the string pointed to by *PP.
3750 The value of *PP is advanced over the number.
3751 If END is nonzero, the character that ends the
3752 number must match END, or an error happens;
3753 and that character is skipped if it does match.
3754 If END is zero, *PP is left pointing to that character.
3756 If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
3757 the number is represented in an octal representation, assume that
3758 it is represented in a 2's complement representation with a size of
3759 TWOS_COMPLEMENT_BITS.
3761 If the number fits in a long, set *BITS to 0 and return the value.
3762 If not, set *BITS to be the number of bits in the number and return 0.
3764 If encounter garbage, set *BITS to -1 and return 0. */
3767 read_huge_number (const char **pp
, int end
, int *bits
,
3768 int twos_complement_bits
)
3770 const char *p
= *pp
;
3779 int twos_complement_representation
= 0;
3787 /* Leading zero means octal. GCC uses this to output values larger
3788 than an int (because that would be hard in decimal). */
3795 /* Skip extra zeros. */
3799 if (sign
> 0 && radix
== 8 && twos_complement_bits
> 0)
3801 /* Octal, possibly signed. Check if we have enough chars for a
3807 while ((c
= *p1
) >= '0' && c
< '8')
3811 if (len
> twos_complement_bits
/ 3
3812 || (twos_complement_bits
% 3 == 0
3813 && len
== twos_complement_bits
/ 3))
3815 /* Ok, we have enough characters for a signed value, check
3816 for signedness by testing if the sign bit is set. */
3817 sign_bit
= (twos_complement_bits
% 3 + 2) % 3;
3819 if (c
& (1 << sign_bit
))
3821 /* Definitely signed. */
3822 twos_complement_representation
= 1;
3828 upper_limit
= LONG_MAX
/ radix
;
3830 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3832 if (n
<= upper_limit
)
3834 if (twos_complement_representation
)
3836 /* Octal, signed, twos complement representation. In
3837 this case, n is the corresponding absolute value. */
3840 long sn
= c
- '0' - ((2 * (c
- '0')) | (2 << sign_bit
));
3852 /* unsigned representation */
3854 n
+= c
- '0'; /* FIXME this overflows anyway. */
3860 /* This depends on large values being output in octal, which is
3867 /* Ignore leading zeroes. */
3871 else if (c
== '2' || c
== '3')
3892 if (radix
== 8 && twos_complement_bits
> 0 && nbits
> twos_complement_bits
)
3894 /* We were supposed to parse a number with maximum
3895 TWOS_COMPLEMENT_BITS bits, but something went wrong. */
3906 /* Large decimal constants are an error (because it is hard to
3907 count how many bits are in them). */
3913 /* -0x7f is the same as 0x80. So deal with it by adding one to
3914 the number of bits. Two's complement represention octals
3915 can't have a '-' in front. */
3916 if (sign
== -1 && !twos_complement_representation
)
3927 /* It's *BITS which has the interesting information. */
3931 static struct type
*
3932 read_range_type (const char **pp
, int typenums
[2], int type_size
,
3933 struct objfile
*objfile
)
3935 struct gdbarch
*gdbarch
= objfile
->arch ();
3936 const char *orig_pp
= *pp
;
3941 struct type
*result_type
;
3942 struct type
*index_type
= NULL
;
3944 /* First comes a type we are a subrange of.
3945 In C it is usually 0, 1 or the type being defined. */
3946 if (read_type_number (pp
, rangenums
) != 0)
3947 return error_type (pp
, objfile
);
3948 self_subrange
= (rangenums
[0] == typenums
[0] &&
3949 rangenums
[1] == typenums
[1]);
3954 index_type
= read_type (pp
, objfile
);
3957 /* A semicolon should now follow; skip it. */
3961 /* The remaining two operands are usually lower and upper bounds
3962 of the range. But in some special cases they mean something else. */
3963 n2
= read_huge_number (pp
, ';', &n2bits
, type_size
);
3964 n3
= read_huge_number (pp
, ';', &n3bits
, type_size
);
3966 if (n2bits
== -1 || n3bits
== -1)
3967 return error_type (pp
, objfile
);
3969 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
3972 goto handle_true_range
;
3974 /* If limits are huge, must be large integral type. */
3975 if (n2bits
!= 0 || n3bits
!= 0)
3977 char got_signed
= 0;
3978 char got_unsigned
= 0;
3979 /* Number of bits in the type. */
3982 /* If a type size attribute has been specified, the bounds of
3983 the range should fit in this size. If the lower bounds needs
3984 more bits than the upper bound, then the type is signed. */
3985 if (n2bits
<= type_size
&& n3bits
<= type_size
)
3987 if (n2bits
== type_size
&& n2bits
> n3bits
)
3993 /* Range from 0 to <large number> is an unsigned large integral type. */
3994 else if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3999 /* Range from <large number> to <large number>-1 is a large signed
4000 integral type. Take care of the case where <large number> doesn't
4001 fit in a long but <large number>-1 does. */
4002 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4003 || (n2bits
!= 0 && n3bits
== 0
4004 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4011 if (got_signed
|| got_unsigned
)
4012 return init_integer_type (alloc
, nbits
, got_unsigned
, NULL
);
4014 return error_type (pp
, objfile
);
4017 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4018 if (self_subrange
&& n2
== 0 && n3
== 0)
4019 return alloc
.new_type (TYPE_CODE_VOID
, TARGET_CHAR_BIT
, nullptr);
4021 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4022 is the width in bytes.
4024 Fortran programs appear to use this for complex types also. To
4025 distinguish between floats and complex, g77 (and others?) seem
4026 to use self-subranges for the complexes, and subranges of int for
4029 Also note that for complexes, g77 sets n2 to the size of one of
4030 the member floats, not the whole complex beast. My guess is that
4031 this was to work well with pre-COMPLEX versions of gdb. */
4033 if (n3
== 0 && n2
> 0)
4035 struct type
*float_type
4036 = dbx_init_float_type (objfile
, n2
* TARGET_CHAR_BIT
);
4039 return init_complex_type (NULL
, float_type
);
4044 /* If the upper bound is -1, it must really be an unsigned integral. */
4046 else if (n2
== 0 && n3
== -1)
4048 int bits
= type_size
;
4052 /* We don't know its size. It is unsigned int or unsigned
4053 long. GCC 2.3.3 uses this for long long too, but that is
4054 just a GDB 3.5 compatibility hack. */
4055 bits
= gdbarch_int_bit (gdbarch
);
4058 return init_integer_type (alloc
, bits
, 1, NULL
);
4061 /* Special case: char is defined (Who knows why) as a subrange of
4062 itself with range 0-127. */
4063 else if (self_subrange
&& n2
== 0 && n3
== 127)
4065 struct type
*type
= init_integer_type (alloc
, TARGET_CHAR_BIT
,
4067 type
->set_has_no_signedness (true);
4070 /* We used to do this only for subrange of self or subrange of int. */
4073 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4074 "unsigned long", and we already checked for that,
4075 so don't need to test for it here. */
4078 /* n3 actually gives the size. */
4079 return init_integer_type (alloc
, -n3
* TARGET_CHAR_BIT
, 1, NULL
);
4081 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4082 unsigned n-byte integer. But do require n to be a power of
4083 two; we don't want 3- and 5-byte integers flying around. */
4089 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4092 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4093 return init_integer_type (alloc
, bytes
* TARGET_CHAR_BIT
, 1, NULL
);
4096 /* I think this is for Convex "long long". Since I don't know whether
4097 Convex sets self_subrange, I also accept that particular size regardless
4098 of self_subrange. */
4099 else if (n3
== 0 && n2
< 0
4101 || n2
== -gdbarch_long_long_bit
4102 (gdbarch
) / TARGET_CHAR_BIT
))
4103 return init_integer_type (alloc
, -n2
* TARGET_CHAR_BIT
, 0, NULL
);
4104 else if (n2
== -n3
- 1)
4107 return init_integer_type (alloc
, 8, 0, NULL
);
4109 return init_integer_type (alloc
, 16, 0, NULL
);
4110 if (n3
== 0x7fffffff)
4111 return init_integer_type (alloc
, 32, 0, NULL
);
4114 /* We have a real range type on our hands. Allocate space and
4115 return a real pointer. */
4119 index_type
= builtin_type (objfile
)->builtin_int
;
4121 index_type
= *dbx_lookup_type (rangenums
, objfile
);
4122 if (index_type
== NULL
)
4124 /* Does this actually ever happen? Is that why we are worrying
4125 about dealing with it rather than just calling error_type? */
4127 complaint (_("base type %d of range type is not defined"), rangenums
[1]);
4129 index_type
= builtin_type (objfile
)->builtin_int
;
4133 = create_static_range_type (alloc
, index_type
, n2
, n3
);
4134 return (result_type
);
4137 /* Read in an argument list. This is a list of types, separated by commas
4138 and terminated with END. Return the list of types read in, or NULL
4139 if there is an error. */
4141 static struct field
*
4142 read_args (const char **pp
, int end
, struct objfile
*objfile
, int *nargsp
,
4145 /* FIXME! Remove this arbitrary limit! */
4146 struct type
*types
[1024]; /* Allow for fns of 1023 parameters. */
4153 /* Invalid argument list: no ','. */
4156 STABS_CONTINUE (pp
, objfile
);
4157 types
[n
++] = read_type (pp
, objfile
);
4159 (*pp
)++; /* get past `end' (the ':' character). */
4163 /* We should read at least the THIS parameter here. Some broken stabs
4164 output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
4165 have been present ";-16,(0,43)" reference instead. This way the
4166 excessive ";" marker prematurely stops the parameters parsing. */
4168 complaint (_("Invalid (empty) method arguments"));
4171 else if (types
[n
- 1]->code () != TYPE_CODE_VOID
)
4179 rval
= XCNEWVEC (struct field
, n
);
4180 for (i
= 0; i
< n
; i
++)
4181 rval
[i
].set_type (types
[i
]);
4186 /* Common block handling. */
4188 /* List of symbols declared since the last BCOMM. This list is a tail
4189 of local_symbols. When ECOMM is seen, the symbols on the list
4190 are noted so their proper addresses can be filled in later,
4191 using the common block base address gotten from the assembler
4194 static struct pending
*common_block
;
4195 static int common_block_i
;
4197 /* Name of the current common block. We get it from the BCOMM instead of the
4198 ECOMM to match IBM documentation (even though IBM puts the name both places
4199 like everyone else). */
4200 static char *common_block_name
;
4202 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4203 to remain after this function returns. */
4206 common_block_start (const char *name
, struct objfile
*objfile
)
4208 if (common_block_name
!= NULL
)
4210 complaint (_("Invalid symbol data: common block within common block"));
4212 common_block
= *get_local_symbols ();
4213 common_block_i
= common_block
? common_block
->nsyms
: 0;
4214 common_block_name
= obstack_strdup (&objfile
->objfile_obstack
, name
);
4217 /* Process a N_ECOMM symbol. */
4220 common_block_end (struct objfile
*objfile
)
4222 /* Symbols declared since the BCOMM are to have the common block
4223 start address added in when we know it. common_block and
4224 common_block_i point to the first symbol after the BCOMM in
4225 the local_symbols list; copy the list and hang it off the
4226 symbol for the common block name for later fixup. */
4229 struct pending
*newobj
= 0;
4230 struct pending
*next
;
4233 if (common_block_name
== NULL
)
4235 complaint (_("ECOMM symbol unmatched by BCOMM"));
4239 sym
= new (&objfile
->objfile_obstack
) symbol
;
4240 /* Note: common_block_name already saved on objfile_obstack. */
4241 sym
->set_linkage_name (common_block_name
);
4242 sym
->set_aclass_index (LOC_BLOCK
);
4244 /* Now we copy all the symbols which have been defined since the BCOMM. */
4246 /* Copy all the struct pendings before common_block. */
4247 for (next
= *get_local_symbols ();
4248 next
!= NULL
&& next
!= common_block
;
4251 for (j
= 0; j
< next
->nsyms
; j
++)
4252 add_symbol_to_list (next
->symbol
[j
], &newobj
);
4255 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4256 NULL, it means copy all the local symbols (which we already did
4259 if (common_block
!= NULL
)
4260 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4261 add_symbol_to_list (common_block
->symbol
[j
], &newobj
);
4263 sym
->set_type ((struct type
*) newobj
);
4265 /* Should we be putting local_symbols back to what it was?
4268 i
= hashname (sym
->linkage_name ());
4269 sym
->set_value_chain (global_sym_chain
[i
]);
4270 global_sym_chain
[i
] = sym
;
4271 common_block_name
= NULL
;
4274 /* Add a common block's start address to the offset of each symbol
4275 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4276 the common block name). */
4279 fix_common_block (struct symbol
*sym
, CORE_ADDR valu
, int section_index
)
4281 struct pending
*next
= (struct pending
*) sym
->type ();
4283 for (; next
; next
= next
->next
)
4287 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4289 next
->symbol
[j
]->set_value_address
4290 (next
->symbol
[j
]->value_address () + valu
);
4291 next
->symbol
[j
]->set_section_index (section_index
);
4298 /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
4299 See add_undefined_type for more details. */
4302 add_undefined_type_noname (struct type
*type
, int typenums
[2])
4306 nat
.typenums
[0] = typenums
[0];
4307 nat
.typenums
[1] = typenums
[1];
4310 if (noname_undefs_length
== noname_undefs_allocated
)
4312 noname_undefs_allocated
*= 2;
4313 noname_undefs
= (struct nat
*)
4314 xrealloc ((char *) noname_undefs
,
4315 noname_undefs_allocated
* sizeof (struct nat
));
4317 noname_undefs
[noname_undefs_length
++] = nat
;
4320 /* Add TYPE to the UNDEF_TYPES vector.
4321 See add_undefined_type for more details. */
4324 add_undefined_type_1 (struct type
*type
)
4326 if (undef_types_length
== undef_types_allocated
)
4328 undef_types_allocated
*= 2;
4329 undef_types
= (struct type
**)
4330 xrealloc ((char *) undef_types
,
4331 undef_types_allocated
* sizeof (struct type
*));
4333 undef_types
[undef_types_length
++] = type
;
4336 /* What about types defined as forward references inside of a small lexical
4338 /* Add a type to the list of undefined types to be checked through
4339 once this file has been read in.
4341 In practice, we actually maintain two such lists: The first list
4342 (UNDEF_TYPES) is used for types whose name has been provided, and
4343 concerns forward references (eg 'xs' or 'xu' forward references);
4344 the second list (NONAME_UNDEFS) is used for types whose name is
4345 unknown at creation time, because they were referenced through
4346 their type number before the actual type was declared.
4347 This function actually adds the given type to the proper list. */
4350 add_undefined_type (struct type
*type
, int typenums
[2])
4352 if (type
->name () == NULL
)
4353 add_undefined_type_noname (type
, typenums
);
4355 add_undefined_type_1 (type
);
4358 /* Try to fix all undefined types pushed on the UNDEF_TYPES vector. */
4361 cleanup_undefined_types_noname (struct objfile
*objfile
)
4365 for (i
= 0; i
< noname_undefs_length
; i
++)
4367 struct nat nat
= noname_undefs
[i
];
4370 type
= dbx_lookup_type (nat
.typenums
, objfile
);
4371 if (nat
.type
!= *type
&& (*type
)->code () != TYPE_CODE_UNDEF
)
4373 /* The instance flags of the undefined type are still unset,
4374 and needs to be copied over from the reference type.
4375 Since replace_type expects them to be identical, we need
4376 to set these flags manually before hand. */
4377 nat
.type
->set_instance_flags ((*type
)->instance_flags ());
4378 replace_type (nat
.type
, *type
);
4382 noname_undefs_length
= 0;
4385 /* Go through each undefined type, see if it's still undefined, and fix it
4386 up if possible. We have two kinds of undefined types:
4388 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4389 Fix: update array length using the element bounds
4390 and the target type's length.
4391 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4392 yet defined at the time a pointer to it was made.
4393 Fix: Do a full lookup on the struct/union tag. */
4396 cleanup_undefined_types_1 (void)
4400 /* Iterate over every undefined type, and look for a symbol whose type
4401 matches our undefined type. The symbol matches if:
4402 1. It is a typedef in the STRUCT domain;
4403 2. It has the same name, and same type code;
4404 3. The instance flags are identical.
4406 It is important to check the instance flags, because we have seen
4407 examples where the debug info contained definitions such as:
4409 "foo_t:t30=B31=xefoo_t:"
4411 In this case, we have created an undefined type named "foo_t" whose
4412 instance flags is null (when processing "xefoo_t"), and then created
4413 another type with the same name, but with different instance flags
4414 ('B' means volatile). I think that the definition above is wrong,
4415 since the same type cannot be volatile and non-volatile at the same
4416 time, but we need to be able to cope with it when it happens. The
4417 approach taken here is to treat these two types as different. */
4419 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4421 switch ((*type
)->code ())
4424 case TYPE_CODE_STRUCT
:
4425 case TYPE_CODE_UNION
:
4426 case TYPE_CODE_ENUM
:
4428 /* Check if it has been defined since. Need to do this here
4429 as well as in check_typedef to deal with the (legitimate in
4430 C though not C++) case of several types with the same name
4431 in different source files. */
4432 if ((*type
)->is_stub ())
4434 struct pending
*ppt
;
4436 /* Name of the type, without "struct" or "union". */
4437 const char *type_name
= (*type
)->name ();
4439 if (type_name
== NULL
)
4441 complaint (_("need a type name"));
4444 for (ppt
= *get_file_symbols (); ppt
; ppt
= ppt
->next
)
4446 for (i
= 0; i
< ppt
->nsyms
; i
++)
4448 struct symbol
*sym
= ppt
->symbol
[i
];
4450 if (sym
->aclass () == LOC_TYPEDEF
4451 && sym
->domain () == STRUCT_DOMAIN
4452 && (sym
->type ()->code () == (*type
)->code ())
4453 && ((*type
)->instance_flags ()
4454 == sym
->type ()->instance_flags ())
4455 && strcmp (sym
->linkage_name (), type_name
) == 0)
4456 replace_type (*type
, sym
->type ());
4465 complaint (_("forward-referenced types left unresolved, "
4473 undef_types_length
= 0;
4476 /* Try to fix all the undefined types we encountered while processing
4480 cleanup_undefined_stabs_types (struct objfile
*objfile
)
4482 cleanup_undefined_types_1 ();
4483 cleanup_undefined_types_noname (objfile
);
4486 /* See stabsread.h. */
4489 scan_file_globals (struct objfile
*objfile
)
4492 struct symbol
*sym
, *prev
;
4493 struct objfile
*resolve_objfile
;
4495 /* SVR4 based linkers copy referenced global symbols from shared
4496 libraries to the main executable.
4497 If we are scanning the symbols for a shared library, try to resolve
4498 them from the minimal symbols of the main executable first. */
4500 if (current_program_space
->symfile_object_file
4501 && objfile
!= current_program_space
->symfile_object_file
)
4502 resolve_objfile
= current_program_space
->symfile_object_file
;
4504 resolve_objfile
= objfile
;
4508 /* Avoid expensive loop through all minimal symbols if there are
4509 no unresolved symbols. */
4510 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4512 if (global_sym_chain
[hash
])
4515 if (hash
>= HASHSIZE
)
4518 for (minimal_symbol
*msymbol
: resolve_objfile
->msymbols ())
4522 /* Skip static symbols. */
4523 switch (msymbol
->type ())
4535 /* Get the hash index and check all the symbols
4536 under that hash index. */
4538 hash
= hashname (msymbol
->linkage_name ());
4540 for (sym
= global_sym_chain
[hash
]; sym
;)
4542 if (strcmp (msymbol
->linkage_name (), sym
->linkage_name ()) == 0)
4544 /* Splice this symbol out of the hash chain and
4545 assign the value we have to it. */
4548 prev
->set_value_chain (sym
->value_chain ());
4552 global_sym_chain
[hash
] = sym
->value_chain ();
4555 /* Check to see whether we need to fix up a common block. */
4556 /* Note: this code might be executed several times for
4557 the same symbol if there are multiple references. */
4560 if (sym
->aclass () == LOC_BLOCK
)
4562 (sym
, msymbol
->value_address (resolve_objfile
),
4563 msymbol
->section_index ());
4565 sym
->set_value_address
4566 (msymbol
->value_address (resolve_objfile
));
4567 sym
->set_section_index (msymbol
->section_index ());
4572 sym
= prev
->value_chain ();
4576 sym
= global_sym_chain
[hash
];
4582 sym
= sym
->value_chain ();
4586 if (resolve_objfile
== objfile
)
4588 resolve_objfile
= objfile
;
4591 /* Change the storage class of any remaining unresolved globals to
4592 LOC_UNRESOLVED and remove them from the chain. */
4593 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4595 sym
= global_sym_chain
[hash
];
4599 sym
= sym
->value_chain ();
4601 /* Change the symbol address from the misleading chain value
4603 prev
->set_value_address (0);
4605 /* Complain about unresolved common block symbols. */
4606 if (prev
->aclass () == LOC_STATIC
)
4607 prev
->set_aclass_index (LOC_UNRESOLVED
);
4609 complaint (_("%s: common block `%s' from "
4610 "global_sym_chain unresolved"),
4611 objfile_name (objfile
), prev
->print_name ());
4614 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4617 /* Initialize anything that needs initializing when starting to read
4618 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4622 stabsread_init (void)
4626 /* Initialize anything that needs initializing when a completely new
4627 symbol file is specified (not just adding some symbols from another
4628 file, e.g. a shared library). */
4631 stabsread_new_init (void)
4633 /* Empty the hash table of global syms looking for values. */
4634 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4637 /* Initialize anything that needs initializing at the same time as
4638 start_compunit_symtab() is called. */
4643 global_stabs
= NULL
; /* AIX COFF */
4644 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4645 n_this_object_header_files
= 1;
4646 type_vector_length
= 0;
4647 type_vector
= (struct type
**) 0;
4648 within_function
= 0;
4650 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4651 common_block_name
= NULL
;
4654 /* Call after end_compunit_symtab(). */
4661 xfree (type_vector
);
4664 type_vector_length
= 0;
4665 previous_stab_code
= 0;
4669 finish_global_stabs (struct objfile
*objfile
)
4673 patch_block_stabs (*get_global_symbols (), global_stabs
, objfile
);
4674 xfree (global_stabs
);
4675 global_stabs
= NULL
;
4679 /* Find the end of the name, delimited by a ':', but don't match
4680 ObjC symbols which look like -[Foo bar::]:bla. */
4682 find_name_end (const char *name
)
4684 const char *s
= name
;
4686 if (s
[0] == '-' || *s
== '+')
4688 /* Must be an ObjC method symbol. */
4691 error (_("invalid symbol name \"%s\""), name
);
4693 s
= strchr (s
, ']');
4696 error (_("invalid symbol name \"%s\""), name
);
4698 return strchr (s
, ':');
4702 return strchr (s
, ':');
4706 /* See stabsread.h. */
4709 hashname (const char *name
)
4711 return fast_hash (name
, strlen (name
)) % HASHSIZE
;
4714 /* Initializer for this module. */
4716 void _initialize_stabsread ();
4718 _initialize_stabsread ()
4720 undef_types_allocated
= 20;
4721 undef_types_length
= 0;
4722 undef_types
= XNEWVEC (struct type
*, undef_types_allocated
);
4724 noname_undefs_allocated
= 20;
4725 noname_undefs_length
= 0;
4726 noname_undefs
= XNEWVEC (struct nat
, noname_undefs_allocated
);
4728 stab_register_index
= register_symbol_register_impl (LOC_REGISTER
,
4729 &stab_register_funcs
);
4730 stab_regparm_index
= register_symbol_register_impl (LOC_REGPARM_ADDR
,
4731 &stab_register_funcs
);