Home | History | Annotate | Line # | Download | only in gdb
mdebugread.c revision 1.12
      1 /* Read a symbol table in ECOFF format (Third-Eye).
      2 
      3    Copyright (C) 1986-2024 Free Software Foundation, Inc.
      4 
      5    Original version contributed by Alessandro Forin (af (at) cs.cmu.edu) at
      6    CMU.  Major work by Per Bothner, John Gilmore and Ian Lance Taylor
      7    at Cygnus Support.
      8 
      9    This file is part of GDB.
     10 
     11    This program is free software; you can redistribute it and/or modify
     12    it under the terms of the GNU General Public License as published by
     13    the Free Software Foundation; either version 3 of the License, or
     14    (at your option) any later version.
     15 
     16    This program is distributed in the hope that it will be useful,
     17    but WITHOUT ANY WARRANTY; without even the implied warranty of
     18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19    GNU General Public License for more details.
     20 
     21    You should have received a copy of the GNU General Public License
     22    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     23 
     24 /* This module provides the function mdebug_build_psymtabs.  It reads
     25    ECOFF debugging information into partial symbol tables.  The
     26    debugging information is read from two structures.  A struct
     27    ecoff_debug_swap includes the sizes of each ECOFF structure and
     28    swapping routines; these are fixed for a particular target.  A
     29    struct ecoff_debug_info points to the debugging information for a
     30    particular object file.
     31 
     32    ECOFF symbol tables are mostly written in the byte order of the
     33    target machine.  However, one section of the table (the auxiliary
     34    symbol information) is written in the host byte order.  There is a
     35    bit in the other symbol info which describes which host byte order
     36    was used.  ECOFF thereby takes the trophy from Intel `b.out' for
     37    the most brain-dead adaptation of a file format to byte order.
     38 
     39    This module can read all four of the known byte-order combinations,
     40    on any type of host.  */
     41 
     42 #include "symtab.h"
     43 #include "gdbtypes.h"
     44 #include "gdbcore.h"
     45 #include "filenames.h"
     46 #include "objfiles.h"
     47 #include "gdbsupport/gdb_obstack.h"
     48 #include "buildsym-legacy.h"
     49 #include "stabsread.h"
     50 #include "complaints.h"
     51 #include "demangle.h"
     52 #include "gdb-demangle.h"
     53 #include "block.h"
     54 #include "dictionary.h"
     55 #include "mdebugread.h"
     56 #include <sys/stat.h>
     57 #include "psymtab.h"
     58 #include "source.h"
     59 
     60 #include "bfd.h"
     61 
     62 #include "coff/ecoff.h"
     63 
     64 #include "libaout.h"
     65 #include "aout/aout64.h"
     66 #include "aout/stab_gnu.h"
     67 
     68 #include "expression.h"
     69 
     70 #include <algorithm>
     71 
     72 /* Provide a way to test if we have both ECOFF and ELF symbol tables.
     73    We use this define in order to know whether we should override a
     74    symbol's ECOFF section with its ELF section.  This is necessary in
     75    case the symbol's ELF section could not be represented in ECOFF.  */
     76 #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
     77 			   && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
     78 
     79 /* The objfile we are currently reading.  */
     80 
     81 static struct objfile *mdebugread_objfile;
     82 
     83 
     84 
     86 /* We put a pointer to this structure in the read_symtab_private field
     87    of the psymtab.  */
     88 
     89 struct md_symloc
     90   {
     91     /* Index of the FDR that this psymtab represents.  */
     92     int fdr_idx;
     93     /* The BFD that the psymtab was created from.  */
     94     bfd *cur_bfd;
     95     const struct ecoff_debug_swap *debug_swap;
     96     struct ecoff_debug_info *debug_info;
     97     struct mdebug_pending **pending_list;
     98     /* Pointer to external symbols for this file.  */
     99     EXTR *extern_tab;
    100     /* Size of extern_tab.  */
    101     int extern_count;
    102     enum language pst_language;
    103   };
    104 
    105 #define PST_PRIVATE(p) ((struct md_symloc *)(p)->read_symtab_private)
    106 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
    107 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
    108 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
    109 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
    110 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
    111 
    112 #define SC_IS_TEXT(sc) ((sc) == scText \
    113 		   || (sc) == scRConst \
    114 	  	   || (sc) == scInit \
    115 	  	   || (sc) == scFini)
    116 #define SC_IS_DATA(sc) ((sc) == scData \
    117 		   || (sc) == scSData \
    118 		   || (sc) == scRData \
    119 		   || (sc) == scPData \
    120 		   || (sc) == scXData)
    121 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
    122 #define SC_IS_BSS(sc) ((sc) == scBss)
    123 #define SC_IS_SBSS(sc) ((sc) == scSBss)
    124 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
    125 
    126 /* Various complaints about symbol reading that don't abort the process.  */
    128 static void
    129 index_complaint (const char *arg1)
    130 {
    131   complaint (_("bad aux index at symbol %s"), arg1);
    132 }
    133 
    134 static void
    135 unknown_ext_complaint (const char *arg1)
    136 {
    137   complaint (_("unknown external symbol %s"), arg1);
    138 }
    139 
    140 static void
    141 basic_type_complaint (int arg1, const char *arg2)
    142 {
    143   complaint (_("cannot map ECOFF basic type 0x%x for %s"),
    144 	     arg1, arg2);
    145 }
    146 
    147 static void
    148 bad_tag_guess_complaint (const char *arg1)
    149 {
    150   complaint (_("guessed tag type of %s incorrectly"), arg1);
    151 }
    152 
    153 static void
    154 bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3)
    155 {
    156   complaint (_("bad rfd entry for %s: file %d, index %d"),
    157 	     arg1, arg2, arg3);
    158 }
    159 
    160 static void
    161 unexpected_type_code_complaint (const char *arg1)
    162 {
    163   complaint (_("unexpected type code for %s"), arg1);
    164 }
    165 
    166 /* Macros and extra defs.  */
    167 
    168 /* Puns: hard to find whether -g was used and how.  */
    169 
    170 #define MIN_GLEVEL GLEVEL_0
    171 #define compare_glevel(a,b)					\
    172 	(((a) == GLEVEL_3) ? ((b) < GLEVEL_3) :			\
    173 	 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
    174 
    175 /* Things that really are local to this module.  */
    177 
    178 /* Remember what we deduced to be the source language of this psymtab.  */
    179 
    180 static enum language psymtab_language = language_unknown;
    181 
    182 /* Current BFD.  */
    183 
    184 static bfd *cur_bfd;
    185 
    186 /* How to parse debugging information for CUR_BFD.  */
    187 
    188 static const struct ecoff_debug_swap *debug_swap;
    189 
    190 /* Pointers to debugging information for CUR_BFD.  */
    191 
    192 static struct ecoff_debug_info *debug_info;
    193 
    194 /* Pointer to current file descriptor record, and its index.  */
    195 
    196 static FDR *cur_fdr;
    197 static int cur_fd;
    198 
    199 /* Index of current symbol.  */
    200 
    201 static int cur_sdx;
    202 
    203 /* Note how much "debuggable" this image is.  We would like
    204    to see at least one FDR with full symbols.  */
    205 
    206 static int max_gdbinfo;
    207 static int max_glevel;
    208 
    209 /* When examining .o files, report on undefined symbols.  */
    210 
    211 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
    212 
    213 /* Pseudo symbol to use when putting stabs into the symbol table.  */
    214 
    215 static char stabs_symbol[] = STABS_SYMBOL;
    216 
    217 /* Nonzero if we have seen ecoff debugging info for a file.  */
    218 
    219 static int found_ecoff_debugging_info;
    220 
    221 /* Forward declarations.  */
    222 
    223 static int upgrade_type (int, struct type **, int, union aux_ext *,
    224 			 int, const char *);
    225 
    226 static void parse_partial_symbols (minimal_symbol_reader &,
    227 				   psymtab_storage *,
    228 				   struct objfile *);
    229 
    230 static int has_opaque_xref (FDR *, SYMR *);
    231 
    232 static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
    233 		      const char **, int, const char *);
    234 
    235 static struct symbol *new_symbol (const char *);
    236 
    237 static struct type *new_type (char *);
    238 
    239 enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
    240 
    241 static struct block *new_block (struct objfile *objfile,
    242 				enum block_type, enum language);
    243 
    244 static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);
    245 
    246 static struct linetable *new_linetable (int);
    247 
    248 static struct blockvector *new_bvect (int);
    249 
    250 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
    251 				int, const char *);
    252 
    253 static struct symbol *mylookup_symbol (const char *, const struct block *,
    254 				       domain_enum, enum address_class);
    255 
    256 static void sort_blocks (struct symtab *);
    257 
    258 static legacy_psymtab *new_psymtab (const char *, psymtab_storage *,
    259 				    struct objfile *);
    260 
    261 static void mdebug_expand_psymtab (legacy_psymtab *pst,
    262 				  struct objfile *objfile);
    263 
    264 static void add_block (struct block *, struct symtab *);
    265 
    266 static void add_symbol (struct symbol *, struct symtab *, struct block *);
    267 
    268 static int add_line (struct linetable *, int, CORE_ADDR, int);
    269 
    270 static struct linetable *shrink_linetable (struct linetable *);
    271 
    272 static void handle_psymbol_enumerators (struct objfile *, psymtab_storage *,
    273 					partial_symtab *,
    274 					FDR *, int, CORE_ADDR);
    275 
    276 static const char *mdebug_next_symbol_text (struct objfile *);
    277 
    278 /* Exported procedure: Builds a symtab from the partial symtab SELF.
    280    Restores the environment in effect when SELF was created, delegates
    281    most of the work to an ancillary procedure, and sorts
    282    and reorders the symtab list at the end.  SELF is not NULL.  */
    283 
    284 static void
    285 mdebug_read_symtab (legacy_psymtab *self, struct objfile *objfile)
    286 {
    287   next_symbol_text_func = mdebug_next_symbol_text;
    288 
    289   self->expand_psymtab (objfile);
    290 
    291   /* Match with global symbols.  This only needs to be done once,
    292      after all of the symtabs and dependencies have been read in.  */
    293   scan_file_globals (objfile);
    294 }
    295 
    296 /* File-level interface functions.  */
    298 
    299 /* Find a file descriptor given its index RF relative to a file CF.  */
    300 
    301 static FDR *
    302 get_rfd (int cf, int rf)
    303 {
    304   FDR *fdrs;
    305   FDR *f;
    306   RFDT rfd;
    307 
    308   fdrs = debug_info->fdr;
    309   f = fdrs + cf;
    310   /* Object files do not have the RFD table, all refs are absolute.  */
    311   if (f->rfdBase == 0)
    312     return fdrs + rf;
    313   (*debug_swap->swap_rfd_in) (cur_bfd,
    314 			      ((char *) debug_info->external_rfd
    315 			       + ((f->rfdBase + rf)
    316 				  * debug_swap->external_rfd_size)),
    317 			      &rfd);
    318   return fdrs + rfd;
    319 }
    320 
    321 /* Return a safer print NAME for a file descriptor.  */
    322 
    323 static const char *
    324 fdr_name (FDR *f)
    325 {
    326   if (f->rss == -1)
    327     return "<stripped file>";
    328   if (f->rss == 0)
    329     return "<NFY>";
    330   return debug_info->ss + f->issBase + f->rss;
    331 }
    332 
    333 
    334 /* Read in and parse the symtab of the file OBJFILE.  Symbols from
    335    different sections are relocated via the SECTION_OFFSETS.  */
    336 
    337 void
    338 mdebug_build_psymtabs (minimal_symbol_reader &reader,
    339 		       struct objfile *objfile,
    340 		       const struct ecoff_debug_swap *swap,
    341 		       struct ecoff_debug_info *info)
    342 {
    343   cur_bfd = objfile->obfd.get ();
    344   debug_swap = swap;
    345   debug_info = info;
    346 
    347   stabsread_new_init ();
    348   free_header_files ();
    349   init_header_files ();
    350 
    351   /* Make sure all the FDR information is swapped in.  */
    352   if (info->fdr == NULL)
    353     {
    354       char *fdr_src;
    355       char *fdr_end;
    356       FDR *fdr_ptr;
    357 
    358       info->fdr = (FDR *) XOBNEWVEC (&objfile->objfile_obstack, FDR,
    359 				     info->symbolic_header.ifdMax);
    360       fdr_src = (char *) info->external_fdr;
    361       fdr_end = (fdr_src
    362 		 + info->symbolic_header.ifdMax * swap->external_fdr_size);
    363       fdr_ptr = info->fdr;
    364       for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
    365 	(*swap->swap_fdr_in) (objfile->obfd.get (), fdr_src, fdr_ptr);
    366     }
    367 
    368   psymbol_functions *psf = new psymbol_functions ();
    369   psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
    370   objfile->qf.emplace_front (psf);
    371   parse_partial_symbols (reader, partial_symtabs, objfile);
    372 
    373 #if 0
    374   /* Check to make sure file was compiled with -g.  If not, warn the
    375      user of this limitation.  */
    376   if (compare_glevel (max_glevel, GLEVEL_2) < 0)
    377     {
    378       if (max_gdbinfo == 0)
    379 	gdb_printf (_("\n%s not compiled with -g, "
    380 		      "debugging support is limited.\n"),
    381 		    objfile->name);
    382       gdb_printf (_("You should compile with -g2 or "
    383 		    "-g3 for best debugging support.\n"));
    384     }
    385 #endif
    386 }
    387 
    388 /* Local utilities */
    390 
    391 /* Map of FDR indexes to partial symtabs.  */
    392 
    393 struct pst_map
    394 {
    395   legacy_psymtab *pst = nullptr;  /* the psymtab proper */
    396   long n_globals = 0;		  /* exported globals (external symbols) */
    397   long globals_offset = 0;	  /* cumulative */
    398 };
    399 
    400 
    401 /* Utility stack, used to nest procedures and blocks properly.
    402    It is a doubly linked list, to avoid too many alloc/free.
    403    Since we might need it quite a few times it is NOT deallocated
    404    after use.  */
    405 
    406 static struct parse_stack
    407   {
    408     struct parse_stack *next, *prev;
    409     struct symtab *cur_st;	/* Current symtab.  */
    410     struct block *cur_block;	/* Block in it.  */
    411 
    412     /* What are we parsing.  stFile, or stBlock are for files and
    413        blocks.  stProc or stStaticProc means we have seen the start of a
    414        procedure, but not the start of the block within in.  When we see
    415        the start of that block, we change it to stNil, without pushing a
    416        new block, i.e. stNil means both a procedure and a block.  */
    417 
    418     int blocktype;
    419 
    420     struct type *cur_type;	/* Type we parse fields for.  */
    421     int cur_field;		/* Field number in cur_type.  */
    422     CORE_ADDR procadr;		/* Start address of this procedure.  */
    423     int numargs;		/* Its argument count.  */
    424   }
    425 
    426  *top_stack;			/* Top stack ptr */
    427 
    428 
    429 /* Enter a new lexical context.  */
    430 
    431 static void
    432 push_parse_stack (void)
    433 {
    434   struct parse_stack *newobj;
    435 
    436   /* Reuse frames if possible.  */
    437   if (top_stack && top_stack->prev)
    438     newobj = top_stack->prev;
    439   else
    440     newobj = XCNEW (struct parse_stack);
    441   /* Initialize new frame with previous content.  */
    442   if (top_stack)
    443     {
    444       struct parse_stack *prev = newobj->prev;
    445 
    446       *newobj = *top_stack;
    447       top_stack->prev = newobj;
    448       newobj->prev = prev;
    449       newobj->next = top_stack;
    450     }
    451   top_stack = newobj;
    452 }
    453 
    454 /* Exit a lexical context.  */
    455 
    456 static void
    457 pop_parse_stack (void)
    458 {
    459   if (!top_stack)
    460     return;
    461   if (top_stack->next)
    462     top_stack = top_stack->next;
    463 }
    464 
    465 
    466 /* Cross-references might be to things we haven't looked at
    467    yet, e.g. type references.  To avoid too many type
    468    duplications we keep a quick fixup table, an array
    469    of lists of references indexed by file descriptor.  */
    470 
    471 struct mdebug_pending
    472 {
    473   struct mdebug_pending *next;	/* link */
    474   char *s;			/* the unswapped symbol */
    475   struct type *t;		/* its partial type descriptor */
    476 };
    477 
    478 
    479 /* The pending information is kept for an entire object file.  We
    480    allocate the pending information table when we create the partial
    481    symbols, and we store a pointer to the single table in each
    482    psymtab.  */
    483 
    484 static struct mdebug_pending **pending_list;
    485 
    486 /* Check whether we already saw symbol SH in file FH.  */
    487 
    488 static struct mdebug_pending *
    489 is_pending_symbol (FDR *fh, char *sh)
    490 {
    491   int f_idx = fh - debug_info->fdr;
    492   struct mdebug_pending *p;
    493 
    494   /* Linear search is ok, list is typically no more than 10 deep.  */
    495   for (p = pending_list[f_idx]; p; p = p->next)
    496     if (p->s == sh)
    497       break;
    498   return p;
    499 }
    500 
    501 /* Add a new symbol SH of type T.  */
    502 
    503 static void
    504 add_pending (FDR *fh, char *sh, struct type *t)
    505 {
    506   int f_idx = fh - debug_info->fdr;
    507   struct mdebug_pending *p = is_pending_symbol (fh, sh);
    508 
    509   /* Make sure we do not make duplicates.  */
    510   if (!p)
    511     {
    512       p = XOBNEW (&mdebugread_objfile->objfile_obstack, mdebug_pending);
    513       p->s = sh;
    514       p->t = t;
    515       p->next = pending_list[f_idx];
    516       pending_list[f_idx] = p;
    517     }
    518 }
    519 
    520 
    522 /* Parsing Routines proper.  */
    523 
    524 static void
    525 reg_value_complaint (int regnum, int num_regs, const char *sym)
    526 {
    527   complaint (_("bad register number %d (max %d) in symbol %s"),
    528 	     regnum, num_regs - 1, sym);
    529 }
    530 
    531 /* Parse a single symbol.  Mostly just make up a GDB symbol for it.
    532    For blocks, procedures and types we open a new lexical context.
    533    This is basically just a big switch on the symbol's type.  Argument
    534    AX is the base pointer of aux symbols for this file (fh->iauxBase).
    535    EXT_SH points to the unswapped symbol, which is needed for struct,
    536    union, etc., types; it is NULL for an EXTR.  BIGEND says whether
    537    aux symbols are big-endian or little-endian.  Return count of
    538    SYMR's handled (normally one).  */
    539 
    540 static int
    541 mdebug_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
    542 {
    543   int regno = gdbarch_ecoff_reg_to_regnum (gdbarch, sym->value_longest ());
    544 
    545   if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
    546     {
    547       reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
    548 			   sym->print_name ());
    549 
    550       regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless.  */
    551     }
    552 
    553   return regno;
    554 }
    555 
    556 static const struct symbol_register_ops mdebug_register_funcs = {
    557   mdebug_reg_to_regnum
    558 };
    559 
    560 /* The "aclass" indices for computed symbols.  */
    561 
    562 static int mdebug_register_index;
    563 static int mdebug_regparm_index;
    564 
    565 /* Common code for symbols describing data.  */
    566 
    567 static void
    568 add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend,
    569 		 struct symbol *s, int aclass_index, struct block *b,
    570 		 struct objfile *objfile, const char *name)
    571 {
    572   s->set_domain (VAR_DOMAIN);
    573   s->set_aclass_index (aclass_index);
    574   add_symbol (s, top_stack->cur_st, b);
    575 
    576   /* Type could be missing if file is compiled without debugging info.  */
    577   if (SC_IS_UNDEF (sh->sc)
    578       || sh->sc == scNil || sh->index == indexNil)
    579     s->set_type (builtin_type (objfile)->nodebug_data_symbol);
    580   else
    581     s->set_type (parse_type (cur_fd, ax, sh->index, 0, bigend, name));
    582   /* Value of a data symbol is its memory address.  */
    583 }
    584 
    585 static int
    586 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
    587 	      const section_offsets &section_offsets, struct objfile *objfile)
    588 {
    589   struct gdbarch *gdbarch = objfile->arch ();
    590   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
    591   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
    592   const char *name;
    593   struct symbol *s;
    594   struct block *b;
    595   struct mdebug_pending *pend;
    596   struct type *t;
    597   int count = 1;
    598   TIR tir;
    599   long svalue = sh->value;
    600   int bitsize;
    601 
    602   if (ext_sh == NULL)
    603     name = debug_info->ssext + sh->iss;
    604   else
    605     name = debug_info->ss + cur_fdr->issBase + sh->iss;
    606 
    607   int section_index = -1;
    608   switch (sh->sc)
    609     {
    610     case scText:
    611     case scRConst:
    612       /* Do not relocate relative values.
    613 	 The value of a stEnd symbol is the displacement from the
    614 	 corresponding start symbol value.
    615 	 The value of a stBlock symbol is the displacement from the
    616 	 procedure address.  */
    617       if (sh->st != stEnd && sh->st != stBlock)
    618 	section_index = SECT_OFF_TEXT (objfile);
    619       break;
    620     case scData:
    621     case scSData:
    622     case scRData:
    623     case scPData:
    624     case scXData:
    625       section_index = SECT_OFF_DATA (objfile);
    626       break;
    627     case scBss:
    628     case scSBss:
    629       section_index = SECT_OFF_BSS (objfile);
    630       break;
    631     }
    632 
    633   if (section_index != -1)
    634     sh->value += section_offsets[section_index];
    635 
    636   switch (sh->st)
    637     {
    638     case stNil:
    639       break;
    640 
    641     case stGlobal:		/* External symbol, goes into global block.  */
    642       b = top_stack->cur_st->compunit ()->blockvector ()->global_block ();
    643       s = new_symbol (name);
    644       s->set_section_index (section_index);
    645       s->set_value_address (sh->value);
    646       add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
    647       break;
    648 
    649     case stStatic:		/* Static data, goes into current block.  */
    650       b = top_stack->cur_block;
    651       s = new_symbol (name);
    652       if (SC_IS_COMMON (sh->sc))
    653 	{
    654 	  /* It is a FORTRAN common block.  At least for SGI Fortran the
    655 	     address is not in the symbol; we need to fix it later in
    656 	     scan_file_globals.  */
    657 	  int bucket = hashname (s->linkage_name ());
    658 	  s->set_value_chain (global_sym_chain[bucket]);
    659 	  global_sym_chain[bucket] = s;
    660 	}
    661       else
    662 	{
    663 	  s->set_section_index (section_index);
    664 	  s->set_value_address (sh->value);
    665 	}
    666       add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
    667       break;
    668 
    669     case stLocal:		/* Local variable, goes into current block.  */
    670       b = top_stack->cur_block;
    671       s = new_symbol (name);
    672       s->set_value_longest (svalue);
    673       if (sh->sc == scRegister)
    674 	add_data_symbol (sh, ax, bigend, s, mdebug_register_index,
    675 			 b, objfile, name);
    676       else
    677 	add_data_symbol (sh, ax, bigend, s, LOC_LOCAL,
    678 			 b, objfile, name);
    679       break;
    680 
    681     case stParam:		/* Arg to procedure, goes into current
    682 				   block.  */
    683       max_gdbinfo++;
    684       found_ecoff_debugging_info = 1;
    685       top_stack->numargs++;
    686 
    687       /* Special GNU C++ name.  */
    688       if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
    689 	name = "this";		/* FIXME, not alloc'd in obstack.  */
    690       s = new_symbol (name);
    691 
    692       s->set_domain (VAR_DOMAIN);
    693       s->set_is_argument (1);
    694       switch (sh->sc)
    695 	{
    696 	case scRegister:
    697 	  /* Pass by value in register.  */
    698 	  s->set_aclass_index (mdebug_register_index);
    699 	  break;
    700 	case scVar:
    701 	  /* Pass by reference on stack.  */
    702 	  s->set_aclass_index (LOC_REF_ARG);
    703 	  break;
    704 	case scVarRegister:
    705 	  /* Pass by reference in register.  */
    706 	  s->set_aclass_index (mdebug_regparm_index);
    707 	  break;
    708 	default:
    709 	  /* Pass by value on stack.  */
    710 	  s->set_aclass_index (LOC_ARG);
    711 	  break;
    712 	}
    713       s->set_value_longest (svalue);
    714       s->set_type (parse_type (cur_fd, ax, sh->index, 0, bigend, name));
    715       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
    716       break;
    717 
    718     case stLabel:		/* label, goes into current block.  */
    719       s = new_symbol (name);
    720       s->set_domain (LABEL_DOMAIN);	/* So that it can be used */
    721       s->set_aclass_index (LOC_LABEL);	/* but not misused.  */
    722       s->set_section_index (section_index);
    723       s->set_value_address (sh->value);
    724       s->set_type (builtin_type (objfile)->builtin_int);
    725       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
    726       break;
    727 
    728     case stProc:	/* Procedure, usually goes into global block.  */
    729     case stStaticProc:	/* Static procedure, goes into current block.  */
    730       /* For stProc symbol records, we need to check the storage class
    731 	 as well, as only (stProc, scText) entries represent "real"
    732 	 procedures - See the Compaq document titled "Object File /
    733 	 Symbol Table Format Specification" for more information.
    734 	 If the storage class is not scText, we discard the whole block
    735 	 of symbol records for this stProc.  */
    736       if (sh->st == stProc && sh->sc != scText)
    737 	{
    738 	  char *ext_tsym = ext_sh;
    739 	  int keep_counting = 1;
    740 	  SYMR tsym;
    741 
    742 	  while (keep_counting)
    743 	    {
    744 	      ext_tsym += external_sym_size;
    745 	      (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
    746 	      count++;
    747 	      switch (tsym.st)
    748 		{
    749 		  case stParam:
    750 		    break;
    751 		  case stEnd:
    752 		    keep_counting = 0;
    753 		    break;
    754 		  default:
    755 		    complaint (_("unknown symbol type 0x%x"), sh->st);
    756 		    break;
    757 		}
    758 	    }
    759 	  break;
    760 	}
    761       s = new_symbol (name);
    762       s->set_domain (FUNCTION_DOMAIN);
    763       s->set_aclass_index (LOC_BLOCK);
    764       s->set_section_index (section_index);
    765       /* Type of the return value.  */
    766       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
    767 	t = builtin_type (objfile)->builtin_int;
    768       else
    769 	{
    770 	  t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
    771 	  if (strcmp (name, "malloc") == 0
    772 	      && t->code () == TYPE_CODE_VOID)
    773 	    {
    774 	      /* I don't know why, but, at least under Alpha GNU/Linux,
    775 		 when linking against a malloc without debugging
    776 		 symbols, its read as a function returning void---this
    777 		 is bad because it means we cannot call functions with
    778 		 string arguments interactively; i.e., "call
    779 		 printf("howdy\n")" would fail with the error message
    780 		 "program has no memory available".  To avoid this, we
    781 		 patch up the type and make it void*
    782 		 instead. (davidm (at) azstarnet.com).  */
    783 	      t = make_pointer_type (t, NULL);
    784 	    }
    785 	}
    786       b = top_stack->cur_block;
    787       if (sh->st == stProc)
    788 	{
    789 	  struct blockvector *bv
    790 	    = top_stack->cur_st->compunit ()->blockvector ();
    791 
    792 	  /* The next test should normally be true, but provides a
    793 	     hook for nested functions (which we don't want to make
    794 	     global).  */
    795 	  if (b == bv->static_block ())
    796 	    b = bv->global_block ();
    797 	  /* Irix 5 sometimes has duplicate names for the same
    798 	     function.  We want to add such names up at the global
    799 	     level, not as a nested function.  */
    800 	  else if (sh->value == top_stack->procadr)
    801 	    b = bv->global_block ();
    802 	}
    803       add_symbol (s, top_stack->cur_st, b);
    804 
    805       /* Make a type for the procedure itself.  */
    806       s->set_type (lookup_function_type (t));
    807 
    808       /* All functions in C++ have prototypes.  For C we don't have enough
    809 	 information in the debug info.  */
    810       if (s->language () == language_cplus)
    811 	s->type ()->set_is_prototyped (true);
    812 
    813       /* Create and enter a new lexical context.  */
    814       b = new_block (objfile, FUNCTION_BLOCK, s->language ());
    815       s->set_value_block (b);
    816       b->set_function (s);
    817       b->set_start (sh->value);
    818       b->set_end (sh->value);
    819       b->set_superblock (top_stack->cur_block);
    820       add_block (b, top_stack->cur_st);
    821 
    822       /* Not if we only have partial info.  */
    823       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
    824 	break;
    825 
    826       push_parse_stack ();
    827       top_stack->cur_block = b;
    828       top_stack->blocktype = sh->st;
    829       top_stack->cur_type = s->type ();
    830       top_stack->cur_field = -1;
    831       top_stack->procadr = sh->value;
    832       top_stack->numargs = 0;
    833       break;
    834 
    835       /* Beginning of code for structure, union, and enum definitions.
    836 	 They all share a common set of local variables, defined here.  */
    837       {
    838 	enum type_code type_code;
    839 	char *ext_tsym;
    840 	int nfields;
    841 	long max_value;
    842 	struct field *f;
    843 
    844     case stStruct:		/* Start a block defining a struct type.  */
    845 	type_code = TYPE_CODE_STRUCT;
    846 	goto structured_common;
    847 
    848     case stUnion:		/* Start a block defining a union type.  */
    849 	type_code = TYPE_CODE_UNION;
    850 	goto structured_common;
    851 
    852     case stEnum:		/* Start a block defining an enum type.  */
    853 	type_code = TYPE_CODE_ENUM;
    854 	goto structured_common;
    855 
    856     case stBlock:		/* Either a lexical block, or some type.  */
    857 	if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
    858 	  goto case_stBlock_code;	/* Lexical block */
    859 
    860 	type_code = TYPE_CODE_UNDEF;	/* We have a type.  */
    861 
    862 	/* Common code for handling struct, union, enum, and/or as-yet-
    863 	   unknown-type blocks of info about structured data.  `type_code'
    864 	   has been set to the proper TYPE_CODE, if we know it.  */
    865       structured_common:
    866 	found_ecoff_debugging_info = 1;
    867 	push_parse_stack ();
    868 	top_stack->blocktype = stBlock;
    869 
    870 	/* First count the number of fields and the highest value.  */
    871 	nfields = 0;
    872 	max_value = 0;
    873 	for (ext_tsym = ext_sh + external_sym_size;
    874 	     ;
    875 	     ext_tsym += external_sym_size)
    876 	  {
    877 	    SYMR tsym;
    878 
    879 	    (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
    880 
    881 	    switch (tsym.st)
    882 	      {
    883 	      case stEnd:
    884 		/* C++ encodes class types as structures where there the
    885 		   methods are encoded as stProc.  The scope of stProc
    886 		   symbols also ends with stEnd, thus creating a risk of
    887 		   taking the wrong stEnd symbol record as the end of
    888 		   the current struct, which would cause GDB to undercount
    889 		   the real number of fields in this struct.  To make sure
    890 		   we really reached the right stEnd symbol record, we
    891 		   check the associated name, and match it against the
    892 		   struct name.  Since method names are mangled while
    893 		   the class name is not, there is no risk of having a
    894 		   method whose name is identical to the class name
    895 		   (in particular constructor method names are different
    896 		   from the class name).  There is therefore no risk that
    897 		   this check stops the count on the StEnd of a method.
    898 
    899 		   Also, assume that we're really at the end when tsym.iss
    900 		   is 0 (issNull).  */
    901 		if (tsym.iss == issNull
    902 		    || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss,
    903 			       name) == 0)
    904 		  goto end_of_fields;
    905 		break;
    906 
    907 	      case stMember:
    908 		if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
    909 		  {
    910 		    /* If the type of the member is Nil (or Void),
    911 		       without qualifiers, assume the tag is an
    912 		       enumeration.
    913 		       Alpha cc -migrate enums are recognized by a zero
    914 		       index and a zero symbol value.
    915 		       DU 4.0 cc enums are recognized by a member type of
    916 		       btEnum without qualifiers and a zero symbol value.  */
    917 		    if (tsym.index == indexNil
    918 			|| (tsym.index == 0 && sh->value == 0))
    919 		      type_code = TYPE_CODE_ENUM;
    920 		    else
    921 		      {
    922 			(*debug_swap->swap_tir_in) (bigend,
    923 						    &ax[tsym.index].a_ti,
    924 						    &tir);
    925 			if ((tir.bt == btNil || tir.bt == btVoid
    926 			     || (tir.bt == btEnum && sh->value == 0))
    927 			    && tir.tq0 == tqNil)
    928 			  type_code = TYPE_CODE_ENUM;
    929 		      }
    930 		  }
    931 		nfields++;
    932 		if (tsym.value > max_value)
    933 		  max_value = tsym.value;
    934 		break;
    935 
    936 	      case stBlock:
    937 	      case stUnion:
    938 	      case stEnum:
    939 	      case stStruct:
    940 		{
    941 #if 0
    942 		  /* This is a no-op; is it trying to tell us something
    943 		     we should be checking?  */
    944 		  if (tsym.sc == scVariant);	/*UNIMPLEMENTED */
    945 #endif
    946 		  if (tsym.index != 0)
    947 		    {
    948 		      /* This is something like a struct within a
    949 			 struct.  Skip over the fields of the inner
    950 			 struct.  The -1 is because the for loop will
    951 			 increment ext_tsym.  */
    952 		      ext_tsym = ((char *) debug_info->external_sym
    953 				  + ((cur_fdr->isymBase + tsym.index - 1)
    954 				     * external_sym_size));
    955 		    }
    956 		}
    957 		break;
    958 
    959 	      case stTypedef:
    960 		/* mips cc puts out a typedef for struct x if it is not yet
    961 		   defined when it encounters
    962 		   struct y { struct x *xp; };
    963 		   Just ignore it.  */
    964 		break;
    965 
    966 	      case stIndirect:
    967 		/* Irix5 cc puts out a stIndirect for struct x if it is not
    968 		   yet defined when it encounters
    969 		   struct y { struct x *xp; };
    970 		   Just ignore it.  */
    971 		break;
    972 
    973 	      default:
    974 		complaint (_("declaration block contains "
    975 			     "unhandled symbol type %d"),
    976 			   tsym.st);
    977 	      }
    978 	  }
    979       end_of_fields:
    980 
    981 	/* In an stBlock, there is no way to distinguish structs,
    982 	   unions, and enums at this point.  This is a bug in the
    983 	   original design (that has been fixed with the recent
    984 	   addition of the stStruct, stUnion, and stEnum symbol
    985 	   types.)  The way you can tell is if/when you see a variable
    986 	   or field of that type.  In that case the variable's type
    987 	   (in the AUX table) says if the type is struct, union, or
    988 	   enum, and points back to the stBlock here.  So you can
    989 	   patch the tag kind up later - but only if there actually is
    990 	   a variable or field of that type.
    991 
    992 	   So until we know for sure, we will guess at this point.
    993 	   The heuristic is:
    994 	   If the first member has index==indexNil or a void type,
    995 	   assume we have an enumeration.
    996 	   Otherwise, if there is more than one member, and all
    997 	   the members have offset 0, assume we have a union.
    998 	   Otherwise, assume we have a struct.
    999 
   1000 	   The heuristic could guess wrong in the case of of an
   1001 	   enumeration with no members or a union with one (or zero)
   1002 	   members, or when all except the last field of a struct have
   1003 	   width zero.  These are uncommon and/or illegal situations,
   1004 	   and in any case guessing wrong probably doesn't matter
   1005 	   much.
   1006 
   1007 	   But if we later do find out we were wrong, we fixup the tag
   1008 	   kind.  Members of an enumeration must be handled
   1009 	   differently from struct/union fields, and that is harder to
   1010 	   patch up, but luckily we shouldn't need to.  (If there are
   1011 	   any enumeration members, we can tell for sure it's an enum
   1012 	   here.)  */
   1013 
   1014 	if (type_code == TYPE_CODE_UNDEF)
   1015 	  {
   1016 	    if (nfields > 1 && max_value == 0)
   1017 	      type_code = TYPE_CODE_UNION;
   1018 	    else
   1019 	      type_code = TYPE_CODE_STRUCT;
   1020 	  }
   1021 
   1022 	/* Create a new type or use the pending type.  */
   1023 	pend = is_pending_symbol (cur_fdr, ext_sh);
   1024 	if (pend == NULL)
   1025 	  {
   1026 	    t = new_type (NULL);
   1027 	    add_pending (cur_fdr, ext_sh, t);
   1028 	  }
   1029 	else
   1030 	  t = pend->t;
   1031 
   1032 	/* Do not set the tag name if it is a compiler generated tag name
   1033 	   (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
   1034 	   Alpha cc puts out an sh->iss of zero for those.  */
   1035 	if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
   1036 	  t->set_name (NULL);
   1037 	else
   1038 	  t->set_name (obconcat (&mdebugread_objfile->objfile_obstack,
   1039 				 name, (char *) NULL));
   1040 
   1041 	t->set_code (type_code);
   1042 	t->set_length (sh->value);
   1043 	t->alloc_fields (nfields);
   1044 	f = t->fields();
   1045 
   1046 	if (type_code == TYPE_CODE_ENUM)
   1047 	  {
   1048 	    int unsigned_enum = 1;
   1049 
   1050 	    /* This is a non-empty enum.  */
   1051 
   1052 	    /* DEC c89 has the number of enumerators in the sh.value field,
   1053 	       not the type length, so we have to compensate for that
   1054 	       incompatibility quirk.
   1055 	       This might do the wrong thing for an enum with one or two
   1056 	       enumerators and gcc -gcoff -fshort-enums, but these cases
   1057 	       are hopefully rare enough.
   1058 	       Alpha cc -migrate has a sh.value field of zero, we adjust
   1059 	       that too.  */
   1060 	    if (t->length () == t->num_fields ()
   1061 		|| t->length () == 0)
   1062 	      t->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT);
   1063 	    for (ext_tsym = ext_sh + external_sym_size;
   1064 		 ;
   1065 		 ext_tsym += external_sym_size)
   1066 	      {
   1067 		SYMR tsym;
   1068 		struct symbol *enum_sym;
   1069 
   1070 		(*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
   1071 
   1072 		if (tsym.st != stMember)
   1073 		  break;
   1074 
   1075 		f->set_loc_enumval (tsym.value);
   1076 		f->set_type (t);
   1077 		f->set_name (debug_info->ss + cur_fdr->issBase + tsym.iss);
   1078 		f->set_bitsize (0);
   1079 
   1080 		enum_sym = new (&mdebugread_objfile->objfile_obstack) symbol;
   1081 		enum_sym->set_linkage_name
   1082 		  (obstack_strdup (&mdebugread_objfile->objfile_obstack,
   1083 				   f->name ()));
   1084 		enum_sym->set_aclass_index (LOC_CONST);
   1085 		enum_sym->set_type (t);
   1086 		enum_sym->set_domain (VAR_DOMAIN);
   1087 		enum_sym->set_value_longest (tsym.value);
   1088 		if (enum_sym->value_longest () < 0)
   1089 		  unsigned_enum = 0;
   1090 		add_symbol (enum_sym, top_stack->cur_st, top_stack->cur_block);
   1091 
   1092 		/* Skip the stMembers that we've handled.  */
   1093 		count++;
   1094 		f++;
   1095 	      }
   1096 	    if (unsigned_enum)
   1097 	      t->set_is_unsigned (true);
   1098 	  }
   1099 	/* Make this the current type.  */
   1100 	top_stack->cur_type = t;
   1101 	top_stack->cur_field = 0;
   1102 
   1103 	/* Do not create a symbol for alpha cc unnamed structs.  */
   1104 	if (sh->iss == 0)
   1105 	  break;
   1106 
   1107 	/* gcc puts out an empty struct for an opaque struct definitions,
   1108 	   do not create a symbol for it either.  */
   1109 	if (t->num_fields () == 0)
   1110 	  {
   1111 	    t->set_is_stub (true);
   1112 	    break;
   1113 	  }
   1114 
   1115 	s = new_symbol (name);
   1116 	s->set_domain (STRUCT_DOMAIN);
   1117 	s->set_aclass_index (LOC_TYPEDEF);
   1118 	s->set_value_longest (0);
   1119 	s->set_type (t);
   1120 	add_symbol (s, top_stack->cur_st, top_stack->cur_block);
   1121 	break;
   1122 
   1123 	/* End of local variables shared by struct, union, enum, and
   1124 	   block (as yet unknown struct/union/enum) processing.  */
   1125       }
   1126 
   1127     case_stBlock_code:
   1128       found_ecoff_debugging_info = 1;
   1129       /* Beginnning of (code) block.  Value of symbol
   1130 	 is the displacement from procedure start.  */
   1131       push_parse_stack ();
   1132 
   1133       /* Do not start a new block if this is the outermost block of a
   1134 	 procedure.  This allows the LOC_BLOCK symbol to point to the
   1135 	 block with the local variables, so funcname::var works.  */
   1136       if (top_stack->blocktype == stProc
   1137 	  || top_stack->blocktype == stStaticProc)
   1138 	{
   1139 	  top_stack->blocktype = stNil;
   1140 	  break;
   1141 	}
   1142 
   1143       top_stack->blocktype = stBlock;
   1144       b = new_block (objfile, NON_FUNCTION_BLOCK, psymtab_language);
   1145       b->set_start (sh->value + top_stack->procadr);
   1146       b->set_superblock (top_stack->cur_block);
   1147       top_stack->cur_block = b;
   1148       add_block (b, top_stack->cur_st);
   1149       break;
   1150 
   1151     case stEnd:		/* end (of anything) */
   1152       if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
   1153 	{
   1154 	  /* Finished with type */
   1155 	  top_stack->cur_type = 0;
   1156 	}
   1157       else if (sh->sc == scText &&
   1158 	       (top_stack->blocktype == stProc ||
   1159 		top_stack->blocktype == stStaticProc))
   1160 	{
   1161 	  /* Finished with procedure */
   1162 	  struct blockvector *bv
   1163 	    = top_stack->cur_st->compunit ()->blockvector ();
   1164 	  struct mdebug_extra_func_info *e;
   1165 	  struct block *cblock = top_stack->cur_block;
   1166 	  struct type *ftype = top_stack->cur_type;
   1167 
   1168 	  top_stack->cur_block->set_end
   1169 	    (top_stack->cur_block->end () + sh->value); /* size */
   1170 
   1171 	  /* Make up special symbol to contain procedure specific info.  */
   1172 	  s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
   1173 	  s->set_domain (LABEL_DOMAIN);
   1174 	  s->set_aclass_index (LOC_CONST);
   1175 	  s->set_type (builtin_type (mdebugread_objfile)->builtin_void);
   1176 	  e = OBSTACK_ZALLOC (&mdebugread_objfile->objfile_obstack,
   1177 			      mdebug_extra_func_info);
   1178 	  s->set_value_bytes ((gdb_byte *) e);
   1179 	  e->numargs = top_stack->numargs;
   1180 	  e->pdr.framereg = -1;
   1181 	  add_symbol (s, top_stack->cur_st, top_stack->cur_block);
   1182 
   1183 	  /* f77 emits proc-level with address bounds==[0,0],
   1184 	     So look for such child blocks, and patch them.  */
   1185 	  for (block *b_bad : bv->blocks ())
   1186 	    {
   1187 	      if (b_bad->superblock () == cblock
   1188 		  && b_bad->start () == top_stack->procadr
   1189 		  && b_bad->end () == top_stack->procadr)
   1190 		{
   1191 		  b_bad->set_start (cblock->start ());
   1192 		  b_bad->set_end (cblock->end ());
   1193 		}
   1194 	    }
   1195 
   1196 	  if (ftype->num_fields () <= 0)
   1197 	    {
   1198 	      /* No parameter type information is recorded with the function's
   1199 		 type.  Set that from the type of the parameter symbols.  */
   1200 	      int nparams = top_stack->numargs;
   1201 	      int iparams;
   1202 
   1203 	      if (nparams > 0)
   1204 		{
   1205 		  ftype->alloc_fields (nparams);
   1206 
   1207 		  iparams = 0;
   1208 		  for (struct symbol *sym : block_iterator_range (cblock))
   1209 		    {
   1210 		      if (iparams == nparams)
   1211 			break;
   1212 
   1213 		      if (sym->is_argument ())
   1214 			{
   1215 			  ftype->field (iparams).set_type (sym->type ());
   1216 			  ftype->field (iparams).set_is_artificial (false);
   1217 			  iparams++;
   1218 			}
   1219 		    }
   1220 		}
   1221 	    }
   1222 	}
   1223       else if (sh->sc == scText && top_stack->blocktype == stBlock)
   1224 	{
   1225 	  /* End of (code) block.  The value of the symbol is the
   1226 	     displacement from the procedure`s start address of the
   1227 	     end of this block.  */
   1228 	  top_stack->cur_block->set_end (sh->value + top_stack->procadr);
   1229 	}
   1230       else if (sh->sc == scText && top_stack->blocktype == stNil)
   1231 	{
   1232 	  /* End of outermost block.  Pop parse stack and ignore.  The
   1233 	     following stEnd of stProc will take care of the block.  */
   1234 	  ;
   1235 	}
   1236       else if (sh->sc == scText && top_stack->blocktype == stFile)
   1237 	{
   1238 	  /* End of file.  Pop parse stack and ignore.  Higher
   1239 	     level code deals with this.  */
   1240 	  ;
   1241 	}
   1242       else
   1243 	complaint (_("stEnd with storage class %d not handled"), sh->sc);
   1244 
   1245       pop_parse_stack ();	/* Restore previous lexical context.  */
   1246       break;
   1247 
   1248     case stMember:		/* member of struct or union */
   1249       {
   1250 	struct field *f = &top_stack->cur_type->field (top_stack->cur_field);
   1251 	top_stack->cur_field++;
   1252 	f->set_name (name);
   1253 	f->set_loc_bitpos (sh->value);
   1254 	bitsize = 0;
   1255 	f->set_type (parse_type (cur_fd, ax, sh->index, &bitsize, bigend,
   1256 				 name));
   1257 	f->set_bitsize (bitsize);
   1258       }
   1259       break;
   1260 
   1261     case stIndirect:		/* forward declaration on Irix5 */
   1262       /* Forward declarations from Irix5 cc are handled by cross_ref,
   1263 	 skip them.  */
   1264       break;
   1265 
   1266     case stTypedef:		/* type definition */
   1267       found_ecoff_debugging_info = 1;
   1268 
   1269       /* Typedefs for forward declarations and opaque structs from alpha cc
   1270 	 are handled by cross_ref, skip them.  */
   1271       if (sh->iss == 0)
   1272 	break;
   1273 
   1274       /* Parse the type or use the pending type.  */
   1275       pend = is_pending_symbol (cur_fdr, ext_sh);
   1276       if (pend == NULL)
   1277 	{
   1278 	  t = parse_type (cur_fd, ax, sh->index, NULL, bigend, name);
   1279 	  add_pending (cur_fdr, ext_sh, t);
   1280 	}
   1281       else
   1282 	t = pend->t;
   1283 
   1284       /* Mips cc puts out a typedef with the name of the struct for forward
   1285 	 declarations.  These should not go into the symbol table and
   1286 	 TYPE_NAME should not be set for them.
   1287 	 They can't be distinguished from an intentional typedef to
   1288 	 the same name however:
   1289 	 x.h:
   1290 	 struct x { int ix; int jx; };
   1291 	 struct xx;
   1292 	 x.c:
   1293 	 typedef struct x x;
   1294 	 struct xx {int ixx; int jxx; };
   1295 	 generates a cross referencing stTypedef for x and xx.
   1296 	 The user visible effect of this is that the type of a pointer
   1297 	 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
   1298 	 The problem is fixed with alpha cc and Irix5 cc.  */
   1299 
   1300       /* However if the typedef cross references to an opaque aggregate, it
   1301 	 is safe to omit it from the symbol table.  */
   1302 
   1303       if (has_opaque_xref (cur_fdr, sh))
   1304 	break;
   1305       s = new_symbol (name);
   1306       s->set_domain (TYPE_DOMAIN);
   1307       s->set_aclass_index (LOC_TYPEDEF);
   1308       s->set_value_block (top_stack->cur_block);
   1309       s->set_type (t);
   1310       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
   1311 
   1312       /* Incomplete definitions of structs should not get a name.  */
   1313       if (s->type ()->name () == NULL
   1314 	  && (s->type ()->num_fields () != 0
   1315 	      || (s->type ()->code () != TYPE_CODE_STRUCT
   1316 		  && s->type ()->code () != TYPE_CODE_UNION)))
   1317 	{
   1318 	  if (s->type ()->code () == TYPE_CODE_PTR
   1319 	      || s->type ()->code () == TYPE_CODE_FUNC)
   1320 	    {
   1321 	      /* If we are giving a name to a type such as "pointer to
   1322 		 foo" or "function returning foo", we better not set
   1323 		 the TYPE_NAME.  If the program contains "typedef char
   1324 		 *caddr_t;", we don't want all variables of type char
   1325 		 * to print as caddr_t.  This is not just a
   1326 		 consequence of GDB's type management; CC and GCC (at
   1327 		 least through version 2.4) both output variables of
   1328 		 either type char * or caddr_t with the type
   1329 		 referring to the stTypedef symbol for caddr_t.  If a future
   1330 		 compiler cleans this up it GDB is not ready for it
   1331 		 yet, but if it becomes ready we somehow need to
   1332 		 disable this check (without breaking the PCC/GCC2.4
   1333 		 case).
   1334 
   1335 		 Sigh.
   1336 
   1337 		 Fortunately, this check seems not to be necessary
   1338 		 for anything except pointers or functions.  */
   1339 	    }
   1340 	  else
   1341 	    s->type ()->set_name (s->linkage_name ());
   1342 	}
   1343       break;
   1344 
   1345     case stFile:		/* file name */
   1346       push_parse_stack ();
   1347       top_stack->blocktype = sh->st;
   1348       break;
   1349 
   1350       /* I`ve never seen these for C */
   1351     case stRegReloc:
   1352       break;			/* register relocation */
   1353     case stForward:
   1354       break;			/* forwarding address */
   1355     case stConstant:
   1356       break;			/* constant */
   1357     default:
   1358       complaint (_("unknown symbol type 0x%x"), sh->st);
   1359       break;
   1360     }
   1361 
   1362   return count;
   1363 }
   1364 
   1365 /* Basic types.  */
   1366 
   1367 static const registry<objfile>::key<struct type *,
   1368 				    gdb::noop_deleter<struct type *>>
   1369   basic_type_data;
   1370 
   1371 static struct type *
   1372 basic_type (int bt, struct objfile *objfile)
   1373 {
   1374   struct gdbarch *gdbarch = objfile->arch ();
   1375   struct type **map_bt = basic_type_data.get (objfile);
   1376   struct type *tp;
   1377 
   1378   if (bt >= btMax)
   1379     return NULL;
   1380 
   1381   if (!map_bt)
   1382     {
   1383       map_bt = OBSTACK_CALLOC (&objfile->objfile_obstack,
   1384 			       btMax, struct type *);
   1385       basic_type_data.set (objfile, map_bt);
   1386     }
   1387 
   1388   if (map_bt[bt])
   1389     return map_bt[bt];
   1390 
   1391   type_allocator alloc (objfile, get_current_subfile ()->language);
   1392 
   1393   switch (bt)
   1394     {
   1395     case btNil:
   1396       tp = builtin_type (objfile)->builtin_void;
   1397       break;
   1398 
   1399     case btAdr:
   1400       tp = init_pointer_type (alloc, 32, "adr_32",
   1401 			      builtin_type (objfile)->builtin_void);
   1402       break;
   1403 
   1404     case btChar:
   1405       tp = init_integer_type (alloc, 8, 0, "char");
   1406       tp->set_has_no_signedness (true);
   1407       break;
   1408 
   1409     case btUChar:
   1410       tp = init_integer_type (alloc, 8, 1, "unsigned char");
   1411       break;
   1412 
   1413     case btShort:
   1414       tp = init_integer_type (alloc, 16, 0, "short");
   1415       break;
   1416 
   1417     case btUShort:
   1418       tp = init_integer_type (alloc, 16, 1, "unsigned short");
   1419       break;
   1420 
   1421     case btInt:
   1422       tp = init_integer_type (alloc, 32, 0, "int");
   1423       break;
   1424 
   1425    case btUInt:
   1426       tp = init_integer_type (alloc, 32, 1, "unsigned int");
   1427       break;
   1428 
   1429     case btLong:
   1430       tp = init_integer_type (alloc, 32, 0, "long");
   1431       break;
   1432 
   1433     case btULong:
   1434       tp = init_integer_type (alloc, 32, 1, "unsigned long");
   1435       break;
   1436 
   1437     case btFloat:
   1438       tp = init_float_type (alloc, gdbarch_float_bit (gdbarch),
   1439 			    "float", gdbarch_float_format (gdbarch));
   1440       break;
   1441 
   1442     case btDouble:
   1443       tp = init_float_type (alloc, gdbarch_double_bit (gdbarch),
   1444 			    "double", gdbarch_double_format (gdbarch));
   1445       break;
   1446 
   1447     case btComplex:
   1448       tp = init_complex_type ("complex", basic_type (btFloat, objfile));
   1449       break;
   1450 
   1451     case btDComplex:
   1452       tp = init_complex_type ("double complex", basic_type (btFloat, objfile));
   1453       break;
   1454 
   1455     case btFixedDec:
   1456       /* We use TYPE_CODE_INT to print these as integers.  Does this do any
   1457 	 good?  Would we be better off with TYPE_CODE_ERROR?  Should
   1458 	 TYPE_CODE_ERROR print things in hex if it knows the size?  */
   1459       tp = init_integer_type (alloc, gdbarch_int_bit (gdbarch), 0,
   1460 			      "fixed decimal");
   1461       break;
   1462 
   1463     case btFloatDec:
   1464       tp = alloc.new_type (TYPE_CODE_ERROR,
   1465 			   gdbarch_double_bit (gdbarch), "floating decimal");
   1466       break;
   1467 
   1468     case btString:
   1469       /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
   1470 	 FIXME.  */
   1471       tp = alloc.new_type (TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
   1472       break;
   1473 
   1474     case btVoid:
   1475       tp = builtin_type (objfile)->builtin_void;
   1476       break;
   1477 
   1478     case btLong64:
   1479       tp = init_integer_type (alloc, 64, 0, "long");
   1480       break;
   1481 
   1482     case btULong64:
   1483       tp = init_integer_type (alloc, 64, 1, "unsigned long");
   1484       break;
   1485 
   1486     case btLongLong64:
   1487       tp = init_integer_type (alloc, 64, 0, "long long");
   1488       break;
   1489 
   1490     case btULongLong64:
   1491       tp = init_integer_type (alloc, 64, 1, "unsigned long long");
   1492       break;
   1493 
   1494     case btAdr64:
   1495       tp = init_pointer_type (alloc, 64, "adr_64",
   1496 			      builtin_type (objfile)->builtin_void);
   1497       break;
   1498 
   1499     case btInt64:
   1500       tp = init_integer_type (alloc, 64, 0, "int");
   1501       break;
   1502 
   1503     case btUInt64:
   1504       tp = init_integer_type (alloc, 64, 1, "unsigned int");
   1505       break;
   1506 
   1507     default:
   1508       tp = NULL;
   1509       break;
   1510     }
   1511 
   1512   map_bt[bt] = tp;
   1513   return tp;
   1514 }
   1515 
   1516 /* Parse the type information provided in the raw AX entries for
   1517    the symbol SH.  Return the bitfield size in BS, in case.
   1518    We must byte-swap the AX entries before we use them; BIGEND says whether
   1519    they are big-endian or little-endian (from fh->fBigendian).  */
   1520 
   1521 static struct type *
   1522 parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
   1523 	    int bigend, const char *sym_name)
   1524 {
   1525   TIR t[1];
   1526   struct type *tp = 0;
   1527   enum type_code type_code = TYPE_CODE_UNDEF;
   1528 
   1529   /* Handle undefined types, they have indexNil.  */
   1530   if (aux_index == indexNil)
   1531     return basic_type (btInt, mdebugread_objfile);
   1532 
   1533   /* Handle corrupt aux indices.  */
   1534   if (aux_index >= (debug_info->fdr + fd)->caux)
   1535     {
   1536       index_complaint (sym_name);
   1537       return basic_type (btInt, mdebugread_objfile);
   1538     }
   1539   ax += aux_index;
   1540 
   1541   /* Use aux as a type information record, map its basic type.  */
   1542   (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
   1543   tp = basic_type (t->bt, mdebugread_objfile);
   1544   if (tp == NULL)
   1545     {
   1546       /* Cannot use builtin types -- build our own.  */
   1547       switch (t->bt)
   1548 	{
   1549 	case btStruct:
   1550 	  type_code = TYPE_CODE_STRUCT;
   1551 	  break;
   1552 	case btUnion:
   1553 	  type_code = TYPE_CODE_UNION;
   1554 	  break;
   1555 	case btEnum:
   1556 	  type_code = TYPE_CODE_ENUM;
   1557 	  break;
   1558 	case btRange:
   1559 	  type_code = TYPE_CODE_RANGE;
   1560 	  break;
   1561 	case btSet:
   1562 	  type_code = TYPE_CODE_SET;
   1563 	  break;
   1564 	case btIndirect:
   1565 	  /* alpha cc -migrate uses this for typedefs.  The true type will
   1566 	     be obtained by crossreferencing below.  */
   1567 	  type_code = TYPE_CODE_ERROR;
   1568 	  break;
   1569 	case btTypedef:
   1570 	  /* alpha cc uses this for typedefs.  The true type will be
   1571 	     obtained by crossreferencing below.  */
   1572 	  type_code = TYPE_CODE_ERROR;
   1573 	  break;
   1574 	default:
   1575 	  basic_type_complaint (t->bt, sym_name);
   1576 	  return basic_type (btInt, mdebugread_objfile);
   1577 	}
   1578     }
   1579 
   1580   type_allocator alloc (mdebugread_objfile, get_current_subfile ()->language);
   1581 
   1582   /* Move on to next aux.  */
   1583   ax++;
   1584 
   1585   if (t->fBitfield)
   1586     {
   1587       int width = AUX_GET_WIDTH (bigend, ax);
   1588 
   1589       /* Inhibit core dumps if TIR is corrupted.  */
   1590       if (bs == NULL)
   1591 	{
   1592 	  /* Alpha cc -migrate encodes char and unsigned char types
   1593 	     as short and unsigned short types with a field width of 8.
   1594 	     Enum types also have a field width which we ignore for now.  */
   1595 	  if (t->bt == btShort && width == 8)
   1596 	    tp = basic_type (btChar, mdebugread_objfile);
   1597 	  else if (t->bt == btUShort && width == 8)
   1598 	    tp = basic_type (btUChar, mdebugread_objfile);
   1599 	  else if (t->bt == btEnum)
   1600 	    ;
   1601 	  else
   1602 	    complaint (_("can't handle TIR fBitfield for %s"),
   1603 		       sym_name);
   1604 	}
   1605       else
   1606 	*bs = width;
   1607       ax++;
   1608     }
   1609 
   1610   /* A btIndirect entry cross references to an aux entry containing
   1611      the type.  */
   1612   if (t->bt == btIndirect)
   1613     {
   1614       RNDXR rn[1];
   1615       int rf;
   1616       FDR *xref_fh;
   1617       int xref_fd;
   1618 
   1619       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
   1620       ax++;
   1621       if (rn->rfd == 0xfff)
   1622 	{
   1623 	  rf = AUX_GET_ISYM (bigend, ax);
   1624 	  ax++;
   1625 	}
   1626       else
   1627 	rf = rn->rfd;
   1628 
   1629       if (rf == -1)
   1630 	{
   1631 	  complaint (_("unable to cross ref btIndirect for %s"), sym_name);
   1632 	  return basic_type (btInt, mdebugread_objfile);
   1633 	}
   1634       xref_fh = get_rfd (fd, rf);
   1635       xref_fd = xref_fh - debug_info->fdr;
   1636       tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
   1637 		    rn->index, NULL, xref_fh->fBigendian, sym_name);
   1638     }
   1639 
   1640   /* All these types really point to some (common) MIPS type
   1641      definition, and only the type-qualifiers fully identify
   1642      them.  We'll make the same effort at sharing.  */
   1643   if (t->bt == btStruct ||
   1644       t->bt == btUnion ||
   1645       t->bt == btEnum ||
   1646 
   1647   /* btSet (I think) implies that the name is a tag name, not a typedef
   1648      name.  This apparently is a MIPS extension for C sets.  */
   1649       t->bt == btSet)
   1650     {
   1651       const char *name;
   1652 
   1653       /* Try to cross reference this type, build new type on failure.  */
   1654       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
   1655       if (tp == NULL)
   1656 	tp = alloc.new_type (type_code, 0, NULL);
   1657 
   1658       /* DEC c89 produces cross references to qualified aggregate types,
   1659 	 dereference them.  */
   1660       while (tp->code () == TYPE_CODE_PTR
   1661 	     || tp->code () == TYPE_CODE_ARRAY)
   1662 	tp = tp->target_type ();
   1663 
   1664       /* Make sure that TYPE_CODE(tp) has an expected type code.
   1665 	 Any type may be returned from cross_ref if file indirect entries
   1666 	 are corrupted.  */
   1667       if (tp->code () != TYPE_CODE_STRUCT
   1668 	  && tp->code () != TYPE_CODE_UNION
   1669 	  && tp->code () != TYPE_CODE_ENUM)
   1670 	{
   1671 	  unexpected_type_code_complaint (sym_name);
   1672 	}
   1673       else
   1674 	{
   1675 	  /* Usually, TYPE_CODE(tp) is already type_code.  The main
   1676 	     exception is if we guessed wrong re struct/union/enum.
   1677 	     But for struct vs. union a wrong guess is harmless, so
   1678 	     don't complain().  */
   1679 	  if ((tp->code () == TYPE_CODE_ENUM
   1680 	       && type_code != TYPE_CODE_ENUM)
   1681 	      || (tp->code () != TYPE_CODE_ENUM
   1682 		  && type_code == TYPE_CODE_ENUM))
   1683 	    {
   1684 	      bad_tag_guess_complaint (sym_name);
   1685 	    }
   1686 
   1687 	  if (tp->code () != type_code)
   1688 	    {
   1689 	      tp->set_code (type_code);
   1690 	    }
   1691 
   1692 	  /* Do not set the tag name if it is a compiler generated tag name
   1693 	     (.Fxx or .xxfake or empty) for unnamed struct/union/enums.  */
   1694 	  if (name[0] == '.' || name[0] == '\0')
   1695 	    tp->set_name (NULL);
   1696 	  else if (tp->name () == NULL
   1697 		   || strcmp (tp->name (), name) != 0)
   1698 	    tp->set_name (obstack_strdup (&mdebugread_objfile->objfile_obstack,
   1699 					  name));
   1700 	}
   1701     }
   1702 
   1703   /* All these types really point to some (common) MIPS type
   1704      definition, and only the type-qualifiers fully identify
   1705      them.  We'll make the same effort at sharing.
   1706      FIXME: We are not doing any guessing on range types.  */
   1707   if (t->bt == btRange)
   1708     {
   1709       const char *name;
   1710 
   1711       /* Try to cross reference this type, build new type on failure.  */
   1712       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
   1713       if (tp == NULL)
   1714 	tp = alloc.new_type (type_code, 0, NULL);
   1715 
   1716       /* Make sure that TYPE_CODE(tp) has an expected type code.
   1717 	 Any type may be returned from cross_ref if file indirect entries
   1718 	 are corrupted.  */
   1719       if (tp->code () != TYPE_CODE_RANGE)
   1720 	{
   1721 	  unexpected_type_code_complaint (sym_name);
   1722 	}
   1723       else
   1724 	{
   1725 	  /* Usually, TYPE_CODE(tp) is already type_code.  The main
   1726 	     exception is if we guessed wrong re struct/union/enum.  */
   1727 	  if (tp->code () != type_code)
   1728 	    {
   1729 	      bad_tag_guess_complaint (sym_name);
   1730 	      tp->set_code (type_code);
   1731 	    }
   1732 	  if (tp->name () == NULL
   1733 	      || strcmp (tp->name (), name) != 0)
   1734 	    tp->set_name (obstack_strdup (&mdebugread_objfile->objfile_obstack,
   1735 					  name));
   1736 	}
   1737     }
   1738   if (t->bt == btTypedef)
   1739     {
   1740       const char *name;
   1741 
   1742       /* Try to cross reference this type, it should succeed.  */
   1743       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
   1744       if (tp == NULL)
   1745 	{
   1746 	  complaint (_("unable to cross ref btTypedef for %s"), sym_name);
   1747 	  tp = basic_type (btInt, mdebugread_objfile);
   1748 	}
   1749     }
   1750 
   1751   /* Deal with range types.  */
   1752   if (t->bt == btRange)
   1753     {
   1754       tp->set_num_fields (0);
   1755       tp->set_bounds (((struct range_bounds *)
   1756 			TYPE_ZALLOC (tp, sizeof (struct range_bounds))));
   1757       tp->bounds ()->low.set_const_val (AUX_GET_DNLOW (bigend, ax));
   1758       ax++;
   1759       tp->bounds ()->high.set_const_val (AUX_GET_DNHIGH (bigend, ax));
   1760       ax++;
   1761     }
   1762 
   1763   /* Parse all the type qualifiers now.  If there are more
   1764      than 6 the game will continue in the next aux.  */
   1765 
   1766   while (1)
   1767     {
   1768 #define PARSE_TQ(tq) \
   1769       if (t->tq != tqNil) \
   1770 	ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
   1771       else \
   1772 	break;
   1773 
   1774       PARSE_TQ (tq0);
   1775       PARSE_TQ (tq1);
   1776       PARSE_TQ (tq2);
   1777       PARSE_TQ (tq3);
   1778       PARSE_TQ (tq4);
   1779       PARSE_TQ (tq5);
   1780 #undef	PARSE_TQ
   1781 
   1782       /* mips cc 2.x and gcc never put out continued aux entries.  */
   1783       if (!t->continued)
   1784 	break;
   1785 
   1786       (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
   1787       ax++;
   1788     }
   1789 
   1790   /* Complain for illegal continuations due to corrupt aux entries.  */
   1791   if (t->continued)
   1792     complaint (_("illegal TIR continued for %s"), sym_name);
   1793 
   1794   return tp;
   1795 }
   1796 
   1797 /* Make up a complex type from a basic one.  Type is passed by
   1798    reference in TPP and side-effected as necessary.  The type
   1799    qualifier TQ says how to handle the aux symbols at AX for
   1800    the symbol SX we are currently analyzing.  BIGEND says whether
   1801    aux symbols are big-endian or little-endian.
   1802    Returns the number of aux symbols we parsed.  */
   1803 
   1804 static int
   1805 upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
   1806 	      const char *sym_name)
   1807 {
   1808   int off;
   1809   struct type *t;
   1810 
   1811   /* Used in array processing.  */
   1812   int rf, id;
   1813   FDR *fh;
   1814   struct type *range;
   1815   struct type *indx;
   1816   int lower, upper;
   1817   RNDXR rndx;
   1818 
   1819   switch (tq)
   1820     {
   1821     case tqPtr:
   1822       t = lookup_pointer_type (*tpp);
   1823       *tpp = t;
   1824       return 0;
   1825 
   1826     case tqProc:
   1827       t = lookup_function_type (*tpp);
   1828       *tpp = t;
   1829       return 0;
   1830 
   1831     case tqArray:
   1832       off = 0;
   1833 
   1834       /* Determine and record the domain type (type of index).  */
   1835       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
   1836       id = rndx.index;
   1837       rf = rndx.rfd;
   1838       if (rf == 0xfff)
   1839 	{
   1840 	  ax++;
   1841 	  rf = AUX_GET_ISYM (bigend, ax);
   1842 	  off++;
   1843 	}
   1844       fh = get_rfd (fd, rf);
   1845 
   1846       indx = parse_type (fh - debug_info->fdr,
   1847 			 debug_info->external_aux + fh->iauxBase,
   1848 			 id, NULL, bigend, sym_name);
   1849 
   1850       /* The bounds type should be an integer type, but might be anything
   1851 	 else due to corrupt aux entries.  */
   1852       if (indx->code () != TYPE_CODE_INT)
   1853 	{
   1854 	  complaint (_("illegal array index type for %s, assuming int"),
   1855 		     sym_name);
   1856 	  indx = builtin_type (mdebugread_objfile)->builtin_int;
   1857 	}
   1858 
   1859       /* Get the bounds, and create the array type.  */
   1860       ax++;
   1861       lower = AUX_GET_DNLOW (bigend, ax);
   1862       ax++;
   1863       upper = AUX_GET_DNHIGH (bigend, ax);
   1864       ax++;
   1865       rf = AUX_GET_WIDTH (bigend, ax);	/* bit size of array element */
   1866 
   1867       {
   1868 	type_allocator alloc (indx);
   1869 	range = create_static_range_type (alloc, indx, lower, upper);
   1870 
   1871 	t = create_array_type (alloc, *tpp, range);
   1872       }
   1873 
   1874       /* We used to fill in the supplied array element bitsize
   1875 	 here if the TYPE_LENGTH of the target type was zero.
   1876 	 This happens for a `pointer to an array of anonymous structs',
   1877 	 but in this case the array element bitsize is also zero,
   1878 	 so nothing is gained.
   1879 	 And we used to check the TYPE_LENGTH of the target type against
   1880 	 the supplied array element bitsize.
   1881 	 gcc causes a mismatch for `pointer to array of object',
   1882 	 since the sdb directives it uses do not have a way of
   1883 	 specifying the bitsize, but it does no harm (the
   1884 	 TYPE_LENGTH should be correct) and we should be able to
   1885 	 ignore the erroneous bitsize from the auxiliary entry safely.
   1886 	 dbx seems to ignore it too.  */
   1887 
   1888       /* TYPE_TARGET_STUB now takes care of the zero TYPE_LENGTH problem.  */
   1889       if ((*tpp)->length () == 0)
   1890 	t->set_target_is_stub (true);
   1891 
   1892       *tpp = t;
   1893       return 4 + off;
   1894 
   1895     case tqVol:
   1896       /* Volatile -- currently ignored */
   1897       return 0;
   1898 
   1899     case tqConst:
   1900       /* Const -- currently ignored */
   1901       return 0;
   1902 
   1903     default:
   1904       complaint (_("unknown type qualifier 0x%x"), tq);
   1905       return 0;
   1906     }
   1907 }
   1908 
   1909 
   1910 /* Parse a procedure descriptor record PR.  Note that the procedure is
   1911    parsed _after_ the local symbols, now we just insert the extra
   1912    information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has
   1913    already been placed in the procedure's main block.  Note also that
   1914    images that have been partially stripped (ld -x) have been deprived
   1915    of local symbols, and we have to cope with them here.  FIRST_OFF is
   1916    the offset of the first procedure for this FDR; we adjust the
   1917    address by this amount, but I don't know why.  SEARCH_SYMTAB is the symtab
   1918    to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol
   1919    in question, or NULL to use top_stack->cur_block.  */
   1920 
   1921 static void
   1922 parse_procedure (PDR *pr, struct compunit_symtab *search_symtab,
   1923 		 legacy_psymtab *pst)
   1924 {
   1925   struct symbol *s, *i;
   1926   const struct block *b;
   1927   char *sh_name;
   1928 
   1929   /* Simple rule to find files linked "-x".  */
   1930   if (cur_fdr->rss == -1)
   1931     {
   1932       if (pr->isym == -1)
   1933 	{
   1934 	  /* Static procedure at address pr->adr.  Sigh.  */
   1935 	  /* FIXME-32x64.  assuming pr->adr fits in long.  */
   1936 	  complaint (_("can't handle PDR for static proc at 0x%lx"),
   1937 		     (unsigned long) pr->adr);
   1938 	  return;
   1939 	}
   1940       else
   1941 	{
   1942 	  /* external */
   1943 	  EXTR she;
   1944 
   1945 	  (*debug_swap->swap_ext_in) (cur_bfd,
   1946 				      ((char *) debug_info->external_ext
   1947 				       + (pr->isym
   1948 					  * debug_swap->external_ext_size)),
   1949 				      &she);
   1950 	  sh_name = debug_info->ssext + she.asym.iss;
   1951 	}
   1952     }
   1953   else
   1954     {
   1955       /* Full symbols */
   1956       SYMR sh;
   1957 
   1958       (*debug_swap->swap_sym_in) (cur_bfd,
   1959 				  ((char *) debug_info->external_sym
   1960 				   + ((cur_fdr->isymBase + pr->isym)
   1961 				      * debug_swap->external_sym_size)),
   1962 				  &sh);
   1963       sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
   1964     }
   1965 
   1966   if (search_symtab != NULL)
   1967     {
   1968 #if 0
   1969       /* This loses both in the case mentioned (want a static, find a global),
   1970 	 but also if we are looking up a non-mangled name which happens to
   1971 	 match the name of a mangled function.  */
   1972       /* We have to save the cur_fdr across the call to lookup_symbol.
   1973 	 If the pdr is for a static function and if a global function with
   1974 	 the same name exists, lookup_symbol will eventually read in the symtab
   1975 	 for the global function and clobber cur_fdr.  */
   1976       FDR *save_cur_fdr = cur_fdr;
   1977 
   1978       s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0);
   1979       cur_fdr = save_cur_fdr;
   1980 #else
   1981       s = mylookup_symbol
   1982 	(sh_name,
   1983 	 search_symtab->blockvector ()->static_block (),
   1984 	 VAR_DOMAIN,
   1985 	 LOC_BLOCK);
   1986 #endif
   1987     }
   1988   else
   1989     s = mylookup_symbol (sh_name, top_stack->cur_block,
   1990 			 VAR_DOMAIN, LOC_BLOCK);
   1991 
   1992   if (s != 0)
   1993     {
   1994       b = s->value_block ();
   1995     }
   1996   else
   1997     {
   1998       complaint (_("PDR for %s, but no symbol"), sh_name);
   1999 #if 1
   2000       return;
   2001 #else
   2002 /* FIXME -- delete.  We can't do symbol allocation now; it's all done.  */
   2003       s = new_symbol (sh_name);
   2004       s->set_domain (VAR_DOMAIN);
   2005       SYMBOL_CLASS (s) = LOC_BLOCK;
   2006       /* Don't know its type, hope int is ok.  */
   2007       s->type ()
   2008 	= lookup_function_type (builtin_type (pst->objfile)->builtin_int);
   2009       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
   2010       /* Won't have symbols for this one.  */
   2011       b = new_block (2);
   2012       SYMBOL_BLOCK_VALUE (s) = b;
   2013       BLOCK_FUNCTION (b) = s;
   2014       BLOCK_START (b) = pr->adr;
   2015       /* BOUND used to be the end of procedure's text, but the
   2016 	 argument is no longer passed in.  */
   2017       BLOCK_END (b) = bound;
   2018       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
   2019       add_block (b, top_stack->cur_st);
   2020 #endif
   2021     }
   2022 
   2023   i = mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST);
   2024 
   2025   if (i)
   2026     {
   2027       struct mdebug_extra_func_info *e;
   2028 
   2029       e = (struct mdebug_extra_func_info *) i->value_bytes ();
   2030       e->pdr = *pr;
   2031 
   2032       /* GDB expects the absolute function start address for the
   2033 	 procedure descriptor in e->pdr.adr.
   2034 	 As the address in the procedure descriptor is usually relative,
   2035 	 we would have to relocate e->pdr.adr with cur_fdr->adr.
   2036 	 Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
   2037 	 in shared libraries on some systems, and on other systems
   2038 	 e->pdr.adr is sometimes offset by a bogus value.
   2039 	 To work around these problems, we replace e->pdr.adr with
   2040 	 the start address of the function.  */
   2041       e->pdr.adr = b->start ();
   2042     }
   2043 
   2044   /* It would be reasonable that functions that have been compiled
   2045      without debugging info have a btNil type for their return value,
   2046      and functions that are void and are compiled with debugging info
   2047      have btVoid.
   2048      gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
   2049      to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
   2050      case right.
   2051      The glevel field in cur_fdr could be used to determine the presence
   2052      of debugging info, but GCC doesn't always pass the -g switch settings
   2053      to the assembler and GAS doesn't set the glevel field from the -g switch
   2054      settings.
   2055      To work around these problems, the return value type of a TYPE_CODE_VOID
   2056      function is adjusted accordingly if no debugging info was found in the
   2057      compilation unit.  */
   2058 
   2059   if (processing_gcc_compilation == 0
   2060       && found_ecoff_debugging_info == 0
   2061       && s->type ()->target_type ()->code () == TYPE_CODE_VOID)
   2062     s->set_type (builtin_type (mdebugread_objfile)->nodebug_text_symbol);
   2063 }
   2064 
   2065 /* Parse the external symbol ES.  Just call parse_symbol() after
   2066    making sure we know where the aux are for it.
   2067    BIGEND says whether aux entries are big-endian or little-endian.
   2068 
   2069    This routine clobbers top_stack->cur_block and ->cur_st.  */
   2070 
   2071 static void
   2072 parse_external (EXTR *es, int bigend, const section_offsets &section_offsets,
   2073 		struct objfile *objfile)
   2074 {
   2075   union aux_ext *ax;
   2076 
   2077   if (es->ifd != ifdNil)
   2078     {
   2079       cur_fd = es->ifd;
   2080       cur_fdr = debug_info->fdr + cur_fd;
   2081       ax = debug_info->external_aux + cur_fdr->iauxBase;
   2082     }
   2083   else
   2084     {
   2085       cur_fdr = debug_info->fdr;
   2086       ax = 0;
   2087     }
   2088 
   2089   /* Reading .o files */
   2090   if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
   2091     {
   2092       const char *what;
   2093       switch (es->asym.st)
   2094 	{
   2095 	case stNil:
   2096 	  /* These are generated for static symbols in .o files,
   2097 	     ignore them.  */
   2098 	  return;
   2099 	case stStaticProc:
   2100 	case stProc:
   2101 	  what = "procedure";
   2102 	  n_undef_procs++;
   2103 	  break;
   2104 	case stGlobal:
   2105 	  what = "variable";
   2106 	  n_undef_vars++;
   2107 	  break;
   2108 	case stLabel:
   2109 	  what = "label";
   2110 	  n_undef_labels++;
   2111 	  break;
   2112 	default:
   2113 	  what = "symbol";
   2114 	  break;
   2115 	}
   2116       n_undef_symbols++;
   2117       /* FIXME:  Turn this into a complaint?  */
   2118       if (info_verbose)
   2119 	gdb_printf (_("Warning: %s `%s' is undefined (in %s)\n"),
   2120 		    what, debug_info->ssext + es->asym.iss,
   2121 		    fdr_name (cur_fdr));
   2122       return;
   2123     }
   2124 
   2125   switch (es->asym.st)
   2126     {
   2127     case stProc:
   2128     case stStaticProc:
   2129       /* There is no need to parse the external procedure symbols.
   2130 	 If they are from objects compiled without -g, their index will
   2131 	 be indexNil, and the symbol definition from the minimal symbol
   2132 	 is preferrable (yielding a function returning int instead of int).
   2133 	 If the index points to a local procedure symbol, the local
   2134 	 symbol already provides the correct type.
   2135 	 Note that the index of the external procedure symbol points
   2136 	 to the local procedure symbol in the local symbol table, and
   2137 	 _not_ to the auxiliary symbol info.  */
   2138       break;
   2139     case stGlobal:
   2140     case stLabel:
   2141       /* Global common symbols are resolved by the runtime loader,
   2142 	 ignore them.  */
   2143       if (SC_IS_COMMON (es->asym.sc))
   2144 	break;
   2145 
   2146       /* Note that the case of a symbol with indexNil must be handled
   2147 	 anyways by parse_symbol().  */
   2148       parse_symbol (&es->asym, ax, NULL,
   2149 		    bigend, section_offsets, objfile);
   2150       break;
   2151     default:
   2152       break;
   2153     }
   2154 }
   2155 
   2156 /* Parse the line number info for file descriptor FH into
   2157    GDB's linetable LT.  MIPS' encoding requires a little bit
   2158    of magic to get things out.  Note also that MIPS' line
   2159    numbers can go back and forth, apparently we can live
   2160    with that and do not need to reorder our linetables.  */
   2161 
   2162 static void
   2163 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
   2164 	     CORE_ADDR lowest_pdr_addr)
   2165 {
   2166   unsigned char *base;
   2167   int j, k;
   2168   int delta, count, lineno = 0;
   2169 
   2170   if (fh->cbLine == 0)
   2171     return;
   2172 
   2173   /* Scan by procedure descriptors.  */
   2174   k = 0;
   2175   for (j = 0; j < fh->cpd; j++, pr++)
   2176     {
   2177       CORE_ADDR l;
   2178       CORE_ADDR adr;
   2179       unsigned char *halt;
   2180 
   2181       /* No code for this one.  */
   2182       if (pr->iline == ilineNil ||
   2183 	  pr->lnLow == -1 || pr->lnHigh == -1)
   2184 	continue;
   2185 
   2186       /* Determine start and end address of compressed line bytes for
   2187 	 this procedure.  */
   2188       base = debug_info->line + fh->cbLineOffset;
   2189       if (j != (fh->cpd - 1))
   2190 	halt = base + pr[1].cbLineOffset;
   2191       else
   2192 	halt = base + fh->cbLine;
   2193       base += pr->cbLineOffset;
   2194 
   2195       adr = pr->adr - lowest_pdr_addr;
   2196 
   2197       l = adr >> 2;		/* in words */
   2198       for (lineno = pr->lnLow; base < halt;)
   2199 	{
   2200 	  count = *base & 0x0f;
   2201 	  delta = *base++ >> 4;
   2202 	  if (delta >= 8)
   2203 	    delta -= 16;
   2204 	  if (delta == -8)
   2205 	    {
   2206 	      delta = (base[0] << 8) | base[1];
   2207 	      if (delta >= 0x8000)
   2208 		delta -= 0x10000;
   2209 	      base += 2;
   2210 	    }
   2211 	  lineno += delta;	/* first delta is 0 */
   2212 
   2213 	  /* Complain if the line table overflows.  Could happen
   2214 	     with corrupt binaries.  */
   2215 	  if (lt->nitems >= maxlines)
   2216 	    {
   2217 	      complaint (_("guessed size of linetable for %s incorrectly"),
   2218 			 fdr_name (fh));
   2219 	      break;
   2220 	    }
   2221 	  k = add_line (lt, lineno, l, k);
   2222 	  l += count + 1;
   2223 	}
   2224     }
   2225 }
   2226 
   2227 static void
   2229 function_outside_compilation_unit_complaint (const char *arg1)
   2230 {
   2231   complaint (_("function `%s' appears to be defined "
   2232 	       "outside of all compilation units"),
   2233 	     arg1);
   2234 }
   2235 
   2236 /* Use the STORAGE_CLASS to compute which section the given symbol
   2237    belongs to, and then records this new minimal symbol.  */
   2238 
   2239 static void
   2240 record_minimal_symbol (minimal_symbol_reader &reader,
   2241 		       const char *name, const unrelocated_addr address,
   2242 		       enum minimal_symbol_type ms_type, int storage_class,
   2243 		       struct objfile *objfile)
   2244 {
   2245   int section;
   2246 
   2247   switch (storage_class)
   2248     {
   2249       case scText:
   2250 	section = SECT_OFF_TEXT (objfile);
   2251 	break;
   2252       case scData:
   2253 	section = SECT_OFF_DATA (objfile);
   2254 	break;
   2255       case scBss:
   2256 	section = SECT_OFF_BSS (objfile);
   2257 	break;
   2258       case scSData:
   2259 	section = get_section_index (objfile, ".sdata");
   2260 	break;
   2261       case scSBss:
   2262 	section = get_section_index (objfile, ".sbss");
   2263 	break;
   2264       case scRData:
   2265 	section = get_section_index (objfile, ".rdata");
   2266 	break;
   2267       case scInit:
   2268 	section = get_section_index (objfile, ".init");
   2269 	break;
   2270       case scXData:
   2271 	section = get_section_index (objfile, ".xdata");
   2272 	break;
   2273       case scPData:
   2274 	section = get_section_index (objfile, ".pdata");
   2275 	break;
   2276       case scFini:
   2277 	section = get_section_index (objfile, ".fini");
   2278 	break;
   2279       case scRConst:
   2280 	section = get_section_index (objfile, ".rconst");
   2281 	break;
   2282 #ifdef scTlsData
   2283       case scTlsData:
   2284 	section = get_section_index (objfile, ".tlsdata");
   2285 	break;
   2286 #endif
   2287 #ifdef scTlsBss
   2288       case scTlsBss:
   2289 	section = get_section_index (objfile, ".tlsbss");
   2290 	break;
   2291 #endif
   2292       default:
   2293 	/* This kind of symbol is not associated to a section.  */
   2294 	section = -1;
   2295     }
   2296 
   2297   reader.record_with_info (name, address, ms_type, section);
   2298 }
   2299 
   2300 /* Master parsing procedure for first-pass reading of file symbols
   2301    into a partial_symtab.  */
   2302 
   2303 static void
   2304 parse_partial_symbols (minimal_symbol_reader &reader,
   2305 		       psymtab_storage *partial_symtabs,
   2306 		       struct objfile *objfile)
   2307 {
   2308   struct gdbarch *gdbarch = objfile->arch ();
   2309   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   2310   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
   2311   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
   2312   void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
   2313   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
   2314   void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
   2315   int f_idx, s_idx;
   2316   HDRR *hdr = &debug_info->symbolic_header;
   2317   /* Running pointers */
   2318   FDR *fh;
   2319   char *ext_out;
   2320   char *ext_out_end;
   2321   EXTR *ext_in;
   2322   EXTR *ext_in_end;
   2323   SYMR sh;
   2324   legacy_psymtab *pst;
   2325   int textlow_not_set = 1;
   2326 
   2327   /* List of current psymtab's include files.  */
   2328   const char **psymtab_include_list;
   2329   int includes_allocated;
   2330   int includes_used;
   2331   EXTR *extern_tab;
   2332   struct pst_map *fdr_to_pst;
   2333   /* Index within current psymtab dependency list.  */
   2334   legacy_psymtab **dependency_list;
   2335   int dependencies_used, dependencies_allocated;
   2336   char *name;
   2337   enum language prev_language;
   2338   asection *text_sect;
   2339   int relocatable = 0;
   2340 
   2341   /* Irix 5.2 shared libraries have a fh->adr field of zero, but
   2342      the shared libraries are prelinked at a high memory address.
   2343      We have to adjust the start address of the object file for this case,
   2344      by setting it to the start address of the first procedure in the file.
   2345      But we should do no adjustments if we are debugging a .o file, where
   2346      the text section (and fh->adr) really starts at zero.  */
   2347   text_sect = bfd_get_section_by_name (cur_bfd, ".text");
   2348   if (text_sect != NULL
   2349       && (bfd_section_flags (text_sect) & SEC_RELOC))
   2350     relocatable = 1;
   2351 
   2352   extern_tab = XOBNEWVEC (&objfile->objfile_obstack, EXTR, hdr->iextMax);
   2353 
   2354   includes_allocated = 30;
   2355   includes_used = 0;
   2356   psymtab_include_list = (const char **) alloca (includes_allocated *
   2357 						 sizeof (const char *));
   2358   next_symbol_text_func = mdebug_next_symbol_text;
   2359 
   2360   dependencies_allocated = 30;
   2361   dependencies_used = 0;
   2362   dependency_list =
   2363     (legacy_psymtab **) alloca (dependencies_allocated *
   2364 				sizeof (legacy_psymtab *));
   2365 
   2366   set_last_source_file (NULL);
   2367 
   2368   /*
   2369    * Big plan:
   2370    *
   2371    * Only parse the Local and External symbols, and the Relative FDR.
   2372    * Fixup enough of the loader symtab to be able to use it.
   2373    * Allocate space only for the file's portions we need to
   2374    * look at.  (XXX)
   2375    */
   2376 
   2377   max_gdbinfo = 0;
   2378   max_glevel = MIN_GLEVEL;
   2379 
   2380   /* Allocate the map FDR -> PST.
   2381      Minor hack: -O3 images might claim some global data belongs
   2382      to FDR -1.  We`ll go along with that.  */
   2383   std::vector<struct pst_map> fdr_to_pst_holder (hdr->ifdMax + 1);
   2384   fdr_to_pst = fdr_to_pst_holder.data ();
   2385   fdr_to_pst++;
   2386   {
   2387     legacy_psymtab *new_pst = new_psymtab ("", partial_symtabs, objfile);
   2388 
   2389     fdr_to_pst[-1].pst = new_pst;
   2390     FDR_IDX (new_pst) = -1;
   2391   }
   2392 
   2393   /* Allocate the global pending list.  */
   2394   pending_list = XOBNEWVEC (&objfile->objfile_obstack, mdebug_pending *,
   2395 			    hdr->ifdMax);
   2396   memset (pending_list, 0,
   2397 	  hdr->ifdMax * sizeof (struct mdebug_pending *));
   2398 
   2399   /* Pass 0 over external syms: swap them in.  */
   2400   gdb::def_vector<EXTR> ext_block (hdr->iextMax);
   2401 
   2402   ext_out = (char *) debug_info->external_ext;
   2403   ext_out_end = ext_out + hdr->iextMax * external_ext_size;
   2404   ext_in = ext_block.data ();
   2405   for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
   2406     (*swap_ext_in) (cur_bfd, ext_out, ext_in);
   2407 
   2408   /* Pass 1 over external syms: Presize and partition the list.  */
   2409   ext_in = ext_block.data ();
   2410   ext_in_end = ext_in + hdr->iextMax;
   2411   for (; ext_in < ext_in_end; ext_in++)
   2412     {
   2413       /* See calls to complain below.  */
   2414       if (ext_in->ifd >= -1
   2415 	  && ext_in->ifd < hdr->ifdMax
   2416 	  && ext_in->asym.iss >= 0
   2417 	  && ext_in->asym.iss < hdr->issExtMax)
   2418 	fdr_to_pst[ext_in->ifd].n_globals++;
   2419     }
   2420 
   2421   /* Pass 1.5 over files:  partition out global symbol space.  */
   2422   s_idx = 0;
   2423   for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
   2424     {
   2425       fdr_to_pst[f_idx].globals_offset = s_idx;
   2426       s_idx += fdr_to_pst[f_idx].n_globals;
   2427       fdr_to_pst[f_idx].n_globals = 0;
   2428     }
   2429 
   2430   /* ECOFF in ELF:
   2431 
   2432      For ECOFF in ELF, we skip the creation of the minimal symbols.
   2433      The ECOFF symbols should be a subset of the Elf symbols, and the
   2434      section information of the elf symbols will be more accurate.
   2435      FIXME!  What about Irix 5's native linker?
   2436 
   2437      By default, Elf sections which don't exist in ECOFF
   2438      get put in ECOFF's absolute section by the gnu linker.
   2439      Since absolute sections don't get relocated, we
   2440      end up calculating an address different from that of
   2441      the symbol's minimal symbol (created earlier from the
   2442      Elf symtab).
   2443 
   2444      To fix this, either :
   2445      1) don't create the duplicate symbol
   2446      (assumes ECOFF symtab is a subset of the ELF symtab;
   2447      assumes no side-effects result from ignoring ECOFF symbol)
   2448      2) create it, only if lookup for existing symbol in ELF's minimal
   2449      symbols fails
   2450      (inefficient;
   2451      assumes no side-effects result from ignoring ECOFF symbol)
   2452      3) create it, but lookup ELF's minimal symbol and use it's section
   2453      during relocation, then modify "uniquify" phase to merge and
   2454      eliminate the duplicate symbol
   2455      (highly inefficient)
   2456 
   2457      I've implemented #1 here...
   2458      Skip the creation of the minimal symbols based on the ECOFF
   2459      symbol table.  */
   2460 
   2461   /* Pass 2 over external syms: fill in external symbols.  */
   2462   ext_in = ext_block.data ();
   2463   ext_in_end = ext_in + hdr->iextMax;
   2464   for (; ext_in < ext_in_end; ext_in++)
   2465     {
   2466       enum minimal_symbol_type ms_type = mst_text;
   2467       unrelocated_addr svalue = unrelocated_addr (ext_in->asym.value);
   2468 
   2469       /* The Irix 5 native tools seem to sometimes generate bogus
   2470 	 external symbols.  */
   2471       if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
   2472 	{
   2473 	  complaint (_("bad ifd for external symbol: %d (max %ld)"),
   2474 		     ext_in->ifd, hdr->ifdMax);
   2475 	  continue;
   2476 	}
   2477       if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
   2478 	{
   2479 	  complaint (_("bad iss for external symbol: %ld (max %ld)"),
   2480 		     ext_in->asym.iss, hdr->issExtMax);
   2481 	  continue;
   2482 	}
   2483 
   2484       extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
   2485 		 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
   2486 
   2487 
   2488       if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
   2489 	continue;
   2490 
   2491 
   2492       /* Pass 3 over files, over local syms: fill in static symbols.  */
   2493       name = debug_info->ssext + ext_in->asym.iss;
   2494 
   2495       /* Process ECOFF Symbol Types and Storage Classes.  */
   2496       switch (ext_in->asym.st)
   2497 	{
   2498 	case stProc:
   2499 	  /* Beginnning of Procedure */
   2500 	  break;
   2501 	case stStaticProc:
   2502 	  /* Load time only static procs */
   2503 	  ms_type = mst_file_text;
   2504 	  break;
   2505 	case stGlobal:
   2506 	  /* External symbol */
   2507 	  if (SC_IS_COMMON (ext_in->asym.sc))
   2508 	    {
   2509 	      /* The value of a common symbol is its size, not its address.
   2510 		 Ignore it.  */
   2511 	      continue;
   2512 	    }
   2513 	  else if (SC_IS_DATA (ext_in->asym.sc))
   2514 	    {
   2515 	      ms_type = mst_data;
   2516 	    }
   2517 	  else if (SC_IS_BSS (ext_in->asym.sc))
   2518 	    {
   2519 	      ms_type = mst_bss;
   2520 	    }
   2521 	  else if (SC_IS_SBSS (ext_in->asym.sc))
   2522 	    {
   2523 	      ms_type = mst_bss;
   2524 	    }
   2525 	  else
   2526 	    ms_type = mst_abs;
   2527 	  break;
   2528 	case stLabel:
   2529 	  /* Label */
   2530 
   2531 	  /* On certain platforms, some extra label symbols can be
   2532 	     generated by the linker.  One possible usage for this kind
   2533 	     of symbols is to represent the address of the beginning of a
   2534 	     given section.  For instance, on Tru64 5.1, the address of
   2535 	     the _ftext label is the start address of the .text section.
   2536 
   2537 	     The storage class of these symbols is usually directly
   2538 	     related to the section to which the symbol refers.  For
   2539 	     instance, on Tru64 5.1, the storage class for the _fdata
   2540 	     label is scData, referring to the .data section.
   2541 
   2542 	     It is actually possible that the section associated to the
   2543 	     storage class of the label does not exist.  On True64 5.1
   2544 	     for instance, the libm.so shared library does not contain
   2545 	     any .data section, although it contains a _fpdata label
   2546 	     which storage class is scData...  Since these symbols are
   2547 	     usually useless for the debugger user anyway, we just
   2548 	     discard these symbols.  */
   2549 
   2550 	  if (SC_IS_TEXT (ext_in->asym.sc))
   2551 	    {
   2552 	      if (objfile->sect_index_text == -1)
   2553 		continue;
   2554 
   2555 	      ms_type = mst_file_text;
   2556 	    }
   2557 	  else if (SC_IS_DATA (ext_in->asym.sc))
   2558 	    {
   2559 	      if (objfile->sect_index_data == -1)
   2560 		continue;
   2561 
   2562 	      ms_type = mst_file_data;
   2563 	    }
   2564 	  else if (SC_IS_BSS (ext_in->asym.sc))
   2565 	    {
   2566 	      if (objfile->sect_index_bss == -1)
   2567 		continue;
   2568 
   2569 	      ms_type = mst_file_bss;
   2570 	    }
   2571 	  else if (SC_IS_SBSS (ext_in->asym.sc))
   2572 	    {
   2573 	      const int sbss_sect_index = get_section_index (objfile, ".sbss");
   2574 
   2575 	      if (sbss_sect_index == -1)
   2576 		continue;
   2577 
   2578 	      ms_type = mst_file_bss;
   2579 	    }
   2580 	  else
   2581 	    ms_type = mst_abs;
   2582 	  break;
   2583 	case stLocal:
   2584 	case stNil:
   2585 	  /* The alpha has the section start addresses in stLocal symbols
   2586 	     whose name starts with a `.'.  Skip those but complain for all
   2587 	     other stLocal symbols.
   2588 	     Irix6 puts the section start addresses in stNil symbols, skip
   2589 	     those too.  */
   2590 	  if (name[0] == '.')
   2591 	    continue;
   2592 	  [[fallthrough]];
   2593 	default:
   2594 	  ms_type = mst_unknown;
   2595 	  unknown_ext_complaint (name);
   2596 	}
   2597       if (!ECOFF_IN_ELF (cur_bfd))
   2598 	record_minimal_symbol (reader, name, svalue, ms_type, ext_in->asym.sc,
   2599 			       objfile);
   2600     }
   2601 
   2602   /* Pass 3 over files, over local syms: fill in static symbols.  */
   2603   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
   2604     {
   2605       legacy_psymtab *save_pst;
   2606       EXTR *ext_ptr;
   2607       unrelocated_addr textlow;
   2608 
   2609       cur_fdr = fh = debug_info->fdr + f_idx;
   2610 
   2611       if (fh->csym == 0)
   2612 	{
   2613 	  fdr_to_pst[f_idx].pst = NULL;
   2614 	  continue;
   2615 	}
   2616 
   2617       /* Determine the start address for this object file from the
   2618 	 file header and relocate it, except for Irix 5.2 zero fh->adr.  */
   2619       if (fh->cpd)
   2620 	textlow = unrelocated_addr (fh->adr);
   2621       else
   2622 	textlow = unrelocated_addr (0);
   2623       pst = new legacy_psymtab (fdr_name (fh), partial_symtabs,
   2624 				objfile->per_bfd, textlow);
   2625       pst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, md_symloc);
   2626       memset (pst->read_symtab_private, 0, sizeof (struct md_symloc));
   2627 
   2628       save_pst = pst;
   2629       FDR_IDX (pst) = f_idx;
   2630       CUR_BFD (pst) = cur_bfd;
   2631       DEBUG_SWAP (pst) = debug_swap;
   2632       DEBUG_INFO (pst) = debug_info;
   2633       PENDING_LIST (pst) = pending_list;
   2634 
   2635       /* The way to turn this into a symtab is to call...  */
   2636       pst->legacy_read_symtab = mdebug_read_symtab;
   2637       pst->legacy_expand_psymtab = mdebug_expand_psymtab;
   2638 
   2639       /* Set up language for the pst.
   2640 	 The language from the FDR is used if it is unambiguous (e.g. cfront
   2641 	 with native cc and g++ will set the language to C).
   2642 	 Otherwise we have to deduce the language from the filename.
   2643 	 Native ecoff has every header file in a separate FDR, so
   2644 	 deduce_language_from_filename will return language_unknown for
   2645 	 a header file, which is not what we want.
   2646 	 But the FDRs for the header files are after the FDR for the source
   2647 	 file, so we can assign the language of the source file to the
   2648 	 following header files.  Then we save the language in the private
   2649 	 pst data so that we can reuse it when building symtabs.  */
   2650       prev_language = psymtab_language;
   2651 
   2652       switch (fh->lang)
   2653 	{
   2654 	case langCplusplusV2:
   2655 	  psymtab_language = language_cplus;
   2656 	  break;
   2657 	default:
   2658 	  psymtab_language = deduce_language_from_filename (fdr_name (fh));
   2659 	  break;
   2660 	}
   2661       if (psymtab_language == language_unknown)
   2662 	psymtab_language = prev_language;
   2663       PST_PRIVATE (pst)->pst_language = psymtab_language;
   2664 
   2665       pst->set_text_high (pst->unrelocated_text_low ());
   2666 
   2667       /* For stabs-in-ecoff files, the second symbol must be @stab.
   2668 	 This symbol is emitted by mips-tfile to signal that the
   2669 	 current object file uses encapsulated stabs instead of mips
   2670 	 ecoff for local symbols.  (It is the second symbol because
   2671 	 the first symbol is the stFile used to signal the start of a
   2672 	 file).  */
   2673       processing_gcc_compilation = 0;
   2674       if (fh->csym >= 2)
   2675 	{
   2676 	  (*swap_sym_in) (cur_bfd,
   2677 			  ((char *) debug_info->external_sym
   2678 			   + (fh->isymBase + 1) * external_sym_size),
   2679 			  &sh);
   2680 	  if (strcmp (debug_info->ss + fh->issBase + sh.iss,
   2681 		      stabs_symbol) == 0)
   2682 	    processing_gcc_compilation = 2;
   2683 	}
   2684 
   2685       if (processing_gcc_compilation != 0)
   2686 	{
   2687 	  for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
   2688 	    {
   2689 	      int type_code;
   2690 	      const char *namestring;
   2691 
   2692 	      (*swap_sym_in) (cur_bfd,
   2693 			      (((char *) debug_info->external_sym)
   2694 			    + (fh->isymBase + cur_sdx) * external_sym_size),
   2695 			      &sh);
   2696 	      type_code = ECOFF_UNMARK_STAB (sh.index);
   2697 	      if (!ECOFF_IS_STAB (&sh))
   2698 		{
   2699 		  if (sh.st == stProc || sh.st == stStaticProc)
   2700 		    {
   2701 		      unrelocated_addr procaddr;
   2702 		      long isym;
   2703 
   2704 		      if (sh.st == stStaticProc)
   2705 			{
   2706 			  namestring = debug_info->ss + fh->issBase + sh.iss;
   2707 			  record_minimal_symbol (reader, namestring,
   2708 						 unrelocated_addr (sh.value),
   2709 						 mst_file_text, sh.sc,
   2710 						 objfile);
   2711 			}
   2712 		      procaddr = unrelocated_addr (sh.value);
   2713 
   2714 		      isym = AUX_GET_ISYM (fh->fBigendian,
   2715 					   (debug_info->external_aux
   2716 					    + fh->iauxBase
   2717 					    + sh.index));
   2718 		      (*swap_sym_in) (cur_bfd,
   2719 				      ((char *) debug_info->external_sym
   2720 				       + ((fh->isymBase + isym - 1)
   2721 					  * external_sym_size)),
   2722 				      &sh);
   2723 		      if (sh.st == stEnd)
   2724 			{
   2725 			  unrelocated_addr high
   2726 			    = unrelocated_addr (CORE_ADDR (procaddr)
   2727 						+ sh.value);
   2728 
   2729 			  /* Kludge for Irix 5.2 zero fh->adr.  */
   2730 			  if (!relocatable
   2731 			      && (!pst->text_low_valid
   2732 				  || procaddr < pst->unrelocated_text_low ()))
   2733 			    pst->set_text_low (procaddr);
   2734 			  if (high > pst->unrelocated_text_high ())
   2735 			    pst->set_text_high (high);
   2736 			}
   2737 		    }
   2738 		  else if (sh.st == stStatic)
   2739 		    {
   2740 		      switch (sh.sc)
   2741 			{
   2742 			case scUndefined:
   2743 			case scSUndefined:
   2744 			case scNil:
   2745 			case scAbs:
   2746 			  break;
   2747 
   2748 			case scData:
   2749 			case scSData:
   2750 			case scRData:
   2751 			case scPData:
   2752 			case scXData:
   2753 			  namestring = debug_info->ss + fh->issBase + sh.iss;
   2754 			  record_minimal_symbol (reader, namestring,
   2755 						 unrelocated_addr (sh.value),
   2756 						 mst_file_data, sh.sc,
   2757 						 objfile);
   2758 			  break;
   2759 
   2760 			default:
   2761 			  /* FIXME!  Shouldn't this use cases for bss,
   2762 			     then have the default be abs?  */
   2763 			  namestring = debug_info->ss + fh->issBase + sh.iss;
   2764 			  record_minimal_symbol (reader, namestring,
   2765 						 unrelocated_addr (sh.value),
   2766 						 mst_file_bss, sh.sc,
   2767 						 objfile);
   2768 			  break;
   2769 			}
   2770 		    }
   2771 		  continue;
   2772 		}
   2773 	      /* Handle stabs continuation.  */
   2774 	      {
   2775 		char *stabstring = debug_info->ss + fh->issBase + sh.iss;
   2776 		/* If we need to heap-allocate STABSTRING, this owns
   2777 		   it.  */
   2778 		gdb::unique_xmalloc_ptr<char> stabstring_storage;
   2779 		int len = strlen (stabstring);
   2780 
   2781 		while (stabstring[len - 1] == '\\')
   2782 		  {
   2783 		    SYMR sh2;
   2784 		    char *stabstring1 = stabstring;
   2785 		    char *stabstring2;
   2786 		    int len2;
   2787 
   2788 		    /* Ignore continuation char from 1st string.  */
   2789 		    len--;
   2790 
   2791 		    /* Read next stabstring.  */
   2792 		    cur_sdx++;
   2793 		    (*swap_sym_in) (cur_bfd,
   2794 				    (((char *) debug_info->external_sym)
   2795 				     + (fh->isymBase + cur_sdx)
   2796 				     * external_sym_size),
   2797 				    &sh2);
   2798 		    stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
   2799 		    len2 = strlen (stabstring2);
   2800 
   2801 		    /* Concatenate stabstring2 with stabstring1.  */
   2802 		    if (stabstring_storage != nullptr)
   2803 		      {
   2804 			stabstring_storage.reset
   2805 			  ((char *) xrealloc (stabstring_storage.release (),
   2806 					      len + len2 + 1));
   2807 			stabstring = stabstring_storage.get ();
   2808 		      }
   2809 		    else
   2810 		      {
   2811 			stabstring_storage.reset
   2812 			  ((char *) xmalloc (len + len2 + 1));
   2813 			stabstring = stabstring_storage.get ();
   2814 			strcpy (stabstring, stabstring1);
   2815 		      }
   2816 		    strcpy (stabstring + len, stabstring2);
   2817 		    len += len2;
   2818 		  }
   2819 
   2820 		switch (type_code)
   2821 		  {
   2822 		    const char *p;
   2823 
   2824 		    /* Standard, external, non-debugger, symbols.  */
   2825 
   2826 		  case N_TEXT | N_EXT:
   2827 		  case N_NBTEXT | N_EXT:
   2828 		    goto record_it;
   2829 
   2830 		  case N_DATA | N_EXT:
   2831 		  case N_NBDATA | N_EXT:
   2832 		    goto record_it;
   2833 
   2834 		  case N_BSS:
   2835 		  case N_BSS | N_EXT:
   2836 		  case N_NBBSS | N_EXT:
   2837 		  case N_SETV | N_EXT:		/* FIXME, is this in BSS?  */
   2838 		    goto record_it;
   2839 
   2840 		  case N_ABS | N_EXT:
   2841 		  record_it:
   2842 		    continue;
   2843 
   2844 		  /* Standard, local, non-debugger, symbols.  */
   2845 
   2846 		  case N_NBTEXT:
   2847 
   2848 		    /* We need to be able to deal with both N_FN or
   2849 		       N_TEXT, because we have no way of knowing
   2850 		       whether the sys-supplied ld or GNU ld was used
   2851 		       to make the executable.  Sequents throw in
   2852 		       another wrinkle -- they renumbered N_FN.  */
   2853 
   2854 		  case N_FN:
   2855 		  case N_FN_SEQ:
   2856 		  case N_TEXT:
   2857 		    continue;
   2858 
   2859 		  case N_DATA:
   2860 		    goto record_it;
   2861 
   2862 		  case N_UNDF | N_EXT:
   2863 		    continue;		/* Just undefined, not COMMON.  */
   2864 
   2865 		  case N_UNDF:
   2866 		    continue;
   2867 
   2868 		    /* Lots of symbol types we can just ignore.  */
   2869 
   2870 		  case N_ABS:
   2871 		  case N_NBDATA:
   2872 		  case N_NBBSS:
   2873 		    continue;
   2874 
   2875 		    /* Keep going . . .  */
   2876 
   2877 		    /*
   2878 		     * Special symbol types for GNU
   2879 		     */
   2880 		  case N_INDR:
   2881 		  case N_INDR | N_EXT:
   2882 		  case N_SETA:
   2883 		  case N_SETA | N_EXT:
   2884 		  case N_SETT:
   2885 		  case N_SETT | N_EXT:
   2886 		  case N_SETD:
   2887 		  case N_SETD | N_EXT:
   2888 		  case N_SETB:
   2889 		  case N_SETB | N_EXT:
   2890 		  case N_SETV:
   2891 		    continue;
   2892 
   2893 		    /*
   2894 		     * Debugger symbols
   2895 		     */
   2896 
   2897 		  case N_SO:
   2898 		    {
   2899 		      static int prev_so_symnum = -10;
   2900 		      const char *basename;
   2901 
   2902 		      /* A zero value is probably an indication for the
   2903 			 SunPRO 3.0 compiler.  stabs_end_psymtab explicitly tests
   2904 			 for zero, so don't relocate it.  */
   2905 
   2906 		      if (sh.value == 0
   2907 			  && gdbarch_sofun_address_maybe_missing (gdbarch))
   2908 			textlow_not_set = 1;
   2909 		      else
   2910 			textlow_not_set = 0;
   2911 
   2912 		      if (prev_so_symnum != symnum - 1)
   2913 			{		/* Here if prev stab wasn't N_SO.  */
   2914 			  if (pst)
   2915 			    {
   2916 			      pst = (legacy_psymtab *) 0;
   2917 			      includes_used = 0;
   2918 			      dependencies_used = 0;
   2919 			    }
   2920 			}
   2921 
   2922 		      prev_so_symnum = symnum;
   2923 
   2924 		      /* End the current partial symtab and start a
   2925 			 new one.  */
   2926 
   2927 		      /* SET_NAMESTRING ();*/
   2928 		      namestring = stabstring;
   2929 
   2930 		      /* Null name means end of .o file.  Don't start a new
   2931 			 one.  */
   2932 		      if (*namestring == '\000')
   2933 			continue;
   2934 
   2935 		      /* Some compilers (including gcc) emit a pair of
   2936 			 initial N_SOs.  The first one is a directory name;
   2937 			 the second the file name.  If pst exists, is
   2938 			 empty, and has a filename ending in '/', we assume
   2939 			 the previous N_SO was a directory name.  */
   2940 		      basename = lbasename (namestring);
   2941 		      if (basename != namestring && *basename == '\000')
   2942 			continue;		/* Simply ignore directory
   2943 						   name SOs.  */
   2944 
   2945 		      /* Some other compilers (C++ ones in particular) emit
   2946 			 useless SOs for non-existant .c files.  We ignore
   2947 			 all subsequent SOs that immediately follow the
   2948 			 first.  */
   2949 
   2950 		      if (!pst)
   2951 			pst = save_pst;
   2952 		      continue;
   2953 		    }
   2954 
   2955 		  case N_BINCL:
   2956 		    continue;
   2957 
   2958 		  case N_SOL:
   2959 		    {
   2960 		      enum language tmp_language;
   2961 
   2962 		      /* Mark down an include file in the current psymtab.  */
   2963 
   2964 		      /* SET_NAMESTRING (); */
   2965 		      namestring = stabstring;
   2966 
   2967 		      tmp_language
   2968 			= deduce_language_from_filename (namestring);
   2969 
   2970 		      /* Only change the psymtab's language if we've
   2971 			 learned something useful (eg. tmp_language is not
   2972 			 language_unknown).  In addition, to match what
   2973 			 start_subfile does, never change from C++ to
   2974 			 C.  */
   2975 		      if (tmp_language != language_unknown
   2976 			  && (tmp_language != language_c
   2977 			      || psymtab_language != language_cplus))
   2978 			psymtab_language = tmp_language;
   2979 
   2980 		      /* In C++, one may expect the same filename to come
   2981 			 round many times, when code is coming alternately
   2982 			 from the main file and from inline functions in
   2983 			 other files.  So I check to see if this is a file
   2984 			 we've seen before -- either the main source file,
   2985 			 or a previously included file.
   2986 
   2987 			 This seems to be a lot of time to be spending on
   2988 			 N_SOL, but things like "break c-exp.y:435" need to
   2989 			 work (I suppose the psymtab_include_list could be
   2990 			 hashed or put in a binary tree, if profiling shows
   2991 			 this is a major hog).  */
   2992 		      if (pst && filename_cmp (namestring, pst->filename) == 0)
   2993 			continue;
   2994 
   2995 		      {
   2996 			int i;
   2997 
   2998 			for (i = 0; i < includes_used; i++)
   2999 			  if (filename_cmp (namestring,
   3000 					    psymtab_include_list[i]) == 0)
   3001 			    {
   3002 			      i = -1;
   3003 			      break;
   3004 			    }
   3005 			if (i == -1)
   3006 			  continue;
   3007 		      }
   3008 
   3009 		      psymtab_include_list[includes_used++] = namestring;
   3010 		      if (includes_used >= includes_allocated)
   3011 			{
   3012 			  const char **orig = psymtab_include_list;
   3013 
   3014 			  psymtab_include_list = (const char **)
   3015 			    alloca ((includes_allocated *= 2) *
   3016 				    sizeof (const char *));
   3017 			  memcpy (psymtab_include_list, orig,
   3018 				  includes_used * sizeof (const char *));
   3019 			}
   3020 		      continue;
   3021 		    }
   3022 		  case N_LSYM:	    /* Typedef or automatic variable.  */
   3023 		  case N_STSYM:	    /* Data seg var -- static  */
   3024 		  case N_LCSYM:	    /* BSS      "  */
   3025 		  case N_ROSYM:	    /* Read-only data seg var -- static.  */
   3026 		  case N_NBSTS:	    /* Gould nobase.  */
   3027 		  case N_NBLCS:	    /* symbols.  */
   3028 		  case N_FUN:
   3029 		  case N_GSYM:	    /* Global (extern) variable; can be
   3030 				       data or bss (sigh FIXME).  */
   3031 
   3032 		    /* Following may probably be ignored; I'll leave them here
   3033 		       for now (until I do Pascal and Modula 2 extensions).  */
   3034 
   3035 		  case N_PC:	    /* I may or may not need this; I
   3036 				       suspect not.  */
   3037 		  case N_M2C:	    /* I suspect that I can ignore this
   3038 				       here.  */
   3039 		  case N_SCOPE:	    /* Same.  */
   3040 
   3041 		    /*    SET_NAMESTRING (); */
   3042 		    namestring = stabstring;
   3043 		    p = (char *) strchr (namestring, ':');
   3044 		    if (!p)
   3045 		      continue;	    /* Not a debugging symbol.  */
   3046 
   3047 
   3048 
   3049 		    /* Main processing section for debugging symbols which
   3050 		       the initial read through the symbol tables needs to
   3051 		       worry about.  If we reach this point, the symbol
   3052 		       which we are considering is definitely one we are
   3053 		       interested in.  p must also contain the (valid)
   3054 		       index into the namestring which indicates the
   3055 		       debugging type symbol.  */
   3056 
   3057 		    switch (p[1])
   3058 		      {
   3059 		      case 'S':
   3060 			pst->add_psymbol (std::string_view (namestring,
   3061 							    p - namestring),
   3062 					  true, VAR_DOMAIN, LOC_STATIC,
   3063 					  SECT_OFF_DATA (objfile),
   3064 					  psymbol_placement::STATIC,
   3065 					  unrelocated_addr (sh.value),
   3066 					  psymtab_language,
   3067 					  partial_symtabs, objfile);
   3068 			continue;
   3069 		      case 'G':
   3070 			/* The addresses in these entries are reported
   3071 			   to be wrong.  See the code that reads 'G's
   3072 			   for symtabs.  */
   3073 			pst->add_psymbol (std::string_view (namestring,
   3074 							    p - namestring),
   3075 					  true, VAR_DOMAIN, LOC_STATIC,
   3076 					  SECT_OFF_DATA (objfile),
   3077 					  psymbol_placement::GLOBAL,
   3078 					  unrelocated_addr (sh.value),
   3079 					  psymtab_language,
   3080 					  partial_symtabs, objfile);
   3081 			continue;
   3082 
   3083 		      case 'T':
   3084 			/* When a 'T' entry is defining an anonymous enum, it
   3085 			   may have a name which is the empty string, or a
   3086 			   single space.  Since they're not really defining a
   3087 			   symbol, those shouldn't go in the partial symbol
   3088 			   table.  We do pick up the elements of such enums at
   3089 			   'check_enum:', below.  */
   3090 			if (p >= namestring + 2
   3091 			    || (p == namestring + 1
   3092 				&& namestring[0] != ' '))
   3093 			  {
   3094 			    pst->add_psymbol
   3095 			      (std::string_view (namestring, p - namestring),
   3096 			       true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
   3097 			       psymbol_placement::STATIC,
   3098 			       unrelocated_addr (0),
   3099 			       psymtab_language,
   3100 			       partial_symtabs, objfile);
   3101 			    if (p[2] == 't')
   3102 			      {
   3103 				/* Also a typedef with the same name.  */
   3104 				pst->add_psymbol
   3105 				  (std::string_view (namestring,
   3106 						     p - namestring),
   3107 				   true, VAR_DOMAIN, LOC_TYPEDEF, -1,
   3108 				   psymbol_placement::STATIC,
   3109 				   unrelocated_addr (0),
   3110 				   psymtab_language,
   3111 				   partial_symtabs, objfile);
   3112 				p += 1;
   3113 			      }
   3114 			  }
   3115 			goto check_enum;
   3116 		      case 't':
   3117 			if (p != namestring)	/* a name is there, not
   3118 						   just :T...  */
   3119 			  {
   3120 			    pst->add_psymbol
   3121 			      (std::string_view (namestring,
   3122 						 p - namestring),
   3123 			       true, VAR_DOMAIN, LOC_TYPEDEF, -1,
   3124 			       psymbol_placement::STATIC,
   3125 			       unrelocated_addr (0),
   3126 			       psymtab_language,
   3127 			       partial_symtabs, objfile);
   3128 			  }
   3129 		      check_enum:
   3130 			/* If this is an enumerated type, we need to add
   3131 			   all the enum constants to the partial symbol
   3132 			   table.  This does not cover enums without names,
   3133 			   e.g. "enum {a, b} c;" in C, but fortunately
   3134 			   those are rare.  There is no way for GDB to find
   3135 			   those from the enum type without spending too
   3136 			   much time on it.  Thus to solve this problem,
   3137 			   the compiler needs to put out the enum in a
   3138 			   nameless type.  GCC2 does this.  */
   3139 
   3140 			/* We are looking for something of the form
   3141 			   <name> ":" ("t" | "T") [<number> "="] "e"
   3142 			   {<constant> ":" <value> ","} ";".  */
   3143 
   3144 			/* Skip over the colon and the 't' or 'T'.  */
   3145 			p += 2;
   3146 			/* This type may be given a number.  Also, numbers
   3147 			   can come in pairs like (0,26).  Skip over it.  */
   3148 			while ((*p >= '0' && *p <= '9')
   3149 			       || *p == '(' || *p == ',' || *p == ')'
   3150 			       || *p == '=')
   3151 			  p++;
   3152 
   3153 			if (*p++ == 'e')
   3154 			  {
   3155 			    /* The aix4 compiler emits extra crud before
   3156 			       the members.  */
   3157 			    if (*p == '-')
   3158 			      {
   3159 				/* Skip over the type (?).  */
   3160 				while (*p != ':')
   3161 				  p++;
   3162 
   3163 				/* Skip over the colon.  */
   3164 				p++;
   3165 			      }
   3166 
   3167 			    /* We have found an enumerated type.  */
   3168 			    /* According to comments in read_enum_type
   3169 			       a comma could end it instead of a semicolon.
   3170 			       I don't know where that happens.
   3171 			       Accept either.  */
   3172 			    while (*p && *p != ';' && *p != ',')
   3173 			      {
   3174 				const char *q;
   3175 
   3176 				/* Check for and handle cretinous dbx
   3177 				   symbol name continuation!  */
   3178 				if (*p == '\\' || (*p == '?' && p[1] == '\0'))
   3179 				  p = next_symbol_text (objfile);
   3180 
   3181 				/* Point to the character after the name
   3182 				   of the enum constant.  */
   3183 				for (q = p; *q && *q != ':'; q++)
   3184 				  ;
   3185 				/* Note that the value doesn't matter for
   3186 				   enum constants in psymtabs, just in
   3187 				   symtabs.  */
   3188 				pst->add_psymbol (std::string_view (p,
   3189 								    q - p),
   3190 						  true, VAR_DOMAIN,
   3191 						  LOC_CONST, -1,
   3192 						  psymbol_placement::STATIC,
   3193 						  unrelocated_addr (0),
   3194 						  psymtab_language,
   3195 						  partial_symtabs, objfile);
   3196 				/* Point past the name.  */
   3197 				p = q;
   3198 				/* Skip over the value.  */
   3199 				while (*p && *p != ',')
   3200 				  p++;
   3201 				/* Advance past the comma.  */
   3202 				if (*p)
   3203 				  p++;
   3204 			      }
   3205 			  }
   3206 			continue;
   3207 		      case 'c':
   3208 			/* Constant, e.g. from "const" in Pascal.  */
   3209 			pst->add_psymbol (std::string_view (namestring,
   3210 							    p - namestring),
   3211 					  true, VAR_DOMAIN, LOC_CONST, -1,
   3212 					  psymbol_placement::STATIC,
   3213 					  unrelocated_addr (0),
   3214 					  psymtab_language,
   3215 					  partial_symtabs, objfile);
   3216 			continue;
   3217 
   3218 		      case 'f':
   3219 			if (! pst)
   3220 			  {
   3221 			    std::string copy (namestring, p);
   3222 			    function_outside_compilation_unit_complaint
   3223 			      (copy.c_str ());
   3224 			  }
   3225 			pst->add_psymbol (std::string_view (namestring,
   3226 							    p - namestring),
   3227 					  true, VAR_DOMAIN, LOC_BLOCK,
   3228 					  SECT_OFF_TEXT (objfile),
   3229 					  psymbol_placement::STATIC,
   3230 					  unrelocated_addr (sh.value),
   3231 					  psymtab_language,
   3232 					  partial_symtabs, objfile);
   3233 			continue;
   3234 
   3235 			/* Global functions were ignored here, but now they
   3236 			   are put into the global psymtab like one would
   3237 			   expect.  They're also in the minimal symbol
   3238 			   table.  */
   3239 		      case 'F':
   3240 			if (! pst)
   3241 			  {
   3242 			    std::string copy (namestring, p);
   3243 			    function_outside_compilation_unit_complaint
   3244 			      (copy.c_str ());
   3245 			  }
   3246 			pst->add_psymbol (std::string_view (namestring,
   3247 							    p - namestring),
   3248 					  true, VAR_DOMAIN, LOC_BLOCK,
   3249 					  SECT_OFF_TEXT (objfile),
   3250 					  psymbol_placement::GLOBAL,
   3251 					  unrelocated_addr (sh.value),
   3252 					  psymtab_language,
   3253 					  partial_symtabs, objfile);
   3254 			continue;
   3255 
   3256 			/* Two things show up here (hopefully); static
   3257 			   symbols of local scope (static used inside
   3258 			   braces) or extensions of structure symbols.  We
   3259 			   can ignore both.  */
   3260 		      case 'V':
   3261 		      case '(':
   3262 		      case '0':
   3263 		      case '1':
   3264 		      case '2':
   3265 		      case '3':
   3266 		      case '4':
   3267 		      case '5':
   3268 		      case '6':
   3269 		      case '7':
   3270 		      case '8':
   3271 		      case '9':
   3272 		      case '-':
   3273 		      case '#':		/* For symbol identification (used
   3274 					   in live ranges).  */
   3275 			continue;
   3276 
   3277 		      case ':':
   3278 			/* It is a C++ nested symbol.  We don't need to
   3279 			   record it (I don't think); if we try to look up
   3280 			   foo::bar::baz, then symbols for the symtab
   3281 			   containing foo should get read in, I think.  */
   3282 			/* Someone says sun cc puts out symbols like
   3283 			   /foo/baz/maclib::/usr/local/bin/maclib,
   3284 			   which would get here with a symbol type of ':'.  */
   3285 			continue;
   3286 
   3287 		      default:
   3288 			/* Unexpected symbol descriptor.  The second and
   3289 			   subsequent stabs of a continued stab can show up
   3290 			   here.  The question is whether they ever can
   3291 			   mimic a normal stab--it would be nice if not,
   3292 			   since we certainly don't want to spend the time
   3293 			   searching to the end of every string looking for
   3294 			   a backslash.  */
   3295 
   3296 			complaint (_("unknown symbol descriptor `%c'"), p[1]);
   3297 
   3298 			/* Ignore it; perhaps it is an extension that we don't
   3299 			   know about.  */
   3300 			continue;
   3301 		      }
   3302 
   3303 		  case N_EXCL:
   3304 		    continue;
   3305 
   3306 		  case N_ENDM:
   3307 		    /* Solaris 2 end of module, finish current partial
   3308 		       symbol table.  stabs_end_psymtab will set the
   3309 		       high text address of PST to the proper value,
   3310 		       which is necessary if a module compiled without
   3311 		       debugging info follows this module.  */
   3312 		    if (pst
   3313 			&& gdbarch_sofun_address_maybe_missing (gdbarch))
   3314 		      {
   3315 			pst = (legacy_psymtab *) 0;
   3316 			includes_used = 0;
   3317 			dependencies_used = 0;
   3318 		      }
   3319 		    continue;
   3320 
   3321 		  case N_RBRAC:
   3322 		    {
   3323 		      unrelocated_addr unrel_value
   3324 			= unrelocated_addr (sh.value);
   3325 		      if (unrel_value > save_pst->unrelocated_text_high ())
   3326 			save_pst->set_text_high (unrel_value);
   3327 		    }
   3328 		    continue;
   3329 		  case N_EINCL:
   3330 		  case N_DSLINE:
   3331 		  case N_BSLINE:
   3332 		  case N_SSYM:		/* Claim: Structure or union
   3333 					   element.  Hopefully, I can
   3334 					   ignore this.  */
   3335 		  case N_ENTRY:		/* Alternate entry point; can
   3336 					   ignore.  */
   3337 		  case N_MAIN:		/* Can definitely ignore this.   */
   3338 		  case N_CATCH:		/* These are GNU C++ extensions.  */
   3339 		  case N_EHDECL:	/* that can safely be ignored here.  */
   3340 		  case N_LENG:
   3341 		  case N_BCOMM:
   3342 		  case N_ECOMM:
   3343 		  case N_ECOML:
   3344 		  case N_FNAME:
   3345 		  case N_SLINE:
   3346 		  case N_RSYM:
   3347 		  case N_PSYM:
   3348 		  case N_LBRAC:
   3349 		  case N_NSYMS:		/* Ultrix 4.0: symbol count */
   3350 		  case N_DEFD:			/* GNU Modula-2 */
   3351 		  case N_ALIAS:		/* SunPro F77: alias name, ignore
   3352 					   for now.  */
   3353 
   3354 		  case N_OBJ:		/* Useless types from Solaris.  */
   3355 		  case N_OPT:
   3356 		    /* These symbols aren't interesting; don't worry about
   3357 		       them.  */
   3358 
   3359 		    continue;
   3360 
   3361 		  default:
   3362 		    /* If we haven't found it yet, ignore it.  It's
   3363 		       probably some new type we don't know about yet.  */
   3364 		    complaint (_("unknown symbol type %s"),
   3365 			       hex_string (type_code)); /* CUR_SYMBOL_TYPE */
   3366 		    continue;
   3367 		  }
   3368 	      }
   3369 	      /* end - Handle continuation */
   3370 	    }
   3371 	}
   3372       else
   3373 	{
   3374 	  for (cur_sdx = 0; cur_sdx < fh->csym;)
   3375 	    {
   3376 	      char *sym_name;
   3377 	      enum address_class theclass;
   3378 	      unrelocated_addr minsym_value;
   3379 	      int section = -1;
   3380 
   3381 	      (*swap_sym_in) (cur_bfd,
   3382 			      ((char *) debug_info->external_sym
   3383 			       + ((fh->isymBase + cur_sdx)
   3384 				  * external_sym_size)),
   3385 			      &sh);
   3386 
   3387 	      if (ECOFF_IS_STAB (&sh))
   3388 		{
   3389 		  cur_sdx++;
   3390 		  continue;
   3391 		}
   3392 
   3393 	      /* Non absolute static symbols go into the minimal table.  */
   3394 	      if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
   3395 		  || (sh.index == indexNil
   3396 		      && (sh.st != stStatic || sh.sc == scAbs)))
   3397 		{
   3398 		  /* FIXME, premature?  */
   3399 		  cur_sdx++;
   3400 		  continue;
   3401 		}
   3402 
   3403 	      sym_name = debug_info->ss + fh->issBase + sh.iss;
   3404 
   3405 	      minsym_value = unrelocated_addr (sh.value);
   3406 
   3407 	      switch (sh.sc)
   3408 		{
   3409 		case scText:
   3410 		case scRConst:
   3411 		  /* The value of a stEnd symbol is the displacement from the
   3412 		     corresponding start symbol value, do not relocate it.  */
   3413 		  if (sh.st != stEnd)
   3414 		    section = SECT_OFF_TEXT (objfile);
   3415 		  break;
   3416 		case scData:
   3417 		case scSData:
   3418 		case scRData:
   3419 		case scPData:
   3420 		case scXData:
   3421 		  section = SECT_OFF_DATA (objfile);
   3422 		  break;
   3423 		case scBss:
   3424 		case scSBss:
   3425 		  section = SECT_OFF_BSS (objfile);
   3426 		  break;
   3427 		}
   3428 
   3429 	      switch (sh.st)
   3430 		{
   3431 		  unrelocated_addr high;
   3432 		  unrelocated_addr procaddr;
   3433 		  int new_sdx;
   3434 
   3435 		case stStaticProc:
   3436 		  reader.record_with_info (sym_name, minsym_value,
   3437 					   mst_file_text,
   3438 					   SECT_OFF_TEXT (objfile));
   3439 
   3440 		  [[fallthrough]];
   3441 
   3442 		case stProc:
   3443 		  /* Ignore all parameter symbol records.  */
   3444 		  if (sh.index >= hdr->iauxMax)
   3445 		    {
   3446 		      /* Should not happen, but does when cross-compiling
   3447 			 with the MIPS compiler.  FIXME -- pull later.  */
   3448 		      index_complaint (sym_name);
   3449 		      new_sdx = cur_sdx + 1;	/* Don't skip at all.  */
   3450 		    }
   3451 		  else
   3452 		    new_sdx = AUX_GET_ISYM (fh->fBigendian,
   3453 					    (debug_info->external_aux
   3454 					     + fh->iauxBase
   3455 					     + sh.index));
   3456 
   3457 		  if (new_sdx <= cur_sdx)
   3458 		    {
   3459 		      /* This should not happen either... FIXME.  */
   3460 		      complaint (_("bad proc end in aux found from symbol %s"),
   3461 				 sym_name);
   3462 		      new_sdx = cur_sdx + 1;	/* Don't skip backward.  */
   3463 		    }
   3464 
   3465 		  /* For stProc symbol records, we need to check the
   3466 		     storage class as well, as only (stProc, scText)
   3467 		     entries represent "real" procedures - See the
   3468 		     Compaq document titled "Object File / Symbol Table
   3469 		     Format Specification" for more information.  If the
   3470 		     storage class is not scText, we discard the whole
   3471 		     block of symbol records for this stProc.  */
   3472 		  if (sh.st == stProc && sh.sc != scText)
   3473 		    goto skip;
   3474 
   3475 		  /* Usually there is a local and a global stProc symbol
   3476 		     for a function.  This means that the function name
   3477 		     has already been entered into the minimal symbol table
   3478 		     while processing the global symbols in pass 2 above.
   3479 		     One notable exception is the PROGRAM name from
   3480 		     f77 compiled executables, it is only put out as
   3481 		     local stProc symbol, and a global MAIN__ stProc symbol
   3482 		     points to it.  It doesn't matter though, as gdb is
   3483 		     still able to find the PROGRAM name via the partial
   3484 		     symbol table, and the MAIN__ symbol via the minimal
   3485 		     symbol table.  */
   3486 		  if (sh.st == stProc)
   3487 		    pst->add_psymbol (sym_name, true,
   3488 				      VAR_DOMAIN, LOC_BLOCK,
   3489 				      section,
   3490 				      psymbol_placement::GLOBAL,
   3491 				      unrelocated_addr (sh.value),
   3492 				      psymtab_language,
   3493 				      partial_symtabs, objfile);
   3494 		  else
   3495 		    pst->add_psymbol (sym_name, true,
   3496 				      VAR_DOMAIN, LOC_BLOCK,
   3497 				      section,
   3498 				      psymbol_placement::STATIC,
   3499 				      unrelocated_addr (sh.value),
   3500 				      psymtab_language,
   3501 				      partial_symtabs, objfile);
   3502 
   3503 		  procaddr = unrelocated_addr (sh.value);
   3504 
   3505 		  cur_sdx = new_sdx;
   3506 		  (*swap_sym_in) (cur_bfd,
   3507 				  ((char *) debug_info->external_sym
   3508 				   + ((fh->isymBase + cur_sdx - 1)
   3509 				      * external_sym_size)),
   3510 				  &sh);
   3511 		  if (sh.st != stEnd)
   3512 		    continue;
   3513 
   3514 		  /* Kludge for Irix 5.2 zero fh->adr.  */
   3515 		  if (!relocatable
   3516 		      && (!pst->text_low_valid
   3517 			  || procaddr < pst->unrelocated_text_low ()))
   3518 		    pst->set_text_low (procaddr);
   3519 
   3520 		  high = unrelocated_addr (CORE_ADDR (procaddr) + sh.value);
   3521 		  if (high > pst->unrelocated_text_high ())
   3522 		    pst->set_text_high (high);
   3523 		  continue;
   3524 
   3525 		case stStatic:	/* Variable */
   3526 		  if (SC_IS_DATA (sh.sc))
   3527 		    reader.record_with_info (sym_name, minsym_value,
   3528 					     mst_file_data,
   3529 					     SECT_OFF_DATA (objfile));
   3530 		  else
   3531 		    reader.record_with_info (sym_name, minsym_value,
   3532 					     mst_file_bss,
   3533 					     SECT_OFF_BSS (objfile));
   3534 		  theclass = LOC_STATIC;
   3535 		  break;
   3536 
   3537 		case stIndirect:	/* Irix5 forward declaration */
   3538 		  /* Skip forward declarations from Irix5 cc.  */
   3539 		  goto skip;
   3540 
   3541 		case stTypedef:	/* Typedef */
   3542 		  /* Skip typedefs for forward declarations and opaque
   3543 		     structs from alpha and mips cc.  */
   3544 		  if (sh.iss == 0 || has_opaque_xref (fh, &sh))
   3545 		    goto skip;
   3546 		  theclass = LOC_TYPEDEF;
   3547 		  break;
   3548 
   3549 		case stConstant:	/* Constant decl */
   3550 		  theclass = LOC_CONST;
   3551 		  break;
   3552 
   3553 		case stUnion:
   3554 		case stStruct:
   3555 		case stEnum:
   3556 		case stBlock:	/* { }, str, un, enum */
   3557 		  /* Do not create a partial symbol for cc unnamed aggregates
   3558 		     and gcc empty aggregates.  */
   3559 		  if ((sh.sc == scInfo
   3560 		       || SC_IS_COMMON (sh.sc))
   3561 		      && sh.iss != 0
   3562 		      && sh.index != cur_sdx + 2)
   3563 		    {
   3564 		      pst->add_psymbol (sym_name, true,
   3565 					STRUCT_DOMAIN, LOC_TYPEDEF, -1,
   3566 					psymbol_placement::STATIC,
   3567 					unrelocated_addr (0),
   3568 					psymtab_language,
   3569 					partial_symtabs, objfile);
   3570 		    }
   3571 		  handle_psymbol_enumerators (objfile, partial_symtabs,
   3572 					      pst, fh, sh.st, sh.value);
   3573 
   3574 		  /* Skip over the block.  */
   3575 		  new_sdx = sh.index;
   3576 		  if (new_sdx <= cur_sdx)
   3577 		    {
   3578 		      /* This happens with the Ultrix kernel.  */
   3579 		      complaint (_("bad aux index at block symbol %s"),
   3580 				 sym_name);
   3581 		      new_sdx = cur_sdx + 1;	/* Don't skip backward.  */
   3582 		    }
   3583 		  cur_sdx = new_sdx;
   3584 		  continue;
   3585 
   3586 		case stFile:	/* File headers */
   3587 		case stLabel:	/* Labels */
   3588 		case stEnd:	/* Ends of files */
   3589 		  goto skip;
   3590 
   3591 		case stLocal:	/* Local variables */
   3592 		  /* Normally these are skipped because we skip over
   3593 		     all blocks we see.  However, these can occur
   3594 		     as visible symbols in a .h file that contains code.  */
   3595 		  goto skip;
   3596 
   3597 		default:
   3598 		  /* Both complaints are valid:  one gives symbol sym_name,
   3599 		     the other the offending symbol type.  */
   3600 		  complaint (_("unknown local symbol %s"),
   3601 			     sym_name);
   3602 		  complaint (_("with type %d"), sh.st);
   3603 		  cur_sdx++;
   3604 		  continue;
   3605 		}
   3606 	      /* Use this gdb symbol.  */
   3607 	      pst->add_psymbol (sym_name, true,
   3608 				VAR_DOMAIN, theclass, section,
   3609 				psymbol_placement::STATIC,
   3610 				unrelocated_addr (sh.value),
   3611 				psymtab_language,
   3612 				partial_symtabs, objfile);
   3613 	    skip:
   3614 	      cur_sdx++;	/* Go to next file symbol.  */
   3615 	    }
   3616 
   3617 	  /* Now do enter the external symbols.  */
   3618 	  ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
   3619 	  cur_sdx = fdr_to_pst[f_idx].n_globals;
   3620 	  PST_PRIVATE (save_pst)->extern_count = cur_sdx;
   3621 	  PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
   3622 	  for (; --cur_sdx >= 0; ext_ptr++)
   3623 	    {
   3624 	      enum address_class theclass;
   3625 	      SYMR *psh;
   3626 	      CORE_ADDR svalue;
   3627 	      int section;
   3628 
   3629 	      gdb_assert (ext_ptr->ifd == f_idx);
   3630 
   3631 	      psh = &ext_ptr->asym;
   3632 
   3633 	      /* Do not add undefined symbols to the partial symbol table.  */
   3634 	      if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
   3635 		continue;
   3636 
   3637 	      svalue = psh->value;
   3638 	      switch (psh->sc)
   3639 		{
   3640 		default:
   3641 		case scText:
   3642 		case scRConst:
   3643 		  section = SECT_OFF_TEXT (objfile);
   3644 		  break;
   3645 		case scData:
   3646 		case scSData:
   3647 		case scRData:
   3648 		case scPData:
   3649 		case scXData:
   3650 		  section = SECT_OFF_DATA (objfile);
   3651 		  break;
   3652 		case scBss:
   3653 		case scSBss:
   3654 		  section = SECT_OFF_BSS (objfile);
   3655 		  break;
   3656 		}
   3657 
   3658 	      switch (psh->st)
   3659 		{
   3660 		case stNil:
   3661 		  /* These are generated for static symbols in .o files,
   3662 		     ignore them.  */
   3663 		  continue;
   3664 		case stProc:
   3665 		case stStaticProc:
   3666 		  /* External procedure symbols have been entered
   3667 		     into the minimal symbol table in pass 2 above.
   3668 		     Ignore them, as parse_external will ignore them too.  */
   3669 		  continue;
   3670 		case stLabel:
   3671 		  theclass = LOC_LABEL;
   3672 		  break;
   3673 		default:
   3674 		  unknown_ext_complaint (debug_info->ssext + psh->iss);
   3675 		  /* Pretend it's global.  */
   3676 		  [[fallthrough]];
   3677 		case stGlobal:
   3678 		  /* Global common symbols are resolved by the runtime loader,
   3679 		     ignore them.  */
   3680 		  if (SC_IS_COMMON (psh->sc))
   3681 		    continue;
   3682 
   3683 		  theclass = LOC_STATIC;
   3684 		  break;
   3685 		}
   3686 	      char *sym_name = debug_info->ssext + psh->iss;
   3687 	      pst->add_psymbol (sym_name, true,
   3688 				VAR_DOMAIN, theclass,
   3689 				section,
   3690 				psymbol_placement::GLOBAL,
   3691 				unrelocated_addr (svalue),
   3692 				psymtab_language,
   3693 				partial_symtabs, objfile);
   3694 	    }
   3695 	}
   3696 
   3697       /* Link pst to FDR.  stabs_end_psymtab returns NULL if the psymtab was
   3698 	 empty and put on the free list.  */
   3699       fdr_to_pst[f_idx].pst
   3700 	= stabs_end_psymtab (objfile, partial_symtabs, save_pst,
   3701 			     psymtab_include_list, includes_used,
   3702 			     -1, save_pst->unrelocated_text_high (),
   3703 			     dependency_list, dependencies_used,
   3704 			     textlow_not_set);
   3705       includes_used = 0;
   3706       dependencies_used = 0;
   3707     }
   3708 
   3709   /* Now scan the FDRs for dependencies.  */
   3710   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
   3711     {
   3712       fh = f_idx + debug_info->fdr;
   3713       pst = fdr_to_pst[f_idx].pst;
   3714 
   3715       if (pst == NULL)
   3716 	continue;
   3717 
   3718       /* This should catch stabs-in-ecoff.  */
   3719       if (fh->crfd <= 1)
   3720 	continue;
   3721 
   3722       /* Skip the first file indirect entry as it is a self dependency for
   3723 	 source files or a reverse .h -> .c dependency for header files.  */
   3724       pst->number_of_dependencies = 0;
   3725       pst->dependencies
   3726 	= partial_symtabs->allocate_dependencies (fh->crfd - 1);
   3727       for (s_idx = 1; s_idx < fh->crfd; s_idx++)
   3728 	{
   3729 	  RFDT rh;
   3730 
   3731 	  (*swap_rfd_in) (cur_bfd,
   3732 			  ((char *) debug_info->external_rfd
   3733 			   + (fh->rfdBase + s_idx) * external_rfd_size),
   3734 			  &rh);
   3735 	  if (rh < 0 || rh >= hdr->ifdMax)
   3736 	    {
   3737 	      complaint (_("bad file number %ld"), rh);
   3738 	      continue;
   3739 	    }
   3740 
   3741 	  /* Skip self dependencies of header files.  */
   3742 	  if (rh == f_idx)
   3743 	    continue;
   3744 
   3745 	  /* Do not add to dependency list if psymtab was empty.  */
   3746 	  if (fdr_to_pst[rh].pst == NULL)
   3747 	    continue;
   3748 	  pst->dependencies[pst->number_of_dependencies++]
   3749 	    = fdr_to_pst[rh].pst;
   3750 	}
   3751     }
   3752 
   3753   /* Remove the dummy psymtab created for -O3 images above, if it is
   3754      still empty, to enable the detection of stripped executables.  */
   3755   partial_symtab *pst_del = partial_symtabs->psymtabs;
   3756   if (pst_del->next == NULL
   3757       && pst_del->number_of_dependencies == 0
   3758       && pst_del->empty ())
   3759     partial_symtabs->discard_psymtab (pst_del);
   3760 }
   3761 
   3762 /* If the current psymbol has an enumerated type, we need to add
   3763    all the enum constants to the partial symbol table.  */
   3764 
   3765 static void
   3766 handle_psymbol_enumerators (struct objfile *objfile,
   3767 			    psymtab_storage *partial_symtabs,
   3768 			    partial_symtab *pst,
   3769 			    FDR *fh, int stype, CORE_ADDR svalue)
   3770 {
   3771   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   3772   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
   3773   char *ext_sym = ((char *) debug_info->external_sym
   3774 		   + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
   3775   SYMR sh;
   3776   TIR tir;
   3777 
   3778   switch (stype)
   3779     {
   3780     case stEnum:
   3781       break;
   3782 
   3783     case stBlock:
   3784       /* It is an enumerated type if the next symbol entry is a stMember
   3785 	 and its auxiliary index is indexNil or its auxiliary entry
   3786 	 is a plain btNil or btVoid.
   3787 	 Alpha cc -migrate enums are recognized by a zero index and
   3788 	 a zero symbol value.
   3789 	 DU 4.0 cc enums are recognized by a member type of btEnum without
   3790 	 qualifiers and a zero symbol value.  */
   3791       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
   3792       if (sh.st != stMember)
   3793 	return;
   3794 
   3795       if (sh.index == indexNil
   3796 	  || (sh.index == 0 && svalue == 0))
   3797 	break;
   3798       (*debug_swap->swap_tir_in) (fh->fBigendian,
   3799 				  &(debug_info->external_aux
   3800 				    + fh->iauxBase + sh.index)->a_ti,
   3801 				  &tir);
   3802       if ((tir.bt != btNil
   3803 	   && tir.bt != btVoid
   3804 	   && (tir.bt != btEnum || svalue != 0))
   3805 	  || tir.tq0 != tqNil)
   3806 	return;
   3807       break;
   3808 
   3809     default:
   3810       return;
   3811     }
   3812 
   3813   for (;;)
   3814     {
   3815       char *name;
   3816 
   3817       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
   3818       if (sh.st != stMember)
   3819 	break;
   3820       name = debug_info->ss + cur_fdr->issBase + sh.iss;
   3821 
   3822       /* Note that the value doesn't matter for enum constants
   3823 	 in psymtabs, just in symtabs.  */
   3824       pst->add_psymbol (name, true,
   3825 			VAR_DOMAIN, LOC_CONST, -1,
   3826 			psymbol_placement::STATIC,
   3827 			unrelocated_addr (0),
   3828 			psymtab_language, partial_symtabs, objfile);
   3829       ext_sym += external_sym_size;
   3830     }
   3831 }
   3832 
   3833 /* Get the next symbol.  OBJFILE is unused.  */
   3834 
   3835 static const char *
   3836 mdebug_next_symbol_text (struct objfile *objfile)
   3837 {
   3838   SYMR sh;
   3839 
   3840   cur_sdx++;
   3841   (*debug_swap->swap_sym_in) (cur_bfd,
   3842 			      ((char *) debug_info->external_sym
   3843 			       + ((cur_fdr->isymBase + cur_sdx)
   3844 				  * debug_swap->external_sym_size)),
   3845 			      &sh);
   3846   return debug_info->ss + cur_fdr->issBase + sh.iss;
   3847 }
   3848 
   3849 /* Ancillary function to psymtab_to_symtab().  Does all the work
   3850    for turning the partial symtab PST into a symtab, recurring
   3851    first on all dependent psymtabs.  The argument FILENAME is
   3852    only passed so we can see in debug stack traces what file
   3853    is being read.
   3854 
   3855    This function has a split personality, based on whether the
   3856    symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
   3857    The flow of control and even the memory allocation differs.  FIXME.  */
   3858 
   3859 static void
   3860 mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
   3861 {
   3862   bfd_size_type external_sym_size;
   3863   bfd_size_type external_pdr_size;
   3864   void (*swap_sym_in) (bfd *, void *, SYMR *);
   3865   void (*swap_pdr_in) (bfd *, void *, PDR *);
   3866   int i;
   3867   struct compunit_symtab *cust = NULL;
   3868   FDR *fh;
   3869   struct linetable *lines;
   3870   CORE_ADDR lowest_pdr_addr = 0;
   3871   int last_symtab_ended = 0;
   3872   const section_offsets &section_offsets = objfile->section_offsets;
   3873 
   3874   if (pst->readin)
   3875     return;
   3876   pst->readin = true;
   3877 
   3878   /* Read in all partial symtabs on which this one is dependent.
   3879      NOTE that we do have circular dependencies, sigh.  We solved
   3880      that by setting pst->readin before this point.  */
   3881   pst->expand_dependencies (objfile);
   3882 
   3883   /* Do nothing if this is a dummy psymtab.  */
   3884 
   3885   if (pst->empty () && !pst->text_low_valid && !pst->text_high_valid)
   3886     return;
   3887 
   3888   /* Now read the symbols for this symtab.  */
   3889 
   3890   cur_bfd = CUR_BFD (pst);
   3891   debug_swap = DEBUG_SWAP (pst);
   3892   debug_info = DEBUG_INFO (pst);
   3893   pending_list = PENDING_LIST (pst);
   3894   external_sym_size = debug_swap->external_sym_size;
   3895   external_pdr_size = debug_swap->external_pdr_size;
   3896   swap_sym_in = debug_swap->swap_sym_in;
   3897   swap_pdr_in = debug_swap->swap_pdr_in;
   3898   mdebugread_objfile = objfile;
   3899   cur_fd = FDR_IDX (pst);
   3900   fh = ((cur_fd == -1)
   3901 	? NULL
   3902 	: debug_info->fdr + cur_fd);
   3903   cur_fdr = fh;
   3904 
   3905   /* See comment in parse_partial_symbols about the @stabs sentinel.  */
   3906   processing_gcc_compilation = 0;
   3907   if (fh != NULL && fh->csym >= 2)
   3908     {
   3909       SYMR sh;
   3910 
   3911       (*swap_sym_in) (cur_bfd,
   3912 		      ((char *) debug_info->external_sym
   3913 		       + (fh->isymBase + 1) * external_sym_size),
   3914 		      &sh);
   3915       if (strcmp (debug_info->ss + fh->issBase + sh.iss,
   3916 		  stabs_symbol) == 0)
   3917 	{
   3918 	  /* We indicate that this is a GCC compilation so that certain
   3919 	     features will be enabled in stabsread/dbxread.  */
   3920 	  processing_gcc_compilation = 2;
   3921 	}
   3922     }
   3923 
   3924   if (processing_gcc_compilation != 0)
   3925     {
   3926       struct gdbarch *gdbarch = objfile->arch ();
   3927 
   3928       /* This symbol table contains stabs-in-ecoff entries.  */
   3929 
   3930       /* Parse local symbols first.  */
   3931 
   3932       if (fh->csym <= 2)	/* FIXME, this blows psymtab->symtab ptr.  */
   3933 	{
   3934 	  mdebugread_objfile = NULL;
   3935 	  return;
   3936 	}
   3937       for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
   3938 	{
   3939 	  SYMR sh;
   3940 	  char *name;
   3941 	  CORE_ADDR valu;
   3942 
   3943 	  (*swap_sym_in) (cur_bfd,
   3944 			  (((char *) debug_info->external_sym)
   3945 			   + (fh->isymBase + cur_sdx) * external_sym_size),
   3946 			  &sh);
   3947 	  name = debug_info->ss + fh->issBase + sh.iss;
   3948 	  valu = sh.value;
   3949 	  /* XXX This is a hack.  It will go away!  */
   3950 	  if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
   3951 	    {
   3952 	      int type_code = ECOFF_UNMARK_STAB (sh.index);
   3953 	      enum language language = PST_PRIVATE (pst)->pst_language;
   3954 
   3955 	      /* We should never get non N_STAB symbols here, but they
   3956 		 should be harmless, so keep process_one_symbol from
   3957 		 complaining about them.  */
   3958 	      if (type_code & N_STAB)
   3959 		{
   3960 		  /* If we found a trailing N_SO with no name, process
   3961 		     it here instead of in process_one_symbol, so we
   3962 		     can keep a handle to its symtab.  The symtab
   3963 		     would otherwise be ended twice, once in
   3964 		     process_one_symbol, and once after this loop.  */
   3965 		  if (type_code == N_SO
   3966 		      && get_last_source_file ()
   3967 		      && previous_stab_code != (unsigned char) N_SO
   3968 		      && *name == '\000')
   3969 		    {
   3970 		      valu += section_offsets[SECT_OFF_TEXT (objfile)];
   3971 		      previous_stab_code = N_SO;
   3972 		      cust = end_compunit_symtab (valu);
   3973 		      end_stabs ();
   3974 		      last_symtab_ended = 1;
   3975 		    }
   3976 		  else
   3977 		    {
   3978 		      last_symtab_ended = 0;
   3979 		      process_one_symbol (type_code, 0, valu, name,
   3980 					  section_offsets, objfile, language);
   3981 		    }
   3982 		}
   3983 	      /* Similarly a hack.  */
   3984 	      else if (name[0] == '#')
   3985 		{
   3986 		  process_one_symbol (N_SLINE, 0, valu, name,
   3987 				      section_offsets, objfile, language);
   3988 		}
   3989 	      if (type_code == N_FUN)
   3990 		{
   3991 		  /* Make up special symbol to contain
   3992 		     procedure specific info.  */
   3993 		  mdebug_extra_func_info *e
   3994 		    = OBSTACK_ZALLOC (&mdebugread_objfile->objfile_obstack,
   3995 				      mdebug_extra_func_info);
   3996 		  struct symbol *s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
   3997 
   3998 		  s->set_domain (LABEL_DOMAIN);
   3999 		  s->set_aclass_index (LOC_CONST);
   4000 		  s->set_type (builtin_type (objfile)->builtin_void);
   4001 		  s->set_value_bytes ((gdb_byte *) e);
   4002 		  e->pdr.framereg = -1;
   4003 		  add_symbol_to_list (s, get_local_symbols ());
   4004 		}
   4005 	    }
   4006 	  else if (sh.st == stLabel)
   4007 	    {
   4008 	      if (sh.index == indexNil)
   4009 		{
   4010 		  /* This is what the gcc2_compiled and __gnu_compiled_*
   4011 		     show up as.  So don't complain.  */
   4012 		  ;
   4013 		}
   4014 	      else
   4015 		{
   4016 		  /* Handle encoded stab line number.  */
   4017 		  record_line
   4018 		    (get_current_subfile (), sh.index,
   4019 		     unrelocated_addr (gdbarch_addr_bits_remove (gdbarch,
   4020 								 valu)));
   4021 		}
   4022 	    }
   4023 	  else if (sh.st == stProc || sh.st == stStaticProc
   4024 		   || sh.st == stStatic || sh.st == stEnd)
   4025 	    /* These are generated by gcc-2.x, do not complain.  */
   4026 	    ;
   4027 	  else
   4028 	    complaint (_("unknown stabs symbol %s"), name);
   4029 	}
   4030 
   4031       if (! last_symtab_ended)
   4032 	{
   4033 	  cust = end_compunit_symtab (pst->text_high (objfile));
   4034 	  end_stabs ();
   4035 	}
   4036 
   4037       /* There used to be a call to sort_blocks here, but this should not
   4038 	 be necessary for stabs symtabs.  And as sort_blocks modifies the
   4039 	 start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
   4040 	 it did the wrong thing if the first procedure in a file was
   4041 	 generated via asm statements.  */
   4042 
   4043       /* Fill in procedure info next.  */
   4044       if (fh->cpd > 0)
   4045 	{
   4046 	  char *pdr_ptr;
   4047 	  char *pdr_end;
   4048 	  PDR *pdr_in;
   4049 	  PDR *pdr_in_end;
   4050 
   4051 	  gdb::def_vector<PDR> pr_block (fh->cpd);
   4052 
   4053 	  pdr_ptr = ((char *) debug_info->external_pdr
   4054 		     + fh->ipdFirst * external_pdr_size);
   4055 	  pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
   4056 	  pdr_in = pr_block.data ();
   4057 	  for (;
   4058 	       pdr_ptr < pdr_end;
   4059 	       pdr_ptr += external_pdr_size, pdr_in++)
   4060 	    {
   4061 	      (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
   4062 
   4063 	      /* Determine lowest PDR address, the PDRs are not always
   4064 		 sorted.  */
   4065 	      if (pdr_in == pr_block.data ())
   4066 		lowest_pdr_addr = pdr_in->adr;
   4067 	      else if (pdr_in->adr < lowest_pdr_addr)
   4068 		lowest_pdr_addr = pdr_in->adr;
   4069 	    }
   4070 
   4071 	  pdr_in = pr_block.data ();
   4072 	  pdr_in_end = pdr_in + fh->cpd;
   4073 	  for (; pdr_in < pdr_in_end; pdr_in++)
   4074 	    parse_procedure (pdr_in, cust, pst);
   4075 	}
   4076     }
   4077   else
   4078     {
   4079       /* This symbol table contains ordinary ecoff entries.  */
   4080 
   4081       int maxlines, size;
   4082       EXTR *ext_ptr;
   4083 
   4084       if (fh == 0)
   4085 	{
   4086 	  maxlines = 0;
   4087 	  cust = new_symtab ("unknown", 0, objfile);
   4088 	}
   4089       else
   4090 	{
   4091 	  maxlines = 2 * fh->cline;
   4092 	  cust = new_symtab (pst->filename, maxlines, objfile);
   4093 
   4094 	  /* The proper language was already determined when building
   4095 	     the psymtab, use it.  */
   4096 	  cust->primary_filetab ()->set_language
   4097 	    (PST_PRIVATE (pst)->pst_language);
   4098 	}
   4099 
   4100       psymtab_language = cust->primary_filetab ()->language ();
   4101 
   4102       /* This code allocates the line table on the heap and then later
   4103 	 copies it to the obstack.  So, while casting away const here
   4104 	 is ugly, it's not incorrect.  */
   4105       lines = const_cast<linetable *> (cust->primary_filetab ()->linetable ());
   4106 
   4107       /* Get a new lexical context.  */
   4108 
   4109       push_parse_stack ();
   4110       top_stack->cur_st = cust->primary_filetab ();
   4111       top_stack->cur_block = cust->blockvector ()->static_block ();
   4112       top_stack->cur_block->set_start (pst->text_low (objfile));
   4113       top_stack->cur_block->set_end (0);
   4114       top_stack->blocktype = stFile;
   4115       top_stack->cur_type = 0;
   4116       top_stack->procadr = 0;
   4117       top_stack->numargs = 0;
   4118       found_ecoff_debugging_info = 0;
   4119 
   4120       if (fh)
   4121 	{
   4122 	  char *sym_ptr;
   4123 	  char *sym_end;
   4124 
   4125 	  /* Parse local symbols first.  */
   4126 	  sym_ptr = ((char *) debug_info->external_sym
   4127 		     + fh->isymBase * external_sym_size);
   4128 	  sym_end = sym_ptr + fh->csym * external_sym_size;
   4129 	  while (sym_ptr < sym_end)
   4130 	    {
   4131 	      SYMR sh;
   4132 	      int c;
   4133 
   4134 	      (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
   4135 	      c = parse_symbol (&sh,
   4136 				debug_info->external_aux + fh->iauxBase,
   4137 				sym_ptr, fh->fBigendian,
   4138 				section_offsets, objfile);
   4139 	      sym_ptr += c * external_sym_size;
   4140 	    }
   4141 
   4142 	  /* Linenumbers.  At the end, check if we can save memory.
   4143 	     parse_lines has to look ahead an arbitrary number of PDR
   4144 	     structures, so we swap them all first.  */
   4145 	  if (fh->cpd > 0)
   4146 	    {
   4147 	      char *pdr_ptr;
   4148 	      char *pdr_end;
   4149 	      PDR *pdr_in;
   4150 	      PDR *pdr_in_end;
   4151 
   4152 	      gdb::def_vector<PDR> pr_block (fh->cpd);
   4153 
   4154 	      pdr_ptr = ((char *) debug_info->external_pdr
   4155 			 + fh->ipdFirst * external_pdr_size);
   4156 	      pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
   4157 	      pdr_in = pr_block.data ();
   4158 	      for (;
   4159 		   pdr_ptr < pdr_end;
   4160 		   pdr_ptr += external_pdr_size, pdr_in++)
   4161 		{
   4162 		  (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
   4163 
   4164 		  /* Determine lowest PDR address, the PDRs are not always
   4165 		     sorted.  */
   4166 		  if (pdr_in == pr_block.data ())
   4167 		    lowest_pdr_addr = pdr_in->adr;
   4168 		  else if (pdr_in->adr < lowest_pdr_addr)
   4169 		    lowest_pdr_addr = pdr_in->adr;
   4170 		}
   4171 
   4172 	      parse_lines (fh, pr_block.data (), lines, maxlines,
   4173 			   lowest_pdr_addr);
   4174 	      if (lines->nitems < fh->cline)
   4175 		lines = shrink_linetable (lines);
   4176 
   4177 	      /* Fill in procedure info next.  */
   4178 	      pdr_in = pr_block.data ();
   4179 	      pdr_in_end = pdr_in + fh->cpd;
   4180 	      for (; pdr_in < pdr_in_end; pdr_in++)
   4181 		parse_procedure (pdr_in, NULL, pst);
   4182 	    }
   4183 	}
   4184 
   4185       size = lines->nitems;
   4186       if (size > 1)
   4187 	--size;
   4188       cust->primary_filetab ()->set_linetable
   4189 	((struct linetable *)
   4190 	 obstack_copy (&mdebugread_objfile->objfile_obstack,
   4191 		       lines, (sizeof (struct linetable)
   4192 			       + size * sizeof (lines->item))));
   4193       xfree (lines);
   4194 
   4195       /* .. and our share of externals.
   4196 	 XXX use the global list to speed up things here.  How?
   4197 	 FIXME, Maybe quit once we have found the right number of ext's?  */
   4198       top_stack->cur_st = cust->primary_filetab ();
   4199       top_stack->cur_block
   4200 	= top_stack->cur_st->compunit ()->blockvector ()->global_block ();
   4201       top_stack->blocktype = stFile;
   4202 
   4203       ext_ptr = PST_PRIVATE (pst)->extern_tab;
   4204       for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
   4205 	parse_external (ext_ptr, fh->fBigendian,
   4206 			section_offsets, objfile);
   4207 
   4208       /* If there are undefined symbols, tell the user.
   4209 	 The alpha has an undefined symbol for every symbol that is
   4210 	 from a shared library, so tell the user only if verbose is on.  */
   4211       if (info_verbose && n_undef_symbols)
   4212 	{
   4213 	  gdb_printf (_("File %s contains %d unresolved references:"),
   4214 		      symtab_to_filename_for_display
   4215 		      (cust->primary_filetab ()),
   4216 		      n_undef_symbols);
   4217 	  gdb_printf ("\n\t%4d variables\n\t%4d "
   4218 		      "procedures\n\t%4d labels\n",
   4219 		      n_undef_vars, n_undef_procs, n_undef_labels);
   4220 	  n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
   4221 
   4222 	}
   4223       pop_parse_stack ();
   4224 
   4225       sort_blocks (cust->primary_filetab ());
   4226     }
   4227 
   4228   /* Now link the psymtab and the symtab.  */
   4229   pst->compunit_symtab = cust;
   4230 
   4231   mdebugread_objfile = NULL;
   4232 }
   4233 
   4234 /* Ancillary parsing procedures.  */
   4236 
   4237 /* Return 1 if the symbol pointed to by SH has a cross reference
   4238    to an opaque aggregate type, else 0.  */
   4239 
   4240 static int
   4241 has_opaque_xref (FDR *fh, SYMR *sh)
   4242 {
   4243   TIR tir;
   4244   union aux_ext *ax;
   4245   RNDXR rn[1];
   4246   unsigned int rf;
   4247 
   4248   if (sh->index == indexNil)
   4249     return 0;
   4250 
   4251   ax = debug_info->external_aux + fh->iauxBase + sh->index;
   4252   (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
   4253   if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
   4254     return 0;
   4255 
   4256   ax++;
   4257   (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
   4258   if (rn->rfd == 0xfff)
   4259     rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
   4260   else
   4261     rf = rn->rfd;
   4262   if (rf != -1)
   4263     return 0;
   4264   return 1;
   4265 }
   4266 
   4267 /* Lookup the type at relative index RN.  Return it in TPP
   4268    if found and in any event come up with its name PNAME.
   4269    BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
   4270    Return value says how many aux symbols we ate.  */
   4271 
   4272 static int
   4273 cross_ref (int fd, union aux_ext *ax, struct type **tpp,
   4274 	   enum type_code type_code,
   4275 	   /* Use to alloc new type if none is found.  */
   4276 	   const char **pname, int bigend, const char *sym_name)
   4277 {
   4278   RNDXR rn[1];
   4279   unsigned int rf;
   4280   int result = 1;
   4281   FDR *fh;
   4282   char *esh;
   4283   SYMR sh;
   4284   int xref_fd;
   4285   struct mdebug_pending *pend;
   4286 
   4287   *tpp = NULL;
   4288 
   4289   (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
   4290 
   4291   /* Escape index means 'the next one'.  */
   4292   if (rn->rfd == 0xfff)
   4293     {
   4294       result++;
   4295       rf = AUX_GET_ISYM (bigend, ax + 1);
   4296     }
   4297   else
   4298     {
   4299       rf = rn->rfd;
   4300     }
   4301 
   4302   type_allocator alloc (mdebugread_objfile, get_current_subfile ()->language);
   4303 
   4304   /* mips cc uses a rf of -1 for opaque struct definitions.
   4305      Set TYPE_STUB for these types so that check_typedef will
   4306      resolve them if the struct gets defined in another compilation unit.  */
   4307   if (rf == -1)
   4308     {
   4309       *pname = "<undefined>";
   4310       *tpp = alloc.new_type (type_code, 0, NULL);
   4311       (*tpp)->set_is_stub (true);
   4312       return result;
   4313     }
   4314 
   4315   /* mips cc uses an escaped rn->index of 0 for struct return types
   4316      of procedures that were compiled without -g.  These will always remain
   4317      undefined.  */
   4318   if (rn->rfd == 0xfff && rn->index == 0)
   4319     {
   4320       *pname = "<undefined>";
   4321       return result;
   4322     }
   4323 
   4324   /* Find the relative file descriptor and the symbol in it.  */
   4325   fh = get_rfd (fd, rf);
   4326   xref_fd = fh - debug_info->fdr;
   4327 
   4328   if (rn->index >= fh->csym)
   4329     {
   4330       /* File indirect entry is corrupt.  */
   4331       *pname = "<illegal>";
   4332       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
   4333       return result;
   4334     }
   4335 
   4336   /* If we have processed this symbol then we left a forwarding
   4337      pointer to the type in the pending list.  If not, we`ll put
   4338      it in a list of pending types, to be processed later when
   4339      the file will be.  In any event, we collect the name for the
   4340      type here.  */
   4341 
   4342   esh = ((char *) debug_info->external_sym
   4343 	 + ((fh->isymBase + rn->index)
   4344 	    * debug_swap->external_sym_size));
   4345   (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
   4346 
   4347   /* Make sure that this type of cross reference can be handled.  */
   4348   if ((sh.sc != scInfo
   4349        || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
   4350 	   && sh.st != stStruct && sh.st != stUnion
   4351 	   && sh.st != stEnum))
   4352       && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
   4353     {
   4354       /* File indirect entry is corrupt.  */
   4355       *pname = "<illegal>";
   4356       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
   4357       return result;
   4358     }
   4359 
   4360   *pname = debug_info->ss + fh->issBase + sh.iss;
   4361 
   4362   pend = is_pending_symbol (fh, esh);
   4363   if (pend)
   4364     *tpp = pend->t;
   4365   else
   4366     {
   4367       /* We have not yet seen this type.  */
   4368 
   4369       if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
   4370 	{
   4371 	  TIR tir;
   4372 
   4373 	  /* alpha cc puts out a stTypedef with a sh.iss of zero for
   4374 	     two cases:
   4375 	     a) forward declarations of structs/unions/enums which are not
   4376 	     defined in this compilation unit.
   4377 	     For these the type will be void.  This is a bad design decision
   4378 	     as cross referencing across compilation units is impossible
   4379 	     due to the missing name.
   4380 	     b) forward declarations of structs/unions/enums/typedefs which
   4381 	     are defined later in this file or in another file in the same
   4382 	     compilation unit.  Irix5 cc uses a stIndirect symbol for this.
   4383 	     Simply cross reference those again to get the true type.
   4384 	     The forward references are not entered in the pending list and
   4385 	     in the symbol table.  */
   4386 
   4387 	  (*debug_swap->swap_tir_in) (bigend,
   4388 				      &(debug_info->external_aux
   4389 					+ fh->iauxBase + sh.index)->a_ti,
   4390 				      &tir);
   4391 	  if (tir.tq0 != tqNil)
   4392 	    complaint (_("illegal tq0 in forward typedef for %s"), sym_name);
   4393 	  switch (tir.bt)
   4394 	    {
   4395 	    case btVoid:
   4396 	      *tpp = alloc.new_type (type_code, 0, NULL);
   4397 	      *pname = "<undefined>";
   4398 	      break;
   4399 
   4400 	    case btStruct:
   4401 	    case btUnion:
   4402 	    case btEnum:
   4403 	      cross_ref (xref_fd,
   4404 			 (debug_info->external_aux
   4405 			  + fh->iauxBase + sh.index + 1),
   4406 			 tpp, type_code, pname,
   4407 			 fh->fBigendian, sym_name);
   4408 	      break;
   4409 
   4410 	    case btTypedef:
   4411 	      /* Follow a forward typedef.  This might recursively
   4412 		 call cross_ref till we get a non typedef'ed type.
   4413 		 FIXME: This is not correct behavior, but gdb currently
   4414 		 cannot handle typedefs without type copying.  Type
   4415 		 copying is impossible as we might have mutual forward
   4416 		 references between two files and the copied type would not
   4417 		 get filled in when we later parse its definition.  */
   4418 	      *tpp = parse_type (xref_fd,
   4419 				 debug_info->external_aux + fh->iauxBase,
   4420 				 sh.index,
   4421 				 NULL,
   4422 				 fh->fBigendian,
   4423 				 debug_info->ss + fh->issBase + sh.iss);
   4424 	      add_pending (fh, esh, *tpp);
   4425 	      break;
   4426 
   4427 	    default:
   4428 	      complaint (_("illegal bt %d in forward typedef for %s"), tir.bt,
   4429 			 sym_name);
   4430 	      *tpp = alloc.new_type (type_code, 0, NULL);
   4431 	      break;
   4432 	    }
   4433 	  return result;
   4434 	}
   4435       else if (sh.st == stTypedef)
   4436 	{
   4437 	  /* Parse the type for a normal typedef.  This might recursively call
   4438 	     cross_ref till we get a non typedef'ed type.
   4439 	     FIXME: This is not correct behavior, but gdb currently
   4440 	     cannot handle typedefs without type copying.  But type copying is
   4441 	     impossible as we might have mutual forward references between
   4442 	     two files and the copied type would not get filled in when
   4443 	     we later parse its definition.   */
   4444 	  *tpp = parse_type (xref_fd,
   4445 			     debug_info->external_aux + fh->iauxBase,
   4446 			     sh.index,
   4447 			     NULL,
   4448 			     fh->fBigendian,
   4449 			     debug_info->ss + fh->issBase + sh.iss);
   4450 	}
   4451       else
   4452 	{
   4453 	  /* Cross reference to a struct/union/enum which is defined
   4454 	     in another file in the same compilation unit but that file
   4455 	     has not been parsed yet.
   4456 	     Initialize the type only, it will be filled in when
   4457 	     it's definition is parsed.  */
   4458 	  *tpp = alloc.new_type (type_code, 0, NULL);
   4459 	}
   4460       add_pending (fh, esh, *tpp);
   4461     }
   4462 
   4463   /* We used one auxent normally, two if we got a "next one" rf.  */
   4464   return result;
   4465 }
   4466 
   4467 
   4468 /* Quick&dirty lookup procedure, to avoid the MI ones that require
   4469    keeping the symtab sorted.  */
   4470 
   4471 static struct symbol *
   4472 mylookup_symbol (const char *name, const struct block *block,
   4473 		 domain_enum domain, enum address_class theclass)
   4474 {
   4475   int inc;
   4476 
   4477   inc = name[0];
   4478   for (struct symbol *sym : block_iterator_range (block))
   4479     {
   4480       if (sym->linkage_name ()[0] == inc
   4481 	  && sym->domain () == domain
   4482 	  && sym->aclass () == theclass
   4483 	  && strcmp (sym->linkage_name (), name) == 0)
   4484 	return sym;
   4485     }
   4486 
   4487   block = block->superblock ();
   4488   if (block)
   4489     return mylookup_symbol (name, block, domain, theclass);
   4490   return 0;
   4491 }
   4492 
   4493 
   4494 /* Add a new symbol S to a block B.  */
   4495 
   4496 static void
   4497 add_symbol (struct symbol *s, struct symtab *symtab, struct block *b)
   4498 {
   4499   s->set_symtab (symtab);
   4500   mdict_add_symbol (b->multidict (), s);
   4501 }
   4502 
   4503 /* Add a new block B to a symtab S.  */
   4504 
   4505 static void
   4506 add_block (struct block *b, struct symtab *s)
   4507 {
   4508   /* Cast away "const", but that's ok because we're building the
   4509      symtab and blockvector here.  */
   4510   struct blockvector *bv
   4511     = (struct blockvector *) s->compunit ()->blockvector ();
   4512 
   4513   bv = (struct blockvector *) xrealloc ((void *) bv,
   4514 					(sizeof (struct blockvector)
   4515 					 + bv->num_blocks ()
   4516 					 * sizeof (struct block)));
   4517   if (bv != s->compunit ()->blockvector ())
   4518     s->compunit ()->set_blockvector (bv);
   4519 
   4520   bv->set_block (bv->num_blocks (), b);
   4521   bv->set_num_blocks (bv->num_blocks () + 1);
   4522 }
   4523 
   4524 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
   4525    MIPS' linenumber encoding might need more than one byte
   4526    to describe it, LAST is used to detect these continuation lines.
   4527 
   4528    Combining lines with the same line number seems like a bad idea.
   4529    E.g: There could be a line number entry with the same line number after the
   4530    prologue and GDB should not ignore it (this is a better way to find
   4531    a prologue than mips_skip_prologue).
   4532    But due to the compressed line table format there are line number entries
   4533    for the same line which are needed to bridge the gap to the next
   4534    line number entry.  These entries have a bogus address info with them
   4535    and we are unable to tell them from intended duplicate line number
   4536    entries.
   4537    This is another reason why -ggdb debugging format is preferable.  */
   4538 
   4539 static int
   4540 add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
   4541 {
   4542   /* DEC c89 sometimes produces zero linenos which confuse gdb.
   4543      Change them to something sensible.  */
   4544   if (lineno == 0)
   4545     lineno = 1;
   4546   if (last == 0)
   4547     last = -2;			/* Make sure we record first line.  */
   4548 
   4549   if (last == lineno)		/* Skip continuation lines.  */
   4550     return lineno;
   4551 
   4552   lt->item[lt->nitems].line = lineno;
   4553   lt->item[lt->nitems++].set_unrelocated_pc (unrelocated_addr (adr << 2));
   4554   return lineno;
   4555 }
   4556 
   4557 /* Sorting and reordering procedures.  */
   4559 
   4560 /* Blocks with a smaller low bound should come first.  */
   4561 
   4562 static bool
   4563 block_is_less_than (const struct block *b1, const struct block *b2)
   4564 {
   4565   CORE_ADDR start1 = b1->start ();
   4566   CORE_ADDR start2 = b2->start ();
   4567 
   4568   if (start1 != start2)
   4569     return start1 < start2;
   4570 
   4571   return (b2->end ()) < (b1->end ());
   4572 }
   4573 
   4574 /* Sort the blocks of a symtab S.
   4575    Reorder the blocks in the blockvector by code-address,
   4576    as required by some MI search routines.  */
   4577 
   4578 static void
   4579 sort_blocks (struct symtab *s)
   4580 {
   4581   /* We have to cast away const here, but this is ok because we're
   4582      constructing the blockvector in this code.  */
   4583   struct blockvector *bv
   4584     = (struct blockvector *) s->compunit ()->blockvector ();
   4585 
   4586   if (bv->num_blocks () <= FIRST_LOCAL_BLOCK)
   4587     {
   4588       /* Cosmetic */
   4589       if (bv->global_block ()->end () == 0)
   4590 	bv->global_block ()->set_start (0);
   4591       if (bv->static_block ()->end () == 0)
   4592 	bv->static_block ()->set_start (0);
   4593       return;
   4594     }
   4595   /*
   4596    * This is very unfortunate: normally all functions are compiled in
   4597    * the order they are found, but if the file is compiled -O3 things
   4598    * are very different.  It would be nice to find a reliable test
   4599    * to detect -O3 images in advance.
   4600    */
   4601   if (bv->num_blocks () > FIRST_LOCAL_BLOCK + 1)
   4602     {
   4603       gdb::array_view<block *> blocks_view = bv->blocks ();
   4604 
   4605       std::sort (blocks_view.begin () + FIRST_LOCAL_BLOCK,
   4606 		 blocks_view.end (), block_is_less_than);
   4607     }
   4608 
   4609   {
   4610     CORE_ADDR high = 0;
   4611     int i, j = bv->num_blocks ();
   4612 
   4613     for (i = FIRST_LOCAL_BLOCK; i < j; i++)
   4614       if (high < bv->block (i)->end ())
   4615 	high = bv->block (i)->end ();
   4616     bv->global_block ()->set_end (high);
   4617   }
   4618 
   4619   bv->global_block ()->set_start (bv->block (FIRST_LOCAL_BLOCK)->start ());
   4620   bv->static_block ()->set_start (bv->global_block ()->start ());
   4621   bv->static_block ()->set_end (bv->global_block ()->end ());
   4622 }
   4623 
   4624 
   4626 /* Constructor/restructor/destructor procedures.  */
   4627 
   4628 /* Allocate a new symtab for NAME.  Needs an estimate of how many
   4629    linenumbers MAXLINES we'll put in it.  */
   4630 
   4631 static struct compunit_symtab *
   4632 new_symtab (const char *name, int maxlines, struct objfile *objfile)
   4633 {
   4634   struct compunit_symtab *cust = allocate_compunit_symtab (objfile, name);
   4635   struct symtab *symtab;
   4636   struct blockvector *bv;
   4637   enum language lang;
   4638 
   4639   add_compunit_symtab_to_objfile (cust);
   4640   symtab = allocate_symtab (cust, name);
   4641 
   4642   symtab->set_linetable (new_linetable (maxlines));
   4643   lang = cust->language ();
   4644 
   4645   /* All symtabs must have at least two blocks.  */
   4646   bv = new_bvect (2);
   4647   bv->set_block (GLOBAL_BLOCK, new_block (objfile, NON_FUNCTION_BLOCK, lang));
   4648   bv->set_block (STATIC_BLOCK, new_block (objfile, NON_FUNCTION_BLOCK, lang));
   4649   bv->static_block ()->set_superblock (bv->global_block ());
   4650   cust->set_blockvector (bv);
   4651 
   4652   cust->set_debugformat ("ECOFF");
   4653   return cust;
   4654 }
   4655 
   4656 /* Allocate a new partial_symtab NAME.  */
   4657 
   4658 static legacy_psymtab *
   4659 new_psymtab (const char *name, psymtab_storage *partial_symtabs,
   4660 	     struct objfile *objfile)
   4661 {
   4662   legacy_psymtab *psymtab;
   4663 
   4664   psymtab = new legacy_psymtab (name, partial_symtabs, objfile->per_bfd);
   4665 
   4666   /* Keep a backpointer to the file's symbols.  */
   4667 
   4668   psymtab->read_symtab_private
   4669     = OBSTACK_ZALLOC (&objfile->objfile_obstack, md_symloc);
   4670   CUR_BFD (psymtab) = cur_bfd;
   4671   DEBUG_SWAP (psymtab) = debug_swap;
   4672   DEBUG_INFO (psymtab) = debug_info;
   4673   PENDING_LIST (psymtab) = pending_list;
   4674 
   4675   /* The way to turn this into a symtab is to call...  */
   4676   psymtab->legacy_read_symtab = mdebug_read_symtab;
   4677   psymtab->legacy_expand_psymtab = mdebug_expand_psymtab;
   4678   return (psymtab);
   4679 }
   4680 
   4681 
   4682 /* Allocate a linetable array of the given SIZE.  Since the struct
   4683    already includes one item, we subtract one when calculating the
   4684    proper size to allocate.  */
   4685 
   4686 static struct linetable *
   4687 new_linetable (int size)
   4688 {
   4689   struct linetable *l;
   4690 
   4691   if (size > 1)
   4692     --size;
   4693   size = size * sizeof (l->item) + sizeof (struct linetable);
   4694   l = (struct linetable *) xmalloc (size);
   4695   l->nitems = 0;
   4696   return l;
   4697 }
   4698 
   4699 /* Oops, too big.  Shrink it.  This was important with the 2.4 linetables,
   4700    I am not so sure about the 3.4 ones.
   4701 
   4702    Since the struct linetable already includes one item, we subtract one when
   4703    calculating the proper size to allocate.  */
   4704 
   4705 static struct linetable *
   4706 shrink_linetable (struct linetable *lt)
   4707 {
   4708   return (struct linetable *) xrealloc ((void *) lt,
   4709 					(sizeof (struct linetable)
   4710 					 + ((lt->nitems - 1)
   4711 					    * sizeof (lt->item))));
   4712 }
   4713 
   4714 /* Allocate and zero a new blockvector of NBLOCKS blocks.  */
   4715 
   4716 static struct blockvector *
   4717 new_bvect (int nblocks)
   4718 {
   4719   struct blockvector *bv;
   4720   int size;
   4721 
   4722   size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
   4723   bv = (struct blockvector *) xzalloc (size);
   4724   bv->set_num_blocks (nblocks);
   4725 
   4726   return bv;
   4727 }
   4728 
   4729 /* Allocate and zero a new block of language LANGUAGE, and set its
   4730    BLOCK_MULTIDICT.  If function is non-zero, assume the block is
   4731    associated to a function, and make sure that the symbols are stored
   4732    linearly; otherwise, store them hashed.  */
   4733 
   4734 static struct block *
   4735 new_block (struct objfile *objfile, enum block_type type,
   4736 	   enum language language)
   4737 {
   4738   struct block *retval = new (&objfile->objfile_obstack) block;
   4739 
   4740   if (type == FUNCTION_BLOCK)
   4741     retval->set_multidict (mdict_create_linear_expandable (language));
   4742   else
   4743     retval->set_multidict (mdict_create_hashed_expandable (language));
   4744 
   4745   return retval;
   4746 }
   4747 
   4748 /* Create a new symbol with printname NAME.  */
   4749 
   4750 static struct symbol *
   4751 new_symbol (const char *name)
   4752 {
   4753   struct symbol *s = new (&mdebugread_objfile->objfile_obstack) symbol;
   4754 
   4755   s->set_language (psymtab_language, &mdebugread_objfile->objfile_obstack);
   4756   s->compute_and_set_names (name, true, mdebugread_objfile->per_bfd);
   4757   return s;
   4758 }
   4759 
   4760 /* Create a new type with printname NAME.  */
   4761 
   4762 static struct type *
   4763 new_type (char *name)
   4764 {
   4765   struct type *t;
   4766 
   4767   t = type_allocator (mdebugread_objfile,
   4768 		      get_current_subfile ()->language).new_type ();
   4769   t->set_name (name);
   4770   INIT_CPLUS_SPECIFIC (t);
   4771   return t;
   4772 }
   4773 
   4774 /* Read ECOFF debugging information from a BFD section.  This is
   4776    called from elfread.c.  It parses the section into a
   4777    ecoff_debug_info struct, and then lets the rest of the file handle
   4778    it as normal.  */
   4779 
   4780 void
   4781 elfmdebug_build_psymtabs (struct objfile *objfile,
   4782 			  const struct ecoff_debug_swap *swap, asection *sec)
   4783 {
   4784   bfd *abfd = objfile->obfd.get ();
   4785   struct ecoff_debug_info *info;
   4786 
   4787   /* FIXME: It's not clear whether we should be getting minimal symbol
   4788      information from .mdebug in an ELF file, or whether we will.
   4789      Re-initialize the minimal symbol reader in case we do.  */
   4790 
   4791   minimal_symbol_reader reader (objfile);
   4792 
   4793   info = XOBNEW (&objfile->objfile_obstack, ecoff_debug_info);
   4794 
   4795   if (!(*swap->read_debug_info) (abfd, sec, info))
   4796     error (_("Error reading ECOFF debugging information: %s"),
   4797 	   bfd_errmsg (bfd_get_error ()));
   4798 
   4799   mdebug_build_psymtabs (reader, objfile, swap, info);
   4800 
   4801   reader.install ();
   4802 }
   4803 
   4804 void _initialize_mdebugread ();
   4805 void
   4806 _initialize_mdebugread ()
   4807 {
   4808   mdebug_register_index
   4809     = register_symbol_register_impl (LOC_REGISTER, &mdebug_register_funcs);
   4810   mdebug_regparm_index
   4811     = register_symbol_register_impl (LOC_REGPARM_ADDR, &mdebug_register_funcs);
   4812 }
   4813