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