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