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