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