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