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