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