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