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