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