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