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