OSDN Git Service

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