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