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