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