2003-01-02 Andrew Cagney <ac131313@redhat.com>
[external/binutils.git] / gdb / stabsread.c
1 /* Support routines for decoding "stabs" debugging information format.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3    1996, 1997, 1998, 1999, 2000, 2001, 2002
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 /* Support routines for reading and decoding debugging information in
24    the "stabs" format.  This format is used with many systems that use
25    the a.out object file format, as well as some systems that use
26    COFF or ELF where the stabs data is placed in a special section.
27    Avoid placing any object file format specific code in this file. */
28
29 #include "defs.h"
30 #include "gdb_string.h"
31 #include "bfd.h"
32 #include "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.  */
1537       if (SYMBOL_LANGUAGE (sym) == language_cplus)
1538         TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1539
1540       /* fall into process_prototype_types */
1541
1542     process_prototype_types:
1543       /* Sun acc puts declared types of arguments here.  */
1544       if (*p == ';')
1545         {
1546           struct type *ftype = SYMBOL_TYPE (sym);
1547           int nsemi = 0;
1548           int nparams = 0;
1549           char *p1 = p;
1550
1551           /* Obtain a worst case guess for the number of arguments
1552              by counting the semicolons.  */
1553           while (*p1)
1554             {
1555               if (*p1++ == ';')
1556                 nsemi++;
1557             }
1558
1559           /* Allocate parameter information fields and fill them in. */
1560           TYPE_FIELDS (ftype) = (struct field *)
1561             TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
1562           while (*p++ == ';')
1563             {
1564               struct type *ptype;
1565
1566               /* A type number of zero indicates the start of varargs.
1567                  FIXME: GDB currently ignores vararg functions.  */
1568               if (p[0] == '0' && p[1] == '\0')
1569                 break;
1570               ptype = read_type (&p, objfile);
1571
1572               /* The Sun compilers mark integer arguments, which should
1573                  be promoted to the width of the calling conventions, with
1574                  a type which references itself. This type is turned into
1575                  a TYPE_CODE_VOID type by read_type, and we have to turn
1576                  it back into builtin_type_int here.
1577                  FIXME: Do we need a new builtin_type_promoted_int_arg ?  */
1578               if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
1579                 ptype = builtin_type_int;
1580               TYPE_FIELD_TYPE (ftype, nparams) = ptype;
1581               TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
1582             }
1583           TYPE_NFIELDS (ftype) = nparams;
1584           TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
1585         }
1586       break;
1587
1588     case 'F':
1589       /* A global function definition.  */
1590       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1591       SYMBOL_CLASS (sym) = LOC_BLOCK;
1592       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1593       add_symbol_to_list (sym, &global_symbols);
1594       goto process_function_types;
1595
1596     case 'G':
1597       /* For a class G (global) symbol, it appears that the
1598          value is not correct.  It is necessary to search for the
1599          corresponding linker definition to find the value.
1600          These definitions appear at the end of the namelist.  */
1601       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1602       SYMBOL_CLASS (sym) = LOC_STATIC;
1603       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1604       /* Don't add symbol references to global_sym_chain.
1605          Symbol references don't have valid names and wont't match up with
1606          minimal symbols when the global_sym_chain is relocated.
1607          We'll fixup symbol references when we fixup the defining symbol.  */
1608       if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1609         {
1610           i = hashname (SYMBOL_NAME (sym));
1611           SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1612           global_sym_chain[i] = sym;
1613         }
1614       add_symbol_to_list (sym, &global_symbols);
1615       break;
1616
1617       /* This case is faked by a conditional above,
1618          when there is no code letter in the dbx data.
1619          Dbx data never actually contains 'l'.  */
1620     case 's':
1621     case 'l':
1622       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1623       SYMBOL_CLASS (sym) = LOC_LOCAL;
1624       SYMBOL_VALUE (sym) = valu;
1625       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1626       add_symbol_to_list (sym, &local_symbols);
1627       break;
1628
1629     case 'p':
1630       if (*p == 'F')
1631         /* pF is a two-letter code that means a function parameter in Fortran.
1632            The type-number specifies the type of the return value.
1633            Translate it into a pointer-to-function type.  */
1634         {
1635           p++;
1636           SYMBOL_TYPE (sym)
1637             = lookup_pointer_type
1638             (lookup_function_type (read_type (&p, objfile)));
1639         }
1640       else
1641         SYMBOL_TYPE (sym) = read_type (&p, objfile);
1642
1643       /* Normally this is a parameter, a LOC_ARG.  On the i960, it
1644          can also be a LOC_LOCAL_ARG depending on symbol type.  */
1645 #ifndef DBX_PARM_SYMBOL_CLASS
1646 #define DBX_PARM_SYMBOL_CLASS(type)     LOC_ARG
1647 #endif
1648
1649       SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1650       SYMBOL_VALUE (sym) = valu;
1651       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1652       add_symbol_to_list (sym, &local_symbols);
1653
1654       if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
1655         {
1656           /* On little-endian machines, this crud is never necessary,
1657              and, if the extra bytes contain garbage, is harmful.  */
1658           break;
1659         }
1660
1661       /* If it's gcc-compiled, if it says `short', believe it.  */
1662       if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1663         break;
1664
1665       if (!BELIEVE_PCC_PROMOTION)
1666         {
1667           /* This is the signed type which arguments get promoted to.  */
1668           static struct type *pcc_promotion_type;
1669           /* This is the unsigned type which arguments get promoted to.  */
1670           static struct type *pcc_unsigned_promotion_type;
1671
1672           /* Call it "int" because this is mainly C lossage.  */
1673           if (pcc_promotion_type == NULL)
1674             pcc_promotion_type =
1675               init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1676                          0, "int", NULL);
1677
1678           if (pcc_unsigned_promotion_type == NULL)
1679             pcc_unsigned_promotion_type =
1680               init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1681                          TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1682
1683           if (BELIEVE_PCC_PROMOTION_TYPE)
1684             {
1685               /* This is defined on machines (e.g. sparc) where we
1686                  should believe the type of a PCC 'short' argument,
1687                  but shouldn't believe the address (the address is the
1688                  address of the corresponding int).
1689
1690                  My guess is that this correction, as opposed to
1691                  changing the parameter to an 'int' (as done below,
1692                  for PCC on most machines), is the right thing to do
1693                  on all machines, but I don't want to risk breaking
1694                  something that already works.  On most PCC machines,
1695                  the sparc problem doesn't come up because the calling
1696                  function has to zero the top bytes (not knowing
1697                  whether the called function wants an int or a short),
1698                  so there is little practical difference between an
1699                  int and a short (except perhaps what happens when the
1700                  GDB user types "print short_arg = 0x10000;").
1701
1702                  Hacked for SunOS 4.1 by gnu@cygnus.com.  In 4.1, the
1703                  compiler actually produces the correct address (we
1704                  don't need to fix it up).  I made this code adapt so
1705                  that it will offset the symbol if it was pointing at
1706                  an int-aligned location and not otherwise.  This way
1707                  you can use the same gdb for 4.0.x and 4.1 systems.
1708
1709                  If the parameter is shorter than an int, and is
1710                  integral (e.g. char, short, or unsigned equivalent),
1711                  and is claimed to be passed on an integer boundary,
1712                  don't believe it!  Offset the parameter's address to
1713                  the tail-end of that integer.  */
1714
1715               if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1716                   && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1717               && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1718                 {
1719                   SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1720                     - TYPE_LENGTH (SYMBOL_TYPE (sym));
1721                 }
1722               break;
1723             }
1724           else
1725             {
1726               /* If PCC says a parameter is a short or a char,
1727                  it is really an int.  */
1728               if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1729                   && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1730                 {
1731                   SYMBOL_TYPE (sym) =
1732                     TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1733                     ? pcc_unsigned_promotion_type
1734                     : pcc_promotion_type;
1735                 }
1736               break;
1737             }
1738         }
1739
1740     case 'P':
1741       /* acc seems to use P to declare the prototypes of functions that
1742          are referenced by this file.  gdb is not prepared to deal
1743          with this extra information.  FIXME, it ought to.  */
1744       if (type == N_FUN)
1745         {
1746           SYMBOL_TYPE (sym) = read_type (&p, objfile);
1747           goto process_prototype_types;
1748         }
1749       /*FALLTHROUGH */
1750
1751     case 'R':
1752       /* Parameter which is in a register.  */
1753       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1754       SYMBOL_CLASS (sym) = LOC_REGPARM;
1755       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1756       if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1757         {
1758           reg_value_complaint (SYMBOL_VALUE (sym),
1759                                NUM_REGS + NUM_PSEUDO_REGS,
1760                                SYMBOL_SOURCE_NAME (sym));
1761           SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
1762         }
1763       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1764       add_symbol_to_list (sym, &local_symbols);
1765       break;
1766
1767     case 'r':
1768       /* Register variable (either global or local).  */
1769       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1770       SYMBOL_CLASS (sym) = LOC_REGISTER;
1771       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1772       if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1773         {
1774           reg_value_complaint (SYMBOL_VALUE (sym),
1775                                NUM_REGS + NUM_PSEUDO_REGS,
1776                                SYMBOL_SOURCE_NAME (sym));
1777           SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
1778         }
1779       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1780       if (within_function)
1781         {
1782           /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1783              name to represent an argument passed in a register.
1784              GCC uses 'P' for the same case.  So if we find such a symbol pair
1785              we combine it into one 'P' symbol.  For Sun cc we need to do this
1786              regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1787              the 'p' symbol even if it never saves the argument onto the stack.
1788
1789              On most machines, we want to preserve both symbols, so that
1790              we can still get information about what is going on with the
1791              stack (VAX for computing args_printed, using stack slots instead
1792              of saved registers in backtraces, etc.).
1793
1794              Note that this code illegally combines
1795              main(argc) struct foo argc; { register struct foo argc; }
1796              but this case is considered pathological and causes a warning
1797              from a decent compiler.  */
1798
1799           if (local_symbols
1800               && local_symbols->nsyms > 0
1801 #ifndef USE_REGISTER_NOT_ARG
1802               && REG_STRUCT_HAS_ADDR_P ()
1803               && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1804                                       SYMBOL_TYPE (sym))
1805               && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1806                   || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1807                   || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1808                   || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1809 #endif
1810             )
1811             {
1812               struct symbol *prev_sym;
1813               prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1814               if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1815                    || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1816                   && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
1817                 {
1818                   SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1819                   /* Use the type from the LOC_REGISTER; that is the type
1820                      that is actually in that register.  */
1821                   SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1822                   SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1823                   sym = prev_sym;
1824                   break;
1825                 }
1826             }
1827           add_symbol_to_list (sym, &local_symbols);
1828         }
1829       else
1830         add_symbol_to_list (sym, &file_symbols);
1831       break;
1832
1833     case 'S':
1834       /* Static symbol at top level of file */
1835       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1836       SYMBOL_CLASS (sym) = LOC_STATIC;
1837       SYMBOL_VALUE_ADDRESS (sym) = valu;
1838 #ifdef STATIC_TRANSFORM_NAME
1839       if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1840         {
1841           struct minimal_symbol *msym;
1842           msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1843           if (msym != NULL)
1844             {
1845               SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1846               SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1847             }
1848         }
1849 #endif
1850       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1851       add_symbol_to_list (sym, &file_symbols);
1852       break;
1853
1854     case 't':
1855       /* Typedef */
1856       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1857
1858       /* For a nameless type, we don't want a create a symbol, thus we
1859          did not use `sym'. Return without further processing. */
1860       if (nameless)
1861         return NULL;
1862
1863       SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1864       SYMBOL_VALUE (sym) = valu;
1865       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1866       /* C++ vagaries: we may have a type which is derived from
1867          a base type which did not have its name defined when the
1868          derived class was output.  We fill in the derived class's
1869          base part member's name here in that case.  */
1870       if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1871         if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1872              || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1873             && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1874           {
1875             int j;
1876             for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1877               if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1878                 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1879                   type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1880           }
1881
1882       if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1883         {
1884           /* gcc-2.6 or later (when using -fvtable-thunks)
1885              emits a unique named type for a vtable entry.
1886              Some gdb code depends on that specific name. */
1887           extern const char vtbl_ptr_name[];
1888
1889           if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1890                && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1891               || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1892             {
1893               /* If we are giving a name to a type such as "pointer to
1894                  foo" or "function returning foo", we better not set
1895                  the TYPE_NAME.  If the program contains "typedef char
1896                  *caddr_t;", we don't want all variables of type char
1897                  * to print as caddr_t.  This is not just a
1898                  consequence of GDB's type management; PCC and GCC (at
1899                  least through version 2.4) both output variables of
1900                  either type char * or caddr_t with the type number
1901                  defined in the 't' symbol for caddr_t.  If a future
1902                  compiler cleans this up it GDB is not ready for it
1903                  yet, but if it becomes ready we somehow need to
1904                  disable this check (without breaking the PCC/GCC2.4
1905                  case).
1906
1907                  Sigh.
1908
1909                  Fortunately, this check seems not to be necessary
1910                  for anything except pointers or functions.  */
1911               /* ezannoni: 2000-10-26. This seems to apply for
1912                  versions of gcc older than 2.8. This was the original
1913                  problem: with the following code gdb would tell that
1914                  the type for name1 is caddr_t, and func is char()
1915                  typedef char *caddr_t;
1916                  char *name2;
1917                  struct x
1918                  {
1919                  char *name1;
1920                  } xx;
1921                  char *func()
1922                  {
1923                  }
1924                  main () {}
1925                  */
1926
1927               /* Pascal accepts names for pointer types. */
1928               if (current_subfile->language == language_pascal)
1929                 {
1930                   TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1931                 }
1932             }
1933           else
1934             TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1935         }
1936
1937       add_symbol_to_list (sym, &file_symbols);
1938       break;
1939
1940     case 'T':
1941       /* Struct, union, or enum tag.  For GNU C++, this can be be followed
1942          by 't' which means we are typedef'ing it as well.  */
1943       synonym = *p == 't';
1944
1945       if (synonym)
1946         p++;
1947       /* The semantics of C++ state that "struct foo { ... }" also defines 
1948          a typedef for "foo".  Unfortunately, cfront never makes the typedef
1949          when translating C++ into C.  We make the typedef here so that
1950          "ptype foo" works as expected for cfront translated code.  */
1951       else if ((current_subfile->language == language_cplus)
1952                || (current_subfile->language == language_objc))
1953         synonym = 1;
1954
1955       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1956
1957       /* For a nameless type, we don't want a create a symbol, thus we
1958          did not use `sym'. Return without further processing. */
1959       if (nameless)
1960         return NULL;
1961
1962       SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1963       SYMBOL_VALUE (sym) = valu;
1964       SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1965       if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1966         TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1967           = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
1968       add_symbol_to_list (sym, &file_symbols);
1969
1970       if (synonym)
1971         {
1972           /* Clone the sym and then modify it. */
1973           register struct symbol *typedef_sym = (struct symbol *)
1974           obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1975           *typedef_sym = *sym;
1976           SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1977           SYMBOL_VALUE (typedef_sym) = valu;
1978           SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1979           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1980             TYPE_NAME (SYMBOL_TYPE (sym))
1981               = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
1982           add_symbol_to_list (typedef_sym, &file_symbols);
1983         }
1984       break;
1985
1986     case 'V':
1987       /* Static symbol of local scope */
1988       SYMBOL_TYPE (sym) = read_type (&p, objfile);
1989       SYMBOL_CLASS (sym) = LOC_STATIC;
1990       SYMBOL_VALUE_ADDRESS (sym) = valu;
1991 #ifdef STATIC_TRANSFORM_NAME
1992       if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1993         {
1994           struct minimal_symbol *msym;
1995           msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1996           if (msym != NULL)
1997             {
1998               SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1999               SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2000             }
2001         }
2002 #endif
2003       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2004         add_symbol_to_list (sym, &local_symbols);
2005       break;
2006
2007     case 'v':
2008       /* Reference parameter */
2009       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2010       SYMBOL_CLASS (sym) = LOC_REF_ARG;
2011       SYMBOL_VALUE (sym) = valu;
2012       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2013       add_symbol_to_list (sym, &local_symbols);
2014       break;
2015
2016     case 'a':
2017       /* Reference parameter which is in a register.  */
2018       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2019       SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2020       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2021       if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
2022         {
2023           reg_value_complaint (SYMBOL_VALUE (sym),
2024                                NUM_REGS + NUM_PSEUDO_REGS,
2025                                SYMBOL_SOURCE_NAME (sym));
2026           SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
2027         }
2028       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2029       add_symbol_to_list (sym, &local_symbols);
2030       break;
2031
2032     case 'X':
2033       /* This is used by Sun FORTRAN for "function result value".
2034          Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2035          that Pascal uses it too, but when I tried it Pascal used
2036          "x:3" (local symbol) instead.  */
2037       SYMBOL_TYPE (sym) = read_type (&p, objfile);
2038       SYMBOL_CLASS (sym) = LOC_LOCAL;
2039       SYMBOL_VALUE (sym) = valu;
2040       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2041       add_symbol_to_list (sym, &local_symbols);
2042       break;
2043
2044       /* New code added to support cfront stabs strings.
2045          Note: case 'P' already handled above */
2046     case 'Z':
2047       /* Cfront type continuation coming up!
2048          Find the original definition and add to it.
2049          We'll have to do this for the typedef too,
2050          since we cloned the symbol to define a type in read_type.
2051          Stabs info examples:
2052          __1C :Ztl 
2053          foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2054          C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2055          where C is the name of the class.
2056          Unfortunately, we can't lookup the original symbol yet 'cuz 
2057          we haven't finished reading all the symbols.
2058          Instead, we save it for processing later */
2059       process_later (sym, p, resolve_cfront_continuation);
2060       SYMBOL_TYPE (sym) = error_type (&p, objfile);     /* FIXME! change later */
2061       SYMBOL_CLASS (sym) = LOC_CONST;
2062       SYMBOL_VALUE (sym) = 0;
2063       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2064       /* Don't add to list - we'll delete it later when 
2065          we add the continuation to the real sym */
2066       return sym;
2067       /* End of new code added to support cfront stabs strings */
2068
2069     default:
2070       SYMBOL_TYPE (sym) = error_type (&p, objfile);
2071       SYMBOL_CLASS (sym) = LOC_CONST;
2072       SYMBOL_VALUE (sym) = 0;
2073       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2074       add_symbol_to_list (sym, &file_symbols);
2075       break;
2076     }
2077
2078   /* When passing structures to a function, some systems sometimes pass
2079      the address in a register, not the structure itself. */
2080
2081   if (REG_STRUCT_HAS_ADDR_P ()
2082       && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2083       && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2084     {
2085       struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2086
2087       if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2088           || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2089           || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2090           || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2091         {
2092           /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2093              LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2094           if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2095             SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2096           /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2097              and subsequent arguments on the sparc, for example).  */
2098           else if (SYMBOL_CLASS (sym) == LOC_ARG)
2099             SYMBOL_CLASS (sym) = LOC_REF_ARG;
2100         }
2101     }
2102
2103   /* Is there more to parse?  For example LRS/alias information?  */
2104   while (*p && *p == ';')
2105     {
2106       p++;
2107       if (*p && p[0] == 'l' && p[1] == '(')
2108         {
2109           /* GNU extensions for live range splitting may be appended to 
2110              the end of the stab string.  eg. "l(#1,#2);l(#3,#5)" */
2111
2112           /* Resolve the live range and add it to SYM's live range list.  */
2113           if (!resolve_live_range (objfile, sym, p))
2114             return NULL;
2115
2116           /* Find end of live range info. */
2117           p = strchr (p, ')');
2118           if (!*p || *p != ')')
2119             {
2120               lrs_general_complaint ("live range format not recognized");
2121               return NULL;
2122             }
2123           p++;
2124         }
2125     }
2126   return sym;
2127 }
2128
2129 /* Add the live range found in P to the symbol SYM in objfile OBJFILE.  Returns
2130    non-zero on success, zero otherwise.  */
2131
2132 static int
2133 resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
2134 {
2135   int refnum;
2136   CORE_ADDR start, end;
2137
2138   /* Sanity check the beginning of the stabs string.  */
2139   if (!*p || *p != 'l')
2140     {
2141       lrs_general_complaint ("live range string 1");
2142       return 0;
2143     }
2144   p++;
2145
2146   if (!*p || *p != '(')
2147     {
2148       lrs_general_complaint ("live range string 2");
2149       return 0;
2150     }
2151   p++;
2152
2153   /* Get starting value of range and advance P past the reference id.
2154
2155      ?!? In theory, the process_reference should never fail, but we should
2156      catch that case just in case the compiler scrogged the stabs.  */
2157   refnum = process_reference (&p);
2158   start = ref_search_value (refnum);
2159   if (!start)
2160     {
2161       lrs_general_complaint ("Live range symbol not found 1");
2162       return 0;
2163     }
2164
2165   if (!*p || *p != ',')
2166     {
2167       lrs_general_complaint ("live range string 3");
2168       return 0;
2169     }
2170   p++;
2171
2172   /* Get ending value of range and advance P past the reference id.
2173
2174      ?!? In theory, the process_reference should never fail, but we should
2175      catch that case just in case the compiler scrogged the stabs.  */
2176   refnum = process_reference (&p);
2177   end = ref_search_value (refnum);
2178   if (!end)
2179     {
2180       lrs_general_complaint ("Live range symbol not found 2");
2181       return 0;
2182     }
2183
2184   if (!*p || *p != ')')
2185     {
2186       lrs_general_complaint ("live range string 4");
2187       return 0;
2188     }
2189
2190   /* Now that we know the bounds of the range, add it to the
2191      symbol.  */
2192   add_live_range (objfile, sym, start, end);
2193
2194   return 1;
2195 }
2196
2197 /* Add a new live range defined by START and END to the symbol SYM
2198    in objfile OBJFILE.  */
2199
2200 static void
2201 add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2202                 CORE_ADDR end)
2203 {
2204   struct range_list *r, *rs;
2205
2206   if (start >= end)
2207     {
2208       lrs_general_complaint ("end of live range follows start");
2209       return;
2210     }
2211
2212   /* Alloc new live range structure. */
2213   r = (struct range_list *)
2214     obstack_alloc (&objfile->type_obstack,
2215                    sizeof (struct range_list));
2216   r->start = start;
2217   r->end = end;
2218   r->next = 0;
2219
2220   /* Append this range to the symbol's range list. */
2221   if (!SYMBOL_RANGES (sym))
2222     SYMBOL_RANGES (sym) = r;
2223   else
2224     {
2225       /* Get the last range for the symbol. */
2226       for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2227         ;
2228       rs->next = r;
2229     }
2230 }
2231 \f
2232
2233 /* Skip rest of this symbol and return an error type.
2234
2235    General notes on error recovery:  error_type always skips to the
2236    end of the symbol (modulo cretinous dbx symbol name continuation).
2237    Thus code like this:
2238
2239    if (*(*pp)++ != ';')
2240    return error_type (pp, objfile);
2241
2242    is wrong because if *pp starts out pointing at '\0' (typically as the
2243    result of an earlier error), it will be incremented to point to the
2244    start of the next symbol, which might produce strange results, at least
2245    if you run off the end of the string table.  Instead use
2246
2247    if (**pp != ';')
2248    return error_type (pp, objfile);
2249    ++*pp;
2250
2251    or
2252
2253    if (**pp != ';')
2254    foo = error_type (pp, objfile);
2255    else
2256    ++*pp;
2257
2258    And in case it isn't obvious, the point of all this hair is so the compiler
2259    can define new types and new syntaxes, and old versions of the
2260    debugger will be able to read the new symbol tables.  */
2261
2262 static struct type *
2263 error_type (char **pp, struct objfile *objfile)
2264 {
2265   complaint (&symfile_complaints, "couldn't parse type; debugger out of date?");
2266   while (1)
2267     {
2268       /* Skip to end of symbol.  */
2269       while (**pp != '\0')
2270         {
2271           (*pp)++;
2272         }
2273
2274       /* Check for and handle cretinous dbx symbol name continuation!  */
2275       if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2276         {
2277           *pp = next_symbol_text (objfile);
2278         }
2279       else
2280         {
2281           break;
2282         }
2283     }
2284   return (builtin_type_error);
2285 }
2286 \f
2287
2288 /* Read type information or a type definition; return the type.  Even
2289    though this routine accepts either type information or a type
2290    definition, the distinction is relevant--some parts of stabsread.c
2291    assume that type information starts with a digit, '-', or '(' in
2292    deciding whether to call read_type.  */
2293
2294 struct type *
2295 read_type (register char **pp, struct objfile *objfile)
2296 {
2297   register struct type *type = 0;
2298   struct type *type1;
2299   int typenums[2];
2300   char type_descriptor;
2301
2302   /* Size in bits of type if specified by a type attribute, or -1 if
2303      there is no size attribute.  */
2304   int type_size = -1;
2305
2306   /* Used to distinguish string and bitstring from char-array and set. */
2307   int is_string = 0;
2308
2309   /* Used to distinguish vector from array. */
2310   int is_vector = 0;
2311
2312   /* Read type number if present.  The type number may be omitted.
2313      for instance in a two-dimensional array declared with type
2314      "ar1;1;10;ar1;1;10;4".  */
2315   if ((**pp >= '0' && **pp <= '9')
2316       || **pp == '('
2317       || **pp == '-')
2318     {
2319       if (read_type_number (pp, typenums) != 0)
2320         return error_type (pp, objfile);
2321
2322       /* Type is not being defined here.  Either it already exists,
2323          or this is a forward reference to it.  dbx_alloc_type handles
2324          both cases.  */
2325       if (**pp != '=')
2326         return dbx_alloc_type (typenums, objfile);
2327
2328       /* Type is being defined here.  */
2329       /* Skip the '='.
2330          Also skip the type descriptor - we get it below with (*pp)[-1].  */
2331       (*pp) += 2;
2332     }
2333   else
2334     {
2335       /* 'typenums=' not present, type is anonymous.  Read and return
2336          the definition, but don't put it in the type vector.  */
2337       typenums[0] = typenums[1] = -1;
2338       (*pp)++;
2339     }
2340
2341 again:
2342   type_descriptor = (*pp)[-1];
2343   switch (type_descriptor)
2344     {
2345     case 'x':
2346       {
2347         enum type_code code;
2348
2349         /* Used to index through file_symbols.  */
2350         struct pending *ppt;
2351         int i;
2352
2353         /* Name including "struct", etc.  */
2354         char *type_name;
2355
2356         {
2357           char *from, *to, *p, *q1, *q2;
2358
2359           /* Set the type code according to the following letter.  */
2360           switch ((*pp)[0])
2361             {
2362             case 's':
2363               code = TYPE_CODE_STRUCT;
2364               break;
2365             case 'u':
2366               code = TYPE_CODE_UNION;
2367               break;
2368             case 'e':
2369               code = TYPE_CODE_ENUM;
2370               break;
2371             default:
2372               {
2373                 /* Complain and keep going, so compilers can invent new
2374                    cross-reference types.  */
2375                 complaint (&symfile_complaints,
2376                            "Unrecognized cross-reference type `%c'", (*pp)[0]);
2377                 code = TYPE_CODE_STRUCT;
2378                 break;
2379               }
2380             }
2381
2382           q1 = strchr (*pp, '<');
2383           p = strchr (*pp, ':');
2384           if (p == NULL)
2385             return error_type (pp, objfile);
2386           if (q1 && p > q1 && p[1] == ':')
2387             {
2388               int nesting_level = 0;
2389               for (q2 = q1; *q2; q2++)
2390                 {
2391                   if (*q2 == '<')
2392                     nesting_level++;
2393                   else if (*q2 == '>')
2394                     nesting_level--;
2395                   else if (*q2 == ':' && nesting_level == 0)
2396                     break;
2397                 }
2398               p = q2;
2399               if (*p != ':')
2400                 return error_type (pp, objfile);
2401             }
2402           to = type_name =
2403             (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2404
2405           /* Copy the name.  */
2406           from = *pp + 1;
2407           while (from < p)
2408             *to++ = *from++;
2409           *to = '\0';
2410
2411           /* Set the pointer ahead of the name which we just read, and
2412              the colon.  */
2413           *pp = from + 1;
2414         }
2415
2416         /* Now check to see whether the type has already been
2417            declared.  This was written for arrays of cross-referenced
2418            types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2419            sure it is not necessary anymore.  But it might be a good
2420            idea, to save a little memory.  */
2421
2422         for (ppt = file_symbols; ppt; ppt = ppt->next)
2423           for (i = 0; i < ppt->nsyms; i++)
2424             {
2425               struct symbol *sym = ppt->symbol[i];
2426
2427               if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2428                   && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2429                   && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2430                   && STREQ (SYMBOL_NAME (sym), type_name))
2431                 {
2432                   obstack_free (&objfile->type_obstack, type_name);
2433                   type = SYMBOL_TYPE (sym);
2434                   return type;
2435                 }
2436             }
2437
2438         /* Didn't find the type to which this refers, so we must
2439            be dealing with a forward reference.  Allocate a type
2440            structure for it, and keep track of it so we can
2441            fill in the rest of the fields when we get the full
2442            type.  */
2443         type = dbx_alloc_type (typenums, objfile);
2444         TYPE_CODE (type) = code;
2445         TYPE_TAG_NAME (type) = type_name;
2446         INIT_CPLUS_SPECIFIC (type);
2447         TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2448
2449         add_undefined_type (type);
2450         return type;
2451       }
2452
2453     case '-':                   /* RS/6000 built-in type */
2454     case '0':
2455     case '1':
2456     case '2':
2457     case '3':
2458     case '4':
2459     case '5':
2460     case '6':
2461     case '7':
2462     case '8':
2463     case '9':
2464     case '(':
2465       (*pp)--;
2466
2467       /* We deal with something like t(1,2)=(3,4)=... which
2468          the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2469
2470       /* Allocate and enter the typedef type first.
2471          This handles recursive types. */
2472       type = dbx_alloc_type (typenums, objfile);
2473       TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2474       {
2475         struct type *xtype = read_type (pp, objfile);
2476         if (type == xtype)
2477           {
2478             /* It's being defined as itself.  That means it is "void".  */
2479             TYPE_CODE (type) = TYPE_CODE_VOID;
2480             TYPE_LENGTH (type) = 1;
2481           }
2482         else if (type_size >= 0 || is_string)
2483           {
2484             /* This is the absolute wrong way to construct types.  Every
2485                other debug format has found a way around this problem and
2486                the related problems with unnecessarily stubbed types;
2487                someone motivated should attempt to clean up the issue
2488                here as well.  Once a type pointed to has been created it
2489                should not be modified.
2490
2491                Well, it's not *absolutely* wrong.  Constructing recursive
2492                types (trees, linked lists) necessarily entails modifying
2493                types after creating them.  Constructing any loop structure
2494                entails side effects.  The Dwarf 2 reader does handle this
2495                more gracefully (it never constructs more than once
2496                instance of a type object, so it doesn't have to copy type
2497                objects wholesale), but it still mutates type objects after
2498                other folks have references to them.
2499
2500                Keep in mind that this circularity/mutation issue shows up
2501                at the source language level, too: C's "incomplete types",
2502                for example.  So the proper cleanup, I think, would be to
2503                limit GDB's type smashing to match exactly those required
2504                by the source language.  So GDB could have a
2505                "complete_this_type" function, but never create unnecessary
2506                copies of a type otherwise.  */
2507             replace_type (type, xtype);
2508             TYPE_NAME (type) = NULL;
2509             TYPE_TAG_NAME (type) = NULL;
2510           }
2511         else
2512           {
2513             TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2514             TYPE_TARGET_TYPE (type) = xtype;
2515           }
2516       }
2517       break;
2518
2519       /* In the following types, we must be sure to overwrite any existing
2520          type that the typenums refer to, rather than allocating a new one
2521          and making the typenums point to the new one.  This is because there
2522          may already be pointers to the existing type (if it had been
2523          forward-referenced), and we must change it to a pointer, function,
2524          reference, or whatever, *in-place*.  */
2525
2526     case '*':                   /* Pointer to another type */
2527       type1 = read_type (pp, objfile);
2528       type = make_pointer_type (type1, dbx_lookup_type (typenums));
2529       break;
2530
2531     case '&':                   /* Reference to another type */
2532       type1 = read_type (pp, objfile);
2533       type = make_reference_type (type1, dbx_lookup_type (typenums));
2534       break;
2535
2536     case 'f':                   /* Function returning another type */
2537       type1 = read_type (pp, objfile);
2538       type = make_function_type (type1, dbx_lookup_type (typenums));
2539       break;
2540
2541     case 'g':                   /* Prototyped function.  (Sun)  */
2542       {
2543         /* Unresolved questions:
2544
2545            - According to Sun's ``STABS Interface Manual'', for 'f'
2546            and 'F' symbol descriptors, a `0' in the argument type list
2547            indicates a varargs function.  But it doesn't say how 'g'
2548            type descriptors represent that info.  Someone with access
2549            to Sun's toolchain should try it out.
2550
2551            - According to the comment in define_symbol (search for
2552            `process_prototype_types:'), Sun emits integer arguments as
2553            types which ref themselves --- like `void' types.  Do we
2554            have to deal with that here, too?  Again, someone with
2555            access to Sun's toolchain should try it out and let us
2556            know.  */
2557
2558         const char *type_start = (*pp) - 1;
2559         struct type *return_type = read_type (pp, objfile);
2560         struct type *func_type
2561           = make_function_type (return_type, dbx_lookup_type (typenums));
2562         struct type_list {
2563           struct type *type;
2564           struct type_list *next;
2565         } *arg_types = 0;
2566         int num_args = 0;
2567
2568         while (**pp && **pp != '#')
2569           {
2570             struct type *arg_type = read_type (pp, objfile);
2571             struct type_list *new = alloca (sizeof (*new));
2572             new->type = arg_type;
2573             new->next = arg_types;
2574             arg_types = new;
2575             num_args++;
2576           }
2577         if (**pp == '#')
2578           ++*pp;
2579         else
2580           {
2581             complaint (&symfile_complaints,
2582                        "Prototyped function type didn't end arguments with `#':\n%s",
2583                        type_start);
2584           }
2585
2586         /* If there is just one argument whose type is `void', then
2587            that's just an empty argument list.  */
2588         if (arg_types
2589             && ! arg_types->next
2590             && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
2591           num_args = 0;
2592
2593         TYPE_FIELDS (func_type)
2594           = (struct field *) TYPE_ALLOC (func_type,
2595                                          num_args * sizeof (struct field));
2596         memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
2597         {
2598           int i;
2599           struct type_list *t;
2600
2601           /* We stuck each argument type onto the front of the list
2602              when we read it, so the list is reversed.  Build the
2603              fields array right-to-left.  */
2604           for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
2605             TYPE_FIELD_TYPE (func_type, i) = t->type;
2606         }
2607         TYPE_NFIELDS (func_type) = num_args;
2608         TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
2609
2610         type = func_type;
2611         break;
2612       }
2613
2614     case 'k':                   /* Const qualifier on some type (Sun) */
2615       type = read_type (pp, objfile);
2616       type = make_cv_type (1, TYPE_VOLATILE (type), type,
2617                            dbx_lookup_type (typenums));
2618       break;
2619
2620     case 'B':                   /* Volatile qual on some type (Sun) */
2621       type = read_type (pp, objfile);
2622       type = make_cv_type (TYPE_CONST (type), 1, type,
2623                            dbx_lookup_type (typenums));
2624       break;
2625
2626     case '@':
2627       if (isdigit (**pp) || **pp == '(' || **pp == '-')
2628         {                       /* Member (class & variable) type */
2629           /* FIXME -- we should be doing smash_to_XXX types here.  */
2630
2631           struct type *domain = read_type (pp, objfile);
2632           struct type *memtype;
2633
2634           if (**pp != ',')
2635             /* Invalid member type data format.  */
2636             return error_type (pp, objfile);
2637           ++*pp;
2638
2639           memtype = read_type (pp, objfile);
2640           type = dbx_alloc_type (typenums, objfile);
2641           smash_to_member_type (type, domain, memtype);
2642         }
2643       else
2644         /* type attribute */
2645         {
2646           char *attr = *pp;
2647           /* Skip to the semicolon.  */
2648           while (**pp != ';' && **pp != '\0')
2649             ++(*pp);
2650           if (**pp == '\0')
2651             return error_type (pp, objfile);
2652           else
2653             ++ * pp;            /* Skip the semicolon.  */
2654
2655           switch (*attr)
2656             {
2657             case 's':           /* Size attribute */
2658               type_size = atoi (attr + 1);
2659               if (type_size <= 0)
2660                 type_size = -1;
2661               break;
2662
2663             case 'S':           /* String attribute */
2664               /* FIXME: check to see if following type is array? */
2665               is_string = 1;
2666               break;
2667
2668             case 'V':           /* Vector attribute */
2669               /* FIXME: check to see if following type is array? */
2670               is_vector = 1;
2671               break;
2672
2673             default:
2674               /* Ignore unrecognized type attributes, so future compilers
2675                  can invent new ones.  */
2676               break;
2677             }
2678           ++*pp;
2679           goto again;
2680         }
2681       break;
2682
2683     case '#':                   /* Method (class & fn) type */
2684       if ((*pp)[0] == '#')
2685         {
2686           /* We'll get the parameter types from the name.  */
2687           struct type *return_type;
2688
2689           (*pp)++;
2690           return_type = read_type (pp, objfile);
2691           if (*(*pp)++ != ';')
2692             complaint (&symfile_complaints,
2693                        "invalid (minimal) member type data format at symtab pos %d.",
2694                        symnum);
2695           type = allocate_stub_method (return_type);
2696           if (typenums[0] != -1)
2697             *dbx_lookup_type (typenums) = type;
2698         }
2699       else
2700         {
2701           struct type *domain = read_type (pp, objfile);
2702           struct type *return_type;
2703           struct field *args;
2704           int nargs, varargs;
2705
2706           if (**pp != ',')
2707             /* Invalid member type data format.  */
2708             return error_type (pp, objfile);
2709           else
2710             ++(*pp);
2711
2712           return_type = read_type (pp, objfile);
2713           args = read_args (pp, ';', objfile, &nargs, &varargs);
2714           type = dbx_alloc_type (typenums, objfile);
2715           smash_to_method_type (type, domain, return_type, args,
2716                                 nargs, varargs);
2717         }
2718       break;
2719
2720     case 'r':                   /* Range type */
2721       type = read_range_type (pp, typenums, objfile);
2722       if (typenums[0] != -1)
2723         *dbx_lookup_type (typenums) = type;
2724       break;
2725
2726     case 'b':
2727         {
2728           /* Sun ACC builtin int type */
2729           type = read_sun_builtin_type (pp, typenums, objfile);
2730           if (typenums[0] != -1)
2731             *dbx_lookup_type (typenums) = type;
2732         }
2733       break;
2734
2735     case 'R':                   /* Sun ACC builtin float type */
2736       type = read_sun_floating_type (pp, typenums, objfile);
2737       if (typenums[0] != -1)
2738         *dbx_lookup_type (typenums) = type;
2739       break;
2740
2741     case 'e':                   /* Enumeration type */
2742       type = dbx_alloc_type (typenums, objfile);
2743       type = read_enum_type (pp, type, objfile);
2744       if (typenums[0] != -1)
2745         *dbx_lookup_type (typenums) = type;
2746       break;
2747
2748     case 's':                   /* Struct type */
2749     case 'u':                   /* Union type */
2750       {
2751         enum type_code type_code = TYPE_CODE_UNDEF;
2752         type = dbx_alloc_type (typenums, objfile);
2753         switch (type_descriptor)
2754           {
2755           case 's':
2756             type_code = TYPE_CODE_STRUCT;
2757             break;
2758           case 'u':
2759             type_code = TYPE_CODE_UNION;
2760             break;
2761           }
2762         type = read_struct_type (pp, type, type_code, objfile);
2763         break;
2764       }
2765
2766     case 'a':                   /* Array type */
2767       if (**pp != 'r')
2768         return error_type (pp, objfile);
2769       ++*pp;
2770
2771       type = dbx_alloc_type (typenums, objfile);
2772       type = read_array_type (pp, type, objfile);
2773       if (is_string)
2774         TYPE_CODE (type) = TYPE_CODE_STRING;
2775       if (is_vector)
2776         TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
2777       break;
2778
2779     case 'S':                   /* Set or bitstring  type */
2780       type1 = read_type (pp, objfile);
2781       type = create_set_type ((struct type *) NULL, type1);
2782       if (is_string)
2783         TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2784       if (typenums[0] != -1)
2785         *dbx_lookup_type (typenums) = type;
2786       break;
2787
2788     default:
2789       --*pp;                    /* Go back to the symbol in error */
2790       /* Particularly important if it was \0! */
2791       return error_type (pp, objfile);
2792     }
2793
2794   if (type == 0)
2795     {
2796       warning ("GDB internal error, type is NULL in stabsread.c\n");
2797       return error_type (pp, objfile);
2798     }
2799
2800   /* Size specified in a type attribute overrides any other size.  */
2801   if (type_size != -1)
2802     TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2803
2804   return type;
2805 }
2806 \f
2807 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2808    Return the proper type node for a given builtin type number. */
2809
2810 static struct type *
2811 rs6000_builtin_type (int typenum)
2812 {
2813   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
2814 #define NUMBER_RECOGNIZED 34
2815   /* This includes an empty slot for type number -0.  */
2816   static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2817   struct type *rettype = NULL;
2818
2819   if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2820     {
2821       complaint (&symfile_complaints, "Unknown builtin type %d", typenum);
2822       return builtin_type_error;
2823     }
2824   if (negative_types[-typenum] != NULL)
2825     return negative_types[-typenum];
2826
2827 #if TARGET_CHAR_BIT != 8
2828 #error This code wrong for TARGET_CHAR_BIT not 8
2829   /* These definitions all assume that TARGET_CHAR_BIT is 8.  I think
2830      that if that ever becomes not true, the correct fix will be to
2831      make the size in the struct type to be in bits, not in units of
2832      TARGET_CHAR_BIT.  */
2833 #endif
2834
2835   switch (-typenum)
2836     {
2837     case 1:
2838       /* The size of this and all the other types are fixed, defined
2839          by the debugging format.  If there is a type called "int" which
2840          is other than 32 bits, then it should use a new negative type
2841          number (or avoid negative type numbers for that case).
2842          See stabs.texinfo.  */
2843       rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2844       break;
2845     case 2:
2846       rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2847       break;
2848     case 3:
2849       rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2850       break;
2851     case 4:
2852       rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2853       break;
2854     case 5:
2855       rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2856                            "unsigned char", NULL);
2857       break;
2858     case 6:
2859       rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2860       break;
2861     case 7:
2862       rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2863                            "unsigned short", NULL);
2864       break;
2865     case 8:
2866       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2867                            "unsigned int", NULL);
2868       break;
2869     case 9:
2870       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2871                            "unsigned", NULL);
2872     case 10:
2873       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2874                            "unsigned long", NULL);
2875       break;
2876     case 11:
2877       rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2878       break;
2879     case 12:
2880       /* IEEE single precision (32 bit).  */
2881       rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2882       break;
2883     case 13:
2884       /* IEEE double precision (64 bit).  */
2885       rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2886       break;
2887     case 14:
2888       /* This is an IEEE double on the RS/6000, and different machines with
2889          different sizes for "long double" should use different negative
2890          type numbers.  See stabs.texinfo.  */
2891       rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2892       break;
2893     case 15:
2894       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2895       break;
2896     case 16:
2897       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2898                            "boolean", NULL);
2899       break;
2900     case 17:
2901       rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2902       break;
2903     case 18:
2904       rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2905       break;
2906     case 19:
2907       rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2908       break;
2909     case 20:
2910       rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2911                            "character", NULL);
2912       break;
2913     case 21:
2914       rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2915                            "logical*1", NULL);
2916       break;
2917     case 22:
2918       rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
2919                            "logical*2", NULL);
2920       break;
2921     case 23:
2922       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2923                            "logical*4", NULL);
2924       break;
2925     case 24:
2926       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2927                            "logical", NULL);
2928       break;
2929     case 25:
2930       /* Complex type consisting of two IEEE single precision values.  */
2931       rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
2932       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
2933                                               NULL);
2934       break;
2935     case 26:
2936       /* Complex type consisting of two IEEE double precision values.  */
2937       rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
2938       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
2939                                               NULL);
2940       break;
2941     case 27:
2942       rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
2943       break;
2944     case 28:
2945       rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
2946       break;
2947     case 29:
2948       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
2949       break;
2950     case 30:
2951       rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
2952       break;
2953     case 31:
2954       rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
2955       break;
2956     case 32:
2957       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2958                            "unsigned long long", NULL);
2959       break;
2960     case 33:
2961       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2962                            "logical*8", NULL);
2963       break;
2964     case 34:
2965       rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
2966       break;
2967     }
2968   negative_types[-typenum] = rettype;
2969   return rettype;
2970 }
2971 \f
2972 /* This page contains subroutines of read_type.  */
2973
2974 /* Replace *OLD_NAME with the method name portion of PHYSNAME.  */
2975
2976 static void
2977 update_method_name_from_physname (char **old_name, char *physname)
2978 {
2979   char *method_name;
2980
2981   method_name = method_name_from_physname (physname);
2982
2983   if (method_name == NULL)
2984     error ("bad physname %s\n", physname);
2985
2986   if (strcmp (*old_name, method_name) != 0)
2987     {
2988       xfree (*old_name);
2989       *old_name = method_name;
2990     }
2991   else
2992     xfree (method_name);
2993 }
2994
2995 /* Read member function stabs info for C++ classes.  The form of each member
2996    function data is:
2997
2998    NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2999
3000    An example with two member functions is:
3001
3002    afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
3003
3004    For the case of overloaded operators, the format is op$::*.funcs, where
3005    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
3006    name (such as `+=') and `.' marks the end of the operator name.
3007
3008    Returns 1 for success, 0 for failure.  */
3009
3010 static int
3011 read_member_functions (struct field_info *fip, char **pp, struct type *type,
3012                        struct objfile *objfile)
3013 {
3014   int nfn_fields = 0;
3015   int length = 0;
3016   /* Total number of member functions defined in this class.  If the class
3017      defines two `f' functions, and one `g' function, then this will have
3018      the value 3.  */
3019   int total_length = 0;
3020   int i;
3021   struct next_fnfield
3022     {
3023       struct next_fnfield *next;
3024       struct fn_field fn_field;
3025     }
3026    *sublist;
3027   struct type *look_ahead_type;
3028   struct next_fnfieldlist *new_fnlist;
3029   struct next_fnfield *new_sublist;
3030   char *main_fn_name;
3031   register char *p;
3032
3033   /* Process each list until we find something that is not a member function
3034      or find the end of the functions. */
3035
3036   while (**pp != ';')
3037     {
3038       /* We should be positioned at the start of the function name.
3039          Scan forward to find the first ':' and if it is not the
3040          first of a "::" delimiter, then this is not a member function. */
3041       p = *pp;
3042       while (*p != ':')
3043         {
3044           p++;
3045         }
3046       if (p[1] != ':')
3047         {
3048           break;
3049         }
3050
3051       sublist = NULL;
3052       look_ahead_type = NULL;
3053       length = 0;
3054
3055       new_fnlist = (struct next_fnfieldlist *)
3056         xmalloc (sizeof (struct next_fnfieldlist));
3057       make_cleanup (xfree, new_fnlist);
3058       memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
3059
3060       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
3061         {
3062           /* This is a completely wierd case.  In order to stuff in the
3063              names that might contain colons (the usual name delimiter),
3064              Mike Tiemann defined a different name format which is
3065              signalled if the identifier is "op$".  In that case, the
3066              format is "op$::XXXX." where XXXX is the name.  This is
3067              used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
3068           /* This lets the user type "break operator+".
3069              We could just put in "+" as the name, but that wouldn't
3070              work for "*".  */
3071           static char opname[32] = "op$";
3072           char *o = opname + 3;
3073
3074           /* Skip past '::'.  */
3075           *pp = p + 2;
3076
3077           STABS_CONTINUE (pp, objfile);
3078           p = *pp;
3079           while (*p != '.')
3080             {
3081               *o++ = *p++;
3082             }
3083           main_fn_name = savestring (opname, o - opname);
3084           /* Skip past '.'  */
3085           *pp = p + 1;
3086         }
3087       else
3088         {
3089           main_fn_name = savestring (*pp, p - *pp);
3090           /* Skip past '::'.  */
3091           *pp = p + 2;
3092         }
3093       new_fnlist->fn_fieldlist.name = main_fn_name;
3094
3095       do
3096         {
3097           new_sublist =
3098             (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
3099           make_cleanup (xfree, new_sublist);
3100           memset (new_sublist, 0, sizeof (struct next_fnfield));
3101
3102           /* Check for and handle cretinous dbx symbol name continuation!  */
3103           if (look_ahead_type == NULL)
3104             {
3105               /* Normal case. */
3106               STABS_CONTINUE (pp, objfile);
3107
3108               new_sublist->fn_field.type = read_type (pp, objfile);
3109               if (**pp != ':')
3110                 {
3111                   /* Invalid symtab info for member function.  */
3112                   return 0;
3113                 }
3114             }
3115           else
3116             {
3117               /* g++ version 1 kludge */
3118               new_sublist->fn_field.type = look_ahead_type;
3119               look_ahead_type = NULL;
3120             }
3121
3122           (*pp)++;
3123           p = *pp;
3124           while (*p != ';')
3125             {
3126               p++;
3127             }
3128
3129           /* If this is just a stub, then we don't have the real name here. */
3130
3131           if (TYPE_STUB (new_sublist->fn_field.type))
3132             {
3133               if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3134                 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3135               new_sublist->fn_field.is_stub = 1;
3136             }
3137           new_sublist->fn_field.physname = savestring (*pp, p - *pp);
3138           *pp = p + 1;
3139
3140           /* Set this member function's visibility fields.  */
3141           switch (*(*pp)++)
3142             {
3143             case VISIBILITY_PRIVATE:
3144               new_sublist->fn_field.is_private = 1;
3145               break;
3146             case VISIBILITY_PROTECTED:
3147               new_sublist->fn_field.is_protected = 1;
3148               break;
3149             }
3150
3151           STABS_CONTINUE (pp, objfile);
3152           switch (**pp)
3153             {
3154             case 'A':           /* Normal functions. */
3155               new_sublist->fn_field.is_const = 0;
3156               new_sublist->fn_field.is_volatile = 0;
3157               (*pp)++;
3158               break;
3159             case 'B':           /* `const' member functions. */
3160               new_sublist->fn_field.is_const = 1;
3161               new_sublist->fn_field.is_volatile = 0;
3162               (*pp)++;
3163               break;
3164             case 'C':           /* `volatile' member function. */
3165               new_sublist->fn_field.is_const = 0;
3166               new_sublist->fn_field.is_volatile = 1;
3167               (*pp)++;
3168               break;
3169             case 'D':           /* `const volatile' member function. */
3170               new_sublist->fn_field.is_const = 1;
3171               new_sublist->fn_field.is_volatile = 1;
3172               (*pp)++;
3173               break;
3174             case '*':           /* File compiled with g++ version 1 -- no info */
3175             case '?':
3176             case '.':
3177               break;
3178             default:
3179               complaint (&symfile_complaints,
3180                          "const/volatile indicator missing, got '%c'", **pp);
3181               break;
3182             }
3183
3184           switch (*(*pp)++)
3185             {
3186             case '*':
3187               {
3188                 int nbits;
3189                 /* virtual member function, followed by index.
3190                    The sign bit is set to distinguish pointers-to-methods
3191                    from virtual function indicies.  Since the array is
3192                    in words, the quantity must be shifted left by 1
3193                    on 16 bit machine, and by 2 on 32 bit machine, forcing
3194                    the sign bit out, and usable as a valid index into
3195                    the array.  Remove the sign bit here.  */
3196                 new_sublist->fn_field.voffset =
3197                   (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3198                 if (nbits != 0)
3199                   return 0;
3200
3201                 STABS_CONTINUE (pp, objfile);
3202                 if (**pp == ';' || **pp == '\0')
3203                   {
3204                     /* Must be g++ version 1.  */
3205                     new_sublist->fn_field.fcontext = 0;
3206                   }
3207                 else
3208                   {
3209                     /* Figure out from whence this virtual function came.
3210                        It may belong to virtual function table of
3211                        one of its baseclasses.  */
3212                     look_ahead_type = read_type (pp, objfile);
3213                     if (**pp == ':')
3214                       {
3215                         /* g++ version 1 overloaded methods. */
3216                       }
3217                     else
3218                       {
3219                         new_sublist->fn_field.fcontext = look_ahead_type;
3220                         if (**pp != ';')
3221                           {
3222                             return 0;
3223                           }
3224                         else
3225                           {
3226                             ++*pp;
3227                           }
3228                         look_ahead_type = NULL;
3229                       }
3230                   }
3231                 break;
3232               }
3233             case '?':
3234               /* static member function.  */
3235               {
3236                 int slen = strlen (main_fn_name);
3237
3238                 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3239
3240                 /* For static member functions, we can't tell if they
3241                    are stubbed, as they are put out as functions, and not as
3242                    methods.
3243                    GCC v2 emits the fully mangled name if
3244                    dbxout.c:flag_minimal_debug is not set, so we have to
3245                    detect a fully mangled physname here and set is_stub
3246                    accordingly.  Fully mangled physnames in v2 start with
3247                    the member function name, followed by two underscores.
3248                    GCC v3 currently always emits stubbed member functions,
3249                    but with fully mangled physnames, which start with _Z.  */
3250                 if (!(strncmp (new_sublist->fn_field.physname,
3251                                main_fn_name, slen) == 0
3252                       && new_sublist->fn_field.physname[slen] == '_'
3253                       && new_sublist->fn_field.physname[slen + 1] == '_'))
3254                   {
3255                     new_sublist->fn_field.is_stub = 1;
3256                   }
3257                 break;
3258               }
3259
3260             default:
3261               /* error */
3262               complaint (&symfile_complaints,
3263                          "member function type missing, got '%c'", (*pp)[-1]);
3264               /* Fall through into normal member function.  */
3265
3266             case '.':
3267               /* normal member function.  */
3268               new_sublist->fn_field.voffset = 0;
3269               new_sublist->fn_field.fcontext = 0;
3270               break;
3271             }
3272
3273           new_sublist->next = sublist;
3274           sublist = new_sublist;
3275           length++;
3276           STABS_CONTINUE (pp, objfile);
3277         }
3278       while (**pp != ';' && **pp != '\0');
3279
3280       (*pp)++;
3281       STABS_CONTINUE (pp, objfile);
3282
3283       /* Skip GCC 3.X member functions which are duplicates of the callable
3284          constructor/destructor.  */
3285       if (strcmp (main_fn_name, "__base_ctor") == 0
3286           || strcmp (main_fn_name, "__base_dtor") == 0
3287           || strcmp (main_fn_name, "__deleting_dtor") == 0)
3288         {
3289           xfree (main_fn_name);
3290         }
3291       else
3292         {
3293           int has_stub = 0;
3294           int has_destructor = 0, has_other = 0;
3295           int is_v3 = 0;
3296           struct next_fnfield *tmp_sublist;
3297
3298           /* Various versions of GCC emit various mostly-useless
3299              strings in the name field for special member functions.
3300
3301              For stub methods, we need to defer correcting the name
3302              until we are ready to unstub the method, because the current
3303              name string is used by gdb_mangle_name.  The only stub methods
3304              of concern here are GNU v2 operators; other methods have their
3305              names correct (see caveat below).
3306
3307              For non-stub methods, in GNU v3, we have a complete physname.
3308              Therefore we can safely correct the name now.  This primarily
3309              affects constructors and destructors, whose name will be
3310              __comp_ctor or __comp_dtor instead of Foo or ~Foo.  Cast
3311              operators will also have incorrect names; for instance,
3312              "operator int" will be named "operator i" (i.e. the type is
3313              mangled).
3314
3315              For non-stub methods in GNU v2, we have no easy way to
3316              know if we have a complete physname or not.  For most
3317              methods the result depends on the platform (if CPLUS_MARKER
3318              can be `$' or `.', it will use minimal debug information, or
3319              otherwise the full physname will be included).
3320
3321              Rather than dealing with this, we take a different approach.
3322              For v3 mangled names, we can use the full physname; for v2,
3323              we use cplus_demangle_opname (which is actually v2 specific),
3324              because the only interesting names are all operators - once again
3325              barring the caveat below.  Skip this process if any method in the
3326              group is a stub, to prevent our fouling up the workings of
3327              gdb_mangle_name.
3328
3329              The caveat: GCC 2.95.x (and earlier?) put constructors and
3330              destructors in the same method group.  We need to split this
3331              into two groups, because they should have different names.
3332              So for each method group we check whether it contains both
3333              routines whose physname appears to be a destructor (the physnames
3334              for and destructors are always provided, due to quirks in v2
3335              mangling) and routines whose physname does not appear to be a
3336              destructor.  If so then we break up the list into two halves.
3337              Even if the constructors and destructors aren't in the same group
3338              the destructor will still lack the leading tilde, so that also
3339              needs to be fixed.
3340
3341              So, to summarize what we expect and handle here:
3342
3343                 Given         Given          Real         Real       Action
3344              method name     physname      physname   method name
3345
3346              __opi            [none]     __opi__3Foo  operator int    opname
3347                                                                    [now or later]
3348              Foo              _._3Foo       _._3Foo      ~Foo       separate and
3349                                                                        rename
3350              operator i     _ZN3FoocviEv _ZN3FoocviEv operator int    demangle
3351              __comp_ctor  _ZN3FooC1ERKS_ _ZN3FooC1ERKS_   Foo         demangle
3352           */
3353
3354           tmp_sublist = sublist;
3355           while (tmp_sublist != NULL)
3356             {
3357               if (tmp_sublist->fn_field.is_stub)
3358                 has_stub = 1;
3359               if (tmp_sublist->fn_field.physname[0] == '_'
3360                   && tmp_sublist->fn_field.physname[1] == 'Z')
3361                 is_v3 = 1;
3362
3363               if (is_destructor_name (tmp_sublist->fn_field.physname))
3364                 has_destructor++;
3365               else
3366                 has_other++;
3367
3368               tmp_sublist = tmp_sublist->next;
3369             }
3370
3371           if (has_destructor && has_other)
3372             {
3373               struct next_fnfieldlist *destr_fnlist;
3374               struct next_fnfield *last_sublist;
3375
3376               /* Create a new fn_fieldlist for the destructors.  */
3377
3378               destr_fnlist = (struct next_fnfieldlist *)
3379                 xmalloc (sizeof (struct next_fnfieldlist));
3380               make_cleanup (xfree, destr_fnlist);
3381               memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
3382               destr_fnlist->fn_fieldlist.name
3383                 = obconcat (&objfile->type_obstack, "", "~",
3384                             new_fnlist->fn_fieldlist.name);
3385
3386               destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3387                 obstack_alloc (&objfile->type_obstack,
3388                                sizeof (struct fn_field) * has_destructor);
3389               memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
3390                   sizeof (struct fn_field) * has_destructor);
3391               tmp_sublist = sublist;
3392               last_sublist = NULL;
3393               i = 0;
3394               while (tmp_sublist != NULL)
3395                 {
3396                   if (!is_destructor_name (tmp_sublist->fn_field.physname))
3397                     {
3398                       tmp_sublist = tmp_sublist->next;
3399                       continue;
3400                     }
3401                   
3402                   destr_fnlist->fn_fieldlist.fn_fields[i++]
3403                     = tmp_sublist->fn_field;
3404                   if (last_sublist)
3405                     last_sublist->next = tmp_sublist->next;
3406                   else
3407                     sublist = tmp_sublist->next;
3408                   last_sublist = tmp_sublist;
3409                   tmp_sublist = tmp_sublist->next;
3410                 }
3411
3412               destr_fnlist->fn_fieldlist.length = has_destructor;
3413               destr_fnlist->next = fip->fnlist;
3414               fip->fnlist = destr_fnlist;
3415               nfn_fields++;
3416               total_length += has_destructor;
3417               length -= has_destructor;
3418             }
3419           else if (is_v3)
3420             {
3421               /* v3 mangling prevents the use of abbreviated physnames,
3422                  so we can do this here.  There are stubbed methods in v3
3423                  only:
3424                  - in -gstabs instead of -gstabs+
3425                  - or for static methods, which are output as a function type
3426                    instead of a method type.  */
3427
3428               update_method_name_from_physname (&new_fnlist->fn_fieldlist.name,
3429                                                 sublist->fn_field.physname);
3430             }
3431           else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
3432             {
3433               new_fnlist->fn_fieldlist.name = concat ("~", main_fn_name, NULL);
3434               xfree (main_fn_name);
3435             }
3436           else if (!has_stub)
3437             {
3438               char dem_opname[256];
3439               int ret;
3440               ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3441                                               dem_opname, DMGL_ANSI);
3442               if (!ret)
3443                 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3444                                              dem_opname, 0);
3445               if (ret)
3446                 new_fnlist->fn_fieldlist.name
3447                   = obsavestring (dem_opname, strlen (dem_opname),
3448                                   &objfile->type_obstack);
3449             }
3450
3451           new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3452             obstack_alloc (&objfile->type_obstack,
3453                            sizeof (struct fn_field) * length);
3454           memset (new_fnlist->fn_fieldlist.fn_fields, 0,
3455                   sizeof (struct fn_field) * length);
3456           for (i = length; (i--, sublist); sublist = sublist->next)
3457             {
3458               new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
3459             }
3460
3461           new_fnlist->fn_fieldlist.length = length;
3462           new_fnlist->next = fip->fnlist;
3463           fip->fnlist = new_fnlist;
3464           nfn_fields++;
3465           total_length += length;
3466         }
3467     }
3468
3469   if (nfn_fields)
3470     {
3471       ALLOCATE_CPLUS_STRUCT_TYPE (type);
3472       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3473         TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3474       memset (TYPE_FN_FIELDLISTS (type), 0,
3475               sizeof (struct fn_fieldlist) * nfn_fields);
3476       TYPE_NFN_FIELDS (type) = nfn_fields;
3477       TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3478     }
3479
3480   return 1;
3481 }
3482
3483 /* Special GNU C++ name.
3484
3485    Returns 1 for success, 0 for failure.  "failure" means that we can't
3486    keep parsing and it's time for error_type().  */
3487
3488 static int
3489 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3490                  struct objfile *objfile)
3491 {
3492   register char *p;
3493   char *name;
3494   char cpp_abbrev;
3495   struct type *context;
3496
3497   p = *pp;
3498   if (*++p == 'v')
3499     {
3500       name = NULL;
3501       cpp_abbrev = *++p;
3502
3503       *pp = p + 1;
3504
3505       /* At this point, *pp points to something like "22:23=*22...",
3506          where the type number before the ':' is the "context" and
3507          everything after is a regular type definition.  Lookup the
3508          type, find it's name, and construct the field name. */
3509
3510       context = read_type (pp, objfile);
3511
3512       switch (cpp_abbrev)
3513         {
3514         case 'f':               /* $vf -- a virtual function table pointer */
3515           name = type_name_no_tag (context);
3516           if (name == NULL)
3517           {
3518                   name = "";
3519           }
3520           fip->list->field.name =
3521             obconcat (&objfile->type_obstack, vptr_name, name, "");
3522           break;
3523
3524         case 'b':               /* $vb -- a virtual bsomethingorother */
3525           name = type_name_no_tag (context);
3526           if (name == NULL)
3527             {
3528               complaint (&symfile_complaints,
3529                          "C++ abbreviated type name unknown at symtab pos %d",
3530                          symnum);
3531               name = "FOO";
3532             }
3533           fip->list->field.name =
3534             obconcat (&objfile->type_obstack, vb_name, name, "");
3535           break;
3536
3537         default:
3538           invalid_cpp_abbrev_complaint (*pp);
3539           fip->list->field.name =
3540             obconcat (&objfile->type_obstack,
3541                       "INVALID_CPLUSPLUS_ABBREV", "", "");
3542           break;
3543         }
3544
3545       /* At this point, *pp points to the ':'.  Skip it and read the
3546          field type. */
3547
3548       p = ++(*pp);
3549       if (p[-1] != ':')
3550         {
3551           invalid_cpp_abbrev_complaint (*pp);
3552           return 0;
3553         }
3554       fip->list->field.type = read_type (pp, objfile);
3555       if (**pp == ',')
3556         (*pp)++;                /* Skip the comma.  */
3557       else
3558         return 0;
3559
3560       {
3561         int nbits;
3562         FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3563         if (nbits != 0)
3564           return 0;
3565       }
3566       /* This field is unpacked.  */
3567       FIELD_BITSIZE (fip->list->field) = 0;
3568       fip->list->visibility = VISIBILITY_PRIVATE;
3569     }
3570   else
3571     {
3572       invalid_cpp_abbrev_complaint (*pp);
3573       /* We have no idea what syntax an unrecognized abbrev would have, so
3574          better return 0.  If we returned 1, we would need to at least advance
3575          *pp to avoid an infinite loop.  */
3576       return 0;
3577     }
3578   return 1;
3579 }
3580
3581 static void
3582 read_one_struct_field (struct field_info *fip, char **pp, char *p,
3583                        struct type *type, struct objfile *objfile)
3584 {
3585   /* The following is code to work around cfront generated stabs.
3586      The stabs contains full mangled name for each field.
3587      We try to demangle the name and extract the field name out of it.
3588    */
3589   if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3590     {
3591       char save_p;
3592       char *dem, *dem_p;
3593       save_p = *p;
3594       *p = '\0';
3595       dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3596       if (dem != NULL)
3597         {
3598           dem_p = strrchr (dem, ':');
3599           if (dem_p != 0 && *(dem_p - 1) == ':')
3600             dem_p++;
3601           FIELD_NAME (fip->list->field) =
3602             obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3603         }
3604       else
3605         {
3606           FIELD_NAME (fip->list->field) =
3607             obsavestring (*pp, p - *pp, &objfile->type_obstack);
3608         }
3609       *p = save_p;
3610     }
3611   /* end of code for cfront work around */
3612
3613   else
3614     fip->list->field.name =
3615       obsavestring (*pp, p - *pp, &objfile->type_obstack);
3616   *pp = p + 1;
3617
3618   /* This means we have a visibility for a field coming. */
3619   if (**pp == '/')
3620     {
3621       (*pp)++;
3622       fip->list->visibility = *(*pp)++;
3623     }
3624   else
3625     {
3626       /* normal dbx-style format, no explicit visibility */
3627       fip->list->visibility = VISIBILITY_PUBLIC;
3628     }
3629
3630   fip->list->field.type = read_type (pp, objfile);
3631   if (**pp == ':')
3632     {
3633       p = ++(*pp);
3634 #if 0
3635       /* Possible future hook for nested types. */
3636       if (**pp == '!')
3637         {
3638           fip->list->field.bitpos = (long) -2;  /* nested type */
3639           p = ++(*pp);
3640         }
3641       else
3642         ...;
3643 #endif
3644       while (*p != ';')
3645         {
3646           p++;
3647         }
3648       /* Static class member.  */
3649       SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3650       *pp = p + 1;
3651       return;
3652     }
3653   else if (**pp != ',')
3654     {
3655       /* Bad structure-type format.  */
3656       stabs_general_complaint ("bad structure-type format");
3657       return;
3658     }
3659
3660   (*pp)++;                      /* Skip the comma.  */
3661
3662   {
3663     int nbits;
3664     FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3665     if (nbits != 0)
3666       {
3667         stabs_general_complaint ("bad structure-type format");
3668         return;
3669       }
3670     FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3671     if (nbits != 0)
3672       {
3673         stabs_general_complaint ("bad structure-type format");
3674         return;
3675       }
3676   }
3677
3678   if (FIELD_BITPOS (fip->list->field) == 0
3679       && FIELD_BITSIZE (fip->list->field) == 0)
3680     {
3681       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3682          it is a field which has been optimized out.  The correct stab for
3683          this case is to use VISIBILITY_IGNORE, but that is a recent
3684          invention.  (2) It is a 0-size array.  For example
3685          union { int num; char str[0]; } foo.  Printing "<no value>" for
3686          str in "p foo" is OK, since foo.str (and thus foo.str[3])
3687          will continue to work, and a 0-size array as a whole doesn't
3688          have any contents to print.
3689
3690          I suspect this probably could also happen with gcc -gstabs (not
3691          -gstabs+) for static fields, and perhaps other C++ extensions.
3692          Hopefully few people use -gstabs with gdb, since it is intended
3693          for dbx compatibility.  */
3694
3695       /* Ignore this field.  */
3696       fip->list->visibility = VISIBILITY_IGNORE;
3697     }
3698   else
3699     {
3700       /* Detect an unpacked field and mark it as such.
3701          dbx gives a bit size for all fields.
3702          Note that forward refs cannot be packed,
3703          and treat enums as if they had the width of ints.  */
3704
3705       struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3706
3707       if (TYPE_CODE (field_type) != TYPE_CODE_INT
3708           && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3709           && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3710           && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3711         {
3712           FIELD_BITSIZE (fip->list->field) = 0;
3713         }
3714       if ((FIELD_BITSIZE (fip->list->field)
3715            == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3716            || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
3717                && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3718           )
3719           &&
3720           FIELD_BITPOS (fip->list->field) % 8 == 0)
3721         {
3722           FIELD_BITSIZE (fip->list->field) = 0;
3723         }
3724     }
3725 }
3726
3727
3728 /* Read struct or class data fields.  They have the form:
3729
3730    NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3731
3732    At the end, we see a semicolon instead of a field.
3733
3734    In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3735    a static field.
3736
3737    The optional VISIBILITY is one of:
3738
3739    '/0' (VISIBILITY_PRIVATE)
3740    '/1' (VISIBILITY_PROTECTED)
3741    '/2' (VISIBILITY_PUBLIC)
3742    '/9' (VISIBILITY_IGNORE)
3743
3744    or nothing, for C style fields with public visibility.
3745
3746    Returns 1 for success, 0 for failure.  */
3747
3748 static int
3749 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3750                     struct objfile *objfile)
3751 {
3752   register char *p;
3753   struct nextfield *new;
3754
3755   /* We better set p right now, in case there are no fields at all...    */
3756
3757   p = *pp;
3758
3759   /* Read each data member type until we find the terminating ';' at the end of
3760      the data member list, or break for some other reason such as finding the
3761      start of the member function list. */
3762   /* Stab string for structure/union does not end with two ';' in
3763      SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3764
3765   while (**pp != ';' && **pp != '\0')
3766     {
3767       STABS_CONTINUE (pp, objfile);
3768       /* Get space to record the next field's data.  */
3769       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3770       make_cleanup (xfree, new);
3771       memset (new, 0, sizeof (struct nextfield));
3772       new->next = fip->list;
3773       fip->list = new;
3774
3775       /* Get the field name.  */
3776       p = *pp;
3777
3778       /* If is starts with CPLUS_MARKER it is a special abbreviation,
3779          unless the CPLUS_MARKER is followed by an underscore, in
3780          which case it is just the name of an anonymous type, which we
3781          should handle like any other type name.  */
3782
3783       if (is_cplus_marker (p[0]) && p[1] != '_')
3784         {
3785           if (!read_cpp_abbrev (fip, pp, type, objfile))
3786             return 0;
3787           continue;
3788         }
3789
3790       /* Look for the ':' that separates the field name from the field
3791          values.  Data members are delimited by a single ':', while member
3792          functions are delimited by a pair of ':'s.  When we hit the member
3793          functions (if any), terminate scan loop and return. */
3794
3795       while (*p != ':' && *p != '\0')
3796         {
3797           p++;
3798         }
3799       if (*p == '\0')
3800         return 0;
3801
3802       /* Check to see if we have hit the member functions yet.  */
3803       if (p[1] == ':')
3804         {
3805           break;
3806         }
3807       read_one_struct_field (fip, pp, p, type, objfile);
3808     }
3809   if (p[0] == ':' && p[1] == ':')
3810     {
3811       /* (the deleted) chill the list of fields: the last entry (at
3812          the head) is a partially constructed entry which we now
3813          scrub. */
3814       fip->list = fip->list->next;
3815     }
3816   return 1;
3817 }
3818 /* *INDENT-OFF* */
3819 /* The stabs for C++ derived classes contain baseclass information which
3820    is marked by a '!' character after the total size.  This function is
3821    called when we encounter the baseclass marker, and slurps up all the
3822    baseclass information.
3823
3824    Immediately following the '!' marker is the number of base classes that
3825    the class is derived from, followed by information for each base class.
3826    For each base class, there are two visibility specifiers, a bit offset
3827    to the base class information within the derived class, a reference to
3828    the type for the base class, and a terminating semicolon.
3829
3830    A typical example, with two base classes, would be "!2,020,19;0264,21;".
3831                                                        ^^ ^ ^ ^  ^ ^  ^
3832         Baseclass information marker __________________|| | | |  | |  |
3833         Number of baseclasses __________________________| | | |  | |  |
3834         Visibility specifiers (2) ________________________| | |  | |  |
3835         Offset in bits from start of class _________________| |  | |  |
3836         Type number for base class ___________________________|  | |  |
3837         Visibility specifiers (2) _______________________________| |  |
3838         Offset in bits from start of class ________________________|  |
3839         Type number of base class ____________________________________|
3840
3841   Return 1 for success, 0 for (error-type-inducing) failure.  */
3842 /* *INDENT-ON* */
3843
3844
3845
3846 static int
3847 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3848                   struct objfile *objfile)
3849 {
3850   int i;
3851   struct nextfield *new;
3852
3853   if (**pp != '!')
3854     {
3855       return 1;
3856     }
3857   else
3858     {
3859       /* Skip the '!' baseclass information marker. */
3860       (*pp)++;
3861     }
3862
3863   ALLOCATE_CPLUS_STRUCT_TYPE (type);
3864   {
3865     int nbits;
3866     TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3867     if (nbits != 0)
3868       return 0;
3869   }
3870
3871 #if 0
3872   /* Some stupid compilers have trouble with the following, so break
3873      it up into simpler expressions.  */
3874   TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3875     TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3876 #else
3877   {
3878     int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3879     char *pointer;
3880
3881     pointer = (char *) TYPE_ALLOC (type, num_bytes);
3882     TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3883   }
3884 #endif /* 0 */
3885
3886   B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3887
3888   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3889     {
3890       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3891       make_cleanup (xfree, new);
3892       memset (new, 0, sizeof (struct nextfield));
3893       new->next = fip->list;
3894       fip->list = new;
3895       FIELD_BITSIZE (new->field) = 0;   /* this should be an unpacked field! */
3896
3897       STABS_CONTINUE (pp, objfile);
3898       switch (**pp)
3899         {
3900         case '0':
3901           /* Nothing to do. */
3902           break;
3903         case '1':
3904           SET_TYPE_FIELD_VIRTUAL (type, i);
3905           break;
3906         default:
3907           /* Unknown character.  Complain and treat it as non-virtual.  */
3908           {
3909             complaint (&symfile_complaints,
3910                        "Unknown virtual character `%c' for baseclass", **pp);
3911           }
3912         }
3913       ++(*pp);
3914
3915       new->visibility = *(*pp)++;
3916       switch (new->visibility)
3917         {
3918         case VISIBILITY_PRIVATE:
3919         case VISIBILITY_PROTECTED:
3920         case VISIBILITY_PUBLIC:
3921           break;
3922         default:
3923           /* Bad visibility format.  Complain and treat it as
3924              public.  */
3925           {
3926             complaint (&symfile_complaints,
3927                        "Unknown visibility `%c' for baseclass",
3928                        new->visibility);
3929             new->visibility = VISIBILITY_PUBLIC;
3930           }
3931         }
3932
3933       {
3934         int nbits;
3935
3936         /* The remaining value is the bit offset of the portion of the object
3937            corresponding to this baseclass.  Always zero in the absence of
3938            multiple inheritance.  */
3939
3940         FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3941         if (nbits != 0)
3942           return 0;
3943       }
3944
3945       /* The last piece of baseclass information is the type of the
3946          base class.  Read it, and remember it's type name as this
3947          field's name. */
3948
3949       new->field.type = read_type (pp, objfile);
3950       new->field.name = type_name_no_tag (new->field.type);
3951
3952       /* skip trailing ';' and bump count of number of fields seen */
3953       if (**pp == ';')
3954         (*pp)++;
3955       else
3956         return 0;
3957     }
3958   return 1;
3959 }
3960
3961 /* The tail end of stabs for C++ classes that contain a virtual function
3962    pointer contains a tilde, a %, and a type number.
3963    The type number refers to the base class (possibly this class itself) which
3964    contains the vtable pointer for the current class.
3965
3966    This function is called when we have parsed all the method declarations,
3967    so we can look for the vptr base class info.  */
3968
3969 static int
3970 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
3971                    struct objfile *objfile)
3972 {
3973   register char *p;
3974
3975   STABS_CONTINUE (pp, objfile);
3976
3977   /* If we are positioned at a ';', then skip it. */
3978   if (**pp == ';')
3979     {
3980       (*pp)++;
3981     }
3982
3983   if (**pp == '~')
3984     {
3985       (*pp)++;
3986
3987       if (**pp == '=' || **pp == '+' || **pp == '-')
3988         {
3989           /* Obsolete flags that used to indicate the presence
3990              of constructors and/or destructors. */
3991           (*pp)++;
3992         }
3993
3994       /* Read either a '%' or the final ';'.  */
3995       if (*(*pp)++ == '%')
3996         {
3997           /* The next number is the type number of the base class
3998              (possibly our own class) which supplies the vtable for
3999              this class.  Parse it out, and search that class to find
4000              its vtable pointer, and install those into TYPE_VPTR_BASETYPE
4001              and TYPE_VPTR_FIELDNO.  */
4002
4003           struct type *t;
4004           int i;
4005
4006           t = read_type (pp, objfile);
4007           p = (*pp)++;
4008           while (*p != '\0' && *p != ';')
4009             {
4010               p++;
4011             }
4012           if (*p == '\0')
4013             {
4014               /* Premature end of symbol.  */
4015               return 0;
4016             }
4017
4018           TYPE_VPTR_BASETYPE (type) = t;
4019           if (type == t)        /* Our own class provides vtbl ptr */
4020             {
4021               for (i = TYPE_NFIELDS (t) - 1;
4022                    i >= TYPE_N_BASECLASSES (t);
4023                    --i)
4024                 {
4025                   char *name = TYPE_FIELD_NAME (t, i);
4026                   if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
4027                       && is_cplus_marker (name[sizeof (vptr_name) - 2]))
4028                     {
4029                       TYPE_VPTR_FIELDNO (type) = i;
4030                       goto gotit;
4031                     }
4032                 }
4033               /* Virtual function table field not found.  */
4034               complaint (&symfile_complaints,
4035                          "virtual function table pointer not found when defining class `%s'",
4036                          TYPE_NAME (type));
4037               return 0;
4038             }
4039           else
4040             {
4041               TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
4042             }
4043
4044         gotit:
4045           *pp = p + 1;
4046         }
4047     }
4048   return 1;
4049 }
4050
4051 static int
4052 attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
4053 {
4054   register int n;
4055
4056   for (n = TYPE_NFN_FIELDS (type);
4057        fip->fnlist != NULL;
4058        fip->fnlist = fip->fnlist->next)
4059     {
4060       --n;                      /* Circumvent Sun3 compiler bug */
4061       TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
4062     }
4063   return 1;
4064 }
4065
4066 /* read cfront class static data.
4067    pp points to string starting with the list of static data
4068    eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
4069    ^^^^^^^^
4070
4071    A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
4072    ^
4073  */
4074
4075 static int
4076 read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
4077                            struct objfile *objfile)
4078 {
4079   struct nextfield *new;
4080   struct type *stype;
4081   char *sname;
4082   struct symbol *ref_static = 0;
4083
4084   if (**pp == ';')              /* no static data; return */
4085     {
4086       ++(*pp);
4087       return 1;
4088     }
4089
4090   /* Process each field in the list until we find the terminating ";" */
4091
4092   /* eg: p = "as__1A ;;;" */
4093   STABS_CONTINUE (pp, objfile); /* handle \\ */
4094   while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
4095     {
4096       ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0);       /*demangled_name */
4097       if (!ref_static)
4098         {
4099           complaint (&symfile_complaints,
4100                      "Unable to find symbol for static data field %s", sname);
4101           continue;
4102         }
4103       stype = SYMBOL_TYPE (ref_static);
4104
4105       /* allocate a new fip */
4106       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4107       make_cleanup (xfree, new);
4108       memset (new, 0, sizeof (struct nextfield));
4109       new->next = fip->list;
4110       fip->list = new;
4111
4112       /* set visibility */
4113       /* FIXME! no way to tell visibility from stabs??? */
4114       new->visibility = VISIBILITY_PUBLIC;
4115
4116       /* set field info into fip */
4117       fip->list->field.type = stype;
4118
4119       /* set bitpos & bitsize */
4120       SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
4121
4122       /* set name field */
4123       /* The following is code to work around cfront generated stabs.
4124          The stabs contains full mangled name for each field.
4125          We try to demangle the name and extract the field name out of it.
4126        */
4127       if (ARM_DEMANGLING)
4128         {
4129           char *dem, *dem_p;
4130           dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
4131           if (dem != NULL)
4132             {
4133               dem_p = strrchr (dem, ':');
4134               if (dem_p != 0 && *(dem_p - 1) == ':')
4135                 dem_p++;
4136               fip->list->field.name =
4137                 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
4138             }
4139           else
4140             {
4141               fip->list->field.name =
4142                 obsavestring (sname, strlen (sname), &objfile->type_obstack);
4143             }
4144         }                       /* end of code for cfront work around */
4145     }                           /* loop again for next static field */
4146   return 1;
4147 }
4148
4149 /* Copy structure fields to fip so attach_fields_to_type will work.
4150    type has already been created with the initial instance data fields.
4151    Now we want to be able to add the other members to the class,
4152    so we want to add them back to the fip and reattach them again
4153    once we have collected all the class members. */
4154
4155 static int
4156 copy_cfront_struct_fields (struct field_info *fip, struct type *type,
4157                            struct objfile *objfile)
4158 {
4159   int nfields = TYPE_NFIELDS (type);
4160   int i;
4161   struct nextfield *new;
4162
4163   /* Copy the fields into the list of fips and reset the types 
4164      to remove the old fields */
4165
4166   for (i = 0; i < nfields; i++)
4167     {
4168       /* allocate a new fip */
4169       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4170       make_cleanup (xfree, new);
4171       memset (new, 0, sizeof (struct nextfield));
4172       new->next = fip->list;
4173       fip->list = new;
4174
4175       /* copy field info into fip */
4176       new->field = TYPE_FIELD (type, i);
4177       /* set visibility */
4178       if (TYPE_FIELD_PROTECTED (type, i))
4179         new->visibility = VISIBILITY_PROTECTED;
4180       else if (TYPE_FIELD_PRIVATE (type, i))
4181         new->visibility = VISIBILITY_PRIVATE;
4182       else
4183         new->visibility = VISIBILITY_PUBLIC;
4184     }
4185   /* Now delete the fields from the type since we will be 
4186      allocing new space once we get the rest of the fields 
4187      in attach_fields_to_type.
4188      The pointer TYPE_FIELDS(type) is left dangling but should 
4189      be freed later by objstack_free */
4190   TYPE_FIELDS (type) = 0;
4191   TYPE_NFIELDS (type) = 0;
4192
4193   return 1;
4194 }
4195
4196 /* Create the vector of fields, and record how big it is.
4197    We need this info to record proper virtual function table information
4198    for this class's virtual functions.  */
4199
4200 static int
4201 attach_fields_to_type (struct field_info *fip, register struct type *type,
4202                        struct objfile *objfile)
4203 {
4204   register int nfields = 0;
4205   register int non_public_fields = 0;
4206   register struct nextfield *scan;
4207
4208   /* Count up the number of fields that we have, as well as taking note of
4209      whether or not there are any non-public fields, which requires us to
4210      allocate and build the private_field_bits and protected_field_bits
4211      bitfields. */
4212
4213   for (scan = fip->list; scan != NULL; scan = scan->next)
4214     {
4215       nfields++;
4216       if (scan->visibility != VISIBILITY_PUBLIC)
4217         {
4218           non_public_fields++;
4219         }
4220     }
4221
4222   /* Now we know how many fields there are, and whether or not there are any
4223      non-public fields.  Record the field count, allocate space for the
4224      array of fields, and create blank visibility bitfields if necessary. */
4225
4226   TYPE_NFIELDS (type) = nfields;
4227   TYPE_FIELDS (type) = (struct field *)
4228     TYPE_ALLOC (type, sizeof (struct field) * nfields);
4229   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4230
4231   if (non_public_fields)
4232     {
4233       ALLOCATE_CPLUS_STRUCT_TYPE (type);
4234
4235       TYPE_FIELD_PRIVATE_BITS (type) =
4236         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4237       B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4238
4239       TYPE_FIELD_PROTECTED_BITS (type) =
4240         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4241       B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4242
4243       TYPE_FIELD_IGNORE_BITS (type) =
4244         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4245       B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4246     }
4247
4248   /* Copy the saved-up fields into the field vector.  Start from the head
4249      of the list, adding to the tail of the field array, so that they end
4250      up in the same order in the array in which they were added to the list. */
4251
4252   while (nfields-- > 0)
4253     {
4254       TYPE_FIELD (type, nfields) = fip->list->field;
4255       switch (fip->list->visibility)
4256         {
4257         case VISIBILITY_PRIVATE:
4258           SET_TYPE_FIELD_PRIVATE (type, nfields);
4259           break;
4260
4261         case VISIBILITY_PROTECTED:
4262           SET_TYPE_FIELD_PROTECTED (type, nfields);
4263           break;
4264
4265         case VISIBILITY_IGNORE:
4266           SET_TYPE_FIELD_IGNORE (type, nfields);
4267           break;
4268
4269         case VISIBILITY_PUBLIC:
4270           break;
4271
4272         default:
4273           /* Unknown visibility.  Complain and treat it as public.  */
4274           {
4275             complaint (&symfile_complaints, "Unknown visibility `%c' for field",
4276                        fip->list->visibility);
4277           }
4278           break;
4279         }
4280       fip->list = fip->list->next;
4281     }
4282   return 1;
4283 }
4284
4285
4286 /* Complain that the compiler has emitted more than one definition for the
4287    structure type TYPE.  */
4288 static void 
4289 complain_about_struct_wipeout (struct type *type)
4290 {
4291   char *name = "";
4292   char *kind = "";
4293
4294   if (TYPE_TAG_NAME (type))
4295     {
4296       name = TYPE_TAG_NAME (type);
4297       switch (TYPE_CODE (type))
4298         {
4299         case TYPE_CODE_STRUCT: kind = "struct "; break;
4300         case TYPE_CODE_UNION:  kind = "union ";  break;
4301         case TYPE_CODE_ENUM:   kind = "enum ";   break;
4302         default: kind = "";
4303         }
4304     }
4305   else if (TYPE_NAME (type))
4306     {
4307       name = TYPE_NAME (type);
4308       kind = "";
4309     }
4310   else
4311     {
4312       name = "<unknown>";
4313       kind = "";
4314     }
4315
4316   complaint (&symfile_complaints,
4317              "struct/union type gets multiply defined: %s%s", kind, name);
4318 }
4319
4320
4321 /* Read the description of a structure (or union type) and return an object
4322    describing the type.
4323
4324    PP points to a character pointer that points to the next unconsumed token
4325    in the the stabs string.  For example, given stabs "A:T4=s4a:1,0,32;;",
4326    *PP will point to "4a:1,0,32;;".
4327
4328    TYPE points to an incomplete type that needs to be filled in.
4329
4330    OBJFILE points to the current objfile from which the stabs information is
4331    being read.  (Note that it is redundant in that TYPE also contains a pointer
4332    to this same objfile, so it might be a good idea to eliminate it.  FIXME). 
4333  */
4334
4335 static struct type *
4336 read_struct_type (char **pp, struct type *type, enum type_code type_code,
4337                   struct objfile *objfile)
4338 {
4339   struct cleanup *back_to;
4340   struct field_info fi;
4341
4342   fi.list = NULL;
4343   fi.fnlist = NULL;
4344
4345   /* When describing struct/union/class types in stabs, G++ always drops
4346      all qualifications from the name.  So if you've got:
4347        struct A { ... struct B { ... }; ... };
4348      then G++ will emit stabs for `struct A::B' that call it simply
4349      `struct B'.  Obviously, if you've got a real top-level definition for
4350      `struct B', or other nested definitions, this is going to cause
4351      problems.
4352
4353      Obviously, GDB can't fix this by itself, but it can at least avoid
4354      scribbling on existing structure type objects when new definitions
4355      appear.  */
4356   if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
4357          || TYPE_STUB (type)))
4358     {
4359       complain_about_struct_wipeout (type);
4360
4361       /* It's probably best to return the type unchanged.  */
4362       return type;
4363     }
4364
4365   back_to = make_cleanup (null_cleanup, 0);
4366
4367   INIT_CPLUS_SPECIFIC (type);
4368   TYPE_CODE (type) = type_code;
4369   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4370
4371   /* First comes the total size in bytes.  */
4372
4373   {
4374     int nbits;
4375     TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4376     if (nbits != 0)
4377       return error_type (pp, objfile);
4378   }
4379
4380   /* Now read the baseclasses, if any, read the regular C struct or C++
4381      class member fields, attach the fields to the type, read the C++
4382      member functions, attach them to the type, and then read any tilde
4383      field (baseclass specifier for the class holding the main vtable). */
4384
4385   if (!read_baseclasses (&fi, pp, type, objfile)
4386       || !read_struct_fields (&fi, pp, type, objfile)
4387       || !attach_fields_to_type (&fi, type, objfile)
4388       || !read_member_functions (&fi, pp, type, objfile)
4389       || !attach_fn_fields_to_type (&fi, type)
4390       || !read_tilde_fields (&fi, pp, type, objfile))
4391     {
4392       type = error_type (pp, objfile);
4393     }
4394
4395   do_cleanups (back_to);
4396   return (type);
4397 }
4398
4399 /* Read a definition of an array type,
4400    and create and return a suitable type object.
4401    Also creates a range type which represents the bounds of that
4402    array.  */
4403
4404 static struct type *
4405 read_array_type (register char **pp, register struct type *type,
4406                  struct objfile *objfile)
4407 {
4408   struct type *index_type, *element_type, *range_type;
4409   int lower, upper;
4410   int adjustable = 0;
4411   int nbits;
4412
4413   /* Format of an array type:
4414      "ar<index type>;lower;upper;<array_contents_type>".
4415      OS9000: "arlower,upper;<array_contents_type>".
4416
4417      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4418      for these, produce a type like float[][].  */
4419
4420     {
4421       index_type = read_type (pp, objfile);
4422       if (**pp != ';')
4423         /* Improper format of array type decl.  */
4424         return error_type (pp, objfile);
4425       ++*pp;
4426     }
4427
4428   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4429     {
4430       (*pp)++;
4431       adjustable = 1;
4432     }
4433   lower = read_huge_number (pp, ';', &nbits);
4434
4435   if (nbits != 0)
4436     return error_type (pp, objfile);
4437
4438   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4439     {
4440       (*pp)++;
4441       adjustable = 1;
4442     }
4443   upper = read_huge_number (pp, ';', &nbits);
4444   if (nbits != 0)
4445     return error_type (pp, objfile);
4446
4447   element_type = read_type (pp, objfile);
4448
4449   if (adjustable)
4450     {
4451       lower = 0;
4452       upper = -1;
4453     }
4454
4455   range_type =
4456     create_range_type ((struct type *) NULL, index_type, lower, upper);
4457   type = create_array_type (type, element_type, range_type);
4458
4459   return type;
4460 }
4461
4462
4463 /* Read a definition of an enumeration type,
4464    and create and return a suitable type object.
4465    Also defines the symbols that represent the values of the type.  */
4466
4467 static struct type *
4468 read_enum_type (register char **pp, register struct type *type,
4469                 struct objfile *objfile)
4470 {
4471   register char *p;
4472   char *name;
4473   register long n;
4474   register struct symbol *sym;
4475   int nsyms = 0;
4476   struct pending **symlist;
4477   struct pending *osyms, *syms;
4478   int o_nsyms;
4479   int nbits;
4480   int unsigned_enum = 1;
4481
4482 #if 0
4483   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
4484      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
4485      to do?  For now, force all enum values to file scope.  */
4486   if (within_function)
4487     symlist = &local_symbols;
4488   else
4489 #endif
4490     symlist = &file_symbols;
4491   osyms = *symlist;
4492   o_nsyms = osyms ? osyms->nsyms : 0;
4493
4494   /* The aix4 compiler emits an extra field before the enum members;
4495      my guess is it's a type of some sort.  Just ignore it.  */
4496   if (**pp == '-')
4497     {
4498       /* Skip over the type.  */
4499       while (**pp != ':')
4500         (*pp)++;
4501
4502       /* Skip over the colon.  */
4503       (*pp)++;
4504     }
4505
4506   /* Read the value-names and their values.
4507      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4508      A semicolon or comma instead of a NAME means the end.  */
4509   while (**pp && **pp != ';' && **pp != ',')
4510     {
4511       STABS_CONTINUE (pp, objfile);
4512       p = *pp;
4513       while (*p != ':')
4514         p++;
4515       name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
4516       *pp = p + 1;
4517       n = read_huge_number (pp, ',', &nbits);
4518       if (nbits != 0)
4519         return error_type (pp, objfile);
4520
4521       sym = (struct symbol *)
4522         obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4523       memset (sym, 0, sizeof (struct symbol));
4524       SYMBOL_NAME (sym) = name;
4525       SYMBOL_LANGUAGE (sym) = current_subfile->language;
4526       SYMBOL_CLASS (sym) = LOC_CONST;
4527       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4528       SYMBOL_VALUE (sym) = n;
4529       if (n < 0)
4530         unsigned_enum = 0;
4531       add_symbol_to_list (sym, symlist);
4532       nsyms++;
4533     }
4534
4535   if (**pp == ';')
4536     (*pp)++;                    /* Skip the semicolon.  */
4537
4538   /* Now fill in the fields of the type-structure.  */
4539
4540   TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4541   TYPE_CODE (type) = TYPE_CODE_ENUM;
4542   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4543   if (unsigned_enum)
4544     TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4545   TYPE_NFIELDS (type) = nsyms;
4546   TYPE_FIELDS (type) = (struct field *)
4547     TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4548   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4549
4550   /* Find the symbols for the values and put them into the type.
4551      The symbols can be found in the symlist that we put them on
4552      to cause them to be defined.  osyms contains the old value
4553      of that symlist; everything up to there was defined by us.  */
4554   /* Note that we preserve the order of the enum constants, so
4555      that in something like "enum {FOO, LAST_THING=FOO}" we print
4556      FOO, not LAST_THING.  */
4557
4558   for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4559     {
4560       int last = syms == osyms ? o_nsyms : 0;
4561       int j = syms->nsyms;
4562       for (; --j >= last; --n)
4563         {
4564           struct symbol *xsym = syms->symbol[j];
4565           SYMBOL_TYPE (xsym) = type;
4566           TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4567           TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4568           TYPE_FIELD_BITSIZE (type, n) = 0;
4569         }
4570       if (syms == osyms)
4571         break;
4572     }
4573
4574   return type;
4575 }
4576
4577 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4578    typedefs in every file (for int, long, etc):
4579
4580    type = b <signed> <width> <format type>; <offset>; <nbits>
4581    signed = u or s.
4582    optional format type = c or b for char or boolean.
4583    offset = offset from high order bit to start bit of type.
4584    width is # bytes in object of this type, nbits is # bits in type.
4585
4586    The width/offset stuff appears to be for small objects stored in
4587    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
4588    FIXME.  */
4589
4590 static struct type *
4591 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
4592 {
4593   int type_bits;
4594   int nbits;
4595   int signed_type;
4596   enum type_code code = TYPE_CODE_INT;
4597
4598   switch (**pp)
4599     {
4600     case 's':
4601       signed_type = 1;
4602       break;
4603     case 'u':
4604       signed_type = 0;
4605       break;
4606     default:
4607       return error_type (pp, objfile);
4608     }
4609   (*pp)++;
4610
4611   /* For some odd reason, all forms of char put a c here.  This is strange
4612      because no other type has this honor.  We can safely ignore this because
4613      we actually determine 'char'acterness by the number of bits specified in
4614      the descriptor.
4615      Boolean forms, e.g Fortran logical*X, put a b here.  */
4616
4617   if (**pp == 'c')
4618     (*pp)++;
4619   else if (**pp == 'b')
4620     {
4621       code = TYPE_CODE_BOOL;
4622       (*pp)++;
4623     }
4624
4625   /* The first number appears to be the number of bytes occupied
4626      by this type, except that unsigned short is 4 instead of 2.
4627      Since this information is redundant with the third number,
4628      we will ignore it.  */
4629   read_huge_number (pp, ';', &nbits);
4630   if (nbits != 0)
4631     return error_type (pp, objfile);
4632
4633   /* The second number is always 0, so ignore it too. */
4634   read_huge_number (pp, ';', &nbits);
4635   if (nbits != 0)
4636     return error_type (pp, objfile);
4637
4638   /* The third number is the number of bits for this type. */
4639   type_bits = read_huge_number (pp, 0, &nbits);
4640   if (nbits != 0)
4641     return error_type (pp, objfile);
4642   /* The type *should* end with a semicolon.  If it are embedded
4643      in a larger type the semicolon may be the only way to know where
4644      the type ends.  If this type is at the end of the stabstring we
4645      can deal with the omitted semicolon (but we don't have to like
4646      it).  Don't bother to complain(), Sun's compiler omits the semicolon
4647      for "void".  */
4648   if (**pp == ';')
4649     ++(*pp);
4650
4651   if (type_bits == 0)
4652     return init_type (TYPE_CODE_VOID, 1,
4653                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4654                       objfile);
4655   else
4656     return init_type (code,
4657                       type_bits / TARGET_CHAR_BIT,
4658                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4659                       objfile);
4660 }
4661
4662 static struct type *
4663 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
4664 {
4665   int nbits;
4666   int details;
4667   int nbytes;
4668   struct type *rettype;
4669
4670   /* The first number has more details about the type, for example
4671      FN_COMPLEX.  */
4672   details = read_huge_number (pp, ';', &nbits);
4673   if (nbits != 0)
4674     return error_type (pp, objfile);
4675
4676   /* The second number is the number of bytes occupied by this type */
4677   nbytes = read_huge_number (pp, ';', &nbits);
4678   if (nbits != 0)
4679     return error_type (pp, objfile);
4680
4681   if (details == NF_COMPLEX || details == NF_COMPLEX16
4682       || details == NF_COMPLEX32)
4683     {
4684       rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4685       TYPE_TARGET_TYPE (rettype)
4686         = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
4687       return rettype;
4688     }
4689
4690   return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4691 }
4692
4693 /* Read a number from the string pointed to by *PP.
4694    The value of *PP is advanced over the number.
4695    If END is nonzero, the character that ends the
4696    number must match END, or an error happens;
4697    and that character is skipped if it does match.
4698    If END is zero, *PP is left pointing to that character.
4699
4700    If the number fits in a long, set *BITS to 0 and return the value.
4701    If not, set *BITS to be the number of bits in the number and return 0.
4702
4703    If encounter garbage, set *BITS to -1 and return 0.  */
4704
4705 static long
4706 read_huge_number (char **pp, int end, int *bits)
4707 {
4708   char *p = *pp;
4709   int sign = 1;
4710   long n = 0;
4711   int radix = 10;
4712   char overflow = 0;
4713   int nbits = 0;
4714   int c;
4715   long upper_limit;
4716
4717   if (*p == '-')
4718     {
4719       sign = -1;
4720       p++;
4721     }
4722
4723   /* Leading zero means octal.  GCC uses this to output values larger
4724      than an int (because that would be hard in decimal).  */
4725   if (*p == '0')
4726     {
4727       radix = 8;
4728       p++;
4729     }
4730
4731   upper_limit = LONG_MAX / radix;
4732
4733   while ((c = *p++) >= '0' && c < ('0' + radix))
4734     {
4735       if (n <= upper_limit)
4736         {
4737           n *= radix;
4738           n += c - '0';         /* FIXME this overflows anyway */
4739         }
4740       else
4741         overflow = 1;
4742
4743       /* This depends on large values being output in octal, which is
4744          what GCC does. */
4745       if (radix == 8)
4746         {
4747           if (nbits == 0)
4748             {
4749               if (c == '0')
4750                 /* Ignore leading zeroes.  */
4751                 ;
4752               else if (c == '1')
4753                 nbits = 1;
4754               else if (c == '2' || c == '3')
4755                 nbits = 2;
4756               else
4757                 nbits = 3;
4758             }
4759           else
4760             nbits += 3;
4761         }
4762     }
4763   if (end)
4764     {
4765       if (c && c != end)
4766         {
4767           if (bits != NULL)
4768             *bits = -1;
4769           return 0;
4770         }
4771     }
4772   else
4773     --p;
4774
4775   *pp = p;
4776   if (overflow)
4777     {
4778       if (nbits == 0)
4779         {
4780           /* Large decimal constants are an error (because it is hard to
4781              count how many bits are in them).  */
4782           if (bits != NULL)
4783             *bits = -1;
4784           return 0;
4785         }
4786
4787       /* -0x7f is the same as 0x80.  So deal with it by adding one to
4788          the number of bits.  */
4789       if (sign == -1)
4790         ++nbits;
4791       if (bits)
4792         *bits = nbits;
4793     }
4794   else
4795     {
4796       if (bits)
4797         *bits = 0;
4798       return n * sign;
4799     }
4800   /* It's *BITS which has the interesting information.  */
4801   return 0;
4802 }
4803
4804 static struct type *
4805 read_range_type (char **pp, int typenums[2], struct objfile *objfile)
4806 {
4807   char *orig_pp = *pp;
4808   int rangenums[2];
4809   long n2, n3;
4810   int n2bits, n3bits;
4811   int self_subrange;
4812   struct type *result_type;
4813   struct type *index_type = NULL;
4814
4815   /* First comes a type we are a subrange of.
4816      In C it is usually 0, 1 or the type being defined.  */
4817   if (read_type_number (pp, rangenums) != 0)
4818     return error_type (pp, objfile);
4819   self_subrange = (rangenums[0] == typenums[0] &&
4820                    rangenums[1] == typenums[1]);
4821
4822   if (**pp == '=')
4823     {
4824       *pp = orig_pp;
4825       index_type = read_type (pp, objfile);
4826     }
4827
4828   /* A semicolon should now follow; skip it.  */
4829   if (**pp == ';')
4830     (*pp)++;
4831
4832   /* The remaining two operands are usually lower and upper bounds
4833      of the range.  But in some special cases they mean something else.  */
4834   n2 = read_huge_number (pp, ';', &n2bits);
4835   n3 = read_huge_number (pp, ';', &n3bits);
4836
4837   if (n2bits == -1 || n3bits == -1)
4838     return error_type (pp, objfile);
4839
4840   if (index_type)
4841     goto handle_true_range;
4842
4843   /* If limits are huge, must be large integral type.  */
4844   if (n2bits != 0 || n3bits != 0)
4845     {
4846       char got_signed = 0;
4847       char got_unsigned = 0;
4848       /* Number of bits in the type.  */
4849       int nbits = 0;
4850
4851       /* Range from 0 to <large number> is an unsigned large integral type.  */
4852       if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4853         {
4854           got_unsigned = 1;
4855           nbits = n3bits;
4856         }
4857       /* Range from <large number> to <large number>-1 is a large signed
4858          integral type.  Take care of the case where <large number> doesn't
4859          fit in a long but <large number>-1 does.  */
4860       else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4861                || (n2bits != 0 && n3bits == 0
4862                    && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4863                    && n3 == LONG_MAX))
4864         {
4865           got_signed = 1;
4866           nbits = n2bits;
4867         }
4868
4869       if (got_signed || got_unsigned)
4870         {
4871           return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4872                             got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4873                             objfile);
4874         }
4875       else
4876         return error_type (pp, objfile);
4877     }
4878
4879   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
4880   if (self_subrange && n2 == 0 && n3 == 0)
4881     return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
4882
4883   /* If n3 is zero and n2 is positive, we want a floating type, and n2
4884      is the width in bytes.
4885
4886      Fortran programs appear to use this for complex types also.  To
4887      distinguish between floats and complex, g77 (and others?)  seem
4888      to use self-subranges for the complexes, and subranges of int for
4889      the floats.
4890
4891      Also note that for complexes, g77 sets n2 to the size of one of
4892      the member floats, not the whole complex beast.  My guess is that
4893      this was to work well with pre-COMPLEX versions of gdb. */
4894
4895   if (n3 == 0 && n2 > 0)
4896     {
4897       struct type *float_type
4898         = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
4899
4900       if (self_subrange)
4901         {
4902           struct type *complex_type = 
4903             init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
4904           TYPE_TARGET_TYPE (complex_type) = float_type;
4905           return complex_type;
4906         }
4907       else
4908         return float_type;
4909     }
4910
4911   /* If the upper bound is -1, it must really be an unsigned int.  */
4912
4913   else if (n2 == 0 && n3 == -1)
4914     {
4915       /* It is unsigned int or unsigned long.  */
4916       /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4917          compatibility hack.  */
4918       return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4919                         TYPE_FLAG_UNSIGNED, NULL, objfile);
4920     }
4921
4922   /* Special case: char is defined (Who knows why) as a subrange of
4923      itself with range 0-127.  */
4924   else if (self_subrange && n2 == 0 && n3 == 127)
4925     return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4926
4927   /* We used to do this only for subrange of self or subrange of int.  */
4928   else if (n2 == 0)
4929     {
4930       /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4931          "unsigned long", and we already checked for that,
4932          so don't need to test for it here.  */
4933
4934       if (n3 < 0)
4935         /* n3 actually gives the size.  */
4936         return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
4937                           NULL, objfile);
4938
4939       /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
4940          unsigned n-byte integer.  But do require n to be a power of
4941          two; we don't want 3- and 5-byte integers flying around.  */
4942       {
4943         int bytes;
4944         unsigned long bits;
4945
4946         bits = n3;
4947         for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
4948           bits >>= 8;
4949         if (bits == 0
4950             && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
4951           return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
4952                             objfile);
4953       }
4954     }
4955   /* I think this is for Convex "long long".  Since I don't know whether
4956      Convex sets self_subrange, I also accept that particular size regardless
4957      of self_subrange.  */
4958   else if (n3 == 0 && n2 < 0
4959            && (self_subrange
4960                || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4961     return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
4962   else if (n2 == -n3 - 1)
4963     {
4964       if (n3 == 0x7f)
4965         return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4966       if (n3 == 0x7fff)
4967         return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4968       if (n3 == 0x7fffffff)
4969         return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
4970     }
4971
4972   /* We have a real range type on our hands.  Allocate space and
4973      return a real pointer.  */
4974 handle_true_range:
4975
4976   if (self_subrange)
4977     index_type = builtin_type_int;
4978   else
4979     index_type = *dbx_lookup_type (rangenums);
4980   if (index_type == NULL)
4981     {
4982       /* Does this actually ever happen?  Is that why we are worrying
4983          about dealing with it rather than just calling error_type?  */
4984
4985       static struct type *range_type_index;
4986
4987       complaint (&symfile_complaints,
4988                  "base type %d of range type is not defined", rangenums[1]);
4989       if (range_type_index == NULL)
4990         range_type_index =
4991           init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4992                      0, "range type index type", NULL);
4993       index_type = range_type_index;
4994     }
4995
4996   result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
4997   return (result_type);
4998 }
4999
5000 /* Read in an argument list.  This is a list of types, separated by commas
5001    and terminated with END.  Return the list of types read in, or (struct type
5002    **)-1 if there is an error.  */
5003
5004 static struct field *
5005 read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
5006            int *varargsp)
5007 {
5008   /* FIXME!  Remove this arbitrary limit!  */
5009   struct type *types[1024];     /* allow for fns of 1023 parameters */
5010   int n = 0, i;
5011   struct field *rval;
5012
5013   while (**pp != end)
5014     {
5015       if (**pp != ',')
5016         /* Invalid argument list: no ','.  */
5017         return (struct field *) -1;
5018       (*pp)++;
5019       STABS_CONTINUE (pp, objfile);
5020       types[n++] = read_type (pp, objfile);
5021     }
5022   (*pp)++;                      /* get past `end' (the ':' character) */
5023
5024   if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
5025     *varargsp = 1;
5026   else
5027     {
5028       n--;
5029       *varargsp = 0;
5030     }
5031
5032   rval = (struct field *) xmalloc (n * sizeof (struct field));
5033   memset (rval, 0, n * sizeof (struct field));
5034   for (i = 0; i < n; i++)
5035     rval[i].type = types[i];
5036   *nargsp = n;
5037   return rval;
5038 }
5039 \f
5040 /* Common block handling.  */
5041
5042 /* List of symbols declared since the last BCOMM.  This list is a tail
5043    of local_symbols.  When ECOMM is seen, the symbols on the list
5044    are noted so their proper addresses can be filled in later,
5045    using the common block base address gotten from the assembler
5046    stabs.  */
5047
5048 static struct pending *common_block;
5049 static int common_block_i;
5050
5051 /* Name of the current common block.  We get it from the BCOMM instead of the
5052    ECOMM to match IBM documentation (even though IBM puts the name both places
5053    like everyone else).  */
5054 static char *common_block_name;
5055
5056 /* Process a N_BCOMM symbol.  The storage for NAME is not guaranteed
5057    to remain after this function returns.  */
5058
5059 void
5060 common_block_start (char *name, struct objfile *objfile)
5061 {
5062   if (common_block_name != NULL)
5063     {
5064       complaint (&symfile_complaints,
5065                  "Invalid symbol data: common block within common block");
5066     }
5067   common_block = local_symbols;
5068   common_block_i = local_symbols ? local_symbols->nsyms : 0;
5069   common_block_name = obsavestring (name, strlen (name),
5070                                     &objfile->symbol_obstack);
5071 }
5072
5073 /* Process a N_ECOMM symbol.  */
5074
5075 void
5076 common_block_end (struct objfile *objfile)
5077 {
5078   /* Symbols declared since the BCOMM are to have the common block
5079      start address added in when we know it.  common_block and
5080      common_block_i point to the first symbol after the BCOMM in
5081      the local_symbols list; copy the list and hang it off the
5082      symbol for the common block name for later fixup.  */
5083   int i;
5084   struct symbol *sym;
5085   struct pending *new = 0;
5086   struct pending *next;
5087   int j;
5088
5089   if (common_block_name == NULL)
5090     {
5091       complaint (&symfile_complaints, "ECOMM symbol unmatched by BCOMM");
5092       return;
5093     }
5094
5095   sym = (struct symbol *)
5096     obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
5097   memset (sym, 0, sizeof (struct symbol));
5098   /* Note: common_block_name already saved on symbol_obstack */
5099   SYMBOL_NAME (sym) = common_block_name;
5100   SYMBOL_CLASS (sym) = LOC_BLOCK;
5101
5102   /* Now we copy all the symbols which have been defined since the BCOMM.  */
5103
5104   /* Copy all the struct pendings before common_block.  */
5105   for (next = local_symbols;
5106        next != NULL && next != common_block;
5107        next = next->next)
5108     {
5109       for (j = 0; j < next->nsyms; j++)
5110         add_symbol_to_list (next->symbol[j], &new);
5111     }
5112
5113   /* Copy however much of COMMON_BLOCK we need.  If COMMON_BLOCK is
5114      NULL, it means copy all the local symbols (which we already did
5115      above).  */
5116
5117   if (common_block != NULL)
5118     for (j = common_block_i; j < common_block->nsyms; j++)
5119       add_symbol_to_list (common_block->symbol[j], &new);
5120
5121   SYMBOL_TYPE (sym) = (struct type *) new;
5122
5123   /* Should we be putting local_symbols back to what it was?
5124      Does it matter?  */
5125
5126   i = hashname (SYMBOL_NAME (sym));
5127   SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
5128   global_sym_chain[i] = sym;
5129   common_block_name = NULL;
5130 }
5131
5132 /* Add a common block's start address to the offset of each symbol
5133    declared to be in it (by being between a BCOMM/ECOMM pair that uses
5134    the common block name).  */
5135
5136 static void
5137 fix_common_block (struct symbol *sym, int valu)
5138 {
5139   struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
5140   for (; next; next = next->next)
5141     {
5142       register int j;
5143       for (j = next->nsyms - 1; j >= 0; j--)
5144         SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
5145     }
5146 }
5147 \f
5148
5149
5150 /* What about types defined as forward references inside of a small lexical
5151    scope?  */
5152 /* Add a type to the list of undefined types to be checked through
5153    once this file has been read in.  */
5154
5155 void
5156 add_undefined_type (struct type *type)
5157 {
5158   if (undef_types_length == undef_types_allocated)
5159     {
5160       undef_types_allocated *= 2;
5161       undef_types = (struct type **)
5162         xrealloc ((char *) undef_types,
5163                   undef_types_allocated * sizeof (struct type *));
5164     }
5165   undef_types[undef_types_length++] = type;
5166 }
5167
5168 /* Go through each undefined type, see if it's still undefined, and fix it
5169    up if possible.  We have two kinds of undefined types:
5170
5171    TYPE_CODE_ARRAY:  Array whose target type wasn't defined yet.
5172    Fix:  update array length using the element bounds
5173    and the target type's length.
5174    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
5175    yet defined at the time a pointer to it was made.
5176    Fix:  Do a full lookup on the struct/union tag.  */
5177 void
5178 cleanup_undefined_types (void)
5179 {
5180   struct type **type;
5181
5182   for (type = undef_types; type < undef_types + undef_types_length; type++)
5183     {
5184       switch (TYPE_CODE (*type))
5185         {
5186
5187         case TYPE_CODE_STRUCT:
5188         case TYPE_CODE_UNION:
5189         case TYPE_CODE_ENUM:
5190           {
5191             /* Check if it has been defined since.  Need to do this here
5192                as well as in check_typedef to deal with the (legitimate in
5193                C though not C++) case of several types with the same name
5194                in different source files.  */
5195             if (TYPE_STUB (*type))
5196               {
5197                 struct pending *ppt;
5198                 int i;
5199                 /* Name of the type, without "struct" or "union" */
5200                 char *typename = TYPE_TAG_NAME (*type);
5201
5202                 if (typename == NULL)
5203                   {
5204                     complaint (&symfile_complaints, "need a type name");
5205                     break;
5206                   }
5207                 for (ppt = file_symbols; ppt; ppt = ppt->next)
5208                   {
5209                     for (i = 0; i < ppt->nsyms; i++)
5210                       {
5211                         struct symbol *sym = ppt->symbol[i];
5212
5213                         if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
5214                             && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
5215                             && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
5216                                 TYPE_CODE (*type))
5217                             && STREQ (SYMBOL_NAME (sym), typename))
5218                           replace_type (*type, SYMBOL_TYPE (sym));
5219                       }
5220                   }
5221               }
5222           }
5223           break;
5224
5225         default:
5226           {
5227             complaint (&symfile_complaints,
5228                        "GDB internal error.  cleanup_undefined_types with bad type %d.",
5229                        TYPE_CODE (*type));
5230           }
5231           break;
5232         }
5233     }
5234
5235   undef_types_length = 0;
5236 }
5237
5238 /* Scan through all of the global symbols defined in the object file,
5239    assigning values to the debugging symbols that need to be assigned
5240    to.  Get these symbols from the minimal symbol table.  */
5241
5242 void
5243 scan_file_globals (struct objfile *objfile)
5244 {
5245   int hash;
5246   struct minimal_symbol *msymbol;
5247   struct symbol *sym, *prev, *rsym;
5248   struct objfile *resolve_objfile;
5249
5250   /* SVR4 based linkers copy referenced global symbols from shared
5251      libraries to the main executable.
5252      If we are scanning the symbols for a shared library, try to resolve
5253      them from the minimal symbols of the main executable first.  */
5254
5255   if (symfile_objfile && objfile != symfile_objfile)
5256     resolve_objfile = symfile_objfile;
5257   else
5258     resolve_objfile = objfile;
5259
5260   while (1)
5261     {
5262       /* Avoid expensive loop through all minimal symbols if there are
5263          no unresolved symbols.  */
5264       for (hash = 0; hash < HASHSIZE; hash++)
5265         {
5266           if (global_sym_chain[hash])
5267             break;
5268         }
5269       if (hash >= HASHSIZE)
5270         return;
5271
5272       for (msymbol = resolve_objfile->msymbols;
5273            msymbol && SYMBOL_NAME (msymbol) != NULL;
5274            msymbol++)
5275         {
5276           QUIT;
5277
5278           /* Skip static symbols.  */
5279           switch (MSYMBOL_TYPE (msymbol))
5280             {
5281             case mst_file_text:
5282             case mst_file_data:
5283             case mst_file_bss:
5284               continue;
5285             default:
5286               break;
5287             }
5288
5289           prev = NULL;
5290
5291           /* Get the hash index and check all the symbols
5292              under that hash index. */
5293
5294           hash = hashname (SYMBOL_NAME (msymbol));
5295
5296           for (sym = global_sym_chain[hash]; sym;)
5297             {
5298               if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
5299                   STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
5300                 {
5301
5302                   struct alias_list *aliases;
5303
5304                   /* Splice this symbol out of the hash chain and
5305                      assign the value we have to it. */
5306                   if (prev)
5307                     {
5308                       SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
5309                     }
5310                   else
5311                     {
5312                       global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5313                     }
5314
5315                   /* Check to see whether we need to fix up a common block.  */
5316                   /* Note: this code might be executed several times for
5317                      the same symbol if there are multiple references.  */
5318
5319                   /* If symbol has aliases, do minimal symbol fixups for each.
5320                      These live aliases/references weren't added to 
5321                      global_sym_chain hash but may also need to be fixed up. */
5322                   /* FIXME: Maybe should have added aliases to the global chain,                     resolved symbol name, then treated aliases as normal 
5323                      symbols?  Still, we wouldn't want to add_to_list. */
5324                   /* Now do the same for each alias of this symbol */
5325                   rsym = sym;
5326                   aliases = SYMBOL_ALIASES (sym);
5327                   while (rsym)
5328                     {
5329                       if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5330                         {
5331                           fix_common_block (rsym,
5332                                             SYMBOL_VALUE_ADDRESS (msymbol));
5333                         }
5334                       else
5335                         {
5336                           SYMBOL_VALUE_ADDRESS (rsym)
5337                             = SYMBOL_VALUE_ADDRESS (msymbol);
5338                         }
5339                       SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5340                       if (aliases)
5341                         {
5342                           rsym = aliases->sym;
5343                           aliases = aliases->next;
5344                         }
5345                       else
5346                         rsym = NULL;
5347                     }
5348
5349
5350                   if (prev)
5351                     {
5352                       sym = SYMBOL_VALUE_CHAIN (prev);
5353                     }
5354                   else
5355                     {
5356                       sym = global_sym_chain[hash];
5357                     }
5358                 }
5359               else
5360                 {
5361                   prev = sym;
5362                   sym = SYMBOL_VALUE_CHAIN (sym);
5363                 }
5364             }
5365         }
5366       if (resolve_objfile == objfile)
5367         break;
5368       resolve_objfile = objfile;
5369     }
5370
5371   /* Change the storage class of any remaining unresolved globals to
5372      LOC_UNRESOLVED and remove them from the chain.  */
5373   for (hash = 0; hash < HASHSIZE; hash++)
5374     {
5375       sym = global_sym_chain[hash];
5376       while (sym)
5377         {
5378           prev = sym;
5379           sym = SYMBOL_VALUE_CHAIN (sym);
5380
5381           /* Change the symbol address from the misleading chain value
5382              to address zero.  */
5383           SYMBOL_VALUE_ADDRESS (prev) = 0;
5384
5385           /* Complain about unresolved common block symbols.  */
5386           if (SYMBOL_CLASS (prev) == LOC_STATIC)
5387             SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5388           else
5389             complaint (&symfile_complaints,
5390                        "%s: common block `%s' from global_sym_chain unresolved",
5391                        objfile->name, SYMBOL_NAME (prev));
5392         }
5393     }
5394   memset (global_sym_chain, 0, sizeof (global_sym_chain));
5395 }
5396
5397 /* Initialize anything that needs initializing when starting to read
5398    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5399    to a psymtab.  */
5400
5401 void
5402 stabsread_init (void)
5403 {
5404 }
5405
5406 /* Initialize anything that needs initializing when a completely new
5407    symbol file is specified (not just adding some symbols from another
5408    file, e.g. a shared library).  */
5409
5410 void
5411 stabsread_new_init (void)
5412 {
5413   /* Empty the hash table of global syms looking for values.  */
5414   memset (global_sym_chain, 0, sizeof (global_sym_chain));
5415 }
5416
5417 /* Initialize anything that needs initializing at the same time as
5418    start_symtab() is called. */
5419
5420 void
5421 start_stabs (void)
5422 {
5423   global_stabs = NULL;          /* AIX COFF */
5424   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
5425   n_this_object_header_files = 1;
5426   type_vector_length = 0;
5427   type_vector = (struct type **) 0;
5428
5429   /* FIXME: If common_block_name is not already NULL, we should complain().  */
5430   common_block_name = NULL;
5431 }
5432
5433 /* Call after end_symtab() */
5434
5435 void
5436 end_stabs (void)
5437 {
5438   if (type_vector)
5439     {
5440       xfree (type_vector);
5441     }
5442   type_vector = 0;
5443   type_vector_length = 0;
5444   previous_stab_code = 0;
5445 }
5446
5447 void
5448 finish_global_stabs (struct objfile *objfile)
5449 {
5450   if (global_stabs)
5451     {
5452       patch_block_stabs (global_symbols, global_stabs, objfile);
5453       xfree (global_stabs);
5454       global_stabs = NULL;
5455     }
5456 }
5457
5458 /* Find the end of the name, delimited by a ':', but don't match
5459    ObjC symbols which look like -[Foo bar::]:bla.  */
5460 static char *
5461 find_name_end (char *name)
5462 {
5463   char *s = name;
5464   if (s[0] == '-' || *s == '+')
5465     {
5466       /* Must be an ObjC method symbol.  */
5467       if (s[1] != '[')
5468         {
5469           error ("invalid symbol name \"%s\"", name);
5470         }
5471       s = strchr (s, ']');
5472       if (s == NULL)
5473         {
5474           error ("invalid symbol name \"%s\"", name);
5475         }
5476       return strchr (s, ':');
5477     }
5478   else
5479     {
5480       return strchr (s, ':');
5481     }
5482 }
5483
5484 /* Initializer for this module */
5485
5486 void
5487 _initialize_stabsread (void)
5488 {
5489   undef_types_allocated = 20;
5490   undef_types_length = 0;
5491   undef_types = (struct type **)
5492     xmalloc (undef_types_allocated * sizeof (struct type *));
5493 }