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