gdb/mdebugread.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Read a symbol table in ECOFF format (Third-Eye).

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
  4.    CMU.  Major work by Per Bothner, John Gilmore and Ian Lance Taylor
  5.    at Cygnus Support.

  6.    This file is part of GDB.

  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.

  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.

  15.    You should have received a copy of the GNU General Public License
  16.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  17. /* This module provides the function mdebug_build_psymtabs.  It reads
  18.    ECOFF debugging information into partial symbol tables.  The
  19.    debugging information is read from two structures.  A struct
  20.    ecoff_debug_swap includes the sizes of each ECOFF structure and
  21.    swapping routines; these are fixed for a particular target.  A
  22.    struct ecoff_debug_info points to the debugging information for a
  23.    particular object file.

  24.    ECOFF symbol tables are mostly written in the byte order of the
  25.    target machine.  However, one section of the table (the auxiliary
  26.    symbol information) is written in the host byte order.  There is a
  27.    bit in the other symbol info which describes which host byte order
  28.    was used.  ECOFF thereby takes the trophy from Intel `b.out' for
  29.    the most brain-dead adaptation of a file format to byte order.

  30.    This module can read all four of the known byte-order combinations,
  31.    on any type of host.  */

  32. #include "defs.h"
  33. #include "symtab.h"
  34. #include "gdbtypes.h"
  35. #include "gdbcore.h"
  36. #include "filenames.h"
  37. #include "objfiles.h"
  38. #include "gdb_obstack.h"
  39. #include "buildsym.h"
  40. #include "stabsread.h"
  41. #include "complaints.h"
  42. #include "demangle.h"
  43. #include "gdb-demangle.h"
  44. #include "block.h"
  45. #include "dictionary.h"
  46. #include "mdebugread.h"
  47. #include <sys/stat.h>
  48. #include "psympriv.h"
  49. #include "source.h"

  50. #include "bfd.h"

  51. #include "coff/ecoff.h"                /* COFF-like aspects of ecoff files.  */

  52. #include "libaout.h"                /* Private BFD a.out information.  */
  53. #include "aout/aout64.h"
  54. #include "aout/stab_gnu.h"        /* STABS information.  */

  55. #include "expression.h"

  56. extern void _initialize_mdebugread (void);

  57. /* Provide a way to test if we have both ECOFF and ELF symbol tables.
  58.    We use this define in order to know whether we should override a
  59.    symbol's ECOFF section with its ELF section.  This is necessary in
  60.    case the symbol's ELF section could not be represented in ECOFF.  */
  61. #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  62.                            && bfd_get_section_by_name (bfd, ".mdebug") != NULL)

  63. /* The objfile we are currently reading.  */

  64. static struct objfile *mdebugread_objfile;



  65. /* We put a pointer to this structure in the read_symtab_private field
  66.    of the psymtab.  */

  67. struct symloc
  68.   {
  69.     /* Index of the FDR that this psymtab represents.  */
  70.     int fdr_idx;
  71.     /* The BFD that the psymtab was created from.  */
  72.     bfd *cur_bfd;
  73.     const struct ecoff_debug_swap *debug_swap;
  74.     struct ecoff_debug_info *debug_info;
  75.     struct mdebug_pending **pending_list;
  76.     /* Pointer to external symbols for this file.  */
  77.     EXTR *extern_tab;
  78.     /* Size of extern_tab.  */
  79.     int extern_count;
  80.     enum language pst_language;
  81.   };

  82. #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
  83. #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
  84. #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
  85. #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
  86. #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
  87. #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)

  88. #define SC_IS_TEXT(sc) ((sc) == scText \
  89.                    || (sc) == scRConst \
  90.                      || (sc) == scInit \
  91.                      || (sc) == scFini)
  92. #define SC_IS_DATA(sc) ((sc) == scData \
  93.                    || (sc) == scSData \
  94.                    || (sc) == scRData \
  95.                    || (sc) == scPData \
  96.                    || (sc) == scXData)
  97. #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
  98. #define SC_IS_BSS(sc) ((sc) == scBss)
  99. #define SC_IS_SBSS(sc) ((sc) == scSBss)
  100. #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)

  101. /* Various complaints about symbol reading that don't abort the process.  */
  102. static void
  103. index_complaint (const char *arg1)
  104. {
  105.   complaint (&symfile_complaints, _("bad aux index at symbol %s"), arg1);
  106. }

  107. static void
  108. unknown_ext_complaint (const char *arg1)
  109. {
  110.   complaint (&symfile_complaints, _("unknown external symbol %s"), arg1);
  111. }

  112. static void
  113. basic_type_complaint (int arg1, const char *arg2)
  114. {
  115.   complaint (&symfile_complaints, _("cannot map ECOFF basic type 0x%x for %s"),
  116.              arg1, arg2);
  117. }

  118. static void
  119. bad_tag_guess_complaint (const char *arg1)
  120. {
  121.   complaint (&symfile_complaints,
  122.              _("guessed tag type of %s incorrectly"), arg1);
  123. }

  124. static void
  125. bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3)
  126. {
  127.   complaint (&symfile_complaints, _("bad rfd entry for %s: file %d, index %d"),
  128.              arg1, arg2, arg3);
  129. }

  130. static void
  131. unexpected_type_code_complaint (const char *arg1)
  132. {
  133.   complaint (&symfile_complaints, _("unexpected type code for %s"), arg1);
  134. }

  135. /* Macros and extra defs.  */

  136. /* Puns: hard to find whether -g was used and how.  */

  137. #define MIN_GLEVEL GLEVEL_0
  138. #define compare_glevel(a,b)                                        \
  139.         (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) :                        \
  140.          ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))

  141. /* Things that really are local to this module.  */

  142. /* Remember what we deduced to be the source language of this psymtab.  */

  143. static enum language psymtab_language = language_unknown;

  144. /* Current BFD.  */

  145. static bfd *cur_bfd;

  146. /* How to parse debugging information for CUR_BFD.  */

  147. static const struct ecoff_debug_swap *debug_swap;

  148. /* Pointers to debugging information for CUR_BFD.  */

  149. static struct ecoff_debug_info *debug_info;

  150. /* Pointer to current file decriptor record, and its index.  */

  151. static FDR *cur_fdr;
  152. static int cur_fd;

  153. /* Index of current symbol.  */

  154. static int cur_sdx;

  155. /* Note how much "debuggable" this image is.  We would like
  156.    to see at least one FDR with full symbols.  */

  157. static int max_gdbinfo;
  158. static int max_glevel;

  159. /* When examining .o files, report on undefined symbols.  */

  160. static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;

  161. /* Pseudo symbol to use when putting stabs into the symbol table.  */

  162. static char stabs_symbol[] = STABS_SYMBOL;

  163. /* Nonzero if we have seen ecoff debugging info for a file.  */

  164. static int found_ecoff_debugging_info;

  165. /* Forward declarations.  */

  166. static int upgrade_type (int, struct type **, int, union aux_ext *,
  167.                          int, char *);

  168. static void parse_partial_symbols (struct objfile *);

  169. static int has_opaque_xref (FDR *, SYMR *);

  170. static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
  171.                       char **, int, char *);

  172. static struct symbol *new_symbol (char *);

  173. static struct type *new_type (char *);

  174. enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };

  175. static struct block *new_block (enum block_type);

  176. static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);

  177. static struct linetable *new_linetable (int);

  178. static struct blockvector *new_bvect (int);

  179. static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
  180.                                 int, char *);

  181. static struct symbol *mylookup_symbol (char *, const struct block *,
  182.                                        domain_enum, enum address_class);

  183. static void sort_blocks (struct symtab *);

  184. static struct partial_symtab *new_psymtab (char *, struct objfile *);

  185. static void psymtab_to_symtab_1 (struct objfile *objfile,
  186.                                  struct partial_symtab *, const char *);

  187. static void add_block (struct block *, struct symtab *);

  188. static void add_symbol (struct symbol *, struct symtab *, struct block *);

  189. static int add_line (struct linetable *, int, CORE_ADDR, int);

  190. static struct linetable *shrink_linetable (struct linetable *);

  191. static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
  192.                                         CORE_ADDR);

  193. static char *mdebug_next_symbol_text (struct objfile *);

  194. /* Exported procedure: Builds a symtab from the partial symtab SELF.
  195.    Restores the environment in effect when SELF was created, delegates
  196.    most of the work to an ancillary procedure, and sorts
  197.    and reorders the symtab list at the end.  SELF is not NULL.  */

  198. static void
  199. mdebug_read_symtab (struct partial_symtab *self, struct objfile *objfile)
  200. {
  201.   if (info_verbose)
  202.     {
  203.       printf_filtered (_("Reading in symbols for %s..."), self->filename);
  204.       gdb_flush (gdb_stdout);
  205.     }

  206.   next_symbol_text_func = mdebug_next_symbol_text;

  207.   psymtab_to_symtab_1 (objfile, self, self->filename);

  208.   /* Match with global symbols.  This only needs to be done once,
  209.      after all of the symtabs and dependencies have been read in.  */
  210.   scan_file_globals (objfile);

  211.   if (info_verbose)
  212.     printf_filtered (_("done.\n"));
  213. }

  214. /* File-level interface functions.  */

  215. /* Find a file descriptor given its index RF relative to a file CF.  */

  216. static FDR *
  217. get_rfd (int cf, int rf)
  218. {
  219.   FDR *fdrs;
  220.   FDR *f;
  221.   RFDT rfd;

  222.   fdrs = debug_info->fdr;
  223.   f = fdrs + cf;
  224.   /* Object files do not have the RFD table, all refs are absolute.  */
  225.   if (f->rfdBase == 0)
  226.     return fdrs + rf;
  227.   (*debug_swap->swap_rfd_in) (cur_bfd,
  228.                               ((char *) debug_info->external_rfd
  229.                                + ((f->rfdBase + rf)
  230.                                   * debug_swap->external_rfd_size)),
  231.                               &rfd);
  232.   return fdrs + rfd;
  233. }

  234. /* Return a safer print NAME for a file descriptor.  */

  235. static char *
  236. fdr_name (FDR *f)
  237. {
  238.   if (f->rss == -1)
  239.     return "<stripped file>";
  240.   if (f->rss == 0)
  241.     return "<NFY>";
  242.   return debug_info->ss + f->issBase + f->rss;
  243. }


  244. /* Read in and parse the symtab of the file OBJFILE.  Symbols from
  245.    different sections are relocated via the SECTION_OFFSETS.  */

  246. void
  247. mdebug_build_psymtabs (struct objfile *objfile,
  248.                        const struct ecoff_debug_swap *swap,
  249.                        struct ecoff_debug_info *info)
  250. {
  251.   cur_bfd = objfile->obfd;
  252.   debug_swap = swap;
  253.   debug_info = info;

  254.   stabsread_new_init ();
  255.   buildsym_new_init ();
  256.   free_header_files ();
  257.   init_header_files ();

  258.   /* Make sure all the FDR information is swapped in.  */
  259.   if (info->fdr == (FDR *) NULL)
  260.     {
  261.       char *fdr_src;
  262.       char *fdr_end;
  263.       FDR *fdr_ptr;

  264.       info->fdr = (FDR *) obstack_alloc (&objfile->objfile_obstack,
  265.                                          (info->symbolic_header.ifdMax
  266.                                           * sizeof (FDR)));
  267.       fdr_src = info->external_fdr;
  268.       fdr_end = (fdr_src
  269.                  + info->symbolic_header.ifdMax * swap->external_fdr_size);
  270.       fdr_ptr = info->fdr;
  271.       for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
  272.         (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
  273.     }

  274.   parse_partial_symbols (objfile);

  275. #if 0
  276.   /* Check to make sure file was compiled with -g.  If not, warn the
  277.      user of this limitation.  */
  278.   if (compare_glevel (max_glevel, GLEVEL_2) < 0)
  279.     {
  280.       if (max_gdbinfo == 0)
  281.         printf_unfiltered (_("\n%s not compiled with -g, "
  282.                              "debugging support is limited.\n"),
  283.                            objfile->name);
  284.       printf_unfiltered (_("You should compile with -g2 or "
  285.                            "-g3 for best debugging support.\n"));
  286.       gdb_flush (gdb_stdout);
  287.     }
  288. #endif
  289. }

  290. /* Local utilities */

  291. /* Map of FDR indexes to partial symtabs.  */

  292. struct pst_map
  293. {
  294.   struct partial_symtab *pst;        /* the psymtab proper */
  295.   long n_globals;                /* exported globals (external symbols) */
  296.   long globals_offset;                /* cumulative */
  297. };


  298. /* Utility stack, used to nest procedures and blocks properly.
  299.    It is a doubly linked list, to avoid too many alloc/free.
  300.    Since we might need it quite a few times it is NOT deallocated
  301.    after use.  */

  302. static struct parse_stack
  303.   {
  304.     struct parse_stack *next, *prev;
  305.     struct symtab *cur_st;        /* Current symtab.  */
  306.     struct block *cur_block;        /* Block in it.  */

  307.     /* What are we parsing.  stFile, or stBlock are for files and
  308.        blocks.  stProc or stStaticProc means we have seen the start of a
  309.        procedure, but not the start of the block within in.  When we see
  310.        the start of that block, we change it to stNil, without pushing a
  311.        new block, i.e. stNil means both a procedure and a block.  */

  312.     int blocktype;

  313.     struct type *cur_type;        /* Type we parse fields for.  */
  314.     int cur_field;                /* Field number in cur_type.  */
  315.     CORE_ADDR procadr;                /* Start addres of this procedure.  */
  316.     int numargs;                /* Its argument count.  */
  317.   }

  318. *top_stack;                        /* Top stack ptr */


  319. /* Enter a new lexical context.  */

  320. static void
  321. push_parse_stack (void)
  322. {
  323.   struct parse_stack *new;

  324.   /* Reuse frames if possible.  */
  325.   if (top_stack && top_stack->prev)
  326.     new = top_stack->prev;
  327.   else
  328.     new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
  329.   /* Initialize new frame with previous content.  */
  330.   if (top_stack)
  331.     {
  332.       struct parse_stack *prev = new->prev;

  333.       *new = *top_stack;
  334.       top_stack->prev = new;
  335.       new->prev = prev;
  336.       new->next = top_stack;
  337.     }
  338.   top_stack = new;
  339. }

  340. /* Exit a lexical context.  */

  341. static void
  342. pop_parse_stack (void)
  343. {
  344.   if (!top_stack)
  345.     return;
  346.   if (top_stack->next)
  347.     top_stack = top_stack->next;
  348. }


  349. /* Cross-references might be to things we haven't looked at
  350.    yet, e.g. type references.  To avoid too many type
  351.    duplications we keep a quick fixup table, an array
  352.    of lists of references indexed by file descriptor.  */

  353. struct mdebug_pending
  354. {
  355.   struct mdebug_pending *next;        /* link */
  356.   char *s;                        /* the unswapped symbol */
  357.   struct type *t;                /* its partial type descriptor */
  358. };


  359. /* The pending information is kept for an entire object file.  We
  360.    allocate the pending information table when we create the partial
  361.    symbols, and we store a pointer to the single table in each
  362.    psymtab.  */

  363. static struct mdebug_pending **pending_list;

  364. /* Check whether we already saw symbol SH in file FH.  */

  365. static struct mdebug_pending *
  366. is_pending_symbol (FDR *fh, char *sh)
  367. {
  368.   int f_idx = fh - debug_info->fdr;
  369.   struct mdebug_pending *p;

  370.   /* Linear search is ok, list is typically no more than 10 deep.  */
  371.   for (p = pending_list[f_idx]; p; p = p->next)
  372.     if (p->s == sh)
  373.       break;
  374.   return p;
  375. }

  376. /* Add a new symbol SH of type T.  */

  377. static void
  378. add_pending (FDR *fh, char *sh, struct type *t)
  379. {
  380.   int f_idx = fh - debug_info->fdr;
  381.   struct mdebug_pending *p = is_pending_symbol (fh, sh);

  382.   /* Make sure we do not make duplicates.  */
  383.   if (!p)
  384.     {
  385.       p = ((struct mdebug_pending *)
  386.            obstack_alloc (&mdebugread_objfile->objfile_obstack,
  387.                           sizeof (struct mdebug_pending)));
  388.       p->s = sh;
  389.       p->t = t;
  390.       p->next = pending_list[f_idx];
  391.       pending_list[f_idx] = p;
  392.     }
  393. }


  394. /* Parsing Routines proper.  */

  395. /* Parse a single symbol.  Mostly just make up a GDB symbol for it.
  396.    For blocks, procedures and types we open a new lexical context.
  397.    This is basically just a big switch on the symbol's type.  Argument
  398.    AX is the base pointer of aux symbols for this file (fh->iauxBase).
  399.    EXT_SH points to the unswapped symbol, which is needed for struct,
  400.    union, etc., types; it is NULL for an EXTR.  BIGEND says whether
  401.    aux symbols are big-endian or little-endian.  Return count of
  402.    SYMR's handled (normally one).  */

  403. static int
  404. mdebug_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
  405. {
  406.   return gdbarch_ecoff_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
  407. }

  408. static const struct symbol_register_ops mdebug_register_funcs = {
  409.   mdebug_reg_to_regnum
  410. };

  411. /* The "aclass" indices for computed symbols.  */

  412. static int mdebug_register_index;
  413. static int mdebug_regparm_index;

  414. static int
  415. parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
  416.               struct section_offsets *section_offsets, struct objfile *objfile)
  417. {
  418.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  419.   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
  420.   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
  421.   char *name;
  422.   struct symbol *s;
  423.   struct block *b;
  424.   struct mdebug_pending *pend;
  425.   struct type *t;
  426.   struct field *f;
  427.   int count = 1;
  428.   enum address_class class;
  429.   TIR tir;
  430.   long svalue = sh->value;
  431.   int bitsize;

  432.   if (ext_sh == (char *) NULL)
  433.     name = debug_info->ssext + sh->iss;
  434.   else
  435.     name = debug_info->ss + cur_fdr->issBase + sh->iss;

  436.   switch (sh->sc)
  437.     {
  438.     case scText:
  439.     case scRConst:
  440.       /* Do not relocate relative values.
  441.          The value of a stEnd symbol is the displacement from the
  442.          corresponding start symbol value.
  443.          The value of a stBlock symbol is the displacement from the
  444.          procedure address.  */
  445.       if (sh->st != stEnd && sh->st != stBlock)
  446.         sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
  447.       break;
  448.     case scData:
  449.     case scSData:
  450.     case scRData:
  451.     case scPData:
  452.     case scXData:
  453.       sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
  454.       break;
  455.     case scBss:
  456.     case scSBss:
  457.       sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
  458.       break;
  459.     }

  460.   switch (sh->st)
  461.     {
  462.     case stNil:
  463.       break;

  464.     case stGlobal:                /* External symbol, goes into global block.  */
  465.       class = LOC_STATIC;
  466.       b = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (top_stack->cur_st),
  467.                              GLOBAL_BLOCK);
  468.       s = new_symbol (name);
  469.       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
  470.       goto data;

  471.     case stStatic:                /* Static data, goes into current block.  */
  472.       class = LOC_STATIC;
  473.       b = top_stack->cur_block;
  474.       s = new_symbol (name);
  475.       if (SC_IS_COMMON (sh->sc))
  476.         {
  477.           /* It is a FORTRAN common block.  At least for SGI Fortran the
  478.              address is not in the symbol; we need to fix it later in
  479.              scan_file_globals.  */
  480.           int bucket = hashname (SYMBOL_LINKAGE_NAME (s));
  481.           SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
  482.           global_sym_chain[bucket] = s;
  483.         }
  484.       else
  485.         SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
  486.       goto data;

  487.     case stLocal:                /* Local variable, goes into current block.  */
  488.       b = top_stack->cur_block;
  489.       s = new_symbol (name);
  490.       SYMBOL_VALUE (s) = svalue;
  491.       if (sh->sc == scRegister)
  492.         class = mdebug_register_index;
  493.       else
  494.         class = LOC_LOCAL;

  495.     data:                        /* Common code for symbols describing data.  */
  496.       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
  497.       SYMBOL_ACLASS_INDEX (s) = class;
  498.       add_symbol (s, top_stack->cur_st, b);

  499.       /* Type could be missing if file is compiled without debugging info.  */
  500.       if (SC_IS_UNDEF (sh->sc)
  501.           || sh->sc == scNil || sh->index == indexNil)
  502.         SYMBOL_TYPE (s) = objfile_type (objfile)->nodebug_data_symbol;
  503.       else
  504.         SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
  505.       /* Value of a data symbol is its memory address.  */
  506.       break;

  507.     case stParam:                /* Arg to procedure, goes into current
  508.                                    block.  */
  509.       max_gdbinfo++;
  510.       found_ecoff_debugging_info = 1;
  511.       top_stack->numargs++;

  512.       /* Special GNU C++ name.  */
  513.       if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
  514.         name = "this";                /* FIXME, not alloc'd in obstack.  */
  515.       s = new_symbol (name);

  516.       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
  517.       SYMBOL_IS_ARGUMENT (s) = 1;
  518.       switch (sh->sc)
  519.         {
  520.         case scRegister:
  521.           /* Pass by value in register.  */
  522.           SYMBOL_ACLASS_INDEX (s) = mdebug_register_index;
  523.           break;
  524.         case scVar:
  525.           /* Pass by reference on stack.  */
  526.           SYMBOL_ACLASS_INDEX (s) = LOC_REF_ARG;
  527.           break;
  528.         case scVarRegister:
  529.           /* Pass by reference in register.  */
  530.           SYMBOL_ACLASS_INDEX (s) = mdebug_regparm_index;
  531.           break;
  532.         default:
  533.           /* Pass by value on stack.  */
  534.           SYMBOL_ACLASS_INDEX (s) = LOC_ARG;
  535.           break;
  536.         }
  537.       SYMBOL_VALUE (s) = svalue;
  538.       SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
  539.       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  540.       break;

  541.     case stLabel:                /* label, goes into current block.  */
  542.       s = new_symbol (name);
  543.       SYMBOL_DOMAIN (s) = VAR_DOMAIN;        /* So that it can be used */
  544.       SYMBOL_ACLASS_INDEX (s) = LOC_LABEL;        /* but not misused.  */
  545.       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
  546.       SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_int;
  547.       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  548.       break;

  549.     case stProc:        /* Procedure, usually goes into global block.  */
  550.     case stStaticProc:        /* Static procedure, goes into current block.  */
  551.       /* For stProc symbol records, we need to check the storage class
  552.          as well, as only (stProc, scText) entries represent "real"
  553.          procedures - See the Compaq document titled "Object File /
  554.          Symbol Table Format Specification" for more information.
  555.          If the storage class is not scText, we discard the whole block
  556.          of symbol records for this stProc.  */
  557.       if (sh->st == stProc && sh->sc != scText)
  558.         {
  559.           char *ext_tsym = ext_sh;
  560.           int keep_counting = 1;
  561.           SYMR tsym;

  562.           while (keep_counting)
  563.             {
  564.               ext_tsym += external_sym_size;
  565.               (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
  566.               count++;
  567.               switch (tsym.st)
  568.                 {
  569.                   case stParam:
  570.                     break;
  571.                   case stEnd:
  572.                     keep_counting = 0;
  573.                     break;
  574.                   default:
  575.                     complaint (&symfile_complaints,
  576.                                _("unknown symbol type 0x%x"), sh->st);
  577.                     break;
  578.                 }
  579.             }
  580.           break;
  581.         }
  582.       s = new_symbol (name);
  583.       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
  584.       SYMBOL_ACLASS_INDEX (s) = LOC_BLOCK;
  585.       /* Type of the return value.  */
  586.       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
  587.         t = objfile_type (objfile)->builtin_int;
  588.       else
  589.         {
  590.           t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
  591.           if (strcmp (name, "malloc") == 0
  592.               && TYPE_CODE (t) == TYPE_CODE_VOID)
  593.             {
  594.               /* I don't know why, but, at least under Alpha GNU/Linux,
  595.                  when linking against a malloc without debugging
  596.                  symbols, its read as a function returning void---this
  597.                  is bad because it means we cannot call functions with
  598.                  string arguments interactively; i.e., "call
  599.                  printf("howdy\n")" would fail with the error message
  600.                  "program has no memory available".  To avoid this, we
  601.                  patch up the type and make it void*
  602.                  instead. (davidm@azstarnet.com).  */
  603.               t = make_pointer_type (t, NULL);
  604.             }
  605.         }
  606.       b = top_stack->cur_block;
  607.       if (sh->st == stProc)
  608.         {
  609.           const struct blockvector *bv
  610.             = SYMTAB_BLOCKVECTOR (top_stack->cur_st);

  611.           /* The next test should normally be true, but provides a
  612.              hook for nested functions (which we don't want to make
  613.              global).  */
  614.           if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
  615.             b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  616.           /* Irix 5 sometimes has duplicate names for the same
  617.              function.  We want to add such names up at the global
  618.              level, not as a nested function.  */
  619.           else if (sh->value == top_stack->procadr)
  620.             b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  621.         }
  622.       add_symbol (s, top_stack->cur_st, b);

  623.       /* Make a type for the procedure itself.  */
  624.       SYMBOL_TYPE (s) = lookup_function_type (t);

  625.       /* All functions in C++ have prototypes.  For C we don't have enough
  626.          information in the debug info.  */
  627.       if (SYMBOL_LANGUAGE (s) == language_cplus)
  628.         TYPE_PROTOTYPED (SYMBOL_TYPE (s)) = 1;

  629.       /* Create and enter a new lexical context.  */
  630.       b = new_block (FUNCTION_BLOCK);
  631.       SYMBOL_BLOCK_VALUE (s) = b;
  632.       BLOCK_FUNCTION (b) = s;
  633.       BLOCK_START (b) = BLOCK_END (b) = sh->value;
  634.       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  635.       add_block (b, top_stack->cur_st);

  636.       /* Not if we only have partial info.  */
  637.       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
  638.         break;

  639.       push_parse_stack ();
  640.       top_stack->cur_block = b;
  641.       top_stack->blocktype = sh->st;
  642.       top_stack->cur_type = SYMBOL_TYPE (s);
  643.       top_stack->cur_field = -1;
  644.       top_stack->procadr = sh->value;
  645.       top_stack->numargs = 0;
  646.       break;

  647.       /* Beginning of code for structure, union, and enum definitions.
  648.          They all share a common set of local variables, defined here.  */
  649.       {
  650.         enum type_code type_code;
  651.         char *ext_tsym;
  652.         int nfields;
  653.         long max_value;
  654.         struct field *f;

  655.     case stStruct:                /* Start a block defining a struct type.  */
  656.         type_code = TYPE_CODE_STRUCT;
  657.         goto structured_common;

  658.     case stUnion:                /* Start a block defining a union type.  */
  659.         type_code = TYPE_CODE_UNION;
  660.         goto structured_common;

  661.     case stEnum:                /* Start a block defining an enum type.  */
  662.         type_code = TYPE_CODE_ENUM;
  663.         goto structured_common;

  664.     case stBlock:                /* Either a lexical block, or some type.  */
  665.         if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
  666.           goto case_stBlock_code;        /* Lexical block */

  667.         type_code = TYPE_CODE_UNDEF;        /* We have a type.  */

  668.         /* Common code for handling struct, union, enum, and/or as-yet-
  669.            unknown-type blocks of info about structured data.  `type_code'
  670.            has been set to the proper TYPE_CODE, if we know it.  */
  671.       structured_common:
  672.         found_ecoff_debugging_info = 1;
  673.         push_parse_stack ();
  674.         top_stack->blocktype = stBlock;

  675.         /* First count the number of fields and the highest value.  */
  676.         nfields = 0;
  677.         max_value = 0;
  678.         for (ext_tsym = ext_sh + external_sym_size;
  679.              ;
  680.              ext_tsym += external_sym_size)
  681.           {
  682.             SYMR tsym;

  683.             (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);

  684.             switch (tsym.st)
  685.               {
  686.               case stEnd:
  687.                 /* C++ encodes class types as structures where there the
  688.                    methods are encoded as stProc.  The scope of stProc
  689.                    symbols also ends with stEnd, thus creating a risk of
  690.                    taking the wrong stEnd symbol record as the end of
  691.                    the current struct, which would cause GDB to undercount
  692.                    the real number of fields in this struct.  To make sure
  693.                    we really reached the right stEnd symbol record, we
  694.                    check the associated name, and match it against the
  695.                    struct name.  Since method names are mangled while
  696.                    the class name is not, there is no risk of having a
  697.                    method whose name is identical to the class name
  698.                    (in particular constructor method names are different
  699.                    from the class name).  There is therefore no risk that
  700.                    this check stops the count on the StEnd of a method.

  701.                    Also, assume that we're really at the end when tsym.iss
  702.                    is 0 (issNull).  */
  703.                 if (tsym.iss == issNull
  704.                     || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss,
  705.                                name) == 0)
  706.                   goto end_of_fields;
  707.                 break;

  708.               case stMember:
  709.                 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
  710.                   {
  711.                     /* If the type of the member is Nil (or Void),
  712.                        without qualifiers, assume the tag is an
  713.                        enumeration.
  714.                        Alpha cc -migrate enums are recognized by a zero
  715.                        index and a zero symbol value.
  716.                        DU 4.0 cc enums are recognized by a member type of
  717.                        btEnum without qualifiers and a zero symbol value.  */
  718.                     if (tsym.index == indexNil
  719.                         || (tsym.index == 0 && sh->value == 0))
  720.                       type_code = TYPE_CODE_ENUM;
  721.                     else
  722.                       {
  723.                         (*debug_swap->swap_tir_in) (bigend,
  724.                                                     &ax[tsym.index].a_ti,
  725.                                                     &tir);
  726.                         if ((tir.bt == btNil || tir.bt == btVoid
  727.                              || (tir.bt == btEnum && sh->value == 0))
  728.                             && tir.tq0 == tqNil)
  729.                           type_code = TYPE_CODE_ENUM;
  730.                       }
  731.                   }
  732.                 nfields++;
  733.                 if (tsym.value > max_value)
  734.                   max_value = tsym.value;
  735.                 break;

  736.               case stBlock:
  737.               case stUnion:
  738.               case stEnum:
  739.               case stStruct:
  740.                 {
  741. #if 0
  742.                   /* This is a no-op; is it trying to tell us something
  743.                      we should be checking?  */
  744.                   if (tsym.sc == scVariant);        /*UNIMPLEMENTED */
  745. #endif
  746.                   if (tsym.index != 0)
  747.                     {
  748.                       /* This is something like a struct within a
  749.                          struct.  Skip over the fields of the inner
  750.                          struct.  The -1 is because the for loop will
  751.                          increment ext_tsym.  */
  752.                       ext_tsym = ((char *) debug_info->external_sym
  753.                                   + ((cur_fdr->isymBase + tsym.index - 1)
  754.                                      * external_sym_size));
  755.                     }
  756.                 }
  757.                 break;

  758.               case stTypedef:
  759.                 /* mips cc puts out a typedef for struct x if it is not yet
  760.                    defined when it encounters
  761.                    struct y { struct x *xp; };
  762.                    Just ignore it.  */
  763.                 break;

  764.               case stIndirect:
  765.                 /* Irix5 cc puts out a stIndirect for struct x if it is not
  766.                    yet defined when it encounters
  767.                    struct y { struct x *xp; };
  768.                    Just ignore it.  */
  769.                 break;

  770.               default:
  771.                 complaint (&symfile_complaints,
  772.                            _("declaration block contains "
  773.                              "unhandled symbol type %d"),
  774.                            tsym.st);
  775.               }
  776.           }
  777.       end_of_fields:

  778.         /* In an stBlock, there is no way to distinguish structs,
  779.            unions, and enums at this point.  This is a bug in the
  780.            original design (that has been fixed with the recent
  781.            addition of the stStruct, stUnion, and stEnum symbol
  782.            types.)  The way you can tell is if/when you see a variable
  783.            or field of that type.  In that case the variable's type
  784.            (in the AUX table) says if the type is struct, union, or
  785.            enum, and points back to the stBlock here.  So you can
  786.            patch the tag kind up later - but only if there actually is
  787.            a variable or field of that type.

  788.            So until we know for sure, we will guess at this point.
  789.            The heuristic is:
  790.            If the first member has index==indexNil or a void type,
  791.            assume we have an enumeration.
  792.            Otherwise, if there is more than one member, and all
  793.            the members have offset 0, assume we have a union.
  794.            Otherwise, assume we have a struct.

  795.            The heuristic could guess wrong in the case of of an
  796.            enumeration with no members or a union with one (or zero)
  797.            members, or when all except the last field of a struct have
  798.            width zero.  These are uncommon and/or illegal situations,
  799.            and in any case guessing wrong probably doesn't matter
  800.            much.

  801.            But if we later do find out we were wrong, we fixup the tag
  802.            kind.  Members of an enumeration must be handled
  803.            differently from struct/union fields, and that is harder to
  804.            patch up, but luckily we shouldn't need to.  (If there are
  805.            any enumeration members, we can tell for sure it's an enum
  806.            here.)  */

  807.         if (type_code == TYPE_CODE_UNDEF)
  808.           {
  809.             if (nfields > 1 && max_value == 0)
  810.               type_code = TYPE_CODE_UNION;
  811.             else
  812.               type_code = TYPE_CODE_STRUCT;
  813.           }

  814.         /* Create a new type or use the pending type.  */
  815.         pend = is_pending_symbol (cur_fdr, ext_sh);
  816.         if (pend == (struct mdebug_pending *) NULL)
  817.           {
  818.             t = new_type (NULL);
  819.             add_pending (cur_fdr, ext_sh, t);
  820.           }
  821.         else
  822.           t = pend->t;

  823.         /* Do not set the tag name if it is a compiler generated tag name
  824.            (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
  825.            Alpha cc puts out an sh->iss of zero for those.  */
  826.         if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
  827.           TYPE_TAG_NAME (t) = NULL;
  828.         else
  829.           TYPE_TAG_NAME (t) = obconcat (&mdebugread_objfile->objfile_obstack,
  830.                                         name, (char *) NULL);

  831.         TYPE_CODE (t) = type_code;
  832.         TYPE_LENGTH (t) = sh->value;
  833.         TYPE_NFIELDS (t) = nfields;
  834.         TYPE_FIELDS (t) = f = ((struct field *)
  835.                                TYPE_ALLOC (t,
  836.                                            nfields * sizeof (struct field)));

  837.         if (type_code == TYPE_CODE_ENUM)
  838.           {
  839.             int unsigned_enum = 1;

  840.             /* This is a non-empty enum.  */

  841.             /* DEC c89 has the number of enumerators in the sh.value field,
  842.                not the type length, so we have to compensate for that
  843.                incompatibility quirk.
  844.                This might do the wrong thing for an enum with one or two
  845.                enumerators and gcc -gcoff -fshort-enums, but these cases
  846.                are hopefully rare enough.
  847.                Alpha cc -migrate has a sh.value field of zero, we adjust
  848.                that too.  */
  849.             if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
  850.                 || TYPE_LENGTH (t) == 0)
  851.               TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
  852.             for (ext_tsym = ext_sh + external_sym_size;
  853.                  ;
  854.                  ext_tsym += external_sym_size)
  855.               {
  856.                 SYMR tsym;
  857.                 struct symbol *enum_sym;

  858.                 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);

  859.                 if (tsym.st != stMember)
  860.                   break;

  861.                 SET_FIELD_ENUMVAL (*f, tsym.value);
  862.                 FIELD_TYPE (*f) = t;
  863.                 FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
  864.                 FIELD_BITSIZE (*f) = 0;

  865.                 enum_sym = allocate_symbol (mdebugread_objfile);
  866.                 SYMBOL_SET_LINKAGE_NAME
  867.                   (enum_sym,
  868.                    obstack_copy0 (&mdebugread_objfile->objfile_obstack,
  869.                                   f->name, strlen (f->name)));
  870.                 SYMBOL_ACLASS_INDEX (enum_sym) = LOC_CONST;
  871.                 SYMBOL_TYPE (enum_sym) = t;
  872.                 SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN;
  873.                 SYMBOL_VALUE (enum_sym) = tsym.value;
  874.                 if (SYMBOL_VALUE (enum_sym) < 0)
  875.                   unsigned_enum = 0;
  876.                 add_symbol (enum_sym, top_stack->cur_st, top_stack->cur_block);

  877.                 /* Skip the stMembers that we've handled.  */
  878.                 count++;
  879.                 f++;
  880.               }
  881.             if (unsigned_enum)
  882.               TYPE_UNSIGNED (t) = 1;
  883.           }
  884.         /* Make this the current type.  */
  885.         top_stack->cur_type = t;
  886.         top_stack->cur_field = 0;

  887.         /* Do not create a symbol for alpha cc unnamed structs.  */
  888.         if (sh->iss == 0)
  889.           break;

  890.         /* gcc puts out an empty struct for an opaque struct definitions,
  891.            do not create a symbol for it either.  */
  892.         if (TYPE_NFIELDS (t) == 0)
  893.           {
  894.             TYPE_STUB (t) = 1;
  895.             break;
  896.           }

  897.         s = new_symbol (name);
  898.         SYMBOL_DOMAIN (s) = STRUCT_DOMAIN;
  899.         SYMBOL_ACLASS_INDEX (s) = LOC_TYPEDEF;
  900.         SYMBOL_VALUE (s) = 0;
  901.         SYMBOL_TYPE (s) = t;
  902.         add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  903.         break;

  904.         /* End of local variables shared by struct, union, enum, and
  905.            block (as yet unknown struct/union/enum) processing.  */
  906.       }

  907.     case_stBlock_code:
  908.       found_ecoff_debugging_info = 1;
  909.       /* Beginnning of (code) block.  Value of symbol
  910.          is the displacement from procedure start.  */
  911.       push_parse_stack ();

  912.       /* Do not start a new block if this is the outermost block of a
  913.          procedure.  This allows the LOC_BLOCK symbol to point to the
  914.          block with the local variables, so funcname::var works.  */
  915.       if (top_stack->blocktype == stProc
  916.           || top_stack->blocktype == stStaticProc)
  917.         {
  918.           top_stack->blocktype = stNil;
  919.           break;
  920.         }

  921.       top_stack->blocktype = stBlock;
  922.       b = new_block (NON_FUNCTION_BLOCK);
  923.       BLOCK_START (b) = sh->value + top_stack->procadr;
  924.       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  925.       top_stack->cur_block = b;
  926.       add_block (b, top_stack->cur_st);
  927.       break;

  928.     case stEnd:                /* end (of anything) */
  929.       if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
  930.         {
  931.           /* Finished with type */
  932.           top_stack->cur_type = 0;
  933.         }
  934.       else if (sh->sc == scText &&
  935.                (top_stack->blocktype == stProc ||
  936.                 top_stack->blocktype == stStaticProc))
  937.         {
  938.           /* Finished with procedure */
  939.           const struct blockvector *bv
  940.             = SYMTAB_BLOCKVECTOR (top_stack->cur_st);
  941.           struct mdebug_extra_func_info *e;
  942.           struct block *b = top_stack->cur_block;
  943.           struct type *ftype = top_stack->cur_type;
  944.           int i;

  945.           BLOCK_END (top_stack->cur_block) += sh->value;        /* size */

  946.           /* Make up special symbol to contain procedure specific info.  */
  947.           s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
  948.           SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
  949.           SYMBOL_ACLASS_INDEX (s) = LOC_CONST;
  950.           SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->builtin_void;
  951.           e = ((struct mdebug_extra_func_info *)
  952.                obstack_alloc (&mdebugread_objfile->objfile_obstack,
  953.                               sizeof (struct mdebug_extra_func_info)));
  954.           memset (e, 0, sizeof (struct mdebug_extra_func_info));
  955.           SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
  956.           e->numargs = top_stack->numargs;
  957.           e->pdr.framereg = -1;
  958.           add_symbol (s, top_stack->cur_st, top_stack->cur_block);

  959.           /* f77 emits proc-level with address bounds==[0,0],
  960.              So look for such child blocks, and patch them.  */
  961.           for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
  962.             {
  963.               struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);

  964.               if (BLOCK_SUPERBLOCK (b_bad) == b
  965.                   && BLOCK_START (b_bad) == top_stack->procadr
  966.                   && BLOCK_END (b_bad) == top_stack->procadr)
  967.                 {
  968.                   BLOCK_START (b_bad) = BLOCK_START (b);
  969.                   BLOCK_END (b_bad) = BLOCK_END (b);
  970.                 }
  971.             }

  972.           if (TYPE_NFIELDS (ftype) <= 0)
  973.             {
  974.               /* No parameter type information is recorded with the function's
  975.                  type.  Set that from the type of the parameter symbols.  */
  976.               int nparams = top_stack->numargs;
  977.               int iparams;
  978.               struct symbol *sym;

  979.               if (nparams > 0)
  980.                 {
  981.                   struct block_iterator iter;

  982.                   TYPE_NFIELDS (ftype) = nparams;
  983.                   TYPE_FIELDS (ftype) = (struct field *)
  984.                     TYPE_ALLOC (ftype, nparams * sizeof (struct field));

  985.                   iparams = 0;
  986.                   ALL_BLOCK_SYMBOLS (b, iter, sym)
  987.                     {
  988.                       if (iparams == nparams)
  989.                         break;

  990.                       if (SYMBOL_IS_ARGUMENT (sym))
  991.                         {
  992.                           TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
  993.                           TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
  994.                           iparams++;
  995.                         }
  996.                     }
  997.                 }
  998.             }
  999.         }
  1000.       else if (sh->sc == scText && top_stack->blocktype == stBlock)
  1001.         {
  1002.           /* End of (code) block.  The value of the symbol is the
  1003.              displacement from the procedure`s start address of the
  1004.              end of this block.  */
  1005.           BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
  1006.         }
  1007.       else if (sh->sc == scText && top_stack->blocktype == stNil)
  1008.         {
  1009.           /* End of outermost block.  Pop parse stack and ignore.  The
  1010.              following stEnd of stProc will take care of the block.  */
  1011.           ;
  1012.         }
  1013.       else if (sh->sc == scText && top_stack->blocktype == stFile)
  1014.         {
  1015.           /* End of file.  Pop parse stack and ignore.  Higher
  1016.              level code deals with this.  */
  1017.           ;
  1018.         }
  1019.       else
  1020.         complaint (&symfile_complaints,
  1021.                    _("stEnd with storage class %d not handled"), sh->sc);

  1022.       pop_parse_stack ();        /* Restore previous lexical context.  */
  1023.       break;

  1024.     case stMember:                /* member of struct or union */
  1025.       f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
  1026.       FIELD_NAME (*f) = name;
  1027.       SET_FIELD_BITPOS (*f, sh->value);
  1028.       bitsize = 0;
  1029.       FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index,
  1030.                                     &bitsize, bigend, name);
  1031.       FIELD_BITSIZE (*f) = bitsize;
  1032.       break;

  1033.     case stIndirect:                /* forward declaration on Irix5 */
  1034.       /* Forward declarations from Irix5 cc are handled by cross_ref,
  1035.          skip them.  */
  1036.       break;

  1037.     case stTypedef:                /* type definition */
  1038.       found_ecoff_debugging_info = 1;

  1039.       /* Typedefs for forward declarations and opaque structs from alpha cc
  1040.          are handled by cross_ref, skip them.  */
  1041.       if (sh->iss == 0)
  1042.         break;

  1043.       /* Parse the type or use the pending type.  */
  1044.       pend = is_pending_symbol (cur_fdr, ext_sh);
  1045.       if (pend == (struct mdebug_pending *) NULL)
  1046.         {
  1047.           t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name);
  1048.           add_pending (cur_fdr, ext_sh, t);
  1049.         }
  1050.       else
  1051.         t = pend->t;

  1052.       /* Mips cc puts out a typedef with the name of the struct for forward
  1053.          declarations.  These should not go into the symbol table and
  1054.          TYPE_NAME should not be set for them.
  1055.          They can't be distinguished from an intentional typedef to
  1056.          the same name however:
  1057.          x.h:
  1058.          struct x { int ix; int jx; };
  1059.          struct xx;
  1060.          x.c:
  1061.          typedef struct x x;
  1062.          struct xx {int ixx; int jxx; };
  1063.          generates a cross referencing stTypedef for x and xx.
  1064.          The user visible effect of this is that the type of a pointer
  1065.          to struct foo sometimes is given as `foo *' instead of `struct foo *'.
  1066.          The problem is fixed with alpha cc and Irix5 cc.  */

  1067.       /* However if the typedef cross references to an opaque aggregate, it
  1068.          is safe to omit it from the symbol table.  */

  1069.       if (has_opaque_xref (cur_fdr, sh))
  1070.         break;
  1071.       s = new_symbol (name);
  1072.       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
  1073.       SYMBOL_ACLASS_INDEX (s) = LOC_TYPEDEF;
  1074.       SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
  1075.       SYMBOL_TYPE (s) = t;
  1076.       add_symbol (s, top_stack->cur_st, top_stack->cur_block);

  1077.       /* Incomplete definitions of structs should not get a name.  */
  1078.       if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
  1079.           && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
  1080.               || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
  1081.                   && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
  1082.         {
  1083.           if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
  1084.               || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
  1085.             {
  1086.               /* If we are giving a name to a type such as "pointer to
  1087.                  foo" or "function returning foo", we better not set
  1088.                  the TYPE_NAME.  If the program contains "typedef char
  1089.                  *caddr_t;", we don't want all variables of type char
  1090.                  * to print as caddr_t.  This is not just a
  1091.                  consequence of GDB's type management; CC and GCC (at
  1092.                  least through version 2.4) both output variables of
  1093.                  either type char * or caddr_t with the type
  1094.                  refering to the stTypedef symbol for caddr_t.  If a future
  1095.                  compiler cleans this up it GDB is not ready for it
  1096.                  yet, but if it becomes ready we somehow need to
  1097.                  disable this check (without breaking the PCC/GCC2.4
  1098.                  case).

  1099.                  Sigh.

  1100.                  Fortunately, this check seems not to be necessary
  1101.                  for anything except pointers or functions.  */
  1102.             }
  1103.           else
  1104.             TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_LINKAGE_NAME (s);
  1105.         }
  1106.       break;

  1107.     case stFile:                /* file name */
  1108.       push_parse_stack ();
  1109.       top_stack->blocktype = sh->st;
  1110.       break;

  1111.       /* I`ve never seen these for C */
  1112.     case stRegReloc:
  1113.       break;                        /* register relocation */
  1114.     case stForward:
  1115.       break;                        /* forwarding address */
  1116.     case stConstant:
  1117.       break;                        /* constant */
  1118.     default:
  1119.       complaint (&symfile_complaints, _("unknown symbol type 0x%x"), sh->st);
  1120.       break;
  1121.     }

  1122.   return count;
  1123. }

  1124. /* Basic types.  */

  1125. static const struct objfile_data *basic_type_data;

  1126. static struct type *
  1127. basic_type (int bt, struct objfile *objfile)
  1128. {
  1129.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  1130.   struct type **map_bt = objfile_data (objfile, basic_type_data);
  1131.   struct type *tp;

  1132.   if (bt >= btMax)
  1133.     return NULL;

  1134.   if (!map_bt)
  1135.     {
  1136.       map_bt = OBSTACK_CALLOC (&objfile->objfile_obstack,
  1137.                                btMax, struct type *);
  1138.       set_objfile_data (objfile, basic_type_data, map_bt);
  1139.     }

  1140.   if (map_bt[bt])
  1141.     return map_bt[bt];

  1142.   switch (bt)
  1143.     {
  1144.     case btNil:
  1145.       tp = objfile_type (objfile)->builtin_void;
  1146.       break;

  1147.     case btAdr:
  1148.       tp = init_type (TYPE_CODE_PTR, 4, TYPE_FLAG_UNSIGNED,
  1149.                       "adr_32", objfile);
  1150.       TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
  1151.       break;

  1152.     case btChar:
  1153.       tp = init_type (TYPE_CODE_INT, 1, 0,
  1154.                       "char", objfile);
  1155.       break;

  1156.     case btUChar:
  1157.       tp = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
  1158.                       "unsigned char", objfile);
  1159.       break;

  1160.     case btShort:
  1161.       tp = init_type (TYPE_CODE_INT, 2, 0,
  1162.                       "short", objfile);
  1163.       break;

  1164.     case btUShort:
  1165.       tp = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
  1166.                       "unsigned short", objfile);
  1167.       break;

  1168.     case btInt:
  1169.       tp = init_type (TYPE_CODE_INT, 4, 0,
  1170.                       "int", objfile);
  1171.       break;

  1172.    case btUInt:
  1173.       tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
  1174.                       "unsigned int", objfile);
  1175.       break;

  1176.     case btLong:
  1177.       tp = init_type (TYPE_CODE_INT, 4, 0,
  1178.                       "long", objfile);
  1179.       break;

  1180.     case btULong:
  1181.       tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
  1182.                       "unsigned long", objfile);
  1183.       break;

  1184.     case btFloat:
  1185.       tp = init_type (TYPE_CODE_FLT,
  1186.                       gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
  1187.                       "float", objfile);
  1188.       break;

  1189.     case btDouble:
  1190.       tp = init_type (TYPE_CODE_FLT,
  1191.                       gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
  1192.                       "double", objfile);
  1193.       break;

  1194.     case btComplex:
  1195.       tp = init_type (TYPE_CODE_COMPLEX,
  1196.                       2 * gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
  1197.                       "complex", objfile);
  1198.       TYPE_TARGET_TYPE (tp) = basic_type (btFloat, objfile);
  1199.       break;

  1200.     case btDComplex:
  1201.       tp = init_type (TYPE_CODE_COMPLEX,
  1202.                       2 * gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
  1203.                       "double complex", objfile);
  1204.       TYPE_TARGET_TYPE (tp) = basic_type (btDouble, objfile);
  1205.       break;

  1206.     case btFixedDec:
  1207.       /* We use TYPE_CODE_INT to print these as integers.  Does this do any
  1208.          good?  Would we be better off with TYPE_CODE_ERROR?  Should
  1209.          TYPE_CODE_ERROR print things in hex if it knows the size?  */
  1210.       tp = init_type (TYPE_CODE_INT,
  1211.                       gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, 0,
  1212.                       "fixed decimal", objfile);
  1213.       break;

  1214.     case btFloatDec:
  1215.       tp = init_type (TYPE_CODE_ERROR,
  1216.                       gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
  1217.                       "floating decimal", objfile);
  1218.       break;

  1219.     case btString:
  1220.       /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
  1221.          FIXME.  */
  1222.       tp = init_type (TYPE_CODE_STRING, 1, 0,
  1223.                       "string", objfile);
  1224.       break;

  1225.     case btVoid:
  1226.       tp = objfile_type (objfile)->builtin_void;
  1227.       break;

  1228.     case btLong64:
  1229.       tp = init_type (TYPE_CODE_INT, 8, 0,
  1230.                       "long", objfile);
  1231.       break;

  1232.     case btULong64:
  1233.       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
  1234.                       "unsigned long", objfile);
  1235.       break;

  1236.     case btLongLong64:
  1237.       tp = init_type (TYPE_CODE_INT, 8, 0,
  1238.                       "long long", objfile);
  1239.       break;

  1240.     case btULongLong64:
  1241.       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
  1242.                       "unsigned long long", objfile);
  1243.       break;

  1244.     case btAdr64:
  1245.       tp = init_type (TYPE_CODE_PTR, 8, TYPE_FLAG_UNSIGNED,
  1246.                       "adr_64", objfile);
  1247.       TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
  1248.       break;

  1249.     case btInt64:
  1250.       tp = init_type (TYPE_CODE_INT, 8, 0,
  1251.                       "int", objfile);
  1252.       break;

  1253.     case btUInt64:
  1254.       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
  1255.                       "unsigned int", objfile);
  1256.       break;

  1257.     default:
  1258.       tp = NULL;
  1259.       break;
  1260.     }

  1261.   map_bt[bt] = tp;
  1262.   return tp;
  1263. }

  1264. /* Parse the type information provided in the raw AX entries for
  1265.    the symbol SH.  Return the bitfield size in BS, in case.
  1266.    We must byte-swap the AX entries before we use them; BIGEND says whether
  1267.    they are big-endian or little-endian (from fh->fBigendian).  */

  1268. static struct type *
  1269. parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
  1270.             int bigend, char *sym_name)
  1271. {
  1272.   TIR t[1];
  1273.   struct type *tp = 0;
  1274.   enum type_code type_code = TYPE_CODE_UNDEF;

  1275.   /* Handle undefined types, they have indexNil.  */
  1276.   if (aux_index == indexNil)
  1277.     return basic_type (btInt, mdebugread_objfile);

  1278.   /* Handle corrupt aux indices.  */
  1279.   if (aux_index >= (debug_info->fdr + fd)->caux)
  1280.     {
  1281.       index_complaint (sym_name);
  1282.       return basic_type (btInt, mdebugread_objfile);
  1283.     }
  1284.   ax += aux_index;

  1285.   /* Use aux as a type information record, map its basic type.  */
  1286.   (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
  1287.   tp = basic_type (t->bt, mdebugread_objfile);
  1288.   if (tp == NULL)
  1289.     {
  1290.       /* Cannot use builtin types -- build our own.  */
  1291.       switch (t->bt)
  1292.         {
  1293.         case btStruct:
  1294.           type_code = TYPE_CODE_STRUCT;
  1295.           break;
  1296.         case btUnion:
  1297.           type_code = TYPE_CODE_UNION;
  1298.           break;
  1299.         case btEnum:
  1300.           type_code = TYPE_CODE_ENUM;
  1301.           break;
  1302.         case btRange:
  1303.           type_code = TYPE_CODE_RANGE;
  1304.           break;
  1305.         case btSet:
  1306.           type_code = TYPE_CODE_SET;
  1307.           break;
  1308.         case btIndirect:
  1309.           /* alpha cc -migrate uses this for typedefs.  The true type will
  1310.              be obtained by crossreferencing below.  */
  1311.           type_code = TYPE_CODE_ERROR;
  1312.           break;
  1313.         case btTypedef:
  1314.           /* alpha cc uses this for typedefs.  The true type will be
  1315.              obtained by crossreferencing below.  */
  1316.           type_code = TYPE_CODE_ERROR;
  1317.           break;
  1318.         default:
  1319.           basic_type_complaint (t->bt, sym_name);
  1320.           return basic_type (btInt, mdebugread_objfile);
  1321.         }
  1322.     }

  1323.   /* Move on to next aux.  */
  1324.   ax++;

  1325.   if (t->fBitfield)
  1326.     {
  1327.       int width = AUX_GET_WIDTH (bigend, ax);

  1328.       /* Inhibit core dumps if TIR is corrupted.  */
  1329.       if (bs == (int *) NULL)
  1330.         {
  1331.           /* Alpha cc -migrate encodes char and unsigned char types
  1332.              as short and unsigned short types with a field width of 8.
  1333.              Enum types also have a field width which we ignore for now.  */
  1334.           if (t->bt == btShort && width == 8)
  1335.             tp = basic_type (btChar, mdebugread_objfile);
  1336.           else if (t->bt == btUShort && width == 8)
  1337.             tp = basic_type (btUChar, mdebugread_objfile);
  1338.           else if (t->bt == btEnum)
  1339.             ;
  1340.           else
  1341.             complaint (&symfile_complaints,
  1342.                        _("can't handle TIR fBitfield for %s"),
  1343.                        sym_name);
  1344.         }
  1345.       else
  1346.         *bs = width;
  1347.       ax++;
  1348.     }

  1349.   /* A btIndirect entry cross references to an aux entry containing
  1350.      the type.  */
  1351.   if (t->bt == btIndirect)
  1352.     {
  1353.       RNDXR rn[1];
  1354.       int rf;
  1355.       FDR *xref_fh;
  1356.       int xref_fd;

  1357.       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
  1358.       ax++;
  1359.       if (rn->rfd == 0xfff)
  1360.         {
  1361.           rf = AUX_GET_ISYM (bigend, ax);
  1362.           ax++;
  1363.         }
  1364.       else
  1365.         rf = rn->rfd;

  1366.       if (rf == -1)
  1367.         {
  1368.           complaint (&symfile_complaints,
  1369.                      _("unable to cross ref btIndirect for %s"), sym_name);
  1370.           return basic_type (btInt, mdebugread_objfile);
  1371.         }
  1372.       xref_fh = get_rfd (fd, rf);
  1373.       xref_fd = xref_fh - debug_info->fdr;
  1374.       tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
  1375.                     rn->index, (int *) NULL, xref_fh->fBigendian, sym_name);
  1376.     }

  1377.   /* All these types really point to some (common) MIPS type
  1378.      definition, and only the type-qualifiers fully identify
  1379.      them.  We'll make the same effort at sharing.  */
  1380.   if (t->bt == btStruct ||
  1381.       t->bt == btUnion ||
  1382.       t->bt == btEnum ||

  1383.   /* btSet (I think) implies that the name is a tag name, not a typedef
  1384.      name.  This apparently is a MIPS extension for C sets.  */
  1385.       t->bt == btSet)
  1386.     {
  1387.       char *name;

  1388.       /* Try to cross reference this type, build new type on failure.  */
  1389.       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
  1390.       if (tp == (struct type *) NULL)
  1391.         tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);

  1392.       /* DEC c89 produces cross references to qualified aggregate types,
  1393.          dereference them.  */
  1394.       while (TYPE_CODE (tp) == TYPE_CODE_PTR
  1395.              || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
  1396.         tp = TYPE_TARGET_TYPE (tp);

  1397.       /* Make sure that TYPE_CODE(tp) has an expected type code.
  1398.          Any type may be returned from cross_ref if file indirect entries
  1399.          are corrupted.  */
  1400.       if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
  1401.           && TYPE_CODE (tp) != TYPE_CODE_UNION
  1402.           && TYPE_CODE (tp) != TYPE_CODE_ENUM)
  1403.         {
  1404.           unexpected_type_code_complaint (sym_name);
  1405.         }
  1406.       else
  1407.         {
  1408.           /* Usually, TYPE_CODE(tp) is already type_code.  The main
  1409.              exception is if we guessed wrong re struct/union/enum.
  1410.              But for struct vs. union a wrong guess is harmless, so
  1411.              don't complain().  */
  1412.           if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
  1413.                && type_code != TYPE_CODE_ENUM)
  1414.               || (TYPE_CODE (tp) != TYPE_CODE_ENUM
  1415.                   && type_code == TYPE_CODE_ENUM))
  1416.             {
  1417.               bad_tag_guess_complaint (sym_name);
  1418.             }

  1419.           if (TYPE_CODE (tp) != type_code)
  1420.             {
  1421.               TYPE_CODE (tp) = type_code;
  1422.             }

  1423.           /* Do not set the tag name if it is a compiler generated tag name
  1424.              (.Fxx or .xxfake or empty) for unnamed struct/union/enums.  */
  1425.           if (name[0] == '.' || name[0] == '\0')
  1426.             TYPE_TAG_NAME (tp) = NULL;
  1427.           else if (TYPE_TAG_NAME (tp) == NULL
  1428.                    || strcmp (TYPE_TAG_NAME (tp), name) != 0)
  1429.             TYPE_TAG_NAME (tp)
  1430.               = obstack_copy0 (&mdebugread_objfile->objfile_obstack,
  1431.                                name, strlen (name));
  1432.         }
  1433.     }

  1434.   /* All these types really point to some (common) MIPS type
  1435.      definition, and only the type-qualifiers fully identify
  1436.      them.  We'll make the same effort at sharing.
  1437.      FIXME: We are not doing any guessing on range types.  */
  1438.   if (t->bt == btRange)
  1439.     {
  1440.       char *name;

  1441.       /* Try to cross reference this type, build new type on failure.  */
  1442.       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
  1443.       if (tp == (struct type *) NULL)
  1444.         tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);

  1445.       /* Make sure that TYPE_CODE(tp) has an expected type code.
  1446.          Any type may be returned from cross_ref if file indirect entries
  1447.          are corrupted.  */
  1448.       if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
  1449.         {
  1450.           unexpected_type_code_complaint (sym_name);
  1451.         }
  1452.       else
  1453.         {
  1454.           /* Usually, TYPE_CODE(tp) is already type_code.  The main
  1455.              exception is if we guessed wrong re struct/union/enum.  */
  1456.           if (TYPE_CODE (tp) != type_code)
  1457.             {
  1458.               bad_tag_guess_complaint (sym_name);
  1459.               TYPE_CODE (tp) = type_code;
  1460.             }
  1461.           if (TYPE_NAME (tp) == NULL
  1462.               || strcmp (TYPE_NAME (tp), name) != 0)
  1463.             TYPE_NAME (tp)
  1464.               = obstack_copy0 (&mdebugread_objfile->objfile_obstack,
  1465.                                name, strlen (name));
  1466.         }
  1467.     }
  1468.   if (t->bt == btTypedef)
  1469.     {
  1470.       char *name;

  1471.       /* Try to cross reference this type, it should succeed.  */
  1472.       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
  1473.       if (tp == (struct type *) NULL)
  1474.         {
  1475.           complaint (&symfile_complaints,
  1476.                      _("unable to cross ref btTypedef for %s"), sym_name);
  1477.           tp = basic_type (btInt, mdebugread_objfile);
  1478.         }
  1479.     }

  1480.   /* Deal with range types.  */
  1481.   if (t->bt == btRange)
  1482.     {
  1483.       TYPE_NFIELDS (tp) = 0;
  1484.       TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
  1485.                           TYPE_ZALLOC (tp, sizeof (struct range_bounds)));
  1486.       TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
  1487.       ax++;
  1488.       TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
  1489.       ax++;
  1490.     }

  1491.   /* Parse all the type qualifiers now.  If there are more
  1492.      than 6 the game will continue in the next aux.  */

  1493.   while (1)
  1494.     {
  1495. #define PARSE_TQ(tq) \
  1496.       if (t->tq != tqNil) \
  1497.         ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
  1498.       else \
  1499.         break;

  1500.       PARSE_TQ (tq0);
  1501.       PARSE_TQ (tq1);
  1502.       PARSE_TQ (tq2);
  1503.       PARSE_TQ (tq3);
  1504.       PARSE_TQ (tq4);
  1505.       PARSE_TQ (tq5);
  1506. #undef        PARSE_TQ

  1507.       /* mips cc 2.x and gcc never put out continued aux entries.  */
  1508.       if (!t->continued)
  1509.         break;

  1510.       (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
  1511.       ax++;
  1512.     }

  1513.   /* Complain for illegal continuations due to corrupt aux entries.  */
  1514.   if (t->continued)
  1515.     complaint (&symfile_complaints,
  1516.                _("illegal TIR continued for %s"), sym_name);

  1517.   return tp;
  1518. }

  1519. /* Make up a complex type from a basic one.  Type is passed by
  1520.    reference in TPP and side-effected as necessary.  The type
  1521.    qualifier TQ says how to handle the aux symbols at AX for
  1522.    the symbol SX we are currently analyzing.  BIGEND says whether
  1523.    aux symbols are big-endian or little-endian.
  1524.    Returns the number of aux symbols we parsed.  */

  1525. static int
  1526. upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
  1527.               char *sym_name)
  1528. {
  1529.   int off;
  1530.   struct type *t;

  1531.   /* Used in array processing.  */
  1532.   int rf, id;
  1533.   FDR *fh;
  1534.   struct type *range;
  1535.   struct type *indx;
  1536.   int lower, upper;
  1537.   RNDXR rndx;

  1538.   switch (tq)
  1539.     {
  1540.     case tqPtr:
  1541.       t = lookup_pointer_type (*tpp);
  1542.       *tpp = t;
  1543.       return 0;

  1544.     case tqProc:
  1545.       t = lookup_function_type (*tpp);
  1546.       *tpp = t;
  1547.       return 0;

  1548.     case tqArray:
  1549.       off = 0;

  1550.       /* Determine and record the domain type (type of index).  */
  1551.       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
  1552.       id = rndx.index;
  1553.       rf = rndx.rfd;
  1554.       if (rf == 0xfff)
  1555.         {
  1556.           ax++;
  1557.           rf = AUX_GET_ISYM (bigend, ax);
  1558.           off++;
  1559.         }
  1560.       fh = get_rfd (fd, rf);

  1561.       indx = parse_type (fh - debug_info->fdr,
  1562.                          debug_info->external_aux + fh->iauxBase,
  1563.                          id, (int *) NULL, bigend, sym_name);

  1564.       /* The bounds type should be an integer type, but might be anything
  1565.          else due to corrupt aux entries.  */
  1566.       if (TYPE_CODE (indx) != TYPE_CODE_INT)
  1567.         {
  1568.           complaint (&symfile_complaints,
  1569.                      _("illegal array index type for %s, assuming int"),
  1570.                      sym_name);
  1571.           indx = objfile_type (mdebugread_objfile)->builtin_int;
  1572.         }

  1573.       /* Get the bounds, and create the array type.  */
  1574.       ax++;
  1575.       lower = AUX_GET_DNLOW (bigend, ax);
  1576.       ax++;
  1577.       upper = AUX_GET_DNHIGH (bigend, ax);
  1578.       ax++;
  1579.       rf = AUX_GET_WIDTH (bigend, ax);        /* bit size of array element */

  1580.       range = create_static_range_type ((struct type *) NULL, indx,
  1581.                                         lower, upper);

  1582.       t = create_array_type ((struct type *) NULL, *tpp, range);

  1583.       /* We used to fill in the supplied array element bitsize
  1584.          here if the TYPE_LENGTH of the target type was zero.
  1585.          This happens for a `pointer to an array of anonymous structs',
  1586.          but in this case the array element bitsize is also zero,
  1587.          so nothing is gained.
  1588.          And we used to check the TYPE_LENGTH of the target type against
  1589.          the supplied array element bitsize.
  1590.          gcc causes a mismatch for `pointer to array of object',
  1591.          since the sdb directives it uses do not have a way of
  1592.          specifying the bitsize, but it does no harm (the
  1593.          TYPE_LENGTH should be correct) and we should be able to
  1594.          ignore the erroneous bitsize from the auxiliary entry safely.
  1595.          dbx seems to ignore it too.  */

  1596.       /* TYPE_TARGET_STUB now takes care of the zero TYPE_LENGTH problem.  */
  1597.       if (TYPE_LENGTH (*tpp) == 0)
  1598.         TYPE_TARGET_STUB (t) = 1;

  1599.       *tpp = t;
  1600.       return 4 + off;

  1601.     case tqVol:
  1602.       /* Volatile -- currently ignored */
  1603.       return 0;

  1604.     case tqConst:
  1605.       /* Const -- currently ignored */
  1606.       return 0;

  1607.     default:
  1608.       complaint (&symfile_complaints, _("unknown type qualifier 0x%x"), tq);
  1609.       return 0;
  1610.     }
  1611. }


  1612. /* Parse a procedure descriptor record PR.  Note that the procedure is
  1613.    parsed _after_ the local symbols, now we just insert the extra
  1614.    information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has
  1615.    already been placed in the procedure's main block.  Note also that
  1616.    images that have been partially stripped (ld -x) have been deprived
  1617.    of local symbols, and we have to cope with them here.  FIRST_OFF is
  1618.    the offset of the first procedure for this FDR; we adjust the
  1619.    address by this amount, but I don't know why.  SEARCH_SYMTAB is the symtab
  1620.    to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol
  1621.    in question, or NULL to use top_stack->cur_block.  */

  1622. static void
  1623. parse_procedure (PDR *pr, struct compunit_symtab *search_symtab,
  1624.                  struct partial_symtab *pst)
  1625. {
  1626.   struct symbol *s, *i;
  1627.   const struct block *b;
  1628.   char *sh_name;

  1629.   /* Simple rule to find files linked "-x".  */
  1630.   if (cur_fdr->rss == -1)
  1631.     {
  1632.       if (pr->isym == -1)
  1633.         {
  1634.           /* Static procedure at address pr->adr.  Sigh.  */
  1635.           /* FIXME-32x64.  assuming pr->adr fits in long.  */
  1636.           complaint (&symfile_complaints,
  1637.                      _("can't handle PDR for static proc at 0x%lx"),
  1638.                      (unsigned long) pr->adr);
  1639.           return;
  1640.         }
  1641.       else
  1642.         {
  1643.           /* external */
  1644.           EXTR she;

  1645.           (*debug_swap->swap_ext_in) (cur_bfd,
  1646.                                       ((char *) debug_info->external_ext
  1647.                                        + (pr->isym
  1648.                                           * debug_swap->external_ext_size)),
  1649.                                       &she);
  1650.           sh_name = debug_info->ssext + she.asym.iss;
  1651.         }
  1652.     }
  1653.   else
  1654.     {
  1655.       /* Full symbols */
  1656.       SYMR sh;

  1657.       (*debug_swap->swap_sym_in) (cur_bfd,
  1658.                                   ((char *) debug_info->external_sym
  1659.                                    + ((cur_fdr->isymBase + pr->isym)
  1660.                                       * debug_swap->external_sym_size)),
  1661.                                   &sh);
  1662.       sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
  1663.     }

  1664.   if (search_symtab != NULL)
  1665.     {
  1666. #if 0
  1667.       /* This loses both in the case mentioned (want a static, find a global),
  1668.          but also if we are looking up a non-mangled name which happens to
  1669.          match the name of a mangled function.  */
  1670.       /* We have to save the cur_fdr across the call to lookup_symbol.
  1671.          If the pdr is for a static function and if a global function with
  1672.          the same name exists, lookup_symbol will eventually read in the symtab
  1673.          for the global function and clobber cur_fdr.  */
  1674.       FDR *save_cur_fdr = cur_fdr;

  1675.       s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0);
  1676.       cur_fdr = save_cur_fdr;
  1677. #else
  1678.       s = mylookup_symbol
  1679.         (sh_name,
  1680.          BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (search_symtab),
  1681.                             STATIC_BLOCK),
  1682.          VAR_DOMAIN,
  1683.          LOC_BLOCK);
  1684. #endif
  1685.     }
  1686.   else
  1687.     s = mylookup_symbol (sh_name, top_stack->cur_block,
  1688.                          VAR_DOMAIN, LOC_BLOCK);

  1689.   if (s != 0)
  1690.     {
  1691.       b = SYMBOL_BLOCK_VALUE (s);
  1692.     }
  1693.   else
  1694.     {
  1695.       complaint (&symfile_complaints, _("PDR for %s, but no symbol"), sh_name);
  1696. #if 1
  1697.       return;
  1698. #else
  1699. /* FIXME -- delete.  We can't do symbol allocation now; it's all done.  */
  1700.       s = new_symbol (sh_name);
  1701.       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
  1702.       SYMBOL_CLASS (s) = LOC_BLOCK;
  1703.       /* Donno its type, hope int is ok.  */
  1704.       SYMBOL_TYPE (s)
  1705.         = lookup_function_type (objfile_type (pst->objfile)->builtin_int);
  1706.       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  1707.       /* Won't have symbols for this one.  */
  1708.       b = new_block (2);
  1709.       SYMBOL_BLOCK_VALUE (s) = b;
  1710.       BLOCK_FUNCTION (b) = s;
  1711.       BLOCK_START (b) = pr->adr;
  1712.       /* BOUND used to be the end of procedure's text, but the
  1713.          argument is no longer passed in.  */
  1714.       BLOCK_END (b) = bound;
  1715.       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  1716.       add_block (b, top_stack->cur_st);
  1717. #endif
  1718.     }

  1719.   i = mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST);

  1720.   if (i)
  1721.     {
  1722.       struct mdebug_extra_func_info *e;

  1723.       e = (struct mdebug_extra_func_info *) SYMBOL_VALUE_BYTES (i);
  1724.       e->pdr = *pr;

  1725.       /* GDB expects the absolute function start address for the
  1726.          procedure descriptor in e->pdr.adr.
  1727.          As the address in the procedure descriptor is usually relative,
  1728.          we would have to relocate e->pdr.adr with cur_fdr->adr and
  1729.          ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)).
  1730.          Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
  1731.          in shared libraries on some systems, and on other systems
  1732.          e->pdr.adr is sometimes offset by a bogus value.
  1733.          To work around these problems, we replace e->pdr.adr with
  1734.          the start address of the function.  */
  1735.       e->pdr.adr = BLOCK_START (b);
  1736.     }

  1737.   /* It would be reasonable that functions that have been compiled
  1738.      without debugging info have a btNil type for their return value,
  1739.      and functions that are void and are compiled with debugging info
  1740.      have btVoid.
  1741.      gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
  1742.      to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
  1743.      case right.
  1744.      The glevel field in cur_fdr could be used to determine the presence
  1745.      of debugging info, but GCC doesn't always pass the -g switch settings
  1746.      to the assembler and GAS doesn't set the glevel field from the -g switch
  1747.      settings.
  1748.      To work around these problems, the return value type of a TYPE_CODE_VOID
  1749.      function is adjusted accordingly if no debugging info was found in the
  1750.      compilation unit.  */

  1751.   if (processing_gcc_compilation == 0
  1752.       && found_ecoff_debugging_info == 0
  1753.       && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID)
  1754.     SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->nodebug_text_symbol;
  1755. }

  1756. /* Parse the external symbol ES.  Just call parse_symbol() after
  1757.    making sure we know where the aux are for it.
  1758.    BIGEND says whether aux entries are big-endian or little-endian.

  1759.    This routine clobbers top_stack->cur_block and ->cur_st.  */

  1760. static void parse_external (EXTR *, int, struct section_offsets *,
  1761.                             struct objfile *);

  1762. static void
  1763. parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
  1764.                 struct objfile *objfile)
  1765. {
  1766.   union aux_ext *ax;

  1767.   if (es->ifd != ifdNil)
  1768.     {
  1769.       cur_fd = es->ifd;
  1770.       cur_fdr = debug_info->fdr + cur_fd;
  1771.       ax = debug_info->external_aux + cur_fdr->iauxBase;
  1772.     }
  1773.   else
  1774.     {
  1775.       cur_fdr = debug_info->fdr;
  1776.       ax = 0;
  1777.     }

  1778.   /* Reading .o files */
  1779.   if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
  1780.     {
  1781.       char *what;
  1782.       switch (es->asym.st)
  1783.         {
  1784.         case stNil:
  1785.           /* These are generated for static symbols in .o files,
  1786.              ignore them.  */
  1787.           return;
  1788.         case stStaticProc:
  1789.         case stProc:
  1790.           what = "procedure";
  1791.           n_undef_procs++;
  1792.           break;
  1793.         case stGlobal:
  1794.           what = "variable";
  1795.           n_undef_vars++;
  1796.           break;
  1797.         case stLabel:
  1798.           what = "label";
  1799.           n_undef_labels++;
  1800.           break;
  1801.         default:
  1802.           what = "symbol";
  1803.           break;
  1804.         }
  1805.       n_undef_symbols++;
  1806.       /* FIXME:  Turn this into a complaint?  */
  1807.       if (info_verbose)
  1808.         printf_filtered (_("Warning: %s `%s' is undefined (in %s)\n"),
  1809.                          what, debug_info->ssext + es->asym.iss,
  1810.                          fdr_name (cur_fdr));
  1811.       return;
  1812.     }

  1813.   switch (es->asym.st)
  1814.     {
  1815.     case stProc:
  1816.     case stStaticProc:
  1817.       /* There is no need to parse the external procedure symbols.
  1818.          If they are from objects compiled without -g, their index will
  1819.          be indexNil, and the symbol definition from the minimal symbol
  1820.          is preferrable (yielding a function returning int instead of int).
  1821.          If the index points to a local procedure symbol, the local
  1822.          symbol already provides the correct type.
  1823.          Note that the index of the external procedure symbol points
  1824.          to the local procedure symbol in the local symbol table, and
  1825.          _not_ to the auxiliary symbol info.  */
  1826.       break;
  1827.     case stGlobal:
  1828.     case stLabel:
  1829.       /* Global common symbols are resolved by the runtime loader,
  1830.          ignore them.  */
  1831.       if (SC_IS_COMMON (es->asym.sc))
  1832.         break;

  1833.       /* Note that the case of a symbol with indexNil must be handled
  1834.          anyways by parse_symbol().  */
  1835.       parse_symbol (&es->asym, ax, (char *) NULL,
  1836.                     bigend, section_offsets, objfile);
  1837.       break;
  1838.     default:
  1839.       break;
  1840.     }
  1841. }

  1842. /* Parse the line number info for file descriptor FH into
  1843.    GDB's linetable LT.  MIPS' encoding requires a little bit
  1844.    of magic to get things out.  Note also that MIPS' line
  1845.    numbers can go back and forth, apparently we can live
  1846.    with that and do not need to reorder our linetables.  */

  1847. static void parse_lines (FDR *, PDR *, struct linetable *, int,
  1848.                          struct partial_symtab *, CORE_ADDR);

  1849. static void
  1850. parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
  1851.              struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
  1852. {
  1853.   unsigned char *base;
  1854.   int j, k;
  1855.   int delta, count, lineno = 0;

  1856.   if (fh->cbLine == 0)
  1857.     return;

  1858.   /* Scan by procedure descriptors.  */
  1859.   k = 0;
  1860.   for (j = 0; j < fh->cpd; j++, pr++)
  1861.     {
  1862.       CORE_ADDR l;
  1863.       CORE_ADDR adr;
  1864.       unsigned char *halt;

  1865.       /* No code for this one.  */
  1866.       if (pr->iline == ilineNil ||
  1867.           pr->lnLow == -1 || pr->lnHigh == -1)
  1868.         continue;

  1869.       /* Determine start and end address of compressed line bytes for
  1870.          this procedure.  */
  1871.       base = debug_info->line + fh->cbLineOffset;
  1872.       if (j != (fh->cpd - 1))
  1873.         halt = base + pr[1].cbLineOffset;
  1874.       else
  1875.         halt = base + fh->cbLine;
  1876.       base += pr->cbLineOffset;

  1877.       adr = pst->textlow + pr->adr - lowest_pdr_addr;

  1878.       l = adr >> 2;                /* in words */
  1879.       for (lineno = pr->lnLow; base < halt;)
  1880.         {
  1881.           count = *base & 0x0f;
  1882.           delta = *base++ >> 4;
  1883.           if (delta >= 8)
  1884.             delta -= 16;
  1885.           if (delta == -8)
  1886.             {
  1887.               delta = (base[0] << 8) | base[1];
  1888.               if (delta >= 0x8000)
  1889.                 delta -= 0x10000;
  1890.               base += 2;
  1891.             }
  1892.           lineno += delta;        /* first delta is 0 */

  1893.           /* Complain if the line table overflows.  Could happen
  1894.              with corrupt binaries.  */
  1895.           if (lt->nitems >= maxlines)
  1896.             {
  1897.               complaint (&symfile_complaints,
  1898.                          _("guessed size of linetable for %s incorrectly"),
  1899.                          fdr_name (fh));
  1900.               break;
  1901.             }
  1902.           k = add_line (lt, lineno, l, k);
  1903.           l += count + 1;
  1904.         }
  1905.     }
  1906. }

  1907. static void
  1908. function_outside_compilation_unit_complaint (const char *arg1)
  1909. {
  1910.   complaint (&symfile_complaints,
  1911.              _("function `%s' appears to be defined "
  1912.                "outside of all compilation units"),
  1913.              arg1);
  1914. }

  1915. /* Use the STORAGE_CLASS to compute which section the given symbol
  1916.    belongs to, and then records this new minimal symbol.  */

  1917. static void
  1918. record_minimal_symbol (const char *name, const CORE_ADDR address,
  1919.                        enum minimal_symbol_type ms_type, int storage_class,
  1920.                        struct objfile *objfile)
  1921. {
  1922.   int section;

  1923.   switch (storage_class)
  1924.     {
  1925.       case scText:
  1926.         section = SECT_OFF_TEXT (objfile);
  1927.         break;
  1928.       case scData:
  1929.         section = SECT_OFF_DATA (objfile);
  1930.         break;
  1931.       case scBss:
  1932.         section = SECT_OFF_BSS (objfile);
  1933.         break;
  1934.       case scSData:
  1935.         section = get_section_index (objfile, ".sdata");
  1936.         break;
  1937.       case scSBss:
  1938.         section = get_section_index (objfile, ".sbss");
  1939.         break;
  1940.       case scRData:
  1941.         section = get_section_index (objfile, ".rdata");
  1942.         break;
  1943.       case scInit:
  1944.         section = get_section_index (objfile, ".init");
  1945.         break;
  1946.       case scXData:
  1947.         section = get_section_index (objfile, ".xdata");
  1948.         break;
  1949.       case scPData:
  1950.         section = get_section_index (objfile, ".pdata");
  1951.         break;
  1952.       case scFini:
  1953.         section = get_section_index (objfile, ".fini");
  1954.         break;
  1955.       case scRConst:
  1956.         section = get_section_index (objfile, ".rconst");
  1957.         break;
  1958. #ifdef scTlsData
  1959.       case scTlsData:
  1960.         section = get_section_index (objfile, ".tlsdata");
  1961.         break;
  1962. #endif
  1963. #ifdef scTlsBss
  1964.       case scTlsBss:
  1965.         section = get_section_index (objfile, ".tlsbss");
  1966.         break;
  1967. #endif
  1968.       default:
  1969.         /* This kind of symbol is not associated to a section.  */
  1970.         section = -1;
  1971.     }

  1972.   prim_record_minimal_symbol_and_info (name, address, ms_type,
  1973.                                        section, objfile);
  1974. }

  1975. /* Master parsing procedure for first-pass reading of file symbols
  1976.    into a partial_symtab.  */

  1977. static void
  1978. parse_partial_symbols (struct objfile *objfile)
  1979. {
  1980.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  1981.   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
  1982.   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
  1983.   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
  1984.   void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
  1985.   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
  1986.   void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
  1987.   int f_idx, s_idx;
  1988.   HDRR *hdr = &debug_info->symbolic_header;
  1989.   /* Running pointers */
  1990.   FDR *fh;
  1991.   char *ext_out;
  1992.   char *ext_out_end;
  1993.   EXTR *ext_block;
  1994.   EXTR *ext_in;
  1995.   EXTR *ext_in_end;
  1996.   SYMR sh;
  1997.   struct partial_symtab *pst;
  1998.   int textlow_not_set = 1;
  1999.   int past_first_source_file = 0;

  2000.   /* List of current psymtab's include files.  */
  2001.   const char **psymtab_include_list;
  2002.   int includes_allocated;
  2003.   int includes_used;
  2004.   EXTR *extern_tab;
  2005.   struct pst_map *fdr_to_pst;
  2006.   /* Index within current psymtab dependency list.  */
  2007.   struct partial_symtab **dependency_list;
  2008.   int dependencies_used, dependencies_allocated;
  2009.   struct cleanup *old_chain;
  2010.   char *name;
  2011.   enum language prev_language;
  2012.   asection *text_sect;
  2013.   int relocatable = 0;

  2014.   /* Irix 5.2 shared libraries have a fh->adr field of zero, but
  2015.      the shared libraries are prelinked at a high memory address.
  2016.      We have to adjust the start address of the object file for this case,
  2017.      by setting it to the start address of the first procedure in the file.
  2018.      But we should do no adjustments if we are debugging a .o file, where
  2019.      the text section (and fh->adr) really starts at zero.  */
  2020.   text_sect = bfd_get_section_by_name (cur_bfd, ".text");
  2021.   if (text_sect != NULL
  2022.       && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC))
  2023.     relocatable = 1;

  2024.   extern_tab = (EXTR *) obstack_alloc (&objfile->objfile_obstack,
  2025.                                        sizeof (EXTR) * hdr->iextMax);

  2026.   includes_allocated = 30;
  2027.   includes_used = 0;
  2028.   psymtab_include_list = (const char **) alloca (includes_allocated *
  2029.                                                  sizeof (const char *));
  2030.   next_symbol_text_func = mdebug_next_symbol_text;

  2031.   dependencies_allocated = 30;
  2032.   dependencies_used = 0;
  2033.   dependency_list =
  2034.     (struct partial_symtab **) alloca (dependencies_allocated *
  2035.                                        sizeof (struct partial_symtab *));

  2036.   set_last_source_file (NULL);

  2037.   /*
  2038.    * Big plan:
  2039.    *
  2040.    * Only parse the Local and External symbols, and the Relative FDR.
  2041.    * Fixup enough of the loader symtab to be able to use it.
  2042.    * Allocate space only for the file's portions we need to
  2043.    * look at.  (XXX)
  2044.    */

  2045.   max_gdbinfo = 0;
  2046.   max_glevel = MIN_GLEVEL;

  2047.   /* Allocate the map FDR -> PST.
  2048.      Minor hack: -O3 images might claim some global data belongs
  2049.      to FDR -1.  We`ll go along with that.  */
  2050.   fdr_to_pst = (struct pst_map *)
  2051.     xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
  2052.   old_chain = make_cleanup (xfree, fdr_to_pst);
  2053.   fdr_to_pst++;
  2054.   {
  2055.     struct partial_symtab *pst = new_psymtab ("", objfile);

  2056.     fdr_to_pst[-1].pst = pst;
  2057.     FDR_IDX (pst) = -1;
  2058.   }

  2059.   /* Allocate the global pending list.  */
  2060.   pending_list =
  2061.     ((struct mdebug_pending **)
  2062.      obstack_alloc (&objfile->objfile_obstack,
  2063.                     hdr->ifdMax * sizeof (struct mdebug_pending *)));
  2064.   memset (pending_list, 0,
  2065.           hdr->ifdMax * sizeof (struct mdebug_pending *));

  2066.   /* Pass 0 over external syms: swap them in.  */
  2067.   ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
  2068.   make_cleanup (xfree, ext_block);

  2069.   ext_out = (char *) debug_info->external_ext;
  2070.   ext_out_end = ext_out + hdr->iextMax * external_ext_size;
  2071.   ext_in = ext_block;
  2072.   for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
  2073.     (*swap_ext_in) (cur_bfd, ext_out, ext_in);

  2074.   /* Pass 1 over external syms: Presize and partition the list.  */
  2075.   ext_in = ext_block;
  2076.   ext_in_end = ext_in + hdr->iextMax;
  2077.   for (; ext_in < ext_in_end; ext_in++)
  2078.     {
  2079.       /* See calls to complain below.  */
  2080.       if (ext_in->ifd >= -1
  2081.           && ext_in->ifd < hdr->ifdMax
  2082.           && ext_in->asym.iss >= 0
  2083.           && ext_in->asym.iss < hdr->issExtMax)
  2084.         fdr_to_pst[ext_in->ifd].n_globals++;
  2085.     }

  2086.   /* Pass 1.5 over files:  partition out global symbol space.  */
  2087.   s_idx = 0;
  2088.   for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
  2089.     {
  2090.       fdr_to_pst[f_idx].globals_offset = s_idx;
  2091.       s_idx += fdr_to_pst[f_idx].n_globals;
  2092.       fdr_to_pst[f_idx].n_globals = 0;
  2093.     }

  2094.   /* ECOFF in ELF:

  2095.      For ECOFF in ELF, we skip the creation of the minimal symbols.
  2096.      The ECOFF symbols should be a subset of the Elf symbols, and the
  2097.      section information of the elf symbols will be more accurate.
  2098.      FIXME!  What about Irix 5's native linker?

  2099.      By default, Elf sections which don't exist in ECOFF
  2100.      get put in ECOFF's absolute section by the gnu linker.
  2101.      Since absolute sections don't get relocated, we
  2102.      end up calculating an address different from that of
  2103.      the symbol's minimal symbol (created earlier from the
  2104.      Elf symtab).

  2105.      To fix this, either :
  2106.      1) don't create the duplicate symbol
  2107.      (assumes ECOFF symtab is a subset of the ELF symtab;
  2108.      assumes no side-effects result from ignoring ECOFF symbol)
  2109.      2) create it, only if lookup for existing symbol in ELF's minimal
  2110.      symbols fails
  2111.      (inefficient;
  2112.      assumes no side-effects result from ignoring ECOFF symbol)
  2113.      3) create it, but lookup ELF's minimal symbol and use it's section
  2114.      during relocation, then modify "uniqify" phase to merge and
  2115.      eliminate the duplicate symbol
  2116.      (highly inefficient)

  2117.      I've implemented #1 here...
  2118.      Skip the creation of the minimal symbols based on the ECOFF
  2119.      symbol table.  */

  2120.   /* Pass 2 over external syms: fill in external symbols.  */
  2121.   ext_in = ext_block;
  2122.   ext_in_end = ext_in + hdr->iextMax;
  2123.   for (; ext_in < ext_in_end; ext_in++)
  2124.     {
  2125.       enum minimal_symbol_type ms_type = mst_text;
  2126.       CORE_ADDR svalue = ext_in->asym.value;

  2127.       /* The Irix 5 native tools seem to sometimes generate bogus
  2128.          external symbols.  */
  2129.       if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
  2130.         {
  2131.           complaint (&symfile_complaints,
  2132.                      _("bad ifd for external symbol: %d (max %ld)"),
  2133.                      ext_in->ifd, hdr->ifdMax);
  2134.           continue;
  2135.         }
  2136.       if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
  2137.         {
  2138.           complaint (&symfile_complaints,
  2139.                      _("bad iss for external symbol: %ld (max %ld)"),
  2140.                      ext_in->asym.iss, hdr->issExtMax);
  2141.           continue;
  2142.         }

  2143.       extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
  2144.                  + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;


  2145.       if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
  2146.         continue;


  2147.       /* Pass 3 over files, over local syms: fill in static symbols.  */
  2148.       name = debug_info->ssext + ext_in->asym.iss;

  2149.       /* Process ECOFF Symbol Types and Storage Classes.  */
  2150.       switch (ext_in->asym.st)
  2151.         {
  2152.         case stProc:
  2153.           /* Beginnning of Procedure */
  2154.           break;
  2155.         case stStaticProc:
  2156.           /* Load time only static procs */
  2157.           ms_type = mst_file_text;
  2158.           break;
  2159.         case stGlobal:
  2160.           /* External symbol */
  2161.           if (SC_IS_COMMON (ext_in->asym.sc))
  2162.             {
  2163.               /* The value of a common symbol is its size, not its address.
  2164.                  Ignore it.  */
  2165.               continue;
  2166.             }
  2167.           else if (SC_IS_DATA (ext_in->asym.sc))
  2168.             {
  2169.               ms_type = mst_data;
  2170.             }
  2171.           else if (SC_IS_BSS (ext_in->asym.sc))
  2172.             {
  2173.               ms_type = mst_bss;
  2174.             }
  2175.           else if (SC_IS_SBSS (ext_in->asym.sc))
  2176.             {
  2177.               ms_type = mst_bss;
  2178.             }
  2179.           else
  2180.             ms_type = mst_abs;
  2181.           break;
  2182.         case stLabel:
  2183.           /* Label */

  2184.           /* On certain platforms, some extra label symbols can be
  2185.              generated by the linker.  One possible usage for this kind
  2186.              of symbols is to represent the address of the begining of a
  2187.              given section.  For instance, on Tru64 5.1, the address of
  2188.              the _ftext label is the start address of the .text section.

  2189.              The storage class of these symbols is usually directly
  2190.              related to the section to which the symbol refers.  For
  2191.              instance, on Tru64 5.1, the storage class for the _fdata
  2192.              label is scData, refering to the .data section.

  2193.              It is actually possible that the section associated to the
  2194.              storage class of the label does not exist.  On True64 5.1
  2195.              for instance, the libm.so shared library does not contain
  2196.              any .data section, although it contains a _fpdata label
  2197.              which storage class is scData...  Since these symbols are
  2198.              usually useless for the debugger user anyway, we just
  2199.              discard these symbols.  */

  2200.           if (SC_IS_TEXT (ext_in->asym.sc))
  2201.             {
  2202.               if (objfile->sect_index_text == -1)
  2203.                 continue;

  2204.               ms_type = mst_file_text;
  2205.             }
  2206.           else if (SC_IS_DATA (ext_in->asym.sc))
  2207.             {
  2208.               if (objfile->sect_index_data == -1)
  2209.                 continue;

  2210.               ms_type = mst_file_data;
  2211.             }
  2212.           else if (SC_IS_BSS (ext_in->asym.sc))
  2213.             {
  2214.               if (objfile->sect_index_bss == -1)
  2215.                 continue;

  2216.               ms_type = mst_file_bss;
  2217.             }
  2218.           else if (SC_IS_SBSS (ext_in->asym.sc))
  2219.             {
  2220.               const int sbss_sect_index = get_section_index (objfile, ".sbss");

  2221.               if (sbss_sect_index == -1)
  2222.                 continue;

  2223.               ms_type = mst_file_bss;
  2224.             }
  2225.           else
  2226.             ms_type = mst_abs;
  2227.           break;
  2228.         case stLocal:
  2229.         case stNil:
  2230.           /* The alpha has the section start addresses in stLocal symbols
  2231.              whose name starts with a `.'.  Skip those but complain for all
  2232.              other stLocal symbols.
  2233.              Irix6 puts the section start addresses in stNil symbols, skip
  2234.              those too.  */
  2235.           if (name[0] == '.')
  2236.             continue;
  2237.           /* Fall through.  */
  2238.         default:
  2239.           ms_type = mst_unknown;
  2240.           unknown_ext_complaint (name);
  2241.         }
  2242.       if (!ECOFF_IN_ELF (cur_bfd))
  2243.         record_minimal_symbol (name, svalue, ms_type, ext_in->asym.sc,
  2244.                                objfile);
  2245.     }

  2246.   /* Pass 3 over files, over local syms: fill in static symbols.  */
  2247.   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
  2248.     {
  2249.       struct partial_symtab *save_pst;
  2250.       EXTR *ext_ptr;
  2251.       CORE_ADDR textlow;

  2252.       cur_fdr = fh = debug_info->fdr + f_idx;

  2253.       if (fh->csym == 0)
  2254.         {
  2255.           fdr_to_pst[f_idx].pst = NULL;
  2256.           continue;
  2257.         }

  2258.       /* Determine the start address for this object file from the
  2259.          file header and relocate it, except for Irix 5.2 zero fh->adr.  */
  2260.       if (fh->cpd)
  2261.         {
  2262.           textlow = fh->adr;
  2263.           if (relocatable || textlow != 0)
  2264.             textlow += ANOFFSET (objfile->section_offsets,
  2265.                                  SECT_OFF_TEXT (objfile));
  2266.         }
  2267.       else
  2268.         textlow = 0;
  2269.       pst = start_psymtab_common (objfile, objfile->section_offsets,
  2270.                                   fdr_name (fh),
  2271.                                   textlow,
  2272.                                   objfile->global_psymbols.next,
  2273.                                   objfile->static_psymbols.next);
  2274.       pst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
  2275.                                                 sizeof (struct symloc));
  2276.       memset (pst->read_symtab_private, 0, sizeof (struct symloc));

  2277.       save_pst = pst;
  2278.       FDR_IDX (pst) = f_idx;
  2279.       CUR_BFD (pst) = cur_bfd;
  2280.       DEBUG_SWAP (pst) = debug_swap;
  2281.       DEBUG_INFO (pst) = debug_info;
  2282.       PENDING_LIST (pst) = pending_list;

  2283.       /* The way to turn this into a symtab is to call...  */
  2284.       pst->read_symtab = mdebug_read_symtab;

  2285.       /* Set up language for the pst.
  2286.          The language from the FDR is used if it is unambigious (e.g. cfront
  2287.          with native cc and g++ will set the language to C).
  2288.          Otherwise we have to deduce the language from the filename.
  2289.          Native ecoff has every header file in a separate FDR, so
  2290.          deduce_language_from_filename will return language_unknown for
  2291.          a header file, which is not what we want.
  2292.          But the FDRs for the header files are after the FDR for the source
  2293.          file, so we can assign the language of the source file to the
  2294.          following header files.  Then we save the language in the private
  2295.          pst data so that we can reuse it when building symtabs.  */
  2296.       prev_language = psymtab_language;

  2297.       switch (fh->lang)
  2298.         {
  2299.         case langCplusplusV2:
  2300.           psymtab_language = language_cplus;
  2301.           break;
  2302.         default:
  2303.           psymtab_language = deduce_language_from_filename (fdr_name (fh));
  2304.           break;
  2305.         }
  2306.       if (psymtab_language == language_unknown)
  2307.         psymtab_language = prev_language;
  2308.       PST_PRIVATE (pst)->pst_language = psymtab_language;

  2309.       pst->texthigh = pst->textlow;

  2310.       /* For stabs-in-ecoff files, the second symbol must be @stab.
  2311.          This symbol is emitted by mips-tfile to signal that the
  2312.          current object file uses encapsulated stabs instead of mips
  2313.          ecoff for local symbols.  (It is the second symbol because
  2314.          the first symbol is the stFile used to signal the start of a
  2315.          file).  */
  2316.       processing_gcc_compilation = 0;
  2317.       if (fh->csym >= 2)
  2318.         {
  2319.           (*swap_sym_in) (cur_bfd,
  2320.                           ((char *) debug_info->external_sym
  2321.                            + (fh->isymBase + 1) * external_sym_size),
  2322.                           &sh);
  2323.           if (strcmp (debug_info->ss + fh->issBase + sh.iss,
  2324.                       stabs_symbol) == 0)
  2325.             processing_gcc_compilation = 2;
  2326.         }

  2327.       if (processing_gcc_compilation != 0)
  2328.         {
  2329.           for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
  2330.             {
  2331.               int type_code;
  2332.               const char *namestring;

  2333.               (*swap_sym_in) (cur_bfd,
  2334.                               (((char *) debug_info->external_sym)
  2335.                             + (fh->isymBase + cur_sdx) * external_sym_size),
  2336.                               &sh);
  2337.               type_code = ECOFF_UNMARK_STAB (sh.index);
  2338.               if (!ECOFF_IS_STAB (&sh))
  2339.                 {
  2340.                   if (sh.st == stProc || sh.st == stStaticProc)
  2341.                     {
  2342.                       CORE_ADDR procaddr;
  2343.                       long isym;

  2344.                       if (sh.st == stStaticProc)
  2345.                         {
  2346.                           namestring = debug_info->ss + fh->issBase + sh.iss;
  2347.                           record_minimal_symbol (namestring, sh.value,
  2348.                                                  mst_file_text, sh.sc,
  2349.                                                  objfile);
  2350.                         }
  2351.                       sh.value += ANOFFSET (objfile->section_offsets,
  2352.                                             SECT_OFF_TEXT (objfile));
  2353.                       procaddr = sh.value;

  2354.                       isym = AUX_GET_ISYM (fh->fBigendian,
  2355.                                            (debug_info->external_aux
  2356.                                             + fh->iauxBase
  2357.                                             + sh.index));
  2358.                       (*swap_sym_in) (cur_bfd,
  2359.                                       ((char *) debug_info->external_sym
  2360.                                        + ((fh->isymBase + isym - 1)
  2361.                                           * external_sym_size)),
  2362.                                       &sh);
  2363.                       if (sh.st == stEnd)
  2364.                         {
  2365.                           CORE_ADDR high = procaddr + sh.value;

  2366.                           /* Kludge for Irix 5.2 zero fh->adr.  */
  2367.                           if (!relocatable
  2368.                           && (pst->textlow == 0 || procaddr < pst->textlow))
  2369.                             pst->textlow = procaddr;
  2370.                           if (high > pst->texthigh)
  2371.                             pst->texthigh = high;
  2372.                         }
  2373.                     }
  2374.                   else if (sh.st == stStatic)
  2375.                     {
  2376.                       switch (sh.sc)
  2377.                         {
  2378.                         case scUndefined:
  2379.                         case scSUndefined:
  2380.                         case scNil:
  2381.                         case scAbs:
  2382.                           break;

  2383.                         case scData:
  2384.                         case scSData:
  2385.                         case scRData:
  2386.                         case scPData:
  2387.                         case scXData:
  2388.                           namestring = debug_info->ss + fh->issBase + sh.iss;
  2389.                           record_minimal_symbol (namestring, sh.value,
  2390.                                                  mst_file_data, sh.sc,
  2391.                                                  objfile);
  2392.                           sh.value += ANOFFSET (objfile->section_offsets,
  2393.                                                 SECT_OFF_DATA (objfile));
  2394.                           break;

  2395.                         default:
  2396.                           /* FIXME!  Shouldn't this use cases for bss,
  2397.                              then have the default be abs?  */
  2398.                           namestring = debug_info->ss + fh->issBase + sh.iss;
  2399.                           record_minimal_symbol (namestring, sh.value,
  2400.                                                  mst_file_bss, sh.sc,
  2401.                                                  objfile);
  2402.                           sh.value += ANOFFSET (objfile->section_offsets,
  2403.                                                 SECT_OFF_BSS (objfile));
  2404.                           break;
  2405.                         }
  2406.                     }
  2407.                   continue;
  2408.                 }
  2409.               /* Handle stabs continuation.  */
  2410.               {
  2411.                 char *stabstring = debug_info->ss + fh->issBase + sh.iss;
  2412.                 int len = strlen (stabstring);

  2413.                 while (stabstring[len - 1] == '\\')
  2414.                   {
  2415.                     SYMR sh2;
  2416.                     char *stabstring1 = stabstring;
  2417.                     char *stabstring2;
  2418.                     int len2;

  2419.                     /* Ignore continuation char from 1st string.  */
  2420.                     len--;

  2421.                     /* Read next stabstring.  */
  2422.                     cur_sdx++;
  2423.                     (*swap_sym_in) (cur_bfd,
  2424.                                     (((char *) debug_info->external_sym)
  2425.                                      + (fh->isymBase + cur_sdx)
  2426.                                      * external_sym_size),
  2427.                                     &sh2);
  2428.                     stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
  2429.                     len2 = strlen (stabstring2);

  2430.                     /* Concatinate stabstring2 with stabstring1.  */
  2431.                     if (stabstring
  2432.                      && stabstring != debug_info->ss + fh->issBase + sh.iss)
  2433.                       stabstring = xrealloc (stabstring, len + len2 + 1);
  2434.                     else
  2435.                       {
  2436.                         stabstring = xmalloc (len + len2 + 1);
  2437.                         strcpy (stabstring, stabstring1);
  2438.                       }
  2439.                     strcpy (stabstring + len, stabstring2);
  2440.                     len += len2;
  2441.                   }

  2442.                 switch (type_code)
  2443.                   {
  2444.                     char *p;

  2445.                     /* Standard, external, non-debugger, symbols.  */

  2446.                   case N_TEXT | N_EXT:
  2447.                   case N_NBTEXT | N_EXT:
  2448.                     sh.value += ANOFFSET (objfile->section_offsets,
  2449.                                           SECT_OFF_TEXT (objfile));
  2450.                     goto record_it;

  2451.                   case N_DATA | N_EXT:
  2452.                   case N_NBDATA | N_EXT:
  2453.                     sh.value += ANOFFSET (objfile->section_offsets,
  2454.                                           SECT_OFF_DATA (objfile));
  2455.                     goto record_it;

  2456.                   case N_BSS:
  2457.                   case N_BSS | N_EXT:
  2458.                   case N_NBBSS | N_EXT:
  2459.                   case N_SETV | N_EXT:                /* FIXME, is this in BSS?  */
  2460.                     sh.value += ANOFFSET (objfile->section_offsets,
  2461.                                           SECT_OFF_BSS (objfile));
  2462.                     goto record_it;

  2463.                   case N_ABS | N_EXT:
  2464.                   record_it:
  2465.                     continue;

  2466.                   /* Standard, local, non-debugger, symbols.  */

  2467.                   case N_NBTEXT:

  2468.                     /* We need to be able to deal with both N_FN or
  2469.                        N_TEXT, because we have no way of knowing
  2470.                        whether the sys-supplied ld or GNU ld was used
  2471.                        to make the executable.  Sequents throw in
  2472.                        another wrinkle -- they renumbered N_FN.  */

  2473.                   case N_FN:
  2474.                   case N_FN_SEQ:
  2475.                   case N_TEXT:
  2476.                     continue;

  2477.                   case N_DATA:
  2478.                     sh.value += ANOFFSET (objfile->section_offsets,
  2479.                                           SECT_OFF_DATA (objfile));
  2480.                     goto record_it;

  2481.                   case N_UNDF | N_EXT:
  2482.                     continue;                /* Just undefined, not COMMON.  */

  2483.                   case N_UNDF:
  2484.                     continue;

  2485.                     /* Lots of symbol types we can just ignore.  */

  2486.                   case N_ABS:
  2487.                   case N_NBDATA:
  2488.                   case N_NBBSS:
  2489.                     continue;

  2490.                     /* Keep going . . .  */

  2491.                     /*
  2492.                      * Special symbol types for GNU
  2493.                      */
  2494.                   case N_INDR:
  2495.                   case N_INDR | N_EXT:
  2496.                   case N_SETA:
  2497.                   case N_SETA | N_EXT:
  2498.                   case N_SETT:
  2499.                   case N_SETT | N_EXT:
  2500.                   case N_SETD:
  2501.                   case N_SETD | N_EXT:
  2502.                   case N_SETB:
  2503.                   case N_SETB | N_EXT:
  2504.                   case N_SETV:
  2505.                     continue;

  2506.                     /*
  2507.                      * Debugger symbols
  2508.                      */

  2509.                   case N_SO:
  2510.                     {
  2511.                       CORE_ADDR valu;
  2512.                       static int prev_so_symnum = -10;
  2513.                       static int first_so_symnum;
  2514.                       const char *p;
  2515.                       int prev_textlow_not_set;

  2516.                       valu = sh.value + ANOFFSET (objfile->section_offsets,
  2517.                                                   SECT_OFF_TEXT (objfile));

  2518.                       prev_textlow_not_set = textlow_not_set;

  2519.                       /* A zero value is probably an indication for the
  2520.                          SunPRO 3.0 compiler.  end_psymtab explicitly tests
  2521.                          for zero, so don't relocate it.  */

  2522.                       if (sh.value == 0
  2523.                           && gdbarch_sofun_address_maybe_missing (gdbarch))
  2524.                         {
  2525.                           textlow_not_set = 1;
  2526.                           valu = 0;
  2527.                         }
  2528.                       else
  2529.                         textlow_not_set = 0;

  2530.                       past_first_source_file = 1;

  2531.                       if (prev_so_symnum != symnum - 1)
  2532.                         {                /* Here if prev stab wasn't N_SO.  */
  2533.                           first_so_symnum = symnum;

  2534.                           if (pst)
  2535.                             {
  2536.                               pst = (struct partial_symtab *) 0;
  2537.                               includes_used = 0;
  2538.                               dependencies_used = 0;
  2539.                             }
  2540.                         }

  2541.                       prev_so_symnum = symnum;

  2542.                       /* End the current partial symtab and start a
  2543.                          new one.  */

  2544.                       /* SET_NAMESTRING ();*/
  2545.                       namestring = stabstring;

  2546.                       /* Null name means end of .o file.  Don't start a new
  2547.                          one.  */
  2548.                       if (*namestring == '\000')
  2549.                         continue;

  2550.                       /* Some compilers (including gcc) emit a pair of
  2551.                          initial N_SOs.  The first one is a directory name;
  2552.                          the second the file name.  If pst exists, is
  2553.                          empty, and has a filename ending in '/', we assume
  2554.                          the previous N_SO was a directory name.  */
  2555.                       p = lbasename (namestring);
  2556.                       if (p != namestring && *p == '\000')
  2557.                         continue;                /* Simply ignore directory
  2558.                                                    name SOs.  */

  2559.                       /* Some other compilers (C++ ones in particular) emit
  2560.                          useless SOs for non-existant .c files.  We ignore
  2561.                          all subsequent SOs that immediately follow the
  2562.                          first.  */

  2563.                       if (!pst)
  2564.                         pst = save_pst;
  2565.                       continue;
  2566.                     }

  2567.                   case N_BINCL:
  2568.                     continue;

  2569.                   case N_SOL:
  2570.                     {
  2571.                       enum language tmp_language;

  2572.                       /* Mark down an include file in the current psymtab.  */

  2573.                       /* SET_NAMESTRING (); */
  2574.                       namestring = stabstring;

  2575.                       tmp_language
  2576.                         = deduce_language_from_filename (namestring);

  2577.                       /* Only change the psymtab's language if we've
  2578.                          learned something useful (eg. tmp_language is not
  2579.                          language_unknown).  In addition, to match what
  2580.                          start_subfile does, never change from C++ to
  2581.                          C.  */
  2582.                       if (tmp_language != language_unknown
  2583.                           && (tmp_language != language_c
  2584.                               || psymtab_language != language_cplus))
  2585.                         psymtab_language = tmp_language;

  2586.                       /* In C++, one may expect the same filename to come
  2587.                          round many times, when code is coming alternately
  2588.                          from the main file and from inline functions in
  2589.                          other files.  So I check to see if this is a file
  2590.                          we've seen before -- either the main source file,
  2591.                          or a previously included file.

  2592.                          This seems to be a lot of time to be spending on
  2593.                          N_SOL, but things like "break c-exp.y:435" need to
  2594.                          work (I suppose the psymtab_include_list could be
  2595.                          hashed or put in a binary tree, if profiling shows
  2596.                          this is a major hog).  */
  2597.                       if (pst && filename_cmp (namestring, pst->filename) == 0)
  2598.                         continue;

  2599.                       {
  2600.                         int i;

  2601.                         for (i = 0; i < includes_used; i++)
  2602.                           if (filename_cmp (namestring,
  2603.                                             psymtab_include_list[i]) == 0)
  2604.                             {
  2605.                               i = -1;
  2606.                               break;
  2607.                             }
  2608.                         if (i == -1)
  2609.                           continue;
  2610.                       }

  2611.                       psymtab_include_list[includes_used++] = namestring;
  2612.                       if (includes_used >= includes_allocated)
  2613.                         {
  2614.                           const char **orig = psymtab_include_list;

  2615.                           psymtab_include_list = (const char **)
  2616.                             alloca ((includes_allocated *= 2) *
  2617.                                     sizeof (const char *));
  2618.                           memcpy (psymtab_include_list, orig,
  2619.                                   includes_used * sizeof (const char *));
  2620.                         }
  2621.                       continue;
  2622.                     }
  2623.                   case N_LSYM:            /* Typedef or automatic variable.  */
  2624.                   case N_STSYM:            /* Data seg var -- static  */
  2625.                   case N_LCSYM:            /* BSS      "  */
  2626.                   case N_ROSYM:            /* Read-only data seg var -- static.  */
  2627.                   case N_NBSTS:            /* Gould nobase.  */
  2628.                   case N_NBLCS:            /* symbols.  */
  2629.                   case N_FUN:
  2630.                   case N_GSYM:            /* Global (extern) variable; can be
  2631.                                        data or bss (sigh FIXME).  */

  2632.                     /* Following may probably be ignored; I'll leave them here
  2633.                        for now (until I do Pascal and Modula 2 extensions).  */

  2634.                   case N_PC:            /* I may or may not need this; I
  2635.                                        suspect not.  */
  2636.                   case N_M2C:            /* I suspect that I can ignore this
  2637.                                        here.  */
  2638.                   case N_SCOPE:            /* Same.  */

  2639.                     /*    SET_NAMESTRING (); */
  2640.                     namestring = stabstring;
  2641.                     p = (char *) strchr (namestring, ':');
  2642.                     if (!p)
  2643.                       continue;            /* Not a debugging symbol.  */



  2644.                     /* Main processing section for debugging symbols which
  2645.                        the initial read through the symbol tables needs to
  2646.                        worry about.  If we reach this point, the symbol
  2647.                        which we are considering is definitely one we are
  2648.                        interested in.  p must also contain the (valid)
  2649.                        index into the namestring which indicates the
  2650.                        debugging type symbol.  */

  2651.                     switch (p[1])
  2652.                       {
  2653.                       case 'S':
  2654.                         sh.value += ANOFFSET (objfile->section_offsets,
  2655.                                               SECT_OFF_DATA (objfile));

  2656.                         if (gdbarch_static_transform_name_p (gdbarch))
  2657.                           namestring = gdbarch_static_transform_name
  2658.                                          (gdbarch, namestring);

  2659.                         add_psymbol_to_list (namestring, p - namestring, 1,
  2660.                                              VAR_DOMAIN, LOC_STATIC,
  2661.                                              &objfile->static_psymbols,
  2662.                                              0, sh.value,
  2663.                                              psymtab_language, objfile);
  2664.                         continue;
  2665.                       case 'G':
  2666.                         sh.value += ANOFFSET (objfile->section_offsets,
  2667.                                               SECT_OFF_DATA (objfile));
  2668.                         /* The addresses in these entries are reported
  2669.                            to be wrong.  See the code that reads 'G's
  2670.                            for symtabs.  */
  2671.                         add_psymbol_to_list (namestring, p - namestring, 1,
  2672.                                              VAR_DOMAIN, LOC_STATIC,
  2673.                                              &objfile->global_psymbols,
  2674.                                              0, sh.value,
  2675.                                              psymtab_language, objfile);
  2676.                         continue;

  2677.                       case 'T':
  2678.                         /* When a 'T' entry is defining an anonymous enum, it
  2679.                            may have a name which is the empty string, or a
  2680.                            single space.  Since they're not really defining a
  2681.                            symbol, those shouldn't go in the partial symbol
  2682.                            table.  We do pick up the elements of such enums at
  2683.                            'check_enum:', below.  */
  2684.                         if (p >= namestring + 2
  2685.                             || (p == namestring + 1
  2686.                                 && namestring[0] != ' '))
  2687.                           {
  2688.                             add_psymbol_to_list (namestring, p - namestring, 1,
  2689.                                                  STRUCT_DOMAIN, LOC_TYPEDEF,
  2690.                                                  &objfile->static_psymbols,
  2691.                                                  sh.value, 0,
  2692.                                                  psymtab_language, objfile);
  2693.                             if (p[2] == 't')
  2694.                               {
  2695.                                 /* Also a typedef with the same name.  */
  2696.                                 add_psymbol_to_list (namestring,
  2697.                                                      p - namestring, 1,
  2698.                                                      VAR_DOMAIN, LOC_TYPEDEF,
  2699.                                                      &objfile->static_psymbols,
  2700.                                                      sh.value, 0,
  2701.                                                      psymtab_language,
  2702.                                                      objfile);
  2703.                                 p += 1;
  2704.                               }
  2705.                           }
  2706.                         goto check_enum;
  2707.                       case 't':
  2708.                         if (p != namestring)        /* a name is there, not
  2709.                                                    just :T...  */
  2710.                           {
  2711.                             add_psymbol_to_list (namestring, p - namestring, 1,
  2712.                                                  VAR_DOMAIN, LOC_TYPEDEF,
  2713.                                                  &objfile->static_psymbols,
  2714.                                                  sh.value, 0,
  2715.                                                  psymtab_language, objfile);
  2716.                           }
  2717.                       check_enum:
  2718.                         /* If this is an enumerated type, we need to add
  2719.                            all the enum constants to the partial symbol
  2720.                            table.  This does not cover enums without names,
  2721.                            e.g. "enum {a, b} c;" in C, but fortunately
  2722.                            those are rare.  There is no way for GDB to find
  2723.                            those from the enum type without spending too
  2724.                            much time on it.  Thus to solve this problem,
  2725.                            the compiler needs to put out the enum in a
  2726.                            nameless type.  GCC2 does this.  */

  2727.                         /* We are looking for something of the form
  2728.                            <name> ":" ("t" | "T") [<number> "="] "e"
  2729.                            {<constant> ":" <value> ","} ";".  */

  2730.                         /* Skip over the colon and the 't' or 'T'.  */
  2731.                         p += 2;
  2732.                         /* This type may be given a number.  Also, numbers
  2733.                            can come in pairs like (0,26).  Skip over it.  */
  2734.                         while ((*p >= '0' && *p <= '9')
  2735.                                || *p == '(' || *p == ',' || *p == ')'
  2736.                                || *p == '=')
  2737.                           p++;

  2738.                         if (*p++ == 'e')
  2739.                           {
  2740.                             /* The aix4 compiler emits extra crud before
  2741.                                the members.  */
  2742.                             if (*p == '-')
  2743.                               {
  2744.                                 /* Skip over the type (?).  */
  2745.                                 while (*p != ':')
  2746.                                   p++;

  2747.                                 /* Skip over the colon.  */
  2748.                                 p++;
  2749.                               }

  2750.                             /* We have found an enumerated type.  */
  2751.                             /* According to comments in read_enum_type
  2752.                                a comma could end it instead of a semicolon.
  2753.                                I don't know where that happens.
  2754.                                Accept either.  */
  2755.                             while (*p && *p != ';' && *p != ',')
  2756.                               {
  2757.                                 char *q;

  2758.                                 /* Check for and handle cretinous dbx
  2759.                                    symbol name continuation!  */
  2760.                                 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
  2761.                                   p = next_symbol_text (objfile);

  2762.                                 /* Point to the character after the name
  2763.                                    of the enum constant.  */
  2764.                                 for (q = p; *q && *q != ':'; q++)
  2765.                                   ;
  2766.                                 /* Note that the value doesn't matter for
  2767.                                    enum constants in psymtabs, just in
  2768.                                    symtabs.  */
  2769.                                 add_psymbol_to_list (p, q - p, 1,
  2770.                                                      VAR_DOMAIN, LOC_CONST,
  2771.                                                      &objfile->static_psymbols,
  2772.                                                      0, 0, psymtab_language,
  2773.                                                      objfile);
  2774.                                 /* Point past the name.  */
  2775.                                 p = q;
  2776.                                 /* Skip over the value.  */
  2777.                                 while (*p && *p != ',')
  2778.                                   p++;
  2779.                                 /* Advance past the comma.  */
  2780.                                 if (*p)
  2781.                                   p++;
  2782.                               }
  2783.                           }
  2784.                         continue;
  2785.                       case 'c':
  2786.                         /* Constant, e.g. from "const" in Pascal.  */
  2787.                         add_psymbol_to_list (namestring, p - namestring, 1,
  2788.                                              VAR_DOMAIN, LOC_CONST,
  2789.                                              &objfile->static_psymbols,
  2790.                                              sh.value, 0, psymtab_language,
  2791.                                              objfile);
  2792.                         continue;

  2793.                       case 'f':
  2794.                         if (! pst)
  2795.                           {
  2796.                             int name_len = p - namestring;
  2797.                             char *name = xmalloc (name_len + 1);

  2798.                             memcpy (name, namestring, name_len);
  2799.                             name[name_len] = '\0';
  2800.                             function_outside_compilation_unit_complaint (name);
  2801.                             xfree (name);
  2802.                           }
  2803.                         sh.value += ANOFFSET (objfile->section_offsets,
  2804.                                               SECT_OFF_TEXT (objfile));
  2805.                         add_psymbol_to_list (namestring, p - namestring, 1,
  2806.                                              VAR_DOMAIN, LOC_BLOCK,
  2807.                                              &objfile->static_psymbols,
  2808.                                              0, sh.value,
  2809.                                              psymtab_language, objfile);
  2810.                         continue;

  2811.                         /* Global functions were ignored here, but now they
  2812.                            are put into the global psymtab like one would
  2813.                            expect.  They're also in the minimal symbol
  2814.                            table.  */
  2815.                       case 'F':
  2816.                         if (! pst)
  2817.                           {
  2818.                             int name_len = p - namestring;
  2819.                             char *name = xmalloc (name_len + 1);

  2820.                             memcpy (name, namestring, name_len);
  2821.                             name[name_len] = '\0';
  2822.                             function_outside_compilation_unit_complaint (name);
  2823.                             xfree (name);
  2824.                           }
  2825.                         sh.value += ANOFFSET (objfile->section_offsets,
  2826.                                               SECT_OFF_TEXT (objfile));
  2827.                         add_psymbol_to_list (namestring, p - namestring, 1,
  2828.                                              VAR_DOMAIN, LOC_BLOCK,
  2829.                                              &objfile->global_psymbols,
  2830.                                              0, sh.value,
  2831.                                              psymtab_language, objfile);
  2832.                         continue;

  2833.                         /* Two things show up here (hopefully); static
  2834.                            symbols of local scope (static used inside
  2835.                            braces) or extensions of structure symbols.  We
  2836.                            can ignore both.  */
  2837.                       case 'V':
  2838.                       case '(':
  2839.                       case '0':
  2840.                       case '1':
  2841.                       case '2':
  2842.                       case '3':
  2843.                       case '4':
  2844.                       case '5':
  2845.                       case '6':
  2846.                       case '7':
  2847.                       case '8':
  2848.                       case '9':
  2849.                       case '-':
  2850.                       case '#':                /* For symbol identification (used
  2851.                                            in live ranges).  */
  2852.                         continue;

  2853.                       case ':':
  2854.                         /* It is a C++ nested symbol.  We don't need to
  2855.                            record it (I don't think); if we try to look up
  2856.                            foo::bar::baz, then symbols for the symtab
  2857.                            containing foo should get read in, I think.  */
  2858.                         /* Someone says sun cc puts out symbols like
  2859.                            /foo/baz/maclib::/usr/local/bin/maclib,
  2860.                            which would get here with a symbol type of ':'.  */
  2861.                         continue;

  2862.                       default:
  2863.                         /* Unexpected symbol descriptor.  The second and
  2864.                            subsequent stabs of a continued stab can show up
  2865.                            here.  The question is whether they ever can
  2866.                            mimic a normal stab--it would be nice if not,
  2867.                            since we certainly don't want to spend the time
  2868.                            searching to the end of every string looking for
  2869.                            a backslash.  */

  2870.                         complaint (&symfile_complaints,
  2871.                                    _("unknown symbol descriptor `%c'"), p[1]);

  2872.                         /* Ignore it; perhaps it is an extension that we don't
  2873.                            know about.  */
  2874.                         continue;
  2875.                       }

  2876.                   case N_EXCL:
  2877.                     continue;

  2878.                   case N_ENDM:
  2879.                     /* Solaris 2 end of module, finish current partial
  2880.                        symbol table.  END_PSYMTAB will set
  2881.                        pst->texthigh to the proper value, which is
  2882.                        necessary if a module compiled without
  2883.                        debugging info follows this module.  */
  2884.                     if (pst
  2885.                         && gdbarch_sofun_address_maybe_missing (gdbarch))
  2886.                       {
  2887.                         pst = (struct partial_symtab *) 0;
  2888.                         includes_used = 0;
  2889.                         dependencies_used = 0;
  2890.                       }
  2891.                     continue;

  2892.                   case N_RBRAC:
  2893.                     if (sh.value > save_pst->texthigh)
  2894.                       save_pst->texthigh = sh.value;
  2895.                     continue;
  2896.                   case N_EINCL:
  2897.                   case N_DSLINE:
  2898.                   case N_BSLINE:
  2899.                   case N_SSYM:                /* Claim: Structure or union
  2900.                                            element.  Hopefully, I can
  2901.                                            ignore this.  */
  2902.                   case N_ENTRY:                /* Alternate entry point; can
  2903.                                            ignore.  */
  2904.                   case N_MAIN:                /* Can definitely ignore this.   */
  2905.                   case N_CATCH:                /* These are GNU C++ extensions.  */
  2906.                   case N_EHDECL:        /* that can safely be ignored here.  */
  2907.                   case N_LENG:
  2908.                   case N_BCOMM:
  2909.                   case N_ECOMM:
  2910.                   case N_ECOML:
  2911.                   case N_FNAME:
  2912.                   case N_SLINE:
  2913.                   case N_RSYM:
  2914.                   case N_PSYM:
  2915.                   case N_LBRAC:
  2916.                   case N_NSYMS:                /* Ultrix 4.0: symbol count */
  2917.                   case N_DEFD:                        /* GNU Modula-2 */
  2918.                   case N_ALIAS:                /* SunPro F77: alias name, ignore
  2919.                                            for now.  */

  2920.                   case N_OBJ:                /* Useless types from Solaris.  */
  2921.                   case N_OPT:
  2922.                     /* These symbols aren't interesting; don't worry about
  2923.                        them.  */

  2924.                     continue;

  2925.                   default:
  2926.                     /* If we haven't found it yet, ignore it.  It's
  2927.                        probably some new type we don't know about yet.  */
  2928.                     complaint (&symfile_complaints,
  2929.                                _("unknown symbol type %s"),
  2930.                                hex_string (type_code)); /* CUR_SYMBOL_TYPE */
  2931.                     continue;
  2932.                   }
  2933.                 if (stabstring
  2934.                     && stabstring != debug_info->ss + fh->issBase + sh.iss)
  2935.                   xfree (stabstring);
  2936.               }
  2937.               /* end - Handle continuation */
  2938.             }
  2939.         }
  2940.       else
  2941.         {
  2942.           for (cur_sdx = 0; cur_sdx < fh->csym;)
  2943.             {
  2944.               char *name;
  2945.               enum address_class class;
  2946.               CORE_ADDR minsym_value;

  2947.               (*swap_sym_in) (cur_bfd,
  2948.                               ((char *) debug_info->external_sym
  2949.                                + ((fh->isymBase + cur_sdx)
  2950.                                   * external_sym_size)),
  2951.                               &sh);

  2952.               if (ECOFF_IS_STAB (&sh))
  2953.                 {
  2954.                   cur_sdx++;
  2955.                   continue;
  2956.                 }

  2957.               /* Non absolute static symbols go into the minimal table.  */
  2958.               if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
  2959.                   || (sh.index == indexNil
  2960.                       && (sh.st != stStatic || sh.sc == scAbs)))
  2961.                 {
  2962.                   /* FIXME, premature?  */
  2963.                   cur_sdx++;
  2964.                   continue;
  2965.                 }

  2966.               name = debug_info->ss + fh->issBase + sh.iss;

  2967.               minsym_value = sh.value;

  2968.               switch (sh.sc)
  2969.                 {
  2970.                 case scText:
  2971.                 case scRConst:
  2972.                   /* The value of a stEnd symbol is the displacement from the
  2973.                      corresponding start symbol value, do not relocate it.  */
  2974.                   if (sh.st != stEnd)
  2975.                     sh.value += ANOFFSET (objfile->section_offsets,
  2976.                                           SECT_OFF_TEXT (objfile));
  2977.                   break;
  2978.                 case scData:
  2979.                 case scSData:
  2980.                 case scRData:
  2981.                 case scPData:
  2982.                 case scXData:
  2983.                   sh.value += ANOFFSET (objfile->section_offsets,
  2984.                                         SECT_OFF_DATA (objfile));
  2985.                   break;
  2986.                 case scBss:
  2987.                 case scSBss:
  2988.                   sh.value += ANOFFSET (objfile->section_offsets,
  2989.                                         SECT_OFF_BSS (objfile));
  2990.                   break;
  2991.                 }

  2992.               switch (sh.st)
  2993.                 {
  2994.                   CORE_ADDR high;
  2995.                   CORE_ADDR procaddr;
  2996.                   int new_sdx;

  2997.                 case stStaticProc:
  2998.                   prim_record_minimal_symbol_and_info (name, minsym_value,
  2999.                                                        mst_file_text,
  3000.                                                        SECT_OFF_TEXT (objfile),
  3001.                                                        objfile);

  3002.                   /* FALLTHROUGH */

  3003.                 case stProc:
  3004.                   /* Ignore all parameter symbol records.  */
  3005.                   if (sh.index >= hdr->iauxMax)
  3006.                     {
  3007.                       /* Should not happen, but does when cross-compiling
  3008.                          with the MIPS compiler.  FIXME -- pull later.  */
  3009.                       index_complaint (name);
  3010.                       new_sdx = cur_sdx + 1;        /* Don't skip at all.  */
  3011.                     }
  3012.                   else
  3013.                     new_sdx = AUX_GET_ISYM (fh->fBigendian,
  3014.                                             (debug_info->external_aux
  3015.                                              + fh->iauxBase
  3016.                                              + sh.index));

  3017.                   if (new_sdx <= cur_sdx)
  3018.                     {
  3019.                       /* This should not happen either... FIXME.  */
  3020.                       complaint (&symfile_complaints,
  3021.                                  _("bad proc end in aux found from symbol %s"),
  3022.                                  name);
  3023.                       new_sdx = cur_sdx + 1;        /* Don't skip backward.  */
  3024.                     }

  3025.                   /* For stProc symbol records, we need to check the
  3026.                      storage class as well, as only (stProc, scText)
  3027.                      entries represent "real" procedures - See the
  3028.                      Compaq document titled "Object File / Symbol Table
  3029.                      Format Specification" for more information.  If the
  3030.                      storage class is not scText, we discard the whole
  3031.                      block of symbol records for this stProc.  */
  3032.                   if (sh.st == stProc && sh.sc != scText)
  3033.                     goto skip;

  3034.                   /* Usually there is a local and a global stProc symbol
  3035.                      for a function.  This means that the function name
  3036.                      has already been entered into the mimimal symbol table
  3037.                      while processing the global symbols in pass 2 above.
  3038.                      One notable exception is the PROGRAM name from
  3039.                      f77 compiled executables, it is only put out as
  3040.                      local stProc symbol, and a global MAIN__ stProc symbol
  3041.                      points to it.  It doesn't matter though, as gdb is
  3042.                      still able to find the PROGRAM name via the partial
  3043.                      symbol table, and the MAIN__ symbol via the minimal
  3044.                      symbol table.  */
  3045.                   if (sh.st == stProc)
  3046.                     add_psymbol_to_list (name, strlen (name), 1,
  3047.                                          VAR_DOMAIN, LOC_BLOCK,
  3048.                                          &objfile->global_psymbols,
  3049.                                     0, sh.value, psymtab_language, objfile);
  3050.                   else
  3051.                     add_psymbol_to_list (name, strlen (name), 1,
  3052.                                          VAR_DOMAIN, LOC_BLOCK,
  3053.                                          &objfile->static_psymbols,
  3054.                                     0, sh.value, psymtab_language, objfile);

  3055.                   procaddr = sh.value;

  3056.                   cur_sdx = new_sdx;
  3057.                   (*swap_sym_in) (cur_bfd,
  3058.                                   ((char *) debug_info->external_sym
  3059.                                    + ((fh->isymBase + cur_sdx - 1)
  3060.                                       * external_sym_size)),
  3061.                                   &sh);
  3062.                   if (sh.st != stEnd)
  3063.                     continue;

  3064.                   /* Kludge for Irix 5.2 zero fh->adr.  */
  3065.                   if (!relocatable
  3066.                       && (pst->textlow == 0 || procaddr < pst->textlow))
  3067.                     pst->textlow = procaddr;

  3068.                   high = procaddr + sh.value;
  3069.                   if (high > pst->texthigh)
  3070.                     pst->texthigh = high;
  3071.                   continue;

  3072.                 case stStatic:        /* Variable */
  3073.                   if (SC_IS_DATA (sh.sc))
  3074.                     prim_record_minimal_symbol_and_info (name, minsym_value,
  3075.                                                          mst_file_data,
  3076.                                                          SECT_OFF_DATA (objfile),
  3077.                                                          objfile);
  3078.                   else
  3079.                     prim_record_minimal_symbol_and_info (name, minsym_value,
  3080.                                                          mst_file_bss,
  3081.                                                          SECT_OFF_BSS (objfile),
  3082.                                                          objfile);
  3083.                   class = LOC_STATIC;
  3084.                   break;

  3085.                 case stIndirect:        /* Irix5 forward declaration */
  3086.                   /* Skip forward declarations from Irix5 cc.  */
  3087.                   goto skip;

  3088.                 case stTypedef:        /* Typedef */
  3089.                   /* Skip typedefs for forward declarations and opaque
  3090.                      structs from alpha and mips cc.  */
  3091.                   if (sh.iss == 0 || has_opaque_xref (fh, &sh))
  3092.                     goto skip;
  3093.                   class = LOC_TYPEDEF;
  3094.                   break;

  3095.                 case stConstant:        /* Constant decl */
  3096.                   class = LOC_CONST;
  3097.                   break;

  3098.                 case stUnion:
  3099.                 case stStruct:
  3100.                 case stEnum:
  3101.                 case stBlock:        /* { }, str, un, enum */
  3102.                   /* Do not create a partial symbol for cc unnamed aggregates
  3103.                      and gcc empty aggregates.  */
  3104.                   if ((sh.sc == scInfo
  3105.                        || SC_IS_COMMON (sh.sc))
  3106.                       && sh.iss != 0
  3107.                       && sh.index != cur_sdx + 2)
  3108.                     {
  3109.                       add_psymbol_to_list (name, strlen (name), 1,
  3110.                                            STRUCT_DOMAIN, LOC_TYPEDEF,
  3111.                                            &objfile->static_psymbols,
  3112.                                            0, (CORE_ADDR) 0,
  3113.                                            psymtab_language, objfile);
  3114.                     }
  3115.                   handle_psymbol_enumerators (objfile, fh, sh.st, sh.value);

  3116.                   /* Skip over the block.  */
  3117.                   new_sdx = sh.index;
  3118.                   if (new_sdx <= cur_sdx)
  3119.                     {
  3120.                       /* This happens with the Ultrix kernel.  */
  3121.                       complaint (&symfile_complaints,
  3122.                                  _("bad aux index at block symbol %s"), name);
  3123.                       new_sdx = cur_sdx + 1;        /* Don't skip backward.  */
  3124.                     }
  3125.                   cur_sdx = new_sdx;
  3126.                   continue;

  3127.                 case stFile:        /* File headers */
  3128.                 case stLabel:        /* Labels */
  3129.                 case stEnd:        /* Ends of files */
  3130.                   goto skip;

  3131.                 case stLocal:        /* Local variables */
  3132.                   /* Normally these are skipped because we skip over
  3133.                      all blocks we see.  However, these can occur
  3134.                      as visible symbols in a .h file that contains code.  */
  3135.                   goto skip;

  3136.                 default:
  3137.                   /* Both complaints are valid:  one gives symbol name,
  3138.                      the other the offending symbol type.  */
  3139.                   complaint (&symfile_complaints, _("unknown local symbol %s"),
  3140.                              name);
  3141.                   complaint (&symfile_complaints, _("with type %d"), sh.st);
  3142.                   cur_sdx++;
  3143.                   continue;
  3144.                 }
  3145.               /* Use this gdb symbol.  */
  3146.               add_psymbol_to_list (name, strlen (name), 1,
  3147.                                    VAR_DOMAIN, class,
  3148.                                    &objfile->static_psymbols,
  3149.                                    0, sh.value, psymtab_language, objfile);
  3150.             skip:
  3151.               cur_sdx++;        /* Go to next file symbol.  */
  3152.             }

  3153.           /* Now do enter the external symbols.  */
  3154.           ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
  3155.           cur_sdx = fdr_to_pst[f_idx].n_globals;
  3156.           PST_PRIVATE (save_pst)->extern_count = cur_sdx;
  3157.           PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
  3158.           for (; --cur_sdx >= 0; ext_ptr++)
  3159.             {
  3160.               enum address_class class;
  3161.               SYMR *psh;
  3162.               char *name;
  3163.               CORE_ADDR svalue;

  3164.               if (ext_ptr->ifd != f_idx)
  3165.                 internal_error (__FILE__, __LINE__,
  3166.                                 _("failed internal consistency check"));
  3167.               psh = &ext_ptr->asym;

  3168.               /* Do not add undefined symbols to the partial symbol table.  */
  3169.               if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
  3170.                 continue;

  3171.               svalue = psh->value;
  3172.               switch (psh->sc)
  3173.                 {
  3174.                 case scText:
  3175.                 case scRConst:
  3176.                   svalue += ANOFFSET (objfile->section_offsets,
  3177.                                       SECT_OFF_TEXT (objfile));
  3178.                   break;
  3179.                 case scData:
  3180.                 case scSData:
  3181.                 case scRData:
  3182.                 case scPData:
  3183.                 case scXData:
  3184.                   svalue += ANOFFSET (objfile->section_offsets,
  3185.                                       SECT_OFF_DATA (objfile));
  3186.                   break;
  3187.                 case scBss:
  3188.                 case scSBss:
  3189.                   svalue += ANOFFSET (objfile->section_offsets,
  3190.                                       SECT_OFF_BSS (objfile));
  3191.                   break;
  3192.                 }

  3193.               switch (psh->st)
  3194.                 {
  3195.                 case stNil:
  3196.                   /* These are generated for static symbols in .o files,
  3197.                      ignore them.  */
  3198.                   continue;
  3199.                 case stProc:
  3200.                 case stStaticProc:
  3201.                   /* External procedure symbols have been entered
  3202.                      into the minimal symbol table in pass 2 above.
  3203.                      Ignore them, as parse_external will ignore them too.  */
  3204.                   continue;
  3205.                 case stLabel:
  3206.                   class = LOC_LABEL;
  3207.                   break;
  3208.                 default:
  3209.                   unknown_ext_complaint (debug_info->ssext + psh->iss);
  3210.                   /* Fall through, pretend it's global.  */
  3211.                 case stGlobal:
  3212.                   /* Global common symbols are resolved by the runtime loader,
  3213.                      ignore them.  */
  3214.                   if (SC_IS_COMMON (psh->sc))
  3215.                     continue;

  3216.                   class = LOC_STATIC;
  3217.                   break;
  3218.                 }
  3219.               name = debug_info->ssext + psh->iss;
  3220.               add_psymbol_to_list (name, strlen (name), 1,
  3221.                                    VAR_DOMAIN, class,
  3222.                                    &objfile->global_psymbols,
  3223.                                    0, svalue,
  3224.                                    psymtab_language, objfile);
  3225.             }
  3226.         }

  3227.       /* Link pst to FDR.  end_psymtab returns NULL if the psymtab was
  3228.          empty and put on the free list.  */
  3229.       fdr_to_pst[f_idx].pst = end_psymtab (objfile, save_pst,
  3230.                                         psymtab_include_list, includes_used,
  3231.                                            -1, save_pst->texthigh,
  3232.                        dependency_list, dependencies_used, textlow_not_set);
  3233.       includes_used = 0;
  3234.       dependencies_used = 0;

  3235.       /* The objfile has its functions reordered if this partial symbol
  3236.          table overlaps any other partial symbol table.
  3237.          We cannot assume a reordered objfile if a partial symbol table
  3238.          is contained within another partial symbol table, as partial symbol
  3239.          tables for include files with executable code are contained
  3240.          within the partial symbol table for the including source file,
  3241.          and we do not want to flag the objfile reordered for these cases.

  3242.          This strategy works well for Irix-5.2 shared libraries, but we
  3243.          might have to use a more elaborate (and slower) algorithm for
  3244.          other cases.  */
  3245.       save_pst = fdr_to_pst[f_idx].pst;
  3246.       if (save_pst != NULL
  3247.           && save_pst->textlow != 0
  3248.           && !(objfile->flags & OBJF_REORDERED))
  3249.         {
  3250.           ALL_OBJFILE_PSYMTABS (objfile, pst)
  3251.           {
  3252.             if (save_pst != pst
  3253.                 && save_pst->textlow >= pst->textlow
  3254.                 && save_pst->textlow < pst->texthigh
  3255.                 && save_pst->texthigh > pst->texthigh)
  3256.               {
  3257.                 objfile->flags |= OBJF_REORDERED;
  3258.                 break;
  3259.               }
  3260.           }
  3261.         }
  3262.     }

  3263.   /* Now scan the FDRs for dependencies.  */
  3264.   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
  3265.     {
  3266.       fh = f_idx + debug_info->fdr;
  3267.       pst = fdr_to_pst[f_idx].pst;

  3268.       if (pst == (struct partial_symtab *) NULL)
  3269.         continue;

  3270.       /* This should catch stabs-in-ecoff.  */
  3271.       if (fh->crfd <= 1)
  3272.         continue;

  3273.       /* Skip the first file indirect entry as it is a self dependency for
  3274.          source files or a reverse .h -> .c dependency for header files.  */
  3275.       pst->number_of_dependencies = 0;
  3276.       pst->dependencies =
  3277.         ((struct partial_symtab **)
  3278.          obstack_alloc (&objfile->objfile_obstack,
  3279.                         ((fh->crfd - 1)
  3280.                          * sizeof (struct partial_symtab *))));
  3281.       for (s_idx = 1; s_idx < fh->crfd; s_idx++)
  3282.         {
  3283.           RFDT rh;

  3284.           (*swap_rfd_in) (cur_bfd,
  3285.                           ((char *) debug_info->external_rfd
  3286.                            + (fh->rfdBase + s_idx) * external_rfd_size),
  3287.                           &rh);
  3288.           if (rh < 0 || rh >= hdr->ifdMax)
  3289.             {
  3290.               complaint (&symfile_complaints, _("bad file number %ld"), rh);
  3291.               continue;
  3292.             }

  3293.           /* Skip self dependencies of header files.  */
  3294.           if (rh == f_idx)
  3295.             continue;

  3296.           /* Do not add to dependeny list if psymtab was empty.  */
  3297.           if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL)
  3298.             continue;
  3299.           pst->dependencies[pst->number_of_dependencies++]
  3300.             = fdr_to_pst[rh].pst;
  3301.         }
  3302.     }

  3303.   /* Remove the dummy psymtab created for -O3 images above, if it is
  3304.      still empty, to enable the detection of stripped executables.  */
  3305.   if (objfile->psymtabs->next == NULL
  3306.       && objfile->psymtabs->number_of_dependencies == 0
  3307.       && objfile->psymtabs->n_global_syms == 0
  3308.       && objfile->psymtabs->n_static_syms == 0)
  3309.     objfile->psymtabs = NULL;
  3310.   do_cleanups (old_chain);
  3311. }

  3312. /* If the current psymbol has an enumerated type, we need to add
  3313.    all the enum constants to the partial symbol table.  */

  3314. static void
  3315. handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
  3316.                             CORE_ADDR svalue)
  3317. {
  3318.   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
  3319.   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
  3320.   char *ext_sym = ((char *) debug_info->external_sym
  3321.                    + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
  3322.   SYMR sh;
  3323.   TIR tir;

  3324.   switch (stype)
  3325.     {
  3326.     case stEnum:
  3327.       break;

  3328.     case stBlock:
  3329.       /* It is an enumerated type if the next symbol entry is a stMember
  3330.          and its auxiliary index is indexNil or its auxiliary entry
  3331.          is a plain btNil or btVoid.
  3332.          Alpha cc -migrate enums are recognized by a zero index and
  3333.          a zero symbol value.
  3334.          DU 4.0 cc enums are recognized by a member type of btEnum without
  3335.          qualifiers and a zero symbol value.  */
  3336.       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
  3337.       if (sh.st != stMember)
  3338.         return;

  3339.       if (sh.index == indexNil
  3340.           || (sh.index == 0 && svalue == 0))
  3341.         break;
  3342.       (*debug_swap->swap_tir_in) (fh->fBigendian,
  3343.                                   &(debug_info->external_aux
  3344.                                     + fh->iauxBase + sh.index)->a_ti,
  3345.                                   &tir);
  3346.       if ((tir.bt != btNil
  3347.            && tir.bt != btVoid
  3348.            && (tir.bt != btEnum || svalue != 0))
  3349.           || tir.tq0 != tqNil)
  3350.         return;
  3351.       break;

  3352.     default:
  3353.       return;
  3354.     }

  3355.   for (;;)
  3356.     {
  3357.       char *name;

  3358.       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
  3359.       if (sh.st != stMember)
  3360.         break;
  3361.       name = debug_info->ss + cur_fdr->issBase + sh.iss;

  3362.       /* Note that the value doesn't matter for enum constants
  3363.          in psymtabs, just in symtabs.  */
  3364.       add_psymbol_to_list (name, strlen (name), 1,
  3365.                            VAR_DOMAIN, LOC_CONST,
  3366.                            &objfile->static_psymbols, 0,
  3367.                            (CORE_ADDR) 0, psymtab_language, objfile);
  3368.       ext_sym += external_sym_size;
  3369.     }
  3370. }

  3371. /* Get the next symbol.  OBJFILE is unused.  */

  3372. static char *
  3373. mdebug_next_symbol_text (struct objfile *objfile)
  3374. {
  3375.   SYMR sh;

  3376.   cur_sdx++;
  3377.   (*debug_swap->swap_sym_in) (cur_bfd,
  3378.                               ((char *) debug_info->external_sym
  3379.                                + ((cur_fdr->isymBase + cur_sdx)
  3380.                                   * debug_swap->external_sym_size)),
  3381.                               &sh);
  3382.   return debug_info->ss + cur_fdr->issBase + sh.iss;
  3383. }

  3384. /* Ancillary function to psymtab_to_symtab().  Does all the work
  3385.    for turning the partial symtab PST into a symtab, recurring
  3386.    first on all dependent psymtabs.  The argument FILENAME is
  3387.    only passed so we can see in debug stack traces what file
  3388.    is being read.

  3389.    This function has a split personality, based on whether the
  3390.    symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
  3391.    The flow of control and even the memory allocation differs.  FIXME.  */

  3392. static void
  3393. psymtab_to_symtab_1 (struct objfile *objfile,
  3394.                      struct partial_symtab *pst, const char *filename)
  3395. {
  3396.   bfd_size_type external_sym_size;
  3397.   bfd_size_type external_pdr_size;
  3398.   void (*swap_sym_in) (bfd *, void *, SYMR *);
  3399.   void (*swap_pdr_in) (bfd *, void *, PDR *);
  3400.   int i;
  3401.   struct compunit_symtab *cust = NULL;
  3402.   FDR *fh;
  3403.   struct linetable *lines;
  3404.   CORE_ADDR lowest_pdr_addr = 0;
  3405.   int last_symtab_ended = 0;

  3406.   if (pst->readin)
  3407.     return;
  3408.   pst->readin = 1;

  3409.   /* Read in all partial symbtabs on which this one is dependent.
  3410.      NOTE that we do have circular dependencies, sigh.  We solved
  3411.      that by setting pst->readin before this point.  */

  3412.   for (i = 0; i < pst->number_of_dependencies; i++)
  3413.     if (!pst->dependencies[i]->readin)
  3414.       {
  3415.         /* Inform about additional files to be read in.  */
  3416.         if (info_verbose)
  3417.           {
  3418.             fputs_filtered (" ", gdb_stdout);
  3419.             wrap_here ("");
  3420.             fputs_filtered ("and ", gdb_stdout);
  3421.             wrap_here ("");
  3422.             printf_filtered ("%s...",
  3423.                              pst->dependencies[i]->filename);
  3424.             wrap_here ("");        /* Flush output */
  3425.             gdb_flush (gdb_stdout);
  3426.           }
  3427.         /* We only pass the filename for debug purposes.  */
  3428.         psymtab_to_symtab_1 (objfile, pst->dependencies[i],
  3429.                              pst->dependencies[i]->filename);
  3430.       }

  3431.   /* Do nothing if this is a dummy psymtab.  */

  3432.   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
  3433.       && pst->textlow == 0 && pst->texthigh == 0)
  3434.     return;

  3435.   /* Now read the symbols for this symtab.  */

  3436.   cur_bfd = CUR_BFD (pst);
  3437.   debug_swap = DEBUG_SWAP (pst);
  3438.   debug_info = DEBUG_INFO (pst);
  3439.   pending_list = PENDING_LIST (pst);
  3440.   external_sym_size = debug_swap->external_sym_size;
  3441.   external_pdr_size = debug_swap->external_pdr_size;
  3442.   swap_sym_in = debug_swap->swap_sym_in;
  3443.   swap_pdr_in = debug_swap->swap_pdr_in;
  3444.   mdebugread_objfile = objfile;
  3445.   cur_fd = FDR_IDX (pst);
  3446.   fh = ((cur_fd == -1)
  3447.         ? (FDR *) NULL
  3448.         : debug_info->fdr + cur_fd);
  3449.   cur_fdr = fh;

  3450.   /* See comment in parse_partial_symbols about the @stabs sentinel.  */
  3451.   processing_gcc_compilation = 0;
  3452.   if (fh != (FDR *) NULL && fh->csym >= 2)
  3453.     {
  3454.       SYMR sh;

  3455.       (*swap_sym_in) (cur_bfd,
  3456.                       ((char *) debug_info->external_sym
  3457.                        + (fh->isymBase + 1) * external_sym_size),
  3458.                       &sh);
  3459.       if (strcmp (debug_info->ss + fh->issBase + sh.iss,
  3460.                   stabs_symbol) == 0)
  3461.         {
  3462.           /* We indicate that this is a GCC compilation so that certain
  3463.              features will be enabled in stabsread/dbxread.  */
  3464.           processing_gcc_compilation = 2;
  3465.         }
  3466.     }

  3467.   if (processing_gcc_compilation != 0)
  3468.     {
  3469.       struct gdbarch *gdbarch = get_objfile_arch (objfile);

  3470.       /* This symbol table contains stabs-in-ecoff entries.  */

  3471.       /* Parse local symbols first.  */

  3472.       if (fh->csym <= 2)        /* FIXME, this blows psymtab->symtab ptr.  */
  3473.         {
  3474.           mdebugread_objfile = NULL;
  3475.           return;
  3476.         }
  3477.       for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
  3478.         {
  3479.           SYMR sh;
  3480.           char *name;
  3481.           CORE_ADDR valu;

  3482.           (*swap_sym_in) (cur_bfd,
  3483.                           (((char *) debug_info->external_sym)
  3484.                            + (fh->isymBase + cur_sdx) * external_sym_size),
  3485.                           &sh);
  3486.           name = debug_info->ss + fh->issBase + sh.iss;
  3487.           valu = sh.value;
  3488.           /* XXX This is a hack.  It will go away!  */
  3489.           if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
  3490.             {
  3491.               int type_code = ECOFF_UNMARK_STAB (sh.index);

  3492.               /* We should never get non N_STAB symbols here, but they
  3493.                  should be harmless, so keep process_one_symbol from
  3494.                  complaining about them.  */
  3495.               if (type_code & N_STAB)
  3496.                 {
  3497.                   /* If we found a trailing N_SO with no name, process
  3498.                      it here instead of in process_one_symbol, so we
  3499.                      can keep a handle to its symtab.  The symtab
  3500.                      would otherwise be ended twice, once in
  3501.                      process_one_symbol, and once after this loop.  */
  3502.                   if (type_code == N_SO
  3503.                       && get_last_source_file ()
  3504.                       && previous_stab_code != (unsigned char) N_SO
  3505.                       && *name == '\000')
  3506.                     {
  3507.                       valu += ANOFFSET (pst->section_offsets,
  3508.                                         SECT_OFF_TEXT (objfile));
  3509.                       previous_stab_code = N_SO;
  3510.                       cust = end_symtab (valu, SECT_OFF_TEXT (objfile));
  3511.                       end_stabs ();
  3512.                       last_symtab_ended = 1;
  3513.                     }
  3514.                   else
  3515.                     {
  3516.                       last_symtab_ended = 0;
  3517.                       process_one_symbol (type_code, 0, valu, name,
  3518.                                           pst->section_offsets, objfile);
  3519.                     }
  3520.                 }
  3521.               /* Similarly a hack.  */
  3522.               else if (name[0] == '#')
  3523.                 {
  3524.                   process_one_symbol (N_SLINE, 0, valu, name,
  3525.                                       pst->section_offsets, objfile);
  3526.                 }
  3527.               if (type_code == N_FUN)
  3528.                 {
  3529.                   /* Make up special symbol to contain
  3530.                      procedure specific info.  */
  3531.                   struct mdebug_extra_func_info *e =
  3532.                     ((struct mdebug_extra_func_info *)
  3533.                      obstack_alloc (&mdebugread_objfile->objfile_obstack,
  3534.                                     sizeof (struct mdebug_extra_func_info)));
  3535.                   struct symbol *s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);

  3536.                   memset (e, 0, sizeof (struct mdebug_extra_func_info));
  3537.                   SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
  3538.                   SYMBOL_ACLASS_INDEX (s) = LOC_CONST;
  3539.                   SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_void;
  3540.                   SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
  3541.                   e->pdr.framereg = -1;
  3542.                   add_symbol_to_list (s, &local_symbols);
  3543.                 }
  3544.             }
  3545.           else if (sh.st == stLabel)
  3546.             {
  3547.               if (sh.index == indexNil)
  3548.                 {
  3549.                   /* This is what the gcc2_compiled and __gnu_compiled_*
  3550.                      show up as.  So don't complain.  */
  3551.                   ;
  3552.                 }
  3553.               else
  3554.                 {
  3555.                   /* Handle encoded stab line number.  */
  3556.                   valu += ANOFFSET (pst->section_offsets,
  3557.                                     SECT_OFF_TEXT (objfile));
  3558.                   record_line (current_subfile, sh.index,
  3559.                                gdbarch_addr_bits_remove (gdbarch, valu));
  3560.                 }
  3561.             }
  3562.           else if (sh.st == stProc || sh.st == stStaticProc
  3563.                    || sh.st == stStatic || sh.st == stEnd)
  3564.             /* These are generated by gcc-2.x, do not complain.  */
  3565.             ;
  3566.           else
  3567.             complaint (&symfile_complaints,
  3568.                        _("unknown stabs symbol %s"), name);
  3569.         }

  3570.       if (! last_symtab_ended)
  3571.         {
  3572.           cust = end_symtab (pst->texthigh, SECT_OFF_TEXT (objfile));
  3573.           end_stabs ();
  3574.         }

  3575.       /* There used to be a call to sort_blocks here, but this should not
  3576.          be necessary for stabs symtabs.  And as sort_blocks modifies the
  3577.          start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
  3578.          it did the wrong thing if the first procedure in a file was
  3579.          generated via asm statements.  */

  3580.       /* Fill in procedure info next.  */
  3581.       if (fh->cpd > 0)
  3582.         {
  3583.           PDR *pr_block;
  3584.           struct cleanup *old_chain;
  3585.           char *pdr_ptr;
  3586.           char *pdr_end;
  3587.           PDR *pdr_in;
  3588.           PDR *pdr_in_end;

  3589.           pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
  3590.           old_chain = make_cleanup (xfree, pr_block);

  3591.           pdr_ptr = ((char *) debug_info->external_pdr
  3592.                      + fh->ipdFirst * external_pdr_size);
  3593.           pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
  3594.           pdr_in = pr_block;
  3595.           for (;
  3596.                pdr_ptr < pdr_end;
  3597.                pdr_ptr += external_pdr_size, pdr_in++)
  3598.             {
  3599.               (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);

  3600.               /* Determine lowest PDR address, the PDRs are not always
  3601.                  sorted.  */
  3602.               if (pdr_in == pr_block)
  3603.                 lowest_pdr_addr = pdr_in->adr;
  3604.               else if (pdr_in->adr < lowest_pdr_addr)
  3605.                 lowest_pdr_addr = pdr_in->adr;
  3606.             }

  3607.           pdr_in = pr_block;
  3608.           pdr_in_end = pdr_in + fh->cpd;
  3609.           for (; pdr_in < pdr_in_end; pdr_in++)
  3610.             parse_procedure (pdr_in, cust, pst);

  3611.           do_cleanups (old_chain);
  3612.         }
  3613.     }
  3614.   else
  3615.     {
  3616.       /* This symbol table contains ordinary ecoff entries.  */

  3617.       int maxlines, size;
  3618.       EXTR *ext_ptr;

  3619.       if (fh == 0)
  3620.         {
  3621.           maxlines = 0;
  3622.           cust = new_symtab ("unknown", 0, objfile);
  3623.         }
  3624.       else
  3625.         {
  3626.           maxlines = 2 * fh->cline;
  3627.           cust = new_symtab (pst->filename, maxlines, objfile);

  3628.           /* The proper language was already determined when building
  3629.              the psymtab, use it.  */
  3630.           COMPUNIT_FILETABS (cust)->language = PST_PRIVATE (pst)->pst_language;
  3631.         }

  3632.       psymtab_language = COMPUNIT_FILETABS (cust)->language;

  3633.       lines = SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust));

  3634.       /* Get a new lexical context.  */

  3635.       push_parse_stack ();
  3636.       top_stack->cur_st = COMPUNIT_FILETABS (cust);
  3637.       top_stack->cur_block
  3638.         = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
  3639.       BLOCK_START (top_stack->cur_block) = pst->textlow;
  3640.       BLOCK_END (top_stack->cur_block) = 0;
  3641.       top_stack->blocktype = stFile;
  3642.       top_stack->cur_type = 0;
  3643.       top_stack->procadr = 0;
  3644.       top_stack->numargs = 0;
  3645.       found_ecoff_debugging_info = 0;

  3646.       if (fh)
  3647.         {
  3648.           char *sym_ptr;
  3649.           char *sym_end;

  3650.           /* Parse local symbols first.  */
  3651.           sym_ptr = ((char *) debug_info->external_sym
  3652.                      + fh->isymBase * external_sym_size);
  3653.           sym_end = sym_ptr + fh->csym * external_sym_size;
  3654.           while (sym_ptr < sym_end)
  3655.             {
  3656.               SYMR sh;
  3657.               int c;

  3658.               (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
  3659.               c = parse_symbol (&sh,
  3660.                                 debug_info->external_aux + fh->iauxBase,
  3661.                                 sym_ptr, fh->fBigendian,
  3662.                                 pst->section_offsets, objfile);
  3663.               sym_ptr += c * external_sym_size;
  3664.             }

  3665.           /* Linenumbers.  At the end, check if we can save memory.
  3666.              parse_lines has to look ahead an arbitrary number of PDR
  3667.              structures, so we swap them all first.  */
  3668.           if (fh->cpd > 0)
  3669.             {
  3670.               PDR *pr_block;
  3671.               struct cleanup *old_chain;
  3672.               char *pdr_ptr;
  3673.               char *pdr_end;
  3674.               PDR *pdr_in;
  3675.               PDR *pdr_in_end;

  3676.               pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));

  3677.               old_chain = make_cleanup (xfree, pr_block);

  3678.               pdr_ptr = ((char *) debug_info->external_pdr
  3679.                          + fh->ipdFirst * external_pdr_size);
  3680.               pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
  3681.               pdr_in = pr_block;
  3682.               for (;
  3683.                    pdr_ptr < pdr_end;
  3684.                    pdr_ptr += external_pdr_size, pdr_in++)
  3685.                 {
  3686.                   (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);

  3687.                   /* Determine lowest PDR address, the PDRs are not always
  3688.                      sorted.  */
  3689.                   if (pdr_in == pr_block)
  3690.                     lowest_pdr_addr = pdr_in->adr;
  3691.                   else if (pdr_in->adr < lowest_pdr_addr)
  3692.                     lowest_pdr_addr = pdr_in->adr;
  3693.                 }

  3694.               parse_lines (fh, pr_block, lines, maxlines,
  3695.                            pst, lowest_pdr_addr);
  3696.               if (lines->nitems < fh->cline)
  3697.                 lines = shrink_linetable (lines);

  3698.               /* Fill in procedure info next.  */
  3699.               pdr_in = pr_block;
  3700.               pdr_in_end = pdr_in + fh->cpd;
  3701.               for (; pdr_in < pdr_in_end; pdr_in++)
  3702.                 parse_procedure (pdr_in, NULL, pst);

  3703.               do_cleanups (old_chain);
  3704.             }
  3705.         }

  3706.       size = lines->nitems;
  3707.       if (size > 1)
  3708.         --size;
  3709.       SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust))
  3710.         = obstack_copy (&mdebugread_objfile->objfile_obstack,
  3711.                         lines,
  3712.                         (sizeof (struct linetable)
  3713.                          + size * sizeof (lines->item)));
  3714.       xfree (lines);

  3715.       /* .. and our share of externals.
  3716.          XXX use the global list to speed up things here.  How?
  3717.          FIXME, Maybe quit once we have found the right number of ext's?  */
  3718.       top_stack->cur_st = COMPUNIT_FILETABS (cust);
  3719.       top_stack->cur_block
  3720.         = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (top_stack->cur_st),
  3721.                              GLOBAL_BLOCK);
  3722.       top_stack->blocktype = stFile;

  3723.       ext_ptr = PST_PRIVATE (pst)->extern_tab;
  3724.       for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
  3725.         parse_external (ext_ptr, fh->fBigendian,
  3726.                         pst->section_offsets, objfile);

  3727.       /* If there are undefined symbols, tell the user.
  3728.          The alpha has an undefined symbol for every symbol that is
  3729.          from a shared library, so tell the user only if verbose is on.  */
  3730.       if (info_verbose && n_undef_symbols)
  3731.         {
  3732.           printf_filtered (_("File %s contains %d unresolved references:"),
  3733.                            symtab_to_filename_for_display
  3734.                              (COMPUNIT_FILETABS (cust)),
  3735.                            n_undef_symbols);
  3736.           printf_filtered ("\n\t%4d variables\n\t%4d "
  3737.                            "procedures\n\t%4d labels\n",
  3738.                            n_undef_vars, n_undef_procs, n_undef_labels);
  3739.           n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;

  3740.         }
  3741.       pop_parse_stack ();

  3742.       sort_blocks (COMPUNIT_FILETABS (cust));
  3743.     }

  3744.   /* Now link the psymtab and the symtab.  */
  3745.   pst->compunit_symtab = cust;

  3746.   mdebugread_objfile = NULL;
  3747. }

  3748. /* Ancillary parsing procedures.  */

  3749. /* Return 1 if the symbol pointed to by SH has a cross reference
  3750.    to an opaque aggregate type, else 0.  */

  3751. static int
  3752. has_opaque_xref (FDR *fh, SYMR *sh)
  3753. {
  3754.   TIR tir;
  3755.   union aux_ext *ax;
  3756.   RNDXR rn[1];
  3757.   unsigned int rf;

  3758.   if (sh->index == indexNil)
  3759.     return 0;

  3760.   ax = debug_info->external_aux + fh->iauxBase + sh->index;
  3761.   (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
  3762.   if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
  3763.     return 0;

  3764.   ax++;
  3765.   (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
  3766.   if (rn->rfd == 0xfff)
  3767.     rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
  3768.   else
  3769.     rf = rn->rfd;
  3770.   if (rf != -1)
  3771.     return 0;
  3772.   return 1;
  3773. }

  3774. /* Lookup the type at relative index RN.  Return it in TPP
  3775.    if found and in any event come up with its name PNAME.
  3776.    BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
  3777.    Return value says how many aux symbols we ate.  */

  3778. static int
  3779. cross_ref (int fd, union aux_ext *ax, struct type **tpp,
  3780.            enum type_code type_code,
  3781.            /* Use to alloc new type if none is found.  */
  3782.            char **pname, int bigend, char *sym_name)
  3783. {
  3784.   RNDXR rn[1];
  3785.   unsigned int rf;
  3786.   int result = 1;
  3787.   FDR *fh;
  3788.   char *esh;
  3789.   SYMR sh;
  3790.   int xref_fd;
  3791.   struct mdebug_pending *pend;

  3792.   *tpp = (struct type *) NULL;

  3793.   (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);

  3794.   /* Escape index means 'the next one'.  */
  3795.   if (rn->rfd == 0xfff)
  3796.     {
  3797.       result++;
  3798.       rf = AUX_GET_ISYM (bigend, ax + 1);
  3799.     }
  3800.   else
  3801.     {
  3802.       rf = rn->rfd;
  3803.     }

  3804.   /* mips cc uses a rf of -1 for opaque struct definitions.
  3805.      Set TYPE_FLAG_STUB for these types so that check_typedef will
  3806.      resolve them if the struct gets defined in another compilation unit.  */
  3807.   if (rf == -1)
  3808.     {
  3809.       *pname = "<undefined>";
  3810.       *tpp = init_type (type_code, 0, TYPE_FLAG_STUB,
  3811.                         (char *) NULL, mdebugread_objfile);
  3812.       return result;
  3813.     }

  3814.   /* mips cc uses an escaped rn->index of 0 for struct return types
  3815.      of procedures that were compiled without -g.  These will always remain
  3816.      undefined.  */
  3817.   if (rn->rfd == 0xfff && rn->index == 0)
  3818.     {
  3819.       *pname = "<undefined>";
  3820.       return result;
  3821.     }

  3822.   /* Find the relative file descriptor and the symbol in it.  */
  3823.   fh = get_rfd (fd, rf);
  3824.   xref_fd = fh - debug_info->fdr;

  3825.   if (rn->index >= fh->csym)
  3826.     {
  3827.       /* File indirect entry is corrupt.  */
  3828.       *pname = "<illegal>";
  3829.       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
  3830.       return result;
  3831.     }

  3832.   /* If we have processed this symbol then we left a forwarding
  3833.      pointer to the type in the pending list.  If not, we`ll put
  3834.      it in a list of pending types, to be processed later when
  3835.      the file will be.  In any event, we collect the name for the
  3836.      type here.  */

  3837.   esh = ((char *) debug_info->external_sym
  3838.          + ((fh->isymBase + rn->index)
  3839.             * debug_swap->external_sym_size));
  3840.   (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);

  3841.   /* Make sure that this type of cross reference can be handled.  */
  3842.   if ((sh.sc != scInfo
  3843.        || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
  3844.            && sh.st != stStruct && sh.st != stUnion
  3845.            && sh.st != stEnum))
  3846.       && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
  3847.     {
  3848.       /* File indirect entry is corrupt.  */
  3849.       *pname = "<illegal>";
  3850.       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
  3851.       return result;
  3852.     }

  3853.   *pname = debug_info->ss + fh->issBase + sh.iss;

  3854.   pend = is_pending_symbol (fh, esh);
  3855.   if (pend)
  3856.     *tpp = pend->t;
  3857.   else
  3858.     {
  3859.       /* We have not yet seen this type.  */

  3860.       if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
  3861.         {
  3862.           TIR tir;

  3863.           /* alpha cc puts out a stTypedef with a sh.iss of zero for
  3864.              two cases:
  3865.              a) forward declarations of structs/unions/enums which are not
  3866.              defined in this compilation unit.
  3867.              For these the type will be void.  This is a bad design decision
  3868.              as cross referencing across compilation units is impossible
  3869.              due to the missing name.
  3870.              b) forward declarations of structs/unions/enums/typedefs which
  3871.              are defined later in this file or in another file in the same
  3872.              compilation unit.  Irix5 cc uses a stIndirect symbol for this.
  3873.              Simply cross reference those again to get the true type.
  3874.              The forward references are not entered in the pending list and
  3875.              in the symbol table.  */

  3876.           (*debug_swap->swap_tir_in) (bigend,
  3877.                                       &(debug_info->external_aux
  3878.                                         + fh->iauxBase + sh.index)->a_ti,
  3879.                                       &tir);
  3880.           if (tir.tq0 != tqNil)
  3881.             complaint (&symfile_complaints,
  3882.                        _("illegal tq0 in forward typedef for %s"), sym_name);
  3883.           switch (tir.bt)
  3884.             {
  3885.             case btVoid:
  3886.               *tpp = init_type (type_code, 0, 0, (char *) NULL,
  3887.                                 mdebugread_objfile);
  3888.               *pname = "<undefined>";
  3889.               break;

  3890.             case btStruct:
  3891.             case btUnion:
  3892.             case btEnum:
  3893.               cross_ref (xref_fd,
  3894.                          (debug_info->external_aux
  3895.                           + fh->iauxBase + sh.index + 1),
  3896.                          tpp, type_code, pname,
  3897.                          fh->fBigendian, sym_name);
  3898.               break;

  3899.             case btTypedef:
  3900.               /* Follow a forward typedef.  This might recursively
  3901.                  call cross_ref till we get a non typedef'ed type.
  3902.                  FIXME: This is not correct behaviour, but gdb currently
  3903.                  cannot handle typedefs without type copying.  Type
  3904.                  copying is impossible as we might have mutual forward
  3905.                  references between two files and the copied type would not
  3906.                  get filled in when we later parse its definition.  */
  3907.               *tpp = parse_type (xref_fd,
  3908.                                  debug_info->external_aux + fh->iauxBase,
  3909.                                  sh.index,
  3910.                                  (int *) NULL,
  3911.                                  fh->fBigendian,
  3912.                                  debug_info->ss + fh->issBase + sh.iss);
  3913.               add_pending (fh, esh, *tpp);
  3914.               break;

  3915.             default:
  3916.               complaint (&symfile_complaints,
  3917.                          _("illegal bt %d in forward typedef for %s"), tir.bt,
  3918.                          sym_name);
  3919.               *tpp = init_type (type_code, 0, 0, (char *) NULL,
  3920.                                 mdebugread_objfile);
  3921.               break;
  3922.             }
  3923.           return result;
  3924.         }
  3925.       else if (sh.st == stTypedef)
  3926.         {
  3927.           /* Parse the type for a normal typedef.  This might recursively call
  3928.              cross_ref till we get a non typedef'ed type.
  3929.              FIXME: This is not correct behaviour, but gdb currently
  3930.              cannot handle typedefs without type copying.  But type copying is
  3931.              impossible as we might have mutual forward references between
  3932.              two files and the copied type would not get filled in when
  3933.              we later parse its definition.   */
  3934.           *tpp = parse_type (xref_fd,
  3935.                              debug_info->external_aux + fh->iauxBase,
  3936.                              sh.index,
  3937.                              (int *) NULL,
  3938.                              fh->fBigendian,
  3939.                              debug_info->ss + fh->issBase + sh.iss);
  3940.         }
  3941.       else
  3942.         {
  3943.           /* Cross reference to a struct/union/enum which is defined
  3944.              in another file in the same compilation unit but that file
  3945.              has not been parsed yet.
  3946.              Initialize the type only, it will be filled in when
  3947.              it's definition is parsed.  */
  3948.           *tpp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
  3949.         }
  3950.       add_pending (fh, esh, *tpp);
  3951.     }

  3952.   /* We used one auxent normally, two if we got a "next one" rf.  */
  3953.   return result;
  3954. }


  3955. /* Quick&dirty lookup procedure, to avoid the MI ones that require
  3956.    keeping the symtab sorted.  */

  3957. static struct symbol *
  3958. mylookup_symbol (char *name, const struct block *block,
  3959.                  domain_enum domain, enum address_class class)
  3960. {
  3961.   struct block_iterator iter;
  3962.   int inc;
  3963.   struct symbol *sym;

  3964.   inc = name[0];
  3965.   ALL_BLOCK_SYMBOLS (block, iter, sym)
  3966.     {
  3967.       if (SYMBOL_LINKAGE_NAME (sym)[0] == inc
  3968.           && SYMBOL_DOMAIN (sym) == domain
  3969.           && SYMBOL_CLASS (sym) == class
  3970.           && strcmp (SYMBOL_LINKAGE_NAME (sym), name) == 0)
  3971.         return sym;
  3972.     }

  3973.   block = BLOCK_SUPERBLOCK (block);
  3974.   if (block)
  3975.     return mylookup_symbol (name, block, domain, class);
  3976.   return 0;
  3977. }


  3978. /* Add a new symbol S to a block B.  */

  3979. static void
  3980. add_symbol (struct symbol *s, struct symtab *symtab, struct block *b)
  3981. {
  3982.   symbol_set_symtab (s, symtab);
  3983.   dict_add_symbol (BLOCK_DICT (b), s);
  3984. }

  3985. /* Add a new block B to a symtab S.  */

  3986. static void
  3987. add_block (struct block *b, struct symtab *s)
  3988. {
  3989.   /* Cast away "const", but that's ok because we're building the
  3990.      symtab and blockvector here.  */
  3991.   struct blockvector *bv = (struct blockvector *) SYMTAB_BLOCKVECTOR (s);

  3992.   bv = (struct blockvector *) xrealloc ((void *) bv,
  3993.                                         (sizeof (struct blockvector)
  3994.                                          + BLOCKVECTOR_NBLOCKS (bv)
  3995.                                          * sizeof (bv->block)));
  3996.   if (bv != SYMTAB_BLOCKVECTOR (s))
  3997.     SYMTAB_BLOCKVECTOR (s) = bv;

  3998.   BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
  3999. }

  4000. /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
  4001.    MIPS' linenumber encoding might need more than one byte
  4002.    to describe it, LAST is used to detect these continuation lines.

  4003.    Combining lines with the same line number seems like a bad idea.
  4004.    E.g: There could be a line number entry with the same line number after the
  4005.    prologue and GDB should not ignore it (this is a better way to find
  4006.    a prologue than mips_skip_prologue).
  4007.    But due to the compressed line table format there are line number entries
  4008.    for the same line which are needed to bridge the gap to the next
  4009.    line number entry.  These entries have a bogus address info with them
  4010.    and we are unable to tell them from intended duplicate line number
  4011.    entries.
  4012.    This is another reason why -ggdb debugging format is preferable.  */

  4013. static int
  4014. add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
  4015. {
  4016.   /* DEC c89 sometimes produces zero linenos which confuse gdb.
  4017.      Change them to something sensible.  */
  4018.   if (lineno == 0)
  4019.     lineno = 1;
  4020.   if (last == 0)
  4021.     last = -2;                        /* Make sure we record first line.  */

  4022.   if (last == lineno)                /* Skip continuation lines.  */
  4023.     return lineno;

  4024.   lt->item[lt->nitems].line = lineno;
  4025.   lt->item[lt->nitems++].pc = adr << 2;
  4026.   return lineno;
  4027. }

  4028. /* Sorting and reordering procedures.  */

  4029. /* Blocks with a smaller low bound should come first.  */

  4030. static int
  4031. compare_blocks (const void *arg1, const void *arg2)
  4032. {
  4033.   LONGEST addr_diff;
  4034.   struct block **b1 = (struct block **) arg1;
  4035.   struct block **b2 = (struct block **) arg2;

  4036.   addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
  4037.   if (addr_diff == 0)
  4038.     return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
  4039.   return addr_diff;
  4040. }

  4041. /* Sort the blocks of a symtab S.
  4042.    Reorder the blocks in the blockvector by code-address,
  4043.    as required by some MI search routines.  */

  4044. static void
  4045. sort_blocks (struct symtab *s)
  4046. {
  4047.   /* We have to cast away const here, but this is ok because we're
  4048.      constructing the blockvector in this code.  */
  4049.   struct blockvector *bv = (struct blockvector *) SYMTAB_BLOCKVECTOR (s);

  4050.   if (BLOCKVECTOR_NBLOCKS (bv) <= FIRST_LOCAL_BLOCK)
  4051.     {
  4052.       /* Cosmetic */
  4053.       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
  4054.         BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
  4055.       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
  4056.         BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
  4057.       return;
  4058.     }
  4059.   /*
  4060.    * This is very unfortunate: normally all functions are compiled in
  4061.    * the order they are found, but if the file is compiled -O3 things
  4062.    * are very different.  It would be nice to find a reliable test
  4063.    * to detect -O3 images in advance.
  4064.    */
  4065.   if (BLOCKVECTOR_NBLOCKS (bv) > FIRST_LOCAL_BLOCK + 1)
  4066.     qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
  4067.            BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
  4068.            sizeof (struct block *),
  4069.            compare_blocks);

  4070.   {
  4071.     CORE_ADDR high = 0;
  4072.     int i, j = BLOCKVECTOR_NBLOCKS (bv);

  4073.     for (i = FIRST_LOCAL_BLOCK; i < j; i++)
  4074.       if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
  4075.         high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
  4076.     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
  4077.   }

  4078.   BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
  4079.     BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));

  4080.   BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  4081.     BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
  4082.   BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  4083.     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
  4084. }


  4085. /* Constructor/restructor/destructor procedures.  */

  4086. /* Allocate a new symtab for NAME.  Needs an estimate of how many
  4087.    linenumbers MAXLINES we'll put in it.  */

  4088. static struct compunit_symtab *
  4089. new_symtab (const char *name, int maxlines, struct objfile *objfile)
  4090. {
  4091.   struct compunit_symtab *cust = allocate_compunit_symtab (objfile, name);
  4092.   struct symtab *symtab;
  4093.   struct blockvector *bv;

  4094.   add_compunit_symtab_to_objfile (cust);
  4095.   symtab = allocate_symtab (cust, name);

  4096.   SYMTAB_LINETABLE (symtab) = new_linetable (maxlines);

  4097.   /* All symtabs must have at least two blocks.  */
  4098.   bv = new_bvect (2);
  4099.   BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK);
  4100.   BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK);
  4101.   BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  4102.     BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  4103.   COMPUNIT_BLOCKVECTOR (cust) = bv;

  4104.   COMPUNIT_DEBUGFORMAT (cust) = "ECOFF";
  4105.   return cust;
  4106. }

  4107. /* Allocate a new partial_symtab NAME.  */

  4108. static struct partial_symtab *
  4109. new_psymtab (char *name, struct objfile *objfile)
  4110. {
  4111.   struct partial_symtab *psymtab;

  4112.   psymtab = allocate_psymtab (name, objfile);
  4113.   psymtab->section_offsets = objfile->section_offsets;

  4114.   /* Keep a backpointer to the file's symbols.  */

  4115.   psymtab->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
  4116.                                                 sizeof (struct symloc));
  4117.   memset (psymtab->read_symtab_private, 0, sizeof (struct symloc));
  4118.   CUR_BFD (psymtab) = cur_bfd;
  4119.   DEBUG_SWAP (psymtab) = debug_swap;
  4120.   DEBUG_INFO (psymtab) = debug_info;
  4121.   PENDING_LIST (psymtab) = pending_list;

  4122.   /* The way to turn this into a symtab is to call...  */
  4123.   psymtab->read_symtab = mdebug_read_symtab;
  4124.   return (psymtab);
  4125. }


  4126. /* Allocate a linetable array of the given SIZE.  Since the struct
  4127.    already includes one item, we subtract one when calculating the
  4128.    proper size to allocate.  */

  4129. static struct linetable *
  4130. new_linetable (int size)
  4131. {
  4132.   struct linetable *l;

  4133.   if (size > 1)
  4134.     --size;
  4135.   size = size * sizeof (l->item) + sizeof (struct linetable);
  4136.   l = (struct linetable *) xmalloc (size);
  4137.   l->nitems = 0;
  4138.   return l;
  4139. }

  4140. /* Oops, too big.  Shrink it.  This was important with the 2.4 linetables,
  4141.    I am not so sure about the 3.4 ones.

  4142.    Since the struct linetable already includes one item, we subtract one when
  4143.    calculating the proper size to allocate.  */

  4144. static struct linetable *
  4145. shrink_linetable (struct linetable *lt)
  4146. {
  4147.   return (struct linetable *) xrealloc ((void *) lt,
  4148.                                         (sizeof (struct linetable)
  4149.                                          + ((lt->nitems - 1)
  4150.                                             * sizeof (lt->item))));
  4151. }

  4152. /* Allocate and zero a new blockvector of NBLOCKS blocks.  */

  4153. static struct blockvector *
  4154. new_bvect (int nblocks)
  4155. {
  4156.   struct blockvector *bv;
  4157.   int size;

  4158.   size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
  4159.   bv = (struct blockvector *) xzalloc (size);

  4160.   BLOCKVECTOR_NBLOCKS (bv) = nblocks;

  4161.   return bv;
  4162. }

  4163. /* Allocate and zero a new block, and set its BLOCK_DICT.  If function
  4164.    is non-zero, assume the block is associated to a function, and make
  4165.    sure that the symbols are stored linearly; otherwise, store them
  4166.    hashed.  */

  4167. static struct block *
  4168. new_block (enum block_type type)
  4169. {
  4170.   /* FIXME: carlton/2003-09-11: This should use allocate_block to
  4171.      allocate the block.  Which, in turn, suggests that the block
  4172.      should be allocated on an obstack.  */
  4173.   struct block *retval = xzalloc (sizeof (struct block));

  4174.   if (type == FUNCTION_BLOCK)
  4175.     BLOCK_DICT (retval) = dict_create_linear_expandable ();
  4176.   else
  4177.     BLOCK_DICT (retval) = dict_create_hashed_expandable ();

  4178.   return retval;
  4179. }

  4180. /* Create a new symbol with printname NAME.  */

  4181. static struct symbol *
  4182. new_symbol (char *name)
  4183. {
  4184.   struct symbol *s = allocate_symbol (mdebugread_objfile);

  4185.   SYMBOL_SET_LANGUAGE (s, psymtab_language,
  4186.                        &mdebugread_objfile->objfile_obstack);
  4187.   SYMBOL_SET_NAMES (s, name, strlen (name), 1, mdebugread_objfile);
  4188.   return s;
  4189. }

  4190. /* Create a new type with printname NAME.  */

  4191. static struct type *
  4192. new_type (char *name)
  4193. {
  4194.   struct type *t;

  4195.   t = alloc_type (mdebugread_objfile);
  4196.   TYPE_NAME (t) = name;
  4197.   INIT_CPLUS_SPECIFIC (t);
  4198.   return t;
  4199. }

  4200. /* Read ECOFF debugging information from a BFD section.  This is
  4201.    called from elfread.c.  It parses the section into a
  4202.    ecoff_debug_info struct, and then lets the rest of the file handle
  4203.    it as normal.  */

  4204. void
  4205. elfmdebug_build_psymtabs (struct objfile *objfile,
  4206.                           const struct ecoff_debug_swap *swap, asection *sec)
  4207. {
  4208.   bfd *abfd = objfile->obfd;
  4209.   struct ecoff_debug_info *info;
  4210.   struct cleanup *back_to;

  4211.   /* FIXME: It's not clear whether we should be getting minimal symbol
  4212.      information from .mdebug in an ELF file, or whether we will.
  4213.      Re-initialize the minimal symbol reader in case we do.  */

  4214.   init_minimal_symbol_collection ();
  4215.   back_to = make_cleanup_discard_minimal_symbols ();

  4216.   info = ((struct ecoff_debug_info *)
  4217.           obstack_alloc (&objfile->objfile_obstack,
  4218.                          sizeof (struct ecoff_debug_info)));

  4219.   if (!(*swap->read_debug_info) (abfd, sec, info))
  4220.     error (_("Error reading ECOFF debugging information: %s"),
  4221.            bfd_errmsg (bfd_get_error ()));

  4222.   mdebug_build_psymtabs (objfile, swap, info);

  4223.   install_minimal_symbols (objfile);
  4224.   do_cleanups (back_to);
  4225. }

  4226. void
  4227. _initialize_mdebugread (void)
  4228. {
  4229.   basic_type_data = register_objfile_data ();

  4230.   mdebug_register_index
  4231.     = register_symbol_register_impl (LOC_REGISTER, &mdebug_register_funcs);
  4232.   mdebug_regparm_index
  4233.     = register_symbol_register_impl (LOC_REGPARM_ADDR, &mdebug_register_funcs);
  4234. }