Commit | Line | Data |
---|---|---|
d07734e3 | 1 | /* Support routines for decoding "stabs" debugging information format. |
ba47c66a | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 |
d07734e3 FF |
3 | Free Software Foundation, Inc. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* Support routines for reading and decoding debugging information in | |
22 | the "stabs" format. This format is used with many systems that use | |
23 | the a.out object file format, as well as some systems that use | |
24 | COFF or ELF where the stabs data is placed in a special section. | |
25 | Avoid placing any object file format specific code in this file. */ | |
26 | ||
27 | #include "defs.h" | |
ba47c66a | 28 | #include <string.h> |
d07734e3 FF |
29 | #include "bfd.h" |
30 | #include "obstack.h" | |
31 | #include "symtab.h" | |
32 | #include "gdbtypes.h" | |
51b80b00 | 33 | #include "symfile.h" |
d07734e3 FF |
34 | #include "objfiles.h" |
35 | #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */ | |
a66e8382 SG |
36 | #include "libaout.h" |
37 | #include "aout/aout64.h" | |
38 | #include "gdb-stabs.h" | |
d07734e3 | 39 | #include "buildsym.h" |
51b80b00 | 40 | #include "complaints.h" |
2e4964ad | 41 | #include "demangle.h" |
d07734e3 | 42 | |
9ddfb9eb JK |
43 | #include <ctype.h> |
44 | ||
d07734e3 FF |
45 | /* Ask stabsread.h to define the vars it normally declares `extern'. */ |
46 | #define EXTERN /**/ | |
47 | #include "stabsread.h" /* Our own declarations */ | |
48 | #undef EXTERN | |
49 | ||
e7177cc2 FF |
50 | /* The routines that read and process a complete stabs for a C struct or |
51 | C++ class pass lists of data member fields and lists of member function | |
52 | fields in an instance of a field_info structure, as defined below. | |
53 | This is part of some reorganization of low level C++ support and is | |
54 | expected to eventually go away... (FIXME) */ | |
55 | ||
56 | struct field_info | |
57 | { | |
58 | struct nextfield | |
59 | { | |
60 | struct nextfield *next; | |
1dfaef62 JK |
61 | |
62 | /* This is the raw visibility from the stab. It is not checked | |
63 | for being one of the visibilities we recognize, so code which | |
64 | examines this field better be able to deal. */ | |
e7177cc2 | 65 | int visibility; |
1dfaef62 | 66 | |
e7177cc2 FF |
67 | struct field field; |
68 | } *list; | |
69 | struct next_fnfieldlist | |
70 | { | |
71 | struct next_fnfieldlist *next; | |
72 | struct fn_fieldlist fn_fieldlist; | |
73 | } *fnlist; | |
74 | }; | |
75 | ||
d07734e3 FF |
76 | static struct type * |
77 | dbx_alloc_type PARAMS ((int [2], struct objfile *)); | |
78 | ||
ea753d03 JK |
79 | static long read_huge_number PARAMS ((char **, int, int *)); |
80 | ||
81 | static struct type *error_type PARAMS ((char **)); | |
d07734e3 FF |
82 | |
83 | static void | |
84 | patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *, | |
85 | struct objfile *)); | |
86 | ||
87 | static void | |
88 | fix_common_block PARAMS ((struct symbol *, int)); | |
89 | ||
ea753d03 JK |
90 | static int |
91 | read_type_number PARAMS ((char **, int *)); | |
92 | ||
d07734e3 FF |
93 | static struct type * |
94 | read_range_type PARAMS ((char **, int [2], struct objfile *)); | |
95 | ||
96 | static struct type * | |
97 | read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *)); | |
98 | ||
99 | static struct type * | |
100 | read_sun_floating_type PARAMS ((char **, int [2], struct objfile *)); | |
101 | ||
102 | static struct type * | |
103 | read_enum_type PARAMS ((char **, struct type *, struct objfile *)); | |
104 | ||
dd469789 | 105 | static struct type * |
a387370d | 106 | rs6000_builtin_type PARAMS ((int)); |
dd469789 | 107 | |
e7177cc2 FF |
108 | static int |
109 | read_member_functions PARAMS ((struct field_info *, char **, struct type *, | |
110 | struct objfile *)); | |
111 | ||
112 | static int | |
113 | read_struct_fields PARAMS ((struct field_info *, char **, struct type *, | |
114 | struct objfile *)); | |
115 | ||
116 | static int | |
117 | read_baseclasses PARAMS ((struct field_info *, char **, struct type *, | |
118 | struct objfile *)); | |
119 | ||
120 | static int | |
121 | read_tilde_fields PARAMS ((struct field_info *, char **, struct type *, | |
122 | struct objfile *)); | |
123 | ||
124 | static int | |
125 | attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *)); | |
126 | ||
127 | static int | |
128 | attach_fields_to_type PARAMS ((struct field_info *, struct type *, | |
129 | struct objfile *)); | |
130 | ||
d07734e3 FF |
131 | static struct type * |
132 | read_struct_type PARAMS ((char **, struct type *, struct objfile *)); | |
133 | ||
134 | static struct type * | |
135 | read_array_type PARAMS ((char **, struct type *, struct objfile *)); | |
136 | ||
137 | static struct type ** | |
138 | read_args PARAMS ((char **, int, struct objfile *)); | |
139 | ||
ea753d03 | 140 | static int |
e7177cc2 FF |
141 | read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *, |
142 | struct objfile *)); | |
143 | ||
d07734e3 FF |
144 | static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' }; |
145 | static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' }; | |
146 | ||
147 | /* Define this as 1 if a pcc declaration of a char or short argument | |
148 | gives the correct address. Otherwise assume pcc gives the | |
149 | address of the corresponding int, which is not the same on a | |
150 | big-endian machine. */ | |
151 | ||
152 | #ifndef BELIEVE_PCC_PROMOTION | |
153 | #define BELIEVE_PCC_PROMOTION 0 | |
154 | #endif | |
155 | ||
d07734e3 FF |
156 | struct complaint invalid_cpp_abbrev_complaint = |
157 | {"invalid C++ abbreviation `%s'", 0, 0}; | |
158 | ||
159 | struct complaint invalid_cpp_type_complaint = | |
160 | {"C++ abbreviated type name unknown at symtab pos %d", 0, 0}; | |
161 | ||
162 | struct complaint member_fn_complaint = | |
163 | {"member function type missing, got '%c'", 0, 0}; | |
164 | ||
165 | struct complaint const_vol_complaint = | |
166 | {"const/volatile indicator missing, got '%c'", 0, 0}; | |
167 | ||
168 | struct complaint error_type_complaint = | |
169 | {"debug info mismatch between compiler and debugger", 0, 0}; | |
170 | ||
171 | struct complaint invalid_member_complaint = | |
172 | {"invalid (minimal) member type data format at symtab pos %d.", 0, 0}; | |
173 | ||
174 | struct complaint range_type_base_complaint = | |
175 | {"base type %d of range type is not defined", 0, 0}; | |
176 | ||
177 | struct complaint reg_value_complaint = | |
178 | {"register number too large in symbol %s", 0, 0}; | |
179 | ||
2a021f21 JG |
180 | struct complaint vtbl_notfound_complaint = |
181 | {"virtual function table pointer not found when defining class `%s'", 0, 0}; | |
182 | ||
183 | struct complaint unrecognized_cplus_name_complaint = | |
184 | {"Unknown C++ symbol name `%s'", 0, 0}; | |
185 | ||
dd469789 | 186 | struct complaint rs6000_builtin_complaint = |
a387370d | 187 | {"Unknown builtin type %d", 0, 0}; |
dd469789 | 188 | |
e7177cc2 FF |
189 | struct complaint stabs_general_complaint = |
190 | {"%s", 0, 0}; | |
191 | ||
d07734e3 FF |
192 | /* Make a list of forward references which haven't been defined. */ |
193 | ||
194 | static struct type **undef_types; | |
195 | static int undef_types_allocated; | |
196 | static int undef_types_length; | |
197 | ||
e7177cc2 FF |
198 | /* Check for and handle cretinous stabs symbol name continuation! */ |
199 | #define STABS_CONTINUE(pp) \ | |
200 | do { \ | |
91a0575c JK |
201 | if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \ |
202 | *(pp) = next_symbol_text (); \ | |
e7177cc2 | 203 | } while (0) |
d07734e3 | 204 | \f |
25200748 JK |
205 | /* FIXME: These probably should be our own types (like rs6000_builtin_type |
206 | has its own types) rather than builtin_type_*. */ | |
207 | static struct type **os9k_type_vector[] = { | |
208 | 0, | |
209 | &builtin_type_int, | |
210 | &builtin_type_char, | |
211 | &builtin_type_long, | |
212 | &builtin_type_short, | |
213 | &builtin_type_unsigned_char, | |
214 | &builtin_type_unsigned_short, | |
215 | &builtin_type_unsigned_long, | |
216 | &builtin_type_unsigned_int, | |
217 | &builtin_type_float, | |
218 | &builtin_type_double, | |
219 | &builtin_type_void, | |
220 | &builtin_type_long_double | |
221 | }; | |
222 | ||
223 | static void os9k_init_type_vector PARAMS ((struct type **)); | |
224 | ||
225 | static void | |
226 | os9k_init_type_vector(tv) | |
227 | struct type **tv; | |
228 | { | |
229 | int i; | |
230 | for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++) | |
231 | tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i])); | |
232 | } | |
233 | ||
d07734e3 FF |
234 | /* Look up a dbx type-number pair. Return the address of the slot |
235 | where the type for that number-pair is stored. | |
236 | The number-pair is in TYPENUMS. | |
237 | ||
238 | This can be used for finding the type associated with that pair | |
239 | or for associating a new type with the pair. */ | |
240 | ||
241 | struct type ** | |
242 | dbx_lookup_type (typenums) | |
243 | int typenums[2]; | |
244 | { | |
245 | register int filenum = typenums[0]; | |
246 | register int index = typenums[1]; | |
247 | unsigned old_len; | |
248 | register int real_filenum; | |
249 | register struct header_file *f; | |
250 | int f_orig_length; | |
251 | ||
252 | if (filenum == -1) /* -1,-1 is for temporary types. */ | |
253 | return 0; | |
254 | ||
255 | if (filenum < 0 || filenum >= n_this_object_header_files) | |
ea753d03 JK |
256 | { |
257 | static struct complaint msg = {"\ | |
258 | Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.", | |
259 | 0, 0}; | |
260 | complain (&msg, filenum, index, symnum); | |
261 | goto error_return; | |
262 | } | |
d07734e3 FF |
263 | |
264 | if (filenum == 0) | |
265 | { | |
a387370d JG |
266 | if (index < 0) |
267 | { | |
268 | /* Caller wants address of address of type. We think | |
269 | that negative (rs6k builtin) types will never appear as | |
270 | "lvalues", (nor should they), so we stuff the real type | |
271 | pointer into a temp, and return its address. If referenced, | |
272 | this will do the right thing. */ | |
273 | static struct type *temp_type; | |
274 | ||
275 | temp_type = rs6000_builtin_type(index); | |
276 | return &temp_type; | |
277 | } | |
278 | ||
d07734e3 FF |
279 | /* Type is defined outside of header files. |
280 | Find it in this object file's type vector. */ | |
281 | if (index >= type_vector_length) | |
282 | { | |
283 | old_len = type_vector_length; | |
284 | if (old_len == 0) | |
285 | { | |
286 | type_vector_length = INITIAL_TYPE_VECTOR_LENGTH; | |
287 | type_vector = (struct type **) | |
288 | malloc (type_vector_length * sizeof (struct type *)); | |
289 | } | |
290 | while (index >= type_vector_length) | |
291 | { | |
292 | type_vector_length *= 2; | |
293 | } | |
294 | type_vector = (struct type **) | |
295 | xrealloc ((char *) type_vector, | |
296 | (type_vector_length * sizeof (struct type *))); | |
297 | memset (&type_vector[old_len], 0, | |
298 | (type_vector_length - old_len) * sizeof (struct type *)); | |
25200748 JK |
299 | |
300 | if (os9k_stabs) | |
301 | /* Deal with OS9000 fundamental types. */ | |
302 | os9k_init_type_vector (type_vector); | |
d07734e3 FF |
303 | } |
304 | return (&type_vector[index]); | |
305 | } | |
306 | else | |
307 | { | |
308 | real_filenum = this_object_header_files[filenum]; | |
309 | ||
310 | if (real_filenum >= n_header_files) | |
311 | { | |
ea753d03 JK |
312 | struct type *temp_type; |
313 | struct type **temp_type_p; | |
314 | ||
315 | warning ("GDB internal error: bad real_filenum"); | |
316 | ||
317 | error_return: | |
318 | temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL); | |
319 | temp_type_p = (struct type **) xmalloc (sizeof (struct type *)); | |
320 | *temp_type_p = temp_type; | |
321 | return temp_type_p; | |
d07734e3 FF |
322 | } |
323 | ||
324 | f = &header_files[real_filenum]; | |
325 | ||
326 | f_orig_length = f->length; | |
327 | if (index >= f_orig_length) | |
328 | { | |
329 | while (index >= f->length) | |
330 | { | |
331 | f->length *= 2; | |
332 | } | |
333 | f->vector = (struct type **) | |
334 | xrealloc ((char *) f->vector, f->length * sizeof (struct type *)); | |
335 | memset (&f->vector[f_orig_length], 0, | |
336 | (f->length - f_orig_length) * sizeof (struct type *)); | |
337 | } | |
338 | return (&f->vector[index]); | |
339 | } | |
340 | } | |
341 | ||
342 | /* Make sure there is a type allocated for type numbers TYPENUMS | |
343 | and return the type object. | |
344 | This can create an empty (zeroed) type object. | |
345 | TYPENUMS may be (-1, -1) to return a new type object that is not | |
346 | put into the type vector, and so may not be referred to by number. */ | |
347 | ||
348 | static struct type * | |
349 | dbx_alloc_type (typenums, objfile) | |
350 | int typenums[2]; | |
351 | struct objfile *objfile; | |
352 | { | |
353 | register struct type **type_addr; | |
354 | ||
355 | if (typenums[0] == -1) | |
356 | { | |
357 | return (alloc_type (objfile)); | |
358 | } | |
359 | ||
360 | type_addr = dbx_lookup_type (typenums); | |
361 | ||
362 | /* If we are referring to a type not known at all yet, | |
363 | allocate an empty type for it. | |
364 | We will fill it in later if we find out how. */ | |
365 | if (*type_addr == 0) | |
366 | { | |
367 | *type_addr = alloc_type (objfile); | |
368 | } | |
369 | ||
370 | return (*type_addr); | |
371 | } | |
372 | ||
373 | /* for all the stabs in a given stab vector, build appropriate types | |
374 | and fix their symbols in given symbol vector. */ | |
375 | ||
376 | static void | |
377 | patch_block_stabs (symbols, stabs, objfile) | |
378 | struct pending *symbols; | |
379 | struct pending_stabs *stabs; | |
380 | struct objfile *objfile; | |
381 | { | |
382 | int ii; | |
383 | char *name; | |
384 | char *pp; | |
385 | struct symbol *sym; | |
386 | ||
387 | if (stabs) | |
388 | { | |
389 | ||
390 | /* for all the stab entries, find their corresponding symbols and | |
391 | patch their types! */ | |
392 | ||
393 | for (ii = 0; ii < stabs->count; ++ii) | |
394 | { | |
395 | name = stabs->stab[ii]; | |
396 | pp = (char*) strchr (name, ':'); | |
2fb58b98 KH |
397 | while (pp[1] == ':') |
398 | { | |
399 | pp += 2; | |
400 | pp = (char *)strchr(pp, ':'); | |
401 | } | |
d07734e3 FF |
402 | sym = find_symbol_in_list (symbols, name, pp-name); |
403 | if (!sym) | |
404 | { | |
553e1862 JK |
405 | /* FIXME-maybe: it would be nice if we noticed whether |
406 | the variable was defined *anywhere*, not just whether | |
407 | it is defined in this compilation unit. But neither | |
408 | xlc or GCC seem to need such a definition, and until | |
409 | we do psymtabs (so that the minimal symbols from all | |
410 | compilation units are available now), I'm not sure | |
411 | how to get the information. */ | |
acdec954 | 412 | |
0848ad1c JK |
413 | /* On xcoff, if a global is defined and never referenced, |
414 | ld will remove it from the executable. There is then | |
415 | a N_GSYM stab for it, but no regular (C_EXT) symbol. */ | |
416 | sym = (struct symbol *) | |
417 | obstack_alloc (&objfile->symbol_obstack, | |
418 | sizeof (struct symbol)); | |
419 | ||
420 | memset (sym, 0, sizeof (struct symbol)); | |
421 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
422 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
423 | SYMBOL_NAME (sym) = | |
424 | obstack_copy0 (&objfile->symbol_obstack, name, pp - name); | |
425 | pp += 2; | |
426 | if (*(pp-1) == 'F' || *(pp-1) == 'f') | |
427 | { | |
428 | /* I don't think the linker does this with functions, | |
429 | so as far as I know this is never executed. | |
430 | But it doesn't hurt to check. */ | |
431 | SYMBOL_TYPE (sym) = | |
432 | lookup_function_type (read_type (&pp, objfile)); | |
433 | } | |
434 | else | |
435 | { | |
436 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); | |
437 | } | |
438 | add_symbol_to_list (sym, &global_symbols); | |
d07734e3 FF |
439 | } |
440 | else | |
441 | { | |
442 | pp += 2; | |
443 | if (*(pp-1) == 'F' || *(pp-1) == 'f') | |
444 | { | |
445 | SYMBOL_TYPE (sym) = | |
446 | lookup_function_type (read_type (&pp, objfile)); | |
447 | } | |
448 | else | |
449 | { | |
450 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); | |
451 | } | |
452 | } | |
453 | } | |
454 | } | |
455 | } | |
456 | ||
457 | \f | |
458 | /* Read a number by which a type is referred to in dbx data, | |
459 | or perhaps read a pair (FILENUM, TYPENUM) in parentheses. | |
460 | Just a single number N is equivalent to (0,N). | |
461 | Return the two numbers by storing them in the vector TYPENUMS. | |
ea753d03 | 462 | TYPENUMS will then be used as an argument to dbx_lookup_type. |
d07734e3 | 463 | |
ea753d03 JK |
464 | Returns 0 for success, -1 for error. */ |
465 | ||
466 | static int | |
d07734e3 FF |
467 | read_type_number (pp, typenums) |
468 | register char **pp; | |
469 | register int *typenums; | |
470 | { | |
ea753d03 | 471 | int nbits; |
d07734e3 FF |
472 | if (**pp == '(') |
473 | { | |
474 | (*pp)++; | |
ea753d03 JK |
475 | typenums[0] = read_huge_number (pp, ',', &nbits); |
476 | if (nbits != 0) return -1; | |
477 | typenums[1] = read_huge_number (pp, ')', &nbits); | |
478 | if (nbits != 0) return -1; | |
d07734e3 FF |
479 | } |
480 | else | |
481 | { | |
482 | typenums[0] = 0; | |
ea753d03 JK |
483 | typenums[1] = read_huge_number (pp, 0, &nbits); |
484 | if (nbits != 0) return -1; | |
d07734e3 | 485 | } |
ea753d03 | 486 | return 0; |
d07734e3 FF |
487 | } |
488 | ||
489 | \f | |
490 | /* To handle GNU C++ typename abbreviation, we need to be able to | |
491 | fill in a type's name as soon as space for that type is allocated. | |
492 | `type_synonym_name' is the name of the type being allocated. | |
493 | It is cleared as soon as it is used (lest all allocated types | |
494 | get this name). */ | |
495 | ||
496 | static char *type_synonym_name; | |
497 | ||
28f851f9 | 498 | #if !defined (REG_STRUCT_HAS_ADDR) |
84ad95c1 | 499 | #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0 |
28f851f9 JK |
500 | #endif |
501 | ||
d07734e3 FF |
502 | /* ARGSUSED */ |
503 | struct symbol * | |
504 | define_symbol (valu, string, desc, type, objfile) | |
cef4c2e7 | 505 | CORE_ADDR valu; |
d07734e3 FF |
506 | char *string; |
507 | int desc; | |
508 | int type; | |
509 | struct objfile *objfile; | |
510 | { | |
511 | register struct symbol *sym; | |
512 | char *p = (char *) strchr (string, ':'); | |
513 | int deftype; | |
514 | int synonym = 0; | |
515 | register int i; | |
d07734e3 FF |
516 | |
517 | /* We would like to eliminate nameless symbols, but keep their types. | |
518 | E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer | |
94daba7f | 519 | to type 2, but, should not create a symbol to address that type. Since |
d07734e3 FF |
520 | the symbol will be nameless, there is no way any user can refer to it. */ |
521 | ||
522 | int nameless; | |
523 | ||
524 | /* Ignore syms with empty names. */ | |
525 | if (string[0] == 0) | |
526 | return 0; | |
527 | ||
528 | /* Ignore old-style symbols from cc -go */ | |
529 | if (p == 0) | |
530 | return 0; | |
531 | ||
2fb58b98 KH |
532 | while (p[1] == ':') |
533 | { | |
534 | p += 2; | |
535 | p = strchr(p, ':'); | |
536 | } | |
537 | ||
d07734e3 | 538 | /* If a nameless stab entry, all we need is the type, not the symbol. |
94daba7f FF |
539 | e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */ |
540 | nameless = (p == string || ((string[0] == ' ') && (string[1] == ':'))); | |
d07734e3 FF |
541 | |
542 | sym = (struct symbol *) | |
543 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); | |
c02a37ea | 544 | memset (sym, 0, sizeof (struct symbol)); |
d07734e3 | 545 | |
a66e8382 SG |
546 | switch (type & N_TYPE) |
547 | { | |
548 | case N_TEXT: | |
549 | SYMBOL_SECTION(sym) = SECT_OFF_TEXT; | |
550 | break; | |
551 | case N_DATA: | |
552 | SYMBOL_SECTION(sym) = SECT_OFF_DATA; | |
553 | break; | |
554 | case N_BSS: | |
555 | SYMBOL_SECTION(sym) = SECT_OFF_BSS; | |
556 | break; | |
557 | } | |
558 | ||
d07734e3 FF |
559 | if (processing_gcc_compilation) |
560 | { | |
561 | /* GCC 2.x puts the line number in desc. SunOS apparently puts in the | |
562 | number of bytes occupied by a type or object, which we ignore. */ | |
563 | SYMBOL_LINE(sym) = desc; | |
564 | } | |
565 | else | |
566 | { | |
567 | SYMBOL_LINE(sym) = 0; /* unknown */ | |
568 | } | |
569 | ||
570 | if (string[0] == CPLUS_MARKER) | |
571 | { | |
572 | /* Special GNU C++ names. */ | |
573 | switch (string[1]) | |
574 | { | |
575 | case 't': | |
576 | SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"), | |
577 | &objfile -> symbol_obstack); | |
578 | break; | |
579 | ||
580 | case 'v': /* $vtbl_ptr_type */ | |
581 | /* Was: SYMBOL_NAME (sym) = "vptr"; */ | |
582 | goto normal; | |
583 | ||
584 | case 'e': | |
585 | SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"), | |
586 | &objfile -> symbol_obstack); | |
587 | break; | |
588 | ||
589 | case '_': | |
590 | /* This was an anonymous type that was never fixed up. */ | |
591 | goto normal; | |
592 | ||
593 | default: | |
b646b438 | 594 | complain (&unrecognized_cplus_name_complaint, string); |
2a021f21 | 595 | goto normal; /* Do *something* with it */ |
d07734e3 FF |
596 | } |
597 | } | |
598 | else | |
599 | { | |
600 | normal: | |
2e4964ad | 601 | SYMBOL_LANGUAGE (sym) = current_subfile -> language; |
d07734e3 FF |
602 | SYMBOL_NAME (sym) = (char *) |
603 | obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1)); | |
ade40d31 | 604 | /* Open-coded memcpy--saves function call time. */ |
2e4964ad FF |
605 | /* FIXME: Does it really? Try replacing with simple strcpy and |
606 | try it on an executable with a large symbol table. */ | |
ade40d31 RP |
607 | /* FIXME: considering that gcc can open code memcpy anyway, I |
608 | doubt it. xoxorich. */ | |
d07734e3 FF |
609 | { |
610 | register char *p1 = string; | |
611 | register char *p2 = SYMBOL_NAME (sym); | |
612 | while (p1 != p) | |
613 | { | |
614 | *p2++ = *p1++; | |
615 | } | |
616 | *p2++ = '\0'; | |
617 | } | |
2e4964ad FF |
618 | |
619 | /* If this symbol is from a C++ compilation, then attempt to cache the | |
620 | demangled form for future reference. This is a typical time versus | |
621 | space tradeoff, that was decided in favor of time because it sped up | |
622 | C++ symbol lookups by a factor of about 20. */ | |
623 | ||
7532cf10 | 624 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); |
d07734e3 FF |
625 | } |
626 | p++; | |
9b280a7f | 627 | |
d07734e3 | 628 | /* Determine the type of name being defined. */ |
ea753d03 JK |
629 | #if 0 |
630 | /* Getting GDB to correctly skip the symbol on an undefined symbol | |
631 | descriptor and not ever dump core is a very dodgy proposition if | |
632 | we do things this way. I say the acorn RISC machine can just | |
633 | fix their compiler. */ | |
d07734e3 FF |
634 | /* The Acorn RISC machine's compiler can put out locals that don't |
635 | start with "234=" or "(3,4)=", so assume anything other than the | |
636 | deftypes we know how to handle is a local. */ | |
d07734e3 | 637 | if (!strchr ("cfFGpPrStTvVXCR", *p)) |
ea753d03 JK |
638 | #else |
639 | if (isdigit (*p) || *p == '(' || *p == '-') | |
640 | #endif | |
d07734e3 FF |
641 | deftype = 'l'; |
642 | else | |
643 | deftype = *p++; | |
644 | ||
59d69506 | 645 | switch (deftype) |
d07734e3 | 646 | { |
59d69506 JK |
647 | case 'c': |
648 | /* c is a special case, not followed by a type-number. | |
649 | SYMBOL:c=iVALUE for an integer constant symbol. | |
650 | SYMBOL:c=rVALUE for a floating constant symbol. | |
651 | SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. | |
652 | e.g. "b:c=e6,0" for "const b = blob1" | |
653 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
ea753d03 JK |
654 | if (*p != '=') |
655 | { | |
656 | SYMBOL_CLASS (sym) = LOC_CONST; | |
657 | SYMBOL_TYPE (sym) = error_type (&p); | |
658 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
659 | add_symbol_to_list (sym, &file_symbols); | |
660 | return sym; | |
661 | } | |
662 | ++p; | |
d07734e3 FF |
663 | switch (*p++) |
664 | { | |
665 | case 'r': | |
666 | { | |
667 | double d = atof (p); | |
668 | char *dbl_valu; | |
669 | ||
bf5c0d64 JK |
670 | /* FIXME-if-picky-about-floating-accuracy: Should be using |
671 | target arithmetic to get the value. real.c in GCC | |
672 | probably has the necessary code. */ | |
673 | ||
f52bde21 JK |
674 | /* FIXME: lookup_fundamental_type is a hack. We should be |
675 | creating a type especially for the type of float constants. | |
bf5c0d64 | 676 | Problem is, what type should it be? |
f52bde21 JK |
677 | |
678 | Also, what should the name of this type be? Should we | |
679 | be using 'S' constants (see stabs.texinfo) instead? */ | |
680 | ||
d07734e3 FF |
681 | SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, |
682 | FT_DBL_PREC_FLOAT); | |
683 | dbl_valu = (char *) | |
bf5c0d64 JK |
684 | obstack_alloc (&objfile -> symbol_obstack, |
685 | TYPE_LENGTH (SYMBOL_TYPE (sym))); | |
73edb321 | 686 | store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d); |
d07734e3 FF |
687 | SYMBOL_VALUE_BYTES (sym) = dbl_valu; |
688 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
689 | } | |
690 | break; | |
691 | case 'i': | |
692 | { | |
f52bde21 JK |
693 | /* Defining integer constants this way is kind of silly, |
694 | since 'e' constants allows the compiler to give not | |
695 | only the value, but the type as well. C has at least | |
696 | int, long, unsigned int, and long long as constant | |
697 | types; other languages probably should have at least | |
698 | unsigned as well as signed constants. */ | |
699 | ||
700 | /* We just need one int constant type for all objfiles. | |
701 | It doesn't depend on languages or anything (arguably its | |
702 | name should be a language-specific name for a type of | |
703 | that size, but I'm inclined to say that if the compiler | |
704 | wants a nice name for the type, it can use 'e'). */ | |
705 | static struct type *int_const_type; | |
706 | ||
707 | /* Yes, this is as long as a *host* int. That is because we | |
708 | use atoi. */ | |
709 | if (int_const_type == NULL) | |
710 | int_const_type = | |
711 | init_type (TYPE_CODE_INT, | |
712 | sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0, | |
713 | "integer constant", | |
714 | (struct objfile *)NULL); | |
715 | SYMBOL_TYPE (sym) = int_const_type; | |
d07734e3 FF |
716 | SYMBOL_VALUE (sym) = atoi (p); |
717 | SYMBOL_CLASS (sym) = LOC_CONST; | |
718 | } | |
719 | break; | |
720 | case 'e': | |
f52bde21 JK |
721 | /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value |
722 | can be represented as integral. | |
d07734e3 FF |
723 | e.g. "b:c=e6,0" for "const b = blob1" |
724 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
725 | { | |
d07734e3 | 726 | SYMBOL_CLASS (sym) = LOC_CONST; |
f52bde21 JK |
727 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
728 | ||
729 | if (*p != ',') | |
730 | { | |
731 | SYMBOL_TYPE (sym) = error_type (&p); | |
732 | break; | |
733 | } | |
734 | ++p; | |
735 | ||
736 | /* If the value is too big to fit in an int (perhaps because | |
737 | it is unsigned), or something like that, we silently get | |
738 | a bogus value. The type and everything else about it is | |
739 | correct. Ideally, we should be using whatever we have | |
740 | available for parsing unsigned and long long values, | |
741 | however. */ | |
742 | SYMBOL_VALUE (sym) = atoi (p); | |
d07734e3 FF |
743 | } |
744 | break; | |
745 | default: | |
ff580c7b | 746 | { |
ff580c7b | 747 | SYMBOL_CLASS (sym) = LOC_CONST; |
ff580c7b JK |
748 | SYMBOL_TYPE (sym) = error_type (&p); |
749 | } | |
d07734e3 FF |
750 | } |
751 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
752 | add_symbol_to_list (sym, &file_symbols); | |
753 | return sym; | |
d07734e3 | 754 | |
d07734e3 FF |
755 | case 'C': |
756 | /* The name of a caught exception. */ | |
59d69506 | 757 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
758 | SYMBOL_CLASS (sym) = LOC_LABEL; |
759 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
760 | SYMBOL_VALUE_ADDRESS (sym) = valu; | |
761 | add_symbol_to_list (sym, &local_symbols); | |
762 | break; | |
763 | ||
764 | case 'f': | |
765 | /* A static function definition. */ | |
59d69506 | 766 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
767 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
768 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
769 | add_symbol_to_list (sym, &file_symbols); | |
770 | /* fall into process_function_types. */ | |
771 | ||
772 | process_function_types: | |
773 | /* Function result types are described as the result type in stabs. | |
774 | We need to convert this to the function-returning-type-X type | |
775 | in GDB. E.g. "int" is converted to "function returning int". */ | |
776 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC) | |
777 | { | |
778 | #if 0 | |
779 | /* This code doesn't work -- it needs to realloc and can't. */ | |
780 | /* Attempt to set up to record a function prototype... */ | |
dac9734e | 781 | struct type *new = alloc_type (objfile); |
d07734e3 FF |
782 | |
783 | /* Generate a template for the type of this function. The | |
784 | types of the arguments will be added as we read the symbol | |
785 | table. */ | |
786 | *new = *lookup_function_type (SYMBOL_TYPE(sym)); | |
787 | SYMBOL_TYPE(sym) = new; | |
788 | TYPE_OBJFILE (new) = objfile; | |
789 | in_function_type = new; | |
790 | #else | |
791 | SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym)); | |
792 | #endif | |
793 | } | |
794 | /* fall into process_prototype_types */ | |
795 | ||
796 | process_prototype_types: | |
797 | /* Sun acc puts declared types of arguments here. We don't care | |
798 | about their actual types (FIXME -- we should remember the whole | |
799 | function prototype), but the list may define some new types | |
800 | that we have to remember, so we must scan it now. */ | |
801 | while (*p == ';') { | |
802 | p++; | |
803 | read_type (&p, objfile); | |
804 | } | |
805 | break; | |
806 | ||
807 | case 'F': | |
808 | /* A global function definition. */ | |
59d69506 | 809 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
810 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
811 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
812 | add_symbol_to_list (sym, &global_symbols); | |
813 | goto process_function_types; | |
814 | ||
815 | case 'G': | |
816 | /* For a class G (global) symbol, it appears that the | |
817 | value is not correct. It is necessary to search for the | |
818 | corresponding linker definition to find the value. | |
819 | These definitions appear at the end of the namelist. */ | |
59d69506 | 820 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
821 | i = hashname (SYMBOL_NAME (sym)); |
822 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; | |
823 | global_sym_chain[i] = sym; | |
824 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
825 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
826 | add_symbol_to_list (sym, &global_symbols); | |
827 | break; | |
828 | ||
829 | /* This case is faked by a conditional above, | |
830 | when there is no code letter in the dbx data. | |
831 | Dbx data never actually contains 'l'. */ | |
d9389f37 | 832 | case 's': |
d07734e3 | 833 | case 'l': |
59d69506 | 834 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
835 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
836 | SYMBOL_VALUE (sym) = valu; | |
837 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
838 | add_symbol_to_list (sym, &local_symbols); | |
839 | break; | |
840 | ||
841 | case 'p': | |
59d69506 JK |
842 | if (*p == 'F') |
843 | /* pF is a two-letter code that means a function parameter in Fortran. | |
844 | The type-number specifies the type of the return value. | |
845 | Translate it into a pointer-to-function type. */ | |
846 | { | |
847 | p++; | |
848 | SYMBOL_TYPE (sym) | |
849 | = lookup_pointer_type | |
850 | (lookup_function_type (read_type (&p, objfile))); | |
851 | } | |
852 | else | |
853 | SYMBOL_TYPE (sym) = read_type (&p, objfile); | |
854 | ||
d07734e3 FF |
855 | /* Normally this is a parameter, a LOC_ARG. On the i960, it |
856 | can also be a LOC_LOCAL_ARG depending on symbol type. */ | |
857 | #ifndef DBX_PARM_SYMBOL_CLASS | |
858 | #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG | |
859 | #endif | |
59d69506 | 860 | |
d07734e3 FF |
861 | SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type); |
862 | SYMBOL_VALUE (sym) = valu; | |
863 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
864 | #if 0 | |
865 | /* This doesn't work yet. */ | |
866 | add_param_to_type (&in_function_type, sym); | |
867 | #endif | |
868 | add_symbol_to_list (sym, &local_symbols); | |
869 | ||
dcb38973 JK |
870 | #if TARGET_BYTE_ORDER == LITTLE_ENDIAN |
871 | /* On little-endian machines, this crud is never necessary, and, | |
872 | if the extra bytes contain garbage, is harmful. */ | |
873 | break; | |
874 | #else /* Big endian. */ | |
d07734e3 FF |
875 | /* If it's gcc-compiled, if it says `short', believe it. */ |
876 | if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION) | |
877 | break; | |
878 | ||
f52bde21 JK |
879 | #if !BELIEVE_PCC_PROMOTION |
880 | { | |
881 | /* This is the signed type which arguments get promoted to. */ | |
882 | static struct type *pcc_promotion_type; | |
883 | /* This is the unsigned type which arguments get promoted to. */ | |
884 | static struct type *pcc_unsigned_promotion_type; | |
885 | ||
886 | /* Call it "int" because this is mainly C lossage. */ | |
887 | if (pcc_promotion_type == NULL) | |
888 | pcc_promotion_type = | |
889 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
890 | 0, "int", NULL); | |
891 | ||
892 | if (pcc_unsigned_promotion_type == NULL) | |
893 | pcc_unsigned_promotion_type = | |
894 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
895 | TYPE_FLAG_UNSIGNED, "unsigned int", NULL); | |
d07734e3 | 896 | |
f52bde21 JK |
897 | #if defined(BELIEVE_PCC_PROMOTION_TYPE) |
898 | /* This macro is defined on machines (e.g. sparc) where | |
899 | we should believe the type of a PCC 'short' argument, | |
900 | but shouldn't believe the address (the address is | |
dcb38973 | 901 | the address of the corresponding int). |
f52bde21 JK |
902 | |
903 | My guess is that this correction, as opposed to changing | |
904 | the parameter to an 'int' (as done below, for PCC | |
905 | on most machines), is the right thing to do | |
906 | on all machines, but I don't want to risk breaking | |
907 | something that already works. On most PCC machines, | |
908 | the sparc problem doesn't come up because the calling | |
909 | function has to zero the top bytes (not knowing whether | |
910 | the called function wants an int or a short), so there | |
dcb38973 | 911 | is little practical difference between an int and a short |
f52bde21 JK |
912 | (except perhaps what happens when the GDB user types |
913 | "print short_arg = 0x10000;"). | |
914 | ||
915 | Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler | |
916 | actually produces the correct address (we don't need to fix it | |
917 | up). I made this code adapt so that it will offset the symbol | |
918 | if it was pointing at an int-aligned location and not | |
919 | otherwise. This way you can use the same gdb for 4.0.x and | |
920 | 4.1 systems. | |
921 | ||
922 | If the parameter is shorter than an int, and is integral | |
923 | (e.g. char, short, or unsigned equivalent), and is claimed to | |
924 | be passed on an integer boundary, don't believe it! Offset the | |
925 | parameter's address to the tail-end of that integer. */ | |
926 | ||
927 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) | |
928 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT | |
929 | && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type)) | |
930 | { | |
931 | SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type) | |
932 | - TYPE_LENGTH (SYMBOL_TYPE (sym)); | |
933 | } | |
934 | break; | |
935 | ||
d07734e3 FF |
936 | #else /* no BELIEVE_PCC_PROMOTION_TYPE. */ |
937 | ||
f52bde21 JK |
938 | /* If PCC says a parameter is a short or a char, |
939 | it is really an int. */ | |
940 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) | |
941 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT) | |
942 | { | |
943 | SYMBOL_TYPE (sym) = | |
944 | TYPE_UNSIGNED (SYMBOL_TYPE (sym)) | |
945 | ? pcc_unsigned_promotion_type | |
946 | : pcc_promotion_type; | |
947 | } | |
948 | break; | |
d07734e3 FF |
949 | |
950 | #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */ | |
f52bde21 JK |
951 | } |
952 | #endif /* !BELIEVE_PCC_PROMOTION. */ | |
dcb38973 | 953 | #endif /* Big endian. */ |
d07734e3 FF |
954 | |
955 | case 'P': | |
956 | /* acc seems to use P to delare the prototypes of functions that | |
957 | are referenced by this file. gdb is not prepared to deal | |
958 | with this extra information. FIXME, it ought to. */ | |
959 | if (type == N_FUN) | |
59d69506 JK |
960 | { |
961 | read_type (&p, objfile); | |
962 | goto process_prototype_types; | |
963 | } | |
f52bde21 | 964 | /*FALLTHROUGH*/ |
d07734e3 | 965 | |
f52bde21 | 966 | case 'R': |
d07734e3 | 967 | /* Parameter which is in a register. */ |
59d69506 | 968 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
969 | SYMBOL_CLASS (sym) = LOC_REGPARM; |
970 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); | |
971 | if (SYMBOL_VALUE (sym) >= NUM_REGS) | |
972 | { | |
2e4964ad | 973 | complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym)); |
d07734e3 FF |
974 | SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ |
975 | } | |
976 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
977 | add_symbol_to_list (sym, &local_symbols); | |
978 | break; | |
979 | ||
d07734e3 FF |
980 | case 'r': |
981 | /* Register variable (either global or local). */ | |
59d69506 | 982 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
983 | SYMBOL_CLASS (sym) = LOC_REGISTER; |
984 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); | |
985 | if (SYMBOL_VALUE (sym) >= NUM_REGS) | |
986 | { | |
2e4964ad | 987 | complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym)); |
d07734e3 FF |
988 | SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ |
989 | } | |
990 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
4bfe9e81 | 991 | if (within_function) |
5afa2040 JK |
992 | { |
993 | /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same | |
994 | name to represent an argument passed in a register. | |
995 | GCC uses 'P' for the same case. So if we find such a symbol pair | |
649694ea JK |
996 | we combine it into one 'P' symbol. For Sun cc we need to do this |
997 | regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out | |
998 | the 'p' symbol even if it never saves the argument onto the stack. | |
28f851f9 | 999 | |
649694ea | 1000 | On most machines, we want to preserve both symbols, so that |
28f851f9 | 1001 | we can still get information about what is going on with the |
4bfe9e81 JK |
1002 | stack (VAX for computing args_printed, using stack slots instead |
1003 | of saved registers in backtraces, etc.). | |
1004 | ||
5afa2040 | 1005 | Note that this code illegally combines |
28f851f9 | 1006 | main(argc) struct foo argc; { register struct foo argc; } |
5afa2040 JK |
1007 | but this case is considered pathological and causes a warning |
1008 | from a decent compiler. */ | |
28f851f9 | 1009 | |
5afa2040 | 1010 | if (local_symbols |
4bfe9e81 | 1011 | && local_symbols->nsyms > 0 |
649694ea | 1012 | #ifndef USE_REGISTER_NOT_ARG |
84ad95c1 JL |
1013 | && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, |
1014 | SYMBOL_TYPE (sym)) | |
4bfe9e81 | 1015 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT |
649694ea JK |
1016 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) |
1017 | #endif | |
1018 | ) | |
5afa2040 JK |
1019 | { |
1020 | struct symbol *prev_sym; | |
1021 | prev_sym = local_symbols->symbol[local_symbols->nsyms - 1]; | |
649694ea JK |
1022 | if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG |
1023 | || SYMBOL_CLASS (prev_sym) == LOC_ARG) | |
5afa2040 JK |
1024 | && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym))) |
1025 | { | |
1026 | SYMBOL_CLASS (prev_sym) = LOC_REGPARM; | |
fc81adb8 JK |
1027 | /* Use the type from the LOC_REGISTER; that is the type |
1028 | that is actually in that register. */ | |
1029 | SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym); | |
5afa2040 JK |
1030 | SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym); |
1031 | sym = prev_sym; | |
1032 | break; | |
1033 | } | |
1034 | } | |
1035 | add_symbol_to_list (sym, &local_symbols); | |
1036 | } | |
d07734e3 FF |
1037 | else |
1038 | add_symbol_to_list (sym, &file_symbols); | |
1039 | break; | |
1040 | ||
1041 | case 'S': | |
1042 | /* Static symbol at top level of file */ | |
59d69506 | 1043 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
1044 | SYMBOL_CLASS (sym) = LOC_STATIC; |
1045 | SYMBOL_VALUE_ADDRESS (sym) = valu; | |
1046 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1047 | add_symbol_to_list (sym, &file_symbols); | |
1048 | break; | |
1049 | ||
1050 | case 't': | |
59d69506 JK |
1051 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
1052 | ||
d07734e3 FF |
1053 | /* For a nameless type, we don't want a create a symbol, thus we |
1054 | did not use `sym'. Return without further processing. */ | |
1055 | if (nameless) return NULL; | |
1056 | ||
1057 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
1058 | SYMBOL_VALUE (sym) = valu; | |
1059 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1060 | /* C++ vagaries: we may have a type which is derived from | |
59d69506 JK |
1061 | a base type which did not have its name defined when the |
1062 | derived class was output. We fill in the derived class's | |
1063 | base part member's name here in that case. */ | |
d07734e3 | 1064 | if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL) |
59d69506 JK |
1065 | if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT |
1066 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) | |
1067 | && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) | |
1068 | { | |
1069 | int j; | |
1070 | for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--) | |
1071 | if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0) | |
1072 | TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) = | |
1073 | type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j)); | |
1074 | } | |
d07734e3 | 1075 | |
f52bde21 | 1076 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL) |
59d69506 | 1077 | { |
5af4f5f6 JK |
1078 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR |
1079 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC) | |
59d69506 | 1080 | { |
5af4f5f6 JK |
1081 | /* If we are giving a name to a type such as "pointer to |
1082 | foo" or "function returning foo", we better not set | |
1083 | the TYPE_NAME. If the program contains "typedef char | |
1084 | *caddr_t;", we don't want all variables of type char | |
1085 | * to print as caddr_t. This is not just a | |
1086 | consequence of GDB's type management; PCC and GCC (at | |
1087 | least through version 2.4) both output variables of | |
1088 | either type char * or caddr_t with the type number | |
1089 | defined in the 't' symbol for caddr_t. If a future | |
1090 | compiler cleans this up it GDB is not ready for it | |
1091 | yet, but if it becomes ready we somehow need to | |
1092 | disable this check (without breaking the PCC/GCC2.4 | |
1093 | case). | |
59d69506 JK |
1094 | |
1095 | Sigh. | |
1096 | ||
1097 | Fortunately, this check seems not to be necessary | |
5af4f5f6 | 1098 | for anything except pointers or functions. */ |
59d69506 JK |
1099 | } |
1100 | else | |
1101 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym); | |
1102 | } | |
f52bde21 | 1103 | |
d07734e3 FF |
1104 | add_symbol_to_list (sym, &file_symbols); |
1105 | break; | |
1106 | ||
1107 | case 'T': | |
59d69506 JK |
1108 | /* Struct, union, or enum tag. For GNU C++, this can be be followed |
1109 | by 't' which means we are typedef'ing it as well. */ | |
1110 | synonym = *p == 't'; | |
1111 | ||
1112 | if (synonym) | |
1113 | { | |
1114 | p++; | |
91f87016 JL |
1115 | type_synonym_name = obsavestring (SYMBOL_NAME (sym), |
1116 | strlen (SYMBOL_NAME (sym)), | |
1117 | &objfile -> symbol_obstack); | |
1118 | } | |
1119 | /* The semantics of C++ state that "struct foo { ... }" also defines | |
1120 | a typedef for "foo". Unfortunately, cfront never makes the typedef | |
1121 | when translating C++ into C. We make the typedef here so that | |
1122 | "ptype foo" works as expected for cfront translated code. */ | |
1123 | else if (current_subfile->language == language_cplus) | |
1124 | { | |
1125 | synonym = 1; | |
59d69506 JK |
1126 | type_synonym_name = obsavestring (SYMBOL_NAME (sym), |
1127 | strlen (SYMBOL_NAME (sym)), | |
1128 | &objfile -> symbol_obstack); | |
1129 | } | |
1130 | ||
1131 | SYMBOL_TYPE (sym) = read_type (&p, objfile); | |
1132 | ||
d07734e3 FF |
1133 | /* For a nameless type, we don't want a create a symbol, thus we |
1134 | did not use `sym'. Return without further processing. */ | |
1135 | if (nameless) return NULL; | |
1136 | ||
1137 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
1138 | SYMBOL_VALUE (sym) = valu; | |
1139 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
b2bebdb0 JK |
1140 | if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0) |
1141 | TYPE_TAG_NAME (SYMBOL_TYPE (sym)) | |
1142 | = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym)); | |
d07734e3 FF |
1143 | add_symbol_to_list (sym, &file_symbols); |
1144 | ||
1145 | if (synonym) | |
1146 | { | |
2e4964ad | 1147 | /* Clone the sym and then modify it. */ |
d07734e3 | 1148 | register struct symbol *typedef_sym = (struct symbol *) |
dac9734e | 1149 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
2e4964ad | 1150 | *typedef_sym = *sym; |
d07734e3 FF |
1151 | SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF; |
1152 | SYMBOL_VALUE (typedef_sym) = valu; | |
1153 | SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE; | |
b2bebdb0 JK |
1154 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
1155 | TYPE_NAME (SYMBOL_TYPE (sym)) | |
1156 | = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym)); | |
d07734e3 FF |
1157 | add_symbol_to_list (typedef_sym, &file_symbols); |
1158 | } | |
1159 | break; | |
1160 | ||
1161 | case 'V': | |
1162 | /* Static symbol of local scope */ | |
59d69506 | 1163 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
1164 | SYMBOL_CLASS (sym) = LOC_STATIC; |
1165 | SYMBOL_VALUE_ADDRESS (sym) = valu; | |
1166 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
25200748 JK |
1167 | if (os9k_stabs) |
1168 | add_symbol_to_list (sym, &global_symbols); | |
1169 | else | |
1170 | add_symbol_to_list (sym, &local_symbols); | |
d07734e3 FF |
1171 | break; |
1172 | ||
1173 | case 'v': | |
1174 | /* Reference parameter */ | |
59d69506 | 1175 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
1176 | SYMBOL_CLASS (sym) = LOC_REF_ARG; |
1177 | SYMBOL_VALUE (sym) = valu; | |
1178 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1179 | add_symbol_to_list (sym, &local_symbols); | |
1180 | break; | |
1181 | ||
1182 | case 'X': | |
1183 | /* This is used by Sun FORTRAN for "function result value". | |
1184 | Sun claims ("dbx and dbxtool interfaces", 2nd ed) | |
1185 | that Pascal uses it too, but when I tried it Pascal used | |
1186 | "x:3" (local symbol) instead. */ | |
59d69506 | 1187 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
d07734e3 FF |
1188 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
1189 | SYMBOL_VALUE (sym) = valu; | |
1190 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1191 | add_symbol_to_list (sym, &local_symbols); | |
1192 | break; | |
1193 | ||
1194 | default: | |
59d69506 | 1195 | SYMBOL_TYPE (sym) = error_type (&p); |
ea753d03 JK |
1196 | SYMBOL_CLASS (sym) = LOC_CONST; |
1197 | SYMBOL_VALUE (sym) = 0; | |
ea753d03 JK |
1198 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
1199 | add_symbol_to_list (sym, &file_symbols); | |
1200 | break; | |
d07734e3 | 1201 | } |
5afa2040 JK |
1202 | |
1203 | /* When passing structures to a function, some systems sometimes pass | |
1204 | the address in a register, not the structure itself. | |
1205 | ||
1206 | If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM | |
1207 | to LOC_REGPARM_ADDR for structures and unions. */ | |
1208 | ||
5afa2040 | 1209 | if (SYMBOL_CLASS (sym) == LOC_REGPARM |
84ad95c1 JL |
1210 | && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, |
1211 | SYMBOL_TYPE (sym)) | |
28f851f9 | 1212 | && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT) |
5afa2040 JK |
1213 | || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))) |
1214 | SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; | |
1215 | ||
f2613710 JK |
1216 | /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and |
1217 | subsequent arguments on the sparc, for example). */ | |
1218 | if (SYMBOL_CLASS (sym) == LOC_ARG | |
84ad95c1 JL |
1219 | && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, |
1220 | SYMBOL_TYPE (sym)) | |
f2613710 JK |
1221 | && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT) |
1222 | || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))) | |
1223 | SYMBOL_CLASS (sym) = LOC_REF_ARG; | |
1224 | ||
d07734e3 FF |
1225 | return sym; |
1226 | } | |
1227 | ||
1228 | \f | |
1229 | /* Skip rest of this symbol and return an error type. | |
1230 | ||
1231 | General notes on error recovery: error_type always skips to the | |
1232 | end of the symbol (modulo cretinous dbx symbol name continuation). | |
1233 | Thus code like this: | |
1234 | ||
1235 | if (*(*pp)++ != ';') | |
1236 | return error_type (pp); | |
1237 | ||
1238 | is wrong because if *pp starts out pointing at '\0' (typically as the | |
1239 | result of an earlier error), it will be incremented to point to the | |
1240 | start of the next symbol, which might produce strange results, at least | |
1241 | if you run off the end of the string table. Instead use | |
1242 | ||
1243 | if (**pp != ';') | |
1244 | return error_type (pp); | |
1245 | ++*pp; | |
1246 | ||
1247 | or | |
1248 | ||
1249 | if (**pp != ';') | |
1250 | foo = error_type (pp); | |
1251 | else | |
1252 | ++*pp; | |
1253 | ||
1254 | And in case it isn't obvious, the point of all this hair is so the compiler | |
1255 | can define new types and new syntaxes, and old versions of the | |
1256 | debugger will be able to read the new symbol tables. */ | |
1257 | ||
ea753d03 | 1258 | static struct type * |
d07734e3 FF |
1259 | error_type (pp) |
1260 | char **pp; | |
1261 | { | |
51b80b00 | 1262 | complain (&error_type_complaint); |
d07734e3 FF |
1263 | while (1) |
1264 | { | |
1265 | /* Skip to end of symbol. */ | |
1266 | while (**pp != '\0') | |
e7177cc2 FF |
1267 | { |
1268 | (*pp)++; | |
1269 | } | |
d07734e3 FF |
1270 | |
1271 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
91a0575c | 1272 | if ((*pp)[-1] == '\\' || (*pp)[-1] == '?') |
e7177cc2 FF |
1273 | { |
1274 | *pp = next_symbol_text (); | |
1275 | } | |
d07734e3 | 1276 | else |
e7177cc2 FF |
1277 | { |
1278 | break; | |
1279 | } | |
d07734e3 | 1280 | } |
e7177cc2 | 1281 | return (builtin_type_error); |
d07734e3 FF |
1282 | } |
1283 | ||
1284 | \f | |
59d69506 JK |
1285 | /* Read type information or a type definition; return the type. Even |
1286 | though this routine accepts either type information or a type | |
1287 | definition, the distinction is relevant--some parts of stabsread.c | |
1288 | assume that type information starts with a digit, '-', or '(' in | |
1289 | deciding whether to call read_type. */ | |
d07734e3 FF |
1290 | |
1291 | struct type * | |
1292 | read_type (pp, objfile) | |
1293 | register char **pp; | |
1294 | struct objfile *objfile; | |
1295 | { | |
1296 | register struct type *type = 0; | |
1297 | struct type *type1; | |
1298 | int typenums[2]; | |
1299 | int xtypenums[2]; | |
e7177cc2 | 1300 | char type_descriptor; |
d07734e3 | 1301 | |
5ed0ccaf JK |
1302 | /* Size in bits of type if specified by a type attribute, or -1 if |
1303 | there is no size attribute. */ | |
1304 | int type_size = -1; | |
1305 | ||
cba00921 PB |
1306 | /* Used to distinguish string and bitstring from char-array and set. */ |
1307 | int is_string = 0; | |
1308 | ||
d07734e3 FF |
1309 | /* Read type number if present. The type number may be omitted. |
1310 | for instance in a two-dimensional array declared with type | |
1311 | "ar1;1;10;ar1;1;10;4". */ | |
1312 | if ((**pp >= '0' && **pp <= '9') | |
4fc9d7c7 JK |
1313 | || **pp == '(' |
1314 | || **pp == '-') | |
d07734e3 | 1315 | { |
ea753d03 JK |
1316 | if (read_type_number (pp, typenums) != 0) |
1317 | return error_type (pp); | |
d07734e3 FF |
1318 | |
1319 | /* Type is not being defined here. Either it already exists, | |
1320 | or this is a forward reference to it. dbx_alloc_type handles | |
1321 | both cases. */ | |
1322 | if (**pp != '=') | |
1323 | return dbx_alloc_type (typenums, objfile); | |
1324 | ||
1325 | /* Type is being defined here. */ | |
36bcda79 JK |
1326 | /* Skip the '='. */ |
1327 | ++(*pp); | |
d07734e3 | 1328 | |
36bcda79 JK |
1329 | while (**pp == '@') |
1330 | { | |
1331 | char *p = *pp + 1; | |
1332 | /* It might be a type attribute or a member type. */ | |
1333 | if (isdigit (*p) || *p == '(' || *p == '-') | |
1334 | /* Member type. */ | |
1335 | break; | |
1336 | else | |
1337 | { | |
5ed0ccaf JK |
1338 | /* Type attributes. */ |
1339 | char *attr = p; | |
1340 | ||
1341 | /* Skip to the semicolon. */ | |
36bcda79 JK |
1342 | while (*p != ';' && *p != '\0') |
1343 | ++p; | |
1344 | *pp = p; | |
1345 | if (*p == '\0') | |
1346 | return error_type (pp); | |
1347 | else | |
1348 | /* Skip the semicolon. */ | |
1349 | ++*pp; | |
5ed0ccaf JK |
1350 | |
1351 | switch (*attr) | |
1352 | { | |
1353 | case 's': | |
1354 | type_size = atoi (attr + 1); | |
1355 | if (type_size <= 0) | |
1356 | type_size = -1; | |
1357 | break; | |
7677d4fd | 1358 | |
cba00921 PB |
1359 | case 'S': |
1360 | is_string = 1; | |
7677d4fd JK |
1361 | break; |
1362 | ||
5ed0ccaf JK |
1363 | default: |
1364 | /* Ignore unrecognized type attributes, so future compilers | |
1365 | can invent new ones. */ | |
1366 | break; | |
1367 | } | |
36bcda79 JK |
1368 | } |
1369 | } | |
1370 | /* Skip the type descriptor, we get it below with (*pp)[-1]. */ | |
1371 | ++(*pp); | |
d07734e3 FF |
1372 | } |
1373 | else | |
1374 | { | |
1375 | /* 'typenums=' not present, type is anonymous. Read and return | |
1376 | the definition, but don't put it in the type vector. */ | |
1377 | typenums[0] = typenums[1] = -1; | |
e7177cc2 | 1378 | (*pp)++; |
d07734e3 FF |
1379 | } |
1380 | ||
e7177cc2 FF |
1381 | type_descriptor = (*pp)[-1]; |
1382 | switch (type_descriptor) | |
d07734e3 FF |
1383 | { |
1384 | case 'x': | |
1385 | { | |
1386 | enum type_code code; | |
1387 | ||
1388 | /* Used to index through file_symbols. */ | |
1389 | struct pending *ppt; | |
1390 | int i; | |
1391 | ||
1392 | /* Name including "struct", etc. */ | |
1393 | char *type_name; | |
1394 | ||
d07734e3 | 1395 | { |
279a3cfd | 1396 | char *from, *to, *p, *q1, *q2; |
d07734e3 FF |
1397 | |
1398 | /* Set the type code according to the following letter. */ | |
1399 | switch ((*pp)[0]) | |
1400 | { | |
1401 | case 's': | |
1402 | code = TYPE_CODE_STRUCT; | |
d07734e3 FF |
1403 | break; |
1404 | case 'u': | |
1405 | code = TYPE_CODE_UNION; | |
d07734e3 FF |
1406 | break; |
1407 | case 'e': | |
1408 | code = TYPE_CODE_ENUM; | |
d07734e3 FF |
1409 | break; |
1410 | default: | |
79cf7e1f JK |
1411 | { |
1412 | /* Complain and keep going, so compilers can invent new | |
1413 | cross-reference types. */ | |
1414 | static struct complaint msg = | |
1415 | {"Unrecognized cross-reference type `%c'", 0, 0}; | |
1416 | complain (&msg, (*pp)[0]); | |
1417 | code = TYPE_CODE_STRUCT; | |
1418 | break; | |
1419 | } | |
d07734e3 | 1420 | } |
2fb58b98 | 1421 | |
279a3cfd | 1422 | q1 = strchr(*pp, '<'); |
2fb58b98 | 1423 | p = strchr(*pp, ':'); |
79cf7e1f JK |
1424 | if (p == NULL) |
1425 | return error_type (pp); | |
279a3cfd | 1426 | while (q1 && p > q1 && p[1] == ':') |
2fb58b98 | 1427 | { |
279a3cfd KH |
1428 | q2 = strchr(q1, '>'); |
1429 | if (!q2 || q2 < p) | |
1430 | break; | |
2fb58b98 KH |
1431 | p += 2; |
1432 | p = strchr(p, ':'); | |
79cf7e1f JK |
1433 | if (p == NULL) |
1434 | return error_type (pp); | |
2fb58b98 KH |
1435 | } |
1436 | to = type_name = | |
1437 | (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1); | |
d07734e3 | 1438 | |
d07734e3 FF |
1439 | /* Copy the name. */ |
1440 | from = *pp + 1; | |
2fb58b98 KH |
1441 | while (from < p) |
1442 | *to++ = *from++; | |
1443 | *to = '\0'; | |
d07734e3 | 1444 | |
79cf7e1f JK |
1445 | /* Set the pointer ahead of the name which we just read, and |
1446 | the colon. */ | |
1447 | *pp = from + 1; | |
d07734e3 FF |
1448 | } |
1449 | ||
dda398c3 JK |
1450 | /* Now check to see whether the type has already been |
1451 | declared. This was written for arrays of cross-referenced | |
1452 | types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty | |
1453 | sure it is not necessary anymore. But it might be a good | |
1454 | idea, to save a little memory. */ | |
1455 | ||
d07734e3 FF |
1456 | for (ppt = file_symbols; ppt; ppt = ppt->next) |
1457 | for (i = 0; i < ppt->nsyms; i++) | |
1458 | { | |
1459 | struct symbol *sym = ppt->symbol[i]; | |
1460 | ||
1461 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF | |
1462 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE | |
1463 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == code) | |
b2bebdb0 | 1464 | && STREQ (SYMBOL_NAME (sym), type_name)) |
d07734e3 FF |
1465 | { |
1466 | obstack_free (&objfile -> type_obstack, type_name); | |
1467 | type = SYMBOL_TYPE (sym); | |
1468 | return type; | |
1469 | } | |
1470 | } | |
dda398c3 | 1471 | |
d07734e3 FF |
1472 | /* Didn't find the type to which this refers, so we must |
1473 | be dealing with a forward reference. Allocate a type | |
1474 | structure for it, and keep track of it so we can | |
1475 | fill in the rest of the fields when we get the full | |
1476 | type. */ | |
1477 | type = dbx_alloc_type (typenums, objfile); | |
1478 | TYPE_CODE (type) = code; | |
b2bebdb0 | 1479 | TYPE_TAG_NAME (type) = type_name; |
d07734e3 FF |
1480 | INIT_CPLUS_SPECIFIC(type); |
1481 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
1482 | ||
1483 | add_undefined_type (type); | |
1484 | return type; | |
1485 | } | |
1486 | ||
1487 | case '-': /* RS/6000 built-in type */ | |
d07734e3 FF |
1488 | case '0': |
1489 | case '1': | |
1490 | case '2': | |
1491 | case '3': | |
1492 | case '4': | |
1493 | case '5': | |
1494 | case '6': | |
1495 | case '7': | |
1496 | case '8': | |
1497 | case '9': | |
1498 | case '(': | |
f52bde21 | 1499 | |
4b404661 JK |
1500 | { |
1501 | char *pp_saved; | |
5ed0ccaf | 1502 | |
4b404661 JK |
1503 | (*pp)--; |
1504 | pp_saved = *pp; | |
5ed0ccaf | 1505 | |
4b404661 JK |
1506 | /* Peek ahead at the number to detect void. */ |
1507 | if (read_type_number (pp, xtypenums) != 0) | |
1508 | return error_type (pp); | |
5ed0ccaf | 1509 | |
4b404661 JK |
1510 | if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1]) |
1511 | /* It's being defined as itself. That means it is "void". */ | |
2f3b7d8e | 1512 | type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
4b404661 JK |
1513 | else |
1514 | { | |
1515 | struct type *xtype; | |
1516 | ||
1517 | /* Go back to the number and have read_type get it. This means | |
1518 | that we can deal with something like t(1,2)=(3,4)=... which | |
1519 | the Lucid compiler uses. */ | |
1520 | *pp = pp_saved; | |
1521 | xtype = read_type (pp, objfile); | |
1522 | ||
1523 | /* The type is being defined to another type. So we copy the type. | |
1524 | This loses if we copy a C++ class and so we lose track of how | |
1525 | the names are mangled (but g++ doesn't output stabs like this | |
1526 | now anyway). */ | |
1527 | ||
1528 | type = alloc_type (objfile); | |
1529 | memcpy (type, xtype, sizeof (struct type)); | |
1530 | ||
1531 | /* The idea behind clearing the names is that the only purpose | |
1532 | for defining a type to another type is so that the name of | |
1533 | one can be different. So we probably don't need to worry much | |
1534 | about the case where the compiler doesn't give a name to the | |
1535 | new type. */ | |
1536 | TYPE_NAME (type) = NULL; | |
1537 | TYPE_TAG_NAME (type) = NULL; | |
1538 | } | |
1539 | if (typenums[0] != -1) | |
1540 | *dbx_lookup_type (typenums) = type; | |
1541 | break; | |
1542 | } | |
d07734e3 FF |
1543 | |
1544 | /* In the following types, we must be sure to overwrite any existing | |
1545 | type that the typenums refer to, rather than allocating a new one | |
1546 | and making the typenums point to the new one. This is because there | |
1547 | may already be pointers to the existing type (if it had been | |
1548 | forward-referenced), and we must change it to a pointer, function, | |
1549 | reference, or whatever, *in-place*. */ | |
1550 | ||
1551 | case '*': | |
1552 | type1 = read_type (pp, objfile); | |
1553 | type = make_pointer_type (type1, dbx_lookup_type (typenums)); | |
1554 | break; | |
1555 | ||
1556 | case '&': /* Reference to another type */ | |
1557 | type1 = read_type (pp, objfile); | |
1558 | type = make_reference_type (type1, dbx_lookup_type (typenums)); | |
1559 | break; | |
1560 | ||
1561 | case 'f': /* Function returning another type */ | |
25200748 JK |
1562 | if (os9k_stabs && **pp == '(') |
1563 | { | |
d5336fc5 | 1564 | /* Function prototype; parse it. |
25200748 JK |
1565 | We must conditionalize this on os9k_stabs because otherwise |
1566 | it could be confused with a Sun-style (1,3) typenumber | |
1567 | (I think). */ | |
d5336fc5 | 1568 | struct type *t; |
25200748 | 1569 | ++*pp; |
d5336fc5 KH |
1570 | while (**pp != ')') |
1571 | { | |
0a2e98a9 | 1572 | t = read_type(pp, objfile); |
d5336fc5 KH |
1573 | if (**pp == ',') ++*pp; |
1574 | } | |
25200748 | 1575 | } |
d07734e3 FF |
1576 | type1 = read_type (pp, objfile); |
1577 | type = make_function_type (type1, dbx_lookup_type (typenums)); | |
1578 | break; | |
1579 | ||
25200748 JK |
1580 | case 'k': /* Const qualifier on some type (Sun) */ |
1581 | case 'c': /* Const qualifier on some type (OS9000) */ | |
1582 | /* Because 'c' means other things to AIX and 'k' is perfectly good, | |
1583 | only accept 'c' in the os9k_stabs case. */ | |
1584 | if (type_descriptor == 'c' && !os9k_stabs) | |
1585 | return error_type (pp); | |
d07734e3 FF |
1586 | type = read_type (pp, objfile); |
1587 | /* FIXME! For now, we ignore const and volatile qualifiers. */ | |
1588 | break; | |
1589 | ||
25200748 JK |
1590 | case 'B': /* Volatile qual on some type (Sun) */ |
1591 | case 'i': /* Volatile qual on some type (OS9000) */ | |
1592 | /* Because 'i' means other things to AIX and 'B' is perfectly good, | |
1593 | only accept 'i' in the os9k_stabs case. */ | |
1594 | if (type_descriptor == 'i' && !os9k_stabs) | |
1595 | return error_type (pp); | |
d07734e3 FF |
1596 | type = read_type (pp, objfile); |
1597 | /* FIXME! For now, we ignore const and volatile qualifiers. */ | |
1598 | break; | |
1599 | ||
1600 | /* FIXME -- we should be doing smash_to_XXX types here. */ | |
1601 | case '@': /* Member (class & variable) type */ | |
1602 | { | |
1603 | struct type *domain = read_type (pp, objfile); | |
1604 | struct type *memtype; | |
1605 | ||
1606 | if (**pp != ',') | |
1607 | /* Invalid member type data format. */ | |
1608 | return error_type (pp); | |
1609 | ++*pp; | |
1610 | ||
1611 | memtype = read_type (pp, objfile); | |
1612 | type = dbx_alloc_type (typenums, objfile); | |
1613 | smash_to_member_type (type, domain, memtype); | |
1614 | } | |
1615 | break; | |
1616 | ||
1617 | case '#': /* Method (class & fn) type */ | |
1618 | if ((*pp)[0] == '#') | |
1619 | { | |
2640f7e1 | 1620 | /* We'll get the parameter types from the name. */ |
d07734e3 FF |
1621 | struct type *return_type; |
1622 | ||
e7177cc2 | 1623 | (*pp)++; |
d07734e3 FF |
1624 | return_type = read_type (pp, objfile); |
1625 | if (*(*pp)++ != ';') | |
51b80b00 | 1626 | complain (&invalid_member_complaint, symnum); |
d07734e3 FF |
1627 | type = allocate_stub_method (return_type); |
1628 | if (typenums[0] != -1) | |
1629 | *dbx_lookup_type (typenums) = type; | |
1630 | } | |
1631 | else | |
1632 | { | |
1633 | struct type *domain = read_type (pp, objfile); | |
1634 | struct type *return_type; | |
1635 | struct type **args; | |
1636 | ||
ea753d03 JK |
1637 | if (**pp != ',') |
1638 | /* Invalid member type data format. */ | |
1639 | return error_type (pp); | |
1640 | else | |
1641 | ++(*pp); | |
d07734e3 FF |
1642 | |
1643 | return_type = read_type (pp, objfile); | |
1644 | args = read_args (pp, ';', objfile); | |
1645 | type = dbx_alloc_type (typenums, objfile); | |
1646 | smash_to_method_type (type, domain, return_type, args); | |
1647 | } | |
1648 | break; | |
1649 | ||
1650 | case 'r': /* Range type */ | |
1651 | type = read_range_type (pp, typenums, objfile); | |
1652 | if (typenums[0] != -1) | |
1653 | *dbx_lookup_type (typenums) = type; | |
1654 | break; | |
1655 | ||
25200748 JK |
1656 | case 'b': |
1657 | if (os9k_stabs) | |
1658 | /* Const and volatile qualified type. */ | |
1659 | type = read_type (pp, objfile); | |
1660 | else | |
1661 | { | |
1662 | /* Sun ACC builtin int type */ | |
1663 | type = read_sun_builtin_type (pp, typenums, objfile); | |
1664 | if (typenums[0] != -1) | |
1665 | *dbx_lookup_type (typenums) = type; | |
1666 | } | |
d07734e3 FF |
1667 | break; |
1668 | ||
1669 | case 'R': /* Sun ACC builtin float type */ | |
1670 | type = read_sun_floating_type (pp, typenums, objfile); | |
1671 | if (typenums[0] != -1) | |
1672 | *dbx_lookup_type (typenums) = type; | |
1673 | break; | |
1674 | ||
1675 | case 'e': /* Enumeration type */ | |
1676 | type = dbx_alloc_type (typenums, objfile); | |
1677 | type = read_enum_type (pp, type, objfile); | |
ea753d03 JK |
1678 | if (typenums[0] != -1) |
1679 | *dbx_lookup_type (typenums) = type; | |
d07734e3 FF |
1680 | break; |
1681 | ||
1682 | case 's': /* Struct type */ | |
d07734e3 FF |
1683 | case 'u': /* Union type */ |
1684 | type = dbx_alloc_type (typenums, objfile); | |
1685 | if (!TYPE_NAME (type)) | |
e7177cc2 FF |
1686 | { |
1687 | TYPE_NAME (type) = type_synonym_name; | |
1688 | } | |
1689 | type_synonym_name = NULL; | |
1690 | switch (type_descriptor) | |
1691 | { | |
1692 | case 's': | |
1693 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
1694 | break; | |
1695 | case 'u': | |
1696 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
1697 | break; | |
1698 | } | |
d07734e3 | 1699 | type = read_struct_type (pp, type, objfile); |
d07734e3 FF |
1700 | break; |
1701 | ||
1702 | case 'a': /* Array type */ | |
1703 | if (**pp != 'r') | |
1704 | return error_type (pp); | |
1705 | ++*pp; | |
1706 | ||
1707 | type = dbx_alloc_type (typenums, objfile); | |
1708 | type = read_array_type (pp, type, objfile); | |
cba00921 PB |
1709 | if (is_string) |
1710 | TYPE_CODE (type) = TYPE_CODE_STRING; | |
d07734e3 FF |
1711 | break; |
1712 | ||
e909f287 PB |
1713 | case 'S': |
1714 | type1 = read_type (pp, objfile); | |
1715 | type = create_set_type ((struct type*) NULL, type1); | |
cba00921 PB |
1716 | if (is_string) |
1717 | TYPE_CODE (type) = TYPE_CODE_BITSTRING; | |
e909f287 PB |
1718 | if (typenums[0] != -1) |
1719 | *dbx_lookup_type (typenums) = type; | |
1720 | break; | |
1721 | ||
d07734e3 FF |
1722 | default: |
1723 | --*pp; /* Go back to the symbol in error */ | |
1724 | /* Particularly important if it was \0! */ | |
1725 | return error_type (pp); | |
1726 | } | |
1727 | ||
1728 | if (type == 0) | |
ea753d03 JK |
1729 | { |
1730 | warning ("GDB internal error, type is NULL in stabsread.c\n"); | |
1731 | return error_type (pp); | |
1732 | } | |
d07734e3 | 1733 | |
5ed0ccaf JK |
1734 | /* Size specified in a type attribute overrides any other size. */ |
1735 | if (type_size != -1) | |
1736 | TYPE_LENGTH (type) = type_size / TARGET_CHAR_BIT; | |
1737 | ||
d07734e3 FF |
1738 | return type; |
1739 | } | |
1740 | \f | |
dd469789 JG |
1741 | /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1. |
1742 | Return the proper type node for a given builtin type number. */ | |
1743 | ||
1744 | static struct type * | |
a387370d | 1745 | rs6000_builtin_type (typenum) |
f52bde21 | 1746 | int typenum; |
dd469789 | 1747 | { |
f52bde21 JK |
1748 | /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */ |
1749 | #define NUMBER_RECOGNIZED 30 | |
1750 | /* This includes an empty slot for type number -0. */ | |
1751 | static struct type *negative_types[NUMBER_RECOGNIZED + 1]; | |
46c28185 | 1752 | struct type *rettype = NULL; |
f52bde21 JK |
1753 | |
1754 | if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED) | |
1755 | { | |
1756 | complain (&rs6000_builtin_complaint, typenum); | |
1757 | return builtin_type_error; | |
1758 | } | |
1759 | if (negative_types[-typenum] != NULL) | |
1760 | return negative_types[-typenum]; | |
1761 | ||
1762 | #if TARGET_CHAR_BIT != 8 | |
1763 | #error This code wrong for TARGET_CHAR_BIT not 8 | |
1764 | /* These definitions all assume that TARGET_CHAR_BIT is 8. I think | |
1765 | that if that ever becomes not true, the correct fix will be to | |
1766 | make the size in the struct type to be in bits, not in units of | |
1767 | TARGET_CHAR_BIT. */ | |
1768 | #endif | |
1769 | ||
1770 | switch (-typenum) | |
1771 | { | |
1772 | case 1: | |
1773 | /* The size of this and all the other types are fixed, defined | |
1774 | by the debugging format. If there is a type called "int" which | |
1775 | is other than 32 bits, then it should use a new negative type | |
1776 | number (or avoid negative type numbers for that case). | |
1777 | See stabs.texinfo. */ | |
1778 | rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL); | |
1779 | break; | |
1780 | case 2: | |
1781 | rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL); | |
1782 | break; | |
1783 | case 3: | |
1784 | rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL); | |
1785 | break; | |
1786 | case 4: | |
1787 | rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL); | |
1788 | break; | |
1789 | case 5: | |
1790 | rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, | |
1791 | "unsigned char", NULL); | |
1792 | break; | |
1793 | case 6: | |
1794 | rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL); | |
1795 | break; | |
1796 | case 7: | |
1797 | rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, | |
1798 | "unsigned short", NULL); | |
1799 | break; | |
1800 | case 8: | |
1801 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, | |
1802 | "unsigned int", NULL); | |
1803 | break; | |
1804 | case 9: | |
1805 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, | |
1806 | "unsigned", NULL); | |
1807 | case 10: | |
1808 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, | |
1809 | "unsigned long", NULL); | |
1810 | break; | |
1811 | case 11: | |
2f3b7d8e | 1812 | rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL); |
f52bde21 JK |
1813 | break; |
1814 | case 12: | |
1815 | /* IEEE single precision (32 bit). */ | |
1816 | rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL); | |
1817 | break; | |
1818 | case 13: | |
1819 | /* IEEE double precision (64 bit). */ | |
1820 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL); | |
1821 | break; | |
1822 | case 14: | |
1823 | /* This is an IEEE double on the RS/6000, and different machines with | |
1824 | different sizes for "long double" should use different negative | |
1825 | type numbers. See stabs.texinfo. */ | |
1826 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL); | |
1827 | break; | |
1828 | case 15: | |
1829 | rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL); | |
1830 | break; | |
1831 | case 16: | |
7e71985c | 1832 | rettype = init_type (TYPE_CODE_BOOL, 4, 0, "boolean", NULL); |
f52bde21 JK |
1833 | break; |
1834 | case 17: | |
1835 | rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL); | |
1836 | break; | |
1837 | case 18: | |
1838 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL); | |
1839 | break; | |
1840 | case 19: | |
1841 | rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL); | |
1842 | break; | |
1843 | case 20: | |
1844 | rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED, | |
1845 | "character", NULL); | |
1846 | break; | |
1847 | case 21: | |
230a3ab0 | 1848 | rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, |
f52bde21 JK |
1849 | "logical*1", NULL); |
1850 | break; | |
1851 | case 22: | |
230a3ab0 | 1852 | rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED, |
f52bde21 JK |
1853 | "logical*2", NULL); |
1854 | break; | |
1855 | case 23: | |
230a3ab0 | 1856 | rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, |
f52bde21 JK |
1857 | "logical*4", NULL); |
1858 | break; | |
1859 | case 24: | |
91ab5674 | 1860 | rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, |
f52bde21 JK |
1861 | "logical", NULL); |
1862 | break; | |
1863 | case 25: | |
1864 | /* Complex type consisting of two IEEE single precision values. */ | |
1865 | rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL); | |
1866 | break; | |
1867 | case 26: | |
1868 | /* Complex type consisting of two IEEE double precision values. */ | |
1869 | rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL); | |
1870 | break; | |
1871 | case 27: | |
1872 | rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL); | |
1873 | break; | |
1874 | case 28: | |
1875 | rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL); | |
1876 | break; | |
1877 | case 29: | |
1878 | rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL); | |
1879 | break; | |
1880 | case 30: | |
1881 | rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL); | |
1882 | break; | |
1883 | } | |
1884 | negative_types[-typenum] = rettype; | |
1885 | return rettype; | |
dd469789 JG |
1886 | } |
1887 | \f | |
d07734e3 FF |
1888 | /* This page contains subroutines of read_type. */ |
1889 | ||
e7177cc2 FF |
1890 | #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */ |
1891 | #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */ | |
1892 | #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */ | |
1dfaef62 | 1893 | #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */ |
d07734e3 | 1894 | |
e7177cc2 FF |
1895 | /* Read member function stabs info for C++ classes. The form of each member |
1896 | function data is: | |
1897 | ||
1898 | NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; | |
1899 | ||
1900 | An example with two member functions is: | |
1901 | ||
1902 | afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; | |
1903 | ||
1904 | For the case of overloaded operators, the format is op$::*.funcs, where | |
1905 | $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator | |
ea753d03 JK |
1906 | name (such as `+=') and `.' marks the end of the operator name. |
1907 | ||
1908 | Returns 1 for success, 0 for failure. */ | |
e7177cc2 FF |
1909 | |
1910 | static int | |
1911 | read_member_functions (fip, pp, type, objfile) | |
1912 | struct field_info *fip; | |
d07734e3 | 1913 | char **pp; |
e7177cc2 | 1914 | struct type *type; |
d07734e3 FF |
1915 | struct objfile *objfile; |
1916 | { | |
e7177cc2 FF |
1917 | int nfn_fields = 0; |
1918 | int length = 0; | |
1919 | /* Total number of member functions defined in this class. If the class | |
1920 | defines two `f' functions, and one `g' function, then this will have | |
1921 | the value 3. */ | |
d07734e3 | 1922 | int total_length = 0; |
e7177cc2 | 1923 | int i; |
d07734e3 FF |
1924 | struct next_fnfield |
1925 | { | |
1926 | struct next_fnfield *next; | |
1927 | struct fn_field fn_field; | |
e7177cc2 FF |
1928 | } *sublist; |
1929 | struct type *look_ahead_type; | |
1930 | struct next_fnfieldlist *new_fnlist; | |
1931 | struct next_fnfield *new_sublist; | |
1932 | char *main_fn_name; | |
d07734e3 | 1933 | register char *p; |
e7177cc2 FF |
1934 | |
1935 | /* Process each list until we find something that is not a member function | |
1936 | or find the end of the functions. */ | |
d07734e3 | 1937 | |
e7177cc2 | 1938 | while (**pp != ';') |
d07734e3 | 1939 | { |
e7177cc2 FF |
1940 | /* We should be positioned at the start of the function name. |
1941 | Scan forward to find the first ':' and if it is not the | |
1942 | first of a "::" delimiter, then this is not a member function. */ | |
1943 | p = *pp; | |
1944 | while (*p != ':') | |
1945 | { | |
1946 | p++; | |
1947 | } | |
1948 | if (p[1] != ':') | |
1949 | { | |
1950 | break; | |
1951 | } | |
d07734e3 | 1952 | |
e7177cc2 FF |
1953 | sublist = NULL; |
1954 | look_ahead_type = NULL; | |
1955 | length = 0; | |
1956 | ||
1957 | new_fnlist = (struct next_fnfieldlist *) | |
1958 | xmalloc (sizeof (struct next_fnfieldlist)); | |
1959 | make_cleanup (free, new_fnlist); | |
1960 | memset (new_fnlist, 0, sizeof (struct next_fnfieldlist)); | |
1961 | ||
1962 | if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER) | |
d07734e3 | 1963 | { |
e7177cc2 FF |
1964 | /* This is a completely wierd case. In order to stuff in the |
1965 | names that might contain colons (the usual name delimiter), | |
1966 | Mike Tiemann defined a different name format which is | |
1967 | signalled if the identifier is "op$". In that case, the | |
1968 | format is "op$::XXXX." where XXXX is the name. This is | |
1969 | used for names like "+" or "=". YUUUUUUUK! FIXME! */ | |
1970 | /* This lets the user type "break operator+". | |
1971 | We could just put in "+" as the name, but that wouldn't | |
1972 | work for "*". */ | |
1973 | static char opname[32] = {'o', 'p', CPLUS_MARKER}; | |
1974 | char *o = opname + 3; | |
1975 | ||
1976 | /* Skip past '::'. */ | |
1977 | *pp = p + 2; | |
d07734e3 | 1978 | |
e7177cc2 FF |
1979 | STABS_CONTINUE (pp); |
1980 | p = *pp; | |
1981 | while (*p != '.') | |
d07734e3 | 1982 | { |
e7177cc2 FF |
1983 | *o++ = *p++; |
1984 | } | |
1985 | main_fn_name = savestring (opname, o - opname); | |
1986 | /* Skip past '.' */ | |
1987 | *pp = p + 1; | |
1988 | } | |
1989 | else | |
1990 | { | |
1991 | main_fn_name = savestring (*pp, p - *pp); | |
1992 | /* Skip past '::'. */ | |
1993 | *pp = p + 2; | |
1994 | } | |
1995 | new_fnlist -> fn_fieldlist.name = main_fn_name; | |
1996 | ||
1997 | do | |
1998 | { | |
1999 | new_sublist = | |
2000 | (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield)); | |
2001 | make_cleanup (free, new_sublist); | |
2002 | memset (new_sublist, 0, sizeof (struct next_fnfield)); | |
2003 | ||
2004 | /* Check for and handle cretinous dbx symbol name continuation! */ | |
2005 | if (look_ahead_type == NULL) | |
2006 | { | |
2007 | /* Normal case. */ | |
2008 | STABS_CONTINUE (pp); | |
2009 | ||
2010 | new_sublist -> fn_field.type = read_type (pp, objfile); | |
2011 | if (**pp != ':') | |
2012 | { | |
2013 | /* Invalid symtab info for member function. */ | |
2a021f21 | 2014 | return 0; |
e7177cc2 FF |
2015 | } |
2016 | } | |
2017 | else | |
2018 | { | |
2019 | /* g++ version 1 kludge */ | |
2020 | new_sublist -> fn_field.type = look_ahead_type; | |
2021 | look_ahead_type = NULL; | |
2022 | } | |
2023 | ||
2024 | (*pp)++; | |
2025 | p = *pp; | |
2026 | while (*p != ';') | |
2027 | { | |
2028 | p++; | |
d07734e3 | 2029 | } |
e7177cc2 FF |
2030 | |
2031 | /* If this is just a stub, then we don't have the real name here. */ | |
d07734e3 | 2032 | |
e7177cc2 FF |
2033 | if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB) |
2034 | { | |
39cb3d04 PS |
2035 | if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type)) |
2036 | TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type; | |
e7177cc2 FF |
2037 | new_sublist -> fn_field.is_stub = 1; |
2038 | } | |
2039 | new_sublist -> fn_field.physname = savestring (*pp, p - *pp); | |
2040 | *pp = p + 1; | |
2041 | ||
2042 | /* Set this member function's visibility fields. */ | |
2043 | switch (*(*pp)++) | |
2044 | { | |
2045 | case VISIBILITY_PRIVATE: | |
2046 | new_sublist -> fn_field.is_private = 1; | |
2047 | break; | |
2048 | case VISIBILITY_PROTECTED: | |
2049 | new_sublist -> fn_field.is_protected = 1; | |
2050 | break; | |
2051 | } | |
2052 | ||
2053 | STABS_CONTINUE (pp); | |
d07734e3 FF |
2054 | switch (**pp) |
2055 | { | |
e7177cc2 FF |
2056 | case 'A': /* Normal functions. */ |
2057 | new_sublist -> fn_field.is_const = 0; | |
2058 | new_sublist -> fn_field.is_volatile = 0; | |
2059 | (*pp)++; | |
2060 | break; | |
2061 | case 'B': /* `const' member functions. */ | |
2062 | new_sublist -> fn_field.is_const = 1; | |
2063 | new_sublist -> fn_field.is_volatile = 0; | |
2064 | (*pp)++; | |
2065 | break; | |
2066 | case 'C': /* `volatile' member function. */ | |
2067 | new_sublist -> fn_field.is_const = 0; | |
2068 | new_sublist -> fn_field.is_volatile = 1; | |
2069 | (*pp)++; | |
2070 | break; | |
2071 | case 'D': /* `const volatile' member function. */ | |
2072 | new_sublist -> fn_field.is_const = 1; | |
2073 | new_sublist -> fn_field.is_volatile = 1; | |
2074 | (*pp)++; | |
2075 | break; | |
2076 | case '*': /* File compiled with g++ version 1 -- no info */ | |
2077 | case '?': | |
2078 | case '.': | |
2079 | break; | |
2080 | default: | |
51b80b00 | 2081 | complain (&const_vol_complaint, **pp); |
e7177cc2 | 2082 | break; |
d07734e3 | 2083 | } |
e7177cc2 FF |
2084 | |
2085 | switch (*(*pp)++) | |
2086 | { | |
2087 | case '*': | |
ea753d03 JK |
2088 | { |
2089 | int nbits; | |
e7177cc2 FF |
2090 | /* virtual member function, followed by index. |
2091 | The sign bit is set to distinguish pointers-to-methods | |
2092 | from virtual function indicies. Since the array is | |
2093 | in words, the quantity must be shifted left by 1 | |
2094 | on 16 bit machine, and by 2 on 32 bit machine, forcing | |
2095 | the sign bit out, and usable as a valid index into | |
2096 | the array. Remove the sign bit here. */ | |
2097 | new_sublist -> fn_field.voffset = | |
ea753d03 JK |
2098 | (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2; |
2099 | if (nbits != 0) | |
2100 | return 0; | |
e7177cc2 FF |
2101 | |
2102 | STABS_CONTINUE (pp); | |
2103 | if (**pp == ';' || **pp == '\0') | |
2104 | { | |
2105 | /* Must be g++ version 1. */ | |
2106 | new_sublist -> fn_field.fcontext = 0; | |
2107 | } | |
2108 | else | |
2109 | { | |
2110 | /* Figure out from whence this virtual function came. | |
2111 | It may belong to virtual function table of | |
2112 | one of its baseclasses. */ | |
2113 | look_ahead_type = read_type (pp, objfile); | |
2114 | if (**pp == ':') | |
2115 | { | |
2116 | /* g++ version 1 overloaded methods. */ | |
2117 | } | |
2118 | else | |
2119 | { | |
2120 | new_sublist -> fn_field.fcontext = look_ahead_type; | |
2121 | if (**pp != ';') | |
2122 | { | |
2a021f21 | 2123 | return 0; |
e7177cc2 FF |
2124 | } |
2125 | else | |
2126 | { | |
2127 | ++*pp; | |
2128 | } | |
2129 | look_ahead_type = NULL; | |
2130 | } | |
2131 | } | |
2132 | break; | |
ea753d03 | 2133 | } |
e7177cc2 FF |
2134 | case '?': |
2135 | /* static member function. */ | |
2136 | new_sublist -> fn_field.voffset = VOFFSET_STATIC; | |
2137 | if (strncmp (new_sublist -> fn_field.physname, | |
2138 | main_fn_name, strlen (main_fn_name))) | |
2139 | { | |
2140 | new_sublist -> fn_field.is_stub = 1; | |
2141 | } | |
2142 | break; | |
2143 | ||
2144 | default: | |
2145 | /* error */ | |
51b80b00 | 2146 | complain (&member_fn_complaint, (*pp)[-1]); |
e7177cc2 FF |
2147 | /* Fall through into normal member function. */ |
2148 | ||
2149 | case '.': | |
2150 | /* normal member function. */ | |
2151 | new_sublist -> fn_field.voffset = 0; | |
2152 | new_sublist -> fn_field.fcontext = 0; | |
2153 | break; | |
2154 | } | |
2155 | ||
2156 | new_sublist -> next = sublist; | |
2157 | sublist = new_sublist; | |
2158 | length++; | |
2159 | STABS_CONTINUE (pp); | |
d07734e3 | 2160 | } |
e7177cc2 FF |
2161 | while (**pp != ';' && **pp != '\0'); |
2162 | ||
2163 | (*pp)++; | |
2164 | ||
2165 | new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *) | |
2166 | obstack_alloc (&objfile -> type_obstack, | |
2167 | sizeof (struct fn_field) * length); | |
2168 | memset (new_fnlist -> fn_fieldlist.fn_fields, 0, | |
2169 | sizeof (struct fn_field) * length); | |
2170 | for (i = length; (i--, sublist); sublist = sublist -> next) | |
2171 | { | |
2172 | new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field; | |
2173 | } | |
2174 | ||
2175 | new_fnlist -> fn_fieldlist.length = length; | |
2176 | new_fnlist -> next = fip -> fnlist; | |
2177 | fip -> fnlist = new_fnlist; | |
2178 | nfn_fields++; | |
2179 | total_length += length; | |
2180 | STABS_CONTINUE (pp); | |
d07734e3 FF |
2181 | } |
2182 | ||
e7177cc2 FF |
2183 | if (nfn_fields) |
2184 | { | |
2185 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
2186 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
2187 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields); | |
2188 | memset (TYPE_FN_FIELDLISTS (type), 0, | |
2189 | sizeof (struct fn_fieldlist) * nfn_fields); | |
2190 | TYPE_NFN_FIELDS (type) = nfn_fields; | |
2191 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
2192 | } | |
d07734e3 | 2193 | |
2a021f21 | 2194 | return 1; |
e7177cc2 | 2195 | } |
d07734e3 | 2196 | |
e7177cc2 | 2197 | /* Special GNU C++ name. |
d07734e3 | 2198 | |
ea753d03 JK |
2199 | Returns 1 for success, 0 for failure. "failure" means that we can't |
2200 | keep parsing and it's time for error_type(). */ | |
2201 | ||
2202 | static int | |
e7177cc2 FF |
2203 | read_cpp_abbrev (fip, pp, type, objfile) |
2204 | struct field_info *fip; | |
2205 | char **pp; | |
2206 | struct type *type; | |
2207 | struct objfile *objfile; | |
2208 | { | |
2209 | register char *p; | |
e7177cc2 | 2210 | char *name; |
2a021f21 | 2211 | char cpp_abbrev; |
e7177cc2 | 2212 | struct type *context; |
d07734e3 | 2213 | |
e7177cc2 FF |
2214 | p = *pp; |
2215 | if (*++p == 'v') | |
d07734e3 | 2216 | { |
e7177cc2 | 2217 | name = NULL; |
2a021f21 JG |
2218 | cpp_abbrev = *++p; |
2219 | ||
d07734e3 FF |
2220 | *pp = p + 1; |
2221 | ||
e7177cc2 FF |
2222 | /* At this point, *pp points to something like "22:23=*22...", |
2223 | where the type number before the ':' is the "context" and | |
2224 | everything after is a regular type definition. Lookup the | |
2225 | type, find it's name, and construct the field name. */ | |
2226 | ||
2227 | context = read_type (pp, objfile); | |
2a021f21 JG |
2228 | |
2229 | switch (cpp_abbrev) | |
d07734e3 | 2230 | { |
2a021f21 JG |
2231 | case 'f': /* $vf -- a virtual function table pointer */ |
2232 | fip->list->field.name = | |
2233 | obconcat (&objfile->type_obstack, vptr_name, "", ""); | |
2234 | break; | |
2235 | ||
2236 | case 'b': /* $vb -- a virtual bsomethingorother */ | |
2237 | name = type_name_no_tag (context); | |
2238 | if (name == NULL) | |
2239 | { | |
2240 | complain (&invalid_cpp_type_complaint, symnum); | |
2241 | name = "FOO"; | |
2242 | } | |
2243 | fip->list->field.name = | |
2244 | obconcat (&objfile->type_obstack, vb_name, name, ""); | |
2245 | break; | |
2246 | ||
2247 | default: | |
2248 | complain (&invalid_cpp_abbrev_complaint, *pp); | |
2249 | fip->list->field.name = | |
2250 | obconcat (&objfile->type_obstack, | |
2251 | "INVALID_CPLUSPLUS_ABBREV", "", ""); | |
2252 | break; | |
e7177cc2 | 2253 | } |
d07734e3 | 2254 | |
e7177cc2 FF |
2255 | /* At this point, *pp points to the ':'. Skip it and read the |
2256 | field type. */ | |
d07734e3 | 2257 | |
e7177cc2 FF |
2258 | p = ++(*pp); |
2259 | if (p[-1] != ':') | |
2260 | { | |
2261 | complain (&invalid_cpp_abbrev_complaint, *pp); | |
ea753d03 | 2262 | return 0; |
e7177cc2 | 2263 | } |
2a021f21 | 2264 | fip->list->field.type = read_type (pp, objfile); |
ea753d03 JK |
2265 | if (**pp == ',') |
2266 | (*pp)++; /* Skip the comma. */ | |
2267 | else | |
2268 | return 0; | |
2269 | ||
2270 | { | |
2271 | int nbits; | |
2272 | fip->list->field.bitpos = read_huge_number (pp, ';', &nbits); | |
2273 | if (nbits != 0) | |
2274 | return 0; | |
2275 | } | |
e7177cc2 | 2276 | /* This field is unpacked. */ |
2a021f21 JG |
2277 | fip->list->field.bitsize = 0; |
2278 | fip->list->visibility = VISIBILITY_PRIVATE; | |
e7177cc2 | 2279 | } |
e7177cc2 FF |
2280 | else |
2281 | { | |
2282 | complain (&invalid_cpp_abbrev_complaint, *pp); | |
089dc220 JK |
2283 | /* We have no idea what syntax an unrecognized abbrev would have, so |
2284 | better return 0. If we returned 1, we would need to at least advance | |
2285 | *pp to avoid an infinite loop. */ | |
2286 | return 0; | |
e7177cc2 | 2287 | } |
ea753d03 | 2288 | return 1; |
e7177cc2 | 2289 | } |
d07734e3 | 2290 | |
e7177cc2 FF |
2291 | static void |
2292 | read_one_struct_field (fip, pp, p, type, objfile) | |
2293 | struct field_info *fip; | |
2294 | char **pp; | |
2295 | char *p; | |
2296 | struct type *type; | |
2297 | struct objfile *objfile; | |
2298 | { | |
2299 | fip -> list -> field.name = | |
2300 | obsavestring (*pp, p - *pp, &objfile -> type_obstack); | |
2301 | *pp = p + 1; | |
1dfaef62 | 2302 | |
e7177cc2 FF |
2303 | /* This means we have a visibility for a field coming. */ |
2304 | if (**pp == '/') | |
2305 | { | |
2306 | (*pp)++; | |
2307 | fip -> list -> visibility = *(*pp)++; | |
e7177cc2 FF |
2308 | } |
2309 | else | |
2310 | { | |
2311 | /* normal dbx-style format, no explicit visibility */ | |
2312 | fip -> list -> visibility = VISIBILITY_PUBLIC; | |
2313 | } | |
1dfaef62 | 2314 | |
e7177cc2 FF |
2315 | fip -> list -> field.type = read_type (pp, objfile); |
2316 | if (**pp == ':') | |
2317 | { | |
2318 | p = ++(*pp); | |
d07734e3 | 2319 | #if 0 |
e7177cc2 FF |
2320 | /* Possible future hook for nested types. */ |
2321 | if (**pp == '!') | |
d07734e3 | 2322 | { |
e7177cc2 FF |
2323 | fip -> list -> field.bitpos = (long)-2; /* nested type */ |
2324 | p = ++(*pp); | |
d07734e3 FF |
2325 | } |
2326 | else | |
e7177cc2 FF |
2327 | #endif |
2328 | { | |
2329 | /* Static class member. */ | |
2330 | fip -> list -> field.bitpos = (long) -1; | |
2331 | } | |
2332 | while (*p != ';') | |
2333 | { | |
2334 | p++; | |
2335 | } | |
2336 | fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp); | |
2337 | *pp = p + 1; | |
2338 | return; | |
2339 | } | |
2340 | else if (**pp != ',') | |
2341 | { | |
2342 | /* Bad structure-type format. */ | |
2343 | complain (&stabs_general_complaint, "bad structure-type format"); | |
2344 | return; | |
2345 | } | |
ea753d03 | 2346 | |
e7177cc2 | 2347 | (*pp)++; /* Skip the comma. */ |
ea753d03 JK |
2348 | |
2349 | { | |
2350 | int nbits; | |
2351 | fip -> list -> field.bitpos = read_huge_number (pp, ',', &nbits); | |
2352 | if (nbits != 0) | |
2353 | { | |
2354 | complain (&stabs_general_complaint, "bad structure-type format"); | |
2355 | return; | |
2356 | } | |
2357 | fip -> list -> field.bitsize = read_huge_number (pp, ';', &nbits); | |
2358 | if (nbits != 0) | |
2359 | { | |
2360 | complain (&stabs_general_complaint, "bad structure-type format"); | |
2361 | return; | |
2362 | } | |
2363 | } | |
d4e68dec | 2364 | |
e7177cc2 FF |
2365 | if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0) |
2366 | { | |
d4e68dec JK |
2367 | /* This can happen in two cases: (1) at least for gcc 2.4.5 or so, |
2368 | it is a field which has been optimized out. The correct stab for | |
2369 | this case is to use VISIBILITY_IGNORE, but that is a recent | |
2370 | invention. (2) It is a 0-size array. For example | |
2371 | union { int num; char str[0]; } foo. Printing "<no value>" for | |
2372 | str in "p foo" is OK, since foo.str (and thus foo.str[3]) | |
2373 | will continue to work, and a 0-size array as a whole doesn't | |
2374 | have any contents to print. | |
2375 | ||
2376 | I suspect this probably could also happen with gcc -gstabs (not | |
2377 | -gstabs+) for static fields, and perhaps other C++ extensions. | |
2378 | Hopefully few people use -gstabs with gdb, since it is intended | |
2379 | for dbx compatibility. */ | |
2380 | ||
e7177cc2 | 2381 | /* Ignore this field. */ |
024f65b1 | 2382 | fip -> list-> visibility = VISIBILITY_IGNORE; |
e7177cc2 FF |
2383 | } |
2384 | else | |
e7177cc2 FF |
2385 | { |
2386 | /* Detect an unpacked field and mark it as such. | |
2387 | dbx gives a bit size for all fields. | |
2388 | Note that forward refs cannot be packed, | |
2389 | and treat enums as if they had the width of ints. */ | |
1dfaef62 | 2390 | |
e7177cc2 FF |
2391 | if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT |
2392 | && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM) | |
d07734e3 | 2393 | { |
e7177cc2 FF |
2394 | fip -> list -> field.bitsize = 0; |
2395 | } | |
2396 | if ((fip -> list -> field.bitsize | |
f52bde21 | 2397 | == TARGET_CHAR_BIT * TYPE_LENGTH (fip -> list -> field.type) |
e7177cc2 FF |
2398 | || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM |
2399 | && (fip -> list -> field.bitsize | |
f52bde21 | 2400 | == TARGET_INT_BIT) |
d07734e3 | 2401 | ) |
e7177cc2 FF |
2402 | ) |
2403 | && | |
2404 | fip -> list -> field.bitpos % 8 == 0) | |
2405 | { | |
2406 | fip -> list -> field.bitsize = 0; | |
d07734e3 FF |
2407 | } |
2408 | } | |
e7177cc2 | 2409 | } |
d07734e3 | 2410 | |
d07734e3 | 2411 | |
e7177cc2 | 2412 | /* Read struct or class data fields. They have the form: |
d07734e3 | 2413 | |
e7177cc2 | 2414 | NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; |
d07734e3 | 2415 | |
e7177cc2 FF |
2416 | At the end, we see a semicolon instead of a field. |
2417 | ||
2418 | In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for | |
2419 | a static field. | |
2420 | ||
2421 | The optional VISIBILITY is one of: | |
2422 | ||
2423 | '/0' (VISIBILITY_PRIVATE) | |
2424 | '/1' (VISIBILITY_PROTECTED) | |
2425 | '/2' (VISIBILITY_PUBLIC) | |
1dfaef62 | 2426 | '/9' (VISIBILITY_IGNORE) |
e7177cc2 | 2427 | |
ea753d03 JK |
2428 | or nothing, for C style fields with public visibility. |
2429 | ||
2430 | Returns 1 for success, 0 for failure. */ | |
d4e68dec | 2431 | |
e7177cc2 FF |
2432 | static int |
2433 | read_struct_fields (fip, pp, type, objfile) | |
2434 | struct field_info *fip; | |
2435 | char **pp; | |
2436 | struct type *type; | |
2437 | struct objfile *objfile; | |
2438 | { | |
2439 | register char *p; | |
2440 | struct nextfield *new; | |
2441 | ||
2442 | /* We better set p right now, in case there are no fields at all... */ | |
2443 | ||
2444 | p = *pp; | |
2445 | ||
2446 | /* Read each data member type until we find the terminating ';' at the end of | |
2447 | the data member list, or break for some other reason such as finding the | |
2448 | start of the member function list. */ | |
2449 | ||
2450 | while (**pp != ';') | |
d07734e3 | 2451 | { |
e7177cc2 FF |
2452 | STABS_CONTINUE (pp); |
2453 | /* Get space to record the next field's data. */ | |
2454 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
2455 | make_cleanup (free, new); | |
2456 | memset (new, 0, sizeof (struct nextfield)); | |
2457 | new -> next = fip -> list; | |
2458 | fip -> list = new; | |
d07734e3 | 2459 | |
e7177cc2 FF |
2460 | /* Get the field name. */ |
2461 | p = *pp; | |
f73fb0ce JK |
2462 | |
2463 | /* If is starts with CPLUS_MARKER it is a special abbreviation, | |
2464 | unless the CPLUS_MARKER is followed by an underscore, in | |
2465 | which case it is just the name of an anonymous type, which we | |
2466 | should handle like any other type name. We accept either '$' | |
2467 | or '.', because a field name can never contain one of these | |
2468 | characters except as a CPLUS_MARKER (we probably should be | |
2469 | doing that in most parts of GDB). */ | |
2470 | ||
2471 | if ((*p == '$' || *p == '.') && p[1] != '_') | |
e7177cc2 | 2472 | { |
ea753d03 JK |
2473 | if (!read_cpp_abbrev (fip, pp, type, objfile)) |
2474 | return 0; | |
e7177cc2 FF |
2475 | continue; |
2476 | } | |
d07734e3 | 2477 | |
e7177cc2 FF |
2478 | /* Look for the ':' that separates the field name from the field |
2479 | values. Data members are delimited by a single ':', while member | |
2480 | functions are delimited by a pair of ':'s. When we hit the member | |
2481 | functions (if any), terminate scan loop and return. */ | |
d07734e3 | 2482 | |
ea753d03 | 2483 | while (*p != ':' && *p != '\0') |
e7177cc2 FF |
2484 | { |
2485 | p++; | |
2486 | } | |
ea753d03 JK |
2487 | if (*p == '\0') |
2488 | return 0; | |
d07734e3 | 2489 | |
e7177cc2 FF |
2490 | /* Check to see if we have hit the member functions yet. */ |
2491 | if (p[1] == ':') | |
2492 | { | |
2493 | break; | |
2494 | } | |
2495 | read_one_struct_field (fip, pp, p, type, objfile); | |
2496 | } | |
e9935d43 | 2497 | if (p[0] == ':' && p[1] == ':') |
d07734e3 | 2498 | { |
e7177cc2 FF |
2499 | /* chill the list of fields: the last entry (at the head) is a |
2500 | partially constructed entry which we now scrub. */ | |
2501 | fip -> list = fip -> list -> next; | |
d07734e3 | 2502 | } |
2a021f21 | 2503 | return 1; |
e7177cc2 | 2504 | } |
d07734e3 | 2505 | |
e7177cc2 FF |
2506 | /* The stabs for C++ derived classes contain baseclass information which |
2507 | is marked by a '!' character after the total size. This function is | |
2508 | called when we encounter the baseclass marker, and slurps up all the | |
2509 | baseclass information. | |
2510 | ||
2511 | Immediately following the '!' marker is the number of base classes that | |
2512 | the class is derived from, followed by information for each base class. | |
2513 | For each base class, there are two visibility specifiers, a bit offset | |
2514 | to the base class information within the derived class, a reference to | |
2515 | the type for the base class, and a terminating semicolon. | |
2516 | ||
2517 | A typical example, with two base classes, would be "!2,020,19;0264,21;". | |
2518 | ^^ ^ ^ ^ ^ ^ ^ | |
2519 | Baseclass information marker __________________|| | | | | | | | |
2520 | Number of baseclasses __________________________| | | | | | | | |
2521 | Visibility specifiers (2) ________________________| | | | | | | |
2522 | Offset in bits from start of class _________________| | | | | | |
2523 | Type number for base class ___________________________| | | | | |
2524 | Visibility specifiers (2) _______________________________| | | | |
2525 | Offset in bits from start of class ________________________| | | |
2526 | Type number of base class ____________________________________| | |
ea753d03 JK |
2527 | |
2528 | Return 1 for success, 0 for (error-type-inducing) failure. */ | |
e7177cc2 FF |
2529 | |
2530 | static int | |
2531 | read_baseclasses (fip, pp, type, objfile) | |
2532 | struct field_info *fip; | |
2533 | char **pp; | |
2534 | struct type *type; | |
2535 | struct objfile *objfile; | |
2536 | { | |
2537 | int i; | |
2538 | struct nextfield *new; | |
d07734e3 | 2539 | |
e7177cc2 FF |
2540 | if (**pp != '!') |
2541 | { | |
2a021f21 | 2542 | return 1; |
e7177cc2 FF |
2543 | } |
2544 | else | |
d07734e3 | 2545 | { |
e7177cc2 FF |
2546 | /* Skip the '!' baseclass information marker. */ |
2547 | (*pp)++; | |
2548 | } | |
d07734e3 | 2549 | |
e7177cc2 | 2550 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
ea753d03 JK |
2551 | { |
2552 | int nbits; | |
2553 | TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits); | |
2554 | if (nbits != 0) | |
2555 | return 0; | |
2556 | } | |
d07734e3 | 2557 | |
e7177cc2 FF |
2558 | #if 0 |
2559 | /* Some stupid compilers have trouble with the following, so break | |
2560 | it up into simpler expressions. */ | |
2561 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) | |
2562 | TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); | |
2563 | #else | |
2564 | { | |
2565 | int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type)); | |
2566 | char *pointer; | |
d07734e3 | 2567 | |
e7177cc2 FF |
2568 | pointer = (char *) TYPE_ALLOC (type, num_bytes); |
2569 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; | |
2570 | } | |
2571 | #endif /* 0 */ | |
d07734e3 | 2572 | |
e7177cc2 | 2573 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); |
d07734e3 | 2574 | |
e7177cc2 FF |
2575 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
2576 | { | |
2577 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
2578 | make_cleanup (free, new); | |
2579 | memset (new, 0, sizeof (struct nextfield)); | |
2580 | new -> next = fip -> list; | |
2581 | fip -> list = new; | |
2582 | new -> field.bitsize = 0; /* this should be an unpacked field! */ | |
d07734e3 | 2583 | |
e7177cc2 | 2584 | STABS_CONTINUE (pp); |
1dfaef62 | 2585 | switch (**pp) |
e7177cc2 FF |
2586 | { |
2587 | case '0': | |
2588 | /* Nothing to do. */ | |
2589 | break; | |
2590 | case '1': | |
2591 | SET_TYPE_FIELD_VIRTUAL (type, i); | |
2592 | break; | |
2593 | default: | |
1dfaef62 JK |
2594 | /* Unknown character. Complain and treat it as non-virtual. */ |
2595 | { | |
2596 | static struct complaint msg = { | |
2597 | "Unknown virtual character `%c' for baseclass", 0, 0}; | |
2598 | complain (&msg, **pp); | |
2599 | } | |
e7177cc2 | 2600 | } |
1dfaef62 | 2601 | ++(*pp); |
d07734e3 | 2602 | |
e7177cc2 FF |
2603 | new -> visibility = *(*pp)++; |
2604 | switch (new -> visibility) | |
2605 | { | |
2606 | case VISIBILITY_PRIVATE: | |
2607 | case VISIBILITY_PROTECTED: | |
2608 | case VISIBILITY_PUBLIC: | |
2609 | break; | |
2610 | default: | |
1dfaef62 JK |
2611 | /* Bad visibility format. Complain and treat it as |
2612 | public. */ | |
2613 | { | |
2614 | static struct complaint msg = { | |
2615 | "Unknown visibility `%c' for baseclass", 0, 0}; | |
2616 | complain (&msg, new -> visibility); | |
2617 | new -> visibility = VISIBILITY_PUBLIC; | |
2618 | } | |
e7177cc2 | 2619 | } |
d07734e3 | 2620 | |
ea753d03 JK |
2621 | { |
2622 | int nbits; | |
2623 | ||
2624 | /* The remaining value is the bit offset of the portion of the object | |
2625 | corresponding to this baseclass. Always zero in the absence of | |
2626 | multiple inheritance. */ | |
d07734e3 | 2627 | |
ea753d03 JK |
2628 | new -> field.bitpos = read_huge_number (pp, ',', &nbits); |
2629 | if (nbits != 0) | |
2630 | return 0; | |
2631 | } | |
d07734e3 | 2632 | |
ea753d03 JK |
2633 | /* The last piece of baseclass information is the type of the |
2634 | base class. Read it, and remember it's type name as this | |
2635 | field's name. */ | |
d07734e3 | 2636 | |
e7177cc2 FF |
2637 | new -> field.type = read_type (pp, objfile); |
2638 | new -> field.name = type_name_no_tag (new -> field.type); | |
d07734e3 | 2639 | |
e7177cc2 | 2640 | /* skip trailing ';' and bump count of number of fields seen */ |
ea753d03 JK |
2641 | if (**pp == ';') |
2642 | (*pp)++; | |
2643 | else | |
2644 | return 0; | |
d07734e3 | 2645 | } |
2a021f21 | 2646 | return 1; |
e7177cc2 | 2647 | } |
d07734e3 | 2648 | |
2a021f21 JG |
2649 | /* The tail end of stabs for C++ classes that contain a virtual function |
2650 | pointer contains a tilde, a %, and a type number. | |
2651 | The type number refers to the base class (possibly this class itself) which | |
2652 | contains the vtable pointer for the current class. | |
2653 | ||
2654 | This function is called when we have parsed all the method declarations, | |
2655 | so we can look for the vptr base class info. */ | |
2656 | ||
e7177cc2 FF |
2657 | static int |
2658 | read_tilde_fields (fip, pp, type, objfile) | |
2659 | struct field_info *fip; | |
2660 | char **pp; | |
2661 | struct type *type; | |
2662 | struct objfile *objfile; | |
2663 | { | |
2664 | register char *p; | |
d07734e3 | 2665 | |
e7177cc2 | 2666 | STABS_CONTINUE (pp); |
d07734e3 | 2667 | |
e7177cc2 FF |
2668 | /* If we are positioned at a ';', then skip it. */ |
2669 | if (**pp == ';') | |
d07734e3 | 2670 | { |
e7177cc2 | 2671 | (*pp)++; |
d07734e3 FF |
2672 | } |
2673 | ||
d07734e3 FF |
2674 | if (**pp == '~') |
2675 | { | |
e7177cc2 | 2676 | (*pp)++; |
d07734e3 FF |
2677 | |
2678 | if (**pp == '=' || **pp == '+' || **pp == '-') | |
2679 | { | |
2680 | /* Obsolete flags that used to indicate the presence | |
2681 | of constructors and/or destructors. */ | |
e7177cc2 | 2682 | (*pp)++; |
d07734e3 FF |
2683 | } |
2684 | ||
2685 | /* Read either a '%' or the final ';'. */ | |
2686 | if (*(*pp)++ == '%') | |
2687 | { | |
2a021f21 JG |
2688 | /* The next number is the type number of the base class |
2689 | (possibly our own class) which supplies the vtable for | |
2690 | this class. Parse it out, and search that class to find | |
2691 | its vtable pointer, and install those into TYPE_VPTR_BASETYPE | |
2692 | and TYPE_VPTR_FIELDNO. */ | |
d07734e3 FF |
2693 | |
2694 | struct type *t; | |
2695 | int i; | |
2696 | ||
d07734e3 FF |
2697 | t = read_type (pp, objfile); |
2698 | p = (*pp)++; | |
2699 | while (*p != '\0' && *p != ';') | |
e7177cc2 FF |
2700 | { |
2701 | p++; | |
2702 | } | |
d07734e3 | 2703 | if (*p == '\0') |
e7177cc2 FF |
2704 | { |
2705 | /* Premature end of symbol. */ | |
2a021f21 | 2706 | return 0; |
e7177cc2 | 2707 | } |
d07734e3 FF |
2708 | |
2709 | TYPE_VPTR_BASETYPE (type) = t; | |
2a021f21 | 2710 | if (type == t) /* Our own class provides vtbl ptr */ |
d07734e3 | 2711 | { |
2a021f21 JG |
2712 | for (i = TYPE_NFIELDS (t) - 1; |
2713 | i >= TYPE_N_BASECLASSES (t); | |
2714 | --i) | |
d07734e3 | 2715 | { |
2a021f21 JG |
2716 | if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name, |
2717 | sizeof (vptr_name) - 1)) | |
e7177cc2 | 2718 | { |
2a021f21 JG |
2719 | TYPE_VPTR_FIELDNO (type) = i; |
2720 | goto gotit; | |
e7177cc2 FF |
2721 | } |
2722 | } | |
2a021f21 | 2723 | /* Virtual function table field not found. */ |
b646b438 | 2724 | complain (&vtbl_notfound_complaint, TYPE_NAME (type)); |
2a021f21 | 2725 | return 0; |
d07734e3 FF |
2726 | } |
2727 | else | |
e7177cc2 FF |
2728 | { |
2729 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
2730 | } | |
d07734e3 | 2731 | |
2a021f21 | 2732 | gotit: |
d07734e3 FF |
2733 | *pp = p + 1; |
2734 | } | |
2735 | } | |
2a021f21 | 2736 | return 1; |
e7177cc2 | 2737 | } |
d07734e3 | 2738 | |
e7177cc2 FF |
2739 | static int |
2740 | attach_fn_fields_to_type (fip, type) | |
2741 | struct field_info *fip; | |
2742 | register struct type *type; | |
2743 | { | |
2744 | register int n; | |
2745 | ||
2746 | for (n = 0; n < TYPE_N_BASECLASSES (type); n++) | |
2747 | { | |
2748 | if (TYPE_CODE (TYPE_BASECLASS (type, n)) == TYPE_CODE_UNDEF) | |
2749 | { | |
2750 | /* @@ Memory leak on objfile -> type_obstack? */ | |
2a021f21 | 2751 | return 0; |
e7177cc2 FF |
2752 | } |
2753 | TYPE_NFN_FIELDS_TOTAL (type) += | |
2754 | TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, n)); | |
2755 | } | |
2756 | ||
2757 | for (n = TYPE_NFN_FIELDS (type); | |
2758 | fip -> fnlist != NULL; | |
2759 | fip -> fnlist = fip -> fnlist -> next) | |
2760 | { | |
2761 | --n; /* Circumvent Sun3 compiler bug */ | |
2762 | TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist; | |
2763 | } | |
2a021f21 | 2764 | return 1; |
e7177cc2 FF |
2765 | } |
2766 | ||
2767 | /* Create the vector of fields, and record how big it is. | |
2768 | We need this info to record proper virtual function table information | |
2769 | for this class's virtual functions. */ | |
2770 | ||
2771 | static int | |
2772 | attach_fields_to_type (fip, type, objfile) | |
2773 | struct field_info *fip; | |
2774 | register struct type *type; | |
2775 | struct objfile *objfile; | |
2776 | { | |
2777 | register int nfields = 0; | |
2778 | register int non_public_fields = 0; | |
2779 | register struct nextfield *scan; | |
2780 | ||
2781 | /* Count up the number of fields that we have, as well as taking note of | |
2782 | whether or not there are any non-public fields, which requires us to | |
2783 | allocate and build the private_field_bits and protected_field_bits | |
2784 | bitfields. */ | |
2785 | ||
2786 | for (scan = fip -> list; scan != NULL; scan = scan -> next) | |
2787 | { | |
2788 | nfields++; | |
2789 | if (scan -> visibility != VISIBILITY_PUBLIC) | |
2790 | { | |
2791 | non_public_fields++; | |
2792 | } | |
2793 | } | |
2794 | ||
2795 | /* Now we know how many fields there are, and whether or not there are any | |
2796 | non-public fields. Record the field count, allocate space for the | |
2797 | array of fields, and create blank visibility bitfields if necessary. */ | |
2798 | ||
2799 | TYPE_NFIELDS (type) = nfields; | |
2800 | TYPE_FIELDS (type) = (struct field *) | |
2801 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
2802 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
2803 | ||
2804 | if (non_public_fields) | |
2805 | { | |
2806 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
2807 | ||
2808 | TYPE_FIELD_PRIVATE_BITS (type) = | |
2809 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
2810 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
2811 | ||
2812 | TYPE_FIELD_PROTECTED_BITS (type) = | |
2813 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
2814 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
024f65b1 KH |
2815 | |
2816 | TYPE_FIELD_IGNORE_BITS (type) = | |
2817 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
2818 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
e7177cc2 FF |
2819 | } |
2820 | ||
2821 | /* Copy the saved-up fields into the field vector. Start from the head | |
2822 | of the list, adding to the tail of the field array, so that they end | |
2823 | up in the same order in the array in which they were added to the list. */ | |
2824 | ||
2825 | while (nfields-- > 0) | |
2826 | { | |
2827 | TYPE_FIELD (type, nfields) = fip -> list -> field; | |
2828 | switch (fip -> list -> visibility) | |
2829 | { | |
2830 | case VISIBILITY_PRIVATE: | |
2831 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
2832 | break; | |
2833 | ||
2834 | case VISIBILITY_PROTECTED: | |
2835 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
2836 | break; | |
2837 | ||
024f65b1 KH |
2838 | case VISIBILITY_IGNORE: |
2839 | SET_TYPE_FIELD_IGNORE (type, nfields); | |
1dfaef62 | 2840 | break; |
024f65b1 | 2841 | |
e7177cc2 FF |
2842 | case VISIBILITY_PUBLIC: |
2843 | break; | |
2844 | ||
2845 | default: | |
1dfaef62 JK |
2846 | /* Unknown visibility. Complain and treat it as public. */ |
2847 | { | |
2848 | static struct complaint msg = { | |
2849 | "Unknown visibility `%c' for field", 0, 0}; | |
2850 | complain (&msg, fip -> list -> visibility); | |
2851 | } | |
e7177cc2 FF |
2852 | break; |
2853 | } | |
2854 | fip -> list = fip -> list -> next; | |
2855 | } | |
2a021f21 | 2856 | return 1; |
e7177cc2 FF |
2857 | } |
2858 | ||
2859 | /* Read the description of a structure (or union type) and return an object | |
2860 | describing the type. | |
2861 | ||
2862 | PP points to a character pointer that points to the next unconsumed token | |
2863 | in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", | |
2864 | *PP will point to "4a:1,0,32;;". | |
2865 | ||
2866 | TYPE points to an incomplete type that needs to be filled in. | |
2867 | ||
2868 | OBJFILE points to the current objfile from which the stabs information is | |
2869 | being read. (Note that it is redundant in that TYPE also contains a pointer | |
2870 | to this same objfile, so it might be a good idea to eliminate it. FIXME). | |
2871 | */ | |
2872 | ||
2873 | static struct type * | |
2874 | read_struct_type (pp, type, objfile) | |
2875 | char **pp; | |
2876 | struct type *type; | |
2877 | struct objfile *objfile; | |
2878 | { | |
2879 | struct cleanup *back_to; | |
2880 | struct field_info fi; | |
2881 | ||
2882 | fi.list = NULL; | |
2883 | fi.fnlist = NULL; | |
2884 | ||
2885 | back_to = make_cleanup (null_cleanup, 0); | |
2886 | ||
2887 | INIT_CPLUS_SPECIFIC (type); | |
2888 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; | |
2889 | ||
2890 | /* First comes the total size in bytes. */ | |
2891 | ||
ea753d03 JK |
2892 | { |
2893 | int nbits; | |
2894 | TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits); | |
2895 | if (nbits != 0) | |
2896 | return error_type (pp); | |
2897 | } | |
e7177cc2 FF |
2898 | |
2899 | /* Now read the baseclasses, if any, read the regular C struct or C++ | |
2900 | class member fields, attach the fields to the type, read the C++ | |
2901 | member functions, attach them to the type, and then read any tilde | |
dd469789 JG |
2902 | field (baseclass specifier for the class holding the main vtable). */ |
2903 | ||
8a177da6 PB |
2904 | if (!read_baseclasses (&fi, pp, type, objfile) |
2905 | || !read_struct_fields (&fi, pp, type, objfile) | |
2906 | || !attach_fields_to_type (&fi, type, objfile) | |
2907 | || !read_member_functions (&fi, pp, type, objfile) | |
2908 | || !attach_fn_fields_to_type (&fi, type) | |
2909 | || !read_tilde_fields (&fi, pp, type, objfile)) | |
e7177cc2 FF |
2910 | { |
2911 | do_cleanups (back_to); | |
2912 | return (error_type (pp)); | |
2913 | } | |
2914 | ||
2915 | do_cleanups (back_to); | |
2916 | return (type); | |
d07734e3 FF |
2917 | } |
2918 | ||
2919 | /* Read a definition of an array type, | |
2920 | and create and return a suitable type object. | |
2921 | Also creates a range type which represents the bounds of that | |
2922 | array. */ | |
2923 | ||
2924 | static struct type * | |
2925 | read_array_type (pp, type, objfile) | |
2926 | register char **pp; | |
2927 | register struct type *type; | |
2928 | struct objfile *objfile; | |
2929 | { | |
2930 | struct type *index_type, *element_type, *range_type; | |
2931 | int lower, upper; | |
2932 | int adjustable = 0; | |
ea753d03 | 2933 | int nbits; |
d07734e3 FF |
2934 | |
2935 | /* Format of an array type: | |
25200748 JK |
2936 | "ar<index type>;lower;upper;<array_contents_type>". |
2937 | OS9000: "arlower,upper;<array_contents_type>". | |
d07734e3 FF |
2938 | |
2939 | Fortran adjustable arrays use Adigits or Tdigits for lower or upper; | |
2940 | for these, produce a type like float[][]. */ | |
2941 | ||
25200748 JK |
2942 | if (os9k_stabs) |
2943 | index_type = builtin_type_int; | |
2944 | else | |
2945 | { | |
2946 | index_type = read_type (pp, objfile); | |
2947 | if (**pp != ';') | |
2948 | /* Improper format of array type decl. */ | |
2949 | return error_type (pp); | |
2950 | ++*pp; | |
2951 | } | |
d07734e3 | 2952 | |
11b959da | 2953 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') |
d07734e3 | 2954 | { |
e7177cc2 | 2955 | (*pp)++; |
d07734e3 FF |
2956 | adjustable = 1; |
2957 | } | |
25200748 | 2958 | lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits); |
ea753d03 JK |
2959 | if (nbits != 0) |
2960 | return error_type (pp); | |
d07734e3 | 2961 | |
11b959da | 2962 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') |
d07734e3 | 2963 | { |
e7177cc2 | 2964 | (*pp)++; |
d07734e3 FF |
2965 | adjustable = 1; |
2966 | } | |
ea753d03 JK |
2967 | upper = read_huge_number (pp, ';', &nbits); |
2968 | if (nbits != 0) | |
2969 | return error_type (pp); | |
d07734e3 FF |
2970 | |
2971 | element_type = read_type (pp, objfile); | |
2972 | ||
2973 | if (adjustable) | |
2974 | { | |
2975 | lower = 0; | |
2976 | upper = -1; | |
2977 | } | |
2978 | ||
a8a69e63 FF |
2979 | range_type = |
2980 | create_range_type ((struct type *) NULL, index_type, lower, upper); | |
2981 | type = create_array_type (type, element_type, range_type); | |
d07734e3 FF |
2982 | |
2983 | /* If we have an array whose element type is not yet known, but whose | |
2984 | bounds *are* known, record it to be adjusted at the end of the file. */ | |
dda398c3 JK |
2985 | /* FIXME: Why check for zero length rather than TYPE_FLAG_STUB? I think |
2986 | the two have the same effect except that the latter is cleaner and the | |
2987 | former would be wrong for types which really are zero-length (if we | |
2988 | have any). */ | |
85f0a848 | 2989 | |
d07734e3 | 2990 | if (TYPE_LENGTH (element_type) == 0 && !adjustable) |
85f0a848 | 2991 | { |
dda398c3 | 2992 | TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB; |
85f0a848 FF |
2993 | add_undefined_type (type); |
2994 | } | |
d07734e3 FF |
2995 | |
2996 | return type; | |
2997 | } | |
2998 | ||
2999 | ||
3000 | /* Read a definition of an enumeration type, | |
3001 | and create and return a suitable type object. | |
3002 | Also defines the symbols that represent the values of the type. */ | |
3003 | ||
3004 | static struct type * | |
3005 | read_enum_type (pp, type, objfile) | |
3006 | register char **pp; | |
3007 | register struct type *type; | |
3008 | struct objfile *objfile; | |
3009 | { | |
3010 | register char *p; | |
3011 | char *name; | |
3012 | register long n; | |
3013 | register struct symbol *sym; | |
3014 | int nsyms = 0; | |
3015 | struct pending **symlist; | |
3016 | struct pending *osyms, *syms; | |
3017 | int o_nsyms; | |
25200748 | 3018 | int nbits; |
d07734e3 FF |
3019 | |
3020 | #if 0 | |
3021 | /* FIXME! The stabs produced by Sun CC merrily define things that ought | |
3022 | to be file-scope, between N_FN entries, using N_LSYM. What's a mother | |
3023 | to do? For now, force all enum values to file scope. */ | |
3024 | if (within_function) | |
3025 | symlist = &local_symbols; | |
3026 | else | |
3027 | #endif | |
3028 | symlist = &file_symbols; | |
3029 | osyms = *symlist; | |
3030 | o_nsyms = osyms ? osyms->nsyms : 0; | |
3031 | ||
25200748 JK |
3032 | if (os9k_stabs) |
3033 | { | |
3034 | /* Size. Perhaps this does not have to be conditionalized on | |
3035 | os9k_stabs (assuming the name of an enum constant can't start | |
3036 | with a digit). */ | |
3037 | read_huge_number (pp, 0, &nbits); | |
3038 | if (nbits != 0) | |
3039 | return error_type (pp); | |
3040 | } | |
3041 | ||
d07734e3 FF |
3042 | /* Read the value-names and their values. |
3043 | The input syntax is NAME:VALUE,NAME:VALUE, and so on. | |
3044 | A semicolon or comma instead of a NAME means the end. */ | |
3045 | while (**pp && **pp != ';' && **pp != ',') | |
3046 | { | |
e7177cc2 | 3047 | STABS_CONTINUE (pp); |
d07734e3 FF |
3048 | p = *pp; |
3049 | while (*p != ':') p++; | |
3050 | name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack); | |
3051 | *pp = p + 1; | |
ea753d03 JK |
3052 | n = read_huge_number (pp, ',', &nbits); |
3053 | if (nbits != 0) | |
3054 | return error_type (pp); | |
d07734e3 | 3055 | |
c02a37ea FF |
3056 | sym = (struct symbol *) |
3057 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); | |
d07734e3 FF |
3058 | memset (sym, 0, sizeof (struct symbol)); |
3059 | SYMBOL_NAME (sym) = name; | |
2e4964ad | 3060 | SYMBOL_LANGUAGE (sym) = current_subfile -> language; |
d07734e3 FF |
3061 | SYMBOL_CLASS (sym) = LOC_CONST; |
3062 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3063 | SYMBOL_VALUE (sym) = n; | |
3064 | add_symbol_to_list (sym, symlist); | |
3065 | nsyms++; | |
3066 | } | |
3067 | ||
3068 | if (**pp == ';') | |
3069 | (*pp)++; /* Skip the semicolon. */ | |
3070 | ||
3071 | /* Now fill in the fields of the type-structure. */ | |
3072 | ||
eaba7fae | 3073 | TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT; |
d07734e3 FF |
3074 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
3075 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; | |
3076 | TYPE_NFIELDS (type) = nsyms; | |
3077 | TYPE_FIELDS (type) = (struct field *) | |
dac9734e | 3078 | TYPE_ALLOC (type, sizeof (struct field) * nsyms); |
c02a37ea | 3079 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms); |
d07734e3 FF |
3080 | |
3081 | /* Find the symbols for the values and put them into the type. | |
3082 | The symbols can be found in the symlist that we put them on | |
3083 | to cause them to be defined. osyms contains the old value | |
3084 | of that symlist; everything up to there was defined by us. */ | |
3085 | /* Note that we preserve the order of the enum constants, so | |
3086 | that in something like "enum {FOO, LAST_THING=FOO}" we print | |
3087 | FOO, not LAST_THING. */ | |
3088 | ||
3089 | for (syms = *symlist, n = 0; syms; syms = syms->next) | |
3090 | { | |
3091 | int j = 0; | |
3092 | if (syms == osyms) | |
3093 | j = o_nsyms; | |
3094 | for (; j < syms->nsyms; j++,n++) | |
3095 | { | |
3096 | struct symbol *xsym = syms->symbol[j]; | |
3097 | SYMBOL_TYPE (xsym) = type; | |
3098 | TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); | |
3099 | TYPE_FIELD_VALUE (type, n) = 0; | |
3100 | TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); | |
3101 | TYPE_FIELD_BITSIZE (type, n) = 0; | |
3102 | } | |
3103 | if (syms == osyms) | |
3104 | break; | |
3105 | } | |
3106 | ||
d07734e3 FF |
3107 | return type; |
3108 | } | |
3109 | ||
3110 | /* Sun's ACC uses a somewhat saner method for specifying the builtin | |
3111 | typedefs in every file (for int, long, etc): | |
3112 | ||
3113 | type = b <signed> <width>; <offset>; <nbits> | |
3114 | signed = u or s. Possible c in addition to u or s (for char?). | |
3115 | offset = offset from high order bit to start bit of type. | |
3116 | width is # bytes in object of this type, nbits is # bits in type. | |
3117 | ||
3118 | The width/offset stuff appears to be for small objects stored in | |
3119 | larger ones (e.g. `shorts' in `int' registers). We ignore it for now, | |
3120 | FIXME. */ | |
3121 | ||
3122 | static struct type * | |
3123 | read_sun_builtin_type (pp, typenums, objfile) | |
3124 | char **pp; | |
3125 | int typenums[2]; | |
3126 | struct objfile *objfile; | |
3127 | { | |
ea753d03 | 3128 | int type_bits; |
d07734e3 FF |
3129 | int nbits; |
3130 | int signed_type; | |
3131 | ||
3132 | switch (**pp) | |
3133 | { | |
3134 | case 's': | |
3135 | signed_type = 1; | |
3136 | break; | |
3137 | case 'u': | |
3138 | signed_type = 0; | |
3139 | break; | |
3140 | default: | |
3141 | return error_type (pp); | |
3142 | } | |
3143 | (*pp)++; | |
3144 | ||
3145 | /* For some odd reason, all forms of char put a c here. This is strange | |
3146 | because no other type has this honor. We can safely ignore this because | |
3147 | we actually determine 'char'acterness by the number of bits specified in | |
3148 | the descriptor. */ | |
3149 | ||
3150 | if (**pp == 'c') | |
3151 | (*pp)++; | |
3152 | ||
3153 | /* The first number appears to be the number of bytes occupied | |
3154 | by this type, except that unsigned short is 4 instead of 2. | |
3155 | Since this information is redundant with the third number, | |
3156 | we will ignore it. */ | |
ea753d03 JK |
3157 | read_huge_number (pp, ';', &nbits); |
3158 | if (nbits != 0) | |
3159 | return error_type (pp); | |
d07734e3 FF |
3160 | |
3161 | /* The second number is always 0, so ignore it too. */ | |
ea753d03 JK |
3162 | read_huge_number (pp, ';', &nbits); |
3163 | if (nbits != 0) | |
3164 | return error_type (pp); | |
d07734e3 FF |
3165 | |
3166 | /* The third number is the number of bits for this type. */ | |
ea753d03 JK |
3167 | type_bits = read_huge_number (pp, 0, &nbits); |
3168 | if (nbits != 0) | |
3169 | return error_type (pp); | |
159ada02 JK |
3170 | /* The type *should* end with a semicolon. If it are embedded |
3171 | in a larger type the semicolon may be the only way to know where | |
3172 | the type ends. If this type is at the end of the stabstring we | |
3173 | can deal with the omitted semicolon (but we don't have to like | |
3174 | it). Don't bother to complain(), Sun's compiler omits the semicolon | |
3175 | for "void". */ | |
3176 | if (**pp == ';') | |
3177 | ++(*pp); | |
d07734e3 | 3178 | |
2f3b7d8e JK |
3179 | if (type_bits == 0) |
3180 | return init_type (TYPE_CODE_VOID, 1, | |
3181 | signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL, | |
3182 | objfile); | |
3183 | else | |
3184 | return init_type (TYPE_CODE_INT, | |
3185 | type_bits / TARGET_CHAR_BIT, | |
3186 | signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL, | |
3187 | objfile); | |
d07734e3 FF |
3188 | } |
3189 | ||
3190 | static struct type * | |
3191 | read_sun_floating_type (pp, typenums, objfile) | |
3192 | char **pp; | |
3193 | int typenums[2]; | |
3194 | struct objfile *objfile; | |
3195 | { | |
ea753d03 | 3196 | int nbits; |
f52bde21 | 3197 | int details; |
d07734e3 FF |
3198 | int nbytes; |
3199 | ||
3200 | /* The first number has more details about the type, for example | |
f52bde21 | 3201 | FN_COMPLEX. */ |
ea753d03 JK |
3202 | details = read_huge_number (pp, ';', &nbits); |
3203 | if (nbits != 0) | |
3204 | return error_type (pp); | |
d07734e3 FF |
3205 | |
3206 | /* The second number is the number of bytes occupied by this type */ | |
ea753d03 JK |
3207 | nbytes = read_huge_number (pp, ';', &nbits); |
3208 | if (nbits != 0) | |
3209 | return error_type (pp); | |
d07734e3 | 3210 | |
ea753d03 | 3211 | if (details == NF_COMPLEX || details == NF_COMPLEX16 |
f52bde21 JK |
3212 | || details == NF_COMPLEX32) |
3213 | /* This is a type we can't handle, but we do know the size. | |
3214 | We also will be able to give it a name. */ | |
3215 | return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile); | |
d07734e3 | 3216 | |
f52bde21 | 3217 | return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile); |
d07734e3 FF |
3218 | } |
3219 | ||
3220 | /* Read a number from the string pointed to by *PP. | |
3221 | The value of *PP is advanced over the number. | |
3222 | If END is nonzero, the character that ends the | |
3223 | number must match END, or an error happens; | |
3224 | and that character is skipped if it does match. | |
3225 | If END is zero, *PP is left pointing to that character. | |
3226 | ||
ea753d03 JK |
3227 | If the number fits in a long, set *BITS to 0 and return the value. |
3228 | If not, set *BITS to be the number of bits in the number and return 0. | |
d07734e3 | 3229 | |
ea753d03 | 3230 | If encounter garbage, set *BITS to -1 and return 0. */ |
d07734e3 | 3231 | |
ea753d03 JK |
3232 | static long |
3233 | read_huge_number (pp, end, bits) | |
d07734e3 FF |
3234 | char **pp; |
3235 | int end; | |
d07734e3 FF |
3236 | int *bits; |
3237 | { | |
3238 | char *p = *pp; | |
3239 | int sign = 1; | |
3240 | long n = 0; | |
3241 | int radix = 10; | |
3242 | char overflow = 0; | |
3243 | int nbits = 0; | |
3244 | int c; | |
3245 | long upper_limit; | |
3246 | ||
3247 | if (*p == '-') | |
3248 | { | |
3249 | sign = -1; | |
3250 | p++; | |
3251 | } | |
3252 | ||
3253 | /* Leading zero means octal. GCC uses this to output values larger | |
3254 | than an int (because that would be hard in decimal). */ | |
3255 | if (*p == '0') | |
3256 | { | |
3257 | radix = 8; | |
3258 | p++; | |
3259 | } | |
3260 | ||
3261 | upper_limit = LONG_MAX / radix; | |
574a2a49 | 3262 | while ((c = *p++) >= '0' && c < ('0' + radix)) |
d07734e3 FF |
3263 | { |
3264 | if (n <= upper_limit) | |
3265 | { | |
3266 | n *= radix; | |
3267 | n += c - '0'; /* FIXME this overflows anyway */ | |
3268 | } | |
3269 | else | |
3270 | overflow = 1; | |
3271 | ||
3272 | /* This depends on large values being output in octal, which is | |
3273 | what GCC does. */ | |
3274 | if (radix == 8) | |
3275 | { | |
3276 | if (nbits == 0) | |
3277 | { | |
3278 | if (c == '0') | |
3279 | /* Ignore leading zeroes. */ | |
3280 | ; | |
3281 | else if (c == '1') | |
3282 | nbits = 1; | |
3283 | else if (c == '2' || c == '3') | |
3284 | nbits = 2; | |
3285 | else | |
3286 | nbits = 3; | |
3287 | } | |
3288 | else | |
3289 | nbits += 3; | |
3290 | } | |
3291 | } | |
3292 | if (end) | |
3293 | { | |
3294 | if (c && c != end) | |
3295 | { | |
3296 | if (bits != NULL) | |
3297 | *bits = -1; | |
996ccb30 | 3298 | return 0; |
d07734e3 FF |
3299 | } |
3300 | } | |
3301 | else | |
3302 | --p; | |
3303 | ||
3304 | *pp = p; | |
3305 | if (overflow) | |
3306 | { | |
3307 | if (nbits == 0) | |
3308 | { | |
3309 | /* Large decimal constants are an error (because it is hard to | |
3310 | count how many bits are in them). */ | |
3311 | if (bits != NULL) | |
3312 | *bits = -1; | |
996ccb30 | 3313 | return 0; |
d07734e3 FF |
3314 | } |
3315 | ||
3316 | /* -0x7f is the same as 0x80. So deal with it by adding one to | |
3317 | the number of bits. */ | |
3318 | if (sign == -1) | |
3319 | ++nbits; | |
3320 | if (bits) | |
3321 | *bits = nbits; | |
3322 | } | |
3323 | else | |
3324 | { | |
d07734e3 FF |
3325 | if (bits) |
3326 | *bits = 0; | |
ea753d03 | 3327 | return n * sign; |
d07734e3 | 3328 | } |
ea753d03 JK |
3329 | /* It's *BITS which has the interesting information. */ |
3330 | return 0; | |
d07734e3 FF |
3331 | } |
3332 | ||
3333 | static struct type * | |
3334 | read_range_type (pp, typenums, objfile) | |
3335 | char **pp; | |
3336 | int typenums[2]; | |
3337 | struct objfile *objfile; | |
3338 | { | |
3339 | int rangenums[2]; | |
3340 | long n2, n3; | |
3341 | int n2bits, n3bits; | |
3342 | int self_subrange; | |
3343 | struct type *result_type; | |
a8a69e63 | 3344 | struct type *index_type; |
d07734e3 FF |
3345 | |
3346 | /* First comes a type we are a subrange of. | |
3347 | In C it is usually 0, 1 or the type being defined. */ | |
ea753d03 JK |
3348 | /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id |
3349 | not just a type number. */ | |
3350 | if (read_type_number (pp, rangenums) != 0) | |
3351 | return error_type (pp); | |
d07734e3 FF |
3352 | self_subrange = (rangenums[0] == typenums[0] && |
3353 | rangenums[1] == typenums[1]); | |
3354 | ||
3355 | /* A semicolon should now follow; skip it. */ | |
3356 | if (**pp == ';') | |
3357 | (*pp)++; | |
3358 | ||
3359 | /* The remaining two operands are usually lower and upper bounds | |
3360 | of the range. But in some special cases they mean something else. */ | |
ea753d03 JK |
3361 | n2 = read_huge_number (pp, ';', &n2bits); |
3362 | n3 = read_huge_number (pp, ';', &n3bits); | |
d07734e3 FF |
3363 | |
3364 | if (n2bits == -1 || n3bits == -1) | |
3365 | return error_type (pp); | |
3366 | ||
3367 | /* If limits are huge, must be large integral type. */ | |
3368 | if (n2bits != 0 || n3bits != 0) | |
3369 | { | |
3370 | char got_signed = 0; | |
3371 | char got_unsigned = 0; | |
3372 | /* Number of bits in the type. */ | |
46c28185 | 3373 | int nbits = 0; |
d07734e3 FF |
3374 | |
3375 | /* Range from 0 to <large number> is an unsigned large integral type. */ | |
3376 | if ((n2bits == 0 && n2 == 0) && n3bits != 0) | |
3377 | { | |
3378 | got_unsigned = 1; | |
3379 | nbits = n3bits; | |
3380 | } | |
3381 | /* Range from <large number> to <large number>-1 is a large signed | |
cef4c2e7 PS |
3382 | integral type. Take care of the case where <large number> doesn't |
3383 | fit in a long but <large number>-1 does. */ | |
3384 | else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1) | |
3385 | || (n2bits != 0 && n3bits == 0 | |
3386 | && (n2bits == sizeof (long) * HOST_CHAR_BIT) | |
3387 | && n3 == LONG_MAX)) | |
d07734e3 FF |
3388 | { |
3389 | got_signed = 1; | |
3390 | nbits = n2bits; | |
3391 | } | |
3392 | ||
d07734e3 FF |
3393 | if (got_signed || got_unsigned) |
3394 | { | |
f52bde21 JK |
3395 | return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT, |
3396 | got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL, | |
3397 | objfile); | |
d07734e3 FF |
3398 | } |
3399 | else | |
3400 | return error_type (pp); | |
3401 | } | |
3402 | ||
3403 | /* A type defined as a subrange of itself, with bounds both 0, is void. */ | |
3404 | if (self_subrange && n2 == 0 && n3 == 0) | |
2f3b7d8e | 3405 | return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
d07734e3 FF |
3406 | |
3407 | /* If n3 is zero and n2 is not, we want a floating type, | |
3408 | and n2 is the width in bytes. | |
3409 | ||
3410 | Fortran programs appear to use this for complex types also, | |
3411 | and they give no way to distinguish between double and single-complex! | |
f52bde21 JK |
3412 | |
3413 | GDB does not have complex types. | |
3414 | ||
3415 | Just return the complex as a float of that size. It won't work right | |
ebccb10b | 3416 | for the complex values, but at least it makes the file loadable. */ |
d07734e3 FF |
3417 | |
3418 | if (n3 == 0 && n2 > 0) | |
3419 | { | |
f52bde21 | 3420 | return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile); |
d07734e3 FF |
3421 | } |
3422 | ||
3423 | /* If the upper bound is -1, it must really be an unsigned int. */ | |
3424 | ||
3425 | else if (n2 == 0 && n3 == -1) | |
3426 | { | |
f52bde21 | 3427 | /* It is unsigned int or unsigned long. */ |
78934ba8 JK |
3428 | /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5 |
3429 | compatibility hack. */ | |
f52bde21 JK |
3430 | return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
3431 | TYPE_FLAG_UNSIGNED, NULL, objfile); | |
d07734e3 FF |
3432 | } |
3433 | ||
3434 | /* Special case: char is defined (Who knows why) as a subrange of | |
3435 | itself with range 0-127. */ | |
3436 | else if (self_subrange && n2 == 0 && n3 == 127) | |
f52bde21 JK |
3437 | return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile); |
3438 | ||
3439 | /* We used to do this only for subrange of self or subrange of int. */ | |
3440 | else if (n2 == 0) | |
3441 | { | |
3442 | if (n3 < 0) | |
3443 | /* n3 actually gives the size. */ | |
3444 | return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED, | |
3445 | NULL, objfile); | |
3446 | if (n3 == 0xff) | |
3447 | return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile); | |
3448 | if (n3 == 0xffff) | |
3449 | return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile); | |
3450 | ||
3451 | /* -1 is used for the upper bound of (4 byte) "unsigned int" and | |
3452 | "unsigned long", and we already checked for that, | |
3453 | so don't need to test for it here. */ | |
3454 | } | |
3455 | /* I think this is for Convex "long long". Since I don't know whether | |
3456 | Convex sets self_subrange, I also accept that particular size regardless | |
3457 | of self_subrange. */ | |
3458 | else if (n3 == 0 && n2 < 0 | |
3459 | && (self_subrange | |
3460 | || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT)) | |
3461 | return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile); | |
d07734e3 FF |
3462 | else if (n2 == -n3 -1) |
3463 | { | |
f52bde21 JK |
3464 | if (n3 == 0x7f) |
3465 | return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile); | |
3466 | if (n3 == 0x7fff) | |
3467 | return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile); | |
3468 | if (n3 == 0x7fffffff) | |
3469 | return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile); | |
d07734e3 FF |
3470 | } |
3471 | ||
3472 | /* We have a real range type on our hands. Allocate space and | |
3473 | return a real pointer. */ | |
3474 | ||
3475 | /* At this point I don't have the faintest idea how to deal with | |
3476 | a self_subrange type; I'm going to assume that this is used | |
3477 | as an idiom, and that all of them are special cases. So . . . */ | |
3478 | if (self_subrange) | |
3479 | return error_type (pp); | |
3480 | ||
a8a69e63 FF |
3481 | index_type = *dbx_lookup_type (rangenums); |
3482 | if (index_type == NULL) | |
3483 | { | |
f52bde21 JK |
3484 | /* Does this actually ever happen? Is that why we are worrying |
3485 | about dealing with it rather than just calling error_type? */ | |
3486 | ||
3487 | static struct type *range_type_index; | |
3488 | ||
a8a69e63 | 3489 | complain (&range_type_base_complaint, rangenums[1]); |
f52bde21 JK |
3490 | if (range_type_index == NULL) |
3491 | range_type_index = | |
3492 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
3493 | 0, "range type index type", NULL); | |
3494 | index_type = range_type_index; | |
a8a69e63 | 3495 | } |
d07734e3 | 3496 | |
a8a69e63 FF |
3497 | result_type = create_range_type ((struct type *) NULL, index_type, n2, n3); |
3498 | return (result_type); | |
d07734e3 FF |
3499 | } |
3500 | ||
d07734e3 FF |
3501 | /* Read in an argument list. This is a list of types, separated by commas |
3502 | and terminated with END. Return the list of types read in, or (struct type | |
3503 | **)-1 if there is an error. */ | |
3504 | ||
3505 | static struct type ** | |
3506 | read_args (pp, end, objfile) | |
3507 | char **pp; | |
3508 | int end; | |
3509 | struct objfile *objfile; | |
3510 | { | |
3511 | /* FIXME! Remove this arbitrary limit! */ | |
3512 | struct type *types[1024], **rval; /* allow for fns of 1023 parameters */ | |
3513 | int n = 0; | |
3514 | ||
3515 | while (**pp != end) | |
3516 | { | |
3517 | if (**pp != ',') | |
3518 | /* Invalid argument list: no ','. */ | |
3519 | return (struct type **)-1; | |
e7177cc2 FF |
3520 | (*pp)++; |
3521 | STABS_CONTINUE (pp); | |
d07734e3 FF |
3522 | types[n++] = read_type (pp, objfile); |
3523 | } | |
e7177cc2 | 3524 | (*pp)++; /* get past `end' (the ':' character) */ |
d07734e3 FF |
3525 | |
3526 | if (n == 1) | |
3527 | { | |
3528 | rval = (struct type **) xmalloc (2 * sizeof (struct type *)); | |
3529 | } | |
3530 | else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID) | |
3531 | { | |
3532 | rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *)); | |
3533 | memset (rval + n, 0, sizeof (struct type *)); | |
3534 | } | |
3535 | else | |
3536 | { | |
3537 | rval = (struct type **) xmalloc (n * sizeof (struct type *)); | |
3538 | } | |
3539 | memcpy (rval, types, n * sizeof (struct type *)); | |
3540 | return rval; | |
3541 | } | |
9438d642 JK |
3542 | \f |
3543 | /* Common block handling. */ | |
3544 | ||
3545 | /* List of symbols declared since the last BCOMM. This list is a tail | |
3546 | of local_symbols. When ECOMM is seen, the symbols on the list | |
3547 | are noted so their proper addresses can be filled in later, | |
3548 | using the common block base address gotten from the assembler | |
3549 | stabs. */ | |
3550 | ||
3551 | static struct pending *common_block; | |
3552 | static int common_block_i; | |
3553 | ||
3554 | /* Name of the current common block. We get it from the BCOMM instead of the | |
3555 | ECOMM to match IBM documentation (even though IBM puts the name both places | |
3556 | like everyone else). */ | |
3557 | static char *common_block_name; | |
3558 | ||
3559 | /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed | |
3560 | to remain after this function returns. */ | |
3561 | ||
3562 | void | |
3563 | common_block_start (name, objfile) | |
3564 | char *name; | |
3565 | struct objfile *objfile; | |
3566 | { | |
3567 | if (common_block_name != NULL) | |
3568 | { | |
3569 | static struct complaint msg = { | |
3570 | "Invalid symbol data: common block within common block", | |
3571 | 0, 0}; | |
3572 | complain (&msg); | |
3573 | } | |
3574 | common_block = local_symbols; | |
3575 | common_block_i = local_symbols ? local_symbols->nsyms : 0; | |
3576 | common_block_name = obsavestring (name, strlen (name), | |
3577 | &objfile -> symbol_obstack); | |
3578 | } | |
3579 | ||
3580 | /* Process a N_ECOMM symbol. */ | |
3581 | ||
3582 | void | |
3583 | common_block_end (objfile) | |
3584 | struct objfile *objfile; | |
3585 | { | |
3586 | /* Symbols declared since the BCOMM are to have the common block | |
3587 | start address added in when we know it. common_block and | |
3588 | common_block_i point to the first symbol after the BCOMM in | |
3589 | the local_symbols list; copy the list and hang it off the | |
3590 | symbol for the common block name for later fixup. */ | |
3591 | int i; | |
3592 | struct symbol *sym; | |
3593 | struct pending *new = 0; | |
3594 | struct pending *next; | |
3595 | int j; | |
3596 | ||
3597 | if (common_block_name == NULL) | |
3598 | { | |
3599 | static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0}; | |
3600 | complain (&msg); | |
3601 | return; | |
3602 | } | |
3603 | ||
3604 | sym = (struct symbol *) | |
3605 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); | |
3606 | memset (sym, 0, sizeof (struct symbol)); | |
3607 | SYMBOL_NAME (sym) = common_block_name; | |
3608 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
3609 | ||
3610 | /* Now we copy all the symbols which have been defined since the BCOMM. */ | |
3611 | ||
3612 | /* Copy all the struct pendings before common_block. */ | |
3613 | for (next = local_symbols; | |
3614 | next != NULL && next != common_block; | |
3615 | next = next->next) | |
3616 | { | |
3617 | for (j = 0; j < next->nsyms; j++) | |
3618 | add_symbol_to_list (next->symbol[j], &new); | |
3619 | } | |
3620 | ||
3621 | /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is | |
3622 | NULL, it means copy all the local symbols (which we already did | |
3623 | above). */ | |
3624 | ||
3625 | if (common_block != NULL) | |
3626 | for (j = common_block_i; j < common_block->nsyms; j++) | |
3627 | add_symbol_to_list (common_block->symbol[j], &new); | |
3628 | ||
fddb9bda | 3629 | SYMBOL_TYPE (sym) = (struct type *) new; |
9438d642 JK |
3630 | |
3631 | /* Should we be putting local_symbols back to what it was? | |
3632 | Does it matter? */ | |
3633 | ||
3634 | i = hashname (SYMBOL_NAME (sym)); | |
3635 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; | |
3636 | global_sym_chain[i] = sym; | |
3637 | common_block_name = NULL; | |
3638 | } | |
d07734e3 FF |
3639 | |
3640 | /* Add a common block's start address to the offset of each symbol | |
3641 | declared to be in it (by being between a BCOMM/ECOMM pair that uses | |
3642 | the common block name). */ | |
3643 | ||
3644 | static void | |
3645 | fix_common_block (sym, valu) | |
3646 | struct symbol *sym; | |
3647 | int valu; | |
3648 | { | |
fddb9bda | 3649 | struct pending *next = (struct pending *) SYMBOL_TYPE (sym); |
d07734e3 FF |
3650 | for ( ; next; next = next->next) |
3651 | { | |
3652 | register int j; | |
3653 | for (j = next->nsyms - 1; j >= 0; j--) | |
3654 | SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu; | |
3655 | } | |
3656 | } | |
3657 | ||
3658 | ||
3659 | \f | |
3660 | /* What about types defined as forward references inside of a small lexical | |
3661 | scope? */ | |
3662 | /* Add a type to the list of undefined types to be checked through | |
3663 | once this file has been read in. */ | |
3664 | ||
3665 | void | |
3666 | add_undefined_type (type) | |
3667 | struct type *type; | |
3668 | { | |
3669 | if (undef_types_length == undef_types_allocated) | |
3670 | { | |
3671 | undef_types_allocated *= 2; | |
3672 | undef_types = (struct type **) | |
3673 | xrealloc ((char *) undef_types, | |
3674 | undef_types_allocated * sizeof (struct type *)); | |
3675 | } | |
3676 | undef_types[undef_types_length++] = type; | |
3677 | } | |
3678 | ||
3679 | /* Go through each undefined type, see if it's still undefined, and fix it | |
3680 | up if possible. We have two kinds of undefined types: | |
3681 | ||
3682 | TYPE_CODE_ARRAY: Array whose target type wasn't defined yet. | |
3683 | Fix: update array length using the element bounds | |
3684 | and the target type's length. | |
3685 | TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not | |
3686 | yet defined at the time a pointer to it was made. | |
3687 | Fix: Do a full lookup on the struct/union tag. */ | |
3688 | void | |
3689 | cleanup_undefined_types () | |
3690 | { | |
3691 | struct type **type; | |
3692 | ||
3693 | for (type = undef_types; type < undef_types + undef_types_length; type++) | |
3694 | { | |
3695 | switch (TYPE_CODE (*type)) | |
3696 | { | |
3697 | ||
3698 | case TYPE_CODE_STRUCT: | |
3699 | case TYPE_CODE_UNION: | |
3700 | case TYPE_CODE_ENUM: | |
3701 | { | |
dda398c3 JK |
3702 | /* Check if it has been defined since. Need to do this here |
3703 | as well as in check_stub_type to deal with the (legitimate in | |
3704 | C though not C++) case of several types with the same name | |
3705 | in different source files. */ | |
d07734e3 FF |
3706 | if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB) |
3707 | { | |
3708 | struct pending *ppt; | |
3709 | int i; | |
3710 | /* Name of the type, without "struct" or "union" */ | |
b2bebdb0 | 3711 | char *typename = TYPE_TAG_NAME (*type); |
d07734e3 | 3712 | |
ea753d03 JK |
3713 | if (typename == NULL) |
3714 | { | |
3715 | static struct complaint msg = {"need a type name", 0, 0}; | |
3716 | complain (&msg); | |
3717 | break; | |
3718 | } | |
d07734e3 FF |
3719 | for (ppt = file_symbols; ppt; ppt = ppt->next) |
3720 | { | |
3721 | for (i = 0; i < ppt->nsyms; i++) | |
3722 | { | |
3723 | struct symbol *sym = ppt->symbol[i]; | |
3724 | ||
3725 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF | |
3726 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE | |
3727 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == | |
3728 | TYPE_CODE (*type)) | |
2e4964ad | 3729 | && STREQ (SYMBOL_NAME (sym), typename)) |
d07734e3 FF |
3730 | { |
3731 | memcpy (*type, SYMBOL_TYPE (sym), | |
3732 | sizeof (struct type)); | |
3733 | } | |
3734 | } | |
3735 | } | |
3736 | } | |
3737 | } | |
3738 | break; | |
3739 | ||
dda398c3 | 3740 | case TYPE_CODE_ARRAY: |
d07734e3 | 3741 | { |
dda398c3 JK |
3742 | /* This is a kludge which is here for historical reasons |
3743 | because I suspect that check_stub_type does not get | |
3744 | called everywhere it needs to be called for arrays. Even | |
3745 | with this kludge, those places are broken for the case | |
3746 | where the stub type is defined in another compilation | |
3747 | unit, but this kludge at least deals with it for the case | |
3748 | in which it is the same compilation unit. | |
3749 | ||
3750 | Don't try to do this by calling check_stub_type; it might | |
3751 | cause symbols to be read in lookup_symbol, and the symbol | |
3752 | reader is not reentrant. */ | |
3753 | ||
d07734e3 FF |
3754 | struct type *range_type; |
3755 | int lower, upper; | |
3756 | ||
3757 | if (TYPE_LENGTH (*type) != 0) /* Better be unknown */ | |
3758 | goto badtype; | |
3759 | if (TYPE_NFIELDS (*type) != 1) | |
3760 | goto badtype; | |
3761 | range_type = TYPE_FIELD_TYPE (*type, 0); | |
3762 | if (TYPE_CODE (range_type) != TYPE_CODE_RANGE) | |
3763 | goto badtype; | |
3764 | ||
3765 | /* Now recompute the length of the array type, based on its | |
3766 | number of elements and the target type's length. */ | |
3767 | lower = TYPE_FIELD_BITPOS (range_type, 0); | |
3768 | upper = TYPE_FIELD_BITPOS (range_type, 1); | |
3769 | TYPE_LENGTH (*type) = (upper - lower + 1) | |
3770 | * TYPE_LENGTH (TYPE_TARGET_TYPE (*type)); | |
dda398c3 JK |
3771 | |
3772 | /* If the target type is not a stub, we could be clearing | |
3773 | TYPE_FLAG_TARGET_STUB for *type. */ | |
d07734e3 FF |
3774 | } |
3775 | break; | |
3776 | ||
ea753d03 JK |
3777 | default: |
3778 | badtype: | |
3779 | { | |
3780 | static struct complaint msg = {"\ | |
3781 | GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0}; | |
3782 | complain (&msg, TYPE_CODE (*type)); | |
3783 | } | |
d07734e3 FF |
3784 | break; |
3785 | } | |
3786 | } | |
dda398c3 | 3787 | |
d07734e3 FF |
3788 | undef_types_length = 0; |
3789 | } | |
3790 | ||
3791 | /* Scan through all of the global symbols defined in the object file, | |
3792 | assigning values to the debugging symbols that need to be assigned | |
3793 | to. Get these symbols from the minimal symbol table. */ | |
3794 | ||
3795 | void | |
3796 | scan_file_globals (objfile) | |
3797 | struct objfile *objfile; | |
3798 | { | |
3799 | int hash; | |
3800 | struct minimal_symbol *msymbol; | |
3801 | struct symbol *sym, *prev; | |
3802 | ||
3803 | if (objfile->msymbols == 0) /* Beware the null file. */ | |
3804 | return; | |
3805 | ||
2e4964ad | 3806 | for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++) |
d07734e3 FF |
3807 | { |
3808 | QUIT; | |
3809 | ||
3810 | prev = NULL; | |
3811 | ||
3812 | /* Get the hash index and check all the symbols | |
3813 | under that hash index. */ | |
3814 | ||
2e4964ad | 3815 | hash = hashname (SYMBOL_NAME (msymbol)); |
d07734e3 FF |
3816 | |
3817 | for (sym = global_sym_chain[hash]; sym;) | |
3818 | { | |
2e4964ad FF |
3819 | if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] && |
3820 | STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1)) | |
d07734e3 FF |
3821 | { |
3822 | /* Splice this symbol out of the hash chain and | |
3823 | assign the value we have to it. */ | |
3824 | if (prev) | |
3825 | { | |
3826 | SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); | |
3827 | } | |
3828 | else | |
3829 | { | |
3830 | global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym); | |
3831 | } | |
3832 | ||
3833 | /* Check to see whether we need to fix up a common block. */ | |
3834 | /* Note: this code might be executed several times for | |
3835 | the same symbol if there are multiple references. */ | |
3836 | ||
3837 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) | |
3838 | { | |
2e4964ad | 3839 | fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol)); |
d07734e3 FF |
3840 | } |
3841 | else | |
3842 | { | |
2e4964ad | 3843 | SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol); |
d07734e3 | 3844 | } |
a66e8382 SG |
3845 | |
3846 | SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol); | |
d07734e3 FF |
3847 | |
3848 | if (prev) | |
3849 | { | |
3850 | sym = SYMBOL_VALUE_CHAIN (prev); | |
3851 | } | |
3852 | else | |
3853 | { | |
3854 | sym = global_sym_chain[hash]; | |
3855 | } | |
3856 | } | |
3857 | else | |
3858 | { | |
3859 | prev = sym; | |
3860 | sym = SYMBOL_VALUE_CHAIN (sym); | |
3861 | } | |
3862 | } | |
3863 | } | |
3864 | } | |
3865 | ||
3866 | /* Initialize anything that needs initializing when starting to read | |
3867 | a fresh piece of a symbol file, e.g. reading in the stuff corresponding | |
3868 | to a psymtab. */ | |
3869 | ||
3870 | void | |
3871 | stabsread_init () | |
3872 | { | |
3873 | } | |
3874 | ||
3875 | /* Initialize anything that needs initializing when a completely new | |
3876 | symbol file is specified (not just adding some symbols from another | |
3877 | file, e.g. a shared library). */ | |
3878 | ||
3879 | void | |
3880 | stabsread_new_init () | |
3881 | { | |
3882 | /* Empty the hash table of global syms looking for values. */ | |
3883 | memset (global_sym_chain, 0, sizeof (global_sym_chain)); | |
3884 | } | |
3885 | ||
3886 | /* Initialize anything that needs initializing at the same time as | |
3887 | start_symtab() is called. */ | |
3888 | ||
3889 | void start_stabs () | |
3890 | { | |
3891 | global_stabs = NULL; /* AIX COFF */ | |
3892 | /* Leave FILENUM of 0 free for builtin types and this file's types. */ | |
3893 | n_this_object_header_files = 1; | |
3894 | type_vector_length = 0; | |
3895 | type_vector = (struct type **) 0; | |
9438d642 JK |
3896 | |
3897 | /* FIXME: If common_block_name is not already NULL, we should complain(). */ | |
3898 | common_block_name = NULL; | |
25200748 JK |
3899 | |
3900 | os9k_stabs = 0; | |
d07734e3 FF |
3901 | } |
3902 | ||
3903 | /* Call after end_symtab() */ | |
3904 | ||
3905 | void end_stabs () | |
3906 | { | |
3907 | if (type_vector) | |
3908 | { | |
3909 | free ((char *) type_vector); | |
3910 | } | |
3911 | type_vector = 0; | |
3912 | type_vector_length = 0; | |
3913 | previous_stab_code = 0; | |
3914 | } | |
3915 | ||
3916 | void | |
3917 | finish_global_stabs (objfile) | |
d07734e3 FF |
3918 | struct objfile *objfile; |
3919 | { | |
3920 | if (global_stabs) | |
3921 | { | |
3922 | patch_block_stabs (global_symbols, global_stabs, objfile); | |
3923 | free ((PTR) global_stabs); | |
3924 | global_stabs = NULL; | |
3925 | } | |
3926 | } | |
3927 | ||
3928 | /* Initializer for this module */ | |
3929 | ||
3930 | void | |
3931 | _initialize_stabsread () | |
3932 | { | |
3933 | undef_types_allocated = 20; | |
3934 | undef_types_length = 0; | |
3935 | undef_types = (struct type **) | |
3936 | xmalloc (undef_types_allocated * sizeof (struct type *)); | |
3937 | } |