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