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