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