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