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