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