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