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