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