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