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