gdb/stabsread.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Support routines for decoding "stabs" debugging information format.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* Support routines for reading and decoding debugging information in
  15.    the "stabs" format.  This format is used with many systems that use
  16.    the a.out object file format, as well as some systems that use
  17.    COFF or ELF where the stabs data is placed in a special section.
  18.    Avoid placing any object file format specific code in this file.  */

  19. #include "defs.h"
  20. #include "bfd.h"
  21. #include "gdb_obstack.h"
  22. #include "symtab.h"
  23. #include "gdbtypes.h"
  24. #include "expression.h"
  25. #include "symfile.h"
  26. #include "objfiles.h"
  27. #include "aout/stab_gnu.h"        /* We always use GNU stabs, not native.  */
  28. #include "libaout.h"
  29. #include "aout/aout64.h"
  30. #include "gdb-stabs.h"
  31. #include "buildsym.h"
  32. #include "complaints.h"
  33. #include "demangle.h"
  34. #include "gdb-demangle.h"
  35. #include "language.h"
  36. #include "doublest.h"
  37. #include "cp-abi.h"
  38. #include "cp-support.h"
  39. #include <ctype.h>

  40. /* Ask stabsread.h to define the vars it normally declares `extern'.  */
  41. #define        EXTERN
  42. /**/
  43. #include "stabsread.h"                /* Our own declarations */
  44. #undef        EXTERN

  45. extern void _initialize_stabsread (void);

  46. /* The routines that read and process a complete stabs for a C struct or
  47.    C++ class pass lists of data member fields and lists of member function
  48.    fields in an instance of a field_info structure, as defined below.
  49.    This is part of some reorganization of low level C++ support and is
  50.    expected to eventually go away...  (FIXME) */

  51. struct field_info
  52.   {
  53.     struct nextfield
  54.       {
  55.         struct nextfield *next;

  56.         /* This is the raw visibility from the stab.  It is not checked
  57.            for being one of the visibilities we recognize, so code which
  58.            examines this field better be able to deal.  */
  59.         int visibility;

  60.         struct field field;
  61.       }
  62.      *list;
  63.     struct next_fnfieldlist
  64.       {
  65.         struct next_fnfieldlist *next;
  66.         struct fn_fieldlist fn_fieldlist;
  67.       }
  68.      *fnlist;
  69.   };

  70. static void
  71. read_one_struct_field (struct field_info *, char **, char *,
  72.                        struct type *, struct objfile *);

  73. static struct type *dbx_alloc_type (int[2], struct objfile *);

  74. static long read_huge_number (char **, int, int *, int);

  75. static struct type *error_type (char **, struct objfile *);

  76. static void
  77. patch_block_stabs (struct pending *, struct pending_stabs *,
  78.                    struct objfile *);

  79. static void fix_common_block (struct symbol *, CORE_ADDR);

  80. static int read_type_number (char **, int *);

  81. static struct type *read_type (char **, struct objfile *);

  82. static struct type *read_range_type (char **, int[2], int, struct objfile *);

  83. static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);

  84. static struct type *read_sun_floating_type (char **, int[2],
  85.                                             struct objfile *);

  86. static struct type *read_enum_type (char **, struct type *, struct objfile *);

  87. static struct type *rs6000_builtin_type (int, struct objfile *);

  88. static int
  89. read_member_functions (struct field_info *, char **, struct type *,
  90.                        struct objfile *);

  91. static int
  92. read_struct_fields (struct field_info *, char **, struct type *,
  93.                     struct objfile *);

  94. static int
  95. read_baseclasses (struct field_info *, char **, struct type *,
  96.                   struct objfile *);

  97. static int
  98. read_tilde_fields (struct field_info *, char **, struct type *,
  99.                    struct objfile *);

  100. static int attach_fn_fields_to_type (struct field_info *, struct type *);

  101. static int attach_fields_to_type (struct field_info *, struct type *,
  102.                                   struct objfile *);

  103. static struct type *read_struct_type (char **, struct type *,
  104.                                       enum type_code,
  105.                                       struct objfile *);

  106. static struct type *read_array_type (char **, struct type *,
  107.                                      struct objfile *);

  108. static struct field *read_args (char **, int, struct objfile *, int *, int *);

  109. static void add_undefined_type (struct type *, int[2]);

  110. static int
  111. read_cpp_abbrev (struct field_info *, char **, struct type *,
  112.                  struct objfile *);

  113. static char *find_name_end (char *name);

  114. static int process_reference (char **string);

  115. void stabsread_clear_cache (void);

  116. static const char vptr_name[] = "_vptr$";
  117. static const char vb_name[] = "_vb$";

  118. static void
  119. invalid_cpp_abbrev_complaint (const char *arg1)
  120. {
  121.   complaint (&symfile_complaints, _("invalid C++ abbreviation `%s'"), arg1);
  122. }

  123. static void
  124. reg_value_complaint (int regnum, int num_regs, const char *sym)
  125. {
  126.   complaint (&symfile_complaints,
  127.              _("register number %d too large (max %d) in symbol %s"),
  128.              regnum, num_regs - 1, sym);
  129. }

  130. static void
  131. stabs_general_complaint (const char *arg1)
  132. {
  133.   complaint (&symfile_complaints, "%s", arg1);
  134. }

  135. /* Make a list of forward references which haven't been defined.  */

  136. static struct type **undef_types;
  137. static int undef_types_allocated;
  138. static int undef_types_length;
  139. static struct symbol *current_symbol = NULL;

  140. /* Make a list of nameless types that are undefined.
  141.    This happens when another type is referenced by its number
  142.    before this type is actually defined.  For instance "t(0,1)=k(0,2)"
  143.    and type (0,2) is defined only later.  */

  144. struct nat
  145. {
  146.   int typenums[2];
  147.   struct type *type;
  148. };
  149. static struct nat *noname_undefs;
  150. static int noname_undefs_allocated;
  151. static int noname_undefs_length;

  152. /* Check for and handle cretinous stabs symbol name continuation!  */
  153. #define STABS_CONTINUE(pp,objfile)                                \
  154.   do {                                                        \
  155.     if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
  156.       *(pp) = next_symbol_text (objfile);        \
  157.   } while (0)

  158. /* Vector of types defined so far, indexed by their type numbers.
  159.    (In newer sun systems, dbx uses a pair of numbers in parens,
  160.    as in "(SUBFILENUM,NUMWITHINSUBFILE)".
  161.    Then these numbers must be translated through the type_translations
  162.    hash table to get the index into the type vector.)  */

  163. static struct type **type_vector;

  164. /* Number of elements allocated for type_vector currently.  */

  165. static int type_vector_length;

  166. /* Initial size of type vector.  Is realloc'd larger if needed, and
  167.    realloc'd down to the size actually used, when completed.  */

  168. #define INITIAL_TYPE_VECTOR_LENGTH 160


  169. /* Look up a dbx type-number pair.  Return the address of the slot
  170.    where the type for that number-pair is stored.
  171.    The number-pair is in TYPENUMS.

  172.    This can be used for finding the type associated with that pair
  173.    or for associating a new type with the pair.  */

  174. static struct type **
  175. dbx_lookup_type (int typenums[2], struct objfile *objfile)
  176. {
  177.   int filenum = typenums[0];
  178.   int index = typenums[1];
  179.   unsigned old_len;
  180.   int real_filenum;
  181.   struct header_file *f;
  182.   int f_orig_length;

  183.   if (filenum == -1)                /* -1,-1 is for temporary types.  */
  184.     return 0;

  185.   if (filenum < 0 || filenum >= n_this_object_header_files)
  186.     {
  187.       complaint (&symfile_complaints,
  188.                  _("Invalid symbol data: type number "
  189.                    "(%d,%d) out of range at symtab pos %d."),
  190.                  filenum, index, symnum);
  191.       goto error_return;
  192.     }

  193.   if (filenum == 0)
  194.     {
  195.       if (index < 0)
  196.         {
  197.           /* Caller wants address of address of type.  We think
  198.              that negative (rs6k builtin) types will never appear as
  199.              "lvalues", (nor should they), so we stuff the real type
  200.              pointer into a temp, and return its address.  If referenced,
  201.              this will do the right thing.  */
  202.           static struct type *temp_type;

  203.           temp_type = rs6000_builtin_type (index, objfile);
  204.           return &temp_type;
  205.         }

  206.       /* Type is defined outside of header files.
  207.          Find it in this object file's type vector.  */
  208.       if (index >= type_vector_length)
  209.         {
  210.           old_len = type_vector_length;
  211.           if (old_len == 0)
  212.             {
  213.               type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
  214.               type_vector = (struct type **)
  215.                 xmalloc (type_vector_length * sizeof (struct type *));
  216.             }
  217.           while (index >= type_vector_length)
  218.             {
  219.               type_vector_length *= 2;
  220.             }
  221.           type_vector = (struct type **)
  222.             xrealloc ((char *) type_vector,
  223.                       (type_vector_length * sizeof (struct type *)));
  224.           memset (&type_vector[old_len], 0,
  225.                   (type_vector_length - old_len) * sizeof (struct type *));
  226.         }
  227.       return (&type_vector[index]);
  228.     }
  229.   else
  230.     {
  231.       real_filenum = this_object_header_files[filenum];

  232.       if (real_filenum >= N_HEADER_FILES (objfile))
  233.         {
  234.           static struct type *temp_type;

  235.           warning (_("GDB internal error: bad real_filenum"));

  236.         error_return:
  237.           temp_type = objfile_type (objfile)->builtin_error;
  238.           return &temp_type;
  239.         }

  240.       f = HEADER_FILES (objfile) + real_filenum;

  241.       f_orig_length = f->length;
  242.       if (index >= f_orig_length)
  243.         {
  244.           while (index >= f->length)
  245.             {
  246.               f->length *= 2;
  247.             }
  248.           f->vector = (struct type **)
  249.             xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
  250.           memset (&f->vector[f_orig_length], 0,
  251.                   (f->length - f_orig_length) * sizeof (struct type *));
  252.         }
  253.       return (&f->vector[index]);
  254.     }
  255. }

  256. /* Make sure there is a type allocated for type numbers TYPENUMS
  257.    and return the type object.
  258.    This can create an empty (zeroed) type object.
  259.    TYPENUMS may be (-1, -1) to return a new type object that is not
  260.    put into the type vector, and so may not be referred to by number.  */

  261. static struct type *
  262. dbx_alloc_type (int typenums[2], struct objfile *objfile)
  263. {
  264.   struct type **type_addr;

  265.   if (typenums[0] == -1)
  266.     {
  267.       return (alloc_type (objfile));
  268.     }

  269.   type_addr = dbx_lookup_type (typenums, objfile);

  270.   /* If we are referring to a type not known at all yet,
  271.      allocate an empty type for it.
  272.      We will fill it in later if we find out how.  */
  273.   if (*type_addr == 0)
  274.     {
  275.       *type_addr = alloc_type (objfile);
  276.     }

  277.   return (*type_addr);
  278. }

  279. /* for all the stabs in a given stab vector, build appropriate types
  280.    and fix their symbols in given symbol vector.  */

  281. static void
  282. patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
  283.                    struct objfile *objfile)
  284. {
  285.   int ii;
  286.   char *name;
  287.   char *pp;
  288.   struct symbol *sym;

  289.   if (stabs)
  290.     {
  291.       /* for all the stab entries, find their corresponding symbols and
  292.          patch their types!  */

  293.       for (ii = 0; ii < stabs->count; ++ii)
  294.         {
  295.           name = stabs->stab[ii];
  296.           pp = (char *) strchr (name, ':');
  297.           gdb_assert (pp);        /* Must find a ':' or game's over.  */
  298.           while (pp[1] == ':')
  299.             {
  300.               pp += 2;
  301.               pp = (char *) strchr (pp, ':');
  302.             }
  303.           sym = find_symbol_in_list (symbols, name, pp - name);
  304.           if (!sym)
  305.             {
  306.               /* FIXME-maybe: it would be nice if we noticed whether
  307.                  the variable was defined *anywhere*, not just whether
  308.                  it is defined in this compilation unit.  But neither
  309.                  xlc or GCC seem to need such a definition, and until
  310.                  we do psymtabs (so that the minimal symbols from all
  311.                  compilation units are available now), I'm not sure
  312.                  how to get the information.  */

  313.               /* On xcoff, if a global is defined and never referenced,
  314.                  ld will remove it from the executable.  There is then
  315.                  a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
  316.               sym = allocate_symbol (objfile);
  317.               SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  318.               SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
  319.               SYMBOL_SET_LINKAGE_NAME
  320.                 (sym, obstack_copy0 (&objfile->objfile_obstack,
  321.                                      name, pp - name));
  322.               pp += 2;
  323.               if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
  324.                 {
  325.                   /* I don't think the linker does this with functions,
  326.                      so as far as I know this is never executed.
  327.                      But it doesn't hurt to check.  */
  328.                   SYMBOL_TYPE (sym) =
  329.                     lookup_function_type (read_type (&pp, objfile));
  330.                 }
  331.               else
  332.                 {
  333.                   SYMBOL_TYPE (sym) = read_type (&pp, objfile);
  334.                 }
  335.               add_symbol_to_list (sym, &global_symbols);
  336.             }
  337.           else
  338.             {
  339.               pp += 2;
  340.               if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
  341.                 {
  342.                   SYMBOL_TYPE (sym) =
  343.                     lookup_function_type (read_type (&pp, objfile));
  344.                 }
  345.               else
  346.                 {
  347.                   SYMBOL_TYPE (sym) = read_type (&pp, objfile);
  348.                 }
  349.             }
  350.         }
  351.     }
  352. }


  353. /* Read a number by which a type is referred to in dbx data,
  354.    or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
  355.    Just a single number N is equivalent to (0,N).
  356.    Return the two numbers by storing them in the vector TYPENUMS.
  357.    TYPENUMS will then be used as an argument to dbx_lookup_type.

  358.    Returns 0 for success, -1 for error.  */

  359. static int
  360. read_type_number (char **pp, int *typenums)
  361. {
  362.   int nbits;

  363.   if (**pp == '(')
  364.     {
  365.       (*pp)++;
  366.       typenums[0] = read_huge_number (pp, ',', &nbits, 0);
  367.       if (nbits != 0)
  368.         return -1;
  369.       typenums[1] = read_huge_number (pp, ')', &nbits, 0);
  370.       if (nbits != 0)
  371.         return -1;
  372.     }
  373.   else
  374.     {
  375.       typenums[0] = 0;
  376.       typenums[1] = read_huge_number (pp, 0, &nbits, 0);
  377.       if (nbits != 0)
  378.         return -1;
  379.     }
  380.   return 0;
  381. }


  382. #define VISIBILITY_PRIVATE        '0'        /* Stabs character for private field */
  383. #define VISIBILITY_PROTECTED        '1'        /* Stabs character for protected fld */
  384. #define VISIBILITY_PUBLIC        '2'        /* Stabs character for public field */
  385. #define VISIBILITY_IGNORE        '9'        /* Optimized out or zero length */

  386. /* Structure for storing pointers to reference definitions for fast lookup
  387.    during "process_later".  */

  388. struct ref_map
  389. {
  390.   char *stabs;
  391.   CORE_ADDR value;
  392.   struct symbol *sym;
  393. };

  394. #define MAX_CHUNK_REFS 100
  395. #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
  396. #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)

  397. static struct ref_map *ref_map;

  398. /* Ptr to free cell in chunk's linked list.  */
  399. static int ref_count = 0;

  400. /* Number of chunks malloced.  */
  401. static int ref_chunk = 0;

  402. /* This file maintains a cache of stabs aliases found in the symbol
  403.    table.  If the symbol table changes, this cache must be cleared
  404.    or we are left holding onto data in invalid obstacks.  */
  405. void
  406. stabsread_clear_cache (void)
  407. {
  408.   ref_count = 0;
  409.   ref_chunk = 0;
  410. }

  411. /* Create array of pointers mapping refids to symbols and stab strings.
  412.    Add pointers to reference definition symbols and/or their values as we
  413.    find them, using their reference numbers as our index.
  414.    These will be used later when we resolve references.  */
  415. void
  416. ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
  417. {
  418.   if (ref_count == 0)
  419.     ref_chunk = 0;
  420.   if (refnum >= ref_count)
  421.     ref_count = refnum + 1;
  422.   if (ref_count > ref_chunk * MAX_CHUNK_REFS)
  423.     {
  424.       int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
  425.       int new_chunks = new_slots / MAX_CHUNK_REFS + 1;

  426.       ref_map = (struct ref_map *)
  427.         xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
  428.       memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0,
  429.               new_chunks * REF_CHUNK_SIZE);
  430.       ref_chunk += new_chunks;
  431.     }
  432.   ref_map[refnum].stabs = stabs;
  433.   ref_map[refnum].sym = sym;
  434.   ref_map[refnum].value = value;
  435. }

  436. /* Return defined sym for the reference REFNUM.  */
  437. struct symbol *
  438. ref_search (int refnum)
  439. {
  440.   if (refnum < 0 || refnum > ref_count)
  441.     return 0;
  442.   return ref_map[refnum].sym;
  443. }

  444. /* Parse a reference id in STRING and return the resulting
  445.    reference number.  Move STRING beyond the reference id.  */

  446. static int
  447. process_reference (char **string)
  448. {
  449.   char *p;
  450.   int refnum = 0;

  451.   if (**string != '#')
  452.     return 0;

  453.   /* Advance beyond the initial '#'.  */
  454.   p = *string + 1;

  455.   /* Read number as reference id.  */
  456.   while (*p && isdigit (*p))
  457.     {
  458.       refnum = refnum * 10 + *p - '0';
  459.       p++;
  460.     }
  461.   *string = p;
  462.   return refnum;
  463. }

  464. /* If STRING defines a reference, store away a pointer to the reference
  465.    definition for later use.  Return the reference number.  */

  466. int
  467. symbol_reference_defined (char **string)
  468. {
  469.   char *p = *string;
  470.   int refnum = 0;

  471.   refnum = process_reference (&p);

  472.   /* Defining symbols end in '='.  */
  473.   if (*p == '=')
  474.     {
  475.       /* Symbol is being defined here.  */
  476.       *string = p + 1;
  477.       return refnum;
  478.     }
  479.   else
  480.     {
  481.       /* Must be a reference.  Either the symbol has already been defined,
  482.          or this is a forward reference to it.  */
  483.       *string = p;
  484.       return -1;
  485.     }
  486. }

  487. static int
  488. stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
  489. {
  490.   int regno = gdbarch_stab_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));

  491.   if (regno >= gdbarch_num_regs (gdbarch)
  492.                 + gdbarch_num_pseudo_regs (gdbarch))
  493.     {
  494.       reg_value_complaint (regno,
  495.                            gdbarch_num_regs (gdbarch)
  496.                              + gdbarch_num_pseudo_regs (gdbarch),
  497.                            SYMBOL_PRINT_NAME (sym));

  498.       regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless.  */
  499.     }

  500.   return regno;
  501. }

  502. static const struct symbol_register_ops stab_register_funcs = {
  503.   stab_reg_to_regnum
  504. };

  505. /* The "aclass" indices for computed symbols.  */

  506. static int stab_register_index;
  507. static int stab_regparm_index;

  508. struct symbol *
  509. define_symbol (CORE_ADDR valu, char *string, int desc, int type,
  510.                struct objfile *objfile)
  511. {
  512.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  513.   struct symbol *sym;
  514.   char *p = (char *) find_name_end (string);
  515.   int deftype;
  516.   int synonym = 0;
  517.   int i;
  518.   char *new_name = NULL;

  519.   /* We would like to eliminate nameless symbols, but keep their types.
  520.      E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
  521.      to type 2, but, should not create a symbol to address that type.  Since
  522.      the symbol will be nameless, there is no way any user can refer to it.  */

  523.   int nameless;

  524.   /* Ignore syms with empty names.  */
  525.   if (string[0] == 0)
  526.     return 0;

  527.   /* Ignore old-style symbols from cc -go.  */
  528.   if (p == 0)
  529.     return 0;

  530.   while (p[1] == ':')
  531.     {
  532.       p += 2;
  533.       p = strchr (p, ':');
  534.       if (p == NULL)
  535.         {
  536.           complaint (&symfile_complaints,
  537.                      _("Bad stabs string '%s'"), string);
  538.           return NULL;
  539.         }
  540.     }

  541.   /* If a nameless stab entry, all we need is the type, not the symbol.
  542.      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
  543.   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));

  544.   current_symbol = sym = allocate_symbol (objfile);

  545.   if (processing_gcc_compilation)
  546.     {
  547.       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
  548.          number of bytes occupied by a type or object, which we ignore.  */
  549.       SYMBOL_LINE (sym) = desc;
  550.     }
  551.   else
  552.     {
  553.       SYMBOL_LINE (sym) = 0;        /* unknown */
  554.     }

  555.   SYMBOL_SET_LANGUAGE (sym, current_subfile->language,
  556.                        &objfile->objfile_obstack);

  557.   if (is_cplus_marker (string[0]))
  558.     {
  559.       /* Special GNU C++ names.  */
  560.       switch (string[1])
  561.         {
  562.         case 't':
  563.           SYMBOL_SET_LINKAGE_NAME (sym, "this");
  564.           break;

  565.         case 'v':                /* $vtbl_ptr_type */
  566.           goto normal;

  567.         case 'e':
  568.           SYMBOL_SET_LINKAGE_NAME (sym, "eh_throw");
  569.           break;

  570.         case '_':
  571.           /* This was an anonymous type that was never fixed up.  */
  572.           goto normal;

  573.         case 'X':
  574.           /* SunPRO (3.0 at least) static variable encoding.  */
  575.           if (gdbarch_static_transform_name_p (gdbarch))
  576.             goto normal;
  577.           /* ... fall through ...  */

  578.         default:
  579.           complaint (&symfile_complaints, _("Unknown C++ symbol name `%s'"),
  580.                      string);
  581.           goto normal;                /* Do *something* with it.  */
  582.         }
  583.     }
  584.   else
  585.     {
  586.     normal:
  587.       if (SYMBOL_LANGUAGE (sym) == language_cplus)
  588.         {
  589.           char *name = alloca (p - string + 1);

  590.           memcpy (name, string, p - string);
  591.           name[p - string] = '\0';
  592.           new_name = cp_canonicalize_string (name);
  593.         }
  594.       if (new_name != NULL)
  595.         {
  596.           SYMBOL_SET_NAMES (sym, new_name, strlen (new_name), 1, objfile);
  597.           xfree (new_name);
  598.         }
  599.       else
  600.         SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile);

  601.       if (SYMBOL_LANGUAGE (sym) == language_cplus)
  602.         cp_scan_for_anonymous_namespaces (sym, objfile);

  603.     }
  604.   p++;

  605.   /* Determine the type of name being defined.  */
  606. #if 0
  607.   /* Getting GDB to correctly skip the symbol on an undefined symbol
  608.      descriptor and not ever dump core is a very dodgy proposition if
  609.      we do things this way.  I say the acorn RISC machine can just
  610.      fix their compiler.  */
  611.   /* The Acorn RISC machine's compiler can put out locals that don't
  612.      start with "234=" or "(3,4)=", so assume anything other than the
  613.      deftypes we know how to handle is a local.  */
  614.   if (!strchr ("cfFGpPrStTvVXCR", *p))
  615. #else
  616.   if (isdigit (*p) || *p == '(' || *p == '-')
  617. #endif
  618.     deftype = 'l';
  619.   else
  620.     deftype = *p++;

  621.   switch (deftype)
  622.     {
  623.     case 'c':
  624.       /* c is a special case, not followed by a type-number.
  625.          SYMBOL:c=iVALUE for an integer constant symbol.
  626.          SYMBOL:c=rVALUE for a floating constant symbol.
  627.          SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
  628.          e.g. "b:c=e6,0" for "const b = blob1"
  629.          (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
  630.       if (*p != '=')
  631.         {
  632.           SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  633.           SYMBOL_TYPE (sym) = error_type (&p, objfile);
  634.           SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  635.           add_symbol_to_list (sym, &file_symbols);
  636.           return sym;
  637.         }
  638.       ++p;
  639.       switch (*p++)
  640.         {
  641.         case 'r':
  642.           {
  643.             double d = atof (p);
  644.             gdb_byte *dbl_valu;
  645.             struct type *dbl_type;

  646.             /* FIXME-if-picky-about-floating-accuracy: Should be using
  647.                target arithmetic to get the value.  real.c in GCC
  648.                probably has the necessary code.  */

  649.             dbl_type = objfile_type (objfile)->builtin_double;
  650.             dbl_valu =
  651.               obstack_alloc (&objfile->objfile_obstack,
  652.                              TYPE_LENGTH (dbl_type));
  653.             store_typed_floating (dbl_valu, dbl_type, d);

  654.             SYMBOL_TYPE (sym) = dbl_type;
  655.             SYMBOL_VALUE_BYTES (sym) = dbl_valu;
  656.             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
  657.           }
  658.           break;
  659.         case 'i':
  660.           {
  661.             /* Defining integer constants this way is kind of silly,
  662.                since 'e' constants allows the compiler to give not
  663.                only the value, but the type as well.  C has at least
  664.                int, long, unsigned int, and long long as constant
  665.                types; other languages probably should have at least
  666.                unsigned as well as signed constants.  */

  667.             SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_long;
  668.             SYMBOL_VALUE (sym) = atoi (p);
  669.             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  670.           }
  671.           break;

  672.         case 'c':
  673.           {
  674.             SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_char;
  675.             SYMBOL_VALUE (sym) = atoi (p);
  676.             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  677.           }
  678.           break;

  679.         case 's':
  680.           {
  681.             struct type *range_type;
  682.             int ind = 0;
  683.             char quote = *p++;
  684.             gdb_byte *string_local = (gdb_byte *) alloca (strlen (p));
  685.             gdb_byte *string_value;

  686.             if (quote != '\'' && quote != '"')
  687.               {
  688.                 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  689.                 SYMBOL_TYPE (sym) = error_type (&p, objfile);
  690.                 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  691.                 add_symbol_to_list (sym, &file_symbols);
  692.                 return sym;
  693.               }

  694.             /* Find matching quote, rejecting escaped quotes.  */
  695.             while (*p && *p != quote)
  696.               {
  697.                 if (*p == '\\' && p[1] == quote)
  698.                   {
  699.                     string_local[ind] = (gdb_byte) quote;
  700.                     ind++;
  701.                     p += 2;
  702.                   }
  703.                 else if (*p)
  704.                   {
  705.                     string_local[ind] = (gdb_byte) (*p);
  706.                     ind++;
  707.                     p++;
  708.                   }
  709.               }
  710.             if (*p != quote)
  711.               {
  712.                 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  713.                 SYMBOL_TYPE (sym) = error_type (&p, objfile);
  714.                 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  715.                 add_symbol_to_list (sym, &file_symbols);
  716.                 return sym;
  717.               }

  718.             /* NULL terminate the string.  */
  719.             string_local[ind] = 0;
  720.             range_type
  721.               = create_static_range_type (NULL,
  722.                                           objfile_type (objfile)->builtin_int,
  723.                                           0, ind);
  724.             SYMBOL_TYPE (sym) = create_array_type (NULL,
  725.                                   objfile_type (objfile)->builtin_char,
  726.                                   range_type);
  727.             string_value = obstack_alloc (&objfile->objfile_obstack, ind + 1);
  728.             memcpy (string_value, string_local, ind + 1);
  729.             p++;

  730.             SYMBOL_VALUE_BYTES (sym) = string_value;
  731.             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
  732.           }
  733.           break;

  734.         case 'e':
  735.           /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
  736.              can be represented as integral.
  737.              e.g. "b:c=e6,0" for "const b = blob1"
  738.              (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
  739.           {
  740.             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  741.             SYMBOL_TYPE (sym) = read_type (&p, objfile);

  742.             if (*p != ',')
  743.               {
  744.                 SYMBOL_TYPE (sym) = error_type (&p, objfile);
  745.                 break;
  746.               }
  747.             ++p;

  748.             /* If the value is too big to fit in an int (perhaps because
  749.                it is unsigned), or something like that, we silently get
  750.                a bogus value.  The type and everything else about it is
  751.                correct.  Ideally, we should be using whatever we have
  752.                available for parsing unsigned and long long values,
  753.                however.  */
  754.             SYMBOL_VALUE (sym) = atoi (p);
  755.           }
  756.           break;
  757.         default:
  758.           {
  759.             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  760.             SYMBOL_TYPE (sym) = error_type (&p, objfile);
  761.           }
  762.         }
  763.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  764.       add_symbol_to_list (sym, &file_symbols);
  765.       return sym;

  766.     case 'C':
  767.       /* The name of a caught exception.  */
  768.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  769.       SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
  770.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  771.       SYMBOL_VALUE_ADDRESS (sym) = valu;
  772.       add_symbol_to_list (sym, &local_symbols);
  773.       break;

  774.     case 'f':
  775.       /* A static function definition.  */
  776.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  777.       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
  778.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  779.       add_symbol_to_list (sym, &file_symbols);
  780.       /* fall into process_function_types.  */

  781.     process_function_types:
  782.       /* Function result types are described as the result type in stabs.
  783.          We need to convert this to the function-returning-type-X type
  784.          in GDB.  E.g. "int" is converted to "function returning int".  */
  785.       if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
  786.         SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));

  787.       /* All functions in C++ have prototypes.  Stabs does not offer an
  788.          explicit way to identify prototyped or unprototyped functions,
  789.          but both GCC and Sun CC emit stabs for the "call-as" type rather
  790.          than the "declared-as" type for unprototyped functions, so
  791.          we treat all functions as if they were prototyped.  This is used
  792.          primarily for promotion when calling the function from GDB.  */
  793.       TYPE_PROTOTYPED (SYMBOL_TYPE (sym)) = 1;

  794.       /* fall into process_prototype_types.  */

  795.     process_prototype_types:
  796.       /* Sun acc puts declared types of arguments here.  */
  797.       if (*p == ';')
  798.         {
  799.           struct type *ftype = SYMBOL_TYPE (sym);
  800.           int nsemi = 0;
  801.           int nparams = 0;
  802.           char *p1 = p;

  803.           /* Obtain a worst case guess for the number of arguments
  804.              by counting the semicolons.  */
  805.           while (*p1)
  806.             {
  807.               if (*p1++ == ';')
  808.                 nsemi++;
  809.             }

  810.           /* Allocate parameter information fields and fill them in.  */
  811.           TYPE_FIELDS (ftype) = (struct field *)
  812.             TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
  813.           while (*p++ == ';')
  814.             {
  815.               struct type *ptype;

  816.               /* A type number of zero indicates the start of varargs.
  817.                  FIXME: GDB currently ignores vararg functions.  */
  818.               if (p[0] == '0' && p[1] == '\0')
  819.                 break;
  820.               ptype = read_type (&p, objfile);

  821.               /* The Sun compilers mark integer arguments, which should
  822.                  be promoted to the width of the calling conventions, with
  823.                  a type which references itself.  This type is turned into
  824.                  a TYPE_CODE_VOID type by read_type, and we have to turn
  825.                  it back into builtin_int here.
  826.                  FIXME: Do we need a new builtin_promoted_int_arg ?  */
  827.               if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
  828.                 ptype = objfile_type (objfile)->builtin_int;
  829.               TYPE_FIELD_TYPE (ftype, nparams) = ptype;
  830.               TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
  831.             }
  832.           TYPE_NFIELDS (ftype) = nparams;
  833.           TYPE_PROTOTYPED (ftype) = 1;
  834.         }
  835.       break;

  836.     case 'F':
  837.       /* A global function definition.  */
  838.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  839.       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
  840.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  841.       add_symbol_to_list (sym, &global_symbols);
  842.       goto process_function_types;

  843.     case 'G':
  844.       /* For a class G (global) symbol, it appears that the
  845.          value is not correct.  It is necessary to search for the
  846.          corresponding linker definition to find the value.
  847.          These definitions appear at the end of the namelist.  */
  848.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  849.       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
  850.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  851.       /* Don't add symbol references to global_sym_chain.
  852.          Symbol references don't have valid names and wont't match up with
  853.          minimal symbols when the global_sym_chain is relocated.
  854.          We'll fixup symbol references when we fixup the defining symbol.  */
  855.       if (SYMBOL_LINKAGE_NAME (sym) && SYMBOL_LINKAGE_NAME (sym)[0] != '#')
  856.         {
  857.           i = hashname (SYMBOL_LINKAGE_NAME (sym));
  858.           SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
  859.           global_sym_chain[i] = sym;
  860.         }
  861.       add_symbol_to_list (sym, &global_symbols);
  862.       break;

  863.       /* This case is faked by a conditional above,
  864.          when there is no code letter in the dbx data.
  865.          Dbx data never actually contains 'l'.  */
  866.     case 's':
  867.     case 'l':
  868.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  869.       SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
  870.       SYMBOL_VALUE (sym) = valu;
  871.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  872.       add_symbol_to_list (sym, &local_symbols);
  873.       break;

  874.     case 'p':
  875.       if (*p == 'F')
  876.         /* pF is a two-letter code that means a function parameter in Fortran.
  877.            The type-number specifies the type of the return value.
  878.            Translate it into a pointer-to-function type.  */
  879.         {
  880.           p++;
  881.           SYMBOL_TYPE (sym)
  882.             = lookup_pointer_type
  883.             (lookup_function_type (read_type (&p, objfile)));
  884.         }
  885.       else
  886.         SYMBOL_TYPE (sym) = read_type (&p, objfile);

  887.       SYMBOL_ACLASS_INDEX (sym) = LOC_ARG;
  888.       SYMBOL_VALUE (sym) = valu;
  889.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  890.       SYMBOL_IS_ARGUMENT (sym) = 1;
  891.       add_symbol_to_list (sym, &local_symbols);

  892.       if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
  893.         {
  894.           /* On little-endian machines, this crud is never necessary,
  895.              and, if the extra bytes contain garbage, is harmful.  */
  896.           break;
  897.         }

  898.       /* If it's gcc-compiled, if it says `short', believe it.  */
  899.       if (processing_gcc_compilation
  900.           || gdbarch_believe_pcc_promotion (gdbarch))
  901.         break;

  902.       if (!gdbarch_believe_pcc_promotion (gdbarch))
  903.         {
  904.           /* If PCC says a parameter is a short or a char, it is
  905.              really an int.  */
  906.           if (TYPE_LENGTH (SYMBOL_TYPE (sym))
  907.               < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
  908.               && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
  909.             {
  910.               SYMBOL_TYPE (sym) =
  911.                 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
  912.                 ? objfile_type (objfile)->builtin_unsigned_int
  913.                 : objfile_type (objfile)->builtin_int;
  914.             }
  915.           break;
  916.         }

  917.     case 'P':
  918.       /* acc seems to use P to declare the prototypes of functions that
  919.          are referenced by this file.  gdb is not prepared to deal
  920.          with this extra information.  FIXME, it ought to.  */
  921.       if (type == N_FUN)
  922.         {
  923.           SYMBOL_TYPE (sym) = read_type (&p, objfile);
  924.           goto process_prototype_types;
  925.         }
  926.       /*FALLTHROUGH */

  927.     case 'R':
  928.       /* Parameter which is in a register.  */
  929.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  930.       SYMBOL_ACLASS_INDEX (sym) = stab_register_index;
  931.       SYMBOL_IS_ARGUMENT (sym) = 1;
  932.       SYMBOL_VALUE (sym) = valu;
  933.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  934.       add_symbol_to_list (sym, &local_symbols);
  935.       break;

  936.     case 'r':
  937.       /* Register variable (either global or local).  */
  938.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  939.       SYMBOL_ACLASS_INDEX (sym) = stab_register_index;
  940.       SYMBOL_VALUE (sym) = valu;
  941.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  942.       if (within_function)
  943.         {
  944.           /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
  945.              the same name to represent an argument passed in a
  946.              register.  GCC uses 'P' for the same case.  So if we find
  947.              such a symbol pair we combine it into one 'P' symbol.
  948.              For Sun cc we need to do this regardless of
  949.              stabs_argument_has_addr, because the compiler puts out
  950.              the 'p' symbol even if it never saves the argument onto
  951.              the stack.

  952.              On most machines, we want to preserve both symbols, so
  953.              that we can still get information about what is going on
  954.              with the stack (VAX for computing args_printed, using
  955.              stack slots instead of saved registers in backtraces,
  956.              etc.).

  957.              Note that this code illegally combines
  958.              main(argc) struct foo argc; { register struct foo argc; }
  959.              but this case is considered pathological and causes a warning
  960.              from a decent compiler.  */

  961.           if (local_symbols
  962.               && local_symbols->nsyms > 0
  963.               && gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym)))
  964.             {
  965.               struct symbol *prev_sym;

  966.               prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
  967.               if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
  968.                    || SYMBOL_CLASS (prev_sym) == LOC_ARG)
  969.                   && strcmp (SYMBOL_LINKAGE_NAME (prev_sym),
  970.                              SYMBOL_LINKAGE_NAME (sym)) == 0)
  971.                 {
  972.                   SYMBOL_ACLASS_INDEX (prev_sym) = stab_register_index;
  973.                   /* Use the type from the LOC_REGISTER; that is the type
  974.                      that is actually in that register.  */
  975.                   SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
  976.                   SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
  977.                   sym = prev_sym;
  978.                   break;
  979.                 }
  980.             }
  981.           add_symbol_to_list (sym, &local_symbols);
  982.         }
  983.       else
  984.         add_symbol_to_list (sym, &file_symbols);
  985.       break;

  986.     case 'S':
  987.       /* Static symbol at top level of file.  */
  988.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  989.       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
  990.       SYMBOL_VALUE_ADDRESS (sym) = valu;
  991.       if (gdbarch_static_transform_name_p (gdbarch)
  992.           && gdbarch_static_transform_name (gdbarch,
  993.                                             SYMBOL_LINKAGE_NAME (sym))
  994.              != SYMBOL_LINKAGE_NAME (sym))
  995.         {
  996.           struct bound_minimal_symbol msym;

  997.           msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
  998.                                         NULL, objfile);
  999.           if (msym.minsym != NULL)
  1000.             {
  1001.               const char *new_name = gdbarch_static_transform_name
  1002.                 (gdbarch, SYMBOL_LINKAGE_NAME (sym));

  1003.               SYMBOL_SET_LINKAGE_NAME (sym, new_name);
  1004.               SYMBOL_VALUE_ADDRESS (sym) = BMSYMBOL_VALUE_ADDRESS (msym);
  1005.             }
  1006.         }
  1007.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  1008.       add_symbol_to_list (sym, &file_symbols);
  1009.       break;

  1010.     case 't':
  1011.       /* In Ada, there is no distinction between typedef and non-typedef;
  1012.          any type declaration implicitly has the equivalent of a typedef,
  1013.          and thus 't' is in fact equivalent to 'Tt'.

  1014.          Therefore, for Ada units, we check the character immediately
  1015.          before the 't', and if we do not find a 'T', then make sure to
  1016.          create the associated symbol in the STRUCT_DOMAIN ('t' definitions
  1017.          will be stored in the VAR_DOMAIN).  If the symbol was indeed
  1018.          defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
  1019.          elsewhere, so we don't need to take care of that.

  1020.          This is important to do, because of forward references:
  1021.          The cleanup of undefined types stored in undef_types only uses
  1022.          STRUCT_DOMAIN symbols to perform the replacement.  */
  1023.       synonym = (SYMBOL_LANGUAGE (sym) == language_ada && p[-2] != 'T');

  1024.       /* Typedef */
  1025.       SYMBOL_TYPE (sym) = read_type (&p, objfile);

  1026.       /* For a nameless type, we don't want a create a symbol, thus we
  1027.          did not use `sym'.  Return without further processing.  */
  1028.       if (nameless)
  1029.         return NULL;

  1030.       SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
  1031.       SYMBOL_VALUE (sym) = valu;
  1032.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  1033.       /* C++ vagaries: we may have a type which is derived from
  1034.          a base type which did not have its name defined when the
  1035.          derived class was output.  We fill in the derived class's
  1036.          base part member's name here in that case.  */
  1037.       if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
  1038.         if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
  1039.              || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
  1040.             && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
  1041.           {
  1042.             int j;

  1043.             for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
  1044.               if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
  1045.                 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
  1046.                   type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
  1047.           }

  1048.       if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
  1049.         {
  1050.           /* gcc-2.6 or later (when using -fvtable-thunks)
  1051.              emits a unique named type for a vtable entry.
  1052.              Some gdb code depends on that specific name.  */
  1053.           extern const char vtbl_ptr_name[];

  1054.           if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
  1055.                && strcmp (SYMBOL_LINKAGE_NAME (sym), vtbl_ptr_name))
  1056.               || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
  1057.             {
  1058.               /* If we are giving a name to a type such as "pointer to
  1059.                  foo" or "function returning foo", we better not set
  1060.                  the TYPE_NAME.  If the program contains "typedef char
  1061.                  *caddr_t;", we don't want all variables of type char
  1062.                  * to print as caddr_t.  This is not just a
  1063.                  consequence of GDB's type management; PCC and GCC (at
  1064.                  least through version 2.4) both output variables of
  1065.                  either type char * or caddr_t with the type number
  1066.                  defined in the 't' symbol for caddr_t.  If a future
  1067.                  compiler cleans this up it GDB is not ready for it
  1068.                  yet, but if it becomes ready we somehow need to
  1069.                  disable this check (without breaking the PCC/GCC2.4
  1070.                  case).

  1071.                  Sigh.

  1072.                  Fortunately, this check seems not to be necessary
  1073.                  for anything except pointers or functions.  */
  1074.               /* ezannoni: 2000-10-26.  This seems to apply for
  1075.                  versions of gcc older than 2.8.  This was the original
  1076.                  problem: with the following code gdb would tell that
  1077.                  the type for name1 is caddr_t, and func is char().

  1078.                  typedef char *caddr_t;
  1079.                  char *name2;
  1080.                  struct x
  1081.                  {
  1082.                    char *name1;
  1083.                  } xx;
  1084.                  char *func()
  1085.                  {
  1086.                  }
  1087.                  main () {}
  1088.                  */

  1089.               /* Pascal accepts names for pointer types.  */
  1090.               if (current_subfile->language == language_pascal)
  1091.                 {
  1092.                   TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
  1093.                   }
  1094.             }
  1095.           else
  1096.             TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
  1097.         }

  1098.       add_symbol_to_list (sym, &file_symbols);

  1099.       if (synonym)
  1100.         {
  1101.           /* Create the STRUCT_DOMAIN clone.  */
  1102.           struct symbol *struct_sym = allocate_symbol (objfile);

  1103.           *struct_sym = *sym;
  1104.           SYMBOL_ACLASS_INDEX (struct_sym) = LOC_TYPEDEF;
  1105.           SYMBOL_VALUE (struct_sym) = valu;
  1106.           SYMBOL_DOMAIN (struct_sym) = STRUCT_DOMAIN;
  1107.           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
  1108.             TYPE_NAME (SYMBOL_TYPE (sym))
  1109.               = obconcat (&objfile->objfile_obstack,
  1110.                           SYMBOL_LINKAGE_NAME (sym),
  1111.                           (char *) NULL);
  1112.           add_symbol_to_list (struct_sym, &file_symbols);
  1113.         }

  1114.       break;

  1115.     case 'T':
  1116.       /* Struct, union, or enum tag.  For GNU C++, this can be be followed
  1117.          by 't' which means we are typedef'ing it as well.  */
  1118.       synonym = *p == 't';

  1119.       if (synonym)
  1120.         p++;

  1121.       SYMBOL_TYPE (sym) = read_type (&p, objfile);

  1122.       /* For a nameless type, we don't want a create a symbol, thus we
  1123.          did not use `sym'.  Return without further processing.  */
  1124.       if (nameless)
  1125.         return NULL;

  1126.       SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
  1127.       SYMBOL_VALUE (sym) = valu;
  1128.       SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
  1129.       if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
  1130.         TYPE_TAG_NAME (SYMBOL_TYPE (sym))
  1131.           = obconcat (&objfile->objfile_obstack,
  1132.                       SYMBOL_LINKAGE_NAME (sym),
  1133.                       (char *) NULL);
  1134.       add_symbol_to_list (sym, &file_symbols);

  1135.       if (synonym)
  1136.         {
  1137.           /* Clone the sym and then modify it.  */
  1138.           struct symbol *typedef_sym = allocate_symbol (objfile);

  1139.           *typedef_sym = *sym;
  1140.           SYMBOL_ACLASS_INDEX (typedef_sym) = LOC_TYPEDEF;
  1141.           SYMBOL_VALUE (typedef_sym) = valu;
  1142.           SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
  1143.           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
  1144.             TYPE_NAME (SYMBOL_TYPE (sym))
  1145.               = obconcat (&objfile->objfile_obstack,
  1146.                           SYMBOL_LINKAGE_NAME (sym),
  1147.                           (char *) NULL);
  1148.           add_symbol_to_list (typedef_sym, &file_symbols);
  1149.         }
  1150.       break;

  1151.     case 'V':
  1152.       /* Static symbol of local scope.  */
  1153.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  1154.       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
  1155.       SYMBOL_VALUE_ADDRESS (sym) = valu;
  1156.       if (gdbarch_static_transform_name_p (gdbarch)
  1157.           && gdbarch_static_transform_name (gdbarch,
  1158.                                             SYMBOL_LINKAGE_NAME (sym))
  1159.              != SYMBOL_LINKAGE_NAME (sym))
  1160.         {
  1161.           struct bound_minimal_symbol msym;

  1162.           msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
  1163.                                         NULL, objfile);
  1164.           if (msym.minsym != NULL)
  1165.             {
  1166.               const char *new_name = gdbarch_static_transform_name
  1167.                 (gdbarch, SYMBOL_LINKAGE_NAME (sym));

  1168.               SYMBOL_SET_LINKAGE_NAME (sym, new_name);
  1169.               SYMBOL_VALUE_ADDRESS (sym) = BMSYMBOL_VALUE_ADDRESS (msym);
  1170.             }
  1171.         }
  1172.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  1173.         add_symbol_to_list (sym, &local_symbols);
  1174.       break;

  1175.     case 'v':
  1176.       /* Reference parameter */
  1177.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  1178.       SYMBOL_ACLASS_INDEX (sym) = LOC_REF_ARG;
  1179.       SYMBOL_IS_ARGUMENT (sym) = 1;
  1180.       SYMBOL_VALUE (sym) = valu;
  1181.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  1182.       add_symbol_to_list (sym, &local_symbols);
  1183.       break;

  1184.     case 'a':
  1185.       /* Reference parameter which is in a register.  */
  1186.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  1187.       SYMBOL_ACLASS_INDEX (sym) = stab_regparm_index;
  1188.       SYMBOL_IS_ARGUMENT (sym) = 1;
  1189.       SYMBOL_VALUE (sym) = valu;
  1190.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  1191.       add_symbol_to_list (sym, &local_symbols);
  1192.       break;

  1193.     case 'X':
  1194.       /* This is used by Sun FORTRAN for "function result value".
  1195.          Sun claims ("dbx and dbxtool interfaces", 2nd ed)
  1196.          that Pascal uses it too, but when I tried it Pascal used
  1197.          "x:3" (local symbol) instead.  */
  1198.       SYMBOL_TYPE (sym) = read_type (&p, objfile);
  1199.       SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
  1200.       SYMBOL_VALUE (sym) = valu;
  1201.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  1202.       add_symbol_to_list (sym, &local_symbols);
  1203.       break;

  1204.     default:
  1205.       SYMBOL_TYPE (sym) = error_type (&p, objfile);
  1206.       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  1207.       SYMBOL_VALUE (sym) = 0;
  1208.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  1209.       add_symbol_to_list (sym, &file_symbols);
  1210.       break;
  1211.     }

  1212.   /* Some systems pass variables of certain types by reference instead
  1213.      of by value, i.e. they will pass the address of a structure (in a
  1214.      register or on the stack) instead of the structure itself.  */

  1215.   if (gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym))
  1216.       && SYMBOL_IS_ARGUMENT (sym))
  1217.     {
  1218.       /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
  1219.          variables passed in a register).  */
  1220.       if (SYMBOL_CLASS (sym) == LOC_REGISTER)
  1221.         SYMBOL_ACLASS_INDEX (sym) = LOC_REGPARM_ADDR;
  1222.       /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
  1223.          and subsequent arguments on SPARC, for example).  */
  1224.       else if (SYMBOL_CLASS (sym) == LOC_ARG)
  1225.         SYMBOL_ACLASS_INDEX (sym) = LOC_REF_ARG;
  1226.     }

  1227.   return sym;
  1228. }

  1229. /* Skip rest of this symbol and return an error type.

  1230.    General notes on error recovery:  error_type always skips to the
  1231.    end of the symbol (modulo cretinous dbx symbol name continuation).
  1232.    Thus code like this:

  1233.    if (*(*pp)++ != ';')
  1234.    return error_type (pp, objfile);

  1235.    is wrong because if *pp starts out pointing at '\0' (typically as the
  1236.    result of an earlier error), it will be incremented to point to the
  1237.    start of the next symbol, which might produce strange results, at least
  1238.    if you run off the end of the string table.  Instead use

  1239.    if (**pp != ';')
  1240.    return error_type (pp, objfile);
  1241.    ++*pp;

  1242.    or

  1243.    if (**pp != ';')
  1244.    foo = error_type (pp, objfile);
  1245.    else
  1246.    ++*pp;

  1247.    And in case it isn't obvious, the point of all this hair is so the compiler
  1248.    can define new types and new syntaxes, and old versions of the
  1249.    debugger will be able to read the new symbol tables.  */

  1250. static struct type *
  1251. error_type (char **pp, struct objfile *objfile)
  1252. {
  1253.   complaint (&symfile_complaints,
  1254.              _("couldn't parse type; debugger out of date?"));
  1255.   while (1)
  1256.     {
  1257.       /* Skip to end of symbol.  */
  1258.       while (**pp != '\0')
  1259.         {
  1260.           (*pp)++;
  1261.         }

  1262.       /* Check for and handle cretinous dbx symbol name continuation!  */
  1263.       if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
  1264.         {
  1265.           *pp = next_symbol_text (objfile);
  1266.         }
  1267.       else
  1268.         {
  1269.           break;
  1270.         }
  1271.     }
  1272.   return objfile_type (objfile)->builtin_error;
  1273. }


  1274. /* Read type information or a type definition; return the type.  Even
  1275.    though this routine accepts either type information or a type
  1276.    definition, the distinction is relevant--some parts of stabsread.c
  1277.    assume that type information starts with a digit, '-', or '(' in
  1278.    deciding whether to call read_type.  */

  1279. static struct type *
  1280. read_type (char **pp, struct objfile *objfile)
  1281. {
  1282.   struct type *type = 0;
  1283.   struct type *type1;
  1284.   int typenums[2];
  1285.   char type_descriptor;

  1286.   /* Size in bits of type if specified by a type attribute, or -1 if
  1287.      there is no size attribute.  */
  1288.   int type_size = -1;

  1289.   /* Used to distinguish string and bitstring from char-array and set.  */
  1290.   int is_string = 0;

  1291.   /* Used to distinguish vector from array.  */
  1292.   int is_vector = 0;

  1293.   /* Read type number if present.  The type number may be omitted.
  1294.      for instance in a two-dimensional array declared with type
  1295.      "ar1;1;10;ar1;1;10;4".  */
  1296.   if ((**pp >= '0' && **pp <= '9')
  1297.       || **pp == '('
  1298.       || **pp == '-')
  1299.     {
  1300.       if (read_type_number (pp, typenums) != 0)
  1301.         return error_type (pp, objfile);

  1302.       if (**pp != '=')
  1303.         {
  1304.           /* Type is not being defined here.  Either it already
  1305.              exists, or this is a forward reference to it.
  1306.              dbx_alloc_type handles both cases.  */
  1307.           type = dbx_alloc_type (typenums, objfile);

  1308.           /* If this is a forward reference, arrange to complain if it
  1309.              doesn't get patched up by the time we're done
  1310.              reading.  */
  1311.           if (TYPE_CODE (type) == TYPE_CODE_UNDEF)
  1312.             add_undefined_type (type, typenums);

  1313.           return type;
  1314.         }

  1315.       /* Type is being defined here.  */
  1316.       /* Skip the '='.
  1317.          Also skip the type descriptor - we get it below with (*pp)[-1].  */
  1318.       (*pp) += 2;
  1319.     }
  1320.   else
  1321.     {
  1322.       /* 'typenums=' not present, type is anonymous.  Read and return
  1323.          the definition, but don't put it in the type vector.  */
  1324.       typenums[0] = typenums[1] = -1;
  1325.       (*pp)++;
  1326.     }

  1327. again:
  1328.   type_descriptor = (*pp)[-1];
  1329.   switch (type_descriptor)
  1330.     {
  1331.     case 'x':
  1332.       {
  1333.         enum type_code code;

  1334.         /* Used to index through file_symbols.  */
  1335.         struct pending *ppt;
  1336.         int i;

  1337.         /* Name including "struct", etc.  */
  1338.         char *type_name;

  1339.         {
  1340.           char *from, *to, *p, *q1, *q2;

  1341.           /* Set the type code according to the following letter.  */
  1342.           switch ((*pp)[0])
  1343.             {
  1344.             case 's':
  1345.               code = TYPE_CODE_STRUCT;
  1346.               break;
  1347.             case 'u':
  1348.               code = TYPE_CODE_UNION;
  1349.               break;
  1350.             case 'e':
  1351.               code = TYPE_CODE_ENUM;
  1352.               break;
  1353.             default:
  1354.               {
  1355.                 /* Complain and keep going, so compilers can invent new
  1356.                    cross-reference types.  */
  1357.                 complaint (&symfile_complaints,
  1358.                            _("Unrecognized cross-reference type `%c'"),
  1359.                            (*pp)[0]);
  1360.                 code = TYPE_CODE_STRUCT;
  1361.                 break;
  1362.               }
  1363.             }

  1364.           q1 = strchr (*pp, '<');
  1365.           p = strchr (*pp, ':');
  1366.           if (p == NULL)
  1367.             return error_type (pp, objfile);
  1368.           if (q1 && p > q1 && p[1] == ':')
  1369.             {
  1370.               int nesting_level = 0;

  1371.               for (q2 = q1; *q2; q2++)
  1372.                 {
  1373.                   if (*q2 == '<')
  1374.                     nesting_level++;
  1375.                   else if (*q2 == '>')
  1376.                     nesting_level--;
  1377.                   else if (*q2 == ':' && nesting_level == 0)
  1378.                     break;
  1379.                 }
  1380.               p = q2;
  1381.               if (*p != ':')
  1382.                 return error_type (pp, objfile);
  1383.             }
  1384.           type_name = NULL;
  1385.           if (current_subfile->language == language_cplus)
  1386.             {
  1387.               char *new_name, *name = alloca (p - *pp + 1);

  1388.               memcpy (name, *pp, p - *pp);
  1389.               name[p - *pp] = '\0';
  1390.               new_name = cp_canonicalize_string (name);
  1391.               if (new_name != NULL)
  1392.                 {
  1393.                   type_name = obstack_copy0 (&objfile->objfile_obstack,
  1394.                                              new_name, strlen (new_name));
  1395.                   xfree (new_name);
  1396.                 }
  1397.             }
  1398.           if (type_name == NULL)
  1399.             {
  1400.               to = type_name = (char *)
  1401.                 obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);

  1402.               /* Copy the name.  */
  1403.               from = *pp + 1;
  1404.               while (from < p)
  1405.                 *to++ = *from++;
  1406.               *to = '\0';
  1407.             }

  1408.           /* Set the pointer ahead of the name which we just read, and
  1409.              the colon.  */
  1410.           *pp = p + 1;
  1411.         }

  1412.         /* If this type has already been declared, then reuse the same
  1413.            type, rather than allocating a new one.  This saves some
  1414.            memory.  */

  1415.         for (ppt = file_symbols; ppt; ppt = ppt->next)
  1416.           for (i = 0; i < ppt->nsyms; i++)
  1417.             {
  1418.               struct symbol *sym = ppt->symbol[i];

  1419.               if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
  1420.                   && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
  1421.                   && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
  1422.                   && strcmp (SYMBOL_LINKAGE_NAME (sym), type_name) == 0)
  1423.                 {
  1424.                   obstack_free (&objfile->objfile_obstack, type_name);
  1425.                   type = SYMBOL_TYPE (sym);
  1426.                   if (typenums[0] != -1)
  1427.                     *dbx_lookup_type (typenums, objfile) = type;
  1428.                   return type;
  1429.                 }
  1430.             }

  1431.         /* Didn't find the type to which this refers, so we must
  1432.            be dealing with a forward reference.  Allocate a type
  1433.            structure for it, and keep track of it so we can
  1434.            fill in the rest of the fields when we get the full
  1435.            type.  */
  1436.         type = dbx_alloc_type (typenums, objfile);
  1437.         TYPE_CODE (type) = code;
  1438.         TYPE_TAG_NAME (type) = type_name;
  1439.         INIT_CPLUS_SPECIFIC (type);
  1440.         TYPE_STUB (type) = 1;

  1441.         add_undefined_type (type, typenums);
  1442.         return type;
  1443.       }

  1444.     case '-':                        /* RS/6000 built-in type */
  1445.     case '0':
  1446.     case '1':
  1447.     case '2':
  1448.     case '3':
  1449.     case '4':
  1450.     case '5':
  1451.     case '6':
  1452.     case '7':
  1453.     case '8':
  1454.     case '9':
  1455.     case '(':
  1456.       (*pp)--;

  1457.       /* We deal with something like t(1,2)=(3,4)=... which
  1458.          the Lucid compiler and recent gcc versions (post 2.7.3) use.  */

  1459.       /* Allocate and enter the typedef type first.
  1460.          This handles recursive types.  */
  1461.       type = dbx_alloc_type (typenums, objfile);
  1462.       TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
  1463.       {
  1464.         struct type *xtype = read_type (pp, objfile);

  1465.         if (type == xtype)
  1466.           {
  1467.             /* It's being defined as itself.  That means it is "void".  */
  1468.             TYPE_CODE (type) = TYPE_CODE_VOID;
  1469.             TYPE_LENGTH (type) = 1;
  1470.           }
  1471.         else if (type_size >= 0 || is_string)
  1472.           {
  1473.             /* This is the absolute wrong way to construct types.  Every
  1474.                other debug format has found a way around this problem and
  1475.                the related problems with unnecessarily stubbed types;
  1476.                someone motivated should attempt to clean up the issue
  1477.                here as well.  Once a type pointed to has been created it
  1478.                should not be modified.

  1479.                Well, it's not *absolutely* wrong.  Constructing recursive
  1480.                types (trees, linked lists) necessarily entails modifying
  1481.                types after creating them.  Constructing any loop structure
  1482.                entails side effects.  The Dwarf 2 reader does handle this
  1483.                more gracefully (it never constructs more than once
  1484.                instance of a type object, so it doesn't have to copy type
  1485.                objects wholesale), but it still mutates type objects after
  1486.                other folks have references to them.

  1487.                Keep in mind that this circularity/mutation issue shows up
  1488.                at the source language level, too: C's "incomplete types",
  1489.                for example.  So the proper cleanup, I think, would be to
  1490.                limit GDB's type smashing to match exactly those required
  1491.                by the source language.  So GDB could have a
  1492.                "complete_this_type" function, but never create unnecessary
  1493.                copies of a type otherwise.  */
  1494.             replace_type (type, xtype);
  1495.             TYPE_NAME (type) = NULL;
  1496.             TYPE_TAG_NAME (type) = NULL;
  1497.           }
  1498.         else
  1499.           {
  1500.             TYPE_TARGET_STUB (type) = 1;
  1501.             TYPE_TARGET_TYPE (type) = xtype;
  1502.           }
  1503.       }
  1504.       break;

  1505.       /* In the following types, we must be sure to overwrite any existing
  1506.          type that the typenums refer to, rather than allocating a new one
  1507.          and making the typenums point to the new one.  This is because there
  1508.          may already be pointers to the existing type (if it had been
  1509.          forward-referenced), and we must change it to a pointer, function,
  1510.          reference, or whatever, *in-place*.  */

  1511.     case '*':                        /* Pointer to another type */
  1512.       type1 = read_type (pp, objfile);
  1513.       type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile));
  1514.       break;

  1515.     case '&':                        /* Reference to another type */
  1516.       type1 = read_type (pp, objfile);
  1517.       type = make_reference_type (type1, dbx_lookup_type (typenums, objfile));
  1518.       break;

  1519.     case 'f':                        /* Function returning another type */
  1520.       type1 = read_type (pp, objfile);
  1521.       type = make_function_type (type1, dbx_lookup_type (typenums, objfile));
  1522.       break;

  1523.     case 'g':                   /* Prototyped function.  (Sun)  */
  1524.       {
  1525.         /* Unresolved questions:

  1526.            - According to Sun's ``STABS Interface Manual'', for 'f'
  1527.            and 'F' symbol descriptors, a `0' in the argument type list
  1528.            indicates a varargs function.  But it doesn't say how 'g'
  1529.            type descriptors represent that info.  Someone with access
  1530.            to Sun's toolchain should try it out.

  1531.            - According to the comment in define_symbol (search for
  1532.            `process_prototype_types:'), Sun emits integer arguments as
  1533.            types which ref themselves --- like `void' types.  Do we
  1534.            have to deal with that here, too?  Again, someone with
  1535.            access to Sun's toolchain should try it out and let us
  1536.            know.  */

  1537.         const char *type_start = (*pp) - 1;
  1538.         struct type *return_type = read_type (pp, objfile);
  1539.         struct type *func_type
  1540.           = make_function_type (return_type,
  1541.                                 dbx_lookup_type (typenums, objfile));
  1542.         struct type_list {
  1543.           struct type *type;
  1544.           struct type_list *next;
  1545.         } *arg_types = 0;
  1546.         int num_args = 0;

  1547.         while (**pp && **pp != '#')
  1548.           {
  1549.             struct type *arg_type = read_type (pp, objfile);
  1550.             struct type_list *new = alloca (sizeof (*new));
  1551.             new->type = arg_type;
  1552.             new->next = arg_types;
  1553.             arg_types = new;
  1554.             num_args++;
  1555.           }
  1556.         if (**pp == '#')
  1557.           ++*pp;
  1558.         else
  1559.           {
  1560.             complaint (&symfile_complaints,
  1561.                        _("Prototyped function type didn't "
  1562.                          "end arguments with `#':\n%s"),
  1563.                        type_start);
  1564.           }

  1565.         /* If there is just one argument whose type is `void', then
  1566.            that's just an empty argument list.  */
  1567.         if (arg_types
  1568.             && ! arg_types->next
  1569.             && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
  1570.           num_args = 0;

  1571.         TYPE_FIELDS (func_type)
  1572.           = (struct field *) TYPE_ALLOC (func_type,
  1573.                                          num_args * sizeof (struct field));
  1574.         memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
  1575.         {
  1576.           int i;
  1577.           struct type_list *t;

  1578.           /* We stuck each argument type onto the front of the list
  1579.              when we read it, so the list is reversed.  Build the
  1580.              fields array right-to-left.  */
  1581.           for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
  1582.             TYPE_FIELD_TYPE (func_type, i) = t->type;
  1583.         }
  1584.         TYPE_NFIELDS (func_type) = num_args;
  1585.         TYPE_PROTOTYPED (func_type) = 1;

  1586.         type = func_type;
  1587.         break;
  1588.       }

  1589.     case 'k':                        /* Const qualifier on some type (Sun) */
  1590.       type = read_type (pp, objfile);
  1591.       type = make_cv_type (1, TYPE_VOLATILE (type), type,
  1592.                            dbx_lookup_type (typenums, objfile));
  1593.       break;

  1594.     case 'B':                        /* Volatile qual on some type (Sun) */
  1595.       type = read_type (pp, objfile);
  1596.       type = make_cv_type (TYPE_CONST (type), 1, type,
  1597.                            dbx_lookup_type (typenums, objfile));
  1598.       break;

  1599.     case '@':
  1600.       if (isdigit (**pp) || **pp == '(' || **pp == '-')
  1601.         {                        /* Member (class & variable) type */
  1602.           /* FIXME -- we should be doing smash_to_XXX types here.  */

  1603.           struct type *domain = read_type (pp, objfile);
  1604.           struct type *memtype;

  1605.           if (**pp != ',')
  1606.             /* Invalid member type data format.  */
  1607.             return error_type (pp, objfile);
  1608.           ++*pp;

  1609.           memtype = read_type (pp, objfile);
  1610.           type = dbx_alloc_type (typenums, objfile);
  1611.           smash_to_memberptr_type (type, domain, memtype);
  1612.         }
  1613.       else
  1614.         /* type attribute */
  1615.         {
  1616.           char *attr = *pp;

  1617.           /* Skip to the semicolon.  */
  1618.           while (**pp != ';' && **pp != '\0')
  1619.             ++(*pp);
  1620.           if (**pp == '\0')
  1621.             return error_type (pp, objfile);
  1622.           else
  1623.             ++ * pp;                /* Skip the semicolon.  */

  1624.           switch (*attr)
  1625.             {
  1626.             case 's':                /* Size attribute */
  1627.               type_size = atoi (attr + 1);
  1628.               if (type_size <= 0)
  1629.                 type_size = -1;
  1630.               break;

  1631.             case 'S':                /* String attribute */
  1632.               /* FIXME: check to see if following type is array?  */
  1633.               is_string = 1;
  1634.               break;

  1635.             case 'V':                /* Vector attribute */
  1636.               /* FIXME: check to see if following type is array?  */
  1637.               is_vector = 1;
  1638.               break;

  1639.             default:
  1640.               /* Ignore unrecognized type attributes, so future compilers
  1641.                  can invent new ones.  */
  1642.               break;
  1643.             }
  1644.           ++*pp;
  1645.           goto again;
  1646.         }
  1647.       break;

  1648.     case '#':                        /* Method (class & fn) type */
  1649.       if ((*pp)[0] == '#')
  1650.         {
  1651.           /* We'll get the parameter types from the name.  */
  1652.           struct type *return_type;

  1653.           (*pp)++;
  1654.           return_type = read_type (pp, objfile);
  1655.           if (*(*pp)++ != ';')
  1656.             complaint (&symfile_complaints,
  1657.                        _("invalid (minimal) member type "
  1658.                          "data format at symtab pos %d."),
  1659.                        symnum);
  1660.           type = allocate_stub_method (return_type);
  1661.           if (typenums[0] != -1)
  1662.             *dbx_lookup_type (typenums, objfile) = type;
  1663.         }
  1664.       else
  1665.         {
  1666.           struct type *domain = read_type (pp, objfile);
  1667.           struct type *return_type;
  1668.           struct field *args;
  1669.           int nargs, varargs;

  1670.           if (**pp != ',')
  1671.             /* Invalid member type data format.  */
  1672.             return error_type (pp, objfile);
  1673.           else
  1674.             ++(*pp);

  1675.           return_type = read_type (pp, objfile);
  1676.           args = read_args (pp, ';', objfile, &nargs, &varargs);
  1677.           if (args == NULL)
  1678.             return error_type (pp, objfile);
  1679.           type = dbx_alloc_type (typenums, objfile);
  1680.           smash_to_method_type (type, domain, return_type, args,
  1681.                                 nargs, varargs);
  1682.         }
  1683.       break;

  1684.     case 'r':                        /* Range type */
  1685.       type = read_range_type (pp, typenums, type_size, objfile);
  1686.       if (typenums[0] != -1)
  1687.         *dbx_lookup_type (typenums, objfile) = type;
  1688.       break;

  1689.     case 'b':
  1690.         {
  1691.           /* Sun ACC builtin int type */
  1692.           type = read_sun_builtin_type (pp, typenums, objfile);
  1693.           if (typenums[0] != -1)
  1694.             *dbx_lookup_type (typenums, objfile) = type;
  1695.         }
  1696.       break;

  1697.     case 'R':                        /* Sun ACC builtin float type */
  1698.       type = read_sun_floating_type (pp, typenums, objfile);
  1699.       if (typenums[0] != -1)
  1700.         *dbx_lookup_type (typenums, objfile) = type;
  1701.       break;

  1702.     case 'e':                        /* Enumeration type */
  1703.       type = dbx_alloc_type (typenums, objfile);
  1704.       type = read_enum_type (pp, type, objfile);
  1705.       if (typenums[0] != -1)
  1706.         *dbx_lookup_type (typenums, objfile) = type;
  1707.       break;

  1708.     case 's':                        /* Struct type */
  1709.     case 'u':                        /* Union type */
  1710.       {
  1711.         enum type_code type_code = TYPE_CODE_UNDEF;
  1712.         type = dbx_alloc_type (typenums, objfile);
  1713.         switch (type_descriptor)
  1714.           {
  1715.           case 's':
  1716.             type_code = TYPE_CODE_STRUCT;
  1717.             break;
  1718.           case 'u':
  1719.             type_code = TYPE_CODE_UNION;
  1720.             break;
  1721.           }
  1722.         type = read_struct_type (pp, type, type_code, objfile);
  1723.         break;
  1724.       }

  1725.     case 'a':                        /* Array type */
  1726.       if (**pp != 'r')
  1727.         return error_type (pp, objfile);
  1728.       ++*pp;

  1729.       type = dbx_alloc_type (typenums, objfile);
  1730.       type = read_array_type (pp, type, objfile);
  1731.       if (is_string)
  1732.         TYPE_CODE (type) = TYPE_CODE_STRING;
  1733.       if (is_vector)
  1734.         make_vector_type (type);
  1735.       break;

  1736.     case 'S':                        /* Set type */
  1737.       type1 = read_type (pp, objfile);
  1738.       type = create_set_type ((struct type *) NULL, type1);
  1739.       if (typenums[0] != -1)
  1740.         *dbx_lookup_type (typenums, objfile) = type;
  1741.       break;

  1742.     default:
  1743.       --*pp;                        /* Go back to the symbol in error.  */
  1744.       /* Particularly important if it was \0!  */
  1745.       return error_type (pp, objfile);
  1746.     }

  1747.   if (type == 0)
  1748.     {
  1749.       warning (_("GDB internal error, type is NULL in stabsread.c."));
  1750.       return error_type (pp, objfile);
  1751.     }

  1752.   /* Size specified in a type attribute overrides any other size.  */
  1753.   if (type_size != -1)
  1754.     TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;

  1755.   return type;
  1756. }

  1757. /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
  1758.    Return the proper type node for a given builtin type number.  */

  1759. static const struct objfile_data *rs6000_builtin_type_data;

  1760. static struct type *
  1761. rs6000_builtin_type (int typenum, struct objfile *objfile)
  1762. {
  1763.   struct type **negative_types = objfile_data (objfile,
  1764.                                                rs6000_builtin_type_data);

  1765.   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
  1766. #define NUMBER_RECOGNIZED 34
  1767.   struct type *rettype = NULL;

  1768.   if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
  1769.     {
  1770.       complaint (&symfile_complaints, _("Unknown builtin type %d"), typenum);
  1771.       return objfile_type (objfile)->builtin_error;
  1772.     }

  1773.   if (!negative_types)
  1774.     {
  1775.       /* This includes an empty slot for type number -0.  */
  1776.       negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack,
  1777.                                        NUMBER_RECOGNIZED + 1, struct type *);
  1778.       set_objfile_data (objfile, rs6000_builtin_type_data, negative_types);
  1779.     }

  1780.   if (negative_types[-typenum] != NULL)
  1781.     return negative_types[-typenum];

  1782. #if TARGET_CHAR_BIT != 8
  1783. #error This code wrong for TARGET_CHAR_BIT not 8
  1784.   /* These definitions all assume that TARGET_CHAR_BIT is 8.  I think
  1785.      that if that ever becomes not true, the correct fix will be to
  1786.      make the size in the struct type to be in bits, not in units of
  1787.      TARGET_CHAR_BIT.  */
  1788. #endif

  1789.   switch (-typenum)
  1790.     {
  1791.     case 1:
  1792.       /* The size of this and all the other types are fixed, defined
  1793.          by the debugging format.  If there is a type called "int" which
  1794.          is other than 32 bits, then it should use a new negative type
  1795.          number (or avoid negative type numbers for that case).
  1796.          See stabs.texinfo.  */
  1797.       rettype = init_type (TYPE_CODE_INT, 4, 0, "int", objfile);
  1798.       break;
  1799.     case 2:
  1800.       rettype = init_type (TYPE_CODE_INT, 1, 0, "char", objfile);
  1801.       break;
  1802.     case 3:
  1803.       rettype = init_type (TYPE_CODE_INT, 2, 0, "short", objfile);
  1804.       break;
  1805.     case 4:
  1806.       rettype = init_type (TYPE_CODE_INT, 4, 0, "long", objfile);
  1807.       break;
  1808.     case 5:
  1809.       rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
  1810.                            "unsigned char", objfile);
  1811.       break;
  1812.     case 6:
  1813.       rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", objfile);
  1814.       break;
  1815.     case 7:
  1816.       rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
  1817.                            "unsigned short", objfile);
  1818.       break;
  1819.     case 8:
  1820.       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
  1821.                            "unsigned int", objfile);
  1822.       break;
  1823.     case 9:
  1824.       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
  1825.                            "unsigned", objfile);
  1826.       break;
  1827.     case 10:
  1828.       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
  1829.                            "unsigned long", objfile);
  1830.       break;
  1831.     case 11:
  1832.       rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", objfile);
  1833.       break;
  1834.     case 12:
  1835.       /* IEEE single precision (32 bit).  */
  1836.       rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", objfile);
  1837.       break;
  1838.     case 13:
  1839.       /* IEEE double precision (64 bit).  */
  1840.       rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", objfile);
  1841.       break;
  1842.     case 14:
  1843.       /* This is an IEEE double on the RS/6000, and different machines with
  1844.          different sizes for "long double" should use different negative
  1845.          type numbers.  See stabs.texinfo.  */
  1846.       rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", objfile);
  1847.       break;
  1848.     case 15:
  1849.       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", objfile);
  1850.       break;
  1851.     case 16:
  1852.       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
  1853.                            "boolean", objfile);
  1854.       break;
  1855.     case 17:
  1856.       rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", objfile);
  1857.       break;
  1858.     case 18:
  1859.       rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", objfile);
  1860.       break;
  1861.     case 19:
  1862.       rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", objfile);
  1863.       break;
  1864.     case 20:
  1865.       rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
  1866.                            "character", objfile);
  1867.       break;
  1868.     case 21:
  1869.       rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
  1870.                            "logical*1", objfile);
  1871.       break;
  1872.     case 22:
  1873.       rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
  1874.                            "logical*2", objfile);
  1875.       break;
  1876.     case 23:
  1877.       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
  1878.                            "logical*4", objfile);
  1879.       break;
  1880.     case 24:
  1881.       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
  1882.                            "logical", objfile);
  1883.       break;
  1884.     case 25:
  1885.       /* Complex type consisting of two IEEE single precision values.  */
  1886.       rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", objfile);
  1887.       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
  1888.                                               objfile);
  1889.       break;
  1890.     case 26:
  1891.       /* Complex type consisting of two IEEE double precision values.  */
  1892.       rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
  1893.       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
  1894.                                               objfile);
  1895.       break;
  1896.     case 27:
  1897.       rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", objfile);
  1898.       break;
  1899.     case 28:
  1900.       rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", objfile);
  1901.       break;
  1902.     case 29:
  1903.       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", objfile);
  1904.       break;
  1905.     case 30:
  1906.       rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", objfile);
  1907.       break;
  1908.     case 31:
  1909.       rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", objfile);
  1910.       break;
  1911.     case 32:
  1912.       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
  1913.                            "unsigned long long", objfile);
  1914.       break;
  1915.     case 33:
  1916.       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
  1917.                            "logical*8", objfile);
  1918.       break;
  1919.     case 34:
  1920.       rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", objfile);
  1921.       break;
  1922.     }
  1923.   negative_types[-typenum] = rettype;
  1924.   return rettype;
  1925. }

  1926. /* This page contains subroutines of read_type.  */

  1927. /* Wrapper around method_name_from_physname to flag a complaint
  1928.    if there is an error.  */

  1929. static char *
  1930. stabs_method_name_from_physname (const char *physname)
  1931. {
  1932.   char *method_name;

  1933.   method_name = method_name_from_physname (physname);

  1934.   if (method_name == NULL)
  1935.     {
  1936.       complaint (&symfile_complaints,
  1937.                  _("Method has bad physname %s\n"), physname);
  1938.       return NULL;
  1939.     }

  1940.   return method_name;
  1941. }

  1942. /* Read member function stabs info for C++ classes.  The form of each member
  1943.    function data is:

  1944.    NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;

  1945.    An example with two member functions is:

  1946.    afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;

  1947.    For the case of overloaded operators, the format is op$::*.funcs, where
  1948.    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
  1949.    name (such as `+=') and `.' marks the end of the operator name.

  1950.    Returns 1 for success, 0 for failure.  */

  1951. static int
  1952. read_member_functions (struct field_info *fip, char **pp, struct type *type,
  1953.                        struct objfile *objfile)
  1954. {
  1955.   int nfn_fields = 0;
  1956.   int length = 0;
  1957.   int i;
  1958.   struct next_fnfield
  1959.     {
  1960.       struct next_fnfield *next;
  1961.       struct fn_field fn_field;
  1962.     }
  1963.    *sublist;
  1964.   struct type *look_ahead_type;
  1965.   struct next_fnfieldlist *new_fnlist;
  1966.   struct next_fnfield *new_sublist;
  1967.   char *main_fn_name;
  1968.   char *p;

  1969.   /* Process each list until we find something that is not a member function
  1970.      or find the end of the functions.  */

  1971.   while (**pp != ';')
  1972.     {
  1973.       /* We should be positioned at the start of the function name.
  1974.          Scan forward to find the first ':' and if it is not the
  1975.          first of a "::" delimiter, then this is not a member function.  */
  1976.       p = *pp;
  1977.       while (*p != ':')
  1978.         {
  1979.           p++;
  1980.         }
  1981.       if (p[1] != ':')
  1982.         {
  1983.           break;
  1984.         }

  1985.       sublist = NULL;
  1986.       look_ahead_type = NULL;
  1987.       length = 0;

  1988.       new_fnlist = (struct next_fnfieldlist *)
  1989.         xmalloc (sizeof (struct next_fnfieldlist));
  1990.       make_cleanup (xfree, new_fnlist);
  1991.       memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));

  1992.       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
  1993.         {
  1994.           /* This is a completely wierd case.  In order to stuff in the
  1995.              names that might contain colons (the usual name delimiter),
  1996.              Mike Tiemann defined a different name format which is
  1997.              signalled if the identifier is "op$".  In that case, the
  1998.              format is "op$::XXXX." where XXXX is the name.  This is
  1999.              used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
  2000.           /* This lets the user type "break operator+".
  2001.              We could just put in "+" as the name, but that wouldn't
  2002.              work for "*".  */
  2003.           static char opname[32] = "op$";
  2004.           char *o = opname + 3;

  2005.           /* Skip past '::'.  */
  2006.           *pp = p + 2;

  2007.           STABS_CONTINUE (pp, objfile);
  2008.           p = *pp;
  2009.           while (*p != '.')
  2010.             {
  2011.               *o++ = *p++;
  2012.             }
  2013.           main_fn_name = savestring (opname, o - opname);
  2014.           /* Skip past '.'  */
  2015.           *pp = p + 1;
  2016.         }
  2017.       else
  2018.         {
  2019.           main_fn_name = savestring (*pp, p - *pp);
  2020.           /* Skip past '::'.  */
  2021.           *pp = p + 2;
  2022.         }
  2023.       new_fnlist->fn_fieldlist.name = main_fn_name;

  2024.       do
  2025.         {
  2026.           new_sublist =
  2027.             (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
  2028.           make_cleanup (xfree, new_sublist);
  2029.           memset (new_sublist, 0, sizeof (struct next_fnfield));

  2030.           /* Check for and handle cretinous dbx symbol name continuation!  */
  2031.           if (look_ahead_type == NULL)
  2032.             {
  2033.               /* Normal case.  */
  2034.               STABS_CONTINUE (pp, objfile);

  2035.               new_sublist->fn_field.type = read_type (pp, objfile);
  2036.               if (**pp != ':')
  2037.                 {
  2038.                   /* Invalid symtab info for member function.  */
  2039.                   return 0;
  2040.                 }
  2041.             }
  2042.           else
  2043.             {
  2044.               /* g++ version 1 kludge */
  2045.               new_sublist->fn_field.type = look_ahead_type;
  2046.               look_ahead_type = NULL;
  2047.             }

  2048.           (*pp)++;
  2049.           p = *pp;
  2050.           while (*p != ';')
  2051.             {
  2052.               p++;
  2053.             }

  2054.           /* If this is just a stub, then we don't have the real name here.  */

  2055.           if (TYPE_STUB (new_sublist->fn_field.type))
  2056.             {
  2057.               if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
  2058.                 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
  2059.               new_sublist->fn_field.is_stub = 1;
  2060.             }
  2061.           new_sublist->fn_field.physname = savestring (*pp, p - *pp);
  2062.           *pp = p + 1;

  2063.           /* Set this member function's visibility fields.  */
  2064.           switch (*(*pp)++)
  2065.             {
  2066.             case VISIBILITY_PRIVATE:
  2067.               new_sublist->fn_field.is_private = 1;
  2068.               break;
  2069.             case VISIBILITY_PROTECTED:
  2070.               new_sublist->fn_field.is_protected = 1;
  2071.               break;
  2072.             }

  2073.           STABS_CONTINUE (pp, objfile);
  2074.           switch (**pp)
  2075.             {
  2076.             case 'A':                /* Normal functions.  */
  2077.               new_sublist->fn_field.is_const = 0;
  2078.               new_sublist->fn_field.is_volatile = 0;
  2079.               (*pp)++;
  2080.               break;
  2081.             case 'B':                /* `const' member functions.  */
  2082.               new_sublist->fn_field.is_const = 1;
  2083.               new_sublist->fn_field.is_volatile = 0;
  2084.               (*pp)++;
  2085.               break;
  2086.             case 'C':                /* `volatile' member function.  */
  2087.               new_sublist->fn_field.is_const = 0;
  2088.               new_sublist->fn_field.is_volatile = 1;
  2089.               (*pp)++;
  2090.               break;
  2091.             case 'D':                /* `const volatile' member function.  */
  2092.               new_sublist->fn_field.is_const = 1;
  2093.               new_sublist->fn_field.is_volatile = 1;
  2094.               (*pp)++;
  2095.               break;
  2096.             case '*':                /* File compiled with g++ version 1 --
  2097.                                    no info.  */
  2098.             case '?':
  2099.             case '.':
  2100.               break;
  2101.             default:
  2102.               complaint (&symfile_complaints,
  2103.                          _("const/volatile indicator missing, got '%c'"),
  2104.                          **pp);
  2105.               break;
  2106.             }

  2107.           switch (*(*pp)++)
  2108.             {
  2109.             case '*':
  2110.               {
  2111.                 int nbits;
  2112.                 /* virtual member function, followed by index.
  2113.                    The sign bit is set to distinguish pointers-to-methods
  2114.                    from virtual function indicies.  Since the array is
  2115.                    in words, the quantity must be shifted left by 1
  2116.                    on 16 bit machine, and by 2 on 32 bit machine, forcing
  2117.                    the sign bit out, and usable as a valid index into
  2118.                    the array.  Remove the sign bit here.  */
  2119.                 new_sublist->fn_field.voffset =
  2120.                   (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2;
  2121.                 if (nbits != 0)
  2122.                   return 0;

  2123.                 STABS_CONTINUE (pp, objfile);
  2124.                 if (**pp == ';' || **pp == '\0')
  2125.                   {
  2126.                     /* Must be g++ version 1.  */
  2127.                     new_sublist->fn_field.fcontext = 0;
  2128.                   }
  2129.                 else
  2130.                   {
  2131.                     /* Figure out from whence this virtual function came.
  2132.                        It may belong to virtual function table of
  2133.                        one of its baseclasses.  */
  2134.                     look_ahead_type = read_type (pp, objfile);
  2135.                     if (**pp == ':')
  2136.                       {
  2137.                         /* g++ version 1 overloaded methods.  */
  2138.                       }
  2139.                     else
  2140.                       {
  2141.                         new_sublist->fn_field.fcontext = look_ahead_type;
  2142.                         if (**pp != ';')
  2143.                           {
  2144.                             return 0;
  2145.                           }
  2146.                         else
  2147.                           {
  2148.                             ++*pp;
  2149.                           }
  2150.                         look_ahead_type = NULL;
  2151.                       }
  2152.                   }
  2153.                 break;
  2154.               }
  2155.             case '?':
  2156.               /* static member function.  */
  2157.               {
  2158.                 int slen = strlen (main_fn_name);

  2159.                 new_sublist->fn_field.voffset = VOFFSET_STATIC;

  2160.                 /* For static member functions, we can't tell if they
  2161.                    are stubbed, as they are put out as functions, and not as
  2162.                    methods.
  2163.                    GCC v2 emits the fully mangled name if
  2164.                    dbxout.c:flag_minimal_debug is not set, so we have to
  2165.                    detect a fully mangled physname here and set is_stub
  2166.                    accordingly.  Fully mangled physnames in v2 start with
  2167.                    the member function name, followed by two underscores.
  2168.                    GCC v3 currently always emits stubbed member functions,
  2169.                    but with fully mangled physnames, which start with _Z.  */
  2170.                 if (!(strncmp (new_sublist->fn_field.physname,
  2171.                                main_fn_name, slen) == 0
  2172.                       && new_sublist->fn_field.physname[slen] == '_'
  2173.                       && new_sublist->fn_field.physname[slen + 1] == '_'))
  2174.                   {
  2175.                     new_sublist->fn_field.is_stub = 1;
  2176.                   }
  2177.                 break;
  2178.               }

  2179.             default:
  2180.               /* error */
  2181.               complaint (&symfile_complaints,
  2182.                          _("member function type missing, got '%c'"),
  2183.                          (*pp)[-1]);
  2184.               /* Fall through into normal member function.  */

  2185.             case '.':
  2186.               /* normal member function.  */
  2187.               new_sublist->fn_field.voffset = 0;
  2188.               new_sublist->fn_field.fcontext = 0;
  2189.               break;
  2190.             }

  2191.           new_sublist->next = sublist;
  2192.           sublist = new_sublist;
  2193.           length++;
  2194.           STABS_CONTINUE (pp, objfile);
  2195.         }
  2196.       while (**pp != ';' && **pp != '\0');

  2197.       (*pp)++;
  2198.       STABS_CONTINUE (pp, objfile);

  2199.       /* Skip GCC 3.X member functions which are duplicates of the callable
  2200.          constructor/destructor.  */
  2201.       if (strcmp_iw (main_fn_name, "__base_ctor ") == 0
  2202.           || strcmp_iw (main_fn_name, "__base_dtor ") == 0
  2203.           || strcmp (main_fn_name, "__deleting_dtor") == 0)
  2204.         {
  2205.           xfree (main_fn_name);
  2206.         }
  2207.       else
  2208.         {
  2209.           int has_stub = 0;
  2210.           int has_destructor = 0, has_other = 0;
  2211.           int is_v3 = 0;
  2212.           struct next_fnfield *tmp_sublist;

  2213.           /* Various versions of GCC emit various mostly-useless
  2214.              strings in the name field for special member functions.

  2215.              For stub methods, we need to defer correcting the name
  2216.              until we are ready to unstub the method, because the current
  2217.              name string is used by gdb_mangle_name.  The only stub methods
  2218.              of concern here are GNU v2 operators; other methods have their
  2219.              names correct (see caveat below).

  2220.              For non-stub methods, in GNU v3, we have a complete physname.
  2221.              Therefore we can safely correct the name now.  This primarily
  2222.              affects constructors and destructors, whose name will be
  2223.              __comp_ctor or __comp_dtor instead of Foo or ~Foo.  Cast
  2224.              operators will also have incorrect names; for instance,
  2225.              "operator int" will be named "operator i" (i.e. the type is
  2226.              mangled).

  2227.              For non-stub methods in GNU v2, we have no easy way to
  2228.              know if we have a complete physname or not.  For most
  2229.              methods the result depends on the platform (if CPLUS_MARKER
  2230.              can be `$' or `.', it will use minimal debug information, or
  2231.              otherwise the full physname will be included).

  2232.              Rather than dealing with this, we take a different approach.
  2233.              For v3 mangled names, we can use the full physname; for v2,
  2234.              we use cplus_demangle_opname (which is actually v2 specific),
  2235.              because the only interesting names are all operators - once again
  2236.              barring the caveat below.  Skip this process if any method in the
  2237.              group is a stub, to prevent our fouling up the workings of
  2238.              gdb_mangle_name.

  2239.              The caveat: GCC 2.95.x (and earlier?) put constructors and
  2240.              destructors in the same method group.  We need to split this
  2241.              into two groups, because they should have different names.
  2242.              So for each method group we check whether it contains both
  2243.              routines whose physname appears to be a destructor (the physnames
  2244.              for and destructors are always provided, due to quirks in v2
  2245.              mangling) and routines whose physname does not appear to be a
  2246.              destructor.  If so then we break up the list into two halves.
  2247.              Even if the constructors and destructors aren't in the same group
  2248.              the destructor will still lack the leading tilde, so that also
  2249.              needs to be fixed.

  2250.              So, to summarize what we expect and handle here:

  2251.                 Given         Given          Real         Real       Action
  2252.              method name     physname      physname   method name

  2253.              __opi            [none]     __opi__3Foo  operator int    opname
  2254.                                                                  [now or later]
  2255.              Foo              _._3Foo       _._3Foo      ~Foo      separate and
  2256.                                                                        rename
  2257.              operator i     _ZN3FoocviEv _ZN3FoocviEv operator int    demangle
  2258.              __comp_ctor  _ZN3FooC1ERKS_ _ZN3FooC1ERKS_   Foo         demangle
  2259.           */

  2260.           tmp_sublist = sublist;
  2261.           while (tmp_sublist != NULL)
  2262.             {
  2263.               if (tmp_sublist->fn_field.is_stub)
  2264.                 has_stub = 1;
  2265.               if (tmp_sublist->fn_field.physname[0] == '_'
  2266.                   && tmp_sublist->fn_field.physname[1] == 'Z')
  2267.                 is_v3 = 1;

  2268.               if (is_destructor_name (tmp_sublist->fn_field.physname))
  2269.                 has_destructor++;
  2270.               else
  2271.                 has_other++;

  2272.               tmp_sublist = tmp_sublist->next;
  2273.             }

  2274.           if (has_destructor && has_other)
  2275.             {
  2276.               struct next_fnfieldlist *destr_fnlist;
  2277.               struct next_fnfield *last_sublist;

  2278.               /* Create a new fn_fieldlist for the destructors.  */

  2279.               destr_fnlist = (struct next_fnfieldlist *)
  2280.                 xmalloc (sizeof (struct next_fnfieldlist));
  2281.               make_cleanup (xfree, destr_fnlist);
  2282.               memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
  2283.               destr_fnlist->fn_fieldlist.name
  2284.                 = obconcat (&objfile->objfile_obstack, "~",
  2285.                             new_fnlist->fn_fieldlist.name, (char *) NULL);

  2286.               destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
  2287.                 obstack_alloc (&objfile->objfile_obstack,
  2288.                                sizeof (struct fn_field) * has_destructor);
  2289.               memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
  2290.                   sizeof (struct fn_field) * has_destructor);
  2291.               tmp_sublist = sublist;
  2292.               last_sublist = NULL;
  2293.               i = 0;
  2294.               while (tmp_sublist != NULL)
  2295.                 {
  2296.                   if (!is_destructor_name (tmp_sublist->fn_field.physname))
  2297.                     {
  2298.                       tmp_sublist = tmp_sublist->next;
  2299.                       continue;
  2300.                     }

  2301.                   destr_fnlist->fn_fieldlist.fn_fields[i++]
  2302.                     = tmp_sublist->fn_field;
  2303.                   if (last_sublist)
  2304.                     last_sublist->next = tmp_sublist->next;
  2305.                   else
  2306.                     sublist = tmp_sublist->next;
  2307.                   last_sublist = tmp_sublist;
  2308.                   tmp_sublist = tmp_sublist->next;
  2309.                 }

  2310.               destr_fnlist->fn_fieldlist.length = has_destructor;
  2311.               destr_fnlist->next = fip->fnlist;
  2312.               fip->fnlist = destr_fnlist;
  2313.               nfn_fields++;
  2314.               length -= has_destructor;
  2315.             }
  2316.           else if (is_v3)
  2317.             {
  2318.               /* v3 mangling prevents the use of abbreviated physnames,
  2319.                  so we can do this here.  There are stubbed methods in v3
  2320.                  only:
  2321.                  - in -gstabs instead of -gstabs+
  2322.                  - or for static methods, which are output as a function type
  2323.                    instead of a method type.  */
  2324.               char *new_method_name =
  2325.                 stabs_method_name_from_physname (sublist->fn_field.physname);

  2326.               if (new_method_name != NULL
  2327.                   && strcmp (new_method_name,
  2328.                              new_fnlist->fn_fieldlist.name) != 0)
  2329.                 {
  2330.                   new_fnlist->fn_fieldlist.name = new_method_name;
  2331.                   xfree (main_fn_name);
  2332.                 }
  2333.               else
  2334.                 xfree (new_method_name);
  2335.             }
  2336.           else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
  2337.             {
  2338.               new_fnlist->fn_fieldlist.name =
  2339.                 obconcat (&objfile->objfile_obstack,
  2340.                           "~", main_fn_name, (char *)NULL);
  2341.               xfree (main_fn_name);
  2342.             }
  2343.           else if (!has_stub)
  2344.             {
  2345.               char dem_opname[256];
  2346.               int ret;

  2347.               ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
  2348.                                               dem_opname, DMGL_ANSI);
  2349.               if (!ret)
  2350.                 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
  2351.                                              dem_opname, 0);
  2352.               if (ret)
  2353.                 new_fnlist->fn_fieldlist.name
  2354.                   = obstack_copy0 (&objfile->objfile_obstack,
  2355.                                    dem_opname, strlen (dem_opname));
  2356.               xfree (main_fn_name);
  2357.             }

  2358.           new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
  2359.             obstack_alloc (&objfile->objfile_obstack,
  2360.                            sizeof (struct fn_field) * length);
  2361.           memset (new_fnlist->fn_fieldlist.fn_fields, 0,
  2362.                   sizeof (struct fn_field) * length);
  2363.           for (i = length; (i--, sublist); sublist = sublist->next)
  2364.             {
  2365.               new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
  2366.             }

  2367.           new_fnlist->fn_fieldlist.length = length;
  2368.           new_fnlist->next = fip->fnlist;
  2369.           fip->fnlist = new_fnlist;
  2370.           nfn_fields++;
  2371.         }
  2372.     }

  2373.   if (nfn_fields)
  2374.     {
  2375.       ALLOCATE_CPLUS_STRUCT_TYPE (type);
  2376.       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
  2377.         TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
  2378.       memset (TYPE_FN_FIELDLISTS (type), 0,
  2379.               sizeof (struct fn_fieldlist) * nfn_fields);
  2380.       TYPE_NFN_FIELDS (type) = nfn_fields;
  2381.     }

  2382.   return 1;
  2383. }

  2384. /* Special GNU C++ name.

  2385.    Returns 1 for success, 0 for failure.  "failure" means that we can't
  2386.    keep parsing and it's time for error_type().  */

  2387. static int
  2388. read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
  2389.                  struct objfile *objfile)
  2390. {
  2391.   char *p;
  2392.   const char *name;
  2393.   char cpp_abbrev;
  2394.   struct type *context;

  2395.   p = *pp;
  2396.   if (*++p == 'v')
  2397.     {
  2398.       name = NULL;
  2399.       cpp_abbrev = *++p;

  2400.       *pp = p + 1;

  2401.       /* At this point, *pp points to something like "22:23=*22...",
  2402.          where the type number before the ':' is the "context" and
  2403.          everything after is a regular type definition.  Lookup the
  2404.          type, find it's name, and construct the field name.  */

  2405.       context = read_type (pp, objfile);

  2406.       switch (cpp_abbrev)
  2407.         {
  2408.         case 'f':                /* $vf -- a virtual function table pointer */
  2409.           name = type_name_no_tag (context);
  2410.           if (name == NULL)
  2411.             {
  2412.               name = "";
  2413.             }
  2414.           fip->list->field.name = obconcat (&objfile->objfile_obstack,
  2415.                                             vptr_name, name, (char *) NULL);
  2416.           break;

  2417.         case 'b':                /* $vb -- a virtual bsomethingorother */
  2418.           name = type_name_no_tag (context);
  2419.           if (name == NULL)
  2420.             {
  2421.               complaint (&symfile_complaints,
  2422.                          _("C++ abbreviated type name "
  2423.                            "unknown at symtab pos %d"),
  2424.                          symnum);
  2425.               name = "FOO";
  2426.             }
  2427.           fip->list->field.name = obconcat (&objfile->objfile_obstack, vb_name,
  2428.                                             name, (char *) NULL);
  2429.           break;

  2430.         default:
  2431.           invalid_cpp_abbrev_complaint (*pp);
  2432.           fip->list->field.name = obconcat (&objfile->objfile_obstack,
  2433.                                             "INVALID_CPLUSPLUS_ABBREV",
  2434.                                             (char *) NULL);
  2435.           break;
  2436.         }

  2437.       /* At this point, *pp points to the ':'.  Skip it and read the
  2438.          field type.  */

  2439.       p = ++(*pp);
  2440.       if (p[-1] != ':')
  2441.         {
  2442.           invalid_cpp_abbrev_complaint (*pp);
  2443.           return 0;
  2444.         }
  2445.       fip->list->field.type = read_type (pp, objfile);
  2446.       if (**pp == ',')
  2447.         (*pp)++;                /* Skip the comma.  */
  2448.       else
  2449.         return 0;

  2450.       {
  2451.         int nbits;

  2452.         SET_FIELD_BITPOS (fip->list->field,
  2453.                           read_huge_number (pp, ';', &nbits, 0));
  2454.         if (nbits != 0)
  2455.           return 0;
  2456.       }
  2457.       /* This field is unpacked.  */
  2458.       FIELD_BITSIZE (fip->list->field) = 0;
  2459.       fip->list->visibility = VISIBILITY_PRIVATE;
  2460.     }
  2461.   else
  2462.     {
  2463.       invalid_cpp_abbrev_complaint (*pp);
  2464.       /* We have no idea what syntax an unrecognized abbrev would have, so
  2465.          better return 0.  If we returned 1, we would need to at least advance
  2466.          *pp to avoid an infinite loop.  */
  2467.       return 0;
  2468.     }
  2469.   return 1;
  2470. }

  2471. static void
  2472. read_one_struct_field (struct field_info *fip, char **pp, char *p,
  2473.                        struct type *type, struct objfile *objfile)
  2474. {
  2475.   struct gdbarch *gdbarch = get_objfile_arch (objfile);

  2476.   fip->list->field.name =
  2477.     obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
  2478.   *pp = p + 1;

  2479.   /* This means we have a visibility for a field coming.  */
  2480.   if (**pp == '/')
  2481.     {
  2482.       (*pp)++;
  2483.       fip->list->visibility = *(*pp)++;
  2484.     }
  2485.   else
  2486.     {
  2487.       /* normal dbx-style format, no explicit visibility */
  2488.       fip->list->visibility = VISIBILITY_PUBLIC;
  2489.     }

  2490.   fip->list->field.type = read_type (pp, objfile);
  2491.   if (**pp == ':')
  2492.     {
  2493.       p = ++(*pp);
  2494. #if 0
  2495.       /* Possible future hook for nested types.  */
  2496.       if (**pp == '!')
  2497.         {
  2498.           fip->list->field.bitpos = (long) -2;        /* nested type */
  2499.           p = ++(*pp);
  2500.         }
  2501.       else
  2502.         ...;
  2503. #endif
  2504.       while (*p != ';')
  2505.         {
  2506.           p++;
  2507.         }
  2508.       /* Static class member.  */
  2509.       SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
  2510.       *pp = p + 1;
  2511.       return;
  2512.     }
  2513.   else if (**pp != ',')
  2514.     {
  2515.       /* Bad structure-type format.  */
  2516.       stabs_general_complaint ("bad structure-type format");
  2517.       return;
  2518.     }

  2519.   (*pp)++;                        /* Skip the comma.  */

  2520.   {
  2521.     int nbits;

  2522.     SET_FIELD_BITPOS (fip->list->field,
  2523.                       read_huge_number (pp, ',', &nbits, 0));
  2524.     if (nbits != 0)
  2525.       {
  2526.         stabs_general_complaint ("bad structure-type format");
  2527.         return;
  2528.       }
  2529.     FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits, 0);
  2530.     if (nbits != 0)
  2531.       {
  2532.         stabs_general_complaint ("bad structure-type format");
  2533.         return;
  2534.       }
  2535.   }

  2536.   if (FIELD_BITPOS (fip->list->field) == 0
  2537.       && FIELD_BITSIZE (fip->list->field) == 0)
  2538.     {
  2539.       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
  2540.          it is a field which has been optimized out.  The correct stab for
  2541.          this case is to use VISIBILITY_IGNORE, but that is a recent
  2542.          invention.  (2) It is a 0-size array.  For example
  2543.          union { int num; char str[0]; } foo.  Printing _("<no value>" for
  2544.          str in "p foo" is OK, since foo.str (and thus foo.str[3])
  2545.          will continue to work, and a 0-size array as a whole doesn't
  2546.          have any contents to print.

  2547.          I suspect this probably could also happen with gcc -gstabs (not
  2548.          -gstabs+) for static fields, and perhaps other C++ extensions.
  2549.          Hopefully few people use -gstabs with gdb, since it is intended
  2550.          for dbx compatibility.  */

  2551.       /* Ignore this field.  */
  2552.       fip->list->visibility = VISIBILITY_IGNORE;
  2553.     }
  2554.   else
  2555.     {
  2556.       /* Detect an unpacked field and mark it as such.
  2557.          dbx gives a bit size for all fields.
  2558.          Note that forward refs cannot be packed,
  2559.          and treat enums as if they had the width of ints.  */

  2560.       struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));

  2561.       if (TYPE_CODE (field_type) != TYPE_CODE_INT
  2562.           && TYPE_CODE (field_type) != TYPE_CODE_RANGE
  2563.           && TYPE_CODE (field_type) != TYPE_CODE_BOOL
  2564.           && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
  2565.         {
  2566.           FIELD_BITSIZE (fip->list->field) = 0;
  2567.         }
  2568.       if ((FIELD_BITSIZE (fip->list->field)
  2569.            == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
  2570.            || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
  2571.                && FIELD_BITSIZE (fip->list->field)
  2572.                   == gdbarch_int_bit (gdbarch))
  2573.           )
  2574.           &&
  2575.           FIELD_BITPOS (fip->list->field) % 8 == 0)
  2576.         {
  2577.           FIELD_BITSIZE (fip->list->field) = 0;
  2578.         }
  2579.     }
  2580. }


  2581. /* Read struct or class data fields.  They have the form:

  2582.    NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;

  2583.    At the end, we see a semicolon instead of a field.

  2584.    In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
  2585.    a static field.

  2586.    The optional VISIBILITY is one of:

  2587.    '/0' (VISIBILITY_PRIVATE)
  2588.    '/1' (VISIBILITY_PROTECTED)
  2589.    '/2' (VISIBILITY_PUBLIC)
  2590.    '/9' (VISIBILITY_IGNORE)

  2591.    or nothing, for C style fields with public visibility.

  2592.    Returns 1 for success, 0 for failure.  */

  2593. static int
  2594. read_struct_fields (struct field_info *fip, char **pp, struct type *type,
  2595.                     struct objfile *objfile)
  2596. {
  2597.   char *p;
  2598.   struct nextfield *new;

  2599.   /* We better set p right now, in case there are no fields at all...    */

  2600.   p = *pp;

  2601.   /* Read each data member type until we find the terminating ';' at the end of
  2602.      the data member list, or break for some other reason such as finding the
  2603.      start of the member function list.  */
  2604.   /* Stab string for structure/union does not end with two ';' in
  2605.      SUN C compiler 5.3 i.e. F6U2, hence check for end of string.  */

  2606.   while (**pp != ';' && **pp != '\0')
  2607.     {
  2608.       STABS_CONTINUE (pp, objfile);
  2609.       /* Get space to record the next field's data.  */
  2610.       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
  2611.       make_cleanup (xfree, new);
  2612.       memset (new, 0, sizeof (struct nextfield));
  2613.       new->next = fip->list;
  2614.       fip->list = new;

  2615.       /* Get the field name.  */
  2616.       p = *pp;

  2617.       /* If is starts with CPLUS_MARKER it is a special abbreviation,
  2618.          unless the CPLUS_MARKER is followed by an underscore, in
  2619.          which case it is just the name of an anonymous type, which we
  2620.          should handle like any other type name.  */

  2621.       if (is_cplus_marker (p[0]) && p[1] != '_')
  2622.         {
  2623.           if (!read_cpp_abbrev (fip, pp, type, objfile))
  2624.             return 0;
  2625.           continue;
  2626.         }

  2627.       /* Look for the ':' that separates the field name from the field
  2628.          valuesData members are delimited by a single ':', while member
  2629.          functions are delimited by a pair of ':'s.  When we hit the member
  2630.          functions (if any), terminate scan loop and return.  */

  2631.       while (*p != ':' && *p != '\0')
  2632.         {
  2633.           p++;
  2634.         }
  2635.       if (*p == '\0')
  2636.         return 0;

  2637.       /* Check to see if we have hit the member functions yet.  */
  2638.       if (p[1] == ':')
  2639.         {
  2640.           break;
  2641.         }
  2642.       read_one_struct_field (fip, pp, p, type, objfile);
  2643.     }
  2644.   if (p[0] == ':' && p[1] == ':')
  2645.     {
  2646.       /* (the deleted) chill the list of fields: the last entry (at
  2647.          the head) is a partially constructed entry which we now
  2648.          scrub.  */
  2649.       fip->list = fip->list->next;
  2650.     }
  2651.   return 1;
  2652. }
  2653. /* *INDENT-OFF* */
  2654. /* The stabs for C++ derived classes contain baseclass information which
  2655.    is marked by a '!' character after the total size.  This function is
  2656.    called when we encounter the baseclass marker, and slurps up all the
  2657.    baseclass information.

  2658.    Immediately following the '!' marker is the number of base classes that
  2659.    the class is derived from, followed by information for each base class.
  2660.    For each base class, there are two visibility specifiers, a bit offset
  2661.    to the base class information within the derived class, a reference to
  2662.    the type for the base class, and a terminating semicolon.

  2663.    A typical example, with two base classes, would be "!2,020,19;0264,21;".
  2664.                                                           ^^ ^ ^ ^  ^ ^  ^
  2665.         Baseclass information marker __________________|| | | |  | |  |
  2666.         Number of baseclasses __________________________| | | |  | |  |
  2667.         Visibility specifiers (2) ________________________| | |  | |  |
  2668.         Offset in bits from start of class _________________| |  | |  |
  2669.         Type number for base class ___________________________|  | |  |
  2670.         Visibility specifiers (2) _______________________________| |  |
  2671.         Offset in bits from start of class ________________________|  |
  2672.         Type number of base class ____________________________________|

  2673.   Return 1 for success, 0 for (error-type-inducing) failure.  */
  2674. /* *INDENT-ON* */



  2675. static int
  2676. read_baseclasses (struct field_info *fip, char **pp, struct type *type,
  2677.                   struct objfile *objfile)
  2678. {
  2679.   int i;
  2680.   struct nextfield *new;

  2681.   if (**pp != '!')
  2682.     {
  2683.       return 1;
  2684.     }
  2685.   else
  2686.     {
  2687.       /* Skip the '!' baseclass information marker.  */
  2688.       (*pp)++;
  2689.     }

  2690.   ALLOCATE_CPLUS_STRUCT_TYPE (type);
  2691.   {
  2692.     int nbits;

  2693.     TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0);
  2694.     if (nbits != 0)
  2695.       return 0;
  2696.   }

  2697. #if 0
  2698.   /* Some stupid compilers have trouble with the following, so break
  2699.      it up into simpler expressions.  */
  2700.   TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
  2701.     TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
  2702. #else
  2703.   {
  2704.     int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
  2705.     char *pointer;

  2706.     pointer = (char *) TYPE_ALLOC (type, num_bytes);
  2707.     TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
  2708.   }
  2709. #endif /* 0 */

  2710.   B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));

  2711.   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
  2712.     {
  2713.       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
  2714.       make_cleanup (xfree, new);
  2715.       memset (new, 0, sizeof (struct nextfield));
  2716.       new->next = fip->list;
  2717.       fip->list = new;
  2718.       FIELD_BITSIZE (new->field) = 0;        /* This should be an unpacked
  2719.                                            field!  */

  2720.       STABS_CONTINUE (pp, objfile);
  2721.       switch (**pp)
  2722.         {
  2723.         case '0':
  2724.           /* Nothing to do.  */
  2725.           break;
  2726.         case '1':
  2727.           SET_TYPE_FIELD_VIRTUAL (type, i);
  2728.           break;
  2729.         default:
  2730.           /* Unknown character.  Complain and treat it as non-virtual.  */
  2731.           {
  2732.             complaint (&symfile_complaints,
  2733.                        _("Unknown virtual character `%c' for baseclass"),
  2734.                        **pp);
  2735.           }
  2736.         }
  2737.       ++(*pp);

  2738.       new->visibility = *(*pp)++;
  2739.       switch (new->visibility)
  2740.         {
  2741.         case VISIBILITY_PRIVATE:
  2742.         case VISIBILITY_PROTECTED:
  2743.         case VISIBILITY_PUBLIC:
  2744.           break;
  2745.         default:
  2746.           /* Bad visibility format.  Complain and treat it as
  2747.              public.  */
  2748.           {
  2749.             complaint (&symfile_complaints,
  2750.                        _("Unknown visibility `%c' for baseclass"),
  2751.                        new->visibility);
  2752.             new->visibility = VISIBILITY_PUBLIC;
  2753.           }
  2754.         }

  2755.       {
  2756.         int nbits;

  2757.         /* The remaining value is the bit offset of the portion of the object
  2758.            corresponding to this baseclass.  Always zero in the absence of
  2759.            multiple inheritance.  */

  2760.         SET_FIELD_BITPOS (new->field, read_huge_number (pp, ',', &nbits, 0));
  2761.         if (nbits != 0)
  2762.           return 0;
  2763.       }

  2764.       /* The last piece of baseclass information is the type of the
  2765.          base class.  Read it, and remember it's type name as this
  2766.          field's name.  */

  2767.       new->field.type = read_type (pp, objfile);
  2768.       new->field.name = type_name_no_tag (new->field.type);

  2769.       /* Skip trailing ';' and bump count of number of fields seen.  */
  2770.       if (**pp == ';')
  2771.         (*pp)++;
  2772.       else
  2773.         return 0;
  2774.     }
  2775.   return 1;
  2776. }

  2777. /* The tail end of stabs for C++ classes that contain a virtual function
  2778.    pointer contains a tilde, a %, and a type number.
  2779.    The type number refers to the base class (possibly this class itself) which
  2780.    contains the vtable pointer for the current class.

  2781.    This function is called when we have parsed all the method declarations,
  2782.    so we can look for the vptr base class info.  */

  2783. static int
  2784. read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
  2785.                    struct objfile *objfile)
  2786. {
  2787.   char *p;

  2788.   STABS_CONTINUE (pp, objfile);

  2789.   /* If we are positioned at a ';', then skip it.  */
  2790.   if (**pp == ';')
  2791.     {
  2792.       (*pp)++;
  2793.     }

  2794.   if (**pp == '~')
  2795.     {
  2796.       (*pp)++;

  2797.       if (**pp == '=' || **pp == '+' || **pp == '-')
  2798.         {
  2799.           /* Obsolete flags that used to indicate the presence
  2800.              of constructors and/or destructors.  */
  2801.           (*pp)++;
  2802.         }

  2803.       /* Read either a '%' or the final ';'.  */
  2804.       if (*(*pp)++ == '%')
  2805.         {
  2806.           /* The next number is the type number of the base class
  2807.              (possibly our own class) which supplies the vtable for
  2808.              this class.  Parse it out, and search that class to find
  2809.              its vtable pointer, and install those into TYPE_VPTR_BASETYPE
  2810.              and TYPE_VPTR_FIELDNO.  */

  2811.           struct type *t;
  2812.           int i;

  2813.           t = read_type (pp, objfile);
  2814.           p = (*pp)++;
  2815.           while (*p != '\0' && *p != ';')
  2816.             {
  2817.               p++;
  2818.             }
  2819.           if (*p == '\0')
  2820.             {
  2821.               /* Premature end of symbol.  */
  2822.               return 0;
  2823.             }

  2824.           TYPE_VPTR_BASETYPE (type) = t;
  2825.           if (type == t)        /* Our own class provides vtbl ptr.  */
  2826.             {
  2827.               for (i = TYPE_NFIELDS (t) - 1;
  2828.                    i >= TYPE_N_BASECLASSES (t);
  2829.                    --i)
  2830.                 {
  2831.                   const char *name = TYPE_FIELD_NAME (t, i);

  2832.                   if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
  2833.                       && is_cplus_marker (name[sizeof (vptr_name) - 2]))
  2834.                     {
  2835.                       TYPE_VPTR_FIELDNO (type) = i;
  2836.                       goto gotit;
  2837.                     }
  2838.                 }
  2839.               /* Virtual function table field not found.  */
  2840.               complaint (&symfile_complaints,
  2841.                          _("virtual function table pointer "
  2842.                            "not found when defining class `%s'"),
  2843.                          TYPE_NAME (type));
  2844.               return 0;
  2845.             }
  2846.           else
  2847.             {
  2848.               TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
  2849.             }

  2850.         gotit:
  2851.           *pp = p + 1;
  2852.         }
  2853.     }
  2854.   return 1;
  2855. }

  2856. static int
  2857. attach_fn_fields_to_type (struct field_info *fip, struct type *type)
  2858. {
  2859.   int n;

  2860.   for (n = TYPE_NFN_FIELDS (type);
  2861.        fip->fnlist != NULL;
  2862.        fip->fnlist = fip->fnlist->next)
  2863.     {
  2864.       --n;                        /* Circumvent Sun3 compiler bug.  */
  2865.       TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
  2866.     }
  2867.   return 1;
  2868. }

  2869. /* Create the vector of fields, and record how big it is.
  2870.    We need this info to record proper virtual function table information
  2871.    for this class's virtual functions.  */

  2872. static int
  2873. attach_fields_to_type (struct field_info *fip, struct type *type,
  2874.                        struct objfile *objfile)
  2875. {
  2876.   int nfields = 0;
  2877.   int non_public_fields = 0;
  2878.   struct nextfield *scan;

  2879.   /* Count up the number of fields that we have, as well as taking note of
  2880.      whether or not there are any non-public fields, which requires us to
  2881.      allocate and build the private_field_bits and protected_field_bits
  2882.      bitfields.  */

  2883.   for (scan = fip->list; scan != NULL; scan = scan->next)
  2884.     {
  2885.       nfields++;
  2886.       if (scan->visibility != VISIBILITY_PUBLIC)
  2887.         {
  2888.           non_public_fields++;
  2889.         }
  2890.     }

  2891.   /* Now we know how many fields there are, and whether or not there are any
  2892.      non-public fields.  Record the field count, allocate space for the
  2893.      array of fields, and create blank visibility bitfields if necessary.  */

  2894.   TYPE_NFIELDS (type) = nfields;
  2895.   TYPE_FIELDS (type) = (struct field *)
  2896.     TYPE_ALLOC (type, sizeof (struct field) * nfields);
  2897.   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);

  2898.   if (non_public_fields)
  2899.     {
  2900.       ALLOCATE_CPLUS_STRUCT_TYPE (type);

  2901.       TYPE_FIELD_PRIVATE_BITS (type) =
  2902.         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
  2903.       B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);

  2904.       TYPE_FIELD_PROTECTED_BITS (type) =
  2905.         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
  2906.       B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);

  2907.       TYPE_FIELD_IGNORE_BITS (type) =
  2908.         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
  2909.       B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
  2910.     }

  2911.   /* Copy the saved-up fields into the field vector.  Start from the
  2912.      head of the list, adding to the tail of the field array, so that
  2913.      they end up in the same order in the array in which they were
  2914.      added to the list.  */

  2915.   while (nfields-- > 0)
  2916.     {
  2917.       TYPE_FIELD (type, nfields) = fip->list->field;
  2918.       switch (fip->list->visibility)
  2919.         {
  2920.         case VISIBILITY_PRIVATE:
  2921.           SET_TYPE_FIELD_PRIVATE (type, nfields);
  2922.           break;

  2923.         case VISIBILITY_PROTECTED:
  2924.           SET_TYPE_FIELD_PROTECTED (type, nfields);
  2925.           break;

  2926.         case VISIBILITY_IGNORE:
  2927.           SET_TYPE_FIELD_IGNORE (type, nfields);
  2928.           break;

  2929.         case VISIBILITY_PUBLIC:
  2930.           break;

  2931.         default:
  2932.           /* Unknown visibility.  Complain and treat it as public.  */
  2933.           {
  2934.             complaint (&symfile_complaints,
  2935.                        _("Unknown visibility `%c' for field"),
  2936.                        fip->list->visibility);
  2937.           }
  2938.           break;
  2939.         }
  2940.       fip->list = fip->list->next;
  2941.     }
  2942.   return 1;
  2943. }


  2944. /* Complain that the compiler has emitted more than one definition for the
  2945.    structure type TYPE.  */
  2946. static void
  2947. complain_about_struct_wipeout (struct type *type)
  2948. {
  2949.   const char *name = "";
  2950.   const char *kind = "";

  2951.   if (TYPE_TAG_NAME (type))
  2952.     {
  2953.       name = TYPE_TAG_NAME (type);
  2954.       switch (TYPE_CODE (type))
  2955.         {
  2956.         case TYPE_CODE_STRUCT: kind = "struct "; break;
  2957.         case TYPE_CODE_UNION:  kind = "union "break;
  2958.         case TYPE_CODE_ENUM:   kind = "enum ";   break;
  2959.         default: kind = "";
  2960.         }
  2961.     }
  2962.   else if (TYPE_NAME (type))
  2963.     {
  2964.       name = TYPE_NAME (type);
  2965.       kind = "";
  2966.     }
  2967.   else
  2968.     {
  2969.       name = "<unknown>";
  2970.       kind = "";
  2971.     }

  2972.   complaint (&symfile_complaints,
  2973.              _("struct/union type gets multiply defined: %s%s"), kind, name);
  2974. }

  2975. /* Set the length for all variants of a same main_type, which are
  2976.    connected in the closed chain.

  2977.    This is something that needs to be done when a type is defined *after*
  2978.    some cross references to this type have already been read.  Consider
  2979.    for instance the following scenario where we have the following two
  2980.    stabs entries:

  2981.         .stabs  "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
  2982.         .stabs  "dummy:T(0,23)=s16x:(0,1),0,3[...]"

  2983.    A stubbed version of type dummy is created while processing the first
  2984.    stabs entry.  The length of that type is initially set to zero, since
  2985.    it is unknown at this point.  Also, a "constant" variation of type
  2986.    "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
  2987.    the stabs line).

  2988.    The second stabs entry allows us to replace the stubbed definition
  2989.    with the real definition.  However, we still need to adjust the length
  2990.    of the "constant" variation of that type, as its length was left
  2991.    untouched during the main type replacement...  */

  2992. static void
  2993. set_length_in_type_chain (struct type *type)
  2994. {
  2995.   struct type *ntype = TYPE_CHAIN (type);

  2996.   while (ntype != type)
  2997.     {
  2998.       if (TYPE_LENGTH(ntype) == 0)
  2999.         TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
  3000.       else
  3001.         complain_about_struct_wipeout (ntype);
  3002.       ntype = TYPE_CHAIN (ntype);
  3003.     }
  3004. }

  3005. /* Read the description of a structure (or union type) and return an object
  3006.    describing the type.

  3007.    PP points to a character pointer that points to the next unconsumed token
  3008.    in the stabs string.  For example, given stabs "A:T4=s4a:1,0,32;;",
  3009.    *PP will point to "4a:1,0,32;;".

  3010.    TYPE points to an incomplete type that needs to be filled in.

  3011.    OBJFILE points to the current objfile from which the stabs information is
  3012.    being read.  (Note that it is redundant in that TYPE also contains a pointer
  3013.    to this same objfile, so it might be a good idea to eliminate it.  FIXME).
  3014. */

  3015. static struct type *
  3016. read_struct_type (char **pp, struct type *type, enum type_code type_code,
  3017.                   struct objfile *objfile)
  3018. {
  3019.   struct cleanup *back_to;
  3020.   struct field_info fi;

  3021.   fi.list = NULL;
  3022.   fi.fnlist = NULL;

  3023.   /* When describing struct/union/class types in stabs, G++ always drops
  3024.      all qualifications from the name.  So if you've got:
  3025.        struct A { ... struct B { ... }; ... };
  3026.      then G++ will emit stabs for `struct A::B' that call it simply
  3027.      `struct B'.  Obviously, if you've got a real top-level definition for
  3028.      `struct B', or other nested definitions, this is going to cause
  3029.      problems.

  3030.      Obviously, GDB can't fix this by itself, but it can at least avoid
  3031.      scribbling on existing structure type objects when new definitions
  3032.      appear.  */
  3033.   if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
  3034.          || TYPE_STUB (type)))
  3035.     {
  3036.       complain_about_struct_wipeout (type);

  3037.       /* It's probably best to return the type unchanged.  */
  3038.       return type;
  3039.     }

  3040.   back_to = make_cleanup (null_cleanup, 0);

  3041.   INIT_CPLUS_SPECIFIC (type);
  3042.   TYPE_CODE (type) = type_code;
  3043.   TYPE_STUB (type) = 0;

  3044.   /* First comes the total size in bytes.  */

  3045.   {
  3046.     int nbits;

  3047.     TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits, 0);
  3048.     if (nbits != 0)
  3049.       {
  3050.         do_cleanups (back_to);
  3051.         return error_type (pp, objfile);
  3052.       }
  3053.     set_length_in_type_chain (type);
  3054.   }

  3055.   /* Now read the baseclasses, if any, read the regular C struct or C++
  3056.      class member fields, attach the fields to the type, read the C++
  3057.      member functions, attach them to the type, and then read any tilde
  3058.      field (baseclass specifier for the class holding the main vtable).  */

  3059.   if (!read_baseclasses (&fi, pp, type, objfile)
  3060.       || !read_struct_fields (&fi, pp, type, objfile)
  3061.       || !attach_fields_to_type (&fi, type, objfile)
  3062.       || !read_member_functions (&fi, pp, type, objfile)
  3063.       || !attach_fn_fields_to_type (&fi, type)
  3064.       || !read_tilde_fields (&fi, pp, type, objfile))
  3065.     {
  3066.       type = error_type (pp, objfile);
  3067.     }

  3068.   do_cleanups (back_to);
  3069.   return (type);
  3070. }

  3071. /* Read a definition of an array type,
  3072.    and create and return a suitable type object.
  3073.    Also creates a range type which represents the bounds of that
  3074.    array.  */

  3075. static struct type *
  3076. read_array_type (char **pp, struct type *type,
  3077.                  struct objfile *objfile)
  3078. {
  3079.   struct type *index_type, *element_type, *range_type;
  3080.   int lower, upper;
  3081.   int adjustable = 0;
  3082.   int nbits;

  3083.   /* Format of an array type:
  3084.      "ar<index type>;lower;upper;<array_contents_type>".
  3085.      OS9000: "arlower,upper;<array_contents_type>".

  3086.      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
  3087.      for these, produce a type like float[][].  */

  3088.     {
  3089.       index_type = read_type (pp, objfile);
  3090.       if (**pp != ';')
  3091.         /* Improper format of array type decl.  */
  3092.         return error_type (pp, objfile);
  3093.       ++*pp;
  3094.     }

  3095.   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
  3096.     {
  3097.       (*pp)++;
  3098.       adjustable = 1;
  3099.     }
  3100.   lower = read_huge_number (pp, ';', &nbits, 0);

  3101.   if (nbits != 0)
  3102.     return error_type (pp, objfile);

  3103.   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
  3104.     {
  3105.       (*pp)++;
  3106.       adjustable = 1;
  3107.     }
  3108.   upper = read_huge_number (pp, ';', &nbits, 0);
  3109.   if (nbits != 0)
  3110.     return error_type (pp, objfile);

  3111.   element_type = read_type (pp, objfile);

  3112.   if (adjustable)
  3113.     {
  3114.       lower = 0;
  3115.       upper = -1;
  3116.     }

  3117.   range_type =
  3118.     create_static_range_type ((struct type *) NULL, index_type, lower, upper);
  3119.   type = create_array_type (type, element_type, range_type);

  3120.   return type;
  3121. }


  3122. /* Read a definition of an enumeration type,
  3123.    and create and return a suitable type object.
  3124.    Also defines the symbols that represent the values of the type.  */

  3125. static struct type *
  3126. read_enum_type (char **pp, struct type *type,
  3127.                 struct objfile *objfile)
  3128. {
  3129.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  3130.   char *p;
  3131.   char *name;
  3132.   long n;
  3133.   struct symbol *sym;
  3134.   int nsyms = 0;
  3135.   struct pending **symlist;
  3136.   struct pending *osyms, *syms;
  3137.   int o_nsyms;
  3138.   int nbits;
  3139.   int unsigned_enum = 1;

  3140. #if 0
  3141.   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
  3142.      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
  3143.      to do?  For now, force all enum values to file scope.  */
  3144.   if (within_function)
  3145.     symlist = &local_symbols;
  3146.   else
  3147. #endif
  3148.     symlist = &file_symbols;
  3149.   osyms = *symlist;
  3150.   o_nsyms = osyms ? osyms->nsyms : 0;

  3151.   /* The aix4 compiler emits an extra field before the enum members;
  3152.      my guess is it's a type of some sort.  Just ignore it.  */
  3153.   if (**pp == '-')
  3154.     {
  3155.       /* Skip over the type.  */
  3156.       while (**pp != ':')
  3157.         (*pp)++;

  3158.       /* Skip over the colon.  */
  3159.       (*pp)++;
  3160.     }

  3161.   /* Read the value-names and their values.
  3162.      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
  3163.      A semicolon or comma instead of a NAME means the end.  */
  3164.   while (**pp && **pp != ';' && **pp != ',')
  3165.     {
  3166.       STABS_CONTINUE (pp, objfile);
  3167.       p = *pp;
  3168.       while (*p != ':')
  3169.         p++;
  3170.       name = obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
  3171.       *pp = p + 1;
  3172.       n = read_huge_number (pp, ',', &nbits, 0);
  3173.       if (nbits != 0)
  3174.         return error_type (pp, objfile);

  3175.       sym = allocate_symbol (objfile);
  3176.       SYMBOL_SET_LINKAGE_NAME (sym, name);
  3177.       SYMBOL_SET_LANGUAGE (sym, current_subfile->language,
  3178.                            &objfile->objfile_obstack);
  3179.       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
  3180.       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
  3181.       SYMBOL_VALUE (sym) = n;
  3182.       if (n < 0)
  3183.         unsigned_enum = 0;
  3184.       add_symbol_to_list (sym, symlist);
  3185.       nsyms++;
  3186.     }

  3187.   if (**pp == ';')
  3188.     (*pp)++;                        /* Skip the semicolon.  */

  3189.   /* Now fill in the fields of the type-structure.  */

  3190.   TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
  3191.   set_length_in_type_chain (type);
  3192.   TYPE_CODE (type) = TYPE_CODE_ENUM;
  3193.   TYPE_STUB (type) = 0;
  3194.   if (unsigned_enum)
  3195.     TYPE_UNSIGNED (type) = 1;
  3196.   TYPE_NFIELDS (type) = nsyms;
  3197.   TYPE_FIELDS (type) = (struct field *)
  3198.     TYPE_ALLOC (type, sizeof (struct field) * nsyms);
  3199.   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);

  3200.   /* Find the symbols for the values and put them into the type.
  3201.      The symbols can be found in the symlist that we put them on
  3202.      to cause them to be defined.  osyms contains the old value
  3203.      of that symlist; everything up to there was defined by us.  */
  3204.   /* Note that we preserve the order of the enum constants, so
  3205.      that in something like "enum {FOO, LAST_THING=FOO}" we print
  3206.      FOO, not LAST_THING.  */

  3207.   for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
  3208.     {
  3209.       int last = syms == osyms ? o_nsyms : 0;
  3210.       int j = syms->nsyms;

  3211.       for (; --j >= last; --n)
  3212.         {
  3213.           struct symbol *xsym = syms->symbol[j];

  3214.           SYMBOL_TYPE (xsym) = type;
  3215.           TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
  3216.           SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
  3217.           TYPE_FIELD_BITSIZE (type, n) = 0;
  3218.         }
  3219.       if (syms == osyms)
  3220.         break;
  3221.     }

  3222.   return type;
  3223. }

  3224. /* Sun's ACC uses a somewhat saner method for specifying the builtin
  3225.    typedefs in every file (for int, long, etc):

  3226.    type = b <signed> <width> <format type>; <offset>; <nbits>
  3227.    signed = u or s.
  3228.    optional format type = c or b for char or boolean.
  3229.    offset = offset from high order bit to start bit of type.
  3230.    width is # bytes in object of this type, nbits is # bits in type.

  3231.    The width/offset stuff appears to be for small objects stored in
  3232.    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
  3233.    FIXME.  */

  3234. static struct type *
  3235. read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
  3236. {
  3237.   int type_bits;
  3238.   int nbits;
  3239.   int signed_type;
  3240.   enum type_code code = TYPE_CODE_INT;

  3241.   switch (**pp)
  3242.     {
  3243.     case 's':
  3244.       signed_type = 1;
  3245.       break;
  3246.     case 'u':
  3247.       signed_type = 0;
  3248.       break;
  3249.     default:
  3250.       return error_type (pp, objfile);
  3251.     }
  3252.   (*pp)++;

  3253.   /* For some odd reason, all forms of char put a c here.  This is strange
  3254.      because no other type has this honor.  We can safely ignore this because
  3255.      we actually determine 'char'acterness by the number of bits specified in
  3256.      the descriptor.
  3257.      Boolean forms, e.g Fortran logical*X, put a b here.  */

  3258.   if (**pp == 'c')
  3259.     (*pp)++;
  3260.   else if (**pp == 'b')
  3261.     {
  3262.       code = TYPE_CODE_BOOL;
  3263.       (*pp)++;
  3264.     }

  3265.   /* The first number appears to be the number of bytes occupied
  3266.      by this type, except that unsigned short is 4 instead of 2.
  3267.      Since this information is redundant with the third number,
  3268.      we will ignore it.  */
  3269.   read_huge_number (pp, ';', &nbits, 0);
  3270.   if (nbits != 0)
  3271.     return error_type (pp, objfile);

  3272.   /* The second number is always 0, so ignore it too.  */
  3273.   read_huge_number (pp, ';', &nbits, 0);
  3274.   if (nbits != 0)
  3275.     return error_type (pp, objfile);

  3276.   /* The third number is the number of bits for this type.  */
  3277.   type_bits = read_huge_number (pp, 0, &nbits, 0);
  3278.   if (nbits != 0)
  3279.     return error_type (pp, objfile);
  3280.   /* The type *should* end with a semicolon.  If it are embedded
  3281.      in a larger type the semicolon may be the only way to know where
  3282.      the type ends.  If this type is at the end of the stabstring we
  3283.      can deal with the omitted semicolon (but we don't have to like
  3284.      it).  Don't bother to complain(), Sun's compiler omits the semicolon
  3285.      for "void".  */
  3286.   if (**pp == ';')
  3287.     ++(*pp);

  3288.   if (type_bits == 0)
  3289.     return init_type (TYPE_CODE_VOID, 1,
  3290.                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
  3291.                       objfile);
  3292.   else
  3293.     return init_type (code,
  3294.                       type_bits / TARGET_CHAR_BIT,
  3295.                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
  3296.                       objfile);
  3297. }

  3298. static struct type *
  3299. read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
  3300. {
  3301.   int nbits;
  3302.   int details;
  3303.   int nbytes;
  3304.   struct type *rettype;

  3305.   /* The first number has more details about the type, for example
  3306.      FN_COMPLEX.  */
  3307.   details = read_huge_number (pp, ';', &nbits, 0);
  3308.   if (nbits != 0)
  3309.     return error_type (pp, objfile);

  3310.   /* The second number is the number of bytes occupied by this type.  */
  3311.   nbytes = read_huge_number (pp, ';', &nbits, 0);
  3312.   if (nbits != 0)
  3313.     return error_type (pp, objfile);

  3314.   if (details == NF_COMPLEX || details == NF_COMPLEX16
  3315.       || details == NF_COMPLEX32)
  3316.     {
  3317.       rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
  3318.       TYPE_TARGET_TYPE (rettype)
  3319.         = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
  3320.       return rettype;
  3321.     }

  3322.   return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
  3323. }

  3324. /* Read a number from the string pointed to by *PP.
  3325.    The value of *PP is advanced over the number.
  3326.    If END is nonzero, the character that ends the
  3327.    number must match END, or an error happens;
  3328.    and that character is skipped if it does match.
  3329.    If END is zero, *PP is left pointing to that character.

  3330.    If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
  3331.    the number is represented in an octal representation, assume that
  3332.    it is represented in a 2's complement representation with a size of
  3333.    TWOS_COMPLEMENT_BITS.

  3334.    If the number fits in a long, set *BITS to 0 and return the value.
  3335.    If not, set *BITS to be the number of bits in the number and return 0.

  3336.    If encounter garbage, set *BITS to -1 and return 0.  */

  3337. static long
  3338. read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
  3339. {
  3340.   char *p = *pp;
  3341.   int sign = 1;
  3342.   int sign_bit = 0;
  3343.   long n = 0;
  3344.   int radix = 10;
  3345.   char overflow = 0;
  3346.   int nbits = 0;
  3347.   int c;
  3348.   long upper_limit;
  3349.   int twos_complement_representation = 0;

  3350.   if (*p == '-')
  3351.     {
  3352.       sign = -1;
  3353.       p++;
  3354.     }

  3355.   /* Leading zero means octal.  GCC uses this to output values larger
  3356.      than an int (because that would be hard in decimal).  */
  3357.   if (*p == '0')
  3358.     {
  3359.       radix = 8;
  3360.       p++;
  3361.     }

  3362.   /* Skip extra zeros.  */
  3363.   while (*p == '0')
  3364.     p++;

  3365.   if (sign > 0 && radix == 8 && twos_complement_bits > 0)
  3366.     {
  3367.       /* Octal, possibly signed.  Check if we have enough chars for a
  3368.          negative number.  */

  3369.       size_t len;
  3370.       char *p1 = p;

  3371.       while ((c = *p1) >= '0' && c < '8')
  3372.         p1++;

  3373.       len = p1 - p;
  3374.       if (len > twos_complement_bits / 3
  3375.           || (twos_complement_bits % 3 == 0
  3376.               && len == twos_complement_bits / 3))
  3377.         {
  3378.           /* Ok, we have enough characters for a signed value, check
  3379.              for signness by testing if the sign bit is set.  */
  3380.           sign_bit = (twos_complement_bits % 3 + 2) % 3;
  3381.           c = *p - '0';
  3382.           if (c & (1 << sign_bit))
  3383.             {
  3384.               /* Definitely signed.  */
  3385.               twos_complement_representation = 1;
  3386.               sign = -1;
  3387.             }
  3388.         }
  3389.     }

  3390.   upper_limit = LONG_MAX / radix;

  3391.   while ((c = *p++) >= '0' && c < ('0' + radix))
  3392.     {
  3393.       if (n <= upper_limit)
  3394.         {
  3395.           if (twos_complement_representation)
  3396.             {
  3397.               /* Octal, signed, twos complement representation.  In
  3398.                  this case, n is the corresponding absolute value.  */
  3399.               if (n == 0)
  3400.                 {
  3401.                   long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));

  3402.                   n = -sn;
  3403.                 }
  3404.               else
  3405.                 {
  3406.                   n *= radix;
  3407.                   n -= c - '0';
  3408.                 }
  3409.             }
  3410.           else
  3411.             {
  3412.               /* unsigned representation */
  3413.               n *= radix;
  3414.               n += c - '0';                /* FIXME this overflows anyway.  */
  3415.             }
  3416.         }
  3417.       else
  3418.         overflow = 1;

  3419.       /* This depends on large values being output in octal, which is
  3420.          what GCC does.  */
  3421.       if (radix == 8)
  3422.         {
  3423.           if (nbits == 0)
  3424.             {
  3425.               if (c == '0')
  3426.                 /* Ignore leading zeroes.  */
  3427.                 ;
  3428.               else if (c == '1')
  3429.                 nbits = 1;
  3430.               else if (c == '2' || c == '3')
  3431.                 nbits = 2;
  3432.               else
  3433.                 nbits = 3;
  3434.             }
  3435.           else
  3436.             nbits += 3;
  3437.         }
  3438.     }
  3439.   if (end)
  3440.     {
  3441.       if (c && c != end)
  3442.         {
  3443.           if (bits != NULL)
  3444.             *bits = -1;
  3445.           return 0;
  3446.         }
  3447.     }
  3448.   else
  3449.     --p;

  3450.   if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
  3451.     {
  3452.       /* We were supposed to parse a number with maximum
  3453.          TWOS_COMPLEMENT_BITS bits, but something went wrong.  */
  3454.       if (bits != NULL)
  3455.         *bits = -1;
  3456.       return 0;
  3457.     }

  3458.   *pp = p;
  3459.   if (overflow)
  3460.     {
  3461.       if (nbits == 0)
  3462.         {
  3463.           /* Large decimal constants are an error (because it is hard to
  3464.              count how many bits are in them).  */
  3465.           if (bits != NULL)
  3466.             *bits = -1;
  3467.           return 0;
  3468.         }

  3469.       /* -0x7f is the same as 0x80.  So deal with it by adding one to
  3470.          the number of bitsTwo's complement represention octals
  3471.          can't have a '-' in front.  */
  3472.       if (sign == -1 && !twos_complement_representation)
  3473.         ++nbits;
  3474.       if (bits)
  3475.         *bits = nbits;
  3476.     }
  3477.   else
  3478.     {
  3479.       if (bits)
  3480.         *bits = 0;
  3481.       return n * sign;
  3482.     }
  3483.   /* It's *BITS which has the interesting information.  */
  3484.   return 0;
  3485. }

  3486. static struct type *
  3487. read_range_type (char **pp, int typenums[2], int type_size,
  3488.                  struct objfile *objfile)
  3489. {
  3490.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  3491.   char *orig_pp = *pp;
  3492.   int rangenums[2];
  3493.   long n2, n3;
  3494.   int n2bits, n3bits;
  3495.   int self_subrange;
  3496.   struct type *result_type;
  3497.   struct type *index_type = NULL;

  3498.   /* First comes a type we are a subrange of.
  3499.      In C it is usually 0, 1 or the type being defined.  */
  3500.   if (read_type_number (pp, rangenums) != 0)
  3501.     return error_type (pp, objfile);
  3502.   self_subrange = (rangenums[0] == typenums[0] &&
  3503.                    rangenums[1] == typenums[1]);

  3504.   if (**pp == '=')
  3505.     {
  3506.       *pp = orig_pp;
  3507.       index_type = read_type (pp, objfile);
  3508.     }

  3509.   /* A semicolon should now follow; skip it.  */
  3510.   if (**pp == ';')
  3511.     (*pp)++;

  3512.   /* The remaining two operands are usually lower and upper bounds
  3513.      of the range.  But in some special cases they mean something else.  */
  3514.   n2 = read_huge_number (pp, ';', &n2bits, type_size);
  3515.   n3 = read_huge_number (pp, ';', &n3bits, type_size);

  3516.   if (n2bits == -1 || n3bits == -1)
  3517.     return error_type (pp, objfile);

  3518.   if (index_type)
  3519.     goto handle_true_range;

  3520.   /* If limits are huge, must be large integral type.  */
  3521.   if (n2bits != 0 || n3bits != 0)
  3522.     {
  3523.       char got_signed = 0;
  3524.       char got_unsigned = 0;
  3525.       /* Number of bits in the type.  */
  3526.       int nbits = 0;

  3527.       /* If a type size attribute has been specified, the bounds of
  3528.          the range should fit in this size.  If the lower bounds needs
  3529.          more bits than the upper bound, then the type is signed.  */
  3530.       if (n2bits <= type_size && n3bits <= type_size)
  3531.         {
  3532.           if (n2bits == type_size && n2bits > n3bits)
  3533.             got_signed = 1;
  3534.           else
  3535.             got_unsigned = 1;
  3536.           nbits = type_size;
  3537.         }
  3538.       /* Range from 0 to <large number> is an unsigned large integral type.  */
  3539.       else if ((n2bits == 0 && n2 == 0) && n3bits != 0)
  3540.         {
  3541.           got_unsigned = 1;
  3542.           nbits = n3bits;
  3543.         }
  3544.       /* Range from <large number> to <large number>-1 is a large signed
  3545.          integral type.  Take care of the case where <large number> doesn't
  3546.          fit in a long but <large number>-1 does.  */
  3547.       else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
  3548.                || (n2bits != 0 && n3bits == 0
  3549.                    && (n2bits == sizeof (long) * HOST_CHAR_BIT)
  3550.                    && n3 == LONG_MAX))
  3551.         {
  3552.           got_signed = 1;
  3553.           nbits = n2bits;
  3554.         }

  3555.       if (got_signed || got_unsigned)
  3556.         {
  3557.           return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
  3558.                             got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
  3559.                             objfile);
  3560.         }
  3561.       else
  3562.         return error_type (pp, objfile);
  3563.     }

  3564.   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
  3565.   if (self_subrange && n2 == 0 && n3 == 0)
  3566.     return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);

  3567.   /* If n3 is zero and n2 is positive, we want a floating type, and n2
  3568.      is the width in bytes.

  3569.      Fortran programs appear to use this for complex types also.  To
  3570.      distinguish between floats and complex, g77 (and others?)  seem
  3571.      to use self-subranges for the complexes, and subranges of int for
  3572.      the floats.

  3573.      Also note that for complexes, g77 sets n2 to the size of one of
  3574.      the member floats, not the whole complex beast.  My guess is that
  3575.      this was to work well with pre-COMPLEX versions of gdb.  */

  3576.   if (n3 == 0 && n2 > 0)
  3577.     {
  3578.       struct type *float_type
  3579.         = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);

  3580.       if (self_subrange)
  3581.         {
  3582.           struct type *complex_type =
  3583.             init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);

  3584.           TYPE_TARGET_TYPE (complex_type) = float_type;
  3585.           return complex_type;
  3586.         }
  3587.       else
  3588.         return float_type;
  3589.     }

  3590.   /* If the upper bound is -1, it must really be an unsigned integral.  */

  3591.   else if (n2 == 0 && n3 == -1)
  3592.     {
  3593.       int bits = type_size;

  3594.       if (bits <= 0)
  3595.         {
  3596.           /* We don't know its size.  It is unsigned int or unsigned
  3597.              long.  GCC 2.3.3 uses this for long long too, but that is
  3598.              just a GDB 3.5 compatibility hack.  */
  3599.           bits = gdbarch_int_bit (gdbarch);
  3600.         }

  3601.       return init_type (TYPE_CODE_INT, bits / TARGET_CHAR_BIT,
  3602.                         TYPE_FLAG_UNSIGNED, NULL, objfile);
  3603.     }

  3604.   /* Special case: char is defined (Who knows why) as a subrange of
  3605.      itself with range 0-127.  */
  3606.   else if (self_subrange && n2 == 0 && n3 == 127)
  3607.     return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_NOSIGN, NULL, objfile);

  3608.   /* We used to do this only for subrange of self or subrange of int.  */
  3609.   else if (n2 == 0)
  3610.     {
  3611.       /* -1 is used for the upper bound of (4 byte) "unsigned int" and
  3612.          "unsigned long", and we already checked for that,
  3613.          so don't need to test for it here.  */

  3614.       if (n3 < 0)
  3615.         /* n3 actually gives the size.  */
  3616.         return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
  3617.                           NULL, objfile);

  3618.       /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
  3619.          unsigned n-byte integer.  But do require n to be a power of
  3620.          two; we don't want 3- and 5-byte integers flying around.  */
  3621.       {
  3622.         int bytes;
  3623.         unsigned long bits;

  3624.         bits = n3;
  3625.         for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
  3626.           bits >>= 8;
  3627.         if (bits == 0
  3628.             && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
  3629.           return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
  3630.                             objfile);
  3631.       }
  3632.     }
  3633.   /* I think this is for Convex "long long".  Since I don't know whether
  3634.      Convex sets self_subrange, I also accept that particular size regardless
  3635.      of self_subrange.  */
  3636.   else if (n3 == 0 && n2 < 0
  3637.            && (self_subrange
  3638.                || n2 == -gdbarch_long_long_bit
  3639.                           (gdbarch) / TARGET_CHAR_BIT))
  3640.     return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
  3641.   else if (n2 == -n3 - 1)
  3642.     {
  3643.       if (n3 == 0x7f)
  3644.         return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
  3645.       if (n3 == 0x7fff)
  3646.         return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
  3647.       if (n3 == 0x7fffffff)
  3648.         return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
  3649.     }

  3650.   /* We have a real range type on our hands.  Allocate space and
  3651.      return a real pointer.  */
  3652. handle_true_range:

  3653.   if (self_subrange)
  3654.     index_type = objfile_type (objfile)->builtin_int;
  3655.   else
  3656.     index_type = *dbx_lookup_type (rangenums, objfile);
  3657.   if (index_type == NULL)
  3658.     {
  3659.       /* Does this actually ever happen?  Is that why we are worrying
  3660.          about dealing with it rather than just calling error_type?  */

  3661.       complaint (&symfile_complaints,
  3662.                  _("base type %d of range type is not defined"), rangenums[1]);

  3663.       index_type = objfile_type (objfile)->builtin_int;
  3664.     }

  3665.   result_type
  3666.     = create_static_range_type ((struct type *) NULL, index_type, n2, n3);
  3667.   return (result_type);
  3668. }

  3669. /* Read in an argument list.  This is a list of types, separated by commas
  3670.    and terminated with END.  Return the list of types read in, or NULL
  3671.    if there is an error.  */

  3672. static struct field *
  3673. read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
  3674.            int *varargsp)
  3675. {
  3676.   /* FIXME!  Remove this arbitrary limit!  */
  3677.   struct type *types[1024];        /* Allow for fns of 1023 parameters.  */
  3678.   int n = 0, i;
  3679.   struct field *rval;

  3680.   while (**pp != end)
  3681.     {
  3682.       if (**pp != ',')
  3683.         /* Invalid argument list: no ','.  */
  3684.         return NULL;
  3685.       (*pp)++;
  3686.       STABS_CONTINUE (pp, objfile);
  3687.       types[n++] = read_type (pp, objfile);
  3688.     }
  3689.   (*pp)++;                        /* get past `end' (the ':' character).  */

  3690.   if (n == 0)
  3691.     {
  3692.       /* We should read at least the THIS parameter here.  Some broken stabs
  3693.          output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
  3694.          have been present ";-16,(0,43)" reference instead.  This way the
  3695.          excessive ";" marker prematurely stops the parameters parsing.  */

  3696.       complaint (&symfile_complaints, _("Invalid (empty) method arguments"));
  3697.       *varargsp = 0;
  3698.     }
  3699.   else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
  3700.     *varargsp = 1;
  3701.   else
  3702.     {
  3703.       n--;
  3704.       *varargsp = 0;
  3705.     }

  3706.   rval = (struct field *) xmalloc (n * sizeof (struct field));
  3707.   memset (rval, 0, n * sizeof (struct field));
  3708.   for (i = 0; i < n; i++)
  3709.     rval[i].type = types[i];
  3710.   *nargsp = n;
  3711.   return rval;
  3712. }

  3713. /* Common block handling.  */

  3714. /* List of symbols declared since the last BCOMM.  This list is a tail
  3715.    of local_symbols.  When ECOMM is seen, the symbols on the list
  3716.    are noted so their proper addresses can be filled in later,
  3717.    using the common block base address gotten from the assembler
  3718.    stabs.  */

  3719. static struct pending *common_block;
  3720. static int common_block_i;

  3721. /* Name of the current common block.  We get it from the BCOMM instead of the
  3722.    ECOMM to match IBM documentation (even though IBM puts the name both places
  3723.    like everyone else).  */
  3724. static char *common_block_name;

  3725. /* Process a N_BCOMM symbol.  The storage for NAME is not guaranteed
  3726.    to remain after this function returns.  */

  3727. void
  3728. common_block_start (char *name, struct objfile *objfile)
  3729. {
  3730.   if (common_block_name != NULL)
  3731.     {
  3732.       complaint (&symfile_complaints,
  3733.                  _("Invalid symbol data: common block within common block"));
  3734.     }
  3735.   common_block = local_symbols;
  3736.   common_block_i = local_symbols ? local_symbols->nsyms : 0;
  3737.   common_block_name = obstack_copy0 (&objfile->objfile_obstack,
  3738.                                      name, strlen (name));
  3739. }

  3740. /* Process a N_ECOMM symbol.  */

  3741. void
  3742. common_block_end (struct objfile *objfile)
  3743. {
  3744.   /* Symbols declared since the BCOMM are to have the common block
  3745.      start address added in when we know it.  common_block and
  3746.      common_block_i point to the first symbol after the BCOMM in
  3747.      the local_symbols list; copy the list and hang it off the
  3748.      symbol for the common block name for later fixup.  */
  3749.   int i;
  3750.   struct symbol *sym;
  3751.   struct pending *new = 0;
  3752.   struct pending *next;
  3753.   int j;

  3754.   if (common_block_name == NULL)
  3755.     {
  3756.       complaint (&symfile_complaints, _("ECOMM symbol unmatched by BCOMM"));
  3757.       return;
  3758.     }

  3759.   sym = allocate_symbol (objfile);
  3760.   /* Note: common_block_name already saved on objfile_obstack.  */
  3761.   SYMBOL_SET_LINKAGE_NAME (sym, common_block_name);
  3762.   SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;

  3763.   /* Now we copy all the symbols which have been defined since the BCOMM.  */

  3764.   /* Copy all the struct pendings before common_block.  */
  3765.   for (next = local_symbols;
  3766.        next != NULL && next != common_block;
  3767.        next = next->next)
  3768.     {
  3769.       for (j = 0; j < next->nsyms; j++)
  3770.         add_symbol_to_list (next->symbol[j], &new);
  3771.     }

  3772.   /* Copy however much of COMMON_BLOCK we need.  If COMMON_BLOCK is
  3773.      NULL, it means copy all the local symbols (which we already did
  3774.      above).  */

  3775.   if (common_block != NULL)
  3776.     for (j = common_block_i; j < common_block->nsyms; j++)
  3777.       add_symbol_to_list (common_block->symbol[j], &new);

  3778.   SYMBOL_TYPE (sym) = (struct type *) new;

  3779.   /* Should we be putting local_symbols back to what it was?
  3780.      Does it matter?  */

  3781.   i = hashname (SYMBOL_LINKAGE_NAME (sym));
  3782.   SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
  3783.   global_sym_chain[i] = sym;
  3784.   common_block_name = NULL;
  3785. }

  3786. /* Add a common block's start address to the offset of each symbol
  3787.    declared to be in it (by being between a BCOMM/ECOMM pair that uses
  3788.    the common block name).  */

  3789. static void
  3790. fix_common_block (struct symbol *sym, CORE_ADDR valu)
  3791. {
  3792.   struct pending *next = (struct pending *) SYMBOL_TYPE (sym);

  3793.   for (; next; next = next->next)
  3794.     {
  3795.       int j;

  3796.       for (j = next->nsyms - 1; j >= 0; j--)
  3797.         SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
  3798.     }
  3799. }



  3800. /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
  3801.    See add_undefined_type for more details.  */

  3802. static void
  3803. add_undefined_type_noname (struct type *type, int typenums[2])
  3804. {
  3805.   struct nat nat;

  3806.   nat.typenums[0] = typenums [0];
  3807.   nat.typenums[1] = typenums [1];
  3808.   nat.type = type;

  3809.   if (noname_undefs_length == noname_undefs_allocated)
  3810.     {
  3811.       noname_undefs_allocated *= 2;
  3812.       noname_undefs = (struct nat *)
  3813.         xrealloc ((char *) noname_undefs,
  3814.                   noname_undefs_allocated * sizeof (struct nat));
  3815.     }
  3816.   noname_undefs[noname_undefs_length++] = nat;
  3817. }

  3818. /* Add TYPE to the UNDEF_TYPES vector.
  3819.    See add_undefined_type for more details.  */

  3820. static void
  3821. add_undefined_type_1 (struct type *type)
  3822. {
  3823.   if (undef_types_length == undef_types_allocated)
  3824.     {
  3825.       undef_types_allocated *= 2;
  3826.       undef_types = (struct type **)
  3827.         xrealloc ((char *) undef_types,
  3828.                   undef_types_allocated * sizeof (struct type *));
  3829.     }
  3830.   undef_types[undef_types_length++] = type;
  3831. }

  3832. /* What about types defined as forward references inside of a small lexical
  3833.    scope?  */
  3834. /* Add a type to the list of undefined types to be checked through
  3835.    once this file has been read in.

  3836.    In practice, we actually maintain two such lists: The first list
  3837.    (UNDEF_TYPES) is used for types whose name has been provided, and
  3838.    concerns forward references (eg 'xs' or 'xu' forward references);
  3839.    the second list (NONAME_UNDEFS) is used for types whose name is
  3840.    unknown at creation time, because they were referenced through
  3841.    their type number before the actual type was declared.
  3842.    This function actually adds the given type to the proper list.  */

  3843. static void
  3844. add_undefined_type (struct type *type, int typenums[2])
  3845. {
  3846.   if (TYPE_TAG_NAME (type) == NULL)
  3847.     add_undefined_type_noname (type, typenums);
  3848.   else
  3849.     add_undefined_type_1 (type);
  3850. }

  3851. /* Try to fix all undefined types pushed on the UNDEF_TYPES vector.  */

  3852. static void
  3853. cleanup_undefined_types_noname (struct objfile *objfile)
  3854. {
  3855.   int i;

  3856.   for (i = 0; i < noname_undefs_length; i++)
  3857.     {
  3858.       struct nat nat = noname_undefs[i];
  3859.       struct type **type;

  3860.       type = dbx_lookup_type (nat.typenums, objfile);
  3861.       if (nat.type != *type && TYPE_CODE (*type) != TYPE_CODE_UNDEF)
  3862.         {
  3863.           /* The instance flags of the undefined type are still unset,
  3864.              and needs to be copied over from the reference type.
  3865.              Since replace_type expects them to be identical, we need
  3866.              to set these flags manually before hand.  */
  3867.           TYPE_INSTANCE_FLAGS (nat.type) = TYPE_INSTANCE_FLAGS (*type);
  3868.           replace_type (nat.type, *type);
  3869.         }
  3870.     }

  3871.   noname_undefs_length = 0;
  3872. }

  3873. /* Go through each undefined type, see if it's still undefined, and fix it
  3874.    up if possible.  We have two kinds of undefined types:

  3875.    TYPE_CODE_ARRAY:  Array whose target type wasn't defined yet.
  3876.    Fix:  update array length using the element bounds
  3877.    and the target type's length.
  3878.    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
  3879.    yet defined at the time a pointer to it was made.
  3880.    Fix:  Do a full lookup on the struct/union tag.  */

  3881. static void
  3882. cleanup_undefined_types_1 (void)
  3883. {
  3884.   struct type **type;

  3885.   /* Iterate over every undefined type, and look for a symbol whose type
  3886.      matches our undefined type.  The symbol matches if:
  3887.        1. It is a typedef in the STRUCT domain;
  3888.        2. It has the same name, and same type code;
  3889.        3. The instance flags are identical.

  3890.      It is important to check the instance flags, because we have seen
  3891.      examples where the debug info contained definitions such as:

  3892.          "foo_t:t30=B31=xefoo_t:"

  3893.      In this case, we have created an undefined type named "foo_t" whose
  3894.      instance flags is null (when processing "xefoo_t"), and then created
  3895.      another type with the same name, but with different instance flags
  3896.      ('B' means volatile).  I think that the definition above is wrong,
  3897.      since the same type cannot be volatile and non-volatile at the same
  3898.      time, but we need to be able to cope with it when it happens.  The
  3899.      approach taken here is to treat these two types as different.  */

  3900.   for (type = undef_types; type < undef_types + undef_types_length; type++)
  3901.     {
  3902.       switch (TYPE_CODE (*type))
  3903.         {

  3904.         case TYPE_CODE_STRUCT:
  3905.         case TYPE_CODE_UNION:
  3906.         case TYPE_CODE_ENUM:
  3907.           {
  3908.             /* Check if it has been defined since.  Need to do this here
  3909.                as well as in check_typedef to deal with the (legitimate in
  3910.                C though not C++) case of several types with the same name
  3911.                in different source files.  */
  3912.             if (TYPE_STUB (*type))
  3913.               {
  3914.                 struct pending *ppt;
  3915.                 int i;
  3916.                 /* Name of the type, without "struct" or "union".  */
  3917.                 const char *typename = TYPE_TAG_NAME (*type);

  3918.                 if (typename == NULL)
  3919.                   {
  3920.                     complaint (&symfile_complaints, _("need a type name"));
  3921.                     break;
  3922.                   }
  3923.                 for (ppt = file_symbols; ppt; ppt = ppt->next)
  3924.                   {
  3925.                     for (i = 0; i < ppt->nsyms; i++)
  3926.                       {
  3927.                         struct symbol *sym = ppt->symbol[i];

  3928.                         if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
  3929.                             && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
  3930.                             && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
  3931.                                 TYPE_CODE (*type))
  3932.                             && (TYPE_INSTANCE_FLAGS (*type) ==
  3933.                                 TYPE_INSTANCE_FLAGS (SYMBOL_TYPE (sym)))
  3934.                             && strcmp (SYMBOL_LINKAGE_NAME (sym),
  3935.                                        typename) == 0)
  3936.                           replace_type (*type, SYMBOL_TYPE (sym));
  3937.                       }
  3938.                   }
  3939.               }
  3940.           }
  3941.           break;

  3942.         default:
  3943.           {
  3944.             complaint (&symfile_complaints,
  3945.                        _("forward-referenced types left unresolved, "
  3946.                        "type code %d."),
  3947.                        TYPE_CODE (*type));
  3948.           }
  3949.           break;
  3950.         }
  3951.     }

  3952.   undef_types_length = 0;
  3953. }

  3954. /* Try to fix all the undefined types we ecountered while processing
  3955.    this unit.  */

  3956. void
  3957. cleanup_undefined_stabs_types (struct objfile *objfile)
  3958. {
  3959.   cleanup_undefined_types_1 ();
  3960.   cleanup_undefined_types_noname (objfile);
  3961. }

  3962. /* Scan through all of the global symbols defined in the object file,
  3963.    assigning values to the debugging symbols that need to be assigned
  3964.    to.  Get these symbols from the minimal symbol table.  */

  3965. void
  3966. scan_file_globals (struct objfile *objfile)
  3967. {
  3968.   int hash;
  3969.   struct minimal_symbol *msymbol;
  3970.   struct symbol *sym, *prev;
  3971.   struct objfile *resolve_objfile;

  3972.   /* SVR4 based linkers copy referenced global symbols from shared
  3973.      libraries to the main executable.
  3974.      If we are scanning the symbols for a shared library, try to resolve
  3975.      them from the minimal symbols of the main executable first.  */

  3976.   if (symfile_objfile && objfile != symfile_objfile)
  3977.     resolve_objfile = symfile_objfile;
  3978.   else
  3979.     resolve_objfile = objfile;

  3980.   while (1)
  3981.     {
  3982.       /* Avoid expensive loop through all minimal symbols if there are
  3983.          no unresolved symbols.  */
  3984.       for (hash = 0; hash < HASHSIZE; hash++)
  3985.         {
  3986.           if (global_sym_chain[hash])
  3987.             break;
  3988.         }
  3989.       if (hash >= HASHSIZE)
  3990.         return;

  3991.       ALL_OBJFILE_MSYMBOLS (resolve_objfile, msymbol)
  3992.         {
  3993.           QUIT;

  3994.           /* Skip static symbols.  */
  3995.           switch (MSYMBOL_TYPE (msymbol))
  3996.             {
  3997.             case mst_file_text:
  3998.             case mst_file_data:
  3999.             case mst_file_bss:
  4000.               continue;
  4001.             default:
  4002.               break;
  4003.             }

  4004.           prev = NULL;

  4005.           /* Get the hash index and check all the symbols
  4006.              under that hash index.  */

  4007.           hash = hashname (MSYMBOL_LINKAGE_NAME (msymbol));

  4008.           for (sym = global_sym_chain[hash]; sym;)
  4009.             {
  4010.               if (strcmp (MSYMBOL_LINKAGE_NAME (msymbol),
  4011.                           SYMBOL_LINKAGE_NAME (sym)) == 0)
  4012.                 {
  4013.                   /* Splice this symbol out of the hash chain and
  4014.                      assign the value we have to it.  */
  4015.                   if (prev)
  4016.                     {
  4017.                       SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
  4018.                     }
  4019.                   else
  4020.                     {
  4021.                       global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
  4022.                     }

  4023.                   /* Check to see whether we need to fix up a common block.  */
  4024.                   /* Note: this code might be executed several times for
  4025.                      the same symbol if there are multiple references.  */
  4026.                   if (sym)
  4027.                     {
  4028.                       if (SYMBOL_CLASS (sym) == LOC_BLOCK)
  4029.                         {
  4030.                           fix_common_block (sym,
  4031.                                             MSYMBOL_VALUE_ADDRESS (resolve_objfile,
  4032.                                                                    msymbol));
  4033.                         }
  4034.                       else
  4035.                         {
  4036.                           SYMBOL_VALUE_ADDRESS (sym)
  4037.                             = MSYMBOL_VALUE_ADDRESS (resolve_objfile, msymbol);
  4038.                         }
  4039.                       SYMBOL_SECTION (sym) = MSYMBOL_SECTION (msymbol);
  4040.                     }

  4041.                   if (prev)
  4042.                     {
  4043.                       sym = SYMBOL_VALUE_CHAIN (prev);
  4044.                     }
  4045.                   else
  4046.                     {
  4047.                       sym = global_sym_chain[hash];
  4048.                     }
  4049.                 }
  4050.               else
  4051.                 {
  4052.                   prev = sym;
  4053.                   sym = SYMBOL_VALUE_CHAIN (sym);
  4054.                 }
  4055.             }
  4056.         }
  4057.       if (resolve_objfile == objfile)
  4058.         break;
  4059.       resolve_objfile = objfile;
  4060.     }

  4061.   /* Change the storage class of any remaining unresolved globals to
  4062.      LOC_UNRESOLVED and remove them from the chain.  */
  4063.   for (hash = 0; hash < HASHSIZE; hash++)
  4064.     {
  4065.       sym = global_sym_chain[hash];
  4066.       while (sym)
  4067.         {
  4068.           prev = sym;
  4069.           sym = SYMBOL_VALUE_CHAIN (sym);

  4070.           /* Change the symbol address from the misleading chain value
  4071.              to address zero.  */
  4072.           SYMBOL_VALUE_ADDRESS (prev) = 0;

  4073.           /* Complain about unresolved common block symbols.  */
  4074.           if (SYMBOL_CLASS (prev) == LOC_STATIC)
  4075.             SYMBOL_ACLASS_INDEX (prev) = LOC_UNRESOLVED;
  4076.           else
  4077.             complaint (&symfile_complaints,
  4078.                        _("%s: common block `%s' from "
  4079.                          "global_sym_chain unresolved"),
  4080.                        objfile_name (objfile), SYMBOL_PRINT_NAME (prev));
  4081.         }
  4082.     }
  4083.   memset (global_sym_chain, 0, sizeof (global_sym_chain));
  4084. }

  4085. /* Initialize anything that needs initializing when starting to read
  4086.    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
  4087.    to a psymtab.  */

  4088. void
  4089. stabsread_init (void)
  4090. {
  4091. }

  4092. /* Initialize anything that needs initializing when a completely new
  4093.    symbol file is specified (not just adding some symbols from another
  4094.    file, e.g. a shared library).  */

  4095. void
  4096. stabsread_new_init (void)
  4097. {
  4098.   /* Empty the hash table of global syms looking for values.  */
  4099.   memset (global_sym_chain, 0, sizeof (global_sym_chain));
  4100. }

  4101. /* Initialize anything that needs initializing at the same time as
  4102.    start_symtab() is called.  */

  4103. void
  4104. start_stabs (void)
  4105. {
  4106.   global_stabs = NULL;                /* AIX COFF */
  4107.   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
  4108.   n_this_object_header_files = 1;
  4109.   type_vector_length = 0;
  4110.   type_vector = (struct type **) 0;

  4111.   /* FIXME: If common_block_name is not already NULL, we should complain().  */
  4112.   common_block_name = NULL;
  4113. }

  4114. /* Call after end_symtab().  */

  4115. void
  4116. end_stabs (void)
  4117. {
  4118.   if (type_vector)
  4119.     {
  4120.       xfree (type_vector);
  4121.     }
  4122.   type_vector = 0;
  4123.   type_vector_length = 0;
  4124.   previous_stab_code = 0;
  4125. }

  4126. void
  4127. finish_global_stabs (struct objfile *objfile)
  4128. {
  4129.   if (global_stabs)
  4130.     {
  4131.       patch_block_stabs (global_symbols, global_stabs, objfile);
  4132.       xfree (global_stabs);
  4133.       global_stabs = NULL;
  4134.     }
  4135. }

  4136. /* Find the end of the name, delimited by a ':', but don't match
  4137.    ObjC symbols which look like -[Foo bar::]:bla.  */
  4138. static char *
  4139. find_name_end (char *name)
  4140. {
  4141.   char *s = name;

  4142.   if (s[0] == '-' || *s == '+')
  4143.     {
  4144.       /* Must be an ObjC method symbol.  */
  4145.       if (s[1] != '[')
  4146.         {
  4147.           error (_("invalid symbol name \"%s\""), name);
  4148.         }
  4149.       s = strchr (s, ']');
  4150.       if (s == NULL)
  4151.         {
  4152.           error (_("invalid symbol name \"%s\""), name);
  4153.         }
  4154.       return strchr (s, ':');
  4155.     }
  4156.   else
  4157.     {
  4158.       return strchr (s, ':');
  4159.     }
  4160. }

  4161. /* Initializer for this module.  */

  4162. void
  4163. _initialize_stabsread (void)
  4164. {
  4165.   rs6000_builtin_type_data = register_objfile_data ();

  4166.   undef_types_allocated = 20;
  4167.   undef_types_length = 0;
  4168.   undef_types = (struct type **)
  4169.     xmalloc (undef_types_allocated * sizeof (struct type *));

  4170.   noname_undefs_allocated = 20;
  4171.   noname_undefs_length = 0;
  4172.   noname_undefs = (struct nat *)
  4173.     xmalloc (noname_undefs_allocated * sizeof (struct nat));

  4174.   stab_register_index = register_symbol_register_impl (LOC_REGISTER,
  4175.                                                        &stab_register_funcs);
  4176.   stab_regparm_index = register_symbol_register_impl (LOC_REGPARM_ADDR,
  4177.                                                       &stab_register_funcs);
  4178. }