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