2002-05-14 Daniel Jacobowitz <drow@mvista.com>
[external/binutils.git] / gdb / stabsread.c
1 /* Support routines for decoding "stabs" debugging information format.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3    1996, 1997, 1998, 1999, 2000, 2001, 2002
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 /* Support routines for reading and decoding debugging information in
24    the "stabs" format.  This format is used with many systems that use
25    the a.out object file format, as well as some systems that use
26    COFF or ELF where the stabs data is placed in a special section.
27    Avoid placing any object file format specific code in this file. */
28
29 #include "defs.h"
30 #include "gdb_string.h"
31 #include "bfd.h"
32 #include "obstack.h"
33 #include "symtab.h"
34 #include "gdbtypes.h"
35 #include "expression.h"
36 #include "symfile.h"
37 #include "objfiles.h"
38 #include "aout/stab_gnu.h"      /* We always use GNU stabs, not native */
39 #include "libaout.h"
40 #include "aout/aout64.h"
41 #include "gdb-stabs.h"
42 #include "buildsym.h"
43 #include "complaints.h"
44 #include "demangle.h"
45 #include "language.h"
46 #include "doublest.h"
47
48 #include <ctype.h>
49
50 /* Ask stabsread.h to define the vars it normally declares `extern'.  */
51 #define EXTERN
52 /**/
53 #include "stabsread.h"          /* Our own declarations */
54 #undef  EXTERN
55
56 extern void _initialize_stabsread (void);
57
58 /* The routines that read and process a complete stabs for a C struct or 
59    C++ class pass lists of data member fields and lists of member function
60    fields in an instance of a field_info structure, as defined below.
61    This is part of some reorganization of low level C++ support and is
62    expected to eventually go away... (FIXME) */
63
64 struct field_info
65   {
66     struct nextfield
67       {
68         struct nextfield *next;
69
70         /* This is the raw visibility from the stab.  It is not checked
71            for being one of the visibilities we recognize, so code which
72            examines this field better be able to deal.  */
73         int visibility;
74
75         struct field field;
76       }
77      *list;
78     struct next_fnfieldlist
79       {
80         struct next_fnfieldlist *next;
81         struct fn_fieldlist fn_fieldlist;
82       }
83      *fnlist;
84   };
85
86 static void
87 read_one_struct_field (struct field_info *, char **, char *,
88                        struct type *, struct objfile *);
89
90 static char *get_substring (char **, int);
91
92 static struct type *dbx_alloc_type (int[2], struct objfile *);
93
94 static long read_huge_number (char **, int, int *);
95
96 static struct type *error_type (char **, struct objfile *);
97
98 static void
99 patch_block_stabs (struct pending *, struct pending_stabs *,
100                    struct objfile *);
101
102 static void fix_common_block (struct symbol *, int);
103
104 static int read_type_number (char **, int *);
105
106 static struct type *read_range_type (char **, int[2], struct objfile *);
107
108 static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
109
110 static struct type *read_sun_floating_type (char **, int[2],
111                                             struct objfile *);
112
113 static struct type *read_enum_type (char **, struct type *, struct objfile *);
114
115 static struct type *rs6000_builtin_type (int);
116
117 static int
118 read_member_functions (struct field_info *, char **, struct type *,
119                        struct objfile *);
120
121 static int
122 read_struct_fields (struct field_info *, char **, struct type *,
123                     struct objfile *);
124
125 static int
126 read_baseclasses (struct field_info *, char **, struct type *,
127                   struct objfile *);
128
129 static int
130 read_tilde_fields (struct field_info *, char **, struct type *,
131                    struct objfile *);
132
133 static int attach_fn_fields_to_type (struct field_info *, struct type *);
134
135 static int
136 attach_fields_to_type (struct field_info *, struct type *, struct objfile *);
137
138 static struct type *read_struct_type (char **, struct type *,
139                                       enum type_code,
140                                       struct objfile *);
141
142 static struct type *read_array_type (char **, struct type *,
143                                      struct objfile *);
144
145 static struct type **read_args (char **, int, struct objfile *);
146
147 static int
148 read_cpp_abbrev (struct field_info *, char **, struct type *,
149                  struct objfile *);
150
151 /* new functions added for cfront support */
152
153 static int
154 copy_cfront_struct_fields (struct field_info *, struct type *,
155                            struct objfile *);
156
157 static char *get_cfront_method_physname (char *);
158
159 static int
160 read_cfront_baseclasses (struct field_info *, char **,
161                          struct type *, struct objfile *);
162
163 static int
164 read_cfront_static_fields (struct field_info *, char **,
165                            struct type *, struct objfile *);
166 static int
167 read_cfront_member_functions (struct field_info *, char **,
168                               struct type *, struct objfile *);
169
170 /* end new functions added for cfront support */
171
172 static void
173 add_live_range (struct objfile *, struct symbol *, CORE_ADDR, CORE_ADDR);
174
175 static int resolve_live_range (struct objfile *, struct symbol *, char *);
176
177 static int process_reference (char **string);
178
179 static CORE_ADDR ref_search_value (int refnum);
180
181 static int
182 resolve_symbol_reference (struct objfile *, struct symbol *, char *);
183
184 void stabsread_clear_cache (void);
185
186 static const char vptr_name[] =
187 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER, '\0'};
188 static const char vb_name[] =
189 {'_', 'v', 'b', CPLUS_MARKER, '\0'};
190
191 /* Define this as 1 if a pcc declaration of a char or short argument
192    gives the correct address.  Otherwise assume pcc gives the
193    address of the corresponding int, which is not the same on a
194    big-endian machine.  */
195
196 #if !defined (BELIEVE_PCC_PROMOTION)
197 #define BELIEVE_PCC_PROMOTION 0
198 #endif
199 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
200 #define BELIEVE_PCC_PROMOTION_TYPE 0
201 #endif
202
203 static struct complaint invalid_cpp_abbrev_complaint =
204 {"invalid C++ abbreviation `%s'", 0, 0};
205
206 static struct complaint invalid_cpp_type_complaint =
207 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
208
209 static struct complaint member_fn_complaint =
210 {"member function type missing, got '%c'", 0, 0};
211
212 static struct complaint const_vol_complaint =
213 {"const/volatile indicator missing, got '%c'", 0, 0};
214
215 static struct complaint error_type_complaint =
216 {"couldn't parse type; debugger out of date?", 0, 0};
217
218 static struct complaint invalid_member_complaint =
219 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
220
221 static struct complaint range_type_base_complaint =
222 {"base type %d of range type is not defined", 0, 0};
223
224 static struct complaint reg_value_complaint =
225 {"register number %d too large (max %d) in symbol %s", 0, 0};
226
227 static struct complaint vtbl_notfound_complaint =
228 {"virtual function table pointer not found when defining class `%s'", 0, 0};
229
230 static struct complaint unrecognized_cplus_name_complaint =
231 {"Unknown C++ symbol name `%s'", 0, 0};
232
233 static struct complaint rs6000_builtin_complaint =
234 {"Unknown builtin type %d", 0, 0};
235
236 static struct complaint unresolved_sym_chain_complaint =
237 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
238
239 static struct complaint stabs_general_complaint =
240 {"%s", 0, 0};
241
242 static struct complaint lrs_general_complaint =
243 {"%s", 0, 0};
244
245 /* Make a list of forward references which haven't been defined.  */
246
247 static struct type **undef_types;
248 static int undef_types_allocated;
249 static int undef_types_length;
250 static struct symbol *current_symbol = NULL;
251
252 /* Check for and handle cretinous stabs symbol name continuation!  */
253 #define STABS_CONTINUE(pp,objfile)                              \
254   do {                                                  \
255     if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
256       *(pp) = next_symbol_text (objfile);       \
257   } while (0)
258 \f
259 /* FIXME: These probably should be our own types (like rs6000_builtin_type
260    has its own types) rather than builtin_type_*.  */
261 static struct type **os9k_type_vector[] =
262 {
263   0,
264   &builtin_type_int,
265   &builtin_type_char,
266   &builtin_type_long,
267   &builtin_type_short,
268   &builtin_type_unsigned_char,
269   &builtin_type_unsigned_short,
270   &builtin_type_unsigned_long,
271   &builtin_type_unsigned_int,
272   &builtin_type_float,
273   &builtin_type_double,
274   &builtin_type_void,
275   &builtin_type_long_double
276 };
277
278 static void os9k_init_type_vector (struct type **);
279
280 static void
281 os9k_init_type_vector (struct type **tv)
282 {
283   unsigned int i;
284   for (i = 0; i < sizeof (os9k_type_vector) / sizeof (struct type **); i++)
285     tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
286 }
287
288 /* Look up a dbx type-number pair.  Return the address of the slot
289    where the type for that number-pair is stored.
290    The number-pair is in TYPENUMS.
291
292    This can be used for finding the type associated with that pair
293    or for associating a new type with the pair.  */
294
295 struct type **
296 dbx_lookup_type (int typenums[2])
297 {
298   register int filenum = typenums[0];
299   register int index = typenums[1];
300   unsigned old_len;
301   register int real_filenum;
302   register struct header_file *f;
303   int f_orig_length;
304
305   if (filenum == -1)            /* -1,-1 is for temporary types.  */
306     return 0;
307
308   if (filenum < 0 || filenum >= n_this_object_header_files)
309     {
310       static struct complaint msg =
311       {"\
312 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
313        0, 0};
314       complain (&msg, filenum, index, symnum);
315       goto error_return;
316     }
317
318   if (filenum == 0)
319     {
320       if (index < 0)
321         {
322           /* Caller wants address of address of type.  We think
323              that negative (rs6k builtin) types will never appear as
324              "lvalues", (nor should they), so we stuff the real type
325              pointer into a temp, and return its address.  If referenced,
326              this will do the right thing.  */
327           static struct type *temp_type;
328
329           temp_type = rs6000_builtin_type (index);
330           return &temp_type;
331         }
332
333       /* Type is defined outside of header files.
334          Find it in this object file's type vector.  */
335       if (index >= type_vector_length)
336         {
337           old_len = type_vector_length;
338           if (old_len == 0)
339             {
340               type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
341               type_vector = (struct type **)
342                 xmalloc (type_vector_length * sizeof (struct type *));
343             }
344           while (index >= type_vector_length)
345             {
346               type_vector_length *= 2;
347             }
348           type_vector = (struct type **)
349             xrealloc ((char *) type_vector,
350                       (type_vector_length * sizeof (struct type *)));
351           memset (&type_vector[old_len], 0,
352                   (type_vector_length - old_len) * sizeof (struct type *));
353
354           if (os9k_stabs)
355             /* Deal with OS9000 fundamental types.  */
356             os9k_init_type_vector (type_vector);
357         }
358       return (&type_vector[index]);
359     }
360   else
361     {
362       real_filenum = this_object_header_files[filenum];
363
364       if (real_filenum >= N_HEADER_FILES (current_objfile))
365         {
366           struct type *temp_type;
367           struct type **temp_type_p;
368
369           warning ("GDB internal error: bad real_filenum");
370
371         error_return:
372           temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
373           temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
374           *temp_type_p = temp_type;
375           return temp_type_p;
376         }
377
378       f = HEADER_FILES (current_objfile) + real_filenum;
379
380       f_orig_length = f->length;
381       if (index >= f_orig_length)
382         {
383           while (index >= f->length)
384             {
385               f->length *= 2;
386             }
387           f->vector = (struct type **)
388             xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
389           memset (&f->vector[f_orig_length], 0,
390                   (f->length - f_orig_length) * sizeof (struct type *));
391         }
392       return (&f->vector[index]);
393     }
394 }
395
396 /* Make sure there is a type allocated for type numbers TYPENUMS
397    and return the type object.
398    This can create an empty (zeroed) type object.
399    TYPENUMS may be (-1, -1) to return a new type object that is not
400    put into the type vector, and so may not be referred to by number. */
401
402 static struct type *
403 dbx_alloc_type (int typenums[2], struct objfile *objfile)
404 {
405   register struct type **type_addr;
406
407   if (typenums[0] == -1)
408     {
409       return (alloc_type (objfile));
410     }
411
412   type_addr = dbx_lookup_type (typenums);
413
414   /* If we are referring to a type not known at all yet,
415      allocate an empty type for it.
416      We will fill it in later if we find out how.  */
417   if (*type_addr == 0)
418     {
419       *type_addr = alloc_type (objfile);
420     }
421
422   return (*type_addr);
423 }
424
425 /* for all the stabs in a given stab vector, build appropriate types 
426    and fix their symbols in given symbol vector. */
427
428 static void
429 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
430                    struct objfile *objfile)
431 {
432   int ii;
433   char *name;
434   char *pp;
435   struct symbol *sym;
436
437   if (stabs)
438     {
439
440       /* for all the stab entries, find their corresponding symbols and 
441          patch their types! */
442
443       for (ii = 0; ii < stabs->count; ++ii)
444         {
445           name = stabs->stab[ii];
446           pp = (char *) strchr (name, ':');
447           while (pp[1] == ':')
448             {
449               pp += 2;
450               pp = (char *) strchr (pp, ':');
451             }
452           sym = find_symbol_in_list (symbols, name, pp - name);
453           if (!sym)
454             {
455               /* FIXME-maybe: it would be nice if we noticed whether
456                  the variable was defined *anywhere*, not just whether
457                  it is defined in this compilation unit.  But neither
458                  xlc or GCC seem to need such a definition, and until
459                  we do psymtabs (so that the minimal symbols from all
460                  compilation units are available now), I'm not sure
461                  how to get the information.  */
462
463               /* On xcoff, if a global is defined and never referenced,
464                  ld will remove it from the executable.  There is then
465                  a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
466               sym = (struct symbol *)
467                 obstack_alloc (&objfile->symbol_obstack,
468                                sizeof (struct symbol));
469
470               memset (sym, 0, sizeof (struct symbol));
471               SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
472               SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
473               SYMBOL_NAME (sym) =
474                 obsavestring (name, pp - name, &objfile->symbol_obstack);
475               pp += 2;
476               if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
477                 {
478                   /* I don't think the linker does this with functions,
479                      so as far as I know this is never executed.
480                      But it doesn't hurt to check.  */
481                   SYMBOL_TYPE (sym) =
482                     lookup_function_type (read_type (&pp, objfile));
483                 }
484               else
485                 {
486                   SYMBOL_TYPE (sym) = read_type (&pp, objfile);
487                 }
488               add_symbol_to_list (sym, &global_symbols);
489             }
490           else
491             {
492               pp += 2;
493               if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
494                 {
495                   SYMBOL_TYPE (sym) =
496                     lookup_function_type (read_type (&pp, objfile));
497                 }
498               else
499                 {
500                   SYMBOL_TYPE (sym) = read_type (&pp, objfile);
501                 }
502             }
503         }
504     }
505 }
506 \f
507
508 /* Read a number by which a type is referred to in dbx data,
509    or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
510    Just a single number N is equivalent to (0,N).
511    Return the two numbers by storing them in the vector TYPENUMS.
512    TYPENUMS will then be used as an argument to dbx_lookup_type.
513
514    Returns 0 for success, -1 for error.  */
515
516 static int
517 read_type_number (register char **pp, register int *typenums)
518 {
519   int nbits;
520   if (**pp == '(')
521     {
522       (*pp)++;
523       typenums[0] = read_huge_number (pp, ',', &nbits);
524       if (nbits != 0)
525         return -1;
526       typenums[1] = read_huge_number (pp, ')', &nbits);
527       if (nbits != 0)
528         return -1;
529     }
530   else
531     {
532       typenums[0] = 0;
533       typenums[1] = read_huge_number (pp, 0, &nbits);
534       if (nbits != 0)
535         return -1;
536     }
537   return 0;
538 }
539 \f
540
541 #define VISIBILITY_PRIVATE      '0'     /* Stabs character for private field */
542 #define VISIBILITY_PROTECTED    '1'     /* Stabs character for protected fld */
543 #define VISIBILITY_PUBLIC       '2'     /* Stabs character for public field */
544 #define VISIBILITY_IGNORE       '9'     /* Optimized out or zero length */
545
546 #define CFRONT_VISIBILITY_PRIVATE       '2'     /* Stabs character for private field */
547 #define CFRONT_VISIBILITY_PUBLIC        '1'     /* Stabs character for public field */
548
549 /* This code added to support parsing of ARM/Cfront stabs strings */
550
551 /* Get substring from string up to char c, advance string pointer past
552    suibstring. */
553
554 static char *
555 get_substring (char **p, int c)
556 {
557   char *str;
558   str = *p;
559   *p = strchr (*p, c);
560   if (*p)
561     {
562       **p = 0;
563       (*p)++;
564     }
565   else
566     str = 0;
567   return str;
568 }
569
570 /* Physname gets strcat'd onto sname in order to recreate the mangled
571    name (see funtion gdb_mangle_name in gdbtypes.c).  For cfront, make
572    the physname look like that of g++ - take out the initial mangling
573    eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
574
575 static char *
576 get_cfront_method_physname (char *fname)
577 {
578   int len = 0;
579   /* FIXME would like to make this generic for g++ too, but 
580      that is already handled in read_member_funcctions */
581   char *p = fname;
582
583   /* search ahead to find the start of the mangled suffix */
584   if (*p == '_' && *(p + 1) == '_')     /* compiler generated; probably a ctor/dtor */
585     p += 2;
586   while (p && (unsigned) ((p + 1) - fname) < strlen (fname) && *(p + 1) != '_')
587     p = strchr (p, '_');
588   if (!(p && *p == '_' && *(p + 1) == '_'))
589     error ("Invalid mangled function name %s", fname);
590   p += 2;                       /* advance past '__' */
591
592   /* struct name length and name of type should come next; advance past it */
593   while (isdigit (*p))
594     {
595       len = len * 10 + (*p - '0');
596       p++;
597     }
598   p += len;
599
600   return p;
601 }
602
603 /* Read base classes within cfront class definition.
604    eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
605    ^^^^^^^^^^^^^^^^^^
606
607    A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
608    ^
609  */
610
611 static int
612 read_cfront_baseclasses (struct field_info *fip, char **pp, struct type *type,
613                          struct objfile *objfile)
614 {
615   static struct complaint msg_unknown =
616   {"\
617          Unsupported token in stabs string %s.\n",
618    0, 0};
619   static struct complaint msg_notfound =
620   {"\
621                    Unable to find base type for %s.\n",
622    0, 0};
623   int bnum = 0;
624   char *p;
625   int i;
626   struct nextfield *new;
627
628   if (**pp == ';')              /* no base classes; return */
629     {
630       ++(*pp);
631       return 1;
632     }
633
634   /* first count base classes so we can allocate space before parsing */
635   for (p = *pp; p && *p && *p != ';'; p++)
636     {
637       if (*p == ' ')
638         bnum++;
639     }
640   bnum++;                       /* add one more for last one */
641
642   /* now parse the base classes until we get to the start of the methods 
643      (code extracted and munged from read_baseclasses) */
644   ALLOCATE_CPLUS_STRUCT_TYPE (type);
645   TYPE_N_BASECLASSES (type) = bnum;
646
647   /* allocate space */
648   {
649     int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
650     char *pointer;
651
652     pointer = (char *) TYPE_ALLOC (type, num_bytes);
653     TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
654   }
655   B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
656
657   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
658     {
659       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
660       make_cleanup (xfree, new);
661       memset (new, 0, sizeof (struct nextfield));
662       new->next = fip->list;
663       fip->list = new;
664       FIELD_BITSIZE (new->field) = 0;   /* this should be an unpacked field! */
665
666       STABS_CONTINUE (pp, objfile);
667
668       /* virtual?  eg: v2@Bvir */
669       if (**pp == 'v')
670         {
671           SET_TYPE_FIELD_VIRTUAL (type, i);
672           ++(*pp);
673         }
674
675       /* access?  eg: 2@Bvir */
676       /* Note: protected inheritance not supported in cfront */
677       switch (*(*pp)++)
678         {
679         case CFRONT_VISIBILITY_PRIVATE:
680           new->visibility = VISIBILITY_PRIVATE;
681           break;
682         case CFRONT_VISIBILITY_PUBLIC:
683           new->visibility = VISIBILITY_PUBLIC;
684           break;
685         default:
686           /* Bad visibility format.  Complain and treat it as
687              public.  */
688           {
689             static struct complaint msg =
690             {
691               "Unknown visibility `%c' for baseclass", 0, 0};
692             complain (&msg, new->visibility);
693             new->visibility = VISIBILITY_PUBLIC;
694           }
695         }
696
697       /* "@" comes next - eg: @Bvir */
698       if (**pp != '@')
699         {
700           complain (&msg_unknown, *pp);
701           return 1;
702         }
703       ++(*pp);
704
705
706       /* Set the bit offset of the portion of the object corresponding 
707          to this baseclass.  Always zero in the absence of
708          multiple inheritance.  */
709       /* Unable to read bit position from stabs;
710          Assuming no multiple inheritance for now FIXME! */
711       /* We may have read this in the structure definition;
712          now we should fixup the members to be the actual base classes */
713       FIELD_BITPOS (new->field) = 0;
714
715       /* Get the base class name and type */
716       {
717         char *bname;            /* base class name */
718         struct symbol *bsym;    /* base class */
719         char *p1, *p2;
720         p1 = strchr (*pp, ' ');
721         p2 = strchr (*pp, ';');
722         if (p1 < p2)
723           bname = get_substring (pp, ' ');
724         else
725           bname = get_substring (pp, ';');
726         if (!bname || !*bname)
727           {
728             complain (&msg_unknown, *pp);
729             return 1;
730           }
731         /* FIXME! attach base info to type */
732         bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0);        /*demangled_name */
733         if (bsym)
734           {
735             new->field.type = SYMBOL_TYPE (bsym);
736             new->field.name = type_name_no_tag (new->field.type);
737           }
738         else
739           {
740             complain (&msg_notfound, *pp);
741             return 1;
742           }
743       }
744
745       /* If more base classes to parse, loop again.
746          We ate the last ' ' or ';' in get_substring,
747          so on exit we will have skipped the trailing ';' */
748       /* if invalid, return 0; add code to detect  - FIXME! */
749     }
750   return 1;
751 }
752
753 /* read cfront member functions.
754    pp points to string starting with list of functions
755    eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
756    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
757    A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
758    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
759  */
760
761 static int
762 read_cfront_member_functions (struct field_info *fip, char **pp,
763                               struct type *type, struct objfile *objfile)
764 {
765   /* This code extracted from read_member_functions 
766      so as to do the similar thing for our funcs */
767
768   int nfn_fields = 0;
769   int length = 0;
770   /* Total number of member functions defined in this class.  If the class
771      defines two `f' functions, and one `g' function, then this will have
772      the value 3.  */
773   int total_length = 0;
774   int i;
775   struct next_fnfield
776     {
777       struct next_fnfield *next;
778       struct fn_field fn_field;
779     }
780    *sublist;
781   struct type *look_ahead_type;
782   struct next_fnfieldlist *new_fnlist;
783   struct next_fnfield *new_sublist;
784   char *main_fn_name;
785   char *fname;
786   struct symbol *ref_func = 0;
787
788   /* Process each list until we find the end of the member functions.
789      eg: p = "__ct__1AFv foo__1AFv ;;;" */
790
791   STABS_CONTINUE (pp, objfile); /* handle \\ */
792
793   while (**pp != ';' && (fname = get_substring (pp, ' '), fname))
794     {
795       int is_static = 0;
796       int sublist_count = 0;
797       char *pname;
798       if (fname[0] == '*')      /* static member */
799         {
800           is_static = 1;
801           sublist_count++;
802           fname++;
803         }
804       ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0);         /* demangled name */
805       if (!ref_func)
806         {
807           static struct complaint msg =
808           {"\
809                 Unable to find function symbol for %s\n",
810            0, 0};
811           complain (&msg, fname);
812           continue;
813         }
814       sublist = NULL;
815       look_ahead_type = NULL;
816       length = 0;
817
818       new_fnlist = (struct next_fnfieldlist *)
819         xmalloc (sizeof (struct next_fnfieldlist));
820       make_cleanup (xfree, new_fnlist);
821       memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
822
823       /* The following is code to work around cfront generated stabs.
824          The stabs contains full mangled name for each field.
825          We try to demangle the name and extract the field name out of it.  */
826       {
827         char *dem, *dem_p, *dem_args;
828         int dem_len;
829         dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
830         if (dem != NULL)
831           {
832             dem_p = strrchr (dem, ':');
833             if (dem_p != 0 && *(dem_p - 1) == ':')
834               dem_p++;
835             /* get rid of args */
836             dem_args = strchr (dem_p, '(');
837             if (dem_args == NULL)
838               dem_len = strlen (dem_p);
839             else
840               dem_len = dem_args - dem_p;
841             main_fn_name =
842               obsavestring (dem_p, dem_len, &objfile->type_obstack);
843           }
844         else
845           {
846             main_fn_name =
847               obsavestring (fname, strlen (fname), &objfile->type_obstack);
848           }
849       }                         /* end of code for cfront work around */
850
851       new_fnlist->fn_fieldlist.name = main_fn_name;
852
853 /*-------------------------------------------------*/
854       /* Set up the sublists
855          Sublists are stuff like args, static, visibility, etc.
856          so in ARM, we have to set that info some other way.
857          Multiple sublists happen if overloading
858          eg: foo::26=##1;:;2A.;
859          In g++, we'd loop here thru all the sublists...  */
860
861       new_sublist =
862         (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
863       make_cleanup (xfree, new_sublist);
864       memset (new_sublist, 0, sizeof (struct next_fnfield));
865
866       /* eat 1; from :;2A.; */
867       new_sublist->fn_field.type = SYMBOL_TYPE (ref_func);      /* normally takes a read_type */
868       /* Make this type look like a method stub for gdb */
869       TYPE_FLAGS (new_sublist->fn_field.type) |= TYPE_FLAG_STUB;
870       TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
871
872       /* If this is just a stub, then we don't have the real name here. */
873       if (TYPE_STUB (new_sublist->fn_field.type))
874         {
875           if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
876             TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
877           new_sublist->fn_field.is_stub = 1;
878         }
879
880       /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i 
881          physname gets strcat'd in order to recreate the onto mangled name */
882       pname = get_cfront_method_physname (fname);
883       new_sublist->fn_field.physname = savestring (pname, strlen (pname));
884
885
886       /* Set this member function's visibility fields. 
887          Unable to distinguish access from stabs definition!
888          Assuming public for now.  FIXME!
889          (for private, set new_sublist->fn_field.is_private = 1,
890          for public, set new_sublist->fn_field.is_protected = 1) */
891
892       /* Unable to distinguish const/volatile from stabs definition!
893          Assuming normal for now.  FIXME! */
894
895       new_sublist->fn_field.is_const = 0;
896       new_sublist->fn_field.is_volatile = 0;    /* volatile not implemented in cfront */
897
898       /* Set virtual/static function info
899          How to get vtable offsets ? 
900          Assuming normal for now FIXME!! 
901          For vtables, figure out from whence this virtual function came.
902          It may belong to virtual function table of
903          one of its baseclasses.
904          set:
905          new_sublist -> fn_field.voffset = vtable offset,
906          new_sublist -> fn_field.fcontext = look_ahead_type;
907          where look_ahead_type is type of baseclass */
908       if (is_static)
909         new_sublist->fn_field.voffset = VOFFSET_STATIC;
910       else                      /* normal member function.  */
911         new_sublist->fn_field.voffset = 0;
912       new_sublist->fn_field.fcontext = 0;
913
914
915       /* Prepare new sublist */
916       new_sublist->next = sublist;
917       sublist = new_sublist;
918       length++;
919
920       /* In g++, we loop thu sublists - now we set from functions. */
921       new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
922         obstack_alloc (&objfile->type_obstack,
923                        sizeof (struct fn_field) * length);
924       memset (new_fnlist->fn_fieldlist.fn_fields, 0,
925               sizeof (struct fn_field) * length);
926       for (i = length; (i--, sublist); sublist = sublist->next)
927         {
928           new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
929         }
930
931       new_fnlist->fn_fieldlist.length = length;
932       new_fnlist->next = fip->fnlist;
933       fip->fnlist = new_fnlist;
934       nfn_fields++;
935       total_length += length;
936       STABS_CONTINUE (pp, objfile);     /* handle \\ */
937     }                           /* end of loop */
938
939   if (nfn_fields)
940     {
941       /* type should already have space */
942       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
943         TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
944       memset (TYPE_FN_FIELDLISTS (type), 0,
945               sizeof (struct fn_fieldlist) * nfn_fields);
946       TYPE_NFN_FIELDS (type) = nfn_fields;
947       TYPE_NFN_FIELDS_TOTAL (type) = total_length;
948     }
949
950   /* end of scope for reading member func */
951
952   /* eg: ";;" */
953
954   /* Skip trailing ';' and bump count of number of fields seen */
955   if (**pp == ';')
956     (*pp)++;
957   else
958     return 0;
959   return 1;
960 }
961
962 /* This routine fixes up partial cfront types that were created
963    while parsing the stabs.  The main need for this function is
964    to add information such as methods to classes.
965    Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
966 int
967 resolve_cfront_continuation (struct objfile *objfile, struct symbol *sym,
968                              char *p)
969 {
970   struct symbol *ref_sym = 0;
971   char *sname;
972   /* snarfed from read_struct_type */
973   struct field_info fi;
974   struct type *type;
975   struct cleanup *back_to;
976
977   /* Need to make sure that fi isn't gunna conflict with struct 
978      in case struct already had some fnfs */
979   fi.list = NULL;
980   fi.fnlist = NULL;
981   back_to = make_cleanup (null_cleanup, 0);
982
983   /* We only accept structs, classes and unions at the moment. 
984      Other continuation types include t (typedef), r (long dbl), ... 
985      We may want to add support for them as well; 
986      right now they are handled by duplicating the symbol information 
987      into the type information (see define_symbol) */
988   if (*p != 's'                 /* structs */
989       && *p != 'c'              /* class */
990       && *p != 'u')             /* union */
991     return 0;                   /* only handle C++ types */
992   p++;
993
994   /* Get symbol typs name and validate 
995      eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
996   sname = get_substring (&p, ';');
997   if (!sname || strcmp (sname, SYMBOL_NAME (sym)))
998     error ("Internal error: base symbol type name does not match\n");
999
1000   /* Find symbol's internal gdb reference using demangled_name.
1001      This is the real sym that we want; 
1002      sym was a temp hack to make debugger happy */
1003   ref_sym = lookup_symbol (SYMBOL_NAME (sym), 0, STRUCT_NAMESPACE, 0, 0);
1004   type = SYMBOL_TYPE (ref_sym);
1005
1006
1007   /* Now read the baseclasses, if any, read the regular C struct or C++
1008      class member fields, attach the fields to the type, read the C++
1009      member functions, attach them to the type, and then read any tilde
1010      field (baseclass specifier for the class holding the main vtable). */
1011
1012   if (!read_cfront_baseclasses (&fi, &p, type, objfile)
1013   /* g++ does this next, but cfront already did this: 
1014      || !read_struct_fields (&fi, &p, type, objfile) */
1015       || !copy_cfront_struct_fields (&fi, type, objfile)
1016       || !read_cfront_member_functions (&fi, &p, type, objfile)
1017       || !read_cfront_static_fields (&fi, &p, type, objfile)
1018       || !attach_fields_to_type (&fi, type, objfile)
1019       || !attach_fn_fields_to_type (&fi, type)
1020   /* g++ does this next, but cfront doesn't seem to have this: 
1021      || !read_tilde_fields (&fi, &p, type, objfile) */
1022     )
1023     {
1024       type = error_type (&p, objfile);
1025     }
1026
1027   do_cleanups (back_to);
1028   return 0;
1029 }
1030 /* End of code added to support parsing of ARM/Cfront stabs strings */
1031
1032
1033 /* This routine fixes up symbol references/aliases to point to the original
1034    symbol definition.  Returns 0 on failure, non-zero on success.  */
1035
1036 static int
1037 resolve_symbol_reference (struct objfile *objfile, struct symbol *sym, char *p)
1038 {
1039   int refnum;
1040   struct symbol *ref_sym = 0;
1041   struct alias_list *alias;
1042
1043   /* If this is not a symbol reference return now.  */
1044   if (*p != '#')
1045     return 0;
1046
1047   /* Use "#<num>" as the name; we'll fix the name later.
1048      We stored the original symbol name as "#<id>=<name>"
1049      so we can now search for "#<id>" to resolving the reference.
1050      We'll fix the names later by removing the "#<id>" or "#<id>=" */
1051
1052 /*---------------------------------------------------------*/
1053   /* Get the reference id number, and 
1054      advance p past the names so we can parse the rest. 
1055      eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1056 /*---------------------------------------------------------*/
1057
1058   /* This gets reference name from string.  sym may not have a name. */
1059
1060   /* Get the reference number associated with the reference id in the
1061      gdb stab string.  From that reference number, get the main/primary
1062      symbol for this alias.  */
1063   refnum = process_reference (&p);
1064   ref_sym = ref_search (refnum);
1065   if (!ref_sym)
1066     {
1067       complain (&lrs_general_complaint, "symbol for reference not found");
1068       return 0;
1069     }
1070
1071   /* Parse the stab of the referencing symbol
1072      now that we have the referenced symbol.
1073      Add it as a new symbol and a link back to the referenced symbol.
1074      eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1075
1076
1077   /* If the stab symbol table and string contain:
1078      RSYM   0      5      00000000 868    #15=z:r(0,1)
1079      LBRAC  0      0      00000000 899    #5=
1080      SLINE  0      16     00000003 923    #6=
1081      Then the same symbols can be later referenced by:
1082      RSYM   0      5      00000000 927    #15:r(0,1);l(#5,#6)
1083      This is used in live range splitting to:
1084      1) specify that a symbol (#15) is actually just a new storage 
1085      class for a symbol (#15=z) which was previously defined.
1086      2) specify that the beginning and ending ranges for a symbol 
1087      (#15) are the values of the beginning (#5) and ending (#6) 
1088      symbols. */
1089
1090   /* Read number as reference id.
1091      eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1092   /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1093      in case of "l(0,0)"? */
1094
1095 /*--------------------------------------------------*/
1096   /* Add this symbol to the reference list.           */
1097 /*--------------------------------------------------*/
1098
1099   alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack,
1100                                                sizeof (struct alias_list));
1101   if (!alias)
1102     {
1103       complain (&lrs_general_complaint, "Unable to allocate alias list memory");
1104       return 0;
1105     }
1106
1107   alias->next = 0;
1108   alias->sym = sym;
1109
1110   if (!SYMBOL_ALIASES (ref_sym))
1111     {
1112       SYMBOL_ALIASES (ref_sym) = alias;
1113     }
1114   else
1115     {
1116       struct alias_list *temp;
1117
1118       /* Get to the end of the list.  */
1119       for (temp = SYMBOL_ALIASES (ref_sym);
1120            temp->next;
1121            temp = temp->next)
1122         ;
1123       temp->next = alias;
1124     }
1125
1126   /* Want to fix up name so that other functions (eg. valops)
1127      will correctly print the name.
1128      Don't add_symbol_to_list so that lookup_symbol won't find it.
1129      nope... needed for fixups. */
1130   SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym);
1131
1132   /* Done!  */
1133   return 1;
1134 }
1135
1136 /* Structure for storing pointers to reference definitions for fast lookup 
1137    during "process_later". */
1138
1139 struct ref_map
1140 {
1141   char *stabs;
1142   CORE_ADDR value;
1143   struct symbol *sym;
1144 };
1145
1146 #define MAX_CHUNK_REFS 100
1147 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1148 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1149
1150 static struct ref_map *ref_map;
1151
1152 /* Ptr to free cell in chunk's linked list. */
1153 static int ref_count = 0;
1154
1155 /* Number of chunks malloced. */
1156 static int ref_chunk = 0;
1157
1158 /* This file maintains a cache of stabs aliases found in the symbol
1159    table. If the symbol table changes, this cache must be cleared
1160    or we are left holding onto data in invalid obstacks. */
1161 void
1162 stabsread_clear_cache (void)
1163 {
1164   ref_count = 0;
1165   ref_chunk = 0;
1166 }
1167
1168 /* Create array of pointers mapping refids to symbols and stab strings.
1169    Add pointers to reference definition symbols and/or their values as we 
1170    find them, using their reference numbers as our index. 
1171    These will be used later when we resolve references. */
1172 void
1173 ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
1174 {
1175   if (ref_count == 0)
1176     ref_chunk = 0;
1177   if (refnum >= ref_count)
1178     ref_count = refnum + 1;
1179   if (ref_count > ref_chunk * MAX_CHUNK_REFS)
1180     {
1181       int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
1182       int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
1183       ref_map = (struct ref_map *)
1184         xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
1185       memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE);
1186       ref_chunk += new_chunks;
1187     }
1188   ref_map[refnum].stabs = stabs;
1189   ref_map[refnum].sym = sym;
1190   ref_map[refnum].value = value;
1191 }
1192
1193 /* Return defined sym for the reference REFNUM.  */
1194 struct symbol *
1195 ref_search (int refnum)
1196 {
1197   if (refnum < 0 || refnum > ref_count)
1198     return 0;
1199   return ref_map[refnum].sym;
1200 }
1201
1202 /* Return value for the reference REFNUM.  */
1203
1204 static CORE_ADDR
1205 ref_search_value (int refnum)
1206 {
1207   if (refnum < 0 || refnum > ref_count)
1208     return 0;
1209   return ref_map[refnum].value;
1210 }
1211
1212 /* Parse a reference id in STRING and return the resulting
1213    reference number.  Move STRING beyond the reference id.  */
1214
1215 static int
1216 process_reference (char **string)
1217 {
1218   char *p;
1219   int refnum = 0;
1220
1221   if (**string != '#')
1222     return 0;
1223
1224   /* Advance beyond the initial '#'.  */
1225   p = *string + 1;
1226
1227   /* Read number as reference id. */
1228   while (*p && isdigit (*p))
1229     {
1230       refnum = refnum * 10 + *p - '0';
1231       p++;
1232     }
1233   *string = p;
1234   return refnum;
1235 }
1236
1237 /* If STRING defines a reference, store away a pointer to the reference 
1238    definition for later use.  Return the reference number.  */
1239
1240 int
1241 symbol_reference_defined (char **string)
1242 {
1243   char *p = *string;
1244   int refnum = 0;
1245
1246   refnum = process_reference (&p);
1247
1248   /* Defining symbols end in '=' */
1249   if (*p == '=')
1250     {
1251       /* Symbol is being defined here. */
1252       *string = p + 1;
1253       return refnum;
1254     }
1255   else
1256     {
1257       /* Must be a reference.   Either the symbol has already been defined,
1258          or this is a forward reference to it.  */
1259       *string = p;
1260       return -1;
1261     }
1262 }
1263
1264 /* ARGSUSED */
1265 struct symbol *
1266 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
1267                struct objfile *objfile)
1268 {
1269   register struct symbol *sym;
1270   char *p = (char *) strchr (string, ':');
1271   int deftype;
1272   int synonym = 0;
1273   register int i;
1274
1275   /* We would like to eliminate nameless symbols, but keep their types.
1276      E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1277      to type 2, but, should not create a symbol to address that type. Since
1278      the symbol will be nameless, there is no way any user can refer to it. */
1279
1280   int nameless;
1281
1282   /* Ignore syms with empty names.  */
1283   if (string[0] == 0)
1284     return 0;
1285
1286   /* Ignore old-style symbols from cc -go  */
1287   if (p == 0)
1288     return 0;
1289
1290   while (p[1] == ':')
1291     {
1292       p += 2;
1293       p = strchr (p, ':');
1294     }
1295
1296   /* If a nameless stab entry, all we need is the type, not the symbol.
1297      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1298   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
1299
1300   current_symbol = sym = (struct symbol *)
1301     obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1302   memset (sym, 0, sizeof (struct symbol));
1303
1304   switch (type & N_TYPE)
1305     {
1306     case N_TEXT:
1307       SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
1308       break;
1309     case N_DATA:
1310       SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
1311       break;
1312     case N_BSS:
1313       SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
1314       break;
1315     }
1316
1317   if (processing_gcc_compilation)
1318     {
1319       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
1320          number of bytes occupied by a type or object, which we ignore.  */
1321       SYMBOL_LINE (sym) = desc;
1322     }
1323   else
1324     {
1325       SYMBOL_LINE (sym) = 0;    /* unknown */
1326     }
1327
1328   if (is_cplus_marker (string[0]))
1329     {
1330       /* Special GNU C++ names.  */
1331       switch (string[1])
1332         {
1333         case 't':
1334           SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1335                                             &objfile->symbol_obstack);
1336           break;
1337
1338         case 'v':               /* $vtbl_ptr_type */
1339           /* Was: SYMBOL_NAME (sym) = "vptr"; */
1340           goto normal;
1341
1342         case 'e':
1343           SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1344                                             &objfile->symbol_obstack);
1345           break;
1346
1347         case '_':
1348           /* This was an anonymous type that was never fixed up.  */
1349           goto normal;
1350
1351 #ifdef STATIC_TRANSFORM_NAME
1352         case 'X':
1353           /* SunPRO (3.0 at least) static variable encoding.  */
1354           goto normal;
1355 #endif
1356
1357         default:
1358           complain (&unrecognized_cplus_name_complaint, string);
1359           goto normal;          /* Do *something* with it */
1360         }
1361     }
1362   else if (string[0] == '#')
1363     {
1364       /* Special GNU C extension for referencing symbols.  */
1365       char *s;
1366       int refnum, nlen;
1367
1368       /* If STRING defines a new reference id, then add it to the
1369          reference map.  Else it must be referring to a previously
1370          defined symbol, so add it to the alias list of the previously
1371          defined symbol.  */
1372       s = string;
1373       refnum = symbol_reference_defined (&s);
1374       if (refnum >= 0)
1375         ref_add (refnum, sym, string, SYMBOL_VALUE (sym));
1376       else if (!resolve_symbol_reference (objfile, sym, string))
1377         return NULL;
1378
1379       /* S..P contains the name of the symbol.  We need to store
1380          the correct name into SYMBOL_NAME.  */
1381       nlen = p - s;
1382       if (refnum >= 0)
1383         {
1384           if (nlen > 0)
1385             {
1386               SYMBOL_NAME (sym) = (char *)
1387                 obstack_alloc (&objfile->symbol_obstack, nlen);
1388               strncpy (SYMBOL_NAME (sym), s, nlen);
1389               SYMBOL_NAME (sym)[nlen] = '\0';
1390               SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1391             }
1392           else
1393             /* FIXME! Want SYMBOL_NAME (sym) = 0;
1394                Get error if leave name 0.  So give it something. */
1395             {
1396               nlen = p - string;
1397               SYMBOL_NAME (sym) = (char *)
1398                 obstack_alloc (&objfile->symbol_obstack, nlen);
1399               strncpy (SYMBOL_NAME (sym), string, nlen);
1400               SYMBOL_NAME (sym)[nlen] = '\0';
1401               SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1402             }
1403         }
1404       /* Advance STRING beyond the reference id.  */
1405       string = s;
1406     }
1407   else
1408     {
1409     normal:
1410       SYMBOL_LANGUAGE (sym) = current_subfile->language;
1411       SYMBOL_NAME (sym) = (char *)
1412         obstack_alloc (&objfile->symbol_obstack, ((p - string) + 1));
1413       /* Open-coded memcpy--saves function call time.  */
1414       /* FIXME:  Does it really?  Try replacing with simple strcpy and
1415          try it on an executable with a large symbol table. */
1416       /* FIXME: considering that gcc can open code memcpy anyway, I
1417          doubt it.  xoxorich. */
1418       {
1419         register char *p1 = string;
1420         register char *p2 = SYMBOL_NAME (sym);
1421         while (p1 != p)
1422           {
1423             *p2++ = *p1++;
1424           }
1425         *p2++ = '\0';
1426       }
1427
1428       /* If this symbol is from a C++ compilation, then attempt to cache the
1429          demangled form for future reference.  This is a typical time versus
1430          space tradeoff, that was decided in favor of time because it sped up
1431          C++ symbol lookups by a factor of about 20. */
1432
1433       SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1434     }
1435   p++;
1436
1437   /* Determine the type of name being defined.  */
1438 #if 0
1439   /* Getting GDB to correctly skip the symbol on an undefined symbol
1440      descriptor and not ever dump core is a very dodgy proposition if
1441      we do things this way.  I say the acorn RISC machine can just
1442      fix their compiler.  */
1443   /* The Acorn RISC machine's compiler can put out locals that don't
1444      start with "234=" or "(3,4)=", so assume anything other than the
1445      deftypes we know how to handle is a local.  */
1446   if (!strchr ("cfFGpPrStTvVXCR", *p))
1447 #else
1448   if (isdigit (*p) || *p == '(' || *p == '-')
1449 #endif
1450     deftype = 'l';
1451   else
1452     deftype = *p++;
1453
1454   switch (deftype)
1455     {
1456     case 'c':
1457       /* c is a special case, not followed by a type-number.
1458          SYMBOL:c=iVALUE for an integer constant symbol.
1459          SYMBOL:c=rVALUE for a floating constant symbol.
1460          SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1461          e.g. "b:c=e6,0" for "const b = blob1"
1462          (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
1463       if (*p != '=')
1464         {
1465           SYMBOL_CLASS (sym) = LOC_CONST;
1466           SYMBOL_TYPE (sym) = error_type (&p, objfile);
1467           SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1468           add_symbol_to_list (sym, &file_symbols);
1469           return sym;
1470         }
1471       ++p;
1472       switch (*p++)
1473         {
1474         case 'r':
1475           {
1476             double d = atof (p);
1477             char *dbl_valu;
1478
1479             /* FIXME-if-picky-about-floating-accuracy: Should be using
1480                target arithmetic to get the value.  real.c in GCC
1481                probably has the necessary code.  */
1482
1483             /* FIXME: lookup_fundamental_type is a hack.  We should be
1484                creating a type especially for the type of float constants.
1485                Problem is, what type should it be?
1486
1487                Also, what should the name of this type be?  Should we
1488                be using 'S' constants (see stabs.texinfo) instead?  */
1489
1490             SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1491                                                          FT_DBL_PREC_FLOAT);
1492             dbl_valu = (char *)
1493               obstack_alloc (&objfile->symbol_obstack,
1494                              TYPE_LENGTH (SYMBOL_TYPE (sym)));
1495             store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
1496             SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1497             SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1498           }
1499           break;
1500         case 'i':
1501           {
1502             /* Defining integer constants this way is kind of silly,
1503                since 'e' constants allows the compiler to give not
1504                only the value, but the type as well.  C has at least
1505                int, long, unsigned int, and long long as constant
1506                types; other languages probably should have at least
1507                unsigned as well as signed constants.  */
1508
1509             /* We just need one int constant type for all objfiles.
1510                It doesn't depend on languages or anything (arguably its
1511                name should be a language-specific name for a type of
1512                that size, but I'm inclined to say that if the compiler
1513                wants a nice name for the type, it can use 'e').  */
1514             static struct type *int_const_type;
1515
1516             /* Yes, this is as long as a *host* int.  That is because we
1517                use atoi.  */
1518             if (int_const_type == NULL)
1519               int_const_type =
1520                 init_type (TYPE_CODE_INT,
1521                            sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1522                            "integer constant",
1523                              (struct objfile *) NULL);
1524             SYMBOL_TYPE (sym) = int_const_type;
1525             SYMBOL_VALUE (sym) = atoi (p);
1526             SYMBOL_CLASS (sym) = LOC_CONST;
1527           }
1528           break;
1529         case 'e':
1530           /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1531              can be represented as integral.
1532              e.g. "b:c=e6,0" for "const b = blob1"
1533              (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
1534           {
1535             SYMBOL_CLASS (sym) = LOC_CONST;
1536             SYMBOL_TYPE (sym) = read_type (&p, objfile);
1537
1538             if (*p != ',')
1539               {
1540                 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1541                 break;
1542               }
1543             ++p;
1544
1545             /* If the value is too big to fit in an int (perhaps because
1546                it is unsigned), or something like that, we silently get
1547                a bogus value.  The type and everything else about it is
1548                correct.  Ideally, we should be using whatever we have
1549                available for parsing unsigned and long long values,
1550                however.  */
1551             SYMBOL_VALUE (sym) = atoi (p);
1552           }
1553           break;
1554         default:
1555           {
1556             SYMBOL_CLASS (sym) = LOC_CONST;
1557             SYMBOL_TYPE (sym) = error_type (&p, objfile);
1558           }
1559         }
1560       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1561       add_symbol_to_list (sym, &file_symbols);
1562       return sym;
1563
1564     case 'C':
1565       /* The name of a caught exception.  */
1566       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1567       SYMBOL_CLASS (sym) = LOC_LABEL;
1568       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1569       SYMBOL_VALUE_ADDRESS (sym) = valu;
1570       add_symbol_to_list (sym, &local_symbols);
1571       break;
1572
1573     case 'f':
1574       /* A static function definition.  */
1575       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1576       SYMBOL_CLASS (sym) = LOC_BLOCK;
1577       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1578       add_symbol_to_list (sym, &file_symbols);
1579       /* fall into process_function_types.  */
1580
1581     process_function_types:
1582       /* Function result types are described as the result type in stabs.
1583          We need to convert this to the function-returning-type-X type
1584          in GDB.  E.g. "int" is converted to "function returning int".  */
1585       if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
1586         SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
1587
1588       /* All functions in C++ have prototypes.  */
1589       if (SYMBOL_LANGUAGE (sym) == language_cplus)
1590         TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1591
1592       /* fall into process_prototype_types */
1593
1594     process_prototype_types:
1595       /* Sun acc puts declared types of arguments here.  */
1596       if (*p == ';')
1597         {
1598           struct type *ftype = SYMBOL_TYPE (sym);
1599           int nsemi = 0;
1600           int nparams = 0;
1601           char *p1 = p;
1602
1603           /* Obtain a worst case guess for the number of arguments
1604              by counting the semicolons.  */
1605           while (*p1)
1606             {
1607               if (*p1++ == ';')
1608                 nsemi++;
1609             }
1610
1611           /* Allocate parameter information fields and fill them in. */
1612           TYPE_FIELDS (ftype) = (struct field *)
1613             TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
1614           while (*p++ == ';')
1615             {
1616               struct type *ptype;
1617
1618               /* A type number of zero indicates the start of varargs.
1619                  FIXME: GDB currently ignores vararg functions.  */
1620               if (p[0] == '0' && p[1] == '\0')
1621                 break;
1622               ptype = read_type (&p, objfile);
1623
1624               /* The Sun compilers mark integer arguments, which should
1625                  be promoted to the width of the calling conventions, with
1626                  a type which references itself. This type is turned into
1627                  a TYPE_CODE_VOID type by read_type, and we have to turn
1628                  it back into builtin_type_int here.
1629                  FIXME: Do we need a new builtin_type_promoted_int_arg ?  */
1630               if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
1631                 ptype = builtin_type_int;
1632               TYPE_FIELD_TYPE (ftype, nparams) = ptype;
1633               TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
1634             }
1635           TYPE_NFIELDS (ftype) = nparams;
1636           TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
1637         }
1638       break;
1639
1640     case 'F':
1641       /* A global function definition.  */
1642       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1643       SYMBOL_CLASS (sym) = LOC_BLOCK;
1644       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1645       add_symbol_to_list (sym, &global_symbols);
1646       goto process_function_types;
1647
1648     case 'G':
1649       /* For a class G (global) symbol, it appears that the
1650          value is not correct.  It is necessary to search for the
1651          corresponding linker definition to find the value.
1652          These definitions appear at the end of the namelist.  */
1653       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1654       SYMBOL_CLASS (sym) = LOC_STATIC;
1655       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1656       /* Don't add symbol references to global_sym_chain.
1657          Symbol references don't have valid names and wont't match up with
1658          minimal symbols when the global_sym_chain is relocated.
1659          We'll fixup symbol references when we fixup the defining symbol.  */
1660       if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1661         {
1662           i = hashname (SYMBOL_NAME (sym));
1663           SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1664           global_sym_chain[i] = sym;
1665         }
1666       add_symbol_to_list (sym, &global_symbols);
1667       break;
1668
1669       /* This case is faked by a conditional above,
1670          when there is no code letter in the dbx data.
1671          Dbx data never actually contains 'l'.  */
1672     case 's':
1673     case 'l':
1674       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1675       SYMBOL_CLASS (sym) = LOC_LOCAL;
1676       SYMBOL_VALUE (sym) = valu;
1677       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1678       add_symbol_to_list (sym, &local_symbols);
1679       break;
1680
1681     case 'p':
1682       if (*p == 'F')
1683         /* pF is a two-letter code that means a function parameter in Fortran.
1684            The type-number specifies the type of the return value.
1685            Translate it into a pointer-to-function type.  */
1686         {
1687           p++;
1688           SYMBOL_TYPE (sym)
1689             = lookup_pointer_type
1690             (lookup_function_type (read_type (&p, objfile)));
1691         }
1692       else
1693         SYMBOL_TYPE (sym) = read_type (&p, objfile);
1694
1695       /* Normally this is a parameter, a LOC_ARG.  On the i960, it
1696          can also be a LOC_LOCAL_ARG depending on symbol type.  */
1697 #ifndef DBX_PARM_SYMBOL_CLASS
1698 #define DBX_PARM_SYMBOL_CLASS(type)     LOC_ARG
1699 #endif
1700
1701       SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1702       SYMBOL_VALUE (sym) = valu;
1703       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1704       add_symbol_to_list (sym, &local_symbols);
1705
1706       if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
1707         {
1708           /* On little-endian machines, this crud is never necessary,
1709              and, if the extra bytes contain garbage, is harmful.  */
1710           break;
1711         }
1712
1713       /* If it's gcc-compiled, if it says `short', believe it.  */
1714       if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1715         break;
1716
1717       if (!BELIEVE_PCC_PROMOTION)
1718         {
1719           /* This is the signed type which arguments get promoted to.  */
1720           static struct type *pcc_promotion_type;
1721           /* This is the unsigned type which arguments get promoted to.  */
1722           static struct type *pcc_unsigned_promotion_type;
1723
1724           /* Call it "int" because this is mainly C lossage.  */
1725           if (pcc_promotion_type == NULL)
1726             pcc_promotion_type =
1727               init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1728                          0, "int", NULL);
1729
1730           if (pcc_unsigned_promotion_type == NULL)
1731             pcc_unsigned_promotion_type =
1732               init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1733                          TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1734
1735           if (BELIEVE_PCC_PROMOTION_TYPE)
1736             {
1737               /* This is defined on machines (e.g. sparc) where we
1738                  should believe the type of a PCC 'short' argument,
1739                  but shouldn't believe the address (the address is the
1740                  address of the corresponding int).
1741
1742                  My guess is that this correction, as opposed to
1743                  changing the parameter to an 'int' (as done below,
1744                  for PCC on most machines), is the right thing to do
1745                  on all machines, but I don't want to risk breaking
1746                  something that already works.  On most PCC machines,
1747                  the sparc problem doesn't come up because the calling
1748                  function has to zero the top bytes (not knowing
1749                  whether the called function wants an int or a short),
1750                  so there is little practical difference between an
1751                  int and a short (except perhaps what happens when the
1752                  GDB user types "print short_arg = 0x10000;").
1753
1754                  Hacked for SunOS 4.1 by gnu@cygnus.com.  In 4.1, the
1755                  compiler actually produces the correct address (we
1756                  don't need to fix it up).  I made this code adapt so
1757                  that it will offset the symbol if it was pointing at
1758                  an int-aligned location and not otherwise.  This way
1759                  you can use the same gdb for 4.0.x and 4.1 systems.
1760
1761                  If the parameter is shorter than an int, and is
1762                  integral (e.g. char, short, or unsigned equivalent),
1763                  and is claimed to be passed on an integer boundary,
1764                  don't believe it!  Offset the parameter's address to
1765                  the tail-end of that integer.  */
1766
1767               if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1768                   && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1769               && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1770                 {
1771                   SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1772                     - TYPE_LENGTH (SYMBOL_TYPE (sym));
1773                 }
1774               break;
1775             }
1776           else
1777             {
1778               /* If PCC says a parameter is a short or a char,
1779                  it is really an int.  */
1780               if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1781                   && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1782                 {
1783                   SYMBOL_TYPE (sym) =
1784                     TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1785                     ? pcc_unsigned_promotion_type
1786                     : pcc_promotion_type;
1787                 }
1788               break;
1789             }
1790         }
1791
1792     case 'P':
1793       /* acc seems to use P to declare the prototypes of functions that
1794          are referenced by this file.  gdb is not prepared to deal
1795          with this extra information.  FIXME, it ought to.  */
1796       if (type == N_FUN)
1797         {
1798           SYMBOL_TYPE (sym) = read_type (&p, objfile);
1799           goto process_prototype_types;
1800         }
1801       /*FALLTHROUGH */
1802
1803     case 'R':
1804       /* Parameter which is in a register.  */
1805       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1806       SYMBOL_CLASS (sym) = LOC_REGPARM;
1807       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1808       if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1809         {
1810           complain (&reg_value_complaint, SYMBOL_VALUE (sym),
1811                     NUM_REGS + NUM_PSEUDO_REGS,
1812                     SYMBOL_SOURCE_NAME (sym));
1813           SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
1814         }
1815       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1816       add_symbol_to_list (sym, &local_symbols);
1817       break;
1818
1819     case 'r':
1820       /* Register variable (either global or local).  */
1821       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1822       SYMBOL_CLASS (sym) = LOC_REGISTER;
1823       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1824       if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1825         {
1826           complain (&reg_value_complaint, SYMBOL_VALUE (sym),
1827                     NUM_REGS + NUM_PSEUDO_REGS,
1828                     SYMBOL_SOURCE_NAME (sym));
1829           SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
1830         }
1831       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1832       if (within_function)
1833         {
1834           /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1835              name to represent an argument passed in a register.
1836              GCC uses 'P' for the same case.  So if we find such a symbol pair
1837              we combine it into one 'P' symbol.  For Sun cc we need to do this
1838              regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1839              the 'p' symbol even if it never saves the argument onto the stack.
1840
1841              On most machines, we want to preserve both symbols, so that
1842              we can still get information about what is going on with the
1843              stack (VAX for computing args_printed, using stack slots instead
1844              of saved registers in backtraces, etc.).
1845
1846              Note that this code illegally combines
1847              main(argc) struct foo argc; { register struct foo argc; }
1848              but this case is considered pathological and causes a warning
1849              from a decent compiler.  */
1850
1851           if (local_symbols
1852               && local_symbols->nsyms > 0
1853 #ifndef USE_REGISTER_NOT_ARG
1854               && REG_STRUCT_HAS_ADDR_P ()
1855               && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1856                                       SYMBOL_TYPE (sym))
1857               && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1858                   || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1859                   || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1860                   || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1861 #endif
1862             )
1863             {
1864               struct symbol *prev_sym;
1865               prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1866               if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1867                    || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1868                   && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
1869                 {
1870                   SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1871                   /* Use the type from the LOC_REGISTER; that is the type
1872                      that is actually in that register.  */
1873                   SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1874                   SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1875                   sym = prev_sym;
1876                   break;
1877                 }
1878             }
1879           add_symbol_to_list (sym, &local_symbols);
1880         }
1881       else
1882         add_symbol_to_list (sym, &file_symbols);
1883       break;
1884
1885     case 'S':
1886       /* Static symbol at top level of file */
1887       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1888       SYMBOL_CLASS (sym) = LOC_STATIC;
1889       SYMBOL_VALUE_ADDRESS (sym) = valu;
1890 #ifdef STATIC_TRANSFORM_NAME
1891       if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1892         {
1893           struct minimal_symbol *msym;
1894           msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1895           if (msym != NULL)
1896             {
1897               SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1898               SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1899             }
1900         }
1901 #endif
1902       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1903       add_symbol_to_list (sym, &file_symbols);
1904       break;
1905
1906     case 't':
1907       /* Typedef */
1908       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1909
1910       /* For a nameless type, we don't want a create a symbol, thus we
1911          did not use `sym'. Return without further processing. */
1912       if (nameless)
1913         return NULL;
1914
1915       SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1916       SYMBOL_VALUE (sym) = valu;
1917       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1918       /* C++ vagaries: we may have a type which is derived from
1919          a base type which did not have its name defined when the
1920          derived class was output.  We fill in the derived class's
1921          base part member's name here in that case.  */
1922       if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1923         if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1924              || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1925             && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1926           {
1927             int j;
1928             for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1929               if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1930                 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1931                   type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1932           }
1933
1934       if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1935         {
1936           /* gcc-2.6 or later (when using -fvtable-thunks)
1937              emits a unique named type for a vtable entry.
1938              Some gdb code depends on that specific name. */
1939           extern const char vtbl_ptr_name[];
1940
1941           if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1942                && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1943               || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1944             {
1945               /* If we are giving a name to a type such as "pointer to
1946                  foo" or "function returning foo", we better not set
1947                  the TYPE_NAME.  If the program contains "typedef char
1948                  *caddr_t;", we don't want all variables of type char
1949                  * to print as caddr_t.  This is not just a
1950                  consequence of GDB's type management; PCC and GCC (at
1951                  least through version 2.4) both output variables of
1952                  either type char * or caddr_t with the type number
1953                  defined in the 't' symbol for caddr_t.  If a future
1954                  compiler cleans this up it GDB is not ready for it
1955                  yet, but if it becomes ready we somehow need to
1956                  disable this check (without breaking the PCC/GCC2.4
1957                  case).
1958
1959                  Sigh.
1960
1961                  Fortunately, this check seems not to be necessary
1962                  for anything except pointers or functions.  */
1963               /* ezannoni: 2000-10-26. This seems to apply for
1964                  versions of gcc older than 2.8. This was the original
1965                  problem: with the following code gdb would tell that
1966                  the type for name1 is caddr_t, and func is char()
1967                  typedef char *caddr_t;
1968                  char *name2;
1969                  struct x
1970                  {
1971                  char *name1;
1972                  } xx;
1973                  char *func()
1974                  {
1975                  }
1976                  main () {}
1977                  */
1978
1979               /* Pascal accepts names for pointer types. */
1980               if (current_subfile->language == language_pascal)
1981                 {
1982                   TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1983                 }
1984             }
1985           else
1986             TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1987         }
1988
1989       add_symbol_to_list (sym, &file_symbols);
1990       break;
1991
1992     case 'T':
1993       /* Struct, union, or enum tag.  For GNU C++, this can be be followed
1994          by 't' which means we are typedef'ing it as well.  */
1995       synonym = *p == 't';
1996
1997       if (synonym)
1998         p++;
1999       /* The semantics of C++ state that "struct foo { ... }" also defines 
2000          a typedef for "foo".  Unfortunately, cfront never makes the typedef
2001          when translating C++ into C.  We make the typedef here so that
2002          "ptype foo" works as expected for cfront translated code.  */
2003       else if (current_subfile->language == language_cplus)
2004         synonym = 1;
2005
2006       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2007
2008       /* For a nameless type, we don't want a create a symbol, thus we
2009          did not use `sym'. Return without further processing. */
2010       if (nameless)
2011         return NULL;
2012
2013       SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2014       SYMBOL_VALUE (sym) = valu;
2015       SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2016       if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
2017         TYPE_TAG_NAME (SYMBOL_TYPE (sym))
2018           = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2019       add_symbol_to_list (sym, &file_symbols);
2020
2021       if (synonym)
2022         {
2023           /* Clone the sym and then modify it. */
2024           register struct symbol *typedef_sym = (struct symbol *)
2025           obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
2026           *typedef_sym = *sym;
2027           SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2028           SYMBOL_VALUE (typedef_sym) = valu;
2029           SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2030           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
2031             TYPE_NAME (SYMBOL_TYPE (sym))
2032               = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2033           add_symbol_to_list (typedef_sym, &file_symbols);
2034         }
2035       break;
2036
2037     case 'V':
2038       /* Static symbol of local scope */
2039       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2040       SYMBOL_CLASS (sym) = LOC_STATIC;
2041       SYMBOL_VALUE_ADDRESS (sym) = valu;
2042 #ifdef STATIC_TRANSFORM_NAME
2043       if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
2044         {
2045           struct minimal_symbol *msym;
2046           msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
2047           if (msym != NULL)
2048             {
2049               SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
2050               SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2051             }
2052         }
2053 #endif
2054       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2055       if (os9k_stabs)
2056         add_symbol_to_list (sym, &global_symbols);
2057       else
2058         add_symbol_to_list (sym, &local_symbols);
2059       break;
2060
2061     case 'v':
2062       /* Reference parameter */
2063       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2064       SYMBOL_CLASS (sym) = LOC_REF_ARG;
2065       SYMBOL_VALUE (sym) = valu;
2066       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2067       add_symbol_to_list (sym, &local_symbols);
2068       break;
2069
2070     case 'a':
2071       /* Reference parameter which is in a register.  */
2072       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2073       SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2074       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2075       if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
2076         {
2077           complain (&reg_value_complaint, SYMBOL_VALUE (sym),
2078                     NUM_REGS + NUM_PSEUDO_REGS,
2079                     SYMBOL_SOURCE_NAME (sym));
2080           SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
2081         }
2082       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2083       add_symbol_to_list (sym, &local_symbols);
2084       break;
2085
2086     case 'X':
2087       /* This is used by Sun FORTRAN for "function result value".
2088          Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2089          that Pascal uses it too, but when I tried it Pascal used
2090          "x:3" (local symbol) instead.  */
2091       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2092       SYMBOL_CLASS (sym) = LOC_LOCAL;
2093       SYMBOL_VALUE (sym) = valu;
2094       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2095       add_symbol_to_list (sym, &local_symbols);
2096       break;
2097
2098       /* New code added to support cfront stabs strings.
2099          Note: case 'P' already handled above */
2100     case 'Z':
2101       /* Cfront type continuation coming up!
2102          Find the original definition and add to it.
2103          We'll have to do this for the typedef too,
2104          since we cloned the symbol to define a type in read_type.
2105          Stabs info examples:
2106          __1C :Ztl 
2107          foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2108          C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2109          where C is the name of the class.
2110          Unfortunately, we can't lookup the original symbol yet 'cuz 
2111          we haven't finished reading all the symbols.
2112          Instead, we save it for processing later */
2113       process_later (sym, p, resolve_cfront_continuation);
2114       SYMBOL_TYPE (sym) = error_type (&p, objfile);     /* FIXME! change later */
2115       SYMBOL_CLASS (sym) = LOC_CONST;
2116       SYMBOL_VALUE (sym) = 0;
2117       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2118       /* Don't add to list - we'll delete it later when 
2119          we add the continuation to the real sym */
2120       return sym;
2121       /* End of new code added to support cfront stabs strings */
2122
2123     default:
2124       SYMBOL_TYPE (sym) = error_type (&p, objfile);
2125       SYMBOL_CLASS (sym) = LOC_CONST;
2126       SYMBOL_VALUE (sym) = 0;
2127       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2128       add_symbol_to_list (sym, &file_symbols);
2129       break;
2130     }
2131
2132   /* When passing structures to a function, some systems sometimes pass
2133      the address in a register, not the structure itself. */
2134
2135   if (REG_STRUCT_HAS_ADDR_P ()
2136       && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2137       && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2138     {
2139       struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2140
2141       if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2142           || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2143           || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2144           || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2145         {
2146           /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2147              LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2148           if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2149             SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2150           /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2151              and subsequent arguments on the sparc, for example).  */
2152           else if (SYMBOL_CLASS (sym) == LOC_ARG)
2153             SYMBOL_CLASS (sym) = LOC_REF_ARG;
2154         }
2155     }
2156
2157   /* Is there more to parse?  For example LRS/alias information?  */
2158   while (*p && *p == ';')
2159     {
2160       p++;
2161       if (*p && p[0] == 'l' && p[1] == '(')
2162         {
2163           /* GNU extensions for live range splitting may be appended to 
2164              the end of the stab string.  eg. "l(#1,#2);l(#3,#5)" */
2165
2166           /* Resolve the live range and add it to SYM's live range list.  */
2167           if (!resolve_live_range (objfile, sym, p))
2168             return NULL;
2169
2170           /* Find end of live range info. */
2171           p = strchr (p, ')');
2172           if (!*p || *p != ')')
2173             {
2174               complain (&lrs_general_complaint, "live range format not recognized");
2175               return NULL;
2176             }
2177           p++;
2178         }
2179     }
2180   return sym;
2181 }
2182
2183 /* Add the live range found in P to the symbol SYM in objfile OBJFILE.  Returns
2184    non-zero on success, zero otherwise.  */
2185
2186 static int
2187 resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
2188 {
2189   int refnum;
2190   CORE_ADDR start, end;
2191
2192   /* Sanity check the beginning of the stabs string.  */
2193   if (!*p || *p != 'l')
2194     {
2195       complain (&lrs_general_complaint, "live range string 1");
2196       return 0;
2197     }
2198   p++;
2199
2200   if (!*p || *p != '(')
2201     {
2202       complain (&lrs_general_complaint, "live range string 2");
2203       return 0;
2204     }
2205   p++;
2206
2207   /* Get starting value of range and advance P past the reference id.
2208
2209      ?!? In theory, the process_reference should never fail, but we should
2210      catch that case just in case the compiler scrogged the stabs.  */
2211   refnum = process_reference (&p);
2212   start = ref_search_value (refnum);
2213   if (!start)
2214     {
2215       complain (&lrs_general_complaint, "Live range symbol not found 1");
2216       return 0;
2217     }
2218
2219   if (!*p || *p != ',')
2220     {
2221       complain (&lrs_general_complaint, "live range string 3");
2222       return 0;
2223     }
2224   p++;
2225
2226   /* Get ending value of range and advance P past the reference id.
2227
2228      ?!? In theory, the process_reference should never fail, but we should
2229      catch that case just in case the compiler scrogged the stabs.  */
2230   refnum = process_reference (&p);
2231   end = ref_search_value (refnum);
2232   if (!end)
2233     {
2234       complain (&lrs_general_complaint, "Live range symbol not found 2");
2235       return 0;
2236     }
2237
2238   if (!*p || *p != ')')
2239     {
2240       complain (&lrs_general_complaint, "live range string 4");
2241       return 0;
2242     }
2243
2244   /* Now that we know the bounds of the range, add it to the
2245      symbol.  */
2246   add_live_range (objfile, sym, start, end);
2247
2248   return 1;
2249 }
2250
2251 /* Add a new live range defined by START and END to the symbol SYM
2252    in objfile OBJFILE.  */
2253
2254 static void
2255 add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2256                 CORE_ADDR end)
2257 {
2258   struct range_list *r, *rs;
2259
2260   if (start >= end)
2261     {
2262       complain (&lrs_general_complaint, "end of live range follows start");
2263       return;
2264     }
2265
2266   /* Alloc new live range structure. */
2267   r = (struct range_list *)
2268     obstack_alloc (&objfile->type_obstack,
2269                    sizeof (struct range_list));
2270   r->start = start;
2271   r->end = end;
2272   r->next = 0;
2273
2274   /* Append this range to the symbol's range list. */
2275   if (!SYMBOL_RANGES (sym))
2276     SYMBOL_RANGES (sym) = r;
2277   else
2278     {
2279       /* Get the last range for the symbol. */
2280       for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2281         ;
2282       rs->next = r;
2283     }
2284 }
2285 \f
2286
2287 /* Skip rest of this symbol and return an error type.
2288
2289    General notes on error recovery:  error_type always skips to the
2290    end of the symbol (modulo cretinous dbx symbol name continuation).
2291    Thus code like this:
2292
2293    if (*(*pp)++ != ';')
2294    return error_type (pp, objfile);
2295
2296    is wrong because if *pp starts out pointing at '\0' (typically as the
2297    result of an earlier error), it will be incremented to point to the
2298    start of the next symbol, which might produce strange results, at least
2299    if you run off the end of the string table.  Instead use
2300
2301    if (**pp != ';')
2302    return error_type (pp, objfile);
2303    ++*pp;
2304
2305    or
2306
2307    if (**pp != ';')
2308    foo = error_type (pp, objfile);
2309    else
2310    ++*pp;
2311
2312    And in case it isn't obvious, the point of all this hair is so the compiler
2313    can define new types and new syntaxes, and old versions of the
2314    debugger will be able to read the new symbol tables.  */
2315
2316 static struct type *
2317 error_type (char **pp, struct objfile *objfile)
2318 {
2319   complain (&error_type_complaint);
2320   while (1)
2321     {
2322       /* Skip to end of symbol.  */
2323       while (**pp != '\0')
2324         {
2325           (*pp)++;
2326         }
2327
2328       /* Check for and handle cretinous dbx symbol name continuation!  */
2329       if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2330         {
2331           *pp = next_symbol_text (objfile);
2332         }
2333       else
2334         {
2335           break;
2336         }
2337     }
2338   return (builtin_type_error);
2339 }
2340 \f
2341
2342 /* Read type information or a type definition; return the type.  Even
2343    though this routine accepts either type information or a type
2344    definition, the distinction is relevant--some parts of stabsread.c
2345    assume that type information starts with a digit, '-', or '(' in
2346    deciding whether to call read_type.  */
2347
2348 struct type *
2349 read_type (register char **pp, struct objfile *objfile)
2350 {
2351   register struct type *type = 0;
2352   struct type *type1;
2353   int typenums[2];
2354   char type_descriptor;
2355
2356   /* Size in bits of type if specified by a type attribute, or -1 if
2357      there is no size attribute.  */
2358   int type_size = -1;
2359
2360   /* Used to distinguish string and bitstring from char-array and set. */
2361   int is_string = 0;
2362
2363   /* Used to distinguish vector from array. */
2364   int is_vector = 0;
2365
2366   /* Read type number if present.  The type number may be omitted.
2367      for instance in a two-dimensional array declared with type
2368      "ar1;1;10;ar1;1;10;4".  */
2369   if ((**pp >= '0' && **pp <= '9')
2370       || **pp == '('
2371       || **pp == '-')
2372     {
2373       if (read_type_number (pp, typenums) != 0)
2374         return error_type (pp, objfile);
2375
2376       /* Type is not being defined here.  Either it already exists,
2377          or this is a forward reference to it.  dbx_alloc_type handles
2378          both cases.  */
2379       if (**pp != '=')
2380         return dbx_alloc_type (typenums, objfile);
2381
2382       /* Type is being defined here.  */
2383       /* Skip the '='.
2384          Also skip the type descriptor - we get it below with (*pp)[-1].  */
2385       (*pp) += 2;
2386     }
2387   else
2388     {
2389       /* 'typenums=' not present, type is anonymous.  Read and return
2390          the definition, but don't put it in the type vector.  */
2391       typenums[0] = typenums[1] = -1;
2392       (*pp)++;
2393     }
2394
2395 again:
2396   type_descriptor = (*pp)[-1];
2397   switch (type_descriptor)
2398     {
2399     case 'x':
2400       {
2401         enum type_code code;
2402
2403         /* Used to index through file_symbols.  */
2404         struct pending *ppt;
2405         int i;
2406
2407         /* Name including "struct", etc.  */
2408         char *type_name;
2409
2410         {
2411           char *from, *to, *p, *q1, *q2;
2412
2413           /* Set the type code according to the following letter.  */
2414           switch ((*pp)[0])
2415             {
2416             case 's':
2417               code = TYPE_CODE_STRUCT;
2418               break;
2419             case 'u':
2420               code = TYPE_CODE_UNION;
2421               break;
2422             case 'e':
2423               code = TYPE_CODE_ENUM;
2424               break;
2425             default:
2426               {
2427                 /* Complain and keep going, so compilers can invent new
2428                    cross-reference types.  */
2429                 static struct complaint msg =
2430                 {"Unrecognized cross-reference type `%c'", 0, 0};
2431                 complain (&msg, (*pp)[0]);
2432                 code = TYPE_CODE_STRUCT;
2433                 break;
2434               }
2435             }
2436
2437           q1 = strchr (*pp, '<');
2438           p = strchr (*pp, ':');
2439           if (p == NULL)
2440             return error_type (pp, objfile);
2441           if (q1 && p > q1 && p[1] == ':')
2442             {
2443               int nesting_level = 0;
2444               for (q2 = q1; *q2; q2++)
2445                 {
2446                   if (*q2 == '<')
2447                     nesting_level++;
2448                   else if (*q2 == '>')
2449                     nesting_level--;
2450                   else if (*q2 == ':' && nesting_level == 0)
2451                     break;
2452                 }
2453               p = q2;
2454               if (*p != ':')
2455                 return error_type (pp, objfile);
2456             }
2457           to = type_name =
2458             (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2459
2460           /* Copy the name.  */
2461           from = *pp + 1;
2462           while (from < p)
2463             *to++ = *from++;
2464           *to = '\0';
2465
2466           /* Set the pointer ahead of the name which we just read, and
2467              the colon.  */
2468           *pp = from + 1;
2469         }
2470
2471         /* Now check to see whether the type has already been
2472            declared.  This was written for arrays of cross-referenced
2473            types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2474            sure it is not necessary anymore.  But it might be a good
2475            idea, to save a little memory.  */
2476
2477         for (ppt = file_symbols; ppt; ppt = ppt->next)
2478           for (i = 0; i < ppt->nsyms; i++)
2479             {
2480               struct symbol *sym = ppt->symbol[i];
2481
2482               if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2483                   && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2484                   && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2485                   && STREQ (SYMBOL_NAME (sym), type_name))
2486                 {
2487                   obstack_free (&objfile->type_obstack, type_name);
2488                   type = SYMBOL_TYPE (sym);
2489                   return type;
2490                 }
2491             }
2492
2493         /* Didn't find the type to which this refers, so we must
2494            be dealing with a forward reference.  Allocate a type
2495            structure for it, and keep track of it so we can
2496            fill in the rest of the fields when we get the full
2497            type.  */
2498         type = dbx_alloc_type (typenums, objfile);
2499         TYPE_CODE (type) = code;
2500         TYPE_TAG_NAME (type) = type_name;
2501         INIT_CPLUS_SPECIFIC (type);
2502         TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2503
2504         add_undefined_type (type);
2505         return type;
2506       }
2507
2508     case '-':                   /* RS/6000 built-in type */
2509     case '0':
2510     case '1':
2511     case '2':
2512     case '3':
2513     case '4':
2514     case '5':
2515     case '6':
2516     case '7':
2517     case '8':
2518     case '9':
2519     case '(':
2520       (*pp)--;
2521
2522       /* We deal with something like t(1,2)=(3,4)=... which
2523          the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2524
2525       /* Allocate and enter the typedef type first.
2526          This handles recursive types. */
2527       type = dbx_alloc_type (typenums, objfile);
2528       TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2529       {
2530         struct type *xtype = read_type (pp, objfile);
2531         if (type == xtype)
2532           {
2533             /* It's being defined as itself.  That means it is "void".  */
2534             TYPE_CODE (type) = TYPE_CODE_VOID;
2535             TYPE_LENGTH (type) = 1;
2536           }
2537         else if (type_size >= 0 || is_string)
2538           {
2539             /* This is the absolute wrong way to construct types.  Every
2540                other debug format has found a way around this problem and
2541                the related problems with unnecessarily stubbed types;
2542                someone motivated should attempt to clean up the issue
2543                here as well.  Once a type pointed to has been created it
2544                should not be modified.
2545
2546                Well, it's not *absolutely* wrong.  Constructing recursive
2547                types (trees, linked lists) necessarily entails modifying
2548                types after creating them.  Constructing any loop structure
2549                entails side effects.  The Dwarf 2 reader does handle this
2550                more gracefully (it never constructs more than once
2551                instance of a type object, so it doesn't have to copy type
2552                objects wholesale), but it still mutates type objects after
2553                other folks have references to them.
2554
2555                Keep in mind that this circularity/mutation issue shows up
2556                at the source language level, too: C's "incomplete types",
2557                for example.  So the proper cleanup, I think, would be to
2558                limit GDB's type smashing to match exactly those required
2559                by the source language.  So GDB could have a
2560                "complete_this_type" function, but never create unnecessary
2561                copies of a type otherwise.  */
2562             replace_type (type, xtype);
2563             TYPE_NAME (type) = NULL;
2564             TYPE_TAG_NAME (type) = NULL;
2565           }
2566         else
2567           {
2568             TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2569             TYPE_TARGET_TYPE (type) = xtype;
2570           }
2571       }
2572       break;
2573
2574       /* In the following types, we must be sure to overwrite any existing
2575          type that the typenums refer to, rather than allocating a new one
2576          and making the typenums point to the new one.  This is because there
2577          may already be pointers to the existing type (if it had been
2578          forward-referenced), and we must change it to a pointer, function,
2579          reference, or whatever, *in-place*.  */
2580
2581     case '*':                   /* Pointer to another type */
2582       type1 = read_type (pp, objfile);
2583       type = make_pointer_type (type1, dbx_lookup_type (typenums));
2584       break;
2585
2586     case '&':                   /* Reference to another type */
2587       type1 = read_type (pp, objfile);
2588       type = make_reference_type (type1, dbx_lookup_type (typenums));
2589       break;
2590
2591     case 'f':                   /* Function returning another type */
2592       if (os9k_stabs && **pp == '(')
2593         {
2594           /* Function prototype; parse it.
2595              We must conditionalize this on os9k_stabs because otherwise
2596              it could be confused with a Sun-style (1,3) typenumber
2597              (I think).  */
2598           struct type *t;
2599           ++*pp;
2600           while (**pp != ')')
2601             {
2602               t = read_type (pp, objfile);
2603               if (**pp == ',')
2604                 ++ * pp;
2605             }
2606         }
2607       type1 = read_type (pp, objfile);
2608       type = make_function_type (type1, dbx_lookup_type (typenums));
2609       break;
2610
2611     case 'g':                   /* Prototyped function.  (Sun)  */
2612       {
2613         /* Unresolved questions:
2614
2615            - According to Sun's ``STABS Interface Manual'', for 'f'
2616            and 'F' symbol descriptors, a `0' in the argument type list
2617            indicates a varargs function.  But it doesn't say how 'g'
2618            type descriptors represent that info.  Someone with access
2619            to Sun's toolchain should try it out.
2620
2621            - According to the comment in define_symbol (search for
2622            `process_prototype_types:'), Sun emits integer arguments as
2623            types which ref themselves --- like `void' types.  Do we
2624            have to deal with that here, too?  Again, someone with
2625            access to Sun's toolchain should try it out and let us
2626            know.  */
2627
2628         const char *type_start = (*pp) - 1;
2629         struct type *return_type = read_type (pp, objfile);
2630         struct type *func_type
2631           = make_function_type (return_type, dbx_lookup_type (typenums));
2632         struct type_list {
2633           struct type *type;
2634           struct type_list *next;
2635         } *arg_types = 0;
2636         int num_args = 0;
2637
2638         while (**pp && **pp != '#')
2639           {
2640             struct type *arg_type = read_type (pp, objfile);
2641             struct type_list *new = alloca (sizeof (*new));
2642             new->type = arg_type;
2643             new->next = arg_types;
2644             arg_types = new;
2645             num_args++;
2646           }
2647         if (**pp == '#')
2648           ++*pp;
2649         else
2650           {
2651             static struct complaint msg = {
2652               "Prototyped function type didn't end arguments with `#':\n%s",
2653               0, 0
2654             };
2655             complain (&msg, type_start);
2656           }
2657
2658         /* If there is just one argument whose type is `void', then
2659            that's just an empty argument list.  */
2660         if (arg_types
2661             && ! arg_types->next
2662             && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
2663           num_args = 0;
2664
2665         TYPE_FIELDS (func_type)
2666           = (struct field *) TYPE_ALLOC (func_type,
2667                                          num_args * sizeof (struct field));
2668         memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
2669         {
2670           int i;
2671           struct type_list *t;
2672
2673           /* We stuck each argument type onto the front of the list
2674              when we read it, so the list is reversed.  Build the
2675              fields array right-to-left.  */
2676           for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
2677             TYPE_FIELD_TYPE (func_type, i) = t->type;
2678         }
2679         TYPE_NFIELDS (func_type) = num_args;
2680         TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
2681
2682         type = func_type;
2683         break;
2684       }
2685
2686     case 'k':                   /* Const qualifier on some type (Sun) */
2687     case 'c':                   /* Const qualifier on some type (OS9000) */
2688       /* Because 'c' means other things to AIX and 'k' is perfectly good,
2689          only accept 'c' in the os9k_stabs case.  */
2690       if (type_descriptor == 'c' && !os9k_stabs)
2691         return error_type (pp, objfile);
2692       type = read_type (pp, objfile);
2693       type = make_cv_type (1, TYPE_VOLATILE (type), type,
2694                            dbx_lookup_type (typenums));
2695       break;
2696
2697     case 'B':                   /* Volatile qual on some type (Sun) */
2698     case 'i':                   /* Volatile qual on some type (OS9000) */
2699       /* Because 'i' means other things to AIX and 'B' is perfectly good,
2700          only accept 'i' in the os9k_stabs case.  */
2701       if (type_descriptor == 'i' && !os9k_stabs)
2702         return error_type (pp, objfile);
2703       type = read_type (pp, objfile);
2704       type = make_cv_type (TYPE_CONST (type), 1, type,
2705                            dbx_lookup_type (typenums));
2706       break;
2707
2708     case '@':
2709       if (isdigit (**pp) || **pp == '(' || **pp == '-')
2710         {                       /* Member (class & variable) type */
2711           /* FIXME -- we should be doing smash_to_XXX types here.  */
2712
2713           struct type *domain = read_type (pp, objfile);
2714           struct type *memtype;
2715
2716           if (**pp != ',')
2717             /* Invalid member type data format.  */
2718             return error_type (pp, objfile);
2719           ++*pp;
2720
2721           memtype = read_type (pp, objfile);
2722           type = dbx_alloc_type (typenums, objfile);
2723           smash_to_member_type (type, domain, memtype);
2724         }
2725       else
2726         /* type attribute */
2727         {
2728           char *attr = *pp;
2729           /* Skip to the semicolon.  */
2730           while (**pp != ';' && **pp != '\0')
2731             ++(*pp);
2732           if (**pp == '\0')
2733             return error_type (pp, objfile);
2734           else
2735             ++ * pp;            /* Skip the semicolon.  */
2736
2737           switch (*attr)
2738             {
2739             case 's':           /* Size attribute */
2740               type_size = atoi (attr + 1);
2741               if (type_size <= 0)
2742                 type_size = -1;
2743               break;
2744
2745             case 'S':           /* String attribute */
2746               /* FIXME: check to see if following type is array? */
2747               is_string = 1;
2748               break;
2749
2750             case 'V':           /* Vector attribute */
2751               /* FIXME: check to see if following type is array? */
2752               is_vector = 1;
2753               break;
2754
2755             default:
2756               /* Ignore unrecognized type attributes, so future compilers
2757                  can invent new ones.  */
2758               break;
2759             }
2760           ++*pp;
2761           goto again;
2762         }
2763       break;
2764
2765     case '#':                   /* Method (class & fn) type */
2766       if ((*pp)[0] == '#')
2767         {
2768           /* We'll get the parameter types from the name.  */
2769           struct type *return_type;
2770
2771           (*pp)++;
2772           return_type = read_type (pp, objfile);
2773           if (*(*pp)++ != ';')
2774             complain (&invalid_member_complaint, symnum);
2775           type = allocate_stub_method (return_type);
2776           if (typenums[0] != -1)
2777             *dbx_lookup_type (typenums) = type;
2778         }
2779       else
2780         {
2781           struct type *domain = read_type (pp, objfile);
2782           struct type *return_type;
2783           struct type **args;
2784
2785           if (**pp != ',')
2786             /* Invalid member type data format.  */
2787             return error_type (pp, objfile);
2788           else
2789             ++(*pp);
2790
2791           return_type = read_type (pp, objfile);
2792           args = read_args (pp, ';', objfile);
2793           type = dbx_alloc_type (typenums, objfile);
2794           smash_to_method_type (type, domain, return_type, args);
2795         }
2796       break;
2797
2798     case 'r':                   /* Range type */
2799       type = read_range_type (pp, typenums, objfile);
2800       if (typenums[0] != -1)
2801         *dbx_lookup_type (typenums) = type;
2802       break;
2803
2804     case 'b':
2805       if (os9k_stabs)
2806         /* Const and volatile qualified type.  */
2807         type = read_type (pp, objfile);
2808       else
2809         {
2810           /* Sun ACC builtin int type */
2811           type = read_sun_builtin_type (pp, typenums, objfile);
2812           if (typenums[0] != -1)
2813             *dbx_lookup_type (typenums) = type;
2814         }
2815       break;
2816
2817     case 'R':                   /* Sun ACC builtin float type */
2818       type = read_sun_floating_type (pp, typenums, objfile);
2819       if (typenums[0] != -1)
2820         *dbx_lookup_type (typenums) = type;
2821       break;
2822
2823     case 'e':                   /* Enumeration type */
2824       type = dbx_alloc_type (typenums, objfile);
2825       type = read_enum_type (pp, type, objfile);
2826       if (typenums[0] != -1)
2827         *dbx_lookup_type (typenums) = type;
2828       break;
2829
2830     case 's':                   /* Struct type */
2831     case 'u':                   /* Union type */
2832       {
2833         enum type_code type_code = TYPE_CODE_UNDEF;
2834         type = dbx_alloc_type (typenums, objfile);
2835         switch (type_descriptor)
2836           {
2837           case 's':
2838             type_code = TYPE_CODE_STRUCT;
2839             break;
2840           case 'u':
2841             type_code = TYPE_CODE_UNION;
2842             break;
2843           }
2844         type = read_struct_type (pp, type, type_code, objfile);
2845         break;
2846       }
2847
2848     case 'a':                   /* Array type */
2849       if (**pp != 'r')
2850         return error_type (pp, objfile);
2851       ++*pp;
2852
2853       type = dbx_alloc_type (typenums, objfile);
2854       type = read_array_type (pp, type, objfile);
2855       if (is_string)
2856         TYPE_CODE (type) = TYPE_CODE_STRING;
2857       if (is_vector)
2858         TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
2859       break;
2860
2861     case 'S':                   /* Set or bitstring  type */
2862       type1 = read_type (pp, objfile);
2863       type = create_set_type ((struct type *) NULL, type1);
2864       if (is_string)
2865         TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2866       if (typenums[0] != -1)
2867         *dbx_lookup_type (typenums) = type;
2868       break;
2869
2870     default:
2871       --*pp;                    /* Go back to the symbol in error */
2872       /* Particularly important if it was \0! */
2873       return error_type (pp, objfile);
2874     }
2875
2876   if (type == 0)
2877     {
2878       warning ("GDB internal error, type is NULL in stabsread.c\n");
2879       return error_type (pp, objfile);
2880     }
2881
2882   /* Size specified in a type attribute overrides any other size.  */
2883   if (type_size != -1)
2884     TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2885
2886   return type;
2887 }
2888 \f
2889 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2890    Return the proper type node for a given builtin type number. */
2891
2892 static struct type *
2893 rs6000_builtin_type (int typenum)
2894 {
2895   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
2896 #define NUMBER_RECOGNIZED 34
2897   /* This includes an empty slot for type number -0.  */
2898   static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2899   struct type *rettype = NULL;
2900
2901   if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2902     {
2903       complain (&rs6000_builtin_complaint, typenum);
2904       return builtin_type_error;
2905     }
2906   if (negative_types[-typenum] != NULL)
2907     return negative_types[-typenum];
2908
2909 #if TARGET_CHAR_BIT != 8
2910 #error This code wrong for TARGET_CHAR_BIT not 8
2911   /* These definitions all assume that TARGET_CHAR_BIT is 8.  I think
2912      that if that ever becomes not true, the correct fix will be to
2913      make the size in the struct type to be in bits, not in units of
2914      TARGET_CHAR_BIT.  */
2915 #endif
2916
2917   switch (-typenum)
2918     {
2919     case 1:
2920       /* The size of this and all the other types are fixed, defined
2921          by the debugging format.  If there is a type called "int" which
2922          is other than 32 bits, then it should use a new negative type
2923          number (or avoid negative type numbers for that case).
2924          See stabs.texinfo.  */
2925       rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2926       break;
2927     case 2:
2928       rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2929       break;
2930     case 3:
2931       rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2932       break;
2933     case 4:
2934       rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2935       break;
2936     case 5:
2937       rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2938                            "unsigned char", NULL);
2939       break;
2940     case 6:
2941       rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2942       break;
2943     case 7:
2944       rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2945                            "unsigned short", NULL);
2946       break;
2947     case 8:
2948       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2949                            "unsigned int", NULL);
2950       break;
2951     case 9:
2952       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2953                            "unsigned", NULL);
2954     case 10:
2955       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2956                            "unsigned long", NULL);
2957       break;
2958     case 11:
2959       rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2960       break;
2961     case 12:
2962       /* IEEE single precision (32 bit).  */
2963       rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2964       break;
2965     case 13:
2966       /* IEEE double precision (64 bit).  */
2967       rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2968       break;
2969     case 14:
2970       /* This is an IEEE double on the RS/6000, and different machines with
2971          different sizes for "long double" should use different negative
2972          type numbers.  See stabs.texinfo.  */
2973       rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2974       break;
2975     case 15:
2976       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2977       break;
2978     case 16:
2979       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2980                            "boolean", NULL);
2981       break;
2982     case 17:
2983       rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2984       break;
2985     case 18:
2986       rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2987       break;
2988     case 19:
2989       rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2990       break;
2991     case 20:
2992       rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2993                            "character", NULL);
2994       break;
2995     case 21:
2996       rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2997                            "logical*1", NULL);
2998       break;
2999     case 22:
3000       rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
3001                            "logical*2", NULL);
3002       break;
3003     case 23:
3004       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
3005                            "logical*4", NULL);
3006       break;
3007     case 24:
3008       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
3009                            "logical", NULL);
3010       break;
3011     case 25:
3012       /* Complex type consisting of two IEEE single precision values.  */
3013       rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
3014       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
3015                                               NULL);
3016       break;
3017     case 26:
3018       /* Complex type consisting of two IEEE double precision values.  */
3019       rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
3020       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
3021                                               NULL);
3022       break;
3023     case 27:
3024       rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
3025       break;
3026     case 28:
3027       rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
3028       break;
3029     case 29:
3030       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
3031       break;
3032     case 30:
3033       rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
3034       break;
3035     case 31:
3036       rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
3037       break;
3038     case 32:
3039       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3040                            "unsigned long long", NULL);
3041       break;
3042     case 33:
3043       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3044                            "logical*8", NULL);
3045       break;
3046     case 34:
3047       rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
3048       break;
3049     }
3050   negative_types[-typenum] = rettype;
3051   return rettype;
3052 }
3053 \f
3054 /* This page contains subroutines of read_type.  */
3055
3056 /* Read member function stabs info for C++ classes.  The form of each member
3057    function data is:
3058
3059    NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
3060
3061    An example with two member functions is:
3062
3063    afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
3064
3065    For the case of overloaded operators, the format is op$::*.funcs, where
3066    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
3067    name (such as `+=') and `.' marks the end of the operator name.
3068
3069    Returns 1 for success, 0 for failure.  */
3070
3071 static int
3072 read_member_functions (struct field_info *fip, char **pp, struct type *type,
3073                        struct objfile *objfile)
3074 {
3075   int nfn_fields = 0;
3076   int length = 0;
3077   /* Total number of member functions defined in this class.  If the class
3078      defines two `f' functions, and one `g' function, then this will have
3079      the value 3.  */
3080   int total_length = 0;
3081   int i;
3082   struct next_fnfield
3083     {
3084       struct next_fnfield *next;
3085       struct fn_field fn_field;
3086     }
3087    *sublist;
3088   struct type *look_ahead_type;
3089   struct next_fnfieldlist *new_fnlist;
3090   struct next_fnfield *new_sublist;
3091   char *main_fn_name;
3092   register char *p;
3093
3094   /* Process each list until we find something that is not a member function
3095      or find the end of the functions. */
3096
3097   while (**pp != ';')
3098     {
3099       /* We should be positioned at the start of the function name.
3100          Scan forward to find the first ':' and if it is not the
3101          first of a "::" delimiter, then this is not a member function. */
3102       p = *pp;
3103       while (*p != ':')
3104         {
3105           p++;
3106         }
3107       if (p[1] != ':')
3108         {
3109           break;
3110         }
3111
3112       sublist = NULL;
3113       look_ahead_type = NULL;
3114       length = 0;
3115
3116       new_fnlist = (struct next_fnfieldlist *)
3117         xmalloc (sizeof (struct next_fnfieldlist));
3118       make_cleanup (xfree, new_fnlist);
3119       memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
3120
3121       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
3122         {
3123           /* This is a completely wierd case.  In order to stuff in the
3124              names that might contain colons (the usual name delimiter),
3125              Mike Tiemann defined a different name format which is
3126              signalled if the identifier is "op$".  In that case, the
3127              format is "op$::XXXX." where XXXX is the name.  This is
3128              used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
3129           /* This lets the user type "break operator+".
3130              We could just put in "+" as the name, but that wouldn't
3131              work for "*".  */
3132           static char opname[32] =
3133           {'o', 'p', CPLUS_MARKER};
3134           char *o = opname + 3;
3135
3136           /* Skip past '::'.  */
3137           *pp = p + 2;
3138
3139           STABS_CONTINUE (pp, objfile);
3140           p = *pp;
3141           while (*p != '.')
3142             {
3143               *o++ = *p++;
3144             }
3145           main_fn_name = savestring (opname, o - opname);
3146           /* Skip past '.'  */
3147           *pp = p + 1;
3148         }
3149       else
3150         {
3151           main_fn_name = savestring (*pp, p - *pp);
3152           /* Skip past '::'.  */
3153           *pp = p + 2;
3154         }
3155       new_fnlist->fn_fieldlist.name = main_fn_name;
3156
3157       do
3158         {
3159           new_sublist =
3160             (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
3161           make_cleanup (xfree, new_sublist);
3162           memset (new_sublist, 0, sizeof (struct next_fnfield));
3163
3164           /* Check for and handle cretinous dbx symbol name continuation!  */
3165           if (look_ahead_type == NULL)
3166             {
3167               /* Normal case. */
3168               STABS_CONTINUE (pp, objfile);
3169
3170               new_sublist->fn_field.type = read_type (pp, objfile);
3171               if (**pp != ':')
3172                 {
3173                   /* Invalid symtab info for member function.  */
3174                   return 0;
3175                 }
3176             }
3177           else
3178             {
3179               /* g++ version 1 kludge */
3180               new_sublist->fn_field.type = look_ahead_type;
3181               look_ahead_type = NULL;
3182             }
3183
3184           (*pp)++;
3185           p = *pp;
3186           while (*p != ';')
3187             {
3188               p++;
3189             }
3190
3191           /* If this is just a stub, then we don't have the real name here. */
3192
3193           if (TYPE_STUB (new_sublist->fn_field.type))
3194             {
3195               if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3196                 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3197               new_sublist->fn_field.is_stub = 1;
3198             }
3199           new_sublist->fn_field.physname = savestring (*pp, p - *pp);
3200           *pp = p + 1;
3201
3202           /* Set this member function's visibility fields.  */
3203           switch (*(*pp)++)
3204             {
3205             case VISIBILITY_PRIVATE:
3206               new_sublist->fn_field.is_private = 1;
3207               break;
3208             case VISIBILITY_PROTECTED:
3209               new_sublist->fn_field.is_protected = 1;
3210               break;
3211             }
3212
3213           STABS_CONTINUE (pp, objfile);
3214           switch (**pp)
3215             {
3216             case 'A':           /* Normal functions. */
3217               new_sublist->fn_field.is_const = 0;
3218               new_sublist->fn_field.is_volatile = 0;
3219               (*pp)++;
3220               break;
3221             case 'B':           /* `const' member functions. */
3222               new_sublist->fn_field.is_const = 1;
3223               new_sublist->fn_field.is_volatile = 0;
3224               (*pp)++;
3225               break;
3226             case 'C':           /* `volatile' member function. */
3227               new_sublist->fn_field.is_const = 0;
3228               new_sublist->fn_field.is_volatile = 1;
3229               (*pp)++;
3230               break;
3231             case 'D':           /* `const volatile' member function. */
3232               new_sublist->fn_field.is_const = 1;
3233               new_sublist->fn_field.is_volatile = 1;
3234               (*pp)++;
3235               break;
3236             case '*':           /* File compiled with g++ version 1 -- no info */
3237             case '?':
3238             case '.':
3239               break;
3240             default:
3241               complain (&const_vol_complaint, **pp);
3242               break;
3243             }
3244
3245           switch (*(*pp)++)
3246             {
3247             case '*':
3248               {
3249                 int nbits;
3250                 /* virtual member function, followed by index.
3251                    The sign bit is set to distinguish pointers-to-methods
3252                    from virtual function indicies.  Since the array is
3253                    in words, the quantity must be shifted left by 1
3254                    on 16 bit machine, and by 2 on 32 bit machine, forcing
3255                    the sign bit out, and usable as a valid index into
3256                    the array.  Remove the sign bit here.  */
3257                 new_sublist->fn_field.voffset =
3258                   (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3259                 if (nbits != 0)
3260                   return 0;
3261
3262                 STABS_CONTINUE (pp, objfile);
3263                 if (**pp == ';' || **pp == '\0')
3264                   {
3265                     /* Must be g++ version 1.  */
3266                     new_sublist->fn_field.fcontext = 0;
3267                   }
3268                 else
3269                   {
3270                     /* Figure out from whence this virtual function came.
3271                        It may belong to virtual function table of
3272                        one of its baseclasses.  */
3273                     look_ahead_type = read_type (pp, objfile);
3274                     if (**pp == ':')
3275                       {
3276                         /* g++ version 1 overloaded methods. */
3277                       }
3278                     else
3279                       {
3280                         new_sublist->fn_field.fcontext = look_ahead_type;
3281                         if (**pp != ';')
3282                           {
3283                             return 0;
3284                           }
3285                         else
3286                           {
3287                             ++*pp;
3288                           }
3289                         look_ahead_type = NULL;
3290                       }
3291                   }
3292                 break;
3293               }
3294             case '?':
3295               /* static member function.  */
3296               {
3297                 int slen = strlen (main_fn_name);
3298
3299                 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3300
3301                 /* For static member functions, we can't tell if they
3302                    are stubbed, as they are put out as functions, and not as
3303                    methods.
3304                    GCC v2 emits the fully mangled name if
3305                    dbxout.c:flag_minimal_debug is not set, so we have to
3306                    detect a fully mangled physname here and set is_stub
3307                    accordingly.  Fully mangled physnames in v2 start with
3308                    the member function name, followed by two underscores.
3309                    GCC v3 currently always emits stubbed member functions,
3310                    but with fully mangled physnames, which start with _Z.  */
3311                 if (!(strncmp (new_sublist->fn_field.physname,
3312                                main_fn_name, slen) == 0
3313                       && new_sublist->fn_field.physname[slen] == '_'
3314                       && new_sublist->fn_field.physname[slen + 1] == '_'))
3315                   {
3316                     new_sublist->fn_field.is_stub = 1;
3317                   }
3318                 break;
3319               }
3320
3321             default:
3322               /* error */
3323               complain (&member_fn_complaint, (*pp)[-1]);
3324               /* Fall through into normal member function.  */
3325
3326             case '.':
3327               /* normal member function.  */
3328               new_sublist->fn_field.voffset = 0;
3329               new_sublist->fn_field.fcontext = 0;
3330               break;
3331             }
3332
3333           new_sublist->next = sublist;
3334           sublist = new_sublist;
3335           length++;
3336           STABS_CONTINUE (pp, objfile);
3337         }
3338       while (**pp != ';' && **pp != '\0');
3339
3340       (*pp)++;
3341       STABS_CONTINUE (pp, objfile);
3342
3343       /* Skip GCC 3.X member functions which are duplicates of the callable
3344          constructor/destructor.  */
3345       if (strcmp (main_fn_name, "__base_ctor") == 0
3346           || strcmp (main_fn_name, "__base_dtor") == 0
3347           || strcmp (main_fn_name, "__deleting_dtor") == 0)
3348         {
3349           xfree (main_fn_name);
3350         }
3351       else
3352         {
3353           new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3354             obstack_alloc (&objfile->type_obstack,
3355                            sizeof (struct fn_field) * length);
3356           memset (new_fnlist->fn_fieldlist.fn_fields, 0,
3357                   sizeof (struct fn_field) * length);
3358           for (i = length; (i--, sublist); sublist = sublist->next)
3359             {
3360               new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
3361             }
3362
3363           new_fnlist->fn_fieldlist.length = length;
3364           new_fnlist->next = fip->fnlist;
3365           fip->fnlist = new_fnlist;
3366           nfn_fields++;
3367           total_length += length;
3368         }
3369     }
3370
3371   if (nfn_fields)
3372     {
3373       ALLOCATE_CPLUS_STRUCT_TYPE (type);
3374       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3375         TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3376       memset (TYPE_FN_FIELDLISTS (type), 0,
3377               sizeof (struct fn_fieldlist) * nfn_fields);
3378       TYPE_NFN_FIELDS (type) = nfn_fields;
3379       TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3380     }
3381
3382   return 1;
3383 }
3384
3385 /* Special GNU C++ name.
3386
3387    Returns 1 for success, 0 for failure.  "failure" means that we can't
3388    keep parsing and it's time for error_type().  */
3389
3390 static int
3391 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3392                  struct objfile *objfile)
3393 {
3394   register char *p;
3395   char *name;
3396   char cpp_abbrev;
3397   struct type *context;
3398
3399   p = *pp;
3400   if (*++p == 'v')
3401     {
3402       name = NULL;
3403       cpp_abbrev = *++p;
3404
3405       *pp = p + 1;
3406
3407       /* At this point, *pp points to something like "22:23=*22...",
3408          where the type number before the ':' is the "context" and
3409          everything after is a regular type definition.  Lookup the
3410          type, find it's name, and construct the field name. */
3411
3412       context = read_type (pp, objfile);
3413
3414       switch (cpp_abbrev)
3415         {
3416         case 'f':               /* $vf -- a virtual function table pointer */
3417           name = type_name_no_tag (context);
3418           if (name == NULL)
3419           {
3420                   name = "";
3421           }
3422           fip->list->field.name =
3423             obconcat (&objfile->type_obstack, vptr_name, name, "");
3424           break;
3425
3426         case 'b':               /* $vb -- a virtual bsomethingorother */
3427           name = type_name_no_tag (context);
3428           if (name == NULL)
3429             {
3430               complain (&invalid_cpp_type_complaint, symnum);
3431               name = "FOO";
3432             }
3433           fip->list->field.name =
3434             obconcat (&objfile->type_obstack, vb_name, name, "");
3435           break;
3436
3437         default:
3438           complain (&invalid_cpp_abbrev_complaint, *pp);
3439           fip->list->field.name =
3440             obconcat (&objfile->type_obstack,
3441                       "INVALID_CPLUSPLUS_ABBREV", "", "");
3442           break;
3443         }
3444
3445       /* At this point, *pp points to the ':'.  Skip it and read the
3446          field type. */
3447
3448       p = ++(*pp);
3449       if (p[-1] != ':')
3450         {
3451           complain (&invalid_cpp_abbrev_complaint, *pp);
3452           return 0;
3453         }
3454       fip->list->field.type = read_type (pp, objfile);
3455       if (**pp == ',')
3456         (*pp)++;                /* Skip the comma.  */
3457       else
3458         return 0;
3459
3460       {
3461         int nbits;
3462         FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3463         if (nbits != 0)
3464           return 0;
3465       }
3466       /* This field is unpacked.  */
3467       FIELD_BITSIZE (fip->list->field) = 0;
3468       fip->list->visibility = VISIBILITY_PRIVATE;
3469     }
3470   else
3471     {
3472       complain (&invalid_cpp_abbrev_complaint, *pp);
3473       /* We have no idea what syntax an unrecognized abbrev would have, so
3474          better return 0.  If we returned 1, we would need to at least advance
3475          *pp to avoid an infinite loop.  */
3476       return 0;
3477     }
3478   return 1;
3479 }
3480
3481 static void
3482 read_one_struct_field (struct field_info *fip, char **pp, char *p,
3483                        struct type *type, struct objfile *objfile)
3484 {
3485   /* The following is code to work around cfront generated stabs.
3486      The stabs contains full mangled name for each field.
3487      We try to demangle the name and extract the field name out of it.
3488    */
3489   if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3490     {
3491       char save_p;
3492       char *dem, *dem_p;
3493       save_p = *p;
3494       *p = '\0';
3495       dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3496       if (dem != NULL)
3497         {
3498           dem_p = strrchr (dem, ':');
3499           if (dem_p != 0 && *(dem_p - 1) == ':')
3500             dem_p++;
3501           FIELD_NAME (fip->list->field) =
3502             obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3503         }
3504       else
3505         {
3506           FIELD_NAME (fip->list->field) =
3507             obsavestring (*pp, p - *pp, &objfile->type_obstack);
3508         }
3509       *p = save_p;
3510     }
3511   /* end of code for cfront work around */
3512
3513   else
3514     fip->list->field.name =
3515       obsavestring (*pp, p - *pp, &objfile->type_obstack);
3516   *pp = p + 1;
3517
3518   /* This means we have a visibility for a field coming. */
3519   if (**pp == '/')
3520     {
3521       (*pp)++;
3522       fip->list->visibility = *(*pp)++;
3523     }
3524   else
3525     {
3526       /* normal dbx-style format, no explicit visibility */
3527       fip->list->visibility = VISIBILITY_PUBLIC;
3528     }
3529
3530   fip->list->field.type = read_type (pp, objfile);
3531   if (**pp == ':')
3532     {
3533       p = ++(*pp);
3534 #if 0
3535       /* Possible future hook for nested types. */
3536       if (**pp == '!')
3537         {
3538           fip->list->field.bitpos = (long) -2;  /* nested type */
3539           p = ++(*pp);
3540         }
3541       else
3542         ...;
3543 #endif
3544       while (*p != ';')
3545         {
3546           p++;
3547         }
3548       /* Static class member.  */
3549       SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3550       *pp = p + 1;
3551       return;
3552     }
3553   else if (**pp != ',')
3554     {
3555       /* Bad structure-type format.  */
3556       complain (&stabs_general_complaint, "bad structure-type format");
3557       return;
3558     }
3559
3560   (*pp)++;                      /* Skip the comma.  */
3561
3562   {
3563     int nbits;
3564     FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3565     if (nbits != 0)
3566       {
3567         complain (&stabs_general_complaint, "bad structure-type format");
3568         return;
3569       }
3570     FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3571     if (nbits != 0)
3572       {
3573         complain (&stabs_general_complaint, "bad structure-type format");
3574         return;
3575       }
3576   }
3577
3578   if (FIELD_BITPOS (fip->list->field) == 0
3579       && FIELD_BITSIZE (fip->list->field) == 0)
3580     {
3581       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3582          it is a field which has been optimized out.  The correct stab for
3583          this case is to use VISIBILITY_IGNORE, but that is a recent
3584          invention.  (2) It is a 0-size array.  For example
3585          union { int num; char str[0]; } foo.  Printing "<no value>" for
3586          str in "p foo" is OK, since foo.str (and thus foo.str[3])
3587          will continue to work, and a 0-size array as a whole doesn't
3588          have any contents to print.
3589
3590          I suspect this probably could also happen with gcc -gstabs (not
3591          -gstabs+) for static fields, and perhaps other C++ extensions.
3592          Hopefully few people use -gstabs with gdb, since it is intended
3593          for dbx compatibility.  */
3594
3595       /* Ignore this field.  */
3596       fip->list->visibility = VISIBILITY_IGNORE;
3597     }
3598   else
3599     {
3600       /* Detect an unpacked field and mark it as such.
3601          dbx gives a bit size for all fields.
3602          Note that forward refs cannot be packed,
3603          and treat enums as if they had the width of ints.  */
3604
3605       struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3606
3607       if (TYPE_CODE (field_type) != TYPE_CODE_INT
3608           && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3609           && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3610           && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3611         {
3612           FIELD_BITSIZE (fip->list->field) = 0;
3613         }
3614       if ((FIELD_BITSIZE (fip->list->field)
3615            == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3616            || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
3617                && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3618           )
3619           &&
3620           FIELD_BITPOS (fip->list->field) % 8 == 0)
3621         {
3622           FIELD_BITSIZE (fip->list->field) = 0;
3623         }
3624     }
3625 }
3626
3627
3628 /* Read struct or class data fields.  They have the form:
3629
3630    NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3631
3632    At the end, we see a semicolon instead of a field.
3633
3634    In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3635    a static field.
3636
3637    The optional VISIBILITY is one of:
3638
3639    '/0' (VISIBILITY_PRIVATE)
3640    '/1' (VISIBILITY_PROTECTED)
3641    '/2' (VISIBILITY_PUBLIC)
3642    '/9' (VISIBILITY_IGNORE)
3643
3644    or nothing, for C style fields with public visibility.
3645
3646    Returns 1 for success, 0 for failure.  */
3647
3648 static int
3649 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3650                     struct objfile *objfile)
3651 {
3652   register char *p;
3653   struct nextfield *new;
3654
3655   /* We better set p right now, in case there are no fields at all...    */
3656
3657   p = *pp;
3658
3659   /* Read each data member type until we find the terminating ';' at the end of
3660      the data member list, or break for some other reason such as finding the
3661      start of the member function list. */
3662   /* Stab string for structure/union does not end with two ';' in
3663      SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3664
3665   while (**pp != ';' && **pp != '\0')
3666     {
3667       if (os9k_stabs && **pp == ',')
3668         break;
3669       STABS_CONTINUE (pp, objfile);
3670       /* Get space to record the next field's data.  */
3671       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3672       make_cleanup (xfree, new);
3673       memset (new, 0, sizeof (struct nextfield));
3674       new->next = fip->list;
3675       fip->list = new;
3676
3677       /* Get the field name.  */
3678       p = *pp;
3679
3680       /* If is starts with CPLUS_MARKER it is a special abbreviation,
3681          unless the CPLUS_MARKER is followed by an underscore, in
3682          which case it is just the name of an anonymous type, which we
3683          should handle like any other type name.  */
3684
3685       if (is_cplus_marker (p[0]) && p[1] != '_')
3686         {
3687           if (!read_cpp_abbrev (fip, pp, type, objfile))
3688             return 0;
3689           continue;
3690         }
3691
3692       /* Look for the ':' that separates the field name from the field
3693          values.  Data members are delimited by a single ':', while member
3694          functions are delimited by a pair of ':'s.  When we hit the member
3695          functions (if any), terminate scan loop and return. */
3696
3697       while (*p != ':' && *p != '\0')
3698         {
3699           p++;
3700         }
3701       if (*p == '\0')
3702         return 0;
3703
3704       /* Check to see if we have hit the member functions yet.  */
3705       if (p[1] == ':')
3706         {
3707           break;
3708         }
3709       read_one_struct_field (fip, pp, p, type, objfile);
3710     }
3711   if (p[0] == ':' && p[1] == ':')
3712     {
3713       /* chill the list of fields: the last entry (at the head) is a
3714          partially constructed entry which we now scrub. */
3715       fip->list = fip->list->next;
3716     }
3717   return 1;
3718 }
3719 /* *INDENT-OFF* */
3720 /* The stabs for C++ derived classes contain baseclass information which
3721    is marked by a '!' character after the total size.  This function is
3722    called when we encounter the baseclass marker, and slurps up all the
3723    baseclass information.
3724
3725    Immediately following the '!' marker is the number of base classes that
3726    the class is derived from, followed by information for each base class.
3727    For each base class, there are two visibility specifiers, a bit offset
3728    to the base class information within the derived class, a reference to
3729    the type for the base class, and a terminating semicolon.
3730
3731    A typical example, with two base classes, would be "!2,020,19;0264,21;".
3732                                                        ^^ ^ ^ ^  ^ ^  ^
3733         Baseclass information marker __________________|| | | |  | |  |
3734         Number of baseclasses __________________________| | | |  | |  |
3735         Visibility specifiers (2) ________________________| | |  | |  |
3736         Offset in bits from start of class _________________| |  | |  |
3737         Type number for base class ___________________________|  | |  |
3738         Visibility specifiers (2) _______________________________| |  |
3739         Offset in bits from start of class ________________________|  |
3740         Type number of base class ____________________________________|
3741
3742   Return 1 for success, 0 for (error-type-inducing) failure.  */
3743 /* *INDENT-ON* */
3744
3745
3746
3747 static int
3748 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3749                   struct objfile *objfile)
3750 {
3751   int i;
3752   struct nextfield *new;
3753
3754   if (**pp != '!')
3755     {
3756       return 1;
3757     }
3758   else
3759     {
3760       /* Skip the '!' baseclass information marker. */
3761       (*pp)++;
3762     }
3763
3764   ALLOCATE_CPLUS_STRUCT_TYPE (type);
3765   {
3766     int nbits;
3767     TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3768     if (nbits != 0)
3769       return 0;
3770   }
3771
3772 #if 0
3773   /* Some stupid compilers have trouble with the following, so break
3774      it up into simpler expressions.  */
3775   TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3776     TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3777 #else
3778   {
3779     int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3780     char *pointer;
3781
3782     pointer = (char *) TYPE_ALLOC (type, num_bytes);
3783     TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3784   }
3785 #endif /* 0 */
3786
3787   B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3788
3789   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3790     {
3791       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3792       make_cleanup (xfree, new);
3793       memset (new, 0, sizeof (struct nextfield));
3794       new->next = fip->list;
3795       fip->list = new;
3796       FIELD_BITSIZE (new->field) = 0;   /* this should be an unpacked field! */
3797
3798       STABS_CONTINUE (pp, objfile);
3799       switch (**pp)
3800         {
3801         case '0':
3802           /* Nothing to do. */
3803           break;
3804         case '1':
3805           SET_TYPE_FIELD_VIRTUAL (type, i);
3806           break;
3807         default:
3808           /* Unknown character.  Complain and treat it as non-virtual.  */
3809           {
3810             static struct complaint msg =
3811             {
3812               "Unknown virtual character `%c' for baseclass", 0, 0};
3813             complain (&msg, **pp);
3814           }
3815         }
3816       ++(*pp);
3817
3818       new->visibility = *(*pp)++;
3819       switch (new->visibility)
3820         {
3821         case VISIBILITY_PRIVATE:
3822         case VISIBILITY_PROTECTED:
3823         case VISIBILITY_PUBLIC:
3824           break;
3825         default:
3826           /* Bad visibility format.  Complain and treat it as
3827              public.  */
3828           {
3829             static struct complaint msg =
3830             {
3831               "Unknown visibility `%c' for baseclass", 0, 0
3832             };
3833             complain (&msg, new->visibility);
3834             new->visibility = VISIBILITY_PUBLIC;
3835           }
3836         }
3837
3838       {
3839         int nbits;
3840
3841         /* The remaining value is the bit offset of the portion of the object
3842            corresponding to this baseclass.  Always zero in the absence of
3843            multiple inheritance.  */
3844
3845         FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3846         if (nbits != 0)
3847           return 0;
3848       }
3849
3850       /* The last piece of baseclass information is the type of the
3851          base class.  Read it, and remember it's type name as this
3852          field's name. */
3853
3854       new->field.type = read_type (pp, objfile);
3855       new->field.name = type_name_no_tag (new->field.type);
3856
3857       /* skip trailing ';' and bump count of number of fields seen */
3858       if (**pp == ';')
3859         (*pp)++;
3860       else
3861         return 0;
3862     }
3863   return 1;
3864 }
3865
3866 /* The tail end of stabs for C++ classes that contain a virtual function
3867    pointer contains a tilde, a %, and a type number.
3868    The type number refers to the base class (possibly this class itself) which
3869    contains the vtable pointer for the current class.
3870
3871    This function is called when we have parsed all the method declarations,
3872    so we can look for the vptr base class info.  */
3873
3874 static int
3875 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
3876                    struct objfile *objfile)
3877 {
3878   register char *p;
3879
3880   STABS_CONTINUE (pp, objfile);
3881
3882   /* If we are positioned at a ';', then skip it. */
3883   if (**pp == ';')
3884     {
3885       (*pp)++;
3886     }
3887
3888   if (**pp == '~')
3889     {
3890       (*pp)++;
3891
3892       if (**pp == '=' || **pp == '+' || **pp == '-')
3893         {
3894           /* Obsolete flags that used to indicate the presence
3895              of constructors and/or destructors. */
3896           (*pp)++;
3897         }
3898
3899       /* Read either a '%' or the final ';'.  */
3900       if (*(*pp)++ == '%')
3901         {
3902           /* The next number is the type number of the base class
3903              (possibly our own class) which supplies the vtable for
3904              this class.  Parse it out, and search that class to find
3905              its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3906              and TYPE_VPTR_FIELDNO.  */
3907
3908           struct type *t;
3909           int i;
3910
3911           t = read_type (pp, objfile);
3912           p = (*pp)++;
3913           while (*p != '\0' && *p != ';')
3914             {
3915               p++;
3916             }
3917           if (*p == '\0')
3918             {
3919               /* Premature end of symbol.  */
3920               return 0;
3921             }
3922
3923           TYPE_VPTR_BASETYPE (type) = t;
3924           if (type == t)        /* Our own class provides vtbl ptr */
3925             {
3926               for (i = TYPE_NFIELDS (t) - 1;
3927                    i >= TYPE_N_BASECLASSES (t);
3928                    --i)
3929                 {
3930                   if (!strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
3931                                 sizeof (vptr_name) - 1))
3932                     {
3933                       TYPE_VPTR_FIELDNO (type) = i;
3934                       goto gotit;
3935                     }
3936                 }
3937               /* Virtual function table field not found.  */
3938               complain (&vtbl_notfound_complaint, TYPE_NAME (type));
3939               return 0;
3940             }
3941           else
3942             {
3943               TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3944             }
3945
3946         gotit:
3947           *pp = p + 1;
3948         }
3949     }
3950   return 1;
3951 }
3952
3953 static int
3954 attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
3955 {
3956   register int n;
3957
3958   for (n = TYPE_NFN_FIELDS (type);
3959        fip->fnlist != NULL;
3960        fip->fnlist = fip->fnlist->next)
3961     {
3962       --n;                      /* Circumvent Sun3 compiler bug */
3963       TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
3964     }
3965   return 1;
3966 }
3967
3968 /* read cfront class static data.
3969    pp points to string starting with the list of static data
3970    eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3971    ^^^^^^^^
3972
3973    A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3974    ^
3975  */
3976
3977 static int
3978 read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
3979                            struct objfile *objfile)
3980 {
3981   struct nextfield *new;
3982   struct type *stype;
3983   char *sname;
3984   struct symbol *ref_static = 0;
3985
3986   if (**pp == ';')              /* no static data; return */
3987     {
3988       ++(*pp);
3989       return 1;
3990     }
3991
3992   /* Process each field in the list until we find the terminating ";" */
3993
3994   /* eg: p = "as__1A ;;;" */
3995   STABS_CONTINUE (pp, objfile); /* handle \\ */
3996   while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
3997     {
3998       ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0);       /*demangled_name */
3999       if (!ref_static)
4000         {
4001           static struct complaint msg =
4002           {"\
4003                 Unable to find symbol for static data field %s\n",
4004            0, 0};
4005           complain (&msg, sname);
4006           continue;
4007         }
4008       stype = SYMBOL_TYPE (ref_static);
4009
4010       /* allocate a new fip */
4011       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4012       make_cleanup (xfree, new);
4013       memset (new, 0, sizeof (struct nextfield));
4014       new->next = fip->list;
4015       fip->list = new;
4016
4017       /* set visibility */
4018       /* FIXME! no way to tell visibility from stabs??? */
4019       new->visibility = VISIBILITY_PUBLIC;
4020
4021       /* set field info into fip */
4022       fip->list->field.type = stype;
4023
4024       /* set bitpos & bitsize */
4025       SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
4026
4027       /* set name field */
4028       /* The following is code to work around cfront generated stabs.
4029          The stabs contains full mangled name for each field.
4030          We try to demangle the name and extract the field name out of it.
4031        */
4032       if (ARM_DEMANGLING)
4033         {
4034           char *dem, *dem_p;
4035           dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
4036           if (dem != NULL)
4037             {
4038               dem_p = strrchr (dem, ':');
4039               if (dem_p != 0 && *(dem_p - 1) == ':')
4040                 dem_p++;
4041               fip->list->field.name =
4042                 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
4043             }
4044           else
4045             {
4046               fip->list->field.name =
4047                 obsavestring (sname, strlen (sname), &objfile->type_obstack);
4048             }
4049         }                       /* end of code for cfront work around */
4050     }                           /* loop again for next static field */
4051   return 1;
4052 }
4053
4054 /* Copy structure fields to fip so attach_fields_to_type will work.
4055    type has already been created with the initial instance data fields.
4056    Now we want to be able to add the other members to the class,
4057    so we want to add them back to the fip and reattach them again
4058    once we have collected all the class members. */
4059
4060 static int
4061 copy_cfront_struct_fields (struct field_info *fip, struct type *type,
4062                            struct objfile *objfile)
4063 {
4064   int nfields = TYPE_NFIELDS (type);
4065   int i;
4066   struct nextfield *new;
4067
4068   /* Copy the fields into the list of fips and reset the types 
4069      to remove the old fields */
4070
4071   for (i = 0; i < nfields; i++)
4072     {
4073       /* allocate a new fip */
4074       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4075       make_cleanup (xfree, new);
4076       memset (new, 0, sizeof (struct nextfield));
4077       new->next = fip->list;
4078       fip->list = new;
4079
4080       /* copy field info into fip */
4081       new->field = TYPE_FIELD (type, i);
4082       /* set visibility */
4083       if (TYPE_FIELD_PROTECTED (type, i))
4084         new->visibility = VISIBILITY_PROTECTED;
4085       else if (TYPE_FIELD_PRIVATE (type, i))
4086         new->visibility = VISIBILITY_PRIVATE;
4087       else
4088         new->visibility = VISIBILITY_PUBLIC;
4089     }
4090   /* Now delete the fields from the type since we will be 
4091      allocing new space once we get the rest of the fields 
4092      in attach_fields_to_type.
4093      The pointer TYPE_FIELDS(type) is left dangling but should 
4094      be freed later by objstack_free */
4095   TYPE_FIELDS (type) = 0;
4096   TYPE_NFIELDS (type) = 0;
4097
4098   return 1;
4099 }
4100
4101 /* Create the vector of fields, and record how big it is.
4102    We need this info to record proper virtual function table information
4103    for this class's virtual functions.  */
4104
4105 static int
4106 attach_fields_to_type (struct field_info *fip, register struct type *type,
4107                        struct objfile *objfile)
4108 {
4109   register int nfields = 0;
4110   register int non_public_fields = 0;
4111   register struct nextfield *scan;
4112
4113   /* Count up the number of fields that we have, as well as taking note of
4114      whether or not there are any non-public fields, which requires us to
4115      allocate and build the private_field_bits and protected_field_bits
4116      bitfields. */
4117
4118   for (scan = fip->list; scan != NULL; scan = scan->next)
4119     {
4120       nfields++;
4121       if (scan->visibility != VISIBILITY_PUBLIC)
4122         {
4123           non_public_fields++;
4124         }
4125     }
4126
4127   /* Now we know how many fields there are, and whether or not there are any
4128      non-public fields.  Record the field count, allocate space for the
4129      array of fields, and create blank visibility bitfields if necessary. */
4130
4131   TYPE_NFIELDS (type) = nfields;
4132   TYPE_FIELDS (type) = (struct field *)
4133     TYPE_ALLOC (type, sizeof (struct field) * nfields);
4134   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4135
4136   if (non_public_fields)
4137     {
4138       ALLOCATE_CPLUS_STRUCT_TYPE (type);
4139
4140       TYPE_FIELD_PRIVATE_BITS (type) =
4141         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4142       B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4143
4144       TYPE_FIELD_PROTECTED_BITS (type) =
4145         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4146       B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4147
4148       TYPE_FIELD_IGNORE_BITS (type) =
4149         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4150       B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4151     }
4152
4153   /* Copy the saved-up fields into the field vector.  Start from the head
4154      of the list, adding to the tail of the field array, so that they end
4155      up in the same order in the array in which they were added to the list. */
4156
4157   while (nfields-- > 0)
4158     {
4159       TYPE_FIELD (type, nfields) = fip->list->field;
4160       switch (fip->list->visibility)
4161         {
4162         case VISIBILITY_PRIVATE:
4163           SET_TYPE_FIELD_PRIVATE (type, nfields);
4164           break;
4165
4166         case VISIBILITY_PROTECTED:
4167           SET_TYPE_FIELD_PROTECTED (type, nfields);
4168           break;
4169
4170         case VISIBILITY_IGNORE:
4171           SET_TYPE_FIELD_IGNORE (type, nfields);
4172           break;
4173
4174         case VISIBILITY_PUBLIC:
4175           break;
4176
4177         default:
4178           /* Unknown visibility.  Complain and treat it as public.  */
4179           {
4180             static struct complaint msg =
4181             {
4182               "Unknown visibility `%c' for field", 0, 0};
4183             complain (&msg, fip->list->visibility);
4184           }
4185           break;
4186         }
4187       fip->list = fip->list->next;
4188     }
4189   return 1;
4190 }
4191
4192
4193 static struct complaint multiply_defined_struct =
4194 {"struct/union type gets multiply defined: %s%s", 0, 0};
4195
4196
4197 /* Complain that the compiler has emitted more than one definition for the
4198    structure type TYPE.  */
4199 static void 
4200 complain_about_struct_wipeout (struct type *type)
4201 {
4202   char *name = "";
4203   char *kind = "";
4204
4205   if (TYPE_TAG_NAME (type))
4206     {
4207       name = TYPE_TAG_NAME (type);
4208       switch (TYPE_CODE (type))
4209         {
4210         case TYPE_CODE_STRUCT: kind = "struct "; break;
4211         case TYPE_CODE_UNION:  kind = "union ";  break;
4212         case TYPE_CODE_ENUM:   kind = "enum ";   break;
4213         default: kind = "";
4214         }
4215     }
4216   else if (TYPE_NAME (type))
4217     {
4218       name = TYPE_NAME (type);
4219       kind = "";
4220     }
4221   else
4222     {
4223       name = "<unknown>";
4224       kind = "";
4225     }
4226
4227   complain (&multiply_defined_struct, kind, name);
4228 }
4229
4230
4231 /* Read the description of a structure (or union type) and return an object
4232    describing the type.
4233
4234    PP points to a character pointer that points to the next unconsumed token
4235    in the the stabs string.  For example, given stabs "A:T4=s4a:1,0,32;;",
4236    *PP will point to "4a:1,0,32;;".
4237
4238    TYPE points to an incomplete type that needs to be filled in.
4239
4240    OBJFILE points to the current objfile from which the stabs information is
4241    being read.  (Note that it is redundant in that TYPE also contains a pointer
4242    to this same objfile, so it might be a good idea to eliminate it.  FIXME). 
4243  */
4244
4245 static struct type *
4246 read_struct_type (char **pp, struct type *type, enum type_code type_code,
4247                   struct objfile *objfile)
4248 {
4249   struct cleanup *back_to;
4250   struct field_info fi;
4251
4252   fi.list = NULL;
4253   fi.fnlist = NULL;
4254
4255   /* When describing struct/union/class types in stabs, G++ always drops
4256      all qualifications from the name.  So if you've got:
4257        struct A { ... struct B { ... }; ... };
4258      then G++ will emit stabs for `struct A::B' that call it simply
4259      `struct B'.  Obviously, if you've got a real top-level definition for
4260      `struct B', or other nested definitions, this is going to cause
4261      problems.
4262
4263      Obviously, GDB can't fix this by itself, but it can at least avoid
4264      scribbling on existing structure type objects when new definitions
4265      appear.  */
4266   if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
4267          || TYPE_STUB (type)))
4268     {
4269       complain_about_struct_wipeout (type);
4270
4271       /* It's probably best to return the type unchanged.  */
4272       return type;
4273     }
4274
4275   back_to = make_cleanup (null_cleanup, 0);
4276
4277   INIT_CPLUS_SPECIFIC (type);
4278   TYPE_CODE (type) = type_code;
4279   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4280
4281   /* First comes the total size in bytes.  */
4282
4283   {
4284     int nbits;
4285     TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4286     if (nbits != 0)
4287       return error_type (pp, objfile);
4288   }
4289
4290   /* Now read the baseclasses, if any, read the regular C struct or C++
4291      class member fields, attach the fields to the type, read the C++
4292      member functions, attach them to the type, and then read any tilde
4293      field (baseclass specifier for the class holding the main vtable). */
4294
4295   if (!read_baseclasses (&fi, pp, type, objfile)
4296       || !read_struct_fields (&fi, pp, type, objfile)
4297       || !attach_fields_to_type (&fi, type, objfile)
4298       || !read_member_functions (&fi, pp, type, objfile)
4299       || !attach_fn_fields_to_type (&fi, type)
4300       || !read_tilde_fields (&fi, pp, type, objfile))
4301     {
4302       type = error_type (pp, objfile);
4303     }
4304
4305   do_cleanups (back_to);
4306   return (type);
4307 }
4308
4309 /* Read a definition of an array type,
4310    and create and return a suitable type object.
4311    Also creates a range type which represents the bounds of that
4312    array.  */
4313
4314 static struct type *
4315 read_array_type (register char **pp, register struct type *type,
4316                  struct objfile *objfile)
4317 {
4318   struct type *index_type, *element_type, *range_type;
4319   int lower, upper;
4320   int adjustable = 0;
4321   int nbits;
4322
4323   /* Format of an array type:
4324      "ar<index type>;lower;upper;<array_contents_type>".
4325      OS9000: "arlower,upper;<array_contents_type>".
4326
4327      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4328      for these, produce a type like float[][].  */
4329
4330   if (os9k_stabs)
4331     index_type = builtin_type_int;
4332   else
4333     {
4334       index_type = read_type (pp, objfile);
4335       if (**pp != ';')
4336         /* Improper format of array type decl.  */
4337         return error_type (pp, objfile);
4338       ++*pp;
4339     }
4340
4341   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4342     {
4343       (*pp)++;
4344       adjustable = 1;
4345     }
4346   lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
4347   if (nbits != 0)
4348     return error_type (pp, objfile);
4349
4350   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4351     {
4352       (*pp)++;
4353       adjustable = 1;
4354     }
4355   upper = read_huge_number (pp, ';', &nbits);
4356   if (nbits != 0)
4357     return error_type (pp, objfile);
4358
4359   element_type = read_type (pp, objfile);
4360
4361   if (adjustable)
4362     {
4363       lower = 0;
4364       upper = -1;
4365     }
4366
4367   range_type =
4368     create_range_type ((struct type *) NULL, index_type, lower, upper);
4369   type = create_array_type (type, element_type, range_type);
4370
4371   return type;
4372 }
4373
4374
4375 /* Read a definition of an enumeration type,
4376    and create and return a suitable type object.
4377    Also defines the symbols that represent the values of the type.  */
4378
4379 static struct type *
4380 read_enum_type (register char **pp, register struct type *type,
4381                 struct objfile *objfile)
4382 {
4383   register char *p;
4384   char *name;
4385   register long n;
4386   register struct symbol *sym;
4387   int nsyms = 0;
4388   struct pending **symlist;
4389   struct pending *osyms, *syms;
4390   int o_nsyms;
4391   int nbits;
4392   int unsigned_enum = 1;
4393
4394 #if 0
4395   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
4396      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
4397      to do?  For now, force all enum values to file scope.  */
4398   if (within_function)
4399     symlist = &local_symbols;
4400   else
4401 #endif
4402     symlist = &file_symbols;
4403   osyms = *symlist;
4404   o_nsyms = osyms ? osyms->nsyms : 0;
4405
4406   if (os9k_stabs)
4407     {
4408       /* Size.  Perhaps this does not have to be conditionalized on
4409          os9k_stabs (assuming the name of an enum constant can't start
4410          with a digit).  */
4411       read_huge_number (pp, 0, &nbits);
4412       if (nbits != 0)
4413         return error_type (pp, objfile);
4414     }
4415
4416   /* The aix4 compiler emits an extra field before the enum members;
4417      my guess is it's a type of some sort.  Just ignore it.  */
4418   if (**pp == '-')
4419     {
4420       /* Skip over the type.  */
4421       while (**pp != ':')
4422         (*pp)++;
4423
4424       /* Skip over the colon.  */
4425       (*pp)++;
4426     }
4427
4428   /* Read the value-names and their values.
4429      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4430      A semicolon or comma instead of a NAME means the end.  */
4431   while (**pp && **pp != ';' && **pp != ',')
4432     {
4433       STABS_CONTINUE (pp, objfile);
4434       p = *pp;
4435       while (*p != ':')
4436         p++;
4437       name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
4438       *pp = p + 1;
4439       n = read_huge_number (pp, ',', &nbits);
4440       if (nbits != 0)
4441         return error_type (pp, objfile);
4442
4443       sym = (struct symbol *)
4444         obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4445       memset (sym, 0, sizeof (struct symbol));
4446       SYMBOL_NAME (sym) = name;
4447       SYMBOL_LANGUAGE (sym) = current_subfile->language;
4448       SYMBOL_CLASS (sym) = LOC_CONST;
4449       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4450       SYMBOL_VALUE (sym) = n;
4451       if (n < 0)
4452         unsigned_enum = 0;
4453       add_symbol_to_list (sym, symlist);
4454       nsyms++;
4455     }
4456
4457   if (**pp == ';')
4458     (*pp)++;                    /* Skip the semicolon.  */
4459
4460   /* Now fill in the fields of the type-structure.  */
4461
4462   TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4463   TYPE_CODE (type) = TYPE_CODE_ENUM;
4464   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4465   if (unsigned_enum)
4466     TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4467   TYPE_NFIELDS (type) = nsyms;
4468   TYPE_FIELDS (type) = (struct field *)
4469     TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4470   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4471
4472   /* Find the symbols for the values and put them into the type.
4473      The symbols can be found in the symlist that we put them on
4474      to cause them to be defined.  osyms contains the old value
4475      of that symlist; everything up to there was defined by us.  */
4476   /* Note that we preserve the order of the enum constants, so
4477      that in something like "enum {FOO, LAST_THING=FOO}" we print
4478      FOO, not LAST_THING.  */
4479
4480   for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4481     {
4482       int last = syms == osyms ? o_nsyms : 0;
4483       int j = syms->nsyms;
4484       for (; --j >= last; --n)
4485         {
4486           struct symbol *xsym = syms->symbol[j];
4487           SYMBOL_TYPE (xsym) = type;
4488           TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4489           TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4490           TYPE_FIELD_BITSIZE (type, n) = 0;
4491         }
4492       if (syms == osyms)
4493         break;
4494     }
4495
4496   return type;
4497 }
4498
4499 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4500    typedefs in every file (for int, long, etc):
4501
4502    type = b <signed> <width> <format type>; <offset>; <nbits>
4503    signed = u or s.
4504    optional format type = c or b for char or boolean.
4505    offset = offset from high order bit to start bit of type.
4506    width is # bytes in object of this type, nbits is # bits in type.
4507
4508    The width/offset stuff appears to be for small objects stored in
4509    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
4510    FIXME.  */
4511
4512 static struct type *
4513 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
4514 {
4515   int type_bits;
4516   int nbits;
4517   int signed_type;
4518   enum type_code code = TYPE_CODE_INT;
4519
4520   switch (**pp)
4521     {
4522     case 's':
4523       signed_type = 1;
4524       break;
4525     case 'u':
4526       signed_type = 0;
4527       break;
4528     default:
4529       return error_type (pp, objfile);
4530     }
4531   (*pp)++;
4532
4533   /* For some odd reason, all forms of char put a c here.  This is strange
4534      because no other type has this honor.  We can safely ignore this because
4535      we actually determine 'char'acterness by the number of bits specified in
4536      the descriptor.
4537      Boolean forms, e.g Fortran logical*X, put a b here.  */
4538
4539   if (**pp == 'c')
4540     (*pp)++;
4541   else if (**pp == 'b')
4542     {
4543       code = TYPE_CODE_BOOL;
4544       (*pp)++;
4545     }
4546
4547   /* The first number appears to be the number of bytes occupied
4548      by this type, except that unsigned short is 4 instead of 2.
4549      Since this information is redundant with the third number,
4550      we will ignore it.  */
4551   read_huge_number (pp, ';', &nbits);
4552   if (nbits != 0)
4553     return error_type (pp, objfile);
4554
4555   /* The second number is always 0, so ignore it too. */
4556   read_huge_number (pp, ';', &nbits);
4557   if (nbits != 0)
4558     return error_type (pp, objfile);
4559
4560   /* The third number is the number of bits for this type. */
4561   type_bits = read_huge_number (pp, 0, &nbits);
4562   if (nbits != 0)
4563     return error_type (pp, objfile);
4564   /* The type *should* end with a semicolon.  If it are embedded
4565      in a larger type the semicolon may be the only way to know where
4566      the type ends.  If this type is at the end of the stabstring we
4567      can deal with the omitted semicolon (but we don't have to like
4568      it).  Don't bother to complain(), Sun's compiler omits the semicolon
4569      for "void".  */
4570   if (**pp == ';')
4571     ++(*pp);
4572
4573   if (type_bits == 0)
4574     return init_type (TYPE_CODE_VOID, 1,
4575                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4576                       objfile);
4577   else
4578     return init_type (code,
4579                       type_bits / TARGET_CHAR_BIT,
4580                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4581                       objfile);
4582 }
4583
4584 static struct type *
4585 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
4586 {
4587   int nbits;
4588   int details;
4589   int nbytes;
4590   struct type *rettype;
4591
4592   /* The first number has more details about the type, for example
4593      FN_COMPLEX.  */
4594   details = read_huge_number (pp, ';', &nbits);
4595   if (nbits != 0)
4596     return error_type (pp, objfile);
4597
4598   /* The second number is the number of bytes occupied by this type */
4599   nbytes = read_huge_number (pp, ';', &nbits);
4600   if (nbits != 0)
4601     return error_type (pp, objfile);
4602
4603   if (details == NF_COMPLEX || details == NF_COMPLEX16
4604       || details == NF_COMPLEX32)
4605     {
4606       rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4607       TYPE_TARGET_TYPE (rettype)
4608         = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
4609       return rettype;
4610     }
4611
4612   return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4613 }
4614
4615 /* Read a number from the string pointed to by *PP.
4616    The value of *PP is advanced over the number.
4617    If END is nonzero, the character that ends the
4618    number must match END, or an error happens;
4619    and that character is skipped if it does match.
4620    If END is zero, *PP is left pointing to that character.
4621
4622    If the number fits in a long, set *BITS to 0 and return the value.
4623    If not, set *BITS to be the number of bits in the number and return 0.
4624
4625    If encounter garbage, set *BITS to -1 and return 0.  */
4626
4627 static long
4628 read_huge_number (char **pp, int end, int *bits)
4629 {
4630   char *p = *pp;
4631   int sign = 1;
4632   long n = 0;
4633   int radix = 10;
4634   char overflow = 0;
4635   int nbits = 0;
4636   int c;
4637   long upper_limit;
4638
4639   if (*p == '-')
4640     {
4641       sign = -1;
4642       p++;
4643     }
4644
4645   /* Leading zero means octal.  GCC uses this to output values larger
4646      than an int (because that would be hard in decimal).  */
4647   if (*p == '0')
4648     {
4649       radix = 8;
4650       p++;
4651     }
4652
4653   if (os9k_stabs)
4654     upper_limit = ULONG_MAX / radix;
4655   else
4656     upper_limit = LONG_MAX / radix;
4657
4658   while ((c = *p++) >= '0' && c < ('0' + radix))
4659     {
4660       if (n <= upper_limit)
4661         {
4662           n *= radix;
4663           n += c - '0';         /* FIXME this overflows anyway */
4664         }
4665       else
4666         overflow = 1;
4667
4668       /* This depends on large values being output in octal, which is
4669          what GCC does. */
4670       if (radix == 8)
4671         {
4672           if (nbits == 0)
4673             {
4674               if (c == '0')
4675                 /* Ignore leading zeroes.  */
4676                 ;
4677               else if (c == '1')
4678                 nbits = 1;
4679               else if (c == '2' || c == '3')
4680                 nbits = 2;
4681               else
4682                 nbits = 3;
4683             }
4684           else
4685             nbits += 3;
4686         }
4687     }
4688   if (end)
4689     {
4690       if (c && c != end)
4691         {
4692           if (bits != NULL)
4693             *bits = -1;
4694           return 0;
4695         }
4696     }
4697   else
4698     --p;
4699
4700   *pp = p;
4701   if (overflow)
4702     {
4703       if (nbits == 0)
4704         {
4705           /* Large decimal constants are an error (because it is hard to
4706              count how many bits are in them).  */
4707           if (bits != NULL)
4708             *bits = -1;
4709           return 0;
4710         }
4711
4712       /* -0x7f is the same as 0x80.  So deal with it by adding one to
4713          the number of bits.  */
4714       if (sign == -1)
4715         ++nbits;
4716       if (bits)
4717         *bits = nbits;
4718     }
4719   else
4720     {
4721       if (bits)
4722         *bits = 0;
4723       return n * sign;
4724     }
4725   /* It's *BITS which has the interesting information.  */
4726   return 0;
4727 }
4728
4729 static struct type *
4730 read_range_type (char **pp, int typenums[2], struct objfile *objfile)
4731 {
4732   char *orig_pp = *pp;
4733   int rangenums[2];
4734   long n2, n3;
4735   int n2bits, n3bits;
4736   int self_subrange;
4737   struct type *result_type;
4738   struct type *index_type = NULL;
4739
4740   /* First comes a type we are a subrange of.
4741      In C it is usually 0, 1 or the type being defined.  */
4742   if (read_type_number (pp, rangenums) != 0)
4743     return error_type (pp, objfile);
4744   self_subrange = (rangenums[0] == typenums[0] &&
4745                    rangenums[1] == typenums[1]);
4746
4747   if (**pp == '=')
4748     {
4749       *pp = orig_pp;
4750       index_type = read_type (pp, objfile);
4751     }
4752
4753   /* A semicolon should now follow; skip it.  */
4754   if (**pp == ';')
4755     (*pp)++;
4756
4757   /* The remaining two operands are usually lower and upper bounds
4758      of the range.  But in some special cases they mean something else.  */
4759   n2 = read_huge_number (pp, ';', &n2bits);
4760   n3 = read_huge_number (pp, ';', &n3bits);
4761
4762   if (n2bits == -1 || n3bits == -1)
4763     return error_type (pp, objfile);
4764
4765   if (index_type)
4766     goto handle_true_range;
4767
4768   /* If limits are huge, must be large integral type.  */
4769   if (n2bits != 0 || n3bits != 0)
4770     {
4771       char got_signed = 0;
4772       char got_unsigned = 0;
4773       /* Number of bits in the type.  */
4774       int nbits = 0;
4775
4776       /* Range from 0 to <large number> is an unsigned large integral type.  */
4777       if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4778         {
4779           got_unsigned = 1;
4780           nbits = n3bits;
4781         }
4782       /* Range from <large number> to <large number>-1 is a large signed
4783          integral type.  Take care of the case where <large number> doesn't
4784          fit in a long but <large number>-1 does.  */
4785       else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4786                || (n2bits != 0 && n3bits == 0
4787                    && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4788                    && n3 == LONG_MAX))
4789         {
4790           got_signed = 1;
4791           nbits = n2bits;
4792         }
4793
4794       if (got_signed || got_unsigned)
4795         {
4796           return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4797                             got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4798                             objfile);
4799         }
4800       else
4801         return error_type (pp, objfile);
4802     }
4803
4804   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
4805   if (self_subrange && n2 == 0 && n3 == 0)
4806     return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
4807
4808   /* If n3 is zero and n2 is positive, we want a floating type, and n2
4809      is the width in bytes.
4810
4811      Fortran programs appear to use this for complex types also.  To
4812      distinguish between floats and complex, g77 (and others?)  seem
4813      to use self-subranges for the complexes, and subranges of int for
4814      the floats.
4815
4816      Also note that for complexes, g77 sets n2 to the size of one of
4817      the member floats, not the whole complex beast.  My guess is that
4818      this was to work well with pre-COMPLEX versions of gdb. */
4819
4820   if (n3 == 0 && n2 > 0)
4821     {
4822       struct type *float_type
4823         = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
4824
4825       if (self_subrange)
4826         {
4827           struct type *complex_type = 
4828             init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
4829           TYPE_TARGET_TYPE (complex_type) = float_type;
4830           return complex_type;
4831         }
4832       else
4833         return float_type;
4834     }
4835
4836   /* If the upper bound is -1, it must really be an unsigned int.  */
4837
4838   else if (n2 == 0 && n3 == -1)
4839     {
4840       /* It is unsigned int or unsigned long.  */
4841       /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4842          compatibility hack.  */
4843       return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4844                         TYPE_FLAG_UNSIGNED, NULL, objfile);
4845     }
4846
4847   /* Special case: char is defined (Who knows why) as a subrange of
4848      itself with range 0-127.  */
4849   else if (self_subrange && n2 == 0 && n3 == 127)
4850     return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4851
4852   else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill
4853            && !self_subrange)
4854     goto handle_true_range;
4855
4856   /* We used to do this only for subrange of self or subrange of int.  */
4857   else if (n2 == 0)
4858     {
4859       /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4860          "unsigned long", and we already checked for that,
4861          so don't need to test for it here.  */
4862
4863       if (n3 < 0)
4864         /* n3 actually gives the size.  */
4865         return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
4866                           NULL, objfile);
4867
4868       /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
4869          unsigned n-byte integer.  But do require n to be a power of
4870          two; we don't want 3- and 5-byte integers flying around.  */
4871       {
4872         int bytes;
4873         unsigned long bits;
4874
4875         bits = n3;
4876         for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
4877           bits >>= 8;
4878         if (bits == 0
4879             && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
4880           return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
4881                             objfile);
4882       }
4883     }
4884   /* I think this is for Convex "long long".  Since I don't know whether
4885      Convex sets self_subrange, I also accept that particular size regardless
4886      of self_subrange.  */
4887   else if (n3 == 0 && n2 < 0
4888            && (self_subrange
4889                || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4890     return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
4891   else if (n2 == -n3 - 1)
4892     {
4893       if (n3 == 0x7f)
4894         return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4895       if (n3 == 0x7fff)
4896         return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4897       if (n3 == 0x7fffffff)
4898         return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
4899     }
4900
4901   /* We have a real range type on our hands.  Allocate space and
4902      return a real pointer.  */
4903 handle_true_range:
4904
4905   if (self_subrange)
4906     index_type = builtin_type_int;
4907   else
4908     index_type = *dbx_lookup_type (rangenums);
4909   if (index_type == NULL)
4910     {
4911       /* Does this actually ever happen?  Is that why we are worrying
4912          about dealing with it rather than just calling error_type?  */
4913
4914       static struct type *range_type_index;
4915
4916       complain (&range_type_base_complaint, rangenums[1]);
4917       if (range_type_index == NULL)
4918         range_type_index =
4919           init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4920                      0, "range type index type", NULL);
4921       index_type = range_type_index;
4922     }
4923
4924   result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
4925   return (result_type);
4926 }
4927
4928 /* Read in an argument list.  This is a list of types, separated by commas
4929    and terminated with END.  Return the list of types read in, or (struct type
4930    **)-1 if there is an error.  */
4931
4932 static struct type **
4933 read_args (char **pp, int end, struct objfile *objfile)
4934 {
4935   /* FIXME!  Remove this arbitrary limit!  */
4936   struct type *types[1024], **rval;     /* allow for fns of 1023 parameters */
4937   int n = 0;
4938
4939   while (**pp != end)
4940     {
4941       if (**pp != ',')
4942         /* Invalid argument list: no ','.  */
4943         return (struct type **) -1;
4944       (*pp)++;
4945       STABS_CONTINUE (pp, objfile);
4946       types[n++] = read_type (pp, objfile);
4947     }
4948   (*pp)++;                      /* get past `end' (the ':' character) */
4949
4950   if (n == 1)
4951     {
4952       rval = (struct type **) xmalloc (2 * sizeof (struct type *));
4953     }
4954   else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
4955     {
4956       rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
4957       memset (rval + n, 0, sizeof (struct type *));
4958     }
4959   else
4960     {
4961       rval = (struct type **) xmalloc (n * sizeof (struct type *));
4962     }
4963   memcpy (rval, types, n * sizeof (struct type *));
4964   return rval;
4965 }
4966 \f
4967 /* Common block handling.  */
4968
4969 /* List of symbols declared since the last BCOMM.  This list is a tail
4970    of local_symbols.  When ECOMM is seen, the symbols on the list
4971    are noted so their proper addresses can be filled in later,
4972    using the common block base address gotten from the assembler
4973    stabs.  */
4974
4975 static struct pending *common_block;
4976 static int common_block_i;
4977
4978 /* Name of the current common block.  We get it from the BCOMM instead of the
4979    ECOMM to match IBM documentation (even though IBM puts the name both places
4980    like everyone else).  */
4981 static char *common_block_name;
4982
4983 /* Process a N_BCOMM symbol.  The storage for NAME is not guaranteed
4984    to remain after this function returns.  */
4985
4986 void
4987 common_block_start (char *name, struct objfile *objfile)
4988 {
4989   if (common_block_name != NULL)
4990     {
4991       static struct complaint msg =
4992       {
4993         "Invalid symbol data: common block within common block",
4994         0, 0};
4995       complain (&msg);
4996     }
4997   common_block = local_symbols;
4998   common_block_i = local_symbols ? local_symbols->nsyms : 0;
4999   common_block_name = obsavestring (name, strlen (name),
5000                                     &objfile->symbol_obstack);
5001 }
5002
5003 /* Process a N_ECOMM symbol.  */
5004
5005 void
5006 common_block_end (struct objfile *objfile)
5007 {
5008   /* Symbols declared since the BCOMM are to have the common block
5009      start address added in when we know it.  common_block and
5010      common_block_i point to the first symbol after the BCOMM in
5011      the local_symbols list; copy the list and hang it off the
5012      symbol for the common block name for later fixup.  */
5013   int i;
5014   struct symbol *sym;
5015   struct pending *new = 0;
5016   struct pending *next;
5017   int j;
5018
5019   if (common_block_name == NULL)
5020     {
5021       static struct complaint msg =
5022       {"ECOMM symbol unmatched by BCOMM", 0, 0};
5023       complain (&msg);
5024       return;
5025     }
5026
5027   sym = (struct symbol *)
5028     obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
5029   memset (sym, 0, sizeof (struct symbol));
5030   /* Note: common_block_name already saved on symbol_obstack */
5031   SYMBOL_NAME (sym) = common_block_name;
5032   SYMBOL_CLASS (sym) = LOC_BLOCK;
5033
5034   /* Now we copy all the symbols which have been defined since the BCOMM.  */
5035
5036   /* Copy all the struct pendings before common_block.  */
5037   for (next = local_symbols;
5038        next != NULL && next != common_block;
5039        next = next->next)
5040     {
5041       for (j = 0; j < next->nsyms; j++)
5042         add_symbol_to_list (next->symbol[j], &new);
5043     }
5044
5045   /* Copy however much of COMMON_BLOCK we need.  If COMMON_BLOCK is
5046      NULL, it means copy all the local symbols (which we already did
5047      above).  */
5048
5049   if (common_block != NULL)
5050     for (j = common_block_i; j < common_block->nsyms; j++)
5051       add_symbol_to_list (common_block->symbol[j], &new);
5052
5053   SYMBOL_TYPE (sym) = (struct type *) new;
5054
5055   /* Should we be putting local_symbols back to what it was?
5056      Does it matter?  */
5057
5058   i = hashname (SYMBOL_NAME (sym));
5059   SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
5060   global_sym_chain[i] = sym;
5061   common_block_name = NULL;
5062 }
5063
5064 /* Add a common block's start address to the offset of each symbol
5065    declared to be in it (by being between a BCOMM/ECOMM pair that uses
5066    the common block name).  */
5067
5068 static void
5069 fix_common_block (struct symbol *sym, int valu)
5070 {
5071   struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
5072   for (; next; next = next->next)
5073     {
5074       register int j;
5075       for (j = next->nsyms - 1; j >= 0; j--)
5076         SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
5077     }
5078 }
5079 \f
5080
5081
5082 /* What about types defined as forward references inside of a small lexical
5083    scope?  */
5084 /* Add a type to the list of undefined types to be checked through
5085    once this file has been read in.  */
5086
5087 void
5088 add_undefined_type (struct type *type)
5089 {
5090   if (undef_types_length == undef_types_allocated)
5091     {
5092       undef_types_allocated *= 2;
5093       undef_types = (struct type **)
5094         xrealloc ((char *) undef_types,
5095                   undef_types_allocated * sizeof (struct type *));
5096     }
5097   undef_types[undef_types_length++] = type;
5098 }
5099
5100 /* Go through each undefined type, see if it's still undefined, and fix it
5101    up if possible.  We have two kinds of undefined types:
5102
5103    TYPE_CODE_ARRAY:  Array whose target type wasn't defined yet.
5104    Fix:  update array length using the element bounds
5105    and the target type's length.
5106    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
5107    yet defined at the time a pointer to it was made.
5108    Fix:  Do a full lookup on the struct/union tag.  */
5109 void
5110 cleanup_undefined_types (void)
5111 {
5112   struct type **type;
5113
5114   for (type = undef_types; type < undef_types + undef_types_length; type++)
5115     {
5116       switch (TYPE_CODE (*type))
5117         {
5118
5119         case TYPE_CODE_STRUCT:
5120         case TYPE_CODE_UNION:
5121         case TYPE_CODE_ENUM:
5122           {
5123             /* Check if it has been defined since.  Need to do this here
5124                as well as in check_typedef to deal with the (legitimate in
5125                C though not C++) case of several types with the same name
5126                in different source files.  */
5127             if (TYPE_STUB (*type))
5128               {
5129                 struct pending *ppt;
5130                 int i;
5131                 /* Name of the type, without "struct" or "union" */
5132                 char *typename = TYPE_TAG_NAME (*type);
5133
5134                 if (typename == NULL)
5135                   {
5136                     static struct complaint msg =
5137                     {"need a type name", 0, 0};
5138                     complain (&msg);
5139                     break;
5140                   }
5141                 for (ppt = file_symbols; ppt; ppt = ppt->next)
5142                   {
5143                     for (i = 0; i < ppt->nsyms; i++)
5144                       {
5145                         struct symbol *sym = ppt->symbol[i];
5146
5147                         if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
5148                             && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
5149                             && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
5150                                 TYPE_CODE (*type))
5151                             && STREQ (SYMBOL_NAME (sym), typename))
5152                           replace_type (*type, SYMBOL_TYPE (sym));
5153                       }
5154                   }
5155               }
5156           }
5157           break;
5158
5159         default:
5160           {
5161             static struct complaint msg =
5162             {"\
5163 GDB internal error.  cleanup_undefined_types with bad type %d.", 0, 0};
5164             complain (&msg, TYPE_CODE (*type));
5165           }
5166           break;
5167         }
5168     }
5169
5170   undef_types_length = 0;
5171 }
5172
5173 /* Scan through all of the global symbols defined in the object file,
5174    assigning values to the debugging symbols that need to be assigned
5175    to.  Get these symbols from the minimal symbol table.  */
5176
5177 void
5178 scan_file_globals (struct objfile *objfile)
5179 {
5180   int hash;
5181   struct minimal_symbol *msymbol;
5182   struct symbol *sym, *prev, *rsym;
5183   struct objfile *resolve_objfile;
5184
5185   /* SVR4 based linkers copy referenced global symbols from shared
5186      libraries to the main executable.
5187      If we are scanning the symbols for a shared library, try to resolve
5188      them from the minimal symbols of the main executable first.  */
5189
5190   if (symfile_objfile && objfile != symfile_objfile)
5191     resolve_objfile = symfile_objfile;
5192   else
5193     resolve_objfile = objfile;
5194
5195   while (1)
5196     {
5197       /* Avoid expensive loop through all minimal symbols if there are
5198          no unresolved symbols.  */
5199       for (hash = 0; hash < HASHSIZE; hash++)
5200         {
5201           if (global_sym_chain[hash])
5202             break;
5203         }
5204       if (hash >= HASHSIZE)
5205         return;
5206
5207       for (msymbol = resolve_objfile->msymbols;
5208            msymbol && SYMBOL_NAME (msymbol) != NULL;
5209            msymbol++)
5210         {
5211           QUIT;
5212
5213           /* Skip static symbols.  */
5214           switch (MSYMBOL_TYPE (msymbol))
5215             {
5216             case mst_file_text:
5217             case mst_file_data:
5218             case mst_file_bss:
5219               continue;
5220             default:
5221               break;
5222             }
5223
5224           prev = NULL;
5225
5226           /* Get the hash index and check all the symbols
5227              under that hash index. */
5228
5229           hash = hashname (SYMBOL_NAME (msymbol));
5230
5231           for (sym = global_sym_chain[hash]; sym;)
5232             {
5233               if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
5234                   STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
5235                 {
5236
5237                   struct alias_list *aliases;
5238
5239                   /* Splice this symbol out of the hash chain and
5240                      assign the value we have to it. */
5241                   if (prev)
5242                     {
5243                       SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
5244                     }
5245                   else
5246                     {
5247                       global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5248                     }
5249
5250                   /* Check to see whether we need to fix up a common block.  */
5251                   /* Note: this code might be executed several times for
5252                      the same symbol if there are multiple references.  */
5253
5254                   /* If symbol has aliases, do minimal symbol fixups for each.
5255                      These live aliases/references weren't added to 
5256                      global_sym_chain hash but may also need to be fixed up. */
5257                   /* FIXME: Maybe should have added aliases to the global chain,                     resolved symbol name, then treated aliases as normal 
5258                      symbols?  Still, we wouldn't want to add_to_list. */
5259                   /* Now do the same for each alias of this symbol */
5260                   rsym = sym;
5261                   aliases = SYMBOL_ALIASES (sym);
5262                   while (rsym)
5263                     {
5264                       if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5265                         {
5266                           fix_common_block (rsym,
5267                                             SYMBOL_VALUE_ADDRESS (msymbol));
5268                         }
5269                       else
5270                         {
5271                           SYMBOL_VALUE_ADDRESS (rsym)
5272                             = SYMBOL_VALUE_ADDRESS (msymbol);
5273                         }
5274                       SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5275                       if (aliases)
5276                         {
5277                           rsym = aliases->sym;
5278                           aliases = aliases->next;
5279                         }
5280                       else
5281                         rsym = NULL;
5282                     }
5283
5284
5285                   if (prev)
5286                     {
5287                       sym = SYMBOL_VALUE_CHAIN (prev);
5288                     }
5289                   else
5290                     {
5291                       sym = global_sym_chain[hash];
5292                     }
5293                 }
5294               else
5295                 {
5296                   prev = sym;
5297                   sym = SYMBOL_VALUE_CHAIN (sym);
5298                 }
5299             }
5300         }
5301       if (resolve_objfile == objfile)
5302         break;
5303       resolve_objfile = objfile;
5304     }
5305
5306   /* Change the storage class of any remaining unresolved globals to
5307      LOC_UNRESOLVED and remove them from the chain.  */
5308   for (hash = 0; hash < HASHSIZE; hash++)
5309     {
5310       sym = global_sym_chain[hash];
5311       while (sym)
5312         {
5313           prev = sym;
5314           sym = SYMBOL_VALUE_CHAIN (sym);
5315
5316           /* Change the symbol address from the misleading chain value
5317              to address zero.  */
5318           SYMBOL_VALUE_ADDRESS (prev) = 0;
5319
5320           /* Complain about unresolved common block symbols.  */
5321           if (SYMBOL_CLASS (prev) == LOC_STATIC)
5322             SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5323           else
5324             complain (&unresolved_sym_chain_complaint,
5325                       objfile->name, SYMBOL_NAME (prev));
5326         }
5327     }
5328   memset (global_sym_chain, 0, sizeof (global_sym_chain));
5329 }
5330
5331 /* Initialize anything that needs initializing when starting to read
5332    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5333    to a psymtab.  */
5334
5335 void
5336 stabsread_init (void)
5337 {
5338 }
5339
5340 /* Initialize anything that needs initializing when a completely new
5341    symbol file is specified (not just adding some symbols from another
5342    file, e.g. a shared library).  */
5343
5344 void
5345 stabsread_new_init (void)
5346 {
5347   /* Empty the hash table of global syms looking for values.  */
5348   memset (global_sym_chain, 0, sizeof (global_sym_chain));
5349 }
5350
5351 /* Initialize anything that needs initializing at the same time as
5352    start_symtab() is called. */
5353
5354 void
5355 start_stabs (void)
5356 {
5357   global_stabs = NULL;          /* AIX COFF */
5358   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
5359   n_this_object_header_files = 1;
5360   type_vector_length = 0;
5361   type_vector = (struct type **) 0;
5362
5363   /* FIXME: If common_block_name is not already NULL, we should complain().  */
5364   common_block_name = NULL;
5365
5366   os9k_stabs = 0;
5367 }
5368
5369 /* Call after end_symtab() */
5370
5371 void
5372 end_stabs (void)
5373 {
5374   if (type_vector)
5375     {
5376       xfree (type_vector);
5377     }
5378   type_vector = 0;
5379   type_vector_length = 0;
5380   previous_stab_code = 0;
5381 }
5382
5383 void
5384 finish_global_stabs (struct objfile *objfile)
5385 {
5386   if (global_stabs)
5387     {
5388       patch_block_stabs (global_symbols, global_stabs, objfile);
5389       xfree (global_stabs);
5390       global_stabs = NULL;
5391     }
5392 }
5393
5394 /* Initializer for this module */
5395
5396 void
5397 _initialize_stabsread (void)
5398 {
5399   undef_types_allocated = 20;
5400   undef_types_length = 0;
5401   undef_types = (struct type **)
5402     xmalloc (undef_types_allocated * sizeof (struct type *));
5403 }