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