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