home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / mipsread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  88.7 KB  |  3,293 lines

  1. /* Read a symbol table in MIPS' format (Third-Eye).
  2.    Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software
  3.    Foundation, Inc.
  4.    Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU.  Major work
  5.    by Per Bothner, John Gilmore and Ian Lance Taylor at Cygnus Support.
  6.  
  7. This file is part of GDB.
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  22.  
  23. /* This module provides three functions: mipscoff_symfile_init,
  24.    which initializes to read a symbol file; mipscoff_new_init, which
  25.    discards existing cached information when all symbols are being
  26.    discarded; and mipscoff_symfile_read, which reads a symbol table
  27.    from a file.
  28.  
  29.    mipscoff_symfile_read only does the minimum work necessary for letting the
  30.    user "name" things symbolically; it does not read the entire symtab.
  31.    Instead, it reads the external and static symbols and puts them in partial
  32.    symbol tables.  When more extensive information is requested of a
  33.    file, the corresponding partial symbol table is mutated into a full
  34.    fledged symbol table by going back and reading the symbols
  35.    for real.  mipscoff_psymtab_to_symtab() is called indirectly through
  36.    a pointer in the psymtab to do this.
  37.  
  38.    ECOFF symbol tables are mostly written in the byte order of the
  39.    target machine.  However, one section of the table (the auxiliary
  40.    symbol information) is written in the host byte order.  There is a
  41.    bit in the other symbol info which describes which host byte order
  42.    was used.  ECOFF thereby takes the trophy from Intel `b.out' for
  43.    the most brain-dead adaptation of a file format to byte order.
  44.  
  45.    This module can read all four of the known byte-order combinations,
  46.    on any type of host.  */
  47.  
  48. #define    TM_FILE_OVERRIDE
  49. #include "defs.h"
  50. #include "mips/tm-mips.h"
  51. #include "symtab.h"
  52. #include "gdbtypes.h"
  53. #include "gdbcore.h"
  54. #include "symfile.h"
  55. #include "objfiles.h"
  56. #include "obstack.h"
  57. #include "buildsym.h"
  58. #include "stabsread.h"
  59. #include "complaints.h"
  60.  
  61. #ifdef USG
  62. #include <sys/types.h>
  63. #define L_SET 0
  64. #define L_INCR 1
  65. #endif
  66.  
  67. #include <sys/param.h>
  68. #include <sys/file.h>
  69. #include <sys/stat.h>
  70. #include <string.h>
  71.  
  72. #include "gdb-stabs.h"
  73.  
  74. #include "bfd.h"
  75.  
  76. #include "coff/internal.h"
  77. #include "coff/mips.h"        /* COFF-like aspects of ecoff files */
  78. #include "coff/ecoff-ext.h"    /* External forms of ecoff sym structures */
  79.  
  80. /* FIXME: coff/internal.h and aout/aout64.h both define N_ABS.  We
  81.    want the definition from aout/aout64.h.  */
  82. #undef    N_ABS
  83. /* FIXME: coff/mips.h and aout/aout64.h both define ZMAGIC.  We don't
  84.    use it.  */
  85. #undef    ZMAGIC
  86.  
  87. #include "libaout.h"        /* Private BFD a.out information.  */
  88. #include "aout/aout64.h"
  89. #include "aout/stab_gnu.h"    /* STABS information */
  90.  
  91. /* FIXME: libcoff.h and libaout.h both define a couple of macros.  We
  92.    don't use them.  */
  93. #undef exec_hdr
  94. #undef obj_sym_filepos
  95.  
  96. #include "libcoff.h"        /* Private BFD COFF information.  */
  97. #include "libecoff.h"        /* Private BFD ECOFF information.  */
  98.  
  99. #include "expression.h"
  100. #include "language.h"        /* Needed inside partial-stab.h */
  101.  
  102. /* Each partial symbol table entry contains a pointer to private data
  103.    for the read_symtab() function to use when expanding a partial
  104.    symbol table entry to a full symbol table entry.
  105.  
  106.    For mipsread this structure contains the index of the FDR that this
  107.    psymtab represents and a pointer to the BFD that the psymtab was
  108.    created from.  */
  109.  
  110. #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
  111. #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
  112. #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
  113.  
  114. struct symloc
  115. {
  116.   int fdr_idx;
  117.   bfd *cur_bfd;
  118.   EXTR *extern_tab;        /* Pointer to external symbols for this file. */
  119.   int extern_count;        /* Size of extern_tab. */
  120.   struct mips_pending **pending_list;
  121. };
  122.  
  123. /* Things we import explicitly from other modules */
  124.  
  125. extern int info_verbose;
  126.  
  127. /* Various complaints about symbol reading that don't abort the process */
  128.  
  129. struct complaint bad_file_number_complaint =
  130. {"bad file number %d", 0, 0};
  131.  
  132. struct complaint index_complaint =
  133. {"bad aux index at symbol %s", 0, 0};
  134.  
  135. struct complaint aux_index_complaint =
  136. {"bad proc end in aux found from symbol %s", 0, 0};
  137.  
  138. struct complaint block_index_complaint =
  139. {"bad aux index at block symbol %s", 0, 0};
  140.  
  141. struct complaint unknown_ext_complaint =
  142. {"unknown external symbol %s", 0, 0};
  143.  
  144. struct complaint unknown_sym_complaint =
  145. {"unknown local symbol %s", 0, 0};
  146.  
  147. struct complaint unknown_st_complaint =
  148. {"with type %d", 0, 0};
  149.  
  150. struct complaint block_overflow_complaint =
  151. {"block containing %s overfilled", 0, 0};
  152.  
  153. struct complaint basic_type_complaint =
  154. {"cannot map MIPS basic type 0x%x", 0, 0};
  155.  
  156. struct complaint unknown_type_qual_complaint =
  157. {"unknown type qualifier 0x%x", 0, 0};
  158.  
  159. struct complaint array_bitsize_complaint =
  160. {"size of array target type not known, assuming %d bits", 0, 0};
  161.  
  162. struct complaint bad_tag_guess_complaint =
  163. {"guessed tag type of %s incorrectly", 0, 0};
  164.  
  165. struct complaint block_member_complaint =
  166. {"declaration block contains unhandled symbol type %d", 0, 0};
  167.  
  168. struct complaint stEnd_complaint =
  169. {"stEnd with storage class %d not handled", 0, 0};
  170.  
  171. struct complaint unknown_mips_symtype_complaint =
  172. {"unknown symbol type 0x%x", 0, 0};
  173.  
  174. struct complaint stab_unknown_complaint =
  175. {"unknown stabs symbol %s", 0, 0};
  176.  
  177. struct complaint pdr_for_nonsymbol_complaint =
  178. {"PDR for %s, but no symbol", 0, 0};
  179.  
  180. struct complaint pdr_static_symbol_complaint =
  181. {"can't handle PDR for static proc at 0x%x", 0, 0};
  182.  
  183. struct complaint bad_setjmp_pdr_complaint =
  184. {"fixing bad setjmp PDR from libc", 0, 0};
  185.  
  186. /* Macros and extra defs */
  187.  
  188. /* Already-parsed symbols are marked specially */
  189.  
  190. #define stParsed stType
  191.  
  192. /* Puns: hard to find whether -g was used and how */
  193.  
  194. #define MIN_GLEVEL GLEVEL_0
  195. #define compare_glevel(a,b)                    \
  196.     (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) :            \
  197.      ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
  198.  
  199. /* Things that really are local to this module */
  200.  
  201. /* Remember what we deduced to be the source language of this psymtab. */
  202.  
  203. static enum language psymtab_language = language_unknown;
  204.  
  205. /* Current BFD.  */
  206.  
  207. static bfd *cur_bfd;
  208.  
  209. /* Pointer to current file decriptor record, and its index */
  210.  
  211. static FDR *cur_fdr;
  212. static int cur_fd;
  213.  
  214. /* Index of current symbol */
  215.  
  216. static int cur_sdx;
  217.  
  218. /* Note how much "debuggable" this image is.  We would like
  219.    to see at least one FDR with full symbols */
  220.  
  221. static max_gdbinfo;
  222. static max_glevel;
  223.  
  224. /* When examining .o files, report on undefined symbols */
  225.  
  226. static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
  227.  
  228. /* Pseudo symbol to use when putting stabs into the symbol table.  */
  229.  
  230. static char stabs_symbol[] = STABS_SYMBOL;
  231.  
  232. /* Extra builtin types */
  233.  
  234. struct type *builtin_type_complex;
  235. struct type *builtin_type_double_complex;
  236. struct type *builtin_type_fixed_dec;
  237. struct type *builtin_type_float_dec;
  238. struct type *builtin_type_string;
  239.  
  240. /* Forward declarations */
  241.  
  242. static void
  243. read_mips_symtab PARAMS ((struct objfile *, struct section_offsets *));
  244.  
  245. static void
  246. read_the_mips_symtab PARAMS ((bfd *));
  247.  
  248. static int
  249. upgrade_type PARAMS ((struct type **, int, union aux_ext *, int));
  250.  
  251. static void
  252. parse_partial_symbols PARAMS ((struct objfile *,
  253.                    struct section_offsets *));
  254.  
  255. static int
  256. cross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **,
  257.            int));
  258.  
  259. static void
  260. fixup_sigtramp PARAMS ((void));
  261.  
  262. static struct symbol *
  263. new_symbol PARAMS ((char *));
  264.  
  265. static struct type *
  266. new_type PARAMS ((char *));
  267.  
  268. static struct block *
  269. new_block PARAMS ((int));
  270.  
  271. static struct symtab *
  272. new_symtab PARAMS ((char *, int, int, struct objfile *));
  273.  
  274. static struct linetable *
  275. new_linetable PARAMS ((int));
  276.  
  277. static struct blockvector *
  278. new_bvect PARAMS ((int));
  279.  
  280. static struct type *
  281. parse_type PARAMS ((union aux_ext *, int *, int));
  282.  
  283. static struct symbol *
  284. mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
  285.              enum address_class));
  286.  
  287. static struct block *
  288. shrink_block PARAMS ((struct block *, struct symtab *));
  289.  
  290. static PTR
  291. xzalloc PARAMS ((unsigned int));
  292.  
  293. static void
  294. sort_blocks PARAMS ((struct symtab *));
  295.  
  296. static int
  297. compare_blocks PARAMS ((const void *, const void *));
  298.  
  299. static struct partial_symtab *
  300. new_psymtab PARAMS ((char *, struct objfile *));
  301.  
  302. #if 0
  303. static struct partial_symtab *
  304. parse_fdr PARAMS ((int, int, struct objfile *));
  305. #endif
  306.  
  307. static void
  308. psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
  309.  
  310. static void
  311. add_block PARAMS ((struct block *, struct symtab *));
  312.  
  313. static void
  314. add_symbol PARAMS ((struct symbol *, struct block *));
  315.  
  316. static int
  317. add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
  318.  
  319. static struct linetable *
  320. shrink_linetable PARAMS ((struct linetable *));
  321.  
  322. static char *
  323. mips_next_symbol_text PARAMS ((void));
  324.  
  325. /* Things we export to other modules */
  326.  
  327. /* Address bounds for the signal trampoline in inferior, if any */
  328. /* FIXME:  Nothing really seems to use this.  Why is it here? */
  329.  
  330. CORE_ADDR sigtramp_address, sigtramp_end;
  331.  
  332. static void
  333. mipscoff_new_init (ignore)
  334.      struct objfile *ignore;
  335. {
  336.   stabsread_new_init ();
  337.   buildsym_new_init ();
  338. }
  339.  
  340. static void
  341. mipscoff_symfile_init (objfile)
  342.      struct objfile *objfile;
  343. {
  344.   if (objfile->sym_private != NULL)
  345.     {
  346.       mfree (objfile->md, objfile->sym_private);
  347.     }
  348.   objfile->sym_private = NULL;
  349. }
  350.  
  351. static void
  352. mipscoff_symfile_read (objfile, section_offsets, mainline)
  353.      struct objfile *objfile;
  354.      struct section_offsets *section_offsets;
  355.      int mainline;
  356. {
  357.   init_minimal_symbol_collection ();
  358.   make_cleanup (discard_minimal_symbols, 0);
  359.  
  360.   /* Now that the executable file is positioned at symbol table,
  361.      process it and define symbols accordingly.  */
  362.  
  363.   read_mips_symtab (objfile, section_offsets);
  364.  
  365.   /* Install any minimal symbols that have been collected as the current
  366.      minimal symbols for this objfile. */
  367.  
  368.   install_minimal_symbols (objfile);
  369. }
  370.  
  371. /* Perform any local cleanups required when we are done with a particular
  372.    objfile.  I.E, we are in the process of discarding all symbol information
  373.    for an objfile, freeing up all memory held for it, and unlinking the
  374.    objfile struct from the global list of known objfiles. */
  375.  
  376. static void
  377. mipscoff_symfile_finish (objfile)
  378.      struct objfile *objfile;
  379. {
  380.   if (objfile->sym_private != NULL)
  381.     {
  382.       mfree (objfile->md, objfile->sym_private);
  383.     }
  384.  
  385.   cur_bfd = 0;
  386. }
  387.  
  388. /* Allocate zeroed memory */
  389.  
  390. static PTR
  391. xzalloc (size)
  392.      unsigned int size;
  393. {
  394.   PTR p = xmalloc (size);
  395.  
  396.   memset (p, 0, size);
  397.   return p;
  398. }
  399.  
  400. /* Exported procedure: Builds a symtab from the PST partial one.
  401.    Restores the environment in effect when PST was created, delegates
  402.    most of the work to an ancillary procedure, and sorts
  403.    and reorders the symtab list at the end */
  404.  
  405. static void
  406. mipscoff_psymtab_to_symtab (pst)
  407.      struct partial_symtab *pst;
  408. {
  409.  
  410.   if (!pst)
  411.     return;
  412.  
  413.   if (info_verbose)
  414.     {
  415.       printf_filtered ("Reading in symbols for %s...", pst->filename);
  416.       fflush (stdout);
  417.     }
  418.  
  419.   next_symbol_text_func = mips_next_symbol_text;
  420.  
  421.   psymtab_to_symtab_1 (pst, pst->filename);
  422.  
  423.   /* Match with global symbols.  This only needs to be done once,
  424.      after all of the symtabs and dependencies have been read in.   */
  425.   scan_file_globals (pst->objfile);
  426.  
  427.   if (info_verbose)
  428.     printf_filtered ("done.\n");
  429. }
  430.  
  431. /* Exported procedure: Is PC in the signal trampoline code */
  432.  
  433. int
  434. in_sigtramp (pc, ignore)
  435.      CORE_ADDR pc;
  436.      char *ignore;        /* function name */
  437. {
  438.   if (sigtramp_address == 0)
  439.     fixup_sigtramp ();
  440.   return (pc >= sigtramp_address && pc < sigtramp_end);
  441. }
  442.  
  443. /* File-level interface functions */
  444.  
  445. /* Read the symtab information from file ABFD into memory.  */
  446.  
  447. static void
  448. read_the_mips_symtab (abfd)
  449.      bfd *abfd;
  450. {
  451.   if (ecoff_slurp_symbolic_info (abfd) == false)
  452.     error ("Error reading symbol table: %s", bfd_errmsg (bfd_error));
  453. }
  454.  
  455. /* Find a file descriptor given its index RF relative to a file CF */
  456.  
  457. static FDR *
  458. get_rfd (cf, rf)
  459.      int cf, rf;
  460. {
  461.   FDR *fdrs;
  462.   register FDR *f;
  463.   RFDT rfd;
  464.  
  465.   fdrs = ecoff_data (cur_bfd)->fdr;
  466.   f = fdrs + cf;
  467.   /* Object files do not have the RFD table, all refs are absolute */
  468.   if (f->rfdBase == 0)
  469.     return fdrs + rf;
  470.   ecoff_swap_rfd_in (cur_bfd,
  471.              ecoff_data (cur_bfd)->external_rfd + f->rfdBase + rf,
  472.              &rfd);
  473.   return fdrs + rfd;
  474. }
  475.  
  476. /* Return a safer print NAME for a file descriptor */
  477.  
  478. static char *
  479. fdr_name (f)
  480.      FDR *f;
  481. {
  482.   if (f->rss == -1)
  483.     return "<stripped file>";
  484.   if (f->rss == 0)
  485.     return "<NFY>";
  486.   return ecoff_data (cur_bfd)->ss + f->issBase + f->rss;
  487. }
  488.  
  489.  
  490. /* Read in and parse the symtab of the file OBJFILE.  Symbols from
  491.    different sections are relocated via the SECTION_OFFSETS.  */
  492.  
  493. static void
  494. read_mips_symtab (objfile, section_offsets)
  495.      struct objfile *objfile;
  496.      struct section_offsets *section_offsets;
  497. {
  498.   cur_bfd = objfile->obfd;
  499.  
  500.   read_the_mips_symtab (objfile->obfd);
  501.  
  502.   parse_partial_symbols (objfile, section_offsets);
  503.  
  504. #if 0
  505.   /* Check to make sure file was compiled with -g.  If not, warn the
  506.      user of this limitation.  */
  507.   if (compare_glevel (max_glevel, GLEVEL_2) < 0)
  508.     {
  509.       if (max_gdbinfo == 0)
  510.     printf ("\n%s not compiled with -g, debugging support is limited.\n",
  511.          objfile->name);
  512.       printf ("You should compile with -g2 or -g3 for best debugging support.\n");
  513.       fflush (stdout);
  514.     }
  515. #endif
  516. }
  517.  
  518. /* Local utilities */
  519.  
  520. /* Map of FDR indexes to partial symtabs */
  521.  
  522. struct pst_map
  523. {
  524.   struct partial_symtab *pst;    /* the psymtab proper */
  525.   int n_globals;        /* exported globals (external symbols) */
  526.   int globals_offset;        /* cumulative */
  527. };
  528.  
  529.  
  530. /* Utility stack, used to nest procedures and blocks properly.
  531.    It is a doubly linked list, to avoid too many alloc/free.
  532.    Since we might need it quite a few times it is NOT deallocated
  533.    after use. */
  534.  
  535. static struct parse_stack
  536. {
  537.   struct parse_stack *next, *prev;
  538.   struct symtab *cur_st;    /* Current symtab. */
  539.   struct block *cur_block;    /* Block in it. */
  540.   int blocktype;        /* What are we parsing. */
  541.   int maxsyms;            /* Max symbols in this block. */
  542.   struct type *cur_type;    /* Type we parse fields for. */
  543.   int cur_field;        /* Field number in cur_type. */
  544.   int procadr;            /* Start addres of this procedure */
  545.   int numargs;            /* Its argument count */
  546. }
  547.  
  548.  *top_stack;            /* Top stack ptr */
  549.  
  550.  
  551. /* Enter a new lexical context */
  552.  
  553. static void
  554. push_parse_stack ()
  555. {
  556.   struct parse_stack *new;
  557.  
  558.   /* Reuse frames if possible */
  559.   if (top_stack && top_stack->prev)
  560.     new = top_stack->prev;
  561.   else
  562.     new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
  563.   /* Initialize new frame with previous content */
  564.   if (top_stack)
  565.     {
  566.       register struct parse_stack *prev = new->prev;
  567.  
  568.       *new = *top_stack;
  569.       top_stack->prev = new;
  570.       new->prev = prev;
  571.       new->next = top_stack;
  572.     }
  573.   top_stack = new;
  574. }
  575.  
  576. /* Exit a lexical context */
  577.  
  578. static void
  579. pop_parse_stack ()
  580. {
  581.   if (!top_stack)
  582.     return;
  583.   if (top_stack->next)
  584.     top_stack = top_stack->next;
  585. }
  586.  
  587.  
  588. /* Cross-references might be to things we haven't looked at
  589.    yet, e.g. type references.  To avoid too many type
  590.    duplications we keep a quick fixup table, an array
  591.    of lists of references indexed by file descriptor */
  592.  
  593. static struct mips_pending
  594. {
  595.   struct mips_pending *next;    /* link */
  596.   struct sym_ext *s;        /* the symbol */
  597.   struct type *t;        /* its partial type descriptor */
  598. } **pending_list;
  599.  
  600.  
  601. /* Check whether we already saw symbol SH in file FH as undefined */
  602.  
  603. static struct mips_pending *
  604. is_pending_symbol (fh, sh)
  605.      FDR *fh;
  606.      struct sym_ext *sh;
  607. {
  608.   int f_idx = fh - ecoff_data (cur_bfd)->fdr;
  609.   register struct mips_pending *p;
  610.  
  611.   /* Linear search is ok, list is typically no more than 10 deep */
  612.   for (p = pending_list[f_idx]; p; p = p->next)
  613.     if (p->s == sh)
  614.       break;
  615.   return p;
  616. }
  617.  
  618. /* Add a new undef symbol SH of type T */
  619.  
  620. static void
  621. add_pending (fh, sh, t)
  622.      FDR *fh;
  623.      struct sym_ext *sh;
  624.      struct type *t;
  625. {
  626.   int f_idx = fh - ecoff_data (cur_bfd)->fdr;
  627.   struct mips_pending *p = is_pending_symbol (fh, sh);
  628.  
  629.   /* Make sure we do not make duplicates */
  630.   if (!p)
  631.     {
  632.       p = (struct mips_pending *) xmalloc (sizeof (*p));
  633.       p->s = sh;
  634.       p->t = t;
  635.       p->next = pending_list[f_idx];
  636.       pending_list[f_idx] = p;
  637.     }
  638. }
  639.  
  640. /* Throw away undef entries when done with file index F_IDX */
  641. /* FIXME -- storage leak.  This is never called!!!   --gnu */
  642.  
  643. #if 0
  644.  
  645. static void
  646. free_pending (f_idx)
  647.      int f_idx;
  648. {
  649.   register struct mips_pending *p, *q;
  650.  
  651.   for (p = pending_list[f_idx]; p; p = q)
  652.     {
  653.       q = p->next;
  654.       free ((PTR) p);
  655.     }
  656.   pending_list[f_idx] = 0;
  657. }
  658.  
  659. #endif
  660.  
  661. static char *
  662. prepend_tag_kind (tag_name, type_code)
  663.      char *tag_name;
  664.      enum type_code type_code;
  665. {
  666.   char *prefix;
  667.   char *result;
  668.   switch (type_code)
  669.     {
  670.     case TYPE_CODE_ENUM:
  671.       prefix = "enum ";
  672.       break;
  673.     case TYPE_CODE_STRUCT:
  674.       prefix = "struct ";
  675.       break;
  676.     case TYPE_CODE_UNION:
  677.       prefix = "union ";
  678.       break;
  679.     default:
  680.       prefix = "";
  681.     }
  682.  
  683.   result = (char *) obstack_alloc (¤t_objfile->symbol_obstack,
  684.                    strlen (prefix) + strlen (tag_name) + 1);
  685.   sprintf (result, "%s%s", prefix, tag_name);
  686.   return result;
  687. }
  688.  
  689.  
  690. /* Parsing Routines proper. */
  691.  
  692. /* Parse a single symbol. Mostly just make up a GDB symbol for it.
  693.    For blocks, procedures and types we open a new lexical context.
  694.    This is basically just a big switch on the symbol's type.  Argument
  695.    AX is the base pointer of aux symbols for this file (fh->iauxBase).
  696.    EXT_SH points to the unswapped symbol, which is needed for struct,
  697.    union, etc., types; it is NULL for an EXTR.  BIGEND says whether
  698.    aux symbols are big-endian or little-endian.  Return count of
  699.    SYMR's handled (normally one).
  700.  
  701.    FIXME: This modifies the symbol, but the only way we have to save
  702.    the modified information is to stuff it back into the BFD data.  */
  703.  
  704. static int
  705. parse_symbol (sh, ax, ext_sh, bigend)
  706.      SYMR *sh;
  707.      union aux_ext *ax;
  708.      struct sym_ext *ext_sh;
  709.      int bigend;
  710. {
  711.   char *name;
  712.   struct symbol *s;
  713.   struct block *b;
  714.   struct mips_pending *pend;
  715.   struct type *t;
  716.   struct field *f;
  717.   int count = 1;
  718.   enum address_class class;
  719.   TIR tir;
  720.  
  721.   if (ext_sh == (struct sym_ext *) NULL)
  722.     name = ecoff_data (cur_bfd)->ssext + sh->iss;
  723.   else
  724.     name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh->iss;
  725.  
  726.   switch (sh->st)
  727.     {
  728.     case stNil:
  729.       break;
  730.  
  731.     case stGlobal:        /* external symbol, goes into global block */
  732.       class = LOC_STATIC;
  733.       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
  734.                  GLOBAL_BLOCK);
  735.       s = new_symbol (name);
  736.       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
  737.       goto data;
  738.  
  739.     case stStatic:        /* static data, goes into current block. */
  740.       class = LOC_STATIC;
  741.       b = top_stack->cur_block;
  742.       s = new_symbol (name);
  743.       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
  744.       goto data;
  745.  
  746.     case stLocal:        /* local variable, goes into current block */
  747.       if (sh->sc == scRegister)
  748.     {
  749.       class = LOC_REGISTER;
  750.       if (sh->value > 31)
  751.         sh->value += FP0_REGNUM - 32;
  752.     }
  753.       else
  754.     class = LOC_LOCAL;
  755.       b = top_stack->cur_block;
  756.       s = new_symbol (name);
  757.       SYMBOL_VALUE (s) = sh->value;
  758.  
  759.     data:            /* Common code for symbols describing data */
  760.       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
  761.       SYMBOL_CLASS (s) = class;
  762.       add_symbol (s, b);
  763.  
  764.       /* Type could be missing in a number of cases */
  765.       if (sh->sc == scUndefined || sh->sc == scNil ||
  766.       sh->index == 0xfffff)
  767.     SYMBOL_TYPE (s) = builtin_type_int;    /* undefined? */
  768.       else
  769.     SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
  770.       /* Value of a data symbol is its memory address */
  771.       break;
  772.  
  773.     case stParam:        /* arg to procedure, goes into current block */
  774.       max_gdbinfo++;
  775.       top_stack->numargs++;
  776.  
  777.       /* Special GNU C++ name.  */
  778.       if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
  779.     name = "this";        /* FIXME, not alloc'd in obstack */
  780.       s = new_symbol (name);
  781.  
  782.       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
  783.       if (sh->sc == scRegister)
  784.     {
  785.       SYMBOL_CLASS (s) = LOC_REGPARM;
  786.       if (sh->value > 31)
  787.         sh->value += FP0_REGNUM - 32;
  788.     }
  789.       else
  790.     SYMBOL_CLASS (s) = LOC_ARG;
  791.       SYMBOL_VALUE (s) = sh->value;
  792.       SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
  793.       add_symbol (s, top_stack->cur_block);
  794. #if 0
  795.       /* FIXME:  This has not been tested.  See dbxread.c */
  796.       /* Add the type of this parameter to the function/procedure
  797.            type of this block. */
  798.       add_param_to_type (&top_stack->cur_block->function->type, s);
  799. #endif
  800.       break;
  801.  
  802.     case stLabel:        /* label, goes into current block */
  803.       s = new_symbol (name);
  804.       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;    /* so that it can be used */
  805.       SYMBOL_CLASS (s) = LOC_LABEL;    /* but not misused */
  806.       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
  807.       SYMBOL_TYPE (s) = builtin_type_int;
  808.       add_symbol (s, top_stack->cur_block);
  809.       break;
  810.  
  811.     case stProc:        /* Procedure, usually goes into global block */
  812.     case stStaticProc:        /* Static procedure, goes into current block */
  813.       s = new_symbol (name);
  814.       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
  815.       SYMBOL_CLASS (s) = LOC_BLOCK;
  816.       /* Type of the return value */
  817.       if (sh->sc == scUndefined || sh->sc == scNil)
  818.     t = builtin_type_int;
  819.       else
  820.     t = parse_type (ax + sh->index + 1, 0, bigend);
  821.       b = top_stack->cur_block;
  822.       if (sh->st == stProc)
  823.     {
  824.       struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
  825.       /* The next test should normally be true,
  826.                but provides a hook for nested functions
  827.                (which we don't want to make global). */
  828.       if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
  829.         b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  830.     }
  831.       add_symbol (s, b);
  832.  
  833.       /* Make a type for the procedure itself */
  834. #if 0
  835.       /* FIXME:  This has not been tested yet!  See dbxread.c */
  836.       /* Generate a template for the type of this function.  The
  837.      types of the arguments will be added as we read the symbol
  838.      table. */
  839.       bcopy (SYMBOL_TYPE (s), lookup_function_type (t), sizeof (struct type));
  840. #else
  841.       SYMBOL_TYPE (s) = lookup_function_type (t);
  842. #endif
  843.  
  844.       /* Create and enter a new lexical context */
  845.       b = new_block (top_stack->maxsyms);
  846.       SYMBOL_BLOCK_VALUE (s) = b;
  847.       BLOCK_FUNCTION (b) = s;
  848.       BLOCK_START (b) = BLOCK_END (b) = sh->value;
  849.       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  850.       add_block (b, top_stack->cur_st);
  851.  
  852.       /* Not if we only have partial info */
  853.       if (sh->sc == scUndefined || sh->sc == scNil)
  854.     break;
  855.  
  856.       push_parse_stack ();
  857.       top_stack->cur_block = b;
  858.       top_stack->blocktype = sh->st;
  859.       top_stack->cur_type = SYMBOL_TYPE (s);
  860.       top_stack->cur_field = -1;
  861.       top_stack->procadr = sh->value;
  862.       top_stack->numargs = 0;
  863.  
  864.       sh->value = (long) SYMBOL_TYPE (s);
  865.       break;
  866.  
  867.       /* Beginning of code for structure, union, and enum definitions.
  868.            They all share a common set of local variables, defined here.  */
  869.       {
  870.     enum type_code type_code;
  871.     struct sym_ext *ext_tsym;
  872.     int nfields;
  873.     long max_value;
  874.     struct field *f;
  875.  
  876.     case stStruct:        /* Start a block defining a struct type */
  877.     type_code = TYPE_CODE_STRUCT;
  878.     goto structured_common;
  879.  
  880.     case stUnion:        /* Start a block defining a union type */
  881.     type_code = TYPE_CODE_UNION;
  882.     goto structured_common;
  883.  
  884.     case stEnum:        /* Start a block defining an enum type */
  885.     type_code = TYPE_CODE_ENUM;
  886.     goto structured_common;
  887.  
  888.     case stBlock:        /* Either a lexical block, or some type */
  889.     if (sh->sc != scInfo)
  890.       goto case_stBlock_code;    /* Lexical block */
  891.  
  892.     type_code = TYPE_CODE_UNDEF;    /* We have a type.  */
  893.  
  894.     /* Common code for handling struct, union, enum, and/or as-yet-
  895.        unknown-type blocks of info about structured data.  `type_code'
  896.        has been set to the proper TYPE_CODE, if we know it.  */
  897.       structured_common:
  898.     push_parse_stack ();
  899.     top_stack->blocktype = stBlock;
  900.  
  901.     s = new_symbol (name);
  902.     SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
  903.     SYMBOL_CLASS (s) = LOC_TYPEDEF;
  904.     SYMBOL_VALUE (s) = 0;
  905.     add_symbol (s, top_stack->cur_block);
  906.  
  907.     /* First count the number of fields and the highest value. */
  908.     nfields = 0;
  909.     max_value = 0;
  910.     for (ext_tsym = ext_sh + 1; ; ext_tsym++)
  911.       {
  912.         SYMR tsym;
  913.  
  914.         ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym);
  915.  
  916.         if (tsym.st == stEnd)
  917.           break;
  918.  
  919.         if (tsym.st == stMember)
  920.           {
  921.         if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
  922.           /* If the type of the member is Nil (or Void),
  923.              without qualifiers, assume the tag is an
  924.              enumeration. */
  925.           if (tsym.index == indexNil)
  926.             type_code = TYPE_CODE_ENUM;
  927.           else
  928.             {
  929.               ecoff_swap_tir_in (bigend,
  930.                      &ax[tsym.index].a_ti,
  931.                      &tir);
  932.               if ((tir.bt == btNil || tir.bt == btVoid)
  933.               && tir.tq0 == tqNil)
  934.             type_code = TYPE_CODE_ENUM;
  935.             }
  936.         nfields++;
  937.         if (tsym.value > max_value)
  938.           max_value = tsym.value;
  939.           }
  940.         else if (tsym.st == stBlock
  941.              || tsym.st == stUnion
  942.              || tsym.st == stEnum
  943.              || tsym.st == stStruct
  944.              || tsym.st == stParsed)
  945.           {
  946.         if (tsym.sc == scVariant);    /*UNIMPLEMENTED*/
  947.         if (tsym.index != 0)
  948.           {
  949.             /* This is something like a struct within a
  950.                struct.  Skip over the fields of the inner
  951.                struct.  The -1 is because the for loop will
  952.                increment ext_tsym.  */
  953.             ext_tsym = (ecoff_data (cur_bfd)->external_sym
  954.                 + cur_fdr->isymBase
  955.                 + tsym.index
  956.                 - 1);
  957.           }
  958.           }
  959.         else
  960.           complain (&block_member_complaint, tsym.st);
  961.       }
  962.  
  963.     /* In an stBlock, there is no way to distinguish structs,
  964.        unions, and enums at this point.  This is a bug in the
  965.        original design (that has been fixed with the recent
  966.        addition of the stStruct, stUnion, and stEnum symbol
  967.        types.)  The way you can tell is if/when you see a variable
  968.        or field of that type.  In that case the variable's type
  969.        (in the AUX table) says if the type is struct, union, or
  970.        enum, and points back to the stBlock here.  So you can
  971.        patch the tag kind up later - but only if there actually is
  972.        a variable or field of that type.
  973.  
  974.        So until we know for sure, we will guess at this point.
  975.        The heuristic is:
  976.        If the first member has index==indexNil or a void type,
  977.        assume we have an enumeration.
  978.        Otherwise, if there is more than one member, and all
  979.        the members have offset 0, assume we have a union.
  980.        Otherwise, assume we have a struct.
  981.  
  982.        The heuristic could guess wrong in the case of of an
  983.        enumeration with no members or a union with one (or zero)
  984.        members, or when all except the last field of a struct have
  985.        width zero.  These are uncommon and/or illegal situations,
  986.        and in any case guessing wrong probably doesn't matter
  987.        much.
  988.  
  989.        But if we later do find out we were wrong, we fixup the tag
  990.        kind.  Members of an enumeration must be handled
  991.        differently from struct/union fields, and that is harder to
  992.        patch up, but luckily we shouldn't need to.  (If there are
  993.        any enumeration members, we can tell for sure it's an enum
  994.        here.) */
  995.  
  996.     if (type_code == TYPE_CODE_UNDEF)
  997.       if (nfields > 1 && max_value == 0)
  998.         type_code = TYPE_CODE_UNION;
  999.       else
  1000.         type_code = TYPE_CODE_STRUCT;
  1001.  
  1002.     /* If this type was expected, use its partial definition */
  1003.     pend = is_pending_symbol (cur_fdr, ext_sh);
  1004.     if (pend != (struct mips_pending *) NULL)
  1005.       t = pend->t;
  1006.     else
  1007.       t = new_type (prepend_tag_kind (name, type_code));
  1008.  
  1009.     TYPE_CODE (t) = type_code;
  1010.     TYPE_LENGTH (t) = sh->value;
  1011.     TYPE_NFIELDS (t) = nfields;
  1012.     TYPE_FIELDS (t) = f = ((struct field *)
  1013.                    TYPE_ALLOC (t,
  1014.                        nfields * sizeof (struct field)));
  1015.  
  1016.     if (type_code == TYPE_CODE_ENUM)
  1017.       {
  1018.         /* This is a non-empty enum. */
  1019.         for (ext_tsym = ext_sh + 1; ; ext_tsym++)
  1020.           {
  1021.         SYMR tsym;
  1022.         struct symbol *enum_sym;
  1023.  
  1024.         ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym);
  1025.  
  1026.         if (tsym.st != stMember)
  1027.           break;
  1028.  
  1029.         f->bitpos = tsym.value;
  1030.         f->type = t;
  1031.         f->name = (ecoff_data (cur_bfd)->ss
  1032.                + cur_fdr->issBase
  1033.                + tsym.iss);
  1034.         f->bitsize = 0;
  1035.  
  1036.         enum_sym = ((struct symbol *)
  1037.                 obstack_alloc (¤t_objfile->symbol_obstack,
  1038.                        sizeof (struct symbol)));
  1039.         memset ((PTR) enum_sym, 0, sizeof (struct symbol));
  1040.         SYMBOL_NAME (enum_sym) = f->name;
  1041.         SYMBOL_CLASS (enum_sym) = LOC_CONST;
  1042.         SYMBOL_TYPE (enum_sym) = t;
  1043.         SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
  1044.         SYMBOL_VALUE (enum_sym) = tsym.value;
  1045.         add_symbol (enum_sym, top_stack->cur_block);
  1046.  
  1047.         /* Skip the stMembers that we've handled. */
  1048.         count++;
  1049.         f++;
  1050.           }
  1051.       }
  1052.     SYMBOL_TYPE (s) = t;
  1053.     /* make this the current type */
  1054.     top_stack->cur_type = t;
  1055.     top_stack->cur_field = 0;
  1056.     /* Mark that symbol has a type, and say which one */
  1057.     sh->value = (long) t;
  1058.     break;
  1059.  
  1060.     /* End of local variables shared by struct, union, enum, and
  1061.        block (as yet unknown struct/union/enum) processing.  */
  1062.       }
  1063.  
  1064.     case_stBlock_code:
  1065.       /* beginnning of (code) block. Value of symbol
  1066.      is the displacement from procedure start */
  1067.       push_parse_stack ();
  1068.       top_stack->blocktype = stBlock;
  1069.       b = new_block (top_stack->maxsyms);
  1070.       BLOCK_START (b) = sh->value + top_stack->procadr;
  1071.       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  1072.       top_stack->cur_block = b;
  1073.       add_block (b, top_stack->cur_st);
  1074.       break;
  1075.  
  1076.     case stEnd:        /* end (of anything) */
  1077.       if (sh->sc == scInfo)
  1078.     {
  1079.       /* Finished with type */
  1080.       top_stack->cur_type = 0;
  1081.     }
  1082.       else if (sh->sc == scText &&
  1083.            (top_stack->blocktype == stProc ||
  1084.         top_stack->blocktype == stStaticProc))
  1085.     {
  1086.       /* Finished with procedure */
  1087.       struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
  1088.       struct mips_extra_func_info *e;
  1089.       struct block *b;
  1090.       int i;
  1091.  
  1092.       BLOCK_END (top_stack->cur_block) += sh->value;    /* size */
  1093.  
  1094.       /* Make up special symbol to contain procedure specific info */
  1095.       s = new_symbol (MIPS_EFI_SYMBOL_NAME);
  1096.       SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
  1097.       SYMBOL_CLASS (s) = LOC_CONST;
  1098.       SYMBOL_TYPE (s) = builtin_type_void;
  1099.       e = ((struct mips_extra_func_info *)
  1100.            obstack_alloc (¤t_objfile->symbol_obstack,
  1101.                   sizeof (struct mips_extra_func_info)));
  1102.       SYMBOL_VALUE (s) = (int) e;
  1103.       e->numargs = top_stack->numargs;
  1104.       add_symbol (s, top_stack->cur_block);
  1105.  
  1106.       /* Reallocate symbols, saving memory */
  1107.       b = shrink_block (top_stack->cur_block, top_stack->cur_st);
  1108.  
  1109.       /* f77 emits proc-level with address bounds==[0,0],
  1110.          So look for such child blocks, and patch them.  */
  1111.       for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
  1112.         {
  1113.           struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
  1114.           if (BLOCK_SUPERBLOCK (b_bad) == b
  1115.           && BLOCK_START (b_bad) == top_stack->procadr
  1116.           && BLOCK_END (b_bad) == top_stack->procadr)
  1117.         {
  1118.           BLOCK_START (b_bad) = BLOCK_START (b);
  1119.           BLOCK_END (b_bad) = BLOCK_END (b);
  1120.         }
  1121.         }
  1122.     }
  1123.       else if (sh->sc == scText && top_stack->blocktype == stBlock)
  1124.     {
  1125.       /* End of (code) block. The value of the symbol is the
  1126.          displacement from the procedure`s start address of the
  1127.          end of this block. */
  1128.       BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
  1129.       shrink_block (top_stack->cur_block, top_stack->cur_st);
  1130.     }
  1131.       else if (sh->sc == scText && top_stack->blocktype == stFile)
  1132.     {
  1133.       /* End of file.  Pop parse stack and ignore.  Higher
  1134.          level code deals with this.  */
  1135.       ;
  1136.     }
  1137.       else
  1138.     complain (&stEnd_complaint, sh->sc);
  1139.  
  1140.       pop_parse_stack ();    /* restore previous lexical context */
  1141.       break;
  1142.  
  1143.     case stMember:        /* member of struct or union */
  1144.       f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
  1145.       f->name = name;
  1146.       f->bitpos = sh->value;
  1147.       f->bitsize = 0;
  1148.       f->type = parse_type (ax + sh->index, &f->bitsize, bigend);
  1149.       break;
  1150.  
  1151.     case stTypedef:        /* type definition */
  1152.       s = new_symbol (name);
  1153.       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
  1154.       SYMBOL_CLASS (s) = LOC_TYPEDEF;
  1155.       SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
  1156.       add_symbol (s, top_stack->cur_block);
  1157.       SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
  1158.       sh->value = (long) SYMBOL_TYPE (s);
  1159.       break;
  1160.  
  1161.     case stFile:        /* file name */
  1162.       push_parse_stack ();
  1163.       top_stack->blocktype = sh->st;
  1164.       break;
  1165.  
  1166.       /* I`ve never seen these for C */
  1167.     case stRegReloc:
  1168.       break;            /* register relocation */
  1169.     case stForward:
  1170.       break;            /* forwarding address */
  1171.     case stConstant:
  1172.       break;            /* constant */
  1173.     default:
  1174.       complain (&unknown_mips_symtype_complaint, sh->st);
  1175.       break;
  1176.     }
  1177.  
  1178.   sh->st = stParsed;
  1179.  
  1180.   return count;
  1181. }
  1182.  
  1183. /* Parse the type information provided in the raw AX entries for
  1184.    the symbol SH. Return the bitfield size in BS, in case.
  1185.    We must byte-swap the AX entries before we use them; BIGEND says whether
  1186.    they are big-endian or little-endian (from fh->fBigendian).  */
  1187.  
  1188. static struct type *
  1189. parse_type (ax, bs, bigend)
  1190.      union aux_ext *ax;
  1191.      int *bs;
  1192.      int bigend;
  1193. {
  1194.   /* Null entries in this map are treated specially */
  1195.   static struct type **map_bt[] =
  1196.   {
  1197.     &builtin_type_void,        /* btNil */
  1198.     0,                /* btAdr */
  1199.     &builtin_type_char,        /* btChar */
  1200.     &builtin_type_unsigned_char,/* btUChar */
  1201.     &builtin_type_short,    /* btShort */
  1202.     &builtin_type_unsigned_short,    /* btUShort */
  1203.     &builtin_type_int,        /* btInt */
  1204.     &builtin_type_unsigned_int,    /* btUInt */
  1205.     &builtin_type_long,        /* btLong */
  1206.     &builtin_type_unsigned_long,/* btULong */
  1207.     &builtin_type_float,    /* btFloat */
  1208.     &builtin_type_double,    /* btDouble */
  1209.     0,                /* btStruct */
  1210.     0,                /* btUnion */
  1211.     0,                /* btEnum */
  1212.     0,                /* btTypedef */
  1213.     0,                /* btRange */
  1214.     0,                /* btSet */
  1215.     &builtin_type_complex,    /* btComplex */
  1216.     &builtin_type_double_complex,    /* btDComplex */
  1217.     0,                /* btIndirect */
  1218.     &builtin_type_fixed_dec,    /* btFixedDec */
  1219.     &builtin_type_float_dec,    /* btFloatDec */
  1220.     &builtin_type_string,    /* btString */
  1221.     0,                /* btBit */
  1222.     0,                /* btPicture */
  1223.     &builtin_type_void,        /* btVoid */
  1224.     &builtin_type_long_long,    /* btLongLong */
  1225.     &builtin_type_unsigned_long_long,    /* btULongLong */
  1226.   };
  1227.  
  1228.   TIR t[1];
  1229.   struct type *tp = 0;
  1230.   char *fmt;
  1231.   union aux_ext *tax;
  1232.   enum type_code type_code = TYPE_CODE_UNDEF;
  1233.  
  1234.   /* Use aux as a type information record, map its basic type.  */
  1235.   tax = ax;
  1236.   ecoff_swap_tir_in (bigend, &tax->a_ti, t);
  1237.   if (t->bt > (sizeof (map_bt) / sizeof (*map_bt)))
  1238.     {
  1239.       complain (&basic_type_complaint, t->bt);
  1240.       return builtin_type_int;
  1241.     }
  1242.   if (map_bt[t->bt])
  1243.     {
  1244.       tp = *map_bt[t->bt];
  1245.       fmt = "%s";
  1246.     }
  1247.   else
  1248.     {
  1249.       tp = NULL;
  1250.       /* Cannot use builtin types -- build our own */
  1251.       switch (t->bt)
  1252.     {
  1253.     case btAdr:
  1254.       tp = lookup_pointer_type (builtin_type_void);
  1255.       fmt = "%s";
  1256.       break;
  1257.     case btStruct:
  1258.       type_code = TYPE_CODE_STRUCT;
  1259.       fmt = "struct %s";
  1260.       break;
  1261.     case btUnion:
  1262.       type_code = TYPE_CODE_UNION;
  1263.       fmt = "union %s";
  1264.       break;
  1265.     case btEnum:
  1266.       type_code = TYPE_CODE_ENUM;
  1267.       fmt = "enum %s";
  1268.       break;
  1269.     case btRange:
  1270.       type_code = TYPE_CODE_RANGE;
  1271.       fmt = "%s";
  1272.       break;
  1273.     case btSet:
  1274.       type_code = TYPE_CODE_SET;
  1275.       fmt = "set %s";
  1276.       break;
  1277.     case btTypedef:
  1278.     default:
  1279.       complain (&basic_type_complaint, t->bt);
  1280.       return builtin_type_int;
  1281.     }
  1282.     }
  1283.  
  1284.   /* Skip over any further type qualifiers (FIXME).  */
  1285.   if (t->continued)
  1286.     {
  1287.       /* This is the way it would work if the compiler worked */
  1288.       TIR t1[1];
  1289.       do
  1290.     {
  1291.       ax++;
  1292.       ecoff_swap_tir_in (bigend, &ax->a_ti, t1);
  1293.     }
  1294.       while (t1->continued);
  1295.     }
  1296.  
  1297.   /* Move on to next aux */
  1298.   ax++;
  1299.  
  1300.   if (t->fBitfield)
  1301.     {
  1302.       *bs = AUX_GET_WIDTH (bigend, ax);
  1303.       ax++;
  1304.     }
  1305.  
  1306.   /* All these types really point to some (common) MIPS type
  1307.      definition, and only the type-qualifiers fully identify
  1308.      them.  We'll make the same effort at sharing. */
  1309.   if (t->bt == btIndirect ||
  1310.       t->bt == btStruct ||
  1311.       t->bt == btUnion ||
  1312.       t->bt == btEnum ||
  1313.       t->bt == btTypedef ||
  1314.       t->bt == btRange ||
  1315.       t->bt == btSet)
  1316.     {
  1317.       char name[256], *pn;
  1318.  
  1319.       /* Try to cross reference this type */
  1320.       ax += cross_ref (ax, &tp, type_code, &pn, bigend);
  1321.       /* reading .o file ? */
  1322.       if (tp == (struct type *) NULL)
  1323.     tp = init_type (type_code, 0, 0, (char *) NULL,
  1324.             (struct objfile *) NULL);
  1325.       /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
  1326.       sprintf (name, fmt, pn);
  1327.  
  1328.       /* Usually, TYPE_CODE(tp) is already type_code.  The main
  1329.      exception is if we guessed wrong re struct/union/enum. */
  1330.       if (TYPE_CODE (tp) != type_code)
  1331.     {
  1332.       complain (&bad_tag_guess_complaint, name);
  1333.       TYPE_CODE (tp) = type_code;
  1334.     }
  1335.       if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
  1336.     TYPE_NAME (tp) = obsavestring (name, strlen (name),
  1337.                        ¤t_objfile->type_obstack);
  1338.     }
  1339.  
  1340.   /* Deal with range types */
  1341.   if (t->bt == btRange)
  1342.     {
  1343.       TYPE_NFIELDS (tp) = 2;
  1344.       TYPE_FIELDS (tp) = ((struct field *)
  1345.               TYPE_ALLOC (tp, 2 * sizeof (struct field)));
  1346.       TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
  1347.                           ¤t_objfile->type_obstack);
  1348.       TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
  1349.       ax++;
  1350.       TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
  1351.                           ¤t_objfile->type_obstack);
  1352.       TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
  1353.       ax++;
  1354.     }
  1355.  
  1356.   /* Parse all the type qualifiers now. If there are more
  1357.      than 6 the game will continue in the next aux */
  1358.  
  1359. #define PARSE_TQ(tq) \
  1360.     if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
  1361.  
  1362. again:PARSE_TQ (tq0);
  1363.   PARSE_TQ (tq1);
  1364.   PARSE_TQ (tq2);
  1365.   PARSE_TQ (tq3);
  1366.   PARSE_TQ (tq4);
  1367.   PARSE_TQ (tq5);
  1368. #undef    PARSE_TQ
  1369.  
  1370.   if (t->continued)
  1371.     {
  1372.       tax++;
  1373.       ecoff_swap_tir_in (bigend, &tax->a_ti, t);
  1374.       goto again;
  1375.     }
  1376.   return tp;
  1377. }
  1378.  
  1379. /* Make up a complex type from a basic one.  Type is passed by
  1380.    reference in TPP and side-effected as necessary. The type
  1381.    qualifier TQ says how to handle the aux symbols at AX for
  1382.    the symbol SX we are currently analyzing.  BIGEND says whether
  1383.    aux symbols are big-endian or little-endian.
  1384.    Returns the number of aux symbols we parsed. */
  1385.  
  1386. static int
  1387. upgrade_type (tpp, tq, ax, bigend)
  1388.      struct type **tpp;
  1389.      int tq;
  1390.      union aux_ext *ax;
  1391.      int bigend;
  1392. {
  1393.   int off;
  1394.   struct type *t;
  1395.  
  1396.   /* Used in array processing */
  1397.   int rf, id;
  1398.   FDR *fh;
  1399.   struct type *range;
  1400.   struct type *indx;
  1401.   int lower, upper;
  1402.   RNDXR rndx;
  1403.  
  1404.   switch (tq)
  1405.     {
  1406.     case tqPtr:
  1407.       t = lookup_pointer_type (*tpp);
  1408.       *tpp = t;
  1409.       return 0;
  1410.  
  1411.     case tqProc:
  1412.       t = lookup_function_type (*tpp);
  1413.       *tpp = t;
  1414.       return 0;
  1415.  
  1416.     case tqArray:
  1417.       off = 0;
  1418.  
  1419.       /* Determine and record the domain type (type of index) */
  1420.       ecoff_swap_rndx_in (bigend, &ax->a_rndx, &rndx);
  1421.       id = rndx.index;
  1422.       rf = rndx.rfd;
  1423.       if (rf == 0xfff)
  1424.     {
  1425.       ax++;
  1426.       rf = AUX_GET_ISYM (bigend, ax);
  1427.       off++;
  1428.     }
  1429.       fh = get_rfd (cur_fd, rf);
  1430.  
  1431.       indx = parse_type ((ecoff_data (cur_bfd)->external_aux
  1432.               + fh->iauxBase
  1433.               + id),
  1434.              (int *) NULL, bigend);
  1435.  
  1436.       /* Get the bounds, and create the array type.  */
  1437.       ax++;
  1438.       lower = AUX_GET_DNLOW (bigend, ax);
  1439.       ax++;
  1440.       upper = AUX_GET_DNHIGH (bigend, ax);
  1441.       ax++;
  1442.       rf = AUX_GET_WIDTH (bigend, ax);    /* bit size of array element */
  1443.  
  1444.       range = create_range_type ((struct type *) NULL, indx,
  1445.                  lower, upper);
  1446.  
  1447.       t = create_array_type ((struct type *) NULL, *tpp, range);
  1448.  
  1449.       /* Check whether supplied array element bit size matches
  1450.      the known size of the element type.  If this complaint
  1451.      ends up not happening, we can remove this code.  It's
  1452.      here because we aren't sure we understand this *&%&$
  1453.      symbol format.  */
  1454.       id = TYPE_LENGTH (TYPE_TARGET_TYPE (t)) << 3;    /* bitsize */
  1455.       if (id == 0)
  1456.     {
  1457.       /* Most likely an undefined type */
  1458.       id = rf;
  1459.       TYPE_LENGTH (TYPE_TARGET_TYPE (t)) = id >> 3;
  1460.     }
  1461.       if (id != rf)
  1462.     complain (&array_bitsize_complaint, rf);
  1463.  
  1464.       *tpp = t;
  1465.       return 4 + off;
  1466.  
  1467.     case tqVol:
  1468.       /* Volatile -- currently ignored */
  1469.       return 0;
  1470.  
  1471.     case tqConst:
  1472.       /* Const -- currently ignored */
  1473.       return 0;
  1474.  
  1475.     default:
  1476.       complain (&unknown_type_qual_complaint, tq);
  1477.       return 0;
  1478.     }
  1479. }
  1480.  
  1481.  
  1482. /* Parse a procedure descriptor record PR.  Note that the procedure is
  1483.    parsed _after_ the local symbols, now we just insert the extra
  1484.    information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
  1485.    already been placed in the procedure's main block.  Note also that
  1486.    images that have been partially stripped (ld -x) have been deprived
  1487.    of local symbols, and we have to cope with them here.  FIRST_OFF is
  1488.    the offset of the first procedure for this FDR; we adjust the
  1489.    address by this amount, but I don't know why.  */
  1490.  
  1491. static void
  1492. parse_procedure (pr, have_stabs, first_off)
  1493.      PDR *pr;
  1494.      int have_stabs;
  1495.      unsigned long first_off;
  1496. {
  1497.   struct symbol *s, *i;
  1498.   struct block *b;
  1499.   struct mips_extra_func_info *e;
  1500.   char *sh_name;
  1501.  
  1502.   /* Simple rule to find files linked "-x" */
  1503.   if (cur_fdr->rss == -1)
  1504.     {
  1505.       if (pr->isym == -1)
  1506.     {
  1507.       /* Static procedure at address pr->adr.  Sigh. */
  1508.       complain (&pdr_static_symbol_complaint, pr->adr);
  1509.       return;
  1510.     }
  1511.       else
  1512.     {
  1513.       /* external */
  1514.       EXTR she;
  1515.       
  1516.       ecoff_swap_ext_in (cur_bfd,
  1517.                  ecoff_data (cur_bfd)->external_ext + pr->isym,
  1518.                  &she);
  1519.       sh_name = ecoff_data (cur_bfd)->ssext + she.asym.iss;
  1520.     }
  1521.     }
  1522.   else
  1523.     {
  1524.       /* Full symbols */
  1525.       SYMR sh;
  1526.  
  1527.       ecoff_swap_sym_in (cur_bfd,
  1528.              (ecoff_data (cur_bfd)->external_sym
  1529.               + cur_fdr->isymBase
  1530.               + pr->isym),
  1531.              &sh);
  1532.       sh_name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
  1533.     }
  1534.  
  1535.   if (have_stabs)
  1536.     {
  1537.       /* We have to save the cur_fdr across the call to lookup_symbol.
  1538.      If the pdr is for a static function and if a global function with
  1539.      the same name exists, lookup_symbol will eventually read in the symtab
  1540.      for the global function and clobber cur_fdr.  */
  1541.       FDR *save_cur_fdr = cur_fdr;
  1542.       s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
  1543.       cur_fdr = save_cur_fdr;
  1544.     }
  1545.   else
  1546.     s = mylookup_symbol (sh_name, top_stack->cur_block,
  1547.              VAR_NAMESPACE, LOC_BLOCK);
  1548.  
  1549.   if (s != 0)
  1550.     {
  1551.       b = SYMBOL_BLOCK_VALUE (s);
  1552.     }
  1553.   else
  1554.     {
  1555.       complain (&pdr_for_nonsymbol_complaint, sh_name);
  1556. #if 1
  1557.       return;
  1558. #else
  1559. /* FIXME -- delete.  We can't do symbol allocation now; it's all done.  */
  1560.       s = new_symbol (sh_name);
  1561.       SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
  1562.       SYMBOL_CLASS (s) = LOC_BLOCK;
  1563.       /* Donno its type, hope int is ok */
  1564.       SYMBOL_TYPE (s) = lookup_function_type (builtin_type_int);
  1565.       add_symbol (s, top_stack->cur_block);
  1566.       /* Wont have symbols for this one */
  1567.       b = new_block (2);
  1568.       SYMBOL_BLOCK_VALUE (s) = b;
  1569.       BLOCK_FUNCTION (b) = s;
  1570.       BLOCK_START (b) = pr->adr;
  1571.       /* BOUND used to be the end of procedure's text, but the
  1572.      argument is no longer passed in.  */
  1573.       BLOCK_END (b) = bound;
  1574.       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  1575.       add_block (b, top_stack->cur_st);
  1576. #endif
  1577.     }
  1578.  
  1579.   i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
  1580.  
  1581.   if (i)
  1582.     {
  1583.       e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
  1584.       e->pdr = *pr;
  1585.       e->pdr.isym = (long) s;
  1586.       e->pdr.adr += cur_fdr->adr - first_off;
  1587.  
  1588.       /* Correct incorrect setjmp procedure descriptor from the library
  1589.      to make backtrace through setjmp work.  */
  1590.       if (e->pdr.pcreg == 0 && strcmp (sh_name, "setjmp") == 0)
  1591.     {
  1592.       complain (&bad_setjmp_pdr_complaint, 0);
  1593.       e->pdr.pcreg = RA_REGNUM;
  1594.       e->pdr.regmask = 0x80000000;
  1595.       e->pdr.regoffset = -4;
  1596.     }
  1597.     }
  1598. }
  1599.  
  1600. /* Parse the external symbol ES. Just call parse_symbol() after
  1601.    making sure we know where the aux are for it. For procedures,
  1602.    parsing of the PDRs has already provided all the needed
  1603.    information, we only parse them if SKIP_PROCEDURES is false,
  1604.    and only if this causes no symbol duplication.
  1605.    BIGEND says whether aux entries are big-endian or little-endian.
  1606.  
  1607.    This routine clobbers top_stack->cur_block and ->cur_st. */
  1608.  
  1609. static void
  1610. parse_external (es, skip_procedures, bigend)
  1611.      EXTR *es;
  1612.      int skip_procedures;
  1613.      int bigend;
  1614. {
  1615.   union aux_ext *ax;
  1616.  
  1617.   if (es->ifd != ifdNil)
  1618.     {
  1619.       cur_fd = es->ifd;
  1620.       cur_fdr = ecoff_data (cur_bfd)->fdr + cur_fd;
  1621.       ax = ecoff_data (cur_bfd)->external_aux + cur_fdr->iauxBase;
  1622.     }
  1623.   else
  1624.     {
  1625.       cur_fdr = ecoff_data (cur_bfd)->fdr;
  1626.       ax = 0;
  1627.     }
  1628.  
  1629.   /* Reading .o files */
  1630.   if (es->asym.sc == scUndefined || es->asym.sc == scNil)
  1631.     {
  1632.       char *what;
  1633.       switch (es->asym.st)
  1634.     {
  1635.     case stStaticProc:
  1636.     case stProc:
  1637.       what = "procedure";
  1638.       n_undef_procs++;
  1639.       break;
  1640.     case stGlobal:
  1641.       what = "variable";
  1642.       n_undef_vars++;
  1643.       break;
  1644.     case stLabel:
  1645.       what = "label";
  1646.       n_undef_labels++;
  1647.       break;
  1648.     default:
  1649.       what = "symbol";
  1650.       break;
  1651.     }
  1652.       n_undef_symbols++;
  1653.       /* FIXME:  Turn this into a complaint? */
  1654.       if (info_verbose)
  1655.     printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
  1656.              what,
  1657.              ecoff_data (cur_bfd)->ssext + es->asym.iss,
  1658.              fdr_name (cur_fdr));
  1659.       return;
  1660.     }
  1661.  
  1662.   switch (es->asym.st)
  1663.     {
  1664.     case stProc:
  1665.       /* If we have full symbols we do not need more */
  1666.       if (skip_procedures)
  1667.     return;
  1668.       if (mylookup_symbol (ecoff_data (cur_bfd)->ssext + es->asym.iss,
  1669.                top_stack->cur_block,
  1670.                VAR_NAMESPACE, LOC_BLOCK))
  1671.     break;
  1672.       /* fall through */
  1673.     case stGlobal:
  1674.     case stLabel:
  1675.       /* Note that the case of a symbol with indexNil must be handled
  1676.      anyways by parse_symbol().  */
  1677.       parse_symbol (&es->asym, ax, (struct sym_ext *) NULL, bigend);
  1678.       /* Note that parse_symbol changed es->asym.  */
  1679.       break;
  1680.     default:
  1681.       break;
  1682.     }
  1683. }
  1684.  
  1685. /* Parse the line number info for file descriptor FH into
  1686.    GDB's linetable LT.  MIPS' encoding requires a little bit
  1687.    of magic to get things out.  Note also that MIPS' line
  1688.    numbers can go back and forth, apparently we can live
  1689.    with that and do not need to reorder our linetables */
  1690.  
  1691. static void
  1692. parse_lines (fh, pr, lt)
  1693.      FDR *fh;
  1694.      PDR *pr;
  1695.      struct linetable *lt;
  1696. {
  1697.   unsigned char *base;
  1698.   int j, k;
  1699.   int delta, count, lineno = 0;
  1700.   unsigned long first_off = pr->adr;
  1701.  
  1702.   if (fh->cbLineOffset == 0)
  1703.     return;
  1704.  
  1705.   base = ecoff_data (cur_bfd)->line + fh->cbLineOffset;
  1706.  
  1707.   /* Scan by procedure descriptors */
  1708.   k = 0;
  1709.   for (j = 0; j < fh->cpd; j++, pr++)
  1710.     {
  1711.       int l, halt;
  1712.       unsigned long adr;
  1713.  
  1714.       /* No code for this one */
  1715.       if (pr->iline == ilineNil ||
  1716.       pr->lnLow == -1 || pr->lnHigh == -1)
  1717.     continue;
  1718.  
  1719.       /* Aurgh! To know where to stop expanding we must look-ahead.  */
  1720.       for (l = 1; l < (fh->cpd - j); l++)
  1721.     if (pr[l].iline != -1)
  1722.       break;
  1723.       if (l == (fh->cpd - j))
  1724.     halt = fh->cline;
  1725.       else
  1726.     halt = pr[l].iline;
  1727.  
  1728.       /* When procedures are moved around the linenumbers are
  1729.      attributed to the next procedure up.  */
  1730.       if (pr->iline >= halt)
  1731.     continue;
  1732.  
  1733.       base = ecoff_data (cur_bfd)->line + fh->cbLineOffset + pr->cbLineOffset;
  1734.       adr = fh->adr + pr->adr - first_off;
  1735.       l = adr >> 2;        /* in words */
  1736.       halt += (adr >> 2) - pr->iline;
  1737.       for (lineno = pr->lnLow; l < halt;)
  1738.     {
  1739.       count = *base & 0x0f;
  1740.       delta = *base++ >> 4;
  1741.       if (delta >= 8)
  1742.         delta -= 16;
  1743.       if (delta == -8)
  1744.         {
  1745.           delta = (base[0] << 8) | base[1];
  1746.           if (delta >= 0x8000)
  1747.         delta -= 0x10000;
  1748.           base += 2;
  1749.         }
  1750.       lineno += delta;    /* first delta is 0 */
  1751.       k = add_line (lt, lineno, l, k);
  1752.       l += count + 1;
  1753.     }
  1754.     }
  1755. }
  1756.  
  1757. /* Master parsing procedure for first-pass reading of file symbols
  1758.    into a partial_symtab.  */
  1759.  
  1760. static void
  1761. parse_partial_symbols (objfile, section_offsets)
  1762.      struct objfile *objfile;
  1763.      struct section_offsets *section_offsets;
  1764. {
  1765.   int f_idx, s_idx;
  1766.   HDRR *hdr = &ecoff_data (cur_bfd)->symbolic_header;
  1767.   /* Running pointers */
  1768.   FDR *fh;
  1769.   struct ext_ext *ext_out;
  1770.   struct ext_ext *ext_out_end;
  1771.   EXTR *ext_block;
  1772.   register EXTR *ext_in;
  1773.   EXTR *ext_in_end;
  1774.   SYMR sh;
  1775.   struct partial_symtab *pst;
  1776.  
  1777.   int past_first_source_file = 0;
  1778.  
  1779.   /* List of current psymtab's include files */
  1780.   char **psymtab_include_list;
  1781.   int includes_allocated;
  1782.   int includes_used;
  1783.   EXTR *extern_tab;
  1784.   struct pst_map *fdr_to_pst;
  1785.   /* Index within current psymtab dependency list */
  1786.   struct partial_symtab **dependency_list;
  1787.   int dependencies_used, dependencies_allocated;
  1788.   struct cleanup *old_chain;
  1789.   char *name;
  1790.  
  1791.   extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
  1792.                        sizeof (EXTR) * hdr->iextMax);
  1793.  
  1794.   includes_allocated = 30;
  1795.   includes_used = 0;
  1796.   psymtab_include_list = (char **) alloca (includes_allocated *
  1797.                        sizeof (char *));
  1798.   next_symbol_text_func = mips_next_symbol_text;
  1799.  
  1800.   dependencies_allocated = 30;
  1801.   dependencies_used = 0;
  1802.   dependency_list =
  1803.     (struct partial_symtab **) alloca (dependencies_allocated *
  1804.                        sizeof (struct partial_symtab *));
  1805.  
  1806.   last_source_file = NULL;
  1807.  
  1808.   /*
  1809.    * Big plan:
  1810.    *
  1811.    * Only parse the Local and External symbols, and the Relative FDR.
  1812.    * Fixup enough of the loader symtab to be able to use it.
  1813.    * Allocate space only for the file's portions we need to
  1814.    * look at. (XXX)
  1815.    */
  1816.  
  1817.   max_gdbinfo = 0;
  1818.   max_glevel = MIN_GLEVEL;
  1819.  
  1820.   /* Allocate the map FDR -> PST.
  1821.      Minor hack: -O3 images might claim some global data belongs
  1822.      to FDR -1. We`ll go along with that */
  1823.   fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
  1824.   old_chain = make_cleanup (free, fdr_to_pst);
  1825.   fdr_to_pst++;
  1826.   {
  1827.     struct partial_symtab *pst = new_psymtab ("", objfile);
  1828.     fdr_to_pst[-1].pst = pst;
  1829.     FDR_IDX (pst) = -1;
  1830.   }
  1831.  
  1832.   /* Pass 0 over external syms: swap them in.  */
  1833.   ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
  1834.   make_cleanup (free, ext_block);
  1835.  
  1836.   ext_out = ecoff_data (cur_bfd)->external_ext;
  1837.   ext_out_end = ext_out + hdr->iextMax;
  1838.   ext_in = ext_block;
  1839.   for (; ext_out < ext_out_end; ext_out++, ext_in++)
  1840.     ecoff_swap_ext_in (cur_bfd, ext_out, ext_in);
  1841.  
  1842.   /* Pass 1 over external syms: Presize and partition the list */
  1843.   ext_in = ext_block;
  1844.   ext_in_end = ext_in + hdr->iextMax;
  1845.   for (; ext_in < ext_in_end; ext_in++)
  1846.     fdr_to_pst[ext_in->ifd].n_globals++;
  1847.  
  1848.   /* Pass 1.5 over files:  partition out global symbol space */
  1849.   s_idx = 0;
  1850.   for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
  1851.     {
  1852.       fdr_to_pst[f_idx].globals_offset = s_idx;
  1853.       s_idx += fdr_to_pst[f_idx].n_globals;
  1854.       fdr_to_pst[f_idx].n_globals = 0;
  1855.     }
  1856.  
  1857.   /* Pass 2 over external syms: fill in external symbols */
  1858.   ext_in = ext_block;
  1859.   ext_in_end = ext_in + hdr->iextMax;
  1860.   for (; ext_in < ext_in_end; ext_in++)
  1861.     {
  1862.       enum minimal_symbol_type ms_type = mst_text;
  1863.  
  1864.       extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
  1865.          + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
  1866.  
  1867.       if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scNil)
  1868.     continue;
  1869.  
  1870.       name = ecoff_data (cur_bfd)->ssext + ext_in->asym.iss;
  1871.       switch (ext_in->asym.st)
  1872.     {
  1873.     case stProc:
  1874.       break;
  1875.     case stGlobal:
  1876.       ms_type = mst_data;
  1877.       break;
  1878.     case stLabel:
  1879.       break;
  1880.     default:
  1881.       ms_type = mst_unknown;
  1882.       complain (&unknown_ext_complaint, name);
  1883.     }
  1884.       prim_record_minimal_symbol (name, ext_in->asym.value, ms_type);
  1885.     }
  1886.  
  1887.   /* Pass 3 over files, over local syms: fill in static symbols */
  1888.   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
  1889.     {
  1890.       struct partial_symtab *save_pst;
  1891.       EXTR *ext_ptr;
  1892.  
  1893.       cur_fdr = fh = ecoff_data (cur_bfd)->fdr + f_idx;
  1894.  
  1895.       if (fh->csym == 0)
  1896.     {
  1897.       fdr_to_pst[f_idx].pst = NULL;
  1898.       continue;
  1899.     }
  1900.       pst = start_psymtab_common (objfile, section_offsets,
  1901.                   fdr_name (fh),
  1902.                   fh->cpd ? fh->adr : 0,
  1903.                   objfile->global_psymbols.next,
  1904.                   objfile->static_psymbols.next);
  1905.       pst->read_symtab_private = ((char *)
  1906.                   obstack_alloc (&objfile->psymbol_obstack,
  1907.                          sizeof (struct symloc)));
  1908.       memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
  1909.  
  1910.       save_pst = pst;
  1911.       /* Make everything point to everything. */
  1912.       FDR_IDX (pst) = f_idx;
  1913.       fdr_to_pst[f_idx].pst = pst;
  1914.  
  1915.       /* FIXME: This tampers with data from BFD.  */
  1916.       fh->ioptBase = (int) pst;
  1917.  
  1918.       CUR_BFD (pst) = cur_bfd;
  1919.  
  1920.       /* The way to turn this into a symtab is to call... */
  1921.       pst->read_symtab = mipscoff_psymtab_to_symtab;
  1922.  
  1923.       pst->texthigh = pst->textlow;
  1924.  
  1925.       /* For stabs-in-ecoff files, the second symbol must be @stab.
  1926.      This symbol is emitted by mips-tfile to signal that the
  1927.      current object file uses encapsulated stabs instead of mips
  1928.      ecoff for local symbols.  (It is the second symbol because
  1929.      the first symbol is the stFile used to signal the start of a
  1930.      file). */
  1931.       processing_gcc_compilation = 0;
  1932.       if (fh->csym >= 2)
  1933.     {
  1934.       ecoff_swap_sym_in (cur_bfd,
  1935.                  (ecoff_data (cur_bfd)->external_sym
  1936.                   + fh->isymBase
  1937.                   + 1),
  1938.                  &sh);
  1939.       if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
  1940.              stabs_symbol))
  1941.         processing_gcc_compilation = 2;
  1942.     }
  1943.  
  1944.       if (processing_gcc_compilation != 0)
  1945.     {
  1946.       for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
  1947.         {
  1948.           int type_code;
  1949.           char *namestring;
  1950.  
  1951.           ecoff_swap_sym_in (cur_bfd,
  1952.                  (ecoff_data (cur_bfd)->external_sym
  1953.                   + fh->isymBase
  1954.                   + cur_sdx),
  1955.                  &sh);
  1956.           type_code = MIPS_UNMARK_STAB (sh.index);
  1957.           if (!MIPS_IS_STAB (&sh))
  1958.         {
  1959.           if (sh.st == stProc || sh.st == stStaticProc)
  1960.             {
  1961.               long procaddr = sh.value;
  1962.               long isym;
  1963.  
  1964.  
  1965.               isym = AUX_GET_ISYM (fh->fBigendian,
  1966.                        (ecoff_data (cur_bfd)->external_aux
  1967.                         + fh->iauxBase
  1968.                         + sh.index));
  1969.               ecoff_swap_sym_in (cur_bfd,
  1970.                      (ecoff_data (cur_bfd)->external_sym
  1971.                       + fh->isymBase
  1972.                       + isym
  1973.                       - 1),
  1974.                      &sh);
  1975.               if (sh.st == stEnd)
  1976.             {
  1977.               long high = procaddr + sh.value;
  1978.               if (high > pst->texthigh)
  1979.                 pst->texthigh = high;
  1980.             }
  1981.             }
  1982.           continue;
  1983.         }
  1984. #define SET_NAMESTRING() \
  1985.   namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
  1986. #define CUR_SYMBOL_TYPE type_code
  1987. #define CUR_SYMBOL_VALUE sh.value
  1988. #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
  1989.   pst = save_pst
  1990. #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
  1991. #define HANDLE_RBRAC(val) \
  1992.   if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
  1993. #include "partial-stab.h"
  1994.         }
  1995.     }
  1996.       else
  1997.     {
  1998.       for (cur_sdx = 0; cur_sdx < fh->csym;)
  1999.         {
  2000.           char *name;
  2001.           enum address_class class;
  2002.  
  2003.           ecoff_swap_sym_in (cur_bfd,
  2004.                  (ecoff_data (cur_bfd)->external_sym
  2005.                   + fh->isymBase
  2006.                   + cur_sdx),
  2007.                  &sh);
  2008.  
  2009.           if (MIPS_IS_STAB (&sh))
  2010.         {
  2011.           cur_sdx++;
  2012.           continue;
  2013.         }
  2014.  
  2015.           if (sh.sc == scUndefined || sh.sc == scNil ||
  2016.           sh.index == 0xfffff)
  2017.         {
  2018.           /* FIXME, premature? */
  2019.           cur_sdx++;
  2020.           continue;
  2021.         }
  2022.  
  2023.           name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
  2024.  
  2025.           switch (sh.st)
  2026.         {
  2027.           long high;
  2028.           long procaddr;
  2029.           int new_sdx;
  2030.  
  2031.         case stProc:    /* Asm labels apparently */
  2032.         case stStaticProc:    /* Function */
  2033.           ADD_PSYMBOL_TO_LIST (name, strlen (name),
  2034.                        VAR_NAMESPACE, LOC_BLOCK,
  2035.                        objfile->static_psymbols, sh.value,
  2036.                        psymtab_language, objfile);
  2037.           /* Skip over procedure to next one. */
  2038.           if (sh.index >= hdr->iauxMax)
  2039.             {
  2040.               /* Should not happen, but does when cross-compiling
  2041.                with the MIPS compiler.  FIXME -- pull later.  */
  2042.               complain (&index_complaint, name);
  2043.               new_sdx = cur_sdx + 1;    /* Don't skip at all */
  2044.             }
  2045.           else
  2046.             new_sdx = AUX_GET_ISYM (fh->fBigendian,
  2047.                         (ecoff_data (cur_bfd)->external_aux
  2048.                          + fh->iauxBase
  2049.                          + sh.index));
  2050.           procaddr = sh.value;
  2051.  
  2052.           if (new_sdx <= cur_sdx)
  2053.             {
  2054.               /* This should not happen either... FIXME.  */
  2055.               complain (&aux_index_complaint, name);
  2056.               new_sdx = cur_sdx + 1;    /* Don't skip backward */
  2057.             }
  2058.  
  2059.           cur_sdx = new_sdx;
  2060.           ecoff_swap_sym_in (cur_bfd,
  2061.                      (ecoff_data (cur_bfd)->external_sym
  2062.                       + fh->isymBase
  2063.                       + cur_sdx
  2064.                       - 1),
  2065.                      &sh);
  2066.           if (sh.st != stEnd)
  2067.             continue;
  2068.           high = procaddr + sh.value;
  2069.           if (high > pst->texthigh)
  2070.             pst->texthigh = high;
  2071.           continue;
  2072.  
  2073.         case stStatic:    /* Variable */
  2074.           class = LOC_STATIC;
  2075.           break;
  2076.  
  2077.         case stTypedef:/* Typedef */
  2078.           class = LOC_TYPEDEF;
  2079.           break;
  2080.  
  2081.         case stConstant:    /* Constant decl */
  2082.           class = LOC_CONST;
  2083.           break;
  2084.  
  2085.         case stUnion:
  2086.         case stStruct:
  2087.         case stEnum:
  2088.         case stBlock:    /* { }, str, un, enum*/
  2089.           if (sh.sc == scInfo)
  2090.             {
  2091.               ADD_PSYMBOL_TO_LIST (name, strlen (name),
  2092.                        STRUCT_NAMESPACE, LOC_TYPEDEF,
  2093.                        objfile->static_psymbols,
  2094.                        sh.value,
  2095.                        psymtab_language, objfile);
  2096.             }
  2097.           /* Skip over the block */
  2098.           new_sdx = sh.index;
  2099.           if (new_sdx <= cur_sdx)
  2100.             {
  2101.               /* This happens with the Ultrix kernel. */
  2102.               complain (&block_index_complaint, name);
  2103.               new_sdx = cur_sdx + 1;    /* Don't skip backward */
  2104.             }
  2105.           cur_sdx = new_sdx;
  2106.           continue;
  2107.  
  2108.         case stFile:    /* File headers */
  2109.         case stLabel:    /* Labels */
  2110.         case stEnd:    /* Ends of files */
  2111.           goto skip;
  2112.  
  2113.         case stLocal:    /* Local variables */
  2114.           /* Normally these are skipped because we skip over
  2115.              all blocks we see.  However, these can occur
  2116.              as visible symbols in a .h file that contains code. */
  2117.           goto skip;
  2118.  
  2119.         default:
  2120.           /* Both complaints are valid:  one gives symbol name,
  2121.              the other the offending symbol type.  */
  2122.           complain (&unknown_sym_complaint, name);
  2123.           complain (&unknown_st_complaint, sh.st);
  2124.           cur_sdx++;
  2125.           continue;
  2126.         }
  2127.           /* Use this gdb symbol */
  2128.           ADD_PSYMBOL_TO_LIST (name, strlen (name),
  2129.                    VAR_NAMESPACE, class,
  2130.                    objfile->static_psymbols, sh.value,
  2131.                    psymtab_language, objfile);
  2132.         skip:
  2133.           cur_sdx++;    /* Go to next file symbol */
  2134.         }
  2135.  
  2136.       /* Now do enter the external symbols. */
  2137.       ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
  2138.       cur_sdx = fdr_to_pst[f_idx].n_globals;
  2139.       PST_PRIVATE (save_pst)->extern_count = cur_sdx;
  2140.       PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
  2141.       for (; --cur_sdx >= 0; ext_ptr++)
  2142.         {
  2143.           register struct partial_symbol *psym;
  2144.           enum address_class class;
  2145.           SYMR *psh;
  2146.           char *name;
  2147.  
  2148.           if (ext_ptr->ifd != f_idx)
  2149.         abort ();
  2150.           psh = &ext_ptr->asym;
  2151.           switch (psh->st)
  2152.         {
  2153.         case stProc:
  2154.           class = LOC_BLOCK;
  2155.           break;
  2156.         case stLabel:
  2157.           class = LOC_LABEL;
  2158.           break;
  2159.         default:
  2160.           complain (&unknown_ext_complaint,
  2161.                 ecoff_data (cur_bfd)->ssext + psh->iss);
  2162.           /* Fall through, pretend it's global.  */
  2163.         case stGlobal:
  2164.           class = LOC_STATIC;
  2165.           break;
  2166.         }
  2167.           name = ecoff_data (cur_bfd)->ssext + psh->iss;
  2168.           ADD_PSYMBOL_ADDR_TO_LIST (name, strlen (name),
  2169.                         VAR_NAMESPACE, class,
  2170.                         objfile->global_psymbols, (CORE_ADDR) psh->value,
  2171.                         psymtab_language, objfile);
  2172.         }
  2173.     }
  2174.  
  2175.       end_psymtab (save_pst, psymtab_include_list, includes_used,
  2176.            -1, save_pst->texthigh,
  2177.            dependency_list, dependencies_used);
  2178.       if (objfile->ei.entry_point >= save_pst->textlow &&
  2179.       objfile->ei.entry_point < save_pst->texthigh)
  2180.     {
  2181.       objfile->ei.entry_file_lowpc = save_pst->textlow;
  2182.       objfile->ei.entry_file_highpc = save_pst->texthigh;
  2183.     }
  2184.     }
  2185.  
  2186.   /* Now scan the FDRs for dependencies */
  2187.   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
  2188.     {
  2189.       int s_id0 = 0;
  2190.       fh = f_idx + ecoff_data (cur_bfd)->fdr;
  2191.       pst = fdr_to_pst[f_idx].pst;
  2192.  
  2193.       /* This should catch stabs-in-ecoff. */
  2194.       if (fh->crfd <= 1)
  2195.     continue;
  2196.  
  2197.       if (fh->cpd == 0)
  2198.     {        /* If there are no functions defined here ... */
  2199.       /* ...then presumably a .h file: drop reverse depends .h->.c */
  2200.       for (; s_id0 < fh->crfd; s_id0++)
  2201.         {
  2202.           RFDT rh;
  2203.  
  2204.           ecoff_swap_rfd_in (cur_bfd,
  2205.                  (ecoff_data (cur_bfd)->external_rfd
  2206.                   + fh->rfdBase
  2207.                   + s_id0),
  2208.                  &rh);
  2209.           if (rh == f_idx)
  2210.         {
  2211.           s_id0++;    /* Skip self-dependency */
  2212.           break;
  2213.         }
  2214.         }
  2215.     }
  2216.       pst->number_of_dependencies = fh->crfd - s_id0;
  2217.       pst->dependencies =
  2218.     ((struct partial_symtab **)
  2219.      obstack_alloc (&objfile->psymbol_obstack,
  2220.             (pst->number_of_dependencies
  2221.              * sizeof (struct partial_symtab *))));
  2222.       for (s_idx = s_id0; s_idx < fh->crfd; s_idx++)
  2223.     {
  2224.       RFDT rh;
  2225.  
  2226.       ecoff_swap_rfd_in (cur_bfd,
  2227.                  (ecoff_data (cur_bfd)->external_rfd
  2228.                   + fh->rfdBase
  2229.                   + s_idx),
  2230.                  &rh);
  2231.       if (rh < 0 || rh >= hdr->ifdMax)
  2232.         complain (&bad_file_number_complaint, rh);
  2233.       else
  2234.         pst->dependencies[s_idx - s_id0] = fdr_to_pst[rh].pst;
  2235.     }
  2236.     }
  2237.   do_cleanups (old_chain);
  2238. }
  2239.  
  2240.  
  2241. #if 0
  2242. /* Do the initial analisys of the F_IDX-th file descriptor.
  2243.    Allocates a partial symtab for it, and builds the list
  2244.    of dependent files by recursion. LEV says at which level
  2245.    of recursion we are called (to pretty up debug traces) */
  2246.  
  2247. static struct partial_symtab *
  2248. parse_fdr (f_idx, lev, objfile)
  2249.      int f_idx;
  2250.      int lev;
  2251.      struct objfile *objfile;
  2252. {
  2253.   register FDR *fh;
  2254.   register struct partial_symtab *pst;
  2255.   int s_idx, s_id0;
  2256.  
  2257.   fh = ecoff_data (cur_bfd)->fdr + f_idx;
  2258.  
  2259.   /* Use this to indicate into which symtab this file was parsed */
  2260.   if (fh->ioptBase)
  2261.     return (struct partial_symtab *) fh->ioptBase;
  2262.  
  2263.   /* Debuggability level */
  2264.   if (compare_glevel (max_glevel, fh->glevel) < 0)
  2265.     max_glevel = fh->glevel;
  2266.  
  2267.   /* Make a new partial_symtab */
  2268.   pst = new_psymtab (fdr_name (fh), objfile);
  2269.   if (fh->cpd == 0)
  2270.     {
  2271.       pst->textlow = 0;
  2272.       pst->texthigh = 0;
  2273.     }
  2274.   else
  2275.     {
  2276.       pst->textlow = fh->adr;
  2277.       pst->texthigh = fh->cpd;    /* To be fixed later */
  2278.     }
  2279.  
  2280.   /* Make everything point to everything. */
  2281.   FDR_IDX (pst) = f_idx;
  2282.   fdr_to_pst[f_idx].pst = pst;
  2283.   fh->ioptBase = (int) pst;
  2284.  
  2285.   /* Analyze its dependencies */
  2286.   if (fh->crfd <= 1)
  2287.     return pst;
  2288.  
  2289.   s_id0 = 0;
  2290.   if (fh->cpd == 0)
  2291.     {                /* If there are no functions defined here ... */
  2292.       /* ...then presumably a .h file: drop reverse depends .h->.c */
  2293.       for (; s_id0 < fh->crfd; s_id0++)
  2294.     {
  2295.       RFDT rh;
  2296.  
  2297.       ecoff_swap_rfd_in (cur_bfd,
  2298.                  (ecoff_data (cur_bfd)->external_rfd
  2299.                   + fh->rfdBase
  2300.                   + s_id0),
  2301.                  &rh);
  2302.       if (rh == f_idx)
  2303.         {
  2304.           s_id0++;        /* Skip self-dependency */
  2305.           break;
  2306.         }
  2307.     }
  2308.     }
  2309.   pst->number_of_dependencies = fh->crfd - s_id0;
  2310.   pst->dependencies = ((struct partial_symtab **)
  2311.                obstack_alloc (&objfile->psymbol_obstack,
  2312.                       (pst->number_of_dependencies
  2313.                        * sizeof (struct partial_symtab *))));
  2314.   for (s_idx = s_id0; s_idx < fh->crfd; s_idx++)
  2315.     {
  2316.       RFDT rh;
  2317.  
  2318.       ecoff_swap_rfd_in (cur_bfd,
  2319.              (ecoff_data (cur_bfd)->external_rfd
  2320.               + fh->rfdBase
  2321.               + s_idx),
  2322.              &rh);
  2323.       pst->dependencies[s_idx - s_id0] = parse_fdr (rh, lev + 1, objfile);
  2324.     }
  2325.  
  2326.   return pst;
  2327. }
  2328.  
  2329. #endif
  2330.  
  2331. static char *
  2332. mips_next_symbol_text ()
  2333. {
  2334.   SYMR sh;
  2335.  
  2336.   cur_sdx++;
  2337.   ecoff_swap_sym_in (cur_bfd,
  2338.              (ecoff_data (cur_bfd)->external_sym
  2339.               + cur_fdr->isymBase
  2340.               + cur_sdx),
  2341.              &sh);
  2342.   return ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
  2343. }
  2344.  
  2345. /* Ancillary function to psymtab_to_symtab().  Does all the work
  2346.    for turning the partial symtab PST into a symtab, recurring
  2347.    first on all dependent psymtabs.  The argument FILENAME is
  2348.    only passed so we can see in debug stack traces what file
  2349.    is being read.
  2350.  
  2351.    This function has a split personality, based on whether the
  2352.    symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
  2353.    The flow of control and even the memory allocation differs.  FIXME.  */
  2354.  
  2355. static void
  2356. psymtab_to_symtab_1 (pst, filename)
  2357.      struct partial_symtab *pst;
  2358.      char *filename;
  2359. {
  2360.   int i;
  2361.   struct symtab *st;
  2362.   FDR *fh;
  2363.   struct linetable *lines;
  2364.  
  2365.   if (pst->readin)
  2366.     return;
  2367.   pst->readin = 1;
  2368.  
  2369.   /* Read in all partial symbtabs on which this one is dependent.
  2370.      NOTE that we do have circular dependencies, sigh.  We solved
  2371.      that by setting pst->readin before this point.  */
  2372.  
  2373.   for (i = 0; i < pst->number_of_dependencies; i++)
  2374.     if (!pst->dependencies[i]->readin)
  2375.       {
  2376.     /* Inform about additional files to be read in.  */
  2377.     if (info_verbose)
  2378.       {
  2379.         fputs_filtered (" ", stdout);
  2380.         wrap_here ("");
  2381.         fputs_filtered ("and ", stdout);
  2382.         wrap_here ("");
  2383.         printf_filtered ("%s...",
  2384.                  pst->dependencies[i]->filename);
  2385.         wrap_here ("");    /* Flush output */
  2386.         fflush (stdout);
  2387.       }
  2388.     /* We only pass the filename for debug purposes */
  2389.     psymtab_to_symtab_1 (pst->dependencies[i],
  2390.                  pst->dependencies[i]->filename);
  2391.       }
  2392.  
  2393.   /* Do nothing if this is a dummy psymtab.  */
  2394.  
  2395.   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
  2396.       && pst->textlow == 0 && pst->texthigh == 0)
  2397.     return;
  2398.  
  2399.   /* Now read the symbols for this symtab */
  2400.  
  2401.   cur_bfd = CUR_BFD (pst);
  2402.   current_objfile = pst->objfile;
  2403.   cur_fd = FDR_IDX (pst);
  2404.   fh = (cur_fd == -1) ? (FDR *) NULL : ecoff_data (cur_bfd)->fdr + cur_fd;
  2405.   cur_fdr = fh;
  2406.  
  2407.   /* See comment in parse_partial_symbols about the @stabs sentinel. */
  2408.   processing_gcc_compilation = 0;
  2409.   if (fh != (FDR *) NULL && fh->csym >= 2)
  2410.     {
  2411.       SYMR sh;
  2412.  
  2413.       ecoff_swap_sym_in (cur_bfd,
  2414.              (ecoff_data (cur_bfd)->external_sym
  2415.               + fh->isymBase
  2416.               + 1),
  2417.              &sh);
  2418.       if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
  2419.          stabs_symbol))
  2420.     {
  2421.       /* We indicate that this is a GCC compilation so that certain
  2422.          features will be enabled in stabsread/dbxread.  */
  2423.       processing_gcc_compilation = 2;
  2424.     }
  2425.     }
  2426.  
  2427.   if (processing_gcc_compilation != 0)
  2428.     {
  2429.       struct pdr_ext *pdr_ptr;
  2430.       struct pdr_ext *pdr_end;
  2431.       int first_pdr;
  2432.       unsigned long first_off;
  2433.  
  2434.       /* This symbol table contains stabs-in-ecoff entries.  */
  2435.  
  2436.       /* Parse local symbols first */
  2437.  
  2438.       if (fh->csym <= 2)    /* FIXME, this blows psymtab->symtab ptr */
  2439.     {
  2440.       current_objfile = NULL;
  2441.       return;
  2442.     }
  2443.       for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
  2444.     {
  2445.       SYMR sh;
  2446.       char *name;
  2447.       CORE_ADDR valu;
  2448.  
  2449.       ecoff_swap_sym_in (cur_bfd,
  2450.                  (ecoff_data (cur_bfd)->external_sym
  2451.                   + fh->isymBase
  2452.                   + cur_sdx),
  2453.                  &sh);
  2454.       name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
  2455.       valu = sh.value;
  2456.       if (MIPS_IS_STAB (&sh))
  2457.         {
  2458.           int type_code = MIPS_UNMARK_STAB (sh.index);
  2459.           process_one_symbol (type_code, 0, valu, name,
  2460.                   pst->section_offsets, pst->objfile);
  2461.           if (type_code == N_FUN)
  2462.         {
  2463.           /* Make up special symbol to contain
  2464.              procedure specific info */
  2465.           struct mips_extra_func_info *e =
  2466.             ((struct mips_extra_func_info *)
  2467.              obstack_alloc (¤t_objfile->symbol_obstack,
  2468.                     sizeof (struct mips_extra_func_info)));
  2469.           struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
  2470.           SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
  2471.           SYMBOL_CLASS (s) = LOC_CONST;
  2472.           SYMBOL_TYPE (s) = builtin_type_void;
  2473.           SYMBOL_VALUE (s) = (int) e;
  2474.           add_symbol_to_list (s, &local_symbols);
  2475.         }
  2476.         }
  2477.       else if (sh.st == stLabel && sh.index != indexNil)
  2478.         {
  2479.           /* Handle encoded stab line number. */
  2480.           record_line (current_subfile, sh.index, valu);
  2481.         }
  2482.       else if (sh.st == stProc || sh.st == stStaticProc || sh.st == stEnd)
  2483.         /* These are generated by gcc-2.x, do not complain */
  2484.         ;
  2485.       else
  2486.         complain (&stab_unknown_complaint, name);
  2487.     }
  2488.       st = end_symtab (pst->texthigh, 0, 0, pst->objfile, SECT_OFF_TEXT);
  2489.       end_stabs ();
  2490.  
  2491.       /* Sort the symbol table now, we are done adding symbols to it.
  2492.      We must do this before parse_procedure calls lookup_symbol.  */
  2493.       sort_symtab_syms (st);
  2494.  
  2495.       /* This may not be necessary for stabs symtabs.  FIXME.  */
  2496.       sort_blocks (st);
  2497.  
  2498.       /* Fill in procedure info next.  */
  2499.       first_pdr = 1;
  2500.       pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst;
  2501.       pdr_end = pdr_ptr + fh->cpd;
  2502.       for (; pdr_ptr < pdr_end; pdr_ptr++)
  2503.     {
  2504.       PDR pr;
  2505.  
  2506.       ecoff_swap_pdr_in (cur_bfd, pdr_ptr, &pr);
  2507.       if (first_pdr)
  2508.         {
  2509.           first_off = pr.adr;
  2510.           first_pdr = 0;
  2511.         }
  2512.       parse_procedure (&pr, 1, first_off);
  2513.     }
  2514.     }
  2515.   else
  2516.     {
  2517.       /* This symbol table contains ordinary ecoff entries.  */
  2518.  
  2519.       /* FIXME:  doesn't use pst->section_offsets.  */
  2520.  
  2521.       int f_max;
  2522.       int maxlines;
  2523.       EXTR *ext_ptr;
  2524.  
  2525.       /* How many symbols will we need */
  2526.       /* FIXME, this does not count enum values. */
  2527.       f_max = pst->n_global_syms + pst->n_static_syms;
  2528.       if (fh == 0)
  2529.     {
  2530.       maxlines = 0;
  2531.       st = new_symtab ("unknown", f_max, 0, pst->objfile);
  2532.     }
  2533.       else
  2534.     {
  2535.       f_max += fh->csym + fh->cpd;
  2536.       maxlines = 2 * fh->cline;
  2537.       st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
  2538.     }
  2539.  
  2540.       lines = LINETABLE (st);
  2541.       pending_list = PST_PRIVATE (pst)->pending_list;
  2542.       if (pending_list == 0)
  2543.     {
  2544.       pending_list = ((struct mips_pending **)
  2545.               xzalloc (ecoff_data (cur_bfd)->symbolic_header.ifdMax
  2546.                    * sizeof (struct mips_pending *)));
  2547.       PST_PRIVATE (pst)->pending_list = pending_list;
  2548.     }
  2549.  
  2550.       /* Get a new lexical context */
  2551.  
  2552.       push_parse_stack ();
  2553.       top_stack->cur_st = st;
  2554.       top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
  2555.                         STATIC_BLOCK);
  2556.       BLOCK_START (top_stack->cur_block) = fh ? fh->adr : 0;
  2557.       BLOCK_END (top_stack->cur_block) = 0;
  2558.       top_stack->blocktype = stFile;
  2559.       top_stack->maxsyms = 2 * f_max;
  2560.       top_stack->cur_type = 0;
  2561.       top_stack->procadr = 0;
  2562.       top_stack->numargs = 0;
  2563.  
  2564.       if (fh)
  2565.     {
  2566.       struct sym_ext *sym_ptr;
  2567.       struct sym_ext *sym_end;
  2568.  
  2569.       /* Parse local symbols first */
  2570.       sym_ptr = ecoff_data (cur_bfd)->external_sym + fh->isymBase;
  2571.       sym_end = sym_ptr + fh->csym;
  2572.       while (sym_ptr < sym_end)
  2573.         {
  2574.           SYMR sh;
  2575.           int c;
  2576.  
  2577.           ecoff_swap_sym_in (cur_bfd, sym_ptr, &sh);
  2578.           c = parse_symbol (&sh,
  2579.                 (ecoff_data (cur_bfd)->external_aux
  2580.                  + fh->iauxBase),
  2581.                 sym_ptr, fh->fBigendian);
  2582.           /* FIXME: We must swap the modified symbol back out,
  2583.          although we would rather not.  See parse_symbol.  */
  2584.           ecoff_swap_sym_out (cur_bfd, &sh, sym_ptr);
  2585.           sym_ptr += c;
  2586.         }
  2587.  
  2588.       /* Linenumbers.  At the end, check if we can save memory.
  2589.          parse_lines has to look ahead an arbitrary number of PDR
  2590.          structures, so we swap them all first.  */
  2591.       if (fh->cpd > 0)
  2592.         {
  2593.           PDR *pr_block;
  2594.           struct cleanup *old_chain;
  2595.           struct pdr_ext *pdr_ptr;
  2596.           struct pdr_ext *pdr_end;
  2597.           PDR *pdr_in;
  2598.           PDR *pdr_in_end;
  2599.  
  2600.           pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
  2601.  
  2602.           old_chain = make_cleanup (free, pr_block);
  2603.  
  2604.           pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst;
  2605.           pdr_end = pdr_ptr + fh->cpd;
  2606.           pdr_in = pr_block;
  2607.           for (; pdr_ptr < pdr_end; pdr_ptr++, pdr_in++)
  2608.         ecoff_swap_pdr_in (cur_bfd, pdr_ptr, pdr_in);
  2609.  
  2610.           parse_lines (fh, pr_block, lines);
  2611.           if (lines->nitems < fh->cline)
  2612.         lines = shrink_linetable (lines);
  2613.  
  2614.           /* Fill in procedure info next.  */
  2615.           pdr_in = pr_block;
  2616.           pdr_in_end = pdr_in + fh->cpd;
  2617.           for (; pdr_in < pdr_in_end; pdr_in++)
  2618.         parse_procedure (pdr_in, 0, pr_block->adr);
  2619.  
  2620.           do_cleanups (old_chain);
  2621.         }
  2622.     }
  2623.  
  2624.       LINETABLE (st) = lines;
  2625.  
  2626.       /* .. and our share of externals.
  2627.      XXX use the global list to speed up things here. how?
  2628.      FIXME, Maybe quit once we have found the right number of ext's? */
  2629.       top_stack->cur_st = st;
  2630.       top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
  2631.                         GLOBAL_BLOCK);
  2632.       top_stack->blocktype = stFile;
  2633.       top_stack->maxsyms = (ecoff_data (cur_bfd)->symbolic_header.isymMax
  2634.                 + ecoff_data (cur_bfd)->symbolic_header.ipdMax
  2635.                 + ecoff_data (cur_bfd)->symbolic_header.iextMax);
  2636.  
  2637.       ext_ptr = PST_PRIVATE (pst)->extern_tab;
  2638.       for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
  2639.     parse_external (ext_ptr, 1, fh->fBigendian);
  2640.  
  2641.       /* If there are undefined, tell the user */
  2642.       if (n_undef_symbols)
  2643.     {
  2644.       printf_filtered ("File %s contains %d unresolved references:",
  2645.                st->filename, n_undef_symbols);
  2646.       printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
  2647.                n_undef_vars, n_undef_procs, n_undef_labels);
  2648.       n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
  2649.  
  2650.     }
  2651.       pop_parse_stack ();
  2652.  
  2653.       /* Sort the symbol table now, we are done adding symbols to it.*/
  2654.       sort_symtab_syms (st);
  2655.  
  2656.       sort_blocks (st);
  2657.     }
  2658.  
  2659.   /* Now link the psymtab and the symtab.  */
  2660.   pst->symtab = st;
  2661.  
  2662.   current_objfile = NULL;
  2663. }
  2664.  
  2665. /* Ancillary parsing procedures. */
  2666.  
  2667. /* Lookup the type at relative index RN.  Return it in TPP
  2668.    if found and in any event come up with its name PNAME.
  2669.    BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
  2670.    Return value says how many aux symbols we ate. */
  2671.  
  2672. static int
  2673. cross_ref (ax, tpp, type_code, pname, bigend)
  2674.      union aux_ext *ax;
  2675.      struct type **tpp;
  2676.      enum type_code type_code;    /* Use to alloc new type if none is found. */
  2677.      char **pname;
  2678.      int bigend;
  2679. {
  2680.   RNDXR rn[1];
  2681.   unsigned rf;
  2682.   int result = 1;
  2683.  
  2684.   ecoff_swap_rndx_in (bigend, &ax->a_rndx, rn);
  2685.  
  2686.   /* Escape index means 'the next one' */
  2687.   if (rn->rfd == 0xfff)
  2688.     {
  2689.       result++;
  2690.       rf = AUX_GET_ISYM (bigend, ax + 1);
  2691.     }
  2692.   else
  2693.     {
  2694.       rf = rn->rfd;
  2695.     }
  2696.  
  2697.   if (rf == -1)
  2698.     {
  2699.       /* Ooops */
  2700.       *pname = "<undefined>";
  2701.     }
  2702.   else
  2703.     {
  2704.       /*
  2705.        * Find the relative file descriptor and the symbol in it
  2706.        */
  2707.       FDR *fh = get_rfd (cur_fd, rf);
  2708.       struct sym_ext *esh;
  2709.       SYMR sh;
  2710.       struct type *t;
  2711.  
  2712.       /* If we have processed this symbol then we left a forwarding
  2713.      pointer to the corresponding GDB symbol.  If not, we`ll put
  2714.      it in a list of pending symbols, to be processed later when
  2715.      the file will be.  In any event, we collect the name for the
  2716.      type here.  Which is why we made a first pass at strings.  */
  2717.  
  2718.       esh = ecoff_data (cur_bfd)->external_sym + fh->isymBase + rn->index;
  2719.       ecoff_swap_sym_in (cur_bfd, esh, &sh);
  2720.  
  2721.       /* Careful, we might be looking at .o files */
  2722.       if (sh.iss == 0)
  2723.     *pname = "<undefined>";
  2724.       else
  2725.     *pname = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
  2726.  
  2727.       /* Have we parsed it ? */
  2728.       if (sh.value != 0 && sh.st == stParsed)
  2729.     {
  2730.       t = (struct type *) sh.value;
  2731.       *tpp = t;
  2732.     }
  2733.       else
  2734.     {
  2735.       /* Avoid duplicates */
  2736.       struct mips_pending *p = is_pending_symbol (fh, esh);
  2737.       if (p)
  2738.         *tpp = p->t;
  2739.       else
  2740.         {
  2741.           *tpp = init_type (type_code, 0, 0, (char *) NULL,
  2742.                 (struct objfile *) NULL);
  2743.           add_pending (fh, esh, *tpp);
  2744.         }
  2745.     }
  2746.     }
  2747.  
  2748.   /* We used one auxent normally, two if we got a "next one" rf. */
  2749.   return result;
  2750. }
  2751.  
  2752.  
  2753. /* Quick&dirty lookup procedure, to avoid the MI ones that require
  2754.    keeping the symtab sorted */
  2755.  
  2756. static struct symbol *
  2757. mylookup_symbol (name, block, namespace, class)
  2758.      char *name;
  2759.      register struct block *block;
  2760.      enum namespace namespace;
  2761.      enum address_class class;
  2762. {
  2763.   register int bot, top, inc;
  2764.   register struct symbol *sym;
  2765.  
  2766.   bot = 0;
  2767.   top = BLOCK_NSYMS (block);
  2768.   inc = name[0];
  2769.   while (bot < top)
  2770.     {
  2771.       sym = BLOCK_SYM (block, bot);
  2772.       if (SYMBOL_NAME (sym)[0] == inc
  2773.       && SYMBOL_NAMESPACE (sym) == namespace
  2774.       && SYMBOL_CLASS (sym) == class
  2775.       && STREQ (SYMBOL_NAME (sym), name))
  2776.     return sym;
  2777.       bot++;
  2778.     }
  2779.   block = BLOCK_SUPERBLOCK (block);
  2780.   if (block)
  2781.     return mylookup_symbol (name, block, namespace, class);
  2782.   return 0;
  2783. }
  2784.  
  2785.  
  2786. /* Add a new symbol S to a block B.
  2787.    Infrequently, we will need to reallocate the block to make it bigger.
  2788.    We only detect this case when adding to top_stack->cur_block, since
  2789.    that's the only time we know how big the block is.  FIXME.  */
  2790.  
  2791. static void
  2792. add_symbol (s, b)
  2793.      struct symbol *s;
  2794.      struct block *b;
  2795. {
  2796.   int nsyms = BLOCK_NSYMS (b)++;
  2797.   struct block *origb;
  2798.   struct parse_stack *stackp;
  2799.  
  2800.   if (b == top_stack->cur_block &&
  2801.       nsyms >= top_stack->maxsyms)
  2802.     {
  2803.       complain (&block_overflow_complaint, SYMBOL_NAME (s));
  2804.       /* In this case shrink_block is actually grow_block, since
  2805.            BLOCK_NSYMS(b) is larger than its current size.  */
  2806.       origb = b;
  2807.       b = shrink_block (top_stack->cur_block, top_stack->cur_st);
  2808.  
  2809.       /* Now run through the stack replacing pointers to the
  2810.      original block.  shrink_block has already done this
  2811.      for the blockvector and BLOCK_FUNCTION.  */
  2812.       for (stackp = top_stack; stackp; stackp = stackp->next)
  2813.     {
  2814.       if (stackp->cur_block == origb)
  2815.         {
  2816.           stackp->cur_block = b;
  2817.           stackp->maxsyms = BLOCK_NSYMS (b);
  2818.         }
  2819.     }
  2820.     }
  2821.   BLOCK_SYM (b, nsyms) = s;
  2822. }
  2823.  
  2824. /* Add a new block B to a symtab S */
  2825.  
  2826. static void
  2827. add_block (b, s)
  2828.      struct block *b;
  2829.      struct symtab *s;
  2830. {
  2831.   struct blockvector *bv = BLOCKVECTOR (s);
  2832.  
  2833.   bv = (struct blockvector *) xrealloc ((PTR) bv,
  2834.                     (sizeof (struct blockvector)
  2835.                      + BLOCKVECTOR_NBLOCKS (bv)
  2836.                      * sizeof (bv->block)));
  2837.   if (bv != BLOCKVECTOR (s))
  2838.     BLOCKVECTOR (s) = bv;
  2839.  
  2840.   BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
  2841. }
  2842.  
  2843. /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
  2844.    MIPS' linenumber encoding might need more than one byte
  2845.    to describe it, LAST is used to detect these continuation lines.
  2846.  
  2847.    Combining lines with the same line number seems like a bad idea.
  2848.    E.g: There could be a line number entry with the same line number after the
  2849.    prologue and GDB should not ignore it (this is a better way to find
  2850.    a prologue than mips_skip_prologue).
  2851.    But due to the compressed line table format there are line number entries
  2852.    for the same line which are needed to bridge the gap to the next
  2853.    line number entry. These entries have a bogus address info with them
  2854.    and we are unable to tell them from intended duplicate line number
  2855.    entries.
  2856.    This is another reason why -ggdb debugging format is preferable.  */
  2857.  
  2858. static int
  2859. add_line (lt, lineno, adr, last)
  2860.      struct linetable *lt;
  2861.      int lineno;
  2862.      CORE_ADDR adr;
  2863.      int last;
  2864. {
  2865.   if (last == 0)
  2866.     last = -2;            /* make sure we record first line */
  2867.  
  2868.   if (last == lineno)        /* skip continuation lines */
  2869.     return lineno;
  2870.  
  2871.   lt->item[lt->nitems].line = lineno;
  2872.   lt->item[lt->nitems++].pc = adr << 2;
  2873.   return lineno;
  2874. }
  2875.  
  2876. /* Sorting and reordering procedures */
  2877.  
  2878. /* Blocks with a smaller low bound should come first */
  2879.  
  2880. static int
  2881. compare_blocks (arg1, arg2)
  2882.      const void *arg1, *arg2;
  2883. {
  2884.   register int addr_diff;
  2885.   struct block **b1 = (struct block **) arg1;
  2886.   struct block **b2 = (struct block **) arg2;
  2887.  
  2888.   addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
  2889.   if (addr_diff == 0)
  2890.     return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
  2891.   return addr_diff;
  2892. }
  2893.  
  2894. /* Sort the blocks of a symtab S.
  2895.    Reorder the blocks in the blockvector by code-address,
  2896.    as required by some MI search routines */
  2897.  
  2898. static void
  2899. sort_blocks (s)
  2900.      struct symtab *s;
  2901. {
  2902.   struct blockvector *bv = BLOCKVECTOR (s);
  2903.  
  2904.   if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
  2905.     {
  2906.       /* Cosmetic */
  2907.       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
  2908.     BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
  2909.       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
  2910.     BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
  2911.       return;
  2912.     }
  2913.   /*
  2914.    * This is very unfortunate: normally all functions are compiled in
  2915.    * the order they are found, but if the file is compiled -O3 things
  2916.    * are very different.  It would be nice to find a reliable test
  2917.    * to detect -O3 images in advance.
  2918.    */
  2919.   if (BLOCKVECTOR_NBLOCKS (bv) > 3)
  2920.     qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
  2921.        BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
  2922.        sizeof (struct block *),
  2923.        compare_blocks);
  2924.  
  2925.   {
  2926.     register CORE_ADDR high = 0;
  2927.     register int i, j = BLOCKVECTOR_NBLOCKS (bv);
  2928.  
  2929.     for (i = FIRST_LOCAL_BLOCK; i < j; i++)
  2930.       if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
  2931.     high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
  2932.     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
  2933.   }
  2934.  
  2935.   BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
  2936.     BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
  2937.  
  2938.   BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  2939.     BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
  2940.   BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  2941.     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
  2942. }
  2943.  
  2944.  
  2945. /* Constructor/restructor/destructor procedures */
  2946.  
  2947. /* Allocate a new symtab for NAME.  Needs an estimate of how many symbols
  2948.    MAXSYMS and linenumbers MAXLINES we'll put in it */
  2949.  
  2950. static struct symtab *
  2951. new_symtab (name, maxsyms, maxlines, objfile)
  2952.      char *name;
  2953.      int maxsyms;
  2954.      int maxlines;
  2955.      struct objfile *objfile;
  2956. {
  2957.   struct symtab *s = allocate_symtab (name, objfile);
  2958.  
  2959.   LINETABLE (s) = new_linetable (maxlines);
  2960.  
  2961.   /* All symtabs must have at least two blocks */
  2962.   BLOCKVECTOR (s) = new_bvect (2);
  2963.   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
  2964.   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
  2965.   BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
  2966.     BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
  2967.  
  2968.   s->free_code = free_linetable;
  2969.  
  2970.   return (s);
  2971. }
  2972.  
  2973. /* Allocate a new partial_symtab NAME */
  2974.  
  2975. static struct partial_symtab *
  2976. new_psymtab (name, objfile)
  2977.      char *name;
  2978.      struct objfile *objfile;
  2979. {
  2980.   struct partial_symtab *psymtab;
  2981.  
  2982.   psymtab = allocate_psymtab (name, objfile);
  2983.  
  2984.   /* Keep a backpointer to the file's symbols */
  2985.  
  2986.   psymtab->read_symtab_private = ((char *)
  2987.                   obstack_alloc (&objfile->psymbol_obstack,
  2988.                          sizeof (struct symloc)));
  2989.   memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
  2990.   CUR_BFD (psymtab) = cur_bfd;
  2991.  
  2992.   /* The way to turn this into a symtab is to call... */
  2993.   psymtab->read_symtab = mipscoff_psymtab_to_symtab;
  2994.   return (psymtab);
  2995. }
  2996.  
  2997.  
  2998. /* Allocate a linetable array of the given SIZE.  Since the struct
  2999.    already includes one item, we subtract one when calculating the
  3000.    proper size to allocate.  */
  3001.  
  3002. static struct linetable *
  3003. new_linetable (size)
  3004.      int size;
  3005. {
  3006.   struct linetable *l;
  3007.  
  3008.   size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
  3009.   l = (struct linetable *) xmalloc (size);
  3010.   l->nitems = 0;
  3011.   return l;
  3012. }
  3013.  
  3014. /* Oops, too big. Shrink it.  This was important with the 2.4 linetables,
  3015.    I am not so sure about the 3.4 ones.
  3016.  
  3017.    Since the struct linetable already includes one item, we subtract one when
  3018.    calculating the proper size to allocate.  */
  3019.  
  3020. static struct linetable *
  3021. shrink_linetable (lt)
  3022.      struct linetable *lt;
  3023. {
  3024.  
  3025.   return (struct linetable *) xrealloc ((PTR) lt,
  3026.                     (sizeof (struct linetable)
  3027.                      + ((lt->nitems - 1)
  3028.                         * sizeof (lt->item))));
  3029. }
  3030.  
  3031. /* Allocate and zero a new blockvector of NBLOCKS blocks. */
  3032.  
  3033. static struct blockvector *
  3034. new_bvect (nblocks)
  3035.      int nblocks;
  3036. {
  3037.   struct blockvector *bv;
  3038.   int size;
  3039.  
  3040.   size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
  3041.   bv = (struct blockvector *) xzalloc (size);
  3042.  
  3043.   BLOCKVECTOR_NBLOCKS (bv) = nblocks;
  3044.  
  3045.   return bv;
  3046. }
  3047.  
  3048. /* Allocate and zero a new block of MAXSYMS symbols */
  3049.  
  3050. static struct block *
  3051. new_block (maxsyms)
  3052.      int maxsyms;
  3053. {
  3054.   int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
  3055.  
  3056.   return (struct block *) xzalloc (size);
  3057. }
  3058.  
  3059. /* Ooops, too big. Shrink block B in symtab S to its minimal size.
  3060.    Shrink_block can also be used by add_symbol to grow a block.  */
  3061.  
  3062. static struct block *
  3063. shrink_block (b, s)
  3064.      struct block *b;
  3065.      struct symtab *s;
  3066. {
  3067.   struct block *new;
  3068.   struct blockvector *bv = BLOCKVECTOR (s);
  3069.   int i;
  3070.  
  3071.   /* Just reallocate it and fix references to the old one */
  3072.  
  3073.   new = (struct block *) xrealloc ((PTR) b,
  3074.                    (sizeof (struct block)
  3075.                     + ((BLOCK_NSYMS (b) - 1)
  3076.                        * sizeof (struct symbol *))));
  3077.  
  3078.   /* Should chase pointers to old one.  Fortunately, that`s just
  3079.        the block`s function and inferior blocks */
  3080.   if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
  3081.     SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
  3082.   for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
  3083.     if (BLOCKVECTOR_BLOCK (bv, i) == b)
  3084.       BLOCKVECTOR_BLOCK (bv, i) = new;
  3085.     else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
  3086.       BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
  3087.   return new;
  3088. }
  3089.  
  3090. /* Create a new symbol with printname NAME */
  3091.  
  3092. static struct symbol *
  3093. new_symbol (name)
  3094.      char *name;
  3095. {
  3096.   struct symbol *s = ((struct symbol *)
  3097.               obstack_alloc (¤t_objfile->symbol_obstack,
  3098.                      sizeof (struct symbol)));
  3099.  
  3100.   memset ((PTR) s, 0, sizeof (*s));
  3101.   SYMBOL_NAME (s) = name;
  3102.   return s;
  3103. }
  3104.  
  3105. /* Create a new type with printname NAME */
  3106.  
  3107. static struct type *
  3108. new_type (name)
  3109.      char *name;
  3110. {
  3111.   struct type *t;
  3112.  
  3113.   t = alloc_type (current_objfile);
  3114.   TYPE_NAME (t) = name;
  3115.   TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
  3116.   return t;
  3117. }
  3118.  
  3119.  
  3120. /* Things used for calling functions in the inferior.
  3121.    These functions are exported to our companion
  3122.    mips-tdep.c file and are here because they play
  3123.    with the symbol-table explicitly. */
  3124.  
  3125. /* Sigtramp: make sure we have all the necessary information
  3126.    about the signal trampoline code. Since the official code
  3127.    from MIPS does not do so, we make up that information ourselves.
  3128.    If they fix the library (unlikely) this code will neutralize itself. */
  3129.  
  3130. static void
  3131. fixup_sigtramp ()
  3132. {
  3133.   struct symbol *s;
  3134.   struct symtab *st;
  3135.   struct block *b, *b0;
  3136.  
  3137.   sigtramp_address = -1;
  3138.  
  3139.   /* We know it is sold as sigvec */
  3140.   s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
  3141.  
  3142.   /* Most programs do not play with signals */
  3143.   if (s == 0)
  3144.     s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
  3145.   else
  3146.     {
  3147.       b0 = SYMBOL_BLOCK_VALUE (s);
  3148.  
  3149.       /* A label of sigvec, to be more precise */
  3150.       s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
  3151.     }
  3152.  
  3153.   /* But maybe this program uses its own version of sigvec */
  3154.   if (s == 0)
  3155.     return;
  3156.  
  3157.   /* Did we or MIPSco fix the library ? */
  3158.   if (SYMBOL_CLASS (s) == LOC_BLOCK)
  3159.     {
  3160.       sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
  3161.       sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
  3162.       return;
  3163.     }
  3164.  
  3165.   sigtramp_address = SYMBOL_VALUE (s);
  3166.   sigtramp_end = sigtramp_address + 0x88;    /* black magic */
  3167.  
  3168.   /* But what symtab does it live in ? */
  3169.   st = find_pc_symtab (SYMBOL_VALUE (s));
  3170.  
  3171.   /*
  3172.    * Ok, there goes the fix: turn it into a procedure, with all the
  3173.    * needed info.  Note we make it a nested procedure of sigvec,
  3174.    * which is the way the (assembly) code is actually written.
  3175.    */
  3176.   SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
  3177.   SYMBOL_CLASS (s) = LOC_BLOCK;
  3178.   SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
  3179.                    (struct objfile *) NULL);
  3180.   TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = builtin_type_void;
  3181.  
  3182.   /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
  3183.   b = new_block (1);
  3184.   SYMBOL_BLOCK_VALUE (s) = b;
  3185.   BLOCK_START (b) = sigtramp_address;
  3186.   BLOCK_END (b) = sigtramp_end;
  3187.   BLOCK_FUNCTION (b) = s;
  3188.   BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
  3189.   add_block (b, st);
  3190.   sort_blocks (st);
  3191.  
  3192.   /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
  3193.   {
  3194.     struct mips_extra_func_info *e =
  3195.       ((struct mips_extra_func_info *)
  3196.        xzalloc (sizeof (struct mips_extra_func_info)));
  3197.  
  3198.     e->numargs = 0;        /* the kernel thinks otherwise */
  3199.     /* align_longword(sigcontext + SIGFRAME) */
  3200.     e->pdr.frameoffset = 0x150;
  3201.     e->pdr.framereg = SP_REGNUM;
  3202.     /* read_next_frame_reg provides the true pc at the time of signal */
  3203.     e->pdr.pcreg = PC_REGNUM;
  3204.     e->pdr.regmask = -2;
  3205.     e->pdr.regoffset = -(41 * sizeof (int));
  3206.     e->pdr.fregmask = -1;
  3207.     e->pdr.fregoffset = -(7 * sizeof (int));
  3208.     e->pdr.isym = (long) s;
  3209.  
  3210.     current_objfile = st->objfile;    /* Keep new_symbol happy */
  3211.     s = new_symbol (MIPS_EFI_SYMBOL_NAME);
  3212.     SYMBOL_VALUE (s) = (int) e;
  3213.     SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
  3214.     SYMBOL_CLASS (s) = LOC_CONST;
  3215.     SYMBOL_TYPE (s) = builtin_type_void;
  3216.     current_objfile = NULL;
  3217.   }
  3218.  
  3219.   BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
  3220. }
  3221.  
  3222.  
  3223. /* Fake up identical offsets for all sections.  */
  3224.  
  3225. struct section_offsets *
  3226. mipscoff_symfile_offsets (objfile, addr)
  3227.      struct objfile *objfile;
  3228.      CORE_ADDR addr;
  3229. {
  3230.   struct section_offsets *section_offsets;
  3231.   int i;
  3232.  
  3233.   section_offsets = ((struct section_offsets *)
  3234.              obstack_alloc (&objfile->psymbol_obstack,
  3235.                     (sizeof (struct section_offsets)
  3236.                      + (sizeof (section_offsets->offsets)
  3237.                     * (SECT_OFF_MAX - 1)))));
  3238.  
  3239.   for (i = 0; i < SECT_OFF_MAX; i++)
  3240.     ANOFFSET (section_offsets, i) = addr;
  3241.  
  3242.   return section_offsets;
  3243. }
  3244.  
  3245. /* Initialization */
  3246.  
  3247. static struct sym_fns ecoff_sym_fns =
  3248. {
  3249.   "ecoff",            /* sym_name: name or name prefix of BFD target type */
  3250.   5,                /* sym_namelen: number of significant sym_name chars */
  3251.   mipscoff_new_init,        /* sym_new_init: init anything gbl to entire symtab */
  3252.   mipscoff_symfile_init,    /* sym_init: read initial info, setup for sym_read() */
  3253.   mipscoff_symfile_read,    /* sym_read: read a symbol file into symtab */
  3254.   mipscoff_symfile_finish,    /* sym_finish: finished with file, cleanup */
  3255.   mipscoff_symfile_offsets,    /* sym_offsets: dummy FIXME til implem sym reloc */
  3256.   NULL                /* next: pointer to next struct sym_fns */
  3257. };
  3258.  
  3259.  
  3260. void
  3261. _initialize_mipsread ()
  3262. {
  3263.   add_symtab_fns (&ecoff_sym_fns);
  3264.  
  3265.   /* Missing basic types */
  3266.  
  3267.   builtin_type_string =
  3268.     init_type (TYPE_CODE_STRING,
  3269.            TARGET_CHAR_BIT / TARGET_CHAR_BIT,
  3270.            0, "string",
  3271.            (struct objfile *) NULL);
  3272.   builtin_type_complex =
  3273.     init_type (TYPE_CODE_FLT,
  3274.            TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
  3275.            0, "complex",
  3276.            (struct objfile *) NULL);
  3277.   builtin_type_double_complex =
  3278.     init_type (TYPE_CODE_FLT,
  3279.            TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
  3280.            0, "double complex",
  3281.            (struct objfile *) NULL);
  3282.   builtin_type_fixed_dec =
  3283.     init_type (TYPE_CODE_INT,
  3284.            TARGET_INT_BIT / TARGET_CHAR_BIT,
  3285.            0, "fixed decimal",
  3286.            (struct objfile *) NULL);
  3287.   builtin_type_float_dec =
  3288.     init_type (TYPE_CODE_FLT,
  3289.            TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
  3290.            0, "floating decimal",
  3291.            (struct objfile *) NULL);
  3292. }
  3293.