Home | History | Annotate | Line # | Download | only in gdb
      1   1.1  christos /* Support routines for decoding "stabs" debugging information format.
      2   1.1  christos 
      3  1.11  christos    Copyright (C) 1986-2024 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.7  christos    the "stabs" format.  This format is used by some systems that use
     22   1.7  christos    COFF or ELF where the stabs data is placed in a special section (as
     23   1.7  christos    well as with many old systems that used the a.out object file
     24   1.7  christos    format).  Avoid placing any object file format specific code in
     25   1.7  christos    this file.  */
     26   1.1  christos 
     27   1.1  christos #include "bfd.h"
     28  1.11  christos #include "event-top.h"
     29  1.10  christos #include "gdbsupport/gdb_obstack.h"
     30   1.1  christos #include "symtab.h"
     31   1.1  christos #include "gdbtypes.h"
     32   1.1  christos #include "expression.h"
     33   1.1  christos #include "symfile.h"
     34   1.1  christos #include "objfiles.h"
     35  1.11  christos #include "aout/stab_gnu.h"
     36  1.12  christos #include "psymtab.h"
     37   1.1  christos #include "libaout.h"
     38   1.1  christos #include "aout/aout64.h"
     39   1.1  christos #include "gdb-stabs.h"
     40   1.8  christos #include "buildsym-legacy.h"
     41   1.1  christos #include "complaints.h"
     42   1.1  christos #include "demangle.h"
     43   1.1  christos #include "gdb-demangle.h"
     44   1.1  christos #include "language.h"
     45   1.8  christos #include "target-float.h"
     46   1.9  christos #include "c-lang.h"
     47   1.1  christos #include "cp-abi.h"
     48   1.1  christos #include "cp-support.h"
     49   1.1  christos #include <ctype.h>
     50  1.12  christos #include "block.h"
     51  1.12  christos #include "filenames.h"
     52   1.1  christos 
     53   1.8  christos #include "stabsread.h"
     54   1.1  christos 
     55   1.8  christos /* See stabsread.h for these globals.  */
     56   1.8  christos unsigned int symnum;
     57   1.8  christos const char *(*next_symbol_text_func) (struct objfile *);
     58   1.8  christos unsigned char processing_gcc_compilation;
     59   1.8  christos int within_function;
     60   1.8  christos struct symbol *global_sym_chain[HASHSIZE];
     61   1.8  christos struct pending_stabs *global_stabs;
     62   1.8  christos int previous_stab_code;
     63   1.8  christos int *this_object_header_files;
     64   1.8  christos int n_this_object_header_files;
     65   1.8  christos int n_allocated_this_object_header_files;
     66   1.1  christos 
     67  1.12  christos /* See stabsread.h.  */
     68  1.12  christos 
     69  1.12  christos const registry<objfile>::key<dbx_symfile_info> dbx_objfile_data_key;
     70  1.12  christos 
     71  1.12  christos dbx_symfile_info::~dbx_symfile_info ()
     72  1.12  christos {
     73  1.12  christos   if (header_files != NULL)
     74  1.12  christos     {
     75  1.12  christos       int i = n_header_files;
     76  1.12  christos       struct header_file *hfiles = header_files;
     77  1.12  christos 
     78  1.12  christos       while (--i >= 0)
     79  1.12  christos 	{
     80  1.12  christos 	  xfree (hfiles[i].name);
     81  1.12  christos 	  xfree (hfiles[i].vector);
     82  1.12  christos 	}
     83  1.12  christos       xfree (hfiles);
     84  1.12  christos     }
     85  1.12  christos }
     86  1.12  christos 
     87  1.10  christos struct stabs_nextfield
     88   1.5  christos {
     89  1.10  christos   struct stabs_nextfield *next;
     90   1.5  christos 
     91   1.5  christos   struct field field;
     92   1.5  christos };
     93   1.5  christos 
     94   1.5  christos struct next_fnfieldlist
     95   1.5  christos {
     96   1.5  christos   struct next_fnfieldlist *next;
     97   1.5  christos   struct fn_fieldlist fn_fieldlist;
     98   1.5  christos };
     99   1.5  christos 
    100   1.1  christos /* The routines that read and process a complete stabs for a C struct or
    101   1.1  christos    C++ class pass lists of data member fields and lists of member function
    102   1.1  christos    fields in an instance of a field_info structure, as defined below.
    103   1.1  christos    This is part of some reorganization of low level C++ support and is
    104   1.1  christos    expected to eventually go away...  (FIXME) */
    105   1.1  christos 
    106   1.9  christos struct stab_field_info
    107   1.1  christos   {
    108  1.10  christos     struct stabs_nextfield *list = nullptr;
    109   1.9  christos     struct next_fnfieldlist *fnlist = nullptr;
    110   1.9  christos 
    111   1.9  christos     auto_obstack obstack;
    112   1.1  christos   };
    113   1.1  christos 
    114   1.1  christos static void
    115   1.9  christos read_one_struct_field (struct stab_field_info *, const char **, const char *,
    116   1.1  christos 		       struct type *, struct objfile *);
    117   1.1  christos 
    118   1.1  christos static struct type *dbx_alloc_type (int[2], struct objfile *);
    119   1.1  christos 
    120   1.7  christos static long read_huge_number (const char **, int, int *, int);
    121   1.1  christos 
    122   1.7  christos static struct type *error_type (const char **, struct objfile *);
    123   1.1  christos 
    124   1.1  christos static void
    125   1.1  christos patch_block_stabs (struct pending *, struct pending_stabs *,
    126   1.1  christos 		   struct objfile *);
    127   1.1  christos 
    128   1.7  christos static int read_type_number (const char **, int *);
    129   1.1  christos 
    130   1.7  christos static struct type *read_type (const char **, struct objfile *);
    131   1.1  christos 
    132   1.7  christos static struct type *read_range_type (const char **, int[2],
    133   1.7  christos 				     int, struct objfile *);
    134   1.1  christos 
    135   1.7  christos static struct type *read_sun_builtin_type (const char **,
    136   1.7  christos 					   int[2], struct objfile *);
    137   1.1  christos 
    138   1.7  christos static struct type *read_sun_floating_type (const char **, int[2],
    139   1.1  christos 					    struct objfile *);
    140   1.1  christos 
    141   1.7  christos static struct type *read_enum_type (const char **, struct type *, struct objfile *);
    142   1.1  christos 
    143   1.1  christos static struct type *rs6000_builtin_type (int, struct objfile *);
    144   1.1  christos 
    145   1.1  christos static int
    146   1.9  christos read_member_functions (struct stab_field_info *, const char **, struct type *,
    147   1.1  christos 		       struct objfile *);
    148   1.1  christos 
    149   1.1  christos static int
    150   1.9  christos read_struct_fields (struct stab_field_info *, const char **, struct type *,
    151   1.1  christos 		    struct objfile *);
    152   1.1  christos 
    153   1.1  christos static int
    154   1.9  christos read_baseclasses (struct stab_field_info *, const char **, struct type *,
    155   1.1  christos 		  struct objfile *);
    156   1.1  christos 
    157   1.1  christos static int
    158   1.9  christos read_tilde_fields (struct stab_field_info *, const char **, struct type *,
    159   1.1  christos 		   struct objfile *);
    160   1.1  christos 
    161   1.9  christos static int attach_fn_fields_to_type (struct stab_field_info *, struct type *);
    162   1.1  christos 
    163   1.9  christos static int attach_fields_to_type (struct stab_field_info *, struct type *,
    164   1.1  christos 				  struct objfile *);
    165   1.1  christos 
    166   1.7  christos static struct type *read_struct_type (const char **, struct type *,
    167  1.10  christos 				      enum type_code,
    168   1.1  christos 				      struct objfile *);
    169   1.1  christos 
    170   1.7  christos static struct type *read_array_type (const char **, struct type *,
    171   1.1  christos 				     struct objfile *);
    172   1.1  christos 
    173   1.7  christos static struct field *read_args (const char **, int, struct objfile *,
    174   1.7  christos 				int *, int *);
    175   1.1  christos 
    176   1.1  christos static void add_undefined_type (struct type *, int[2]);
    177   1.1  christos 
    178   1.1  christos static int
    179   1.9  christos read_cpp_abbrev (struct stab_field_info *, const char **, struct type *,
    180   1.1  christos 		 struct objfile *);
    181   1.1  christos 
    182   1.7  christos static const char *find_name_end (const char *name);
    183   1.1  christos 
    184   1.7  christos static int process_reference (const char **string);
    185   1.1  christos 
    186   1.1  christos void stabsread_clear_cache (void);
    187   1.1  christos 
    188   1.1  christos static const char vptr_name[] = "_vptr$";
    189   1.1  christos static const char vb_name[] = "_vb$";
    190   1.1  christos 
    191  1.12  christos void
    192  1.12  christos unknown_symtype_complaint (const char *arg1)
    193  1.12  christos {
    194  1.12  christos   complaint (_("unknown symbol type %s"), arg1);
    195  1.12  christos }
    196  1.12  christos 
    197  1.12  christos void
    198  1.12  christos lbrac_mismatch_complaint (int arg1)
    199  1.12  christos {
    200  1.12  christos   complaint (_("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
    201  1.12  christos }
    202  1.12  christos 
    203  1.12  christos void
    204  1.12  christos repeated_header_complaint (const char *arg1, int arg2)
    205  1.12  christos {
    206  1.12  christos   complaint (_("\"repeated\" header file %s not "
    207  1.12  christos 	       "previously seen, at symtab pos %d"),
    208  1.12  christos 	     arg1, arg2);
    209  1.12  christos }
    210  1.12  christos 
    211   1.1  christos static void
    212   1.1  christos invalid_cpp_abbrev_complaint (const char *arg1)
    213   1.1  christos {
    214   1.8  christos   complaint (_("invalid C++ abbreviation `%s'"), arg1);
    215   1.1  christos }
    216   1.1  christos 
    217   1.1  christos static void
    218   1.1  christos reg_value_complaint (int regnum, int num_regs, const char *sym)
    219   1.1  christos {
    220   1.8  christos   complaint (_("bad register number %d (max %d) in symbol %s"),
    221  1.10  christos 	     regnum, num_regs - 1, sym);
    222   1.1  christos }
    223   1.1  christos 
    224   1.1  christos static void
    225   1.1  christos stabs_general_complaint (const char *arg1)
    226   1.1  christos {
    227   1.8  christos   complaint ("%s", arg1);
    228   1.1  christos }
    229   1.1  christos 
    230  1.12  christos static void
    231  1.12  christos function_outside_compilation_unit_complaint (const char *arg1)
    232  1.12  christos {
    233  1.12  christos   complaint (_("function `%s' appears to be defined "
    234  1.12  christos 	       "outside of all compilation units"),
    235  1.12  christos 	     arg1);
    236  1.12  christos }
    237  1.12  christos 
    238   1.1  christos /* Make a list of forward references which haven't been defined.  */
    239   1.1  christos 
    240   1.1  christos static struct type **undef_types;
    241   1.1  christos static int undef_types_allocated;
    242   1.1  christos static int undef_types_length;
    243   1.1  christos static struct symbol *current_symbol = NULL;
    244   1.1  christos 
    245   1.1  christos /* Make a list of nameless types that are undefined.
    246   1.1  christos    This happens when another type is referenced by its number
    247   1.1  christos    before this type is actually defined.  For instance "t(0,1)=k(0,2)"
    248   1.1  christos    and type (0,2) is defined only later.  */
    249   1.1  christos 
    250   1.1  christos struct nat
    251   1.1  christos {
    252   1.1  christos   int typenums[2];
    253   1.1  christos   struct type *type;
    254   1.1  christos };
    255   1.1  christos static struct nat *noname_undefs;
    256   1.1  christos static int noname_undefs_allocated;
    257   1.1  christos static int noname_undefs_length;
    258   1.1  christos 
    259   1.1  christos /* Check for and handle cretinous stabs symbol name continuation!  */
    260   1.1  christos #define STABS_CONTINUE(pp,objfile)				\
    261   1.1  christos   do {							\
    262   1.1  christos     if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
    263   1.1  christos       *(pp) = next_symbol_text (objfile);	\
    264   1.1  christos   } while (0)
    265   1.1  christos 
    266   1.1  christos /* Vector of types defined so far, indexed by their type numbers.
    267   1.1  christos    (In newer sun systems, dbx uses a pair of numbers in parens,
    268   1.1  christos    as in "(SUBFILENUM,NUMWITHINSUBFILE)".
    269   1.1  christos    Then these numbers must be translated through the type_translations
    270   1.1  christos    hash table to get the index into the type vector.)  */
    271   1.1  christos 
    272   1.1  christos static struct type **type_vector;
    273   1.1  christos 
    274   1.1  christos /* Number of elements allocated for type_vector currently.  */
    275   1.1  christos 
    276   1.1  christos static int type_vector_length;
    277   1.1  christos 
    278   1.1  christos /* Initial size of type vector.  Is realloc'd larger if needed, and
    279   1.1  christos    realloc'd down to the size actually used, when completed.  */
    280   1.1  christos 
    281   1.1  christos #define INITIAL_TYPE_VECTOR_LENGTH 160
    282   1.1  christos 
    283   1.1  christos 
    285   1.1  christos /* Look up a dbx type-number pair.  Return the address of the slot
    286   1.1  christos    where the type for that number-pair is stored.
    287   1.1  christos    The number-pair is in TYPENUMS.
    288   1.1  christos 
    289   1.1  christos    This can be used for finding the type associated with that pair
    290   1.1  christos    or for associating a new type with the pair.  */
    291   1.1  christos 
    292   1.1  christos static struct type **
    293   1.1  christos dbx_lookup_type (int typenums[2], struct objfile *objfile)
    294   1.1  christos {
    295   1.1  christos   int filenum = typenums[0];
    296   1.1  christos   int index = typenums[1];
    297   1.1  christos   unsigned old_len;
    298   1.1  christos   int real_filenum;
    299   1.1  christos   struct header_file *f;
    300   1.1  christos   int f_orig_length;
    301   1.1  christos 
    302   1.1  christos   if (filenum == -1)		/* -1,-1 is for temporary types.  */
    303   1.1  christos     return 0;
    304   1.1  christos 
    305   1.1  christos   if (filenum < 0 || filenum >= n_this_object_header_files)
    306   1.8  christos     {
    307   1.1  christos       complaint (_("Invalid symbol data: type number "
    308   1.1  christos 		   "(%d,%d) out of range at symtab pos %d."),
    309   1.1  christos 		 filenum, index, symnum);
    310   1.1  christos       goto error_return;
    311   1.1  christos     }
    312   1.1  christos 
    313   1.1  christos   if (filenum == 0)
    314   1.1  christos     {
    315   1.1  christos       if (index < 0)
    316   1.1  christos 	{
    317   1.1  christos 	  /* Caller wants address of address of type.  We think
    318   1.1  christos 	     that negative (rs6k builtin) types will never appear as
    319   1.1  christos 	     "lvalues", (nor should they), so we stuff the real type
    320   1.1  christos 	     pointer into a temp, and return its address.  If referenced,
    321   1.1  christos 	     this will do the right thing.  */
    322   1.1  christos 	  static struct type *temp_type;
    323   1.1  christos 
    324   1.1  christos 	  temp_type = rs6000_builtin_type (index, objfile);
    325   1.1  christos 	  return &temp_type;
    326   1.1  christos 	}
    327   1.1  christos 
    328  1.10  christos       /* Type is defined outside of header files.
    329   1.1  christos 	 Find it in this object file's type vector.  */
    330   1.1  christos       if (index >= type_vector_length)
    331   1.1  christos 	{
    332   1.1  christos 	  old_len = type_vector_length;
    333   1.1  christos 	  if (old_len == 0)
    334   1.1  christos 	    {
    335   1.6  christos 	      type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
    336   1.1  christos 	      type_vector = XNEWVEC (struct type *, type_vector_length);
    337   1.1  christos 	    }
    338   1.1  christos 	  while (index >= type_vector_length)
    339   1.1  christos 	    {
    340   1.1  christos 	      type_vector_length *= 2;
    341   1.1  christos 	    }
    342   1.1  christos 	  type_vector = (struct type **)
    343   1.1  christos 	    xrealloc ((char *) type_vector,
    344   1.1  christos 		      (type_vector_length * sizeof (struct type *)));
    345   1.1  christos 	  memset (&type_vector[old_len], 0,
    346   1.1  christos 		  (type_vector_length - old_len) * sizeof (struct type *));
    347   1.1  christos 	}
    348   1.1  christos       return (&type_vector[index]);
    349   1.1  christos     }
    350   1.1  christos   else
    351   1.1  christos     {
    352   1.1  christos       real_filenum = this_object_header_files[filenum];
    353   1.1  christos 
    354   1.1  christos       if (real_filenum >= N_HEADER_FILES (objfile))
    355   1.1  christos 	{
    356   1.1  christos 	  static struct type *temp_type;
    357   1.1  christos 
    358   1.1  christos 	  warning (_("GDB internal error: bad real_filenum"));
    359   1.1  christos 
    360  1.11  christos 	error_return:
    361   1.1  christos 	  temp_type = builtin_type (objfile)->builtin_error;
    362   1.1  christos 	  return &temp_type;
    363   1.1  christos 	}
    364   1.1  christos 
    365   1.1  christos       f = HEADER_FILES (objfile) + real_filenum;
    366   1.1  christos 
    367   1.1  christos       f_orig_length = f->length;
    368   1.1  christos       if (index >= f_orig_length)
    369   1.1  christos 	{
    370   1.1  christos 	  while (index >= f->length)
    371   1.1  christos 	    {
    372   1.1  christos 	      f->length *= 2;
    373   1.1  christos 	    }
    374   1.1  christos 	  f->vector = (struct type **)
    375   1.1  christos 	    xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
    376   1.1  christos 	  memset (&f->vector[f_orig_length], 0,
    377   1.1  christos 		  (f->length - f_orig_length) * sizeof (struct type *));
    378   1.1  christos 	}
    379   1.1  christos       return (&f->vector[index]);
    380   1.1  christos     }
    381   1.1  christos }
    382   1.1  christos 
    383   1.1  christos /* Make sure there is a type allocated for type numbers TYPENUMS
    384   1.1  christos    and return the type object.
    385   1.1  christos    This can create an empty (zeroed) type object.
    386   1.1  christos    TYPENUMS may be (-1, -1) to return a new type object that is not
    387   1.1  christos    put into the type vector, and so may not be referred to by number.  */
    388   1.1  christos 
    389   1.1  christos static struct type *
    390   1.1  christos dbx_alloc_type (int typenums[2], struct objfile *objfile)
    391   1.1  christos {
    392   1.1  christos   struct type **type_addr;
    393   1.1  christos 
    394   1.1  christos   if (typenums[0] == -1)
    395  1.11  christos     {
    396  1.11  christos       return type_allocator (objfile,
    397   1.1  christos 			     get_current_subfile ()->language).new_type ();
    398   1.1  christos     }
    399   1.1  christos 
    400   1.1  christos   type_addr = dbx_lookup_type (typenums, objfile);
    401   1.1  christos 
    402   1.1  christos   /* If we are referring to a type not known at all yet,
    403   1.1  christos      allocate an empty type for it.
    404   1.1  christos      We will fill it in later if we find out how.  */
    405   1.1  christos   if (*type_addr == 0)
    406  1.11  christos     {
    407  1.11  christos       *type_addr = type_allocator (objfile,
    408   1.1  christos 				   get_current_subfile ()->language).new_type ();
    409   1.1  christos     }
    410   1.1  christos 
    411   1.1  christos   return (*type_addr);
    412   1.1  christos }
    413   1.7  christos 
    414   1.7  christos /* Allocate a floating-point type of size BITS.  */
    415   1.7  christos 
    416   1.7  christos static struct type *
    417   1.7  christos dbx_init_float_type (struct objfile *objfile, int bits)
    418   1.9  christos {
    419   1.7  christos   struct gdbarch *gdbarch = objfile->arch ();
    420   1.7  christos   const struct floatformat **format;
    421   1.7  christos   struct type *type;
    422   1.7  christos 
    423  1.11  christos   format = gdbarch_floatformat_for_type (gdbarch, NULL, bits);
    424   1.7  christos   type_allocator alloc (objfile, get_current_subfile ()->language);
    425  1.11  christos   if (format)
    426   1.7  christos     type = init_float_type (alloc, bits, NULL, format);
    427  1.11  christos   else
    428   1.7  christos     type = alloc.new_type (TYPE_CODE_ERROR, bits, NULL);
    429   1.7  christos 
    430   1.7  christos   return type;
    431   1.7  christos }
    432   1.1  christos 
    433   1.1  christos /* for all the stabs in a given stab vector, build appropriate types
    434   1.1  christos    and fix their symbols in given symbol vector.  */
    435   1.1  christos 
    436   1.1  christos static void
    437   1.1  christos patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
    438   1.1  christos 		   struct objfile *objfile)
    439   1.1  christos {
    440   1.1  christos   int ii;
    441   1.7  christos   char *name;
    442   1.1  christos   const char *pp;
    443   1.1  christos   struct symbol *sym;
    444   1.1  christos 
    445   1.1  christos   if (stabs)
    446   1.1  christos     {
    447  1.10  christos       /* for all the stab entries, find their corresponding symbols and
    448   1.1  christos 	 patch their types!  */
    449   1.1  christos 
    450   1.1  christos       for (ii = 0; ii < stabs->count; ++ii)
    451   1.1  christos 	{
    452   1.1  christos 	  name = stabs->stab[ii];
    453   1.1  christos 	  pp = (char *) strchr (name, ':');
    454   1.1  christos 	  gdb_assert (pp);	/* Must find a ':' or game's over.  */
    455   1.1  christos 	  while (pp[1] == ':')
    456   1.1  christos 	    {
    457   1.1  christos 	      pp += 2;
    458   1.1  christos 	      pp = (char *) strchr (pp, ':');
    459   1.1  christos 	    }
    460   1.1  christos 	  sym = find_symbol_in_list (symbols, name, pp - name);
    461   1.1  christos 	  if (!sym)
    462   1.1  christos 	    {
    463  1.10  christos 	      /* FIXME-maybe: it would be nice if we noticed whether
    464  1.10  christos 		 the variable was defined *anywhere*, not just whether
    465  1.10  christos 		 it is defined in this compilation unit.  But neither
    466  1.10  christos 		 xlc or GCC seem to need such a definition, and until
    467  1.10  christos 		 we do psymtabs (so that the minimal symbols from all
    468  1.10  christos 		 compilation units are available now), I'm not sure
    469   1.1  christos 		 how to get the information.  */
    470   1.1  christos 
    471  1.10  christos 	      /* On xcoff, if a global is defined and never referenced,
    472  1.10  christos 		 ld will remove it from the executable.  There is then
    473   1.9  christos 		 a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
    474  1.10  christos 	      sym = new (&objfile->objfile_obstack) symbol;
    475  1.10  christos 	      sym->set_domain (VAR_DOMAIN);
    476   1.9  christos 	      sym->set_aclass_index (LOC_OPTIMIZED_OUT);
    477   1.9  christos 	      sym->set_linkage_name
    478   1.1  christos 		(obstack_strndup (&objfile->objfile_obstack, name, pp - name));
    479   1.1  christos 	      pp += 2;
    480   1.1  christos 	      if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
    481   1.1  christos 		{
    482   1.1  christos 		  /* I don't think the linker does this with functions,
    483   1.1  christos 		     so as far as I know this is never executed.
    484  1.10  christos 		     But it doesn't hurt to check.  */
    485  1.10  christos 		  sym->set_type
    486   1.1  christos 		    (lookup_function_type (read_type (&pp, objfile)));
    487   1.1  christos 		}
    488   1.1  christos 	      else
    489  1.10  christos 		{
    490   1.1  christos 		  sym->set_type (read_type (&pp, objfile));
    491   1.8  christos 		}
    492   1.1  christos 	      add_symbol_to_list (sym, get_global_symbols ());
    493   1.1  christos 	    }
    494   1.1  christos 	  else
    495   1.1  christos 	    {
    496   1.1  christos 	      pp += 2;
    497   1.1  christos 	      if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
    498  1.10  christos 		{
    499  1.10  christos 		  sym->set_type
    500   1.1  christos 		    (lookup_function_type (read_type (&pp, objfile)));
    501   1.1  christos 		}
    502   1.1  christos 	      else
    503  1.10  christos 		{
    504   1.1  christos 		  sym->set_type (read_type (&pp, objfile));
    505   1.1  christos 		}
    506   1.1  christos 	    }
    507   1.1  christos 	}
    508   1.1  christos     }
    509   1.1  christos }
    510   1.1  christos 
    511   1.1  christos 
    513   1.1  christos /* Read a number by which a type is referred to in dbx data,
    514   1.1  christos    or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
    515   1.1  christos    Just a single number N is equivalent to (0,N).
    516   1.1  christos    Return the two numbers by storing them in the vector TYPENUMS.
    517   1.1  christos    TYPENUMS will then be used as an argument to dbx_lookup_type.
    518   1.1  christos 
    519   1.1  christos    Returns 0 for success, -1 for error.  */
    520   1.7  christos 
    521   1.1  christos static int
    522   1.1  christos read_type_number (const char **pp, int *typenums)
    523   1.1  christos {
    524   1.1  christos   int nbits;
    525   1.1  christos 
    526   1.1  christos   if (**pp == '(')
    527   1.1  christos     {
    528   1.1  christos       (*pp)++;
    529   1.1  christos       typenums[0] = read_huge_number (pp, ',', &nbits, 0);
    530   1.1  christos       if (nbits != 0)
    531   1.1  christos 	return -1;
    532   1.1  christos       typenums[1] = read_huge_number (pp, ')', &nbits, 0);
    533   1.1  christos       if (nbits != 0)
    534   1.1  christos 	return -1;
    535   1.1  christos     }
    536   1.1  christos   else
    537   1.1  christos     {
    538   1.1  christos       typenums[0] = 0;
    539   1.1  christos       typenums[1] = read_huge_number (pp, 0, &nbits, 0);
    540   1.1  christos       if (nbits != 0)
    541   1.1  christos 	return -1;
    542   1.1  christos     }
    543   1.1  christos   return 0;
    544   1.1  christos }
    545  1.12  christos 
    546  1.12  christos 
    548  1.12  christos /* Free up old header file tables.  */
    549  1.12  christos 
    550  1.12  christos void
    551  1.12  christos free_header_files (void)
    552  1.12  christos {
    553  1.12  christos   if (this_object_header_files)
    554  1.12  christos     {
    555  1.12  christos       xfree (this_object_header_files);
    556  1.12  christos       this_object_header_files = NULL;
    557  1.12  christos     }
    558  1.12  christos   n_allocated_this_object_header_files = 0;
    559  1.12  christos }
    560  1.12  christos 
    561  1.12  christos /* Allocate new header file tables.  */
    562  1.12  christos 
    563  1.12  christos void
    564  1.12  christos init_header_files (void)
    565  1.12  christos {
    566  1.12  christos   n_allocated_this_object_header_files = 10;
    567  1.12  christos   this_object_header_files = XNEWVEC (int, 10);
    568  1.12  christos }
    569  1.12  christos 
    570  1.12  christos /* Close off the current usage of PST.
    571  1.12  christos    Returns PST or NULL if the partial symtab was empty and thrown away.
    572  1.12  christos 
    573  1.12  christos    FIXME:  List variables and peculiarities of same.  */
    574  1.12  christos 
    575  1.12  christos legacy_psymtab *
    576  1.12  christos stabs_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
    577  1.12  christos 		   legacy_psymtab *pst,
    578  1.12  christos 		   const char **include_list, int num_includes,
    579  1.12  christos 		   int capping_symbol_offset, unrelocated_addr capping_text,
    580  1.12  christos 		   legacy_psymtab **dependency_list,
    581  1.12  christos 		   int number_dependencies,
    582  1.12  christos 		   int textlow_not_set)
    583  1.12  christos {
    584  1.12  christos   int i;
    585  1.12  christos   struct gdbarch *gdbarch = objfile->arch ();
    586  1.12  christos   dbx_symfile_info *key = dbx_objfile_data_key. get (objfile);
    587  1.12  christos 
    588  1.12  christos   if (capping_symbol_offset != -1)
    589  1.12  christos     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
    590  1.12  christos   pst->set_text_high (capping_text);
    591  1.12  christos 
    592  1.12  christos   /* Under Solaris, the N_SO symbols always have a value of 0,
    593  1.12  christos      instead of the usual address of the .o file.  Therefore,
    594  1.12  christos      we have to do some tricks to fill in texthigh and textlow.
    595  1.12  christos      The first trick is: if we see a static
    596  1.12  christos      or global function, and the textlow for the current pst
    597  1.12  christos      is not set (ie: textlow_not_set), then we use that function's
    598  1.12  christos      address for the textlow of the pst.  */
    599  1.12  christos 
    600  1.12  christos   /* Now, to fill in texthigh, we remember the last function seen
    601  1.12  christos      in the .o file.  Also, there's a hack in
    602  1.12  christos      bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
    603  1.12  christos      to here via the misc_info field.  Therefore, we can fill in
    604  1.12  christos      a reliable texthigh by taking the address plus size of the
    605  1.12  christos      last function in the file.  */
    606  1.12  christos 
    607  1.12  christos   if (!pst->text_high_valid && key->ctx.last_function_name
    608  1.12  christos       && gdbarch_sofun_address_maybe_missing (gdbarch))
    609  1.12  christos     {
    610  1.12  christos       int n;
    611  1.12  christos 
    612  1.12  christos       const char *colon = strchr (key->ctx.last_function_name, ':');
    613  1.12  christos       if (colon == NULL)
    614  1.12  christos 	n = 0;
    615  1.12  christos       else
    616  1.12  christos 	n = colon - key->ctx.last_function_name;
    617  1.12  christos       char *p = (char *) alloca (n + 2);
    618  1.12  christos       strncpy (p, key->ctx.last_function_name, n);
    619  1.12  christos       p[n] = 0;
    620  1.12  christos 
    621  1.12  christos       bound_minimal_symbol minsym
    622  1.12  christos 	= lookup_minimal_symbol (current_program_space, p, objfile,
    623  1.12  christos 				 pst->filename);
    624  1.12  christos       if (minsym.minsym == NULL)
    625  1.12  christos 	{
    626  1.12  christos 	  /* Sun Fortran appends an underscore to the minimal symbol name,
    627  1.12  christos 	     try again with an appended underscore if the minimal symbol
    628  1.12  christos 	     was not found.  */
    629  1.12  christos 	  p[n] = '_';
    630  1.12  christos 	  p[n + 1] = 0;
    631  1.12  christos 	  minsym = lookup_minimal_symbol (current_program_space, p, objfile,
    632  1.12  christos 					  pst->filename);
    633  1.12  christos 	}
    634  1.12  christos 
    635  1.12  christos       if (minsym.minsym)
    636  1.12  christos 	pst->set_text_high
    637  1.12  christos 	  (unrelocated_addr (CORE_ADDR (minsym.minsym->unrelocated_address ())
    638  1.12  christos 			     + minsym.minsym->size ()));
    639  1.12  christos 
    640  1.12  christos       key->ctx.last_function_name = NULL;
    641  1.12  christos     }
    642  1.12  christos 
    643  1.12  christos   if (!gdbarch_sofun_address_maybe_missing (gdbarch))
    644  1.12  christos     ;
    645  1.12  christos   /* This test will be true if the last .o file is only data.  */
    646  1.12  christos   else if (textlow_not_set)
    647  1.12  christos     pst->set_text_low (pst->unrelocated_text_high ());
    648  1.12  christos   else
    649  1.12  christos     {
    650  1.12  christos       /* If we know our own starting text address, then walk through all other
    651  1.12  christos 	 psymtabs for this objfile, and if any didn't know their ending text
    652  1.12  christos 	 address, set it to our starting address.  Take care to not set our
    653  1.12  christos 	 own ending address to our starting address.  */
    654  1.12  christos 
    655  1.12  christos       for (partial_symtab *p1 : partial_symtabs->range ())
    656  1.12  christos 	if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
    657  1.12  christos 	  p1->set_text_high (pst->unrelocated_text_low ());
    658  1.12  christos     }
    659  1.12  christos 
    660  1.12  christos   /* End of kludge for patching Solaris textlow and texthigh.  */
    661  1.12  christos 
    662  1.12  christos   pst->end ();
    663  1.12  christos 
    664  1.12  christos   pst->number_of_dependencies = number_dependencies;
    665  1.12  christos   if (number_dependencies)
    666  1.12  christos     {
    667  1.12  christos       pst->dependencies
    668  1.12  christos 	= partial_symtabs->allocate_dependencies (number_dependencies);
    669  1.12  christos       memcpy (pst->dependencies, dependency_list,
    670  1.12  christos 	      number_dependencies * sizeof (legacy_psymtab *));
    671  1.12  christos     }
    672  1.12  christos   else
    673  1.12  christos     pst->dependencies = 0;
    674  1.12  christos 
    675  1.12  christos   for (i = 0; i < num_includes; i++)
    676  1.12  christos     {
    677  1.12  christos       legacy_psymtab *subpst =
    678  1.12  christos 	new legacy_psymtab (include_list[i], partial_symtabs, objfile->per_bfd);
    679  1.12  christos 
    680  1.12  christos       subpst->read_symtab_private =
    681  1.12  christos 	XOBNEW (&objfile->objfile_obstack, struct symloc);
    682  1.12  christos       LDSYMOFF (subpst) =
    683  1.12  christos 	LDSYMLEN (subpst) = 0;
    684  1.12  christos 
    685  1.12  christos       /* We could save slight bits of space by only making one of these,
    686  1.12  christos 	 shared by the entire set of include files.  FIXME-someday.  */
    687  1.12  christos       subpst->dependencies =
    688  1.12  christos 	partial_symtabs->allocate_dependencies (1);
    689  1.12  christos       subpst->dependencies[0] = pst;
    690  1.12  christos       subpst->number_of_dependencies = 1;
    691  1.12  christos 
    692  1.12  christos       subpst->legacy_read_symtab = pst->legacy_read_symtab;
    693  1.12  christos       subpst->legacy_expand_psymtab = pst->legacy_expand_psymtab;
    694  1.12  christos     }
    695  1.12  christos 
    696  1.12  christos   if (num_includes == 0
    697  1.12  christos       && number_dependencies == 0
    698  1.12  christos       && pst->empty ()
    699  1.12  christos       && key->ctx.has_line_numbers == 0)
    700  1.12  christos     {
    701  1.12  christos       /* Throw away this psymtab, it's empty.  */
    702  1.12  christos       /* Empty psymtabs happen as a result of header files which don't have
    703  1.12  christos 	 any symbols in them.  There can be a lot of them.  But this check
    704  1.12  christos 	 is wrong, in that a psymtab with N_SLINE entries but nothing else
    705  1.12  christos 	 is not empty, but we don't realize that.  Fixing that without slowing
    706  1.12  christos 	 things down might be tricky.  */
    707  1.12  christos 
    708  1.12  christos       partial_symtabs->discard_psymtab (pst);
    709  1.12  christos 
    710  1.12  christos       /* Indicate that psymtab was thrown away.  */
    711  1.12  christos       pst = NULL;
    712  1.12  christos     }
    713  1.12  christos   return pst;
    714  1.12  christos }
    715  1.12  christos 
    716  1.12  christos /* Set namestring based on nlist.  If the string table index is invalid,
    717  1.12  christos    give a fake name, and print a single error message per symbol file read,
    718  1.12  christos    rather than abort the symbol reading or flood the user with messages.  */
    719  1.12  christos 
    720  1.12  christos static const char *
    721  1.12  christos set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
    722  1.12  christos {
    723  1.12  christos   const char *namestring;
    724  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    725  1.12  christos 
    726  1.12  christos   if (nlist->n_strx + key->ctx.file_string_table_offset
    727  1.12  christos       >= DBX_STRINGTAB_SIZE (objfile)
    728  1.12  christos       || nlist->n_strx + key->ctx.file_string_table_offset < nlist->n_strx)
    729  1.12  christos     {
    730  1.12  christos       complaint (_("bad string table offset in symbol %d"),
    731  1.12  christos 		 symnum);
    732  1.12  christos       namestring = "<bad string table offset>";
    733  1.12  christos     }
    734  1.12  christos   else
    735  1.12  christos     namestring = (nlist->n_strx + key->ctx.file_string_table_offset
    736  1.12  christos 		  + DBX_STRINGTAB (objfile));
    737  1.12  christos   return namestring;
    738  1.12  christos }
    739  1.12  christos 
    740  1.12  christos static void
    741  1.12  christos stabs_seek (int sym_offset, struct objfile *objfile)
    742  1.12  christos {
    743  1.12  christos   dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    744  1.12  christos   if (key->ctx.stabs_data)
    745  1.12  christos     {
    746  1.12  christos       key->ctx.symbuf_read += sym_offset;
    747  1.12  christos       key->ctx.symbuf_left -= sym_offset;
    748  1.12  christos     }
    749  1.12  christos   else
    750  1.12  christos     if (bfd_seek (objfile->obfd.get (), sym_offset, SEEK_CUR) != 0)
    751  1.12  christos       perror_with_name (bfd_get_filename (objfile->obfd.get ()));
    752  1.12  christos }
    753  1.12  christos 
    754  1.12  christos /* Buffer for reading the symbol table entries.  */
    755  1.12  christos static struct external_nlist symbuf[4096];
    756  1.12  christos static int symbuf_idx;
    757  1.12  christos static int symbuf_end;
    758  1.12  christos 
    759  1.12  christos /* Refill the symbol table input buffer
    760  1.12  christos    and set the variables that control fetching entries from it.
    761  1.12  christos    Reports an error if no data available.
    762  1.12  christos    This function can read past the end of the symbol table
    763  1.12  christos    (into the string table) but this does no harm.  */
    764  1.12  christos 
    765  1.12  christos static void
    766  1.12  christos fill_symbuf (bfd *sym_bfd, struct objfile *objfile)
    767  1.12  christos {
    768  1.12  christos   unsigned int count;
    769  1.12  christos   int nbytes;
    770  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    771  1.12  christos 
    772  1.12  christos   if (key->ctx.stabs_data)
    773  1.12  christos     {
    774  1.12  christos       nbytes = sizeof (symbuf);
    775  1.12  christos       if (nbytes > key->ctx.symbuf_left)
    776  1.12  christos 	nbytes = key->ctx.symbuf_left;
    777  1.12  christos       memcpy (symbuf, key->ctx.stabs_data + key->ctx.symbuf_read, nbytes);
    778  1.12  christos     }
    779  1.12  christos   else if (key->ctx.symbuf_sections == NULL)
    780  1.12  christos     {
    781  1.12  christos       count = sizeof (symbuf);
    782  1.12  christos       nbytes = bfd_read (symbuf, count, sym_bfd);
    783  1.12  christos     }
    784  1.12  christos   else
    785  1.12  christos     {
    786  1.12  christos       if (key->ctx.symbuf_left <= 0)
    787  1.12  christos 	{
    788  1.12  christos 	  file_ptr filepos = (*key->ctx.symbuf_sections)[key->ctx.sect_idx]->filepos;
    789  1.12  christos 
    790  1.12  christos 	  if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
    791  1.12  christos 	    perror_with_name (bfd_get_filename (sym_bfd));
    792  1.12  christos 	  key->ctx.symbuf_left = bfd_section_size ((*key->ctx.symbuf_sections)[key->ctx.sect_idx]);
    793  1.12  christos 	  key->ctx.symbol_table_offset = filepos - key->ctx.symbuf_read;
    794  1.12  christos 	  ++key->ctx.sect_idx;
    795  1.12  christos 	}
    796  1.12  christos 
    797  1.12  christos       count = key->ctx.symbuf_left;
    798  1.12  christos       if (count > sizeof (symbuf))
    799  1.12  christos 	count = sizeof (symbuf);
    800  1.12  christos       nbytes = bfd_read (symbuf, count, sym_bfd);
    801  1.12  christos     }
    802  1.12  christos 
    803  1.12  christos   if (nbytes < 0)
    804  1.12  christos     perror_with_name (bfd_get_filename (sym_bfd));
    805  1.12  christos   else if (nbytes == 0)
    806  1.12  christos     error (_("Premature end of file reading symbol table"));
    807  1.12  christos   symbuf_end = nbytes / key->ctx.symbol_size;
    808  1.12  christos   symbuf_idx = 0;
    809  1.12  christos   key->ctx.symbuf_left -= nbytes;
    810  1.12  christos   key->ctx.symbuf_read += nbytes;
    811  1.12  christos }
    812  1.12  christos 
    813  1.12  christos /* Read in a defined section of a specific object file's symbols.  */
    814  1.12  christos 
    815  1.12  christos static void
    816  1.12  christos read_ofile_symtab (struct objfile *objfile, legacy_psymtab *pst)
    817  1.12  christos {
    818  1.12  christos   const char *namestring;
    819  1.12  christos   struct external_nlist *bufp;
    820  1.12  christos   struct internal_nlist nlist;
    821  1.12  christos   unsigned char type;
    822  1.12  christos   unsigned max_symnum;
    823  1.12  christos   bfd *abfd;
    824  1.12  christos   int sym_offset;		/* Offset to start of symbols to read */
    825  1.12  christos   int sym_size;			/* Size of symbols to read */
    826  1.12  christos   CORE_ADDR text_offset;	/* Start of text segment for symbols */
    827  1.12  christos   int text_size;		/* Size of text segment for symbols */
    828  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    829  1.12  christos 
    830  1.12  christos   sym_offset = LDSYMOFF (pst);
    831  1.12  christos   sym_size = LDSYMLEN (pst);
    832  1.12  christos   text_offset = pst->text_low (objfile);
    833  1.12  christos   text_size = pst->text_high (objfile) - pst->text_low (objfile);
    834  1.12  christos   const section_offsets &section_offsets = objfile->section_offsets;
    835  1.12  christos 
    836  1.12  christos   key->ctx.stringtab_global = DBX_STRINGTAB (objfile);
    837  1.12  christos   set_last_source_file (NULL);
    838  1.12  christos 
    839  1.12  christos   abfd = objfile->obfd.get ();
    840  1.12  christos   symbuf_end = symbuf_idx = 0;
    841  1.12  christos   key->ctx.symbuf_read = 0;
    842  1.12  christos   key->ctx.symbuf_left = sym_offset + sym_size;
    843  1.12  christos 
    844  1.12  christos   /* It is necessary to actually read one symbol *before* the start
    845  1.12  christos      of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
    846  1.12  christos      occurs before the N_SO symbol.
    847  1.12  christos 
    848  1.12  christos      Detecting this in read_stabs_symtab
    849  1.12  christos      would slow down initial readin, so we look for it here instead.  */
    850  1.12  christos   if (!key->ctx.processing_acc_compilation && sym_offset >= (int) key->ctx.symbol_size)
    851  1.12  christos     {
    852  1.12  christos       stabs_seek (sym_offset - key->ctx.symbol_size, objfile);
    853  1.12  christos       fill_symbuf (abfd, objfile);
    854  1.12  christos       bufp = &symbuf[symbuf_idx++];
    855  1.12  christos       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
    856  1.12  christos       OBJSTAT (objfile, n_stabs++);
    857  1.12  christos 
    858  1.12  christos       namestring = set_namestring (objfile, &nlist);
    859  1.12  christos 
    860  1.12  christos       processing_gcc_compilation = 0;
    861  1.12  christos       if (nlist.n_type == N_TEXT)
    862  1.12  christos 	{
    863  1.12  christos 	  const char *tempstring = namestring;
    864  1.12  christos 
    865  1.12  christos 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
    866  1.12  christos 	    processing_gcc_compilation = 1;
    867  1.12  christos 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
    868  1.12  christos 	    processing_gcc_compilation = 2;
    869  1.12  christos 	  if (*tempstring != '\0'
    870  1.12  christos 	      && *tempstring == bfd_get_symbol_leading_char (objfile->obfd.get ()))
    871  1.12  christos 	    ++tempstring;
    872  1.12  christos 	  if (startswith (tempstring, "__gnu_compiled"))
    873  1.12  christos 	    processing_gcc_compilation = 2;
    874  1.12  christos 	}
    875  1.12  christos     }
    876  1.12  christos   else
    877  1.12  christos     {
    878  1.12  christos       /* The N_SO starting this symtab is the first symbol, so we
    879  1.12  christos 	 better not check the symbol before it.  I'm not this can
    880  1.12  christos 	 happen, but it doesn't hurt to check for it.  */
    881  1.12  christos       stabs_seek (sym_offset, objfile);
    882  1.12  christos       processing_gcc_compilation = 0;
    883  1.12  christos     }
    884  1.12  christos 
    885  1.12  christos   if (symbuf_idx == symbuf_end)
    886  1.12  christos     fill_symbuf (abfd, objfile);
    887  1.12  christos   bufp = &symbuf[symbuf_idx];
    888  1.12  christos   if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
    889  1.12  christos     error (_("First symbol in segment of executable not a source symbol"));
    890  1.12  christos 
    891  1.12  christos   max_symnum = sym_size / key->ctx.symbol_size;
    892  1.12  christos 
    893  1.12  christos   for (symnum = 0;
    894  1.12  christos        symnum < max_symnum;
    895  1.12  christos        symnum++)
    896  1.12  christos     {
    897  1.12  christos       QUIT;			/* Allow this to be interruptable.  */
    898  1.12  christos       if (symbuf_idx == symbuf_end)
    899  1.12  christos 	fill_symbuf (abfd, objfile);
    900  1.12  christos       bufp = &symbuf[symbuf_idx++];
    901  1.12  christos       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
    902  1.12  christos       OBJSTAT (objfile, n_stabs++);
    903  1.12  christos 
    904  1.12  christos       type = bfd_h_get_8 (abfd, bufp->e_type);
    905  1.12  christos 
    906  1.12  christos       namestring = set_namestring (objfile, &nlist);
    907  1.12  christos 
    908  1.12  christos       if (type & N_STAB)
    909  1.12  christos 	{
    910  1.12  christos 	  if (sizeof (nlist.n_value) > 4
    911  1.12  christos 	      /* We are a 64-bit debugger debugging a 32-bit program.  */
    912  1.12  christos 	      && (type == N_LSYM || type == N_PSYM))
    913  1.12  christos 	      /* We have to be careful with the n_value in the case of N_LSYM
    914  1.12  christos 		 and N_PSYM entries, because they are signed offsets from frame
    915  1.12  christos 		 pointer, but we actually read them as unsigned 32-bit values.
    916  1.12  christos 		 This is not a problem for 32-bit debuggers, for which negative
    917  1.12  christos 		 values end up being interpreted correctly (as negative
    918  1.12  christos 		 offsets) due to integer overflow.
    919  1.12  christos 		 But we need to sign-extend the value for 64-bit debuggers,
    920  1.12  christos 		 or we'll end up interpreting negative values as very large
    921  1.12  christos 		 positive offsets.  */
    922  1.12  christos 	    nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
    923  1.12  christos 	  process_one_symbol (type, nlist.n_desc, nlist.n_value,
    924  1.12  christos 			      namestring, section_offsets, objfile,
    925  1.12  christos 			      PST_LANGUAGE (pst));
    926  1.12  christos 	}
    927  1.12  christos       /* We skip checking for a new .o or -l file; that should never
    928  1.12  christos 	 happen in this routine.  */
    929  1.12  christos       else if (type == N_TEXT)
    930  1.12  christos 	{
    931  1.12  christos 	  /* I don't think this code will ever be executed, because
    932  1.12  christos 	     the GCC_COMPILED_FLAG_SYMBOL usually is right before
    933  1.12  christos 	     the N_SO symbol which starts this source file.
    934  1.12  christos 	     However, there is no reason not to accept
    935  1.12  christos 	     the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
    936  1.12  christos 
    937  1.12  christos 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
    938  1.12  christos 	    processing_gcc_compilation = 1;
    939  1.12  christos 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
    940  1.12  christos 	    processing_gcc_compilation = 2;
    941  1.12  christos 	}
    942  1.12  christos       else if (type & N_EXT || type == (unsigned char) N_TEXT
    943  1.12  christos 	       || type == (unsigned char) N_NBTEXT)
    944  1.12  christos 	{
    945  1.12  christos 	  /* Global symbol: see if we came across a dbx definition for
    946  1.12  christos 	     a corresponding symbol.  If so, store the value.  Remove
    947  1.12  christos 	     syms from the chain when their values are stored, but
    948  1.12  christos 	     search the whole chain, as there may be several syms from
    949  1.12  christos 	     different files with the same name.  */
    950  1.12  christos 	  /* This is probably not true.  Since the files will be read
    951  1.12  christos 	     in one at a time, each reference to a global symbol will
    952  1.12  christos 	     be satisfied in each file as it appears.  So we skip this
    953  1.12  christos 	     section.  */
    954  1.12  christos 	  ;
    955  1.12  christos 	}
    956  1.12  christos     }
    957  1.12  christos 
    958  1.12  christos   /* In a Solaris elf file, this variable, which comes from the value
    959  1.12  christos      of the N_SO symbol, will still be 0.  Luckily, text_offset, which
    960  1.12  christos      comes from low text address of PST, is correct.  */
    961  1.12  christos   if (get_last_source_start_addr () == 0)
    962  1.12  christos     set_last_source_start_addr (text_offset);
    963  1.12  christos 
    964  1.12  christos   /* In reordered executables last_source_start_addr may not be the
    965  1.12  christos      lower bound for this symtab, instead use text_offset which comes
    966  1.12  christos      from the low text address of PST, which is correct.  */
    967  1.12  christos   if (get_last_source_start_addr () > text_offset)
    968  1.12  christos     set_last_source_start_addr (text_offset);
    969  1.12  christos 
    970  1.12  christos   pst->compunit_symtab = end_compunit_symtab (text_offset + text_size);
    971  1.12  christos 
    972  1.12  christos   end_stabs ();
    973  1.12  christos 
    974  1.12  christos }
    975  1.12  christos 
    976  1.12  christos static void
    977  1.12  christos dbx_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
    978  1.12  christos {
    979  1.12  christos   gdb_assert (!pst->readin);
    980  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    981  1.12  christos 
    982  1.12  christos   /* Read in all partial symtabs on which this one is dependent.  */
    983  1.12  christos   pst->expand_dependencies (objfile);
    984  1.12  christos 
    985  1.12  christos   if (LDSYMLEN (pst))		/* Otherwise it's a dummy.  */
    986  1.12  christos     {
    987  1.12  christos       /* Init stuff necessary for reading in symbols */
    988  1.12  christos       stabsread_init ();
    989  1.12  christos       scoped_free_pendings free_pending;
    990  1.12  christos       key->ctx.file_string_table_offset = FILE_STRING_OFFSET (pst);
    991  1.12  christos       key->ctx.symbol_size = SYMBOL_SIZE (pst);
    992  1.12  christos 
    993  1.12  christos       /* Read in this file's symbols.  */
    994  1.12  christos       if (bfd_seek (objfile->obfd.get (), SYMBOL_OFFSET (pst), SEEK_SET) == 0)
    995  1.12  christos 	read_ofile_symtab (objfile, pst);
    996  1.12  christos     }
    997  1.12  christos 
    998  1.12  christos   pst->readin = true;
    999  1.12  christos }
   1000  1.12  christos 
   1001  1.12  christos /* Invariant: The symbol pointed to by symbuf_idx is the first one
   1002  1.12  christos    that hasn't been swapped.  Swap the symbol at the same time
   1003  1.12  christos    that symbuf_idx is incremented.  */
   1004  1.12  christos 
   1005  1.12  christos /* dbx allows the text of a symbol name to be continued into the
   1006  1.12  christos    next symbol name!  When such a continuation is encountered
   1007  1.12  christos    (a \ at the end of the text of a name)
   1008  1.12  christos    call this function to get the continuation.  */
   1009  1.12  christos 
   1010  1.12  christos static const char *
   1011  1.12  christos dbx_next_symbol_text (struct objfile *objfile)
   1012  1.12  christos {
   1013  1.12  christos   struct internal_nlist nlist;
   1014  1.12  christos   dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   1015  1.12  christos 
   1016  1.12  christos   if (symbuf_idx == symbuf_end)
   1017  1.12  christos     fill_symbuf (objfile->obfd.get (), objfile);
   1018  1.12  christos 
   1019  1.12  christos   symnum++;
   1020  1.12  christos   INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], objfile->obfd.get ());
   1021  1.12  christos   OBJSTAT (objfile, n_stabs++);
   1022  1.12  christos 
   1023  1.12  christos   symbuf_idx++;
   1024  1.12  christos 
   1025  1.12  christos   return nlist.n_strx + key->ctx.stringtab_global
   1026  1.12  christos     + key->ctx.file_string_table_offset;
   1027  1.12  christos }
   1028  1.12  christos 
   1029  1.12  christos /* Read in all of the symbols for a given psymtab for real.
   1030  1.12  christos    Be verbose about it if the user wants that.  SELF is not NULL.  */
   1031  1.12  christos 
   1032  1.12  christos static void
   1033  1.12  christos stabs_read_symtab (legacy_psymtab *self, struct objfile *objfile)
   1034  1.12  christos {
   1035  1.12  christos   gdb_assert (!self->readin);
   1036  1.12  christos 
   1037  1.12  christos   if (LDSYMLEN (self) || self->number_of_dependencies)
   1038  1.12  christos     {
   1039  1.12  christos       next_symbol_text_func = dbx_next_symbol_text;
   1040  1.12  christos       dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   1041  1.12  christos 
   1042  1.12  christos       {
   1043  1.12  christos 	scoped_restore restore_stabs_data = make_scoped_restore (&key->ctx.stabs_data);
   1044  1.12  christos 	gdb::unique_xmalloc_ptr<gdb_byte> data_holder;
   1045  1.12  christos 	if (DBX_STAB_SECTION (objfile))
   1046  1.12  christos 	  {
   1047  1.12  christos 	    key->ctx.stabs_data
   1048  1.12  christos 	      = symfile_relocate_debug_section (objfile,
   1049  1.12  christos 						DBX_STAB_SECTION (objfile),
   1050  1.12  christos 						NULL);
   1051  1.12  christos 	    data_holder.reset (key->ctx.stabs_data);
   1052  1.12  christos 	  }
   1053  1.12  christos 
   1054  1.12  christos 	self->expand_psymtab (objfile);
   1055  1.12  christos       }
   1056  1.12  christos 
   1057  1.12  christos       /* Match with global symbols.  This only needs to be done once,
   1058  1.12  christos 	 after all of the symtabs and dependencies have been read in.   */
   1059  1.12  christos       scan_file_globals (objfile);
   1060  1.12  christos     }
   1061  1.12  christos }
   1062  1.12  christos 
   1063  1.12  christos static void
   1064  1.12  christos record_minimal_symbol (minimal_symbol_reader &reader,
   1065  1.12  christos 		       const char *name, unrelocated_addr address, int type,
   1066  1.12  christos 		       struct objfile *objfile)
   1067  1.12  christos {
   1068  1.12  christos   enum minimal_symbol_type ms_type;
   1069  1.12  christos   int section;
   1070  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   1071  1.12  christos 
   1072  1.12  christos   switch (type)
   1073  1.12  christos     {
   1074  1.12  christos     case N_TEXT | N_EXT:
   1075  1.12  christos       ms_type = mst_text;
   1076  1.12  christos       section = SECT_OFF_TEXT (objfile);
   1077  1.12  christos       break;
   1078  1.12  christos     case N_DATA | N_EXT:
   1079  1.12  christos       ms_type = mst_data;
   1080  1.12  christos       section = SECT_OFF_DATA (objfile);
   1081  1.12  christos       break;
   1082  1.12  christos     case N_BSS | N_EXT:
   1083  1.12  christos       ms_type = mst_bss;
   1084  1.12  christos       section = SECT_OFF_BSS (objfile);
   1085  1.12  christos       break;
   1086  1.12  christos     case N_ABS | N_EXT:
   1087  1.12  christos       ms_type = mst_abs;
   1088  1.12  christos       section = -1;
   1089  1.12  christos       break;
   1090  1.12  christos #ifdef N_SETV
   1091  1.12  christos     case N_SETV | N_EXT:
   1092  1.12  christos       ms_type = mst_data;
   1093  1.12  christos       section = SECT_OFF_DATA (objfile);
   1094  1.12  christos       break;
   1095  1.12  christos     case N_SETV:
   1096  1.12  christos       /* I don't think this type actually exists; since a N_SETV is the result
   1097  1.12  christos 	 of going over many .o files, it doesn't make sense to have one
   1098  1.12  christos 	 file local.  */
   1099  1.12  christos       ms_type = mst_file_data;
   1100  1.12  christos       section = SECT_OFF_DATA (objfile);
   1101  1.12  christos       break;
   1102  1.12  christos #endif
   1103  1.12  christos     case N_TEXT:
   1104  1.12  christos     case N_NBTEXT:
   1105  1.12  christos     case N_FN:
   1106  1.12  christos     case N_FN_SEQ:
   1107  1.12  christos       ms_type = mst_file_text;
   1108  1.12  christos       section = SECT_OFF_TEXT (objfile);
   1109  1.12  christos       break;
   1110  1.12  christos     case N_DATA:
   1111  1.12  christos       ms_type = mst_file_data;
   1112  1.12  christos 
   1113  1.12  christos       /* Check for __DYNAMIC, which is used by Sun shared libraries.
   1114  1.12  christos 	 Record it as global even if it's local, not global, so
   1115  1.12  christos 	 lookup_minimal_symbol can find it.  We don't check symbol_leading_char
   1116  1.12  christos 	 because for SunOS4 it always is '_'.  */
   1117  1.12  christos       if (strcmp ("__DYNAMIC", name) == 0)
   1118  1.12  christos 	ms_type = mst_data;
   1119  1.12  christos 
   1120  1.12  christos       /* Same with virtual function tables, both global and static.  */
   1121  1.12  christos       {
   1122  1.12  christos 	const char *tempstring = name;
   1123  1.12  christos 
   1124  1.12  christos 	if (*tempstring != '\0'
   1125  1.12  christos 	    && *tempstring == bfd_get_symbol_leading_char (objfile->obfd.get ()))
   1126  1.12  christos 	  ++tempstring;
   1127  1.12  christos 	if (is_vtable_name (tempstring))
   1128  1.12  christos 	  ms_type = mst_data;
   1129  1.12  christos       }
   1130  1.12  christos       section = SECT_OFF_DATA (objfile);
   1131  1.12  christos       break;
   1132  1.12  christos     case N_BSS:
   1133  1.12  christos       ms_type = mst_file_bss;
   1134  1.12  christos       section = SECT_OFF_BSS (objfile);
   1135  1.12  christos       break;
   1136  1.12  christos     default:
   1137  1.12  christos       ms_type = mst_unknown;
   1138  1.12  christos       section = -1;
   1139  1.12  christos       break;
   1140  1.12  christos     }
   1141  1.12  christos 
   1142  1.12  christos   if ((ms_type == mst_file_text || ms_type == mst_text)
   1143  1.12  christos       && address < key->ctx.lowest_text_address)
   1144  1.12  christos     key->ctx.lowest_text_address = address;
   1145  1.12  christos 
   1146  1.12  christos   reader.record_with_info (name, address, ms_type, section);
   1147  1.12  christos }
   1148  1.12  christos 
   1149  1.12  christos /* Given a name, value pair, find the corresponding
   1150  1.12  christos    bincl in the list.  Return the partial symtab associated
   1151  1.12  christos    with that header_file_location.  */
   1152  1.12  christos 
   1153  1.12  christos static legacy_psymtab *
   1154  1.12  christos find_corresponding_bincl_psymtab (const char *name, int instance,
   1155  1.12  christos 				  struct objfile* objfile)
   1156  1.12  christos {
   1157  1.12  christos   stabsread_context ctx = dbx_objfile_data_key.get (objfile) -> ctx;
   1158  1.12  christos   for (const header_file_location &bincl : ctx.bincl_list)
   1159  1.12  christos     if (bincl.instance == instance
   1160  1.12  christos 	&& strcmp (name, bincl.name) == 0)
   1161  1.12  christos       return bincl.pst;
   1162  1.12  christos 
   1163  1.12  christos   repeated_header_complaint (name, symnum);
   1164  1.12  christos   return (legacy_psymtab *) 0;
   1165  1.12  christos }
   1166  1.12  christos 
   1167  1.12  christos /* Allocate and partially fill a partial symtab.  It will be
   1168  1.12  christos    completely filled at the end of the symbol list.
   1169  1.12  christos 
   1170  1.12  christos    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
   1171  1.12  christos    is the address relative to which its symbols are (incremental) or 0
   1172  1.12  christos    (normal).  */
   1173  1.12  christos 
   1174  1.12  christos static legacy_psymtab *
   1175  1.12  christos start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
   1176  1.12  christos 	       const char *filename, unrelocated_addr textlow, int ldsymoff)
   1177  1.12  christos {
   1178  1.12  christos   legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
   1179  1.12  christos 					       objfile->per_bfd, textlow);
   1180  1.12  christos 
   1181  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get(objfile);
   1182  1.12  christos 
   1183  1.12  christos   result->read_symtab_private =
   1184  1.12  christos     XOBNEW (&objfile->objfile_obstack, struct symloc);
   1185  1.12  christos   LDSYMOFF (result) = ldsymoff;
   1186  1.12  christos   result->legacy_read_symtab = stabs_read_symtab;
   1187  1.12  christos   result->legacy_expand_psymtab = dbx_expand_psymtab;
   1188  1.12  christos   SYMBOL_SIZE (result) = key->ctx.symbol_size;
   1189  1.12  christos   SYMBOL_OFFSET (result) = key->ctx.symbol_table_offset;
   1190  1.12  christos   STRING_OFFSET (result) = 0; /* This used to be an uninitialized global.  */
   1191  1.12  christos   FILE_STRING_OFFSET (result) = key->ctx.file_string_table_offset;
   1192  1.12  christos 
   1193  1.12  christos   /* Deduce the source language from the filename for this psymtab.  */
   1194  1.12  christos   key->ctx.psymtab_language = deduce_language_from_filename (filename);
   1195  1.12  christos   PST_LANGUAGE (result) = key->ctx.psymtab_language;
   1196  1.12  christos 
   1197  1.12  christos   return result;
   1198  1.12  christos }
   1199  1.12  christos 
   1200  1.12  christos /* See stabsread.h. */
   1201  1.12  christos 
   1202  1.12  christos static void
   1203  1.12  christos read_stabs_symtab_1 (minimal_symbol_reader &reader,
   1204  1.12  christos 		     psymtab_storage *partial_symtabs,
   1205  1.12  christos 		     struct objfile *objfile)
   1206  1.12  christos {
   1207  1.12  christos   struct gdbarch *gdbarch = objfile->arch ();
   1208  1.12  christos   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch.  */
   1209  1.12  christos   struct internal_nlist nlist;
   1210  1.12  christos   CORE_ADDR text_addr;
   1211  1.12  christos   int text_size;
   1212  1.12  christos   const char *sym_name;
   1213  1.12  christos   int sym_len;
   1214  1.12  christos   unsigned int next_file_string_table_offset = 0;
   1215  1.12  christos   struct dbx_symfile_info *dbx = dbx_objfile_data_key.get(objfile);
   1216  1.12  christos 
   1217  1.12  christos   const char *namestring;
   1218  1.12  christos   int nsl;
   1219  1.12  christos   int past_first_source_file = 0;
   1220  1.12  christos   CORE_ADDR last_function_start = 0;
   1221  1.12  christos   bfd *abfd;
   1222  1.12  christos   int textlow_not_set;
   1223  1.12  christos   int data_sect_index;
   1224  1.12  christos 
   1225  1.12  christos   /* Current partial symtab.  */
   1226  1.12  christos   legacy_psymtab *pst;
   1227  1.12  christos 
   1228  1.12  christos   /* List of current psymtab's include files.  */
   1229  1.12  christos   const char **psymtab_include_list;
   1230  1.12  christos   int includes_allocated;
   1231  1.12  christos   int includes_used;
   1232  1.12  christos 
   1233  1.12  christos   /* Index within current psymtab dependency list.  */
   1234  1.12  christos   legacy_psymtab **dependency_list;
   1235  1.12  christos   int dependencies_used, dependencies_allocated;
   1236  1.12  christos 
   1237  1.12  christos   text_addr = DBX_TEXT_ADDR (objfile);
   1238  1.12  christos   text_size = DBX_TEXT_SIZE (objfile);
   1239  1.12  christos 
   1240  1.12  christos   /* FIXME.  We probably want to change stringtab_global rather than add this
   1241  1.12  christos      while processing every symbol entry.  FIXME.  */
   1242  1.12  christos   dbx->ctx.file_string_table_offset = 0;
   1243  1.12  christos 
   1244  1.12  christos   dbx->ctx.stringtab_global = DBX_STRINGTAB (objfile);
   1245  1.12  christos 
   1246  1.12  christos   pst = (legacy_psymtab *) 0;
   1247  1.12  christos 
   1248  1.12  christos   includes_allocated = 30;
   1249  1.12  christos   includes_used = 0;
   1250  1.12  christos   psymtab_include_list = (const char **) alloca (includes_allocated *
   1251  1.12  christos 						 sizeof (const char *));
   1252  1.12  christos 
   1253  1.12  christos   dependencies_allocated = 30;
   1254  1.12  christos   dependencies_used = 0;
   1255  1.12  christos   dependency_list =
   1256  1.12  christos     (legacy_psymtab **) alloca (dependencies_allocated *
   1257  1.12  christos 				sizeof (legacy_psymtab *));
   1258  1.12  christos 
   1259  1.12  christos   /* Init bincl list */
   1260  1.12  christos   std::vector<struct header_file_location> bincl_storage;
   1261  1.12  christos   scoped_restore restore_bincl_global
   1262  1.12  christos     = make_scoped_restore (&(dbx->ctx.bincl_list), bincl_storage);
   1263  1.12  christos 
   1264  1.12  christos   set_last_source_file (NULL);
   1265  1.12  christos 
   1266  1.12  christos   dbx->ctx.lowest_text_address = (unrelocated_addr) -1;
   1267  1.12  christos 
   1268  1.12  christos   abfd = objfile->obfd.get ();
   1269  1.12  christos   symbuf_end = symbuf_idx = 0;
   1270  1.12  christos   next_symbol_text_func = dbx_next_symbol_text;
   1271  1.12  christos   textlow_not_set = 1;
   1272  1.12  christos   dbx->ctx.has_line_numbers = 0;
   1273  1.12  christos 
   1274  1.12  christos   /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
   1275  1.12  christos      to global and static variables.  The stab for a global or static
   1276  1.12  christos      variable doesn't give us any indication of which section it's in,
   1277  1.12  christos      so we can't tell immediately which offset in
   1278  1.12  christos      objfile->section_offsets we should apply to the variable's
   1279  1.12  christos      address.
   1280  1.12  christos 
   1281  1.12  christos      We could certainly find out which section contains the variable
   1282  1.12  christos      by looking up the variable's unrelocated address with
   1283  1.12  christos      find_pc_section, but that would be expensive; this is the
   1284  1.12  christos      function that constructs the partial symbol tables by examining
   1285  1.12  christos      every symbol in the entire executable, and it's
   1286  1.12  christos      performance-critical.  So that expense would not be welcome.  I'm
   1287  1.12  christos      not sure what to do about this at the moment.
   1288  1.12  christos 
   1289  1.12  christos      What we have done for years is to simply assume that the .data
   1290  1.12  christos      section's offset is appropriate for all global and static
   1291  1.12  christos      variables.  Recently, this was expanded to fall back to the .bss
   1292  1.12  christos      section's offset if there is no .data section, and then to the
   1293  1.12  christos      .rodata section's offset.  */
   1294  1.12  christos   data_sect_index = objfile->sect_index_data;
   1295  1.12  christos   if (data_sect_index == -1)
   1296  1.12  christos     data_sect_index = SECT_OFF_BSS (objfile);
   1297  1.12  christos   if (data_sect_index == -1)
   1298  1.12  christos     data_sect_index = SECT_OFF_RODATA (objfile);
   1299  1.12  christos 
   1300  1.12  christos   /* If data_sect_index is still -1, that's okay.  It's perfectly fine
   1301  1.12  christos      for the file to have no .data, no .bss, and no .text at all, if
   1302  1.12  christos      it also has no global or static variables.  */
   1303  1.12  christos 
   1304  1.12  christos   for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
   1305  1.12  christos     {
   1306  1.12  christos       /* Get the symbol for this run and pull out some info.  */
   1307  1.12  christos       QUIT;			/* Allow this to be interruptable.  */
   1308  1.12  christos       if (symbuf_idx == symbuf_end)
   1309  1.12  christos 	fill_symbuf (abfd, objfile);
   1310  1.12  christos       bufp = &symbuf[symbuf_idx++];
   1311  1.12  christos 
   1312  1.12  christos       /*
   1313  1.12  christos        * Special case to speed up readin.
   1314  1.12  christos        */
   1315  1.12  christos       if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
   1316  1.12  christos 	{
   1317  1.12  christos 	  dbx->ctx.has_line_numbers = 1;
   1318  1.12  christos 	  continue;
   1319  1.12  christos 	}
   1320  1.12  christos 
   1321  1.12  christos       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   1322  1.12  christos       OBJSTAT (objfile, n_stabs++);
   1323  1.12  christos 
   1324  1.12  christos       /* Ok.  There is a lot of code duplicated in the rest of this
   1325  1.12  christos 	 switch statement (for efficiency reasons).  Since I don't
   1326  1.12  christos 	 like duplicating code, I will do my penance here, and
   1327  1.12  christos 	 describe the code which is duplicated:
   1328  1.12  christos 
   1329  1.12  christos 	 *) The assignment to namestring.
   1330  1.12  christos 	 *) The call to strchr.
   1331  1.12  christos 	 *) The addition of a partial symbol the two partial
   1332  1.12  christos 	 symbol lists.  This last is a large section of code, so
   1333  1.12  christos 	 I've embedded it in the following macro.  */
   1334  1.12  christos 
   1335  1.12  christos       switch (nlist.n_type)
   1336  1.12  christos 	{
   1337  1.12  christos 	  /*
   1338  1.12  christos 	   * Standard, external, non-debugger, symbols
   1339  1.12  christos 	   */
   1340  1.12  christos 
   1341  1.12  christos 	case N_TEXT | N_EXT:
   1342  1.12  christos 	case N_NBTEXT | N_EXT:
   1343  1.12  christos 	  goto record_it;
   1344  1.12  christos 
   1345  1.12  christos 	case N_DATA | N_EXT:
   1346  1.12  christos 	case N_NBDATA | N_EXT:
   1347  1.12  christos 	  goto record_it;
   1348  1.12  christos 
   1349  1.12  christos 	case N_BSS:
   1350  1.12  christos 	case N_BSS | N_EXT:
   1351  1.12  christos 	case N_NBBSS | N_EXT:
   1352  1.12  christos 	case N_SETV | N_EXT:		/* FIXME, is this in BSS? */
   1353  1.12  christos 	  goto record_it;
   1354  1.12  christos 
   1355  1.12  christos 	case N_ABS | N_EXT:
   1356  1.12  christos 	  record_it:
   1357  1.12  christos 	  namestring = set_namestring (objfile, &nlist);
   1358  1.12  christos 
   1359  1.12  christos 	  record_minimal_symbol (reader, namestring,
   1360  1.12  christos 				 unrelocated_addr (nlist.n_value),
   1361  1.12  christos 				 nlist.n_type, objfile);	/* Always */
   1362  1.12  christos 	  continue;
   1363  1.12  christos 
   1364  1.12  christos 	  /* Standard, local, non-debugger, symbols.  */
   1365  1.12  christos 
   1366  1.12  christos 	case N_NBTEXT:
   1367  1.12  christos 
   1368  1.12  christos 	  /* We need to be able to deal with both N_FN or N_TEXT,
   1369  1.12  christos 	     because we have no way of knowing whether the sys-supplied ld
   1370  1.12  christos 	     or GNU ld was used to make the executable.  Sequents throw
   1371  1.12  christos 	     in another wrinkle -- they renumbered N_FN.  */
   1372  1.12  christos 
   1373  1.12  christos 	case N_FN:
   1374  1.12  christos 	case N_FN_SEQ:
   1375  1.12  christos 	case N_TEXT:
   1376  1.12  christos 	  namestring = set_namestring (objfile, &nlist);
   1377  1.12  christos 
   1378  1.12  christos 	  if ((namestring[0] == '-' && namestring[1] == 'l')
   1379  1.12  christos 	      || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
   1380  1.12  christos 		  && namestring[nsl - 2] == '.'))
   1381  1.12  christos 	    {
   1382  1.12  christos 	      unrelocated_addr unrel_val = unrelocated_addr (nlist.n_value);
   1383  1.12  christos 
   1384  1.12  christos 	      if (past_first_source_file && pst
   1385  1.12  christos 		  /* The gould NP1 uses low values for .o and -l symbols
   1386  1.12  christos 		     which are not the address.  */
   1387  1.12  christos 		  && unrel_val >= pst->unrelocated_text_low ())
   1388  1.12  christos 		{
   1389  1.12  christos 		  stabs_end_psymtab (objfile, partial_symtabs,
   1390  1.12  christos 				     pst, psymtab_include_list,
   1391  1.12  christos 				     includes_used, symnum * dbx->ctx.symbol_size,
   1392  1.12  christos 				     unrel_val > pst->unrelocated_text_high ()
   1393  1.12  christos 				     ? unrel_val : pst->unrelocated_text_high (),
   1394  1.12  christos 				     dependency_list, dependencies_used,
   1395  1.12  christos 				     textlow_not_set);
   1396  1.12  christos 		  pst = (legacy_psymtab *) 0;
   1397  1.12  christos 		  includes_used = 0;
   1398  1.12  christos 		  dependencies_used = 0;
   1399  1.12  christos 		  dbx->ctx.has_line_numbers = 0;
   1400  1.12  christos 		}
   1401  1.12  christos 	      else
   1402  1.12  christos 		past_first_source_file = 1;
   1403  1.12  christos 	    }
   1404  1.12  christos 	  else
   1405  1.12  christos 	    goto record_it;
   1406  1.12  christos 	  continue;
   1407  1.12  christos 
   1408  1.12  christos 	case N_DATA:
   1409  1.12  christos 	  goto record_it;
   1410  1.12  christos 
   1411  1.12  christos 	case N_UNDF | N_EXT:
   1412  1.12  christos 	  /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
   1413  1.12  christos 	     We used to rely on the target to tell us whether it knows
   1414  1.12  christos 	     where the symbol has been relocated to, but none of the
   1415  1.12  christos 	     target implementations actually provided that operation.
   1416  1.12  christos 	     So we just ignore the symbol, the same way we would do if
   1417  1.12  christos 	     we had a target-side symbol lookup which returned no match.
   1418  1.12  christos 
   1419  1.12  christos 	     All other symbols (with nlist.n_value == 0), are really
   1420  1.12  christos 	     undefined, and so we ignore them too.  */
   1421  1.12  christos 	  continue;
   1422  1.12  christos 
   1423  1.12  christos 	case N_UNDF:
   1424  1.12  christos 	  if (dbx->ctx.processing_acc_compilation && nlist.n_strx == 1)
   1425  1.12  christos 	    {
   1426  1.12  christos 	      /* Deal with relative offsets in the string table
   1427  1.12  christos 		 used in ELF+STAB under Solaris.  If we want to use the
   1428  1.12  christos 		 n_strx field, which contains the name of the file,
   1429  1.12  christos 		 we must adjust file_string_table_offset *before* calling
   1430  1.12  christos 		 set_namestring().  */
   1431  1.12  christos 	      past_first_source_file = 1;
   1432  1.12  christos 	      dbx->ctx.file_string_table_offset = next_file_string_table_offset;
   1433  1.12  christos 	     next_file_string_table_offset =
   1434  1.12  christos 		dbx->ctx.file_string_table_offset + nlist.n_value;
   1435  1.12  christos 	      if (next_file_string_table_offset < dbx->ctx.file_string_table_offset)
   1436  1.12  christos 		error (_("string table offset backs up at %d"), symnum);
   1437  1.12  christos 	      /* FIXME -- replace error() with complaint.  */
   1438  1.12  christos 	      continue;
   1439  1.12  christos 	    }
   1440  1.12  christos 	  continue;
   1441  1.12  christos 
   1442  1.12  christos 	  /* Lots of symbol types we can just ignore.  */
   1443  1.12  christos 
   1444  1.12  christos 	case N_ABS:
   1445  1.12  christos 	case N_NBDATA:
   1446  1.12  christos 	case N_NBBSS:
   1447  1.12  christos 	  continue;
   1448  1.12  christos 
   1449  1.12  christos 	  /* Keep going . . .  */
   1450  1.12  christos 
   1451  1.12  christos 	  /*
   1452  1.12  christos 	   * Special symbol types for GNU
   1453  1.12  christos 	   */
   1454  1.12  christos 	case N_INDR:
   1455  1.12  christos 	case N_INDR | N_EXT:
   1456  1.12  christos 	case N_SETA:
   1457  1.12  christos 	case N_SETA | N_EXT:
   1458  1.12  christos 	case N_SETT:
   1459  1.12  christos 	case N_SETT | N_EXT:
   1460  1.12  christos 	case N_SETD:
   1461  1.12  christos 	case N_SETD | N_EXT:
   1462  1.12  christos 	case N_SETB:
   1463  1.12  christos 	case N_SETB | N_EXT:
   1464  1.12  christos 	case N_SETV:
   1465  1.12  christos 	  continue;
   1466  1.12  christos 
   1467  1.12  christos 	  /*
   1468  1.12  christos 	   * Debugger symbols
   1469  1.12  christos 	   */
   1470  1.12  christos 
   1471  1.12  christos 	case N_SO:
   1472  1.12  christos 	  {
   1473  1.12  christos 	    CORE_ADDR valu;
   1474  1.12  christos 	    static int prev_so_symnum = -10;
   1475  1.12  christos 	    static int first_so_symnum;
   1476  1.12  christos 	    const char *p;
   1477  1.12  christos 	    static const char *dirname_nso;
   1478  1.12  christos 	    int prev_textlow_not_set;
   1479  1.12  christos 
   1480  1.12  christos 	    valu = nlist.n_value;
   1481  1.12  christos 
   1482  1.12  christos 	    prev_textlow_not_set = textlow_not_set;
   1483  1.12  christos 
   1484  1.12  christos 	    /* A zero value is probably an indication for the SunPRO 3.0
   1485  1.12  christos 	       compiler.  stabs_end_psymtab explicitly tests for zero, so
   1486  1.12  christos 	       don't relocate it.  */
   1487  1.12  christos 
   1488  1.12  christos 	    if (nlist.n_value == 0
   1489  1.12  christos 		&& gdbarch_sofun_address_maybe_missing (gdbarch))
   1490  1.12  christos 	      {
   1491  1.12  christos 		textlow_not_set = 1;
   1492  1.12  christos 		valu = 0;
   1493  1.12  christos 	      }
   1494  1.12  christos 	    else
   1495  1.12  christos 	      textlow_not_set = 0;
   1496  1.12  christos 
   1497  1.12  christos 	    past_first_source_file = 1;
   1498  1.12  christos 
   1499  1.12  christos 	    if (prev_so_symnum != symnum - 1)
   1500  1.12  christos 	      {			/* Here if prev stab wasn't N_SO.  */
   1501  1.12  christos 		first_so_symnum = symnum;
   1502  1.12  christos 
   1503  1.12  christos 		if (pst)
   1504  1.12  christos 		  {
   1505  1.12  christos 		    unrelocated_addr unrel_value = unrelocated_addr (valu);
   1506  1.12  christos 		    stabs_end_psymtab (objfile, partial_symtabs,
   1507  1.12  christos 				       pst, psymtab_include_list,
   1508  1.12  christos 				       includes_used, symnum * dbx->ctx.symbol_size,
   1509  1.12  christos 				       unrel_value > pst->unrelocated_text_high ()
   1510  1.12  christos 				       ? unrel_value
   1511  1.12  christos 				       : pst->unrelocated_text_high (),
   1512  1.12  christos 				       dependency_list, dependencies_used,
   1513  1.12  christos 				       prev_textlow_not_set);
   1514  1.12  christos 		    pst = (legacy_psymtab *) 0;
   1515  1.12  christos 		    includes_used = 0;
   1516  1.12  christos 		    dependencies_used = 0;
   1517  1.12  christos 		    dbx->ctx.has_line_numbers = 0;
   1518  1.12  christos 		  }
   1519  1.12  christos 	      }
   1520  1.12  christos 
   1521  1.12  christos 	    prev_so_symnum = symnum;
   1522  1.12  christos 
   1523  1.12  christos 	    /* End the current partial symtab and start a new one.  */
   1524  1.12  christos 
   1525  1.12  christos 	    namestring = set_namestring (objfile, &nlist);
   1526  1.12  christos 
   1527  1.12  christos 	    /* Null name means end of .o file.  Don't start a new one.  */
   1528  1.12  christos 	    if (*namestring == '\000')
   1529  1.12  christos 	      continue;
   1530  1.12  christos 
   1531  1.12  christos 	    /* Some compilers (including gcc) emit a pair of initial N_SOs.
   1532  1.12  christos 	       The first one is a directory name; the second the file name.
   1533  1.12  christos 	       If pst exists, is empty, and has a filename ending in '/',
   1534  1.12  christos 	       we assume the previous N_SO was a directory name.  */
   1535  1.12  christos 
   1536  1.12  christos 	    p = lbasename (namestring);
   1537  1.12  christos 	    if (p != namestring && *p == '\000')
   1538  1.12  christos 	      {
   1539  1.12  christos 		/* Save the directory name SOs locally, then save it into
   1540  1.12  christos 		   the psymtab when it's created below.  */
   1541  1.12  christos 		dirname_nso = namestring;
   1542  1.12  christos 		continue;
   1543  1.12  christos 	      }
   1544  1.12  christos 
   1545  1.12  christos 	    /* Some other compilers (C++ ones in particular) emit useless
   1546  1.12  christos 	       SOs for non-existant .c files.  We ignore all subsequent SOs
   1547  1.12  christos 	       that immediately follow the first.  */
   1548  1.12  christos 
   1549  1.12  christos 	    if (!pst)
   1550  1.12  christos 	      {
   1551  1.12  christos 		pst = start_psymtab (partial_symtabs, objfile,
   1552  1.12  christos 				     namestring,
   1553  1.12  christos 				     unrelocated_addr (valu),
   1554  1.12  christos 				     first_so_symnum * dbx->ctx.symbol_size);
   1555  1.12  christos 		pst->dirname = dirname_nso;
   1556  1.12  christos 		dirname_nso = NULL;
   1557  1.12  christos 	      }
   1558  1.12  christos 	    continue;
   1559  1.12  christos 	  }
   1560  1.12  christos 
   1561  1.12  christos 	case N_BINCL:
   1562  1.12  christos 	  {
   1563  1.12  christos 	    enum language tmp_language;
   1564  1.12  christos 
   1565  1.12  christos 	    /* Add this bincl to the bincl_list for future EXCLs.  No
   1566  1.12  christos 	       need to save the string; it'll be around until
   1567  1.12  christos 	       read_stabs_symtab function returns.  */
   1568  1.12  christos 
   1569  1.12  christos 	    namestring = set_namestring (objfile, &nlist);
   1570  1.12  christos 	    tmp_language = deduce_language_from_filename (namestring);
   1571  1.12  christos 
   1572  1.12  christos 	    /* Only change the psymtab's language if we've learned
   1573  1.12  christos 	       something useful (eg. tmp_language is not language_unknown).
   1574  1.12  christos 	       In addition, to match what start_subfile does, never change
   1575  1.12  christos 	       from C++ to C.  */
   1576  1.12  christos 	    if (tmp_language != language_unknown
   1577  1.12  christos 		&& (tmp_language != language_c
   1578  1.12  christos 		    || dbx->ctx.psymtab_language != language_cplus))
   1579  1.12  christos 	      dbx->ctx.psymtab_language = tmp_language;
   1580  1.12  christos 
   1581  1.12  christos 	    if (pst == NULL)
   1582  1.12  christos 	      {
   1583  1.12  christos 		/* FIXME: we should not get here without a PST to work on.
   1584  1.12  christos 		   Attempt to recover.  */
   1585  1.12  christos 		complaint (_("N_BINCL %s not in entries for "
   1586  1.12  christos 			     "any file, at symtab pos %d"),
   1587  1.12  christos 			   namestring, symnum);
   1588  1.12  christos 		continue;
   1589  1.12  christos 	      }
   1590  1.12  christos 	    dbx->ctx.bincl_list.emplace_back (namestring, nlist.n_value, pst);
   1591  1.12  christos 
   1592  1.12  christos 	    /* Mark down an include file in the current psymtab.  */
   1593  1.12  christos 
   1594  1.12  christos 	    goto record_include_file;
   1595  1.12  christos 	  }
   1596  1.12  christos 
   1597  1.12  christos 	case N_SOL:
   1598  1.12  christos 	  {
   1599  1.12  christos 	    enum language tmp_language;
   1600  1.12  christos 
   1601  1.12  christos 	    /* Mark down an include file in the current psymtab.  */
   1602  1.12  christos 	    namestring = set_namestring (objfile, &nlist);
   1603  1.12  christos 	    tmp_language = deduce_language_from_filename (namestring);
   1604  1.12  christos 
   1605  1.12  christos 	    /* Only change the psymtab's language if we've learned
   1606  1.12  christos 	       something useful (eg. tmp_language is not language_unknown).
   1607  1.12  christos 	       In addition, to match what start_subfile does, never change
   1608  1.12  christos 	       from C++ to C.  */
   1609  1.12  christos 	    if (tmp_language != language_unknown
   1610  1.12  christos 		&& (tmp_language != language_c
   1611  1.12  christos 		    || dbx->ctx.psymtab_language != language_cplus))
   1612  1.12  christos 	      dbx->ctx.psymtab_language = tmp_language;
   1613  1.12  christos 
   1614  1.12  christos 	    /* In C++, one may expect the same filename to come round many
   1615  1.12  christos 	       times, when code is coming alternately from the main file
   1616  1.12  christos 	       and from inline functions in other files.  So I check to see
   1617  1.12  christos 	       if this is a file we've seen before -- either the main
   1618  1.12  christos 	       source file, or a previously included file.
   1619  1.12  christos 
   1620  1.12  christos 	       This seems to be a lot of time to be spending on N_SOL, but
   1621  1.12  christos 	       things like "break c-exp.y:435" need to work (I
   1622  1.12  christos 	       suppose the psymtab_include_list could be hashed or put
   1623  1.12  christos 	       in a binary tree, if profiling shows this is a major hog).  */
   1624  1.12  christos 	    if (pst && filename_cmp (namestring, pst->filename) == 0)
   1625  1.12  christos 	      continue;
   1626  1.12  christos 	    {
   1627  1.12  christos 	      int i;
   1628  1.12  christos 
   1629  1.12  christos 	      for (i = 0; i < includes_used; i++)
   1630  1.12  christos 		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
   1631  1.12  christos 		  {
   1632  1.12  christos 		    i = -1;
   1633  1.12  christos 		    break;
   1634  1.12  christos 		  }
   1635  1.12  christos 	      if (i == -1)
   1636  1.12  christos 		continue;
   1637  1.12  christos 	    }
   1638  1.12  christos 
   1639  1.12  christos 	  record_include_file:
   1640  1.12  christos 
   1641  1.12  christos 	    psymtab_include_list[includes_used++] = namestring;
   1642  1.12  christos 	    if (includes_used >= includes_allocated)
   1643  1.12  christos 	      {
   1644  1.12  christos 		const char **orig = psymtab_include_list;
   1645  1.12  christos 
   1646  1.12  christos 		psymtab_include_list = (const char **)
   1647  1.12  christos 		  alloca ((includes_allocated *= 2) * sizeof (const char *));
   1648  1.12  christos 		memcpy (psymtab_include_list, orig,
   1649  1.12  christos 			includes_used * sizeof (const char *));
   1650  1.12  christos 	      }
   1651  1.12  christos 	    continue;
   1652  1.12  christos 	  }
   1653  1.12  christos 	case N_LSYM:		/* Typedef or automatic variable.  */
   1654  1.12  christos 	case N_STSYM:		/* Data seg var -- static.  */
   1655  1.12  christos 	case N_LCSYM:		/* BSS      "  */
   1656  1.12  christos 	case N_ROSYM:		/* Read-only data seg var -- static.  */
   1657  1.12  christos 	case N_NBSTS:		/* Gould nobase.  */
   1658  1.12  christos 	case N_NBLCS:		/* symbols.  */
   1659  1.12  christos 	case N_FUN:
   1660  1.12  christos 	case N_GSYM:		/* Global (extern) variable; can be
   1661  1.12  christos 				   data or bss (sigh FIXME).  */
   1662  1.12  christos 
   1663  1.12  christos 	  /* Following may probably be ignored; I'll leave them here
   1664  1.12  christos 	     for now (until I do Pascal and Modula 2 extensions).  */
   1665  1.12  christos 
   1666  1.12  christos 	case N_PC:		/* I may or may not need this; I
   1667  1.12  christos 				   suspect not.  */
   1668  1.12  christos 	case N_M2C:		/* I suspect that I can ignore this here.  */
   1669  1.12  christos 	case N_SCOPE:		/* Same.   */
   1670  1.12  christos 	{
   1671  1.12  christos 	  const char *p;
   1672  1.12  christos 
   1673  1.12  christos 	  namestring = set_namestring (objfile, &nlist);
   1674  1.12  christos 
   1675  1.12  christos 	  /* See if this is an end of function stab.  */
   1676  1.12  christos 	  if (pst && nlist.n_type == N_FUN && *namestring == '\000')
   1677  1.12  christos 	    {
   1678  1.12  christos 	      unrelocated_addr valu;
   1679  1.12  christos 
   1680  1.12  christos 	      /* It's value is the size (in bytes) of the function for
   1681  1.12  christos 		 function relative stabs, or the address of the function's
   1682  1.12  christos 		 end for old style stabs.  */
   1683  1.12  christos 	      valu = unrelocated_addr (nlist.n_value + last_function_start);
   1684  1.12  christos 	      if (pst->unrelocated_text_high () == unrelocated_addr (0)
   1685  1.12  christos 		  || valu > pst->unrelocated_text_high ())
   1686  1.12  christos 		pst->set_text_high (valu);
   1687  1.12  christos 	      break;
   1688  1.12  christos 	    }
   1689  1.12  christos 
   1690  1.12  christos 	  p = (char *) strchr (namestring, ':');
   1691  1.12  christos 	  if (!p)
   1692  1.12  christos 	    continue;		/* Not a debugging symbol.   */
   1693  1.12  christos 
   1694  1.12  christos 	  sym_len = 0;
   1695  1.12  christos 	  sym_name = NULL;	/* pacify "gcc -Werror" */
   1696  1.12  christos 	  if (dbx->ctx.psymtab_language == language_cplus)
   1697  1.12  christos 	    {
   1698  1.12  christos 	      std::string name (namestring, p - namestring);
   1699  1.12  christos 	      gdb::unique_xmalloc_ptr<char> new_name
   1700  1.12  christos 		= cp_canonicalize_string (name.c_str ());
   1701  1.12  christos 	      if (new_name != nullptr)
   1702  1.12  christos 		{
   1703  1.12  christos 		  sym_len = strlen (new_name.get ());
   1704  1.12  christos 		  sym_name = obstack_strdup (&objfile->objfile_obstack,
   1705  1.12  christos 					     new_name.get ());
   1706  1.12  christos 		}
   1707  1.12  christos 	    }
   1708  1.12  christos 	  else if (dbx->ctx.psymtab_language == language_c)
   1709  1.12  christos 	    {
   1710  1.12  christos 	      std::string name (namestring, p - namestring);
   1711  1.12  christos 	      gdb::unique_xmalloc_ptr<char> new_name
   1712  1.12  christos 		= c_canonicalize_name (name.c_str ());
   1713  1.12  christos 	      if (new_name != nullptr)
   1714  1.12  christos 		{
   1715  1.12  christos 		  sym_len = strlen (new_name.get ());
   1716  1.12  christos 		  sym_name = obstack_strdup (&objfile->objfile_obstack,
   1717  1.12  christos 					     new_name.get ());
   1718  1.12  christos 		}
   1719  1.12  christos 	    }
   1720  1.12  christos 
   1721  1.12  christos 	  if (sym_len == 0)
   1722  1.12  christos 	    {
   1723  1.12  christos 	      sym_name = namestring;
   1724  1.12  christos 	      sym_len = p - namestring;
   1725  1.12  christos 	    }
   1726  1.12  christos 
   1727  1.12  christos 	  /* Main processing section for debugging symbols which
   1728  1.12  christos 	     the initial read through the symbol tables needs to worry
   1729  1.12  christos 	     about.  If we reach this point, the symbol which we are
   1730  1.12  christos 	     considering is definitely one we are interested in.
   1731  1.12  christos 	     p must also contain the (valid) index into the namestring
   1732  1.12  christos 	     which indicates the debugging type symbol.  */
   1733  1.12  christos 
   1734  1.12  christos 	  switch (p[1])
   1735  1.12  christos 	    {
   1736  1.12  christos 	    case 'S':
   1737  1.12  christos 	      if (pst != nullptr)
   1738  1.12  christos 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1739  1.12  christos 				  VAR_DOMAIN, LOC_STATIC,
   1740  1.12  christos 				  data_sect_index,
   1741  1.12  christos 				  psymbol_placement::STATIC,
   1742  1.12  christos 				  unrelocated_addr (nlist.n_value),
   1743  1.12  christos 				  dbx->ctx.psymtab_language,
   1744  1.12  christos 				  partial_symtabs, objfile);
   1745  1.12  christos 	      else
   1746  1.12  christos 		complaint (_("static `%*s' appears to be defined "
   1747  1.12  christos 			     "outside of all compilation units"),
   1748  1.12  christos 			   sym_len, sym_name);
   1749  1.12  christos 	      continue;
   1750  1.12  christos 
   1751  1.12  christos 	    case 'G':
   1752  1.12  christos 	      /* The addresses in these entries are reported to be
   1753  1.12  christos 		 wrong.  See the code that reads 'G's for symtabs.  */
   1754  1.12  christos 	      if (pst != nullptr)
   1755  1.12  christos 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1756  1.12  christos 				  VAR_DOMAIN, LOC_STATIC,
   1757  1.12  christos 				  data_sect_index,
   1758  1.12  christos 				  psymbol_placement::GLOBAL,
   1759  1.12  christos 				  unrelocated_addr (nlist.n_value),
   1760  1.12  christos 				  dbx->ctx.psymtab_language,
   1761  1.12  christos 				  partial_symtabs, objfile);
   1762  1.12  christos 	      else
   1763  1.12  christos 		complaint (_("global `%*s' appears to be defined "
   1764  1.12  christos 			     "outside of all compilation units"),
   1765  1.12  christos 			   sym_len, sym_name);
   1766  1.12  christos 	      continue;
   1767  1.12  christos 
   1768  1.12  christos 	    case 'T':
   1769  1.12  christos 	      /* When a 'T' entry is defining an anonymous enum, it
   1770  1.12  christos 		 may have a name which is the empty string, or a
   1771  1.12  christos 		 single space.  Since they're not really defining a
   1772  1.12  christos 		 symbol, those shouldn't go in the partial symbol
   1773  1.12  christos 		 table.  We do pick up the elements of such enums at
   1774  1.12  christos 		 'check_enum:', below.  */
   1775  1.12  christos 	      if (p >= namestring + 2
   1776  1.12  christos 		  || (p == namestring + 1
   1777  1.12  christos 		      && namestring[0] != ' '))
   1778  1.12  christos 		{
   1779  1.12  christos 		  if (pst != nullptr)
   1780  1.12  christos 		    pst->add_psymbol (std::string_view (sym_name, sym_len),
   1781  1.12  christos 				      true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
   1782  1.12  christos 				      psymbol_placement::STATIC,
   1783  1.12  christos 				      unrelocated_addr (0),
   1784  1.12  christos 				      dbx->ctx.psymtab_language,
   1785  1.12  christos 				      partial_symtabs, objfile);
   1786  1.12  christos 		  else
   1787  1.12  christos 		    complaint (_("enum, struct, or union `%*s' appears "
   1788  1.12  christos 				 "to be defined outside of all "
   1789  1.12  christos 				 "compilation units"),
   1790  1.12  christos 			       sym_len, sym_name);
   1791  1.12  christos 		  if (p[2] == 't')
   1792  1.12  christos 		    {
   1793  1.12  christos 		      /* Also a typedef with the same name.  */
   1794  1.12  christos 		      if (pst != nullptr)
   1795  1.12  christos 			pst->add_psymbol (std::string_view (sym_name, sym_len),
   1796  1.12  christos 					  true, VAR_DOMAIN, LOC_TYPEDEF, -1,
   1797  1.12  christos 					  psymbol_placement::STATIC,
   1798  1.12  christos 					  unrelocated_addr (0),
   1799  1.12  christos 					  dbx->ctx.psymtab_language,
   1800  1.12  christos 					  partial_symtabs, objfile);
   1801  1.12  christos 		      else
   1802  1.12  christos 			complaint (_("typedef `%*s' appears to be defined "
   1803  1.12  christos 				     "outside of all compilation units"),
   1804  1.12  christos 				   sym_len, sym_name);
   1805  1.12  christos 		      p += 1;
   1806  1.12  christos 		    }
   1807  1.12  christos 		}
   1808  1.12  christos 	      goto check_enum;
   1809  1.12  christos 
   1810  1.12  christos 	    case 't':
   1811  1.12  christos 	      if (p != namestring)	/* a name is there, not just :T...  */
   1812  1.12  christos 		{
   1813  1.12  christos 		  if (pst != nullptr)
   1814  1.12  christos 		    pst->add_psymbol (std::string_view (sym_name, sym_len),
   1815  1.12  christos 				      true, VAR_DOMAIN, LOC_TYPEDEF, -1,
   1816  1.12  christos 				      psymbol_placement::STATIC,
   1817  1.12  christos 				      unrelocated_addr (0),
   1818  1.12  christos 				      dbx->ctx.psymtab_language,
   1819  1.12  christos 				      partial_symtabs, objfile);
   1820  1.12  christos 		  else
   1821  1.12  christos 		    complaint (_("typename `%*s' appears to be defined "
   1822  1.12  christos 				 "outside of all compilation units"),
   1823  1.12  christos 			       sym_len, sym_name);
   1824  1.12  christos 		}
   1825  1.12  christos 	    check_enum:
   1826  1.12  christos 	      /* If this is an enumerated type, we need to
   1827  1.12  christos 		 add all the enum constants to the partial symbol
   1828  1.12  christos 		 table.  This does not cover enums without names, e.g.
   1829  1.12  christos 		 "enum {a, b} c;" in C, but fortunately those are
   1830  1.12  christos 		 rare.  There is no way for GDB to find those from the
   1831  1.12  christos 		 enum type without spending too much time on it.  Thus
   1832  1.12  christos 		 to solve this problem, the compiler needs to put out the
   1833  1.12  christos 		 enum in a nameless type.  GCC2 does this.  */
   1834  1.12  christos 
   1835  1.12  christos 	      /* We are looking for something of the form
   1836  1.12  christos 		 <name> ":" ("t" | "T") [<number> "="] "e"
   1837  1.12  christos 		 {<constant> ":" <value> ","} ";".  */
   1838  1.12  christos 
   1839  1.12  christos 	      /* Skip over the colon and the 't' or 'T'.  */
   1840  1.12  christos 	      p += 2;
   1841  1.12  christos 	      /* This type may be given a number.  Also, numbers can come
   1842  1.12  christos 		 in pairs like (0,26).  Skip over it.  */
   1843  1.12  christos 	      while ((*p >= '0' && *p <= '9')
   1844  1.12  christos 		     || *p == '(' || *p == ',' || *p == ')'
   1845  1.12  christos 		     || *p == '=')
   1846  1.12  christos 		p++;
   1847  1.12  christos 
   1848  1.12  christos 	      if (*p++ == 'e')
   1849  1.12  christos 		{
   1850  1.12  christos 		  /* The aix4 compiler emits extra crud before the members.  */
   1851  1.12  christos 		  if (*p == '-')
   1852  1.12  christos 		    {
   1853  1.12  christos 		      /* Skip over the type (?).  */
   1854  1.12  christos 		      while (*p != ':')
   1855  1.12  christos 			p++;
   1856  1.12  christos 
   1857  1.12  christos 		      /* Skip over the colon.  */
   1858  1.12  christos 		      p++;
   1859  1.12  christos 		    }
   1860  1.12  christos 
   1861  1.12  christos 		  /* We have found an enumerated type.  */
   1862  1.12  christos 		  /* According to comments in read_enum_type
   1863  1.12  christos 		     a comma could end it instead of a semicolon.
   1864  1.12  christos 		     I don't know where that happens.
   1865  1.12  christos 		     Accept either.  */
   1866  1.12  christos 		  while (*p && *p != ';' && *p != ',')
   1867  1.12  christos 		    {
   1868  1.12  christos 		      const char *q;
   1869  1.12  christos 
   1870  1.12  christos 		      /* Check for and handle cretinous dbx symbol name
   1871  1.12  christos 			 continuation!  */
   1872  1.12  christos 		      if (*p == '\\' || (*p == '?' && p[1] == '\0'))
   1873  1.12  christos 			p = next_symbol_text (objfile);
   1874  1.12  christos 
   1875  1.12  christos 		      /* Point to the character after the name
   1876  1.12  christos 			 of the enum constant.  */
   1877  1.12  christos 		      for (q = p; *q && *q != ':'; q++)
   1878  1.12  christos 			;
   1879  1.12  christos 		      /* Note that the value doesn't matter for
   1880  1.12  christos 			 enum constants in psymtabs, just in symtabs.  */
   1881  1.12  christos 		      if (pst != nullptr)
   1882  1.12  christos 			pst->add_psymbol (std::string_view (p, q - p), true,
   1883  1.12  christos 					  VAR_DOMAIN, LOC_CONST, -1,
   1884  1.12  christos 					  psymbol_placement::STATIC,
   1885  1.12  christos 					  unrelocated_addr (0),
   1886  1.12  christos 					  dbx->ctx.psymtab_language,
   1887  1.12  christos 					  partial_symtabs, objfile);
   1888  1.12  christos 		      else
   1889  1.12  christos 			complaint (_("enum constant `%*s' appears to be defined "
   1890  1.12  christos 				     "outside of all compilation units"),
   1891  1.12  christos 				   ((int) (q - p)), p);
   1892  1.12  christos 		      /* Point past the name.  */
   1893  1.12  christos 		      p = q;
   1894  1.12  christos 		      /* Skip over the value.  */
   1895  1.12  christos 		      while (*p && *p != ',')
   1896  1.12  christos 			p++;
   1897  1.12  christos 		      /* Advance past the comma.  */
   1898  1.12  christos 		      if (*p)
   1899  1.12  christos 			p++;
   1900  1.12  christos 		    }
   1901  1.12  christos 		}
   1902  1.12  christos 	      continue;
   1903  1.12  christos 
   1904  1.12  christos 	    case 'c':
   1905  1.12  christos 	      /* Constant, e.g. from "const" in Pascal.  */
   1906  1.12  christos 	      if (pst != nullptr)
   1907  1.12  christos 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1908  1.12  christos 				  VAR_DOMAIN, LOC_CONST, -1,
   1909  1.12  christos 				  psymbol_placement::STATIC,
   1910  1.12  christos 				  unrelocated_addr (0),
   1911  1.12  christos 				  dbx->ctx.psymtab_language,
   1912  1.12  christos 				  partial_symtabs, objfile);
   1913  1.12  christos 	      else
   1914  1.12  christos 		complaint (_("constant `%*s' appears to be defined "
   1915  1.12  christos 			     "outside of all compilation units"),
   1916  1.12  christos 			   sym_len, sym_name);
   1917  1.12  christos 
   1918  1.12  christos 	      continue;
   1919  1.12  christos 
   1920  1.12  christos 	    case 'f':
   1921  1.12  christos 	      if (! pst)
   1922  1.12  christos 		{
   1923  1.12  christos 		  std::string name (namestring, (p - namestring));
   1924  1.12  christos 		  function_outside_compilation_unit_complaint (name.c_str ());
   1925  1.12  christos 		}
   1926  1.12  christos 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1927  1.12  christos 	      dbx->ctx.last_function_name = namestring;
   1928  1.12  christos 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1929  1.12  christos 		 value for the bottom of the text seg in those cases.  */
   1930  1.12  christos 	      if (nlist.n_value == 0
   1931  1.12  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1932  1.12  christos 		{
   1933  1.12  christos 		  bound_minimal_symbol minsym
   1934  1.12  christos 		    = find_stab_function (namestring,
   1935  1.12  christos 					  pst ? pst->filename : NULL, objfile);
   1936  1.12  christos 		  if (minsym.minsym != NULL)
   1937  1.12  christos 		    nlist.n_value
   1938  1.12  christos 		      = CORE_ADDR (minsym.minsym->unrelocated_address ());
   1939  1.12  christos 		}
   1940  1.12  christos 	      if (pst && textlow_not_set
   1941  1.12  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1942  1.12  christos 		{
   1943  1.12  christos 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   1944  1.12  christos 		  textlow_not_set = 0;
   1945  1.12  christos 		}
   1946  1.12  christos 	      /* End kludge.  */
   1947  1.12  christos 
   1948  1.12  christos 	      /* Keep track of the start of the last function so we
   1949  1.12  christos 		 can handle end of function symbols.  */
   1950  1.12  christos 	      last_function_start = nlist.n_value;
   1951  1.12  christos 
   1952  1.12  christos 	      /* In reordered executables this function may lie outside
   1953  1.12  christos 		 the bounds created by N_SO symbols.  If that's the case
   1954  1.12  christos 		 use the address of this function as the low bound for
   1955  1.12  christos 		 the partial symbol table.  */
   1956  1.12  christos 	      if (pst
   1957  1.12  christos 		  && (textlow_not_set
   1958  1.12  christos 		      || (unrelocated_addr (nlist.n_value)
   1959  1.12  christos 			  < pst->unrelocated_text_low ()
   1960  1.12  christos 			  && (nlist.n_value != 0))))
   1961  1.12  christos 		{
   1962  1.12  christos 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   1963  1.12  christos 		  textlow_not_set = 0;
   1964  1.12  christos 		}
   1965  1.12  christos 	      if (pst != nullptr)
   1966  1.12  christos 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1967  1.12  christos 				  VAR_DOMAIN, LOC_BLOCK,
   1968  1.12  christos 				  SECT_OFF_TEXT (objfile),
   1969  1.12  christos 				  psymbol_placement::STATIC,
   1970  1.12  christos 				  unrelocated_addr (nlist.n_value),
   1971  1.12  christos 				  dbx->ctx.psymtab_language,
   1972  1.12  christos 				  partial_symtabs, objfile);
   1973  1.12  christos 	      continue;
   1974  1.12  christos 
   1975  1.12  christos 	      /* Global functions were ignored here, but now they
   1976  1.12  christos 		 are put into the global psymtab like one would expect.
   1977  1.12  christos 		 They're also in the minimal symbol table.  */
   1978  1.12  christos 	    case 'F':
   1979  1.12  christos 	      if (! pst)
   1980  1.12  christos 		{
   1981  1.12  christos 		  std::string name (namestring, (p - namestring));
   1982  1.12  christos 		  function_outside_compilation_unit_complaint (name.c_str ());
   1983  1.12  christos 		}
   1984  1.12  christos 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1985  1.12  christos 	      dbx->ctx.last_function_name = namestring;
   1986  1.12  christos 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1987  1.12  christos 		 value for the bottom of the text seg in those cases.  */
   1988  1.12  christos 	      if (nlist.n_value == 0
   1989  1.12  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1990  1.12  christos 		{
   1991  1.12  christos 		  bound_minimal_symbol minsym
   1992  1.12  christos 		    = find_stab_function (namestring,
   1993  1.12  christos 					  pst ? pst->filename : NULL, objfile);
   1994  1.12  christos 		  if (minsym.minsym != NULL)
   1995  1.12  christos 		    nlist.n_value
   1996  1.12  christos 		      = CORE_ADDR (minsym.minsym->unrelocated_address ());
   1997  1.12  christos 		}
   1998  1.12  christos 	      if (pst && textlow_not_set
   1999  1.12  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   2000  1.12  christos 		{
   2001  1.12  christos 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   2002  1.12  christos 		  textlow_not_set = 0;
   2003  1.12  christos 		}
   2004  1.12  christos 	      /* End kludge.  */
   2005  1.12  christos 
   2006  1.12  christos 	      /* Keep track of the start of the last function so we
   2007  1.12  christos 		 can handle end of function symbols.  */
   2008  1.12  christos 	      last_function_start = nlist.n_value;
   2009  1.12  christos 
   2010  1.12  christos 	      /* In reordered executables this function may lie outside
   2011  1.12  christos 		 the bounds created by N_SO symbols.  If that's the case
   2012  1.12  christos 		 use the address of this function as the low bound for
   2013  1.12  christos 		 the partial symbol table.  */
   2014  1.12  christos 	      if (pst
   2015  1.12  christos 		  && (textlow_not_set
   2016  1.12  christos 		      || (unrelocated_addr (nlist.n_value)
   2017  1.12  christos 			  < pst->unrelocated_text_low ()
   2018  1.12  christos 			  && (nlist.n_value != 0))))
   2019  1.12  christos 		{
   2020  1.12  christos 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   2021  1.12  christos 		  textlow_not_set = 0;
   2022  1.12  christos 		}
   2023  1.12  christos 	      if (pst != nullptr)
   2024  1.12  christos 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   2025  1.12  christos 				  VAR_DOMAIN, LOC_BLOCK,
   2026  1.12  christos 				  SECT_OFF_TEXT (objfile),
   2027  1.12  christos 				  psymbol_placement::GLOBAL,
   2028  1.12  christos 				  unrelocated_addr (nlist.n_value),
   2029  1.12  christos 				  dbx->ctx.psymtab_language,
   2030  1.12  christos 				  partial_symtabs, objfile);
   2031  1.12  christos 	      continue;
   2032  1.12  christos 
   2033  1.12  christos 	      /* Two things show up here (hopefully); static symbols of
   2034  1.12  christos 		 local scope (static used inside braces) or extensions
   2035  1.12  christos 		 of structure symbols.  We can ignore both.  */
   2036  1.12  christos 	    case 'V':
   2037  1.12  christos 	    case '(':
   2038  1.12  christos 	    case '0':
   2039  1.12  christos 	    case '1':
   2040  1.12  christos 	    case '2':
   2041  1.12  christos 	    case '3':
   2042  1.12  christos 	    case '4':
   2043  1.12  christos 	    case '5':
   2044  1.12  christos 	    case '6':
   2045  1.12  christos 	    case '7':
   2046  1.12  christos 	    case '8':
   2047  1.12  christos 	    case '9':
   2048  1.12  christos 	    case '-':
   2049  1.12  christos 	    case '#':	/* For symbol identification (used in live ranges).  */
   2050  1.12  christos 	      continue;
   2051  1.12  christos 
   2052  1.12  christos 	    case ':':
   2053  1.12  christos 	      /* It is a C++ nested symbol.  We don't need to record it
   2054  1.12  christos 		 (I don't think); if we try to look up foo::bar::baz,
   2055  1.12  christos 		 then symbols for the symtab containing foo should get
   2056  1.12  christos 		 read in, I think.  */
   2057  1.12  christos 	      /* Someone says sun cc puts out symbols like
   2058  1.12  christos 		 /foo/baz/maclib::/usr/local/bin/maclib,
   2059  1.12  christos 		 which would get here with a symbol type of ':'.  */
   2060  1.12  christos 	      continue;
   2061  1.12  christos 
   2062  1.12  christos 	    default:
   2063  1.12  christos 	      /* Unexpected symbol descriptor.  The second and subsequent stabs
   2064  1.12  christos 		 of a continued stab can show up here.  The question is
   2065  1.12  christos 		 whether they ever can mimic a normal stab--it would be
   2066  1.12  christos 		 nice if not, since we certainly don't want to spend the
   2067  1.12  christos 		 time searching to the end of every string looking for
   2068  1.12  christos 		 a backslash.  */
   2069  1.12  christos 
   2070  1.12  christos 	      complaint (_("unknown symbol descriptor `%c'"),
   2071  1.12  christos 			 p[1]);
   2072  1.12  christos 
   2073  1.12  christos 	      /* Ignore it; perhaps it is an extension that we don't
   2074  1.12  christos 		 know about.  */
   2075  1.12  christos 	      continue;
   2076  1.12  christos 	    }
   2077  1.12  christos 	}
   2078  1.12  christos 
   2079  1.12  christos 	case N_EXCL:
   2080  1.12  christos 
   2081  1.12  christos 	  namestring = set_namestring (objfile, &nlist);
   2082  1.12  christos 
   2083  1.12  christos 	  /* Find the corresponding bincl and mark that psymtab on the
   2084  1.12  christos 	     psymtab dependency list.  */
   2085  1.12  christos 	  {
   2086  1.12  christos 	    legacy_psymtab *needed_pst =
   2087  1.12  christos 	      find_corresponding_bincl_psymtab (namestring, nlist.n_value, objfile);
   2088  1.12  christos 
   2089  1.12  christos 	    /* If this include file was defined earlier in this file,
   2090  1.12  christos 	       leave it alone.  */
   2091  1.12  christos 	    if (needed_pst == pst)
   2092  1.12  christos 	      continue;
   2093  1.12  christos 
   2094  1.12  christos 	    if (needed_pst)
   2095  1.12  christos 	      {
   2096  1.12  christos 		int i;
   2097  1.12  christos 		int found = 0;
   2098  1.12  christos 
   2099  1.12  christos 		for (i = 0; i < dependencies_used; i++)
   2100  1.12  christos 		  if (dependency_list[i] == needed_pst)
   2101  1.12  christos 		    {
   2102  1.12  christos 		      found = 1;
   2103  1.12  christos 		      break;
   2104  1.12  christos 		    }
   2105  1.12  christos 
   2106  1.12  christos 		/* If it's already in the list, skip the rest.  */
   2107  1.12  christos 		if (found)
   2108  1.12  christos 		  continue;
   2109  1.12  christos 
   2110  1.12  christos 		dependency_list[dependencies_used++] = needed_pst;
   2111  1.12  christos 		if (dependencies_used >= dependencies_allocated)
   2112  1.12  christos 		  {
   2113  1.12  christos 		    legacy_psymtab **orig = dependency_list;
   2114  1.12  christos 
   2115  1.12  christos 		    dependency_list =
   2116  1.12  christos 		      (legacy_psymtab **)
   2117  1.12  christos 		      alloca ((dependencies_allocated *= 2)
   2118  1.12  christos 			      * sizeof (legacy_psymtab *));
   2119  1.12  christos 		    memcpy (dependency_list, orig,
   2120  1.12  christos 			    (dependencies_used
   2121  1.12  christos 			     * sizeof (legacy_psymtab *)));
   2122  1.12  christos #ifdef DEBUG_INFO
   2123  1.12  christos 		    gdb_printf (gdb_stderr,
   2124  1.12  christos 				"Had to reallocate "
   2125  1.12  christos 				"dependency list.\n");
   2126  1.12  christos 		    gdb_printf (gdb_stderr,
   2127  1.12  christos 				"New dependencies allocated: %d\n",
   2128  1.12  christos 				dependencies_allocated);
   2129  1.12  christos #endif
   2130  1.12  christos 		  }
   2131  1.12  christos 	      }
   2132  1.12  christos 	  }
   2133  1.12  christos 	  continue;
   2134  1.12  christos 
   2135  1.12  christos 	case N_ENDM:
   2136  1.12  christos 	  /* Solaris 2 end of module, finish current partial symbol
   2137  1.12  christos 	     table.  stabs_end_psymtab will set the high text address of
   2138  1.12  christos 	     PST to the proper value, which is necessary if a module
   2139  1.12  christos 	     compiled without debugging info follows this module.  */
   2140  1.12  christos 	  if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
   2141  1.12  christos 	    {
   2142  1.12  christos 	      stabs_end_psymtab (objfile, partial_symtabs, pst,
   2143  1.12  christos 				 psymtab_include_list, includes_used,
   2144  1.12  christos 				 symnum * dbx->ctx.symbol_size,
   2145  1.12  christos 				 (unrelocated_addr) 0, dependency_list,
   2146  1.12  christos 				 dependencies_used, textlow_not_set);
   2147  1.12  christos 	      pst = (legacy_psymtab *) 0;
   2148  1.12  christos 	      includes_used = 0;
   2149  1.12  christos 	      dependencies_used = 0;
   2150  1.12  christos 	      dbx->ctx.has_line_numbers = 0;
   2151  1.12  christos 	    }
   2152  1.12  christos 	  continue;
   2153  1.12  christos 
   2154  1.12  christos 	case N_RBRAC:
   2155  1.12  christos #ifdef HANDLE_RBRAC
   2156  1.12  christos 	  HANDLE_RBRAC (nlist.n_value);
   2157  1.12  christos 	  continue;
   2158  1.12  christos #endif
   2159  1.12  christos 	case N_EINCL:
   2160  1.12  christos 	case N_DSLINE:
   2161  1.12  christos 	case N_BSLINE:
   2162  1.12  christos 	case N_SSYM:		/* Claim: Structure or union element.
   2163  1.12  christos 				   Hopefully, I can ignore this.  */
   2164  1.12  christos 	case N_ENTRY:		/* Alternate entry point; can ignore.  */
   2165  1.12  christos 	case N_MAIN:		/* Can definitely ignore this.   */
   2166  1.12  christos 	case N_CATCH:		/* These are GNU C++ extensions */
   2167  1.12  christos 	case N_EHDECL:		/* that can safely be ignored here.  */
   2168  1.12  christos 	case N_LENG:
   2169  1.12  christos 	case N_BCOMM:
   2170  1.12  christos 	case N_ECOMM:
   2171  1.12  christos 	case N_ECOML:
   2172  1.12  christos 	case N_FNAME:
   2173  1.12  christos 	case N_SLINE:
   2174  1.12  christos 	case N_RSYM:
   2175  1.12  christos 	case N_PSYM:
   2176  1.12  christos 	case N_BNSYM:
   2177  1.12  christos 	case N_ENSYM:
   2178  1.12  christos 	case N_LBRAC:
   2179  1.12  christos 	case N_NSYMS:		/* Ultrix 4.0: symbol count */
   2180  1.12  christos 	case N_DEFD:		/* GNU Modula-2 */
   2181  1.12  christos 	case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   2182  1.12  christos 
   2183  1.12  christos 	case N_OBJ:		/* Useless types from Solaris.  */
   2184  1.12  christos 	case N_OPT:
   2185  1.12  christos 	case N_PATCH:
   2186  1.12  christos 	  /* These symbols aren't interesting; don't worry about them.  */
   2187  1.12  christos 	  continue;
   2188  1.12  christos 
   2189  1.12  christos 	default:
   2190  1.12  christos 	  /* If we haven't found it yet, ignore it.  It's probably some
   2191  1.12  christos 	     new type we don't know about yet.  */
   2192  1.12  christos 	  unknown_symtype_complaint (hex_string (nlist.n_type));
   2193  1.12  christos 	  continue;
   2194  1.12  christos 	}
   2195  1.12  christos     }
   2196  1.12  christos 
   2197  1.12  christos   /* If there's stuff to be cleaned up, clean it up.  */
   2198  1.12  christos   if (pst)
   2199  1.12  christos     {
   2200  1.12  christos       /* Don't set high text address of PST lower than it already
   2201  1.12  christos 	 is.  */
   2202  1.12  christos       unrelocated_addr text_end
   2203  1.12  christos 	= (unrelocated_addr
   2204  1.12  christos 	   ((dbx->ctx.lowest_text_address == (unrelocated_addr) -1
   2205  1.12  christos 	     ? text_addr
   2206  1.12  christos 	     : CORE_ADDR (dbx->ctx.lowest_text_address))
   2207  1.12  christos 	    + text_size));
   2208  1.12  christos 
   2209  1.12  christos       stabs_end_psymtab (objfile, partial_symtabs,
   2210  1.12  christos 			 pst, psymtab_include_list, includes_used,
   2211  1.12  christos 			 symnum * dbx->ctx.symbol_size,
   2212  1.12  christos 			 (text_end > pst->unrelocated_text_high ()
   2213  1.12  christos 			  ? text_end : pst->unrelocated_text_high ()),
   2214  1.12  christos 			 dependency_list, dependencies_used, textlow_not_set);
   2215  1.12  christos     }
   2216  1.12  christos }
   2217  1.12  christos 
   2218  1.12  christos /* Scan and build partial symbols for a symbol file.
   2219  1.12  christos    We have been initialized by a call to dbx_symfile_init, which
   2220  1.12  christos    put all the relevant info into a "struct dbx_symfile_info",
   2221  1.12  christos    hung off the objfile structure.  */
   2222  1.12  christos 
   2223  1.12  christos void
   2224  1.12  christos read_stabs_symtab (struct objfile *objfile, symfile_add_flags symfile_flags)
   2225  1.12  christos {
   2226  1.12  christos   bfd *sym_bfd;
   2227  1.12  christos   int val;
   2228  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   2229  1.12  christos 
   2230  1.12  christos   sym_bfd = objfile->obfd.get ();
   2231  1.12  christos 
   2232  1.12  christos   /* .o and .nlm files are relocatables with text, data and bss segs based at
   2233  1.12  christos      0.  This flag disables special (Solaris stabs-in-elf only) fixups for
   2234  1.12  christos      symbols with a value of 0.  */
   2235  1.12  christos 
   2236  1.12  christos   key->ctx.symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
   2237  1.12  christos 
   2238  1.12  christos   val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
   2239  1.12  christos   if (val < 0)
   2240  1.12  christos     perror_with_name (objfile_name (objfile));
   2241  1.12  christos 
   2242  1.12  christos   key->ctx.symbol_size = DBX_SYMBOL_SIZE (objfile);
   2243  1.12  christos   key->ctx.symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
   2244  1.12  christos 
   2245  1.12  christos   scoped_free_pendings free_pending;
   2246  1.12  christos 
   2247  1.12  christos   minimal_symbol_reader reader (objfile);
   2248  1.12  christos 
   2249  1.12  christos   /* Read stabs data from executable file and define symbols.  */
   2250  1.12  christos 
   2251  1.12  christos   psymbol_functions *psf = new psymbol_functions ();
   2252  1.12  christos   psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
   2253  1.12  christos   objfile->qf.emplace_front (psf);
   2254  1.12  christos   read_stabs_symtab_1 (reader, partial_symtabs, objfile);
   2255  1.12  christos 
   2256  1.12  christos   /* Install any minimal symbols that have been collected as the current
   2257  1.12  christos      minimal symbols for this objfile.  */
   2258  1.12  christos 
   2259  1.12  christos   reader.install ();
   2260  1.12  christos }
   2261  1.12  christos 
   2262  1.12  christos /* Record the namespace that the function defined by SYMBOL was
   2263  1.12  christos    defined in, if necessary.  BLOCK is the associated block; use
   2264  1.12  christos    OBSTACK for allocation.  */
   2265  1.12  christos 
   2266  1.12  christos static void
   2267  1.12  christos cp_set_block_scope (const struct symbol *symbol,
   2268  1.12  christos 		    struct block *block,
   2269  1.12  christos 		    struct obstack *obstack)
   2270  1.12  christos {
   2271  1.12  christos   if (symbol->demangled_name () != NULL)
   2272  1.12  christos     {
   2273  1.12  christos       /* Try to figure out the appropriate namespace from the
   2274  1.12  christos 	 demangled name.  */
   2275  1.12  christos 
   2276  1.12  christos       /* FIXME: carlton/2003-04-15: If the function in question is
   2277  1.12  christos 	 a method of a class, the name will actually include the
   2278  1.12  christos 	 name of the class as well.  This should be harmless, but
   2279  1.12  christos 	 is a little unfortunate.  */
   2280  1.12  christos 
   2281  1.12  christos       const char *name = symbol->demangled_name ();
   2282  1.12  christos       unsigned int prefix_len = cp_entire_prefix_len (name);
   2283  1.12  christos 
   2284  1.12  christos       block->set_scope (obstack_strndup (obstack, name, prefix_len),
   2285  1.12  christos 			obstack);
   2286  1.12  christos     }
   2287  1.12  christos }
   2288  1.12  christos 
   2289  1.12  christos bound_minimal_symbol
   2290  1.12  christos find_stab_function (const char *namestring, const char *filename,
   2291  1.12  christos 		    struct objfile *objfile)
   2292  1.12  christos {
   2293  1.12  christos   int n;
   2294  1.12  christos 
   2295  1.12  christos   const char *colon = strchr (namestring, ':');
   2296  1.12  christos   if (colon == NULL)
   2297  1.12  christos     n = 0;
   2298  1.12  christos   else
   2299  1.12  christos     n = colon - namestring;
   2300  1.12  christos 
   2301  1.12  christos   char *p = (char *) alloca (n + 2);
   2302  1.12  christos   strncpy (p, namestring, n);
   2303  1.12  christos   p[n] = 0;
   2304  1.12  christos 
   2305  1.12  christos   bound_minimal_symbol msym
   2306  1.12  christos     = lookup_minimal_symbol (current_program_space, p, objfile, filename);
   2307  1.12  christos   if (msym.minsym == NULL)
   2308  1.12  christos     {
   2309  1.12  christos       /* Sun Fortran appends an underscore to the minimal symbol name,
   2310  1.12  christos 	 try again with an appended underscore if the minimal symbol
   2311  1.12  christos 	 was not found.  */
   2312  1.12  christos       p[n] = '_';
   2313  1.12  christos       p[n + 1] = 0;
   2314  1.12  christos       msym
   2315  1.12  christos 	= lookup_minimal_symbol (current_program_space, p, objfile, filename);
   2316  1.12  christos     }
   2317  1.12  christos 
   2318  1.12  christos   if (msym.minsym == NULL && filename != NULL)
   2319  1.12  christos     {
   2320  1.12  christos       /* Try again without the filename.  */
   2321  1.12  christos       p[n] = 0;
   2322  1.12  christos       msym = lookup_minimal_symbol (current_program_space, p, objfile);
   2323  1.12  christos     }
   2324  1.12  christos   if (msym.minsym == NULL && filename != NULL)
   2325  1.12  christos     {
   2326  1.12  christos       /* And try again for Sun Fortran, but without the filename.  */
   2327  1.12  christos       p[n] = '_';
   2328  1.12  christos       p[n + 1] = 0;
   2329  1.12  christos       msym = lookup_minimal_symbol (current_program_space, p, objfile);
   2330  1.12  christos     }
   2331  1.12  christos 
   2332  1.12  christos   return msym;
   2333  1.12  christos }
   2334  1.12  christos 
   2335  1.12  christos /* Add header file number I for this object file
   2336  1.12  christos    at the next successive FILENUM.  */
   2337  1.12  christos 
   2338  1.12  christos static void
   2339  1.12  christos add_this_object_header_file (int i)
   2340  1.12  christos {
   2341  1.12  christos   if (n_this_object_header_files == n_allocated_this_object_header_files)
   2342  1.12  christos     {
   2343  1.12  christos       n_allocated_this_object_header_files *= 2;
   2344  1.12  christos       this_object_header_files
   2345  1.12  christos 	= (int *) xrealloc ((char *) this_object_header_files,
   2346  1.12  christos 		       n_allocated_this_object_header_files * sizeof (int));
   2347  1.12  christos     }
   2348  1.12  christos 
   2349  1.12  christos   this_object_header_files[n_this_object_header_files++] = i;
   2350  1.12  christos }
   2351  1.12  christos 
   2352  1.12  christos /* Add to this file an "old" header file, one already seen in
   2353  1.12  christos    a previous object file.  NAME is the header file's name.
   2354  1.12  christos    INSTANCE is its instance code, to select among multiple
   2355  1.12  christos    symbol tables for the same header file.  */
   2356  1.12  christos 
   2357  1.12  christos static void
   2358  1.12  christos add_old_header_file (const char *name, int instance, struct objfile *objfile)
   2359  1.12  christos {
   2360  1.12  christos   struct header_file *p = HEADER_FILES (objfile);
   2361  1.12  christos   int i;
   2362  1.12  christos 
   2363  1.12  christos   for (i = 0; i < N_HEADER_FILES (objfile); i++)
   2364  1.12  christos     if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
   2365  1.12  christos       {
   2366  1.12  christos 	add_this_object_header_file (i);
   2367  1.12  christos 	return;
   2368  1.12  christos       }
   2369  1.12  christos   repeated_header_complaint (name, symnum);
   2370  1.12  christos }
   2371  1.12  christos 
   2372  1.12  christos /* Add to this file a "new" header file: definitions for its types follow.
   2373  1.12  christos    NAME is the header file's name.
   2374  1.12  christos    Most often this happens only once for each distinct header file,
   2375  1.12  christos    but not necessarily.  If it happens more than once, INSTANCE has
   2376  1.12  christos    a different value each time, and references to the header file
   2377  1.12  christos    use INSTANCE values to select among them.
   2378  1.12  christos 
   2379  1.12  christos    dbx output contains "begin" and "end" markers for each new header file,
   2380  1.12  christos    but at this level we just need to know which files there have been;
   2381  1.12  christos    so we record the file when its "begin" is seen and ignore the "end".  */
   2382  1.12  christos 
   2383  1.12  christos static void
   2384  1.12  christos add_new_header_file (const char *name, int instance, struct objfile *objfile)
   2385  1.12  christos {
   2386  1.12  christos   int i;
   2387  1.12  christos   struct header_file *hfile;
   2388  1.12  christos 
   2389  1.12  christos   /* Make sure there is room for one more header file.  */
   2390  1.12  christos 
   2391  1.12  christos   i = N_ALLOCATED_HEADER_FILES (objfile);
   2392  1.12  christos 
   2393  1.12  christos   if (N_HEADER_FILES (objfile) == i)
   2394  1.12  christos     {
   2395  1.12  christos       if (i == 0)
   2396  1.12  christos 	{
   2397  1.12  christos 	  N_ALLOCATED_HEADER_FILES (objfile) = 10;
   2398  1.12  christos 	  HEADER_FILES (objfile) = (struct header_file *)
   2399  1.12  christos 	    xmalloc (10 * sizeof (struct header_file));
   2400  1.12  christos 	}
   2401  1.12  christos       else
   2402  1.12  christos 	{
   2403  1.12  christos 	  i *= 2;
   2404  1.12  christos 	  N_ALLOCATED_HEADER_FILES (objfile) = i;
   2405  1.12  christos 	  HEADER_FILES (objfile) = (struct header_file *)
   2406  1.12  christos 	    xrealloc ((char *) HEADER_FILES (objfile),
   2407  1.12  christos 		      (i * sizeof (struct header_file)));
   2408  1.12  christos 	}
   2409  1.12  christos     }
   2410  1.12  christos 
   2411  1.12  christos   /* Create an entry for this header file.  */
   2412  1.12  christos 
   2413  1.12  christos   i = N_HEADER_FILES (objfile)++;
   2414  1.12  christos   hfile = HEADER_FILES (objfile) + i;
   2415  1.12  christos   hfile->name = xstrdup (name);
   2416  1.12  christos   hfile->instance = instance;
   2417  1.12  christos   hfile->length = 10;
   2418  1.12  christos   hfile->vector = XCNEWVEC (struct type *, 10);
   2419  1.12  christos 
   2420  1.12  christos   add_this_object_header_file (i);
   2421  1.12  christos }
   2422  1.12  christos 
   2423  1.12  christos /* See stabsread.h.  */
   2424  1.12  christos 
   2425  1.12  christos void
   2426  1.12  christos process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
   2427  1.12  christos 		    const section_offsets &section_offsets,
   2428  1.12  christos 		    struct objfile *objfile, enum language language)
   2429  1.12  christos {
   2430  1.12  christos   struct gdbarch *gdbarch = objfile->arch ();
   2431  1.12  christos   struct context_stack *newobj;
   2432  1.12  christos   struct context_stack cstk;
   2433  1.12  christos   /* This remembers the address of the start of a function.  It is
   2434  1.12  christos      used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
   2435  1.12  christos      are relative to the current function's start address.  On systems
   2436  1.12  christos      other than Solaris 2, this just holds the SECT_OFF_TEXT value,
   2437  1.12  christos      and is used to relocate these symbol types rather than
   2438  1.12  christos      SECTION_OFFSETS.  */
   2439  1.12  christos   static CORE_ADDR function_start_offset;
   2440  1.12  christos 
   2441  1.12  christos   /* This holds the address of the start of a function, without the
   2442  1.12  christos      system peculiarities of function_start_offset.  */
   2443  1.12  christos   static CORE_ADDR last_function_start;
   2444  1.12  christos 
   2445  1.12  christos   /* If this is nonzero, we've seen an N_SLINE since the start of the
   2446  1.12  christos      current function.  We use this to tell us to move the first sline
   2447  1.12  christos      to the beginning of the function regardless of what its given
   2448  1.12  christos      value is.  */
   2449  1.12  christos   static int sline_found_in_function = 1;
   2450  1.12  christos 
   2451  1.12  christos   /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
   2452  1.12  christos      source file.  Used to detect the SunPRO solaris compiler.  */
   2453  1.12  christos   static int n_opt_found;
   2454  1.12  christos 
   2455  1.12  christos   /* The section index for this symbol.  */
   2456  1.12  christos   int section_index = -1;
   2457  1.12  christos 
   2458  1.12  christos   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   2459  1.12  christos 
   2460  1.12  christos   /* Something is wrong if we see real data before seeing a source
   2461  1.12  christos      file name.  */
   2462  1.12  christos 
   2463  1.12  christos   if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
   2464  1.12  christos     {
   2465  1.12  christos       /* Ignore any symbols which appear before an N_SO symbol.
   2466  1.12  christos 	 Currently no one puts symbols there, but we should deal
   2467  1.12  christos 	 gracefully with the case.  A complain()t might be in order,
   2468  1.12  christos 	 but this should not be an error ().  */
   2469  1.12  christos       return;
   2470  1.12  christos     }
   2471  1.12  christos 
   2472  1.12  christos   switch (type)
   2473  1.12  christos     {
   2474  1.12  christos     case N_FUN:
   2475  1.12  christos     case N_FNAME:
   2476  1.12  christos 
   2477  1.12  christos       if (*name == '\000')
   2478  1.12  christos 	{
   2479  1.12  christos 	  /* This N_FUN marks the end of a function.  This closes off
   2480  1.12  christos 	     the current block.  */
   2481  1.12  christos 	  struct block *block;
   2482  1.12  christos 
   2483  1.12  christos 	  if (outermost_context_p ())
   2484  1.12  christos 	    {
   2485  1.12  christos 	      lbrac_mismatch_complaint (symnum);
   2486  1.12  christos 	      break;
   2487  1.12  christos 	    }
   2488  1.12  christos 
   2489  1.12  christos 	  /* The following check is added before recording line 0 at
   2490  1.12  christos 	     end of function so as to handle hand-generated stabs
   2491  1.12  christos 	     which may have an N_FUN stabs at the end of the function,
   2492  1.12  christos 	     but no N_SLINE stabs.  */
   2493  1.12  christos 	  if (sline_found_in_function)
   2494  1.12  christos 	    {
   2495  1.12  christos 	      CORE_ADDR addr = last_function_start + valu;
   2496  1.12  christos 
   2497  1.12  christos 	      record_line
   2498  1.12  christos 		(get_current_subfile (), 0,
   2499  1.12  christos 		 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
   2500  1.12  christos 				   - objfile->text_section_offset ()));
   2501  1.12  christos 	    }
   2502  1.12  christos 
   2503  1.12  christos 	  within_function = 0;
   2504  1.12  christos 	  cstk = pop_context ();
   2505  1.12  christos 
   2506  1.12  christos 	  /* Make a block for the local symbols within.  */
   2507  1.12  christos 	  block = finish_block (cstk.name,
   2508  1.12  christos 				cstk.old_blocks, NULL,
   2509  1.12  christos 				cstk.start_addr, cstk.start_addr + valu);
   2510  1.12  christos 
   2511  1.12  christos 	  /* For C++, set the block's scope.  */
   2512  1.12  christos 	  if (cstk.name->language () == language_cplus)
   2513  1.12  christos 	    cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack);
   2514  1.12  christos 
   2515  1.12  christos 	  /* May be switching to an assembler file which may not be using
   2516  1.12  christos 	     block relative stabs, so reset the offset.  */
   2517  1.12  christos 	  function_start_offset = 0;
   2518  1.12  christos 
   2519  1.12  christos 	  break;
   2520  1.12  christos 	}
   2521  1.12  christos 
   2522  1.12  christos       sline_found_in_function = 0;
   2523  1.12  christos 
   2524  1.12  christos       /* Relocate for dynamic loading.  */
   2525  1.12  christos       section_index = SECT_OFF_TEXT (objfile);
   2526  1.12  christos       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2527  1.12  christos       valu = gdbarch_addr_bits_remove (gdbarch, valu);
   2528  1.12  christos       last_function_start = valu;
   2529  1.12  christos 
   2530  1.12  christos       goto define_a_symbol;
   2531  1.12  christos 
   2532  1.12  christos     case N_LBRAC:
   2533  1.12  christos       /* This "symbol" just indicates the start of an inner lexical
   2534  1.12  christos 	 context within a function.  */
   2535  1.12  christos 
   2536  1.12  christos       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2537  1.12  christos       if (n_opt_found && desc == 1)
   2538  1.12  christos 	break;
   2539  1.12  christos 
   2540  1.12  christos       valu += function_start_offset;
   2541  1.12  christos 
   2542  1.12  christos       push_context (desc, valu);
   2543  1.12  christos       break;
   2544  1.12  christos 
   2545  1.12  christos     case N_RBRAC:
   2546  1.12  christos       /* This "symbol" just indicates the end of an inner lexical
   2547  1.12  christos 	 context that was started with N_LBRAC.  */
   2548  1.12  christos 
   2549  1.12  christos       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2550  1.12  christos       if (n_opt_found && desc == 1)
   2551  1.12  christos 	break;
   2552  1.12  christos 
   2553  1.12  christos       valu += function_start_offset;
   2554  1.12  christos 
   2555  1.12  christos       if (outermost_context_p ())
   2556  1.12  christos 	{
   2557  1.12  christos 	  lbrac_mismatch_complaint (symnum);
   2558  1.12  christos 	  break;
   2559  1.12  christos 	}
   2560  1.12  christos 
   2561  1.12  christos       cstk = pop_context ();
   2562  1.12  christos       if (desc != cstk.depth)
   2563  1.12  christos 	lbrac_mismatch_complaint (symnum);
   2564  1.12  christos 
   2565  1.12  christos       if (*get_local_symbols () != NULL)
   2566  1.12  christos 	{
   2567  1.12  christos 	  /* GCC development snapshots from March to December of
   2568  1.12  christos 	     2000 would output N_LSYM entries after N_LBRAC
   2569  1.12  christos 	     entries.  As a consequence, these symbols are simply
   2570  1.12  christos 	     discarded.  Complain if this is the case.  */
   2571  1.12  christos 	  complaint (_("misplaced N_LBRAC entry; discarding local "
   2572  1.12  christos 		       "symbols which have no enclosing block"));
   2573  1.12  christos 	}
   2574  1.12  christos       *get_local_symbols () = cstk.locals;
   2575  1.12  christos 
   2576  1.12  christos       if (get_context_stack_depth () > 1)
   2577  1.12  christos 	{
   2578  1.12  christos 	  /* This is not the outermost LBRAC...RBRAC pair in the
   2579  1.12  christos 	     function, its local symbols preceded it, and are the ones
   2580  1.12  christos 	     just recovered from the context stack.  Define the block
   2581  1.12  christos 	     for them (but don't bother if the block contains no
   2582  1.12  christos 	     symbols.  Should we complain on blocks without symbols?
   2583  1.12  christos 	     I can't think of any useful purpose for them).  */
   2584  1.12  christos 	  if (*get_local_symbols () != NULL)
   2585  1.12  christos 	    {
   2586  1.12  christos 	      /* Muzzle a compiler bug that makes end < start.
   2587  1.12  christos 
   2588  1.12  christos 		 ??? Which compilers?  Is this ever harmful?.  */
   2589  1.12  christos 	      if (cstk.start_addr > valu)
   2590  1.12  christos 		{
   2591  1.12  christos 		  complaint (_("block start larger than block end"));
   2592  1.12  christos 		  cstk.start_addr = valu;
   2593  1.12  christos 		}
   2594  1.12  christos 	      /* Make a block for the local symbols within.  */
   2595  1.12  christos 	      finish_block (0, cstk.old_blocks, NULL,
   2596  1.12  christos 			    cstk.start_addr, valu);
   2597  1.12  christos 	    }
   2598  1.12  christos 	}
   2599  1.12  christos       else
   2600  1.12  christos 	{
   2601  1.12  christos 	  /* This is the outermost LBRAC...RBRAC pair.  There is no
   2602  1.12  christos 	     need to do anything; leave the symbols that preceded it
   2603  1.12  christos 	     to be attached to the function's own block.  We need to
   2604  1.12  christos 	     indicate that we just moved outside of the function.  */
   2605  1.12  christos 	  within_function = 0;
   2606  1.12  christos 	}
   2607  1.12  christos 
   2608  1.12  christos       break;
   2609  1.12  christos 
   2610  1.12  christos     case N_FN:
   2611  1.12  christos     case N_FN_SEQ:
   2612  1.12  christos       /* This kind of symbol indicates the start of an object file.
   2613  1.12  christos 	 Relocate for dynamic loading.  */
   2614  1.12  christos       section_index = SECT_OFF_TEXT (objfile);
   2615  1.12  christos       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2616  1.12  christos       break;
   2617  1.12  christos 
   2618  1.12  christos     case N_SO:
   2619  1.12  christos       /* This type of symbol indicates the start of data for one
   2620  1.12  christos 	 source file.  Finish the symbol table of the previous source
   2621  1.12  christos 	 file (if any) and start accumulating a new symbol table.
   2622  1.12  christos 	 Relocate for dynamic loading.  */
   2623  1.12  christos       section_index = SECT_OFF_TEXT (objfile);
   2624  1.12  christos       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2625  1.12  christos 
   2626  1.12  christos       n_opt_found = 0;
   2627  1.12  christos 
   2628  1.12  christos       if (get_last_source_file ())
   2629  1.12  christos 	{
   2630  1.12  christos 	  /* Check if previous symbol was also an N_SO (with some
   2631  1.12  christos 	     sanity checks).  If so, that one was actually the
   2632  1.12  christos 	     directory name, and the current one is the real file
   2633  1.12  christos 	     name.  Patch things up.  */
   2634  1.12  christos 	  if (previous_stab_code == (unsigned char) N_SO)
   2635  1.12  christos 	    {
   2636  1.12  christos 	      patch_subfile_names (get_current_subfile (), name);
   2637  1.12  christos 	      break;		/* Ignore repeated SOs.  */
   2638  1.12  christos 	    }
   2639  1.12  christos 	  end_compunit_symtab (valu);
   2640  1.12  christos 	  end_stabs ();
   2641  1.12  christos 	}
   2642  1.12  christos 
   2643  1.12  christos       /* Null name means this just marks the end of text for this .o
   2644  1.12  christos 	 file.  Don't start a new symtab in this case.  */
   2645  1.12  christos       if (*name == '\000')
   2646  1.12  christos 	break;
   2647  1.12  christos 
   2648  1.12  christos       function_start_offset = 0;
   2649  1.12  christos 
   2650  1.12  christos       start_stabs ();
   2651  1.12  christos       start_compunit_symtab (objfile, name, NULL, valu, language);
   2652  1.12  christos       record_debugformat ("stabs");
   2653  1.12  christos       break;
   2654  1.12  christos 
   2655  1.12  christos     case N_SOL:
   2656  1.12  christos       /* This type of symbol indicates the start of data for a
   2657  1.12  christos 	 sub-source-file, one whose contents were copied or included
   2658  1.12  christos 	 in the compilation of the main source file (whose name was
   2659  1.12  christos 	 given in the N_SO symbol).  Relocate for dynamic loading.  */
   2660  1.12  christos       section_index = SECT_OFF_TEXT (objfile);
   2661  1.12  christos       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2662  1.12  christos       start_subfile (name);
   2663  1.12  christos       break;
   2664  1.12  christos 
   2665  1.12  christos     case N_BINCL:
   2666  1.12  christos       push_subfile ();
   2667  1.12  christos       add_new_header_file (name, valu, objfile);
   2668  1.12  christos       start_subfile (name);
   2669  1.12  christos       break;
   2670  1.12  christos 
   2671  1.12  christos     case N_EINCL:
   2672  1.12  christos       start_subfile (pop_subfile ());
   2673  1.12  christos       break;
   2674  1.12  christos 
   2675  1.12  christos     case N_EXCL:
   2676  1.12  christos       add_old_header_file (name, valu, objfile);
   2677  1.12  christos       break;
   2678  1.12  christos 
   2679  1.12  christos     case N_SLINE:
   2680  1.12  christos       /* This type of "symbol" really just records one line-number --
   2681  1.12  christos 	 core-address correspondence.  Enter it in the line list for
   2682  1.12  christos 	 this symbol table.  */
   2683  1.12  christos 
   2684  1.12  christos       /* Relocate for dynamic loading and for ELF acc
   2685  1.12  christos 	 function-relative symbols.  */
   2686  1.12  christos       valu += function_start_offset;
   2687  1.12  christos 
   2688  1.12  christos       /* GCC 2.95.3 emits the first N_SLINE stab somewhere in the
   2689  1.12  christos 	 middle of the prologue instead of right at the start of the
   2690  1.12  christos 	 function.  To deal with this we record the address for the
   2691  1.12  christos 	 first N_SLINE stab to be the start of the function instead of
   2692  1.12  christos 	 the listed location.  We really shouldn't to this.  When
   2693  1.12  christos 	 compiling with optimization, this first N_SLINE stab might be
   2694  1.12  christos 	 optimized away.  Other (non-GCC) compilers don't emit this
   2695  1.12  christos 	 stab at all.  There is no real harm in having an extra
   2696  1.12  christos 	 numbered line, although it can be a bit annoying for the
   2697  1.12  christos 	 user.  However, it totally screws up our testsuite.
   2698  1.12  christos 
   2699  1.12  christos 	 So for now, keep adjusting the address of the first N_SLINE
   2700  1.12  christos 	 stab, but only for code compiled with GCC.  */
   2701  1.12  christos 
   2702  1.12  christos       if (within_function && sline_found_in_function == 0)
   2703  1.12  christos 	{
   2704  1.12  christos 	  CORE_ADDR addr = processing_gcc_compilation == 2 ?
   2705  1.12  christos 			   last_function_start : valu;
   2706  1.12  christos 
   2707  1.12  christos 	  record_line
   2708  1.12  christos 	    (get_current_subfile (), desc,
   2709  1.12  christos 	     unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
   2710  1.12  christos 			       - objfile->text_section_offset ()));
   2711  1.12  christos 	  sline_found_in_function = 1;
   2712  1.12  christos 	}
   2713  1.12  christos       else
   2714  1.12  christos 	record_line
   2715  1.12  christos 	  (get_current_subfile (), desc,
   2716  1.12  christos 	   unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, valu)
   2717  1.12  christos 			     - objfile->text_section_offset ()));
   2718  1.12  christos       break;
   2719  1.12  christos 
   2720  1.12  christos     case N_BCOMM:
   2721  1.12  christos       common_block_start (name, objfile);
   2722  1.12  christos       break;
   2723  1.12  christos 
   2724  1.12  christos     case N_ECOMM:
   2725  1.12  christos       common_block_end (objfile);
   2726  1.12  christos       break;
   2727  1.12  christos 
   2728  1.12  christos       /* The following symbol types need to have the appropriate
   2729  1.12  christos 	 offset added to their value; then we process symbol
   2730  1.12  christos 	 definitions in the name.  */
   2731  1.12  christos 
   2732  1.12  christos     case N_STSYM:		/* Static symbol in data segment.  */
   2733  1.12  christos     case N_LCSYM:		/* Static symbol in BSS segment.  */
   2734  1.12  christos     case N_ROSYM:		/* Static symbol in read-only data segment.  */
   2735  1.12  christos       /* HORRID HACK DEPT.  However, it's Sun's furgin' fault.
   2736  1.12  christos 	 Solaris 2's stabs-in-elf makes *most* symbols relative but
   2737  1.12  christos 	 leaves a few absolute (at least for Solaris 2.1 and version
   2738  1.12  christos 	 2.0.1 of the SunPRO compiler).  N_STSYM and friends sit on
   2739  1.12  christos 	 the fence.  .stab "foo:S...",N_STSYM is absolute (ld
   2740  1.12  christos 	 relocates it) .stab "foo:V...",N_STSYM is relative (section
   2741  1.12  christos 	 base subtracted).  This leaves us no choice but to search for
   2742  1.12  christos 	 the 'S' or 'V'...  (or pass the whole section_offsets stuff
   2743  1.12  christos 	 down ONE MORE function call level, which we really don't want
   2744  1.12  christos 	 to do).  */
   2745  1.12  christos       {
   2746  1.12  christos 	const char *p;
   2747  1.12  christos 
   2748  1.12  christos 	/* Normal object file and NLMs have non-zero text seg offsets,
   2749  1.12  christos 	   but don't need their static syms offset in this fashion.
   2750  1.12  christos 	   XXX - This is really a crock that should be fixed in the
   2751  1.12  christos 	   solib handling code so that I don't have to work around it
   2752  1.12  christos 	   here.  */
   2753  1.12  christos 
   2754  1.12  christos 	if (!key->ctx.symfile_relocatable)
   2755  1.12  christos 	  {
   2756  1.12  christos 	    p = strchr (name, ':');
   2757  1.12  christos 	    if (p != 0 && p[1] == 'S')
   2758  1.12  christos 	      {
   2759  1.12  christos 		/* The linker relocated it.  We don't want to add a
   2760  1.12  christos 		   Sun-stabs Tfoo.foo-like offset, but we *do*
   2761  1.12  christos 		   want to add whatever solib.c passed to
   2762  1.12  christos 		   symbol_file_add as addr (this is known to affect
   2763  1.12  christos 		   SunOS 4, and I suspect ELF too).  Since there is no
   2764  1.12  christos 		   Ttext.text symbol, we can get addr from the text offset.  */
   2765  1.12  christos 		section_index = SECT_OFF_TEXT (objfile);
   2766  1.12  christos 		valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2767  1.12  christos 		goto define_a_symbol;
   2768  1.12  christos 	      }
   2769  1.12  christos 	  }
   2770  1.12  christos 	/* Since it's not the kludge case, re-dispatch to the right
   2771  1.12  christos 	   handler.  */
   2772  1.12  christos 	switch (type)
   2773  1.12  christos 	  {
   2774  1.12  christos 	  case N_STSYM:
   2775  1.12  christos 	    goto case_N_STSYM;
   2776  1.12  christos 	  case N_LCSYM:
   2777  1.12  christos 	    goto case_N_LCSYM;
   2778  1.12  christos 	  case N_ROSYM:
   2779  1.12  christos 	    goto case_N_ROSYM;
   2780  1.12  christos 	  default:
   2781  1.12  christos 	    internal_error (_("failed internal consistency check"));
   2782  1.12  christos 	  }
   2783  1.12  christos       }
   2784  1.12  christos 
   2785  1.12  christos     case_N_STSYM:		/* Static symbol in data segment.  */
   2786  1.12  christos     case N_DSLINE:		/* Source line number, data segment.  */
   2787  1.12  christos       section_index = SECT_OFF_DATA (objfile);
   2788  1.12  christos       valu += section_offsets[SECT_OFF_DATA (objfile)];
   2789  1.12  christos       goto define_a_symbol;
   2790  1.12  christos 
   2791  1.12  christos     case_N_LCSYM:		/* Static symbol in BSS segment.  */
   2792  1.12  christos     case N_BSLINE:		/* Source line number, BSS segment.  */
   2793  1.12  christos       /* N_BROWS: overlaps with N_BSLINE.  */
   2794  1.12  christos       section_index = SECT_OFF_BSS (objfile);
   2795  1.12  christos       valu += section_offsets[SECT_OFF_BSS (objfile)];
   2796  1.12  christos       goto define_a_symbol;
   2797  1.12  christos 
   2798  1.12  christos     case_N_ROSYM:		/* Static symbol in read-only data segment.  */
   2799  1.12  christos       section_index = SECT_OFF_RODATA (objfile);
   2800  1.12  christos       valu += section_offsets[SECT_OFF_RODATA (objfile)];
   2801  1.12  christos       goto define_a_symbol;
   2802  1.12  christos 
   2803  1.12  christos     case N_ENTRY:		/* Alternate entry point.  */
   2804  1.12  christos       /* Relocate for dynamic loading.  */
   2805  1.12  christos       section_index = SECT_OFF_TEXT (objfile);
   2806  1.12  christos       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2807  1.12  christos       goto define_a_symbol;
   2808  1.12  christos 
   2809  1.12  christos       /* The following symbol types we don't know how to process.
   2810  1.12  christos 	 Handle them in a "default" way, but complain to people who
   2811  1.12  christos 	 care.  */
   2812  1.12  christos     default:
   2813  1.12  christos     case N_CATCH:		/* Exception handler catcher.  */
   2814  1.12  christos     case N_EHDECL:		/* Exception handler name.  */
   2815  1.12  christos     case N_PC:			/* Global symbol in Pascal.  */
   2816  1.12  christos     case N_M2C:			/* Modula-2 compilation unit.  */
   2817  1.12  christos       /* N_MOD2: overlaps with N_EHDECL.  */
   2818  1.12  christos     case N_SCOPE:		/* Modula-2 scope information.  */
   2819  1.12  christos     case N_ECOML:		/* End common (local name).  */
   2820  1.12  christos     case N_NBTEXT:		/* Gould Non-Base-Register symbols???  */
   2821  1.12  christos     case N_NBDATA:
   2822  1.12  christos     case N_NBBSS:
   2823  1.12  christos     case N_NBSTS:
   2824  1.12  christos     case N_NBLCS:
   2825  1.12  christos       unknown_symtype_complaint (hex_string (type));
   2826  1.12  christos 
   2827  1.12  christos     define_a_symbol:
   2828  1.12  christos       [[fallthrough]];
   2829  1.12  christos       /* These symbol types don't need the address field relocated,
   2830  1.12  christos 	 since it is either unused, or is absolute.  */
   2831  1.12  christos     case N_GSYM:		/* Global variable.  */
   2832  1.12  christos     case N_NSYMS:		/* Number of symbols (Ultrix).  */
   2833  1.12  christos     case N_NOMAP:		/* No map?  (Ultrix).  */
   2834  1.12  christos     case N_RSYM:		/* Register variable.  */
   2835  1.12  christos     case N_DEFD:		/* Modula-2 GNU module dependency.  */
   2836  1.12  christos     case N_SSYM:		/* Struct or union element.  */
   2837  1.12  christos     case N_LSYM:		/* Local symbol in stack.  */
   2838  1.12  christos     case N_PSYM:		/* Parameter variable.  */
   2839  1.12  christos     case N_LENG:		/* Length of preceding symbol type.  */
   2840  1.12  christos       if (name)
   2841  1.12  christos 	{
   2842  1.12  christos 	  int deftype;
   2843  1.12  christos 	  const char *colon_pos = strchr (name, ':');
   2844  1.12  christos 
   2845  1.12  christos 	  if (colon_pos == NULL)
   2846  1.12  christos 	    deftype = '\0';
   2847  1.12  christos 	  else
   2848  1.12  christos 	    deftype = colon_pos[1];
   2849  1.12  christos 
   2850  1.12  christos 	  switch (deftype)
   2851  1.12  christos 	    {
   2852  1.12  christos 	    case 'f':
   2853  1.12  christos 	    case 'F':
   2854  1.12  christos 	      /* Deal with the SunPRO 3.0 compiler which omits the
   2855  1.12  christos 		 address from N_FUN symbols.  */
   2856  1.12  christos 	      if (type == N_FUN
   2857  1.12  christos 		  && valu == section_offsets[SECT_OFF_TEXT (objfile)]
   2858  1.12  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   2859  1.12  christos 		{
   2860  1.12  christos 		  bound_minimal_symbol minsym
   2861  1.12  christos 		    = find_stab_function (name, get_last_source_file (),
   2862  1.12  christos 					  objfile);
   2863  1.12  christos 		  if (minsym.minsym != NULL)
   2864  1.12  christos 		    valu = minsym.value_address ();
   2865  1.12  christos 		}
   2866  1.12  christos 
   2867  1.12  christos 	      /* These addresses are absolute.  */
   2868  1.12  christos 	      function_start_offset = valu;
   2869  1.12  christos 
   2870  1.12  christos 	      within_function = 1;
   2871  1.12  christos 
   2872  1.12  christos 	      if (get_context_stack_depth () > 1)
   2873  1.12  christos 		{
   2874  1.12  christos 		  complaint (_("unmatched N_LBRAC before symtab pos %d"),
   2875  1.12  christos 			     symnum);
   2876  1.12  christos 		  break;
   2877  1.12  christos 		}
   2878  1.12  christos 
   2879  1.12  christos 	      if (!outermost_context_p ())
   2880  1.12  christos 		{
   2881  1.12  christos 		  struct block *block;
   2882  1.12  christos 
   2883  1.12  christos 		  cstk = pop_context ();
   2884  1.12  christos 		  /* Make a block for the local symbols within.  */
   2885  1.12  christos 		  block = finish_block (cstk.name,
   2886  1.12  christos 					cstk.old_blocks, NULL,
   2887  1.12  christos 					cstk.start_addr, valu);
   2888  1.12  christos 
   2889  1.12  christos 		  /* For C++, set the block's scope.  */
   2890  1.12  christos 		  if (cstk.name->language () == language_cplus)
   2891  1.12  christos 		    cp_set_block_scope (cstk.name, block,
   2892  1.12  christos 					&objfile->objfile_obstack);
   2893  1.12  christos 		}
   2894  1.12  christos 
   2895  1.12  christos 	      newobj = push_context (0, valu);
   2896  1.12  christos 	      newobj->name = define_symbol (valu, name, desc, type, objfile);
   2897  1.12  christos 	      if (newobj->name != nullptr)
   2898  1.12  christos 		newobj->name->set_section_index (section_index);
   2899  1.12  christos 	      break;
   2900  1.12  christos 
   2901  1.12  christos 	    default:
   2902  1.12  christos 	      {
   2903  1.12  christos 		struct symbol *sym = define_symbol (valu, name, desc, type,
   2904  1.12  christos 						    objfile);
   2905  1.12  christos 		if (sym != nullptr)
   2906  1.12  christos 		  sym->set_section_index (section_index);
   2907  1.12  christos 	      }
   2908  1.12  christos 	      break;
   2909  1.12  christos 	    }
   2910  1.12  christos 	}
   2911  1.12  christos       break;
   2912  1.12  christos 
   2913  1.12  christos       /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
   2914  1.12  christos 	 for a bunch of other flags, too.  Someday we may parse their
   2915  1.12  christos 	 flags; for now we ignore theirs and hope they'll ignore ours.  */
   2916  1.12  christos     case N_OPT:			/* Solaris 2: Compiler options.  */
   2917  1.12  christos       if (name)
   2918  1.12  christos 	{
   2919  1.12  christos 	  if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   2920  1.12  christos 	    {
   2921  1.12  christos 	      processing_gcc_compilation = 2;
   2922  1.12  christos 	    }
   2923  1.12  christos 	  else
   2924  1.12  christos 	    n_opt_found = 1;
   2925  1.12  christos 	}
   2926  1.12  christos       break;
   2927  1.12  christos 
   2928  1.12  christos     case N_MAIN:		/* Name of main routine.  */
   2929  1.12  christos       /* FIXME: If one has a symbol file with N_MAIN and then replaces
   2930  1.12  christos 	 it with a symbol file with "main" and without N_MAIN.  I'm
   2931  1.12  christos 	 not sure exactly what rule to follow but probably something
   2932  1.12  christos 	 like: N_MAIN takes precedence over "main" no matter what
   2933  1.12  christos 	 objfile it is in; If there is more than one N_MAIN, choose
   2934  1.12  christos 	 the one in the symfile_objfile; If there is more than one
   2935  1.12  christos 	 N_MAIN within a given objfile, complain() and choose
   2936  1.12  christos 	 arbitrarily.  (kingdon) */
   2937  1.12  christos       if (name != NULL)
   2938  1.12  christos 	set_objfile_main_name (objfile, name, language_unknown);
   2939  1.12  christos       break;
   2940  1.12  christos 
   2941  1.12  christos       /* The following symbol types can be ignored.  */
   2942  1.12  christos     case N_OBJ:			/* Solaris 2: Object file dir and name.  */
   2943  1.12  christos     case N_PATCH:		/* Solaris 2: Patch Run Time Checker.  */
   2944  1.12  christos       /* N_UNDF:                   Solaris 2: File separator mark.  */
   2945  1.12  christos       /* N_UNDF: -- we will never encounter it, since we only process
   2946  1.12  christos 	 one file's symbols at once.  */
   2947  1.12  christos     case N_ENDM:		/* Solaris 2: End of module.  */
   2948  1.12  christos     case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   2949  1.12  christos       break;
   2950  1.12  christos     }
   2951  1.12  christos 
   2952  1.12  christos   /* '#' is a GNU C extension to allow one symbol to refer to another
   2953  1.12  christos      related symbol.
   2954  1.12  christos 
   2955  1.12  christos      Generally this is used so that an alias can refer to its main
   2956  1.12  christos      symbol.  */
   2957  1.12  christos   gdb_assert (name);
   2958  1.12  christos   if (name[0] == '#')
   2959  1.12  christos     {
   2960  1.12  christos       /* Initialize symbol reference names and determine if this is a
   2961  1.12  christos 	 definition.  If a symbol reference is being defined, go ahead
   2962  1.12  christos 	 and add it.  Otherwise, just return.  */
   2963  1.12  christos 
   2964  1.12  christos       const char *s = name;
   2965  1.12  christos       int refnum;
   2966  1.12  christos 
   2967  1.12  christos       /* If this stab defines a new reference ID that is not on the
   2968  1.12  christos 	 reference list, then put it on the reference list.
   2969  1.12  christos 
   2970  1.12  christos 	 We go ahead and advance NAME past the reference, even though
   2971  1.12  christos 	 it is not strictly necessary at this time.  */
   2972  1.12  christos       refnum = symbol_reference_defined (&s);
   2973  1.12  christos       if (refnum >= 0)
   2974  1.12  christos 	if (!ref_search (refnum))
   2975  1.12  christos 	  ref_add (refnum, 0, name, valu);
   2976  1.12  christos       name = s;
   2977  1.12  christos     }
   2978  1.12  christos 
   2979   1.1  christos   previous_stab_code = type;
   2980   1.1  christos }
   2981   1.1  christos 
   2982   1.1  christos #define VISIBILITY_PRIVATE	'0'	/* Stabs character for private field */
   2983   1.1  christos #define VISIBILITY_PROTECTED	'1'	/* Stabs character for protected fld */
   2984   1.1  christos #define VISIBILITY_PUBLIC	'2'	/* Stabs character for public field */
   2985   1.1  christos #define VISIBILITY_IGNORE	'9'	/* Optimized out or zero length */
   2986   1.1  christos 
   2987   1.1  christos /* Structure for storing pointers to reference definitions for fast lookup
   2988   1.1  christos    during "process_later".  */
   2989   1.7  christos 
   2990   1.1  christos struct ref_map
   2991   1.1  christos {
   2992   1.1  christos   const char *stabs;
   2993   1.1  christos   CORE_ADDR value;
   2994   1.1  christos   struct symbol *sym;
   2995   1.1  christos };
   2996   1.1  christos 
   2997   1.1  christos #define MAX_CHUNK_REFS 100
   2998   1.1  christos #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
   2999   1.1  christos #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
   3000   1.1  christos 
   3001   1.1  christos static struct ref_map *ref_map;
   3002   1.1  christos 
   3003   1.1  christos /* Ptr to free cell in chunk's linked list.  */
   3004   1.1  christos static int ref_count = 0;
   3005   1.1  christos 
   3006   1.1  christos /* Number of chunks malloced.  */
   3007   1.1  christos static int ref_chunk = 0;
   3008   1.1  christos 
   3009   1.1  christos /* This file maintains a cache of stabs aliases found in the symbol
   3010   1.1  christos    table.  If the symbol table changes, this cache must be cleared
   3011   1.1  christos    or we are left holding onto data in invalid obstacks.  */
   3012   1.1  christos void
   3013   1.1  christos stabsread_clear_cache (void)
   3014   1.1  christos {
   3015   1.1  christos   ref_count = 0;
   3016   1.1  christos   ref_chunk = 0;
   3017   1.1  christos }
   3018   1.1  christos 
   3019   1.1  christos /* Create array of pointers mapping refids to symbols and stab strings.
   3020   1.1  christos    Add pointers to reference definition symbols and/or their values as we
   3021   1.7  christos    find them, using their reference numbers as our index.
   3022   1.1  christos    These will be used later when we resolve references.  */
   3023   1.1  christos void
   3024   1.1  christos ref_add (int refnum, struct symbol *sym, const char *stabs, CORE_ADDR value)
   3025   1.1  christos {
   3026   1.1  christos   if (ref_count == 0)
   3027   1.1  christos     ref_chunk = 0;
   3028   1.1  christos   if (refnum >= ref_count)
   3029   1.1  christos     ref_count = refnum + 1;
   3030   1.1  christos   if (ref_count > ref_chunk * MAX_CHUNK_REFS)
   3031   1.1  christos     {
   3032   1.1  christos       int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
   3033   1.1  christos       int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
   3034   1.1  christos 
   3035   1.1  christos       ref_map = (struct ref_map *)
   3036   1.1  christos 	xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
   3037   1.1  christos       memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0,
   3038   1.1  christos 	      new_chunks * REF_CHUNK_SIZE);
   3039   1.1  christos       ref_chunk += new_chunks;
   3040   1.1  christos     }
   3041   1.1  christos   ref_map[refnum].stabs = stabs;
   3042   1.1  christos   ref_map[refnum].sym = sym;
   3043   1.1  christos   ref_map[refnum].value = value;
   3044   1.1  christos }
   3045   1.1  christos 
   3046   1.1  christos /* Return defined sym for the reference REFNUM.  */
   3047   1.1  christos struct symbol *
   3048   1.1  christos ref_search (int refnum)
   3049   1.1  christos {
   3050   1.1  christos   if (refnum < 0 || refnum > ref_count)
   3051   1.1  christos     return 0;
   3052   1.1  christos   return ref_map[refnum].sym;
   3053   1.1  christos }
   3054   1.1  christos 
   3055   1.1  christos /* Parse a reference id in STRING and return the resulting
   3056   1.7  christos    reference number.  Move STRING beyond the reference id.  */
   3057   1.1  christos 
   3058   1.7  christos static int
   3059   1.1  christos process_reference (const char **string)
   3060   1.1  christos {
   3061   1.1  christos   const char *p;
   3062   1.1  christos   int refnum = 0;
   3063   1.1  christos 
   3064   1.1  christos   if (**string != '#')
   3065   1.1  christos     return 0;
   3066   1.1  christos 
   3067   1.1  christos   /* Advance beyond the initial '#'.  */
   3068  1.11  christos   p = *string + 1;
   3069   1.1  christos 
   3070   1.1  christos   /* Read number as reference id.  */
   3071   1.1  christos   while (*p && isdigit ((unsigned char)*p))
   3072   1.1  christos     {
   3073   1.1  christos       refnum = refnum * 10 + *p - '0';
   3074   1.1  christos       p++;
   3075   1.1  christos     }
   3076   1.1  christos   *string = p;
   3077   1.1  christos   return refnum;
   3078   1.1  christos }
   3079   1.1  christos 
   3080   1.1  christos /* If STRING defines a reference, store away a pointer to the reference
   3081   1.7  christos    definition for later use.  Return the reference number.  */
   3082   1.1  christos 
   3083   1.7  christos int
   3084   1.1  christos symbol_reference_defined (const char **string)
   3085   1.1  christos {
   3086   1.1  christos   const char *p = *string;
   3087   1.1  christos   int refnum = 0;
   3088   1.1  christos 
   3089   1.1  christos   refnum = process_reference (&p);
   3090   1.1  christos 
   3091   1.1  christos   /* Defining symbols end in '='.  */
   3092   1.1  christos   if (*p == '=')
   3093   1.1  christos     {
   3094   1.1  christos       /* Symbol is being defined here.  */
   3095   1.1  christos       *string = p + 1;
   3096   1.1  christos       return refnum;
   3097   1.1  christos     }
   3098  1.10  christos   else
   3099   1.1  christos     {
   3100   1.1  christos       /* Must be a reference.  Either the symbol has already been defined,
   3101   1.1  christos 	 or this is a forward reference to it.  */
   3102   1.1  christos       *string = p;
   3103   1.1  christos       return -1;
   3104   1.1  christos     }
   3105   1.1  christos }
   3106   1.1  christos 
   3107  1.10  christos static int
   3108   1.1  christos stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
   3109   1.8  christos {
   3110   1.8  christos   int regno = gdbarch_stab_reg_to_regnum (gdbarch, sym->value_longest ());
   3111   1.8  christos 
   3112   1.9  christos   if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
   3113   1.1  christos     {
   3114   1.1  christos       reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
   3115   1.1  christos 			   sym->print_name ());
   3116   1.1  christos 
   3117   1.1  christos       regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless.  */
   3118   1.1  christos     }
   3119   1.1  christos 
   3120   1.1  christos   return regno;
   3121   1.1  christos }
   3122   1.1  christos 
   3123   1.1  christos static const struct symbol_register_ops stab_register_funcs = {
   3124   1.1  christos   stab_reg_to_regnum
   3125   1.1  christos };
   3126   1.1  christos 
   3127   1.1  christos /* The "aclass" indices for computed symbols.  */
   3128   1.1  christos 
   3129   1.1  christos static int stab_register_index;
   3130   1.7  christos static int stab_regparm_index;
   3131   1.1  christos 
   3132   1.1  christos struct symbol *
   3133   1.9  christos define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
   3134   1.1  christos 	       struct objfile *objfile)
   3135   1.7  christos {
   3136   1.1  christos   struct gdbarch *gdbarch = objfile->arch ();
   3137   1.1  christos   struct symbol *sym;
   3138   1.1  christos   const char *p = find_name_end (string);
   3139   1.1  christos   int deftype;
   3140   1.1  christos   int synonym = 0;
   3141   1.1  christos   int i;
   3142   1.1  christos 
   3143   1.1  christos   /* We would like to eliminate nameless symbols, but keep their types.
   3144   1.1  christos      E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
   3145   1.1  christos      to type 2, but, should not create a symbol to address that type.  Since
   3146   1.1  christos      the symbol will be nameless, there is no way any user can refer to it.  */
   3147   1.1  christos 
   3148   1.1  christos   int nameless;
   3149   1.1  christos 
   3150   1.1  christos   /* Ignore syms with empty names.  */
   3151   1.1  christos   if (string[0] == 0)
   3152   1.1  christos     return 0;
   3153   1.1  christos 
   3154   1.1  christos   /* Ignore old-style symbols from cc -go.  */
   3155   1.1  christos   if (p == 0)
   3156   1.1  christos     return 0;
   3157   1.1  christos 
   3158   1.1  christos   while (p[1] == ':')
   3159   1.1  christos     {
   3160   1.1  christos       p += 2;
   3161   1.8  christos       p = strchr (p, ':');
   3162   1.1  christos       if (p == NULL)
   3163   1.1  christos 	{
   3164   1.1  christos 	  complaint (
   3165   1.1  christos 		     _("Bad stabs string '%s'"), string);
   3166   1.1  christos 	  return NULL;
   3167   1.1  christos 	}
   3168   1.1  christos     }
   3169   1.1  christos 
   3170   1.1  christos   /* If a nameless stab entry, all we need is the type, not the symbol.
   3171   1.9  christos      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
   3172   1.1  christos   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
   3173   1.1  christos 
   3174   1.1  christos   current_symbol = sym = new (&objfile->objfile_obstack) symbol;
   3175   1.1  christos 
   3176  1.10  christos   if (processing_gcc_compilation)
   3177  1.10  christos     {
   3178   1.1  christos       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
   3179   1.1  christos 	 number of bytes occupied by a type or object, which we ignore.  */
   3180   1.1  christos       sym->set_line (desc);
   3181  1.10  christos     }
   3182   1.1  christos   else
   3183   1.1  christos     {
   3184   1.9  christos       sym->set_line (0);	/* unknown */
   3185   1.9  christos     }
   3186   1.3  christos 
   3187   1.1  christos   sym->set_language (get_current_subfile ()->language,
   3188   1.1  christos 		     &objfile->objfile_obstack);
   3189   1.1  christos 
   3190   1.1  christos   if (is_cplus_marker (string[0]))
   3191   1.1  christos     {
   3192   1.1  christos       /* Special GNU C++ names.  */
   3193   1.9  christos       switch (string[1])
   3194   1.1  christos 	{
   3195   1.1  christos 	case 't':
   3196   1.1  christos 	  sym->set_linkage_name ("this");
   3197   1.1  christos 	  break;
   3198   1.1  christos 
   3199   1.1  christos 	case 'v':		/* $vtbl_ptr_type */
   3200   1.9  christos 	  goto normal;
   3201   1.1  christos 
   3202   1.1  christos 	case 'e':
   3203   1.1  christos 	  sym->set_linkage_name ("eh_throw");
   3204   1.1  christos 	  break;
   3205   1.1  christos 
   3206   1.1  christos 	case '_':
   3207   1.1  christos 	  /* This was an anonymous type that was never fixed up.  */
   3208   1.8  christos 	  goto normal;
   3209   1.1  christos 
   3210   1.1  christos 	default:
   3211   1.1  christos 	  complaint (_("Unknown C++ symbol name `%s'"),
   3212   1.1  christos 		     string);
   3213   1.1  christos 	  goto normal;		/* Do *something* with it.  */
   3214   1.1  christos 	}
   3215   1.1  christos     }
   3216   1.9  christos   else
   3217   1.7  christos     {
   3218   1.9  christos     normal:
   3219   1.1  christos       gdb::unique_xmalloc_ptr<char> new_name;
   3220  1.10  christos 
   3221  1.10  christos       if (sym->language () == language_cplus)
   3222  1.10  christos 	{
   3223  1.10  christos 	  std::string name (string, p - string);
   3224  1.10  christos 	  new_name = cp_canonicalize_string (name.c_str ());
   3225  1.10  christos 	}
   3226  1.10  christos       else if (sym->language () == language_c)
   3227   1.1  christos 	{
   3228   1.9  christos 	  std::string name (string, p - string);
   3229   1.9  christos 	  new_name = c_canonicalize_name (name.c_str ());
   3230   1.1  christos 	}
   3231  1.11  christos       if (new_name != nullptr)
   3232   1.9  christos 	sym->compute_and_set_names (new_name.get (), true, objfile->per_bfd);
   3233   1.1  christos       else
   3234   1.9  christos 	sym->compute_and_set_names (std::string_view (string, p - string), true,
   3235   1.8  christos 				    objfile->per_bfd);
   3236   1.8  christos 
   3237   1.1  christos       if (sym->language () == language_cplus)
   3238   1.1  christos 	cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym,
   3239   1.1  christos 					  objfile);
   3240   1.1  christos 
   3241   1.1  christos     }
   3242   1.1  christos   p++;
   3243   1.1  christos 
   3244   1.1  christos   /* Determine the type of name being defined.  */
   3245   1.1  christos #if 0
   3246   1.1  christos   /* Getting GDB to correctly skip the symbol on an undefined symbol
   3247   1.1  christos      descriptor and not ever dump core is a very dodgy proposition if
   3248   1.1  christos      we do things this way.  I say the acorn RISC machine can just
   3249   1.1  christos      fix their compiler.  */
   3250   1.1  christos   /* The Acorn RISC machine's compiler can put out locals that don't
   3251   1.1  christos      start with "234=" or "(3,4)=", so assume anything other than the
   3252  1.11  christos      deftypes we know how to handle is a local.  */
   3253   1.1  christos   if (!strchr ("cfFGpPrStTvVXCR", *p))
   3254   1.1  christos #else
   3255   1.1  christos   if (isdigit ((unsigned char)*p) || *p == '(' || *p == '-')
   3256   1.1  christos #endif
   3257   1.1  christos     deftype = 'l';
   3258   1.1  christos   else
   3259   1.1  christos     deftype = *p++;
   3260   1.1  christos 
   3261   1.1  christos   switch (deftype)
   3262  1.10  christos     {
   3263  1.10  christos     case 'c':
   3264  1.10  christos       /* c is a special case, not followed by a type-number.
   3265  1.10  christos 	 SYMBOL:c=iVALUE for an integer constant symbol.
   3266  1.10  christos 	 SYMBOL:c=rVALUE for a floating constant symbol.
   3267   1.1  christos 	 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
   3268   1.1  christos 	 e.g. "b:c=e6,0" for "const b = blob1"
   3269  1.10  christos 	 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
   3270  1.10  christos       if (*p != '=')
   3271  1.10  christos 	{
   3272   1.8  christos 	  sym->set_aclass_index (LOC_CONST);
   3273   1.1  christos 	  sym->set_type (error_type (&p, objfile));
   3274   1.1  christos 	  sym->set_domain (VAR_DOMAIN);
   3275   1.1  christos 	  add_symbol_to_list (sym, get_file_symbols ());
   3276   1.1  christos 	  return sym;
   3277   1.1  christos 	}
   3278   1.1  christos       ++p;
   3279   1.1  christos       switch (*p++)
   3280   1.1  christos 	{
   3281   1.1  christos 	case 'r':
   3282   1.1  christos 	  {
   3283  1.11  christos 	    gdb_byte *dbl_valu;
   3284   1.6  christos 	    struct type *dbl_type;
   3285   1.6  christos 
   3286  1.10  christos 	    dbl_type = builtin_type (objfile)->builtin_double;
   3287   1.8  christos 	    dbl_valu
   3288   1.8  christos 	      = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack,
   3289   1.1  christos 					    dbl_type->length ());
   3290  1.10  christos 
   3291  1.10  christos 	    target_float_from_string (dbl_valu, dbl_type, std::string (p));
   3292  1.10  christos 
   3293   1.1  christos 	    sym->set_type (dbl_type);
   3294   1.1  christos 	    sym->set_value_bytes (dbl_valu);
   3295   1.1  christos 	    sym->set_aclass_index (LOC_CONST_BYTES);
   3296   1.1  christos 	  }
   3297   1.1  christos 	  break;
   3298   1.1  christos 	case 'i':
   3299   1.1  christos 	  {
   3300   1.1  christos 	    /* Defining integer constants this way is kind of silly,
   3301   1.1  christos 	       since 'e' constants allows the compiler to give not
   3302   1.1  christos 	       only the value, but the type as well.  C has at least
   3303   1.1  christos 	       int, long, unsigned int, and long long as constant
   3304  1.11  christos 	       types; other languages probably should have at least
   3305  1.10  christos 	       unsigned as well as signed constants.  */
   3306  1.10  christos 
   3307   1.1  christos 	    sym->set_type (builtin_type (objfile)->builtin_long);
   3308   1.1  christos 	    sym->set_value_longest (atoi (p));
   3309   1.1  christos 	    sym->set_aclass_index (LOC_CONST);
   3310   1.1  christos 	  }
   3311   1.1  christos 	  break;
   3312  1.11  christos 
   3313  1.10  christos 	case 'c':
   3314  1.10  christos 	  {
   3315   1.1  christos 	    sym->set_type (builtin_type (objfile)->builtin_char);
   3316   1.1  christos 	    sym->set_value_longest (atoi (p));
   3317   1.1  christos 	    sym->set_aclass_index (LOC_CONST);
   3318   1.1  christos 	  }
   3319   1.1  christos 	  break;
   3320   1.1  christos 
   3321   1.1  christos 	case 's':
   3322   1.1  christos 	  {
   3323   1.1  christos 	    struct type *range_type;
   3324   1.1  christos 	    int ind = 0;
   3325   1.1  christos 	    char quote = *p++;
   3326   1.1  christos 	    gdb_byte *string_local = (gdb_byte *) alloca (strlen (p));
   3327   1.1  christos 	    gdb_byte *string_value;
   3328  1.10  christos 
   3329  1.10  christos 	    if (quote != '\'' && quote != '"')
   3330  1.10  christos 	      {
   3331   1.8  christos 		sym->set_aclass_index (LOC_CONST);
   3332   1.1  christos 		sym->set_type (error_type (&p, objfile));
   3333   1.1  christos 		sym->set_domain (VAR_DOMAIN);
   3334   1.1  christos 		add_symbol_to_list (sym, get_file_symbols ());
   3335   1.1  christos 		return sym;
   3336   1.1  christos 	      }
   3337   1.1  christos 
   3338   1.1  christos 	    /* Find matching quote, rejecting escaped quotes.  */
   3339   1.1  christos 	    while (*p && *p != quote)
   3340   1.1  christos 	      {
   3341   1.1  christos 		if (*p == '\\' && p[1] == quote)
   3342   1.1  christos 		  {
   3343   1.1  christos 		    string_local[ind] = (gdb_byte) quote;
   3344   1.1  christos 		    ind++;
   3345   1.1  christos 		    p += 2;
   3346   1.1  christos 		  }
   3347   1.1  christos 		else if (*p)
   3348   1.1  christos 		  {
   3349   1.1  christos 		    string_local[ind] = (gdb_byte) (*p);
   3350   1.1  christos 		    ind++;
   3351   1.1  christos 		    p++;
   3352   1.1  christos 		  }
   3353  1.10  christos 	      }
   3354  1.10  christos 	    if (*p != quote)
   3355  1.10  christos 	      {
   3356   1.8  christos 		sym->set_aclass_index (LOC_CONST);
   3357   1.1  christos 		sym->set_type (error_type (&p, objfile));
   3358   1.1  christos 		sym->set_domain (VAR_DOMAIN);
   3359   1.1  christos 		add_symbol_to_list (sym, get_file_symbols ());
   3360   1.1  christos 		return sym;
   3361   1.1  christos 	      }
   3362  1.11  christos 
   3363   1.1  christos 	    /* NULL terminate the string.  */
   3364  1.11  christos 	    string_local[ind] = 0;
   3365  1.11  christos 	    type_allocator alloc (objfile, get_current_subfile ()->language);
   3366   1.3  christos 	    range_type
   3367  1.10  christos 	      = create_static_range_type (alloc,
   3368  1.11  christos 					  builtin_type (objfile)->builtin_int,
   3369  1.10  christos 					  0, ind);
   3370   1.6  christos 	    sym->set_type
   3371   1.6  christos 	      (create_array_type (alloc, builtin_type (objfile)->builtin_char,
   3372   1.1  christos 				  range_type));
   3373   1.1  christos 	    string_value
   3374   1.1  christos 	      = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, ind + 1);
   3375  1.10  christos 	    memcpy (string_value, string_local, ind + 1);
   3376  1.10  christos 	    p++;
   3377   1.1  christos 
   3378   1.1  christos 	    sym->set_value_bytes (string_value);
   3379   1.1  christos 	    sym->set_aclass_index (LOC_CONST_BYTES);
   3380   1.1  christos 	  }
   3381   1.1  christos 	  break;
   3382   1.1  christos 
   3383   1.1  christos 	case 'e':
   3384   1.1  christos 	  /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
   3385   1.1  christos 	     can be represented as integral.
   3386  1.10  christos 	     e.g. "b:c=e6,0" for "const b = blob1"
   3387  1.10  christos 	     (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
   3388   1.1  christos 	  {
   3389   1.1  christos 	    sym->set_aclass_index (LOC_CONST);
   3390   1.1  christos 	    sym->set_type (read_type (&p, objfile));
   3391  1.10  christos 
   3392   1.1  christos 	    if (*p != ',')
   3393   1.1  christos 	      {
   3394   1.1  christos 		sym->set_type (error_type (&p, objfile));
   3395   1.1  christos 		break;
   3396   1.1  christos 	      }
   3397   1.1  christos 	    ++p;
   3398   1.1  christos 
   3399   1.1  christos 	    /* If the value is too big to fit in an int (perhaps because
   3400   1.1  christos 	       it is unsigned), or something like that, we silently get
   3401   1.1  christos 	       a bogus value.  The type and everything else about it is
   3402  1.10  christos 	       correct.  Ideally, we should be using whatever we have
   3403   1.1  christos 	       available for parsing unsigned and long long values,
   3404   1.1  christos 	       however.  */
   3405   1.1  christos 	    sym->set_value_longest (atoi (p));
   3406   1.1  christos 	  }
   3407  1.10  christos 	  break;
   3408  1.10  christos 	default:
   3409   1.1  christos 	  {
   3410   1.1  christos 	    sym->set_aclass_index (LOC_CONST);
   3411  1.10  christos 	    sym->set_type (error_type (&p, objfile));
   3412   1.8  christos 	  }
   3413   1.1  christos 	}
   3414   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3415   1.1  christos       add_symbol_to_list (sym, get_file_symbols ());
   3416   1.1  christos       return sym;
   3417  1.10  christos 
   3418  1.10  christos     case 'C':
   3419  1.10  christos       /* The name of a caught exception.  */
   3420  1.10  christos       sym->set_type (read_type (&p, objfile));
   3421   1.8  christos       sym->set_aclass_index (LOC_LABEL);
   3422   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3423   1.1  christos       sym->set_value_address (valu);
   3424   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3425   1.1  christos       break;
   3426  1.10  christos 
   3427  1.10  christos     case 'f':
   3428  1.11  christos       /* A static function definition.  */
   3429   1.8  christos       sym->set_type (read_type (&p, objfile));
   3430   1.1  christos       sym->set_aclass_index (LOC_BLOCK);
   3431   1.1  christos       sym->set_domain (FUNCTION_DOMAIN);
   3432   1.1  christos       add_symbol_to_list (sym, get_file_symbols ());
   3433   1.1  christos       /* fall into process_function_types.  */
   3434  1.10  christos 
   3435  1.10  christos     process_function_types:
   3436  1.10  christos       /* Function result types are described as the result type in stabs.
   3437  1.10  christos 	 We need to convert this to the function-returning-type-X type
   3438   1.1  christos 	 in GDB.  E.g. "int" is converted to "function returning int".  */
   3439   1.1  christos       if (sym->type ()->code () != TYPE_CODE_FUNC)
   3440  1.10  christos 	sym->set_type (lookup_function_type (sym->type ()));
   3441  1.10  christos 
   3442  1.10  christos       /* All functions in C++ have prototypes.  Stabs does not offer an
   3443  1.10  christos 	 explicit way to identify prototyped or unprototyped functions,
   3444  1.10  christos 	 but both GCC and Sun CC emit stabs for the "call-as" type rather
   3445  1.10  christos 	 than the "declared-as" type for unprototyped functions, so
   3446   1.1  christos 	 we treat all functions as if they were prototyped.  This is used
   3447   1.1  christos 	 primarily for promotion when calling the function from GDB.  */
   3448   1.1  christos       sym->type ()->set_is_prototyped (true);
   3449   1.1  christos 
   3450   1.1  christos       /* fall into process_prototype_types.  */
   3451   1.1  christos 
   3452   1.1  christos     process_prototype_types:
   3453  1.10  christos       /* Sun acc puts declared types of arguments here.  */
   3454   1.1  christos       if (*p == ';')
   3455   1.1  christos 	{
   3456   1.7  christos 	  struct type *ftype = sym->type ();
   3457   1.1  christos 	  int nsemi = 0;
   3458   1.1  christos 	  int nparams = 0;
   3459   1.1  christos 	  const char *p1 = p;
   3460   1.1  christos 
   3461   1.1  christos 	  /* Obtain a worst case guess for the number of arguments
   3462   1.1  christos 	     by counting the semicolons.  */
   3463   1.1  christos 	  while (*p1)
   3464   1.1  christos 	    {
   3465   1.1  christos 	      if (*p1++ == ';')
   3466   1.1  christos 		nsemi++;
   3467  1.11  christos 	    }
   3468   1.1  christos 
   3469   1.1  christos 	  /* Allocate parameter information fields and fill them in.  */
   3470   1.1  christos 	  ftype->alloc_fields (nsemi);
   3471   1.1  christos 	  while (*p++ == ';')
   3472   1.1  christos 	    {
   3473  1.10  christos 	      struct type *ptype;
   3474   1.1  christos 
   3475   1.1  christos 	      /* A type number of zero indicates the start of varargs.
   3476   1.1  christos 		 FIXME: GDB currently ignores vararg functions.  */
   3477   1.1  christos 	      if (p[0] == '0' && p[1] == '\0')
   3478   1.1  christos 		break;
   3479  1.10  christos 	      ptype = read_type (&p, objfile);
   3480  1.10  christos 
   3481  1.10  christos 	      /* The Sun compilers mark integer arguments, which should
   3482  1.10  christos 		 be promoted to the width of the calling conventions, with
   3483  1.10  christos 		 a type which references itself.  This type is turned into
   3484   1.9  christos 		 a TYPE_CODE_VOID type by read_type, and we have to turn
   3485  1.11  christos 		 it back into builtin_int here.
   3486   1.9  christos 		 FIXME: Do we need a new builtin_promoted_int_arg ?  */
   3487  1.11  christos 	      if (ptype->code () == TYPE_CODE_VOID)
   3488  1.11  christos 		ptype = builtin_type (objfile)->builtin_int;
   3489   1.1  christos 	      ftype->field (nparams).set_type (ptype);
   3490   1.9  christos 	      ftype->field (nparams).set_is_artificial (false);
   3491  1.10  christos 	      nparams++;
   3492   1.1  christos 	    }
   3493   1.1  christos 	  ftype->set_num_fields (nparams);
   3494   1.1  christos 	  ftype->set_is_prototyped (true);
   3495   1.1  christos 	}
   3496   1.1  christos       break;
   3497  1.10  christos 
   3498  1.10  christos     case 'F':
   3499  1.11  christos       /* A global function definition.  */
   3500   1.8  christos       sym->set_type (read_type (&p, objfile));
   3501   1.1  christos       sym->set_aclass_index (LOC_BLOCK);
   3502   1.1  christos       sym->set_domain (FUNCTION_DOMAIN);
   3503   1.1  christos       add_symbol_to_list (sym, get_global_symbols ());
   3504   1.1  christos       goto process_function_types;
   3505  1.10  christos 
   3506  1.10  christos     case 'G':
   3507  1.10  christos       /* For a class G (global) symbol, it appears that the
   3508  1.10  christos 	 value is not correct.  It is necessary to search for the
   3509  1.10  christos 	 corresponding linker definition to find the value.
   3510  1.10  christos 	 These definitions appear at the end of the namelist.  */
   3511   1.1  christos       sym->set_type (read_type (&p, objfile));
   3512  1.10  christos       sym->set_aclass_index (LOC_STATIC);
   3513  1.10  christos       sym->set_domain (VAR_DOMAIN);
   3514  1.10  christos       /* Don't add symbol references to global_sym_chain.
   3515   1.9  christos 	 Symbol references don't have valid names and wont't match up with
   3516   1.1  christos 	 minimal symbols when the global_sym_chain is relocated.
   3517   1.9  christos 	 We'll fixup symbol references when we fixup the defining symbol.  */
   3518  1.10  christos       if (sym->linkage_name () && sym->linkage_name ()[0] != '#')
   3519   1.1  christos 	{
   3520   1.1  christos 	  i = hashname (sym->linkage_name ());
   3521   1.8  christos 	  sym->set_value_chain (global_sym_chain[i]);
   3522   1.1  christos 	  global_sym_chain[i] = sym;
   3523   1.1  christos 	}
   3524   1.1  christos       add_symbol_to_list (sym, get_global_symbols ());
   3525  1.10  christos       break;
   3526  1.10  christos 
   3527   1.1  christos       /* This case is faked by a conditional above,
   3528   1.1  christos 	 when there is no code letter in the dbx data.
   3529  1.10  christos 	 Dbx data never actually contains 'l'.  */
   3530  1.10  christos     case 's':
   3531  1.10  christos     case 'l':
   3532  1.10  christos       sym->set_type (read_type (&p, objfile));
   3533   1.8  christos       sym->set_aclass_index (LOC_LOCAL);
   3534   1.1  christos       sym->set_value_longest (valu);
   3535   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3536   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3537   1.1  christos       break;
   3538   1.1  christos 
   3539   1.1  christos     case 'p':
   3540   1.1  christos       if (*p == 'F')
   3541   1.1  christos 	/* pF is a two-letter code that means a function parameter in Fortran.
   3542   1.1  christos 	   The type-number specifies the type of the return value.
   3543  1.10  christos 	   Translate it into a pointer-to-function type.  */
   3544  1.10  christos 	{
   3545  1.10  christos 	  p++;
   3546   1.1  christos 	  sym->set_type
   3547   1.1  christos 	    (lookup_pointer_type
   3548  1.10  christos 	       (lookup_function_type (read_type (&p, objfile))));
   3549   1.1  christos 	}
   3550  1.10  christos       else
   3551  1.10  christos 	sym->set_type (read_type (&p, objfile));
   3552  1.10  christos 
   3553  1.10  christos       sym->set_aclass_index (LOC_ARG);
   3554   1.8  christos       sym->set_value_longest (valu);
   3555   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3556   1.1  christos       sym->set_is_argument (1);
   3557   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3558   1.1  christos 
   3559   1.1  christos       if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
   3560   1.1  christos 	{
   3561   1.1  christos 	  /* On little-endian machines, this crud is never necessary,
   3562   1.1  christos 	     and, if the extra bytes contain garbage, is harmful.  */
   3563   1.1  christos 	  break;
   3564   1.1  christos 	}
   3565   1.1  christos 
   3566   1.1  christos       /* If it's gcc-compiled, if it says `short', believe it.  */
   3567   1.1  christos       if (processing_gcc_compilation
   3568   1.1  christos 	  || gdbarch_believe_pcc_promotion (gdbarch))
   3569   1.1  christos 	break;
   3570   1.1  christos 
   3571   1.1  christos       if (!gdbarch_believe_pcc_promotion (gdbarch))
   3572  1.10  christos 	{
   3573   1.1  christos 	  /* If PCC says a parameter is a short or a char, it is
   3574  1.10  christos 	     really an int.  */
   3575   1.1  christos 	  if (sym->type ()->length ()
   3576  1.10  christos 	      < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
   3577  1.10  christos 	      && sym->type ()->code () == TYPE_CODE_INT)
   3578  1.11  christos 	    {
   3579  1.11  christos 	      sym->set_type
   3580   1.1  christos 		(sym->type ()->is_unsigned ()
   3581   1.1  christos 		 ? builtin_type (objfile)->builtin_unsigned_int
   3582   1.1  christos 		 : builtin_type (objfile)->builtin_int);
   3583  1.11  christos 	    }
   3584   1.1  christos 	  break;
   3585   1.1  christos 	}
   3586   1.1  christos       [[fallthrough]];
   3587  1.10  christos 
   3588  1.10  christos     case 'P':
   3589   1.1  christos       /* acc seems to use P to declare the prototypes of functions that
   3590   1.1  christos 	 are referenced by this file.  gdb is not prepared to deal
   3591  1.10  christos 	 with this extra information.  FIXME, it ought to.  */
   3592   1.1  christos       if (type == N_FUN)
   3593   1.1  christos 	{
   3594  1.11  christos 	  sym->set_type (read_type (&p, objfile));
   3595   1.1  christos 	  goto process_prototype_types;
   3596   1.1  christos 	}
   3597   1.1  christos       [[fallthrough]];
   3598  1.10  christos 
   3599  1.10  christos     case 'R':
   3600  1.10  christos       /* Parameter which is in a register.  */
   3601  1.10  christos       sym->set_type (read_type (&p, objfile));
   3602  1.10  christos       sym->set_aclass_index (stab_register_index);
   3603   1.8  christos       sym->set_is_argument (1);
   3604   1.1  christos       sym->set_value_longest (valu);
   3605   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3606   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3607   1.1  christos       break;
   3608  1.10  christos 
   3609  1.10  christos     case 'r':
   3610  1.10  christos       /* Register variable (either global or local).  */
   3611  1.10  christos       sym->set_type (read_type (&p, objfile));
   3612   1.1  christos       sym->set_aclass_index (stab_register_index);
   3613   1.1  christos       sym->set_value_longest (valu);
   3614   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3615   1.1  christos       if (within_function)
   3616   1.1  christos 	{
   3617   1.1  christos 	  /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
   3618   1.9  christos 	     the same name to represent an argument passed in a
   3619   1.1  christos 	     register.  GCC uses 'P' for the same case.  So if we find
   3620   1.1  christos 	     such a symbol pair we combine it into one 'P' symbol.
   3621   1.1  christos 	     For Sun cc we need to do this regardless of stabs_argument_has_addr, because the compiler puts out
   3622   1.1  christos 	     the 'p' symbol even if it never saves the argument onto
   3623   1.1  christos 	     the stack.
   3624   1.1  christos 
   3625   1.1  christos 	     On most machines, we want to preserve both symbols, so
   3626   1.1  christos 	     that we can still get information about what is going on
   3627   1.1  christos 	     with the stack (VAX for computing args_printed, using
   3628   1.1  christos 	     stack slots instead of saved registers in backtraces,
   3629   1.1  christos 	     etc.).
   3630   1.1  christos 
   3631   1.1  christos 	     Note that this code illegally combines
   3632   1.1  christos 	     main(argc) struct foo argc; { register struct foo argc; }
   3633   1.8  christos 	     but this case is considered pathological and causes a warning
   3634   1.1  christos 	     from a decent compiler.  */
   3635   1.1  christos 
   3636  1.10  christos 	  struct pending *local_symbols = *get_local_symbols ();
   3637   1.1  christos 	  if (local_symbols
   3638   1.1  christos 	      && local_symbols->nsyms > 0
   3639   1.1  christos 	      && gdbarch_stabs_argument_has_addr (gdbarch, sym->type ()))
   3640   1.1  christos 	    {
   3641  1.10  christos 	      struct symbol *prev_sym;
   3642  1.10  christos 
   3643   1.9  christos 	      prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
   3644   1.9  christos 	      if ((prev_sym->aclass () == LOC_REF_ARG
   3645   1.1  christos 		   || prev_sym->aclass () == LOC_ARG)
   3646  1.10  christos 		  && strcmp (prev_sym->linkage_name (),
   3647   1.1  christos 			     sym->linkage_name ()) == 0)
   3648   1.1  christos 		{
   3649  1.10  christos 		  prev_sym->set_aclass_index (stab_register_index);
   3650  1.10  christos 		  /* Use the type from the LOC_REGISTER; that is the type
   3651   1.1  christos 		     that is actually in that register.  */
   3652   1.1  christos 		  prev_sym->set_type (sym->type ());
   3653   1.1  christos 		  prev_sym->set_value_longest (sym->value_longest ());
   3654   1.1  christos 		  sym = prev_sym;
   3655   1.8  christos 		  break;
   3656   1.1  christos 		}
   3657   1.1  christos 	    }
   3658   1.8  christos 	  add_symbol_to_list (sym, get_local_symbols ());
   3659   1.1  christos 	}
   3660   1.1  christos       else
   3661   1.1  christos 	add_symbol_to_list (sym, get_file_symbols ());
   3662   1.1  christos       break;
   3663  1.10  christos 
   3664  1.10  christos     case 'S':
   3665  1.10  christos       /* Static symbol at top level of file.  */
   3666  1.10  christos       sym->set_type (read_type (&p, objfile));
   3667   1.8  christos       sym->set_aclass_index (LOC_STATIC);
   3668   1.1  christos       sym->set_value_address (valu);
   3669   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3670   1.1  christos       add_symbol_to_list (sym, get_file_symbols ());
   3671   1.1  christos       break;
   3672  1.10  christos 
   3673  1.10  christos     case 't':
   3674   1.1  christos       /* In Ada, there is no distinction between typedef and non-typedef;
   3675  1.10  christos 	 any type declaration implicitly has the equivalent of a typedef,
   3676  1.10  christos 	 and thus 't' is in fact equivalent to 'Tt'.
   3677  1.10  christos 
   3678  1.10  christos 	 Therefore, for Ada units, we check the character immediately
   3679  1.10  christos 	 before the 't', and if we do not find a 'T', then make sure to
   3680  1.10  christos 	 create the associated symbol in the STRUCT_DOMAIN ('t' definitions
   3681  1.10  christos 	 will be stored in the VAR_DOMAIN).  If the symbol was indeed
   3682  1.10  christos 	 defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
   3683  1.10  christos 	 elsewhere, so we don't need to take care of that.
   3684  1.10  christos 
   3685   1.9  christos 	 This is important to do, because of forward references:
   3686   1.1  christos 	 The cleanup of undefined types stored in undef_types only uses
   3687   1.1  christos 	 STRUCT_DOMAIN symbols to perform the replacement.  */
   3688  1.10  christos       synonym = (sym->language () == language_ada && p[-2] != 'T');
   3689   1.1  christos 
   3690   1.1  christos       /* Typedef */
   3691  1.10  christos       sym->set_type (read_type (&p, objfile));
   3692   1.1  christos 
   3693   1.1  christos       /* For a nameless type, we don't want a create a symbol, thus we
   3694   1.1  christos 	 did not use `sym'.  Return without further processing.  */
   3695  1.10  christos       if (nameless)
   3696  1.10  christos 	return NULL;
   3697  1.11  christos 
   3698   1.1  christos       sym->set_aclass_index (LOC_TYPEDEF);
   3699  1.10  christos       sym->set_value_longest (valu);
   3700  1.10  christos       sym->set_domain (TYPE_DOMAIN);
   3701  1.10  christos       /* C++ vagaries: we may have a type which is derived from
   3702  1.10  christos 	 a base type which did not have its name defined when the
   3703  1.10  christos 	 derived class was output.  We fill in the derived class's
   3704  1.10  christos 	 base part member's name here in that case.  */
   3705  1.10  christos       if (sym->type ()->name () != NULL)
   3706   1.1  christos 	if ((sym->type ()->code () == TYPE_CODE_STRUCT
   3707   1.1  christos 	     || sym->type ()->code () == TYPE_CODE_UNION)
   3708   1.1  christos 	    && TYPE_N_BASECLASSES (sym->type ()))
   3709  1.10  christos 	  {
   3710  1.10  christos 	    int j;
   3711  1.10  christos 
   3712  1.10  christos 	    for (j = TYPE_N_BASECLASSES (sym->type ()) - 1; j >= 0; j--)
   3713   1.1  christos 	      if (TYPE_BASECLASS_NAME (sym->type (), j) == 0)
   3714   1.1  christos 		sym->type ()->field (j).set_name
   3715  1.10  christos 		  (TYPE_BASECLASS (sym->type (), j)->name ());
   3716   1.1  christos 	  }
   3717  1.10  christos 
   3718   1.9  christos       if (sym->type ()->name () == NULL)
   3719  1.10  christos 	{
   3720   1.1  christos 	  if ((sym->type ()->code () == TYPE_CODE_PTR
   3721   1.1  christos 	       && strcmp (sym->linkage_name (), vtbl_ptr_name))
   3722  1.10  christos 	      || sym->type ()->code () == TYPE_CODE_FUNC)
   3723  1.10  christos 	    {
   3724  1.10  christos 	      /* If we are giving a name to a type such as "pointer to
   3725  1.10  christos 		 foo" or "function returning foo", we better not set
   3726  1.10  christos 		 the TYPE_NAME.  If the program contains "typedef char
   3727  1.10  christos 		 *caddr_t;", we don't want all variables of type char
   3728  1.10  christos 		 * to print as caddr_t.  This is not just a
   3729  1.10  christos 		 consequence of GDB's type management; PCC and GCC (at
   3730  1.10  christos 		 least through version 2.4) both output variables of
   3731  1.10  christos 		 either type char * or caddr_t with the type number
   3732  1.10  christos 		 defined in the 't' symbol for caddr_t.  If a future
   3733  1.10  christos 		 compiler cleans this up it GDB is not ready for it
   3734  1.10  christos 		 yet, but if it becomes ready we somehow need to
   3735  1.10  christos 		 disable this check (without breaking the PCC/GCC2.4
   3736  1.10  christos 		 case).
   3737  1.10  christos 
   3738  1.10  christos 		 Sigh.
   3739  1.10  christos 
   3740   1.1  christos 		 Fortunately, this check seems not to be necessary
   3741   1.1  christos 		 for anything except pointers or functions.  */
   3742   1.1  christos 	      /* ezannoni: 2000-10-26.  This seems to apply for
   3743   1.1  christos 		 versions of gcc older than 2.8.  This was the original
   3744  1.10  christos 		 problem: with the following code gdb would tell that
   3745   1.1  christos 		 the type for name1 is caddr_t, and func is char().
   3746   1.1  christos 
   3747   1.1  christos 		 typedef char *caddr_t;
   3748   1.1  christos 		 char *name2;
   3749   1.1  christos 		 struct x
   3750   1.1  christos 		 {
   3751   1.1  christos 		   char *name1;
   3752   1.1  christos 		 } xx;
   3753   1.1  christos 		 char *func()
   3754   1.1  christos 		 {
   3755   1.1  christos 		 }
   3756   1.1  christos 		 main () {}
   3757   1.8  christos 		 */
   3758  1.10  christos 
   3759   1.1  christos 	      /* Pascal accepts names for pointer types.  */
   3760   1.1  christos 	      if (get_current_subfile ()->language == language_pascal)
   3761  1.10  christos 		sym->type ()->set_name (sym->linkage_name ());
   3762   1.1  christos 	    }
   3763   1.1  christos 	  else
   3764   1.8  christos 	    sym->type ()->set_name (sym->linkage_name ());
   3765   1.1  christos 	}
   3766   1.1  christos 
   3767  1.10  christos       add_symbol_to_list (sym, get_file_symbols ());
   3768  1.10  christos 
   3769  1.10  christos       if (synonym)
   3770  1.10  christos 	{
   3771  1.10  christos 	  /* Create the STRUCT_DOMAIN clone.  */
   3772  1.10  christos 	  struct symbol *struct_sym = new (&objfile->objfile_obstack) symbol;
   3773  1.10  christos 
   3774  1.10  christos 	  *struct_sym = *sym;
   3775  1.10  christos 	  struct_sym->set_aclass_index (LOC_TYPEDEF);
   3776  1.10  christos 	  struct_sym->set_value_longest (valu);
   3777   1.9  christos 	  struct_sym->set_domain (STRUCT_DOMAIN);
   3778   1.9  christos 	  if (sym->type ()->name () == 0)
   3779  1.10  christos 	    sym->type ()->set_name
   3780  1.10  christos 	      (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
   3781   1.9  christos 			 (char *) NULL));
   3782   1.1  christos 	  add_symbol_to_list (struct_sym, get_file_symbols ());
   3783   1.1  christos 	}
   3784   1.1  christos 
   3785   1.1  christos       break;
   3786  1.10  christos 
   3787   1.1  christos     case 'T':
   3788   1.1  christos       /* Struct, union, or enum tag.  For GNU C++, this can be be followed
   3789   1.1  christos 	 by 't' which means we are typedef'ing it as well.  */
   3790   1.1  christos       synonym = *p == 't';
   3791   1.1  christos 
   3792  1.10  christos       if (synonym)
   3793   1.1  christos 	p++;
   3794   1.1  christos 
   3795  1.10  christos       sym->set_type (read_type (&p, objfile));
   3796   1.1  christos 
   3797   1.1  christos       /* For a nameless type, we don't want a create a symbol, thus we
   3798   1.1  christos 	 did not use `sym'.  Return without further processing.  */
   3799  1.10  christos       if (nameless)
   3800  1.10  christos 	return NULL;
   3801  1.10  christos 
   3802  1.10  christos       sym->set_aclass_index (LOC_TYPEDEF);
   3803  1.10  christos       sym->set_value_longest (valu);
   3804   1.9  christos       sym->set_domain (STRUCT_DOMAIN);
   3805   1.9  christos       if (sym->type ()->name () == 0)
   3806   1.8  christos 	sym->type ()->set_name
   3807   1.1  christos 	  (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
   3808   1.1  christos 		     (char *) NULL));
   3809   1.1  christos       add_symbol_to_list (sym, get_file_symbols ());
   3810   1.1  christos 
   3811   1.9  christos       if (synonym)
   3812   1.1  christos 	{
   3813   1.1  christos 	  /* Clone the sym and then modify it.  */
   3814  1.10  christos 	  struct symbol *typedef_sym = new (&objfile->objfile_obstack) symbol;
   3815  1.10  christos 
   3816  1.11  christos 	  *typedef_sym = *sym;
   3817  1.10  christos 	  typedef_sym->set_aclass_index (LOC_TYPEDEF);
   3818  1.10  christos 	  typedef_sym->set_value_longest (valu);
   3819   1.9  christos 	  typedef_sym->set_domain (TYPE_DOMAIN);
   3820   1.9  christos 	  if (sym->type ()->name () == 0)
   3821   1.8  christos 	    sym->type ()->set_name
   3822   1.1  christos 	      (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
   3823   1.1  christos 			 (char *) NULL));
   3824   1.1  christos 	  add_symbol_to_list (typedef_sym, get_file_symbols ());
   3825   1.1  christos 	}
   3826   1.1  christos       break;
   3827  1.10  christos 
   3828  1.10  christos     case 'V':
   3829  1.10  christos       /* Static symbol of local scope.  */
   3830  1.10  christos       sym->set_type (read_type (&p, objfile));
   3831   1.9  christos       sym->set_aclass_index (LOC_STATIC);
   3832   1.1  christos       sym->set_value_address (valu);
   3833   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3834   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3835   1.1  christos       break;
   3836  1.10  christos 
   3837  1.10  christos     case 'v':
   3838  1.10  christos       /* Reference parameter */
   3839  1.10  christos       sym->set_type (read_type (&p, objfile));
   3840  1.10  christos       sym->set_aclass_index (LOC_REF_ARG);
   3841   1.8  christos       sym->set_is_argument (1);
   3842   1.1  christos       sym->set_value_longest (valu);
   3843   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3844   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3845   1.1  christos       break;
   3846  1.10  christos 
   3847  1.10  christos     case 'a':
   3848  1.10  christos       /* Reference parameter which is in a register.  */
   3849  1.10  christos       sym->set_type (read_type (&p, objfile));
   3850  1.10  christos       sym->set_aclass_index (stab_regparm_index);
   3851   1.8  christos       sym->set_is_argument (1);
   3852   1.1  christos       sym->set_value_longest (valu);
   3853   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3854   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3855   1.1  christos       break;
   3856  1.10  christos 
   3857  1.10  christos     case 'X':
   3858  1.10  christos       /* This is used by Sun FORTRAN for "function result value".
   3859  1.10  christos 	 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
   3860  1.10  christos 	 that Pascal uses it too, but when I tried it Pascal used
   3861  1.10  christos 	 "x:3" (local symbol) instead.  */
   3862  1.10  christos       sym->set_type (read_type (&p, objfile));
   3863   1.8  christos       sym->set_aclass_index (LOC_LOCAL);
   3864   1.1  christos       sym->set_value_longest (valu);
   3865   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3866   1.1  christos       add_symbol_to_list (sym, get_local_symbols ());
   3867  1.10  christos       break;
   3868  1.10  christos 
   3869  1.10  christos     default:
   3870  1.10  christos       sym->set_type (error_type (&p, objfile));
   3871   1.8  christos       sym->set_aclass_index (LOC_CONST);
   3872   1.1  christos       sym->set_value_longest (0);
   3873   1.1  christos       sym->set_domain (VAR_DOMAIN);
   3874   1.1  christos       add_symbol_to_list (sym, get_file_symbols ());
   3875   1.1  christos       break;
   3876   1.1  christos     }
   3877   1.1  christos 
   3878   1.1  christos   /* Some systems pass variables of certain types by reference instead
   3879  1.10  christos      of by value, i.e. they will pass the address of a structure (in a
   3880  1.10  christos      register or on the stack) instead of the structure itself.  */
   3881   1.1  christos 
   3882   1.1  christos   if (gdbarch_stabs_argument_has_addr (gdbarch, sym->type ())
   3883  1.10  christos       && sym->is_argument ())
   3884  1.10  christos     {
   3885  1.10  christos       /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
   3886   1.1  christos 	 variables passed in a register).  */
   3887   1.1  christos       if (sym->aclass () == LOC_REGISTER)
   3888  1.10  christos 	sym->set_aclass_index (LOC_REGPARM_ADDR);
   3889  1.10  christos       /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
   3890   1.1  christos 	 and subsequent arguments on SPARC, for example).  */
   3891   1.1  christos       else if (sym->aclass () == LOC_ARG)
   3892   1.1  christos 	sym->set_aclass_index (LOC_REF_ARG);
   3893   1.1  christos     }
   3894   1.1  christos 
   3895   1.1  christos   return sym;
   3896   1.1  christos }
   3897   1.1  christos 
   3898   1.1  christos /* Skip rest of this symbol and return an error type.
   3899   1.1  christos 
   3900   1.1  christos    General notes on error recovery:  error_type always skips to the
   3901   1.1  christos    end of the symbol (modulo cretinous dbx symbol name continuation).
   3902   1.1  christos    Thus code like this:
   3903   1.1  christos 
   3904   1.1  christos    if (*(*pp)++ != ';')
   3905   1.1  christos    return error_type (pp, objfile);
   3906   1.1  christos 
   3907   1.1  christos    is wrong because if *pp starts out pointing at '\0' (typically as the
   3908   1.1  christos    result of an earlier error), it will be incremented to point to the
   3909   1.1  christos    start of the next symbol, which might produce strange results, at least
   3910   1.1  christos    if you run off the end of the string table.  Instead use
   3911   1.1  christos 
   3912   1.1  christos    if (**pp != ';')
   3913   1.1  christos    return error_type (pp, objfile);
   3914   1.1  christos    ++*pp;
   3915   1.1  christos 
   3916   1.1  christos    or
   3917   1.1  christos 
   3918   1.1  christos    if (**pp != ';')
   3919   1.1  christos    foo = error_type (pp, objfile);
   3920   1.1  christos    else
   3921   1.1  christos    ++*pp;
   3922   1.1  christos 
   3923   1.1  christos    And in case it isn't obvious, the point of all this hair is so the compiler
   3924   1.1  christos    can define new types and new syntaxes, and old versions of the
   3925   1.7  christos    debugger will be able to read the new symbol tables.  */
   3926   1.1  christos 
   3927   1.8  christos static struct type *
   3928   1.1  christos error_type (const char **pp, struct objfile *objfile)
   3929   1.1  christos {
   3930   1.1  christos   complaint (_("couldn't parse type; debugger out of date?"));
   3931   1.1  christos   while (1)
   3932   1.1  christos     {
   3933   1.1  christos       /* Skip to end of symbol.  */
   3934   1.1  christos       while (**pp != '\0')
   3935   1.1  christos 	{
   3936   1.1  christos 	  (*pp)++;
   3937   1.1  christos 	}
   3938   1.1  christos 
   3939   1.1  christos       /* Check for and handle cretinous dbx symbol name continuation!  */
   3940   1.1  christos       if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
   3941   1.1  christos 	{
   3942   1.1  christos 	  *pp = next_symbol_text (objfile);
   3943   1.1  christos 	}
   3944   1.1  christos       else
   3945   1.1  christos 	{
   3946  1.11  christos 	  break;
   3947   1.1  christos 	}
   3948   1.1  christos     }
   3949   1.1  christos   return builtin_type (objfile)->builtin_error;
   3950  1.11  christos }
   3951  1.11  christos 
   3952  1.11  christos 
   3954  1.11  christos /* Allocate a stub method whose return type is TYPE.  This apparently
   3955  1.11  christos    happens for speed of symbol reading, since parsing out the
   3956  1.11  christos    arguments to the method is cpu-intensive, the way we are doing it.
   3957  1.11  christos    So, we will fill in arguments later.  This always returns a fresh
   3958  1.11  christos    type.  */
   3959  1.11  christos 
   3960  1.11  christos static struct type *
   3961  1.11  christos allocate_stub_method (struct type *type)
   3962  1.11  christos {
   3963  1.11  christos   struct type *mtype;
   3964  1.11  christos 
   3965  1.11  christos   mtype = type_allocator (type).new_type ();
   3966  1.11  christos   mtype->set_code (TYPE_CODE_METHOD);
   3967  1.11  christos   mtype->set_length (1);
   3968  1.11  christos   mtype->set_is_stub (true);
   3969  1.11  christos   mtype->set_target_type (type);
   3970   1.1  christos   /* TYPE_SELF_TYPE (mtype) = unknown yet */
   3971   1.1  christos   return mtype;
   3972   1.1  christos }
   3973   1.1  christos 
   3974   1.1  christos /* Read type information or a type definition; return the type.  Even
   3975   1.1  christos    though this routine accepts either type information or a type
   3976   1.1  christos    definition, the distinction is relevant--some parts of stabsread.c
   3977   1.7  christos    assume that type information starts with a digit, '-', or '(' in
   3978   1.1  christos    deciding whether to call read_type.  */
   3979   1.1  christos 
   3980   1.1  christos static struct type *
   3981   1.1  christos read_type (const char **pp, struct objfile *objfile)
   3982   1.1  christos {
   3983   1.1  christos   struct type *type = 0;
   3984   1.1  christos   struct type *type1;
   3985   1.1  christos   int typenums[2];
   3986   1.1  christos   char type_descriptor;
   3987   1.1  christos 
   3988   1.1  christos   /* Size in bits of type if specified by a type attribute, or -1 if
   3989   1.1  christos      there is no size attribute.  */
   3990   1.1  christos   int type_size = -1;
   3991   1.1  christos 
   3992   1.1  christos   /* Used to distinguish string and bitstring from char-array and set.  */
   3993   1.1  christos   int is_string = 0;
   3994   1.1  christos 
   3995   1.1  christos   /* Used to distinguish vector from array.  */
   3996   1.1  christos   int is_vector = 0;
   3997   1.1  christos 
   3998   1.1  christos   /* Read type number if present.  The type number may be omitted.
   3999   1.1  christos      for instance in a two-dimensional array declared with type
   4000   1.1  christos      "ar1;1;10;ar1;1;10;4".  */
   4001   1.1  christos   if ((**pp >= '0' && **pp <= '9')
   4002   1.1  christos       || **pp == '('
   4003   1.1  christos       || **pp == '-')
   4004   1.1  christos     {
   4005  1.10  christos       if (read_type_number (pp, typenums) != 0)
   4006  1.10  christos 	return error_type (pp, objfile);
   4007  1.10  christos 
   4008  1.10  christos       if (**pp != '=')
   4009  1.10  christos 	{
   4010  1.10  christos 	  /* Type is not being defined here.  Either it already
   4011  1.10  christos 	     exists, or this is a forward reference to it.
   4012  1.10  christos 	     dbx_alloc_type handles both cases.  */
   4013  1.10  christos 	  type = dbx_alloc_type (typenums, objfile);
   4014  1.10  christos 
   4015  1.10  christos 	  /* If this is a forward reference, arrange to complain if it
   4016   1.1  christos 	     doesn't get patched up by the time we're done
   4017  1.10  christos 	     reading.  */
   4018  1.10  christos 	  if (type->code () == TYPE_CODE_UNDEF)
   4019   1.1  christos 	    add_undefined_type (type, typenums);
   4020   1.1  christos 
   4021   1.1  christos 	  return type;
   4022  1.10  christos 	}
   4023   1.1  christos 
   4024   1.1  christos       /* Type is being defined here.  */
   4025   1.1  christos       /* Skip the '='.
   4026   1.1  christos 	 Also skip the type descriptor - we get it below with (*pp)[-1].  */
   4027   1.1  christos       (*pp) += 2;
   4028  1.10  christos     }
   4029   1.1  christos   else
   4030   1.1  christos     {
   4031   1.1  christos       /* 'typenums=' not present, type is anonymous.  Read and return
   4032   1.1  christos 	 the definition, but don't put it in the type vector.  */
   4033   1.1  christos       typenums[0] = typenums[1] = -1;
   4034   1.1  christos       (*pp)++;
   4035   1.1  christos     }
   4036   1.1  christos 
   4037   1.1  christos again:
   4038   1.1  christos   type_descriptor = (*pp)[-1];
   4039   1.1  christos   switch (type_descriptor)
   4040   1.1  christos     {
   4041   1.1  christos     case 'x':
   4042   1.1  christos       {
   4043   1.1  christos 	enum type_code code;
   4044   1.1  christos 
   4045   1.1  christos 	/* Used to index through file_symbols.  */
   4046   1.1  christos 	struct pending *ppt;
   4047   1.1  christos 	int i;
   4048   1.1  christos 
   4049   1.7  christos 	/* Name including "struct", etc.  */
   4050   1.1  christos 	char *type_name;
   4051   1.1  christos 
   4052   1.1  christos 	{
   4053   1.1  christos 	  const char *from, *p, *q1, *q2;
   4054   1.1  christos 
   4055   1.1  christos 	  /* Set the type code according to the following letter.  */
   4056   1.1  christos 	  switch ((*pp)[0])
   4057   1.1  christos 	    {
   4058   1.1  christos 	    case 's':
   4059   1.1  christos 	      code = TYPE_CODE_STRUCT;
   4060   1.1  christos 	      break;
   4061   1.1  christos 	    case 'u':
   4062   1.1  christos 	      code = TYPE_CODE_UNION;
   4063   1.1  christos 	      break;
   4064   1.1  christos 	    case 'e':
   4065   1.1  christos 	      code = TYPE_CODE_ENUM;
   4066   1.1  christos 	      break;
   4067   1.8  christos 	    default:
   4068   1.1  christos 	      {
   4069   1.1  christos 		/* Complain and keep going, so compilers can invent new
   4070   1.1  christos 		   cross-reference types.  */
   4071   1.1  christos 		complaint (_("Unrecognized cross-reference type `%c'"),
   4072   1.1  christos 			   (*pp)[0]);
   4073   1.1  christos 		code = TYPE_CODE_STRUCT;
   4074   1.1  christos 		break;
   4075   1.1  christos 	      }
   4076   1.1  christos 	    }
   4077   1.1  christos 
   4078   1.1  christos 	  q1 = strchr (*pp, '<');
   4079   1.1  christos 	  p = strchr (*pp, ':');
   4080   1.1  christos 	  if (p == NULL)
   4081   1.1  christos 	    return error_type (pp, objfile);
   4082   1.1  christos 	  if (q1 && p > q1 && p[1] == ':')
   4083   1.1  christos 	    {
   4084   1.1  christos 	      int nesting_level = 0;
   4085   1.1  christos 
   4086   1.1  christos 	      for (q2 = q1; *q2; q2++)
   4087   1.1  christos 		{
   4088   1.1  christos 		  if (*q2 == '<')
   4089   1.1  christos 		    nesting_level++;
   4090   1.1  christos 		  else if (*q2 == '>')
   4091   1.1  christos 		    nesting_level--;
   4092   1.1  christos 		  else if (*q2 == ':' && nesting_level == 0)
   4093   1.1  christos 		    break;
   4094   1.1  christos 		}
   4095   1.1  christos 	      p = q2;
   4096   1.8  christos 	      if (*p != ':')
   4097   1.1  christos 		return error_type (pp, objfile);
   4098  1.10  christos 	    }
   4099  1.10  christos 	  type_name = NULL;
   4100  1.10  christos 	  if (get_current_subfile ()->language == language_cplus)
   4101  1.10  christos 	    {
   4102  1.10  christos 	      std::string name (*pp, p - *pp);
   4103  1.10  christos 	      gdb::unique_xmalloc_ptr<char> new_name
   4104  1.10  christos 		= cp_canonicalize_string (name.c_str ());
   4105  1.10  christos 	      if (new_name != nullptr)
   4106  1.10  christos 		type_name = obstack_strdup (&objfile->objfile_obstack,
   4107  1.10  christos 					    new_name.get ());
   4108  1.10  christos 	    }
   4109  1.10  christos 	  else if (get_current_subfile ()->language == language_c)
   4110   1.9  christos 	    {
   4111   1.9  christos 	      std::string name (*pp, p - *pp);
   4112   1.9  christos 	      gdb::unique_xmalloc_ptr<char> new_name
   4113   1.1  christos 		= c_canonicalize_name (name.c_str ());
   4114   1.1  christos 	      if (new_name != nullptr)
   4115   1.1  christos 		type_name = obstack_strdup (&objfile->objfile_obstack,
   4116   1.7  christos 					    new_name.get ());
   4117   1.1  christos 	    }
   4118   1.1  christos 	  if (type_name == NULL)
   4119   1.1  christos 	    {
   4120   1.1  christos 	      char *to = type_name = (char *)
   4121   1.1  christos 		obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
   4122   1.1  christos 
   4123   1.1  christos 	      /* Copy the name.  */
   4124   1.1  christos 	      from = *pp + 1;
   4125   1.1  christos 	      while (from < p)
   4126   1.1  christos 		*to++ = *from++;
   4127   1.1  christos 	      *to = '\0';
   4128   1.1  christos 	    }
   4129   1.1  christos 
   4130   1.1  christos 	  /* Set the pointer ahead of the name which we just read, and
   4131  1.10  christos 	     the colon.  */
   4132  1.10  christos 	  *pp = p + 1;
   4133  1.10  christos 	}
   4134   1.1  christos 
   4135   1.8  christos 	/* If this type has already been declared, then reuse the same
   4136   1.1  christos 	   type, rather than allocating a new one.  This saves some
   4137   1.1  christos 	   memory.  */
   4138   1.1  christos 
   4139   1.1  christos 	for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
   4140  1.10  christos 	  for (i = 0; i < ppt->nsyms; i++)
   4141  1.10  christos 	    {
   4142  1.10  christos 	      struct symbol *sym = ppt->symbol[i];
   4143   1.9  christos 
   4144   1.1  christos 	      if (sym->aclass () == LOC_TYPEDEF
   4145   1.1  christos 		  && sym->domain () == STRUCT_DOMAIN
   4146  1.10  christos 		  && (sym->type ()->code () == code)
   4147  1.10  christos 		  && strcmp (sym->linkage_name (), type_name) == 0)
   4148  1.10  christos 		{
   4149   1.1  christos 		  obstack_free (&objfile->objfile_obstack, type_name);
   4150   1.1  christos 		  type = sym->type ();
   4151   1.1  christos 		  if (typenums[0] != -1)
   4152   1.1  christos 		    *dbx_lookup_type (typenums, objfile) = type;
   4153   1.1  christos 		  return type;
   4154   1.1  christos 		}
   4155   1.1  christos 	    }
   4156   1.1  christos 
   4157   1.1  christos 	/* Didn't find the type to which this refers, so we must
   4158   1.1  christos 	   be dealing with a forward reference.  Allocate a type
   4159   1.9  christos 	   structure for it, and keep track of it so we can
   4160   1.9  christos 	   fill in the rest of the fields when we get the full
   4161   1.1  christos 	   type.  */
   4162  1.10  christos 	type = dbx_alloc_type (typenums, objfile);
   4163   1.1  christos 	type->set_code (code);
   4164   1.1  christos 	type->set_name (type_name);
   4165   1.1  christos 	INIT_CPLUS_SPECIFIC (type);
   4166   1.1  christos 	type->set_is_stub (true);
   4167   1.1  christos 
   4168   1.1  christos 	add_undefined_type (type, typenums);
   4169   1.1  christos 	return type;
   4170   1.1  christos       }
   4171   1.1  christos 
   4172   1.1  christos     case '-':			/* RS/6000 built-in type */
   4173   1.1  christos     case '0':
   4174   1.1  christos     case '1':
   4175   1.1  christos     case '2':
   4176   1.1  christos     case '3':
   4177   1.1  christos     case '4':
   4178   1.1  christos     case '5':
   4179   1.1  christos     case '6':
   4180   1.1  christos     case '7':
   4181   1.1  christos     case '8':
   4182   1.1  christos     case '9':
   4183  1.10  christos     case '(':
   4184   1.1  christos       (*pp)--;
   4185   1.1  christos 
   4186  1.10  christos       /* We deal with something like t(1,2)=(3,4)=... which
   4187   1.1  christos 	 the Lucid compiler and recent gcc versions (post 2.7.3) use.  */
   4188   1.9  christos 
   4189   1.1  christos       /* Allocate and enter the typedef type first.
   4190   1.1  christos 	 This handles recursive types.  */
   4191   1.1  christos       type = dbx_alloc_type (typenums, objfile);
   4192   1.1  christos       type->set_code (TYPE_CODE_TYPEDEF);
   4193   1.1  christos       {
   4194   1.1  christos 	struct type *xtype = read_type (pp, objfile);
   4195   1.9  christos 
   4196  1.10  christos 	if (type == xtype)
   4197   1.1  christos 	  {
   4198   1.1  christos 	    /* It's being defined as itself.  That means it is "void".  */
   4199   1.1  christos 	    type->set_code (TYPE_CODE_VOID);
   4200   1.1  christos 	    type->set_length (1);
   4201   1.1  christos 	  }
   4202   1.1  christos 	else if (type_size >= 0 || is_string)
   4203   1.1  christos 	  {
   4204   1.1  christos 	    /* This is the absolute wrong way to construct types.  Every
   4205   1.1  christos 	       other debug format has found a way around this problem and
   4206   1.1  christos 	       the related problems with unnecessarily stubbed types;
   4207  1.10  christos 	       someone motivated should attempt to clean up the issue
   4208  1.10  christos 	       here as well.  Once a type pointed to has been created it
   4209  1.10  christos 	       should not be modified.
   4210  1.10  christos 
   4211  1.10  christos 	       Well, it's not *absolutely* wrong.  Constructing recursive
   4212  1.10  christos 	       types (trees, linked lists) necessarily entails modifying
   4213  1.10  christos 	       types after creating them.  Constructing any loop structure
   4214  1.10  christos 	       entails side effects.  The Dwarf 2 reader does handle this
   4215  1.10  christos 	       more gracefully (it never constructs more than once
   4216  1.10  christos 	       instance of a type object, so it doesn't have to copy type
   4217  1.10  christos 	       objects wholesale), but it still mutates type objects after
   4218  1.10  christos 	       other folks have references to them.
   4219  1.10  christos 
   4220  1.10  christos 	       Keep in mind that this circularity/mutation issue shows up
   4221  1.10  christos 	       at the source language level, too: C's "incomplete types",
   4222  1.10  christos 	       for example.  So the proper cleanup, I think, would be to
   4223   1.1  christos 	       limit GDB's type smashing to match exactly those required
   4224   1.9  christos 	       by the source language.  So GDB could have a
   4225   1.1  christos 	       "complete_this_type" function, but never create unnecessary
   4226   1.1  christos 	       copies of a type otherwise.  */
   4227   1.1  christos 	    replace_type (type, xtype);
   4228  1.10  christos 	    type->set_name (NULL);
   4229  1.10  christos 	  }
   4230   1.1  christos 	else
   4231   1.1  christos 	  {
   4232   1.1  christos 	    type->set_target_is_stub (true);
   4233   1.1  christos 	    type->set_target_type (xtype);
   4234   1.1  christos 	  }
   4235  1.10  christos       }
   4236  1.10  christos       break;
   4237  1.10  christos 
   4238  1.10  christos       /* In the following types, we must be sure to overwrite any existing
   4239  1.10  christos 	 type that the typenums refer to, rather than allocating a new one
   4240   1.1  christos 	 and making the typenums point to the new one.  This is because there
   4241   1.1  christos 	 may already be pointers to the existing type (if it had been
   4242   1.1  christos 	 forward-referenced), and we must change it to a pointer, function,
   4243   1.1  christos 	 reference, or whatever, *in-place*.  */
   4244   1.1  christos 
   4245   1.1  christos     case '*':			/* Pointer to another type */
   4246   1.1  christos       type1 = read_type (pp, objfile);
   4247   1.1  christos       type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile));
   4248   1.7  christos       break;
   4249  1.10  christos 
   4250   1.1  christos     case '&':			/* Reference to another type */
   4251   1.1  christos       type1 = read_type (pp, objfile);
   4252   1.1  christos       type = make_reference_type (type1, dbx_lookup_type (typenums, objfile),
   4253   1.1  christos 				  TYPE_CODE_REF);
   4254   1.1  christos       break;
   4255   1.1  christos 
   4256   1.1  christos     case 'f':			/* Function returning another type */
   4257   1.1  christos       type1 = read_type (pp, objfile);
   4258   1.1  christos       type = make_function_type (type1, dbx_lookup_type (typenums, objfile));
   4259  1.10  christos       break;
   4260   1.1  christos 
   4261  1.10  christos     case 'g':                   /* Prototyped function.  (Sun)  */
   4262  1.10  christos       {
   4263  1.10  christos 	/* Unresolved questions:
   4264  1.10  christos 
   4265  1.10  christos 	   - According to Sun's ``STABS Interface Manual'', for 'f'
   4266  1.10  christos 	   and 'F' symbol descriptors, a `0' in the argument type list
   4267  1.10  christos 	   indicates a varargs function.  But it doesn't say how 'g'
   4268  1.10  christos 	   type descriptors represent that info.  Someone with access
   4269  1.10  christos 	   to Sun's toolchain should try it out.
   4270  1.10  christos 
   4271  1.10  christos 	   - According to the comment in define_symbol (search for
   4272  1.10  christos 	   `process_prototype_types:'), Sun emits integer arguments as
   4273  1.10  christos 	   types which ref themselves --- like `void' types.  Do we
   4274  1.10  christos 	   have to deal with that here, too?  Again, someone with
   4275  1.10  christos 	   access to Sun's toolchain should try it out and let us
   4276  1.10  christos 	   know.  */
   4277  1.10  christos 
   4278   1.1  christos 	const char *type_start = (*pp) - 1;
   4279  1.10  christos 	struct type *return_type = read_type (pp, objfile);
   4280  1.10  christos 	struct type *func_type
   4281  1.10  christos 	  = make_function_type (return_type,
   4282  1.10  christos 				dbx_lookup_type (typenums, objfile));
   4283  1.10  christos 	struct type_list {
   4284  1.10  christos 	  struct type *type;
   4285  1.10  christos 	  struct type_list *next;
   4286  1.10  christos 	} *arg_types = 0;
   4287  1.10  christos 	int num_args = 0;
   4288  1.10  christos 
   4289  1.10  christos 	while (**pp && **pp != '#')
   4290  1.10  christos 	  {
   4291  1.10  christos 	    struct type *arg_type = read_type (pp, objfile);
   4292  1.10  christos 	    struct type_list *newobj = XALLOCA (struct type_list);
   4293  1.10  christos 	    newobj->type = arg_type;
   4294  1.10  christos 	    newobj->next = arg_types;
   4295  1.10  christos 	    arg_types = newobj;
   4296  1.10  christos 	    num_args++;
   4297  1.10  christos 	  }
   4298   1.8  christos 	if (**pp == '#')
   4299   1.1  christos 	  ++*pp;
   4300   1.1  christos 	else
   4301  1.10  christos 	  {
   4302   1.1  christos 	    complaint (_("Prototyped function type didn't "
   4303  1.10  christos 			 "end arguments with `#':\n%s"),
   4304  1.10  christos 		       type_start);
   4305  1.10  christos 	  }
   4306  1.10  christos 
   4307  1.10  christos 	/* If there is just one argument whose type is `void', then
   4308  1.10  christos 	   that's just an empty argument list.  */
   4309   1.1  christos 	if (arg_types
   4310  1.11  christos 	    && ! arg_types->next
   4311  1.10  christos 	    && arg_types->type->code () == TYPE_CODE_VOID)
   4312  1.10  christos 	  num_args = 0;
   4313  1.10  christos 
   4314  1.10  christos 	func_type->alloc_fields (num_args);
   4315  1.10  christos 	{
   4316  1.10  christos 	  int i;
   4317  1.10  christos 	  struct type_list *t;
   4318  1.10  christos 
   4319  1.10  christos 	  /* We stuck each argument type onto the front of the list
   4320  1.10  christos 	     when we read it, so the list is reversed.  Build the
   4321  1.10  christos 	     fields array right-to-left.  */
   4322  1.10  christos 	  for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
   4323   1.1  christos 	    func_type->field (i).set_type (t->type);
   4324  1.10  christos 	}
   4325  1.10  christos 	func_type->set_num_fields (num_args);
   4326   1.1  christos 	func_type->set_is_prototyped (true);
   4327   1.1  christos 
   4328   1.1  christos 	type = func_type;
   4329   1.1  christos 	break;
   4330   1.1  christos       }
   4331   1.1  christos 
   4332   1.1  christos     case 'k':			/* Const qualifier on some type (Sun) */
   4333   1.1  christos       type = read_type (pp, objfile);
   4334   1.1  christos       type = make_cv_type (1, TYPE_VOLATILE (type), type,
   4335   1.1  christos 			   dbx_lookup_type (typenums, objfile));
   4336   1.1  christos       break;
   4337   1.1  christos 
   4338   1.1  christos     case 'B':			/* Volatile qual on some type (Sun) */
   4339   1.1  christos       type = read_type (pp, objfile);
   4340   1.1  christos       type = make_cv_type (TYPE_CONST (type), 1, type,
   4341  1.11  christos 			   dbx_lookup_type (typenums, objfile));
   4342   1.1  christos       break;
   4343   1.1  christos 
   4344   1.1  christos     case '@':
   4345   1.1  christos       if (isdigit ((unsigned char)**pp) || **pp == '(' || **pp == '-')
   4346   1.1  christos 	{			/* Member (class & variable) type */
   4347   1.1  christos 	  /* FIXME -- we should be doing smash_to_XXX types here.  */
   4348   1.1  christos 
   4349   1.1  christos 	  struct type *domain = read_type (pp, objfile);
   4350   1.1  christos 	  struct type *memtype;
   4351   1.1  christos 
   4352   1.1  christos 	  if (**pp != ',')
   4353   1.1  christos 	    /* Invalid member type data format.  */
   4354   1.1  christos 	    return error_type (pp, objfile);
   4355   1.1  christos 	  ++*pp;
   4356   1.1  christos 
   4357   1.1  christos 	  memtype = read_type (pp, objfile);
   4358   1.1  christos 	  type = dbx_alloc_type (typenums, objfile);
   4359   1.1  christos 	  smash_to_memberptr_type (type, domain, memtype);
   4360   1.7  christos 	}
   4361   1.1  christos       else
   4362   1.1  christos 	/* type attribute */
   4363   1.1  christos 	{
   4364   1.1  christos 	  const char *attr = *pp;
   4365   1.1  christos 
   4366   1.1  christos 	  /* Skip to the semicolon.  */
   4367   1.1  christos 	  while (**pp != ';' && **pp != '\0')
   4368   1.1  christos 	    ++(*pp);
   4369   1.1  christos 	  if (**pp == '\0')
   4370   1.1  christos 	    return error_type (pp, objfile);
   4371   1.1  christos 	  else
   4372   1.1  christos 	    ++ * pp;		/* Skip the semicolon.  */
   4373   1.1  christos 
   4374   1.1  christos 	  switch (*attr)
   4375   1.1  christos 	    {
   4376   1.1  christos 	    case 's':		/* Size attribute */
   4377   1.1  christos 	      type_size = atoi (attr + 1);
   4378   1.1  christos 	      if (type_size <= 0)
   4379   1.1  christos 		type_size = -1;
   4380   1.1  christos 	      break;
   4381   1.1  christos 
   4382   1.1  christos 	    case 'S':		/* String attribute */
   4383   1.1  christos 	      /* FIXME: check to see if following type is array?  */
   4384   1.1  christos 	      is_string = 1;
   4385   1.1  christos 	      break;
   4386   1.1  christos 
   4387   1.1  christos 	    case 'V':		/* Vector attribute */
   4388   1.1  christos 	      /* FIXME: check to see if following type is array?  */
   4389   1.1  christos 	      is_vector = 1;
   4390  1.10  christos 	      break;
   4391   1.1  christos 
   4392   1.1  christos 	    default:
   4393   1.1  christos 	      /* Ignore unrecognized type attributes, so future compilers
   4394   1.1  christos 		 can invent new ones.  */
   4395   1.1  christos 	      break;
   4396   1.1  christos 	    }
   4397   1.1  christos 	  ++*pp;
   4398   1.1  christos 	  goto again;
   4399   1.1  christos 	}
   4400   1.1  christos       break;
   4401   1.1  christos 
   4402   1.1  christos     case '#':			/* Method (class & fn) type */
   4403   1.1  christos       if ((*pp)[0] == '#')
   4404   1.1  christos 	{
   4405   1.1  christos 	  /* We'll get the parameter types from the name.  */
   4406   1.1  christos 	  struct type *return_type;
   4407   1.8  christos 
   4408   1.1  christos 	  (*pp)++;
   4409   1.1  christos 	  return_type = read_type (pp, objfile);
   4410   1.1  christos 	  if (*(*pp)++ != ';')
   4411   1.1  christos 	    complaint (_("invalid (minimal) member type "
   4412   1.1  christos 			 "data format at symtab pos %d."),
   4413   1.1  christos 		       symnum);
   4414   1.1  christos 	  type = allocate_stub_method (return_type);
   4415   1.1  christos 	  if (typenums[0] != -1)
   4416   1.1  christos 	    *dbx_lookup_type (typenums, objfile) = type;
   4417   1.1  christos 	}
   4418   1.1  christos       else
   4419   1.1  christos 	{
   4420   1.1  christos 	  struct type *domain = read_type (pp, objfile);
   4421   1.1  christos 	  struct type *return_type;
   4422   1.1  christos 	  struct field *args;
   4423   1.1  christos 	  int nargs, varargs;
   4424   1.1  christos 
   4425   1.1  christos 	  if (**pp != ',')
   4426   1.1  christos 	    /* Invalid member type data format.  */
   4427   1.1  christos 	    return error_type (pp, objfile);
   4428   1.1  christos 	  else
   4429   1.1  christos 	    ++(*pp);
   4430   1.1  christos 
   4431   1.1  christos 	  return_type = read_type (pp, objfile);
   4432   1.1  christos 	  args = read_args (pp, ';', objfile, &nargs, &varargs);
   4433   1.1  christos 	  if (args == NULL)
   4434   1.1  christos 	    return error_type (pp, objfile);
   4435   1.1  christos 	  type = dbx_alloc_type (typenums, objfile);
   4436   1.1  christos 	  smash_to_method_type (type, domain, return_type, args,
   4437   1.1  christos 				nargs, varargs);
   4438   1.1  christos 	}
   4439   1.1  christos       break;
   4440   1.1  christos 
   4441   1.1  christos     case 'r':			/* Range type */
   4442   1.1  christos       type = read_range_type (pp, typenums, type_size, objfile);
   4443   1.1  christos       if (typenums[0] != -1)
   4444   1.1  christos 	*dbx_lookup_type (typenums, objfile) = type;
   4445   1.1  christos       break;
   4446   1.1  christos 
   4447   1.1  christos     case 'b':
   4448   1.1  christos 	{
   4449   1.1  christos 	  /* Sun ACC builtin int type */
   4450   1.1  christos 	  type = read_sun_builtin_type (pp, typenums, objfile);
   4451   1.1  christos 	  if (typenums[0] != -1)
   4452   1.1  christos 	    *dbx_lookup_type (typenums, objfile) = type;
   4453   1.1  christos 	}
   4454   1.1  christos       break;
   4455   1.1  christos 
   4456   1.1  christos     case 'R':			/* Sun ACC builtin float type */
   4457   1.1  christos       type = read_sun_floating_type (pp, typenums, objfile);
   4458   1.1  christos       if (typenums[0] != -1)
   4459   1.1  christos 	*dbx_lookup_type (typenums, objfile) = type;
   4460   1.1  christos       break;
   4461   1.1  christos 
   4462   1.1  christos     case 'e':			/* Enumeration type */
   4463   1.1  christos       type = dbx_alloc_type (typenums, objfile);
   4464   1.1  christos       type = read_enum_type (pp, type, objfile);
   4465   1.1  christos       if (typenums[0] != -1)
   4466   1.1  christos 	*dbx_lookup_type (typenums, objfile) = type;
   4467   1.1  christos       break;
   4468  1.10  christos 
   4469  1.10  christos     case 's':			/* Struct type */
   4470  1.10  christos     case 'u':			/* Union type */
   4471  1.10  christos       {
   4472  1.10  christos 	enum type_code type_code = TYPE_CODE_UNDEF;
   4473  1.10  christos 	type = dbx_alloc_type (typenums, objfile);
   4474  1.10  christos 	switch (type_descriptor)
   4475  1.10  christos 	  {
   4476  1.10  christos 	  case 's':
   4477  1.10  christos 	    type_code = TYPE_CODE_STRUCT;
   4478  1.10  christos 	    break;
   4479  1.10  christos 	  case 'u':
   4480  1.10  christos 	    type_code = TYPE_CODE_UNION;
   4481   1.1  christos 	    break;
   4482   1.1  christos 	  }
   4483   1.1  christos 	type = read_struct_type (pp, type, type_code, objfile);
   4484   1.1  christos 	break;
   4485   1.1  christos       }
   4486   1.1  christos 
   4487   1.1  christos     case 'a':			/* Array type */
   4488   1.1  christos       if (**pp != 'r')
   4489   1.1  christos 	return error_type (pp, objfile);
   4490   1.1  christos       ++*pp;
   4491   1.9  christos 
   4492   1.1  christos       type = dbx_alloc_type (typenums, objfile);
   4493   1.1  christos       type = read_array_type (pp, type, objfile);
   4494   1.1  christos       if (is_string)
   4495   1.1  christos 	type->set_code (TYPE_CODE_STRING);
   4496   1.1  christos       if (is_vector)
   4497  1.11  christos 	make_vector_type (type);
   4498  1.11  christos       break;
   4499  1.11  christos 
   4500  1.11  christos     case 'S':			/* Set type */
   4501  1.11  christos       {
   4502  1.11  christos 	type1 = read_type (pp, objfile);
   4503  1.11  christos 	type_allocator alloc (objfile, get_current_subfile ()->language);
   4504   1.1  christos 	type = create_set_type (alloc, type1);
   4505   1.1  christos 	if (typenums[0] != -1)
   4506   1.1  christos 	  *dbx_lookup_type (typenums, objfile) = type;
   4507   1.1  christos       }
   4508   1.1  christos       break;
   4509   1.1  christos 
   4510   1.1  christos     default:
   4511   1.1  christos       --*pp;			/* Go back to the symbol in error.  */
   4512   1.1  christos       /* Particularly important if it was \0!  */
   4513   1.1  christos       return error_type (pp, objfile);
   4514   1.1  christos     }
   4515   1.1  christos 
   4516   1.1  christos   if (type == 0)
   4517   1.1  christos     {
   4518   1.1  christos       warning (_("GDB internal error, type is NULL in stabsread.c."));
   4519   1.1  christos       return error_type (pp, objfile);
   4520  1.10  christos     }
   4521   1.1  christos 
   4522   1.1  christos   /* Size specified in a type attribute overrides any other size.  */
   4523   1.1  christos   if (type_size != -1)
   4524   1.1  christos     type->set_length ((type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT);
   4525   1.1  christos 
   4526   1.1  christos   return type;
   4527   1.1  christos }
   4528  1.10  christos 
   4529  1.10  christos /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
   4531   1.1  christos    Return the proper type node for a given builtin type number.  */
   4532   1.1  christos 
   4533   1.1  christos static const registry<objfile>::key<struct type *,
   4534   1.1  christos 				    gdb::noop_deleter<struct type *>>
   4535   1.9  christos   rs6000_builtin_type_data;
   4536   1.1  christos 
   4537   1.1  christos static struct type *
   4538   1.1  christos rs6000_builtin_type (int typenum, struct objfile *objfile)
   4539   1.1  christos {
   4540   1.1  christos   struct type **negative_types = rs6000_builtin_type_data.get (objfile);
   4541   1.1  christos 
   4542   1.1  christos   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
   4543   1.8  christos #define NUMBER_RECOGNIZED 34
   4544  1.11  christos   struct type *rettype = NULL;
   4545   1.1  christos 
   4546   1.1  christos   if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
   4547   1.1  christos     {
   4548   1.1  christos       complaint (_("Unknown builtin type %d"), typenum);
   4549   1.1  christos       return builtin_type (objfile)->builtin_error;
   4550   1.1  christos     }
   4551   1.1  christos 
   4552   1.9  christos   if (!negative_types)
   4553   1.1  christos     {
   4554   1.1  christos       /* This includes an empty slot for type number -0.  */
   4555   1.1  christos       negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack,
   4556   1.1  christos 				       NUMBER_RECOGNIZED + 1, struct type *);
   4557   1.1  christos       rs6000_builtin_type_data.set (objfile, negative_types);
   4558   1.1  christos     }
   4559   1.1  christos 
   4560   1.1  christos   if (negative_types[-typenum] != NULL)
   4561   1.1  christos     return negative_types[-typenum];
   4562   1.1  christos 
   4563   1.1  christos #if TARGET_CHAR_BIT != 8
   4564   1.1  christos #error This code wrong for TARGET_CHAR_BIT not 8
   4565   1.1  christos   /* These definitions all assume that TARGET_CHAR_BIT is 8.  I think
   4566  1.11  christos      that if that ever becomes not true, the correct fix will be to
   4567   1.1  christos      make the size in the struct type to be in bits, not in units of
   4568   1.1  christos      TARGET_CHAR_BIT.  */
   4569   1.1  christos #endif
   4570   1.1  christos 
   4571  1.10  christos   type_allocator alloc (objfile, get_current_subfile ()->language);
   4572  1.10  christos   switch (-typenum)
   4573  1.10  christos     {
   4574  1.10  christos     case 1:
   4575  1.11  christos       /* The size of this and all the other types are fixed, defined
   4576   1.1  christos 	 by the debugging format.  If there is a type called "int" which
   4577   1.1  christos 	 is other than 32 bits, then it should use a new negative type
   4578  1.11  christos 	 number (or avoid negative type numbers for that case).
   4579  1.10  christos 	 See stabs.texinfo.  */
   4580   1.1  christos       rettype = init_integer_type (alloc, 32, 0, "int");
   4581   1.1  christos       break;
   4582  1.11  christos     case 2:
   4583   1.1  christos       rettype = init_integer_type (alloc, 8, 0, "char");
   4584   1.1  christos       rettype->set_has_no_signedness (true);
   4585  1.11  christos       break;
   4586   1.1  christos     case 3:
   4587   1.1  christos       rettype = init_integer_type (alloc, 16, 0, "short");
   4588  1.11  christos       break;
   4589   1.1  christos     case 4:
   4590   1.1  christos       rettype = init_integer_type (alloc, 32, 0, "long");
   4591  1.11  christos       break;
   4592   1.1  christos     case 5:
   4593   1.1  christos       rettype = init_integer_type (alloc, 8, 1, "unsigned char");
   4594  1.11  christos       break;
   4595   1.1  christos     case 6:
   4596   1.1  christos       rettype = init_integer_type (alloc, 8, 0, "signed char");
   4597  1.11  christos       break;
   4598   1.1  christos     case 7:
   4599   1.1  christos       rettype = init_integer_type (alloc, 16, 1, "unsigned short");
   4600  1.11  christos       break;
   4601   1.1  christos     case 8:
   4602   1.1  christos       rettype = init_integer_type (alloc, 32, 1, "unsigned int");
   4603  1.11  christos       break;
   4604   1.1  christos     case 9:
   4605   1.1  christos       rettype = init_integer_type (alloc, 32, 1, "unsigned");
   4606  1.11  christos       break;
   4607   1.1  christos     case 10:
   4608   1.1  christos       rettype = init_integer_type (alloc, 32, 1, "unsigned long");
   4609   1.1  christos       break;
   4610  1.11  christos     case 11:
   4611   1.7  christos       rettype = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   4612   1.1  christos       break;
   4613   1.1  christos     case 12:
   4614   1.1  christos       /* IEEE single precision (32 bit).  */
   4615  1.11  christos       rettype = init_float_type (alloc, 32, "float",
   4616   1.7  christos 				 floatformats_ieee_single);
   4617   1.1  christos       break;
   4618   1.1  christos     case 13:
   4619   1.1  christos       /* IEEE double precision (64 bit).  */
   4620  1.10  christos       rettype = init_float_type (alloc, 64, "double",
   4621  1.10  christos 				 floatformats_ieee_double);
   4622  1.11  christos       break;
   4623   1.7  christos     case 14:
   4624   1.1  christos       /* This is an IEEE double on the RS/6000, and different machines with
   4625   1.1  christos 	 different sizes for "long double" should use different negative
   4626  1.11  christos 	 type numbers.  See stabs.texinfo.  */
   4627   1.1  christos       rettype = init_float_type (alloc, 64, "long double",
   4628   1.1  christos 				 floatformats_ieee_double);
   4629  1.11  christos       break;
   4630   1.1  christos     case 15:
   4631   1.1  christos       rettype = init_integer_type (alloc, 32, 0, "integer");
   4632  1.11  christos       break;
   4633   1.7  christos     case 16:
   4634   1.1  christos       rettype = init_boolean_type (alloc, 32, 1, "boolean");
   4635   1.1  christos       break;
   4636  1.11  christos     case 17:
   4637   1.7  christos       rettype = init_float_type (alloc, 32, "short real",
   4638   1.1  christos 				 floatformats_ieee_single);
   4639   1.1  christos       break;
   4640  1.11  christos     case 18:
   4641   1.1  christos       rettype = init_float_type (alloc, 64, "real",
   4642   1.1  christos 				 floatformats_ieee_double);
   4643  1.11  christos       break;
   4644   1.1  christos     case 19:
   4645   1.1  christos       rettype = alloc.new_type (TYPE_CODE_ERROR, 0, "stringptr");
   4646  1.11  christos       break;
   4647   1.1  christos     case 20:
   4648   1.1  christos       rettype = init_character_type (alloc, 8, 1, "character");
   4649  1.11  christos       break;
   4650   1.1  christos     case 21:
   4651   1.1  christos       rettype = init_boolean_type (alloc, 8, 1, "logical*1");
   4652  1.11  christos       break;
   4653   1.1  christos     case 22:
   4654   1.1  christos       rettype = init_boolean_type (alloc, 16, 1, "logical*2");
   4655  1.11  christos       break;
   4656   1.1  christos     case 23:
   4657   1.1  christos       rettype = init_boolean_type (alloc, 32, 1, "logical*4");
   4658   1.1  christos       break;
   4659   1.9  christos     case 24:
   4660   1.7  christos       rettype = init_boolean_type (alloc, 32, 1, "logical");
   4661   1.1  christos       break;
   4662   1.1  christos     case 25:
   4663   1.1  christos       /* Complex type consisting of two IEEE single precision values.  */
   4664   1.9  christos       rettype = init_complex_type ("complex",
   4665   1.7  christos 				   rs6000_builtin_type (12, objfile));
   4666   1.1  christos       break;
   4667   1.1  christos     case 26:
   4668  1.11  christos       /* Complex type consisting of two IEEE double precision values.  */
   4669   1.1  christos       rettype = init_complex_type ("double complex",
   4670   1.1  christos 				   rs6000_builtin_type (13, objfile));
   4671  1.11  christos       break;
   4672   1.1  christos     case 27:
   4673   1.1  christos       rettype = init_integer_type (alloc, 8, 0, "integer*1");
   4674  1.11  christos       break;
   4675   1.1  christos     case 28:
   4676   1.1  christos       rettype = init_integer_type (alloc, 16, 0, "integer*2");
   4677  1.11  christos       break;
   4678   1.1  christos     case 29:
   4679   1.1  christos       rettype = init_integer_type (alloc, 32, 0, "integer*4");
   4680  1.11  christos       break;
   4681   1.1  christos     case 30:
   4682   1.1  christos       rettype = init_character_type (alloc, 16, 0, "wchar");
   4683  1.11  christos       break;
   4684   1.1  christos     case 31:
   4685   1.1  christos       rettype = init_integer_type (alloc, 64, 0, "long long");
   4686  1.11  christos       break;
   4687   1.1  christos     case 32:
   4688   1.1  christos       rettype = init_integer_type (alloc, 64, 1, "unsigned long long");
   4689  1.11  christos       break;
   4690   1.1  christos     case 33:
   4691   1.1  christos       rettype = init_integer_type (alloc, 64, 1, "logical*8");
   4692   1.1  christos       break;
   4693   1.1  christos     case 34:
   4694   1.1  christos       rettype = init_integer_type (alloc, 64, 0, "integer*8");
   4695   1.1  christos       break;
   4696   1.1  christos     }
   4697   1.1  christos   negative_types[-typenum] = rettype;
   4698   1.1  christos   return rettype;
   4699   1.1  christos }
   4700   1.1  christos 
   4701   1.1  christos /* This page contains subroutines of read_type.  */
   4703   1.1  christos 
   4704   1.1  christos /* Wrapper around method_name_from_physname to flag a complaint
   4705   1.1  christos    if there is an error.  */
   4706   1.1  christos 
   4707   1.1  christos static char *
   4708   1.1  christos stabs_method_name_from_physname (const char *physname)
   4709   1.1  christos {
   4710   1.8  christos   char *method_name;
   4711   1.1  christos 
   4712   1.1  christos   method_name = method_name_from_physname (physname);
   4713   1.1  christos 
   4714   1.1  christos   if (method_name == NULL)
   4715   1.1  christos     {
   4716   1.1  christos       complaint (_("Method has bad physname %s\n"), physname);
   4717   1.1  christos       return NULL;
   4718   1.1  christos     }
   4719   1.1  christos 
   4720   1.1  christos   return method_name;
   4721   1.1  christos }
   4722   1.1  christos 
   4723   1.1  christos /* Read member function stabs info for C++ classes.  The form of each member
   4724   1.1  christos    function data is:
   4725   1.1  christos 
   4726   1.1  christos    NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
   4727   1.1  christos 
   4728   1.1  christos    An example with two member functions is:
   4729   1.1  christos 
   4730   1.1  christos    afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
   4731   1.1  christos 
   4732   1.1  christos    For the case of overloaded operators, the format is op$::*.funcs, where
   4733   1.9  christos    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
   4734   1.7  christos    name (such as `+=') and `.' marks the end of the operator name.
   4735   1.1  christos 
   4736   1.1  christos    Returns 1 for success, 0 for failure.  */
   4737   1.1  christos 
   4738   1.1  christos static int
   4739   1.1  christos read_member_functions (struct stab_field_info *fip, const char **pp,
   4740   1.1  christos 		       struct type *type, struct objfile *objfile)
   4741   1.1  christos {
   4742   1.1  christos   int nfn_fields = 0;
   4743   1.1  christos   int length = 0;
   4744   1.1  christos   int i;
   4745   1.1  christos   struct next_fnfield
   4746   1.1  christos     {
   4747   1.1  christos       struct next_fnfield *next;
   4748   1.1  christos       struct fn_field fn_field;
   4749   1.7  christos     }
   4750   1.1  christos    *sublist;
   4751   1.1  christos   struct type *look_ahead_type;
   4752   1.1  christos   struct next_fnfieldlist *new_fnlist;
   4753   1.1  christos   struct next_fnfield *new_sublist;
   4754   1.1  christos   char *main_fn_name;
   4755   1.1  christos   const char *p;
   4756   1.1  christos 
   4757  1.10  christos   /* Process each list until we find something that is not a member function
   4758  1.10  christos      or find the end of the functions.  */
   4759   1.1  christos 
   4760   1.1  christos   while (**pp != ';')
   4761   1.1  christos     {
   4762   1.1  christos       /* We should be positioned at the start of the function name.
   4763   1.1  christos 	 Scan forward to find the first ':' and if it is not the
   4764   1.1  christos 	 first of a "::" delimiter, then this is not a member function.  */
   4765   1.1  christos       p = *pp;
   4766   1.1  christos       while (*p != ':')
   4767   1.1  christos 	{
   4768   1.1  christos 	  p++;
   4769   1.1  christos 	}
   4770   1.1  christos       if (p[1] != ':')
   4771   1.1  christos 	{
   4772   1.1  christos 	  break;
   4773   1.9  christos 	}
   4774   1.1  christos 
   4775   1.1  christos       sublist = NULL;
   4776   1.1  christos       look_ahead_type = NULL;
   4777  1.12  christos       length = 0;
   4778   1.1  christos 
   4779   1.1  christos       new_fnlist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfieldlist);
   4780   1.1  christos 
   4781   1.1  christos       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
   4782   1.1  christos 	{
   4783   1.1  christos 	  /* This is a completely weird case.  In order to stuff in the
   4784   1.1  christos 	     names that might contain colons (the usual name delimiter),
   4785   1.1  christos 	     Mike Tiemann defined a different name format which is
   4786   1.1  christos 	     signalled if the identifier is "op$".  In that case, the
   4787   1.1  christos 	     format is "op$::XXXX." where XXXX is the name.  This is
   4788   1.1  christos 	     used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
   4789   1.1  christos 	  /* This lets the user type "break operator+".
   4790   1.1  christos 	     We could just put in "+" as the name, but that wouldn't
   4791   1.1  christos 	     work for "*".  */
   4792   1.1  christos 	  static char opname[32] = "op$";
   4793   1.1  christos 	  char *o = opname + 3;
   4794   1.1  christos 
   4795   1.1  christos 	  /* Skip past '::'.  */
   4796   1.1  christos 	  *pp = p + 2;
   4797   1.1  christos 
   4798   1.1  christos 	  STABS_CONTINUE (pp, objfile);
   4799   1.1  christos 	  p = *pp;
   4800   1.1  christos 	  while (*p != '.')
   4801   1.1  christos 	    {
   4802   1.1  christos 	      *o++ = *p++;
   4803   1.1  christos 	    }
   4804   1.1  christos 	  main_fn_name = savestring (opname, o - opname);
   4805   1.1  christos 	  /* Skip past '.'  */
   4806   1.1  christos 	  *pp = p + 1;
   4807   1.1  christos 	}
   4808   1.1  christos       else
   4809   1.1  christos 	{
   4810   1.1  christos 	  main_fn_name = savestring (*pp, p - *pp);
   4811   1.1  christos 	  /* Skip past '::'.  */
   4812   1.9  christos 	  *pp = p + 2;
   4813   1.1  christos 	}
   4814   1.1  christos       new_fnlist->fn_fieldlist.name = main_fn_name;
   4815   1.1  christos 
   4816   1.1  christos       do
   4817   1.1  christos 	{
   4818   1.1  christos 	  new_sublist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfield);
   4819   1.1  christos 
   4820   1.1  christos 	  /* Check for and handle cretinous dbx symbol name continuation!  */
   4821   1.1  christos 	  if (look_ahead_type == NULL)
   4822   1.1  christos 	    {
   4823   1.1  christos 	      /* Normal case.  */
   4824   1.1  christos 	      STABS_CONTINUE (pp, objfile);
   4825   1.1  christos 
   4826   1.1  christos 	      new_sublist->fn_field.type = read_type (pp, objfile);
   4827   1.1  christos 	      if (**pp != ':')
   4828   1.1  christos 		{
   4829   1.1  christos 		  /* Invalid symtab info for member function.  */
   4830   1.1  christos 		  return 0;
   4831   1.1  christos 		}
   4832   1.1  christos 	    }
   4833   1.1  christos 	  else
   4834   1.1  christos 	    {
   4835   1.1  christos 	      /* g++ version 1 kludge */
   4836   1.1  christos 	      new_sublist->fn_field.type = look_ahead_type;
   4837   1.1  christos 	      look_ahead_type = NULL;
   4838   1.1  christos 	    }
   4839   1.1  christos 
   4840   1.1  christos 	  (*pp)++;
   4841   1.5  christos 	  p = *pp;
   4842   1.9  christos 	  while (*p != ';')
   4843   1.9  christos 	    {
   4844   1.5  christos 	      p++;
   4845   1.1  christos 	    }
   4846  1.10  christos 
   4847   1.1  christos 	  /* These are methods, not functions.  */
   4848   1.5  christos 	  if (new_sublist->fn_field.type->code () == TYPE_CODE_FUNC)
   4849   1.5  christos 	    new_sublist->fn_field.type->set_code (TYPE_CODE_METHOD);
   4850   1.1  christos 
   4851   1.1  christos 	  /* If this is just a stub, then we don't have the real name here.  */
   4852   1.5  christos 	  if (new_sublist->fn_field.type->is_stub ())
   4853   1.1  christos 	    {
   4854   1.1  christos 	      if (!TYPE_SELF_TYPE (new_sublist->fn_field.type))
   4855   1.1  christos 		set_type_self_type (new_sublist->fn_field.type, type);
   4856   1.1  christos 	      new_sublist->fn_field.is_stub = 1;
   4857   1.1  christos 	    }
   4858   1.1  christos 
   4859   1.1  christos 	  new_sublist->fn_field.physname = savestring (*pp, p - *pp);
   4860  1.11  christos 	  *pp = p + 1;
   4861   1.1  christos 
   4862   1.1  christos 	  /* Set this member function's visibility fields.  */
   4863  1.11  christos 	  switch (*(*pp)++)
   4864   1.1  christos 	    {
   4865   1.1  christos 	    case VISIBILITY_PRIVATE:
   4866   1.1  christos 	      new_sublist->fn_field.accessibility = accessibility::PRIVATE;
   4867   1.1  christos 	      break;
   4868   1.1  christos 	    case VISIBILITY_PROTECTED:
   4869   1.1  christos 	      new_sublist->fn_field.accessibility = accessibility::PROTECTED;
   4870   1.1  christos 	      break;
   4871   1.1  christos 	    }
   4872   1.1  christos 
   4873   1.1  christos 	  STABS_CONTINUE (pp, objfile);
   4874   1.1  christos 	  switch (**pp)
   4875   1.1  christos 	    {
   4876   1.1  christos 	    case 'A':		/* Normal functions.  */
   4877   1.1  christos 	      new_sublist->fn_field.is_const = 0;
   4878   1.1  christos 	      new_sublist->fn_field.is_volatile = 0;
   4879   1.1  christos 	      (*pp)++;
   4880   1.1  christos 	      break;
   4881   1.1  christos 	    case 'B':		/* `const' member functions.  */
   4882   1.1  christos 	      new_sublist->fn_field.is_const = 1;
   4883   1.1  christos 	      new_sublist->fn_field.is_volatile = 0;
   4884   1.1  christos 	      (*pp)++;
   4885   1.1  christos 	      break;
   4886   1.1  christos 	    case 'C':		/* `volatile' member function.  */
   4887   1.1  christos 	      new_sublist->fn_field.is_const = 0;
   4888   1.1  christos 	      new_sublist->fn_field.is_volatile = 1;
   4889   1.1  christos 	      (*pp)++;
   4890   1.1  christos 	      break;
   4891   1.1  christos 	    case 'D':		/* `const volatile' member function.  */
   4892   1.1  christos 	      new_sublist->fn_field.is_const = 1;
   4893   1.1  christos 	      new_sublist->fn_field.is_volatile = 1;
   4894   1.1  christos 	      (*pp)++;
   4895   1.1  christos 	      break;
   4896   1.8  christos 	    case '*':		/* File compiled with g++ version 1 --
   4897   1.1  christos 				   no info.  */
   4898   1.1  christos 	    case '?':
   4899   1.1  christos 	    case '.':
   4900   1.1  christos 	      break;
   4901   1.1  christos 	    default:
   4902   1.1  christos 	      complaint (_("const/volatile indicator missing, got '%c'"),
   4903   1.1  christos 			 **pp);
   4904   1.1  christos 	      break;
   4905   1.1  christos 	    }
   4906   1.1  christos 
   4907   1.1  christos 	  switch (*(*pp)++)
   4908   1.1  christos 	    {
   4909   1.1  christos 	    case '*':
   4910   1.1  christos 	      {
   4911   1.1  christos 		int nbits;
   4912   1.1  christos 		/* virtual member function, followed by index.
   4913   1.1  christos 		   The sign bit is set to distinguish pointers-to-methods
   4914   1.1  christos 		   from virtual function indicies.  Since the array is
   4915   1.1  christos 		   in words, the quantity must be shifted left by 1
   4916   1.1  christos 		   on 16 bit machine, and by 2 on 32 bit machine, forcing
   4917   1.1  christos 		   the sign bit out, and usable as a valid index into
   4918   1.1  christos 		   the array.  Remove the sign bit here.  */
   4919   1.1  christos 		new_sublist->fn_field.voffset =
   4920   1.1  christos 		  (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2;
   4921   1.1  christos 		if (nbits != 0)
   4922   1.1  christos 		  return 0;
   4923   1.1  christos 
   4924   1.1  christos 		STABS_CONTINUE (pp, objfile);
   4925   1.1  christos 		if (**pp == ';' || **pp == '\0')
   4926   1.1  christos 		  {
   4927   1.1  christos 		    /* Must be g++ version 1.  */
   4928   1.1  christos 		    new_sublist->fn_field.fcontext = 0;
   4929   1.1  christos 		  }
   4930   1.1  christos 		else
   4931   1.1  christos 		  {
   4932   1.1  christos 		    /* Figure out from whence this virtual function came.
   4933   1.1  christos 		       It may belong to virtual function table of
   4934   1.1  christos 		       one of its baseclasses.  */
   4935   1.1  christos 		    look_ahead_type = read_type (pp, objfile);
   4936   1.1  christos 		    if (**pp == ':')
   4937   1.1  christos 		      {
   4938   1.1  christos 			/* g++ version 1 overloaded methods.  */
   4939   1.1  christos 		      }
   4940   1.1  christos 		    else
   4941   1.1  christos 		      {
   4942   1.1  christos 			new_sublist->fn_field.fcontext = look_ahead_type;
   4943   1.1  christos 			if (**pp != ';')
   4944   1.1  christos 			  {
   4945   1.1  christos 			    return 0;
   4946   1.1  christos 			  }
   4947   1.1  christos 			else
   4948   1.1  christos 			  {
   4949   1.1  christos 			    ++*pp;
   4950   1.1  christos 			  }
   4951   1.1  christos 			look_ahead_type = NULL;
   4952   1.1  christos 		      }
   4953   1.1  christos 		  }
   4954   1.1  christos 		break;
   4955   1.1  christos 	      }
   4956   1.1  christos 	    case '?':
   4957   1.1  christos 	      /* static member function.  */
   4958   1.1  christos 	      {
   4959   1.1  christos 		int slen = strlen (main_fn_name);
   4960   1.1  christos 
   4961   1.1  christos 		new_sublist->fn_field.voffset = VOFFSET_STATIC;
   4962   1.1  christos 
   4963   1.1  christos 		/* For static member functions, we can't tell if they
   4964   1.1  christos 		   are stubbed, as they are put out as functions, and not as
   4965   1.1  christos 		   methods.
   4966   1.1  christos 		   GCC v2 emits the fully mangled name if
   4967   1.1  christos 		   dbxout.c:flag_minimal_debug is not set, so we have to
   4968   1.1  christos 		   detect a fully mangled physname here and set is_stub
   4969   1.1  christos 		   accordingly.  Fully mangled physnames in v2 start with
   4970   1.1  christos 		   the member function name, followed by two underscores.
   4971   1.1  christos 		   GCC v3 currently always emits stubbed member functions,
   4972   1.1  christos 		   but with fully mangled physnames, which start with _Z.  */
   4973   1.1  christos 		if (!(strncmp (new_sublist->fn_field.physname,
   4974   1.1  christos 			       main_fn_name, slen) == 0
   4975   1.1  christos 		      && new_sublist->fn_field.physname[slen] == '_'
   4976   1.1  christos 		      && new_sublist->fn_field.physname[slen + 1] == '_'))
   4977   1.1  christos 		  {
   4978   1.1  christos 		    new_sublist->fn_field.is_stub = 1;
   4979   1.8  christos 		  }
   4980   1.1  christos 		break;
   4981   1.8  christos 	      }
   4982  1.11  christos 
   4983   1.1  christos 	    default:
   4984   1.1  christos 	      /* error */
   4985   1.1  christos 	      complaint (_("member function type missing, got '%c'"),
   4986   1.1  christos 			 (*pp)[-1]);
   4987   1.1  christos 	      /* Normal member function.  */
   4988   1.1  christos 	      [[fallthrough]];
   4989   1.1  christos 
   4990   1.1  christos 	    case '.':
   4991   1.1  christos 	      /* normal member function.  */
   4992   1.1  christos 	      new_sublist->fn_field.voffset = 0;
   4993   1.1  christos 	      new_sublist->fn_field.fcontext = 0;
   4994   1.1  christos 	      break;
   4995   1.1  christos 	    }
   4996   1.1  christos 
   4997   1.1  christos 	  new_sublist->next = sublist;
   4998   1.1  christos 	  sublist = new_sublist;
   4999   1.1  christos 	  length++;
   5000   1.1  christos 	  STABS_CONTINUE (pp, objfile);
   5001   1.1  christos 	}
   5002   1.1  christos       while (**pp != ';' && **pp != '\0');
   5003   1.1  christos 
   5004   1.1  christos       (*pp)++;
   5005   1.1  christos       STABS_CONTINUE (pp, objfile);
   5006   1.1  christos 
   5007   1.1  christos       /* Skip GCC 3.X member functions which are duplicates of the callable
   5008   1.1  christos 	 constructor/destructor.  */
   5009   1.1  christos       if (strcmp_iw (main_fn_name, "__base_ctor ") == 0
   5010   1.1  christos 	  || strcmp_iw (main_fn_name, "__base_dtor ") == 0
   5011   1.1  christos 	  || strcmp (main_fn_name, "__deleting_dtor") == 0)
   5012   1.1  christos 	{
   5013   1.1  christos 	  xfree (main_fn_name);
   5014   1.1  christos 	}
   5015   1.1  christos       else
   5016   1.1  christos 	{
   5017   1.1  christos 	  int has_destructor = 0, has_other = 0;
   5018   1.1  christos 	  int is_v3 = 0;
   5019   1.1  christos 	  struct next_fnfield *tmp_sublist;
   5020   1.1  christos 
   5021   1.1  christos 	  /* Various versions of GCC emit various mostly-useless
   5022   1.1  christos 	     strings in the name field for special member functions.
   5023   1.1  christos 
   5024   1.1  christos 	     For stub methods, we need to defer correcting the name
   5025   1.1  christos 	     until we are ready to unstub the method, because the current
   5026   1.1  christos 	     name string is used by gdb_mangle_name.  The only stub methods
   5027   1.1  christos 	     of concern here are GNU v2 operators; other methods have their
   5028   1.1  christos 	     names correct (see caveat below).
   5029   1.1  christos 
   5030   1.1  christos 	     For non-stub methods, in GNU v3, we have a complete physname.
   5031   1.1  christos 	     Therefore we can safely correct the name now.  This primarily
   5032   1.1  christos 	     affects constructors and destructors, whose name will be
   5033   1.1  christos 	     __comp_ctor or __comp_dtor instead of Foo or ~Foo.  Cast
   5034   1.1  christos 	     operators will also have incorrect names; for instance,
   5035   1.1  christos 	     "operator int" will be named "operator i" (i.e. the type is
   5036   1.1  christos 	     mangled).
   5037   1.1  christos 
   5038   1.1  christos 	     For non-stub methods in GNU v2, we have no easy way to
   5039   1.1  christos 	     know if we have a complete physname or not.  For most
   5040   1.1  christos 	     methods the result depends on the platform (if CPLUS_MARKER
   5041   1.1  christos 	     can be `$' or `.', it will use minimal debug information, or
   5042   1.1  christos 	     otherwise the full physname will be included).
   5043   1.1  christos 
   5044   1.1  christos 	     Rather than dealing with this, we take a different approach.
   5045   1.1  christos 	     For v3 mangled names, we can use the full physname; for v2,
   5046   1.1  christos 	     we use cplus_demangle_opname (which is actually v2 specific),
   5047   1.1  christos 	     because the only interesting names are all operators - once again
   5048   1.1  christos 	     barring the caveat below.  Skip this process if any method in the
   5049   1.1  christos 	     group is a stub, to prevent our fouling up the workings of
   5050   1.1  christos 	     gdb_mangle_name.
   5051   1.1  christos 
   5052   1.1  christos 	     The caveat: GCC 2.95.x (and earlier?) put constructors and
   5053   1.1  christos 	     destructors in the same method group.  We need to split this
   5054   1.1  christos 	     into two groups, because they should have different names.
   5055   1.1  christos 	     So for each method group we check whether it contains both
   5056   1.1  christos 	     routines whose physname appears to be a destructor (the physnames
   5057   1.1  christos 	     for and destructors are always provided, due to quirks in v2
   5058   1.1  christos 	     mangling) and routines whose physname does not appear to be a
   5059   1.1  christos 	     destructor.  If so then we break up the list into two halves.
   5060  1.10  christos 	     Even if the constructors and destructors aren't in the same group
   5061   1.1  christos 	     the destructor will still lack the leading tilde, so that also
   5062   1.1  christos 	     needs to be fixed.
   5063   1.1  christos 
   5064  1.10  christos 	     So, to summarize what we expect and handle here:
   5065   1.1  christos 
   5066  1.10  christos 		Given         Given          Real         Real       Action
   5067   1.1  christos 	     method name     physname      physname   method name
   5068   1.1  christos 
   5069   1.1  christos 	     __opi            [none]     __opi__3Foo  operator int    opname
   5070   1.1  christos 								 [now or later]
   5071   1.1  christos 	     Foo              _._3Foo       _._3Foo      ~Foo      separate and
   5072   1.1  christos 								       rename
   5073   1.1  christos 	     operator i     _ZN3FoocviEv _ZN3FoocviEv operator int    demangle
   5074   1.1  christos 	     __comp_ctor  _ZN3FooC1ERKS_ _ZN3FooC1ERKS_   Foo         demangle
   5075   1.1  christos 	  */
   5076   1.1  christos 
   5077   1.1  christos 	  tmp_sublist = sublist;
   5078   1.1  christos 	  while (tmp_sublist != NULL)
   5079   1.1  christos 	    {
   5080   1.1  christos 	      if (tmp_sublist->fn_field.physname[0] == '_'
   5081   1.1  christos 		  && tmp_sublist->fn_field.physname[1] == 'Z')
   5082   1.1  christos 		is_v3 = 1;
   5083   1.1  christos 
   5084   1.1  christos 	      if (is_destructor_name (tmp_sublist->fn_field.physname))
   5085   1.1  christos 		has_destructor++;
   5086   1.1  christos 	      else
   5087   1.1  christos 		has_other++;
   5088   1.1  christos 
   5089   1.1  christos 	      tmp_sublist = tmp_sublist->next;
   5090   1.1  christos 	    }
   5091   1.1  christos 
   5092   1.1  christos 	  if (has_destructor && has_other)
   5093   1.9  christos 	    {
   5094   1.9  christos 	      struct next_fnfieldlist *destr_fnlist;
   5095   1.6  christos 	      struct next_fnfield *last_sublist;
   5096   1.1  christos 
   5097   1.1  christos 	      /* Create a new fn_fieldlist for the destructors.  */
   5098   1.1  christos 
   5099   1.1  christos 	      destr_fnlist = OBSTACK_ZALLOC (&fip->obstack,
   5100   1.6  christos 					     struct next_fnfieldlist);
   5101   1.6  christos 
   5102   1.6  christos 	      destr_fnlist->fn_fieldlist.name
   5103   1.1  christos 		= obconcat (&objfile->objfile_obstack, "~",
   5104   1.1  christos 			    new_fnlist->fn_fieldlist.name, (char *) NULL);
   5105   1.1  christos 
   5106   1.1  christos 	      destr_fnlist->fn_fieldlist.fn_fields =
   5107   1.1  christos 		XOBNEWVEC (&objfile->objfile_obstack,
   5108   1.1  christos 			   struct fn_field, has_destructor);
   5109   1.1  christos 	      memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
   5110   1.1  christos 		  sizeof (struct fn_field) * has_destructor);
   5111   1.1  christos 	      tmp_sublist = sublist;
   5112   1.1  christos 	      last_sublist = NULL;
   5113   1.1  christos 	      i = 0;
   5114   1.1  christos 	      while (tmp_sublist != NULL)
   5115   1.1  christos 		{
   5116   1.1  christos 		  if (!is_destructor_name (tmp_sublist->fn_field.physname))
   5117   1.1  christos 		    {
   5118   1.1  christos 		      tmp_sublist = tmp_sublist->next;
   5119   1.1  christos 		      continue;
   5120   1.1  christos 		    }
   5121   1.1  christos 
   5122   1.1  christos 		  destr_fnlist->fn_fieldlist.fn_fields[i++]
   5123   1.1  christos 		    = tmp_sublist->fn_field;
   5124   1.1  christos 		  if (last_sublist)
   5125   1.1  christos 		    last_sublist->next = tmp_sublist->next;
   5126   1.1  christos 		  else
   5127   1.1  christos 		    sublist = tmp_sublist->next;
   5128   1.1  christos 		  last_sublist = tmp_sublist;
   5129   1.1  christos 		  tmp_sublist = tmp_sublist->next;
   5130   1.1  christos 		}
   5131   1.1  christos 
   5132   1.1  christos 	      destr_fnlist->fn_fieldlist.length = has_destructor;
   5133   1.1  christos 	      destr_fnlist->next = fip->fnlist;
   5134   1.1  christos 	      fip->fnlist = destr_fnlist;
   5135   1.1  christos 	      nfn_fields++;
   5136   1.1  christos 	      length -= has_destructor;
   5137   1.1  christos 	    }
   5138   1.1  christos 	  else if (is_v3)
   5139   1.1  christos 	    {
   5140   1.1  christos 	      /* v3 mangling prevents the use of abbreviated physnames,
   5141   1.1  christos 		 so we can do this here.  There are stubbed methods in v3
   5142   1.1  christos 		 only:
   5143   1.1  christos 		 - in -gstabs instead of -gstabs+
   5144   1.1  christos 		 - or for static methods, which are output as a function type
   5145   1.1  christos 		   instead of a method type.  */
   5146   1.1  christos 	      char *new_method_name =
   5147   1.1  christos 		stabs_method_name_from_physname (sublist->fn_field.physname);
   5148   1.1  christos 
   5149   1.1  christos 	      if (new_method_name != NULL
   5150   1.1  christos 		  && strcmp (new_method_name,
   5151   1.1  christos 			     new_fnlist->fn_fieldlist.name) != 0)
   5152   1.1  christos 		{
   5153   1.1  christos 		  new_fnlist->fn_fieldlist.name = new_method_name;
   5154   1.1  christos 		  xfree (main_fn_name);
   5155   1.1  christos 		}
   5156   1.1  christos 	      else
   5157   1.1  christos 		xfree (new_method_name);
   5158   1.1  christos 	    }
   5159   1.1  christos 	  else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
   5160   1.1  christos 	    {
   5161   1.8  christos 	      new_fnlist->fn_fieldlist.name =
   5162   1.8  christos 		obconcat (&objfile->objfile_obstack,
   5163   1.1  christos 			  "~", main_fn_name, (char *)NULL);
   5164   1.1  christos 	      xfree (main_fn_name);
   5165   1.1  christos 	    }
   5166   1.1  christos 
   5167   1.1  christos 	  new_fnlist->fn_fieldlist.fn_fields
   5168   1.1  christos 	    = OBSTACK_CALLOC (&objfile->objfile_obstack, length, fn_field);
   5169   1.1  christos 	  for (i = length; (i--, sublist); sublist = sublist->next)
   5170   1.1  christos 	    {
   5171   1.1  christos 	      new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
   5172   1.1  christos 	    }
   5173   1.1  christos 
   5174   1.1  christos 	  new_fnlist->fn_fieldlist.length = length;
   5175   1.1  christos 	  new_fnlist->next = fip->fnlist;
   5176   1.1  christos 	  fip->fnlist = new_fnlist;
   5177   1.1  christos 	  nfn_fields++;
   5178   1.1  christos 	}
   5179  1.11  christos     }
   5180   1.1  christos 
   5181   1.1  christos   if (nfn_fields)
   5182   1.1  christos     {
   5183   1.1  christos       ALLOCATE_CPLUS_STRUCT_TYPE (type);
   5184   1.1  christos       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
   5185   1.1  christos 	TYPE_ZALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
   5186   1.1  christos       TYPE_NFN_FIELDS (type) = nfn_fields;
   5187   1.1  christos     }
   5188   1.1  christos 
   5189   1.1  christos   return 1;
   5190   1.1  christos }
   5191   1.1  christos 
   5192   1.9  christos /* Special GNU C++ name.
   5193   1.9  christos 
   5194   1.1  christos    Returns 1 for success, 0 for failure.  "failure" means that we can't
   5195   1.7  christos    keep parsing and it's time for error_type().  */
   5196   1.1  christos 
   5197   1.1  christos static int
   5198   1.1  christos read_cpp_abbrev (struct stab_field_info *fip, const char **pp,
   5199   1.1  christos 		 struct type *type, struct objfile *objfile)
   5200   1.1  christos {
   5201   1.1  christos   const char *p;
   5202   1.1  christos   const char *name;
   5203   1.1  christos   char cpp_abbrev;
   5204   1.1  christos   struct type *context;
   5205   1.1  christos 
   5206   1.1  christos   p = *pp;
   5207   1.1  christos   if (*++p == 'v')
   5208   1.1  christos     {
   5209  1.10  christos       name = NULL;
   5210  1.10  christos       cpp_abbrev = *++p;
   5211  1.10  christos 
   5212   1.1  christos       *pp = p + 1;
   5213   1.1  christos 
   5214   1.1  christos       /* At this point, *pp points to something like "22:23=*22...",
   5215   1.1  christos 	 where the type number before the ':' is the "context" and
   5216   1.1  christos 	 everything after is a regular type definition.  Lookup the
   5217   1.1  christos 	 type, find it's name, and construct the field name.  */
   5218   1.9  christos 
   5219   1.1  christos       context = read_type (pp, objfile);
   5220   1.1  christos 
   5221   1.1  christos       switch (cpp_abbrev)
   5222   1.1  christos 	{
   5223  1.10  christos 	case 'f':		/* $vf -- a virtual function table pointer */
   5224  1.10  christos 	  name = context->name ();
   5225   1.1  christos 	  if (name == NULL)
   5226   1.1  christos 	    {
   5227   1.1  christos 	      name = "";
   5228   1.9  christos 	    }
   5229   1.1  christos 	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
   5230   1.1  christos 					       vptr_name, name, (char *) NULL));
   5231   1.8  christos 	  break;
   5232   1.1  christos 
   5233   1.1  christos 	case 'b':		/* $vb -- a virtual bsomethingorother */
   5234   1.1  christos 	  name = context->name ();
   5235   1.1  christos 	  if (name == NULL)
   5236  1.10  christos 	    {
   5237  1.10  christos 	      complaint (_("C++ abbreviated type name "
   5238   1.1  christos 			   "unknown at symtab pos %d"),
   5239   1.1  christos 			 symnum);
   5240   1.1  christos 	      name = "FOO";
   5241   1.1  christos 	    }
   5242  1.10  christos 	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
   5243  1.10  christos 					       vb_name, name, (char *) NULL));
   5244  1.10  christos 	  break;
   5245   1.1  christos 
   5246   1.1  christos 	default:
   5247   1.1  christos 	  invalid_cpp_abbrev_complaint (*pp);
   5248   1.1  christos 	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
   5249  1.10  christos 					       "INVALID_CPLUSPLUS_ABBREV",
   5250   1.1  christos 					       (char *) NULL));
   5251   1.1  christos 	  break;
   5252   1.1  christos 	}
   5253   1.1  christos 
   5254   1.1  christos       /* At this point, *pp points to the ':'.  Skip it and read the
   5255   1.1  christos 	 field type.  */
   5256   1.1  christos 
   5257   1.9  christos       p = ++(*pp);
   5258   1.1  christos       if (p[-1] != ':')
   5259   1.1  christos 	{
   5260   1.1  christos 	  invalid_cpp_abbrev_complaint (*pp);
   5261   1.1  christos 	  return 0;
   5262   1.1  christos 	}
   5263   1.1  christos       fip->list->field.set_type (read_type (pp, objfile));
   5264   1.1  christos       if (**pp == ',')
   5265   1.1  christos 	(*pp)++;		/* Skip the comma.  */
   5266  1.10  christos       else
   5267   1.1  christos 	return 0;
   5268   1.1  christos 
   5269   1.1  christos       {
   5270   1.1  christos 	int nbits;
   5271  1.11  christos 
   5272  1.11  christos 	fip->list->field.set_loc_bitpos (read_huge_number (pp, ';', &nbits, 0));
   5273   1.1  christos 	if (nbits != 0)
   5274   1.1  christos 	  return 0;
   5275   1.1  christos       }
   5276   1.1  christos       /* This field is unpacked.  */
   5277   1.1  christos       fip->list->field.set_bitsize (0);
   5278  1.10  christos       fip->list->field.set_accessibility (accessibility::PRIVATE);
   5279  1.10  christos     }
   5280   1.1  christos   else
   5281   1.1  christos     {
   5282   1.1  christos       invalid_cpp_abbrev_complaint (*pp);
   5283   1.1  christos       /* We have no idea what syntax an unrecognized abbrev would have, so
   5284   1.1  christos 	 better return 0.  If we returned 1, we would need to at least advance
   5285   1.1  christos 	 *pp to avoid an infinite loop.  */
   5286   1.9  christos       return 0;
   5287   1.9  christos     }
   5288   1.9  christos   return 1;
   5289   1.1  christos }
   5290   1.9  christos 
   5291   1.1  christos static void
   5292  1.10  christos read_one_struct_field (struct stab_field_info *fip, const char **pp,
   5293  1.10  christos 		       const char *p, struct type *type,
   5294   1.1  christos 		       struct objfile *objfile)
   5295   1.1  christos {
   5296   1.1  christos   struct gdbarch *gdbarch = objfile->arch ();
   5297  1.11  christos 
   5298   1.1  christos   fip->list->field.set_name
   5299   1.1  christos     (obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp));
   5300   1.1  christos   *pp = p + 1;
   5301  1.11  christos 
   5302   1.1  christos   /* This means we have a visibility for a field coming.  */
   5303   1.1  christos   int visibility;
   5304   1.1  christos   if (**pp == '/')
   5305   1.1  christos     {
   5306  1.11  christos       (*pp)++;
   5307  1.11  christos       visibility = *(*pp)++;
   5308  1.11  christos     }
   5309  1.11  christos   else
   5310  1.11  christos     {
   5311  1.11  christos       /* normal dbx-style format, no explicit visibility */
   5312  1.11  christos       visibility = VISIBILITY_PUBLIC;
   5313  1.11  christos     }
   5314  1.11  christos 
   5315  1.11  christos   switch (visibility)
   5316  1.11  christos     {
   5317  1.11  christos     case VISIBILITY_PRIVATE:
   5318  1.11  christos       fip->list->field.set_accessibility (accessibility::PRIVATE);
   5319  1.11  christos       break;
   5320  1.11  christos 
   5321  1.11  christos     case VISIBILITY_PROTECTED:
   5322  1.11  christos       fip->list->field.set_accessibility (accessibility::PROTECTED);
   5323  1.11  christos       break;
   5324  1.11  christos 
   5325  1.11  christos     case VISIBILITY_IGNORE:
   5326  1.11  christos       fip->list->field.set_ignored ();
   5327  1.11  christos       break;
   5328  1.11  christos 
   5329  1.11  christos     case VISIBILITY_PUBLIC:
   5330  1.11  christos       break;
   5331  1.11  christos 
   5332  1.11  christos     default:
   5333   1.1  christos       /* Unknown visibility.  Complain and treat it as public.  */
   5334   1.1  christos       {
   5335   1.9  christos 	complaint (_("Unknown visibility `%c' for field"),
   5336   1.1  christos 		   visibility);
   5337   1.1  christos       }
   5338   1.1  christos       break;
   5339   1.1  christos     }
   5340   1.1  christos 
   5341   1.1  christos   fip->list->field.set_type (read_type (pp, objfile));
   5342   1.1  christos   if (**pp == ':')
   5343   1.1  christos     {
   5344   1.1  christos       p = ++(*pp);
   5345   1.1  christos #if 0
   5346   1.1  christos       /* Possible future hook for nested types.  */
   5347   1.1  christos       if (**pp == '!')
   5348   1.1  christos 	{
   5349   1.1  christos 	  fip->list->field.bitpos = (long) -2;	/* nested type */
   5350   1.1  christos 	  p = ++(*pp);
   5351   1.1  christos 	}
   5352   1.1  christos       else
   5353   1.1  christos 	...;
   5354  1.10  christos #endif
   5355   1.1  christos       while (*p != ';')
   5356   1.1  christos 	{
   5357   1.1  christos 	  p++;
   5358   1.1  christos 	}
   5359   1.1  christos       /* Static class member.  */
   5360   1.1  christos       fip->list->field.set_loc_physname (savestring (*pp, p - *pp));
   5361   1.1  christos       *pp = p + 1;
   5362   1.1  christos       return;
   5363   1.1  christos     }
   5364   1.1  christos   else if (**pp != ',')
   5365   1.1  christos     {
   5366   1.1  christos       /* Bad structure-type format.  */
   5367   1.1  christos       stabs_general_complaint ("bad structure-type format");
   5368   1.1  christos       return;
   5369   1.1  christos     }
   5370  1.10  christos 
   5371   1.1  christos   (*pp)++;			/* Skip the comma.  */
   5372   1.1  christos 
   5373   1.1  christos   {
   5374   1.1  christos     int nbits;
   5375   1.1  christos 
   5376  1.11  christos     fip->list->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0));
   5377   1.1  christos     if (nbits != 0)
   5378   1.1  christos       {
   5379   1.1  christos 	stabs_general_complaint ("bad structure-type format");
   5380   1.1  christos 	return;
   5381   1.1  christos       }
   5382   1.1  christos     fip->list->field.set_bitsize (read_huge_number (pp, ';', &nbits, 0));
   5383   1.1  christos     if (nbits != 0)
   5384  1.10  christos       {
   5385  1.11  christos 	stabs_general_complaint ("bad structure-type format");
   5386   1.1  christos 	return;
   5387   1.1  christos       }
   5388  1.10  christos   }
   5389  1.10  christos 
   5390  1.10  christos   if (fip->list->field.loc_bitpos () == 0
   5391  1.10  christos       && fip->list->field.bitsize () == 0)
   5392  1.10  christos     {
   5393  1.10  christos       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
   5394  1.10  christos 	 it is a field which has been optimized out.  The correct stab for
   5395  1.10  christos 	 this case is to use VISIBILITY_IGNORE, but that is a recent
   5396  1.10  christos 	 invention.  (2) It is a 0-size array.  For example
   5397  1.10  christos 	 union { int num; char str[0]; } foo.  Printing _("<no value>" for
   5398  1.10  christos 	 str in "p foo" is OK, since foo.str (and thus foo.str[3])
   5399  1.10  christos 	 will continue to work, and a 0-size array as a whole doesn't
   5400   1.1  christos 	 have any contents to print.
   5401   1.1  christos 
   5402  1.11  christos 	 I suspect this probably could also happen with gcc -gstabs (not
   5403   1.1  christos 	 -gstabs+) for static fields, and perhaps other C++ extensions.
   5404   1.1  christos 	 Hopefully few people use -gstabs with gdb, since it is intended
   5405   1.1  christos 	 for dbx compatibility.  */
   5406   1.1  christos 
   5407  1.10  christos       /* Ignore this field.  */
   5408  1.10  christos       fip->list->field.set_ignored ();
   5409  1.10  christos     }
   5410   1.1  christos   else
   5411   1.9  christos     {
   5412   1.1  christos       /* Detect an unpacked field and mark it as such.
   5413   1.9  christos 	 dbx gives a bit size for all fields.
   5414   1.9  christos 	 Note that forward refs cannot be packed,
   5415   1.9  christos 	 and treat enums as if they had the width of ints.  */
   5416   1.9  christos 
   5417   1.1  christos       struct type *field_type = check_typedef (fip->list->field.type ());
   5418  1.11  christos 
   5419   1.1  christos       if (field_type->code () != TYPE_CODE_INT
   5420  1.11  christos 	  && field_type->code () != TYPE_CODE_RANGE
   5421  1.10  christos 	  && field_type->code () != TYPE_CODE_BOOL
   5422   1.9  christos 	  && field_type->code () != TYPE_CODE_ENUM)
   5423  1.11  christos 	{
   5424  1.11  christos 	  fip->list->field.set_bitsize (0);
   5425   1.1  christos 	}
   5426   1.1  christos       if ((fip->list->field.bitsize ()
   5427  1.10  christos 	   == TARGET_CHAR_BIT * field_type->length ()
   5428   1.1  christos 	   || (field_type->code () == TYPE_CODE_ENUM
   5429  1.11  christos 	       && (fip->list->field.bitsize ()
   5430   1.1  christos 		   == gdbarch_int_bit (gdbarch)))
   5431   1.1  christos 	  )
   5432   1.1  christos 	  &&
   5433   1.1  christos 	  fip->list->field.loc_bitpos () % 8 == 0)
   5434   1.1  christos 	{
   5435   1.1  christos 	  fip->list->field.set_bitsize (0);
   5436   1.1  christos 	}
   5437   1.1  christos     }
   5438   1.1  christos }
   5439   1.1  christos 
   5440   1.1  christos 
   5441   1.1  christos /* Read struct or class data fields.  They have the form:
   5442   1.1  christos 
   5443   1.1  christos    NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
   5444   1.1  christos 
   5445   1.1  christos    At the end, we see a semicolon instead of a field.
   5446   1.1  christos 
   5447   1.1  christos    In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
   5448   1.1  christos    a static field.
   5449   1.1  christos 
   5450   1.1  christos    The optional VISIBILITY is one of:
   5451   1.1  christos 
   5452   1.1  christos    '/0' (VISIBILITY_PRIVATE)
   5453   1.1  christos    '/1' (VISIBILITY_PROTECTED)
   5454   1.1  christos    '/2' (VISIBILITY_PUBLIC)
   5455   1.1  christos    '/9' (VISIBILITY_IGNORE)
   5456   1.9  christos 
   5457   1.9  christos    or nothing, for C style fields with public visibility.
   5458   1.1  christos 
   5459   1.7  christos    Returns 1 for success, 0 for failure.  */
   5460  1.10  christos 
   5461   1.1  christos static int
   5462   1.1  christos read_struct_fields (struct stab_field_info *fip, const char **pp,
   5463   1.1  christos 		    struct type *type, struct objfile *objfile)
   5464   1.1  christos {
   5465   1.1  christos   const char *p;
   5466   1.1  christos   struct stabs_nextfield *newobj;
   5467   1.1  christos 
   5468   1.1  christos   /* We better set p right now, in case there are no fields at all...    */
   5469   1.1  christos 
   5470   1.1  christos   p = *pp;
   5471   1.1  christos 
   5472   1.1  christos   /* Read each data member type until we find the terminating ';' at the end of
   5473   1.1  christos      the data member list, or break for some other reason such as finding the
   5474   1.1  christos      start of the member function list.  */
   5475   1.1  christos   /* Stab string for structure/union does not end with two ';' in
   5476  1.10  christos      SUN C compiler 5.3 i.e. F6U2, hence check for end of string.  */
   5477   1.6  christos 
   5478   1.5  christos   while (**pp != ';' && **pp != '\0')
   5479   1.5  christos     {
   5480   1.1  christos       STABS_CONTINUE (pp, objfile);
   5481   1.1  christos       /* Get space to record the next field's data.  */
   5482   1.1  christos       newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield);
   5483   1.1  christos 
   5484   1.1  christos       newobj->next = fip->list;
   5485  1.10  christos       fip->list = newobj;
   5486  1.10  christos 
   5487  1.10  christos       /* Get the field name.  */
   5488   1.1  christos       p = *pp;
   5489   1.1  christos 
   5490   1.1  christos       /* If is starts with CPLUS_MARKER it is a special abbreviation,
   5491   1.1  christos 	 unless the CPLUS_MARKER is followed by an underscore, in
   5492   1.1  christos 	 which case it is just the name of an anonymous type, which we
   5493   1.1  christos 	 should handle like any other type name.  */
   5494   1.1  christos 
   5495   1.1  christos       if (is_cplus_marker (p[0]) && p[1] != '_')
   5496   1.1  christos 	{
   5497  1.10  christos 	  if (!read_cpp_abbrev (fip, pp, type, objfile))
   5498  1.10  christos 	    return 0;
   5499  1.10  christos 	  continue;
   5500   1.1  christos 	}
   5501   1.1  christos 
   5502   1.1  christos       /* Look for the ':' that separates the field name from the field
   5503   1.1  christos 	 values.  Data members are delimited by a single ':', while member
   5504   1.1  christos 	 functions are delimited by a pair of ':'s.  When we hit the member
   5505   1.1  christos 	 functions (if any), terminate scan loop and return.  */
   5506   1.1  christos 
   5507   1.1  christos       while (*p != ':' && *p != '\0')
   5508   1.1  christos 	{
   5509   1.1  christos 	  p++;
   5510   1.1  christos 	}
   5511   1.1  christos       if (*p == '\0')
   5512   1.1  christos 	return 0;
   5513   1.1  christos 
   5514   1.1  christos       /* Check to see if we have hit the member functions yet.  */
   5515   1.1  christos       if (p[1] == ':')
   5516   1.1  christos 	{
   5517   1.1  christos 	  break;
   5518  1.10  christos 	}
   5519  1.10  christos       read_one_struct_field (fip, pp, p, type, objfile);
   5520   1.1  christos     }
   5521   1.1  christos   if (p[0] == ':' && p[1] == ':')
   5522   1.1  christos     {
   5523   1.1  christos       /* (the deleted) chill the list of fields: the last entry (at
   5524   1.1  christos 	 the head) is a partially constructed entry which we now
   5525   1.1  christos 	 scrub.  */
   5526   1.1  christos       fip->list = fip->list->next;
   5527   1.1  christos     }
   5528   1.1  christos   return 1;
   5529   1.1  christos }
   5530   1.1  christos /* The stabs for C++ derived classes contain baseclass information which
   5531   1.1  christos    is marked by a '!' character after the total size.  This function is
   5532   1.1  christos    called when we encounter the baseclass marker, and slurps up all the
   5533   1.1  christos    baseclass information.
   5534   1.1  christos 
   5535   1.1  christos    Immediately following the '!' marker is the number of base classes that
   5536  1.10  christos    the class is derived from, followed by information for each base class.
   5537   1.1  christos    For each base class, there are two visibility specifiers, a bit offset
   5538   1.1  christos    to the base class information within the derived class, a reference to
   5539   1.1  christos    the type for the base class, and a terminating semicolon.
   5540   1.1  christos 
   5541   1.1  christos    A typical example, with two base classes, would be "!2,020,19;0264,21;".
   5542   1.1  christos 						       ^^ ^ ^ ^  ^ ^  ^
   5543   1.1  christos 	Baseclass information marker __________________|| | | |  | |  |
   5544   1.1  christos 	Number of baseclasses __________________________| | | |  | |  |
   5545   1.1  christos 	Visibility specifiers (2) ________________________| | |  | |  |
   5546   1.1  christos 	Offset in bits from start of class _________________| |  | |  |
   5547   1.1  christos 	Type number for base class ___________________________|  | |  |
   5548   1.1  christos 	Visibility specifiers (2) _______________________________| |  |
   5549   1.1  christos 	Offset in bits from start of class ________________________|  |
   5550   1.1  christos 	Type number of base class ____________________________________|
   5551   1.9  christos 
   5552   1.9  christos   Return 1 for success, 0 for (error-type-inducing) failure.  */
   5553   1.1  christos 
   5554   1.1  christos 
   5555  1.10  christos 
   5556   1.1  christos static int
   5557   1.1  christos read_baseclasses (struct stab_field_info *fip, const char **pp,
   5558   1.1  christos 		  struct type *type, struct objfile *objfile)
   5559   1.1  christos {
   5560   1.1  christos   int i;
   5561   1.1  christos   struct stabs_nextfield *newobj;
   5562   1.1  christos 
   5563   1.1  christos   if (**pp != '!')
   5564   1.1  christos     {
   5565   1.1  christos       return 1;
   5566   1.1  christos     }
   5567   1.1  christos   else
   5568   1.1  christos     {
   5569   1.1  christos       /* Skip the '!' baseclass information marker.  */
   5570   1.1  christos       (*pp)++;
   5571   1.1  christos     }
   5572   1.1  christos 
   5573   1.1  christos   ALLOCATE_CPLUS_STRUCT_TYPE (type);
   5574   1.1  christos   {
   5575   1.1  christos     int nbits;
   5576   1.1  christos 
   5577   1.1  christos     TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0);
   5578  1.10  christos     if (nbits != 0)
   5579   1.6  christos       return 0;
   5580   1.5  christos   }
   5581   1.5  christos 
   5582  1.11  christos   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
   5583   1.1  christos     {
   5584   1.1  christos       newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield);
   5585   1.1  christos 
   5586   1.1  christos       newobj->next = fip->list;
   5587   1.1  christos       fip->list = newobj;
   5588   1.1  christos       newobj->field.set_bitsize (0);	/* This should be an unpacked
   5589   1.1  christos 					   field!  */
   5590   1.1  christos 
   5591   1.1  christos       STABS_CONTINUE (pp, objfile);
   5592  1.11  christos       switch (**pp)
   5593   1.1  christos 	{
   5594   1.1  christos 	case '0':
   5595   1.1  christos 	  /* Nothing to do.  */
   5596   1.1  christos 	  break;
   5597   1.8  christos 	case '1':
   5598   1.1  christos 	  newobj->field.set_virtual ();
   5599   1.1  christos 	  break;
   5600   1.1  christos 	default:
   5601   1.1  christos 	  /* Unknown character.  Complain and treat it as non-virtual.  */
   5602   1.1  christos 	  {
   5603  1.11  christos 	    complaint (_("Unknown virtual character `%c' for baseclass"),
   5604  1.11  christos 		       **pp);
   5605   1.1  christos 	  }
   5606   1.1  christos 	}
   5607  1.11  christos       ++(*pp);
   5608  1.11  christos 
   5609   1.1  christos       int visibility = *(*pp)++;
   5610  1.11  christos       switch (visibility)
   5611  1.11  christos 	{
   5612   1.1  christos 	case VISIBILITY_PRIVATE:
   5613   1.1  christos 	  newobj->field.set_accessibility (accessibility::PRIVATE);
   5614   1.1  christos 	  break;
   5615   1.1  christos 	case VISIBILITY_PROTECTED:
   5616   1.1  christos 	  newobj->field.set_accessibility (accessibility::PROTECTED);
   5617   1.1  christos 	  break;
   5618   1.8  christos 	case VISIBILITY_PUBLIC:
   5619  1.11  christos 	  break;
   5620   1.1  christos 	default:
   5621   1.1  christos 	  /* Bad visibility format.  Complain and treat it as
   5622   1.1  christos 	     public.  */
   5623   1.1  christos 	  {
   5624   1.1  christos 	    complaint (_("Unknown visibility `%c' for baseclass"),
   5625   1.1  christos 		       visibility);
   5626   1.1  christos 	  }
   5627   1.1  christos 	}
   5628   1.1  christos 
   5629   1.1  christos       {
   5630  1.10  christos 	int nbits;
   5631   1.1  christos 
   5632   1.1  christos 	/* The remaining value is the bit offset of the portion of the object
   5633   1.1  christos 	   corresponding to this baseclass.  Always zero in the absence of
   5634   1.1  christos 	   multiple inheritance.  */
   5635   1.1  christos 
   5636  1.10  christos 	newobj->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0));
   5637  1.10  christos 	if (nbits != 0)
   5638   1.1  christos 	  return 0;
   5639   1.9  christos       }
   5640  1.10  christos 
   5641   1.1  christos       /* The last piece of baseclass information is the type of the
   5642   1.1  christos 	 base class.  Read it, and remember it's type name as this
   5643   1.1  christos 	 field's name.  */
   5644   1.1  christos 
   5645   1.1  christos       newobj->field.set_type (read_type (pp, objfile));
   5646   1.1  christos       newobj->field.set_name (newobj->field.type ()->name ());
   5647   1.1  christos 
   5648   1.1  christos       /* Skip trailing ';' and bump count of number of fields seen.  */
   5649   1.1  christos       if (**pp == ';')
   5650   1.1  christos 	(*pp)++;
   5651   1.1  christos       else
   5652   1.1  christos 	return 0;
   5653   1.1  christos     }
   5654   1.1  christos   return 1;
   5655   1.1  christos }
   5656   1.1  christos 
   5657   1.1  christos /* The tail end of stabs for C++ classes that contain a virtual function
   5658   1.1  christos    pointer contains a tilde, a %, and a type number.
   5659   1.1  christos    The type number refers to the base class (possibly this class itself) which
   5660   1.9  christos    contains the vtable pointer for the current class.
   5661   1.9  christos 
   5662   1.1  christos    This function is called when we have parsed all the method declarations,
   5663   1.7  christos    so we can look for the vptr base class info.  */
   5664   1.1  christos 
   5665   1.1  christos static int
   5666   1.1  christos read_tilde_fields (struct stab_field_info *fip, const char **pp,
   5667   1.1  christos 		   struct type *type, struct objfile *objfile)
   5668   1.1  christos {
   5669   1.1  christos   const char *p;
   5670   1.1  christos 
   5671   1.1  christos   STABS_CONTINUE (pp, objfile);
   5672   1.1  christos 
   5673   1.1  christos   /* If we are positioned at a ';', then skip it.  */
   5674   1.1  christos   if (**pp == ';')
   5675   1.1  christos     {
   5676   1.1  christos       (*pp)++;
   5677   1.1  christos     }
   5678   1.1  christos 
   5679   1.1  christos   if (**pp == '~')
   5680   1.1  christos     {
   5681   1.1  christos       (*pp)++;
   5682   1.1  christos 
   5683   1.1  christos       if (**pp == '=' || **pp == '+' || **pp == '-')
   5684   1.1  christos 	{
   5685   1.1  christos 	  /* Obsolete flags that used to indicate the presence
   5686   1.1  christos 	     of constructors and/or destructors.  */
   5687   1.1  christos 	  (*pp)++;
   5688   1.1  christos 	}
   5689   1.1  christos 
   5690   1.1  christos       /* Read either a '%' or the final ';'.  */
   5691   1.1  christos       if (*(*pp)++ == '%')
   5692   1.1  christos 	{
   5693   1.1  christos 	  /* The next number is the type number of the base class
   5694   1.1  christos 	     (possibly our own class) which supplies the vtable for
   5695   1.1  christos 	     this class.  Parse it out, and search that class to find
   5696   1.1  christos 	     its vtable pointer, and install those into TYPE_VPTR_BASETYPE
   5697   1.1  christos 	     and TYPE_VPTR_FIELDNO.  */
   5698   1.1  christos 
   5699   1.1  christos 	  struct type *t;
   5700   1.1  christos 	  int i;
   5701   1.1  christos 
   5702   1.1  christos 	  t = read_type (pp, objfile);
   5703   1.1  christos 	  p = (*pp)++;
   5704   1.1  christos 	  while (*p != '\0' && *p != ';')
   5705   1.1  christos 	    {
   5706   1.1  christos 	      p++;
   5707   1.1  christos 	    }
   5708   1.5  christos 	  if (*p == '\0')
   5709   1.1  christos 	    {
   5710   1.1  christos 	      /* Premature end of symbol.  */
   5711   1.9  christos 	      return 0;
   5712   1.1  christos 	    }
   5713   1.1  christos 
   5714   1.1  christos 	  set_type_vptr_basetype (type, t);
   5715  1.10  christos 	  if (type == t)	/* Our own class provides vtbl ptr.  */
   5716   1.1  christos 	    {
   5717   1.1  christos 	      for (i = t->num_fields () - 1;
   5718   1.1  christos 		   i >= TYPE_N_BASECLASSES (t);
   5719   1.1  christos 		   --i)
   5720   1.5  christos 		{
   5721   1.1  christos 		  const char *name = t->field (i).name ();
   5722   1.1  christos 
   5723   1.1  christos 		  if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
   5724   1.1  christos 		      && is_cplus_marker (name[sizeof (vptr_name) - 2]))
   5725   1.8  christos 		    {
   5726   1.1  christos 		      set_type_vptr_fieldno (type, i);
   5727   1.9  christos 		      goto gotit;
   5728   1.1  christos 		    }
   5729   1.1  christos 		}
   5730   1.1  christos 	      /* Virtual function table field not found.  */
   5731   1.1  christos 	      complaint (_("virtual function table pointer "
   5732   1.5  christos 			   "not found when defining class `%s'"),
   5733   1.1  christos 			 type->name ());
   5734   1.1  christos 	      return 0;
   5735   1.1  christos 	    }
   5736   1.1  christos 	  else
   5737   1.1  christos 	    {
   5738   1.1  christos 	      set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t));
   5739   1.1  christos 	    }
   5740   1.1  christos 
   5741   1.1  christos 	gotit:
   5742   1.1  christos 	  *pp = p + 1;
   5743   1.9  christos 	}
   5744   1.1  christos     }
   5745   1.1  christos   return 1;
   5746   1.1  christos }
   5747   1.1  christos 
   5748   1.1  christos static int
   5749   1.1  christos attach_fn_fields_to_type (struct stab_field_info *fip, struct type *type)
   5750   1.1  christos {
   5751   1.1  christos   int n;
   5752   1.1  christos 
   5753   1.1  christos   for (n = TYPE_NFN_FIELDS (type);
   5754   1.1  christos        fip->fnlist != NULL;
   5755   1.1  christos        fip->fnlist = fip->fnlist->next)
   5756   1.1  christos     {
   5757   1.1  christos       --n;			/* Circumvent Sun3 compiler bug.  */
   5758   1.1  christos       TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
   5759   1.1  christos     }
   5760   1.1  christos   return 1;
   5761   1.1  christos }
   5762   1.9  christos 
   5763   1.1  christos /* Create the vector of fields, and record how big it is.
   5764   1.1  christos    We need this info to record proper virtual function table information
   5765   1.1  christos    for this class's virtual functions.  */
   5766  1.10  christos 
   5767   1.1  christos static int
   5768  1.11  christos attach_fields_to_type (struct stab_field_info *fip, struct type *type,
   5769   1.1  christos 		       struct objfile *objfile)
   5770   1.1  christos {
   5771  1.11  christos   int nfields = 0;
   5772   1.1  christos   struct stabs_nextfield *scan;
   5773   1.1  christos 
   5774   1.1  christos   /* Count up the number of fields that we have.  */
   5775  1.11  christos 
   5776   1.1  christos   for (scan = fip->list; scan != NULL; scan = scan->next)
   5777  1.11  christos     nfields++;
   5778   1.1  christos 
   5779   1.1  christos   /* Now we know how many fields there are, and whether or not there are any
   5780   1.1  christos      non-public fields.  Record the field count, allocate space for the
   5781   1.1  christos      array of fields.  */
   5782   1.1  christos 
   5783   1.1  christos   type->alloc_fields (nfields);
   5784   1.1  christos 
   5785   1.1  christos   /* Copy the saved-up fields into the field vector.  Start from the
   5786   1.9  christos      head of the list, adding to the tail of the field array, so that
   5787   1.1  christos      they end up in the same order in the array in which they were
   5788   1.1  christos      added to the list.  */
   5789   1.1  christos 
   5790   1.1  christos   while (nfields-- > 0)
   5791   1.1  christos     {
   5792   1.1  christos       type->field (nfields) = fip->list->field;
   5793   1.1  christos       fip->list = fip->list->next;
   5794   1.1  christos     }
   5795   1.1  christos   return 1;
   5796   1.1  christos }
   5797   1.1  christos 
   5798   1.1  christos 
   5799   1.1  christos /* Complain that the compiler has emitted more than one definition for the
   5800   1.1  christos    structure type TYPE.  */
   5801   1.9  christos static void
   5802   1.1  christos complain_about_struct_wipeout (struct type *type)
   5803   1.9  christos {
   5804   1.9  christos   const char *name = "";
   5805  1.10  christos   const char *kind = "";
   5806  1.10  christos 
   5807  1.10  christos   if (type->name ())
   5808  1.10  christos     {
   5809  1.10  christos       name = type->name ();
   5810  1.10  christos       switch (type->code ())
   5811   1.1  christos 	{
   5812   1.1  christos 	case TYPE_CODE_STRUCT: kind = "struct "; break;
   5813   1.1  christos 	case TYPE_CODE_UNION:  kind = "union ";  break;
   5814   1.1  christos 	case TYPE_CODE_ENUM:   kind = "enum ";   break;
   5815   1.1  christos 	default: kind = "";
   5816   1.1  christos 	}
   5817   1.1  christos     }
   5818   1.8  christos   else
   5819   1.1  christos     {
   5820   1.1  christos       name = "<unknown>";
   5821   1.1  christos       kind = "";
   5822   1.1  christos     }
   5823   1.1  christos 
   5824   1.1  christos   complaint (_("struct/union type gets multiply defined: %s%s"), kind, name);
   5825   1.1  christos }
   5826   1.1  christos 
   5827   1.1  christos /* Set the length for all variants of a same main_type, which are
   5828   1.1  christos    connected in the closed chain.
   5829  1.10  christos 
   5830  1.10  christos    This is something that needs to be done when a type is defined *after*
   5831   1.1  christos    some cross references to this type have already been read.  Consider
   5832   1.1  christos    for instance the following scenario where we have the following two
   5833   1.1  christos    stabs entries:
   5834   1.1  christos 
   5835   1.1  christos 	.stabs  "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
   5836   1.1  christos 	.stabs  "dummy:T(0,23)=s16x:(0,1),0,3[...]"
   5837   1.1  christos 
   5838   1.1  christos    A stubbed version of type dummy is created while processing the first
   5839   1.1  christos    stabs entry.  The length of that type is initially set to zero, since
   5840   1.1  christos    it is unknown at this point.  Also, a "constant" variation of type
   5841   1.1  christos    "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
   5842   1.1  christos    the stabs line).
   5843   1.1  christos 
   5844   1.1  christos    The second stabs entry allows us to replace the stubbed definition
   5845   1.1  christos    with the real definition.  However, we still need to adjust the length
   5846   1.1  christos    of the "constant" variation of that type, as its length was left
   5847   1.1  christos    untouched during the main type replacement...  */
   5848   1.1  christos 
   5849   1.1  christos static void
   5850  1.10  christos set_length_in_type_chain (struct type *type)
   5851  1.10  christos {
   5852   1.1  christos   struct type *ntype = TYPE_CHAIN (type);
   5853  1.10  christos 
   5854   1.1  christos   while (ntype != type)
   5855   1.1  christos     {
   5856   1.1  christos       if (ntype->length () == 0)
   5857   1.1  christos 	ntype->set_length (type->length ());
   5858   1.1  christos       else
   5859   1.1  christos 	complain_about_struct_wipeout (ntype);
   5860   1.1  christos       ntype = TYPE_CHAIN (ntype);
   5861   1.1  christos     }
   5862   1.1  christos }
   5863   1.1  christos 
   5864   1.1  christos /* Read the description of a structure (or union type) and return an object
   5865   1.1  christos    describing the type.
   5866   1.1  christos 
   5867   1.1  christos    PP points to a character pointer that points to the next unconsumed token
   5868   1.1  christos    in the stabs string.  For example, given stabs "A:T4=s4a:1,0,32;;",
   5869   1.1  christos    *PP will point to "4a:1,0,32;;".
   5870   1.1  christos 
   5871   1.1  christos    TYPE points to an incomplete type that needs to be filled in.
   5872   1.1  christos 
   5873   1.7  christos    OBJFILE points to the current objfile from which the stabs information is
   5874  1.10  christos    being read.  (Note that it is redundant in that TYPE also contains a pointer
   5875   1.1  christos    to this same objfile, so it might be a good idea to eliminate it.  FIXME).
   5876   1.9  christos  */
   5877   1.1  christos 
   5878   1.1  christos static struct type *
   5879   1.1  christos read_struct_type (const char **pp, struct type *type, enum type_code type_code,
   5880   1.1  christos 		  struct objfile *objfile)
   5881   1.1  christos {
   5882   1.1  christos   struct stab_field_info fi;
   5883   1.1  christos 
   5884   1.1  christos   /* When describing struct/union/class types in stabs, G++ always drops
   5885   1.1  christos      all qualifications from the name.  So if you've got:
   5886   1.1  christos        struct A { ... struct B { ... }; ... };
   5887   1.1  christos      then G++ will emit stabs for `struct A::B' that call it simply
   5888   1.1  christos      `struct B'.  Obviously, if you've got a real top-level definition for
   5889   1.9  christos      `struct B', or other nested definitions, this is going to cause
   5890  1.10  christos      problems.
   5891   1.1  christos 
   5892   1.1  christos      Obviously, GDB can't fix this by itself, but it can at least avoid
   5893   1.1  christos      scribbling on existing structure type objects when new definitions
   5894   1.1  christos      appear.  */
   5895   1.1  christos   if (! (type->code () == TYPE_CODE_UNDEF
   5896   1.1  christos 	 || type->is_stub ()))
   5897   1.1  christos     {
   5898   1.1  christos       complain_about_struct_wipeout (type);
   5899   1.9  christos 
   5900  1.10  christos       /* It's probably best to return the type unchanged.  */
   5901   1.1  christos       return type;
   5902   1.1  christos     }
   5903   1.1  christos 
   5904   1.1  christos   INIT_CPLUS_SPECIFIC (type);
   5905   1.1  christos   type->set_code (type_code);
   5906   1.1  christos   type->set_is_stub (false);
   5907  1.10  christos 
   5908   1.1  christos   /* First comes the total size in bytes.  */
   5909   1.9  christos 
   5910   1.1  christos   {
   5911   1.1  christos     int nbits;
   5912   1.1  christos 
   5913   1.1  christos     type->set_length (read_huge_number (pp, 0, &nbits, 0));
   5914   1.1  christos     if (nbits != 0)
   5915   1.1  christos       return error_type (pp, objfile);
   5916   1.1  christos     set_length_in_type_chain (type);
   5917   1.1  christos   }
   5918   1.1  christos 
   5919   1.1  christos   /* Now read the baseclasses, if any, read the regular C struct or C++
   5920   1.1  christos      class member fields, attach the fields to the type, read the C++
   5921   1.1  christos      member functions, attach them to the type, and then read any tilde
   5922   1.1  christos      field (baseclass specifier for the class holding the main vtable).  */
   5923   1.1  christos 
   5924   1.1  christos   if (!read_baseclasses (&fi, pp, type, objfile)
   5925   1.1  christos       || !read_struct_fields (&fi, pp, type, objfile)
   5926   1.1  christos       || !attach_fields_to_type (&fi, type, objfile)
   5927   1.1  christos       || !read_member_functions (&fi, pp, type, objfile)
   5928   1.1  christos       || !attach_fn_fields_to_type (&fi, type)
   5929   1.1  christos       || !read_tilde_fields (&fi, pp, type, objfile))
   5930   1.1  christos     {
   5931   1.1  christos       type = error_type (pp, objfile);
   5932   1.1  christos     }
   5933   1.1  christos 
   5934   1.1  christos   return (type);
   5935   1.1  christos }
   5936   1.1  christos 
   5937   1.7  christos /* Read a definition of an array type,
   5938   1.1  christos    and create and return a suitable type object.
   5939   1.1  christos    Also creates a range type which represents the bounds of that
   5940   1.1  christos    array.  */
   5941   1.1  christos 
   5942   1.1  christos static struct type *
   5943   1.1  christos read_array_type (const char **pp, struct type *type,
   5944   1.1  christos 		 struct objfile *objfile)
   5945   1.1  christos {
   5946   1.1  christos   struct type *index_type, *element_type, *range_type;
   5947   1.1  christos   int lower, upper;
   5948   1.1  christos   int adjustable = 0;
   5949   1.1  christos   int nbits;
   5950   1.1  christos 
   5951   1.1  christos   /* Format of an array type:
   5952   1.1  christos      "ar<index type>;lower;upper;<array_contents_type>".
   5953   1.1  christos      OS9000: "arlower,upper;<array_contents_type>".
   5954   1.1  christos 
   5955   1.1  christos      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
   5956   1.1  christos      for these, produce a type like float[][].  */
   5957   1.1  christos 
   5958   1.1  christos     {
   5959   1.1  christos       index_type = read_type (pp, objfile);
   5960   1.1  christos       if (**pp != ';')
   5961   1.1  christos 	/* Improper format of array type decl.  */
   5962   1.1  christos 	return error_type (pp, objfile);
   5963   1.1  christos       ++*pp;
   5964   1.1  christos     }
   5965   1.1  christos 
   5966   1.1  christos   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
   5967   1.1  christos     {
   5968   1.1  christos       (*pp)++;
   5969   1.1  christos       adjustable = 1;
   5970   1.1  christos     }
   5971   1.1  christos   lower = read_huge_number (pp, ';', &nbits, 0);
   5972   1.1  christos 
   5973   1.1  christos   if (nbits != 0)
   5974   1.1  christos     return error_type (pp, objfile);
   5975   1.1  christos 
   5976   1.1  christos   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
   5977   1.1  christos     {
   5978   1.1  christos       (*pp)++;
   5979   1.1  christos       adjustable = 1;
   5980   1.1  christos     }
   5981   1.1  christos   upper = read_huge_number (pp, ';', &nbits, 0);
   5982   1.1  christos   if (nbits != 0)
   5983   1.1  christos     return error_type (pp, objfile);
   5984   1.1  christos 
   5985   1.1  christos   element_type = read_type (pp, objfile);
   5986   1.1  christos 
   5987  1.11  christos   if (adjustable)
   5988   1.1  christos     {
   5989  1.11  christos       lower = 0;
   5990  1.11  christos       upper = -1;
   5991  1.11  christos     }
   5992   1.1  christos 
   5993   1.1  christos   type_allocator alloc (objfile, get_current_subfile ()->language);
   5994   1.1  christos   range_type =
   5995   1.1  christos     create_static_range_type (alloc, index_type, lower, upper);
   5996   1.1  christos   type_allocator smash_alloc (type, type_allocator::SMASH);
   5997   1.1  christos   type = create_array_type (smash_alloc, element_type, range_type);
   5998   1.1  christos 
   5999   1.1  christos   return type;
   6000   1.1  christos }
   6001   1.1  christos 
   6002   1.7  christos 
   6003   1.1  christos /* Read a definition of an enumeration type,
   6004   1.1  christos    and create and return a suitable type object.
   6005   1.9  christos    Also defines the symbols that represent the values of the type.  */
   6006   1.7  christos 
   6007   1.1  christos static struct type *
   6008   1.1  christos read_enum_type (const char **pp, struct type *type,
   6009   1.1  christos 		struct objfile *objfile)
   6010   1.1  christos {
   6011   1.1  christos   struct gdbarch *gdbarch = objfile->arch ();
   6012   1.1  christos   const char *p;
   6013   1.1  christos   char *name;
   6014   1.1  christos   long n;
   6015   1.1  christos   struct symbol *sym;
   6016   1.1  christos   int nsyms = 0;
   6017   1.1  christos   struct pending **symlist;
   6018   1.1  christos   struct pending *osyms, *syms;
   6019   1.1  christos   int o_nsyms;
   6020   1.1  christos   int nbits;
   6021   1.1  christos   int unsigned_enum = 1;
   6022   1.8  christos 
   6023   1.1  christos #if 0
   6024   1.1  christos   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
   6025   1.8  christos      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
   6026   1.1  christos      to do?  For now, force all enum values to file scope.  */
   6027   1.1  christos   if (within_function)
   6028   1.1  christos     symlist = get_local_symbols ();
   6029   1.1  christos   else
   6030   1.1  christos #endif
   6031   1.1  christos     symlist = get_file_symbols ();
   6032   1.1  christos   osyms = *symlist;
   6033   1.1  christos   o_nsyms = osyms ? osyms->nsyms : 0;
   6034   1.1  christos 
   6035   1.1  christos   /* The aix4 compiler emits an extra field before the enum members;
   6036   1.1  christos      my guess is it's a type of some sort.  Just ignore it.  */
   6037   1.1  christos   if (**pp == '-')
   6038   1.1  christos     {
   6039   1.1  christos       /* Skip over the type.  */
   6040   1.1  christos       while (**pp != ':')
   6041   1.1  christos 	(*pp)++;
   6042   1.1  christos 
   6043   1.1  christos       /* Skip over the colon.  */
   6044   1.1  christos       (*pp)++;
   6045   1.1  christos     }
   6046   1.1  christos 
   6047   1.1  christos   /* Read the value-names and their values.
   6048   1.1  christos      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
   6049   1.1  christos      A semicolon or comma instead of a NAME means the end.  */
   6050   1.9  christos   while (**pp && **pp != ';' && **pp != ',')
   6051   1.1  christos     {
   6052   1.1  christos       STABS_CONTINUE (pp, objfile);
   6053   1.1  christos       p = *pp;
   6054   1.1  christos       while (*p != ':')
   6055   1.1  christos 	p++;
   6056   1.9  christos       name = obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp);
   6057   1.9  christos       *pp = p + 1;
   6058   1.9  christos       n = read_huge_number (pp, ',', &nbits, 0);
   6059   1.9  christos       if (nbits != 0)
   6060  1.10  christos 	return error_type (pp, objfile);
   6061  1.10  christos 
   6062  1.10  christos       sym = new (&objfile->objfile_obstack) symbol;
   6063   1.1  christos       sym->set_linkage_name (name);
   6064   1.1  christos       sym->set_language (get_current_subfile ()->language,
   6065   1.1  christos 			 &objfile->objfile_obstack);
   6066   1.1  christos       sym->set_aclass_index (LOC_CONST);
   6067   1.1  christos       sym->set_domain (VAR_DOMAIN);
   6068   1.1  christos       sym->set_value_longest (n);
   6069   1.1  christos       if (n < 0)
   6070   1.1  christos 	unsigned_enum = 0;
   6071   1.1  christos       add_symbol_to_list (sym, symlist);
   6072   1.1  christos       nsyms++;
   6073   1.1  christos     }
   6074  1.10  christos 
   6075   1.1  christos   if (**pp == ';')
   6076   1.9  christos     (*pp)++;			/* Skip the semicolon.  */
   6077  1.10  christos 
   6078   1.1  christos   /* Now fill in the fields of the type-structure.  */
   6079  1.10  christos 
   6080  1.11  christos   type->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT);
   6081   1.1  christos   set_length_in_type_chain (type);
   6082   1.1  christos   type->set_code (TYPE_CODE_ENUM);
   6083   1.1  christos   type->set_is_stub (false);
   6084   1.1  christos   if (unsigned_enum)
   6085   1.1  christos     type->set_is_unsigned (true);
   6086   1.1  christos   type->alloc_fields (nsyms);
   6087   1.1  christos 
   6088   1.1  christos   /* Find the symbols for the values and put them into the type.
   6089   1.1  christos      The symbols can be found in the symlist that we put them on
   6090   1.1  christos      to cause them to be defined.  osyms contains the old value
   6091   1.1  christos      of that symlist; everything up to there was defined by us.  */
   6092   1.1  christos   /* Note that we preserve the order of the enum constants, so
   6093   1.1  christos      that in something like "enum {FOO, LAST_THING=FOO}" we print
   6094   1.1  christos      FOO, not LAST_THING.  */
   6095   1.1  christos 
   6096   1.1  christos   for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
   6097   1.1  christos     {
   6098   1.1  christos       int last = syms == osyms ? o_nsyms : 0;
   6099  1.10  christos       int j = syms->nsyms;
   6100  1.10  christos 
   6101  1.10  christos       for (; --j >= last; --n)
   6102  1.11  christos 	{
   6103   1.1  christos 	  struct symbol *xsym = syms->symbol[j];
   6104   1.1  christos 
   6105   1.1  christos 	  xsym->set_type (type);
   6106   1.1  christos 	  type->field (n).set_name (xsym->linkage_name ());
   6107   1.1  christos 	  type->field (n).set_loc_enumval (xsym->value_longest ());
   6108   1.1  christos 	  type->field (n).set_bitsize (0);
   6109   1.1  christos 	}
   6110   1.1  christos       if (syms == osyms)
   6111   1.1  christos 	break;
   6112   1.1  christos     }
   6113   1.1  christos 
   6114   1.1  christos   return type;
   6115   1.1  christos }
   6116   1.1  christos 
   6117   1.1  christos /* Sun's ACC uses a somewhat saner method for specifying the builtin
   6118   1.1  christos    typedefs in every file (for int, long, etc):
   6119   1.1  christos 
   6120   1.1  christos    type = b <signed> <width> <format type>; <offset>; <nbits>
   6121   1.1  christos    signed = u or s.
   6122   1.1  christos    optional format type = c or b for char or boolean.
   6123   1.1  christos    offset = offset from high order bit to start bit of type.
   6124   1.1  christos    width is # bytes in object of this type, nbits is # bits in type.
   6125   1.7  christos 
   6126   1.1  christos    The width/offset stuff appears to be for small objects stored in
   6127   1.1  christos    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
   6128   1.1  christos    FIXME.  */
   6129   1.7  christos 
   6130   1.7  christos static struct type *
   6131   1.1  christos read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile)
   6132   1.1  christos {
   6133   1.1  christos   int type_bits;
   6134   1.1  christos   int nbits;
   6135   1.7  christos   int unsigned_type;
   6136   1.1  christos   int boolean_type = 0;
   6137   1.1  christos 
   6138   1.7  christos   switch (**pp)
   6139   1.1  christos     {
   6140   1.1  christos     case 's':
   6141   1.1  christos       unsigned_type = 0;
   6142   1.1  christos       break;
   6143   1.1  christos     case 'u':
   6144   1.1  christos       unsigned_type = 1;
   6145   1.1  christos       break;
   6146   1.1  christos     default:
   6147   1.1  christos       return error_type (pp, objfile);
   6148   1.1  christos     }
   6149   1.1  christos   (*pp)++;
   6150   1.1  christos 
   6151   1.1  christos   /* For some odd reason, all forms of char put a c here.  This is strange
   6152   1.1  christos      because no other type has this honor.  We can safely ignore this because
   6153   1.1  christos      we actually determine 'char'acterness by the number of bits specified in
   6154   1.1  christos      the descriptor.
   6155   1.7  christos      Boolean forms, e.g Fortran logical*X, put a b here.  */
   6156   1.1  christos 
   6157   1.1  christos   if (**pp == 'c')
   6158   1.1  christos     (*pp)++;
   6159   1.1  christos   else if (**pp == 'b')
   6160   1.1  christos     {
   6161   1.1  christos       boolean_type = 1;
   6162   1.1  christos       (*pp)++;
   6163   1.1  christos     }
   6164   1.1  christos 
   6165   1.1  christos   /* The first number appears to be the number of bytes occupied
   6166   1.1  christos      by this type, except that unsigned short is 4 instead of 2.
   6167   1.1  christos      Since this information is redundant with the third number,
   6168   1.1  christos      we will ignore it.  */
   6169   1.1  christos   read_huge_number (pp, ';', &nbits, 0);
   6170   1.1  christos   if (nbits != 0)
   6171   1.1  christos     return error_type (pp, objfile);
   6172   1.1  christos 
   6173   1.1  christos   /* The second number is always 0, so ignore it too.  */
   6174   1.1  christos   read_huge_number (pp, ';', &nbits, 0);
   6175   1.1  christos   if (nbits != 0)
   6176   1.1  christos     return error_type (pp, objfile);
   6177   1.1  christos 
   6178   1.1  christos   /* The third number is the number of bits for this type.  */
   6179   1.1  christos   type_bits = read_huge_number (pp, 0, &nbits, 0);
   6180   1.1  christos   if (nbits != 0)
   6181   1.1  christos     return error_type (pp, objfile);
   6182   1.1  christos   /* The type *should* end with a semicolon.  If it are embedded
   6183   1.1  christos      in a larger type the semicolon may be the only way to know where
   6184   1.1  christos      the type ends.  If this type is at the end of the stabstring we
   6185  1.11  christos      can deal with the omitted semicolon (but we don't have to like
   6186   1.1  christos      it).  Don't bother to complain(), Sun's compiler omits the semicolon
   6187   1.7  christos      for "void".  */
   6188  1.11  christos   if (**pp == ';')
   6189  1.11  christos     ++(*pp);
   6190   1.7  christos 
   6191  1.10  christos   type_allocator alloc (objfile, get_current_subfile ()->language);
   6192  1.10  christos   if (type_bits == 0)
   6193   1.7  christos     {
   6194   1.7  christos       struct type *type = alloc.new_type (TYPE_CODE_VOID,
   6195   1.7  christos 					  TARGET_CHAR_BIT, nullptr);
   6196   1.7  christos       if (unsigned_type)
   6197  1.11  christos 	type->set_is_unsigned (true);
   6198   1.1  christos 
   6199  1.11  christos       return type;
   6200   1.1  christos     }
   6201   1.1  christos 
   6202   1.1  christos   if (boolean_type)
   6203   1.7  christos     return init_boolean_type (alloc, type_bits, unsigned_type, NULL);
   6204   1.7  christos   else
   6205   1.1  christos     return init_integer_type (alloc, type_bits, unsigned_type, NULL);
   6206   1.1  christos }
   6207   1.1  christos 
   6208   1.1  christos static struct type *
   6209   1.1  christos read_sun_floating_type (const char **pp, int typenums[2],
   6210   1.1  christos 			struct objfile *objfile)
   6211   1.1  christos {
   6212   1.1  christos   int nbits;
   6213   1.1  christos   int details;
   6214   1.1  christos   int nbytes;
   6215   1.1  christos   struct type *rettype;
   6216   1.1  christos 
   6217   1.1  christos   /* The first number has more details about the type, for example
   6218   1.1  christos      FN_COMPLEX.  */
   6219   1.1  christos   details = read_huge_number (pp, ';', &nbits, 0);
   6220   1.1  christos   if (nbits != 0)
   6221   1.1  christos     return error_type (pp, objfile);
   6222   1.7  christos 
   6223   1.7  christos   /* The second number is the number of bytes occupied by this type.  */
   6224   1.1  christos   nbytes = read_huge_number (pp, ';', &nbits, 0);
   6225   1.1  christos   if (nbits != 0)
   6226   1.1  christos     return error_type (pp, objfile);
   6227   1.7  christos 
   6228   1.9  christos   nbits = nbytes * TARGET_CHAR_BIT;
   6229   1.1  christos 
   6230   1.1  christos   if (details == NF_COMPLEX || details == NF_COMPLEX16
   6231   1.7  christos       || details == NF_COMPLEX32)
   6232   1.1  christos     {
   6233   1.1  christos       rettype = dbx_init_float_type (objfile, nbits / 2);
   6234   1.1  christos       return init_complex_type (NULL, rettype);
   6235   1.1  christos     }
   6236   1.1  christos 
   6237   1.1  christos   return dbx_init_float_type (objfile, nbits);
   6238   1.1  christos }
   6239   1.1  christos 
   6240   1.1  christos /* Read a number from the string pointed to by *PP.
   6241   1.1  christos    The value of *PP is advanced over the number.
   6242   1.1  christos    If END is nonzero, the character that ends the
   6243   1.1  christos    number must match END, or an error happens;
   6244   1.1  christos    and that character is skipped if it does match.
   6245   1.1  christos    If END is zero, *PP is left pointing to that character.
   6246   1.1  christos 
   6247   1.1  christos    If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
   6248   1.1  christos    the number is represented in an octal representation, assume that
   6249   1.1  christos    it is represented in a 2's complement representation with a size of
   6250   1.1  christos    TWOS_COMPLEMENT_BITS.
   6251   1.1  christos 
   6252   1.7  christos    If the number fits in a long, set *BITS to 0 and return the value.
   6253   1.7  christos    If not, set *BITS to be the number of bits in the number and return 0.
   6254   1.1  christos 
   6255   1.7  christos    If encounter garbage, set *BITS to -1 and return 0.  */
   6256   1.1  christos 
   6257   1.1  christos static long
   6258   1.1  christos read_huge_number (const char **pp, int end, int *bits,
   6259   1.1  christos 		  int twos_complement_bits)
   6260   1.1  christos {
   6261   1.1  christos   const char *p = *pp;
   6262   1.1  christos   int sign = 1;
   6263   1.1  christos   int sign_bit = 0;
   6264   1.1  christos   long n = 0;
   6265   1.1  christos   int radix = 10;
   6266   1.1  christos   char overflow = 0;
   6267   1.1  christos   int nbits = 0;
   6268   1.1  christos   int c;
   6269   1.1  christos   long upper_limit;
   6270   1.1  christos   int twos_complement_representation = 0;
   6271   1.1  christos 
   6272   1.1  christos   if (*p == '-')
   6273   1.1  christos     {
   6274   1.1  christos       sign = -1;
   6275   1.1  christos       p++;
   6276   1.1  christos     }
   6277   1.1  christos 
   6278   1.1  christos   /* Leading zero means octal.  GCC uses this to output values larger
   6279   1.1  christos      than an int (because that would be hard in decimal).  */
   6280   1.1  christos   if (*p == '0')
   6281   1.1  christos     {
   6282   1.1  christos       radix = 8;
   6283   1.1  christos       p++;
   6284   1.1  christos     }
   6285   1.1  christos 
   6286   1.1  christos   /* Skip extra zeros.  */
   6287   1.1  christos   while (*p == '0')
   6288   1.1  christos     p++;
   6289   1.1  christos 
   6290   1.7  christos   if (sign > 0 && radix == 8 && twos_complement_bits > 0)
   6291   1.1  christos     {
   6292   1.1  christos       /* Octal, possibly signed.  Check if we have enough chars for a
   6293   1.1  christos 	 negative number.  */
   6294   1.1  christos 
   6295   1.1  christos       size_t len;
   6296   1.1  christos       const char *p1 = p;
   6297   1.1  christos 
   6298   1.1  christos       while ((c = *p1) >= '0' && c < '8')
   6299   1.1  christos 	p1++;
   6300   1.1  christos 
   6301   1.9  christos       len = p1 - p;
   6302   1.1  christos       if (len > twos_complement_bits / 3
   6303   1.1  christos 	  || (twos_complement_bits % 3 == 0
   6304   1.1  christos 	      && len == twos_complement_bits / 3))
   6305   1.1  christos 	{
   6306   1.1  christos 	  /* Ok, we have enough characters for a signed value, check
   6307   1.1  christos 	     for signedness by testing if the sign bit is set.  */
   6308   1.1  christos 	  sign_bit = (twos_complement_bits % 3 + 2) % 3;
   6309   1.1  christos 	  c = *p - '0';
   6310   1.1  christos 	  if (c & (1 << sign_bit))
   6311   1.1  christos 	    {
   6312   1.1  christos 	      /* Definitely signed.  */
   6313   1.1  christos 	      twos_complement_representation = 1;
   6314   1.1  christos 	      sign = -1;
   6315   1.1  christos 	    }
   6316   1.1  christos 	}
   6317   1.1  christos     }
   6318  1.10  christos 
   6319  1.10  christos   upper_limit = LONG_MAX / radix;
   6320  1.10  christos 
   6321   1.1  christos   while ((c = *p++) >= '0' && c < ('0' + radix))
   6322   1.1  christos     {
   6323   1.1  christos       if (n <= upper_limit)
   6324   1.1  christos 	{
   6325   1.1  christos 	  if (twos_complement_representation)
   6326   1.1  christos 	    {
   6327   1.1  christos 	      /* Octal, signed, twos complement representation.  In
   6328   1.1  christos 		 this case, n is the corresponding absolute value.  */
   6329  1.10  christos 	      if (n == 0)
   6330  1.10  christos 		{
   6331  1.10  christos 		  long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
   6332  1.10  christos 
   6333  1.10  christos 		  n = -sn;
   6334  1.10  christos 		}
   6335  1.10  christos 	      else
   6336  1.10  christos 		{
   6337  1.10  christos 		  n *= radix;
   6338  1.10  christos 		  n -= c - '0';
   6339  1.10  christos 		}
   6340  1.10  christos 	    }
   6341  1.10  christos 	  else
   6342   1.1  christos 	    {
   6343  1.10  christos 	      /* unsigned representation */
   6344   1.1  christos 	      n *= radix;
   6345   1.1  christos 	      n += c - '0';		/* FIXME this overflows anyway.  */
   6346  1.10  christos 	    }
   6347   1.1  christos 	}
   6348   1.1  christos       else
   6349   1.1  christos 	overflow = 1;
   6350   1.1  christos 
   6351   1.1  christos       /* This depends on large values being output in octal, which is
   6352   1.1  christos 	 what GCC does.  */
   6353   1.1  christos       if (radix == 8)
   6354   1.1  christos 	{
   6355   1.1  christos 	  if (nbits == 0)
   6356   1.1  christos 	    {
   6357   1.1  christos 	      if (c == '0')
   6358   1.1  christos 		/* Ignore leading zeroes.  */
   6359   1.1  christos 		;
   6360   1.1  christos 	      else if (c == '1')
   6361   1.1  christos 		nbits = 1;
   6362   1.1  christos 	      else if (c == '2' || c == '3')
   6363   1.1  christos 		nbits = 2;
   6364   1.1  christos 	      else
   6365   1.1  christos 		nbits = 3;
   6366   1.1  christos 	    }
   6367   1.1  christos 	  else
   6368   1.1  christos 	    nbits += 3;
   6369   1.1  christos 	}
   6370   1.1  christos     }
   6371   1.1  christos   if (end)
   6372   1.1  christos     {
   6373   1.1  christos       if (c && c != end)
   6374   1.1  christos 	{
   6375   1.1  christos 	  if (bits != NULL)
   6376   1.1  christos 	    *bits = -1;
   6377   1.1  christos 	  return 0;
   6378   1.1  christos 	}
   6379   1.1  christos     }
   6380   1.1  christos   else
   6381   1.1  christos     --p;
   6382   1.1  christos 
   6383   1.1  christos   if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
   6384   1.1  christos     {
   6385   1.1  christos       /* We were supposed to parse a number with maximum
   6386   1.1  christos 	 TWOS_COMPLEMENT_BITS bits, but something went wrong.  */
   6387   1.1  christos       if (bits != NULL)
   6388   1.1  christos 	*bits = -1;
   6389   1.1  christos       return 0;
   6390   1.1  christos     }
   6391   1.1  christos 
   6392   1.1  christos   *pp = p;
   6393   1.1  christos   if (overflow)
   6394   1.1  christos     {
   6395   1.1  christos       if (nbits == 0)
   6396   1.1  christos 	{
   6397   1.1  christos 	  /* Large decimal constants are an error (because it is hard to
   6398   1.1  christos 	     count how many bits are in them).  */
   6399  1.12  christos 	  if (bits != NULL)
   6400  1.10  christos 	    *bits = -1;
   6401   1.1  christos 	  return 0;
   6402   1.1  christos 	}
   6403   1.1  christos 
   6404   1.1  christos       /* -0x7f is the same as 0x80.  So deal with it by adding one to
   6405   1.1  christos 	 the number of bits.  Two's complement representation octals
   6406   1.1  christos 	 can't have a '-' in front.  */
   6407   1.1  christos       if (sign == -1 && !twos_complement_representation)
   6408   1.1  christos 	++nbits;
   6409   1.1  christos       if (bits)
   6410   1.1  christos 	*bits = nbits;
   6411   1.1  christos     }
   6412   1.1  christos   else
   6413   1.1  christos     {
   6414   1.1  christos       if (bits)
   6415   1.1  christos 	*bits = 0;
   6416   1.1  christos       return n * sign;
   6417   1.7  christos     }
   6418  1.10  christos   /* It's *BITS which has the interesting information.  */
   6419   1.1  christos   return 0;
   6420   1.9  christos }
   6421   1.7  christos 
   6422   1.1  christos static struct type *
   6423   1.1  christos read_range_type (const char **pp, int typenums[2], int type_size,
   6424   1.1  christos 		 struct objfile *objfile)
   6425   1.1  christos {
   6426   1.1  christos   struct gdbarch *gdbarch = objfile->arch ();
   6427   1.1  christos   const char *orig_pp = *pp;
   6428   1.1  christos   int rangenums[2];
   6429   1.1  christos   long n2, n3;
   6430   1.1  christos   int n2bits, n3bits;
   6431   1.1  christos   int self_subrange;
   6432   1.1  christos   struct type *result_type;
   6433   1.1  christos   struct type *index_type = NULL;
   6434   1.1  christos 
   6435   1.1  christos   /* First comes a type we are a subrange of.
   6436   1.1  christos      In C it is usually 0, 1 or the type being defined.  */
   6437   1.1  christos   if (read_type_number (pp, rangenums) != 0)
   6438   1.1  christos     return error_type (pp, objfile);
   6439   1.1  christos   self_subrange = (rangenums[0] == typenums[0] &&
   6440   1.1  christos 		   rangenums[1] == typenums[1]);
   6441   1.1  christos 
   6442   1.1  christos   if (**pp == '=')
   6443   1.1  christos     {
   6444   1.1  christos       *pp = orig_pp;
   6445   1.1  christos       index_type = read_type (pp, objfile);
   6446   1.1  christos     }
   6447   1.1  christos 
   6448   1.1  christos   /* A semicolon should now follow; skip it.  */
   6449   1.1  christos   if (**pp == ';')
   6450   1.1  christos     (*pp)++;
   6451   1.1  christos 
   6452   1.1  christos   /* The remaining two operands are usually lower and upper bounds
   6453   1.1  christos      of the range.  But in some special cases they mean something else.  */
   6454  1.11  christos   n2 = read_huge_number (pp, ';', &n2bits, type_size);
   6455  1.11  christos   n3 = read_huge_number (pp, ';', &n3bits, type_size);
   6456   1.1  christos 
   6457   1.1  christos   if (n2bits == -1 || n3bits == -1)
   6458   1.1  christos     return error_type (pp, objfile);
   6459   1.1  christos 
   6460   1.1  christos   type_allocator alloc (objfile, get_current_subfile ()->language);
   6461   1.1  christos 
   6462   1.1  christos   if (index_type)
   6463   1.1  christos     goto handle_true_range;
   6464   1.1  christos 
   6465   1.1  christos   /* If limits are huge, must be large integral type.  */
   6466   1.1  christos   if (n2bits != 0 || n3bits != 0)
   6467   1.1  christos     {
   6468  1.10  christos       char got_signed = 0;
   6469  1.10  christos       char got_unsigned = 0;
   6470   1.1  christos       /* Number of bits in the type.  */
   6471  1.10  christos       int nbits = 0;
   6472  1.10  christos 
   6473  1.10  christos       /* If a type size attribute has been specified, the bounds of
   6474  1.10  christos 	 the range should fit in this size.  If the lower bounds needs
   6475  1.10  christos 	 more bits than the upper bound, then the type is signed.  */
   6476  1.10  christos       if (n2bits <= type_size && n3bits <= type_size)
   6477  1.10  christos 	{
   6478   1.1  christos 	  if (n2bits == type_size && n2bits > n3bits)
   6479   1.1  christos 	    got_signed = 1;
   6480   1.1  christos 	  else
   6481   1.1  christos 	    got_unsigned = 1;
   6482   1.1  christos 	  nbits = type_size;
   6483   1.1  christos 	}
   6484   1.1  christos       /* Range from 0 to <large number> is an unsigned large integral type.  */
   6485  1.10  christos       else if ((n2bits == 0 && n2 == 0) && n3bits != 0)
   6486  1.10  christos 	{
   6487   1.1  christos 	  got_unsigned = 1;
   6488   1.1  christos 	  nbits = n3bits;
   6489   1.1  christos 	}
   6490   1.1  christos       /* Range from <large number> to <large number>-1 is a large signed
   6491   1.1  christos 	 integral type.  Take care of the case where <large number> doesn't
   6492   1.1  christos 	 fit in a long but <large number>-1 does.  */
   6493   1.1  christos       else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
   6494   1.1  christos 	       || (n2bits != 0 && n3bits == 0
   6495   1.1  christos 		   && (n2bits == sizeof (long) * HOST_CHAR_BIT)
   6496   1.1  christos 		   && n3 == LONG_MAX))
   6497  1.11  christos 	{
   6498   1.1  christos 	  got_signed = 1;
   6499   1.1  christos 	  nbits = n2bits;
   6500   1.1  christos 	}
   6501   1.1  christos 
   6502   1.1  christos       if (got_signed || got_unsigned)
   6503   1.1  christos 	return init_integer_type (alloc, nbits, got_unsigned, NULL);
   6504  1.11  christos       else
   6505   1.1  christos 	return error_type (pp, objfile);
   6506   1.1  christos     }
   6507   1.1  christos 
   6508   1.1  christos   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
   6509   1.1  christos   if (self_subrange && n2 == 0 && n3 == 0)
   6510   1.1  christos     return alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, nullptr);
   6511   1.1  christos 
   6512   1.1  christos   /* If n3 is zero and n2 is positive, we want a floating type, and n2
   6513   1.1  christos      is the width in bytes.
   6514   1.1  christos 
   6515   1.1  christos      Fortran programs appear to use this for complex types also.  To
   6516   1.1  christos      distinguish between floats and complex, g77 (and others?)  seem
   6517   1.1  christos      to use self-subranges for the complexes, and subranges of int for
   6518   1.1  christos      the floats.
   6519   1.1  christos 
   6520   1.1  christos      Also note that for complexes, g77 sets n2 to the size of one of
   6521   1.7  christos      the member floats, not the whole complex beast.  My guess is that
   6522   1.1  christos      this was to work well with pre-COMPLEX versions of gdb.  */
   6523   1.1  christos 
   6524   1.9  christos   if (n3 == 0 && n2 > 0)
   6525   1.1  christos     {
   6526   1.1  christos       struct type *float_type
   6527   1.1  christos 	= dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT);
   6528   1.1  christos 
   6529   1.1  christos       if (self_subrange)
   6530   1.1  christos 	return init_complex_type (NULL, float_type);
   6531   1.1  christos       else
   6532   1.1  christos 	return float_type;
   6533   1.1  christos     }
   6534   1.1  christos 
   6535   1.1  christos   /* If the upper bound is -1, it must really be an unsigned integral.  */
   6536   1.1  christos 
   6537   1.1  christos   else if (n2 == 0 && n3 == -1)
   6538   1.1  christos     {
   6539   1.1  christos       int bits = type_size;
   6540   1.1  christos 
   6541   1.1  christos       if (bits <= 0)
   6542   1.1  christos 	{
   6543  1.11  christos 	  /* We don't know its size.  It is unsigned int or unsigned
   6544   1.1  christos 	     long.  GCC 2.3.3 uses this for long long too, but that is
   6545   1.1  christos 	     just a GDB 3.5 compatibility hack.  */
   6546   1.1  christos 	  bits = gdbarch_int_bit (gdbarch);
   6547   1.1  christos 	}
   6548   1.1  christos 
   6549   1.7  christos       return init_integer_type (alloc, bits, 1, NULL);
   6550  1.11  christos     }
   6551   1.8  christos 
   6552  1.10  christos   /* Special case: char is defined (Who knows why) as a subrange of
   6553   1.7  christos      itself with range 0-127.  */
   6554   1.7  christos   else if (self_subrange && n2 == 0 && n3 == 127)
   6555   1.1  christos     {
   6556   1.1  christos       struct type *type = init_integer_type (alloc, TARGET_CHAR_BIT,
   6557   1.1  christos 					     0, NULL);
   6558   1.1  christos       type->set_has_no_signedness (true);
   6559  1.10  christos       return type;
   6560  1.10  christos     }
   6561   1.1  christos   /* We used to do this only for subrange of self or subrange of int.  */
   6562   1.1  christos   else if (n2 == 0)
   6563   1.1  christos     {
   6564  1.11  christos       /* -1 is used for the upper bound of (4 byte) "unsigned int" and
   6565   1.1  christos 	 "unsigned long", and we already checked for that,
   6566   1.1  christos 	 so don't need to test for it here.  */
   6567  1.10  christos 
   6568  1.10  christos       if (n3 < 0)
   6569   1.1  christos 	/* n3 actually gives the size.  */
   6570   1.1  christos 	return init_integer_type (alloc, -n3 * TARGET_CHAR_BIT, 1, NULL);
   6571   1.1  christos 
   6572   1.1  christos       /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
   6573   1.1  christos 	 unsigned n-byte integer.  But do require n to be a power of
   6574   1.1  christos 	 two; we don't want 3- and 5-byte integers flying around.  */
   6575   1.1  christos       {
   6576   1.1  christos 	int bytes;
   6577   1.1  christos 	unsigned long bits;
   6578  1.11  christos 
   6579   1.1  christos 	bits = n3;
   6580   1.1  christos 	for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
   6581   1.1  christos 	  bits >>= 8;
   6582   1.1  christos 	if (bits == 0
   6583   1.1  christos 	    && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
   6584   1.1  christos 	  return init_integer_type (alloc, bytes * TARGET_CHAR_BIT, 1, NULL);
   6585   1.1  christos       }
   6586   1.1  christos     }
   6587   1.1  christos   /* I think this is for Convex "long long".  Since I don't know whether
   6588  1.11  christos      Convex sets self_subrange, I also accept that particular size regardless
   6589   1.1  christos      of self_subrange.  */
   6590   1.1  christos   else if (n3 == 0 && n2 < 0
   6591   1.1  christos 	   && (self_subrange
   6592  1.11  christos 	       || n2 == -gdbarch_long_long_bit
   6593   1.1  christos 			  (gdbarch) / TARGET_CHAR_BIT))
   6594  1.11  christos     return init_integer_type (alloc, -n2 * TARGET_CHAR_BIT, 0, NULL);
   6595   1.1  christos   else if (n2 == -n3 - 1)
   6596  1.11  christos     {
   6597   1.1  christos       if (n3 == 0x7f)
   6598   1.1  christos 	return init_integer_type (alloc, 8, 0, NULL);
   6599   1.1  christos       if (n3 == 0x7fff)
   6600   1.1  christos 	return init_integer_type (alloc, 16, 0, NULL);
   6601   1.1  christos       if (n3 == 0x7fffffff)
   6602   1.1  christos 	return init_integer_type (alloc, 32, 0, NULL);
   6603   1.1  christos     }
   6604  1.11  christos 
   6605   1.1  christos   /* We have a real range type on our hands.  Allocate space and
   6606   1.1  christos      return a real pointer.  */
   6607   1.1  christos handle_true_range:
   6608   1.1  christos 
   6609   1.1  christos   if (self_subrange)
   6610  1.10  christos     index_type = builtin_type (objfile)->builtin_int;
   6611   1.1  christos   else
   6612   1.8  christos     index_type = *dbx_lookup_type (rangenums, objfile);
   6613   1.1  christos   if (index_type == NULL)
   6614  1.11  christos     {
   6615   1.1  christos       /* Does this actually ever happen?  Is that why we are worrying
   6616   1.1  christos 	 about dealing with it rather than just calling error_type?  */
   6617   1.3  christos 
   6618  1.11  christos       complaint (_("base type %d of range type is not defined"), rangenums[1]);
   6619   1.1  christos 
   6620   1.1  christos       index_type = builtin_type (objfile)->builtin_int;
   6621   1.1  christos     }
   6622   1.1  christos 
   6623   1.1  christos   result_type
   6624   1.1  christos     = create_static_range_type (alloc, index_type, n2, n3);
   6625   1.1  christos   return (result_type);
   6626   1.1  christos }
   6627   1.7  christos 
   6628   1.1  christos /* Read in an argument list.  This is a list of types, separated by commas
   6629   1.1  christos    and terminated with END.  Return the list of types read in, or NULL
   6630   1.1  christos    if there is an error.  */
   6631   1.1  christos 
   6632   1.1  christos static struct field *
   6633   1.1  christos read_args (const char **pp, int end, struct objfile *objfile, int *nargsp,
   6634   1.1  christos 	   int *varargsp)
   6635   1.1  christos {
   6636   1.1  christos   /* FIXME!  Remove this arbitrary limit!  */
   6637   1.1  christos   struct type *types[1024];	/* Allow for fns of 1023 parameters.  */
   6638   1.1  christos   int n = 0, i;
   6639   1.1  christos   struct field *rval;
   6640   1.1  christos 
   6641   1.1  christos   while (**pp != end)
   6642   1.1  christos     {
   6643   1.1  christos       if (**pp != ',')
   6644   1.1  christos 	/* Invalid argument list: no ','.  */
   6645   1.1  christos 	return NULL;
   6646   1.1  christos       (*pp)++;
   6647   1.1  christos       STABS_CONTINUE (pp, objfile);
   6648   1.1  christos       types[n++] = read_type (pp, objfile);
   6649   1.1  christos     }
   6650   1.1  christos   (*pp)++;			/* get past `end' (the ':' character).  */
   6651   1.1  christos 
   6652   1.1  christos   if (n == 0)
   6653   1.8  christos     {
   6654   1.1  christos       /* We should read at least the THIS parameter here.  Some broken stabs
   6655   1.1  christos 	 output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
   6656   1.9  christos 	 have been present ";-16,(0,43)" reference instead.  This way the
   6657   1.1  christos 	 excessive ";" marker prematurely stops the parameters parsing.  */
   6658   1.1  christos 
   6659   1.1  christos       complaint (_("Invalid (empty) method arguments"));
   6660   1.1  christos       *varargsp = 0;
   6661   1.1  christos     }
   6662   1.1  christos   else if (types[n - 1]->code () != TYPE_CODE_VOID)
   6663   1.1  christos     *varargsp = 1;
   6664   1.6  christos   else
   6665   1.1  christos     {
   6666   1.9  christos       n--;
   6667   1.1  christos       *varargsp = 0;
   6668   1.1  christos     }
   6669   1.1  christos 
   6670   1.1  christos   rval = XCNEWVEC (struct field, n);
   6671   1.1  christos   for (i = 0; i < n; i++)
   6672   1.1  christos     rval[i].set_type (types[i]);
   6673   1.1  christos   *nargsp = n;
   6674   1.1  christos   return rval;
   6675   1.1  christos }
   6676   1.1  christos 
   6677   1.1  christos /* Common block handling.  */
   6679   1.1  christos 
   6680   1.1  christos /* List of symbols declared since the last BCOMM.  This list is a tail
   6681   1.1  christos    of local_symbols.  When ECOMM is seen, the symbols on the list
   6682   1.1  christos    are noted so their proper addresses can be filled in later,
   6683   1.1  christos    using the common block base address gotten from the assembler
   6684   1.1  christos    stabs.  */
   6685   1.1  christos 
   6686   1.1  christos static struct pending *common_block;
   6687   1.1  christos static int common_block_i;
   6688   1.1  christos 
   6689   1.1  christos /* Name of the current common block.  We get it from the BCOMM instead of the
   6690   1.1  christos    ECOMM to match IBM documentation (even though IBM puts the name both places
   6691   1.7  christos    like everyone else).  */
   6692   1.1  christos static char *common_block_name;
   6693   1.1  christos 
   6694   1.1  christos /* Process a N_BCOMM symbol.  The storage for NAME is not guaranteed
   6695   1.8  christos    to remain after this function returns.  */
   6696   1.1  christos 
   6697   1.8  christos void
   6698   1.8  christos common_block_start (const char *name, struct objfile *objfile)
   6699   1.9  christos {
   6700   1.1  christos   if (common_block_name != NULL)
   6701   1.1  christos     {
   6702   1.1  christos       complaint (_("Invalid symbol data: common block within common block"));
   6703   1.1  christos     }
   6704   1.1  christos   common_block = *get_local_symbols ();
   6705   1.1  christos   common_block_i = common_block ? common_block->nsyms : 0;
   6706   1.1  christos   common_block_name = obstack_strdup (&objfile->objfile_obstack, name);
   6707   1.1  christos }
   6708   1.1  christos 
   6709   1.1  christos /* Process a N_ECOMM symbol.  */
   6710   1.1  christos 
   6711   1.1  christos void
   6712   1.1  christos common_block_end (struct objfile *objfile)
   6713   1.1  christos {
   6714   1.5  christos   /* Symbols declared since the BCOMM are to have the common block
   6715   1.1  christos      start address added in when we know it.  common_block and
   6716   1.1  christos      common_block_i point to the first symbol after the BCOMM in
   6717   1.1  christos      the local_symbols list; copy the list and hang it off the
   6718   1.1  christos      symbol for the common block name for later fixup.  */
   6719   1.1  christos   int i;
   6720   1.8  christos   struct symbol *sym;
   6721   1.1  christos   struct pending *newobj = 0;
   6722   1.1  christos   struct pending *next;
   6723   1.1  christos   int j;
   6724   1.9  christos 
   6725   1.1  christos   if (common_block_name == NULL)
   6726   1.9  christos     {
   6727  1.10  christos       complaint (_("ECOMM symbol unmatched by BCOMM"));
   6728   1.1  christos       return;
   6729   1.1  christos     }
   6730   1.1  christos 
   6731   1.1  christos   sym = new (&objfile->objfile_obstack) symbol;
   6732   1.8  christos   /* Note: common_block_name already saved on objfile_obstack.  */
   6733   1.1  christos   sym->set_linkage_name (common_block_name);
   6734   1.1  christos   sym->set_aclass_index (LOC_BLOCK);
   6735   1.1  christos 
   6736   1.1  christos   /* Now we copy all the symbols which have been defined since the BCOMM.  */
   6737   1.5  christos 
   6738   1.1  christos   /* Copy all the struct pendings before common_block.  */
   6739   1.1  christos   for (next = *get_local_symbols ();
   6740   1.1  christos        next != NULL && next != common_block;
   6741   1.1  christos        next = next->next)
   6742   1.1  christos     {
   6743   1.1  christos       for (j = 0; j < next->nsyms; j++)
   6744   1.1  christos 	add_symbol_to_list (next->symbol[j], &newobj);
   6745   1.1  christos     }
   6746   1.5  christos 
   6747   1.1  christos   /* Copy however much of COMMON_BLOCK we need.  If COMMON_BLOCK is
   6748  1.10  christos      NULL, it means copy all the local symbols (which we already did
   6749   1.1  christos      above).  */
   6750   1.1  christos 
   6751   1.1  christos   if (common_block != NULL)
   6752   1.1  christos     for (j = common_block_i; j < common_block->nsyms; j++)
   6753   1.9  christos       add_symbol_to_list (common_block->symbol[j], &newobj);
   6754  1.10  christos 
   6755   1.1  christos   sym->set_type ((struct type *) newobj);
   6756   1.1  christos 
   6757   1.1  christos   /* Should we be putting local_symbols back to what it was?
   6758   1.1  christos      Does it matter?  */
   6759   1.1  christos 
   6760   1.1  christos   i = hashname (sym->linkage_name ());
   6761   1.1  christos   sym->set_value_chain (global_sym_chain[i]);
   6762   1.1  christos   global_sym_chain[i] = sym;
   6763   1.1  christos   common_block_name = NULL;
   6764  1.11  christos }
   6765   1.1  christos 
   6766  1.10  christos /* Add a common block's start address to the offset of each symbol
   6767   1.1  christos    declared to be in it (by being between a BCOMM/ECOMM pair that uses
   6768   1.1  christos    the common block name).  */
   6769   1.1  christos 
   6770   1.1  christos static void
   6771   1.1  christos fix_common_block (struct symbol *sym, CORE_ADDR valu, int section_index)
   6772   1.1  christos {
   6773  1.11  christos   struct pending *next = (struct pending *) sym->type ();
   6774  1.11  christos 
   6775  1.11  christos   for (; next; next = next->next)
   6776  1.11  christos     {
   6777  1.11  christos       int j;
   6778   1.1  christos 
   6779   1.1  christos       for (j = next->nsyms - 1; j >= 0; j--)
   6780   1.1  christos 	{
   6781   1.1  christos 	  next->symbol[j]->set_value_address
   6782   1.1  christos 	    (next->symbol[j]->value_address () + valu);
   6783   1.1  christos 	  next->symbol[j]->set_section_index (section_index);
   6784   1.1  christos 	}
   6785   1.1  christos     }
   6786   1.1  christos }
   6787   1.1  christos 
   6788   1.1  christos 
   6790   1.1  christos 
   6791   1.1  christos /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
   6792   1.1  christos    See add_undefined_type for more details.  */
   6793   1.1  christos 
   6794   1.1  christos static void
   6795   1.1  christos add_undefined_type_noname (struct type *type, int typenums[2])
   6796   1.1  christos {
   6797   1.1  christos   struct nat nat;
   6798   1.1  christos 
   6799   1.1  christos   nat.typenums[0] = typenums [0];
   6800   1.1  christos   nat.typenums[1] = typenums [1];
   6801   1.1  christos   nat.type = type;
   6802   1.1  christos 
   6803   1.1  christos   if (noname_undefs_length == noname_undefs_allocated)
   6804   1.1  christos     {
   6805   1.1  christos       noname_undefs_allocated *= 2;
   6806   1.1  christos       noname_undefs = (struct nat *)
   6807   1.1  christos 	xrealloc ((char *) noname_undefs,
   6808   1.1  christos 		  noname_undefs_allocated * sizeof (struct nat));
   6809   1.1  christos     }
   6810   1.1  christos   noname_undefs[noname_undefs_length++] = nat;
   6811   1.1  christos }
   6812   1.1  christos 
   6813   1.1  christos /* Add TYPE to the UNDEF_TYPES vector.
   6814   1.1  christos    See add_undefined_type for more details.  */
   6815   1.1  christos 
   6816   1.1  christos static void
   6817   1.1  christos add_undefined_type_1 (struct type *type)
   6818   1.1  christos {
   6819   1.1  christos   if (undef_types_length == undef_types_allocated)
   6820   1.1  christos     {
   6821   1.1  christos       undef_types_allocated *= 2;
   6822   1.1  christos       undef_types = (struct type **)
   6823   1.1  christos 	xrealloc ((char *) undef_types,
   6824   1.1  christos 		  undef_types_allocated * sizeof (struct type *));
   6825   1.1  christos     }
   6826   1.1  christos   undef_types[undef_types_length++] = type;
   6827   1.1  christos }
   6828   1.1  christos 
   6829   1.1  christos /* What about types defined as forward references inside of a small lexical
   6830   1.1  christos    scope?  */
   6831   1.1  christos /* Add a type to the list of undefined types to be checked through
   6832   1.1  christos    once this file has been read in.
   6833   1.1  christos 
   6834   1.1  christos    In practice, we actually maintain two such lists: The first list
   6835   1.1  christos    (UNDEF_TYPES) is used for types whose name has been provided, and
   6836   1.1  christos    concerns forward references (eg 'xs' or 'xu' forward references);
   6837   1.9  christos    the second list (NONAME_UNDEFS) is used for types whose name is
   6838   1.1  christos    unknown at creation time, because they were referenced through
   6839   1.1  christos    their type number before the actual type was declared.
   6840   1.1  christos    This function actually adds the given type to the proper list.  */
   6841   1.1  christos 
   6842   1.1  christos static void
   6843   1.1  christos add_undefined_type (struct type *type, int typenums[2])
   6844   1.1  christos {
   6845   1.1  christos   if (type->name () == NULL)
   6846   1.1  christos     add_undefined_type_noname (type, typenums);
   6847   1.1  christos   else
   6848   1.1  christos     add_undefined_type_1 (type);
   6849   1.1  christos }
   6850   1.1  christos 
   6851   1.1  christos /* Try to fix all undefined types pushed on the UNDEF_TYPES vector.  */
   6852   1.1  christos 
   6853   1.1  christos static void
   6854   1.1  christos cleanup_undefined_types_noname (struct objfile *objfile)
   6855   1.1  christos {
   6856   1.9  christos   int i;
   6857  1.10  christos 
   6858  1.10  christos   for (i = 0; i < noname_undefs_length; i++)
   6859  1.10  christos     {
   6860  1.10  christos       struct nat nat = noname_undefs[i];
   6861  1.10  christos       struct type **type;
   6862  1.10  christos 
   6863  1.10  christos       type = dbx_lookup_type (nat.typenums, objfile);
   6864  1.10  christos       if (nat.type != *type && (*type)->code () != TYPE_CODE_UNDEF)
   6865   1.1  christos 	{
   6866   1.1  christos 	  /* The instance flags of the undefined type are still unset,
   6867   1.1  christos 	     and needs to be copied over from the reference type.
   6868   1.1  christos 	     Since replace_type expects them to be identical, we need
   6869   1.1  christos 	     to set these flags manually before hand.  */
   6870   1.1  christos 	  nat.type->set_instance_flags ((*type)->instance_flags ());
   6871   1.1  christos 	  replace_type (nat.type, *type);
   6872   1.1  christos 	}
   6873   1.1  christos     }
   6874   1.1  christos 
   6875   1.1  christos   noname_undefs_length = 0;
   6876   1.1  christos }
   6877   1.1  christos 
   6878   1.1  christos /* Go through each undefined type, see if it's still undefined, and fix it
   6879   1.1  christos    up if possible.  We have two kinds of undefined types:
   6880   1.1  christos 
   6881   1.1  christos    TYPE_CODE_ARRAY:  Array whose target type wasn't defined yet.
   6882   1.1  christos    Fix:  update array length using the element bounds
   6883   1.1  christos    and the target type's length.
   6884   1.1  christos    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
   6885   1.1  christos    yet defined at the time a pointer to it was made.
   6886   1.1  christos    Fix:  Do a full lookup on the struct/union tag.  */
   6887   1.1  christos 
   6888   1.1  christos static void
   6889   1.1  christos cleanup_undefined_types_1 (void)
   6890   1.1  christos {
   6891   1.1  christos   struct type **type;
   6892   1.1  christos 
   6893   1.1  christos   /* Iterate over every undefined type, and look for a symbol whose type
   6894  1.10  christos      matches our undefined type.  The symbol matches if:
   6895   1.1  christos        1. It is a typedef in the STRUCT domain;
   6896   1.1  christos        2. It has the same name, and same type code;
   6897   1.1  christos        3. The instance flags are identical.
   6898   1.1  christos 
   6899   1.1  christos      It is important to check the instance flags, because we have seen
   6900   1.1  christos      examples where the debug info contained definitions such as:
   6901   1.1  christos 
   6902   1.1  christos 	 "foo_t:t30=B31=xefoo_t:"
   6903   1.1  christos 
   6904   1.1  christos      In this case, we have created an undefined type named "foo_t" whose
   6905   1.1  christos      instance flags is null (when processing "xefoo_t"), and then created
   6906   1.9  christos      another type with the same name, but with different instance flags
   6907   1.1  christos      ('B' means volatile).  I think that the definition above is wrong,
   6908   1.1  christos      since the same type cannot be volatile and non-volatile at the same
   6909   1.1  christos      time, but we need to be able to cope with it when it happens.  The
   6910   1.1  christos      approach taken here is to treat these two types as different.  */
   6911   1.1  christos 
   6912   1.1  christos   for (type = undef_types; type < undef_types + undef_types_length; type++)
   6913   1.1  christos     {
   6914   1.1  christos       switch ((*type)->code ())
   6915   1.1  christos 	{
   6916   1.1  christos 
   6917  1.10  christos 	case TYPE_CODE_STRUCT:
   6918   1.1  christos 	case TYPE_CODE_UNION:
   6919   1.1  christos 	case TYPE_CODE_ENUM:
   6920   1.1  christos 	  {
   6921   1.1  christos 	    /* Check if it has been defined since.  Need to do this here
   6922   1.9  christos 	       as well as in check_typedef to deal with the (legitimate in
   6923   1.1  christos 	       C though not C++) case of several types with the same name
   6924   1.5  christos 	       in different source files.  */
   6925   1.1  christos 	    if ((*type)->is_stub ())
   6926   1.8  christos 	      {
   6927   1.1  christos 		struct pending *ppt;
   6928   1.1  christos 		int i;
   6929   1.8  christos 		/* Name of the type, without "struct" or "union".  */
   6930   1.1  christos 		const char *type_name = (*type)->name ();
   6931   1.1  christos 
   6932   1.1  christos 		if (type_name == NULL)
   6933   1.1  christos 		  {
   6934   1.1  christos 		    complaint (_("need a type name"));
   6935  1.10  christos 		    break;
   6936  1.10  christos 		  }
   6937  1.10  christos 		for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
   6938  1.10  christos 		  {
   6939  1.10  christos 		    for (i = 0; i < ppt->nsyms; i++)
   6940   1.9  christos 		      {
   6941  1.10  christos 			struct symbol *sym = ppt->symbol[i];
   6942   1.1  christos 
   6943   1.1  christos 			if (sym->aclass () == LOC_TYPEDEF
   6944   1.1  christos 			    && sym->domain () == STRUCT_DOMAIN
   6945   1.1  christos 			    && (sym->type ()->code () == (*type)->code ())
   6946   1.1  christos 			    && ((*type)->instance_flags ()
   6947   1.1  christos 				== sym->type ()->instance_flags ())
   6948   1.1  christos 			    && strcmp (sym->linkage_name (), type_name) == 0)
   6949   1.1  christos 			  replace_type (*type, sym->type ());
   6950   1.8  christos 		      }
   6951  1.10  christos 		  }
   6952   1.9  christos 	      }
   6953   1.1  christos 	  }
   6954   1.1  christos 	  break;
   6955   1.1  christos 
   6956   1.1  christos 	default:
   6957   1.1  christos 	  {
   6958   1.1  christos 	    complaint (_("forward-referenced types left unresolved, "
   6959   1.1  christos 		       "type code %d."),
   6960   1.1  christos 		       (*type)->code ());
   6961   1.9  christos 	  }
   6962   1.1  christos 	  break;
   6963   1.1  christos 	}
   6964   1.1  christos     }
   6965   1.1  christos 
   6966   1.1  christos   undef_types_length = 0;
   6967   1.1  christos }
   6968   1.1  christos 
   6969   1.1  christos /* Try to fix all the undefined types we encountered while processing
   6970   1.1  christos    this unit.  */
   6971   1.8  christos 
   6972   1.1  christos void
   6973   1.1  christos cleanup_undefined_stabs_types (struct objfile *objfile)
   6974   1.1  christos {
   6975   1.1  christos   cleanup_undefined_types_1 ();
   6976   1.1  christos   cleanup_undefined_types_noname (objfile);
   6977   1.1  christos }
   6978   1.1  christos 
   6979   1.1  christos /* See stabsread.h.  */
   6980   1.1  christos 
   6981   1.1  christos void
   6982   1.1  christos scan_file_globals (struct objfile *objfile)
   6983   1.1  christos {
   6984   1.1  christos   int hash;
   6985  1.10  christos   struct symbol *sym, *prev;
   6986  1.10  christos   struct objfile *resolve_objfile;
   6987  1.10  christos 
   6988   1.1  christos   /* SVR4 based linkers copy referenced global symbols from shared
   6989   1.1  christos      libraries to the main executable.
   6990   1.1  christos      If we are scanning the symbols for a shared library, try to resolve
   6991   1.1  christos      them from the minimal symbols of the main executable first.  */
   6992   1.1  christos 
   6993   1.1  christos   if (current_program_space->symfile_object_file
   6994  1.10  christos       && objfile != current_program_space->symfile_object_file)
   6995   1.1  christos     resolve_objfile = current_program_space->symfile_object_file;
   6996   1.1  christos   else
   6997   1.1  christos     resolve_objfile = objfile;
   6998   1.1  christos 
   6999   1.1  christos   while (1)
   7000   1.1  christos     {
   7001   1.1  christos       /* Avoid expensive loop through all minimal symbols if there are
   7002   1.1  christos 	 no unresolved symbols.  */
   7003   1.8  christos       for (hash = 0; hash < HASHSIZE; hash++)
   7004   1.1  christos 	{
   7005   1.1  christos 	  if (global_sym_chain[hash])
   7006   1.1  christos 	    break;
   7007   1.1  christos 	}
   7008  1.10  christos       if (hash >= HASHSIZE)
   7009   1.1  christos 	return;
   7010   1.1  christos 
   7011   1.1  christos       for (minimal_symbol *msymbol : resolve_objfile->msymbols ())
   7012   1.1  christos 	{
   7013   1.1  christos 	  QUIT;
   7014   1.1  christos 
   7015   1.1  christos 	  /* Skip static symbols.  */
   7016   1.1  christos 	  switch (msymbol->type ())
   7017   1.1  christos 	    {
   7018   1.1  christos 	    case mst_file_text:
   7019   1.1  christos 	    case mst_file_data:
   7020   1.1  christos 	    case mst_file_bss:
   7021   1.1  christos 	      continue;
   7022   1.1  christos 	    default:
   7023   1.9  christos 	      break;
   7024   1.1  christos 	    }
   7025   1.1  christos 
   7026   1.1  christos 	  prev = NULL;
   7027   1.9  christos 
   7028   1.1  christos 	  /* Get the hash index and check all the symbols
   7029   1.1  christos 	     under that hash index.  */
   7030   1.1  christos 
   7031   1.1  christos 	  hash = hashname (msymbol->linkage_name ());
   7032   1.1  christos 
   7033  1.10  christos 	  for (sym = global_sym_chain[hash]; sym;)
   7034   1.1  christos 	    {
   7035   1.1  christos 	      if (strcmp (msymbol->linkage_name (), sym->linkage_name ()) == 0)
   7036   1.1  christos 		{
   7037  1.10  christos 		  /* Splice this symbol out of the hash chain and
   7038   1.1  christos 		     assign the value we have to it.  */
   7039   1.1  christos 		  if (prev)
   7040   1.1  christos 		    {
   7041   1.1  christos 		      prev->set_value_chain (sym->value_chain ());
   7042   1.1  christos 		    }
   7043   1.1  christos 		  else
   7044   1.1  christos 		    {
   7045  1.10  christos 		      global_sym_chain[hash] = sym->value_chain ();
   7046  1.10  christos 		    }
   7047  1.11  christos 
   7048  1.11  christos 		  /* Check to see whether we need to fix up a common block.  */
   7049   1.1  christos 		  /* Note: this code might be executed several times for
   7050  1.10  christos 		     the same symbol if there are multiple references.  */
   7051  1.10  christos 		  if (sym)
   7052  1.10  christos 		    {
   7053   1.1  christos 		      if (sym->aclass () == LOC_BLOCK)
   7054   1.1  christos 			fix_common_block
   7055   1.1  christos 			  (sym, msymbol->value_address (resolve_objfile),
   7056   1.1  christos 			   msymbol->section_index ());
   7057  1.10  christos 		      else
   7058   1.1  christos 			sym->set_value_address
   7059   1.1  christos 			  (msymbol->value_address (resolve_objfile));
   7060   1.1  christos 		      sym->set_section_index (msymbol->section_index ());
   7061   1.1  christos 		    }
   7062   1.1  christos 
   7063   1.1  christos 		  if (prev)
   7064   1.1  christos 		    {
   7065   1.1  christos 		      sym = prev->value_chain ();
   7066   1.1  christos 		    }
   7067  1.10  christos 		  else
   7068   1.1  christos 		    {
   7069   1.1  christos 		      sym = global_sym_chain[hash];
   7070   1.1  christos 		    }
   7071   1.1  christos 		}
   7072   1.1  christos 	      else
   7073   1.1  christos 		{
   7074   1.1  christos 		  prev = sym;
   7075   1.1  christos 		  sym = sym->value_chain ();
   7076   1.1  christos 		}
   7077   1.1  christos 	    }
   7078   1.1  christos 	}
   7079   1.1  christos       if (resolve_objfile == objfile)
   7080   1.1  christos 	break;
   7081   1.1  christos       resolve_objfile = objfile;
   7082   1.1  christos     }
   7083   1.1  christos 
   7084  1.10  christos   /* Change the storage class of any remaining unresolved globals to
   7085   1.1  christos      LOC_UNRESOLVED and remove them from the chain.  */
   7086   1.1  christos   for (hash = 0; hash < HASHSIZE; hash++)
   7087   1.1  christos     {
   7088  1.10  christos       sym = global_sym_chain[hash];
   7089   1.1  christos       while (sym)
   7090   1.1  christos 	{
   7091  1.10  christos 	  prev = sym;
   7092  1.10  christos 	  sym = sym->value_chain ();
   7093   1.1  christos 
   7094   1.8  christos 	  /* Change the symbol address from the misleading chain value
   7095   1.1  christos 	     to address zero.  */
   7096   1.9  christos 	  prev->set_value_address (0);
   7097   1.1  christos 
   7098   1.1  christos 	  /* Complain about unresolved common block symbols.  */
   7099   1.1  christos 	  if (prev->aclass () == LOC_STATIC)
   7100   1.1  christos 	    prev->set_aclass_index (LOC_UNRESOLVED);
   7101   1.1  christos 	  else
   7102   1.1  christos 	    complaint (_("%s: common block `%s' from "
   7103   1.1  christos 			 "global_sym_chain unresolved"),
   7104   1.1  christos 		       objfile_name (objfile), prev->print_name ());
   7105   1.1  christos 	}
   7106   1.1  christos     }
   7107   1.1  christos   memset (global_sym_chain, 0, sizeof (global_sym_chain));
   7108   1.1  christos }
   7109   1.1  christos 
   7110   1.1  christos /* Initialize anything that needs initializing when starting to read
   7111   1.1  christos    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
   7112   1.1  christos    to a psymtab.  */
   7113   1.1  christos 
   7114   1.1  christos void
   7115   1.1  christos stabsread_init (void)
   7116   1.1  christos {
   7117   1.1  christos }
   7118   1.1  christos 
   7119   1.1  christos /* Initialize anything that needs initializing when a completely new
   7120   1.1  christos    symbol file is specified (not just adding some symbols from another
   7121   1.1  christos    file, e.g. a shared library).  */
   7122   1.1  christos 
   7123  1.10  christos void
   7124   1.1  christos stabsread_new_init (void)
   7125   1.1  christos {
   7126   1.1  christos   /* Empty the hash table of global syms looking for values.  */
   7127   1.1  christos   memset (global_sym_chain, 0, sizeof (global_sym_chain));
   7128   1.1  christos }
   7129   1.1  christos 
   7130   1.1  christos /* Initialize anything that needs initializing at the same time as
   7131   1.1  christos    start_compunit_symtab() is called.  */
   7132   1.1  christos 
   7133   1.8  christos void
   7134   1.1  christos start_stabs (void)
   7135   1.1  christos {
   7136   1.1  christos   global_stabs = NULL;		/* AIX COFF */
   7137   1.1  christos   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
   7138   1.1  christos   n_this_object_header_files = 1;
   7139  1.10  christos   type_vector_length = 0;
   7140   1.1  christos   type_vector = (struct type **) 0;
   7141   1.1  christos   within_function = 0;
   7142   1.1  christos 
   7143   1.1  christos   /* FIXME: If common_block_name is not already NULL, we should complain().  */
   7144   1.1  christos   common_block_name = NULL;
   7145   1.1  christos }
   7146   1.1  christos 
   7147   1.1  christos /* Call after end_compunit_symtab().  */
   7148   1.1  christos 
   7149   1.1  christos void
   7150   1.1  christos end_stabs (void)
   7151   1.1  christos {
   7152   1.1  christos   if (type_vector)
   7153   1.1  christos     {
   7154   1.1  christos       xfree (type_vector);
   7155   1.1  christos     }
   7156   1.1  christos   type_vector = 0;
   7157   1.1  christos   type_vector_length = 0;
   7158   1.8  christos   previous_stab_code = 0;
   7159   1.1  christos }
   7160   1.1  christos 
   7161   1.1  christos void
   7162   1.1  christos finish_global_stabs (struct objfile *objfile)
   7163   1.1  christos {
   7164   1.1  christos   if (global_stabs)
   7165   1.1  christos     {
   7166   1.7  christos       patch_block_stabs (*get_global_symbols (), global_stabs, objfile);
   7167   1.7  christos       xfree (global_stabs);
   7168   1.1  christos       global_stabs = NULL;
   7169   1.7  christos     }
   7170   1.1  christos }
   7171   1.1  christos 
   7172   1.1  christos /* Find the end of the name, delimited by a ':', but don't match
   7173   1.1  christos    ObjC symbols which look like -[Foo bar::]:bla.  */
   7174   1.1  christos static const char *
   7175   1.1  christos find_name_end (const char *name)
   7176   1.1  christos {
   7177   1.1  christos   const char *s = name;
   7178   1.1  christos 
   7179   1.1  christos   if (s[0] == '-' || *s == '+')
   7180   1.1  christos     {
   7181   1.1  christos       /* Must be an ObjC method symbol.  */
   7182   1.1  christos       if (s[1] != '[')
   7183   1.1  christos 	{
   7184   1.1  christos 	  error (_("invalid symbol name \"%s\""), name);
   7185   1.1  christos 	}
   7186   1.1  christos       s = strchr (s, ']');
   7187   1.1  christos       if (s == NULL)
   7188   1.1  christos 	{
   7189   1.1  christos 	  error (_("invalid symbol name \"%s\""), name);
   7190   1.1  christos 	}
   7191   1.8  christos       return strchr (s, ':');
   7192   1.8  christos     }
   7193   1.8  christos   else
   7194   1.8  christos     {
   7195   1.8  christos       return strchr (s, ':');
   7196   1.9  christos     }
   7197   1.8  christos }
   7198   1.8  christos 
   7199   1.1  christos /* See stabsread.h.  */
   7200   1.1  christos 
   7201   1.9  christos int
   7202   1.1  christos hashname (const char *name)
   7203   1.9  christos {
   7204   1.1  christos   return fast_hash (name, strlen (name)) % HASHSIZE;
   7205   1.1  christos }
   7206   1.1  christos 
   7207   1.6  christos /* Initializer for this module.  */
   7208   1.1  christos 
   7209   1.1  christos void _initialize_stabsread ();
   7210   1.1  christos void
   7211   1.6  christos _initialize_stabsread ()
   7212   1.1  christos {
   7213   1.1  christos   undef_types_allocated = 20;
   7214   1.1  christos   undef_types_length = 0;
   7215   1.1  christos   undef_types = XNEWVEC (struct type *, undef_types_allocated);
   7216   1.1  christos 
   7217   1.1  christos   noname_undefs_allocated = 20;
   7218                   noname_undefs_length = 0;
   7219                   noname_undefs = XNEWVEC (struct nat, noname_undefs_allocated);
   7220                 
   7221                   stab_register_index = register_symbol_register_impl (LOC_REGISTER,
   7222                 						       &stab_register_funcs);
   7223                   stab_regparm_index = register_symbol_register_impl (LOC_REGPARM_ADDR,
   7224                 						      &stab_register_funcs);
   7225                 }
   7226