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