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