]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support routines for decoding "stabs" debugging information format. |
cf5b2f1b | 2 | |
213516ef | 3 | Copyright (C) 1986-2023 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | /* Support routines for reading and decoding debugging information in | |
1736a7bd PA |
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 | |
25 | this file. */ | |
c906108c SS |
26 | |
27 | #include "defs.h" | |
c906108c | 28 | #include "bfd.h" |
bf31fd38 | 29 | #include "gdbsupport/gdb_obstack.h" |
c906108c SS |
30 | #include "symtab.h" |
31 | #include "gdbtypes.h" | |
32 | #include "expression.h" | |
33 | #include "symfile.h" | |
34 | #include "objfiles.h" | |
3e43a32a | 35 | #include "aout/stab_gnu.h" /* We always use GNU stabs, not native. */ |
c906108c SS |
36 | #include "libaout.h" |
37 | #include "aout/aout64.h" | |
38 | #include "gdb-stabs.h" | |
0baae8db | 39 | #include "buildsym-legacy.h" |
c906108c SS |
40 | #include "complaints.h" |
41 | #include "demangle.h" | |
50f182aa | 42 | #include "gdb-demangle.h" |
c906108c | 43 | #include "language.h" |
f69fdf9b | 44 | #include "target-float.h" |
bad5c026 | 45 | #include "c-lang.h" |
de17c821 DJ |
46 | #include "cp-abi.h" |
47 | #include "cp-support.h" | |
c906108c SS |
48 | #include <ctype.h> |
49 | ||
d65d5705 TT |
50 | #include "stabsread.h" |
51 | ||
52 | /* See stabsread.h for these globals. */ | |
53 | unsigned int symnum; | |
54 | const char *(*next_symbol_text_func) (struct objfile *); | |
55 | unsigned char processing_gcc_compilation; | |
56 | int within_function; | |
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; | |
c906108c | 63 | |
7e9d9756 | 64 | struct stabs_nextfield |
52059ffd | 65 | { |
7e9d9756 | 66 | struct stabs_nextfield *next; |
52059ffd TT |
67 | |
68 | /* This is the raw visibility from the stab. It is not checked | |
69 | for being one of the visibilities we recognize, so code which | |
70 | examines this field better be able to deal. */ | |
71 | int visibility; | |
72 | ||
73 | struct field field; | |
74 | }; | |
75 | ||
76 | struct next_fnfieldlist | |
77 | { | |
78 | struct next_fnfieldlist *next; | |
79 | struct fn_fieldlist fn_fieldlist; | |
80 | }; | |
81 | ||
c906108c SS |
82 | /* The routines that read and process a complete stabs for a C struct or |
83 | C++ class pass lists of data member fields and lists of member function | |
84 | fields in an instance of a field_info structure, as defined below. | |
85 | This is part of some reorganization of low level C++ support and is | |
c378eb4e | 86 | expected to eventually go away... (FIXME) */ |
c906108c | 87 | |
61b30099 | 88 | struct stab_field_info |
c5aa993b | 89 | { |
7e9d9756 | 90 | struct stabs_nextfield *list = nullptr; |
61b30099 TT |
91 | struct next_fnfieldlist *fnlist = nullptr; |
92 | ||
93 | auto_obstack obstack; | |
c5aa993b | 94 | }; |
c906108c SS |
95 | |
96 | static void | |
61b30099 | 97 | read_one_struct_field (struct stab_field_info *, const char **, const char *, |
a14ed312 | 98 | struct type *, struct objfile *); |
c906108c | 99 | |
a14ed312 | 100 | static struct type *dbx_alloc_type (int[2], struct objfile *); |
c906108c | 101 | |
a121b7c1 | 102 | static long read_huge_number (const char **, int, int *, int); |
c906108c | 103 | |
a121b7c1 | 104 | static struct type *error_type (const char **, struct objfile *); |
c906108c SS |
105 | |
106 | static void | |
a14ed312 KB |
107 | patch_block_stabs (struct pending *, struct pending_stabs *, |
108 | struct objfile *); | |
c906108c | 109 | |
a121b7c1 | 110 | static int read_type_number (const char **, int *); |
c906108c | 111 | |
a121b7c1 | 112 | static struct type *read_type (const char **, struct objfile *); |
a7a48797 | 113 | |
a121b7c1 PA |
114 | static struct type *read_range_type (const char **, int[2], |
115 | int, struct objfile *); | |
c906108c | 116 | |
a121b7c1 PA |
117 | static struct type *read_sun_builtin_type (const char **, |
118 | int[2], struct objfile *); | |
c906108c | 119 | |
a121b7c1 | 120 | static struct type *read_sun_floating_type (const char **, int[2], |
a14ed312 | 121 | struct objfile *); |
c906108c | 122 | |
a121b7c1 | 123 | static struct type *read_enum_type (const char **, struct type *, struct objfile *); |
c906108c | 124 | |
46bf5051 | 125 | static struct type *rs6000_builtin_type (int, struct objfile *); |
c906108c SS |
126 | |
127 | static int | |
61b30099 | 128 | read_member_functions (struct stab_field_info *, const char **, struct type *, |
a14ed312 | 129 | struct objfile *); |
c906108c SS |
130 | |
131 | static int | |
61b30099 | 132 | read_struct_fields (struct stab_field_info *, const char **, struct type *, |
a14ed312 | 133 | struct objfile *); |
c906108c SS |
134 | |
135 | static int | |
61b30099 | 136 | read_baseclasses (struct stab_field_info *, const char **, struct type *, |
a14ed312 | 137 | struct objfile *); |
c906108c SS |
138 | |
139 | static int | |
61b30099 | 140 | read_tilde_fields (struct stab_field_info *, const char **, struct type *, |
a14ed312 | 141 | struct objfile *); |
c906108c | 142 | |
61b30099 | 143 | static int attach_fn_fields_to_type (struct stab_field_info *, struct type *); |
c906108c | 144 | |
61b30099 | 145 | static int attach_fields_to_type (struct stab_field_info *, struct type *, |
570b8f7c | 146 | struct objfile *); |
c906108c | 147 | |
a121b7c1 | 148 | static struct type *read_struct_type (const char **, struct type *, |
dda83cd7 | 149 | enum type_code, |
a14ed312 | 150 | struct objfile *); |
c906108c | 151 | |
a121b7c1 | 152 | static struct type *read_array_type (const char **, struct type *, |
a14ed312 | 153 | struct objfile *); |
c906108c | 154 | |
a121b7c1 PA |
155 | static struct field *read_args (const char **, int, struct objfile *, |
156 | int *, int *); | |
c906108c | 157 | |
bf362611 | 158 | static void add_undefined_type (struct type *, int[2]); |
a7a48797 | 159 | |
c906108c | 160 | static int |
61b30099 | 161 | read_cpp_abbrev (struct stab_field_info *, const char **, struct type *, |
a14ed312 | 162 | struct objfile *); |
c906108c | 163 | |
a121b7c1 | 164 | static const char *find_name_end (const char *name); |
7e1d63ec | 165 | |
a121b7c1 | 166 | static int process_reference (const char **string); |
c906108c | 167 | |
a14ed312 | 168 | void stabsread_clear_cache (void); |
7be570e7 | 169 | |
8343f86c DJ |
170 | static const char vptr_name[] = "_vptr$"; |
171 | static const char vb_name[] = "_vb$"; | |
c906108c | 172 | |
23136709 KB |
173 | static void |
174 | invalid_cpp_abbrev_complaint (const char *arg1) | |
175 | { | |
b98664d3 | 176 | complaint (_("invalid C++ abbreviation `%s'"), arg1); |
23136709 | 177 | } |
c906108c | 178 | |
23136709 | 179 | static void |
49b0b195 | 180 | reg_value_complaint (int regnum, int num_regs, const char *sym) |
23136709 | 181 | { |
b98664d3 | 182 | complaint (_("bad register number %d (max %d) in symbol %s"), |
dda83cd7 | 183 | regnum, num_regs - 1, sym); |
23136709 | 184 | } |
c906108c | 185 | |
23136709 KB |
186 | static void |
187 | stabs_general_complaint (const char *arg1) | |
188 | { | |
b98664d3 | 189 | complaint ("%s", arg1); |
23136709 | 190 | } |
c906108c | 191 | |
c906108c SS |
192 | /* Make a list of forward references which haven't been defined. */ |
193 | ||
194 | static struct type **undef_types; | |
195 | static int undef_types_allocated; | |
196 | static int undef_types_length; | |
197 | static struct symbol *current_symbol = NULL; | |
198 | ||
bf362611 JB |
199 | /* Make a list of nameless types that are undefined. |
200 | This happens when another type is referenced by its number | |
c378eb4e | 201 | before this type is actually defined. For instance "t(0,1)=k(0,2)" |
bf362611 JB |
202 | and type (0,2) is defined only later. */ |
203 | ||
204 | struct nat | |
205 | { | |
206 | int typenums[2]; | |
207 | struct type *type; | |
208 | }; | |
209 | static struct nat *noname_undefs; | |
210 | static int noname_undefs_allocated; | |
211 | static int noname_undefs_length; | |
212 | ||
c906108c SS |
213 | /* Check for and handle cretinous stabs symbol name continuation! */ |
214 | #define STABS_CONTINUE(pp,objfile) \ | |
215 | do { \ | |
216 | if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \ | |
217 | *(pp) = next_symbol_text (objfile); \ | |
218 | } while (0) | |
fc474241 DE |
219 | |
220 | /* Vector of types defined so far, indexed by their type numbers. | |
221 | (In newer sun systems, dbx uses a pair of numbers in parens, | |
222 | as in "(SUBFILENUM,NUMWITHINSUBFILE)". | |
223 | Then these numbers must be translated through the type_translations | |
224 | hash table to get the index into the type vector.) */ | |
225 | ||
226 | static struct type **type_vector; | |
227 | ||
228 | /* Number of elements allocated for type_vector currently. */ | |
229 | ||
230 | static int type_vector_length; | |
231 | ||
232 | /* Initial size of type vector. Is realloc'd larger if needed, and | |
233 | realloc'd down to the size actually used, when completed. */ | |
234 | ||
235 | #define INITIAL_TYPE_VECTOR_LENGTH 160 | |
c906108c | 236 | \f |
c906108c SS |
237 | |
238 | /* Look up a dbx type-number pair. Return the address of the slot | |
239 | where the type for that number-pair is stored. | |
240 | The number-pair is in TYPENUMS. | |
241 | ||
242 | This can be used for finding the type associated with that pair | |
243 | or for associating a new type with the pair. */ | |
244 | ||
a7a48797 | 245 | static struct type ** |
46bf5051 | 246 | dbx_lookup_type (int typenums[2], struct objfile *objfile) |
c906108c | 247 | { |
52f0bd74 AC |
248 | int filenum = typenums[0]; |
249 | int index = typenums[1]; | |
c906108c | 250 | unsigned old_len; |
52f0bd74 AC |
251 | int real_filenum; |
252 | struct header_file *f; | |
c906108c SS |
253 | int f_orig_length; |
254 | ||
255 | if (filenum == -1) /* -1,-1 is for temporary types. */ | |
256 | return 0; | |
257 | ||
258 | if (filenum < 0 || filenum >= n_this_object_header_files) | |
259 | { | |
b98664d3 | 260 | complaint (_("Invalid symbol data: type number " |
3e43a32a | 261 | "(%d,%d) out of range at symtab pos %d."), |
23136709 | 262 | filenum, index, symnum); |
c906108c SS |
263 | goto error_return; |
264 | } | |
265 | ||
266 | if (filenum == 0) | |
267 | { | |
268 | if (index < 0) | |
269 | { | |
270 | /* Caller wants address of address of type. We think | |
271 | that negative (rs6k builtin) types will never appear as | |
272 | "lvalues", (nor should they), so we stuff the real type | |
273 | pointer into a temp, and return its address. If referenced, | |
274 | this will do the right thing. */ | |
275 | static struct type *temp_type; | |
276 | ||
46bf5051 | 277 | temp_type = rs6000_builtin_type (index, objfile); |
c906108c SS |
278 | return &temp_type; |
279 | } | |
280 | ||
281 | /* Type is defined outside of header files. | |
dda83cd7 | 282 | Find it in this object file's type vector. */ |
c906108c SS |
283 | if (index >= type_vector_length) |
284 | { | |
285 | old_len = type_vector_length; | |
286 | if (old_len == 0) | |
287 | { | |
288 | type_vector_length = INITIAL_TYPE_VECTOR_LENGTH; | |
8d749320 | 289 | type_vector = XNEWVEC (struct type *, type_vector_length); |
c906108c SS |
290 | } |
291 | while (index >= type_vector_length) | |
292 | { | |
293 | type_vector_length *= 2; | |
294 | } | |
295 | type_vector = (struct type **) | |
296 | xrealloc ((char *) type_vector, | |
297 | (type_vector_length * sizeof (struct type *))); | |
298 | memset (&type_vector[old_len], 0, | |
299 | (type_vector_length - old_len) * sizeof (struct type *)); | |
c906108c SS |
300 | } |
301 | return (&type_vector[index]); | |
302 | } | |
303 | else | |
304 | { | |
305 | real_filenum = this_object_header_files[filenum]; | |
306 | ||
46bf5051 | 307 | if (real_filenum >= N_HEADER_FILES (objfile)) |
c906108c | 308 | { |
46bf5051 | 309 | static struct type *temp_type; |
c906108c | 310 | |
8a3fe4f8 | 311 | warning (_("GDB internal error: bad real_filenum")); |
c906108c SS |
312 | |
313 | error_return: | |
46bf5051 UW |
314 | temp_type = objfile_type (objfile)->builtin_error; |
315 | return &temp_type; | |
c906108c SS |
316 | } |
317 | ||
46bf5051 | 318 | f = HEADER_FILES (objfile) + real_filenum; |
c906108c SS |
319 | |
320 | f_orig_length = f->length; | |
321 | if (index >= f_orig_length) | |
322 | { | |
323 | while (index >= f->length) | |
324 | { | |
325 | f->length *= 2; | |
326 | } | |
327 | f->vector = (struct type **) | |
328 | xrealloc ((char *) f->vector, f->length * sizeof (struct type *)); | |
329 | memset (&f->vector[f_orig_length], 0, | |
330 | (f->length - f_orig_length) * sizeof (struct type *)); | |
331 | } | |
332 | return (&f->vector[index]); | |
333 | } | |
334 | } | |
335 | ||
336 | /* Make sure there is a type allocated for type numbers TYPENUMS | |
337 | and return the type object. | |
338 | This can create an empty (zeroed) type object. | |
339 | TYPENUMS may be (-1, -1) to return a new type object that is not | |
c378eb4e | 340 | put into the type vector, and so may not be referred to by number. */ |
c906108c SS |
341 | |
342 | static struct type * | |
35a2f538 | 343 | dbx_alloc_type (int typenums[2], struct objfile *objfile) |
c906108c | 344 | { |
52f0bd74 | 345 | struct type **type_addr; |
c906108c SS |
346 | |
347 | if (typenums[0] == -1) | |
348 | { | |
8a17bdd9 | 349 | return type_allocator (objfile).new_type (); |
c906108c SS |
350 | } |
351 | ||
46bf5051 | 352 | type_addr = dbx_lookup_type (typenums, objfile); |
c906108c SS |
353 | |
354 | /* If we are referring to a type not known at all yet, | |
355 | allocate an empty type for it. | |
356 | We will fill it in later if we find out how. */ | |
357 | if (*type_addr == 0) | |
358 | { | |
8a17bdd9 | 359 | *type_addr = type_allocator (objfile).new_type (); |
c906108c SS |
360 | } |
361 | ||
362 | return (*type_addr); | |
363 | } | |
364 | ||
9b790ce7 UW |
365 | /* Allocate a floating-point type of size BITS. */ |
366 | ||
367 | static struct type * | |
368 | dbx_init_float_type (struct objfile *objfile, int bits) | |
369 | { | |
08feed99 | 370 | struct gdbarch *gdbarch = objfile->arch (); |
9b790ce7 UW |
371 | const struct floatformat **format; |
372 | struct type *type; | |
373 | ||
374 | format = gdbarch_floatformat_for_type (gdbarch, NULL, bits); | |
33385940 | 375 | type_allocator alloc (objfile); |
9b790ce7 | 376 | if (format) |
77c5f496 | 377 | type = init_float_type (alloc, bits, NULL, format); |
9b790ce7 | 378 | else |
33385940 | 379 | type = alloc.new_type (TYPE_CODE_ERROR, bits, NULL); |
9b790ce7 UW |
380 | |
381 | return type; | |
382 | } | |
383 | ||
c906108c | 384 | /* for all the stabs in a given stab vector, build appropriate types |
c378eb4e | 385 | and fix their symbols in given symbol vector. */ |
c906108c SS |
386 | |
387 | static void | |
fba45db2 KB |
388 | patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs, |
389 | struct objfile *objfile) | |
c906108c SS |
390 | { |
391 | int ii; | |
392 | char *name; | |
a121b7c1 | 393 | const char *pp; |
c906108c SS |
394 | struct symbol *sym; |
395 | ||
396 | if (stabs) | |
397 | { | |
c906108c | 398 | /* for all the stab entries, find their corresponding symbols and |
dda83cd7 | 399 | patch their types! */ |
c5aa993b | 400 | |
c906108c SS |
401 | for (ii = 0; ii < stabs->count; ++ii) |
402 | { | |
403 | name = stabs->stab[ii]; | |
c5aa993b | 404 | pp = (char *) strchr (name, ':'); |
8fb822e0 | 405 | gdb_assert (pp); /* Must find a ':' or game's over. */ |
c906108c SS |
406 | while (pp[1] == ':') |
407 | { | |
c5aa993b JM |
408 | pp += 2; |
409 | pp = (char *) strchr (pp, ':'); | |
c906108c | 410 | } |
c5aa993b | 411 | sym = find_symbol_in_list (symbols, name, pp - name); |
c906108c SS |
412 | if (!sym) |
413 | { | |
414 | /* FIXME-maybe: it would be nice if we noticed whether | |
dda83cd7 SM |
415 | the variable was defined *anywhere*, not just whether |
416 | it is defined in this compilation unit. But neither | |
417 | xlc or GCC seem to need such a definition, and until | |
418 | we do psymtabs (so that the minimal symbols from all | |
419 | compilation units are available now), I'm not sure | |
420 | how to get the information. */ | |
c906108c SS |
421 | |
422 | /* On xcoff, if a global is defined and never referenced, | |
dda83cd7 SM |
423 | ld will remove it from the executable. There is then |
424 | a N_GSYM stab for it, but no regular (C_EXT) symbol. */ | |
8c14c3a3 | 425 | sym = new (&objfile->objfile_obstack) symbol; |
6c9c307c | 426 | sym->set_domain (VAR_DOMAIN); |
ba44b1a3 | 427 | sym->set_aclass_index (LOC_OPTIMIZED_OUT); |
43678b0a CB |
428 | sym->set_linkage_name |
429 | (obstack_strndup (&objfile->objfile_obstack, name, pp - name)); | |
c906108c | 430 | pp += 2; |
c5aa993b | 431 | if (*(pp - 1) == 'F' || *(pp - 1) == 'f') |
c906108c SS |
432 | { |
433 | /* I don't think the linker does this with functions, | |
434 | so as far as I know this is never executed. | |
435 | But it doesn't hurt to check. */ | |
5f9c5a63 SM |
436 | sym->set_type |
437 | (lookup_function_type (read_type (&pp, objfile))); | |
c906108c SS |
438 | } |
439 | else | |
440 | { | |
5f9c5a63 | 441 | sym->set_type (read_type (&pp, objfile)); |
c906108c | 442 | } |
e148f09d | 443 | add_symbol_to_list (sym, get_global_symbols ()); |
c906108c SS |
444 | } |
445 | else | |
446 | { | |
447 | pp += 2; | |
c5aa993b | 448 | if (*(pp - 1) == 'F' || *(pp - 1) == 'f') |
c906108c | 449 | { |
5f9c5a63 SM |
450 | sym->set_type |
451 | (lookup_function_type (read_type (&pp, objfile))); | |
c906108c SS |
452 | } |
453 | else | |
454 | { | |
5f9c5a63 | 455 | sym->set_type (read_type (&pp, objfile)); |
c906108c SS |
456 | } |
457 | } | |
458 | } | |
459 | } | |
460 | } | |
c906108c | 461 | \f |
c5aa993b | 462 | |
c906108c SS |
463 | /* Read a number by which a type is referred to in dbx data, |
464 | or perhaps read a pair (FILENUM, TYPENUM) in parentheses. | |
465 | Just a single number N is equivalent to (0,N). | |
466 | Return the two numbers by storing them in the vector TYPENUMS. | |
467 | TYPENUMS will then be used as an argument to dbx_lookup_type. | |
468 | ||
469 | Returns 0 for success, -1 for error. */ | |
470 | ||
471 | static int | |
a121b7c1 | 472 | read_type_number (const char **pp, int *typenums) |
c906108c SS |
473 | { |
474 | int nbits; | |
433759f7 | 475 | |
c906108c SS |
476 | if (**pp == '(') |
477 | { | |
478 | (*pp)++; | |
94e10a22 | 479 | typenums[0] = read_huge_number (pp, ',', &nbits, 0); |
c5aa993b JM |
480 | if (nbits != 0) |
481 | return -1; | |
94e10a22 | 482 | typenums[1] = read_huge_number (pp, ')', &nbits, 0); |
c5aa993b JM |
483 | if (nbits != 0) |
484 | return -1; | |
c906108c SS |
485 | } |
486 | else | |
487 | { | |
488 | typenums[0] = 0; | |
94e10a22 | 489 | typenums[1] = read_huge_number (pp, 0, &nbits, 0); |
c5aa993b JM |
490 | if (nbits != 0) |
491 | return -1; | |
c906108c SS |
492 | } |
493 | return 0; | |
494 | } | |
c906108c | 495 | \f |
c5aa993b | 496 | |
c906108c SS |
497 | #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */ |
498 | #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */ | |
499 | #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */ | |
500 | #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */ | |
501 | ||
c906108c | 502 | /* Structure for storing pointers to reference definitions for fast lookup |
c378eb4e | 503 | during "process_later". */ |
c906108c SS |
504 | |
505 | struct ref_map | |
506 | { | |
a121b7c1 | 507 | const char *stabs; |
c906108c SS |
508 | CORE_ADDR value; |
509 | struct symbol *sym; | |
510 | }; | |
511 | ||
512 | #define MAX_CHUNK_REFS 100 | |
513 | #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map)) | |
514 | #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE) | |
515 | ||
c5aa993b | 516 | static struct ref_map *ref_map; |
c906108c | 517 | |
c378eb4e | 518 | /* Ptr to free cell in chunk's linked list. */ |
c5aa993b | 519 | static int ref_count = 0; |
c906108c | 520 | |
c378eb4e | 521 | /* Number of chunks malloced. */ |
c906108c SS |
522 | static int ref_chunk = 0; |
523 | ||
7be570e7 | 524 | /* This file maintains a cache of stabs aliases found in the symbol |
c378eb4e MS |
525 | table. If the symbol table changes, this cache must be cleared |
526 | or we are left holding onto data in invalid obstacks. */ | |
7be570e7 | 527 | void |
fba45db2 | 528 | stabsread_clear_cache (void) |
7be570e7 JM |
529 | { |
530 | ref_count = 0; | |
531 | ref_chunk = 0; | |
532 | } | |
533 | ||
c906108c SS |
534 | /* Create array of pointers mapping refids to symbols and stab strings. |
535 | Add pointers to reference definition symbols and/or their values as we | |
c378eb4e MS |
536 | find them, using their reference numbers as our index. |
537 | These will be used later when we resolve references. */ | |
c906108c | 538 | void |
a121b7c1 | 539 | ref_add (int refnum, struct symbol *sym, const char *stabs, CORE_ADDR value) |
c906108c SS |
540 | { |
541 | if (ref_count == 0) | |
542 | ref_chunk = 0; | |
543 | if (refnum >= ref_count) | |
544 | ref_count = refnum + 1; | |
545 | if (ref_count > ref_chunk * MAX_CHUNK_REFS) | |
546 | { | |
c5aa993b | 547 | int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS; |
c906108c | 548 | int new_chunks = new_slots / MAX_CHUNK_REFS + 1; |
433759f7 | 549 | |
c906108c SS |
550 | ref_map = (struct ref_map *) |
551 | xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks)); | |
433759f7 MS |
552 | memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, |
553 | new_chunks * REF_CHUNK_SIZE); | |
c906108c SS |
554 | ref_chunk += new_chunks; |
555 | } | |
556 | ref_map[refnum].stabs = stabs; | |
557 | ref_map[refnum].sym = sym; | |
558 | ref_map[refnum].value = value; | |
559 | } | |
560 | ||
561 | /* Return defined sym for the reference REFNUM. */ | |
562 | struct symbol * | |
fba45db2 | 563 | ref_search (int refnum) |
c906108c SS |
564 | { |
565 | if (refnum < 0 || refnum > ref_count) | |
566 | return 0; | |
567 | return ref_map[refnum].sym; | |
568 | } | |
569 | ||
c906108c SS |
570 | /* Parse a reference id in STRING and return the resulting |
571 | reference number. Move STRING beyond the reference id. */ | |
572 | ||
c5aa993b | 573 | static int |
a121b7c1 | 574 | process_reference (const char **string) |
c906108c | 575 | { |
a121b7c1 | 576 | const char *p; |
c906108c SS |
577 | int refnum = 0; |
578 | ||
c5aa993b JM |
579 | if (**string != '#') |
580 | return 0; | |
581 | ||
c906108c SS |
582 | /* Advance beyond the initial '#'. */ |
583 | p = *string + 1; | |
584 | ||
c378eb4e | 585 | /* Read number as reference id. */ |
c906108c SS |
586 | while (*p && isdigit (*p)) |
587 | { | |
588 | refnum = refnum * 10 + *p - '0'; | |
589 | p++; | |
590 | } | |
591 | *string = p; | |
592 | return refnum; | |
593 | } | |
594 | ||
595 | /* If STRING defines a reference, store away a pointer to the reference | |
596 | definition for later use. Return the reference number. */ | |
597 | ||
598 | int | |
a121b7c1 | 599 | symbol_reference_defined (const char **string) |
c906108c | 600 | { |
a121b7c1 | 601 | const char *p = *string; |
c906108c SS |
602 | int refnum = 0; |
603 | ||
604 | refnum = process_reference (&p); | |
605 | ||
c378eb4e | 606 | /* Defining symbols end in '='. */ |
c5aa993b | 607 | if (*p == '=') |
c906108c | 608 | { |
c378eb4e | 609 | /* Symbol is being defined here. */ |
c906108c SS |
610 | *string = p + 1; |
611 | return refnum; | |
612 | } | |
613 | else | |
614 | { | |
c378eb4e | 615 | /* Must be a reference. Either the symbol has already been defined, |
dda83cd7 | 616 | or this is a forward reference to it. */ |
c906108c SS |
617 | *string = p; |
618 | return -1; | |
619 | } | |
620 | } | |
621 | ||
768a979c UW |
622 | static int |
623 | stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch) | |
624 | { | |
4aeddc50 | 625 | int regno = gdbarch_stab_reg_to_regnum (gdbarch, sym->value_longest ()); |
768a979c | 626 | |
f6efe3f8 | 627 | if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch)) |
768a979c | 628 | { |
f6efe3f8 | 629 | reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch), |
987012b8 | 630 | sym->print_name ()); |
768a979c | 631 | |
c378eb4e | 632 | regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless. */ |
768a979c UW |
633 | } |
634 | ||
635 | return regno; | |
636 | } | |
637 | ||
638 | static const struct symbol_register_ops stab_register_funcs = { | |
639 | stab_reg_to_regnum | |
640 | }; | |
641 | ||
f1e6e072 TT |
642 | /* The "aclass" indices for computed symbols. */ |
643 | ||
644 | static int stab_register_index; | |
645 | static int stab_regparm_index; | |
646 | ||
c906108c | 647 | struct symbol * |
a121b7c1 | 648 | define_symbol (CORE_ADDR valu, const char *string, int desc, int type, |
fba45db2 | 649 | struct objfile *objfile) |
c906108c | 650 | { |
08feed99 | 651 | struct gdbarch *gdbarch = objfile->arch (); |
52f0bd74 | 652 | struct symbol *sym; |
a121b7c1 | 653 | const char *p = find_name_end (string); |
c906108c SS |
654 | int deftype; |
655 | int synonym = 0; | |
52f0bd74 | 656 | int i; |
c906108c SS |
657 | |
658 | /* We would like to eliminate nameless symbols, but keep their types. | |
659 | E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer | |
c378eb4e MS |
660 | to type 2, but, should not create a symbol to address that type. Since |
661 | the symbol will be nameless, there is no way any user can refer to it. */ | |
c906108c SS |
662 | |
663 | int nameless; | |
664 | ||
665 | /* Ignore syms with empty names. */ | |
666 | if (string[0] == 0) | |
667 | return 0; | |
668 | ||
c378eb4e | 669 | /* Ignore old-style symbols from cc -go. */ |
c906108c SS |
670 | if (p == 0) |
671 | return 0; | |
672 | ||
673 | while (p[1] == ':') | |
674 | { | |
c5aa993b JM |
675 | p += 2; |
676 | p = strchr (p, ':'); | |
681c238c MS |
677 | if (p == NULL) |
678 | { | |
b98664d3 | 679 | complaint ( |
681c238c MS |
680 | _("Bad stabs string '%s'"), string); |
681 | return NULL; | |
682 | } | |
c906108c SS |
683 | } |
684 | ||
685 | /* If a nameless stab entry, all we need is the type, not the symbol. | |
686 | e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */ | |
687 | nameless = (p == string || ((string[0] == ' ') && (string[1] == ':'))); | |
688 | ||
8c14c3a3 | 689 | current_symbol = sym = new (&objfile->objfile_obstack) symbol; |
c906108c | 690 | |
c906108c SS |
691 | if (processing_gcc_compilation) |
692 | { | |
693 | /* GCC 2.x puts the line number in desc. SunOS apparently puts in the | |
dda83cd7 | 694 | number of bytes occupied by a type or object, which we ignore. */ |
5d0027b9 | 695 | sym->set_line (desc); |
c906108c SS |
696 | } |
697 | else | |
698 | { | |
5d0027b9 | 699 | sym->set_line (0); /* unknown */ |
c906108c SS |
700 | } |
701 | ||
d3ecddab CB |
702 | sym->set_language (get_current_subfile ()->language, |
703 | &objfile->objfile_obstack); | |
025ac414 | 704 | |
c906108c SS |
705 | if (is_cplus_marker (string[0])) |
706 | { | |
707 | /* Special GNU C++ names. */ | |
708 | switch (string[1]) | |
709 | { | |
c5aa993b | 710 | case 't': |
43678b0a | 711 | sym->set_linkage_name ("this"); |
c5aa993b | 712 | break; |
c906108c | 713 | |
c5aa993b | 714 | case 'v': /* $vtbl_ptr_type */ |
c5aa993b | 715 | goto normal; |
c906108c | 716 | |
c5aa993b | 717 | case 'e': |
43678b0a | 718 | sym->set_linkage_name ("eh_throw"); |
c5aa993b | 719 | break; |
c906108c | 720 | |
c5aa993b JM |
721 | case '_': |
722 | /* This was an anonymous type that was never fixed up. */ | |
723 | goto normal; | |
c906108c | 724 | |
c5aa993b | 725 | default: |
b98664d3 | 726 | complaint (_("Unknown C++ symbol name `%s'"), |
23136709 | 727 | string); |
c378eb4e | 728 | goto normal; /* Do *something* with it. */ |
c906108c SS |
729 | } |
730 | } | |
c906108c SS |
731 | else |
732 | { | |
733 | normal: | |
596dc4ad | 734 | gdb::unique_xmalloc_ptr<char> new_name; |
2f408ecb | 735 | |
c1b5c1eb | 736 | if (sym->language () == language_cplus) |
71c25dea | 737 | { |
55fc1623 TT |
738 | std::string name (string, p - string); |
739 | new_name = cp_canonicalize_string (name.c_str ()); | |
740 | } | |
741 | else if (sym->language () == language_c) | |
742 | { | |
743 | std::string name (string, p - string); | |
744 | new_name = c_canonicalize_name (name.c_str ()); | |
71c25dea | 745 | } |
596dc4ad TT |
746 | if (new_name != nullptr) |
747 | sym->compute_and_set_names (new_name.get (), true, objfile->per_bfd); | |
71c25dea | 748 | else |
4d4eaa30 CB |
749 | sym->compute_and_set_names (gdb::string_view (string, p - string), true, |
750 | objfile->per_bfd); | |
45c58896 | 751 | |
c1b5c1eb | 752 | if (sym->language () == language_cplus) |
80e649fc TT |
753 | cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym, |
754 | objfile); | |
45c58896 | 755 | |
c906108c SS |
756 | } |
757 | p++; | |
758 | ||
759 | /* Determine the type of name being defined. */ | |
760 | #if 0 | |
761 | /* Getting GDB to correctly skip the symbol on an undefined symbol | |
762 | descriptor and not ever dump core is a very dodgy proposition if | |
763 | we do things this way. I say the acorn RISC machine can just | |
764 | fix their compiler. */ | |
765 | /* The Acorn RISC machine's compiler can put out locals that don't | |
766 | start with "234=" or "(3,4)=", so assume anything other than the | |
767 | deftypes we know how to handle is a local. */ | |
768 | if (!strchr ("cfFGpPrStTvVXCR", *p)) | |
769 | #else | |
770 | if (isdigit (*p) || *p == '(' || *p == '-') | |
771 | #endif | |
772 | deftype = 'l'; | |
773 | else | |
774 | deftype = *p++; | |
775 | ||
776 | switch (deftype) | |
777 | { | |
778 | case 'c': | |
779 | /* c is a special case, not followed by a type-number. | |
dda83cd7 SM |
780 | SYMBOL:c=iVALUE for an integer constant symbol. |
781 | SYMBOL:c=rVALUE for a floating constant symbol. | |
782 | SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. | |
783 | e.g. "b:c=e6,0" for "const b = blob1" | |
784 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
c906108c SS |
785 | if (*p != '=') |
786 | { | |
ba44b1a3 | 787 | sym->set_aclass_index (LOC_CONST); |
5f9c5a63 | 788 | sym->set_type (error_type (&p, objfile)); |
6c9c307c | 789 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 790 | add_symbol_to_list (sym, get_file_symbols ()); |
c906108c SS |
791 | return sym; |
792 | } | |
793 | ++p; | |
794 | switch (*p++) | |
795 | { | |
796 | case 'r': | |
797 | { | |
4e38b386 | 798 | gdb_byte *dbl_valu; |
6ccb9162 | 799 | struct type *dbl_type; |
c906108c | 800 | |
46bf5051 | 801 | dbl_type = objfile_type (objfile)->builtin_double; |
224c3ddb SM |
802 | dbl_valu |
803 | = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, | |
df86565b | 804 | dbl_type->length ()); |
f69fdf9b UW |
805 | |
806 | target_float_from_string (dbl_valu, dbl_type, std::string (p)); | |
6ccb9162 | 807 | |
5f9c5a63 | 808 | sym->set_type (dbl_type); |
4aeddc50 | 809 | sym->set_value_bytes (dbl_valu); |
ba44b1a3 | 810 | sym->set_aclass_index (LOC_CONST_BYTES); |
c906108c SS |
811 | } |
812 | break; | |
813 | case 'i': | |
814 | { | |
815 | /* Defining integer constants this way is kind of silly, | |
816 | since 'e' constants allows the compiler to give not | |
817 | only the value, but the type as well. C has at least | |
818 | int, long, unsigned int, and long long as constant | |
819 | types; other languages probably should have at least | |
820 | unsigned as well as signed constants. */ | |
821 | ||
5f9c5a63 | 822 | sym->set_type (objfile_type (objfile)->builtin_long); |
4aeddc50 | 823 | sym->set_value_longest (atoi (p)); |
ba44b1a3 | 824 | sym->set_aclass_index (LOC_CONST); |
c906108c SS |
825 | } |
826 | break; | |
ec8a089a PM |
827 | |
828 | case 'c': | |
829 | { | |
5f9c5a63 | 830 | sym->set_type (objfile_type (objfile)->builtin_char); |
4aeddc50 | 831 | sym->set_value_longest (atoi (p)); |
ba44b1a3 | 832 | sym->set_aclass_index (LOC_CONST); |
ec8a089a PM |
833 | } |
834 | break; | |
835 | ||
836 | case 's': | |
837 | { | |
838 | struct type *range_type; | |
839 | int ind = 0; | |
840 | char quote = *p++; | |
ec8a089a PM |
841 | gdb_byte *string_local = (gdb_byte *) alloca (strlen (p)); |
842 | gdb_byte *string_value; | |
843 | ||
844 | if (quote != '\'' && quote != '"') | |
845 | { | |
ba44b1a3 | 846 | sym->set_aclass_index (LOC_CONST); |
5f9c5a63 | 847 | sym->set_type (error_type (&p, objfile)); |
6c9c307c | 848 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 849 | add_symbol_to_list (sym, get_file_symbols ()); |
ec8a089a PM |
850 | return sym; |
851 | } | |
852 | ||
853 | /* Find matching quote, rejecting escaped quotes. */ | |
854 | while (*p && *p != quote) | |
855 | { | |
856 | if (*p == '\\' && p[1] == quote) | |
857 | { | |
858 | string_local[ind] = (gdb_byte) quote; | |
859 | ind++; | |
860 | p += 2; | |
861 | } | |
862 | else if (*p) | |
863 | { | |
864 | string_local[ind] = (gdb_byte) (*p); | |
865 | ind++; | |
866 | p++; | |
867 | } | |
868 | } | |
869 | if (*p != quote) | |
870 | { | |
ba44b1a3 | 871 | sym->set_aclass_index (LOC_CONST); |
5f9c5a63 | 872 | sym->set_type (error_type (&p, objfile)); |
6c9c307c | 873 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 874 | add_symbol_to_list (sym, get_file_symbols ()); |
ec8a089a PM |
875 | return sym; |
876 | } | |
877 | ||
878 | /* NULL terminate the string. */ | |
879 | string_local[ind] = 0; | |
e727c536 | 880 | type_allocator alloc (objfile); |
3e43a32a | 881 | range_type |
e727c536 | 882 | = create_static_range_type (alloc, |
0c9c3474 SA |
883 | objfile_type (objfile)->builtin_int, |
884 | 0, ind); | |
5f9c5a63 | 885 | sym->set_type |
9e76b17a | 886 | (create_array_type (alloc, objfile_type (objfile)->builtin_char, |
5f9c5a63 | 887 | range_type)); |
224c3ddb SM |
888 | string_value |
889 | = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, ind + 1); | |
ec8a089a PM |
890 | memcpy (string_value, string_local, ind + 1); |
891 | p++; | |
892 | ||
4aeddc50 | 893 | sym->set_value_bytes (string_value); |
ba44b1a3 | 894 | sym->set_aclass_index (LOC_CONST_BYTES); |
ec8a089a PM |
895 | } |
896 | break; | |
897 | ||
c906108c SS |
898 | case 'e': |
899 | /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value | |
900 | can be represented as integral. | |
901 | e.g. "b:c=e6,0" for "const b = blob1" | |
902 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
903 | { | |
ba44b1a3 | 904 | sym->set_aclass_index (LOC_CONST); |
5f9c5a63 | 905 | sym->set_type (read_type (&p, objfile)); |
c906108c SS |
906 | |
907 | if (*p != ',') | |
908 | { | |
5f9c5a63 | 909 | sym->set_type (error_type (&p, objfile)); |
c906108c SS |
910 | break; |
911 | } | |
912 | ++p; | |
913 | ||
914 | /* If the value is too big to fit in an int (perhaps because | |
915 | it is unsigned), or something like that, we silently get | |
916 | a bogus value. The type and everything else about it is | |
917 | correct. Ideally, we should be using whatever we have | |
918 | available for parsing unsigned and long long values, | |
919 | however. */ | |
4aeddc50 | 920 | sym->set_value_longest (atoi (p)); |
c906108c SS |
921 | } |
922 | break; | |
923 | default: | |
924 | { | |
ba44b1a3 | 925 | sym->set_aclass_index (LOC_CONST); |
5f9c5a63 | 926 | sym->set_type (error_type (&p, objfile)); |
c906108c SS |
927 | } |
928 | } | |
6c9c307c | 929 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 930 | add_symbol_to_list (sym, get_file_symbols ()); |
c906108c SS |
931 | return sym; |
932 | ||
933 | case 'C': | |
934 | /* The name of a caught exception. */ | |
5f9c5a63 | 935 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 936 | sym->set_aclass_index (LOC_LABEL); |
6c9c307c | 937 | sym->set_domain (VAR_DOMAIN); |
4aeddc50 | 938 | sym->set_value_address (valu); |
e148f09d | 939 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c SS |
940 | break; |
941 | ||
942 | case 'f': | |
943 | /* A static function definition. */ | |
5f9c5a63 | 944 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 945 | sym->set_aclass_index (LOC_BLOCK); |
6c9c307c | 946 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 947 | add_symbol_to_list (sym, get_file_symbols ()); |
c906108c SS |
948 | /* fall into process_function_types. */ |
949 | ||
950 | process_function_types: | |
951 | /* Function result types are described as the result type in stabs. | |
dda83cd7 SM |
952 | We need to convert this to the function-returning-type-X type |
953 | in GDB. E.g. "int" is converted to "function returning int". */ | |
5f9c5a63 SM |
954 | if (sym->type ()->code () != TYPE_CODE_FUNC) |
955 | sym->set_type (lookup_function_type (sym->type ())); | |
c906108c | 956 | |
1e698235 | 957 | /* All functions in C++ have prototypes. Stabs does not offer an |
dda83cd7 SM |
958 | explicit way to identify prototyped or unprototyped functions, |
959 | but both GCC and Sun CC emit stabs for the "call-as" type rather | |
960 | than the "declared-as" type for unprototyped functions, so | |
961 | we treat all functions as if they were prototyped. This is used | |
962 | primarily for promotion when calling the function from GDB. */ | |
5f9c5a63 | 963 | sym->type ()->set_is_prototyped (true); |
c906108c | 964 | |
c378eb4e | 965 | /* fall into process_prototype_types. */ |
c906108c SS |
966 | |
967 | process_prototype_types: | |
968 | /* Sun acc puts declared types of arguments here. */ | |
969 | if (*p == ';') | |
970 | { | |
5f9c5a63 | 971 | struct type *ftype = sym->type (); |
c906108c SS |
972 | int nsemi = 0; |
973 | int nparams = 0; | |
a121b7c1 | 974 | const char *p1 = p; |
c906108c SS |
975 | |
976 | /* Obtain a worst case guess for the number of arguments | |
977 | by counting the semicolons. */ | |
978 | while (*p1) | |
979 | { | |
980 | if (*p1++ == ';') | |
981 | nsemi++; | |
982 | } | |
983 | ||
c378eb4e | 984 | /* Allocate parameter information fields and fill them in. */ |
3cabb6b0 SM |
985 | ftype->set_fields |
986 | ((struct field *) | |
987 | TYPE_ALLOC (ftype, nsemi * sizeof (struct field))); | |
c906108c SS |
988 | while (*p++ == ';') |
989 | { | |
990 | struct type *ptype; | |
991 | ||
992 | /* A type number of zero indicates the start of varargs. | |
dda83cd7 | 993 | FIXME: GDB currently ignores vararg functions. */ |
c906108c SS |
994 | if (p[0] == '0' && p[1] == '\0') |
995 | break; | |
996 | ptype = read_type (&p, objfile); | |
997 | ||
998 | /* The Sun compilers mark integer arguments, which should | |
dda83cd7 SM |
999 | be promoted to the width of the calling conventions, with |
1000 | a type which references itself. This type is turned into | |
1001 | a TYPE_CODE_VOID type by read_type, and we have to turn | |
1002 | it back into builtin_int here. | |
1003 | FIXME: Do we need a new builtin_promoted_int_arg ? */ | |
78134374 | 1004 | if (ptype->code () == TYPE_CODE_VOID) |
46bf5051 | 1005 | ptype = objfile_type (objfile)->builtin_int; |
5d14b6e5 | 1006 | ftype->field (nparams).set_type (ptype); |
8176bb6d | 1007 | TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0; |
c906108c | 1008 | } |
5e33d5f4 | 1009 | ftype->set_num_fields (nparams); |
27e69b7a | 1010 | ftype->set_is_prototyped (true); |
c906108c SS |
1011 | } |
1012 | break; | |
1013 | ||
1014 | case 'F': | |
1015 | /* A global function definition. */ | |
5f9c5a63 | 1016 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1017 | sym->set_aclass_index (LOC_BLOCK); |
6c9c307c | 1018 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1019 | add_symbol_to_list (sym, get_global_symbols ()); |
c906108c SS |
1020 | goto process_function_types; |
1021 | ||
1022 | case 'G': | |
1023 | /* For a class G (global) symbol, it appears that the | |
dda83cd7 SM |
1024 | value is not correct. It is necessary to search for the |
1025 | corresponding linker definition to find the value. | |
1026 | These definitions appear at the end of the namelist. */ | |
5f9c5a63 | 1027 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1028 | sym->set_aclass_index (LOC_STATIC); |
6c9c307c | 1029 | sym->set_domain (VAR_DOMAIN); |
c906108c | 1030 | /* Don't add symbol references to global_sym_chain. |
dda83cd7 SM |
1031 | Symbol references don't have valid names and wont't match up with |
1032 | minimal symbols when the global_sym_chain is relocated. | |
1033 | We'll fixup symbol references when we fixup the defining symbol. */ | |
987012b8 | 1034 | if (sym->linkage_name () && sym->linkage_name ()[0] != '#') |
c906108c | 1035 | { |
987012b8 | 1036 | i = hashname (sym->linkage_name ()); |
4aeddc50 | 1037 | sym->set_value_chain (global_sym_chain[i]); |
c5aa993b | 1038 | global_sym_chain[i] = sym; |
c906108c | 1039 | } |
e148f09d | 1040 | add_symbol_to_list (sym, get_global_symbols ()); |
c906108c SS |
1041 | break; |
1042 | ||
1043 | /* This case is faked by a conditional above, | |
dda83cd7 SM |
1044 | when there is no code letter in the dbx data. |
1045 | Dbx data never actually contains 'l'. */ | |
c906108c SS |
1046 | case 's': |
1047 | case 'l': | |
5f9c5a63 | 1048 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1049 | sym->set_aclass_index (LOC_LOCAL); |
4aeddc50 | 1050 | sym->set_value_longest (valu); |
6c9c307c | 1051 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1052 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c SS |
1053 | break; |
1054 | ||
1055 | case 'p': | |
1056 | if (*p == 'F') | |
1057 | /* pF is a two-letter code that means a function parameter in Fortran. | |
1058 | The type-number specifies the type of the return value. | |
1059 | Translate it into a pointer-to-function type. */ | |
1060 | { | |
1061 | p++; | |
5f9c5a63 SM |
1062 | sym->set_type |
1063 | (lookup_pointer_type | |
1064 | (lookup_function_type (read_type (&p, objfile)))); | |
c906108c SS |
1065 | } |
1066 | else | |
5f9c5a63 | 1067 | sym->set_type (read_type (&p, objfile)); |
c906108c | 1068 | |
ba44b1a3 | 1069 | sym->set_aclass_index (LOC_ARG); |
4aeddc50 | 1070 | sym->set_value_longest (valu); |
6c9c307c | 1071 | sym->set_domain (VAR_DOMAIN); |
d9743061 | 1072 | sym->set_is_argument (1); |
e148f09d | 1073 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c | 1074 | |
5e2b427d | 1075 | if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG) |
c906108c SS |
1076 | { |
1077 | /* On little-endian machines, this crud is never necessary, | |
1078 | and, if the extra bytes contain garbage, is harmful. */ | |
1079 | break; | |
1080 | } | |
1081 | ||
1082 | /* If it's gcc-compiled, if it says `short', believe it. */ | |
f73e88f9 | 1083 | if (processing_gcc_compilation |
5e2b427d | 1084 | || gdbarch_believe_pcc_promotion (gdbarch)) |
c906108c SS |
1085 | break; |
1086 | ||
5e2b427d | 1087 | if (!gdbarch_believe_pcc_promotion (gdbarch)) |
7a292a7a | 1088 | { |
8ee56bcf AC |
1089 | /* If PCC says a parameter is a short or a char, it is |
1090 | really an int. */ | |
df86565b | 1091 | if (sym->type ()->length () |
5e2b427d | 1092 | < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT |
5f9c5a63 | 1093 | && sym->type ()->code () == TYPE_CODE_INT) |
7a292a7a | 1094 | { |
5f9c5a63 SM |
1095 | sym->set_type |
1096 | (sym->type ()->is_unsigned () | |
c6d940a9 SM |
1097 | ? objfile_type (objfile)->builtin_unsigned_int |
1098 | : objfile_type (objfile)->builtin_int); | |
7a292a7a | 1099 | } |
8ee56bcf | 1100 | break; |
7a292a7a | 1101 | } |
0019cd49 | 1102 | /* Fall through. */ |
c906108c SS |
1103 | |
1104 | case 'P': | |
1105 | /* acc seems to use P to declare the prototypes of functions that | |
dda83cd7 SM |
1106 | are referenced by this file. gdb is not prepared to deal |
1107 | with this extra information. FIXME, it ought to. */ | |
c906108c SS |
1108 | if (type == N_FUN) |
1109 | { | |
5f9c5a63 | 1110 | sym->set_type (read_type (&p, objfile)); |
c906108c SS |
1111 | goto process_prototype_types; |
1112 | } | |
c5aa993b | 1113 | /*FALLTHROUGH */ |
c906108c SS |
1114 | |
1115 | case 'R': | |
1116 | /* Parameter which is in a register. */ | |
5f9c5a63 | 1117 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1118 | sym->set_aclass_index (stab_register_index); |
d9743061 | 1119 | sym->set_is_argument (1); |
4aeddc50 | 1120 | sym->set_value_longest (valu); |
6c9c307c | 1121 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1122 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c SS |
1123 | break; |
1124 | ||
1125 | case 'r': | |
1126 | /* Register variable (either global or local). */ | |
5f9c5a63 | 1127 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1128 | sym->set_aclass_index (stab_register_index); |
4aeddc50 | 1129 | sym->set_value_longest (valu); |
6c9c307c | 1130 | sym->set_domain (VAR_DOMAIN); |
c906108c SS |
1131 | if (within_function) |
1132 | { | |
192cb3d4 MK |
1133 | /* Sun cc uses a pair of symbols, one 'p' and one 'r', with |
1134 | the same name to represent an argument passed in a | |
1135 | register. GCC uses 'P' for the same case. So if we find | |
1136 | such a symbol pair we combine it into one 'P' symbol. | |
987012b8 | 1137 | For Sun cc we need to do this regardless of stabs_argument_has_addr, because the compiler puts out |
192cb3d4 MK |
1138 | the 'p' symbol even if it never saves the argument onto |
1139 | the stack. | |
1140 | ||
1141 | On most machines, we want to preserve both symbols, so | |
1142 | that we can still get information about what is going on | |
1143 | with the stack (VAX for computing args_printed, using | |
1144 | stack slots instead of saved registers in backtraces, | |
1145 | etc.). | |
c906108c SS |
1146 | |
1147 | Note that this code illegally combines | |
c5aa993b | 1148 | main(argc) struct foo argc; { register struct foo argc; } |
c906108c SS |
1149 | but this case is considered pathological and causes a warning |
1150 | from a decent compiler. */ | |
1151 | ||
e148f09d | 1152 | struct pending *local_symbols = *get_local_symbols (); |
c906108c SS |
1153 | if (local_symbols |
1154 | && local_symbols->nsyms > 0 | |
5f9c5a63 | 1155 | && gdbarch_stabs_argument_has_addr (gdbarch, sym->type ())) |
c906108c SS |
1156 | { |
1157 | struct symbol *prev_sym; | |
433759f7 | 1158 | |
c906108c | 1159 | prev_sym = local_symbols->symbol[local_symbols->nsyms - 1]; |
66d7f48f SM |
1160 | if ((prev_sym->aclass () == LOC_REF_ARG |
1161 | || prev_sym->aclass () == LOC_ARG) | |
987012b8 CB |
1162 | && strcmp (prev_sym->linkage_name (), |
1163 | sym->linkage_name ()) == 0) | |
c906108c | 1164 | { |
ba44b1a3 | 1165 | prev_sym->set_aclass_index (stab_register_index); |
c906108c SS |
1166 | /* Use the type from the LOC_REGISTER; that is the type |
1167 | that is actually in that register. */ | |
5f9c5a63 | 1168 | prev_sym->set_type (sym->type ()); |
4aeddc50 | 1169 | prev_sym->set_value_longest (sym->value_longest ()); |
c906108c SS |
1170 | sym = prev_sym; |
1171 | break; | |
1172 | } | |
1173 | } | |
e148f09d | 1174 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c SS |
1175 | } |
1176 | else | |
e148f09d | 1177 | add_symbol_to_list (sym, get_file_symbols ()); |
c906108c SS |
1178 | break; |
1179 | ||
1180 | case 'S': | |
c378eb4e | 1181 | /* Static symbol at top level of file. */ |
5f9c5a63 | 1182 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1183 | sym->set_aclass_index (LOC_STATIC); |
4aeddc50 | 1184 | sym->set_value_address (valu); |
6c9c307c | 1185 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1186 | add_symbol_to_list (sym, get_file_symbols ()); |
c906108c SS |
1187 | break; |
1188 | ||
1189 | case 't': | |
52eea4ce | 1190 | /* In Ada, there is no distinction between typedef and non-typedef; |
dda83cd7 SM |
1191 | any type declaration implicitly has the equivalent of a typedef, |
1192 | and thus 't' is in fact equivalent to 'Tt'. | |
1193 | ||
1194 | Therefore, for Ada units, we check the character immediately | |
1195 | before the 't', and if we do not find a 'T', then make sure to | |
1196 | create the associated symbol in the STRUCT_DOMAIN ('t' definitions | |
1197 | will be stored in the VAR_DOMAIN). If the symbol was indeed | |
1198 | defined as 'Tt' then the STRUCT_DOMAIN symbol will be created | |
1199 | elsewhere, so we don't need to take care of that. | |
1200 | ||
1201 | This is important to do, because of forward references: | |
1202 | The cleanup of undefined types stored in undef_types only uses | |
1203 | STRUCT_DOMAIN symbols to perform the replacement. */ | |
c1b5c1eb | 1204 | synonym = (sym->language () == language_ada && p[-2] != 'T'); |
52eea4ce | 1205 | |
e2cd42dd | 1206 | /* Typedef */ |
5f9c5a63 | 1207 | sym->set_type (read_type (&p, objfile)); |
c906108c SS |
1208 | |
1209 | /* For a nameless type, we don't want a create a symbol, thus we | |
dda83cd7 | 1210 | did not use `sym'. Return without further processing. */ |
c5aa993b JM |
1211 | if (nameless) |
1212 | return NULL; | |
c906108c | 1213 | |
ba44b1a3 | 1214 | sym->set_aclass_index (LOC_TYPEDEF); |
4aeddc50 | 1215 | sym->set_value_longest (valu); |
6c9c307c | 1216 | sym->set_domain (VAR_DOMAIN); |
c906108c | 1217 | /* C++ vagaries: we may have a type which is derived from |
dda83cd7 SM |
1218 | a base type which did not have its name defined when the |
1219 | derived class was output. We fill in the derived class's | |
1220 | base part member's name here in that case. */ | |
5f9c5a63 SM |
1221 | if (sym->type ()->name () != NULL) |
1222 | if ((sym->type ()->code () == TYPE_CODE_STRUCT | |
1223 | || sym->type ()->code () == TYPE_CODE_UNION) | |
1224 | && TYPE_N_BASECLASSES (sym->type ())) | |
c906108c SS |
1225 | { |
1226 | int j; | |
433759f7 | 1227 | |
5f9c5a63 SM |
1228 | for (j = TYPE_N_BASECLASSES (sym->type ()) - 1; j >= 0; j--) |
1229 | if (TYPE_BASECLASS_NAME (sym->type (), j) == 0) | |
1230 | sym->type ()->field (j).set_name | |
1231 | (TYPE_BASECLASS (sym->type (), j)->name ()); | |
c906108c SS |
1232 | } |
1233 | ||
5f9c5a63 | 1234 | if (sym->type ()->name () == NULL) |
c906108c | 1235 | { |
5f9c5a63 | 1236 | if ((sym->type ()->code () == TYPE_CODE_PTR |
987012b8 | 1237 | && strcmp (sym->linkage_name (), vtbl_ptr_name)) |
5f9c5a63 | 1238 | || sym->type ()->code () == TYPE_CODE_FUNC) |
c906108c SS |
1239 | { |
1240 | /* If we are giving a name to a type such as "pointer to | |
dda83cd7 SM |
1241 | foo" or "function returning foo", we better not set |
1242 | the TYPE_NAME. If the program contains "typedef char | |
1243 | *caddr_t;", we don't want all variables of type char | |
1244 | * to print as caddr_t. This is not just a | |
1245 | consequence of GDB's type management; PCC and GCC (at | |
1246 | least through version 2.4) both output variables of | |
1247 | either type char * or caddr_t with the type number | |
1248 | defined in the 't' symbol for caddr_t. If a future | |
1249 | compiler cleans this up it GDB is not ready for it | |
1250 | yet, but if it becomes ready we somehow need to | |
1251 | disable this check (without breaking the PCC/GCC2.4 | |
1252 | case). | |
1253 | ||
1254 | Sigh. | |
1255 | ||
1256 | Fortunately, this check seems not to be necessary | |
1257 | for anything except pointers or functions. */ | |
1258 | /* ezannoni: 2000-10-26. This seems to apply for | |
c378eb4e | 1259 | versions of gcc older than 2.8. This was the original |
49d97c60 | 1260 | problem: with the following code gdb would tell that |
c378eb4e MS |
1261 | the type for name1 is caddr_t, and func is char(). |
1262 | ||
dda83cd7 | 1263 | typedef char *caddr_t; |
49d97c60 EZ |
1264 | char *name2; |
1265 | struct x | |
1266 | { | |
c378eb4e | 1267 | char *name1; |
49d97c60 EZ |
1268 | } xx; |
1269 | char *func() | |
1270 | { | |
1271 | } | |
1272 | main () {} | |
1273 | */ | |
1274 | ||
c378eb4e | 1275 | /* Pascal accepts names for pointer types. */ |
3c65e5b3 | 1276 | if (get_current_subfile ()->language == language_pascal) |
5f9c5a63 | 1277 | sym->type ()->set_name (sym->linkage_name ()); |
c906108c SS |
1278 | } |
1279 | else | |
5f9c5a63 | 1280 | sym->type ()->set_name (sym->linkage_name ()); |
c906108c SS |
1281 | } |
1282 | ||
e148f09d | 1283 | add_symbol_to_list (sym, get_file_symbols ()); |
52eea4ce JB |
1284 | |
1285 | if (synonym) | |
dda83cd7 SM |
1286 | { |
1287 | /* Create the STRUCT_DOMAIN clone. */ | |
1288 | struct symbol *struct_sym = new (&objfile->objfile_obstack) symbol; | |
1289 | ||
1290 | *struct_sym = *sym; | |
ba44b1a3 | 1291 | struct_sym->set_aclass_index (LOC_TYPEDEF); |
4aeddc50 | 1292 | struct_sym->set_value_longest (valu); |
6c9c307c | 1293 | struct_sym->set_domain (STRUCT_DOMAIN); |
5f9c5a63 SM |
1294 | if (sym->type ()->name () == 0) |
1295 | sym->type ()->set_name | |
d0e39ea2 SM |
1296 | (obconcat (&objfile->objfile_obstack, sym->linkage_name (), |
1297 | (char *) NULL)); | |
dda83cd7 SM |
1298 | add_symbol_to_list (struct_sym, get_file_symbols ()); |
1299 | } | |
d0e39ea2 | 1300 | |
c906108c SS |
1301 | break; |
1302 | ||
1303 | case 'T': | |
1304 | /* Struct, union, or enum tag. For GNU C++, this can be be followed | |
dda83cd7 | 1305 | by 't' which means we are typedef'ing it as well. */ |
c906108c SS |
1306 | synonym = *p == 't'; |
1307 | ||
1308 | if (synonym) | |
1309 | p++; | |
c906108c | 1310 | |
5f9c5a63 | 1311 | sym->set_type (read_type (&p, objfile)); |
25caa7a8 | 1312 | |
c906108c | 1313 | /* For a nameless type, we don't want a create a symbol, thus we |
dda83cd7 | 1314 | did not use `sym'. Return without further processing. */ |
c5aa993b JM |
1315 | if (nameless) |
1316 | return NULL; | |
c906108c | 1317 | |
ba44b1a3 | 1318 | sym->set_aclass_index (LOC_TYPEDEF); |
4aeddc50 | 1319 | sym->set_value_longest (valu); |
6c9c307c | 1320 | sym->set_domain (STRUCT_DOMAIN); |
5f9c5a63 SM |
1321 | if (sym->type ()->name () == 0) |
1322 | sym->type ()->set_name | |
d0e39ea2 SM |
1323 | (obconcat (&objfile->objfile_obstack, sym->linkage_name (), |
1324 | (char *) NULL)); | |
e148f09d | 1325 | add_symbol_to_list (sym, get_file_symbols ()); |
c906108c SS |
1326 | |
1327 | if (synonym) | |
1328 | { | |
c378eb4e | 1329 | /* Clone the sym and then modify it. */ |
8c14c3a3 | 1330 | struct symbol *typedef_sym = new (&objfile->objfile_obstack) symbol; |
433759f7 | 1331 | |
c906108c | 1332 | *typedef_sym = *sym; |
ba44b1a3 | 1333 | typedef_sym->set_aclass_index (LOC_TYPEDEF); |
4aeddc50 | 1334 | typedef_sym->set_value_longest (valu); |
6c9c307c | 1335 | typedef_sym->set_domain (VAR_DOMAIN); |
5f9c5a63 SM |
1336 | if (sym->type ()->name () == 0) |
1337 | sym->type ()->set_name | |
d0e39ea2 SM |
1338 | (obconcat (&objfile->objfile_obstack, sym->linkage_name (), |
1339 | (char *) NULL)); | |
e148f09d | 1340 | add_symbol_to_list (typedef_sym, get_file_symbols ()); |
c906108c SS |
1341 | } |
1342 | break; | |
1343 | ||
1344 | case 'V': | |
c378eb4e | 1345 | /* Static symbol of local scope. */ |
5f9c5a63 | 1346 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1347 | sym->set_aclass_index (LOC_STATIC); |
4aeddc50 | 1348 | sym->set_value_address (valu); |
6c9c307c | 1349 | sym->set_domain (VAR_DOMAIN); |
bb6e55f3 | 1350 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c SS |
1351 | break; |
1352 | ||
1353 | case 'v': | |
1354 | /* Reference parameter */ | |
5f9c5a63 | 1355 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1356 | sym->set_aclass_index (LOC_REF_ARG); |
d9743061 | 1357 | sym->set_is_argument (1); |
4aeddc50 | 1358 | sym->set_value_longest (valu); |
6c9c307c | 1359 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1360 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c SS |
1361 | break; |
1362 | ||
1363 | case 'a': | |
1364 | /* Reference parameter which is in a register. */ | |
5f9c5a63 | 1365 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1366 | sym->set_aclass_index (stab_regparm_index); |
d9743061 | 1367 | sym->set_is_argument (1); |
4aeddc50 | 1368 | sym->set_value_longest (valu); |
6c9c307c | 1369 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1370 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c SS |
1371 | break; |
1372 | ||
1373 | case 'X': | |
1374 | /* This is used by Sun FORTRAN for "function result value". | |
dda83cd7 SM |
1375 | Sun claims ("dbx and dbxtool interfaces", 2nd ed) |
1376 | that Pascal uses it too, but when I tried it Pascal used | |
1377 | "x:3" (local symbol) instead. */ | |
5f9c5a63 | 1378 | sym->set_type (read_type (&p, objfile)); |
ba44b1a3 | 1379 | sym->set_aclass_index (LOC_LOCAL); |
4aeddc50 | 1380 | sym->set_value_longest (valu); |
6c9c307c | 1381 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1382 | add_symbol_to_list (sym, get_local_symbols ()); |
c906108c | 1383 | break; |
c906108c SS |
1384 | |
1385 | default: | |
5f9c5a63 | 1386 | sym->set_type (error_type (&p, objfile)); |
ba44b1a3 | 1387 | sym->set_aclass_index (LOC_CONST); |
4aeddc50 | 1388 | sym->set_value_longest (0); |
6c9c307c | 1389 | sym->set_domain (VAR_DOMAIN); |
e148f09d | 1390 | add_symbol_to_list (sym, get_file_symbols ()); |
c906108c SS |
1391 | break; |
1392 | } | |
1393 | ||
192cb3d4 MK |
1394 | /* Some systems pass variables of certain types by reference instead |
1395 | of by value, i.e. they will pass the address of a structure (in a | |
1396 | register or on the stack) instead of the structure itself. */ | |
c906108c | 1397 | |
5f9c5a63 | 1398 | if (gdbarch_stabs_argument_has_addr (gdbarch, sym->type ()) |
d9743061 | 1399 | && sym->is_argument ()) |
c906108c | 1400 | { |
2a2d4dc3 | 1401 | /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for |
dda83cd7 | 1402 | variables passed in a register). */ |
66d7f48f | 1403 | if (sym->aclass () == LOC_REGISTER) |
ba44b1a3 | 1404 | sym->set_aclass_index (LOC_REGPARM_ADDR); |
192cb3d4 MK |
1405 | /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th |
1406 | and subsequent arguments on SPARC, for example). */ | |
66d7f48f | 1407 | else if (sym->aclass () == LOC_ARG) |
ba44b1a3 | 1408 | sym->set_aclass_index (LOC_REF_ARG); |
c906108c SS |
1409 | } |
1410 | ||
c906108c SS |
1411 | return sym; |
1412 | } | |
1413 | ||
c906108c SS |
1414 | /* Skip rest of this symbol and return an error type. |
1415 | ||
1416 | General notes on error recovery: error_type always skips to the | |
1417 | end of the symbol (modulo cretinous dbx symbol name continuation). | |
1418 | Thus code like this: | |
1419 | ||
1420 | if (*(*pp)++ != ';') | |
c5aa993b | 1421 | return error_type (pp, objfile); |
c906108c SS |
1422 | |
1423 | is wrong because if *pp starts out pointing at '\0' (typically as the | |
1424 | result of an earlier error), it will be incremented to point to the | |
1425 | start of the next symbol, which might produce strange results, at least | |
1426 | if you run off the end of the string table. Instead use | |
1427 | ||
1428 | if (**pp != ';') | |
c5aa993b | 1429 | return error_type (pp, objfile); |
c906108c SS |
1430 | ++*pp; |
1431 | ||
1432 | or | |
1433 | ||
1434 | if (**pp != ';') | |
c5aa993b | 1435 | foo = error_type (pp, objfile); |
c906108c | 1436 | else |
c5aa993b | 1437 | ++*pp; |
c906108c SS |
1438 | |
1439 | And in case it isn't obvious, the point of all this hair is so the compiler | |
1440 | can define new types and new syntaxes, and old versions of the | |
1441 | debugger will be able to read the new symbol tables. */ | |
1442 | ||
1443 | static struct type * | |
a121b7c1 | 1444 | error_type (const char **pp, struct objfile *objfile) |
c906108c | 1445 | { |
b98664d3 | 1446 | complaint (_("couldn't parse type; debugger out of date?")); |
c906108c SS |
1447 | while (1) |
1448 | { | |
1449 | /* Skip to end of symbol. */ | |
1450 | while (**pp != '\0') | |
1451 | { | |
1452 | (*pp)++; | |
1453 | } | |
1454 | ||
1455 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
1456 | if ((*pp)[-1] == '\\' || (*pp)[-1] == '?') | |
1457 | { | |
1458 | *pp = next_symbol_text (objfile); | |
1459 | } | |
1460 | else | |
1461 | { | |
1462 | break; | |
1463 | } | |
1464 | } | |
46bf5051 | 1465 | return objfile_type (objfile)->builtin_error; |
c906108c | 1466 | } |
c906108c | 1467 | \f |
c5aa993b | 1468 | |
1cd0716e TT |
1469 | /* Allocate a stub method whose return type is TYPE. This apparently |
1470 | happens for speed of symbol reading, since parsing out the | |
1471 | arguments to the method is cpu-intensive, the way we are doing it. | |
1472 | So, we will fill in arguments later. This always returns a fresh | |
1473 | type. */ | |
1474 | ||
1475 | static struct type * | |
1476 | allocate_stub_method (struct type *type) | |
1477 | { | |
1478 | struct type *mtype; | |
1479 | ||
9fa83a7a | 1480 | mtype = type_allocator (type).new_type (); |
1cd0716e TT |
1481 | mtype->set_code (TYPE_CODE_METHOD); |
1482 | mtype->set_length (1); | |
1483 | mtype->set_is_stub (true); | |
1484 | mtype->set_target_type (type); | |
1485 | /* TYPE_SELF_TYPE (mtype) = unknown yet */ | |
1486 | return mtype; | |
1487 | } | |
1488 | ||
c906108c SS |
1489 | /* Read type information or a type definition; return the type. Even |
1490 | though this routine accepts either type information or a type | |
1491 | definition, the distinction is relevant--some parts of stabsread.c | |
1492 | assume that type information starts with a digit, '-', or '(' in | |
1493 | deciding whether to call read_type. */ | |
1494 | ||
a7a48797 | 1495 | static struct type * |
a121b7c1 | 1496 | read_type (const char **pp, struct objfile *objfile) |
c906108c | 1497 | { |
52f0bd74 | 1498 | struct type *type = 0; |
c906108c SS |
1499 | struct type *type1; |
1500 | int typenums[2]; | |
1501 | char type_descriptor; | |
1502 | ||
1503 | /* Size in bits of type if specified by a type attribute, or -1 if | |
1504 | there is no size attribute. */ | |
1505 | int type_size = -1; | |
1506 | ||
c378eb4e | 1507 | /* Used to distinguish string and bitstring from char-array and set. */ |
c906108c SS |
1508 | int is_string = 0; |
1509 | ||
c378eb4e | 1510 | /* Used to distinguish vector from array. */ |
e2cd42dd MS |
1511 | int is_vector = 0; |
1512 | ||
c906108c SS |
1513 | /* Read type number if present. The type number may be omitted. |
1514 | for instance in a two-dimensional array declared with type | |
1515 | "ar1;1;10;ar1;1;10;4". */ | |
1516 | if ((**pp >= '0' && **pp <= '9') | |
1517 | || **pp == '(' | |
1518 | || **pp == '-') | |
1519 | { | |
1520 | if (read_type_number (pp, typenums) != 0) | |
1521 | return error_type (pp, objfile); | |
c5aa993b | 1522 | |
c906108c | 1523 | if (**pp != '=') |
dda83cd7 SM |
1524 | { |
1525 | /* Type is not being defined here. Either it already | |
1526 | exists, or this is a forward reference to it. | |
1527 | dbx_alloc_type handles both cases. */ | |
1528 | type = dbx_alloc_type (typenums, objfile); | |
8cfe231d | 1529 | |
dda83cd7 SM |
1530 | /* If this is a forward reference, arrange to complain if it |
1531 | doesn't get patched up by the time we're done | |
1532 | reading. */ | |
1533 | if (type->code () == TYPE_CODE_UNDEF) | |
1534 | add_undefined_type (type, typenums); | |
8cfe231d | 1535 | |
dda83cd7 SM |
1536 | return type; |
1537 | } | |
c906108c SS |
1538 | |
1539 | /* Type is being defined here. */ | |
1540 | /* Skip the '='. | |
dda83cd7 | 1541 | Also skip the type descriptor - we get it below with (*pp)[-1]. */ |
c5aa993b | 1542 | (*pp) += 2; |
c906108c SS |
1543 | } |
1544 | else | |
1545 | { | |
1546 | /* 'typenums=' not present, type is anonymous. Read and return | |
dda83cd7 | 1547 | the definition, but don't put it in the type vector. */ |
c906108c SS |
1548 | typenums[0] = typenums[1] = -1; |
1549 | (*pp)++; | |
1550 | } | |
1551 | ||
c5aa993b | 1552 | again: |
c906108c SS |
1553 | type_descriptor = (*pp)[-1]; |
1554 | switch (type_descriptor) | |
1555 | { | |
1556 | case 'x': | |
1557 | { | |
1558 | enum type_code code; | |
1559 | ||
1560 | /* Used to index through file_symbols. */ | |
1561 | struct pending *ppt; | |
1562 | int i; | |
c5aa993b | 1563 | |
c906108c SS |
1564 | /* Name including "struct", etc. */ |
1565 | char *type_name; | |
c5aa993b | 1566 | |
c906108c | 1567 | { |
a121b7c1 | 1568 | const char *from, *p, *q1, *q2; |
c5aa993b | 1569 | |
c906108c SS |
1570 | /* Set the type code according to the following letter. */ |
1571 | switch ((*pp)[0]) | |
1572 | { | |
1573 | case 's': | |
1574 | code = TYPE_CODE_STRUCT; | |
1575 | break; | |
1576 | case 'u': | |
1577 | code = TYPE_CODE_UNION; | |
1578 | break; | |
1579 | case 'e': | |
1580 | code = TYPE_CODE_ENUM; | |
1581 | break; | |
1582 | default: | |
1583 | { | |
1584 | /* Complain and keep going, so compilers can invent new | |
1585 | cross-reference types. */ | |
b98664d3 | 1586 | complaint (_("Unrecognized cross-reference type `%c'"), |
3e43a32a | 1587 | (*pp)[0]); |
c906108c SS |
1588 | code = TYPE_CODE_STRUCT; |
1589 | break; | |
1590 | } | |
1591 | } | |
c5aa993b | 1592 | |
c906108c SS |
1593 | q1 = strchr (*pp, '<'); |
1594 | p = strchr (*pp, ':'); | |
1595 | if (p == NULL) | |
1596 | return error_type (pp, objfile); | |
1597 | if (q1 && p > q1 && p[1] == ':') | |
1598 | { | |
1599 | int nesting_level = 0; | |
433759f7 | 1600 | |
c906108c SS |
1601 | for (q2 = q1; *q2; q2++) |
1602 | { | |
1603 | if (*q2 == '<') | |
1604 | nesting_level++; | |
1605 | else if (*q2 == '>') | |
1606 | nesting_level--; | |
1607 | else if (*q2 == ':' && nesting_level == 0) | |
1608 | break; | |
1609 | } | |
1610 | p = q2; | |
1611 | if (*p != ':') | |
1612 | return error_type (pp, objfile); | |
1613 | } | |
71c25dea | 1614 | type_name = NULL; |
3c65e5b3 | 1615 | if (get_current_subfile ()->language == language_cplus) |
71c25dea | 1616 | { |
55fc1623 TT |
1617 | std::string name (*pp, p - *pp); |
1618 | gdb::unique_xmalloc_ptr<char> new_name | |
1619 | = cp_canonicalize_string (name.c_str ()); | |
1620 | if (new_name != nullptr) | |
1621 | type_name = obstack_strdup (&objfile->objfile_obstack, | |
1622 | new_name.get ()); | |
1623 | } | |
1624 | else if (get_current_subfile ()->language == language_c) | |
1625 | { | |
1626 | std::string name (*pp, p - *pp); | |
1627 | gdb::unique_xmalloc_ptr<char> new_name | |
1628 | = c_canonicalize_name (name.c_str ()); | |
596dc4ad | 1629 | if (new_name != nullptr) |
efba19b0 | 1630 | type_name = obstack_strdup (&objfile->objfile_obstack, |
596dc4ad | 1631 | new_name.get ()); |
71c25dea TT |
1632 | } |
1633 | if (type_name == NULL) | |
1634 | { | |
a121b7c1 | 1635 | char *to = type_name = (char *) |
3e43a32a | 1636 | obstack_alloc (&objfile->objfile_obstack, p - *pp + 1); |
71c25dea TT |
1637 | |
1638 | /* Copy the name. */ | |
1639 | from = *pp + 1; | |
1640 | while (from < p) | |
1641 | *to++ = *from++; | |
1642 | *to = '\0'; | |
1643 | } | |
c5aa993b | 1644 | |
c906108c SS |
1645 | /* Set the pointer ahead of the name which we just read, and |
1646 | the colon. */ | |
71c25dea | 1647 | *pp = p + 1; |
c906108c SS |
1648 | } |
1649 | ||
dda83cd7 SM |
1650 | /* If this type has already been declared, then reuse the same |
1651 | type, rather than allocating a new one. This saves some | |
1652 | memory. */ | |
c906108c | 1653 | |
e148f09d | 1654 | for (ppt = *get_file_symbols (); ppt; ppt = ppt->next) |
c906108c SS |
1655 | for (i = 0; i < ppt->nsyms; i++) |
1656 | { | |
1657 | struct symbol *sym = ppt->symbol[i]; | |
1658 | ||
66d7f48f | 1659 | if (sym->aclass () == LOC_TYPEDEF |
6c9c307c | 1660 | && sym->domain () == STRUCT_DOMAIN |
5f9c5a63 | 1661 | && (sym->type ()->code () == code) |
987012b8 | 1662 | && strcmp (sym->linkage_name (), type_name) == 0) |
c906108c | 1663 | { |
b99607ea | 1664 | obstack_free (&objfile->objfile_obstack, type_name); |
5f9c5a63 | 1665 | type = sym->type (); |
dda83cd7 SM |
1666 | if (typenums[0] != -1) |
1667 | *dbx_lookup_type (typenums, objfile) = type; | |
c906108c SS |
1668 | return type; |
1669 | } | |
1670 | } | |
1671 | ||
1672 | /* Didn't find the type to which this refers, so we must | |
1673 | be dealing with a forward reference. Allocate a type | |
1674 | structure for it, and keep track of it so we can | |
1675 | fill in the rest of the fields when we get the full | |
1676 | type. */ | |
1677 | type = dbx_alloc_type (typenums, objfile); | |
67607e24 | 1678 | type->set_code (code); |
d0e39ea2 | 1679 | type->set_name (type_name); |
c5aa993b | 1680 | INIT_CPLUS_SPECIFIC (type); |
b4b73759 | 1681 | type->set_is_stub (true); |
c906108c | 1682 | |
bf362611 | 1683 | add_undefined_type (type, typenums); |
c906108c SS |
1684 | return type; |
1685 | } | |
1686 | ||
c5aa993b | 1687 | case '-': /* RS/6000 built-in type */ |
c906108c SS |
1688 | case '0': |
1689 | case '1': | |
1690 | case '2': | |
1691 | case '3': | |
1692 | case '4': | |
1693 | case '5': | |
1694 | case '6': | |
1695 | case '7': | |
1696 | case '8': | |
1697 | case '9': | |
1698 | case '(': | |
1699 | (*pp)--; | |
1700 | ||
1701 | /* We deal with something like t(1,2)=(3,4)=... which | |
dda83cd7 | 1702 | the Lucid compiler and recent gcc versions (post 2.7.3) use. */ |
c906108c SS |
1703 | |
1704 | /* Allocate and enter the typedef type first. | |
dda83cd7 | 1705 | This handles recursive types. */ |
c906108c | 1706 | type = dbx_alloc_type (typenums, objfile); |
67607e24 | 1707 | type->set_code (TYPE_CODE_TYPEDEF); |
c5aa993b JM |
1708 | { |
1709 | struct type *xtype = read_type (pp, objfile); | |
433759f7 | 1710 | |
c906108c SS |
1711 | if (type == xtype) |
1712 | { | |
1713 | /* It's being defined as itself. That means it is "void". */ | |
67607e24 | 1714 | type->set_code (TYPE_CODE_VOID); |
b6cdbc9a | 1715 | type->set_length (1); |
c906108c SS |
1716 | } |
1717 | else if (type_size >= 0 || is_string) | |
1718 | { | |
dd6bda65 DJ |
1719 | /* This is the absolute wrong way to construct types. Every |
1720 | other debug format has found a way around this problem and | |
1721 | the related problems with unnecessarily stubbed types; | |
1722 | someone motivated should attempt to clean up the issue | |
1723 | here as well. Once a type pointed to has been created it | |
13a393b0 JB |
1724 | should not be modified. |
1725 | ||
dda83cd7 SM |
1726 | Well, it's not *absolutely* wrong. Constructing recursive |
1727 | types (trees, linked lists) necessarily entails modifying | |
1728 | types after creating them. Constructing any loop structure | |
1729 | entails side effects. The Dwarf 2 reader does handle this | |
1730 | more gracefully (it never constructs more than once | |
1731 | instance of a type object, so it doesn't have to copy type | |
1732 | objects wholesale), but it still mutates type objects after | |
1733 | other folks have references to them. | |
1734 | ||
1735 | Keep in mind that this circularity/mutation issue shows up | |
1736 | at the source language level, too: C's "incomplete types", | |
1737 | for example. So the proper cleanup, I think, would be to | |
1738 | limit GDB's type smashing to match exactly those required | |
1739 | by the source language. So GDB could have a | |
1740 | "complete_this_type" function, but never create unnecessary | |
1741 | copies of a type otherwise. */ | |
dd6bda65 | 1742 | replace_type (type, xtype); |
d0e39ea2 | 1743 | type->set_name (NULL); |
c906108c SS |
1744 | } |
1745 | else | |
1746 | { | |
8f53807e | 1747 | type->set_target_is_stub (true); |
8a50fdce | 1748 | type->set_target_type (xtype); |
c906108c SS |
1749 | } |
1750 | } | |
1751 | break; | |
1752 | ||
c5aa993b | 1753 | /* In the following types, we must be sure to overwrite any existing |
dda83cd7 SM |
1754 | type that the typenums refer to, rather than allocating a new one |
1755 | and making the typenums point to the new one. This is because there | |
1756 | may already be pointers to the existing type (if it had been | |
1757 | forward-referenced), and we must change it to a pointer, function, | |
1758 | reference, or whatever, *in-place*. */ | |
c906108c | 1759 | |
e2cd42dd | 1760 | case '*': /* Pointer to another type */ |
c906108c | 1761 | type1 = read_type (pp, objfile); |
46bf5051 | 1762 | type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile)); |
c906108c SS |
1763 | break; |
1764 | ||
c5aa993b | 1765 | case '&': /* Reference to another type */ |
c906108c | 1766 | type1 = read_type (pp, objfile); |
3b224330 | 1767 | type = make_reference_type (type1, dbx_lookup_type (typenums, objfile), |
dda83cd7 | 1768 | TYPE_CODE_REF); |
c906108c SS |
1769 | break; |
1770 | ||
c5aa993b | 1771 | case 'f': /* Function returning another type */ |
c906108c | 1772 | type1 = read_type (pp, objfile); |
0c8b41f1 | 1773 | type = make_function_type (type1, dbx_lookup_type (typenums, objfile)); |
c906108c SS |
1774 | break; |
1775 | ||
da966255 JB |
1776 | case 'g': /* Prototyped function. (Sun) */ |
1777 | { | |
dda83cd7 SM |
1778 | /* Unresolved questions: |
1779 | ||
1780 | - According to Sun's ``STABS Interface Manual'', for 'f' | |
1781 | and 'F' symbol descriptors, a `0' in the argument type list | |
1782 | indicates a varargs function. But it doesn't say how 'g' | |
1783 | type descriptors represent that info. Someone with access | |
1784 | to Sun's toolchain should try it out. | |
1785 | ||
1786 | - According to the comment in define_symbol (search for | |
1787 | `process_prototype_types:'), Sun emits integer arguments as | |
1788 | types which ref themselves --- like `void' types. Do we | |
1789 | have to deal with that here, too? Again, someone with | |
1790 | access to Sun's toolchain should try it out and let us | |
1791 | know. */ | |
1792 | ||
1793 | const char *type_start = (*pp) - 1; | |
1794 | struct type *return_type = read_type (pp, objfile); | |
1795 | struct type *func_type | |
1796 | = make_function_type (return_type, | |
0c8b41f1 | 1797 | dbx_lookup_type (typenums, objfile)); |
dda83cd7 SM |
1798 | struct type_list { |
1799 | struct type *type; | |
1800 | struct type_list *next; | |
1801 | } *arg_types = 0; | |
1802 | int num_args = 0; | |
1803 | ||
1804 | while (**pp && **pp != '#') | |
1805 | { | |
1806 | struct type *arg_type = read_type (pp, objfile); | |
1807 | struct type_list *newobj = XALLOCA (struct type_list); | |
1808 | newobj->type = arg_type; | |
1809 | newobj->next = arg_types; | |
1810 | arg_types = newobj; | |
1811 | num_args++; | |
1812 | } | |
1813 | if (**pp == '#') | |
1814 | ++*pp; | |
1815 | else | |
1816 | { | |
b98664d3 | 1817 | complaint (_("Prototyped function type didn't " |
3e43a32a | 1818 | "end arguments with `#':\n%s"), |
23136709 | 1819 | type_start); |
dda83cd7 | 1820 | } |
da966255 | 1821 | |
dda83cd7 SM |
1822 | /* If there is just one argument whose type is `void', then |
1823 | that's just an empty argument list. */ | |
1824 | if (arg_types | |
1825 | && ! arg_types->next | |
1826 | && arg_types->type->code () == TYPE_CODE_VOID) | |
1827 | num_args = 0; | |
da966255 | 1828 | |
3cabb6b0 SM |
1829 | func_type->set_fields |
1830 | ((struct field *) TYPE_ALLOC (func_type, | |
1831 | num_args * sizeof (struct field))); | |
dda83cd7 SM |
1832 | memset (func_type->fields (), 0, num_args * sizeof (struct field)); |
1833 | { | |
1834 | int i; | |
1835 | struct type_list *t; | |
1836 | ||
1837 | /* We stuck each argument type onto the front of the list | |
1838 | when we read it, so the list is reversed. Build the | |
1839 | fields array right-to-left. */ | |
1840 | for (t = arg_types, i = num_args - 1; t; t = t->next, i--) | |
1841 | func_type->field (i).set_type (t->type); | |
1842 | } | |
1843 | func_type->set_num_fields (num_args); | |
27e69b7a | 1844 | func_type->set_is_prototyped (true); |
da966255 | 1845 | |
dda83cd7 SM |
1846 | type = func_type; |
1847 | break; | |
da966255 JB |
1848 | } |
1849 | ||
c5aa993b | 1850 | case 'k': /* Const qualifier on some type (Sun) */ |
c906108c | 1851 | type = read_type (pp, objfile); |
d7242108 | 1852 | type = make_cv_type (1, TYPE_VOLATILE (type), type, |
46bf5051 | 1853 | dbx_lookup_type (typenums, objfile)); |
c906108c SS |
1854 | break; |
1855 | ||
c5aa993b | 1856 | case 'B': /* Volatile qual on some type (Sun) */ |
c906108c | 1857 | type = read_type (pp, objfile); |
d7242108 | 1858 | type = make_cv_type (TYPE_CONST (type), 1, type, |
46bf5051 | 1859 | dbx_lookup_type (typenums, objfile)); |
c906108c SS |
1860 | break; |
1861 | ||
1862 | case '@': | |
c5aa993b JM |
1863 | if (isdigit (**pp) || **pp == '(' || **pp == '-') |
1864 | { /* Member (class & variable) type */ | |
c906108c SS |
1865 | /* FIXME -- we should be doing smash_to_XXX types here. */ |
1866 | ||
1867 | struct type *domain = read_type (pp, objfile); | |
1868 | struct type *memtype; | |
1869 | ||
1870 | if (**pp != ',') | |
1871 | /* Invalid member type data format. */ | |
1872 | return error_type (pp, objfile); | |
1873 | ++*pp; | |
1874 | ||
1875 | memtype = read_type (pp, objfile); | |
1876 | type = dbx_alloc_type (typenums, objfile); | |
0d5de010 | 1877 | smash_to_memberptr_type (type, domain, memtype); |
c906108c | 1878 | } |
c5aa993b JM |
1879 | else |
1880 | /* type attribute */ | |
c906108c | 1881 | { |
a121b7c1 | 1882 | const char *attr = *pp; |
433759f7 | 1883 | |
c906108c SS |
1884 | /* Skip to the semicolon. */ |
1885 | while (**pp != ';' && **pp != '\0') | |
1886 | ++(*pp); | |
1887 | if (**pp == '\0') | |
1888 | return error_type (pp, objfile); | |
1889 | else | |
c5aa993b | 1890 | ++ * pp; /* Skip the semicolon. */ |
c906108c SS |
1891 | |
1892 | switch (*attr) | |
1893 | { | |
e2cd42dd | 1894 | case 's': /* Size attribute */ |
c906108c SS |
1895 | type_size = atoi (attr + 1); |
1896 | if (type_size <= 0) | |
1897 | type_size = -1; | |
1898 | break; | |
1899 | ||
e2cd42dd | 1900 | case 'S': /* String attribute */ |
c378eb4e | 1901 | /* FIXME: check to see if following type is array? */ |
c906108c SS |
1902 | is_string = 1; |
1903 | break; | |
1904 | ||
e2cd42dd | 1905 | case 'V': /* Vector attribute */ |
c378eb4e | 1906 | /* FIXME: check to see if following type is array? */ |
e2cd42dd MS |
1907 | is_vector = 1; |
1908 | break; | |
1909 | ||
c906108c SS |
1910 | default: |
1911 | /* Ignore unrecognized type attributes, so future compilers | |
dda83cd7 | 1912 | can invent new ones. */ |
c906108c SS |
1913 | break; |
1914 | } | |
1915 | ++*pp; | |
1916 | goto again; | |
1917 | } | |
1918 | break; | |
1919 | ||
c5aa993b | 1920 | case '#': /* Method (class & fn) type */ |
c906108c SS |
1921 | if ((*pp)[0] == '#') |
1922 | { | |
1923 | /* We'll get the parameter types from the name. */ | |
1924 | struct type *return_type; | |
1925 | ||
1926 | (*pp)++; | |
1927 | return_type = read_type (pp, objfile); | |
1928 | if (*(*pp)++ != ';') | |
b98664d3 | 1929 | complaint (_("invalid (minimal) member type " |
3e43a32a | 1930 | "data format at symtab pos %d."), |
23136709 | 1931 | symnum); |
c906108c SS |
1932 | type = allocate_stub_method (return_type); |
1933 | if (typenums[0] != -1) | |
46bf5051 | 1934 | *dbx_lookup_type (typenums, objfile) = type; |
c906108c SS |
1935 | } |
1936 | else | |
1937 | { | |
1938 | struct type *domain = read_type (pp, objfile); | |
1939 | struct type *return_type; | |
ad2f7632 DJ |
1940 | struct field *args; |
1941 | int nargs, varargs; | |
c906108c SS |
1942 | |
1943 | if (**pp != ',') | |
1944 | /* Invalid member type data format. */ | |
1945 | return error_type (pp, objfile); | |
1946 | else | |
1947 | ++(*pp); | |
1948 | ||
1949 | return_type = read_type (pp, objfile); | |
ad2f7632 | 1950 | args = read_args (pp, ';', objfile, &nargs, &varargs); |
0a029df5 DJ |
1951 | if (args == NULL) |
1952 | return error_type (pp, objfile); | |
c906108c | 1953 | type = dbx_alloc_type (typenums, objfile); |
ad2f7632 DJ |
1954 | smash_to_method_type (type, domain, return_type, args, |
1955 | nargs, varargs); | |
c906108c SS |
1956 | } |
1957 | break; | |
1958 | ||
c5aa993b | 1959 | case 'r': /* Range type */ |
94e10a22 | 1960 | type = read_range_type (pp, typenums, type_size, objfile); |
c906108c | 1961 | if (typenums[0] != -1) |
46bf5051 | 1962 | *dbx_lookup_type (typenums, objfile) = type; |
c906108c SS |
1963 | break; |
1964 | ||
1965 | case 'b': | |
c906108c SS |
1966 | { |
1967 | /* Sun ACC builtin int type */ | |
1968 | type = read_sun_builtin_type (pp, typenums, objfile); | |
1969 | if (typenums[0] != -1) | |
46bf5051 | 1970 | *dbx_lookup_type (typenums, objfile) = type; |
c906108c SS |
1971 | } |
1972 | break; | |
1973 | ||
c5aa993b | 1974 | case 'R': /* Sun ACC builtin float type */ |
c906108c SS |
1975 | type = read_sun_floating_type (pp, typenums, objfile); |
1976 | if (typenums[0] != -1) | |
46bf5051 | 1977 | *dbx_lookup_type (typenums, objfile) = type; |
c906108c | 1978 | break; |
c5aa993b JM |
1979 | |
1980 | case 'e': /* Enumeration type */ | |
c906108c SS |
1981 | type = dbx_alloc_type (typenums, objfile); |
1982 | type = read_enum_type (pp, type, objfile); | |
1983 | if (typenums[0] != -1) | |
46bf5051 | 1984 | *dbx_lookup_type (typenums, objfile) = type; |
c906108c SS |
1985 | break; |
1986 | ||
c5aa993b JM |
1987 | case 's': /* Struct type */ |
1988 | case 'u': /* Union type */ | |
2ae1c2d2 | 1989 | { |
dda83cd7 SM |
1990 | enum type_code type_code = TYPE_CODE_UNDEF; |
1991 | type = dbx_alloc_type (typenums, objfile); | |
1992 | switch (type_descriptor) | |
1993 | { | |
1994 | case 's': | |
1995 | type_code = TYPE_CODE_STRUCT; | |
1996 | break; | |
1997 | case 'u': | |
1998 | type_code = TYPE_CODE_UNION; | |
1999 | break; | |
2000 | } | |
2001 | type = read_struct_type (pp, type, type_code, objfile); | |
2002 | break; | |
2ae1c2d2 | 2003 | } |
c906108c | 2004 | |
c5aa993b | 2005 | case 'a': /* Array type */ |
c906108c SS |
2006 | if (**pp != 'r') |
2007 | return error_type (pp, objfile); | |
2008 | ++*pp; | |
c5aa993b | 2009 | |
c906108c SS |
2010 | type = dbx_alloc_type (typenums, objfile); |
2011 | type = read_array_type (pp, type, objfile); | |
2012 | if (is_string) | |
67607e24 | 2013 | type->set_code (TYPE_CODE_STRING); |
e2cd42dd | 2014 | if (is_vector) |
ea37ba09 | 2015 | make_vector_type (type); |
c906108c SS |
2016 | break; |
2017 | ||
6b1755ce | 2018 | case 'S': /* Set type */ |
c906108c | 2019 | type1 = read_type (pp, objfile); |
cafb3438 | 2020 | type = create_set_type (NULL, type1); |
c906108c | 2021 | if (typenums[0] != -1) |
46bf5051 | 2022 | *dbx_lookup_type (typenums, objfile) = type; |
c906108c SS |
2023 | break; |
2024 | ||
2025 | default: | |
c378eb4e MS |
2026 | --*pp; /* Go back to the symbol in error. */ |
2027 | /* Particularly important if it was \0! */ | |
c906108c SS |
2028 | return error_type (pp, objfile); |
2029 | } | |
2030 | ||
2031 | if (type == 0) | |
2032 | { | |
8a3fe4f8 | 2033 | warning (_("GDB internal error, type is NULL in stabsread.c.")); |
c906108c SS |
2034 | return error_type (pp, objfile); |
2035 | } | |
2036 | ||
2037 | /* Size specified in a type attribute overrides any other size. */ | |
2038 | if (type_size != -1) | |
b6cdbc9a | 2039 | type->set_length ((type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT); |
c906108c SS |
2040 | |
2041 | return type; | |
2042 | } | |
2043 | \f | |
2044 | /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1. | |
c378eb4e | 2045 | Return the proper type node for a given builtin type number. */ |
c906108c | 2046 | |
08b8a139 TT |
2047 | static const registry<objfile>::key<struct type *, |
2048 | gdb::noop_deleter<struct type *>> | |
d772d2ab | 2049 | rs6000_builtin_type_data; |
46bf5051 | 2050 | |
c906108c | 2051 | static struct type * |
46bf5051 | 2052 | rs6000_builtin_type (int typenum, struct objfile *objfile) |
c906108c | 2053 | { |
d772d2ab | 2054 | struct type **negative_types = rs6000_builtin_type_data.get (objfile); |
46bf5051 | 2055 | |
c906108c SS |
2056 | /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */ |
2057 | #define NUMBER_RECOGNIZED 34 | |
c906108c SS |
2058 | struct type *rettype = NULL; |
2059 | ||
2060 | if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED) | |
2061 | { | |
b98664d3 | 2062 | complaint (_("Unknown builtin type %d"), typenum); |
46bf5051 | 2063 | return objfile_type (objfile)->builtin_error; |
c906108c | 2064 | } |
46bf5051 UW |
2065 | |
2066 | if (!negative_types) | |
2067 | { | |
2068 | /* This includes an empty slot for type number -0. */ | |
2069 | negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2070 | NUMBER_RECOGNIZED + 1, struct type *); | |
d772d2ab | 2071 | rs6000_builtin_type_data.set (objfile, negative_types); |
46bf5051 UW |
2072 | } |
2073 | ||
c906108c SS |
2074 | if (negative_types[-typenum] != NULL) |
2075 | return negative_types[-typenum]; | |
2076 | ||
2077 | #if TARGET_CHAR_BIT != 8 | |
c5aa993b | 2078 | #error This code wrong for TARGET_CHAR_BIT not 8 |
c906108c SS |
2079 | /* These definitions all assume that TARGET_CHAR_BIT is 8. I think |
2080 | that if that ever becomes not true, the correct fix will be to | |
2081 | make the size in the struct type to be in bits, not in units of | |
2082 | TARGET_CHAR_BIT. */ | |
2083 | #endif | |
2084 | ||
33385940 | 2085 | type_allocator alloc (objfile); |
c906108c SS |
2086 | switch (-typenum) |
2087 | { | |
2088 | case 1: | |
2089 | /* The size of this and all the other types are fixed, defined | |
dda83cd7 SM |
2090 | by the debugging format. If there is a type called "int" which |
2091 | is other than 32 bits, then it should use a new negative type | |
2092 | number (or avoid negative type numbers for that case). | |
2093 | See stabs.texinfo. */ | |
2d39ccd3 | 2094 | rettype = init_integer_type (alloc, 32, 0, "int"); |
c906108c SS |
2095 | break; |
2096 | case 2: | |
2d39ccd3 | 2097 | rettype = init_integer_type (alloc, 8, 0, "char"); |
15152a54 | 2098 | rettype->set_has_no_signedness (true); |
c906108c SS |
2099 | break; |
2100 | case 3: | |
2d39ccd3 | 2101 | rettype = init_integer_type (alloc, 16, 0, "short"); |
c906108c SS |
2102 | break; |
2103 | case 4: | |
2d39ccd3 | 2104 | rettype = init_integer_type (alloc, 32, 0, "long"); |
c906108c SS |
2105 | break; |
2106 | case 5: | |
2d39ccd3 | 2107 | rettype = init_integer_type (alloc, 8, 1, "unsigned char"); |
c906108c SS |
2108 | break; |
2109 | case 6: | |
2d39ccd3 | 2110 | rettype = init_integer_type (alloc, 8, 0, "signed char"); |
c906108c SS |
2111 | break; |
2112 | case 7: | |
2d39ccd3 | 2113 | rettype = init_integer_type (alloc, 16, 1, "unsigned short"); |
c906108c SS |
2114 | break; |
2115 | case 8: | |
2d39ccd3 | 2116 | rettype = init_integer_type (alloc, 32, 1, "unsigned int"); |
c906108c SS |
2117 | break; |
2118 | case 9: | |
2d39ccd3 | 2119 | rettype = init_integer_type (alloc, 32, 1, "unsigned"); |
89acf84d | 2120 | break; |
c906108c | 2121 | case 10: |
2d39ccd3 | 2122 | rettype = init_integer_type (alloc, 32, 1, "unsigned long"); |
c906108c SS |
2123 | break; |
2124 | case 11: | |
33385940 | 2125 | rettype = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void"); |
c906108c SS |
2126 | break; |
2127 | case 12: | |
2128 | /* IEEE single precision (32 bit). */ | |
77c5f496 | 2129 | rettype = init_float_type (alloc, 32, "float", |
49f190bc | 2130 | floatformats_ieee_single); |
c906108c SS |
2131 | break; |
2132 | case 13: | |
2133 | /* IEEE double precision (64 bit). */ | |
77c5f496 | 2134 | rettype = init_float_type (alloc, 64, "double", |
49f190bc | 2135 | floatformats_ieee_double); |
c906108c SS |
2136 | break; |
2137 | case 14: | |
2138 | /* This is an IEEE double on the RS/6000, and different machines with | |
dda83cd7 SM |
2139 | different sizes for "long double" should use different negative |
2140 | type numbers. See stabs.texinfo. */ | |
77c5f496 | 2141 | rettype = init_float_type (alloc, 64, "long double", |
49f190bc | 2142 | floatformats_ieee_double); |
c906108c SS |
2143 | break; |
2144 | case 15: | |
2d39ccd3 | 2145 | rettype = init_integer_type (alloc, 32, 0, "integer"); |
c906108c SS |
2146 | break; |
2147 | case 16: | |
46c04ea3 | 2148 | rettype = init_boolean_type (alloc, 32, 1, "boolean"); |
c906108c SS |
2149 | break; |
2150 | case 17: | |
77c5f496 | 2151 | rettype = init_float_type (alloc, 32, "short real", |
49f190bc | 2152 | floatformats_ieee_single); |
c906108c SS |
2153 | break; |
2154 | case 18: | |
77c5f496 | 2155 | rettype = init_float_type (alloc, 64, "real", |
49f190bc | 2156 | floatformats_ieee_double); |
c906108c SS |
2157 | break; |
2158 | case 19: | |
33385940 | 2159 | rettype = alloc.new_type (TYPE_CODE_ERROR, 0, "stringptr"); |
c906108c SS |
2160 | break; |
2161 | case 20: | |
f50b437c | 2162 | rettype = init_character_type (alloc, 8, 1, "character"); |
c906108c SS |
2163 | break; |
2164 | case 21: | |
46c04ea3 | 2165 | rettype = init_boolean_type (alloc, 8, 1, "logical*1"); |
c906108c SS |
2166 | break; |
2167 | case 22: | |
46c04ea3 | 2168 | rettype = init_boolean_type (alloc, 16, 1, "logical*2"); |
c906108c SS |
2169 | break; |
2170 | case 23: | |
46c04ea3 | 2171 | rettype = init_boolean_type (alloc, 32, 1, "logical*4"); |
c906108c SS |
2172 | break; |
2173 | case 24: | |
46c04ea3 | 2174 | rettype = init_boolean_type (alloc, 32, 1, "logical"); |
c906108c SS |
2175 | break; |
2176 | case 25: | |
2177 | /* Complex type consisting of two IEEE single precision values. */ | |
5b930b45 | 2178 | rettype = init_complex_type ("complex", |
19f392bc | 2179 | rs6000_builtin_type (12, objfile)); |
c906108c SS |
2180 | break; |
2181 | case 26: | |
2182 | /* Complex type consisting of two IEEE double precision values. */ | |
5b930b45 | 2183 | rettype = init_complex_type ("double complex", |
19f392bc | 2184 | rs6000_builtin_type (13, objfile)); |
c906108c SS |
2185 | break; |
2186 | case 27: | |
2d39ccd3 | 2187 | rettype = init_integer_type (alloc, 8, 0, "integer*1"); |
c906108c SS |
2188 | break; |
2189 | case 28: | |
2d39ccd3 | 2190 | rettype = init_integer_type (alloc, 16, 0, "integer*2"); |
c906108c SS |
2191 | break; |
2192 | case 29: | |
2d39ccd3 | 2193 | rettype = init_integer_type (alloc, 32, 0, "integer*4"); |
c906108c SS |
2194 | break; |
2195 | case 30: | |
f50b437c | 2196 | rettype = init_character_type (alloc, 16, 0, "wchar"); |
c906108c SS |
2197 | break; |
2198 | case 31: | |
2d39ccd3 | 2199 | rettype = init_integer_type (alloc, 64, 0, "long long"); |
c906108c SS |
2200 | break; |
2201 | case 32: | |
2d39ccd3 | 2202 | rettype = init_integer_type (alloc, 64, 1, "unsigned long long"); |
c906108c SS |
2203 | break; |
2204 | case 33: | |
2d39ccd3 | 2205 | rettype = init_integer_type (alloc, 64, 1, "logical*8"); |
c906108c SS |
2206 | break; |
2207 | case 34: | |
2d39ccd3 | 2208 | rettype = init_integer_type (alloc, 64, 0, "integer*8"); |
c906108c SS |
2209 | break; |
2210 | } | |
2211 | negative_types[-typenum] = rettype; | |
2212 | return rettype; | |
2213 | } | |
2214 | \f | |
2215 | /* This page contains subroutines of read_type. */ | |
2216 | ||
0d5cff50 DE |
2217 | /* Wrapper around method_name_from_physname to flag a complaint |
2218 | if there is an error. */ | |
de17c821 | 2219 | |
0d5cff50 DE |
2220 | static char * |
2221 | stabs_method_name_from_physname (const char *physname) | |
de17c821 DJ |
2222 | { |
2223 | char *method_name; | |
2224 | ||
2225 | method_name = method_name_from_physname (physname); | |
2226 | ||
2227 | if (method_name == NULL) | |
c263362b | 2228 | { |
b98664d3 | 2229 | complaint (_("Method has bad physname %s\n"), physname); |
0d5cff50 | 2230 | return NULL; |
c263362b | 2231 | } |
de17c821 | 2232 | |
0d5cff50 | 2233 | return method_name; |
de17c821 DJ |
2234 | } |
2235 | ||
c906108c SS |
2236 | /* Read member function stabs info for C++ classes. The form of each member |
2237 | function data is: | |
2238 | ||
c5aa993b | 2239 | NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; |
c906108c SS |
2240 | |
2241 | An example with two member functions is: | |
2242 | ||
c5aa993b | 2243 | afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; |
c906108c SS |
2244 | |
2245 | For the case of overloaded operators, the format is op$::*.funcs, where | |
2246 | $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator | |
2247 | name (such as `+=') and `.' marks the end of the operator name. | |
2248 | ||
2249 | Returns 1 for success, 0 for failure. */ | |
2250 | ||
2251 | static int | |
61b30099 | 2252 | read_member_functions (struct stab_field_info *fip, const char **pp, |
a121b7c1 | 2253 | struct type *type, struct objfile *objfile) |
c906108c SS |
2254 | { |
2255 | int nfn_fields = 0; | |
2256 | int length = 0; | |
c906108c SS |
2257 | int i; |
2258 | struct next_fnfield | |
2259 | { | |
2260 | struct next_fnfield *next; | |
2261 | struct fn_field fn_field; | |
c5aa993b JM |
2262 | } |
2263 | *sublist; | |
c906108c SS |
2264 | struct type *look_ahead_type; |
2265 | struct next_fnfieldlist *new_fnlist; | |
2266 | struct next_fnfield *new_sublist; | |
2267 | char *main_fn_name; | |
a121b7c1 | 2268 | const char *p; |
c5aa993b | 2269 | |
c906108c | 2270 | /* Process each list until we find something that is not a member function |
c378eb4e | 2271 | or find the end of the functions. */ |
c906108c SS |
2272 | |
2273 | while (**pp != ';') | |
2274 | { | |
2275 | /* We should be positioned at the start of the function name. | |
dda83cd7 SM |
2276 | Scan forward to find the first ':' and if it is not the |
2277 | first of a "::" delimiter, then this is not a member function. */ | |
c906108c SS |
2278 | p = *pp; |
2279 | while (*p != ':') | |
2280 | { | |
2281 | p++; | |
2282 | } | |
2283 | if (p[1] != ':') | |
2284 | { | |
2285 | break; | |
2286 | } | |
2287 | ||
2288 | sublist = NULL; | |
2289 | look_ahead_type = NULL; | |
2290 | length = 0; | |
c5aa993b | 2291 | |
61b30099 | 2292 | new_fnlist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfieldlist); |
c5aa993b | 2293 | |
c906108c SS |
2294 | if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2])) |
2295 | { | |
2296 | /* This is a completely wierd case. In order to stuff in the | |
2297 | names that might contain colons (the usual name delimiter), | |
2298 | Mike Tiemann defined a different name format which is | |
2299 | signalled if the identifier is "op$". In that case, the | |
2300 | format is "op$::XXXX." where XXXX is the name. This is | |
2301 | used for names like "+" or "=". YUUUUUUUK! FIXME! */ | |
2302 | /* This lets the user type "break operator+". | |
2303 | We could just put in "+" as the name, but that wouldn't | |
2304 | work for "*". */ | |
8343f86c | 2305 | static char opname[32] = "op$"; |
c906108c | 2306 | char *o = opname + 3; |
c5aa993b | 2307 | |
c906108c SS |
2308 | /* Skip past '::'. */ |
2309 | *pp = p + 2; | |
2310 | ||
2311 | STABS_CONTINUE (pp, objfile); | |
2312 | p = *pp; | |
2313 | while (*p != '.') | |
2314 | { | |
2315 | *o++ = *p++; | |
2316 | } | |
2317 | main_fn_name = savestring (opname, o - opname); | |
2318 | /* Skip past '.' */ | |
2319 | *pp = p + 1; | |
2320 | } | |
2321 | else | |
2322 | { | |
2323 | main_fn_name = savestring (*pp, p - *pp); | |
2324 | /* Skip past '::'. */ | |
2325 | *pp = p + 2; | |
2326 | } | |
c5aa993b JM |
2327 | new_fnlist->fn_fieldlist.name = main_fn_name; |
2328 | ||
c906108c SS |
2329 | do |
2330 | { | |
61b30099 | 2331 | new_sublist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfield); |
c5aa993b | 2332 | |
c906108c SS |
2333 | /* Check for and handle cretinous dbx symbol name continuation! */ |
2334 | if (look_ahead_type == NULL) | |
2335 | { | |
c378eb4e | 2336 | /* Normal case. */ |
c906108c | 2337 | STABS_CONTINUE (pp, objfile); |
c5aa993b JM |
2338 | |
2339 | new_sublist->fn_field.type = read_type (pp, objfile); | |
c906108c SS |
2340 | if (**pp != ':') |
2341 | { | |
2342 | /* Invalid symtab info for member function. */ | |
2343 | return 0; | |
2344 | } | |
2345 | } | |
2346 | else | |
2347 | { | |
2348 | /* g++ version 1 kludge */ | |
c5aa993b | 2349 | new_sublist->fn_field.type = look_ahead_type; |
c906108c SS |
2350 | look_ahead_type = NULL; |
2351 | } | |
c5aa993b | 2352 | |
c906108c SS |
2353 | (*pp)++; |
2354 | p = *pp; | |
2355 | while (*p != ';') | |
2356 | { | |
2357 | p++; | |
2358 | } | |
c5aa993b | 2359 | |
09e2d7c7 | 2360 | /* These are methods, not functions. */ |
78134374 | 2361 | if (new_sublist->fn_field.type->code () == TYPE_CODE_FUNC) |
67607e24 | 2362 | new_sublist->fn_field.type->set_code (TYPE_CODE_METHOD); |
c906108c | 2363 | |
09e2d7c7 | 2364 | /* If this is just a stub, then we don't have the real name here. */ |
e46d3488 | 2365 | if (new_sublist->fn_field.type->is_stub ()) |
c906108c | 2366 | { |
4bfb94b8 | 2367 | if (!TYPE_SELF_TYPE (new_sublist->fn_field.type)) |
09e2d7c7 | 2368 | set_type_self_type (new_sublist->fn_field.type, type); |
c5aa993b | 2369 | new_sublist->fn_field.is_stub = 1; |
c906108c | 2370 | } |
09e2d7c7 | 2371 | |
c5aa993b | 2372 | new_sublist->fn_field.physname = savestring (*pp, p - *pp); |
c906108c | 2373 | *pp = p + 1; |
c5aa993b | 2374 | |
c906108c SS |
2375 | /* Set this member function's visibility fields. */ |
2376 | switch (*(*pp)++) | |
2377 | { | |
c5aa993b JM |
2378 | case VISIBILITY_PRIVATE: |
2379 | new_sublist->fn_field.is_private = 1; | |
2380 | break; | |
2381 | case VISIBILITY_PROTECTED: | |
2382 | new_sublist->fn_field.is_protected = 1; | |
2383 | break; | |
c906108c | 2384 | } |
c5aa993b | 2385 | |
c906108c SS |
2386 | STABS_CONTINUE (pp, objfile); |
2387 | switch (**pp) | |
2388 | { | |
c378eb4e | 2389 | case 'A': /* Normal functions. */ |
c5aa993b JM |
2390 | new_sublist->fn_field.is_const = 0; |
2391 | new_sublist->fn_field.is_volatile = 0; | |
2392 | (*pp)++; | |
2393 | break; | |
c378eb4e | 2394 | case 'B': /* `const' member functions. */ |
c5aa993b JM |
2395 | new_sublist->fn_field.is_const = 1; |
2396 | new_sublist->fn_field.is_volatile = 0; | |
2397 | (*pp)++; | |
2398 | break; | |
c378eb4e | 2399 | case 'C': /* `volatile' member function. */ |
c5aa993b JM |
2400 | new_sublist->fn_field.is_const = 0; |
2401 | new_sublist->fn_field.is_volatile = 1; | |
2402 | (*pp)++; | |
2403 | break; | |
c378eb4e | 2404 | case 'D': /* `const volatile' member function. */ |
c5aa993b JM |
2405 | new_sublist->fn_field.is_const = 1; |
2406 | new_sublist->fn_field.is_volatile = 1; | |
2407 | (*pp)++; | |
2408 | break; | |
3e43a32a | 2409 | case '*': /* File compiled with g++ version 1 -- |
c378eb4e | 2410 | no info. */ |
c5aa993b JM |
2411 | case '?': |
2412 | case '.': | |
2413 | break; | |
2414 | default: | |
b98664d3 | 2415 | complaint (_("const/volatile indicator missing, got '%c'"), |
3e43a32a | 2416 | **pp); |
c5aa993b | 2417 | break; |
c906108c | 2418 | } |
c5aa993b | 2419 | |
c906108c SS |
2420 | switch (*(*pp)++) |
2421 | { | |
c5aa993b | 2422 | case '*': |
c906108c SS |
2423 | { |
2424 | int nbits; | |
c5aa993b | 2425 | /* virtual member function, followed by index. |
c906108c SS |
2426 | The sign bit is set to distinguish pointers-to-methods |
2427 | from virtual function indicies. Since the array is | |
2428 | in words, the quantity must be shifted left by 1 | |
2429 | on 16 bit machine, and by 2 on 32 bit machine, forcing | |
2430 | the sign bit out, and usable as a valid index into | |
2431 | the array. Remove the sign bit here. */ | |
c5aa993b | 2432 | new_sublist->fn_field.voffset = |
94e10a22 | 2433 | (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2; |
c906108c SS |
2434 | if (nbits != 0) |
2435 | return 0; | |
c5aa993b | 2436 | |
c906108c SS |
2437 | STABS_CONTINUE (pp, objfile); |
2438 | if (**pp == ';' || **pp == '\0') | |
2439 | { | |
2440 | /* Must be g++ version 1. */ | |
c5aa993b | 2441 | new_sublist->fn_field.fcontext = 0; |
c906108c SS |
2442 | } |
2443 | else | |
2444 | { | |
2445 | /* Figure out from whence this virtual function came. | |
2446 | It may belong to virtual function table of | |
2447 | one of its baseclasses. */ | |
2448 | look_ahead_type = read_type (pp, objfile); | |
2449 | if (**pp == ':') | |
2450 | { | |
c378eb4e | 2451 | /* g++ version 1 overloaded methods. */ |
c906108c SS |
2452 | } |
2453 | else | |
2454 | { | |
c5aa993b | 2455 | new_sublist->fn_field.fcontext = look_ahead_type; |
c906108c SS |
2456 | if (**pp != ';') |
2457 | { | |
2458 | return 0; | |
2459 | } | |
2460 | else | |
2461 | { | |
2462 | ++*pp; | |
2463 | } | |
2464 | look_ahead_type = NULL; | |
2465 | } | |
2466 | } | |
2467 | break; | |
2468 | } | |
c5aa993b JM |
2469 | case '?': |
2470 | /* static member function. */ | |
4ea09c10 PS |
2471 | { |
2472 | int slen = strlen (main_fn_name); | |
2473 | ||
2474 | new_sublist->fn_field.voffset = VOFFSET_STATIC; | |
2475 | ||
2476 | /* For static member functions, we can't tell if they | |
2477 | are stubbed, as they are put out as functions, and not as | |
2478 | methods. | |
2479 | GCC v2 emits the fully mangled name if | |
2480 | dbxout.c:flag_minimal_debug is not set, so we have to | |
2481 | detect a fully mangled physname here and set is_stub | |
2482 | accordingly. Fully mangled physnames in v2 start with | |
2483 | the member function name, followed by two underscores. | |
2484 | GCC v3 currently always emits stubbed member functions, | |
2485 | but with fully mangled physnames, which start with _Z. */ | |
2486 | if (!(strncmp (new_sublist->fn_field.physname, | |
2487 | main_fn_name, slen) == 0 | |
2488 | && new_sublist->fn_field.physname[slen] == '_' | |
2489 | && new_sublist->fn_field.physname[slen + 1] == '_')) | |
2490 | { | |
2491 | new_sublist->fn_field.is_stub = 1; | |
2492 | } | |
2493 | break; | |
2494 | } | |
c5aa993b JM |
2495 | |
2496 | default: | |
2497 | /* error */ | |
b98664d3 | 2498 | complaint (_("member function type missing, got '%c'"), |
3e43a32a | 2499 | (*pp)[-1]); |
86a73007 TT |
2500 | /* Normal member function. */ |
2501 | /* Fall through. */ | |
c5aa993b JM |
2502 | |
2503 | case '.': | |
2504 | /* normal member function. */ | |
2505 | new_sublist->fn_field.voffset = 0; | |
2506 | new_sublist->fn_field.fcontext = 0; | |
2507 | break; | |
c906108c | 2508 | } |
c5aa993b JM |
2509 | |
2510 | new_sublist->next = sublist; | |
c906108c SS |
2511 | sublist = new_sublist; |
2512 | length++; | |
2513 | STABS_CONTINUE (pp, objfile); | |
2514 | } | |
2515 | while (**pp != ';' && **pp != '\0'); | |
c5aa993b | 2516 | |
c906108c | 2517 | (*pp)++; |
0c867556 | 2518 | STABS_CONTINUE (pp, objfile); |
c5aa993b | 2519 | |
0c867556 PS |
2520 | /* Skip GCC 3.X member functions which are duplicates of the callable |
2521 | constructor/destructor. */ | |
6cbbcdfe KS |
2522 | if (strcmp_iw (main_fn_name, "__base_ctor ") == 0 |
2523 | || strcmp_iw (main_fn_name, "__base_dtor ") == 0 | |
0c867556 | 2524 | || strcmp (main_fn_name, "__deleting_dtor") == 0) |
c906108c | 2525 | { |
0c867556 | 2526 | xfree (main_fn_name); |
c906108c | 2527 | } |
0c867556 PS |
2528 | else |
2529 | { | |
de17c821 DJ |
2530 | int has_destructor = 0, has_other = 0; |
2531 | int is_v3 = 0; | |
2532 | struct next_fnfield *tmp_sublist; | |
2533 | ||
2534 | /* Various versions of GCC emit various mostly-useless | |
2535 | strings in the name field for special member functions. | |
2536 | ||
2537 | For stub methods, we need to defer correcting the name | |
2538 | until we are ready to unstub the method, because the current | |
2539 | name string is used by gdb_mangle_name. The only stub methods | |
2540 | of concern here are GNU v2 operators; other methods have their | |
2541 | names correct (see caveat below). | |
2542 | ||
2543 | For non-stub methods, in GNU v3, we have a complete physname. | |
2544 | Therefore we can safely correct the name now. This primarily | |
2545 | affects constructors and destructors, whose name will be | |
2546 | __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast | |
2547 | operators will also have incorrect names; for instance, | |
2548 | "operator int" will be named "operator i" (i.e. the type is | |
2549 | mangled). | |
2550 | ||
2551 | For non-stub methods in GNU v2, we have no easy way to | |
2552 | know if we have a complete physname or not. For most | |
2553 | methods the result depends on the platform (if CPLUS_MARKER | |
2554 | can be `$' or `.', it will use minimal debug information, or | |
2555 | otherwise the full physname will be included). | |
2556 | ||
2557 | Rather than dealing with this, we take a different approach. | |
2558 | For v3 mangled names, we can use the full physname; for v2, | |
2559 | we use cplus_demangle_opname (which is actually v2 specific), | |
2560 | because the only interesting names are all operators - once again | |
2561 | barring the caveat below. Skip this process if any method in the | |
2562 | group is a stub, to prevent our fouling up the workings of | |
2563 | gdb_mangle_name. | |
2564 | ||
2565 | The caveat: GCC 2.95.x (and earlier?) put constructors and | |
2566 | destructors in the same method group. We need to split this | |
2567 | into two groups, because they should have different names. | |
2568 | So for each method group we check whether it contains both | |
2569 | routines whose physname appears to be a destructor (the physnames | |
2570 | for and destructors are always provided, due to quirks in v2 | |
2571 | mangling) and routines whose physname does not appear to be a | |
2572 | destructor. If so then we break up the list into two halves. | |
2573 | Even if the constructors and destructors aren't in the same group | |
2574 | the destructor will still lack the leading tilde, so that also | |
2575 | needs to be fixed. | |
2576 | ||
2577 | So, to summarize what we expect and handle here: | |
2578 | ||
dda83cd7 | 2579 | Given Given Real Real Action |
de17c821 DJ |
2580 | method name physname physname method name |
2581 | ||
2582 | __opi [none] __opi__3Foo operator int opname | |
dda83cd7 | 2583 | [now or later] |
3e43a32a | 2584 | Foo _._3Foo _._3Foo ~Foo separate and |
dda83cd7 | 2585 | rename |
de17c821 DJ |
2586 | operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle |
2587 | __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle | |
2588 | */ | |
2589 | ||
2590 | tmp_sublist = sublist; | |
2591 | while (tmp_sublist != NULL) | |
2592 | { | |
de17c821 DJ |
2593 | if (tmp_sublist->fn_field.physname[0] == '_' |
2594 | && tmp_sublist->fn_field.physname[1] == 'Z') | |
2595 | is_v3 = 1; | |
2596 | ||
2597 | if (is_destructor_name (tmp_sublist->fn_field.physname)) | |
2598 | has_destructor++; | |
2599 | else | |
2600 | has_other++; | |
2601 | ||
2602 | tmp_sublist = tmp_sublist->next; | |
2603 | } | |
2604 | ||
2605 | if (has_destructor && has_other) | |
2606 | { | |
2607 | struct next_fnfieldlist *destr_fnlist; | |
2608 | struct next_fnfield *last_sublist; | |
2609 | ||
2610 | /* Create a new fn_fieldlist for the destructors. */ | |
2611 | ||
61b30099 TT |
2612 | destr_fnlist = OBSTACK_ZALLOC (&fip->obstack, |
2613 | struct next_fnfieldlist); | |
8d749320 | 2614 | |
de17c821 | 2615 | destr_fnlist->fn_fieldlist.name |
48cb83fd JK |
2616 | = obconcat (&objfile->objfile_obstack, "~", |
2617 | new_fnlist->fn_fieldlist.name, (char *) NULL); | |
de17c821 | 2618 | |
8d749320 SM |
2619 | destr_fnlist->fn_fieldlist.fn_fields = |
2620 | XOBNEWVEC (&objfile->objfile_obstack, | |
2621 | struct fn_field, has_destructor); | |
de17c821 DJ |
2622 | memset (destr_fnlist->fn_fieldlist.fn_fields, 0, |
2623 | sizeof (struct fn_field) * has_destructor); | |
2624 | tmp_sublist = sublist; | |
2625 | last_sublist = NULL; | |
2626 | i = 0; | |
2627 | while (tmp_sublist != NULL) | |
2628 | { | |
2629 | if (!is_destructor_name (tmp_sublist->fn_field.physname)) | |
2630 | { | |
2631 | tmp_sublist = tmp_sublist->next; | |
2632 | continue; | |
2633 | } | |
2634 | ||
2635 | destr_fnlist->fn_fieldlist.fn_fields[i++] | |
2636 | = tmp_sublist->fn_field; | |
2637 | if (last_sublist) | |
2638 | last_sublist->next = tmp_sublist->next; | |
2639 | else | |
2640 | sublist = tmp_sublist->next; | |
2641 | last_sublist = tmp_sublist; | |
2642 | tmp_sublist = tmp_sublist->next; | |
2643 | } | |
2644 | ||
2645 | destr_fnlist->fn_fieldlist.length = has_destructor; | |
2646 | destr_fnlist->next = fip->fnlist; | |
2647 | fip->fnlist = destr_fnlist; | |
2648 | nfn_fields++; | |
de17c821 DJ |
2649 | length -= has_destructor; |
2650 | } | |
2651 | else if (is_v3) | |
2652 | { | |
2653 | /* v3 mangling prevents the use of abbreviated physnames, | |
2654 | so we can do this here. There are stubbed methods in v3 | |
2655 | only: | |
2656 | - in -gstabs instead of -gstabs+ | |
2657 | - or for static methods, which are output as a function type | |
2658 | instead of a method type. */ | |
0d5cff50 DE |
2659 | char *new_method_name = |
2660 | stabs_method_name_from_physname (sublist->fn_field.physname); | |
de17c821 | 2661 | |
0d5cff50 DE |
2662 | if (new_method_name != NULL |
2663 | && strcmp (new_method_name, | |
2664 | new_fnlist->fn_fieldlist.name) != 0) | |
2665 | { | |
2666 | new_fnlist->fn_fieldlist.name = new_method_name; | |
2667 | xfree (main_fn_name); | |
2668 | } | |
2669 | else | |
2670 | xfree (new_method_name); | |
de17c821 DJ |
2671 | } |
2672 | else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~') | |
2673 | { | |
1754f103 | 2674 | new_fnlist->fn_fieldlist.name = |
0d5cff50 DE |
2675 | obconcat (&objfile->objfile_obstack, |
2676 | "~", main_fn_name, (char *)NULL); | |
de17c821 DJ |
2677 | xfree (main_fn_name); |
2678 | } | |
de17c821 | 2679 | |
e39db4db SM |
2680 | new_fnlist->fn_fieldlist.fn_fields |
2681 | = OBSTACK_CALLOC (&objfile->objfile_obstack, length, fn_field); | |
0c867556 PS |
2682 | for (i = length; (i--, sublist); sublist = sublist->next) |
2683 | { | |
2684 | new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field; | |
2685 | } | |
c5aa993b | 2686 | |
0c867556 PS |
2687 | new_fnlist->fn_fieldlist.length = length; |
2688 | new_fnlist->next = fip->fnlist; | |
2689 | fip->fnlist = new_fnlist; | |
2690 | nfn_fields++; | |
0c867556 | 2691 | } |
c906108c SS |
2692 | } |
2693 | ||
2694 | if (nfn_fields) | |
2695 | { | |
2696 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
2697 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
2698 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields); | |
2699 | memset (TYPE_FN_FIELDLISTS (type), 0, | |
2700 | sizeof (struct fn_fieldlist) * nfn_fields); | |
2701 | TYPE_NFN_FIELDS (type) = nfn_fields; | |
c906108c SS |
2702 | } |
2703 | ||
2704 | return 1; | |
2705 | } | |
2706 | ||
2707 | /* Special GNU C++ name. | |
2708 | ||
2709 | Returns 1 for success, 0 for failure. "failure" means that we can't | |
2710 | keep parsing and it's time for error_type(). */ | |
2711 | ||
2712 | static int | |
61b30099 TT |
2713 | read_cpp_abbrev (struct stab_field_info *fip, const char **pp, |
2714 | struct type *type, struct objfile *objfile) | |
c906108c | 2715 | { |
a121b7c1 | 2716 | const char *p; |
0d5cff50 | 2717 | const char *name; |
c906108c SS |
2718 | char cpp_abbrev; |
2719 | struct type *context; | |
2720 | ||
2721 | p = *pp; | |
2722 | if (*++p == 'v') | |
2723 | { | |
2724 | name = NULL; | |
2725 | cpp_abbrev = *++p; | |
2726 | ||
2727 | *pp = p + 1; | |
2728 | ||
2729 | /* At this point, *pp points to something like "22:23=*22...", | |
dda83cd7 SM |
2730 | where the type number before the ':' is the "context" and |
2731 | everything after is a regular type definition. Lookup the | |
2732 | type, find it's name, and construct the field name. */ | |
c906108c SS |
2733 | |
2734 | context = read_type (pp, objfile); | |
2735 | ||
2736 | switch (cpp_abbrev) | |
2737 | { | |
c5aa993b | 2738 | case 'f': /* $vf -- a virtual function table pointer */ |
7d93a1e0 | 2739 | name = context->name (); |
c2bd2ed9 | 2740 | if (name == NULL) |
433759f7 MS |
2741 | { |
2742 | name = ""; | |
2743 | } | |
d3fd12df SM |
2744 | fip->list->field.set_name (obconcat (&objfile->objfile_obstack, |
2745 | vptr_name, name, (char *) NULL)); | |
c5aa993b | 2746 | break; |
c906108c | 2747 | |
c5aa993b | 2748 | case 'b': /* $vb -- a virtual bsomethingorother */ |
7d93a1e0 | 2749 | name = context->name (); |
c5aa993b JM |
2750 | if (name == NULL) |
2751 | { | |
b98664d3 | 2752 | complaint (_("C++ abbreviated type name " |
3e43a32a | 2753 | "unknown at symtab pos %d"), |
23136709 | 2754 | symnum); |
c5aa993b JM |
2755 | name = "FOO"; |
2756 | } | |
d3fd12df SM |
2757 | fip->list->field.set_name (obconcat (&objfile->objfile_obstack, |
2758 | vb_name, name, (char *) NULL)); | |
c5aa993b | 2759 | break; |
c906108c | 2760 | |
c5aa993b | 2761 | default: |
23136709 | 2762 | invalid_cpp_abbrev_complaint (*pp); |
d3fd12df SM |
2763 | fip->list->field.set_name (obconcat (&objfile->objfile_obstack, |
2764 | "INVALID_CPLUSPLUS_ABBREV", | |
2765 | (char *) NULL)); | |
c5aa993b | 2766 | break; |
c906108c SS |
2767 | } |
2768 | ||
2769 | /* At this point, *pp points to the ':'. Skip it and read the | |
dda83cd7 | 2770 | field type. */ |
c906108c SS |
2771 | |
2772 | p = ++(*pp); | |
2773 | if (p[-1] != ':') | |
2774 | { | |
23136709 | 2775 | invalid_cpp_abbrev_complaint (*pp); |
c906108c SS |
2776 | return 0; |
2777 | } | |
5d14b6e5 | 2778 | fip->list->field.set_type (read_type (pp, objfile)); |
c906108c | 2779 | if (**pp == ',') |
c5aa993b | 2780 | (*pp)++; /* Skip the comma. */ |
c906108c SS |
2781 | else |
2782 | return 0; | |
2783 | ||
2784 | { | |
2785 | int nbits; | |
433759f7 | 2786 | |
cd3f655c | 2787 | fip->list->field.set_loc_bitpos (read_huge_number (pp, ';', &nbits, 0)); |
c906108c SS |
2788 | if (nbits != 0) |
2789 | return 0; | |
2790 | } | |
2791 | /* This field is unpacked. */ | |
2792 | FIELD_BITSIZE (fip->list->field) = 0; | |
2793 | fip->list->visibility = VISIBILITY_PRIVATE; | |
2794 | } | |
2795 | else | |
2796 | { | |
23136709 | 2797 | invalid_cpp_abbrev_complaint (*pp); |
c906108c | 2798 | /* We have no idea what syntax an unrecognized abbrev would have, so |
dda83cd7 SM |
2799 | better return 0. If we returned 1, we would need to at least advance |
2800 | *pp to avoid an infinite loop. */ | |
c906108c SS |
2801 | return 0; |
2802 | } | |
2803 | return 1; | |
2804 | } | |
2805 | ||
2806 | static void | |
61b30099 TT |
2807 | read_one_struct_field (struct stab_field_info *fip, const char **pp, |
2808 | const char *p, struct type *type, | |
2809 | struct objfile *objfile) | |
c906108c | 2810 | { |
08feed99 | 2811 | struct gdbarch *gdbarch = objfile->arch (); |
5e2b427d | 2812 | |
d3fd12df SM |
2813 | fip->list->field.set_name |
2814 | (obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp)); | |
c906108c SS |
2815 | *pp = p + 1; |
2816 | ||
c378eb4e | 2817 | /* This means we have a visibility for a field coming. */ |
c906108c SS |
2818 | if (**pp == '/') |
2819 | { | |
2820 | (*pp)++; | |
c5aa993b | 2821 | fip->list->visibility = *(*pp)++; |
c906108c SS |
2822 | } |
2823 | else | |
2824 | { | |
2825 | /* normal dbx-style format, no explicit visibility */ | |
c5aa993b | 2826 | fip->list->visibility = VISIBILITY_PUBLIC; |
c906108c SS |
2827 | } |
2828 | ||
5d14b6e5 | 2829 | fip->list->field.set_type (read_type (pp, objfile)); |
c906108c SS |
2830 | if (**pp == ':') |
2831 | { | |
2832 | p = ++(*pp); | |
2833 | #if 0 | |
c378eb4e | 2834 | /* Possible future hook for nested types. */ |
c906108c SS |
2835 | if (**pp == '!') |
2836 | { | |
c5aa993b | 2837 | fip->list->field.bitpos = (long) -2; /* nested type */ |
c906108c SS |
2838 | p = ++(*pp); |
2839 | } | |
c5aa993b JM |
2840 | else |
2841 | ...; | |
c906108c | 2842 | #endif |
c5aa993b | 2843 | while (*p != ';') |
c906108c SS |
2844 | { |
2845 | p++; | |
2846 | } | |
2847 | /* Static class member. */ | |
cd3f655c | 2848 | fip->list->field.set_loc_physname (savestring (*pp, p - *pp)); |
c906108c SS |
2849 | *pp = p + 1; |
2850 | return; | |
2851 | } | |
2852 | else if (**pp != ',') | |
2853 | { | |
2854 | /* Bad structure-type format. */ | |
23136709 | 2855 | stabs_general_complaint ("bad structure-type format"); |
c906108c SS |
2856 | return; |
2857 | } | |
2858 | ||
2859 | (*pp)++; /* Skip the comma. */ | |
2860 | ||
2861 | { | |
2862 | int nbits; | |
433759f7 | 2863 | |
cd3f655c | 2864 | fip->list->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0)); |
c906108c SS |
2865 | if (nbits != 0) |
2866 | { | |
23136709 | 2867 | stabs_general_complaint ("bad structure-type format"); |
c906108c SS |
2868 | return; |
2869 | } | |
94e10a22 | 2870 | FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits, 0); |
c906108c SS |
2871 | if (nbits != 0) |
2872 | { | |
23136709 | 2873 | stabs_general_complaint ("bad structure-type format"); |
c906108c SS |
2874 | return; |
2875 | } | |
2876 | } | |
2877 | ||
3a543e21 | 2878 | if (fip->list->field.loc_bitpos () == 0 |
c906108c SS |
2879 | && FIELD_BITSIZE (fip->list->field) == 0) |
2880 | { | |
2881 | /* This can happen in two cases: (1) at least for gcc 2.4.5 or so, | |
dda83cd7 SM |
2882 | it is a field which has been optimized out. The correct stab for |
2883 | this case is to use VISIBILITY_IGNORE, but that is a recent | |
2884 | invention. (2) It is a 0-size array. For example | |
2885 | union { int num; char str[0]; } foo. Printing _("<no value>" for | |
2886 | str in "p foo" is OK, since foo.str (and thus foo.str[3]) | |
2887 | will continue to work, and a 0-size array as a whole doesn't | |
2888 | have any contents to print. | |
2889 | ||
2890 | I suspect this probably could also happen with gcc -gstabs (not | |
2891 | -gstabs+) for static fields, and perhaps other C++ extensions. | |
2892 | Hopefully few people use -gstabs with gdb, since it is intended | |
2893 | for dbx compatibility. */ | |
c906108c SS |
2894 | |
2895 | /* Ignore this field. */ | |
c5aa993b | 2896 | fip->list->visibility = VISIBILITY_IGNORE; |
c906108c SS |
2897 | } |
2898 | else | |
2899 | { | |
2900 | /* Detect an unpacked field and mark it as such. | |
dda83cd7 SM |
2901 | dbx gives a bit size for all fields. |
2902 | Note that forward refs cannot be packed, | |
2903 | and treat enums as if they had the width of ints. */ | |
c906108c | 2904 | |
b6cdac4b | 2905 | struct type *field_type = check_typedef (fip->list->field.type ()); |
c906108c | 2906 | |
78134374 SM |
2907 | if (field_type->code () != TYPE_CODE_INT |
2908 | && field_type->code () != TYPE_CODE_RANGE | |
2909 | && field_type->code () != TYPE_CODE_BOOL | |
2910 | && field_type->code () != TYPE_CODE_ENUM) | |
c906108c SS |
2911 | { |
2912 | FIELD_BITSIZE (fip->list->field) = 0; | |
2913 | } | |
c5aa993b | 2914 | if ((FIELD_BITSIZE (fip->list->field) |
df86565b | 2915 | == TARGET_CHAR_BIT * field_type->length () |
78134374 | 2916 | || (field_type->code () == TYPE_CODE_ENUM |
9a76efb6 | 2917 | && FIELD_BITSIZE (fip->list->field) |
5e2b427d | 2918 | == gdbarch_int_bit (gdbarch)) |
c5aa993b | 2919 | ) |
c906108c | 2920 | && |
3a543e21 | 2921 | fip->list->field.loc_bitpos () % 8 == 0) |
c906108c SS |
2922 | { |
2923 | FIELD_BITSIZE (fip->list->field) = 0; | |
2924 | } | |
2925 | } | |
2926 | } | |
2927 | ||
2928 | ||
2929 | /* Read struct or class data fields. They have the form: | |
2930 | ||
c5aa993b | 2931 | NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; |
c906108c SS |
2932 | |
2933 | At the end, we see a semicolon instead of a field. | |
2934 | ||
2935 | In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for | |
2936 | a static field. | |
2937 | ||
2938 | The optional VISIBILITY is one of: | |
2939 | ||
c5aa993b JM |
2940 | '/0' (VISIBILITY_PRIVATE) |
2941 | '/1' (VISIBILITY_PROTECTED) | |
2942 | '/2' (VISIBILITY_PUBLIC) | |
2943 | '/9' (VISIBILITY_IGNORE) | |
c906108c SS |
2944 | |
2945 | or nothing, for C style fields with public visibility. | |
2946 | ||
2947 | Returns 1 for success, 0 for failure. */ | |
2948 | ||
2949 | static int | |
61b30099 TT |
2950 | read_struct_fields (struct stab_field_info *fip, const char **pp, |
2951 | struct type *type, struct objfile *objfile) | |
c906108c | 2952 | { |
a121b7c1 | 2953 | const char *p; |
7e9d9756 | 2954 | struct stabs_nextfield *newobj; |
c906108c SS |
2955 | |
2956 | /* We better set p right now, in case there are no fields at all... */ | |
2957 | ||
2958 | p = *pp; | |
2959 | ||
2960 | /* Read each data member type until we find the terminating ';' at the end of | |
2961 | the data member list, or break for some other reason such as finding the | |
c378eb4e | 2962 | start of the member function list. */ |
fedbd091 | 2963 | /* Stab string for structure/union does not end with two ';' in |
c378eb4e | 2964 | SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */ |
c906108c | 2965 | |
fedbd091 | 2966 | while (**pp != ';' && **pp != '\0') |
c906108c | 2967 | { |
c906108c SS |
2968 | STABS_CONTINUE (pp, objfile); |
2969 | /* Get space to record the next field's data. */ | |
7e9d9756 | 2970 | newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield); |
8d749320 | 2971 | |
fe978cb0 PA |
2972 | newobj->next = fip->list; |
2973 | fip->list = newobj; | |
c906108c SS |
2974 | |
2975 | /* Get the field name. */ | |
2976 | p = *pp; | |
2977 | ||
2978 | /* If is starts with CPLUS_MARKER it is a special abbreviation, | |
dda83cd7 SM |
2979 | unless the CPLUS_MARKER is followed by an underscore, in |
2980 | which case it is just the name of an anonymous type, which we | |
2981 | should handle like any other type name. */ | |
c906108c SS |
2982 | |
2983 | if (is_cplus_marker (p[0]) && p[1] != '_') | |
2984 | { | |
2985 | if (!read_cpp_abbrev (fip, pp, type, objfile)) | |
2986 | return 0; | |
2987 | continue; | |
2988 | } | |
2989 | ||
2990 | /* Look for the ':' that separates the field name from the field | |
dda83cd7 SM |
2991 | values. Data members are delimited by a single ':', while member |
2992 | functions are delimited by a pair of ':'s. When we hit the member | |
2993 | functions (if any), terminate scan loop and return. */ | |
c906108c | 2994 | |
c5aa993b | 2995 | while (*p != ':' && *p != '\0') |
c906108c SS |
2996 | { |
2997 | p++; | |
2998 | } | |
2999 | if (*p == '\0') | |
3000 | return 0; | |
3001 | ||
3002 | /* Check to see if we have hit the member functions yet. */ | |
3003 | if (p[1] == ':') | |
3004 | { | |
3005 | break; | |
3006 | } | |
3007 | read_one_struct_field (fip, pp, p, type, objfile); | |
3008 | } | |
3009 | if (p[0] == ':' && p[1] == ':') | |
3010 | { | |
1b831c93 | 3011 | /* (the deleted) chill the list of fields: the last entry (at |
dda83cd7 SM |
3012 | the head) is a partially constructed entry which we now |
3013 | scrub. */ | |
c5aa993b | 3014 | fip->list = fip->list->next; |
c906108c SS |
3015 | } |
3016 | return 1; | |
3017 | } | |
c906108c SS |
3018 | /* The stabs for C++ derived classes contain baseclass information which |
3019 | is marked by a '!' character after the total size. This function is | |
3020 | called when we encounter the baseclass marker, and slurps up all the | |
3021 | baseclass information. | |
3022 | ||
3023 | Immediately following the '!' marker is the number of base classes that | |
3024 | the class is derived from, followed by information for each base class. | |
3025 | For each base class, there are two visibility specifiers, a bit offset | |
3026 | to the base class information within the derived class, a reference to | |
3027 | the type for the base class, and a terminating semicolon. | |
3028 | ||
3029 | A typical example, with two base classes, would be "!2,020,19;0264,21;". | |
24b21115 | 3030 | ^^ ^ ^ ^ ^ ^ ^ |
c906108c SS |
3031 | Baseclass information marker __________________|| | | | | | | |
3032 | Number of baseclasses __________________________| | | | | | | | |
3033 | Visibility specifiers (2) ________________________| | | | | | | |
3034 | Offset in bits from start of class _________________| | | | | | |
3035 | Type number for base class ___________________________| | | | | |
3036 | Visibility specifiers (2) _______________________________| | | | |
3037 | Offset in bits from start of class ________________________| | | |
3038 | Type number of base class ____________________________________| | |
3039 | ||
3040 | Return 1 for success, 0 for (error-type-inducing) failure. */ | |
3041 | ||
c5aa993b JM |
3042 | |
3043 | ||
c906108c | 3044 | static int |
61b30099 TT |
3045 | read_baseclasses (struct stab_field_info *fip, const char **pp, |
3046 | struct type *type, struct objfile *objfile) | |
c906108c SS |
3047 | { |
3048 | int i; | |
7e9d9756 | 3049 | struct stabs_nextfield *newobj; |
c906108c SS |
3050 | |
3051 | if (**pp != '!') | |
3052 | { | |
3053 | return 1; | |
3054 | } | |
3055 | else | |
3056 | { | |
c378eb4e | 3057 | /* Skip the '!' baseclass information marker. */ |
c906108c SS |
3058 | (*pp)++; |
3059 | } | |
3060 | ||
3061 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3062 | { | |
3063 | int nbits; | |
433759f7 | 3064 | |
94e10a22 | 3065 | TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0); |
c906108c SS |
3066 | if (nbits != 0) |
3067 | return 0; | |
3068 | } | |
3069 | ||
3070 | #if 0 | |
3071 | /* Some stupid compilers have trouble with the following, so break | |
3072 | it up into simpler expressions. */ | |
3073 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) | |
3074 | TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); | |
3075 | #else | |
3076 | { | |
3077 | int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type)); | |
3078 | char *pointer; | |
3079 | ||
3080 | pointer = (char *) TYPE_ALLOC (type, num_bytes); | |
3081 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; | |
3082 | } | |
3083 | #endif /* 0 */ | |
3084 | ||
3085 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); | |
3086 | ||
3087 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) | |
3088 | { | |
7e9d9756 | 3089 | newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield); |
8d749320 | 3090 | |
fe978cb0 PA |
3091 | newobj->next = fip->list; |
3092 | fip->list = newobj; | |
3093 | FIELD_BITSIZE (newobj->field) = 0; /* This should be an unpacked | |
c378eb4e | 3094 | field! */ |
c906108c SS |
3095 | |
3096 | STABS_CONTINUE (pp, objfile); | |
3097 | switch (**pp) | |
3098 | { | |
c5aa993b | 3099 | case '0': |
c378eb4e | 3100 | /* Nothing to do. */ |
c5aa993b JM |
3101 | break; |
3102 | case '1': | |
3103 | SET_TYPE_FIELD_VIRTUAL (type, i); | |
3104 | break; | |
3105 | default: | |
3106 | /* Unknown character. Complain and treat it as non-virtual. */ | |
3107 | { | |
b98664d3 | 3108 | complaint (_("Unknown virtual character `%c' for baseclass"), |
3e43a32a | 3109 | **pp); |
c5aa993b | 3110 | } |
c906108c SS |
3111 | } |
3112 | ++(*pp); | |
3113 | ||
fe978cb0 PA |
3114 | newobj->visibility = *(*pp)++; |
3115 | switch (newobj->visibility) | |
c906108c | 3116 | { |
c5aa993b JM |
3117 | case VISIBILITY_PRIVATE: |
3118 | case VISIBILITY_PROTECTED: | |
3119 | case VISIBILITY_PUBLIC: | |
3120 | break; | |
3121 | default: | |
3122 | /* Bad visibility format. Complain and treat it as | |
3123 | public. */ | |
3124 | { | |
b98664d3 | 3125 | complaint (_("Unknown visibility `%c' for baseclass"), |
fe978cb0 PA |
3126 | newobj->visibility); |
3127 | newobj->visibility = VISIBILITY_PUBLIC; | |
c5aa993b | 3128 | } |
c906108c SS |
3129 | } |
3130 | ||
3131 | { | |
3132 | int nbits; | |
c5aa993b | 3133 | |
c906108c SS |
3134 | /* The remaining value is the bit offset of the portion of the object |
3135 | corresponding to this baseclass. Always zero in the absence of | |
3136 | multiple inheritance. */ | |
3137 | ||
cd3f655c | 3138 | newobj->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0)); |
c906108c SS |
3139 | if (nbits != 0) |
3140 | return 0; | |
3141 | } | |
3142 | ||
3143 | /* The last piece of baseclass information is the type of the | |
dda83cd7 SM |
3144 | base class. Read it, and remember it's type name as this |
3145 | field's name. */ | |
c906108c | 3146 | |
5d14b6e5 | 3147 | newobj->field.set_type (read_type (pp, objfile)); |
d3fd12df | 3148 | newobj->field.set_name (newobj->field.type ()->name ()); |
c906108c | 3149 | |
c378eb4e | 3150 | /* Skip trailing ';' and bump count of number of fields seen. */ |
c906108c SS |
3151 | if (**pp == ';') |
3152 | (*pp)++; | |
3153 | else | |
3154 | return 0; | |
3155 | } | |
3156 | return 1; | |
3157 | } | |
3158 | ||
3159 | /* The tail end of stabs for C++ classes that contain a virtual function | |
3160 | pointer contains a tilde, a %, and a type number. | |
3161 | The type number refers to the base class (possibly this class itself) which | |
3162 | contains the vtable pointer for the current class. | |
3163 | ||
3164 | This function is called when we have parsed all the method declarations, | |
3165 | so we can look for the vptr base class info. */ | |
3166 | ||
3167 | static int | |
61b30099 TT |
3168 | read_tilde_fields (struct stab_field_info *fip, const char **pp, |
3169 | struct type *type, struct objfile *objfile) | |
c906108c | 3170 | { |
a121b7c1 | 3171 | const char *p; |
c906108c SS |
3172 | |
3173 | STABS_CONTINUE (pp, objfile); | |
3174 | ||
c378eb4e | 3175 | /* If we are positioned at a ';', then skip it. */ |
c906108c SS |
3176 | if (**pp == ';') |
3177 | { | |
3178 | (*pp)++; | |
3179 | } | |
3180 | ||
3181 | if (**pp == '~') | |
3182 | { | |
3183 | (*pp)++; | |
3184 | ||
3185 | if (**pp == '=' || **pp == '+' || **pp == '-') | |
3186 | { | |
3187 | /* Obsolete flags that used to indicate the presence | |
c378eb4e | 3188 | of constructors and/or destructors. */ |
c906108c SS |
3189 | (*pp)++; |
3190 | } | |
3191 | ||
3192 | /* Read either a '%' or the final ';'. */ | |
3193 | if (*(*pp)++ == '%') | |
3194 | { | |
3195 | /* The next number is the type number of the base class | |
3196 | (possibly our own class) which supplies the vtable for | |
3197 | this class. Parse it out, and search that class to find | |
3198 | its vtable pointer, and install those into TYPE_VPTR_BASETYPE | |
3199 | and TYPE_VPTR_FIELDNO. */ | |
3200 | ||
3201 | struct type *t; | |
3202 | int i; | |
3203 | ||
3204 | t = read_type (pp, objfile); | |
3205 | p = (*pp)++; | |
3206 | while (*p != '\0' && *p != ';') | |
3207 | { | |
3208 | p++; | |
3209 | } | |
3210 | if (*p == '\0') | |
3211 | { | |
3212 | /* Premature end of symbol. */ | |
3213 | return 0; | |
3214 | } | |
c5aa993b | 3215 | |
ae6ae975 | 3216 | set_type_vptr_basetype (type, t); |
c378eb4e | 3217 | if (type == t) /* Our own class provides vtbl ptr. */ |
c906108c | 3218 | { |
1f704f76 | 3219 | for (i = t->num_fields () - 1; |
c906108c SS |
3220 | i >= TYPE_N_BASECLASSES (t); |
3221 | --i) | |
3222 | { | |
33d16dd9 | 3223 | const char *name = t->field (i).name (); |
433759f7 | 3224 | |
8343f86c | 3225 | if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2) |
74451869 | 3226 | && is_cplus_marker (name[sizeof (vptr_name) - 2])) |
c906108c | 3227 | { |
ae6ae975 | 3228 | set_type_vptr_fieldno (type, i); |
c906108c SS |
3229 | goto gotit; |
3230 | } | |
3231 | } | |
3232 | /* Virtual function table field not found. */ | |
b98664d3 | 3233 | complaint (_("virtual function table pointer " |
3e43a32a | 3234 | "not found when defining class `%s'"), |
7d93a1e0 | 3235 | type->name ()); |
c906108c SS |
3236 | return 0; |
3237 | } | |
3238 | else | |
3239 | { | |
ae6ae975 | 3240 | set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t)); |
c906108c SS |
3241 | } |
3242 | ||
c5aa993b | 3243 | gotit: |
c906108c SS |
3244 | *pp = p + 1; |
3245 | } | |
3246 | } | |
3247 | return 1; | |
3248 | } | |
3249 | ||
3250 | static int | |
61b30099 | 3251 | attach_fn_fields_to_type (struct stab_field_info *fip, struct type *type) |
c906108c | 3252 | { |
52f0bd74 | 3253 | int n; |
c906108c SS |
3254 | |
3255 | for (n = TYPE_NFN_FIELDS (type); | |
c5aa993b JM |
3256 | fip->fnlist != NULL; |
3257 | fip->fnlist = fip->fnlist->next) | |
c906108c | 3258 | { |
c378eb4e | 3259 | --n; /* Circumvent Sun3 compiler bug. */ |
c5aa993b | 3260 | TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist; |
c906108c SS |
3261 | } |
3262 | return 1; | |
3263 | } | |
3264 | ||
c906108c SS |
3265 | /* Create the vector of fields, and record how big it is. |
3266 | We need this info to record proper virtual function table information | |
3267 | for this class's virtual functions. */ | |
3268 | ||
3269 | static int | |
61b30099 | 3270 | attach_fields_to_type (struct stab_field_info *fip, struct type *type, |
fba45db2 | 3271 | struct objfile *objfile) |
c906108c | 3272 | { |
52f0bd74 AC |
3273 | int nfields = 0; |
3274 | int non_public_fields = 0; | |
7e9d9756 | 3275 | struct stabs_nextfield *scan; |
c906108c SS |
3276 | |
3277 | /* Count up the number of fields that we have, as well as taking note of | |
3278 | whether or not there are any non-public fields, which requires us to | |
3279 | allocate and build the private_field_bits and protected_field_bits | |
c378eb4e | 3280 | bitfields. */ |
c906108c | 3281 | |
c5aa993b | 3282 | for (scan = fip->list; scan != NULL; scan = scan->next) |
c906108c SS |
3283 | { |
3284 | nfields++; | |
c5aa993b | 3285 | if (scan->visibility != VISIBILITY_PUBLIC) |
c906108c SS |
3286 | { |
3287 | non_public_fields++; | |
3288 | } | |
3289 | } | |
3290 | ||
3291 | /* Now we know how many fields there are, and whether or not there are any | |
3292 | non-public fields. Record the field count, allocate space for the | |
c378eb4e | 3293 | array of fields, and create blank visibility bitfields if necessary. */ |
c906108c | 3294 | |
5e33d5f4 | 3295 | type->set_num_fields (nfields); |
3cabb6b0 SM |
3296 | type->set_fields |
3297 | ((struct field *) | |
3298 | TYPE_ALLOC (type, sizeof (struct field) * nfields)); | |
80fc5e77 | 3299 | memset (type->fields (), 0, sizeof (struct field) * nfields); |
c906108c SS |
3300 | |
3301 | if (non_public_fields) | |
3302 | { | |
3303 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3304 | ||
3305 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3306 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3307 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3308 | ||
3309 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3310 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3311 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3312 | ||
3313 | TYPE_FIELD_IGNORE_BITS (type) = | |
3314 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3315 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3316 | } | |
3317 | ||
c378eb4e MS |
3318 | /* Copy the saved-up fields into the field vector. Start from the |
3319 | head of the list, adding to the tail of the field array, so that | |
3320 | they end up in the same order in the array in which they were | |
3321 | added to the list. */ | |
c906108c SS |
3322 | |
3323 | while (nfields-- > 0) | |
3324 | { | |
ceacbf6e | 3325 | type->field (nfields) = fip->list->field; |
c5aa993b | 3326 | switch (fip->list->visibility) |
c906108c | 3327 | { |
c5aa993b JM |
3328 | case VISIBILITY_PRIVATE: |
3329 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3330 | break; | |
c906108c | 3331 | |
c5aa993b JM |
3332 | case VISIBILITY_PROTECTED: |
3333 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3334 | break; | |
c906108c | 3335 | |
c5aa993b JM |
3336 | case VISIBILITY_IGNORE: |
3337 | SET_TYPE_FIELD_IGNORE (type, nfields); | |
3338 | break; | |
c906108c | 3339 | |
c5aa993b JM |
3340 | case VISIBILITY_PUBLIC: |
3341 | break; | |
c906108c | 3342 | |
c5aa993b JM |
3343 | default: |
3344 | /* Unknown visibility. Complain and treat it as public. */ | |
3345 | { | |
b98664d3 | 3346 | complaint (_("Unknown visibility `%c' for field"), |
23136709 | 3347 | fip->list->visibility); |
c5aa993b JM |
3348 | } |
3349 | break; | |
c906108c | 3350 | } |
c5aa993b | 3351 | fip->list = fip->list->next; |
c906108c SS |
3352 | } |
3353 | return 1; | |
3354 | } | |
3355 | ||
2ae1c2d2 | 3356 | |
2ae1c2d2 JB |
3357 | /* Complain that the compiler has emitted more than one definition for the |
3358 | structure type TYPE. */ | |
3359 | static void | |
3360 | complain_about_struct_wipeout (struct type *type) | |
3361 | { | |
0d5cff50 DE |
3362 | const char *name = ""; |
3363 | const char *kind = ""; | |
2ae1c2d2 | 3364 | |
7d93a1e0 | 3365 | if (type->name ()) |
2ae1c2d2 | 3366 | { |
7d93a1e0 | 3367 | name = type->name (); |
78134374 | 3368 | switch (type->code ()) |
dda83cd7 SM |
3369 | { |
3370 | case TYPE_CODE_STRUCT: kind = "struct "; break; | |
3371 | case TYPE_CODE_UNION: kind = "union "; break; | |
3372 | case TYPE_CODE_ENUM: kind = "enum "; break; | |
3373 | default: kind = ""; | |
3374 | } | |
2ae1c2d2 | 3375 | } |
2ae1c2d2 JB |
3376 | else |
3377 | { | |
3378 | name = "<unknown>"; | |
3379 | kind = ""; | |
3380 | } | |
3381 | ||
b98664d3 | 3382 | complaint (_("struct/union type gets multiply defined: %s%s"), kind, name); |
2ae1c2d2 JB |
3383 | } |
3384 | ||
621791b8 PM |
3385 | /* Set the length for all variants of a same main_type, which are |
3386 | connected in the closed chain. | |
3387 | ||
3388 | This is something that needs to be done when a type is defined *after* | |
3389 | some cross references to this type have already been read. Consider | |
3390 | for instance the following scenario where we have the following two | |
3391 | stabs entries: | |
3392 | ||
dda83cd7 SM |
3393 | .stabs "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24 |
3394 | .stabs "dummy:T(0,23)=s16x:(0,1),0,3[...]" | |
621791b8 PM |
3395 | |
3396 | A stubbed version of type dummy is created while processing the first | |
3397 | stabs entry. The length of that type is initially set to zero, since | |
3398 | it is unknown at this point. Also, a "constant" variation of type | |
3399 | "dummy" is created as well (this is the "(0,22)=k(0,23)" section of | |
3400 | the stabs line). | |
3401 | ||
3402 | The second stabs entry allows us to replace the stubbed definition | |
3403 | with the real definition. However, we still need to adjust the length | |
3404 | of the "constant" variation of that type, as its length was left | |
3405 | untouched during the main type replacement... */ | |
3406 | ||
3407 | static void | |
9e69f3b6 | 3408 | set_length_in_type_chain (struct type *type) |
621791b8 PM |
3409 | { |
3410 | struct type *ntype = TYPE_CHAIN (type); | |
3411 | ||
3412 | while (ntype != type) | |
3413 | { | |
df86565b SM |
3414 | if (ntype->length () == 0) |
3415 | ntype->set_length (type->length ()); | |
621791b8 | 3416 | else |
dda83cd7 | 3417 | complain_about_struct_wipeout (ntype); |
621791b8 PM |
3418 | ntype = TYPE_CHAIN (ntype); |
3419 | } | |
3420 | } | |
2ae1c2d2 | 3421 | |
c906108c SS |
3422 | /* Read the description of a structure (or union type) and return an object |
3423 | describing the type. | |
3424 | ||
3425 | PP points to a character pointer that points to the next unconsumed token | |
b021a221 | 3426 | in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", |
c906108c SS |
3427 | *PP will point to "4a:1,0,32;;". |
3428 | ||
3429 | TYPE points to an incomplete type that needs to be filled in. | |
3430 | ||
3431 | OBJFILE points to the current objfile from which the stabs information is | |
3432 | being read. (Note that it is redundant in that TYPE also contains a pointer | |
3433 | to this same objfile, so it might be a good idea to eliminate it. FIXME). | |
c5aa993b | 3434 | */ |
c906108c SS |
3435 | |
3436 | static struct type * | |
a121b7c1 | 3437 | read_struct_type (const char **pp, struct type *type, enum type_code type_code, |
dda83cd7 | 3438 | struct objfile *objfile) |
c906108c | 3439 | { |
61b30099 | 3440 | struct stab_field_info fi; |
c906108c | 3441 | |
2ae1c2d2 JB |
3442 | /* When describing struct/union/class types in stabs, G++ always drops |
3443 | all qualifications from the name. So if you've got: | |
3444 | struct A { ... struct B { ... }; ... }; | |
3445 | then G++ will emit stabs for `struct A::B' that call it simply | |
3446 | `struct B'. Obviously, if you've got a real top-level definition for | |
3447 | `struct B', or other nested definitions, this is going to cause | |
3448 | problems. | |
3449 | ||
3450 | Obviously, GDB can't fix this by itself, but it can at least avoid | |
3451 | scribbling on existing structure type objects when new definitions | |
3452 | appear. */ | |
78134374 | 3453 | if (! (type->code () == TYPE_CODE_UNDEF |
dda83cd7 | 3454 | || type->is_stub ())) |
2ae1c2d2 JB |
3455 | { |
3456 | complain_about_struct_wipeout (type); | |
3457 | ||
3458 | /* It's probably best to return the type unchanged. */ | |
3459 | return type; | |
3460 | } | |
3461 | ||
c906108c | 3462 | INIT_CPLUS_SPECIFIC (type); |
67607e24 | 3463 | type->set_code (type_code); |
b4b73759 | 3464 | type->set_is_stub (false); |
c906108c SS |
3465 | |
3466 | /* First comes the total size in bytes. */ | |
3467 | ||
3468 | { | |
3469 | int nbits; | |
433759f7 | 3470 | |
b6cdbc9a | 3471 | type->set_length (read_huge_number (pp, 0, &nbits, 0)); |
c906108c | 3472 | if (nbits != 0) |
61b30099 | 3473 | return error_type (pp, objfile); |
621791b8 | 3474 | set_length_in_type_chain (type); |
c906108c SS |
3475 | } |
3476 | ||
3477 | /* Now read the baseclasses, if any, read the regular C struct or C++ | |
3478 | class member fields, attach the fields to the type, read the C++ | |
3479 | member functions, attach them to the type, and then read any tilde | |
3e43a32a | 3480 | field (baseclass specifier for the class holding the main vtable). */ |
c906108c SS |
3481 | |
3482 | if (!read_baseclasses (&fi, pp, type, objfile) | |
3483 | || !read_struct_fields (&fi, pp, type, objfile) | |
3484 | || !attach_fields_to_type (&fi, type, objfile) | |
3485 | || !read_member_functions (&fi, pp, type, objfile) | |
3486 | || !attach_fn_fields_to_type (&fi, type) | |
3487 | || !read_tilde_fields (&fi, pp, type, objfile)) | |
3488 | { | |
3489 | type = error_type (pp, objfile); | |
3490 | } | |
3491 | ||
c906108c SS |
3492 | return (type); |
3493 | } | |
3494 | ||
3495 | /* Read a definition of an array type, | |
3496 | and create and return a suitable type object. | |
3497 | Also creates a range type which represents the bounds of that | |
3498 | array. */ | |
3499 | ||
3500 | static struct type * | |
a121b7c1 | 3501 | read_array_type (const char **pp, struct type *type, |
fba45db2 | 3502 | struct objfile *objfile) |
c906108c SS |
3503 | { |
3504 | struct type *index_type, *element_type, *range_type; | |
3505 | int lower, upper; | |
3506 | int adjustable = 0; | |
3507 | int nbits; | |
3508 | ||
3509 | /* Format of an array type: | |
3510 | "ar<index type>;lower;upper;<array_contents_type>". | |
3511 | OS9000: "arlower,upper;<array_contents_type>". | |
3512 | ||
3513 | Fortran adjustable arrays use Adigits or Tdigits for lower or upper; | |
3514 | for these, produce a type like float[][]. */ | |
3515 | ||
c906108c SS |
3516 | { |
3517 | index_type = read_type (pp, objfile); | |
3518 | if (**pp != ';') | |
3519 | /* Improper format of array type decl. */ | |
3520 | return error_type (pp, objfile); | |
3521 | ++*pp; | |
3522 | } | |
3523 | ||
3524 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') | |
3525 | { | |
3526 | (*pp)++; | |
3527 | adjustable = 1; | |
3528 | } | |
94e10a22 | 3529 | lower = read_huge_number (pp, ';', &nbits, 0); |
cdecafbe | 3530 | |
c906108c SS |
3531 | if (nbits != 0) |
3532 | return error_type (pp, objfile); | |
3533 | ||
3534 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') | |
3535 | { | |
3536 | (*pp)++; | |
3537 | adjustable = 1; | |
3538 | } | |
94e10a22 | 3539 | upper = read_huge_number (pp, ';', &nbits, 0); |
c906108c SS |
3540 | if (nbits != 0) |
3541 | return error_type (pp, objfile); | |
c5aa993b | 3542 | |
c906108c SS |
3543 | element_type = read_type (pp, objfile); |
3544 | ||
3545 | if (adjustable) | |
3546 | { | |
3547 | lower = 0; | |
3548 | upper = -1; | |
3549 | } | |
3550 | ||
e727c536 | 3551 | type_allocator alloc (objfile); |
c906108c | 3552 | range_type = |
e727c536 | 3553 | create_static_range_type (alloc, index_type, lower, upper); |
9e76b17a TT |
3554 | type_allocator smash_alloc (type, type_allocator::SMASH); |
3555 | type = create_array_type (smash_alloc, element_type, range_type); | |
c906108c SS |
3556 | |
3557 | return type; | |
3558 | } | |
3559 | ||
3560 | ||
3561 | /* Read a definition of an enumeration type, | |
3562 | and create and return a suitable type object. | |
3563 | Also defines the symbols that represent the values of the type. */ | |
3564 | ||
3565 | static struct type * | |
a121b7c1 | 3566 | read_enum_type (const char **pp, struct type *type, |
fba45db2 | 3567 | struct objfile *objfile) |
c906108c | 3568 | { |
08feed99 | 3569 | struct gdbarch *gdbarch = objfile->arch (); |
a121b7c1 | 3570 | const char *p; |
c906108c | 3571 | char *name; |
52f0bd74 AC |
3572 | long n; |
3573 | struct symbol *sym; | |
c906108c SS |
3574 | int nsyms = 0; |
3575 | struct pending **symlist; | |
3576 | struct pending *osyms, *syms; | |
3577 | int o_nsyms; | |
3578 | int nbits; | |
3579 | int unsigned_enum = 1; | |
3580 | ||
3581 | #if 0 | |
3582 | /* FIXME! The stabs produced by Sun CC merrily define things that ought | |
3583 | to be file-scope, between N_FN entries, using N_LSYM. What's a mother | |
3584 | to do? For now, force all enum values to file scope. */ | |
3585 | if (within_function) | |
e148f09d | 3586 | symlist = get_local_symbols (); |
c906108c SS |
3587 | else |
3588 | #endif | |
e148f09d | 3589 | symlist = get_file_symbols (); |
c906108c SS |
3590 | osyms = *symlist; |
3591 | o_nsyms = osyms ? osyms->nsyms : 0; | |
3592 | ||
c906108c SS |
3593 | /* The aix4 compiler emits an extra field before the enum members; |
3594 | my guess is it's a type of some sort. Just ignore it. */ | |
3595 | if (**pp == '-') | |
3596 | { | |
3597 | /* Skip over the type. */ | |
3598 | while (**pp != ':') | |
c5aa993b | 3599 | (*pp)++; |
c906108c SS |
3600 | |
3601 | /* Skip over the colon. */ | |
3602 | (*pp)++; | |
3603 | } | |
3604 | ||
3605 | /* Read the value-names and their values. | |
3606 | The input syntax is NAME:VALUE,NAME:VALUE, and so on. | |
3607 | A semicolon or comma instead of a NAME means the end. */ | |
3608 | while (**pp && **pp != ';' && **pp != ',') | |
3609 | { | |
3610 | STABS_CONTINUE (pp, objfile); | |
3611 | p = *pp; | |
c5aa993b JM |
3612 | while (*p != ':') |
3613 | p++; | |
0cf9feb9 | 3614 | name = obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp); |
c906108c | 3615 | *pp = p + 1; |
94e10a22 | 3616 | n = read_huge_number (pp, ',', &nbits, 0); |
c906108c SS |
3617 | if (nbits != 0) |
3618 | return error_type (pp, objfile); | |
3619 | ||
8c14c3a3 | 3620 | sym = new (&objfile->objfile_obstack) symbol; |
43678b0a | 3621 | sym->set_linkage_name (name); |
d3ecddab CB |
3622 | sym->set_language (get_current_subfile ()->language, |
3623 | &objfile->objfile_obstack); | |
ba44b1a3 | 3624 | sym->set_aclass_index (LOC_CONST); |
6c9c307c | 3625 | sym->set_domain (VAR_DOMAIN); |
4aeddc50 | 3626 | sym->set_value_longest (n); |
c906108c SS |
3627 | if (n < 0) |
3628 | unsigned_enum = 0; | |
3629 | add_symbol_to_list (sym, symlist); | |
3630 | nsyms++; | |
3631 | } | |
3632 | ||
3633 | if (**pp == ';') | |
3634 | (*pp)++; /* Skip the semicolon. */ | |
3635 | ||
3636 | /* Now fill in the fields of the type-structure. */ | |
3637 | ||
b6cdbc9a | 3638 | type->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT); |
621791b8 | 3639 | set_length_in_type_chain (type); |
67607e24 | 3640 | type->set_code (TYPE_CODE_ENUM); |
b4b73759 | 3641 | type->set_is_stub (false); |
c906108c | 3642 | if (unsigned_enum) |
653223d3 | 3643 | type->set_is_unsigned (true); |
5e33d5f4 | 3644 | type->set_num_fields (nsyms); |
3cabb6b0 SM |
3645 | type->set_fields |
3646 | ((struct field *) | |
3647 | TYPE_ALLOC (type, sizeof (struct field) * nsyms)); | |
80fc5e77 | 3648 | memset (type->fields (), 0, sizeof (struct field) * nsyms); |
c906108c SS |
3649 | |
3650 | /* Find the symbols for the values and put them into the type. | |
3651 | The symbols can be found in the symlist that we put them on | |
3652 | to cause them to be defined. osyms contains the old value | |
3653 | of that symlist; everything up to there was defined by us. */ | |
3654 | /* Note that we preserve the order of the enum constants, so | |
3655 | that in something like "enum {FOO, LAST_THING=FOO}" we print | |
3656 | FOO, not LAST_THING. */ | |
3657 | ||
3658 | for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next) | |
3659 | { | |
3660 | int last = syms == osyms ? o_nsyms : 0; | |
3661 | int j = syms->nsyms; | |
433759f7 | 3662 | |
c906108c SS |
3663 | for (; --j >= last; --n) |
3664 | { | |
3665 | struct symbol *xsym = syms->symbol[j]; | |
433759f7 | 3666 | |
5f9c5a63 | 3667 | xsym->set_type (type); |
d3fd12df | 3668 | type->field (n).set_name (xsym->linkage_name ()); |
4aeddc50 | 3669 | type->field (n).set_loc_enumval (xsym->value_longest ()); |
c906108c SS |
3670 | TYPE_FIELD_BITSIZE (type, n) = 0; |
3671 | } | |
3672 | if (syms == osyms) | |
3673 | break; | |
3674 | } | |
3675 | ||
3676 | return type; | |
3677 | } | |
3678 | ||
3679 | /* Sun's ACC uses a somewhat saner method for specifying the builtin | |
3680 | typedefs in every file (for int, long, etc): | |
3681 | ||
c5aa993b JM |
3682 | type = b <signed> <width> <format type>; <offset>; <nbits> |
3683 | signed = u or s. | |
3684 | optional format type = c or b for char or boolean. | |
3685 | offset = offset from high order bit to start bit of type. | |
3686 | width is # bytes in object of this type, nbits is # bits in type. | |
c906108c SS |
3687 | |
3688 | The width/offset stuff appears to be for small objects stored in | |
3689 | larger ones (e.g. `shorts' in `int' registers). We ignore it for now, | |
3690 | FIXME. */ | |
3691 | ||
3692 | static struct type * | |
a121b7c1 | 3693 | read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile) |
c906108c SS |
3694 | { |
3695 | int type_bits; | |
3696 | int nbits; | |
19f392bc UW |
3697 | int unsigned_type; |
3698 | int boolean_type = 0; | |
c906108c SS |
3699 | |
3700 | switch (**pp) | |
3701 | { | |
c5aa993b | 3702 | case 's': |
19f392bc | 3703 | unsigned_type = 0; |
c5aa993b JM |
3704 | break; |
3705 | case 'u': | |
19f392bc | 3706 | unsigned_type = 1; |
c5aa993b JM |
3707 | break; |
3708 | default: | |
3709 | return error_type (pp, objfile); | |
c906108c SS |
3710 | } |
3711 | (*pp)++; | |
3712 | ||
3713 | /* For some odd reason, all forms of char put a c here. This is strange | |
3714 | because no other type has this honor. We can safely ignore this because | |
3715 | we actually determine 'char'acterness by the number of bits specified in | |
3716 | the descriptor. | |
3717 | Boolean forms, e.g Fortran logical*X, put a b here. */ | |
3718 | ||
3719 | if (**pp == 'c') | |
3720 | (*pp)++; | |
3721 | else if (**pp == 'b') | |
3722 | { | |
19f392bc | 3723 | boolean_type = 1; |
c906108c SS |
3724 | (*pp)++; |
3725 | } | |
3726 | ||
3727 | /* The first number appears to be the number of bytes occupied | |
3728 | by this type, except that unsigned short is 4 instead of 2. | |
3729 | Since this information is redundant with the third number, | |
3730 | we will ignore it. */ | |
94e10a22 | 3731 | read_huge_number (pp, ';', &nbits, 0); |
c906108c SS |
3732 | if (nbits != 0) |
3733 | return error_type (pp, objfile); | |
3734 | ||
c378eb4e | 3735 | /* The second number is always 0, so ignore it too. */ |
94e10a22 | 3736 | read_huge_number (pp, ';', &nbits, 0); |
c906108c SS |
3737 | if (nbits != 0) |
3738 | return error_type (pp, objfile); | |
3739 | ||
c378eb4e | 3740 | /* The third number is the number of bits for this type. */ |
94e10a22 | 3741 | type_bits = read_huge_number (pp, 0, &nbits, 0); |
c906108c SS |
3742 | if (nbits != 0) |
3743 | return error_type (pp, objfile); | |
3744 | /* The type *should* end with a semicolon. If it are embedded | |
3745 | in a larger type the semicolon may be the only way to know where | |
3746 | the type ends. If this type is at the end of the stabstring we | |
3747 | can deal with the omitted semicolon (but we don't have to like | |
3748 | it). Don't bother to complain(), Sun's compiler omits the semicolon | |
3749 | for "void". */ | |
3750 | if (**pp == ';') | |
3751 | ++(*pp); | |
3752 | ||
33385940 | 3753 | type_allocator alloc (objfile); |
c906108c | 3754 | if (type_bits == 0) |
19f392bc | 3755 | { |
33385940 TT |
3756 | struct type *type = alloc.new_type (TYPE_CODE_VOID, |
3757 | TARGET_CHAR_BIT, nullptr); | |
19f392bc | 3758 | if (unsigned_type) |
653223d3 SM |
3759 | type->set_is_unsigned (true); |
3760 | ||
19f392bc UW |
3761 | return type; |
3762 | } | |
3763 | ||
3764 | if (boolean_type) | |
46c04ea3 | 3765 | return init_boolean_type (alloc, type_bits, unsigned_type, NULL); |
c906108c | 3766 | else |
2d39ccd3 | 3767 | return init_integer_type (alloc, type_bits, unsigned_type, NULL); |
c906108c SS |
3768 | } |
3769 | ||
3770 | static struct type * | |
a121b7c1 PA |
3771 | read_sun_floating_type (const char **pp, int typenums[2], |
3772 | struct objfile *objfile) | |
c906108c SS |
3773 | { |
3774 | int nbits; | |
3775 | int details; | |
3776 | int nbytes; | |
f65ca430 | 3777 | struct type *rettype; |
c906108c SS |
3778 | |
3779 | /* The first number has more details about the type, for example | |
3780 | FN_COMPLEX. */ | |
94e10a22 | 3781 | details = read_huge_number (pp, ';', &nbits, 0); |
c906108c SS |
3782 | if (nbits != 0) |
3783 | return error_type (pp, objfile); | |
3784 | ||
c378eb4e | 3785 | /* The second number is the number of bytes occupied by this type. */ |
94e10a22 | 3786 | nbytes = read_huge_number (pp, ';', &nbits, 0); |
c906108c SS |
3787 | if (nbits != 0) |
3788 | return error_type (pp, objfile); | |
3789 | ||
19f392bc UW |
3790 | nbits = nbytes * TARGET_CHAR_BIT; |
3791 | ||
c906108c SS |
3792 | if (details == NF_COMPLEX || details == NF_COMPLEX16 |
3793 | || details == NF_COMPLEX32) | |
f65ca430 | 3794 | { |
9b790ce7 | 3795 | rettype = dbx_init_float_type (objfile, nbits / 2); |
5b930b45 | 3796 | return init_complex_type (NULL, rettype); |
f65ca430 | 3797 | } |
c906108c | 3798 | |
9b790ce7 | 3799 | return dbx_init_float_type (objfile, nbits); |
c906108c SS |
3800 | } |
3801 | ||
3802 | /* Read a number from the string pointed to by *PP. | |
3803 | The value of *PP is advanced over the number. | |
3804 | If END is nonzero, the character that ends the | |
3805 | number must match END, or an error happens; | |
3806 | and that character is skipped if it does match. | |
3807 | If END is zero, *PP is left pointing to that character. | |
3808 | ||
94e10a22 JG |
3809 | If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if |
3810 | the number is represented in an octal representation, assume that | |
3811 | it is represented in a 2's complement representation with a size of | |
3812 | TWOS_COMPLEMENT_BITS. | |
3813 | ||
c906108c SS |
3814 | If the number fits in a long, set *BITS to 0 and return the value. |
3815 | If not, set *BITS to be the number of bits in the number and return 0. | |
3816 | ||
3817 | If encounter garbage, set *BITS to -1 and return 0. */ | |
3818 | ||
c2d11a7d | 3819 | static long |
a121b7c1 PA |
3820 | read_huge_number (const char **pp, int end, int *bits, |
3821 | int twos_complement_bits) | |
c906108c | 3822 | { |
a121b7c1 | 3823 | const char *p = *pp; |
c906108c | 3824 | int sign = 1; |
51e9e0d4 | 3825 | int sign_bit = 0; |
c2d11a7d | 3826 | long n = 0; |
c906108c SS |
3827 | int radix = 10; |
3828 | char overflow = 0; | |
3829 | int nbits = 0; | |
3830 | int c; | |
c2d11a7d | 3831 | long upper_limit; |
a2699720 | 3832 | int twos_complement_representation = 0; |
c5aa993b | 3833 | |
c906108c SS |
3834 | if (*p == '-') |
3835 | { | |
3836 | sign = -1; | |
3837 | p++; | |
3838 | } | |
3839 | ||
3840 | /* Leading zero means octal. GCC uses this to output values larger | |
3841 | than an int (because that would be hard in decimal). */ | |
3842 | if (*p == '0') | |
3843 | { | |
3844 | radix = 8; | |
3845 | p++; | |
3846 | } | |
3847 | ||
a2699720 PA |
3848 | /* Skip extra zeros. */ |
3849 | while (*p == '0') | |
3850 | p++; | |
3851 | ||
3852 | if (sign > 0 && radix == 8 && twos_complement_bits > 0) | |
3853 | { | |
3854 | /* Octal, possibly signed. Check if we have enough chars for a | |
3855 | negative number. */ | |
3856 | ||
3857 | size_t len; | |
a121b7c1 | 3858 | const char *p1 = p; |
433759f7 | 3859 | |
a2699720 PA |
3860 | while ((c = *p1) >= '0' && c < '8') |
3861 | p1++; | |
3862 | ||
3863 | len = p1 - p; | |
3864 | if (len > twos_complement_bits / 3 | |
3e43a32a MS |
3865 | || (twos_complement_bits % 3 == 0 |
3866 | && len == twos_complement_bits / 3)) | |
a2699720 PA |
3867 | { |
3868 | /* Ok, we have enough characters for a signed value, check | |
85102364 | 3869 | for signedness by testing if the sign bit is set. */ |
a2699720 PA |
3870 | sign_bit = (twos_complement_bits % 3 + 2) % 3; |
3871 | c = *p - '0'; | |
3872 | if (c & (1 << sign_bit)) | |
3873 | { | |
3874 | /* Definitely signed. */ | |
3875 | twos_complement_representation = 1; | |
3876 | sign = -1; | |
3877 | } | |
3878 | } | |
3879 | } | |
3880 | ||
1b831c93 | 3881 | upper_limit = LONG_MAX / radix; |
c906108c SS |
3882 | |
3883 | while ((c = *p++) >= '0' && c < ('0' + radix)) | |
3884 | { | |
3885 | if (n <= upper_limit) | |
dda83cd7 SM |
3886 | { |
3887 | if (twos_complement_representation) | |
3888 | { | |
a2699720 PA |
3889 | /* Octal, signed, twos complement representation. In |
3890 | this case, n is the corresponding absolute value. */ | |
3891 | if (n == 0) | |
3892 | { | |
3893 | long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit)); | |
433759f7 | 3894 | |
a2699720 PA |
3895 | n = -sn; |
3896 | } | |
dda83cd7 SM |
3897 | else |
3898 | { | |
3899 | n *= radix; | |
3900 | n -= c - '0'; | |
3901 | } | |
3902 | } | |
3903 | else | |
3904 | { | |
3905 | /* unsigned representation */ | |
3906 | n *= radix; | |
3907 | n += c - '0'; /* FIXME this overflows anyway. */ | |
3908 | } | |
3909 | } | |
c906108c | 3910 | else |
dda83cd7 | 3911 | overflow = 1; |
c5aa993b | 3912 | |
c906108c | 3913 | /* This depends on large values being output in octal, which is |
dda83cd7 | 3914 | what GCC does. */ |
c906108c SS |
3915 | if (radix == 8) |
3916 | { | |
3917 | if (nbits == 0) | |
3918 | { | |
3919 | if (c == '0') | |
3920 | /* Ignore leading zeroes. */ | |
3921 | ; | |
3922 | else if (c == '1') | |
3923 | nbits = 1; | |
3924 | else if (c == '2' || c == '3') | |
3925 | nbits = 2; | |
3926 | else | |
3927 | nbits = 3; | |
3928 | } | |
3929 | else | |
3930 | nbits += 3; | |
3931 | } | |
3932 | } | |
3933 | if (end) | |
3934 | { | |
3935 | if (c && c != end) | |
3936 | { | |
3937 | if (bits != NULL) | |
3938 | *bits = -1; | |
3939 | return 0; | |
3940 | } | |
3941 | } | |
3942 | else | |
3943 | --p; | |
3944 | ||
a2699720 PA |
3945 | if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits) |
3946 | { | |
3947 | /* We were supposed to parse a number with maximum | |
3948 | TWOS_COMPLEMENT_BITS bits, but something went wrong. */ | |
3949 | if (bits != NULL) | |
3950 | *bits = -1; | |
3951 | return 0; | |
3952 | } | |
3953 | ||
c906108c SS |
3954 | *pp = p; |
3955 | if (overflow) | |
3956 | { | |
3957 | if (nbits == 0) | |
3958 | { | |
3959 | /* Large decimal constants are an error (because it is hard to | |
3960 | count how many bits are in them). */ | |
3961 | if (bits != NULL) | |
3962 | *bits = -1; | |
3963 | return 0; | |
3964 | } | |
c5aa993b | 3965 | |
c906108c | 3966 | /* -0x7f is the same as 0x80. So deal with it by adding one to |
dda83cd7 SM |
3967 | the number of bits. Two's complement represention octals |
3968 | can't have a '-' in front. */ | |
a2699720 | 3969 | if (sign == -1 && !twos_complement_representation) |
c906108c SS |
3970 | ++nbits; |
3971 | if (bits) | |
3972 | *bits = nbits; | |
3973 | } | |
3974 | else | |
3975 | { | |
3976 | if (bits) | |
3977 | *bits = 0; | |
a2699720 | 3978 | return n * sign; |
c906108c SS |
3979 | } |
3980 | /* It's *BITS which has the interesting information. */ | |
3981 | return 0; | |
3982 | } | |
3983 | ||
3984 | static struct type * | |
a121b7c1 | 3985 | read_range_type (const char **pp, int typenums[2], int type_size, |
dda83cd7 | 3986 | struct objfile *objfile) |
c906108c | 3987 | { |
08feed99 | 3988 | struct gdbarch *gdbarch = objfile->arch (); |
a121b7c1 | 3989 | const char *orig_pp = *pp; |
c906108c | 3990 | int rangenums[2]; |
c2d11a7d | 3991 | long n2, n3; |
c906108c SS |
3992 | int n2bits, n3bits; |
3993 | int self_subrange; | |
3994 | struct type *result_type; | |
3995 | struct type *index_type = NULL; | |
3996 | ||
3997 | /* First comes a type we are a subrange of. | |
3998 | In C it is usually 0, 1 or the type being defined. */ | |
3999 | if (read_type_number (pp, rangenums) != 0) | |
4000 | return error_type (pp, objfile); | |
4001 | self_subrange = (rangenums[0] == typenums[0] && | |
4002 | rangenums[1] == typenums[1]); | |
4003 | ||
4004 | if (**pp == '=') | |
4005 | { | |
4006 | *pp = orig_pp; | |
4007 | index_type = read_type (pp, objfile); | |
4008 | } | |
4009 | ||
4010 | /* A semicolon should now follow; skip it. */ | |
4011 | if (**pp == ';') | |
4012 | (*pp)++; | |
4013 | ||
4014 | /* The remaining two operands are usually lower and upper bounds | |
4015 | of the range. But in some special cases they mean something else. */ | |
94e10a22 JG |
4016 | n2 = read_huge_number (pp, ';', &n2bits, type_size); |
4017 | n3 = read_huge_number (pp, ';', &n3bits, type_size); | |
c906108c SS |
4018 | |
4019 | if (n2bits == -1 || n3bits == -1) | |
4020 | return error_type (pp, objfile); | |
4021 | ||
33385940 TT |
4022 | type_allocator alloc (objfile); |
4023 | ||
c906108c SS |
4024 | if (index_type) |
4025 | goto handle_true_range; | |
4026 | ||
4027 | /* If limits are huge, must be large integral type. */ | |
4028 | if (n2bits != 0 || n3bits != 0) | |
4029 | { | |
4030 | char got_signed = 0; | |
4031 | char got_unsigned = 0; | |
4032 | /* Number of bits in the type. */ | |
4033 | int nbits = 0; | |
4034 | ||
94e10a22 | 4035 | /* If a type size attribute has been specified, the bounds of |
dda83cd7 SM |
4036 | the range should fit in this size. If the lower bounds needs |
4037 | more bits than the upper bound, then the type is signed. */ | |
94e10a22 | 4038 | if (n2bits <= type_size && n3bits <= type_size) |
dda83cd7 SM |
4039 | { |
4040 | if (n2bits == type_size && n2bits > n3bits) | |
4041 | got_signed = 1; | |
4042 | else | |
4043 | got_unsigned = 1; | |
4044 | nbits = type_size; | |
4045 | } | |
c906108c | 4046 | /* Range from 0 to <large number> is an unsigned large integral type. */ |
94e10a22 | 4047 | else if ((n2bits == 0 && n2 == 0) && n3bits != 0) |
c906108c SS |
4048 | { |
4049 | got_unsigned = 1; | |
4050 | nbits = n3bits; | |
4051 | } | |
4052 | /* Range from <large number> to <large number>-1 is a large signed | |
dda83cd7 SM |
4053 | integral type. Take care of the case where <large number> doesn't |
4054 | fit in a long but <large number>-1 does. */ | |
c906108c SS |
4055 | else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1) |
4056 | || (n2bits != 0 && n3bits == 0 | |
c2d11a7d JM |
4057 | && (n2bits == sizeof (long) * HOST_CHAR_BIT) |
4058 | && n3 == LONG_MAX)) | |
c906108c SS |
4059 | { |
4060 | got_signed = 1; | |
4061 | nbits = n2bits; | |
4062 | } | |
4063 | ||
4064 | if (got_signed || got_unsigned) | |
2d39ccd3 | 4065 | return init_integer_type (alloc, nbits, got_unsigned, NULL); |
c906108c SS |
4066 | else |
4067 | return error_type (pp, objfile); | |
4068 | } | |
4069 | ||
4070 | /* A type defined as a subrange of itself, with bounds both 0, is void. */ | |
4071 | if (self_subrange && n2 == 0 && n3 == 0) | |
33385940 | 4072 | return alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, nullptr); |
c906108c SS |
4073 | |
4074 | /* If n3 is zero and n2 is positive, we want a floating type, and n2 | |
4075 | is the width in bytes. | |
4076 | ||
4077 | Fortran programs appear to use this for complex types also. To | |
4078 | distinguish between floats and complex, g77 (and others?) seem | |
4079 | to use self-subranges for the complexes, and subranges of int for | |
4080 | the floats. | |
4081 | ||
4082 | Also note that for complexes, g77 sets n2 to the size of one of | |
4083 | the member floats, not the whole complex beast. My guess is that | |
c378eb4e | 4084 | this was to work well with pre-COMPLEX versions of gdb. */ |
c906108c SS |
4085 | |
4086 | if (n3 == 0 && n2 > 0) | |
4087 | { | |
1300f5dd | 4088 | struct type *float_type |
9b790ce7 | 4089 | = dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT); |
1300f5dd | 4090 | |
c906108c | 4091 | if (self_subrange) |
5b930b45 | 4092 | return init_complex_type (NULL, float_type); |
c906108c | 4093 | else |
1300f5dd | 4094 | return float_type; |
c906108c SS |
4095 | } |
4096 | ||
a2699720 | 4097 | /* If the upper bound is -1, it must really be an unsigned integral. */ |
c906108c SS |
4098 | |
4099 | else if (n2 == 0 && n3 == -1) | |
4100 | { | |
a2699720 | 4101 | int bits = type_size; |
433759f7 | 4102 | |
a2699720 PA |
4103 | if (bits <= 0) |
4104 | { | |
4105 | /* We don't know its size. It is unsigned int or unsigned | |
4106 | long. GCC 2.3.3 uses this for long long too, but that is | |
4107 | just a GDB 3.5 compatibility hack. */ | |
5e2b427d | 4108 | bits = gdbarch_int_bit (gdbarch); |
a2699720 PA |
4109 | } |
4110 | ||
2d39ccd3 | 4111 | return init_integer_type (alloc, bits, 1, NULL); |
c906108c SS |
4112 | } |
4113 | ||
4114 | /* Special case: char is defined (Who knows why) as a subrange of | |
4115 | itself with range 0-127. */ | |
4116 | else if (self_subrange && n2 == 0 && n3 == 127) | |
19f392bc | 4117 | { |
2d39ccd3 | 4118 | struct type *type = init_integer_type (alloc, TARGET_CHAR_BIT, |
77b7c781 | 4119 | 0, NULL); |
15152a54 | 4120 | type->set_has_no_signedness (true); |
19f392bc UW |
4121 | return type; |
4122 | } | |
c906108c SS |
4123 | /* We used to do this only for subrange of self or subrange of int. */ |
4124 | else if (n2 == 0) | |
4125 | { | |
a0b3c4fd | 4126 | /* -1 is used for the upper bound of (4 byte) "unsigned int" and |
dda83cd7 SM |
4127 | "unsigned long", and we already checked for that, |
4128 | so don't need to test for it here. */ | |
a0b3c4fd | 4129 | |
c906108c SS |
4130 | if (n3 < 0) |
4131 | /* n3 actually gives the size. */ | |
2d39ccd3 | 4132 | return init_integer_type (alloc, -n3 * TARGET_CHAR_BIT, 1, NULL); |
c906108c | 4133 | |
7be570e7 | 4134 | /* Is n3 == 2**(8n)-1 for some integer n? Then it's an |
dda83cd7 SM |
4135 | unsigned n-byte integer. But do require n to be a power of |
4136 | two; we don't want 3- and 5-byte integers flying around. */ | |
a0b3c4fd JM |
4137 | { |
4138 | int bytes; | |
4139 | unsigned long bits; | |
4140 | ||
4141 | bits = n3; | |
4142 | for (bytes = 0; (bits & 0xff) == 0xff; bytes++) | |
4143 | bits >>= 8; | |
4144 | if (bits == 0 | |
4145 | && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */ | |
2d39ccd3 | 4146 | return init_integer_type (alloc, bytes * TARGET_CHAR_BIT, 1, NULL); |
a0b3c4fd | 4147 | } |
c906108c SS |
4148 | } |
4149 | /* I think this is for Convex "long long". Since I don't know whether | |
4150 | Convex sets self_subrange, I also accept that particular size regardless | |
4151 | of self_subrange. */ | |
4152 | else if (n3 == 0 && n2 < 0 | |
4153 | && (self_subrange | |
9a76efb6 | 4154 | || n2 == -gdbarch_long_long_bit |
5e2b427d | 4155 | (gdbarch) / TARGET_CHAR_BIT)) |
2d39ccd3 | 4156 | return init_integer_type (alloc, -n2 * TARGET_CHAR_BIT, 0, NULL); |
c5aa993b | 4157 | else if (n2 == -n3 - 1) |
c906108c SS |
4158 | { |
4159 | if (n3 == 0x7f) | |
2d39ccd3 | 4160 | return init_integer_type (alloc, 8, 0, NULL); |
c906108c | 4161 | if (n3 == 0x7fff) |
2d39ccd3 | 4162 | return init_integer_type (alloc, 16, 0, NULL); |
c906108c | 4163 | if (n3 == 0x7fffffff) |
2d39ccd3 | 4164 | return init_integer_type (alloc, 32, 0, NULL); |
c906108c SS |
4165 | } |
4166 | ||
4167 | /* We have a real range type on our hands. Allocate space and | |
4168 | return a real pointer. */ | |
c5aa993b | 4169 | handle_true_range: |
c906108c SS |
4170 | |
4171 | if (self_subrange) | |
46bf5051 | 4172 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 4173 | else |
46bf5051 | 4174 | index_type = *dbx_lookup_type (rangenums, objfile); |
c906108c SS |
4175 | if (index_type == NULL) |
4176 | { | |
4177 | /* Does this actually ever happen? Is that why we are worrying | |
dda83cd7 | 4178 | about dealing with it rather than just calling error_type? */ |
c906108c | 4179 | |
b98664d3 | 4180 | complaint (_("base type %d of range type is not defined"), rangenums[1]); |
5e2b427d | 4181 | |
46bf5051 | 4182 | index_type = objfile_type (objfile)->builtin_int; |
c906108c SS |
4183 | } |
4184 | ||
0c9c3474 | 4185 | result_type |
e727c536 | 4186 | = create_static_range_type (alloc, index_type, n2, n3); |
c906108c SS |
4187 | return (result_type); |
4188 | } | |
4189 | ||
4190 | /* Read in an argument list. This is a list of types, separated by commas | |
0a029df5 DJ |
4191 | and terminated with END. Return the list of types read in, or NULL |
4192 | if there is an error. */ | |
c906108c | 4193 | |
ad2f7632 | 4194 | static struct field * |
a121b7c1 | 4195 | read_args (const char **pp, int end, struct objfile *objfile, int *nargsp, |
ad2f7632 | 4196 | int *varargsp) |
c906108c SS |
4197 | { |
4198 | /* FIXME! Remove this arbitrary limit! */ | |
c378eb4e | 4199 | struct type *types[1024]; /* Allow for fns of 1023 parameters. */ |
ad2f7632 DJ |
4200 | int n = 0, i; |
4201 | struct field *rval; | |
c906108c SS |
4202 | |
4203 | while (**pp != end) | |
4204 | { | |
4205 | if (**pp != ',') | |
4206 | /* Invalid argument list: no ','. */ | |
0a029df5 | 4207 | return NULL; |
c906108c SS |
4208 | (*pp)++; |
4209 | STABS_CONTINUE (pp, objfile); | |
4210 | types[n++] = read_type (pp, objfile); | |
4211 | } | |
c378eb4e | 4212 | (*pp)++; /* get past `end' (the ':' character). */ |
c906108c | 4213 | |
d24d8548 JK |
4214 | if (n == 0) |
4215 | { | |
4216 | /* We should read at least the THIS parameter here. Some broken stabs | |
4217 | output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should | |
4218 | have been present ";-16,(0,43)" reference instead. This way the | |
4219 | excessive ";" marker prematurely stops the parameters parsing. */ | |
4220 | ||
b98664d3 | 4221 | complaint (_("Invalid (empty) method arguments")); |
d24d8548 JK |
4222 | *varargsp = 0; |
4223 | } | |
78134374 | 4224 | else if (types[n - 1]->code () != TYPE_CODE_VOID) |
ad2f7632 | 4225 | *varargsp = 1; |
c906108c SS |
4226 | else |
4227 | { | |
ad2f7632 DJ |
4228 | n--; |
4229 | *varargsp = 0; | |
c906108c | 4230 | } |
ad2f7632 | 4231 | |
8d749320 | 4232 | rval = XCNEWVEC (struct field, n); |
ad2f7632 | 4233 | for (i = 0; i < n; i++) |
5d14b6e5 | 4234 | rval[i].set_type (types[i]); |
ad2f7632 | 4235 | *nargsp = n; |
c906108c SS |
4236 | return rval; |
4237 | } | |
4238 | \f | |
4239 | /* Common block handling. */ | |
4240 | ||
4241 | /* List of symbols declared since the last BCOMM. This list is a tail | |
4242 | of local_symbols. When ECOMM is seen, the symbols on the list | |
4243 | are noted so their proper addresses can be filled in later, | |
4244 | using the common block base address gotten from the assembler | |
4245 | stabs. */ | |
4246 | ||
4247 | static struct pending *common_block; | |
4248 | static int common_block_i; | |
4249 | ||
4250 | /* Name of the current common block. We get it from the BCOMM instead of the | |
4251 | ECOMM to match IBM documentation (even though IBM puts the name both places | |
4252 | like everyone else). */ | |
4253 | static char *common_block_name; | |
4254 | ||
4255 | /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed | |
4256 | to remain after this function returns. */ | |
4257 | ||
4258 | void | |
a121b7c1 | 4259 | common_block_start (const char *name, struct objfile *objfile) |
c906108c SS |
4260 | { |
4261 | if (common_block_name != NULL) | |
4262 | { | |
b98664d3 | 4263 | complaint (_("Invalid symbol data: common block within common block")); |
c906108c | 4264 | } |
e148f09d TT |
4265 | common_block = *get_local_symbols (); |
4266 | common_block_i = common_block ? common_block->nsyms : 0; | |
021887d8 | 4267 | common_block_name = obstack_strdup (&objfile->objfile_obstack, name); |
c906108c SS |
4268 | } |
4269 | ||
4270 | /* Process a N_ECOMM symbol. */ | |
4271 | ||
4272 | void | |
fba45db2 | 4273 | common_block_end (struct objfile *objfile) |
c906108c SS |
4274 | { |
4275 | /* Symbols declared since the BCOMM are to have the common block | |
4276 | start address added in when we know it. common_block and | |
4277 | common_block_i point to the first symbol after the BCOMM in | |
4278 | the local_symbols list; copy the list and hang it off the | |
4279 | symbol for the common block name for later fixup. */ | |
4280 | int i; | |
4281 | struct symbol *sym; | |
fe978cb0 | 4282 | struct pending *newobj = 0; |
c906108c SS |
4283 | struct pending *next; |
4284 | int j; | |
4285 | ||
4286 | if (common_block_name == NULL) | |
4287 | { | |
b98664d3 | 4288 | complaint (_("ECOMM symbol unmatched by BCOMM")); |
c906108c SS |
4289 | return; |
4290 | } | |
4291 | ||
8c14c3a3 | 4292 | sym = new (&objfile->objfile_obstack) symbol; |
c378eb4e | 4293 | /* Note: common_block_name already saved on objfile_obstack. */ |
43678b0a | 4294 | sym->set_linkage_name (common_block_name); |
ba44b1a3 | 4295 | sym->set_aclass_index (LOC_BLOCK); |
c906108c SS |
4296 | |
4297 | /* Now we copy all the symbols which have been defined since the BCOMM. */ | |
4298 | ||
4299 | /* Copy all the struct pendings before common_block. */ | |
e148f09d | 4300 | for (next = *get_local_symbols (); |
c906108c SS |
4301 | next != NULL && next != common_block; |
4302 | next = next->next) | |
4303 | { | |
4304 | for (j = 0; j < next->nsyms; j++) | |
fe978cb0 | 4305 | add_symbol_to_list (next->symbol[j], &newobj); |
c906108c SS |
4306 | } |
4307 | ||
4308 | /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is | |
4309 | NULL, it means copy all the local symbols (which we already did | |
4310 | above). */ | |
4311 | ||
4312 | if (common_block != NULL) | |
4313 | for (j = common_block_i; j < common_block->nsyms; j++) | |
fe978cb0 | 4314 | add_symbol_to_list (common_block->symbol[j], &newobj); |
c906108c | 4315 | |
5f9c5a63 | 4316 | sym->set_type ((struct type *) newobj); |
c906108c SS |
4317 | |
4318 | /* Should we be putting local_symbols back to what it was? | |
4319 | Does it matter? */ | |
4320 | ||
987012b8 | 4321 | i = hashname (sym->linkage_name ()); |
4aeddc50 | 4322 | sym->set_value_chain (global_sym_chain[i]); |
c906108c SS |
4323 | global_sym_chain[i] = sym; |
4324 | common_block_name = NULL; | |
4325 | } | |
4326 | ||
4327 | /* Add a common block's start address to the offset of each symbol | |
4328 | declared to be in it (by being between a BCOMM/ECOMM pair that uses | |
4329 | the common block name). */ | |
4330 | ||
4331 | static void | |
b8a6e987 | 4332 | fix_common_block (struct symbol *sym, CORE_ADDR valu, int section_index) |
c906108c | 4333 | { |
5f9c5a63 | 4334 | struct pending *next = (struct pending *) sym->type (); |
433759f7 | 4335 | |
c5aa993b | 4336 | for (; next; next = next->next) |
c906108c | 4337 | { |
aa1ee363 | 4338 | int j; |
433759f7 | 4339 | |
c906108c | 4340 | for (j = next->nsyms - 1; j >= 0; j--) |
b8a6e987 TT |
4341 | { |
4342 | next->symbol[j]->set_value_address | |
4343 | (next->symbol[j]->value_address () + valu); | |
4344 | next->symbol[j]->set_section_index (section_index); | |
4345 | } | |
c906108c SS |
4346 | } |
4347 | } | |
c5aa993b | 4348 | \f |
c906108c SS |
4349 | |
4350 | ||
bf362611 JB |
4351 | /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector. |
4352 | See add_undefined_type for more details. */ | |
c906108c | 4353 | |
a7a48797 | 4354 | static void |
bf362611 JB |
4355 | add_undefined_type_noname (struct type *type, int typenums[2]) |
4356 | { | |
4357 | struct nat nat; | |
4358 | ||
4359 | nat.typenums[0] = typenums [0]; | |
4360 | nat.typenums[1] = typenums [1]; | |
4361 | nat.type = type; | |
4362 | ||
4363 | if (noname_undefs_length == noname_undefs_allocated) | |
4364 | { | |
4365 | noname_undefs_allocated *= 2; | |
4366 | noname_undefs = (struct nat *) | |
4367 | xrealloc ((char *) noname_undefs, | |
4368 | noname_undefs_allocated * sizeof (struct nat)); | |
4369 | } | |
4370 | noname_undefs[noname_undefs_length++] = nat; | |
4371 | } | |
4372 | ||
4373 | /* Add TYPE to the UNDEF_TYPES vector. | |
4374 | See add_undefined_type for more details. */ | |
4375 | ||
4376 | static void | |
4377 | add_undefined_type_1 (struct type *type) | |
c906108c SS |
4378 | { |
4379 | if (undef_types_length == undef_types_allocated) | |
4380 | { | |
4381 | undef_types_allocated *= 2; | |
4382 | undef_types = (struct type **) | |
4383 | xrealloc ((char *) undef_types, | |
4384 | undef_types_allocated * sizeof (struct type *)); | |
4385 | } | |
4386 | undef_types[undef_types_length++] = type; | |
4387 | } | |
4388 | ||
bf362611 JB |
4389 | /* What about types defined as forward references inside of a small lexical |
4390 | scope? */ | |
4391 | /* Add a type to the list of undefined types to be checked through | |
4392 | once this file has been read in. | |
4393 | ||
4394 | In practice, we actually maintain two such lists: The first list | |
4395 | (UNDEF_TYPES) is used for types whose name has been provided, and | |
4396 | concerns forward references (eg 'xs' or 'xu' forward references); | |
4397 | the second list (NONAME_UNDEFS) is used for types whose name is | |
4398 | unknown at creation time, because they were referenced through | |
4399 | their type number before the actual type was declared. | |
4400 | This function actually adds the given type to the proper list. */ | |
4401 | ||
4402 | static void | |
4403 | add_undefined_type (struct type *type, int typenums[2]) | |
4404 | { | |
7d93a1e0 | 4405 | if (type->name () == NULL) |
bf362611 JB |
4406 | add_undefined_type_noname (type, typenums); |
4407 | else | |
4408 | add_undefined_type_1 (type); | |
4409 | } | |
4410 | ||
4411 | /* Try to fix all undefined types pushed on the UNDEF_TYPES vector. */ | |
4412 | ||
2c0b251b | 4413 | static void |
46bf5051 | 4414 | cleanup_undefined_types_noname (struct objfile *objfile) |
bf362611 JB |
4415 | { |
4416 | int i; | |
4417 | ||
4418 | for (i = 0; i < noname_undefs_length; i++) | |
4419 | { | |
4420 | struct nat nat = noname_undefs[i]; | |
4421 | struct type **type; | |
4422 | ||
46bf5051 | 4423 | type = dbx_lookup_type (nat.typenums, objfile); |
78134374 | 4424 | if (nat.type != *type && (*type)->code () != TYPE_CODE_UNDEF) |
dda83cd7 SM |
4425 | { |
4426 | /* The instance flags of the undefined type are still unset, | |
4427 | and needs to be copied over from the reference type. | |
4428 | Since replace_type expects them to be identical, we need | |
4429 | to set these flags manually before hand. */ | |
4430 | nat.type->set_instance_flags ((*type)->instance_flags ()); | |
4431 | replace_type (nat.type, *type); | |
4432 | } | |
bf362611 JB |
4433 | } |
4434 | ||
4435 | noname_undefs_length = 0; | |
4436 | } | |
4437 | ||
c906108c SS |
4438 | /* Go through each undefined type, see if it's still undefined, and fix it |
4439 | up if possible. We have two kinds of undefined types: | |
4440 | ||
4441 | TYPE_CODE_ARRAY: Array whose target type wasn't defined yet. | |
c5aa993b JM |
4442 | Fix: update array length using the element bounds |
4443 | and the target type's length. | |
c906108c | 4444 | TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not |
c5aa993b JM |
4445 | yet defined at the time a pointer to it was made. |
4446 | Fix: Do a full lookup on the struct/union tag. */ | |
bf362611 | 4447 | |
2c0b251b | 4448 | static void |
bf362611 | 4449 | cleanup_undefined_types_1 (void) |
c906108c SS |
4450 | { |
4451 | struct type **type; | |
4452 | ||
9e386756 JB |
4453 | /* Iterate over every undefined type, and look for a symbol whose type |
4454 | matches our undefined type. The symbol matches if: | |
4455 | 1. It is a typedef in the STRUCT domain; | |
4456 | 2. It has the same name, and same type code; | |
4457 | 3. The instance flags are identical. | |
4458 | ||
4459 | It is important to check the instance flags, because we have seen | |
4460 | examples where the debug info contained definitions such as: | |
4461 | ||
dda83cd7 | 4462 | "foo_t:t30=B31=xefoo_t:" |
9e386756 JB |
4463 | |
4464 | In this case, we have created an undefined type named "foo_t" whose | |
4465 | instance flags is null (when processing "xefoo_t"), and then created | |
4466 | another type with the same name, but with different instance flags | |
4467 | ('B' means volatile). I think that the definition above is wrong, | |
4468 | since the same type cannot be volatile and non-volatile at the same | |
4469 | time, but we need to be able to cope with it when it happens. The | |
4470 | approach taken here is to treat these two types as different. */ | |
4471 | ||
c906108c SS |
4472 | for (type = undef_types; type < undef_types + undef_types_length; type++) |
4473 | { | |
78134374 | 4474 | switch ((*type)->code ()) |
c906108c SS |
4475 | { |
4476 | ||
c5aa993b JM |
4477 | case TYPE_CODE_STRUCT: |
4478 | case TYPE_CODE_UNION: | |
4479 | case TYPE_CODE_ENUM: | |
c906108c SS |
4480 | { |
4481 | /* Check if it has been defined since. Need to do this here | |
4482 | as well as in check_typedef to deal with the (legitimate in | |
4483 | C though not C++) case of several types with the same name | |
4484 | in different source files. */ | |
e46d3488 | 4485 | if ((*type)->is_stub ()) |
c906108c SS |
4486 | { |
4487 | struct pending *ppt; | |
4488 | int i; | |
c378eb4e | 4489 | /* Name of the type, without "struct" or "union". */ |
7d93a1e0 | 4490 | const char *type_name = (*type)->name (); |
c906108c | 4491 | |
fe978cb0 | 4492 | if (type_name == NULL) |
c906108c | 4493 | { |
b98664d3 | 4494 | complaint (_("need a type name")); |
c906108c SS |
4495 | break; |
4496 | } | |
e148f09d | 4497 | for (ppt = *get_file_symbols (); ppt; ppt = ppt->next) |
c906108c SS |
4498 | { |
4499 | for (i = 0; i < ppt->nsyms; i++) | |
4500 | { | |
4501 | struct symbol *sym = ppt->symbol[i]; | |
c5aa993b | 4502 | |
66d7f48f | 4503 | if (sym->aclass () == LOC_TYPEDEF |
6c9c307c | 4504 | && sym->domain () == STRUCT_DOMAIN |
5f9c5a63 | 4505 | && (sym->type ()->code () == (*type)->code ()) |
10242f36 | 4506 | && ((*type)->instance_flags () |
5f9c5a63 | 4507 | == sym->type ()->instance_flags ()) |
987012b8 | 4508 | && strcmp (sym->linkage_name (), type_name) == 0) |
5f9c5a63 | 4509 | replace_type (*type, sym->type ()); |
c906108c SS |
4510 | } |
4511 | } | |
4512 | } | |
4513 | } | |
4514 | break; | |
4515 | ||
4516 | default: | |
4517 | { | |
b98664d3 | 4518 | complaint (_("forward-referenced types left unresolved, " |
dda83cd7 | 4519 | "type code %d."), |
78134374 | 4520 | (*type)->code ()); |
c906108c SS |
4521 | } |
4522 | break; | |
4523 | } | |
4524 | } | |
4525 | ||
4526 | undef_types_length = 0; | |
4527 | } | |
4528 | ||
30baf67b | 4529 | /* Try to fix all the undefined types we encountered while processing |
bf362611 JB |
4530 | this unit. */ |
4531 | ||
4532 | void | |
0a0edcd5 | 4533 | cleanup_undefined_stabs_types (struct objfile *objfile) |
bf362611 JB |
4534 | { |
4535 | cleanup_undefined_types_1 (); | |
46bf5051 | 4536 | cleanup_undefined_types_noname (objfile); |
bf362611 JB |
4537 | } |
4538 | ||
77d6f1aa | 4539 | /* See stabsread.h. */ |
c906108c SS |
4540 | |
4541 | void | |
fba45db2 | 4542 | scan_file_globals (struct objfile *objfile) |
c906108c SS |
4543 | { |
4544 | int hash; | |
507836c0 | 4545 | struct symbol *sym, *prev; |
c906108c SS |
4546 | struct objfile *resolve_objfile; |
4547 | ||
4548 | /* SVR4 based linkers copy referenced global symbols from shared | |
4549 | libraries to the main executable. | |
4550 | If we are scanning the symbols for a shared library, try to resolve | |
4551 | them from the minimal symbols of the main executable first. */ | |
4552 | ||
a42d7dd8 TT |
4553 | if (current_program_space->symfile_object_file |
4554 | && objfile != current_program_space->symfile_object_file) | |
4555 | resolve_objfile = current_program_space->symfile_object_file; | |
c906108c SS |
4556 | else |
4557 | resolve_objfile = objfile; | |
4558 | ||
4559 | while (1) | |
4560 | { | |
4561 | /* Avoid expensive loop through all minimal symbols if there are | |
dda83cd7 | 4562 | no unresolved symbols. */ |
c906108c SS |
4563 | for (hash = 0; hash < HASHSIZE; hash++) |
4564 | { | |
4565 | if (global_sym_chain[hash]) | |
4566 | break; | |
4567 | } | |
4568 | if (hash >= HASHSIZE) | |
4569 | return; | |
4570 | ||
7932255d | 4571 | for (minimal_symbol *msymbol : resolve_objfile->msymbols ()) |
c906108c SS |
4572 | { |
4573 | QUIT; | |
4574 | ||
4575 | /* Skip static symbols. */ | |
60f62e2b | 4576 | switch (msymbol->type ()) |
c906108c SS |
4577 | { |
4578 | case mst_file_text: | |
4579 | case mst_file_data: | |
4580 | case mst_file_bss: | |
4581 | continue; | |
4582 | default: | |
4583 | break; | |
4584 | } | |
4585 | ||
4586 | prev = NULL; | |
4587 | ||
4588 | /* Get the hash index and check all the symbols | |
c378eb4e | 4589 | under that hash index. */ |
c906108c | 4590 | |
c9d95fa3 | 4591 | hash = hashname (msymbol->linkage_name ()); |
c906108c SS |
4592 | |
4593 | for (sym = global_sym_chain[hash]; sym;) | |
4594 | { | |
987012b8 | 4595 | if (strcmp (msymbol->linkage_name (), sym->linkage_name ()) == 0) |
c906108c | 4596 | { |
c906108c | 4597 | /* Splice this symbol out of the hash chain and |
c378eb4e | 4598 | assign the value we have to it. */ |
c906108c SS |
4599 | if (prev) |
4600 | { | |
4aeddc50 | 4601 | prev->set_value_chain (sym->value_chain ()); |
c906108c SS |
4602 | } |
4603 | else | |
4604 | { | |
4aeddc50 | 4605 | global_sym_chain[hash] = sym->value_chain (); |
c906108c | 4606 | } |
c5aa993b | 4607 | |
c906108c SS |
4608 | /* Check to see whether we need to fix up a common block. */ |
4609 | /* Note: this code might be executed several times for | |
4610 | the same symbol if there are multiple references. */ | |
507836c0 | 4611 | if (sym) |
c906108c | 4612 | { |
66d7f48f | 4613 | if (sym->aclass () == LOC_BLOCK) |
4aeddc50 | 4614 | fix_common_block |
b8a6e987 TT |
4615 | (sym, msymbol->value_address (resolve_objfile), |
4616 | msymbol->section_index ()); | |
c906108c | 4617 | else |
4aeddc50 SM |
4618 | sym->set_value_address |
4619 | (msymbol->value_address (resolve_objfile)); | |
a52d653e | 4620 | sym->set_section_index (msymbol->section_index ()); |
c906108c SS |
4621 | } |
4622 | ||
c906108c SS |
4623 | if (prev) |
4624 | { | |
4aeddc50 | 4625 | sym = prev->value_chain (); |
c906108c SS |
4626 | } |
4627 | else | |
4628 | { | |
4629 | sym = global_sym_chain[hash]; | |
4630 | } | |
4631 | } | |
4632 | else | |
4633 | { | |
4634 | prev = sym; | |
4aeddc50 | 4635 | sym = sym->value_chain (); |
c906108c SS |
4636 | } |
4637 | } | |
4638 | } | |
4639 | if (resolve_objfile == objfile) | |
4640 | break; | |
4641 | resolve_objfile = objfile; | |
4642 | } | |
4643 | ||
4644 | /* Change the storage class of any remaining unresolved globals to | |
4645 | LOC_UNRESOLVED and remove them from the chain. */ | |
4646 | for (hash = 0; hash < HASHSIZE; hash++) | |
4647 | { | |
4648 | sym = global_sym_chain[hash]; | |
4649 | while (sym) | |
4650 | { | |
4651 | prev = sym; | |
4aeddc50 | 4652 | sym = sym->value_chain (); |
c906108c SS |
4653 | |
4654 | /* Change the symbol address from the misleading chain value | |
4655 | to address zero. */ | |
4aeddc50 | 4656 | prev->set_value_address (0); |
c906108c SS |
4657 | |
4658 | /* Complain about unresolved common block symbols. */ | |
66d7f48f | 4659 | if (prev->aclass () == LOC_STATIC) |
ba44b1a3 | 4660 | prev->set_aclass_index (LOC_UNRESOLVED); |
c906108c | 4661 | else |
b98664d3 | 4662 | complaint (_("%s: common block `%s' from " |
3e43a32a | 4663 | "global_sym_chain unresolved"), |
987012b8 | 4664 | objfile_name (objfile), prev->print_name ()); |
c906108c SS |
4665 | } |
4666 | } | |
4667 | memset (global_sym_chain, 0, sizeof (global_sym_chain)); | |
4668 | } | |
4669 | ||
4670 | /* Initialize anything that needs initializing when starting to read | |
4671 | a fresh piece of a symbol file, e.g. reading in the stuff corresponding | |
4672 | to a psymtab. */ | |
4673 | ||
4674 | void | |
fba45db2 | 4675 | stabsread_init (void) |
c906108c SS |
4676 | { |
4677 | } | |
4678 | ||
4679 | /* Initialize anything that needs initializing when a completely new | |
4680 | symbol file is specified (not just adding some symbols from another | |
4681 | file, e.g. a shared library). */ | |
4682 | ||
4683 | void | |
fba45db2 | 4684 | stabsread_new_init (void) |
c906108c SS |
4685 | { |
4686 | /* Empty the hash table of global syms looking for values. */ | |
4687 | memset (global_sym_chain, 0, sizeof (global_sym_chain)); | |
4688 | } | |
4689 | ||
4690 | /* Initialize anything that needs initializing at the same time as | |
59dfe8ad | 4691 | start_compunit_symtab() is called. */ |
c906108c | 4692 | |
c5aa993b | 4693 | void |
fba45db2 | 4694 | start_stabs (void) |
c906108c SS |
4695 | { |
4696 | global_stabs = NULL; /* AIX COFF */ | |
4697 | /* Leave FILENUM of 0 free for builtin types and this file's types. */ | |
4698 | n_this_object_header_files = 1; | |
4699 | type_vector_length = 0; | |
4700 | type_vector = (struct type **) 0; | |
5985ac61 | 4701 | within_function = 0; |
c906108c SS |
4702 | |
4703 | /* FIXME: If common_block_name is not already NULL, we should complain(). */ | |
4704 | common_block_name = NULL; | |
c906108c SS |
4705 | } |
4706 | ||
59dfe8ad | 4707 | /* Call after end_compunit_symtab(). */ |
c906108c | 4708 | |
c5aa993b | 4709 | void |
fba45db2 | 4710 | end_stabs (void) |
c906108c SS |
4711 | { |
4712 | if (type_vector) | |
4713 | { | |
b8c9b27d | 4714 | xfree (type_vector); |
c906108c SS |
4715 | } |
4716 | type_vector = 0; | |
4717 | type_vector_length = 0; | |
4718 | previous_stab_code = 0; | |
4719 | } | |
4720 | ||
4721 | void | |
fba45db2 | 4722 | finish_global_stabs (struct objfile *objfile) |
c906108c SS |
4723 | { |
4724 | if (global_stabs) | |
4725 | { | |
e148f09d | 4726 | patch_block_stabs (*get_global_symbols (), global_stabs, objfile); |
b8c9b27d | 4727 | xfree (global_stabs); |
c906108c SS |
4728 | global_stabs = NULL; |
4729 | } | |
4730 | } | |
4731 | ||
7e1d63ec AF |
4732 | /* Find the end of the name, delimited by a ':', but don't match |
4733 | ObjC symbols which look like -[Foo bar::]:bla. */ | |
a121b7c1 PA |
4734 | static const char * |
4735 | find_name_end (const char *name) | |
7e1d63ec | 4736 | { |
a121b7c1 | 4737 | const char *s = name; |
433759f7 | 4738 | |
7e1d63ec AF |
4739 | if (s[0] == '-' || *s == '+') |
4740 | { | |
4741 | /* Must be an ObjC method symbol. */ | |
4742 | if (s[1] != '[') | |
4743 | { | |
8a3fe4f8 | 4744 | error (_("invalid symbol name \"%s\""), name); |
7e1d63ec AF |
4745 | } |
4746 | s = strchr (s, ']'); | |
4747 | if (s == NULL) | |
4748 | { | |
8a3fe4f8 | 4749 | error (_("invalid symbol name \"%s\""), name); |
7e1d63ec AF |
4750 | } |
4751 | return strchr (s, ':'); | |
4752 | } | |
4753 | else | |
4754 | { | |
4755 | return strchr (s, ':'); | |
4756 | } | |
4757 | } | |
4758 | ||
2150c3ef TT |
4759 | /* See stabsread.h. */ |
4760 | ||
4761 | int | |
4762 | hashname (const char *name) | |
4763 | { | |
4cbd39b2 | 4764 | return fast_hash (name, strlen (name)) % HASHSIZE; |
2150c3ef TT |
4765 | } |
4766 | ||
c378eb4e | 4767 | /* Initializer for this module. */ |
c906108c | 4768 | |
6c265988 | 4769 | void _initialize_stabsread (); |
c906108c | 4770 | void |
6c265988 | 4771 | _initialize_stabsread () |
c906108c SS |
4772 | { |
4773 | undef_types_allocated = 20; | |
4774 | undef_types_length = 0; | |
8d749320 | 4775 | undef_types = XNEWVEC (struct type *, undef_types_allocated); |
bf362611 JB |
4776 | |
4777 | noname_undefs_allocated = 20; | |
4778 | noname_undefs_length = 0; | |
8d749320 | 4779 | noname_undefs = XNEWVEC (struct nat, noname_undefs_allocated); |
f1e6e072 TT |
4780 | |
4781 | stab_register_index = register_symbol_register_impl (LOC_REGISTER, | |
4782 | &stab_register_funcs); | |
4783 | stab_regparm_index = register_symbol_register_impl (LOC_REGPARM_ADDR, | |
4784 | &stab_register_funcs); | |
c906108c | 4785 | } |