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