xref: /dragonfly/contrib/gdb-7/gdb/mdebugread.c (revision ef5ccd6c)
15796c8dcSSimon Schubert /* Read a symbol table in ECOFF format (Third-Eye).
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
65796c8dcSSimon Schubert    CMU.  Major work by Per Bothner, John Gilmore and Ian Lance Taylor
75796c8dcSSimon Schubert    at Cygnus Support.
85796c8dcSSimon Schubert 
95796c8dcSSimon Schubert    This file is part of GDB.
105796c8dcSSimon Schubert 
115796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
125796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
135796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
145796c8dcSSimon Schubert    (at your option) any later version.
155796c8dcSSimon Schubert 
165796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
175796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
185796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
195796c8dcSSimon Schubert    GNU General Public License for more details.
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
225796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
235796c8dcSSimon Schubert 
245796c8dcSSimon Schubert /* This module provides the function mdebug_build_psymtabs.  It reads
255796c8dcSSimon Schubert    ECOFF debugging information into partial symbol tables.  The
265796c8dcSSimon Schubert    debugging information is read from two structures.  A struct
275796c8dcSSimon Schubert    ecoff_debug_swap includes the sizes of each ECOFF structure and
285796c8dcSSimon Schubert    swapping routines; these are fixed for a particular target.  A
295796c8dcSSimon Schubert    struct ecoff_debug_info points to the debugging information for a
305796c8dcSSimon Schubert    particular object file.
315796c8dcSSimon Schubert 
325796c8dcSSimon Schubert    ECOFF symbol tables are mostly written in the byte order of the
335796c8dcSSimon Schubert    target machine.  However, one section of the table (the auxiliary
345796c8dcSSimon Schubert    symbol information) is written in the host byte order.  There is a
355796c8dcSSimon Schubert    bit in the other symbol info which describes which host byte order
365796c8dcSSimon Schubert    was used.  ECOFF thereby takes the trophy from Intel `b.out' for
375796c8dcSSimon Schubert    the most brain-dead adaptation of a file format to byte order.
385796c8dcSSimon Schubert 
395796c8dcSSimon Schubert    This module can read all four of the known byte-order combinations,
405796c8dcSSimon Schubert    on any type of host.  */
415796c8dcSSimon Schubert 
425796c8dcSSimon Schubert #include "defs.h"
435796c8dcSSimon Schubert #include "symtab.h"
445796c8dcSSimon Schubert #include "gdbtypes.h"
455796c8dcSSimon Schubert #include "gdbcore.h"
46c50c785cSJohn Marino #include "filenames.h"
475796c8dcSSimon Schubert #include "objfiles.h"
485796c8dcSSimon Schubert #include "gdb_obstack.h"
495796c8dcSSimon Schubert #include "buildsym.h"
505796c8dcSSimon Schubert #include "stabsread.h"
515796c8dcSSimon Schubert #include "complaints.h"
525796c8dcSSimon Schubert #include "demangle.h"
53a45ae5f8SJohn Marino #include "gdb-demangle.h"
545796c8dcSSimon Schubert #include "gdb_assert.h"
555796c8dcSSimon Schubert #include "block.h"
565796c8dcSSimon Schubert #include "dictionary.h"
575796c8dcSSimon Schubert #include "mdebugread.h"
585796c8dcSSimon Schubert #include "gdb_stat.h"
595796c8dcSSimon Schubert #include "gdb_string.h"
60cf7f2e2dSJohn Marino #include "psympriv.h"
61*ef5ccd6cSJohn Marino #include "source.h"
625796c8dcSSimon Schubert 
635796c8dcSSimon Schubert #include "bfd.h"
645796c8dcSSimon Schubert 
65c50c785cSJohn Marino #include "coff/ecoff.h"		/* COFF-like aspects of ecoff files.  */
665796c8dcSSimon Schubert 
675796c8dcSSimon Schubert #include "libaout.h"		/* Private BFD a.out information.  */
685796c8dcSSimon Schubert #include "aout/aout64.h"
69c50c785cSJohn Marino #include "aout/stab_gnu.h"	/* STABS information.  */
705796c8dcSSimon Schubert 
715796c8dcSSimon Schubert #include "expression.h"
725796c8dcSSimon Schubert 
735796c8dcSSimon Schubert extern void _initialize_mdebugread (void);
745796c8dcSSimon Schubert 
755796c8dcSSimon Schubert /* Provide a way to test if we have both ECOFF and ELF symbol tables.
765796c8dcSSimon Schubert    We use this define in order to know whether we should override a
775796c8dcSSimon Schubert    symbol's ECOFF section with its ELF section.  This is necessary in
785796c8dcSSimon Schubert    case the symbol's ELF section could not be represented in ECOFF.  */
795796c8dcSSimon Schubert #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
805796c8dcSSimon Schubert 			   && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
81a45ae5f8SJohn Marino 
82a45ae5f8SJohn Marino /* The objfile we are currently reading.  */
83a45ae5f8SJohn Marino 
84a45ae5f8SJohn Marino static struct objfile *mdebugread_objfile;
85a45ae5f8SJohn Marino 
865796c8dcSSimon Schubert 
875796c8dcSSimon Schubert 
885796c8dcSSimon Schubert /* We put a pointer to this structure in the read_symtab_private field
895796c8dcSSimon Schubert    of the psymtab.  */
905796c8dcSSimon Schubert 
915796c8dcSSimon Schubert struct symloc
925796c8dcSSimon Schubert   {
935796c8dcSSimon Schubert     /* Index of the FDR that this psymtab represents.  */
945796c8dcSSimon Schubert     int fdr_idx;
955796c8dcSSimon Schubert     /* The BFD that the psymtab was created from.  */
965796c8dcSSimon Schubert     bfd *cur_bfd;
975796c8dcSSimon Schubert     const struct ecoff_debug_swap *debug_swap;
985796c8dcSSimon Schubert     struct ecoff_debug_info *debug_info;
995796c8dcSSimon Schubert     struct mdebug_pending **pending_list;
1005796c8dcSSimon Schubert     /* Pointer to external symbols for this file.  */
1015796c8dcSSimon Schubert     EXTR *extern_tab;
1025796c8dcSSimon Schubert     /* Size of extern_tab.  */
1035796c8dcSSimon Schubert     int extern_count;
1045796c8dcSSimon Schubert     enum language pst_language;
1055796c8dcSSimon Schubert   };
1065796c8dcSSimon Schubert 
1075796c8dcSSimon Schubert #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
1085796c8dcSSimon Schubert #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
1095796c8dcSSimon Schubert #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
1105796c8dcSSimon Schubert #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
1115796c8dcSSimon Schubert #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
1125796c8dcSSimon Schubert #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
1135796c8dcSSimon Schubert 
1145796c8dcSSimon Schubert #define SC_IS_TEXT(sc) ((sc) == scText \
1155796c8dcSSimon Schubert 		   || (sc) == scRConst \
1165796c8dcSSimon Schubert           	   || (sc) == scInit \
1175796c8dcSSimon Schubert           	   || (sc) == scFini)
1185796c8dcSSimon Schubert #define SC_IS_DATA(sc) ((sc) == scData \
1195796c8dcSSimon Schubert 		   || (sc) == scSData \
1205796c8dcSSimon Schubert 		   || (sc) == scRData \
1215796c8dcSSimon Schubert 		   || (sc) == scPData \
1225796c8dcSSimon Schubert 		   || (sc) == scXData)
1235796c8dcSSimon Schubert #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
1245796c8dcSSimon Schubert #define SC_IS_BSS(sc) ((sc) == scBss)
1255796c8dcSSimon Schubert #define SC_IS_SBSS(sc) ((sc) == scSBss)
1265796c8dcSSimon Schubert #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
1275796c8dcSSimon Schubert 
128c50c785cSJohn Marino /* Various complaints about symbol reading that don't abort the process.  */
1295796c8dcSSimon Schubert static void
index_complaint(const char * arg1)1305796c8dcSSimon Schubert index_complaint (const char *arg1)
1315796c8dcSSimon Schubert {
1325796c8dcSSimon Schubert   complaint (&symfile_complaints, _("bad aux index at symbol %s"), arg1);
1335796c8dcSSimon Schubert }
1345796c8dcSSimon Schubert 
1355796c8dcSSimon Schubert static void
unknown_ext_complaint(const char * arg1)1365796c8dcSSimon Schubert unknown_ext_complaint (const char *arg1)
1375796c8dcSSimon Schubert {
1385796c8dcSSimon Schubert   complaint (&symfile_complaints, _("unknown external symbol %s"), arg1);
1395796c8dcSSimon Schubert }
1405796c8dcSSimon Schubert 
1415796c8dcSSimon Schubert static void
basic_type_complaint(int arg1,const char * arg2)1425796c8dcSSimon Schubert basic_type_complaint (int arg1, const char *arg2)
1435796c8dcSSimon Schubert {
1445796c8dcSSimon Schubert   complaint (&symfile_complaints, _("cannot map ECOFF basic type 0x%x for %s"),
1455796c8dcSSimon Schubert 	     arg1, arg2);
1465796c8dcSSimon Schubert }
1475796c8dcSSimon Schubert 
1485796c8dcSSimon Schubert static void
bad_tag_guess_complaint(const char * arg1)1495796c8dcSSimon Schubert bad_tag_guess_complaint (const char *arg1)
1505796c8dcSSimon Schubert {
151c50c785cSJohn Marino   complaint (&symfile_complaints,
152c50c785cSJohn Marino 	     _("guessed tag type of %s incorrectly"), arg1);
1535796c8dcSSimon Schubert }
1545796c8dcSSimon Schubert 
1555796c8dcSSimon Schubert static void
bad_rfd_entry_complaint(const char * arg1,int arg2,int arg3)1565796c8dcSSimon Schubert bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3)
1575796c8dcSSimon Schubert {
1585796c8dcSSimon Schubert   complaint (&symfile_complaints, _("bad rfd entry for %s: file %d, index %d"),
1595796c8dcSSimon Schubert 	     arg1, arg2, arg3);
1605796c8dcSSimon Schubert }
1615796c8dcSSimon Schubert 
1625796c8dcSSimon Schubert static void
unexpected_type_code_complaint(const char * arg1)1635796c8dcSSimon Schubert unexpected_type_code_complaint (const char *arg1)
1645796c8dcSSimon Schubert {
1655796c8dcSSimon Schubert   complaint (&symfile_complaints, _("unexpected type code for %s"), arg1);
1665796c8dcSSimon Schubert }
1675796c8dcSSimon Schubert 
168c50c785cSJohn Marino /* Macros and extra defs.  */
1695796c8dcSSimon Schubert 
170c50c785cSJohn Marino /* Puns: hard to find whether -g was used and how.  */
1715796c8dcSSimon Schubert 
1725796c8dcSSimon Schubert #define MIN_GLEVEL GLEVEL_0
1735796c8dcSSimon Schubert #define compare_glevel(a,b)					\
1745796c8dcSSimon Schubert 	(((a) == GLEVEL_3) ? ((b) < GLEVEL_3) :			\
1755796c8dcSSimon Schubert 	 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
1765796c8dcSSimon Schubert 
177c50c785cSJohn Marino /* Things that really are local to this module.  */
1785796c8dcSSimon Schubert 
1795796c8dcSSimon Schubert /* Remember what we deduced to be the source language of this psymtab.  */
1805796c8dcSSimon Schubert 
1815796c8dcSSimon Schubert static enum language psymtab_language = language_unknown;
1825796c8dcSSimon Schubert 
1835796c8dcSSimon Schubert /* Current BFD.  */
1845796c8dcSSimon Schubert 
1855796c8dcSSimon Schubert static bfd *cur_bfd;
1865796c8dcSSimon Schubert 
1875796c8dcSSimon Schubert /* How to parse debugging information for CUR_BFD.  */
1885796c8dcSSimon Schubert 
1895796c8dcSSimon Schubert static const struct ecoff_debug_swap *debug_swap;
1905796c8dcSSimon Schubert 
1915796c8dcSSimon Schubert /* Pointers to debugging information for CUR_BFD.  */
1925796c8dcSSimon Schubert 
1935796c8dcSSimon Schubert static struct ecoff_debug_info *debug_info;
1945796c8dcSSimon Schubert 
195c50c785cSJohn Marino /* Pointer to current file decriptor record, and its index.  */
1965796c8dcSSimon Schubert 
1975796c8dcSSimon Schubert static FDR *cur_fdr;
1985796c8dcSSimon Schubert static int cur_fd;
1995796c8dcSSimon Schubert 
200c50c785cSJohn Marino /* Index of current symbol.  */
2015796c8dcSSimon Schubert 
2025796c8dcSSimon Schubert static int cur_sdx;
2035796c8dcSSimon Schubert 
2045796c8dcSSimon Schubert /* Note how much "debuggable" this image is.  We would like
205c50c785cSJohn Marino    to see at least one FDR with full symbols.  */
2065796c8dcSSimon Schubert 
2075796c8dcSSimon Schubert static int max_gdbinfo;
2085796c8dcSSimon Schubert static int max_glevel;
2095796c8dcSSimon Schubert 
210c50c785cSJohn Marino /* When examining .o files, report on undefined symbols.  */
2115796c8dcSSimon Schubert 
2125796c8dcSSimon Schubert static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
2135796c8dcSSimon Schubert 
2145796c8dcSSimon Schubert /* Pseudo symbol to use when putting stabs into the symbol table.  */
2155796c8dcSSimon Schubert 
2165796c8dcSSimon Schubert static char stabs_symbol[] = STABS_SYMBOL;
2175796c8dcSSimon Schubert 
2185796c8dcSSimon Schubert /* Nonzero if we have seen ecoff debugging info for a file.  */
2195796c8dcSSimon Schubert 
2205796c8dcSSimon Schubert static int found_ecoff_debugging_info;
2215796c8dcSSimon Schubert 
222c50c785cSJohn Marino /* Forward declarations.  */
2235796c8dcSSimon Schubert 
2245796c8dcSSimon Schubert static int upgrade_type (int, struct type **, int, union aux_ext *,
2255796c8dcSSimon Schubert 			 int, char *);
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert static void parse_partial_symbols (struct objfile *);
2285796c8dcSSimon Schubert 
2295796c8dcSSimon Schubert static int has_opaque_xref (FDR *, SYMR *);
2305796c8dcSSimon Schubert 
2315796c8dcSSimon Schubert static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
2325796c8dcSSimon Schubert 		      char **, int, char *);
2335796c8dcSSimon Schubert 
2345796c8dcSSimon Schubert static struct symbol *new_symbol (char *);
2355796c8dcSSimon Schubert 
2365796c8dcSSimon Schubert static struct type *new_type (char *);
2375796c8dcSSimon Schubert 
2385796c8dcSSimon Schubert enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
2395796c8dcSSimon Schubert 
2405796c8dcSSimon Schubert static struct block *new_block (enum block_type);
2415796c8dcSSimon Schubert 
242c50c785cSJohn Marino static struct symtab *new_symtab (const char *, int, struct objfile *);
2435796c8dcSSimon Schubert 
2445796c8dcSSimon Schubert static struct linetable *new_linetable (int);
2455796c8dcSSimon Schubert 
2465796c8dcSSimon Schubert static struct blockvector *new_bvect (int);
2475796c8dcSSimon Schubert 
2485796c8dcSSimon Schubert static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
2495796c8dcSSimon Schubert 				int, char *);
2505796c8dcSSimon Schubert 
2515796c8dcSSimon Schubert static struct symbol *mylookup_symbol (char *, struct block *, domain_enum,
2525796c8dcSSimon Schubert 				       enum address_class);
2535796c8dcSSimon Schubert 
2545796c8dcSSimon Schubert static void sort_blocks (struct symtab *);
2555796c8dcSSimon Schubert 
2565796c8dcSSimon Schubert static struct partial_symtab *new_psymtab (char *, struct objfile *);
2575796c8dcSSimon Schubert 
258*ef5ccd6cSJohn Marino static void psymtab_to_symtab_1 (struct objfile *objfile,
259*ef5ccd6cSJohn Marino 				 struct partial_symtab *, const char *);
2605796c8dcSSimon Schubert 
2615796c8dcSSimon Schubert static void add_block (struct block *, struct symtab *);
2625796c8dcSSimon Schubert 
2635796c8dcSSimon Schubert static void add_symbol (struct symbol *, struct symtab *, struct block *);
2645796c8dcSSimon Schubert 
2655796c8dcSSimon Schubert static int add_line (struct linetable *, int, CORE_ADDR, int);
2665796c8dcSSimon Schubert 
2675796c8dcSSimon Schubert static struct linetable *shrink_linetable (struct linetable *);
2685796c8dcSSimon Schubert 
2695796c8dcSSimon Schubert static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
2705796c8dcSSimon Schubert 					CORE_ADDR);
2715796c8dcSSimon Schubert 
2725796c8dcSSimon Schubert static char *mdebug_next_symbol_text (struct objfile *);
2735796c8dcSSimon Schubert 
274*ef5ccd6cSJohn Marino /* Exported procedure: Builds a symtab from the partial symtab SELF.
275*ef5ccd6cSJohn Marino    Restores the environment in effect when SELF was created, delegates
2765796c8dcSSimon Schubert    most of the work to an ancillary procedure, and sorts
277*ef5ccd6cSJohn Marino    and reorders the symtab list at the end.  SELF is not NULL.  */
2785796c8dcSSimon Schubert 
2795796c8dcSSimon Schubert static void
mdebug_read_symtab(struct partial_symtab * self,struct objfile * objfile)280*ef5ccd6cSJohn Marino mdebug_read_symtab (struct partial_symtab *self, struct objfile *objfile)
2815796c8dcSSimon Schubert {
2825796c8dcSSimon Schubert   if (info_verbose)
2835796c8dcSSimon Schubert     {
284*ef5ccd6cSJohn Marino       printf_filtered (_("Reading in symbols for %s..."), self->filename);
2855796c8dcSSimon Schubert       gdb_flush (gdb_stdout);
2865796c8dcSSimon Schubert     }
2875796c8dcSSimon Schubert 
2885796c8dcSSimon Schubert   next_symbol_text_func = mdebug_next_symbol_text;
2895796c8dcSSimon Schubert 
290*ef5ccd6cSJohn Marino   psymtab_to_symtab_1 (objfile, self, self->filename);
2915796c8dcSSimon Schubert 
2925796c8dcSSimon Schubert   /* Match with global symbols.  This only needs to be done once,
2935796c8dcSSimon Schubert      after all of the symtabs and dependencies have been read in.  */
294*ef5ccd6cSJohn Marino   scan_file_globals (objfile);
2955796c8dcSSimon Schubert 
2965796c8dcSSimon Schubert   if (info_verbose)
2975796c8dcSSimon Schubert     printf_filtered (_("done.\n"));
2985796c8dcSSimon Schubert }
2995796c8dcSSimon Schubert 
300c50c785cSJohn Marino /* File-level interface functions.  */
3015796c8dcSSimon Schubert 
302c50c785cSJohn Marino /* Find a file descriptor given its index RF relative to a file CF.  */
3035796c8dcSSimon Schubert 
3045796c8dcSSimon Schubert static FDR *
get_rfd(int cf,int rf)3055796c8dcSSimon Schubert get_rfd (int cf, int rf)
3065796c8dcSSimon Schubert {
3075796c8dcSSimon Schubert   FDR *fdrs;
3085796c8dcSSimon Schubert   FDR *f;
3095796c8dcSSimon Schubert   RFDT rfd;
3105796c8dcSSimon Schubert 
3115796c8dcSSimon Schubert   fdrs = debug_info->fdr;
3125796c8dcSSimon Schubert   f = fdrs + cf;
313c50c785cSJohn Marino   /* Object files do not have the RFD table, all refs are absolute.  */
3145796c8dcSSimon Schubert   if (f->rfdBase == 0)
3155796c8dcSSimon Schubert     return fdrs + rf;
3165796c8dcSSimon Schubert   (*debug_swap->swap_rfd_in) (cur_bfd,
3175796c8dcSSimon Schubert 			      ((char *) debug_info->external_rfd
3185796c8dcSSimon Schubert 			       + ((f->rfdBase + rf)
3195796c8dcSSimon Schubert 				  * debug_swap->external_rfd_size)),
3205796c8dcSSimon Schubert 			      &rfd);
3215796c8dcSSimon Schubert   return fdrs + rfd;
3225796c8dcSSimon Schubert }
3235796c8dcSSimon Schubert 
324c50c785cSJohn Marino /* Return a safer print NAME for a file descriptor.  */
3255796c8dcSSimon Schubert 
3265796c8dcSSimon Schubert static char *
fdr_name(FDR * f)3275796c8dcSSimon Schubert fdr_name (FDR *f)
3285796c8dcSSimon Schubert {
3295796c8dcSSimon Schubert   if (f->rss == -1)
3305796c8dcSSimon Schubert     return "<stripped file>";
3315796c8dcSSimon Schubert   if (f->rss == 0)
3325796c8dcSSimon Schubert     return "<NFY>";
3335796c8dcSSimon Schubert   return debug_info->ss + f->issBase + f->rss;
3345796c8dcSSimon Schubert }
3355796c8dcSSimon Schubert 
3365796c8dcSSimon Schubert 
3375796c8dcSSimon Schubert /* Read in and parse the symtab of the file OBJFILE.  Symbols from
3385796c8dcSSimon Schubert    different sections are relocated via the SECTION_OFFSETS.  */
3395796c8dcSSimon Schubert 
3405796c8dcSSimon Schubert void
mdebug_build_psymtabs(struct objfile * objfile,const struct ecoff_debug_swap * swap,struct ecoff_debug_info * info)3415796c8dcSSimon Schubert mdebug_build_psymtabs (struct objfile *objfile,
3425796c8dcSSimon Schubert 		       const struct ecoff_debug_swap *swap,
3435796c8dcSSimon Schubert 		       struct ecoff_debug_info *info)
3445796c8dcSSimon Schubert {
3455796c8dcSSimon Schubert   cur_bfd = objfile->obfd;
3465796c8dcSSimon Schubert   debug_swap = swap;
3475796c8dcSSimon Schubert   debug_info = info;
3485796c8dcSSimon Schubert 
3495796c8dcSSimon Schubert   stabsread_new_init ();
3505796c8dcSSimon Schubert   buildsym_new_init ();
3515796c8dcSSimon Schubert   free_header_files ();
3525796c8dcSSimon Schubert   init_header_files ();
3535796c8dcSSimon Schubert 
3545796c8dcSSimon Schubert   /* Make sure all the FDR information is swapped in.  */
3555796c8dcSSimon Schubert   if (info->fdr == (FDR *) NULL)
3565796c8dcSSimon Schubert     {
3575796c8dcSSimon Schubert       char *fdr_src;
3585796c8dcSSimon Schubert       char *fdr_end;
3595796c8dcSSimon Schubert       FDR *fdr_ptr;
3605796c8dcSSimon Schubert 
3615796c8dcSSimon Schubert       info->fdr = (FDR *) obstack_alloc (&objfile->objfile_obstack,
3625796c8dcSSimon Schubert 					 (info->symbolic_header.ifdMax
3635796c8dcSSimon Schubert 					  * sizeof (FDR)));
3645796c8dcSSimon Schubert       fdr_src = info->external_fdr;
3655796c8dcSSimon Schubert       fdr_end = (fdr_src
3665796c8dcSSimon Schubert 		 + info->symbolic_header.ifdMax * swap->external_fdr_size);
3675796c8dcSSimon Schubert       fdr_ptr = info->fdr;
3685796c8dcSSimon Schubert       for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
3695796c8dcSSimon Schubert 	(*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
3705796c8dcSSimon Schubert     }
3715796c8dcSSimon Schubert 
3725796c8dcSSimon Schubert   parse_partial_symbols (objfile);
3735796c8dcSSimon Schubert 
3745796c8dcSSimon Schubert #if 0
3755796c8dcSSimon Schubert   /* Check to make sure file was compiled with -g.  If not, warn the
3765796c8dcSSimon Schubert      user of this limitation.  */
3775796c8dcSSimon Schubert   if (compare_glevel (max_glevel, GLEVEL_2) < 0)
3785796c8dcSSimon Schubert     {
3795796c8dcSSimon Schubert       if (max_gdbinfo == 0)
380c50c785cSJohn Marino 	printf_unfiltered (_("\n%s not compiled with -g, "
381c50c785cSJohn Marino 			     "debugging support is limited.\n"),
3825796c8dcSSimon Schubert 			   objfile->name);
383c50c785cSJohn Marino       printf_unfiltered (_("You should compile with -g2 or "
384c50c785cSJohn Marino 			   "-g3 for best debugging support.\n"));
3855796c8dcSSimon Schubert       gdb_flush (gdb_stdout);
3865796c8dcSSimon Schubert     }
3875796c8dcSSimon Schubert #endif
3885796c8dcSSimon Schubert }
3895796c8dcSSimon Schubert 
3905796c8dcSSimon Schubert /* Local utilities */
3915796c8dcSSimon Schubert 
392c50c785cSJohn Marino /* Map of FDR indexes to partial symtabs.  */
3935796c8dcSSimon Schubert 
3945796c8dcSSimon Schubert struct pst_map
3955796c8dcSSimon Schubert {
3965796c8dcSSimon Schubert   struct partial_symtab *pst;	/* the psymtab proper */
3975796c8dcSSimon Schubert   long n_globals;		/* exported globals (external symbols) */
3985796c8dcSSimon Schubert   long globals_offset;		/* cumulative */
3995796c8dcSSimon Schubert };
4005796c8dcSSimon Schubert 
4015796c8dcSSimon Schubert 
4025796c8dcSSimon Schubert /* Utility stack, used to nest procedures and blocks properly.
4035796c8dcSSimon Schubert    It is a doubly linked list, to avoid too many alloc/free.
4045796c8dcSSimon Schubert    Since we might need it quite a few times it is NOT deallocated
4055796c8dcSSimon Schubert    after use.  */
4065796c8dcSSimon Schubert 
4075796c8dcSSimon Schubert static struct parse_stack
4085796c8dcSSimon Schubert   {
4095796c8dcSSimon Schubert     struct parse_stack *next, *prev;
4105796c8dcSSimon Schubert     struct symtab *cur_st;	/* Current symtab.  */
4115796c8dcSSimon Schubert     struct block *cur_block;	/* Block in it.  */
4125796c8dcSSimon Schubert 
4135796c8dcSSimon Schubert     /* What are we parsing.  stFile, or stBlock are for files and
4145796c8dcSSimon Schubert        blocks.  stProc or stStaticProc means we have seen the start of a
4155796c8dcSSimon Schubert        procedure, but not the start of the block within in.  When we see
4165796c8dcSSimon Schubert        the start of that block, we change it to stNil, without pushing a
4175796c8dcSSimon Schubert        new block, i.e. stNil means both a procedure and a block.  */
4185796c8dcSSimon Schubert 
4195796c8dcSSimon Schubert     int blocktype;
4205796c8dcSSimon Schubert 
4215796c8dcSSimon Schubert     struct type *cur_type;	/* Type we parse fields for.  */
4225796c8dcSSimon Schubert     int cur_field;		/* Field number in cur_type.  */
423c50c785cSJohn Marino     CORE_ADDR procadr;		/* Start addres of this procedure.  */
424c50c785cSJohn Marino     int numargs;		/* Its argument count.  */
4255796c8dcSSimon Schubert   }
4265796c8dcSSimon Schubert 
4275796c8dcSSimon Schubert  *top_stack;			/* Top stack ptr */
4285796c8dcSSimon Schubert 
4295796c8dcSSimon Schubert 
430c50c785cSJohn Marino /* Enter a new lexical context.  */
4315796c8dcSSimon Schubert 
4325796c8dcSSimon Schubert static void
push_parse_stack(void)4335796c8dcSSimon Schubert push_parse_stack (void)
4345796c8dcSSimon Schubert {
4355796c8dcSSimon Schubert   struct parse_stack *new;
4365796c8dcSSimon Schubert 
437c50c785cSJohn Marino   /* Reuse frames if possible.  */
4385796c8dcSSimon Schubert   if (top_stack && top_stack->prev)
4395796c8dcSSimon Schubert     new = top_stack->prev;
4405796c8dcSSimon Schubert   else
4415796c8dcSSimon Schubert     new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
442c50c785cSJohn Marino   /* Initialize new frame with previous content.  */
4435796c8dcSSimon Schubert   if (top_stack)
4445796c8dcSSimon Schubert     {
4455796c8dcSSimon Schubert       struct parse_stack *prev = new->prev;
4465796c8dcSSimon Schubert 
4475796c8dcSSimon Schubert       *new = *top_stack;
4485796c8dcSSimon Schubert       top_stack->prev = new;
4495796c8dcSSimon Schubert       new->prev = prev;
4505796c8dcSSimon Schubert       new->next = top_stack;
4515796c8dcSSimon Schubert     }
4525796c8dcSSimon Schubert   top_stack = new;
4535796c8dcSSimon Schubert }
4545796c8dcSSimon Schubert 
455c50c785cSJohn Marino /* Exit a lexical context.  */
4565796c8dcSSimon Schubert 
4575796c8dcSSimon Schubert static void
pop_parse_stack(void)4585796c8dcSSimon Schubert pop_parse_stack (void)
4595796c8dcSSimon Schubert {
4605796c8dcSSimon Schubert   if (!top_stack)
4615796c8dcSSimon Schubert     return;
4625796c8dcSSimon Schubert   if (top_stack->next)
4635796c8dcSSimon Schubert     top_stack = top_stack->next;
4645796c8dcSSimon Schubert }
4655796c8dcSSimon Schubert 
4665796c8dcSSimon Schubert 
4675796c8dcSSimon Schubert /* Cross-references might be to things we haven't looked at
4685796c8dcSSimon Schubert    yet, e.g. type references.  To avoid too many type
4695796c8dcSSimon Schubert    duplications we keep a quick fixup table, an array
470c50c785cSJohn Marino    of lists of references indexed by file descriptor.  */
4715796c8dcSSimon Schubert 
4725796c8dcSSimon Schubert struct mdebug_pending
4735796c8dcSSimon Schubert {
4745796c8dcSSimon Schubert   struct mdebug_pending *next;	/* link */
4755796c8dcSSimon Schubert   char *s;			/* the unswapped symbol */
4765796c8dcSSimon Schubert   struct type *t;		/* its partial type descriptor */
4775796c8dcSSimon Schubert };
4785796c8dcSSimon Schubert 
4795796c8dcSSimon Schubert 
480*ef5ccd6cSJohn Marino /* The pending information is kept for an entire object file.  We
481*ef5ccd6cSJohn Marino    allocate the pending information table when we create the partial
482*ef5ccd6cSJohn Marino    symbols, and we store a pointer to the single table in each
483*ef5ccd6cSJohn Marino    psymtab.  */
4845796c8dcSSimon Schubert 
4855796c8dcSSimon Schubert static struct mdebug_pending **pending_list;
4865796c8dcSSimon Schubert 
487c50c785cSJohn Marino /* Check whether we already saw symbol SH in file FH.  */
4885796c8dcSSimon Schubert 
4895796c8dcSSimon Schubert static struct mdebug_pending *
is_pending_symbol(FDR * fh,char * sh)4905796c8dcSSimon Schubert is_pending_symbol (FDR *fh, char *sh)
4915796c8dcSSimon Schubert {
4925796c8dcSSimon Schubert   int f_idx = fh - debug_info->fdr;
4935796c8dcSSimon Schubert   struct mdebug_pending *p;
4945796c8dcSSimon Schubert 
495c50c785cSJohn Marino   /* Linear search is ok, list is typically no more than 10 deep.  */
4965796c8dcSSimon Schubert   for (p = pending_list[f_idx]; p; p = p->next)
4975796c8dcSSimon Schubert     if (p->s == sh)
4985796c8dcSSimon Schubert       break;
4995796c8dcSSimon Schubert   return p;
5005796c8dcSSimon Schubert }
5015796c8dcSSimon Schubert 
502c50c785cSJohn Marino /* Add a new symbol SH of type T.  */
5035796c8dcSSimon Schubert 
5045796c8dcSSimon Schubert static void
add_pending(FDR * fh,char * sh,struct type * t)5055796c8dcSSimon Schubert add_pending (FDR *fh, char *sh, struct type *t)
5065796c8dcSSimon Schubert {
5075796c8dcSSimon Schubert   int f_idx = fh - debug_info->fdr;
5085796c8dcSSimon Schubert   struct mdebug_pending *p = is_pending_symbol (fh, sh);
5095796c8dcSSimon Schubert 
510c50c785cSJohn Marino   /* Make sure we do not make duplicates.  */
5115796c8dcSSimon Schubert   if (!p)
5125796c8dcSSimon Schubert     {
5135796c8dcSSimon Schubert       p = ((struct mdebug_pending *)
514a45ae5f8SJohn Marino 	   obstack_alloc (&mdebugread_objfile->objfile_obstack,
5155796c8dcSSimon Schubert 			  sizeof (struct mdebug_pending)));
5165796c8dcSSimon Schubert       p->s = sh;
5175796c8dcSSimon Schubert       p->t = t;
5185796c8dcSSimon Schubert       p->next = pending_list[f_idx];
5195796c8dcSSimon Schubert       pending_list[f_idx] = p;
5205796c8dcSSimon Schubert     }
5215796c8dcSSimon Schubert }
5225796c8dcSSimon Schubert 
5235796c8dcSSimon Schubert 
5245796c8dcSSimon Schubert /* Parsing Routines proper.  */
5255796c8dcSSimon Schubert 
5265796c8dcSSimon Schubert /* Parse a single symbol.  Mostly just make up a GDB symbol for it.
5275796c8dcSSimon Schubert    For blocks, procedures and types we open a new lexical context.
5285796c8dcSSimon Schubert    This is basically just a big switch on the symbol's type.  Argument
5295796c8dcSSimon Schubert    AX is the base pointer of aux symbols for this file (fh->iauxBase).
5305796c8dcSSimon Schubert    EXT_SH points to the unswapped symbol, which is needed for struct,
5315796c8dcSSimon Schubert    union, etc., types; it is NULL for an EXTR.  BIGEND says whether
5325796c8dcSSimon Schubert    aux symbols are big-endian or little-endian.  Return count of
5335796c8dcSSimon Schubert    SYMR's handled (normally one).  */
5345796c8dcSSimon Schubert 
5355796c8dcSSimon Schubert static int
mdebug_reg_to_regnum(struct symbol * sym,struct gdbarch * gdbarch)5365796c8dcSSimon Schubert mdebug_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
5375796c8dcSSimon Schubert {
5385796c8dcSSimon Schubert   return gdbarch_ecoff_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
5395796c8dcSSimon Schubert }
5405796c8dcSSimon Schubert 
5415796c8dcSSimon Schubert static const struct symbol_register_ops mdebug_register_funcs = {
5425796c8dcSSimon Schubert   mdebug_reg_to_regnum
5435796c8dcSSimon Schubert };
5445796c8dcSSimon Schubert 
5455796c8dcSSimon Schubert static int
parse_symbol(SYMR * sh,union aux_ext * ax,char * ext_sh,int bigend,struct section_offsets * section_offsets,struct objfile * objfile)5465796c8dcSSimon Schubert parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
5475796c8dcSSimon Schubert 	      struct section_offsets *section_offsets, struct objfile *objfile)
5485796c8dcSSimon Schubert {
5495796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
5505796c8dcSSimon Schubert   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
5515796c8dcSSimon Schubert   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
5525796c8dcSSimon Schubert   char *name;
5535796c8dcSSimon Schubert   struct symbol *s;
5545796c8dcSSimon Schubert   struct block *b;
5555796c8dcSSimon Schubert   struct mdebug_pending *pend;
5565796c8dcSSimon Schubert   struct type *t;
5575796c8dcSSimon Schubert   struct field *f;
5585796c8dcSSimon Schubert   int count = 1;
5595796c8dcSSimon Schubert   enum address_class class;
5605796c8dcSSimon Schubert   TIR tir;
5615796c8dcSSimon Schubert   long svalue = sh->value;
5625796c8dcSSimon Schubert   int bitsize;
5635796c8dcSSimon Schubert 
5645796c8dcSSimon Schubert   if (ext_sh == (char *) NULL)
5655796c8dcSSimon Schubert     name = debug_info->ssext + sh->iss;
5665796c8dcSSimon Schubert   else
5675796c8dcSSimon Schubert     name = debug_info->ss + cur_fdr->issBase + sh->iss;
5685796c8dcSSimon Schubert 
5695796c8dcSSimon Schubert   switch (sh->sc)
5705796c8dcSSimon Schubert     {
5715796c8dcSSimon Schubert     case scText:
5725796c8dcSSimon Schubert     case scRConst:
5735796c8dcSSimon Schubert       /* Do not relocate relative values.
5745796c8dcSSimon Schubert          The value of a stEnd symbol is the displacement from the
5755796c8dcSSimon Schubert          corresponding start symbol value.
5765796c8dcSSimon Schubert          The value of a stBlock symbol is the displacement from the
5775796c8dcSSimon Schubert          procedure address.  */
5785796c8dcSSimon Schubert       if (sh->st != stEnd && sh->st != stBlock)
5795796c8dcSSimon Schubert 	sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
5805796c8dcSSimon Schubert       break;
5815796c8dcSSimon Schubert     case scData:
5825796c8dcSSimon Schubert     case scSData:
5835796c8dcSSimon Schubert     case scRData:
5845796c8dcSSimon Schubert     case scPData:
5855796c8dcSSimon Schubert     case scXData:
5865796c8dcSSimon Schubert       sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
5875796c8dcSSimon Schubert       break;
5885796c8dcSSimon Schubert     case scBss:
5895796c8dcSSimon Schubert     case scSBss:
5905796c8dcSSimon Schubert       sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
5915796c8dcSSimon Schubert       break;
5925796c8dcSSimon Schubert     }
5935796c8dcSSimon Schubert 
5945796c8dcSSimon Schubert   switch (sh->st)
5955796c8dcSSimon Schubert     {
5965796c8dcSSimon Schubert     case stNil:
5975796c8dcSSimon Schubert       break;
5985796c8dcSSimon Schubert 
599c50c785cSJohn Marino     case stGlobal:		/* External symbol, goes into global block.  */
6005796c8dcSSimon Schubert       class = LOC_STATIC;
6015796c8dcSSimon Schubert       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
6025796c8dcSSimon Schubert 			     GLOBAL_BLOCK);
6035796c8dcSSimon Schubert       s = new_symbol (name);
6045796c8dcSSimon Schubert       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
6055796c8dcSSimon Schubert       goto data;
6065796c8dcSSimon Schubert 
607c50c785cSJohn Marino     case stStatic:		/* Static data, goes into current block.  */
6085796c8dcSSimon Schubert       class = LOC_STATIC;
6095796c8dcSSimon Schubert       b = top_stack->cur_block;
6105796c8dcSSimon Schubert       s = new_symbol (name);
6115796c8dcSSimon Schubert       if (SC_IS_COMMON (sh->sc))
6125796c8dcSSimon Schubert 	{
6135796c8dcSSimon Schubert 	  /* It is a FORTRAN common block.  At least for SGI Fortran the
6145796c8dcSSimon Schubert 	     address is not in the symbol; we need to fix it later in
6155796c8dcSSimon Schubert 	     scan_file_globals.  */
6165796c8dcSSimon Schubert 	  int bucket = hashname (SYMBOL_LINKAGE_NAME (s));
6175796c8dcSSimon Schubert 	  SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
6185796c8dcSSimon Schubert 	  global_sym_chain[bucket] = s;
6195796c8dcSSimon Schubert 	}
6205796c8dcSSimon Schubert       else
6215796c8dcSSimon Schubert 	SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
6225796c8dcSSimon Schubert       goto data;
6235796c8dcSSimon Schubert 
624c50c785cSJohn Marino     case stLocal:		/* Local variable, goes into current block.  */
6255796c8dcSSimon Schubert       b = top_stack->cur_block;
6265796c8dcSSimon Schubert       s = new_symbol (name);
6275796c8dcSSimon Schubert       SYMBOL_VALUE (s) = svalue;
6285796c8dcSSimon Schubert       if (sh->sc == scRegister)
6295796c8dcSSimon Schubert 	{
6305796c8dcSSimon Schubert 	  class = LOC_REGISTER;
6315796c8dcSSimon Schubert 	  SYMBOL_REGISTER_OPS (s) = &mdebug_register_funcs;
6325796c8dcSSimon Schubert 	}
6335796c8dcSSimon Schubert       else
6345796c8dcSSimon Schubert 	class = LOC_LOCAL;
6355796c8dcSSimon Schubert 
636c50c785cSJohn Marino     data:			/* Common code for symbols describing data.  */
6375796c8dcSSimon Schubert       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
6385796c8dcSSimon Schubert       SYMBOL_CLASS (s) = class;
6395796c8dcSSimon Schubert       add_symbol (s, top_stack->cur_st, b);
6405796c8dcSSimon Schubert 
6415796c8dcSSimon Schubert       /* Type could be missing if file is compiled without debugging info.  */
6425796c8dcSSimon Schubert       if (SC_IS_UNDEF (sh->sc)
6435796c8dcSSimon Schubert 	  || sh->sc == scNil || sh->index == indexNil)
6445796c8dcSSimon Schubert 	SYMBOL_TYPE (s) = objfile_type (objfile)->nodebug_data_symbol;
6455796c8dcSSimon Schubert       else
6465796c8dcSSimon Schubert 	SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
647c50c785cSJohn Marino       /* Value of a data symbol is its memory address.  */
6485796c8dcSSimon Schubert       break;
6495796c8dcSSimon Schubert 
650c50c785cSJohn Marino     case stParam:		/* Arg to procedure, goes into current
651c50c785cSJohn Marino 				   block.  */
6525796c8dcSSimon Schubert       max_gdbinfo++;
6535796c8dcSSimon Schubert       found_ecoff_debugging_info = 1;
6545796c8dcSSimon Schubert       top_stack->numargs++;
6555796c8dcSSimon Schubert 
6565796c8dcSSimon Schubert       /* Special GNU C++ name.  */
6575796c8dcSSimon Schubert       if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
658c50c785cSJohn Marino 	name = "this";		/* FIXME, not alloc'd in obstack.  */
6595796c8dcSSimon Schubert       s = new_symbol (name);
6605796c8dcSSimon Schubert 
6615796c8dcSSimon Schubert       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
6625796c8dcSSimon Schubert       SYMBOL_IS_ARGUMENT (s) = 1;
6635796c8dcSSimon Schubert       switch (sh->sc)
6645796c8dcSSimon Schubert 	{
6655796c8dcSSimon Schubert 	case scRegister:
6665796c8dcSSimon Schubert 	  /* Pass by value in register.  */
6675796c8dcSSimon Schubert 	  SYMBOL_CLASS (s) = LOC_REGISTER;
6685796c8dcSSimon Schubert 	  SYMBOL_REGISTER_OPS (s) = &mdebug_register_funcs;
6695796c8dcSSimon Schubert 	  break;
6705796c8dcSSimon Schubert 	case scVar:
6715796c8dcSSimon Schubert 	  /* Pass by reference on stack.  */
6725796c8dcSSimon Schubert 	  SYMBOL_CLASS (s) = LOC_REF_ARG;
6735796c8dcSSimon Schubert 	  break;
6745796c8dcSSimon Schubert 	case scVarRegister:
6755796c8dcSSimon Schubert 	  /* Pass by reference in register.  */
6765796c8dcSSimon Schubert 	  SYMBOL_CLASS (s) = LOC_REGPARM_ADDR;
6775796c8dcSSimon Schubert 	  SYMBOL_REGISTER_OPS (s) = &mdebug_register_funcs;
6785796c8dcSSimon Schubert 	  break;
6795796c8dcSSimon Schubert 	default:
6805796c8dcSSimon Schubert 	  /* Pass by value on stack.  */
6815796c8dcSSimon Schubert 	  SYMBOL_CLASS (s) = LOC_ARG;
6825796c8dcSSimon Schubert 	  break;
6835796c8dcSSimon Schubert 	}
6845796c8dcSSimon Schubert       SYMBOL_VALUE (s) = svalue;
6855796c8dcSSimon Schubert       SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
6865796c8dcSSimon Schubert       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
6875796c8dcSSimon Schubert       break;
6885796c8dcSSimon Schubert 
689c50c785cSJohn Marino     case stLabel:		/* label, goes into current block.  */
6905796c8dcSSimon Schubert       s = new_symbol (name);
691c50c785cSJohn Marino       SYMBOL_DOMAIN (s) = VAR_DOMAIN;	/* So that it can be used */
692c50c785cSJohn Marino       SYMBOL_CLASS (s) = LOC_LABEL;	/* but not misused.  */
6935796c8dcSSimon Schubert       SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
6945796c8dcSSimon Schubert       SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_int;
6955796c8dcSSimon Schubert       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
6965796c8dcSSimon Schubert       break;
6975796c8dcSSimon Schubert 
698c50c785cSJohn Marino     case stProc:	/* Procedure, usually goes into global block.  */
699c50c785cSJohn Marino     case stStaticProc:	/* Static procedure, goes into current block.  */
7005796c8dcSSimon Schubert       /* For stProc symbol records, we need to check the storage class
7015796c8dcSSimon Schubert          as well, as only (stProc, scText) entries represent "real"
7025796c8dcSSimon Schubert          procedures - See the Compaq document titled "Object File /
7035796c8dcSSimon Schubert          Symbol Table Format Specification" for more information.
7045796c8dcSSimon Schubert          If the storage class is not scText, we discard the whole block
7055796c8dcSSimon Schubert          of symbol records for this stProc.  */
7065796c8dcSSimon Schubert       if (sh->st == stProc && sh->sc != scText)
7075796c8dcSSimon Schubert         {
7085796c8dcSSimon Schubert           char *ext_tsym = ext_sh;
7095796c8dcSSimon Schubert           int keep_counting = 1;
7105796c8dcSSimon Schubert           SYMR tsym;
7115796c8dcSSimon Schubert 
7125796c8dcSSimon Schubert           while (keep_counting)
7135796c8dcSSimon Schubert             {
7145796c8dcSSimon Schubert               ext_tsym += external_sym_size;
7155796c8dcSSimon Schubert               (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
7165796c8dcSSimon Schubert               count++;
7175796c8dcSSimon Schubert               switch (tsym.st)
7185796c8dcSSimon Schubert                 {
7195796c8dcSSimon Schubert                   case stParam:
7205796c8dcSSimon Schubert                     break;
7215796c8dcSSimon Schubert                   case stEnd:
7225796c8dcSSimon Schubert                     keep_counting = 0;
7235796c8dcSSimon Schubert                     break;
7245796c8dcSSimon Schubert                   default:
7255796c8dcSSimon Schubert                     complaint (&symfile_complaints,
7265796c8dcSSimon Schubert                                _("unknown symbol type 0x%x"), sh->st);
7275796c8dcSSimon Schubert                     break;
7285796c8dcSSimon Schubert                 }
7295796c8dcSSimon Schubert             }
7305796c8dcSSimon Schubert           break;
7315796c8dcSSimon Schubert         }
7325796c8dcSSimon Schubert       s = new_symbol (name);
7335796c8dcSSimon Schubert       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
7345796c8dcSSimon Schubert       SYMBOL_CLASS (s) = LOC_BLOCK;
735c50c785cSJohn Marino       /* Type of the return value.  */
7365796c8dcSSimon Schubert       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
7375796c8dcSSimon Schubert 	t = objfile_type (objfile)->builtin_int;
7385796c8dcSSimon Schubert       else
7395796c8dcSSimon Schubert 	{
7405796c8dcSSimon Schubert 	  t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
7415796c8dcSSimon Schubert 	  if (strcmp (name, "malloc") == 0
7425796c8dcSSimon Schubert 	      && TYPE_CODE (t) == TYPE_CODE_VOID)
7435796c8dcSSimon Schubert 	    {
7445796c8dcSSimon Schubert 	      /* I don't know why, but, at least under Alpha GNU/Linux,
7455796c8dcSSimon Schubert 	         when linking against a malloc without debugging
7465796c8dcSSimon Schubert 	         symbols, its read as a function returning void---this
7475796c8dcSSimon Schubert 	         is bad because it means we cannot call functions with
7485796c8dcSSimon Schubert 	         string arguments interactively; i.e., "call
7495796c8dcSSimon Schubert 	         printf("howdy\n")" would fail with the error message
7505796c8dcSSimon Schubert 	         "program has no memory available".  To avoid this, we
7515796c8dcSSimon Schubert 	         patch up the type and make it void*
752c50c785cSJohn Marino 	         instead. (davidm@azstarnet.com).  */
7535796c8dcSSimon Schubert 	      t = make_pointer_type (t, NULL);
7545796c8dcSSimon Schubert 	    }
7555796c8dcSSimon Schubert 	}
7565796c8dcSSimon Schubert       b = top_stack->cur_block;
7575796c8dcSSimon Schubert       if (sh->st == stProc)
7585796c8dcSSimon Schubert 	{
7595796c8dcSSimon Schubert 	  struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
760cf7f2e2dSJohn Marino 
7615796c8dcSSimon Schubert 	  /* The next test should normally be true, but provides a
7625796c8dcSSimon Schubert 	     hook for nested functions (which we don't want to make
7635796c8dcSSimon Schubert 	     global).  */
7645796c8dcSSimon Schubert 	  if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
7655796c8dcSSimon Schubert 	    b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
7665796c8dcSSimon Schubert 	  /* Irix 5 sometimes has duplicate names for the same
7675796c8dcSSimon Schubert 	     function.  We want to add such names up at the global
7685796c8dcSSimon Schubert 	     level, not as a nested function.  */
7695796c8dcSSimon Schubert 	  else if (sh->value == top_stack->procadr)
7705796c8dcSSimon Schubert 	    b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
7715796c8dcSSimon Schubert 	}
7725796c8dcSSimon Schubert       add_symbol (s, top_stack->cur_st, b);
7735796c8dcSSimon Schubert 
774c50c785cSJohn Marino       /* Make a type for the procedure itself.  */
7755796c8dcSSimon Schubert       SYMBOL_TYPE (s) = lookup_function_type (t);
7765796c8dcSSimon Schubert 
7775796c8dcSSimon Schubert       /* All functions in C++ have prototypes.  For C we don't have enough
7785796c8dcSSimon Schubert          information in the debug info.  */
7795796c8dcSSimon Schubert       if (SYMBOL_LANGUAGE (s) == language_cplus)
7805796c8dcSSimon Schubert 	TYPE_PROTOTYPED (SYMBOL_TYPE (s)) = 1;
7815796c8dcSSimon Schubert 
782c50c785cSJohn Marino       /* Create and enter a new lexical context.  */
7835796c8dcSSimon Schubert       b = new_block (FUNCTION_BLOCK);
7845796c8dcSSimon Schubert       SYMBOL_BLOCK_VALUE (s) = b;
7855796c8dcSSimon Schubert       BLOCK_FUNCTION (b) = s;
7865796c8dcSSimon Schubert       BLOCK_START (b) = BLOCK_END (b) = sh->value;
7875796c8dcSSimon Schubert       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
7885796c8dcSSimon Schubert       add_block (b, top_stack->cur_st);
7895796c8dcSSimon Schubert 
790c50c785cSJohn Marino       /* Not if we only have partial info.  */
7915796c8dcSSimon Schubert       if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
7925796c8dcSSimon Schubert 	break;
7935796c8dcSSimon Schubert 
7945796c8dcSSimon Schubert       push_parse_stack ();
7955796c8dcSSimon Schubert       top_stack->cur_block = b;
7965796c8dcSSimon Schubert       top_stack->blocktype = sh->st;
7975796c8dcSSimon Schubert       top_stack->cur_type = SYMBOL_TYPE (s);
7985796c8dcSSimon Schubert       top_stack->cur_field = -1;
7995796c8dcSSimon Schubert       top_stack->procadr = sh->value;
8005796c8dcSSimon Schubert       top_stack->numargs = 0;
8015796c8dcSSimon Schubert       break;
8025796c8dcSSimon Schubert 
8035796c8dcSSimon Schubert       /* Beginning of code for structure, union, and enum definitions.
8045796c8dcSSimon Schubert          They all share a common set of local variables, defined here.  */
8055796c8dcSSimon Schubert       {
8065796c8dcSSimon Schubert 	enum type_code type_code;
8075796c8dcSSimon Schubert 	char *ext_tsym;
8085796c8dcSSimon Schubert 	int nfields;
8095796c8dcSSimon Schubert 	long max_value;
8105796c8dcSSimon Schubert 	struct field *f;
8115796c8dcSSimon Schubert 
812c50c785cSJohn Marino     case stStruct:		/* Start a block defining a struct type.  */
8135796c8dcSSimon Schubert 	type_code = TYPE_CODE_STRUCT;
8145796c8dcSSimon Schubert 	goto structured_common;
8155796c8dcSSimon Schubert 
816c50c785cSJohn Marino     case stUnion:		/* Start a block defining a union type.  */
8175796c8dcSSimon Schubert 	type_code = TYPE_CODE_UNION;
8185796c8dcSSimon Schubert 	goto structured_common;
8195796c8dcSSimon Schubert 
820c50c785cSJohn Marino     case stEnum:		/* Start a block defining an enum type.  */
8215796c8dcSSimon Schubert 	type_code = TYPE_CODE_ENUM;
8225796c8dcSSimon Schubert 	goto structured_common;
8235796c8dcSSimon Schubert 
824c50c785cSJohn Marino     case stBlock:		/* Either a lexical block, or some type.  */
8255796c8dcSSimon Schubert 	if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
8265796c8dcSSimon Schubert 	  goto case_stBlock_code;	/* Lexical block */
8275796c8dcSSimon Schubert 
8285796c8dcSSimon Schubert 	type_code = TYPE_CODE_UNDEF;	/* We have a type.  */
8295796c8dcSSimon Schubert 
8305796c8dcSSimon Schubert 	/* Common code for handling struct, union, enum, and/or as-yet-
8315796c8dcSSimon Schubert 	   unknown-type blocks of info about structured data.  `type_code'
8325796c8dcSSimon Schubert 	   has been set to the proper TYPE_CODE, if we know it.  */
8335796c8dcSSimon Schubert       structured_common:
8345796c8dcSSimon Schubert 	found_ecoff_debugging_info = 1;
8355796c8dcSSimon Schubert 	push_parse_stack ();
8365796c8dcSSimon Schubert 	top_stack->blocktype = stBlock;
8375796c8dcSSimon Schubert 
8385796c8dcSSimon Schubert 	/* First count the number of fields and the highest value.  */
8395796c8dcSSimon Schubert 	nfields = 0;
8405796c8dcSSimon Schubert 	max_value = 0;
8415796c8dcSSimon Schubert 	for (ext_tsym = ext_sh + external_sym_size;
8425796c8dcSSimon Schubert 	     ;
8435796c8dcSSimon Schubert 	     ext_tsym += external_sym_size)
8445796c8dcSSimon Schubert 	  {
8455796c8dcSSimon Schubert 	    SYMR tsym;
8465796c8dcSSimon Schubert 
8475796c8dcSSimon Schubert 	    (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
8485796c8dcSSimon Schubert 
8495796c8dcSSimon Schubert 	    switch (tsym.st)
8505796c8dcSSimon Schubert 	      {
8515796c8dcSSimon Schubert 	      case stEnd:
8525796c8dcSSimon Schubert                 /* C++ encodes class types as structures where there the
8535796c8dcSSimon Schubert                    methods are encoded as stProc.  The scope of stProc
8545796c8dcSSimon Schubert                    symbols also ends with stEnd, thus creating a risk of
8555796c8dcSSimon Schubert                    taking the wrong stEnd symbol record as the end of
8565796c8dcSSimon Schubert                    the current struct, which would cause GDB to undercount
8575796c8dcSSimon Schubert                    the real number of fields in this struct.  To make sure
8585796c8dcSSimon Schubert                    we really reached the right stEnd symbol record, we
8595796c8dcSSimon Schubert                    check the associated name, and match it against the
8605796c8dcSSimon Schubert                    struct name.  Since method names are mangled while
8615796c8dcSSimon Schubert                    the class name is not, there is no risk of having a
8625796c8dcSSimon Schubert                    method whose name is identical to the class name
8635796c8dcSSimon Schubert                    (in particular constructor method names are different
8645796c8dcSSimon Schubert                    from the class name).  There is therefore no risk that
8655796c8dcSSimon Schubert                    this check stops the count on the StEnd of a method.
8665796c8dcSSimon Schubert 
8675796c8dcSSimon Schubert 		   Also, assume that we're really at the end when tsym.iss
8685796c8dcSSimon Schubert 		   is 0 (issNull).  */
8695796c8dcSSimon Schubert                 if (tsym.iss == issNull
8705796c8dcSSimon Schubert 		    || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss,
8715796c8dcSSimon Schubert                                name) == 0)
8725796c8dcSSimon Schubert                   goto end_of_fields;
8735796c8dcSSimon Schubert                 break;
8745796c8dcSSimon Schubert 
8755796c8dcSSimon Schubert 	      case stMember:
8765796c8dcSSimon Schubert 		if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
8775796c8dcSSimon Schubert 		  {
8785796c8dcSSimon Schubert 		    /* If the type of the member is Nil (or Void),
8795796c8dcSSimon Schubert 		       without qualifiers, assume the tag is an
8805796c8dcSSimon Schubert 		       enumeration.
8815796c8dcSSimon Schubert 		       Alpha cc -migrate enums are recognized by a zero
8825796c8dcSSimon Schubert 		       index and a zero symbol value.
8835796c8dcSSimon Schubert 		       DU 4.0 cc enums are recognized by a member type of
8845796c8dcSSimon Schubert 		       btEnum without qualifiers and a zero symbol value.  */
8855796c8dcSSimon Schubert 		    if (tsym.index == indexNil
8865796c8dcSSimon Schubert 			|| (tsym.index == 0 && sh->value == 0))
8875796c8dcSSimon Schubert 		      type_code = TYPE_CODE_ENUM;
8885796c8dcSSimon Schubert 		    else
8895796c8dcSSimon Schubert 		      {
8905796c8dcSSimon Schubert 			(*debug_swap->swap_tir_in) (bigend,
8915796c8dcSSimon Schubert 						    &ax[tsym.index].a_ti,
8925796c8dcSSimon Schubert 						    &tir);
8935796c8dcSSimon Schubert 			if ((tir.bt == btNil || tir.bt == btVoid
8945796c8dcSSimon Schubert 			     || (tir.bt == btEnum && sh->value == 0))
8955796c8dcSSimon Schubert 			    && tir.tq0 == tqNil)
8965796c8dcSSimon Schubert 			  type_code = TYPE_CODE_ENUM;
8975796c8dcSSimon Schubert 		      }
8985796c8dcSSimon Schubert 		  }
8995796c8dcSSimon Schubert 		nfields++;
9005796c8dcSSimon Schubert 		if (tsym.value > max_value)
9015796c8dcSSimon Schubert 		  max_value = tsym.value;
9025796c8dcSSimon Schubert 		break;
9035796c8dcSSimon Schubert 
9045796c8dcSSimon Schubert 	      case stBlock:
9055796c8dcSSimon Schubert 	      case stUnion:
9065796c8dcSSimon Schubert 	      case stEnum:
9075796c8dcSSimon Schubert 	      case stStruct:
9085796c8dcSSimon Schubert 		{
9095796c8dcSSimon Schubert #if 0
9105796c8dcSSimon Schubert 		  /* This is a no-op; is it trying to tell us something
9115796c8dcSSimon Schubert 		     we should be checking?  */
9125796c8dcSSimon Schubert 		  if (tsym.sc == scVariant);	/*UNIMPLEMENTED */
9135796c8dcSSimon Schubert #endif
9145796c8dcSSimon Schubert 		  if (tsym.index != 0)
9155796c8dcSSimon Schubert 		    {
9165796c8dcSSimon Schubert 		      /* This is something like a struct within a
9175796c8dcSSimon Schubert 		         struct.  Skip over the fields of the inner
9185796c8dcSSimon Schubert 		         struct.  The -1 is because the for loop will
9195796c8dcSSimon Schubert 		         increment ext_tsym.  */
9205796c8dcSSimon Schubert 		      ext_tsym = ((char *) debug_info->external_sym
9215796c8dcSSimon Schubert 				  + ((cur_fdr->isymBase + tsym.index - 1)
9225796c8dcSSimon Schubert 				     * external_sym_size));
9235796c8dcSSimon Schubert 		    }
9245796c8dcSSimon Schubert 		}
9255796c8dcSSimon Schubert 		break;
9265796c8dcSSimon Schubert 
9275796c8dcSSimon Schubert 	      case stTypedef:
9285796c8dcSSimon Schubert 		/* mips cc puts out a typedef for struct x if it is not yet
9295796c8dcSSimon Schubert 		   defined when it encounters
9305796c8dcSSimon Schubert 		   struct y { struct x *xp; };
9315796c8dcSSimon Schubert 		   Just ignore it.  */
9325796c8dcSSimon Schubert 		break;
9335796c8dcSSimon Schubert 
9345796c8dcSSimon Schubert 	      case stIndirect:
9355796c8dcSSimon Schubert 		/* Irix5 cc puts out a stIndirect for struct x if it is not
9365796c8dcSSimon Schubert 		   yet defined when it encounters
9375796c8dcSSimon Schubert 		   struct y { struct x *xp; };
9385796c8dcSSimon Schubert 		   Just ignore it.  */
9395796c8dcSSimon Schubert 		break;
9405796c8dcSSimon Schubert 
9415796c8dcSSimon Schubert 	      default:
9425796c8dcSSimon Schubert 		complaint (&symfile_complaints,
943c50c785cSJohn Marino 			   _("declaration block contains "
944c50c785cSJohn Marino 			     "unhandled symbol type %d"),
9455796c8dcSSimon Schubert 			   tsym.st);
9465796c8dcSSimon Schubert 	      }
9475796c8dcSSimon Schubert 	  }
948c50c785cSJohn Marino       end_of_fields:
9495796c8dcSSimon Schubert 
9505796c8dcSSimon Schubert 	/* In an stBlock, there is no way to distinguish structs,
9515796c8dcSSimon Schubert 	   unions, and enums at this point.  This is a bug in the
9525796c8dcSSimon Schubert 	   original design (that has been fixed with the recent
9535796c8dcSSimon Schubert 	   addition of the stStruct, stUnion, and stEnum symbol
9545796c8dcSSimon Schubert 	   types.)  The way you can tell is if/when you see a variable
9555796c8dcSSimon Schubert 	   or field of that type.  In that case the variable's type
9565796c8dcSSimon Schubert 	   (in the AUX table) says if the type is struct, union, or
9575796c8dcSSimon Schubert 	   enum, and points back to the stBlock here.  So you can
9585796c8dcSSimon Schubert 	   patch the tag kind up later - but only if there actually is
9595796c8dcSSimon Schubert 	   a variable or field of that type.
9605796c8dcSSimon Schubert 
9615796c8dcSSimon Schubert 	   So until we know for sure, we will guess at this point.
9625796c8dcSSimon Schubert 	   The heuristic is:
9635796c8dcSSimon Schubert 	   If the first member has index==indexNil or a void type,
9645796c8dcSSimon Schubert 	   assume we have an enumeration.
9655796c8dcSSimon Schubert 	   Otherwise, if there is more than one member, and all
9665796c8dcSSimon Schubert 	   the members have offset 0, assume we have a union.
9675796c8dcSSimon Schubert 	   Otherwise, assume we have a struct.
9685796c8dcSSimon Schubert 
9695796c8dcSSimon Schubert 	   The heuristic could guess wrong in the case of of an
9705796c8dcSSimon Schubert 	   enumeration with no members or a union with one (or zero)
9715796c8dcSSimon Schubert 	   members, or when all except the last field of a struct have
9725796c8dcSSimon Schubert 	   width zero.  These are uncommon and/or illegal situations,
9735796c8dcSSimon Schubert 	   and in any case guessing wrong probably doesn't matter
9745796c8dcSSimon Schubert 	   much.
9755796c8dcSSimon Schubert 
9765796c8dcSSimon Schubert 	   But if we later do find out we were wrong, we fixup the tag
9775796c8dcSSimon Schubert 	   kind.  Members of an enumeration must be handled
9785796c8dcSSimon Schubert 	   differently from struct/union fields, and that is harder to
9795796c8dcSSimon Schubert 	   patch up, but luckily we shouldn't need to.  (If there are
9805796c8dcSSimon Schubert 	   any enumeration members, we can tell for sure it's an enum
9815796c8dcSSimon Schubert 	   here.)  */
9825796c8dcSSimon Schubert 
9835796c8dcSSimon Schubert 	if (type_code == TYPE_CODE_UNDEF)
9845796c8dcSSimon Schubert 	  {
9855796c8dcSSimon Schubert 	    if (nfields > 1 && max_value == 0)
9865796c8dcSSimon Schubert 	      type_code = TYPE_CODE_UNION;
9875796c8dcSSimon Schubert 	    else
9885796c8dcSSimon Schubert 	      type_code = TYPE_CODE_STRUCT;
9895796c8dcSSimon Schubert 	  }
9905796c8dcSSimon Schubert 
9915796c8dcSSimon Schubert 	/* Create a new type or use the pending type.  */
9925796c8dcSSimon Schubert 	pend = is_pending_symbol (cur_fdr, ext_sh);
9935796c8dcSSimon Schubert 	if (pend == (struct mdebug_pending *) NULL)
9945796c8dcSSimon Schubert 	  {
9955796c8dcSSimon Schubert 	    t = new_type (NULL);
9965796c8dcSSimon Schubert 	    add_pending (cur_fdr, ext_sh, t);
9975796c8dcSSimon Schubert 	  }
9985796c8dcSSimon Schubert 	else
9995796c8dcSSimon Schubert 	  t = pend->t;
10005796c8dcSSimon Schubert 
10015796c8dcSSimon Schubert 	/* Do not set the tag name if it is a compiler generated tag name
10025796c8dcSSimon Schubert 	   (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
10035796c8dcSSimon Schubert 	   Alpha cc puts out an sh->iss of zero for those.  */
10045796c8dcSSimon Schubert 	if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
10055796c8dcSSimon Schubert 	  TYPE_TAG_NAME (t) = NULL;
10065796c8dcSSimon Schubert 	else
1007a45ae5f8SJohn Marino 	  TYPE_TAG_NAME (t) = obconcat (&mdebugread_objfile->objfile_obstack,
1008c50c785cSJohn Marino 					name, (char *) NULL);
10095796c8dcSSimon Schubert 
10105796c8dcSSimon Schubert 	TYPE_CODE (t) = type_code;
10115796c8dcSSimon Schubert 	TYPE_LENGTH (t) = sh->value;
10125796c8dcSSimon Schubert 	TYPE_NFIELDS (t) = nfields;
10135796c8dcSSimon Schubert 	TYPE_FIELDS (t) = f = ((struct field *)
10145796c8dcSSimon Schubert 			       TYPE_ALLOC (t,
10155796c8dcSSimon Schubert 					   nfields * sizeof (struct field)));
10165796c8dcSSimon Schubert 
10175796c8dcSSimon Schubert 	if (type_code == TYPE_CODE_ENUM)
10185796c8dcSSimon Schubert 	  {
10195796c8dcSSimon Schubert 	    int unsigned_enum = 1;
10205796c8dcSSimon Schubert 
10215796c8dcSSimon Schubert 	    /* This is a non-empty enum.  */
10225796c8dcSSimon Schubert 
10235796c8dcSSimon Schubert 	    /* DEC c89 has the number of enumerators in the sh.value field,
10245796c8dcSSimon Schubert 	       not the type length, so we have to compensate for that
10255796c8dcSSimon Schubert 	       incompatibility quirk.
10265796c8dcSSimon Schubert 	       This might do the wrong thing for an enum with one or two
10275796c8dcSSimon Schubert 	       enumerators and gcc -gcoff -fshort-enums, but these cases
10285796c8dcSSimon Schubert 	       are hopefully rare enough.
10295796c8dcSSimon Schubert 	       Alpha cc -migrate has a sh.value field of zero, we adjust
10305796c8dcSSimon Schubert 	       that too.  */
10315796c8dcSSimon Schubert 	    if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
10325796c8dcSSimon Schubert 		|| TYPE_LENGTH (t) == 0)
10335796c8dcSSimon Schubert 	      TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
10345796c8dcSSimon Schubert 	    for (ext_tsym = ext_sh + external_sym_size;
10355796c8dcSSimon Schubert 		 ;
10365796c8dcSSimon Schubert 		 ext_tsym += external_sym_size)
10375796c8dcSSimon Schubert 	      {
10385796c8dcSSimon Schubert 		SYMR tsym;
10395796c8dcSSimon Schubert 		struct symbol *enum_sym;
10405796c8dcSSimon Schubert 
10415796c8dcSSimon Schubert 		(*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
10425796c8dcSSimon Schubert 
10435796c8dcSSimon Schubert 		if (tsym.st != stMember)
10445796c8dcSSimon Schubert 		  break;
10455796c8dcSSimon Schubert 
1046*ef5ccd6cSJohn Marino 		SET_FIELD_ENUMVAL (*f, tsym.value);
10475796c8dcSSimon Schubert 		FIELD_TYPE (*f) = t;
10485796c8dcSSimon Schubert 		FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
10495796c8dcSSimon Schubert 		FIELD_BITSIZE (*f) = 0;
10505796c8dcSSimon Schubert 
10515796c8dcSSimon Schubert 		enum_sym = ((struct symbol *)
1052a45ae5f8SJohn Marino 			    obstack_alloc (&mdebugread_objfile->objfile_obstack,
10535796c8dcSSimon Schubert 					   sizeof (struct symbol)));
10545796c8dcSSimon Schubert 		memset (enum_sym, 0, sizeof (struct symbol));
10555796c8dcSSimon Schubert 		SYMBOL_SET_LINKAGE_NAME
1056*ef5ccd6cSJohn Marino 		  (enum_sym,
1057*ef5ccd6cSJohn Marino 		   obstack_copy0 (&mdebugread_objfile->objfile_obstack,
1058*ef5ccd6cSJohn Marino 				  f->name, strlen (f->name)));
10595796c8dcSSimon Schubert 		SYMBOL_CLASS (enum_sym) = LOC_CONST;
10605796c8dcSSimon Schubert 		SYMBOL_TYPE (enum_sym) = t;
10615796c8dcSSimon Schubert 		SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN;
10625796c8dcSSimon Schubert 		SYMBOL_VALUE (enum_sym) = tsym.value;
10635796c8dcSSimon Schubert 		if (SYMBOL_VALUE (enum_sym) < 0)
10645796c8dcSSimon Schubert 		  unsigned_enum = 0;
10655796c8dcSSimon Schubert 		add_symbol (enum_sym, top_stack->cur_st, top_stack->cur_block);
10665796c8dcSSimon Schubert 
10675796c8dcSSimon Schubert 		/* Skip the stMembers that we've handled.  */
10685796c8dcSSimon Schubert 		count++;
10695796c8dcSSimon Schubert 		f++;
10705796c8dcSSimon Schubert 	      }
10715796c8dcSSimon Schubert 	    if (unsigned_enum)
10725796c8dcSSimon Schubert 	      TYPE_UNSIGNED (t) = 1;
10735796c8dcSSimon Schubert 	  }
1074c50c785cSJohn Marino 	/* Make this the current type.  */
10755796c8dcSSimon Schubert 	top_stack->cur_type = t;
10765796c8dcSSimon Schubert 	top_stack->cur_field = 0;
10775796c8dcSSimon Schubert 
10785796c8dcSSimon Schubert 	/* Do not create a symbol for alpha cc unnamed structs.  */
10795796c8dcSSimon Schubert 	if (sh->iss == 0)
10805796c8dcSSimon Schubert 	  break;
10815796c8dcSSimon Schubert 
10825796c8dcSSimon Schubert 	/* gcc puts out an empty struct for an opaque struct definitions,
10835796c8dcSSimon Schubert 	   do not create a symbol for it either.  */
10845796c8dcSSimon Schubert 	if (TYPE_NFIELDS (t) == 0)
10855796c8dcSSimon Schubert 	  {
10865796c8dcSSimon Schubert 	    TYPE_STUB (t) = 1;
10875796c8dcSSimon Schubert 	    break;
10885796c8dcSSimon Schubert 	  }
10895796c8dcSSimon Schubert 
10905796c8dcSSimon Schubert 	s = new_symbol (name);
10915796c8dcSSimon Schubert 	SYMBOL_DOMAIN (s) = STRUCT_DOMAIN;
10925796c8dcSSimon Schubert 	SYMBOL_CLASS (s) = LOC_TYPEDEF;
10935796c8dcSSimon Schubert 	SYMBOL_VALUE (s) = 0;
10945796c8dcSSimon Schubert 	SYMBOL_TYPE (s) = t;
10955796c8dcSSimon Schubert 	add_symbol (s, top_stack->cur_st, top_stack->cur_block);
10965796c8dcSSimon Schubert 	break;
10975796c8dcSSimon Schubert 
10985796c8dcSSimon Schubert 	/* End of local variables shared by struct, union, enum, and
10995796c8dcSSimon Schubert 	   block (as yet unknown struct/union/enum) processing.  */
11005796c8dcSSimon Schubert       }
11015796c8dcSSimon Schubert 
11025796c8dcSSimon Schubert     case_stBlock_code:
11035796c8dcSSimon Schubert       found_ecoff_debugging_info = 1;
1104c50c785cSJohn Marino       /* Beginnning of (code) block.  Value of symbol
1105c50c785cSJohn Marino          is the displacement from procedure start.  */
11065796c8dcSSimon Schubert       push_parse_stack ();
11075796c8dcSSimon Schubert 
11085796c8dcSSimon Schubert       /* Do not start a new block if this is the outermost block of a
11095796c8dcSSimon Schubert          procedure.  This allows the LOC_BLOCK symbol to point to the
11105796c8dcSSimon Schubert          block with the local variables, so funcname::var works.  */
11115796c8dcSSimon Schubert       if (top_stack->blocktype == stProc
11125796c8dcSSimon Schubert 	  || top_stack->blocktype == stStaticProc)
11135796c8dcSSimon Schubert 	{
11145796c8dcSSimon Schubert 	  top_stack->blocktype = stNil;
11155796c8dcSSimon Schubert 	  break;
11165796c8dcSSimon Schubert 	}
11175796c8dcSSimon Schubert 
11185796c8dcSSimon Schubert       top_stack->blocktype = stBlock;
11195796c8dcSSimon Schubert       b = new_block (NON_FUNCTION_BLOCK);
11205796c8dcSSimon Schubert       BLOCK_START (b) = sh->value + top_stack->procadr;
11215796c8dcSSimon Schubert       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
11225796c8dcSSimon Schubert       top_stack->cur_block = b;
11235796c8dcSSimon Schubert       add_block (b, top_stack->cur_st);
11245796c8dcSSimon Schubert       break;
11255796c8dcSSimon Schubert 
11265796c8dcSSimon Schubert     case stEnd:		/* end (of anything) */
11275796c8dcSSimon Schubert       if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
11285796c8dcSSimon Schubert 	{
11295796c8dcSSimon Schubert 	  /* Finished with type */
11305796c8dcSSimon Schubert 	  top_stack->cur_type = 0;
11315796c8dcSSimon Schubert 	}
11325796c8dcSSimon Schubert       else if (sh->sc == scText &&
11335796c8dcSSimon Schubert 	       (top_stack->blocktype == stProc ||
11345796c8dcSSimon Schubert 		top_stack->blocktype == stStaticProc))
11355796c8dcSSimon Schubert 	{
11365796c8dcSSimon Schubert 	  /* Finished with procedure */
11375796c8dcSSimon Schubert 	  struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
11385796c8dcSSimon Schubert 	  struct mdebug_extra_func_info *e;
11395796c8dcSSimon Schubert 	  struct block *b = top_stack->cur_block;
11405796c8dcSSimon Schubert 	  struct type *ftype = top_stack->cur_type;
11415796c8dcSSimon Schubert 	  int i;
11425796c8dcSSimon Schubert 
11435796c8dcSSimon Schubert 	  BLOCK_END (top_stack->cur_block) += sh->value;	/* size */
11445796c8dcSSimon Schubert 
1145c50c785cSJohn Marino 	  /* Make up special symbol to contain procedure specific info.  */
11465796c8dcSSimon Schubert 	  s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
11475796c8dcSSimon Schubert 	  SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
11485796c8dcSSimon Schubert 	  SYMBOL_CLASS (s) = LOC_CONST;
1149a45ae5f8SJohn Marino 	  SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->builtin_void;
11505796c8dcSSimon Schubert 	  e = ((struct mdebug_extra_func_info *)
1151a45ae5f8SJohn Marino 	       obstack_alloc (&mdebugread_objfile->objfile_obstack,
11525796c8dcSSimon Schubert 			      sizeof (struct mdebug_extra_func_info)));
11535796c8dcSSimon Schubert 	  memset (e, 0, sizeof (struct mdebug_extra_func_info));
11545796c8dcSSimon Schubert 	  SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
11555796c8dcSSimon Schubert 	  e->numargs = top_stack->numargs;
11565796c8dcSSimon Schubert 	  e->pdr.framereg = -1;
11575796c8dcSSimon Schubert 	  add_symbol (s, top_stack->cur_st, top_stack->cur_block);
11585796c8dcSSimon Schubert 
11595796c8dcSSimon Schubert 	  /* f77 emits proc-level with address bounds==[0,0],
11605796c8dcSSimon Schubert 	     So look for such child blocks, and patch them.  */
11615796c8dcSSimon Schubert 	  for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
11625796c8dcSSimon Schubert 	    {
11635796c8dcSSimon Schubert 	      struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1164cf7f2e2dSJohn Marino 
11655796c8dcSSimon Schubert 	      if (BLOCK_SUPERBLOCK (b_bad) == b
11665796c8dcSSimon Schubert 		  && BLOCK_START (b_bad) == top_stack->procadr
11675796c8dcSSimon Schubert 		  && BLOCK_END (b_bad) == top_stack->procadr)
11685796c8dcSSimon Schubert 		{
11695796c8dcSSimon Schubert 		  BLOCK_START (b_bad) = BLOCK_START (b);
11705796c8dcSSimon Schubert 		  BLOCK_END (b_bad) = BLOCK_END (b);
11715796c8dcSSimon Schubert 		}
11725796c8dcSSimon Schubert 	    }
11735796c8dcSSimon Schubert 
11745796c8dcSSimon Schubert 	  if (TYPE_NFIELDS (ftype) <= 0)
11755796c8dcSSimon Schubert 	    {
11765796c8dcSSimon Schubert 	      /* No parameter type information is recorded with the function's
11775796c8dcSSimon Schubert 	         type.  Set that from the type of the parameter symbols.  */
11785796c8dcSSimon Schubert 	      int nparams = top_stack->numargs;
11795796c8dcSSimon Schubert 	      int iparams;
11805796c8dcSSimon Schubert 	      struct symbol *sym;
11815796c8dcSSimon Schubert 
11825796c8dcSSimon Schubert 	      if (nparams > 0)
11835796c8dcSSimon Schubert 		{
1184*ef5ccd6cSJohn Marino 		  struct block_iterator iter;
1185cf7f2e2dSJohn Marino 
11865796c8dcSSimon Schubert 		  TYPE_NFIELDS (ftype) = nparams;
11875796c8dcSSimon Schubert 		  TYPE_FIELDS (ftype) = (struct field *)
11885796c8dcSSimon Schubert 		    TYPE_ALLOC (ftype, nparams * sizeof (struct field));
11895796c8dcSSimon Schubert 
11905796c8dcSSimon Schubert 		  iparams = 0;
11915796c8dcSSimon Schubert 		  ALL_BLOCK_SYMBOLS (b, iter, sym)
11925796c8dcSSimon Schubert 		    {
11935796c8dcSSimon Schubert 		      if (iparams == nparams)
11945796c8dcSSimon Schubert 			break;
11955796c8dcSSimon Schubert 
11965796c8dcSSimon Schubert 		      if (SYMBOL_IS_ARGUMENT (sym))
11975796c8dcSSimon Schubert 			{
11985796c8dcSSimon Schubert 			  TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
11995796c8dcSSimon Schubert 			  TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
12005796c8dcSSimon Schubert 			  iparams++;
12015796c8dcSSimon Schubert 			}
12025796c8dcSSimon Schubert 		    }
12035796c8dcSSimon Schubert 		}
12045796c8dcSSimon Schubert 	    }
12055796c8dcSSimon Schubert 	}
12065796c8dcSSimon Schubert       else if (sh->sc == scText && top_stack->blocktype == stBlock)
12075796c8dcSSimon Schubert 	{
12085796c8dcSSimon Schubert 	  /* End of (code) block.  The value of the symbol is the
12095796c8dcSSimon Schubert 	     displacement from the procedure`s start address of the
12105796c8dcSSimon Schubert 	     end of this block.  */
12115796c8dcSSimon Schubert 	  BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
12125796c8dcSSimon Schubert 	}
12135796c8dcSSimon Schubert       else if (sh->sc == scText && top_stack->blocktype == stNil)
12145796c8dcSSimon Schubert 	{
12155796c8dcSSimon Schubert 	  /* End of outermost block.  Pop parse stack and ignore.  The
12165796c8dcSSimon Schubert 	     following stEnd of stProc will take care of the block.  */
12175796c8dcSSimon Schubert 	  ;
12185796c8dcSSimon Schubert 	}
12195796c8dcSSimon Schubert       else if (sh->sc == scText && top_stack->blocktype == stFile)
12205796c8dcSSimon Schubert 	{
12215796c8dcSSimon Schubert 	  /* End of file.  Pop parse stack and ignore.  Higher
12225796c8dcSSimon Schubert 	     level code deals with this.  */
12235796c8dcSSimon Schubert 	  ;
12245796c8dcSSimon Schubert 	}
12255796c8dcSSimon Schubert       else
12265796c8dcSSimon Schubert 	complaint (&symfile_complaints,
12275796c8dcSSimon Schubert 		   _("stEnd with storage class %d not handled"), sh->sc);
12285796c8dcSSimon Schubert 
1229c50c785cSJohn Marino       pop_parse_stack ();	/* Restore previous lexical context.  */
12305796c8dcSSimon Schubert       break;
12315796c8dcSSimon Schubert 
12325796c8dcSSimon Schubert     case stMember:		/* member of struct or union */
12335796c8dcSSimon Schubert       f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
12345796c8dcSSimon Schubert       FIELD_NAME (*f) = name;
12355796c8dcSSimon Schubert       SET_FIELD_BITPOS (*f, sh->value);
12365796c8dcSSimon Schubert       bitsize = 0;
1237c50c785cSJohn Marino       FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index,
1238c50c785cSJohn Marino 				    &bitsize, bigend, name);
12395796c8dcSSimon Schubert       FIELD_BITSIZE (*f) = bitsize;
12405796c8dcSSimon Schubert       break;
12415796c8dcSSimon Schubert 
12425796c8dcSSimon Schubert     case stIndirect:		/* forward declaration on Irix5 */
12435796c8dcSSimon Schubert       /* Forward declarations from Irix5 cc are handled by cross_ref,
12445796c8dcSSimon Schubert          skip them.  */
12455796c8dcSSimon Schubert       break;
12465796c8dcSSimon Schubert 
12475796c8dcSSimon Schubert     case stTypedef:		/* type definition */
12485796c8dcSSimon Schubert       found_ecoff_debugging_info = 1;
12495796c8dcSSimon Schubert 
12505796c8dcSSimon Schubert       /* Typedefs for forward declarations and opaque structs from alpha cc
12515796c8dcSSimon Schubert          are handled by cross_ref, skip them.  */
12525796c8dcSSimon Schubert       if (sh->iss == 0)
12535796c8dcSSimon Schubert 	break;
12545796c8dcSSimon Schubert 
12555796c8dcSSimon Schubert       /* Parse the type or use the pending type.  */
12565796c8dcSSimon Schubert       pend = is_pending_symbol (cur_fdr, ext_sh);
12575796c8dcSSimon Schubert       if (pend == (struct mdebug_pending *) NULL)
12585796c8dcSSimon Schubert 	{
12595796c8dcSSimon Schubert 	  t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name);
12605796c8dcSSimon Schubert 	  add_pending (cur_fdr, ext_sh, t);
12615796c8dcSSimon Schubert 	}
12625796c8dcSSimon Schubert       else
12635796c8dcSSimon Schubert 	t = pend->t;
12645796c8dcSSimon Schubert 
1265c50c785cSJohn Marino       /* Mips cc puts out a typedef with the name of the struct for forward
12665796c8dcSSimon Schubert          declarations.  These should not go into the symbol table and
12675796c8dcSSimon Schubert          TYPE_NAME should not be set for them.
12685796c8dcSSimon Schubert          They can't be distinguished from an intentional typedef to
12695796c8dcSSimon Schubert          the same name however:
12705796c8dcSSimon Schubert          x.h:
12715796c8dcSSimon Schubert          struct x { int ix; int jx; };
12725796c8dcSSimon Schubert          struct xx;
12735796c8dcSSimon Schubert          x.c:
12745796c8dcSSimon Schubert          typedef struct x x;
12755796c8dcSSimon Schubert          struct xx {int ixx; int jxx; };
12765796c8dcSSimon Schubert          generates a cross referencing stTypedef for x and xx.
12775796c8dcSSimon Schubert          The user visible effect of this is that the type of a pointer
12785796c8dcSSimon Schubert          to struct foo sometimes is given as `foo *' instead of `struct foo *'.
12795796c8dcSSimon Schubert          The problem is fixed with alpha cc and Irix5 cc.  */
12805796c8dcSSimon Schubert 
12815796c8dcSSimon Schubert       /* However if the typedef cross references to an opaque aggregate, it
12825796c8dcSSimon Schubert          is safe to omit it from the symbol table.  */
12835796c8dcSSimon Schubert 
12845796c8dcSSimon Schubert       if (has_opaque_xref (cur_fdr, sh))
12855796c8dcSSimon Schubert 	break;
12865796c8dcSSimon Schubert       s = new_symbol (name);
12875796c8dcSSimon Schubert       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
12885796c8dcSSimon Schubert       SYMBOL_CLASS (s) = LOC_TYPEDEF;
12895796c8dcSSimon Schubert       SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
12905796c8dcSSimon Schubert       SYMBOL_TYPE (s) = t;
12915796c8dcSSimon Schubert       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
12925796c8dcSSimon Schubert 
12935796c8dcSSimon Schubert       /* Incomplete definitions of structs should not get a name.  */
12945796c8dcSSimon Schubert       if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
12955796c8dcSSimon Schubert 	  && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
12965796c8dcSSimon Schubert 	      || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
12975796c8dcSSimon Schubert 		  && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
12985796c8dcSSimon Schubert 	{
12995796c8dcSSimon Schubert 	  if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
13005796c8dcSSimon Schubert 	      || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
13015796c8dcSSimon Schubert 	    {
13025796c8dcSSimon Schubert 	      /* If we are giving a name to a type such as "pointer to
13035796c8dcSSimon Schubert 	         foo" or "function returning foo", we better not set
13045796c8dcSSimon Schubert 	         the TYPE_NAME.  If the program contains "typedef char
13055796c8dcSSimon Schubert 	         *caddr_t;", we don't want all variables of type char
13065796c8dcSSimon Schubert 	         * to print as caddr_t.  This is not just a
13075796c8dcSSimon Schubert 	         consequence of GDB's type management; CC and GCC (at
13085796c8dcSSimon Schubert 	         least through version 2.4) both output variables of
13095796c8dcSSimon Schubert 	         either type char * or caddr_t with the type
13105796c8dcSSimon Schubert 	         refering to the stTypedef symbol for caddr_t.  If a future
13115796c8dcSSimon Schubert 	         compiler cleans this up it GDB is not ready for it
13125796c8dcSSimon Schubert 	         yet, but if it becomes ready we somehow need to
13135796c8dcSSimon Schubert 	         disable this check (without breaking the PCC/GCC2.4
13145796c8dcSSimon Schubert 	         case).
13155796c8dcSSimon Schubert 
13165796c8dcSSimon Schubert 	         Sigh.
13175796c8dcSSimon Schubert 
13185796c8dcSSimon Schubert 	         Fortunately, this check seems not to be necessary
13195796c8dcSSimon Schubert 	         for anything except pointers or functions.  */
13205796c8dcSSimon Schubert 	    }
13215796c8dcSSimon Schubert 	  else
13225796c8dcSSimon Schubert 	    TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_LINKAGE_NAME (s);
13235796c8dcSSimon Schubert 	}
13245796c8dcSSimon Schubert       break;
13255796c8dcSSimon Schubert 
13265796c8dcSSimon Schubert     case stFile:		/* file name */
13275796c8dcSSimon Schubert       push_parse_stack ();
13285796c8dcSSimon Schubert       top_stack->blocktype = sh->st;
13295796c8dcSSimon Schubert       break;
13305796c8dcSSimon Schubert 
13315796c8dcSSimon Schubert       /* I`ve never seen these for C */
13325796c8dcSSimon Schubert     case stRegReloc:
13335796c8dcSSimon Schubert       break;			/* register relocation */
13345796c8dcSSimon Schubert     case stForward:
13355796c8dcSSimon Schubert       break;			/* forwarding address */
13365796c8dcSSimon Schubert     case stConstant:
13375796c8dcSSimon Schubert       break;			/* constant */
13385796c8dcSSimon Schubert     default:
13395796c8dcSSimon Schubert       complaint (&symfile_complaints, _("unknown symbol type 0x%x"), sh->st);
13405796c8dcSSimon Schubert       break;
13415796c8dcSSimon Schubert     }
13425796c8dcSSimon Schubert 
13435796c8dcSSimon Schubert   return count;
13445796c8dcSSimon Schubert }
13455796c8dcSSimon Schubert 
13465796c8dcSSimon Schubert /* Basic types.  */
13475796c8dcSSimon Schubert 
13485796c8dcSSimon Schubert static const struct objfile_data *basic_type_data;
13495796c8dcSSimon Schubert 
13505796c8dcSSimon Schubert static struct type *
basic_type(int bt,struct objfile * objfile)13515796c8dcSSimon Schubert basic_type (int bt, struct objfile *objfile)
13525796c8dcSSimon Schubert {
13535796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
13545796c8dcSSimon Schubert   struct type **map_bt = objfile_data (objfile, basic_type_data);
13555796c8dcSSimon Schubert   struct type *tp;
13565796c8dcSSimon Schubert 
13575796c8dcSSimon Schubert   if (bt >= btMax)
13585796c8dcSSimon Schubert     return NULL;
13595796c8dcSSimon Schubert 
13605796c8dcSSimon Schubert   if (!map_bt)
13615796c8dcSSimon Schubert     {
13625796c8dcSSimon Schubert       map_bt = OBSTACK_CALLOC (&objfile->objfile_obstack,
13635796c8dcSSimon Schubert 			       btMax, struct type *);
13645796c8dcSSimon Schubert       set_objfile_data (objfile, basic_type_data, map_bt);
13655796c8dcSSimon Schubert     }
13665796c8dcSSimon Schubert 
13675796c8dcSSimon Schubert   if (map_bt[bt])
13685796c8dcSSimon Schubert     return map_bt[bt];
13695796c8dcSSimon Schubert 
13705796c8dcSSimon Schubert   switch (bt)
13715796c8dcSSimon Schubert     {
13725796c8dcSSimon Schubert     case btNil:
13735796c8dcSSimon Schubert       tp = objfile_type (objfile)->builtin_void;
13745796c8dcSSimon Schubert       break;
13755796c8dcSSimon Schubert 
13765796c8dcSSimon Schubert     case btAdr:
13775796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_PTR, 4, TYPE_FLAG_UNSIGNED,
13785796c8dcSSimon Schubert 		      "adr_32", objfile);
13795796c8dcSSimon Schubert       TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
13805796c8dcSSimon Schubert       break;
13815796c8dcSSimon Schubert 
13825796c8dcSSimon Schubert     case btChar:
13835796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 1, 0,
13845796c8dcSSimon Schubert 		      "char", objfile);
13855796c8dcSSimon Schubert       break;
13865796c8dcSSimon Schubert 
13875796c8dcSSimon Schubert     case btUChar:
13885796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
13895796c8dcSSimon Schubert 		      "unsigned char", objfile);
13905796c8dcSSimon Schubert       break;
13915796c8dcSSimon Schubert 
13925796c8dcSSimon Schubert     case btShort:
13935796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 2, 0,
13945796c8dcSSimon Schubert 		      "short", objfile);
13955796c8dcSSimon Schubert       break;
13965796c8dcSSimon Schubert 
13975796c8dcSSimon Schubert     case btUShort:
13985796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
13995796c8dcSSimon Schubert 		      "unsigned short", objfile);
14005796c8dcSSimon Schubert       break;
14015796c8dcSSimon Schubert 
14025796c8dcSSimon Schubert     case btInt:
14035796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 4, 0,
14045796c8dcSSimon Schubert 		      "int", objfile);
14055796c8dcSSimon Schubert       break;
14065796c8dcSSimon Schubert 
14075796c8dcSSimon Schubert    case btUInt:
14085796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
14095796c8dcSSimon Schubert 		      "unsigned int", objfile);
14105796c8dcSSimon Schubert       break;
14115796c8dcSSimon Schubert 
14125796c8dcSSimon Schubert     case btLong:
14135796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 4, 0,
14145796c8dcSSimon Schubert 		      "long", objfile);
14155796c8dcSSimon Schubert       break;
14165796c8dcSSimon Schubert 
14175796c8dcSSimon Schubert     case btULong:
14185796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
14195796c8dcSSimon Schubert 		      "unsigned long", objfile);
14205796c8dcSSimon Schubert       break;
14215796c8dcSSimon Schubert 
14225796c8dcSSimon Schubert     case btFloat:
14235796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_FLT,
14245796c8dcSSimon Schubert 		      gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
14255796c8dcSSimon Schubert 		      "float", objfile);
14265796c8dcSSimon Schubert       break;
14275796c8dcSSimon Schubert 
14285796c8dcSSimon Schubert     case btDouble:
14295796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_FLT,
14305796c8dcSSimon Schubert 		      gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
14315796c8dcSSimon Schubert 		      "double", objfile);
14325796c8dcSSimon Schubert       break;
14335796c8dcSSimon Schubert 
14345796c8dcSSimon Schubert     case btComplex:
14355796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_COMPLEX,
14365796c8dcSSimon Schubert 		      2 * gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
14375796c8dcSSimon Schubert 		      "complex", objfile);
14385796c8dcSSimon Schubert       TYPE_TARGET_TYPE (tp) = basic_type (btFloat, objfile);
14395796c8dcSSimon Schubert       break;
14405796c8dcSSimon Schubert 
14415796c8dcSSimon Schubert     case btDComplex:
14425796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_COMPLEX,
14435796c8dcSSimon Schubert 		      2 * gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
14445796c8dcSSimon Schubert 		      "double complex", objfile);
14455796c8dcSSimon Schubert       TYPE_TARGET_TYPE (tp) = basic_type (btDouble, objfile);
14465796c8dcSSimon Schubert       break;
14475796c8dcSSimon Schubert 
14485796c8dcSSimon Schubert     case btFixedDec:
14495796c8dcSSimon Schubert       /* We use TYPE_CODE_INT to print these as integers.  Does this do any
14505796c8dcSSimon Schubert 	 good?  Would we be better off with TYPE_CODE_ERROR?  Should
14515796c8dcSSimon Schubert 	 TYPE_CODE_ERROR print things in hex if it knows the size?  */
14525796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT,
14535796c8dcSSimon Schubert 		      gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, 0,
14545796c8dcSSimon Schubert 		      "fixed decimal", objfile);
14555796c8dcSSimon Schubert       break;
14565796c8dcSSimon Schubert 
14575796c8dcSSimon Schubert     case btFloatDec:
14585796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_ERROR,
14595796c8dcSSimon Schubert 		      gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
14605796c8dcSSimon Schubert 		      "floating decimal", objfile);
14615796c8dcSSimon Schubert       break;
14625796c8dcSSimon Schubert 
14635796c8dcSSimon Schubert     case btString:
14645796c8dcSSimon Schubert       /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
14655796c8dcSSimon Schubert 	 FIXME.  */
14665796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_STRING, 1, 0,
14675796c8dcSSimon Schubert 		      "string", objfile);
14685796c8dcSSimon Schubert       break;
14695796c8dcSSimon Schubert 
14705796c8dcSSimon Schubert     case btVoid:
14715796c8dcSSimon Schubert       tp = objfile_type (objfile)->builtin_void;
14725796c8dcSSimon Schubert       break;
14735796c8dcSSimon Schubert 
14745796c8dcSSimon Schubert     case btLong64:
14755796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 8, 0,
14765796c8dcSSimon Schubert 		      "long", objfile);
14775796c8dcSSimon Schubert       break;
14785796c8dcSSimon Schubert 
14795796c8dcSSimon Schubert     case btULong64:
14805796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
14815796c8dcSSimon Schubert 		      "unsigned long", objfile);
14825796c8dcSSimon Schubert       break;
14835796c8dcSSimon Schubert 
14845796c8dcSSimon Schubert     case btLongLong64:
14855796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 8, 0,
14865796c8dcSSimon Schubert 		      "long long", objfile);
14875796c8dcSSimon Schubert       break;
14885796c8dcSSimon Schubert 
14895796c8dcSSimon Schubert     case btULongLong64:
14905796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
14915796c8dcSSimon Schubert 		      "unsigned long long", objfile);
14925796c8dcSSimon Schubert       break;
14935796c8dcSSimon Schubert 
14945796c8dcSSimon Schubert     case btAdr64:
14955796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_PTR, 8, TYPE_FLAG_UNSIGNED,
14965796c8dcSSimon Schubert 		      "adr_64", objfile);
14975796c8dcSSimon Schubert       TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
14985796c8dcSSimon Schubert       break;
14995796c8dcSSimon Schubert 
15005796c8dcSSimon Schubert     case btInt64:
15015796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 8, 0,
15025796c8dcSSimon Schubert 		      "int", objfile);
15035796c8dcSSimon Schubert       break;
15045796c8dcSSimon Schubert 
15055796c8dcSSimon Schubert     case btUInt64:
15065796c8dcSSimon Schubert       tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
15075796c8dcSSimon Schubert 		      "unsigned int", objfile);
15085796c8dcSSimon Schubert       break;
15095796c8dcSSimon Schubert 
15105796c8dcSSimon Schubert     default:
15115796c8dcSSimon Schubert       tp = NULL;
15125796c8dcSSimon Schubert       break;
15135796c8dcSSimon Schubert     }
15145796c8dcSSimon Schubert 
15155796c8dcSSimon Schubert   map_bt[bt] = tp;
15165796c8dcSSimon Schubert   return tp;
15175796c8dcSSimon Schubert }
15185796c8dcSSimon Schubert 
15195796c8dcSSimon Schubert /* Parse the type information provided in the raw AX entries for
15205796c8dcSSimon Schubert    the symbol SH.  Return the bitfield size in BS, in case.
15215796c8dcSSimon Schubert    We must byte-swap the AX entries before we use them; BIGEND says whether
15225796c8dcSSimon Schubert    they are big-endian or little-endian (from fh->fBigendian).  */
15235796c8dcSSimon Schubert 
15245796c8dcSSimon Schubert static struct type *
parse_type(int fd,union aux_ext * ax,unsigned int aux_index,int * bs,int bigend,char * sym_name)15255796c8dcSSimon Schubert parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
15265796c8dcSSimon Schubert 	    int bigend, char *sym_name)
15275796c8dcSSimon Schubert {
15285796c8dcSSimon Schubert   TIR t[1];
15295796c8dcSSimon Schubert   struct type *tp = 0;
15305796c8dcSSimon Schubert   enum type_code type_code = TYPE_CODE_UNDEF;
15315796c8dcSSimon Schubert 
15325796c8dcSSimon Schubert   /* Handle undefined types, they have indexNil.  */
15335796c8dcSSimon Schubert   if (aux_index == indexNil)
1534a45ae5f8SJohn Marino     return basic_type (btInt, mdebugread_objfile);
15355796c8dcSSimon Schubert 
15365796c8dcSSimon Schubert   /* Handle corrupt aux indices.  */
15375796c8dcSSimon Schubert   if (aux_index >= (debug_info->fdr + fd)->caux)
15385796c8dcSSimon Schubert     {
15395796c8dcSSimon Schubert       index_complaint (sym_name);
1540a45ae5f8SJohn Marino       return basic_type (btInt, mdebugread_objfile);
15415796c8dcSSimon Schubert     }
15425796c8dcSSimon Schubert   ax += aux_index;
15435796c8dcSSimon Schubert 
15445796c8dcSSimon Schubert   /* Use aux as a type information record, map its basic type.  */
15455796c8dcSSimon Schubert   (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1546a45ae5f8SJohn Marino   tp = basic_type (t->bt, mdebugread_objfile);
15475796c8dcSSimon Schubert   if (tp == NULL)
15485796c8dcSSimon Schubert     {
1549c50c785cSJohn Marino       /* Cannot use builtin types -- build our own.  */
15505796c8dcSSimon Schubert       switch (t->bt)
15515796c8dcSSimon Schubert 	{
15525796c8dcSSimon Schubert 	case btStruct:
15535796c8dcSSimon Schubert 	  type_code = TYPE_CODE_STRUCT;
15545796c8dcSSimon Schubert 	  break;
15555796c8dcSSimon Schubert 	case btUnion:
15565796c8dcSSimon Schubert 	  type_code = TYPE_CODE_UNION;
15575796c8dcSSimon Schubert 	  break;
15585796c8dcSSimon Schubert 	case btEnum:
15595796c8dcSSimon Schubert 	  type_code = TYPE_CODE_ENUM;
15605796c8dcSSimon Schubert 	  break;
15615796c8dcSSimon Schubert 	case btRange:
15625796c8dcSSimon Schubert 	  type_code = TYPE_CODE_RANGE;
15635796c8dcSSimon Schubert 	  break;
15645796c8dcSSimon Schubert 	case btSet:
15655796c8dcSSimon Schubert 	  type_code = TYPE_CODE_SET;
15665796c8dcSSimon Schubert 	  break;
15675796c8dcSSimon Schubert 	case btIndirect:
15685796c8dcSSimon Schubert 	  /* alpha cc -migrate uses this for typedefs.  The true type will
15695796c8dcSSimon Schubert 	     be obtained by crossreferencing below.  */
15705796c8dcSSimon Schubert 	  type_code = TYPE_CODE_ERROR;
15715796c8dcSSimon Schubert 	  break;
15725796c8dcSSimon Schubert 	case btTypedef:
15735796c8dcSSimon Schubert 	  /* alpha cc uses this for typedefs.  The true type will be
15745796c8dcSSimon Schubert 	     obtained by crossreferencing below.  */
15755796c8dcSSimon Schubert 	  type_code = TYPE_CODE_ERROR;
15765796c8dcSSimon Schubert 	  break;
15775796c8dcSSimon Schubert 	default:
15785796c8dcSSimon Schubert 	  basic_type_complaint (t->bt, sym_name);
1579a45ae5f8SJohn Marino 	  return basic_type (btInt, mdebugread_objfile);
15805796c8dcSSimon Schubert 	}
15815796c8dcSSimon Schubert     }
15825796c8dcSSimon Schubert 
1583c50c785cSJohn Marino   /* Move on to next aux.  */
15845796c8dcSSimon Schubert   ax++;
15855796c8dcSSimon Schubert 
15865796c8dcSSimon Schubert   if (t->fBitfield)
15875796c8dcSSimon Schubert     {
15885796c8dcSSimon Schubert       int width = AUX_GET_WIDTH (bigend, ax);
1589cf7f2e2dSJohn Marino 
15905796c8dcSSimon Schubert       /* Inhibit core dumps if TIR is corrupted.  */
15915796c8dcSSimon Schubert       if (bs == (int *) NULL)
15925796c8dcSSimon Schubert 	{
15935796c8dcSSimon Schubert 	  /* Alpha cc -migrate encodes char and unsigned char types
15945796c8dcSSimon Schubert 	     as short and unsigned short types with a field width of 8.
15955796c8dcSSimon Schubert 	     Enum types also have a field width which we ignore for now.  */
15965796c8dcSSimon Schubert 	  if (t->bt == btShort && width == 8)
1597a45ae5f8SJohn Marino 	    tp = basic_type (btChar, mdebugread_objfile);
15985796c8dcSSimon Schubert 	  else if (t->bt == btUShort && width == 8)
1599a45ae5f8SJohn Marino 	    tp = basic_type (btUChar, mdebugread_objfile);
16005796c8dcSSimon Schubert 	  else if (t->bt == btEnum)
16015796c8dcSSimon Schubert 	    ;
16025796c8dcSSimon Schubert 	  else
1603c50c785cSJohn Marino 	    complaint (&symfile_complaints,
1604c50c785cSJohn Marino 		       _("can't handle TIR fBitfield for %s"),
16055796c8dcSSimon Schubert 		       sym_name);
16065796c8dcSSimon Schubert 	}
16075796c8dcSSimon Schubert       else
16085796c8dcSSimon Schubert 	*bs = width;
16095796c8dcSSimon Schubert       ax++;
16105796c8dcSSimon Schubert     }
16115796c8dcSSimon Schubert 
16125796c8dcSSimon Schubert   /* A btIndirect entry cross references to an aux entry containing
16135796c8dcSSimon Schubert      the type.  */
16145796c8dcSSimon Schubert   if (t->bt == btIndirect)
16155796c8dcSSimon Schubert     {
16165796c8dcSSimon Schubert       RNDXR rn[1];
16175796c8dcSSimon Schubert       int rf;
16185796c8dcSSimon Schubert       FDR *xref_fh;
16195796c8dcSSimon Schubert       int xref_fd;
16205796c8dcSSimon Schubert 
16215796c8dcSSimon Schubert       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
16225796c8dcSSimon Schubert       ax++;
16235796c8dcSSimon Schubert       if (rn->rfd == 0xfff)
16245796c8dcSSimon Schubert 	{
16255796c8dcSSimon Schubert 	  rf = AUX_GET_ISYM (bigend, ax);
16265796c8dcSSimon Schubert 	  ax++;
16275796c8dcSSimon Schubert 	}
16285796c8dcSSimon Schubert       else
16295796c8dcSSimon Schubert 	rf = rn->rfd;
16305796c8dcSSimon Schubert 
16315796c8dcSSimon Schubert       if (rf == -1)
16325796c8dcSSimon Schubert 	{
16335796c8dcSSimon Schubert 	  complaint (&symfile_complaints,
16345796c8dcSSimon Schubert 		     _("unable to cross ref btIndirect for %s"), sym_name);
1635a45ae5f8SJohn Marino 	  return basic_type (btInt, mdebugread_objfile);
16365796c8dcSSimon Schubert 	}
16375796c8dcSSimon Schubert       xref_fh = get_rfd (fd, rf);
16385796c8dcSSimon Schubert       xref_fd = xref_fh - debug_info->fdr;
16395796c8dcSSimon Schubert       tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
16405796c8dcSSimon Schubert 		    rn->index, (int *) NULL, xref_fh->fBigendian, sym_name);
16415796c8dcSSimon Schubert     }
16425796c8dcSSimon Schubert 
16435796c8dcSSimon Schubert   /* All these types really point to some (common) MIPS type
16445796c8dcSSimon Schubert      definition, and only the type-qualifiers fully identify
16455796c8dcSSimon Schubert      them.  We'll make the same effort at sharing.  */
16465796c8dcSSimon Schubert   if (t->bt == btStruct ||
16475796c8dcSSimon Schubert       t->bt == btUnion ||
16485796c8dcSSimon Schubert       t->bt == btEnum ||
16495796c8dcSSimon Schubert 
16505796c8dcSSimon Schubert   /* btSet (I think) implies that the name is a tag name, not a typedef
16515796c8dcSSimon Schubert      name.  This apparently is a MIPS extension for C sets.  */
16525796c8dcSSimon Schubert       t->bt == btSet)
16535796c8dcSSimon Schubert     {
16545796c8dcSSimon Schubert       char *name;
16555796c8dcSSimon Schubert 
16565796c8dcSSimon Schubert       /* Try to cross reference this type, build new type on failure.  */
16575796c8dcSSimon Schubert       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
16585796c8dcSSimon Schubert       if (tp == (struct type *) NULL)
1659a45ae5f8SJohn Marino 	tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
16605796c8dcSSimon Schubert 
16615796c8dcSSimon Schubert       /* DEC c89 produces cross references to qualified aggregate types,
16625796c8dcSSimon Schubert          dereference them.  */
16635796c8dcSSimon Schubert       while (TYPE_CODE (tp) == TYPE_CODE_PTR
16645796c8dcSSimon Schubert 	     || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
16655796c8dcSSimon Schubert 	tp = TYPE_TARGET_TYPE (tp);
16665796c8dcSSimon Schubert 
16675796c8dcSSimon Schubert       /* Make sure that TYPE_CODE(tp) has an expected type code.
16685796c8dcSSimon Schubert          Any type may be returned from cross_ref if file indirect entries
16695796c8dcSSimon Schubert          are corrupted.  */
16705796c8dcSSimon Schubert       if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
16715796c8dcSSimon Schubert 	  && TYPE_CODE (tp) != TYPE_CODE_UNION
16725796c8dcSSimon Schubert 	  && TYPE_CODE (tp) != TYPE_CODE_ENUM)
16735796c8dcSSimon Schubert 	{
16745796c8dcSSimon Schubert 	  unexpected_type_code_complaint (sym_name);
16755796c8dcSSimon Schubert 	}
16765796c8dcSSimon Schubert       else
16775796c8dcSSimon Schubert 	{
16785796c8dcSSimon Schubert 	  /* Usually, TYPE_CODE(tp) is already type_code.  The main
16795796c8dcSSimon Schubert 	     exception is if we guessed wrong re struct/union/enum.
16805796c8dcSSimon Schubert 	     But for struct vs. union a wrong guess is harmless, so
16815796c8dcSSimon Schubert 	     don't complain().  */
16825796c8dcSSimon Schubert 	  if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
16835796c8dcSSimon Schubert 	       && type_code != TYPE_CODE_ENUM)
16845796c8dcSSimon Schubert 	      || (TYPE_CODE (tp) != TYPE_CODE_ENUM
16855796c8dcSSimon Schubert 		  && type_code == TYPE_CODE_ENUM))
16865796c8dcSSimon Schubert 	    {
16875796c8dcSSimon Schubert 	      bad_tag_guess_complaint (sym_name);
16885796c8dcSSimon Schubert 	    }
16895796c8dcSSimon Schubert 
16905796c8dcSSimon Schubert 	  if (TYPE_CODE (tp) != type_code)
16915796c8dcSSimon Schubert 	    {
16925796c8dcSSimon Schubert 	      TYPE_CODE (tp) = type_code;
16935796c8dcSSimon Schubert 	    }
16945796c8dcSSimon Schubert 
16955796c8dcSSimon Schubert 	  /* Do not set the tag name if it is a compiler generated tag name
16965796c8dcSSimon Schubert 	     (.Fxx or .xxfake or empty) for unnamed struct/union/enums.  */
16975796c8dcSSimon Schubert 	  if (name[0] == '.' || name[0] == '\0')
16985796c8dcSSimon Schubert 	    TYPE_TAG_NAME (tp) = NULL;
16995796c8dcSSimon Schubert 	  else if (TYPE_TAG_NAME (tp) == NULL
17005796c8dcSSimon Schubert 		   || strcmp (TYPE_TAG_NAME (tp), name) != 0)
1701c50c785cSJohn Marino 	    TYPE_TAG_NAME (tp)
1702*ef5ccd6cSJohn Marino 	      = obstack_copy0 (&mdebugread_objfile->objfile_obstack,
1703*ef5ccd6cSJohn Marino 			       name, strlen (name));
17045796c8dcSSimon Schubert 	}
17055796c8dcSSimon Schubert     }
17065796c8dcSSimon Schubert 
17075796c8dcSSimon Schubert   /* All these types really point to some (common) MIPS type
17085796c8dcSSimon Schubert      definition, and only the type-qualifiers fully identify
17095796c8dcSSimon Schubert      them.  We'll make the same effort at sharing.
17105796c8dcSSimon Schubert      FIXME: We are not doing any guessing on range types.  */
17115796c8dcSSimon Schubert   if (t->bt == btRange)
17125796c8dcSSimon Schubert     {
17135796c8dcSSimon Schubert       char *name;
17145796c8dcSSimon Schubert 
17155796c8dcSSimon Schubert       /* Try to cross reference this type, build new type on failure.  */
17165796c8dcSSimon Schubert       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
17175796c8dcSSimon Schubert       if (tp == (struct type *) NULL)
1718a45ae5f8SJohn Marino 	tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
17195796c8dcSSimon Schubert 
17205796c8dcSSimon Schubert       /* Make sure that TYPE_CODE(tp) has an expected type code.
17215796c8dcSSimon Schubert          Any type may be returned from cross_ref if file indirect entries
17225796c8dcSSimon Schubert          are corrupted.  */
17235796c8dcSSimon Schubert       if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
17245796c8dcSSimon Schubert 	{
17255796c8dcSSimon Schubert 	  unexpected_type_code_complaint (sym_name);
17265796c8dcSSimon Schubert 	}
17275796c8dcSSimon Schubert       else
17285796c8dcSSimon Schubert 	{
17295796c8dcSSimon Schubert 	  /* Usually, TYPE_CODE(tp) is already type_code.  The main
17305796c8dcSSimon Schubert 	     exception is if we guessed wrong re struct/union/enum.  */
17315796c8dcSSimon Schubert 	  if (TYPE_CODE (tp) != type_code)
17325796c8dcSSimon Schubert 	    {
17335796c8dcSSimon Schubert 	      bad_tag_guess_complaint (sym_name);
17345796c8dcSSimon Schubert 	      TYPE_CODE (tp) = type_code;
17355796c8dcSSimon Schubert 	    }
17365796c8dcSSimon Schubert 	  if (TYPE_NAME (tp) == NULL
17375796c8dcSSimon Schubert 	      || strcmp (TYPE_NAME (tp), name) != 0)
1738*ef5ccd6cSJohn Marino 	    TYPE_NAME (tp)
1739*ef5ccd6cSJohn Marino 	      = obstack_copy0 (&mdebugread_objfile->objfile_obstack,
1740*ef5ccd6cSJohn Marino 			       name, strlen (name));
17415796c8dcSSimon Schubert 	}
17425796c8dcSSimon Schubert     }
17435796c8dcSSimon Schubert   if (t->bt == btTypedef)
17445796c8dcSSimon Schubert     {
17455796c8dcSSimon Schubert       char *name;
17465796c8dcSSimon Schubert 
17475796c8dcSSimon Schubert       /* Try to cross reference this type, it should succeed.  */
17485796c8dcSSimon Schubert       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
17495796c8dcSSimon Schubert       if (tp == (struct type *) NULL)
17505796c8dcSSimon Schubert 	{
17515796c8dcSSimon Schubert 	  complaint (&symfile_complaints,
17525796c8dcSSimon Schubert 		     _("unable to cross ref btTypedef for %s"), sym_name);
1753a45ae5f8SJohn Marino 	  tp = basic_type (btInt, mdebugread_objfile);
17545796c8dcSSimon Schubert 	}
17555796c8dcSSimon Schubert     }
17565796c8dcSSimon Schubert 
1757c50c785cSJohn Marino   /* Deal with range types.  */
17585796c8dcSSimon Schubert   if (t->bt == btRange)
17595796c8dcSSimon Schubert     {
1760cf7f2e2dSJohn Marino       TYPE_NFIELDS (tp) = 0;
1761cf7f2e2dSJohn Marino       TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
1762cf7f2e2dSJohn Marino 			  TYPE_ZALLOC (tp, sizeof (struct range_bounds)));
17635796c8dcSSimon Schubert       TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
17645796c8dcSSimon Schubert       ax++;
17655796c8dcSSimon Schubert       TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
17665796c8dcSSimon Schubert       ax++;
17675796c8dcSSimon Schubert     }
17685796c8dcSSimon Schubert 
17695796c8dcSSimon Schubert   /* Parse all the type qualifiers now.  If there are more
1770c50c785cSJohn Marino      than 6 the game will continue in the next aux.  */
17715796c8dcSSimon Schubert 
17725796c8dcSSimon Schubert   while (1)
17735796c8dcSSimon Schubert     {
17745796c8dcSSimon Schubert #define PARSE_TQ(tq) \
17755796c8dcSSimon Schubert       if (t->tq != tqNil) \
17765796c8dcSSimon Schubert 	ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
17775796c8dcSSimon Schubert       else \
17785796c8dcSSimon Schubert 	break;
17795796c8dcSSimon Schubert 
17805796c8dcSSimon Schubert       PARSE_TQ (tq0);
17815796c8dcSSimon Schubert       PARSE_TQ (tq1);
17825796c8dcSSimon Schubert       PARSE_TQ (tq2);
17835796c8dcSSimon Schubert       PARSE_TQ (tq3);
17845796c8dcSSimon Schubert       PARSE_TQ (tq4);
17855796c8dcSSimon Schubert       PARSE_TQ (tq5);
17865796c8dcSSimon Schubert #undef	PARSE_TQ
17875796c8dcSSimon Schubert 
17885796c8dcSSimon Schubert       /* mips cc 2.x and gcc never put out continued aux entries.  */
17895796c8dcSSimon Schubert       if (!t->continued)
17905796c8dcSSimon Schubert 	break;
17915796c8dcSSimon Schubert 
17925796c8dcSSimon Schubert       (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
17935796c8dcSSimon Schubert       ax++;
17945796c8dcSSimon Schubert     }
17955796c8dcSSimon Schubert 
17965796c8dcSSimon Schubert   /* Complain for illegal continuations due to corrupt aux entries.  */
17975796c8dcSSimon Schubert   if (t->continued)
1798c50c785cSJohn Marino     complaint (&symfile_complaints,
1799c50c785cSJohn Marino 	       _("illegal TIR continued for %s"), sym_name);
18005796c8dcSSimon Schubert 
18015796c8dcSSimon Schubert   return tp;
18025796c8dcSSimon Schubert }
18035796c8dcSSimon Schubert 
18045796c8dcSSimon Schubert /* Make up a complex type from a basic one.  Type is passed by
18055796c8dcSSimon Schubert    reference in TPP and side-effected as necessary.  The type
18065796c8dcSSimon Schubert    qualifier TQ says how to handle the aux symbols at AX for
18075796c8dcSSimon Schubert    the symbol SX we are currently analyzing.  BIGEND says whether
18085796c8dcSSimon Schubert    aux symbols are big-endian or little-endian.
18095796c8dcSSimon Schubert    Returns the number of aux symbols we parsed.  */
18105796c8dcSSimon Schubert 
18115796c8dcSSimon Schubert static int
upgrade_type(int fd,struct type ** tpp,int tq,union aux_ext * ax,int bigend,char * sym_name)18125796c8dcSSimon Schubert upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
18135796c8dcSSimon Schubert 	      char *sym_name)
18145796c8dcSSimon Schubert {
18155796c8dcSSimon Schubert   int off;
18165796c8dcSSimon Schubert   struct type *t;
18175796c8dcSSimon Schubert 
1818c50c785cSJohn Marino   /* Used in array processing.  */
18195796c8dcSSimon Schubert   int rf, id;
18205796c8dcSSimon Schubert   FDR *fh;
18215796c8dcSSimon Schubert   struct type *range;
18225796c8dcSSimon Schubert   struct type *indx;
18235796c8dcSSimon Schubert   int lower, upper;
18245796c8dcSSimon Schubert   RNDXR rndx;
18255796c8dcSSimon Schubert 
18265796c8dcSSimon Schubert   switch (tq)
18275796c8dcSSimon Schubert     {
18285796c8dcSSimon Schubert     case tqPtr:
18295796c8dcSSimon Schubert       t = lookup_pointer_type (*tpp);
18305796c8dcSSimon Schubert       *tpp = t;
18315796c8dcSSimon Schubert       return 0;
18325796c8dcSSimon Schubert 
18335796c8dcSSimon Schubert     case tqProc:
18345796c8dcSSimon Schubert       t = lookup_function_type (*tpp);
18355796c8dcSSimon Schubert       *tpp = t;
18365796c8dcSSimon Schubert       return 0;
18375796c8dcSSimon Schubert 
18385796c8dcSSimon Schubert     case tqArray:
18395796c8dcSSimon Schubert       off = 0;
18405796c8dcSSimon Schubert 
1841c50c785cSJohn Marino       /* Determine and record the domain type (type of index).  */
18425796c8dcSSimon Schubert       (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
18435796c8dcSSimon Schubert       id = rndx.index;
18445796c8dcSSimon Schubert       rf = rndx.rfd;
18455796c8dcSSimon Schubert       if (rf == 0xfff)
18465796c8dcSSimon Schubert 	{
18475796c8dcSSimon Schubert 	  ax++;
18485796c8dcSSimon Schubert 	  rf = AUX_GET_ISYM (bigend, ax);
18495796c8dcSSimon Schubert 	  off++;
18505796c8dcSSimon Schubert 	}
18515796c8dcSSimon Schubert       fh = get_rfd (fd, rf);
18525796c8dcSSimon Schubert 
18535796c8dcSSimon Schubert       indx = parse_type (fh - debug_info->fdr,
18545796c8dcSSimon Schubert 			 debug_info->external_aux + fh->iauxBase,
18555796c8dcSSimon Schubert 			 id, (int *) NULL, bigend, sym_name);
18565796c8dcSSimon Schubert 
18575796c8dcSSimon Schubert       /* The bounds type should be an integer type, but might be anything
18585796c8dcSSimon Schubert          else due to corrupt aux entries.  */
18595796c8dcSSimon Schubert       if (TYPE_CODE (indx) != TYPE_CODE_INT)
18605796c8dcSSimon Schubert 	{
18615796c8dcSSimon Schubert 	  complaint (&symfile_complaints,
1862c50c785cSJohn Marino 		     _("illegal array index type for %s, assuming int"),
1863c50c785cSJohn Marino 		     sym_name);
1864a45ae5f8SJohn Marino 	  indx = objfile_type (mdebugread_objfile)->builtin_int;
18655796c8dcSSimon Schubert 	}
18665796c8dcSSimon Schubert 
18675796c8dcSSimon Schubert       /* Get the bounds, and create the array type.  */
18685796c8dcSSimon Schubert       ax++;
18695796c8dcSSimon Schubert       lower = AUX_GET_DNLOW (bigend, ax);
18705796c8dcSSimon Schubert       ax++;
18715796c8dcSSimon Schubert       upper = AUX_GET_DNHIGH (bigend, ax);
18725796c8dcSSimon Schubert       ax++;
18735796c8dcSSimon Schubert       rf = AUX_GET_WIDTH (bigend, ax);	/* bit size of array element */
18745796c8dcSSimon Schubert 
18755796c8dcSSimon Schubert       range = create_range_type ((struct type *) NULL, indx,
18765796c8dcSSimon Schubert 				 lower, upper);
18775796c8dcSSimon Schubert 
18785796c8dcSSimon Schubert       t = create_array_type ((struct type *) NULL, *tpp, range);
18795796c8dcSSimon Schubert 
18805796c8dcSSimon Schubert       /* We used to fill in the supplied array element bitsize
18815796c8dcSSimon Schubert          here if the TYPE_LENGTH of the target type was zero.
18825796c8dcSSimon Schubert          This happens for a `pointer to an array of anonymous structs',
18835796c8dcSSimon Schubert          but in this case the array element bitsize is also zero,
18845796c8dcSSimon Schubert          so nothing is gained.
18855796c8dcSSimon Schubert          And we used to check the TYPE_LENGTH of the target type against
18865796c8dcSSimon Schubert          the supplied array element bitsize.
18875796c8dcSSimon Schubert          gcc causes a mismatch for `pointer to array of object',
18885796c8dcSSimon Schubert          since the sdb directives it uses do not have a way of
18895796c8dcSSimon Schubert          specifying the bitsize, but it does no harm (the
18905796c8dcSSimon Schubert          TYPE_LENGTH should be correct) and we should be able to
18915796c8dcSSimon Schubert          ignore the erroneous bitsize from the auxiliary entry safely.
18925796c8dcSSimon Schubert          dbx seems to ignore it too.  */
18935796c8dcSSimon Schubert 
18945796c8dcSSimon Schubert       /* TYPE_TARGET_STUB now takes care of the zero TYPE_LENGTH problem.  */
18955796c8dcSSimon Schubert       if (TYPE_LENGTH (*tpp) == 0)
18965796c8dcSSimon Schubert 	TYPE_TARGET_STUB (t) = 1;
18975796c8dcSSimon Schubert 
18985796c8dcSSimon Schubert       *tpp = t;
18995796c8dcSSimon Schubert       return 4 + off;
19005796c8dcSSimon Schubert 
19015796c8dcSSimon Schubert     case tqVol:
19025796c8dcSSimon Schubert       /* Volatile -- currently ignored */
19035796c8dcSSimon Schubert       return 0;
19045796c8dcSSimon Schubert 
19055796c8dcSSimon Schubert     case tqConst:
19065796c8dcSSimon Schubert       /* Const -- currently ignored */
19075796c8dcSSimon Schubert       return 0;
19085796c8dcSSimon Schubert 
19095796c8dcSSimon Schubert     default:
19105796c8dcSSimon Schubert       complaint (&symfile_complaints, _("unknown type qualifier 0x%x"), tq);
19115796c8dcSSimon Schubert       return 0;
19125796c8dcSSimon Schubert     }
19135796c8dcSSimon Schubert }
19145796c8dcSSimon Schubert 
19155796c8dcSSimon Schubert 
19165796c8dcSSimon Schubert /* Parse a procedure descriptor record PR.  Note that the procedure is
19175796c8dcSSimon Schubert    parsed _after_ the local symbols, now we just insert the extra
19185796c8dcSSimon Schubert    information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has
19195796c8dcSSimon Schubert    already been placed in the procedure's main block.  Note also that
19205796c8dcSSimon Schubert    images that have been partially stripped (ld -x) have been deprived
19215796c8dcSSimon Schubert    of local symbols, and we have to cope with them here.  FIRST_OFF is
19225796c8dcSSimon Schubert    the offset of the first procedure for this FDR; we adjust the
19235796c8dcSSimon Schubert    address by this amount, but I don't know why.  SEARCH_SYMTAB is the symtab
19245796c8dcSSimon Schubert    to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol
19255796c8dcSSimon Schubert    in question, or NULL to use top_stack->cur_block.  */
19265796c8dcSSimon Schubert 
19275796c8dcSSimon Schubert static void parse_procedure (PDR *, struct symtab *, struct partial_symtab *);
19285796c8dcSSimon Schubert 
19295796c8dcSSimon Schubert static void
parse_procedure(PDR * pr,struct symtab * search_symtab,struct partial_symtab * pst)19305796c8dcSSimon Schubert parse_procedure (PDR *pr, struct symtab *search_symtab,
19315796c8dcSSimon Schubert 		 struct partial_symtab *pst)
19325796c8dcSSimon Schubert {
19335796c8dcSSimon Schubert   struct symbol *s, *i;
19345796c8dcSSimon Schubert   struct block *b;
19355796c8dcSSimon Schubert   char *sh_name;
19365796c8dcSSimon Schubert 
1937c50c785cSJohn Marino   /* Simple rule to find files linked "-x".  */
19385796c8dcSSimon Schubert   if (cur_fdr->rss == -1)
19395796c8dcSSimon Schubert     {
19405796c8dcSSimon Schubert       if (pr->isym == -1)
19415796c8dcSSimon Schubert 	{
19425796c8dcSSimon Schubert 	  /* Static procedure at address pr->adr.  Sigh.  */
19435796c8dcSSimon Schubert 	  /* FIXME-32x64.  assuming pr->adr fits in long.  */
19445796c8dcSSimon Schubert 	  complaint (&symfile_complaints,
19455796c8dcSSimon Schubert 		     _("can't handle PDR for static proc at 0x%lx"),
19465796c8dcSSimon Schubert 		     (unsigned long) pr->adr);
19475796c8dcSSimon Schubert 	  return;
19485796c8dcSSimon Schubert 	}
19495796c8dcSSimon Schubert       else
19505796c8dcSSimon Schubert 	{
19515796c8dcSSimon Schubert 	  /* external */
19525796c8dcSSimon Schubert 	  EXTR she;
19535796c8dcSSimon Schubert 
19545796c8dcSSimon Schubert 	  (*debug_swap->swap_ext_in) (cur_bfd,
19555796c8dcSSimon Schubert 				      ((char *) debug_info->external_ext
19565796c8dcSSimon Schubert 				       + (pr->isym
19575796c8dcSSimon Schubert 					  * debug_swap->external_ext_size)),
19585796c8dcSSimon Schubert 				      &she);
19595796c8dcSSimon Schubert 	  sh_name = debug_info->ssext + she.asym.iss;
19605796c8dcSSimon Schubert 	}
19615796c8dcSSimon Schubert     }
19625796c8dcSSimon Schubert   else
19635796c8dcSSimon Schubert     {
19645796c8dcSSimon Schubert       /* Full symbols */
19655796c8dcSSimon Schubert       SYMR sh;
19665796c8dcSSimon Schubert 
19675796c8dcSSimon Schubert       (*debug_swap->swap_sym_in) (cur_bfd,
19685796c8dcSSimon Schubert 				  ((char *) debug_info->external_sym
19695796c8dcSSimon Schubert 				   + ((cur_fdr->isymBase + pr->isym)
19705796c8dcSSimon Schubert 				      * debug_swap->external_sym_size)),
19715796c8dcSSimon Schubert 				  &sh);
19725796c8dcSSimon Schubert       sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
19735796c8dcSSimon Schubert     }
19745796c8dcSSimon Schubert 
19755796c8dcSSimon Schubert   if (search_symtab != NULL)
19765796c8dcSSimon Schubert     {
19775796c8dcSSimon Schubert #if 0
19785796c8dcSSimon Schubert       /* This loses both in the case mentioned (want a static, find a global),
19795796c8dcSSimon Schubert          but also if we are looking up a non-mangled name which happens to
19805796c8dcSSimon Schubert          match the name of a mangled function.  */
19815796c8dcSSimon Schubert       /* We have to save the cur_fdr across the call to lookup_symbol.
19825796c8dcSSimon Schubert          If the pdr is for a static function and if a global function with
19835796c8dcSSimon Schubert          the same name exists, lookup_symbol will eventually read in the symtab
19845796c8dcSSimon Schubert          for the global function and clobber cur_fdr.  */
19855796c8dcSSimon Schubert       FDR *save_cur_fdr = cur_fdr;
1986cf7f2e2dSJohn Marino 
19875796c8dcSSimon Schubert       s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0);
19885796c8dcSSimon Schubert       cur_fdr = save_cur_fdr;
19895796c8dcSSimon Schubert #else
19905796c8dcSSimon Schubert       s = mylookup_symbol
19915796c8dcSSimon Schubert 	(sh_name,
19925796c8dcSSimon Schubert 	 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK),
19935796c8dcSSimon Schubert 	 VAR_DOMAIN,
19945796c8dcSSimon Schubert 	 LOC_BLOCK);
19955796c8dcSSimon Schubert #endif
19965796c8dcSSimon Schubert     }
19975796c8dcSSimon Schubert   else
19985796c8dcSSimon Schubert     s = mylookup_symbol (sh_name, top_stack->cur_block,
19995796c8dcSSimon Schubert 			 VAR_DOMAIN, LOC_BLOCK);
20005796c8dcSSimon Schubert 
20015796c8dcSSimon Schubert   if (s != 0)
20025796c8dcSSimon Schubert     {
20035796c8dcSSimon Schubert       b = SYMBOL_BLOCK_VALUE (s);
20045796c8dcSSimon Schubert     }
20055796c8dcSSimon Schubert   else
20065796c8dcSSimon Schubert     {
20075796c8dcSSimon Schubert       complaint (&symfile_complaints, _("PDR for %s, but no symbol"), sh_name);
20085796c8dcSSimon Schubert #if 1
20095796c8dcSSimon Schubert       return;
20105796c8dcSSimon Schubert #else
20115796c8dcSSimon Schubert /* FIXME -- delete.  We can't do symbol allocation now; it's all done.  */
20125796c8dcSSimon Schubert       s = new_symbol (sh_name);
20135796c8dcSSimon Schubert       SYMBOL_DOMAIN (s) = VAR_DOMAIN;
20145796c8dcSSimon Schubert       SYMBOL_CLASS (s) = LOC_BLOCK;
2015c50c785cSJohn Marino       /* Donno its type, hope int is ok.  */
20165796c8dcSSimon Schubert       SYMBOL_TYPE (s)
20175796c8dcSSimon Schubert 	= lookup_function_type (objfile_type (pst->objfile)->builtin_int);
20185796c8dcSSimon Schubert       add_symbol (s, top_stack->cur_st, top_stack->cur_block);
2019c50c785cSJohn Marino       /* Won't have symbols for this one.  */
20205796c8dcSSimon Schubert       b = new_block (2);
20215796c8dcSSimon Schubert       SYMBOL_BLOCK_VALUE (s) = b;
20225796c8dcSSimon Schubert       BLOCK_FUNCTION (b) = s;
20235796c8dcSSimon Schubert       BLOCK_START (b) = pr->adr;
20245796c8dcSSimon Schubert       /* BOUND used to be the end of procedure's text, but the
20255796c8dcSSimon Schubert          argument is no longer passed in.  */
20265796c8dcSSimon Schubert       BLOCK_END (b) = bound;
20275796c8dcSSimon Schubert       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
20285796c8dcSSimon Schubert       add_block (b, top_stack->cur_st);
20295796c8dcSSimon Schubert #endif
20305796c8dcSSimon Schubert     }
20315796c8dcSSimon Schubert 
20325796c8dcSSimon Schubert   i = mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST);
20335796c8dcSSimon Schubert 
20345796c8dcSSimon Schubert   if (i)
20355796c8dcSSimon Schubert     {
20365796c8dcSSimon Schubert       struct mdebug_extra_func_info *e;
20375796c8dcSSimon Schubert 
20385796c8dcSSimon Schubert       e = (struct mdebug_extra_func_info *) SYMBOL_VALUE_BYTES (i);
20395796c8dcSSimon Schubert       e->pdr = *pr;
20405796c8dcSSimon Schubert 
20415796c8dcSSimon Schubert       /* GDB expects the absolute function start address for the
20425796c8dcSSimon Schubert          procedure descriptor in e->pdr.adr.
20435796c8dcSSimon Schubert          As the address in the procedure descriptor is usually relative,
20445796c8dcSSimon Schubert          we would have to relocate e->pdr.adr with cur_fdr->adr and
20455796c8dcSSimon Schubert          ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)).
20465796c8dcSSimon Schubert          Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
20475796c8dcSSimon Schubert          in shared libraries on some systems, and on other systems
20485796c8dcSSimon Schubert          e->pdr.adr is sometimes offset by a bogus value.
20495796c8dcSSimon Schubert          To work around these problems, we replace e->pdr.adr with
20505796c8dcSSimon Schubert          the start address of the function.  */
20515796c8dcSSimon Schubert       e->pdr.adr = BLOCK_START (b);
20525796c8dcSSimon Schubert     }
20535796c8dcSSimon Schubert 
20545796c8dcSSimon Schubert   /* It would be reasonable that functions that have been compiled
20555796c8dcSSimon Schubert      without debugging info have a btNil type for their return value,
20565796c8dcSSimon Schubert      and functions that are void and are compiled with debugging info
20575796c8dcSSimon Schubert      have btVoid.
20585796c8dcSSimon Schubert      gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
20595796c8dcSSimon Schubert      to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
20605796c8dcSSimon Schubert      case right.
20615796c8dcSSimon Schubert      The glevel field in cur_fdr could be used to determine the presence
20625796c8dcSSimon Schubert      of debugging info, but GCC doesn't always pass the -g switch settings
20635796c8dcSSimon Schubert      to the assembler and GAS doesn't set the glevel field from the -g switch
20645796c8dcSSimon Schubert      settings.
20655796c8dcSSimon Schubert      To work around these problems, the return value type of a TYPE_CODE_VOID
20665796c8dcSSimon Schubert      function is adjusted accordingly if no debugging info was found in the
20675796c8dcSSimon Schubert      compilation unit.  */
20685796c8dcSSimon Schubert 
20695796c8dcSSimon Schubert   if (processing_gcc_compilation == 0
20705796c8dcSSimon Schubert       && found_ecoff_debugging_info == 0
20715796c8dcSSimon Schubert       && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID)
2072*ef5ccd6cSJohn Marino     SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->nodebug_text_symbol;
20735796c8dcSSimon Schubert }
20745796c8dcSSimon Schubert 
20755796c8dcSSimon Schubert /* Parse the external symbol ES.  Just call parse_symbol() after
20765796c8dcSSimon Schubert    making sure we know where the aux are for it.
20775796c8dcSSimon Schubert    BIGEND says whether aux entries are big-endian or little-endian.
20785796c8dcSSimon Schubert 
20795796c8dcSSimon Schubert    This routine clobbers top_stack->cur_block and ->cur_st.  */
20805796c8dcSSimon Schubert 
20815796c8dcSSimon Schubert static void parse_external (EXTR *, int, struct section_offsets *,
20825796c8dcSSimon Schubert 			    struct objfile *);
20835796c8dcSSimon Schubert 
20845796c8dcSSimon Schubert static void
parse_external(EXTR * es,int bigend,struct section_offsets * section_offsets,struct objfile * objfile)20855796c8dcSSimon Schubert parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
20865796c8dcSSimon Schubert 		struct objfile *objfile)
20875796c8dcSSimon Schubert {
20885796c8dcSSimon Schubert   union aux_ext *ax;
20895796c8dcSSimon Schubert 
20905796c8dcSSimon Schubert   if (es->ifd != ifdNil)
20915796c8dcSSimon Schubert     {
20925796c8dcSSimon Schubert       cur_fd = es->ifd;
20935796c8dcSSimon Schubert       cur_fdr = debug_info->fdr + cur_fd;
20945796c8dcSSimon Schubert       ax = debug_info->external_aux + cur_fdr->iauxBase;
20955796c8dcSSimon Schubert     }
20965796c8dcSSimon Schubert   else
20975796c8dcSSimon Schubert     {
20985796c8dcSSimon Schubert       cur_fdr = debug_info->fdr;
20995796c8dcSSimon Schubert       ax = 0;
21005796c8dcSSimon Schubert     }
21015796c8dcSSimon Schubert 
21025796c8dcSSimon Schubert   /* Reading .o files */
21035796c8dcSSimon Schubert   if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
21045796c8dcSSimon Schubert     {
21055796c8dcSSimon Schubert       char *what;
21065796c8dcSSimon Schubert       switch (es->asym.st)
21075796c8dcSSimon Schubert 	{
21085796c8dcSSimon Schubert 	case stNil:
21095796c8dcSSimon Schubert 	  /* These are generated for static symbols in .o files,
21105796c8dcSSimon Schubert 	     ignore them.  */
21115796c8dcSSimon Schubert 	  return;
21125796c8dcSSimon Schubert 	case stStaticProc:
21135796c8dcSSimon Schubert 	case stProc:
21145796c8dcSSimon Schubert 	  what = "procedure";
21155796c8dcSSimon Schubert 	  n_undef_procs++;
21165796c8dcSSimon Schubert 	  break;
21175796c8dcSSimon Schubert 	case stGlobal:
21185796c8dcSSimon Schubert 	  what = "variable";
21195796c8dcSSimon Schubert 	  n_undef_vars++;
21205796c8dcSSimon Schubert 	  break;
21215796c8dcSSimon Schubert 	case stLabel:
21225796c8dcSSimon Schubert 	  what = "label";
21235796c8dcSSimon Schubert 	  n_undef_labels++;
21245796c8dcSSimon Schubert 	  break;
21255796c8dcSSimon Schubert 	default:
21265796c8dcSSimon Schubert 	  what = "symbol";
21275796c8dcSSimon Schubert 	  break;
21285796c8dcSSimon Schubert 	}
21295796c8dcSSimon Schubert       n_undef_symbols++;
21305796c8dcSSimon Schubert       /* FIXME:  Turn this into a complaint?  */
21315796c8dcSSimon Schubert       if (info_verbose)
21325796c8dcSSimon Schubert 	printf_filtered (_("Warning: %s `%s' is undefined (in %s)\n"),
21335796c8dcSSimon Schubert 			 what, debug_info->ssext + es->asym.iss,
21345796c8dcSSimon Schubert 			 fdr_name (cur_fdr));
21355796c8dcSSimon Schubert       return;
21365796c8dcSSimon Schubert     }
21375796c8dcSSimon Schubert 
21385796c8dcSSimon Schubert   switch (es->asym.st)
21395796c8dcSSimon Schubert     {
21405796c8dcSSimon Schubert     case stProc:
21415796c8dcSSimon Schubert     case stStaticProc:
21425796c8dcSSimon Schubert       /* There is no need to parse the external procedure symbols.
21435796c8dcSSimon Schubert          If they are from objects compiled without -g, their index will
21445796c8dcSSimon Schubert          be indexNil, and the symbol definition from the minimal symbol
21455796c8dcSSimon Schubert          is preferrable (yielding a function returning int instead of int).
21465796c8dcSSimon Schubert          If the index points to a local procedure symbol, the local
21475796c8dcSSimon Schubert          symbol already provides the correct type.
21485796c8dcSSimon Schubert          Note that the index of the external procedure symbol points
21495796c8dcSSimon Schubert          to the local procedure symbol in the local symbol table, and
21505796c8dcSSimon Schubert          _not_ to the auxiliary symbol info.  */
21515796c8dcSSimon Schubert       break;
21525796c8dcSSimon Schubert     case stGlobal:
21535796c8dcSSimon Schubert     case stLabel:
21545796c8dcSSimon Schubert       /* Global common symbols are resolved by the runtime loader,
21555796c8dcSSimon Schubert          ignore them.  */
21565796c8dcSSimon Schubert       if (SC_IS_COMMON (es->asym.sc))
21575796c8dcSSimon Schubert 	break;
21585796c8dcSSimon Schubert 
21595796c8dcSSimon Schubert       /* Note that the case of a symbol with indexNil must be handled
21605796c8dcSSimon Schubert          anyways by parse_symbol().  */
2161c50c785cSJohn Marino       parse_symbol (&es->asym, ax, (char *) NULL,
2162c50c785cSJohn Marino 		    bigend, section_offsets, objfile);
21635796c8dcSSimon Schubert       break;
21645796c8dcSSimon Schubert     default:
21655796c8dcSSimon Schubert       break;
21665796c8dcSSimon Schubert     }
21675796c8dcSSimon Schubert }
21685796c8dcSSimon Schubert 
21695796c8dcSSimon Schubert /* Parse the line number info for file descriptor FH into
21705796c8dcSSimon Schubert    GDB's linetable LT.  MIPS' encoding requires a little bit
21715796c8dcSSimon Schubert    of magic to get things out.  Note also that MIPS' line
21725796c8dcSSimon Schubert    numbers can go back and forth, apparently we can live
2173c50c785cSJohn Marino    with that and do not need to reorder our linetables.  */
21745796c8dcSSimon Schubert 
21755796c8dcSSimon Schubert static void parse_lines (FDR *, PDR *, struct linetable *, int,
21765796c8dcSSimon Schubert 			 struct partial_symtab *, CORE_ADDR);
21775796c8dcSSimon Schubert 
21785796c8dcSSimon Schubert static void
parse_lines(FDR * fh,PDR * pr,struct linetable * lt,int maxlines,struct partial_symtab * pst,CORE_ADDR lowest_pdr_addr)21795796c8dcSSimon Schubert parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
21805796c8dcSSimon Schubert 	     struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
21815796c8dcSSimon Schubert {
21825796c8dcSSimon Schubert   unsigned char *base;
21835796c8dcSSimon Schubert   int j, k;
21845796c8dcSSimon Schubert   int delta, count, lineno = 0;
21855796c8dcSSimon Schubert 
21865796c8dcSSimon Schubert   if (fh->cbLine == 0)
21875796c8dcSSimon Schubert     return;
21885796c8dcSSimon Schubert 
2189c50c785cSJohn Marino   /* Scan by procedure descriptors.  */
21905796c8dcSSimon Schubert   k = 0;
21915796c8dcSSimon Schubert   for (j = 0; j < fh->cpd; j++, pr++)
21925796c8dcSSimon Schubert     {
21935796c8dcSSimon Schubert       CORE_ADDR l;
21945796c8dcSSimon Schubert       CORE_ADDR adr;
21955796c8dcSSimon Schubert       unsigned char *halt;
21965796c8dcSSimon Schubert 
2197c50c785cSJohn Marino       /* No code for this one.  */
21985796c8dcSSimon Schubert       if (pr->iline == ilineNil ||
21995796c8dcSSimon Schubert 	  pr->lnLow == -1 || pr->lnHigh == -1)
22005796c8dcSSimon Schubert 	continue;
22015796c8dcSSimon Schubert 
22025796c8dcSSimon Schubert       /* Determine start and end address of compressed line bytes for
22035796c8dcSSimon Schubert          this procedure.  */
22045796c8dcSSimon Schubert       base = debug_info->line + fh->cbLineOffset;
22055796c8dcSSimon Schubert       if (j != (fh->cpd - 1))
22065796c8dcSSimon Schubert 	halt = base + pr[1].cbLineOffset;
22075796c8dcSSimon Schubert       else
22085796c8dcSSimon Schubert 	halt = base + fh->cbLine;
22095796c8dcSSimon Schubert       base += pr->cbLineOffset;
22105796c8dcSSimon Schubert 
22115796c8dcSSimon Schubert       adr = pst->textlow + pr->adr - lowest_pdr_addr;
22125796c8dcSSimon Schubert 
22135796c8dcSSimon Schubert       l = adr >> 2;		/* in words */
22145796c8dcSSimon Schubert       for (lineno = pr->lnLow; base < halt;)
22155796c8dcSSimon Schubert 	{
22165796c8dcSSimon Schubert 	  count = *base & 0x0f;
22175796c8dcSSimon Schubert 	  delta = *base++ >> 4;
22185796c8dcSSimon Schubert 	  if (delta >= 8)
22195796c8dcSSimon Schubert 	    delta -= 16;
22205796c8dcSSimon Schubert 	  if (delta == -8)
22215796c8dcSSimon Schubert 	    {
22225796c8dcSSimon Schubert 	      delta = (base[0] << 8) | base[1];
22235796c8dcSSimon Schubert 	      if (delta >= 0x8000)
22245796c8dcSSimon Schubert 		delta -= 0x10000;
22255796c8dcSSimon Schubert 	      base += 2;
22265796c8dcSSimon Schubert 	    }
22275796c8dcSSimon Schubert 	  lineno += delta;	/* first delta is 0 */
22285796c8dcSSimon Schubert 
22295796c8dcSSimon Schubert 	  /* Complain if the line table overflows.  Could happen
22305796c8dcSSimon Schubert 	     with corrupt binaries.  */
22315796c8dcSSimon Schubert 	  if (lt->nitems >= maxlines)
22325796c8dcSSimon Schubert 	    {
22335796c8dcSSimon Schubert 	      complaint (&symfile_complaints,
22345796c8dcSSimon Schubert 			 _("guessed size of linetable for %s incorrectly"),
22355796c8dcSSimon Schubert 			 fdr_name (fh));
22365796c8dcSSimon Schubert 	      break;
22375796c8dcSSimon Schubert 	    }
22385796c8dcSSimon Schubert 	  k = add_line (lt, lineno, l, k);
22395796c8dcSSimon Schubert 	  l += count + 1;
22405796c8dcSSimon Schubert 	}
22415796c8dcSSimon Schubert     }
22425796c8dcSSimon Schubert }
22435796c8dcSSimon Schubert 
22445796c8dcSSimon Schubert static void
function_outside_compilation_unit_complaint(const char * arg1)22455796c8dcSSimon Schubert function_outside_compilation_unit_complaint (const char *arg1)
22465796c8dcSSimon Schubert {
22475796c8dcSSimon Schubert   complaint (&symfile_complaints,
2248c50c785cSJohn Marino 	     _("function `%s' appears to be defined "
2249c50c785cSJohn Marino 	       "outside of all compilation units"),
22505796c8dcSSimon Schubert 	     arg1);
22515796c8dcSSimon Schubert }
22525796c8dcSSimon Schubert 
22535796c8dcSSimon Schubert /* Use the STORAGE_CLASS to compute which section the given symbol
22545796c8dcSSimon Schubert    belongs to, and then records this new minimal symbol.  */
22555796c8dcSSimon Schubert 
22565796c8dcSSimon Schubert static void
record_minimal_symbol(const char * name,const CORE_ADDR address,enum minimal_symbol_type ms_type,int storage_class,struct objfile * objfile)22575796c8dcSSimon Schubert record_minimal_symbol (const char *name, const CORE_ADDR address,
22585796c8dcSSimon Schubert                        enum minimal_symbol_type ms_type, int storage_class,
22595796c8dcSSimon Schubert                        struct objfile *objfile)
22605796c8dcSSimon Schubert {
22615796c8dcSSimon Schubert   int section;
22625796c8dcSSimon Schubert   asection *bfd_section;
22635796c8dcSSimon Schubert 
22645796c8dcSSimon Schubert   switch (storage_class)
22655796c8dcSSimon Schubert     {
22665796c8dcSSimon Schubert       case scText:
22675796c8dcSSimon Schubert         section = SECT_OFF_TEXT (objfile);
22685796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".text");
22695796c8dcSSimon Schubert         break;
22705796c8dcSSimon Schubert       case scData:
22715796c8dcSSimon Schubert         section = SECT_OFF_DATA (objfile);
22725796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".data");
22735796c8dcSSimon Schubert         break;
22745796c8dcSSimon Schubert       case scBss:
22755796c8dcSSimon Schubert         section = SECT_OFF_BSS (objfile);
22765796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".bss");
22775796c8dcSSimon Schubert         break;
22785796c8dcSSimon Schubert       case scSData:
22795796c8dcSSimon Schubert         section = get_section_index (objfile, ".sdata");
22805796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".sdata");
22815796c8dcSSimon Schubert         break;
22825796c8dcSSimon Schubert       case scSBss:
22835796c8dcSSimon Schubert         section = get_section_index (objfile, ".sbss");
22845796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".sbss");
22855796c8dcSSimon Schubert         break;
22865796c8dcSSimon Schubert       case scRData:
22875796c8dcSSimon Schubert         section = get_section_index (objfile, ".rdata");
22885796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".rdata");
22895796c8dcSSimon Schubert         break;
22905796c8dcSSimon Schubert       case scInit:
22915796c8dcSSimon Schubert         section = get_section_index (objfile, ".init");
22925796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".init");
22935796c8dcSSimon Schubert         break;
22945796c8dcSSimon Schubert       case scXData:
22955796c8dcSSimon Schubert         section = get_section_index (objfile, ".xdata");
22965796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".xdata");
22975796c8dcSSimon Schubert         break;
22985796c8dcSSimon Schubert       case scPData:
22995796c8dcSSimon Schubert         section = get_section_index (objfile, ".pdata");
23005796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".pdata");
23015796c8dcSSimon Schubert         break;
23025796c8dcSSimon Schubert       case scFini:
23035796c8dcSSimon Schubert         section = get_section_index (objfile, ".fini");
23045796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".fini");
23055796c8dcSSimon Schubert         break;
23065796c8dcSSimon Schubert       case scRConst:
23075796c8dcSSimon Schubert         section = get_section_index (objfile, ".rconst");
23085796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".rconst");
23095796c8dcSSimon Schubert         break;
23105796c8dcSSimon Schubert #ifdef scTlsData
23115796c8dcSSimon Schubert       case scTlsData:
23125796c8dcSSimon Schubert         section = get_section_index (objfile, ".tlsdata");
23135796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".tlsdata");
23145796c8dcSSimon Schubert         break;
23155796c8dcSSimon Schubert #endif
23165796c8dcSSimon Schubert #ifdef scTlsBss
23175796c8dcSSimon Schubert       case scTlsBss:
23185796c8dcSSimon Schubert         section = get_section_index (objfile, ".tlsbss");
23195796c8dcSSimon Schubert         bfd_section = bfd_get_section_by_name (cur_bfd, ".tlsbss");
23205796c8dcSSimon Schubert         break;
23215796c8dcSSimon Schubert #endif
23225796c8dcSSimon Schubert       default:
23235796c8dcSSimon Schubert         /* This kind of symbol is not associated to a section.  */
23245796c8dcSSimon Schubert         section = -1;
23255796c8dcSSimon Schubert         bfd_section = NULL;
23265796c8dcSSimon Schubert     }
23275796c8dcSSimon Schubert 
23285796c8dcSSimon Schubert   prim_record_minimal_symbol_and_info (name, address, ms_type,
23295796c8dcSSimon Schubert                                        section, bfd_section, objfile);
23305796c8dcSSimon Schubert }
23315796c8dcSSimon Schubert 
23325796c8dcSSimon Schubert /* Master parsing procedure for first-pass reading of file symbols
23335796c8dcSSimon Schubert    into a partial_symtab.  */
23345796c8dcSSimon Schubert 
23355796c8dcSSimon Schubert static void
parse_partial_symbols(struct objfile * objfile)23365796c8dcSSimon Schubert parse_partial_symbols (struct objfile *objfile)
23375796c8dcSSimon Schubert {
23385796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
23395796c8dcSSimon Schubert   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
23405796c8dcSSimon Schubert   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
23415796c8dcSSimon Schubert   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
23425796c8dcSSimon Schubert   void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
23435796c8dcSSimon Schubert   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
23445796c8dcSSimon Schubert   void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
23455796c8dcSSimon Schubert   int f_idx, s_idx;
23465796c8dcSSimon Schubert   HDRR *hdr = &debug_info->symbolic_header;
23475796c8dcSSimon Schubert   /* Running pointers */
23485796c8dcSSimon Schubert   FDR *fh;
23495796c8dcSSimon Schubert   char *ext_out;
23505796c8dcSSimon Schubert   char *ext_out_end;
23515796c8dcSSimon Schubert   EXTR *ext_block;
23525796c8dcSSimon Schubert   EXTR *ext_in;
23535796c8dcSSimon Schubert   EXTR *ext_in_end;
23545796c8dcSSimon Schubert   SYMR sh;
23555796c8dcSSimon Schubert   struct partial_symtab *pst;
23565796c8dcSSimon Schubert   int textlow_not_set = 1;
23575796c8dcSSimon Schubert   int past_first_source_file = 0;
23585796c8dcSSimon Schubert 
2359c50c785cSJohn Marino   /* List of current psymtab's include files.  */
2360*ef5ccd6cSJohn Marino   const char **psymtab_include_list;
23615796c8dcSSimon Schubert   int includes_allocated;
23625796c8dcSSimon Schubert   int includes_used;
23635796c8dcSSimon Schubert   EXTR *extern_tab;
23645796c8dcSSimon Schubert   struct pst_map *fdr_to_pst;
2365c50c785cSJohn Marino   /* Index within current psymtab dependency list.  */
23665796c8dcSSimon Schubert   struct partial_symtab **dependency_list;
23675796c8dcSSimon Schubert   int dependencies_used, dependencies_allocated;
23685796c8dcSSimon Schubert   struct cleanup *old_chain;
23695796c8dcSSimon Schubert   char *name;
23705796c8dcSSimon Schubert   enum language prev_language;
23715796c8dcSSimon Schubert   asection *text_sect;
23725796c8dcSSimon Schubert   int relocatable = 0;
23735796c8dcSSimon Schubert 
23745796c8dcSSimon Schubert   /* Irix 5.2 shared libraries have a fh->adr field of zero, but
23755796c8dcSSimon Schubert      the shared libraries are prelinked at a high memory address.
23765796c8dcSSimon Schubert      We have to adjust the start address of the object file for this case,
23775796c8dcSSimon Schubert      by setting it to the start address of the first procedure in the file.
23785796c8dcSSimon Schubert      But we should do no adjustments if we are debugging a .o file, where
23795796c8dcSSimon Schubert      the text section (and fh->adr) really starts at zero.  */
23805796c8dcSSimon Schubert   text_sect = bfd_get_section_by_name (cur_bfd, ".text");
23815796c8dcSSimon Schubert   if (text_sect != NULL
23825796c8dcSSimon Schubert       && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC))
23835796c8dcSSimon Schubert     relocatable = 1;
23845796c8dcSSimon Schubert 
23855796c8dcSSimon Schubert   extern_tab = (EXTR *) obstack_alloc (&objfile->objfile_obstack,
23865796c8dcSSimon Schubert 				       sizeof (EXTR) * hdr->iextMax);
23875796c8dcSSimon Schubert 
23885796c8dcSSimon Schubert   includes_allocated = 30;
23895796c8dcSSimon Schubert   includes_used = 0;
2390*ef5ccd6cSJohn Marino   psymtab_include_list = (const char **) alloca (includes_allocated *
2391*ef5ccd6cSJohn Marino 						 sizeof (const char *));
23925796c8dcSSimon Schubert   next_symbol_text_func = mdebug_next_symbol_text;
23935796c8dcSSimon Schubert 
23945796c8dcSSimon Schubert   dependencies_allocated = 30;
23955796c8dcSSimon Schubert   dependencies_used = 0;
23965796c8dcSSimon Schubert   dependency_list =
23975796c8dcSSimon Schubert     (struct partial_symtab **) alloca (dependencies_allocated *
23985796c8dcSSimon Schubert 				       sizeof (struct partial_symtab *));
23995796c8dcSSimon Schubert 
2400*ef5ccd6cSJohn Marino   set_last_source_file (NULL);
24015796c8dcSSimon Schubert 
24025796c8dcSSimon Schubert   /*
24035796c8dcSSimon Schubert    * Big plan:
24045796c8dcSSimon Schubert    *
24055796c8dcSSimon Schubert    * Only parse the Local and External symbols, and the Relative FDR.
24065796c8dcSSimon Schubert    * Fixup enough of the loader symtab to be able to use it.
24075796c8dcSSimon Schubert    * Allocate space only for the file's portions we need to
24085796c8dcSSimon Schubert    * look at.  (XXX)
24095796c8dcSSimon Schubert    */
24105796c8dcSSimon Schubert 
24115796c8dcSSimon Schubert   max_gdbinfo = 0;
24125796c8dcSSimon Schubert   max_glevel = MIN_GLEVEL;
24135796c8dcSSimon Schubert 
24145796c8dcSSimon Schubert   /* Allocate the map FDR -> PST.
24155796c8dcSSimon Schubert      Minor hack: -O3 images might claim some global data belongs
2416c50c785cSJohn Marino      to FDR -1.  We`ll go along with that.  */
2417c50c785cSJohn Marino   fdr_to_pst = (struct pst_map *)
2418c50c785cSJohn Marino     xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
24195796c8dcSSimon Schubert   old_chain = make_cleanup (xfree, fdr_to_pst);
24205796c8dcSSimon Schubert   fdr_to_pst++;
24215796c8dcSSimon Schubert   {
24225796c8dcSSimon Schubert     struct partial_symtab *pst = new_psymtab ("", objfile);
2423cf7f2e2dSJohn Marino 
24245796c8dcSSimon Schubert     fdr_to_pst[-1].pst = pst;
24255796c8dcSSimon Schubert     FDR_IDX (pst) = -1;
24265796c8dcSSimon Schubert   }
24275796c8dcSSimon Schubert 
24285796c8dcSSimon Schubert   /* Allocate the global pending list.  */
24295796c8dcSSimon Schubert   pending_list =
24305796c8dcSSimon Schubert     ((struct mdebug_pending **)
24315796c8dcSSimon Schubert      obstack_alloc (&objfile->objfile_obstack,
24325796c8dcSSimon Schubert 		    hdr->ifdMax * sizeof (struct mdebug_pending *)));
24335796c8dcSSimon Schubert   memset (pending_list, 0,
24345796c8dcSSimon Schubert 	  hdr->ifdMax * sizeof (struct mdebug_pending *));
24355796c8dcSSimon Schubert 
24365796c8dcSSimon Schubert   /* Pass 0 over external syms: swap them in.  */
24375796c8dcSSimon Schubert   ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
24385796c8dcSSimon Schubert   make_cleanup (xfree, ext_block);
24395796c8dcSSimon Schubert 
24405796c8dcSSimon Schubert   ext_out = (char *) debug_info->external_ext;
24415796c8dcSSimon Schubert   ext_out_end = ext_out + hdr->iextMax * external_ext_size;
24425796c8dcSSimon Schubert   ext_in = ext_block;
24435796c8dcSSimon Schubert   for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
24445796c8dcSSimon Schubert     (*swap_ext_in) (cur_bfd, ext_out, ext_in);
24455796c8dcSSimon Schubert 
2446c50c785cSJohn Marino   /* Pass 1 over external syms: Presize and partition the list.  */
24475796c8dcSSimon Schubert   ext_in = ext_block;
24485796c8dcSSimon Schubert   ext_in_end = ext_in + hdr->iextMax;
24495796c8dcSSimon Schubert   for (; ext_in < ext_in_end; ext_in++)
24505796c8dcSSimon Schubert     {
24515796c8dcSSimon Schubert       /* See calls to complain below.  */
24525796c8dcSSimon Schubert       if (ext_in->ifd >= -1
24535796c8dcSSimon Schubert 	  && ext_in->ifd < hdr->ifdMax
24545796c8dcSSimon Schubert 	  && ext_in->asym.iss >= 0
24555796c8dcSSimon Schubert 	  && ext_in->asym.iss < hdr->issExtMax)
24565796c8dcSSimon Schubert 	fdr_to_pst[ext_in->ifd].n_globals++;
24575796c8dcSSimon Schubert     }
24585796c8dcSSimon Schubert 
2459c50c785cSJohn Marino   /* Pass 1.5 over files:  partition out global symbol space.  */
24605796c8dcSSimon Schubert   s_idx = 0;
24615796c8dcSSimon Schubert   for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
24625796c8dcSSimon Schubert     {
24635796c8dcSSimon Schubert       fdr_to_pst[f_idx].globals_offset = s_idx;
24645796c8dcSSimon Schubert       s_idx += fdr_to_pst[f_idx].n_globals;
24655796c8dcSSimon Schubert       fdr_to_pst[f_idx].n_globals = 0;
24665796c8dcSSimon Schubert     }
24675796c8dcSSimon Schubert 
24685796c8dcSSimon Schubert   /* ECOFF in ELF:
24695796c8dcSSimon Schubert 
24705796c8dcSSimon Schubert      For ECOFF in ELF, we skip the creation of the minimal symbols.
24715796c8dcSSimon Schubert      The ECOFF symbols should be a subset of the Elf symbols, and the
24725796c8dcSSimon Schubert      section information of the elf symbols will be more accurate.
24735796c8dcSSimon Schubert      FIXME!  What about Irix 5's native linker?
24745796c8dcSSimon Schubert 
24755796c8dcSSimon Schubert      By default, Elf sections which don't exist in ECOFF
24765796c8dcSSimon Schubert      get put in ECOFF's absolute section by the gnu linker.
24775796c8dcSSimon Schubert      Since absolute sections don't get relocated, we
24785796c8dcSSimon Schubert      end up calculating an address different from that of
24795796c8dcSSimon Schubert      the symbol's minimal symbol (created earlier from the
24805796c8dcSSimon Schubert      Elf symtab).
24815796c8dcSSimon Schubert 
24825796c8dcSSimon Schubert      To fix this, either :
24835796c8dcSSimon Schubert      1) don't create the duplicate symbol
24845796c8dcSSimon Schubert      (assumes ECOFF symtab is a subset of the ELF symtab;
24855796c8dcSSimon Schubert      assumes no side-effects result from ignoring ECOFF symbol)
24865796c8dcSSimon Schubert      2) create it, only if lookup for existing symbol in ELF's minimal
24875796c8dcSSimon Schubert      symbols fails
24885796c8dcSSimon Schubert      (inefficient;
24895796c8dcSSimon Schubert      assumes no side-effects result from ignoring ECOFF symbol)
24905796c8dcSSimon Schubert      3) create it, but lookup ELF's minimal symbol and use it's section
24915796c8dcSSimon Schubert      during relocation, then modify "uniqify" phase to merge and
24925796c8dcSSimon Schubert      eliminate the duplicate symbol
24935796c8dcSSimon Schubert      (highly inefficient)
24945796c8dcSSimon Schubert 
24955796c8dcSSimon Schubert      I've implemented #1 here...
24965796c8dcSSimon Schubert      Skip the creation of the minimal symbols based on the ECOFF
24975796c8dcSSimon Schubert      symbol table.  */
24985796c8dcSSimon Schubert 
2499c50c785cSJohn Marino   /* Pass 2 over external syms: fill in external symbols.  */
25005796c8dcSSimon Schubert   ext_in = ext_block;
25015796c8dcSSimon Schubert   ext_in_end = ext_in + hdr->iextMax;
25025796c8dcSSimon Schubert   for (; ext_in < ext_in_end; ext_in++)
25035796c8dcSSimon Schubert     {
25045796c8dcSSimon Schubert       enum minimal_symbol_type ms_type = mst_text;
25055796c8dcSSimon Schubert       CORE_ADDR svalue = ext_in->asym.value;
25065796c8dcSSimon Schubert 
25075796c8dcSSimon Schubert       /* The Irix 5 native tools seem to sometimes generate bogus
25085796c8dcSSimon Schubert          external symbols.  */
25095796c8dcSSimon Schubert       if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
25105796c8dcSSimon Schubert 	{
25115796c8dcSSimon Schubert 	  complaint (&symfile_complaints,
2512c50c785cSJohn Marino 		     _("bad ifd for external symbol: %d (max %ld)"),
2513c50c785cSJohn Marino 		     ext_in->ifd, hdr->ifdMax);
25145796c8dcSSimon Schubert 	  continue;
25155796c8dcSSimon Schubert 	}
25165796c8dcSSimon Schubert       if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
25175796c8dcSSimon Schubert 	{
25185796c8dcSSimon Schubert 	  complaint (&symfile_complaints,
25195796c8dcSSimon Schubert 		     _("bad iss for external symbol: %ld (max %ld)"),
25205796c8dcSSimon Schubert 		     ext_in->asym.iss, hdr->issExtMax);
25215796c8dcSSimon Schubert 	  continue;
25225796c8dcSSimon Schubert 	}
25235796c8dcSSimon Schubert 
25245796c8dcSSimon Schubert       extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
25255796c8dcSSimon Schubert 		 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
25265796c8dcSSimon Schubert 
25275796c8dcSSimon Schubert 
25285796c8dcSSimon Schubert       if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
25295796c8dcSSimon Schubert 	continue;
25305796c8dcSSimon Schubert 
25315796c8dcSSimon Schubert 
2532c50c785cSJohn Marino       /* Pass 3 over files, over local syms: fill in static symbols.  */
25335796c8dcSSimon Schubert       name = debug_info->ssext + ext_in->asym.iss;
25345796c8dcSSimon Schubert 
2535c50c785cSJohn Marino       /* Process ECOFF Symbol Types and Storage Classes.  */
25365796c8dcSSimon Schubert       switch (ext_in->asym.st)
25375796c8dcSSimon Schubert 	{
25385796c8dcSSimon Schubert 	case stProc:
25395796c8dcSSimon Schubert 	  /* Beginnning of Procedure */
2540c50c785cSJohn Marino 	  svalue += ANOFFSET (objfile->section_offsets,
2541c50c785cSJohn Marino 			      SECT_OFF_TEXT (objfile));
25425796c8dcSSimon Schubert 	  break;
25435796c8dcSSimon Schubert 	case stStaticProc:
25445796c8dcSSimon Schubert 	  /* Load time only static procs */
25455796c8dcSSimon Schubert 	  ms_type = mst_file_text;
2546c50c785cSJohn Marino 	  svalue += ANOFFSET (objfile->section_offsets,
2547c50c785cSJohn Marino 			      SECT_OFF_TEXT (objfile));
25485796c8dcSSimon Schubert 	  break;
25495796c8dcSSimon Schubert 	case stGlobal:
25505796c8dcSSimon Schubert 	  /* External symbol */
25515796c8dcSSimon Schubert 	  if (SC_IS_COMMON (ext_in->asym.sc))
25525796c8dcSSimon Schubert 	    {
25535796c8dcSSimon Schubert 	      /* The value of a common symbol is its size, not its address.
25545796c8dcSSimon Schubert 	         Ignore it.  */
25555796c8dcSSimon Schubert 	      continue;
25565796c8dcSSimon Schubert 	    }
25575796c8dcSSimon Schubert 	  else if (SC_IS_DATA (ext_in->asym.sc))
25585796c8dcSSimon Schubert 	    {
25595796c8dcSSimon Schubert 	      ms_type = mst_data;
2560c50c785cSJohn Marino 	      svalue += ANOFFSET (objfile->section_offsets,
2561c50c785cSJohn Marino 				  SECT_OFF_DATA (objfile));
25625796c8dcSSimon Schubert 	    }
25635796c8dcSSimon Schubert 	  else if (SC_IS_BSS (ext_in->asym.sc))
25645796c8dcSSimon Schubert 	    {
25655796c8dcSSimon Schubert 	      ms_type = mst_bss;
2566c50c785cSJohn Marino 	      svalue += ANOFFSET (objfile->section_offsets,
2567c50c785cSJohn Marino 				  SECT_OFF_BSS (objfile));
25685796c8dcSSimon Schubert 	    }
25695796c8dcSSimon Schubert           else if (SC_IS_SBSS (ext_in->asym.sc))
25705796c8dcSSimon Schubert             {
25715796c8dcSSimon Schubert               ms_type = mst_bss;
25725796c8dcSSimon Schubert               svalue += ANOFFSET (objfile->section_offsets,
25735796c8dcSSimon Schubert                                   get_section_index (objfile, ".sbss"));
25745796c8dcSSimon Schubert             }
25755796c8dcSSimon Schubert 	  else
25765796c8dcSSimon Schubert 	    ms_type = mst_abs;
25775796c8dcSSimon Schubert 	  break;
25785796c8dcSSimon Schubert 	case stLabel:
25795796c8dcSSimon Schubert 	  /* Label */
25805796c8dcSSimon Schubert 
25815796c8dcSSimon Schubert           /* On certain platforms, some extra label symbols can be
25825796c8dcSSimon Schubert              generated by the linker.  One possible usage for this kind
25835796c8dcSSimon Schubert              of symbols is to represent the address of the begining of a
25845796c8dcSSimon Schubert              given section.  For instance, on Tru64 5.1, the address of
25855796c8dcSSimon Schubert              the _ftext label is the start address of the .text section.
25865796c8dcSSimon Schubert 
25875796c8dcSSimon Schubert              The storage class of these symbols is usually directly
25885796c8dcSSimon Schubert              related to the section to which the symbol refers.  For
25895796c8dcSSimon Schubert              instance, on Tru64 5.1, the storage class for the _fdata
25905796c8dcSSimon Schubert              label is scData, refering to the .data section.
25915796c8dcSSimon Schubert 
25925796c8dcSSimon Schubert              It is actually possible that the section associated to the
25935796c8dcSSimon Schubert              storage class of the label does not exist.  On True64 5.1
25945796c8dcSSimon Schubert              for instance, the libm.so shared library does not contain
25955796c8dcSSimon Schubert              any .data section, although it contains a _fpdata label
25965796c8dcSSimon Schubert              which storage class is scData...  Since these symbols are
25975796c8dcSSimon Schubert              usually useless for the debugger user anyway, we just
2598c50c785cSJohn Marino              discard these symbols.  */
25995796c8dcSSimon Schubert 
26005796c8dcSSimon Schubert 	  if (SC_IS_TEXT (ext_in->asym.sc))
26015796c8dcSSimon Schubert 	    {
26025796c8dcSSimon Schubert               if (objfile->sect_index_text == -1)
26035796c8dcSSimon Schubert                 continue;
26045796c8dcSSimon Schubert 
26055796c8dcSSimon Schubert 	      ms_type = mst_file_text;
2606c50c785cSJohn Marino 	      svalue += ANOFFSET (objfile->section_offsets,
2607c50c785cSJohn Marino 				  SECT_OFF_TEXT (objfile));
26085796c8dcSSimon Schubert 	    }
26095796c8dcSSimon Schubert 	  else if (SC_IS_DATA (ext_in->asym.sc))
26105796c8dcSSimon Schubert 	    {
26115796c8dcSSimon Schubert               if (objfile->sect_index_data == -1)
26125796c8dcSSimon Schubert                 continue;
26135796c8dcSSimon Schubert 
26145796c8dcSSimon Schubert 	      ms_type = mst_file_data;
2615c50c785cSJohn Marino 	      svalue += ANOFFSET (objfile->section_offsets,
2616c50c785cSJohn Marino 				  SECT_OFF_DATA (objfile));
26175796c8dcSSimon Schubert 	    }
26185796c8dcSSimon Schubert 	  else if (SC_IS_BSS (ext_in->asym.sc))
26195796c8dcSSimon Schubert 	    {
26205796c8dcSSimon Schubert               if (objfile->sect_index_bss == -1)
26215796c8dcSSimon Schubert                 continue;
26225796c8dcSSimon Schubert 
26235796c8dcSSimon Schubert 	      ms_type = mst_file_bss;
2624c50c785cSJohn Marino 	      svalue += ANOFFSET (objfile->section_offsets,
2625c50c785cSJohn Marino 				  SECT_OFF_BSS (objfile));
26265796c8dcSSimon Schubert 	    }
26275796c8dcSSimon Schubert           else if (SC_IS_SBSS (ext_in->asym.sc))
26285796c8dcSSimon Schubert             {
26295796c8dcSSimon Schubert               const int sbss_sect_index = get_section_index (objfile, ".sbss");
26305796c8dcSSimon Schubert 
26315796c8dcSSimon Schubert               if (sbss_sect_index == -1)
26325796c8dcSSimon Schubert                 continue;
26335796c8dcSSimon Schubert 
26345796c8dcSSimon Schubert               ms_type = mst_file_bss;
26355796c8dcSSimon Schubert               svalue += ANOFFSET (objfile->section_offsets, sbss_sect_index);
26365796c8dcSSimon Schubert             }
26375796c8dcSSimon Schubert 	  else
26385796c8dcSSimon Schubert 	    ms_type = mst_abs;
26395796c8dcSSimon Schubert 	  break;
26405796c8dcSSimon Schubert 	case stLocal:
26415796c8dcSSimon Schubert 	case stNil:
26425796c8dcSSimon Schubert 	  /* The alpha has the section start addresses in stLocal symbols
26435796c8dcSSimon Schubert 	     whose name starts with a `.'.  Skip those but complain for all
26445796c8dcSSimon Schubert 	     other stLocal symbols.
26455796c8dcSSimon Schubert 	     Irix6 puts the section start addresses in stNil symbols, skip
26465796c8dcSSimon Schubert 	     those too.  */
26475796c8dcSSimon Schubert 	  if (name[0] == '.')
26485796c8dcSSimon Schubert 	    continue;
26495796c8dcSSimon Schubert 	  /* Fall through.  */
26505796c8dcSSimon Schubert 	default:
26515796c8dcSSimon Schubert 	  ms_type = mst_unknown;
26525796c8dcSSimon Schubert 	  unknown_ext_complaint (name);
26535796c8dcSSimon Schubert 	}
26545796c8dcSSimon Schubert       if (!ECOFF_IN_ELF (cur_bfd))
26555796c8dcSSimon Schubert         record_minimal_symbol (name, svalue, ms_type, ext_in->asym.sc,
26565796c8dcSSimon Schubert                                objfile);
26575796c8dcSSimon Schubert     }
26585796c8dcSSimon Schubert 
2659c50c785cSJohn Marino   /* Pass 3 over files, over local syms: fill in static symbols.  */
26605796c8dcSSimon Schubert   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
26615796c8dcSSimon Schubert     {
26625796c8dcSSimon Schubert       struct partial_symtab *save_pst;
26635796c8dcSSimon Schubert       EXTR *ext_ptr;
26645796c8dcSSimon Schubert       CORE_ADDR textlow;
26655796c8dcSSimon Schubert 
26665796c8dcSSimon Schubert       cur_fdr = fh = debug_info->fdr + f_idx;
26675796c8dcSSimon Schubert 
26685796c8dcSSimon Schubert       if (fh->csym == 0)
26695796c8dcSSimon Schubert 	{
26705796c8dcSSimon Schubert 	  fdr_to_pst[f_idx].pst = NULL;
26715796c8dcSSimon Schubert 	  continue;
26725796c8dcSSimon Schubert 	}
26735796c8dcSSimon Schubert 
26745796c8dcSSimon Schubert       /* Determine the start address for this object file from the
26755796c8dcSSimon Schubert          file header and relocate it, except for Irix 5.2 zero fh->adr.  */
26765796c8dcSSimon Schubert       if (fh->cpd)
26775796c8dcSSimon Schubert 	{
26785796c8dcSSimon Schubert 	  textlow = fh->adr;
26795796c8dcSSimon Schubert 	  if (relocatable || textlow != 0)
2680c50c785cSJohn Marino 	    textlow += ANOFFSET (objfile->section_offsets,
2681c50c785cSJohn Marino 				 SECT_OFF_TEXT (objfile));
26825796c8dcSSimon Schubert 	}
26835796c8dcSSimon Schubert       else
26845796c8dcSSimon Schubert 	textlow = 0;
26855796c8dcSSimon Schubert       pst = start_psymtab_common (objfile, objfile->section_offsets,
26865796c8dcSSimon Schubert 				  fdr_name (fh),
26875796c8dcSSimon Schubert 				  textlow,
26885796c8dcSSimon Schubert 				  objfile->global_psymbols.next,
26895796c8dcSSimon Schubert 				  objfile->static_psymbols.next);
2690cf7f2e2dSJohn Marino       pst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2691cf7f2e2dSJohn Marino 						sizeof (struct symloc));
26925796c8dcSSimon Schubert       memset (pst->read_symtab_private, 0, sizeof (struct symloc));
26935796c8dcSSimon Schubert 
26945796c8dcSSimon Schubert       save_pst = pst;
26955796c8dcSSimon Schubert       FDR_IDX (pst) = f_idx;
26965796c8dcSSimon Schubert       CUR_BFD (pst) = cur_bfd;
26975796c8dcSSimon Schubert       DEBUG_SWAP (pst) = debug_swap;
26985796c8dcSSimon Schubert       DEBUG_INFO (pst) = debug_info;
26995796c8dcSSimon Schubert       PENDING_LIST (pst) = pending_list;
27005796c8dcSSimon Schubert 
27015796c8dcSSimon Schubert       /* The way to turn this into a symtab is to call...  */
2702*ef5ccd6cSJohn Marino       pst->read_symtab = mdebug_read_symtab;
27035796c8dcSSimon Schubert 
27045796c8dcSSimon Schubert       /* Set up language for the pst.
27055796c8dcSSimon Schubert          The language from the FDR is used if it is unambigious (e.g. cfront
27065796c8dcSSimon Schubert          with native cc and g++ will set the language to C).
27075796c8dcSSimon Schubert          Otherwise we have to deduce the language from the filename.
27085796c8dcSSimon Schubert          Native ecoff has every header file in a separate FDR, so
27095796c8dcSSimon Schubert          deduce_language_from_filename will return language_unknown for
27105796c8dcSSimon Schubert          a header file, which is not what we want.
27115796c8dcSSimon Schubert          But the FDRs for the header files are after the FDR for the source
27125796c8dcSSimon Schubert          file, so we can assign the language of the source file to the
27135796c8dcSSimon Schubert          following header files.  Then we save the language in the private
27145796c8dcSSimon Schubert          pst data so that we can reuse it when building symtabs.  */
27155796c8dcSSimon Schubert       prev_language = psymtab_language;
27165796c8dcSSimon Schubert 
27175796c8dcSSimon Schubert       switch (fh->lang)
27185796c8dcSSimon Schubert 	{
27195796c8dcSSimon Schubert 	case langCplusplusV2:
27205796c8dcSSimon Schubert 	  psymtab_language = language_cplus;
27215796c8dcSSimon Schubert 	  break;
27225796c8dcSSimon Schubert 	default:
27235796c8dcSSimon Schubert 	  psymtab_language = deduce_language_from_filename (fdr_name (fh));
27245796c8dcSSimon Schubert 	  break;
27255796c8dcSSimon Schubert 	}
27265796c8dcSSimon Schubert       if (psymtab_language == language_unknown)
27275796c8dcSSimon Schubert 	psymtab_language = prev_language;
27285796c8dcSSimon Schubert       PST_PRIVATE (pst)->pst_language = psymtab_language;
27295796c8dcSSimon Schubert 
27305796c8dcSSimon Schubert       pst->texthigh = pst->textlow;
27315796c8dcSSimon Schubert 
27325796c8dcSSimon Schubert       /* For stabs-in-ecoff files, the second symbol must be @stab.
27335796c8dcSSimon Schubert          This symbol is emitted by mips-tfile to signal that the
27345796c8dcSSimon Schubert          current object file uses encapsulated stabs instead of mips
27355796c8dcSSimon Schubert          ecoff for local symbols.  (It is the second symbol because
27365796c8dcSSimon Schubert          the first symbol is the stFile used to signal the start of a
27375796c8dcSSimon Schubert          file).  */
27385796c8dcSSimon Schubert       processing_gcc_compilation = 0;
27395796c8dcSSimon Schubert       if (fh->csym >= 2)
27405796c8dcSSimon Schubert 	{
27415796c8dcSSimon Schubert 	  (*swap_sym_in) (cur_bfd,
27425796c8dcSSimon Schubert 			  ((char *) debug_info->external_sym
27435796c8dcSSimon Schubert 			   + (fh->isymBase + 1) * external_sym_size),
27445796c8dcSSimon Schubert 			  &sh);
27455796c8dcSSimon Schubert 	  if (strcmp (debug_info->ss + fh->issBase + sh.iss,
27465796c8dcSSimon Schubert 		      stabs_symbol) == 0)
27475796c8dcSSimon Schubert 	    processing_gcc_compilation = 2;
27485796c8dcSSimon Schubert 	}
27495796c8dcSSimon Schubert 
27505796c8dcSSimon Schubert       if (processing_gcc_compilation != 0)
27515796c8dcSSimon Schubert 	{
27525796c8dcSSimon Schubert 	  for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
27535796c8dcSSimon Schubert 	    {
27545796c8dcSSimon Schubert 	      int type_code;
2755*ef5ccd6cSJohn Marino 	      const char *namestring;
27565796c8dcSSimon Schubert 
27575796c8dcSSimon Schubert 	      (*swap_sym_in) (cur_bfd,
27585796c8dcSSimon Schubert 			      (((char *) debug_info->external_sym)
27595796c8dcSSimon Schubert 			    + (fh->isymBase + cur_sdx) * external_sym_size),
27605796c8dcSSimon Schubert 			      &sh);
27615796c8dcSSimon Schubert 	      type_code = ECOFF_UNMARK_STAB (sh.index);
27625796c8dcSSimon Schubert 	      if (!ECOFF_IS_STAB (&sh))
27635796c8dcSSimon Schubert 		{
27645796c8dcSSimon Schubert 		  if (sh.st == stProc || sh.st == stStaticProc)
27655796c8dcSSimon Schubert 		    {
27665796c8dcSSimon Schubert 		      CORE_ADDR procaddr;
27675796c8dcSSimon Schubert 		      long isym;
27685796c8dcSSimon Schubert 
2769c50c785cSJohn Marino 		      sh.value += ANOFFSET (objfile->section_offsets,
2770c50c785cSJohn Marino 					    SECT_OFF_TEXT (objfile));
27715796c8dcSSimon Schubert 		      if (sh.st == stStaticProc)
27725796c8dcSSimon Schubert 			{
27735796c8dcSSimon Schubert 			  namestring = debug_info->ss + fh->issBase + sh.iss;
27745796c8dcSSimon Schubert                           record_minimal_symbol (namestring, sh.value,
27755796c8dcSSimon Schubert                                                  mst_file_text, sh.sc,
27765796c8dcSSimon Schubert                                                  objfile);
27775796c8dcSSimon Schubert 			}
27785796c8dcSSimon Schubert 		      procaddr = sh.value;
27795796c8dcSSimon Schubert 
27805796c8dcSSimon Schubert 		      isym = AUX_GET_ISYM (fh->fBigendian,
27815796c8dcSSimon Schubert 					   (debug_info->external_aux
27825796c8dcSSimon Schubert 					    + fh->iauxBase
27835796c8dcSSimon Schubert 					    + sh.index));
27845796c8dcSSimon Schubert 		      (*swap_sym_in) (cur_bfd,
27855796c8dcSSimon Schubert 				      ((char *) debug_info->external_sym
27865796c8dcSSimon Schubert 				       + ((fh->isymBase + isym - 1)
27875796c8dcSSimon Schubert 					  * external_sym_size)),
27885796c8dcSSimon Schubert 				      &sh);
27895796c8dcSSimon Schubert 		      if (sh.st == stEnd)
27905796c8dcSSimon Schubert 			{
27915796c8dcSSimon Schubert 			  CORE_ADDR high = procaddr + sh.value;
27925796c8dcSSimon Schubert 
27935796c8dcSSimon Schubert 			  /* Kludge for Irix 5.2 zero fh->adr.  */
27945796c8dcSSimon Schubert 			  if (!relocatable
27955796c8dcSSimon Schubert 			  && (pst->textlow == 0 || procaddr < pst->textlow))
27965796c8dcSSimon Schubert 			    pst->textlow = procaddr;
27975796c8dcSSimon Schubert 			  if (high > pst->texthigh)
27985796c8dcSSimon Schubert 			    pst->texthigh = high;
27995796c8dcSSimon Schubert 			}
28005796c8dcSSimon Schubert 		    }
28015796c8dcSSimon Schubert 		  else if (sh.st == stStatic)
28025796c8dcSSimon Schubert 		    {
28035796c8dcSSimon Schubert 		      switch (sh.sc)
28045796c8dcSSimon Schubert 			{
28055796c8dcSSimon Schubert 			case scUndefined:
28065796c8dcSSimon Schubert 			case scSUndefined:
28075796c8dcSSimon Schubert 			case scNil:
28085796c8dcSSimon Schubert 			case scAbs:
28095796c8dcSSimon Schubert 			  break;
28105796c8dcSSimon Schubert 
28115796c8dcSSimon Schubert 			case scData:
28125796c8dcSSimon Schubert 			case scSData:
28135796c8dcSSimon Schubert 			case scRData:
28145796c8dcSSimon Schubert 			case scPData:
28155796c8dcSSimon Schubert 			case scXData:
28165796c8dcSSimon Schubert 			  namestring = debug_info->ss + fh->issBase + sh.iss;
2817c50c785cSJohn Marino 			  sh.value += ANOFFSET (objfile->section_offsets,
2818c50c785cSJohn Marino 						SECT_OFF_DATA (objfile));
28195796c8dcSSimon Schubert                           record_minimal_symbol (namestring, sh.value,
28205796c8dcSSimon Schubert                                                  mst_file_data, sh.sc,
28215796c8dcSSimon Schubert                                                  objfile);
28225796c8dcSSimon Schubert 			  break;
28235796c8dcSSimon Schubert 
28245796c8dcSSimon Schubert 			default:
28255796c8dcSSimon Schubert 			  /* FIXME!  Shouldn't this use cases for bss,
28265796c8dcSSimon Schubert 			     then have the default be abs?  */
28275796c8dcSSimon Schubert 			  namestring = debug_info->ss + fh->issBase + sh.iss;
2828c50c785cSJohn Marino 			  sh.value += ANOFFSET (objfile->section_offsets,
2829c50c785cSJohn Marino 						SECT_OFF_BSS (objfile));
28305796c8dcSSimon Schubert                           record_minimal_symbol (namestring, sh.value,
28315796c8dcSSimon Schubert                                                  mst_file_bss, sh.sc,
28325796c8dcSSimon Schubert                                                  objfile);
28335796c8dcSSimon Schubert 			  break;
28345796c8dcSSimon Schubert 			}
28355796c8dcSSimon Schubert 		    }
28365796c8dcSSimon Schubert 		  continue;
28375796c8dcSSimon Schubert 		}
2838c50c785cSJohn Marino 	      /* Handle stabs continuation.  */
28395796c8dcSSimon Schubert 	      {
28405796c8dcSSimon Schubert 		char *stabstring = debug_info->ss + fh->issBase + sh.iss;
28415796c8dcSSimon Schubert 		int len = strlen (stabstring);
2842cf7f2e2dSJohn Marino 
28435796c8dcSSimon Schubert 		while (stabstring[len - 1] == '\\')
28445796c8dcSSimon Schubert 		  {
28455796c8dcSSimon Schubert 		    SYMR sh2;
28465796c8dcSSimon Schubert 		    char *stabstring1 = stabstring;
28475796c8dcSSimon Schubert 		    char *stabstring2;
28485796c8dcSSimon Schubert 		    int len2;
28495796c8dcSSimon Schubert 
2850c50c785cSJohn Marino 		    /* Ignore continuation char from 1st string.  */
28515796c8dcSSimon Schubert 		    len--;
28525796c8dcSSimon Schubert 
2853c50c785cSJohn Marino 		    /* Read next stabstring.  */
28545796c8dcSSimon Schubert 		    cur_sdx++;
28555796c8dcSSimon Schubert 		    (*swap_sym_in) (cur_bfd,
28565796c8dcSSimon Schubert 				    (((char *) debug_info->external_sym)
28575796c8dcSSimon Schubert 				     + (fh->isymBase + cur_sdx)
28585796c8dcSSimon Schubert 				     * external_sym_size),
28595796c8dcSSimon Schubert 				    &sh2);
28605796c8dcSSimon Schubert 		    stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
28615796c8dcSSimon Schubert 		    len2 = strlen (stabstring2);
28625796c8dcSSimon Schubert 
2863c50c785cSJohn Marino 		    /* Concatinate stabstring2 with stabstring1.  */
28645796c8dcSSimon Schubert 		    if (stabstring
28655796c8dcSSimon Schubert 		     && stabstring != debug_info->ss + fh->issBase + sh.iss)
28665796c8dcSSimon Schubert 		      stabstring = xrealloc (stabstring, len + len2 + 1);
28675796c8dcSSimon Schubert 		    else
28685796c8dcSSimon Schubert 		      {
28695796c8dcSSimon Schubert 			stabstring = xmalloc (len + len2 + 1);
28705796c8dcSSimon Schubert 			strcpy (stabstring, stabstring1);
28715796c8dcSSimon Schubert 		      }
28725796c8dcSSimon Schubert 		    strcpy (stabstring + len, stabstring2);
28735796c8dcSSimon Schubert 		    len += len2;
28745796c8dcSSimon Schubert 		  }
28755796c8dcSSimon Schubert 
28765796c8dcSSimon Schubert 		switch (type_code)
28775796c8dcSSimon Schubert 		  {
28785796c8dcSSimon Schubert 		    char *p;
2879cf7f2e2dSJohn Marino 
2880c50c785cSJohn Marino 		    /* Standard, external, non-debugger, symbols.  */
28815796c8dcSSimon Schubert 
28825796c8dcSSimon Schubert 		  case N_TEXT | N_EXT:
28835796c8dcSSimon Schubert 		  case N_NBTEXT | N_EXT:
2884c50c785cSJohn Marino 		    sh.value += ANOFFSET (objfile->section_offsets,
2885c50c785cSJohn Marino 					  SECT_OFF_TEXT (objfile));
28865796c8dcSSimon Schubert 		    goto record_it;
28875796c8dcSSimon Schubert 
28885796c8dcSSimon Schubert 		  case N_DATA | N_EXT:
28895796c8dcSSimon Schubert 		  case N_NBDATA | N_EXT:
2890c50c785cSJohn Marino 		    sh.value += ANOFFSET (objfile->section_offsets,
2891c50c785cSJohn Marino 					  SECT_OFF_DATA (objfile));
28925796c8dcSSimon Schubert 		    goto record_it;
28935796c8dcSSimon Schubert 
28945796c8dcSSimon Schubert 		  case N_BSS:
28955796c8dcSSimon Schubert 		  case N_BSS | N_EXT:
28965796c8dcSSimon Schubert 		  case N_NBBSS | N_EXT:
28975796c8dcSSimon Schubert 		  case N_SETV | N_EXT:		/* FIXME, is this in BSS?  */
2898c50c785cSJohn Marino 		    sh.value += ANOFFSET (objfile->section_offsets,
2899c50c785cSJohn Marino 					  SECT_OFF_BSS (objfile));
29005796c8dcSSimon Schubert 		    goto record_it;
29015796c8dcSSimon Schubert 
29025796c8dcSSimon Schubert 		  case N_ABS | N_EXT:
29035796c8dcSSimon Schubert 		  record_it:
29045796c8dcSSimon Schubert 		    continue;
29055796c8dcSSimon Schubert 
2906c50c785cSJohn Marino 		  /* Standard, local, non-debugger, symbols.  */
29075796c8dcSSimon Schubert 
29085796c8dcSSimon Schubert 		  case N_NBTEXT:
29095796c8dcSSimon Schubert 
2910c50c785cSJohn Marino 		    /* We need to be able to deal with both N_FN or
2911c50c785cSJohn Marino 		       N_TEXT, because we have no way of knowing
2912c50c785cSJohn Marino 		       whether the sys-supplied ld or GNU ld was used
2913c50c785cSJohn Marino 		       to make the executable.  Sequents throw in
2914c50c785cSJohn Marino 		       another wrinkle -- they renumbered N_FN.  */
29155796c8dcSSimon Schubert 
29165796c8dcSSimon Schubert 		  case N_FN:
29175796c8dcSSimon Schubert 		  case N_FN_SEQ:
29185796c8dcSSimon Schubert 		  case N_TEXT:
29195796c8dcSSimon Schubert 		    continue;
29205796c8dcSSimon Schubert 
29215796c8dcSSimon Schubert 		  case N_DATA:
2922c50c785cSJohn Marino 		    sh.value += ANOFFSET (objfile->section_offsets,
2923c50c785cSJohn Marino 					  SECT_OFF_DATA (objfile));
29245796c8dcSSimon Schubert 		    goto record_it;
29255796c8dcSSimon Schubert 
29265796c8dcSSimon Schubert 		  case N_UNDF | N_EXT:
2927c50c785cSJohn Marino 		    continue;		/* Just undefined, not COMMON.  */
29285796c8dcSSimon Schubert 
29295796c8dcSSimon Schubert 		  case N_UNDF:
29305796c8dcSSimon Schubert 		    continue;
29315796c8dcSSimon Schubert 
29325796c8dcSSimon Schubert 		    /* Lots of symbol types we can just ignore.  */
29335796c8dcSSimon Schubert 
29345796c8dcSSimon Schubert 		  case N_ABS:
29355796c8dcSSimon Schubert 		  case N_NBDATA:
29365796c8dcSSimon Schubert 		  case N_NBBSS:
29375796c8dcSSimon Schubert 		    continue;
29385796c8dcSSimon Schubert 
29395796c8dcSSimon Schubert 		    /* Keep going . . .  */
29405796c8dcSSimon Schubert 
29415796c8dcSSimon Schubert 		    /*
29425796c8dcSSimon Schubert 		     * Special symbol types for GNU
29435796c8dcSSimon Schubert 		     */
29445796c8dcSSimon Schubert 		  case N_INDR:
29455796c8dcSSimon Schubert 		  case N_INDR | N_EXT:
29465796c8dcSSimon Schubert 		  case N_SETA:
29475796c8dcSSimon Schubert 		  case N_SETA | N_EXT:
29485796c8dcSSimon Schubert 		  case N_SETT:
29495796c8dcSSimon Schubert 		  case N_SETT | N_EXT:
29505796c8dcSSimon Schubert 		  case N_SETD:
29515796c8dcSSimon Schubert 		  case N_SETD | N_EXT:
29525796c8dcSSimon Schubert 		  case N_SETB:
29535796c8dcSSimon Schubert 		  case N_SETB | N_EXT:
29545796c8dcSSimon Schubert 		  case N_SETV:
29555796c8dcSSimon Schubert 		    continue;
29565796c8dcSSimon Schubert 
29575796c8dcSSimon Schubert 		    /*
29585796c8dcSSimon Schubert 		     * Debugger symbols
29595796c8dcSSimon Schubert 		     */
29605796c8dcSSimon Schubert 
29615796c8dcSSimon Schubert 		  case N_SO:
29625796c8dcSSimon Schubert 		    {
29635796c8dcSSimon Schubert 		      CORE_ADDR valu;
29645796c8dcSSimon Schubert 		      static int prev_so_symnum = -10;
29655796c8dcSSimon Schubert 		      static int first_so_symnum;
2966c50c785cSJohn Marino 		      const char *p;
29675796c8dcSSimon Schubert 		      int prev_textlow_not_set;
29685796c8dcSSimon Schubert 
2969c50c785cSJohn Marino 		      valu = sh.value + ANOFFSET (objfile->section_offsets,
2970c50c785cSJohn Marino 						  SECT_OFF_TEXT (objfile));
29715796c8dcSSimon Schubert 
29725796c8dcSSimon Schubert 		      prev_textlow_not_set = textlow_not_set;
29735796c8dcSSimon Schubert 
2974c50c785cSJohn Marino 		      /* A zero value is probably an indication for the
2975c50c785cSJohn Marino 			 SunPRO 3.0 compiler.  end_psymtab explicitly tests
2976c50c785cSJohn Marino 			 for zero, so don't relocate it.  */
29775796c8dcSSimon Schubert 
29785796c8dcSSimon Schubert 		      if (sh.value == 0
29795796c8dcSSimon Schubert 			  && gdbarch_sofun_address_maybe_missing (gdbarch))
29805796c8dcSSimon Schubert 			{
29815796c8dcSSimon Schubert 			  textlow_not_set = 1;
29825796c8dcSSimon Schubert 			  valu = 0;
29835796c8dcSSimon Schubert 			}
29845796c8dcSSimon Schubert 		      else
29855796c8dcSSimon Schubert 			textlow_not_set = 0;
29865796c8dcSSimon Schubert 
29875796c8dcSSimon Schubert 		      past_first_source_file = 1;
29885796c8dcSSimon Schubert 
29895796c8dcSSimon Schubert 		      if (prev_so_symnum != symnum - 1)
2990c50c785cSJohn Marino 			{		/* Here if prev stab wasn't N_SO.  */
29915796c8dcSSimon Schubert 			  first_so_symnum = symnum;
29925796c8dcSSimon Schubert 
29935796c8dcSSimon Schubert 			  if (pst)
29945796c8dcSSimon Schubert 			    {
29955796c8dcSSimon Schubert 			      pst = (struct partial_symtab *) 0;
29965796c8dcSSimon Schubert 			      includes_used = 0;
29975796c8dcSSimon Schubert 			      dependencies_used = 0;
29985796c8dcSSimon Schubert 			    }
29995796c8dcSSimon Schubert 			}
30005796c8dcSSimon Schubert 
30015796c8dcSSimon Schubert 		      prev_so_symnum = symnum;
30025796c8dcSSimon Schubert 
3003c50c785cSJohn Marino 		      /* End the current partial symtab and start a
3004c50c785cSJohn Marino 			 new one.  */
30055796c8dcSSimon Schubert 
30065796c8dcSSimon Schubert 		      /* SET_NAMESTRING ();*/
30075796c8dcSSimon Schubert 		      namestring = stabstring;
30085796c8dcSSimon Schubert 
3009c50c785cSJohn Marino 		      /* Null name means end of .o file.  Don't start a new
3010c50c785cSJohn Marino 			 one.  */
30115796c8dcSSimon Schubert 		      if (*namestring == '\000')
30125796c8dcSSimon Schubert 			continue;
30135796c8dcSSimon Schubert 
3014c50c785cSJohn Marino 		      /* Some compilers (including gcc) emit a pair of
3015c50c785cSJohn Marino 			 initial N_SOs.  The first one is a directory name;
3016c50c785cSJohn Marino 			 the second the file name.  If pst exists, is
3017c50c785cSJohn Marino 			 empty, and has a filename ending in '/', we assume
3018c50c785cSJohn Marino 			 the previous N_SO was a directory name.  */
3019c50c785cSJohn Marino 		      p = lbasename (namestring);
3020c50c785cSJohn Marino 		      if (p != namestring && *p == '\000')
3021c50c785cSJohn Marino 			continue;		/* Simply ignore directory
3022c50c785cSJohn Marino 						   name SOs.  */
30235796c8dcSSimon Schubert 
3024c50c785cSJohn Marino 		      /* Some other compilers (C++ ones in particular) emit
3025c50c785cSJohn Marino 			 useless SOs for non-existant .c files.  We ignore
3026c50c785cSJohn Marino 			 all subsequent SOs that immediately follow the
3027c50c785cSJohn Marino 			 first.  */
30285796c8dcSSimon Schubert 
30295796c8dcSSimon Schubert 		      if (!pst)
30305796c8dcSSimon Schubert 			pst = save_pst;
30315796c8dcSSimon Schubert 		      continue;
30325796c8dcSSimon Schubert 		    }
30335796c8dcSSimon Schubert 
30345796c8dcSSimon Schubert 		  case N_BINCL:
30355796c8dcSSimon Schubert 		    continue;
30365796c8dcSSimon Schubert 
30375796c8dcSSimon Schubert 		  case N_SOL:
30385796c8dcSSimon Schubert 		    {
30395796c8dcSSimon Schubert 		      enum language tmp_language;
3040cf7f2e2dSJohn Marino 
3041c50c785cSJohn Marino 		      /* Mark down an include file in the current psymtab.  */
30425796c8dcSSimon Schubert 
30435796c8dcSSimon Schubert 		      /* SET_NAMESTRING (); */
30445796c8dcSSimon Schubert 		      namestring = stabstring;
30455796c8dcSSimon Schubert 
3046c50c785cSJohn Marino 		      tmp_language
3047c50c785cSJohn Marino 			= deduce_language_from_filename (namestring);
30485796c8dcSSimon Schubert 
3049c50c785cSJohn Marino 		      /* Only change the psymtab's language if we've
3050c50c785cSJohn Marino 			 learned something useful (eg. tmp_language is not
3051c50c785cSJohn Marino 			 language_unknown).  In addition, to match what
3052c50c785cSJohn Marino 			 start_subfile does, never change from C++ to
3053c50c785cSJohn Marino 			 C.  */
30545796c8dcSSimon Schubert 		      if (tmp_language != language_unknown
30555796c8dcSSimon Schubert 			  && (tmp_language != language_c
30565796c8dcSSimon Schubert 			      || psymtab_language != language_cplus))
30575796c8dcSSimon Schubert 			psymtab_language = tmp_language;
30585796c8dcSSimon Schubert 
3059c50c785cSJohn Marino 		      /* In C++, one may expect the same filename to come
3060c50c785cSJohn Marino 			 round many times, when code is coming alternately
3061c50c785cSJohn Marino 			 from the main file and from inline functions in
3062c50c785cSJohn Marino 			 other files.  So I check to see if this is a file
3063c50c785cSJohn Marino 			 we've seen before -- either the main source file,
3064c50c785cSJohn Marino 			 or a previously included file.
30655796c8dcSSimon Schubert 
3066c50c785cSJohn Marino 			 This seems to be a lot of time to be spending on
3067c50c785cSJohn Marino 			 N_SOL, but things like "break c-exp.y:435" need to
3068c50c785cSJohn Marino 			 work (I suppose the psymtab_include_list could be
3069c50c785cSJohn Marino 			 hashed or put in a binary tree, if profiling shows
3070c50c785cSJohn Marino 			 this is a major hog).  */
3071c50c785cSJohn Marino 		      if (pst && filename_cmp (namestring, pst->filename) == 0)
30725796c8dcSSimon Schubert 			continue;
3073cf7f2e2dSJohn Marino 
30745796c8dcSSimon Schubert 		      {
30755796c8dcSSimon Schubert 			int i;
3076cf7f2e2dSJohn Marino 
30775796c8dcSSimon Schubert 			for (i = 0; i < includes_used; i++)
3078c50c785cSJohn Marino 			  if (filename_cmp (namestring,
30795796c8dcSSimon Schubert 					    psymtab_include_list[i]) == 0)
30805796c8dcSSimon Schubert 			    {
30815796c8dcSSimon Schubert 			      i = -1;
30825796c8dcSSimon Schubert 			      break;
30835796c8dcSSimon Schubert 			    }
30845796c8dcSSimon Schubert 			if (i == -1)
30855796c8dcSSimon Schubert 			  continue;
30865796c8dcSSimon Schubert 		      }
30875796c8dcSSimon Schubert 
30885796c8dcSSimon Schubert 		      psymtab_include_list[includes_used++] = namestring;
30895796c8dcSSimon Schubert 		      if (includes_used >= includes_allocated)
30905796c8dcSSimon Schubert 			{
3091*ef5ccd6cSJohn Marino 			  const char **orig = psymtab_include_list;
30925796c8dcSSimon Schubert 
3093*ef5ccd6cSJohn Marino 			  psymtab_include_list = (const char **)
30945796c8dcSSimon Schubert 			    alloca ((includes_allocated *= 2) *
3095*ef5ccd6cSJohn Marino 				    sizeof (const char *));
30965796c8dcSSimon Schubert 			  memcpy (psymtab_include_list, orig,
3097*ef5ccd6cSJohn Marino 				  includes_used * sizeof (const char *));
30985796c8dcSSimon Schubert 			}
30995796c8dcSSimon Schubert 		      continue;
31005796c8dcSSimon Schubert 		    }
31015796c8dcSSimon Schubert 		  case N_LSYM:	    /* Typedef or automatic variable.  */
31025796c8dcSSimon Schubert 		  case N_STSYM:	    /* Data seg var -- static  */
31035796c8dcSSimon Schubert 		  case N_LCSYM:	    /* BSS      "  */
31045796c8dcSSimon Schubert 		  case N_ROSYM:	    /* Read-only data seg var -- static.  */
31055796c8dcSSimon Schubert 		  case N_NBSTS:	    /* Gould nobase.  */
31065796c8dcSSimon Schubert 		  case N_NBLCS:	    /* symbols.  */
31075796c8dcSSimon Schubert 		  case N_FUN:
31085796c8dcSSimon Schubert 		  case N_GSYM:	    /* Global (extern) variable; can be
31095796c8dcSSimon Schubert 				       data or bss (sigh FIXME).  */
31105796c8dcSSimon Schubert 
31115796c8dcSSimon Schubert 		    /* Following may probably be ignored; I'll leave them here
31125796c8dcSSimon Schubert 		       for now (until I do Pascal and Modula 2 extensions).  */
31135796c8dcSSimon Schubert 
31145796c8dcSSimon Schubert 		  case N_PC:	    /* I may or may not need this; I
31155796c8dcSSimon Schubert 				       suspect not.  */
3116c50c785cSJohn Marino 		  case N_M2C:	    /* I suspect that I can ignore this
3117c50c785cSJohn Marino 				       here.  */
31185796c8dcSSimon Schubert 		  case N_SCOPE:	    /* Same.  */
31195796c8dcSSimon Schubert 
31205796c8dcSSimon Schubert 		    /*    SET_NAMESTRING (); */
31215796c8dcSSimon Schubert 		    namestring = stabstring;
31225796c8dcSSimon Schubert 		    p = (char *) strchr (namestring, ':');
31235796c8dcSSimon Schubert 		    if (!p)
31245796c8dcSSimon Schubert 		      continue;	    /* Not a debugging symbol.  */
31255796c8dcSSimon Schubert 
31265796c8dcSSimon Schubert 
31275796c8dcSSimon Schubert 
31285796c8dcSSimon Schubert 		    /* Main processing section for debugging symbols which
3129c50c785cSJohn Marino 		       the initial read through the symbol tables needs to
3130c50c785cSJohn Marino 		       worry about.  If we reach this point, the symbol
3131c50c785cSJohn Marino 		       which we are considering is definitely one we are
3132c50c785cSJohn Marino 		       interested in.  p must also contain the (valid)
3133c50c785cSJohn Marino 		       index into the namestring which indicates the
3134c50c785cSJohn Marino 		       debugging type symbol.  */
31355796c8dcSSimon Schubert 
31365796c8dcSSimon Schubert 		    switch (p[1])
31375796c8dcSSimon Schubert 		      {
31385796c8dcSSimon Schubert 		      case 'S':
3139c50c785cSJohn Marino 			sh.value += ANOFFSET (objfile->section_offsets,
3140c50c785cSJohn Marino 					      SECT_OFF_DATA (objfile));
31415796c8dcSSimon Schubert 
31425796c8dcSSimon Schubert 			if (gdbarch_static_transform_name_p (gdbarch))
31435796c8dcSSimon Schubert 			  namestring = gdbarch_static_transform_name
31445796c8dcSSimon Schubert 					 (gdbarch, namestring);
31455796c8dcSSimon Schubert 
3146cf7f2e2dSJohn Marino 			add_psymbol_to_list (namestring, p - namestring, 1,
31475796c8dcSSimon Schubert 					     VAR_DOMAIN, LOC_STATIC,
31485796c8dcSSimon Schubert 					     &objfile->static_psymbols,
31495796c8dcSSimon Schubert 					     0, sh.value,
31505796c8dcSSimon Schubert 					     psymtab_language, objfile);
31515796c8dcSSimon Schubert 			continue;
31525796c8dcSSimon Schubert 		      case 'G':
3153c50c785cSJohn Marino 			sh.value += ANOFFSET (objfile->section_offsets,
3154c50c785cSJohn Marino 					      SECT_OFF_DATA (objfile));
3155c50c785cSJohn Marino 			/* The addresses in these entries are reported
3156c50c785cSJohn Marino 			   to be wrong.  See the code that reads 'G's
3157c50c785cSJohn Marino 			   for symtabs.  */
3158cf7f2e2dSJohn Marino 			add_psymbol_to_list (namestring, p - namestring, 1,
31595796c8dcSSimon Schubert 					     VAR_DOMAIN, LOC_STATIC,
31605796c8dcSSimon Schubert 					     &objfile->global_psymbols,
31615796c8dcSSimon Schubert 					     0, sh.value,
31625796c8dcSSimon Schubert 					     psymtab_language, objfile);
31635796c8dcSSimon Schubert 			continue;
31645796c8dcSSimon Schubert 
31655796c8dcSSimon Schubert 		      case 'T':
31665796c8dcSSimon Schubert 			/* When a 'T' entry is defining an anonymous enum, it
31675796c8dcSSimon Schubert 			   may have a name which is the empty string, or a
31685796c8dcSSimon Schubert 			   single space.  Since they're not really defining a
31695796c8dcSSimon Schubert 			   symbol, those shouldn't go in the partial symbol
31705796c8dcSSimon Schubert 			   table.  We do pick up the elements of such enums at
31715796c8dcSSimon Schubert 			   'check_enum:', below.  */
31725796c8dcSSimon Schubert 			if (p >= namestring + 2
31735796c8dcSSimon Schubert 			    || (p == namestring + 1
31745796c8dcSSimon Schubert 				&& namestring[0] != ' '))
31755796c8dcSSimon Schubert 			  {
3176cf7f2e2dSJohn Marino 			    add_psymbol_to_list (namestring, p - namestring, 1,
31775796c8dcSSimon Schubert 						 STRUCT_DOMAIN, LOC_TYPEDEF,
31785796c8dcSSimon Schubert 						 &objfile->static_psymbols,
31795796c8dcSSimon Schubert 						 sh.value, 0,
31805796c8dcSSimon Schubert 						 psymtab_language, objfile);
31815796c8dcSSimon Schubert 			    if (p[2] == 't')
31825796c8dcSSimon Schubert 			      {
31835796c8dcSSimon Schubert 				/* Also a typedef with the same name.  */
3184c50c785cSJohn Marino 				add_psymbol_to_list (namestring,
3185c50c785cSJohn Marino 						     p - namestring, 1,
31865796c8dcSSimon Schubert 						     VAR_DOMAIN, LOC_TYPEDEF,
31875796c8dcSSimon Schubert 						     &objfile->static_psymbols,
31885796c8dcSSimon Schubert 						     sh.value, 0,
3189c50c785cSJohn Marino 						     psymtab_language,
3190c50c785cSJohn Marino 						     objfile);
31915796c8dcSSimon Schubert 				p += 1;
31925796c8dcSSimon Schubert 			      }
31935796c8dcSSimon Schubert 			  }
31945796c8dcSSimon Schubert 			goto check_enum;
31955796c8dcSSimon Schubert 		      case 't':
3196c50c785cSJohn Marino 			if (p != namestring)	/* a name is there, not
3197c50c785cSJohn Marino 						   just :T...  */
31985796c8dcSSimon Schubert 			  {
3199cf7f2e2dSJohn Marino 			    add_psymbol_to_list (namestring, p - namestring, 1,
32005796c8dcSSimon Schubert 						 VAR_DOMAIN, LOC_TYPEDEF,
32015796c8dcSSimon Schubert 						 &objfile->static_psymbols,
32025796c8dcSSimon Schubert 						 sh.value, 0,
32035796c8dcSSimon Schubert 						 psymtab_language, objfile);
32045796c8dcSSimon Schubert 			  }
32055796c8dcSSimon Schubert 		      check_enum:
3206c50c785cSJohn Marino 			/* If this is an enumerated type, we need to add
3207c50c785cSJohn Marino 			   all the enum constants to the partial symbol
3208c50c785cSJohn Marino 			   table.  This does not cover enums without names,
3209c50c785cSJohn Marino 			   e.g. "enum {a, b} c;" in C, but fortunately
3210c50c785cSJohn Marino 			   those are rare.  There is no way for GDB to find
3211c50c785cSJohn Marino 			   those from the enum type without spending too
3212c50c785cSJohn Marino 			   much time on it.  Thus to solve this problem,
3213c50c785cSJohn Marino 			   the compiler needs to put out the enum in a
3214c50c785cSJohn Marino 			   nameless type.  GCC2 does this.  */
32155796c8dcSSimon Schubert 
32165796c8dcSSimon Schubert 			/* We are looking for something of the form
32175796c8dcSSimon Schubert 			   <name> ":" ("t" | "T") [<number> "="] "e"
32185796c8dcSSimon Schubert 			   {<constant> ":" <value> ","} ";".  */
32195796c8dcSSimon Schubert 
32205796c8dcSSimon Schubert 			/* Skip over the colon and the 't' or 'T'.  */
32215796c8dcSSimon Schubert 			p += 2;
3222c50c785cSJohn Marino 			/* This type may be given a number.  Also, numbers
3223c50c785cSJohn Marino 			   can come in pairs like (0,26).  Skip over it.  */
32245796c8dcSSimon Schubert 			while ((*p >= '0' && *p <= '9')
32255796c8dcSSimon Schubert 			       || *p == '(' || *p == ',' || *p == ')'
32265796c8dcSSimon Schubert 			       || *p == '=')
32275796c8dcSSimon Schubert 			  p++;
32285796c8dcSSimon Schubert 
32295796c8dcSSimon Schubert 			if (*p++ == 'e')
32305796c8dcSSimon Schubert 			  {
3231c50c785cSJohn Marino 			    /* The aix4 compiler emits extra crud before
3232c50c785cSJohn Marino 			       the members.  */
32335796c8dcSSimon Schubert 			    if (*p == '-')
32345796c8dcSSimon Schubert 			      {
32355796c8dcSSimon Schubert 				/* Skip over the type (?).  */
32365796c8dcSSimon Schubert 				while (*p != ':')
32375796c8dcSSimon Schubert 				  p++;
32385796c8dcSSimon Schubert 
32395796c8dcSSimon Schubert 				/* Skip over the colon.  */
32405796c8dcSSimon Schubert 				p++;
32415796c8dcSSimon Schubert 			      }
32425796c8dcSSimon Schubert 
32435796c8dcSSimon Schubert 			    /* We have found an enumerated type.  */
32445796c8dcSSimon Schubert 			    /* According to comments in read_enum_type
32455796c8dcSSimon Schubert 			       a comma could end it instead of a semicolon.
32465796c8dcSSimon Schubert 			       I don't know where that happens.
32475796c8dcSSimon Schubert 			       Accept either.  */
32485796c8dcSSimon Schubert 			    while (*p && *p != ';' && *p != ',')
32495796c8dcSSimon Schubert 			      {
32505796c8dcSSimon Schubert 				char *q;
32515796c8dcSSimon Schubert 
3252c50c785cSJohn Marino 				/* Check for and handle cretinous dbx
3253c50c785cSJohn Marino 				   symbol name continuation!  */
32545796c8dcSSimon Schubert 				if (*p == '\\' || (*p == '?' && p[1] == '\0'))
32555796c8dcSSimon Schubert 				  p = next_symbol_text (objfile);
32565796c8dcSSimon Schubert 
32575796c8dcSSimon Schubert 				/* Point to the character after the name
32585796c8dcSSimon Schubert 				   of the enum constant.  */
32595796c8dcSSimon Schubert 				for (q = p; *q && *q != ':'; q++)
32605796c8dcSSimon Schubert 				  ;
32615796c8dcSSimon Schubert 				/* Note that the value doesn't matter for
3262c50c785cSJohn Marino 				   enum constants in psymtabs, just in
3263c50c785cSJohn Marino 				   symtabs.  */
3264cf7f2e2dSJohn Marino 				add_psymbol_to_list (p, q - p, 1,
32655796c8dcSSimon Schubert 						     VAR_DOMAIN, LOC_CONST,
3266c50c785cSJohn Marino 						     &objfile->static_psymbols,
3267c50c785cSJohn Marino 						     0, 0, psymtab_language,
3268c50c785cSJohn Marino 						     objfile);
32695796c8dcSSimon Schubert 				/* Point past the name.  */
32705796c8dcSSimon Schubert 				p = q;
32715796c8dcSSimon Schubert 				/* Skip over the value.  */
32725796c8dcSSimon Schubert 				while (*p && *p != ',')
32735796c8dcSSimon Schubert 				  p++;
32745796c8dcSSimon Schubert 				/* Advance past the comma.  */
32755796c8dcSSimon Schubert 				if (*p)
32765796c8dcSSimon Schubert 				  p++;
32775796c8dcSSimon Schubert 			      }
32785796c8dcSSimon Schubert 			  }
32795796c8dcSSimon Schubert 			continue;
32805796c8dcSSimon Schubert 		      case 'c':
32815796c8dcSSimon Schubert 			/* Constant, e.g. from "const" in Pascal.  */
3282cf7f2e2dSJohn Marino 			add_psymbol_to_list (namestring, p - namestring, 1,
32835796c8dcSSimon Schubert 					     VAR_DOMAIN, LOC_CONST,
3284c50c785cSJohn Marino 					     &objfile->static_psymbols,
3285c50c785cSJohn Marino 					     sh.value, 0, psymtab_language,
3286c50c785cSJohn Marino 					     objfile);
32875796c8dcSSimon Schubert 			continue;
32885796c8dcSSimon Schubert 
32895796c8dcSSimon Schubert 		      case 'f':
32905796c8dcSSimon Schubert 			if (! pst)
32915796c8dcSSimon Schubert 			  {
32925796c8dcSSimon Schubert 			    int name_len = p - namestring;
32935796c8dcSSimon Schubert 			    char *name = xmalloc (name_len + 1);
3294cf7f2e2dSJohn Marino 
32955796c8dcSSimon Schubert 			    memcpy (name, namestring, name_len);
32965796c8dcSSimon Schubert 			    name[name_len] = '\0';
32975796c8dcSSimon Schubert 			    function_outside_compilation_unit_complaint (name);
32985796c8dcSSimon Schubert 			    xfree (name);
32995796c8dcSSimon Schubert 			  }
3300c50c785cSJohn Marino 			sh.value += ANOFFSET (objfile->section_offsets,
3301c50c785cSJohn Marino 					      SECT_OFF_TEXT (objfile));
3302cf7f2e2dSJohn Marino 			add_psymbol_to_list (namestring, p - namestring, 1,
33035796c8dcSSimon Schubert 					     VAR_DOMAIN, LOC_BLOCK,
33045796c8dcSSimon Schubert 					     &objfile->static_psymbols,
33055796c8dcSSimon Schubert 					     0, sh.value,
33065796c8dcSSimon Schubert 					     psymtab_language, objfile);
33075796c8dcSSimon Schubert 			continue;
33085796c8dcSSimon Schubert 
33095796c8dcSSimon Schubert 			/* Global functions were ignored here, but now they
3310c50c785cSJohn Marino 			   are put into the global psymtab like one would
3311c50c785cSJohn Marino 			   expect.  They're also in the minimal symbol
3312c50c785cSJohn Marino 			   table.  */
33135796c8dcSSimon Schubert 		      case 'F':
33145796c8dcSSimon Schubert 			if (! pst)
33155796c8dcSSimon Schubert 			  {
33165796c8dcSSimon Schubert 			    int name_len = p - namestring;
33175796c8dcSSimon Schubert 			    char *name = xmalloc (name_len + 1);
3318cf7f2e2dSJohn Marino 
33195796c8dcSSimon Schubert 			    memcpy (name, namestring, name_len);
33205796c8dcSSimon Schubert 			    name[name_len] = '\0';
33215796c8dcSSimon Schubert 			    function_outside_compilation_unit_complaint (name);
33225796c8dcSSimon Schubert 			    xfree (name);
33235796c8dcSSimon Schubert 			  }
3324c50c785cSJohn Marino 			sh.value += ANOFFSET (objfile->section_offsets,
3325c50c785cSJohn Marino 					      SECT_OFF_TEXT (objfile));
3326cf7f2e2dSJohn Marino 			add_psymbol_to_list (namestring, p - namestring, 1,
33275796c8dcSSimon Schubert 					     VAR_DOMAIN, LOC_BLOCK,
33285796c8dcSSimon Schubert 					     &objfile->global_psymbols,
33295796c8dcSSimon Schubert 					     0, sh.value,
33305796c8dcSSimon Schubert 					     psymtab_language, objfile);
33315796c8dcSSimon Schubert 			continue;
33325796c8dcSSimon Schubert 
3333c50c785cSJohn Marino 			/* Two things show up here (hopefully); static
3334c50c785cSJohn Marino 			   symbols of local scope (static used inside
3335c50c785cSJohn Marino 			   braces) or extensions of structure symbols.  We
3336c50c785cSJohn Marino 			   can ignore both.  */
33375796c8dcSSimon Schubert 		      case 'V':
33385796c8dcSSimon Schubert 		      case '(':
33395796c8dcSSimon Schubert 		      case '0':
33405796c8dcSSimon Schubert 		      case '1':
33415796c8dcSSimon Schubert 		      case '2':
33425796c8dcSSimon Schubert 		      case '3':
33435796c8dcSSimon Schubert 		      case '4':
33445796c8dcSSimon Schubert 		      case '5':
33455796c8dcSSimon Schubert 		      case '6':
33465796c8dcSSimon Schubert 		      case '7':
33475796c8dcSSimon Schubert 		      case '8':
33485796c8dcSSimon Schubert 		      case '9':
33495796c8dcSSimon Schubert 		      case '-':
3350c50c785cSJohn Marino 		      case '#':		/* For symbol identification (used
3351c50c785cSJohn Marino 					   in live ranges).  */
33525796c8dcSSimon Schubert 			continue;
33535796c8dcSSimon Schubert 
33545796c8dcSSimon Schubert 		      case ':':
3355c50c785cSJohn Marino 			/* It is a C++ nested symbol.  We don't need to
3356c50c785cSJohn Marino 			   record it (I don't think); if we try to look up
3357c50c785cSJohn Marino 			   foo::bar::baz, then symbols for the symtab
3358c50c785cSJohn Marino 			   containing foo should get read in, I think.  */
33595796c8dcSSimon Schubert 			/* Someone says sun cc puts out symbols like
33605796c8dcSSimon Schubert 			   /foo/baz/maclib::/usr/local/bin/maclib,
33615796c8dcSSimon Schubert 			   which would get here with a symbol type of ':'.  */
33625796c8dcSSimon Schubert 			continue;
33635796c8dcSSimon Schubert 
33645796c8dcSSimon Schubert 		      default:
3365c50c785cSJohn Marino 			/* Unexpected symbol descriptor.  The second and
3366c50c785cSJohn Marino 			   subsequent stabs of a continued stab can show up
3367c50c785cSJohn Marino 			   here.  The question is whether they ever can
3368c50c785cSJohn Marino 			   mimic a normal stab--it would be nice if not,
3369c50c785cSJohn Marino 			   since we certainly don't want to spend the time
3370c50c785cSJohn Marino 			   searching to the end of every string looking for
33715796c8dcSSimon Schubert 			   a backslash.  */
33725796c8dcSSimon Schubert 
33735796c8dcSSimon Schubert 			complaint (&symfile_complaints,
33745796c8dcSSimon Schubert 				   _("unknown symbol descriptor `%c'"), p[1]);
33755796c8dcSSimon Schubert 
33765796c8dcSSimon Schubert 			/* Ignore it; perhaps it is an extension that we don't
33775796c8dcSSimon Schubert 			   know about.  */
33785796c8dcSSimon Schubert 			continue;
33795796c8dcSSimon Schubert 		      }
33805796c8dcSSimon Schubert 
33815796c8dcSSimon Schubert 		  case N_EXCL:
33825796c8dcSSimon Schubert 		    continue;
33835796c8dcSSimon Schubert 
33845796c8dcSSimon Schubert 		  case N_ENDM:
33855796c8dcSSimon Schubert 		    /* Solaris 2 end of module, finish current partial
33865796c8dcSSimon Schubert 		       symbol table.  END_PSYMTAB will set
33875796c8dcSSimon Schubert 		       pst->texthigh to the proper value, which is
33885796c8dcSSimon Schubert 		       necessary if a module compiled without
33895796c8dcSSimon Schubert 		       debugging info follows this module.  */
33905796c8dcSSimon Schubert 		    if (pst
33915796c8dcSSimon Schubert 			&& gdbarch_sofun_address_maybe_missing (gdbarch))
33925796c8dcSSimon Schubert 		      {
33935796c8dcSSimon Schubert 			pst = (struct partial_symtab *) 0;
33945796c8dcSSimon Schubert 			includes_used = 0;
33955796c8dcSSimon Schubert 			dependencies_used = 0;
33965796c8dcSSimon Schubert 		      }
33975796c8dcSSimon Schubert 		    continue;
33985796c8dcSSimon Schubert 
33995796c8dcSSimon Schubert 		  case N_RBRAC:
34005796c8dcSSimon Schubert 		    if (sh.value > save_pst->texthigh)
34015796c8dcSSimon Schubert 		      save_pst->texthigh = sh.value;
34025796c8dcSSimon Schubert 		    continue;
34035796c8dcSSimon Schubert 		  case N_EINCL:
34045796c8dcSSimon Schubert 		  case N_DSLINE:
34055796c8dcSSimon Schubert 		  case N_BSLINE:
3406c50c785cSJohn Marino 		  case N_SSYM:		/* Claim: Structure or union
3407c50c785cSJohn Marino 					   element.  Hopefully, I can
3408c50c785cSJohn Marino 					   ignore this.  */
3409c50c785cSJohn Marino 		  case N_ENTRY:		/* Alternate entry point; can
3410c50c785cSJohn Marino 					   ignore.  */
34115796c8dcSSimon Schubert 		  case N_MAIN:		/* Can definitely ignore this.   */
3412c50c785cSJohn Marino 		  case N_CATCH:		/* These are GNU C++ extensions.  */
34135796c8dcSSimon Schubert 		  case N_EHDECL:	/* that can safely be ignored here.  */
34145796c8dcSSimon Schubert 		  case N_LENG:
34155796c8dcSSimon Schubert 		  case N_BCOMM:
34165796c8dcSSimon Schubert 		  case N_ECOMM:
34175796c8dcSSimon Schubert 		  case N_ECOML:
34185796c8dcSSimon Schubert 		  case N_FNAME:
34195796c8dcSSimon Schubert 		  case N_SLINE:
34205796c8dcSSimon Schubert 		  case N_RSYM:
34215796c8dcSSimon Schubert 		  case N_PSYM:
34225796c8dcSSimon Schubert 		  case N_LBRAC:
34235796c8dcSSimon Schubert 		  case N_NSYMS:		/* Ultrix 4.0: symbol count */
34245796c8dcSSimon Schubert 		  case N_DEFD:			/* GNU Modula-2 */
3425c50c785cSJohn Marino 		  case N_ALIAS:		/* SunPro F77: alias name, ignore
3426c50c785cSJohn Marino 					   for now.  */
34275796c8dcSSimon Schubert 
3428c50c785cSJohn Marino 		  case N_OBJ:		/* Useless types from Solaris.  */
34295796c8dcSSimon Schubert 		  case N_OPT:
3430c50c785cSJohn Marino 		    /* These symbols aren't interesting; don't worry about
3431c50c785cSJohn Marino 		       them.  */
34325796c8dcSSimon Schubert 
34335796c8dcSSimon Schubert 		    continue;
34345796c8dcSSimon Schubert 
34355796c8dcSSimon Schubert 		  default:
3436c50c785cSJohn Marino 		    /* If we haven't found it yet, ignore it.  It's
3437c50c785cSJohn Marino 		       probably some new type we don't know about yet.  */
3438c50c785cSJohn Marino 		    complaint (&symfile_complaints,
3439c50c785cSJohn Marino 			       _("unknown symbol type %s"),
34405796c8dcSSimon Schubert 			       hex_string (type_code)); /* CUR_SYMBOL_TYPE */
34415796c8dcSSimon Schubert 		    continue;
34425796c8dcSSimon Schubert 		  }
34435796c8dcSSimon Schubert 		if (stabstring
34445796c8dcSSimon Schubert 		    && stabstring != debug_info->ss + fh->issBase + sh.iss)
34455796c8dcSSimon Schubert 		  xfree (stabstring);
34465796c8dcSSimon Schubert 	      }
34475796c8dcSSimon Schubert 	      /* end - Handle continuation */
34485796c8dcSSimon Schubert 	    }
34495796c8dcSSimon Schubert 	}
34505796c8dcSSimon Schubert       else
34515796c8dcSSimon Schubert 	{
34525796c8dcSSimon Schubert 	  for (cur_sdx = 0; cur_sdx < fh->csym;)
34535796c8dcSSimon Schubert 	    {
34545796c8dcSSimon Schubert 	      char *name;
34555796c8dcSSimon Schubert 	      enum address_class class;
34565796c8dcSSimon Schubert 
34575796c8dcSSimon Schubert 	      (*swap_sym_in) (cur_bfd,
34585796c8dcSSimon Schubert 			      ((char *) debug_info->external_sym
34595796c8dcSSimon Schubert 			       + ((fh->isymBase + cur_sdx)
34605796c8dcSSimon Schubert 				  * external_sym_size)),
34615796c8dcSSimon Schubert 			      &sh);
34625796c8dcSSimon Schubert 
34635796c8dcSSimon Schubert 	      if (ECOFF_IS_STAB (&sh))
34645796c8dcSSimon Schubert 		{
34655796c8dcSSimon Schubert 		  cur_sdx++;
34665796c8dcSSimon Schubert 		  continue;
34675796c8dcSSimon Schubert 		}
34685796c8dcSSimon Schubert 
34695796c8dcSSimon Schubert 	      /* Non absolute static symbols go into the minimal table.  */
34705796c8dcSSimon Schubert 	      if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
34715796c8dcSSimon Schubert 		  || (sh.index == indexNil
34725796c8dcSSimon Schubert 		      && (sh.st != stStatic || sh.sc == scAbs)))
34735796c8dcSSimon Schubert 		{
34745796c8dcSSimon Schubert 		  /* FIXME, premature?  */
34755796c8dcSSimon Schubert 		  cur_sdx++;
34765796c8dcSSimon Schubert 		  continue;
34775796c8dcSSimon Schubert 		}
34785796c8dcSSimon Schubert 
34795796c8dcSSimon Schubert 	      name = debug_info->ss + fh->issBase + sh.iss;
34805796c8dcSSimon Schubert 
34815796c8dcSSimon Schubert 	      switch (sh.sc)
34825796c8dcSSimon Schubert 		{
34835796c8dcSSimon Schubert 		case scText:
34845796c8dcSSimon Schubert 		case scRConst:
34855796c8dcSSimon Schubert 		  /* The value of a stEnd symbol is the displacement from the
34865796c8dcSSimon Schubert 		     corresponding start symbol value, do not relocate it.  */
34875796c8dcSSimon Schubert 		  if (sh.st != stEnd)
3488c50c785cSJohn Marino 		    sh.value += ANOFFSET (objfile->section_offsets,
3489c50c785cSJohn Marino 					  SECT_OFF_TEXT (objfile));
34905796c8dcSSimon Schubert 		  break;
34915796c8dcSSimon Schubert 		case scData:
34925796c8dcSSimon Schubert 		case scSData:
34935796c8dcSSimon Schubert 		case scRData:
34945796c8dcSSimon Schubert 		case scPData:
34955796c8dcSSimon Schubert 		case scXData:
3496c50c785cSJohn Marino 		  sh.value += ANOFFSET (objfile->section_offsets,
3497c50c785cSJohn Marino 					SECT_OFF_DATA (objfile));
34985796c8dcSSimon Schubert 		  break;
34995796c8dcSSimon Schubert 		case scBss:
35005796c8dcSSimon Schubert 		case scSBss:
3501c50c785cSJohn Marino 		  sh.value += ANOFFSET (objfile->section_offsets,
3502c50c785cSJohn Marino 					SECT_OFF_BSS (objfile));
35035796c8dcSSimon Schubert 		  break;
35045796c8dcSSimon Schubert 		}
35055796c8dcSSimon Schubert 
35065796c8dcSSimon Schubert 	      switch (sh.st)
35075796c8dcSSimon Schubert 		{
35085796c8dcSSimon Schubert 		  CORE_ADDR high;
35095796c8dcSSimon Schubert 		  CORE_ADDR procaddr;
35105796c8dcSSimon Schubert 		  int new_sdx;
35115796c8dcSSimon Schubert 
35125796c8dcSSimon Schubert 		case stStaticProc:
35135796c8dcSSimon Schubert 		  prim_record_minimal_symbol_and_info (name, sh.value,
35145796c8dcSSimon Schubert 						       mst_file_text,
3515c50c785cSJohn Marino 						       SECT_OFF_TEXT (objfile),
3516c50c785cSJohn Marino 						       NULL, objfile);
35175796c8dcSSimon Schubert 
35185796c8dcSSimon Schubert 		  /* FALLTHROUGH */
35195796c8dcSSimon Schubert 
35205796c8dcSSimon Schubert 		case stProc:
35215796c8dcSSimon Schubert 		  /* Ignore all parameter symbol records.  */
35225796c8dcSSimon Schubert 		  if (sh.index >= hdr->iauxMax)
35235796c8dcSSimon Schubert 		    {
35245796c8dcSSimon Schubert 		      /* Should not happen, but does when cross-compiling
35255796c8dcSSimon Schubert 		         with the MIPS compiler.  FIXME -- pull later.  */
35265796c8dcSSimon Schubert 		      index_complaint (name);
3527c50c785cSJohn Marino 		      new_sdx = cur_sdx + 1;	/* Don't skip at all.  */
35285796c8dcSSimon Schubert 		    }
35295796c8dcSSimon Schubert 		  else
35305796c8dcSSimon Schubert 		    new_sdx = AUX_GET_ISYM (fh->fBigendian,
35315796c8dcSSimon Schubert 					    (debug_info->external_aux
35325796c8dcSSimon Schubert 					     + fh->iauxBase
35335796c8dcSSimon Schubert 					     + sh.index));
35345796c8dcSSimon Schubert 
35355796c8dcSSimon Schubert 		  if (new_sdx <= cur_sdx)
35365796c8dcSSimon Schubert 		    {
35375796c8dcSSimon Schubert 		      /* This should not happen either... FIXME.  */
35385796c8dcSSimon Schubert 		      complaint (&symfile_complaints,
35395796c8dcSSimon Schubert 				 _("bad proc end in aux found from symbol %s"),
35405796c8dcSSimon Schubert 				 name);
3541c50c785cSJohn Marino 		      new_sdx = cur_sdx + 1;	/* Don't skip backward.  */
35425796c8dcSSimon Schubert 		    }
35435796c8dcSSimon Schubert 
35445796c8dcSSimon Schubert                   /* For stProc symbol records, we need to check the
35455796c8dcSSimon Schubert                      storage class as well, as only (stProc, scText)
35465796c8dcSSimon Schubert                      entries represent "real" procedures - See the
35475796c8dcSSimon Schubert                      Compaq document titled "Object File / Symbol Table
35485796c8dcSSimon Schubert                      Format Specification" for more information.  If the
35495796c8dcSSimon Schubert                      storage class is not scText, we discard the whole
35505796c8dcSSimon Schubert                      block of symbol records for this stProc.  */
35515796c8dcSSimon Schubert                   if (sh.st == stProc && sh.sc != scText)
35525796c8dcSSimon Schubert                     goto skip;
35535796c8dcSSimon Schubert 
35545796c8dcSSimon Schubert 		  /* Usually there is a local and a global stProc symbol
35555796c8dcSSimon Schubert 		     for a function.  This means that the function name
35565796c8dcSSimon Schubert 		     has already been entered into the mimimal symbol table
35575796c8dcSSimon Schubert 		     while processing the global symbols in pass 2 above.
35585796c8dcSSimon Schubert 		     One notable exception is the PROGRAM name from
35595796c8dcSSimon Schubert 		     f77 compiled executables, it is only put out as
35605796c8dcSSimon Schubert 		     local stProc symbol, and a global MAIN__ stProc symbol
35615796c8dcSSimon Schubert 		     points to it.  It doesn't matter though, as gdb is
35625796c8dcSSimon Schubert 		     still able to find the PROGRAM name via the partial
35635796c8dcSSimon Schubert 		     symbol table, and the MAIN__ symbol via the minimal
35645796c8dcSSimon Schubert 		     symbol table.  */
35655796c8dcSSimon Schubert 		  if (sh.st == stProc)
3566cf7f2e2dSJohn Marino 		    add_psymbol_to_list (name, strlen (name), 1,
35675796c8dcSSimon Schubert 					 VAR_DOMAIN, LOC_BLOCK,
35685796c8dcSSimon Schubert 					 &objfile->global_psymbols,
35695796c8dcSSimon Schubert 				    0, sh.value, psymtab_language, objfile);
35705796c8dcSSimon Schubert 		  else
3571cf7f2e2dSJohn Marino 		    add_psymbol_to_list (name, strlen (name), 1,
35725796c8dcSSimon Schubert 					 VAR_DOMAIN, LOC_BLOCK,
35735796c8dcSSimon Schubert 					 &objfile->static_psymbols,
35745796c8dcSSimon Schubert 				    0, sh.value, psymtab_language, objfile);
35755796c8dcSSimon Schubert 
35765796c8dcSSimon Schubert 		  procaddr = sh.value;
35775796c8dcSSimon Schubert 
35785796c8dcSSimon Schubert 		  cur_sdx = new_sdx;
35795796c8dcSSimon Schubert 		  (*swap_sym_in) (cur_bfd,
35805796c8dcSSimon Schubert 				  ((char *) debug_info->external_sym
35815796c8dcSSimon Schubert 				   + ((fh->isymBase + cur_sdx - 1)
35825796c8dcSSimon Schubert 				      * external_sym_size)),
35835796c8dcSSimon Schubert 				  &sh);
35845796c8dcSSimon Schubert 		  if (sh.st != stEnd)
35855796c8dcSSimon Schubert 		    continue;
35865796c8dcSSimon Schubert 
35875796c8dcSSimon Schubert 		  /* Kludge for Irix 5.2 zero fh->adr.  */
35885796c8dcSSimon Schubert 		  if (!relocatable
35895796c8dcSSimon Schubert 		      && (pst->textlow == 0 || procaddr < pst->textlow))
35905796c8dcSSimon Schubert 		    pst->textlow = procaddr;
35915796c8dcSSimon Schubert 
35925796c8dcSSimon Schubert 		  high = procaddr + sh.value;
35935796c8dcSSimon Schubert 		  if (high > pst->texthigh)
35945796c8dcSSimon Schubert 		    pst->texthigh = high;
35955796c8dcSSimon Schubert 		  continue;
35965796c8dcSSimon Schubert 
35975796c8dcSSimon Schubert 		case stStatic:	/* Variable */
35985796c8dcSSimon Schubert 		  if (SC_IS_DATA (sh.sc))
35995796c8dcSSimon Schubert 		    prim_record_minimal_symbol_and_info (name, sh.value,
36005796c8dcSSimon Schubert 							 mst_file_data,
36015796c8dcSSimon Schubert 							 SECT_OFF_DATA (objfile),
36025796c8dcSSimon Schubert 							 NULL,
36035796c8dcSSimon Schubert 							 objfile);
36045796c8dcSSimon Schubert 		  else
36055796c8dcSSimon Schubert 		    prim_record_minimal_symbol_and_info (name, sh.value,
36065796c8dcSSimon Schubert 							 mst_file_bss,
36075796c8dcSSimon Schubert 							 SECT_OFF_BSS (objfile),
36085796c8dcSSimon Schubert 							 NULL,
36095796c8dcSSimon Schubert 							 objfile);
36105796c8dcSSimon Schubert 		  class = LOC_STATIC;
36115796c8dcSSimon Schubert 		  break;
36125796c8dcSSimon Schubert 
36135796c8dcSSimon Schubert 		case stIndirect:	/* Irix5 forward declaration */
3614c50c785cSJohn Marino 		  /* Skip forward declarations from Irix5 cc.  */
36155796c8dcSSimon Schubert 		  goto skip;
36165796c8dcSSimon Schubert 
36175796c8dcSSimon Schubert 		case stTypedef:	/* Typedef */
36185796c8dcSSimon Schubert 		  /* Skip typedefs for forward declarations and opaque
36195796c8dcSSimon Schubert 		     structs from alpha and mips cc.  */
36205796c8dcSSimon Schubert 		  if (sh.iss == 0 || has_opaque_xref (fh, &sh))
36215796c8dcSSimon Schubert 		    goto skip;
36225796c8dcSSimon Schubert 		  class = LOC_TYPEDEF;
36235796c8dcSSimon Schubert 		  break;
36245796c8dcSSimon Schubert 
36255796c8dcSSimon Schubert 		case stConstant:	/* Constant decl */
36265796c8dcSSimon Schubert 		  class = LOC_CONST;
36275796c8dcSSimon Schubert 		  break;
36285796c8dcSSimon Schubert 
36295796c8dcSSimon Schubert 		case stUnion:
36305796c8dcSSimon Schubert 		case stStruct:
36315796c8dcSSimon Schubert 		case stEnum:
36325796c8dcSSimon Schubert 		case stBlock:	/* { }, str, un, enum */
36335796c8dcSSimon Schubert 		  /* Do not create a partial symbol for cc unnamed aggregates
36345796c8dcSSimon Schubert 		     and gcc empty aggregates.  */
36355796c8dcSSimon Schubert 		  if ((sh.sc == scInfo
36365796c8dcSSimon Schubert 		       || SC_IS_COMMON (sh.sc))
36375796c8dcSSimon Schubert 		      && sh.iss != 0
36385796c8dcSSimon Schubert 		      && sh.index != cur_sdx + 2)
36395796c8dcSSimon Schubert 		    {
3640cf7f2e2dSJohn Marino 		      add_psymbol_to_list (name, strlen (name), 1,
36415796c8dcSSimon Schubert 					   STRUCT_DOMAIN, LOC_TYPEDEF,
36425796c8dcSSimon Schubert 					   &objfile->static_psymbols,
36435796c8dcSSimon Schubert 					   0, (CORE_ADDR) 0,
36445796c8dcSSimon Schubert 					   psymtab_language, objfile);
36455796c8dcSSimon Schubert 		    }
36465796c8dcSSimon Schubert 		  handle_psymbol_enumerators (objfile, fh, sh.st, sh.value);
36475796c8dcSSimon Schubert 
3648c50c785cSJohn Marino 		  /* Skip over the block.  */
36495796c8dcSSimon Schubert 		  new_sdx = sh.index;
36505796c8dcSSimon Schubert 		  if (new_sdx <= cur_sdx)
36515796c8dcSSimon Schubert 		    {
36525796c8dcSSimon Schubert 		      /* This happens with the Ultrix kernel.  */
36535796c8dcSSimon Schubert 		      complaint (&symfile_complaints,
36545796c8dcSSimon Schubert 				 _("bad aux index at block symbol %s"), name);
3655c50c785cSJohn Marino 		      new_sdx = cur_sdx + 1;	/* Don't skip backward.  */
36565796c8dcSSimon Schubert 		    }
36575796c8dcSSimon Schubert 		  cur_sdx = new_sdx;
36585796c8dcSSimon Schubert 		  continue;
36595796c8dcSSimon Schubert 
36605796c8dcSSimon Schubert 		case stFile:	/* File headers */
36615796c8dcSSimon Schubert 		case stLabel:	/* Labels */
36625796c8dcSSimon Schubert 		case stEnd:	/* Ends of files */
36635796c8dcSSimon Schubert 		  goto skip;
36645796c8dcSSimon Schubert 
36655796c8dcSSimon Schubert 		case stLocal:	/* Local variables */
36665796c8dcSSimon Schubert 		  /* Normally these are skipped because we skip over
36675796c8dcSSimon Schubert 		     all blocks we see.  However, these can occur
36685796c8dcSSimon Schubert 		     as visible symbols in a .h file that contains code.  */
36695796c8dcSSimon Schubert 		  goto skip;
36705796c8dcSSimon Schubert 
36715796c8dcSSimon Schubert 		default:
36725796c8dcSSimon Schubert 		  /* Both complaints are valid:  one gives symbol name,
36735796c8dcSSimon Schubert 		     the other the offending symbol type.  */
36745796c8dcSSimon Schubert 		  complaint (&symfile_complaints, _("unknown local symbol %s"),
36755796c8dcSSimon Schubert 			     name);
36765796c8dcSSimon Schubert 		  complaint (&symfile_complaints, _("with type %d"), sh.st);
36775796c8dcSSimon Schubert 		  cur_sdx++;
36785796c8dcSSimon Schubert 		  continue;
36795796c8dcSSimon Schubert 		}
3680c50c785cSJohn Marino 	      /* Use this gdb symbol.  */
3681cf7f2e2dSJohn Marino 	      add_psymbol_to_list (name, strlen (name), 1,
36825796c8dcSSimon Schubert 				   VAR_DOMAIN, class,
36835796c8dcSSimon Schubert 				   &objfile->static_psymbols,
36845796c8dcSSimon Schubert 				   0, sh.value, psymtab_language, objfile);
36855796c8dcSSimon Schubert 	    skip:
3686c50c785cSJohn Marino 	      cur_sdx++;	/* Go to next file symbol.  */
36875796c8dcSSimon Schubert 	    }
36885796c8dcSSimon Schubert 
36895796c8dcSSimon Schubert 	  /* Now do enter the external symbols.  */
36905796c8dcSSimon Schubert 	  ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
36915796c8dcSSimon Schubert 	  cur_sdx = fdr_to_pst[f_idx].n_globals;
36925796c8dcSSimon Schubert 	  PST_PRIVATE (save_pst)->extern_count = cur_sdx;
36935796c8dcSSimon Schubert 	  PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
36945796c8dcSSimon Schubert 	  for (; --cur_sdx >= 0; ext_ptr++)
36955796c8dcSSimon Schubert 	    {
36965796c8dcSSimon Schubert 	      enum address_class class;
36975796c8dcSSimon Schubert 	      SYMR *psh;
36985796c8dcSSimon Schubert 	      char *name;
36995796c8dcSSimon Schubert 	      CORE_ADDR svalue;
37005796c8dcSSimon Schubert 
37015796c8dcSSimon Schubert 	      if (ext_ptr->ifd != f_idx)
3702c50c785cSJohn Marino 		internal_error (__FILE__, __LINE__,
3703c50c785cSJohn Marino 				_("failed internal consistency check"));
37045796c8dcSSimon Schubert 	      psh = &ext_ptr->asym;
37055796c8dcSSimon Schubert 
37065796c8dcSSimon Schubert 	      /* Do not add undefined symbols to the partial symbol table.  */
37075796c8dcSSimon Schubert 	      if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
37085796c8dcSSimon Schubert 		continue;
37095796c8dcSSimon Schubert 
37105796c8dcSSimon Schubert 	      svalue = psh->value;
37115796c8dcSSimon Schubert 	      switch (psh->sc)
37125796c8dcSSimon Schubert 		{
37135796c8dcSSimon Schubert 		case scText:
37145796c8dcSSimon Schubert 		case scRConst:
3715c50c785cSJohn Marino 		  svalue += ANOFFSET (objfile->section_offsets,
3716c50c785cSJohn Marino 				      SECT_OFF_TEXT (objfile));
37175796c8dcSSimon Schubert 		  break;
37185796c8dcSSimon Schubert 		case scData:
37195796c8dcSSimon Schubert 		case scSData:
37205796c8dcSSimon Schubert 		case scRData:
37215796c8dcSSimon Schubert 		case scPData:
37225796c8dcSSimon Schubert 		case scXData:
3723c50c785cSJohn Marino 		  svalue += ANOFFSET (objfile->section_offsets,
3724c50c785cSJohn Marino 				      SECT_OFF_DATA (objfile));
37255796c8dcSSimon Schubert 		  break;
37265796c8dcSSimon Schubert 		case scBss:
37275796c8dcSSimon Schubert 		case scSBss:
3728c50c785cSJohn Marino 		  svalue += ANOFFSET (objfile->section_offsets,
3729c50c785cSJohn Marino 				      SECT_OFF_BSS (objfile));
37305796c8dcSSimon Schubert 		  break;
37315796c8dcSSimon Schubert 		}
37325796c8dcSSimon Schubert 
37335796c8dcSSimon Schubert 	      switch (psh->st)
37345796c8dcSSimon Schubert 		{
37355796c8dcSSimon Schubert 		case stNil:
37365796c8dcSSimon Schubert 		  /* These are generated for static symbols in .o files,
37375796c8dcSSimon Schubert 		     ignore them.  */
37385796c8dcSSimon Schubert 		  continue;
37395796c8dcSSimon Schubert 		case stProc:
37405796c8dcSSimon Schubert 		case stStaticProc:
37415796c8dcSSimon Schubert 		  /* External procedure symbols have been entered
37425796c8dcSSimon Schubert 		     into the minimal symbol table in pass 2 above.
37435796c8dcSSimon Schubert 		     Ignore them, as parse_external will ignore them too.  */
37445796c8dcSSimon Schubert 		  continue;
37455796c8dcSSimon Schubert 		case stLabel:
37465796c8dcSSimon Schubert 		  class = LOC_LABEL;
37475796c8dcSSimon Schubert 		  break;
37485796c8dcSSimon Schubert 		default:
37495796c8dcSSimon Schubert 		  unknown_ext_complaint (debug_info->ssext + psh->iss);
37505796c8dcSSimon Schubert 		  /* Fall through, pretend it's global.  */
37515796c8dcSSimon Schubert 		case stGlobal:
37525796c8dcSSimon Schubert 		  /* Global common symbols are resolved by the runtime loader,
37535796c8dcSSimon Schubert 		     ignore them.  */
37545796c8dcSSimon Schubert 		  if (SC_IS_COMMON (psh->sc))
37555796c8dcSSimon Schubert 		    continue;
37565796c8dcSSimon Schubert 
37575796c8dcSSimon Schubert 		  class = LOC_STATIC;
37585796c8dcSSimon Schubert 		  break;
37595796c8dcSSimon Schubert 		}
37605796c8dcSSimon Schubert 	      name = debug_info->ssext + psh->iss;
3761cf7f2e2dSJohn Marino 	      add_psymbol_to_list (name, strlen (name), 1,
37625796c8dcSSimon Schubert 				   VAR_DOMAIN, class,
37635796c8dcSSimon Schubert 				   &objfile->global_psymbols,
37645796c8dcSSimon Schubert 				   0, svalue,
37655796c8dcSSimon Schubert 				   psymtab_language, objfile);
37665796c8dcSSimon Schubert 	    }
37675796c8dcSSimon Schubert 	}
37685796c8dcSSimon Schubert 
37695796c8dcSSimon Schubert       /* Link pst to FDR.  end_psymtab returns NULL if the psymtab was
37705796c8dcSSimon Schubert          empty and put on the free list.  */
3771*ef5ccd6cSJohn Marino       fdr_to_pst[f_idx].pst = end_psymtab (objfile, save_pst,
37725796c8dcSSimon Schubert 					psymtab_include_list, includes_used,
37735796c8dcSSimon Schubert 					   -1, save_pst->texthigh,
37745796c8dcSSimon Schubert 		       dependency_list, dependencies_used, textlow_not_set);
37755796c8dcSSimon Schubert       includes_used = 0;
37765796c8dcSSimon Schubert       dependencies_used = 0;
37775796c8dcSSimon Schubert 
37785796c8dcSSimon Schubert       /* The objfile has its functions reordered if this partial symbol
37795796c8dcSSimon Schubert          table overlaps any other partial symbol table.
37805796c8dcSSimon Schubert          We cannot assume a reordered objfile if a partial symbol table
37815796c8dcSSimon Schubert          is contained within another partial symbol table, as partial symbol
37825796c8dcSSimon Schubert          tables for include files with executable code are contained
37835796c8dcSSimon Schubert          within the partial symbol table for the including source file,
37845796c8dcSSimon Schubert          and we do not want to flag the objfile reordered for these cases.
37855796c8dcSSimon Schubert 
37865796c8dcSSimon Schubert          This strategy works well for Irix-5.2 shared libraries, but we
37875796c8dcSSimon Schubert          might have to use a more elaborate (and slower) algorithm for
37885796c8dcSSimon Schubert          other cases.  */
37895796c8dcSSimon Schubert       save_pst = fdr_to_pst[f_idx].pst;
37905796c8dcSSimon Schubert       if (save_pst != NULL
37915796c8dcSSimon Schubert 	  && save_pst->textlow != 0
37925796c8dcSSimon Schubert 	  && !(objfile->flags & OBJF_REORDERED))
37935796c8dcSSimon Schubert 	{
37945796c8dcSSimon Schubert 	  ALL_OBJFILE_PSYMTABS (objfile, pst)
37955796c8dcSSimon Schubert 	  {
37965796c8dcSSimon Schubert 	    if (save_pst != pst
37975796c8dcSSimon Schubert 		&& save_pst->textlow >= pst->textlow
37985796c8dcSSimon Schubert 		&& save_pst->textlow < pst->texthigh
37995796c8dcSSimon Schubert 		&& save_pst->texthigh > pst->texthigh)
38005796c8dcSSimon Schubert 	      {
38015796c8dcSSimon Schubert 		objfile->flags |= OBJF_REORDERED;
38025796c8dcSSimon Schubert 		break;
38035796c8dcSSimon Schubert 	      }
38045796c8dcSSimon Schubert 	  }
38055796c8dcSSimon Schubert 	}
38065796c8dcSSimon Schubert     }
38075796c8dcSSimon Schubert 
3808c50c785cSJohn Marino   /* Now scan the FDRs for dependencies.  */
38095796c8dcSSimon Schubert   for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
38105796c8dcSSimon Schubert     {
38115796c8dcSSimon Schubert       fh = f_idx + debug_info->fdr;
38125796c8dcSSimon Schubert       pst = fdr_to_pst[f_idx].pst;
38135796c8dcSSimon Schubert 
38145796c8dcSSimon Schubert       if (pst == (struct partial_symtab *) NULL)
38155796c8dcSSimon Schubert 	continue;
38165796c8dcSSimon Schubert 
38175796c8dcSSimon Schubert       /* This should catch stabs-in-ecoff.  */
38185796c8dcSSimon Schubert       if (fh->crfd <= 1)
38195796c8dcSSimon Schubert 	continue;
38205796c8dcSSimon Schubert 
3821c50c785cSJohn Marino       /* Skip the first file indirect entry as it is a self dependency for
3822c50c785cSJohn Marino          source files or a reverse .h -> .c dependency for header files.  */
38235796c8dcSSimon Schubert       pst->number_of_dependencies = 0;
38245796c8dcSSimon Schubert       pst->dependencies =
38255796c8dcSSimon Schubert 	((struct partial_symtab **)
38265796c8dcSSimon Schubert 	 obstack_alloc (&objfile->objfile_obstack,
38275796c8dcSSimon Schubert 			((fh->crfd - 1)
38285796c8dcSSimon Schubert 			 * sizeof (struct partial_symtab *))));
38295796c8dcSSimon Schubert       for (s_idx = 1; s_idx < fh->crfd; s_idx++)
38305796c8dcSSimon Schubert 	{
38315796c8dcSSimon Schubert 	  RFDT rh;
38325796c8dcSSimon Schubert 
38335796c8dcSSimon Schubert 	  (*swap_rfd_in) (cur_bfd,
38345796c8dcSSimon Schubert 			  ((char *) debug_info->external_rfd
38355796c8dcSSimon Schubert 			   + (fh->rfdBase + s_idx) * external_rfd_size),
38365796c8dcSSimon Schubert 			  &rh);
38375796c8dcSSimon Schubert 	  if (rh < 0 || rh >= hdr->ifdMax)
38385796c8dcSSimon Schubert 	    {
38395796c8dcSSimon Schubert 	      complaint (&symfile_complaints, _("bad file number %ld"), rh);
38405796c8dcSSimon Schubert 	      continue;
38415796c8dcSSimon Schubert 	    }
38425796c8dcSSimon Schubert 
38435796c8dcSSimon Schubert 	  /* Skip self dependencies of header files.  */
38445796c8dcSSimon Schubert 	  if (rh == f_idx)
38455796c8dcSSimon Schubert 	    continue;
38465796c8dcSSimon Schubert 
38475796c8dcSSimon Schubert 	  /* Do not add to dependeny list if psymtab was empty.  */
38485796c8dcSSimon Schubert 	  if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL)
38495796c8dcSSimon Schubert 	    continue;
3850c50c785cSJohn Marino 	  pst->dependencies[pst->number_of_dependencies++]
3851c50c785cSJohn Marino 	    = fdr_to_pst[rh].pst;
38525796c8dcSSimon Schubert 	}
38535796c8dcSSimon Schubert     }
38545796c8dcSSimon Schubert 
38555796c8dcSSimon Schubert   /* Remove the dummy psymtab created for -O3 images above, if it is
38565796c8dcSSimon Schubert      still empty, to enable the detection of stripped executables.  */
38575796c8dcSSimon Schubert   if (objfile->psymtabs->next == NULL
38585796c8dcSSimon Schubert       && objfile->psymtabs->number_of_dependencies == 0
38595796c8dcSSimon Schubert       && objfile->psymtabs->n_global_syms == 0
38605796c8dcSSimon Schubert       && objfile->psymtabs->n_static_syms == 0)
38615796c8dcSSimon Schubert     objfile->psymtabs = NULL;
38625796c8dcSSimon Schubert   do_cleanups (old_chain);
38635796c8dcSSimon Schubert }
38645796c8dcSSimon Schubert 
38655796c8dcSSimon Schubert /* If the current psymbol has an enumerated type, we need to add
3866c50c785cSJohn Marino    all the enum constants to the partial symbol table.  */
38675796c8dcSSimon Schubert 
38685796c8dcSSimon Schubert static void
handle_psymbol_enumerators(struct objfile * objfile,FDR * fh,int stype,CORE_ADDR svalue)38695796c8dcSSimon Schubert handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
38705796c8dcSSimon Schubert 			    CORE_ADDR svalue)
38715796c8dcSSimon Schubert {
38725796c8dcSSimon Schubert   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
38735796c8dcSSimon Schubert   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
38745796c8dcSSimon Schubert   char *ext_sym = ((char *) debug_info->external_sym
38755796c8dcSSimon Schubert 		   + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
38765796c8dcSSimon Schubert   SYMR sh;
38775796c8dcSSimon Schubert   TIR tir;
38785796c8dcSSimon Schubert 
38795796c8dcSSimon Schubert   switch (stype)
38805796c8dcSSimon Schubert     {
38815796c8dcSSimon Schubert     case stEnum:
38825796c8dcSSimon Schubert       break;
38835796c8dcSSimon Schubert 
38845796c8dcSSimon Schubert     case stBlock:
38855796c8dcSSimon Schubert       /* It is an enumerated type if the next symbol entry is a stMember
38865796c8dcSSimon Schubert          and its auxiliary index is indexNil or its auxiliary entry
38875796c8dcSSimon Schubert          is a plain btNil or btVoid.
38885796c8dcSSimon Schubert          Alpha cc -migrate enums are recognized by a zero index and
38895796c8dcSSimon Schubert          a zero symbol value.
38905796c8dcSSimon Schubert          DU 4.0 cc enums are recognized by a member type of btEnum without
38915796c8dcSSimon Schubert          qualifiers and a zero symbol value.  */
38925796c8dcSSimon Schubert       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
38935796c8dcSSimon Schubert       if (sh.st != stMember)
38945796c8dcSSimon Schubert 	return;
38955796c8dcSSimon Schubert 
38965796c8dcSSimon Schubert       if (sh.index == indexNil
38975796c8dcSSimon Schubert 	  || (sh.index == 0 && svalue == 0))
38985796c8dcSSimon Schubert 	break;
38995796c8dcSSimon Schubert       (*debug_swap->swap_tir_in) (fh->fBigendian,
39005796c8dcSSimon Schubert 				  &(debug_info->external_aux
39015796c8dcSSimon Schubert 				    + fh->iauxBase + sh.index)->a_ti,
39025796c8dcSSimon Schubert 				  &tir);
39035796c8dcSSimon Schubert       if ((tir.bt != btNil
39045796c8dcSSimon Schubert 	   && tir.bt != btVoid
39055796c8dcSSimon Schubert 	   && (tir.bt != btEnum || svalue != 0))
39065796c8dcSSimon Schubert 	  || tir.tq0 != tqNil)
39075796c8dcSSimon Schubert 	return;
39085796c8dcSSimon Schubert       break;
39095796c8dcSSimon Schubert 
39105796c8dcSSimon Schubert     default:
39115796c8dcSSimon Schubert       return;
39125796c8dcSSimon Schubert     }
39135796c8dcSSimon Schubert 
39145796c8dcSSimon Schubert   for (;;)
39155796c8dcSSimon Schubert     {
39165796c8dcSSimon Schubert       char *name;
39175796c8dcSSimon Schubert 
39185796c8dcSSimon Schubert       (*swap_sym_in) (cur_bfd, ext_sym, &sh);
39195796c8dcSSimon Schubert       if (sh.st != stMember)
39205796c8dcSSimon Schubert 	break;
39215796c8dcSSimon Schubert       name = debug_info->ss + cur_fdr->issBase + sh.iss;
39225796c8dcSSimon Schubert 
39235796c8dcSSimon Schubert       /* Note that the value doesn't matter for enum constants
39245796c8dcSSimon Schubert          in psymtabs, just in symtabs.  */
3925cf7f2e2dSJohn Marino       add_psymbol_to_list (name, strlen (name), 1,
39265796c8dcSSimon Schubert 			   VAR_DOMAIN, LOC_CONST,
39275796c8dcSSimon Schubert 			   &objfile->static_psymbols, 0,
39285796c8dcSSimon Schubert 			   (CORE_ADDR) 0, psymtab_language, objfile);
39295796c8dcSSimon Schubert       ext_sym += external_sym_size;
39305796c8dcSSimon Schubert     }
39315796c8dcSSimon Schubert }
39325796c8dcSSimon Schubert 
39335796c8dcSSimon Schubert /* Get the next symbol.  OBJFILE is unused.  */
39345796c8dcSSimon Schubert 
39355796c8dcSSimon Schubert static char *
mdebug_next_symbol_text(struct objfile * objfile)39365796c8dcSSimon Schubert mdebug_next_symbol_text (struct objfile *objfile)
39375796c8dcSSimon Schubert {
39385796c8dcSSimon Schubert   SYMR sh;
39395796c8dcSSimon Schubert 
39405796c8dcSSimon Schubert   cur_sdx++;
39415796c8dcSSimon Schubert   (*debug_swap->swap_sym_in) (cur_bfd,
39425796c8dcSSimon Schubert 			      ((char *) debug_info->external_sym
39435796c8dcSSimon Schubert 			       + ((cur_fdr->isymBase + cur_sdx)
39445796c8dcSSimon Schubert 				  * debug_swap->external_sym_size)),
39455796c8dcSSimon Schubert 			      &sh);
39465796c8dcSSimon Schubert   return debug_info->ss + cur_fdr->issBase + sh.iss;
39475796c8dcSSimon Schubert }
39485796c8dcSSimon Schubert 
39495796c8dcSSimon Schubert /* Ancillary function to psymtab_to_symtab().  Does all the work
39505796c8dcSSimon Schubert    for turning the partial symtab PST into a symtab, recurring
39515796c8dcSSimon Schubert    first on all dependent psymtabs.  The argument FILENAME is
39525796c8dcSSimon Schubert    only passed so we can see in debug stack traces what file
39535796c8dcSSimon Schubert    is being read.
39545796c8dcSSimon Schubert 
39555796c8dcSSimon Schubert    This function has a split personality, based on whether the
39565796c8dcSSimon Schubert    symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
39575796c8dcSSimon Schubert    The flow of control and even the memory allocation differs.  FIXME.  */
39585796c8dcSSimon Schubert 
39595796c8dcSSimon Schubert static void
psymtab_to_symtab_1(struct objfile * objfile,struct partial_symtab * pst,const char * filename)3960*ef5ccd6cSJohn Marino psymtab_to_symtab_1 (struct objfile *objfile,
3961*ef5ccd6cSJohn Marino 		     struct partial_symtab *pst, const char *filename)
39625796c8dcSSimon Schubert {
39635796c8dcSSimon Schubert   bfd_size_type external_sym_size;
39645796c8dcSSimon Schubert   bfd_size_type external_pdr_size;
39655796c8dcSSimon Schubert   void (*swap_sym_in) (bfd *, void *, SYMR *);
39665796c8dcSSimon Schubert   void (*swap_pdr_in) (bfd *, void *, PDR *);
39675796c8dcSSimon Schubert   int i;
39685796c8dcSSimon Schubert   struct symtab *st = NULL;
39695796c8dcSSimon Schubert   FDR *fh;
39705796c8dcSSimon Schubert   struct linetable *lines;
39715796c8dcSSimon Schubert   CORE_ADDR lowest_pdr_addr = 0;
39725796c8dcSSimon Schubert   int last_symtab_ended = 0;
39735796c8dcSSimon Schubert 
39745796c8dcSSimon Schubert   if (pst->readin)
39755796c8dcSSimon Schubert     return;
39765796c8dcSSimon Schubert   pst->readin = 1;
39775796c8dcSSimon Schubert 
39785796c8dcSSimon Schubert   /* Read in all partial symbtabs on which this one is dependent.
39795796c8dcSSimon Schubert      NOTE that we do have circular dependencies, sigh.  We solved
39805796c8dcSSimon Schubert      that by setting pst->readin before this point.  */
39815796c8dcSSimon Schubert 
39825796c8dcSSimon Schubert   for (i = 0; i < pst->number_of_dependencies; i++)
39835796c8dcSSimon Schubert     if (!pst->dependencies[i]->readin)
39845796c8dcSSimon Schubert       {
39855796c8dcSSimon Schubert 	/* Inform about additional files to be read in.  */
39865796c8dcSSimon Schubert 	if (info_verbose)
39875796c8dcSSimon Schubert 	  {
39885796c8dcSSimon Schubert 	    fputs_filtered (" ", gdb_stdout);
39895796c8dcSSimon Schubert 	    wrap_here ("");
39905796c8dcSSimon Schubert 	    fputs_filtered ("and ", gdb_stdout);
39915796c8dcSSimon Schubert 	    wrap_here ("");
39925796c8dcSSimon Schubert 	    printf_filtered ("%s...",
39935796c8dcSSimon Schubert 			     pst->dependencies[i]->filename);
39945796c8dcSSimon Schubert 	    wrap_here ("");	/* Flush output */
39955796c8dcSSimon Schubert 	    gdb_flush (gdb_stdout);
39965796c8dcSSimon Schubert 	  }
3997c50c785cSJohn Marino 	/* We only pass the filename for debug purposes.  */
3998*ef5ccd6cSJohn Marino 	psymtab_to_symtab_1 (objfile, pst->dependencies[i],
39995796c8dcSSimon Schubert 			     pst->dependencies[i]->filename);
40005796c8dcSSimon Schubert       }
40015796c8dcSSimon Schubert 
40025796c8dcSSimon Schubert   /* Do nothing if this is a dummy psymtab.  */
40035796c8dcSSimon Schubert 
40045796c8dcSSimon Schubert   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
40055796c8dcSSimon Schubert       && pst->textlow == 0 && pst->texthigh == 0)
40065796c8dcSSimon Schubert     return;
40075796c8dcSSimon Schubert 
4008c50c785cSJohn Marino   /* Now read the symbols for this symtab.  */
40095796c8dcSSimon Schubert 
40105796c8dcSSimon Schubert   cur_bfd = CUR_BFD (pst);
40115796c8dcSSimon Schubert   debug_swap = DEBUG_SWAP (pst);
40125796c8dcSSimon Schubert   debug_info = DEBUG_INFO (pst);
40135796c8dcSSimon Schubert   pending_list = PENDING_LIST (pst);
40145796c8dcSSimon Schubert   external_sym_size = debug_swap->external_sym_size;
40155796c8dcSSimon Schubert   external_pdr_size = debug_swap->external_pdr_size;
40165796c8dcSSimon Schubert   swap_sym_in = debug_swap->swap_sym_in;
40175796c8dcSSimon Schubert   swap_pdr_in = debug_swap->swap_pdr_in;
4018*ef5ccd6cSJohn Marino   mdebugread_objfile = objfile;
40195796c8dcSSimon Schubert   cur_fd = FDR_IDX (pst);
40205796c8dcSSimon Schubert   fh = ((cur_fd == -1)
40215796c8dcSSimon Schubert 	? (FDR *) NULL
40225796c8dcSSimon Schubert 	: debug_info->fdr + cur_fd);
40235796c8dcSSimon Schubert   cur_fdr = fh;
40245796c8dcSSimon Schubert 
40255796c8dcSSimon Schubert   /* See comment in parse_partial_symbols about the @stabs sentinel.  */
40265796c8dcSSimon Schubert   processing_gcc_compilation = 0;
40275796c8dcSSimon Schubert   if (fh != (FDR *) NULL && fh->csym >= 2)
40285796c8dcSSimon Schubert     {
40295796c8dcSSimon Schubert       SYMR sh;
40305796c8dcSSimon Schubert 
40315796c8dcSSimon Schubert       (*swap_sym_in) (cur_bfd,
40325796c8dcSSimon Schubert 		      ((char *) debug_info->external_sym
40335796c8dcSSimon Schubert 		       + (fh->isymBase + 1) * external_sym_size),
40345796c8dcSSimon Schubert 		      &sh);
40355796c8dcSSimon Schubert       if (strcmp (debug_info->ss + fh->issBase + sh.iss,
40365796c8dcSSimon Schubert 		  stabs_symbol) == 0)
40375796c8dcSSimon Schubert 	{
40385796c8dcSSimon Schubert 	  /* We indicate that this is a GCC compilation so that certain
40395796c8dcSSimon Schubert 	     features will be enabled in stabsread/dbxread.  */
40405796c8dcSSimon Schubert 	  processing_gcc_compilation = 2;
40415796c8dcSSimon Schubert 	}
40425796c8dcSSimon Schubert     }
40435796c8dcSSimon Schubert 
40445796c8dcSSimon Schubert   if (processing_gcc_compilation != 0)
40455796c8dcSSimon Schubert     {
4046*ef5ccd6cSJohn Marino       struct gdbarch *gdbarch = get_objfile_arch (objfile);
40475796c8dcSSimon Schubert 
40485796c8dcSSimon Schubert       /* This symbol table contains stabs-in-ecoff entries.  */
40495796c8dcSSimon Schubert 
4050c50c785cSJohn Marino       /* Parse local symbols first.  */
40515796c8dcSSimon Schubert 
4052c50c785cSJohn Marino       if (fh->csym <= 2)	/* FIXME, this blows psymtab->symtab ptr.  */
40535796c8dcSSimon Schubert 	{
4054a45ae5f8SJohn Marino 	  mdebugread_objfile = NULL;
40555796c8dcSSimon Schubert 	  return;
40565796c8dcSSimon Schubert 	}
40575796c8dcSSimon Schubert       for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
40585796c8dcSSimon Schubert 	{
40595796c8dcSSimon Schubert 	  SYMR sh;
40605796c8dcSSimon Schubert 	  char *name;
40615796c8dcSSimon Schubert 	  CORE_ADDR valu;
40625796c8dcSSimon Schubert 
40635796c8dcSSimon Schubert 	  (*swap_sym_in) (cur_bfd,
40645796c8dcSSimon Schubert 			  (((char *) debug_info->external_sym)
40655796c8dcSSimon Schubert 			   + (fh->isymBase + cur_sdx) * external_sym_size),
40665796c8dcSSimon Schubert 			  &sh);
40675796c8dcSSimon Schubert 	  name = debug_info->ss + fh->issBase + sh.iss;
40685796c8dcSSimon Schubert 	  valu = sh.value;
40695796c8dcSSimon Schubert 	  /* XXX This is a hack.  It will go away!  */
40705796c8dcSSimon Schubert 	  if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
40715796c8dcSSimon Schubert 	    {
40725796c8dcSSimon Schubert 	      int type_code = ECOFF_UNMARK_STAB (sh.index);
40735796c8dcSSimon Schubert 
40745796c8dcSSimon Schubert 	      /* We should never get non N_STAB symbols here, but they
40755796c8dcSSimon Schubert 	         should be harmless, so keep process_one_symbol from
40765796c8dcSSimon Schubert 	         complaining about them.  */
40775796c8dcSSimon Schubert 	      if (type_code & N_STAB)
40785796c8dcSSimon Schubert 		{
40795796c8dcSSimon Schubert 		  /* If we found a trailing N_SO with no name, process
40805796c8dcSSimon Schubert                      it here instead of in process_one_symbol, so we
40815796c8dcSSimon Schubert                      can keep a handle to its symtab.  The symtab
40825796c8dcSSimon Schubert                      would otherwise be ended twice, once in
40835796c8dcSSimon Schubert                      process_one_symbol, and once after this loop.  */
40845796c8dcSSimon Schubert 		  if (type_code == N_SO
4085*ef5ccd6cSJohn Marino 		      && get_last_source_file ()
40865796c8dcSSimon Schubert 		      && previous_stab_code != (unsigned char) N_SO
40875796c8dcSSimon Schubert 		      && *name == '\000')
40885796c8dcSSimon Schubert 		    {
40895796c8dcSSimon Schubert 		      valu += ANOFFSET (pst->section_offsets,
4090*ef5ccd6cSJohn Marino 					SECT_OFF_TEXT (objfile));
40915796c8dcSSimon Schubert 		      previous_stab_code = N_SO;
4092*ef5ccd6cSJohn Marino 		      st = end_symtab (valu, objfile,
4093*ef5ccd6cSJohn Marino 				       SECT_OFF_TEXT (objfile));
40945796c8dcSSimon Schubert 		      end_stabs ();
40955796c8dcSSimon Schubert 		      last_symtab_ended = 1;
40965796c8dcSSimon Schubert 		    }
40975796c8dcSSimon Schubert 		  else
40985796c8dcSSimon Schubert 		    {
40995796c8dcSSimon Schubert 		      last_symtab_ended = 0;
41005796c8dcSSimon Schubert 		      process_one_symbol (type_code, 0, valu, name,
4101*ef5ccd6cSJohn Marino 					  pst->section_offsets, objfile);
41025796c8dcSSimon Schubert 		    }
41035796c8dcSSimon Schubert 		}
41045796c8dcSSimon Schubert 	      /* Similarly a hack.  */
41055796c8dcSSimon Schubert 	      else if (name[0] == '#')
41065796c8dcSSimon Schubert 		{
41075796c8dcSSimon Schubert 		  process_one_symbol (N_SLINE, 0, valu, name,
4108*ef5ccd6cSJohn Marino 				      pst->section_offsets, objfile);
41095796c8dcSSimon Schubert 		}
41105796c8dcSSimon Schubert 	      if (type_code == N_FUN)
41115796c8dcSSimon Schubert 		{
41125796c8dcSSimon Schubert 		  /* Make up special symbol to contain
4113c50c785cSJohn Marino 		     procedure specific info.  */
41145796c8dcSSimon Schubert 		  struct mdebug_extra_func_info *e =
41155796c8dcSSimon Schubert 		    ((struct mdebug_extra_func_info *)
4116a45ae5f8SJohn Marino 		     obstack_alloc (&mdebugread_objfile->objfile_obstack,
41175796c8dcSSimon Schubert 				    sizeof (struct mdebug_extra_func_info)));
41185796c8dcSSimon Schubert 		  struct symbol *s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
41195796c8dcSSimon Schubert 
41205796c8dcSSimon Schubert 		  memset (e, 0, sizeof (struct mdebug_extra_func_info));
41215796c8dcSSimon Schubert 		  SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
41225796c8dcSSimon Schubert 		  SYMBOL_CLASS (s) = LOC_CONST;
4123*ef5ccd6cSJohn Marino 		  SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_void;
41245796c8dcSSimon Schubert 		  SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
41255796c8dcSSimon Schubert 		  e->pdr.framereg = -1;
41265796c8dcSSimon Schubert 		  add_symbol_to_list (s, &local_symbols);
41275796c8dcSSimon Schubert 		}
41285796c8dcSSimon Schubert 	    }
41295796c8dcSSimon Schubert 	  else if (sh.st == stLabel)
41305796c8dcSSimon Schubert 	    {
41315796c8dcSSimon Schubert 	      if (sh.index == indexNil)
41325796c8dcSSimon Schubert 		{
41335796c8dcSSimon Schubert 		  /* This is what the gcc2_compiled and __gnu_compiled_*
41345796c8dcSSimon Schubert 		     show up as.  So don't complain.  */
41355796c8dcSSimon Schubert 		  ;
41365796c8dcSSimon Schubert 		}
41375796c8dcSSimon Schubert 	      else
41385796c8dcSSimon Schubert 		{
41395796c8dcSSimon Schubert 		  /* Handle encoded stab line number.  */
4140c50c785cSJohn Marino 		  valu += ANOFFSET (pst->section_offsets,
4141*ef5ccd6cSJohn Marino 				    SECT_OFF_TEXT (objfile));
41425796c8dcSSimon Schubert 		  record_line (current_subfile, sh.index,
41435796c8dcSSimon Schubert 			       gdbarch_addr_bits_remove (gdbarch, valu));
41445796c8dcSSimon Schubert 		}
41455796c8dcSSimon Schubert 	    }
41465796c8dcSSimon Schubert 	  else if (sh.st == stProc || sh.st == stStaticProc
41475796c8dcSSimon Schubert 		   || sh.st == stStatic || sh.st == stEnd)
4148c50c785cSJohn Marino 	    /* These are generated by gcc-2.x, do not complain.  */
41495796c8dcSSimon Schubert 	    ;
41505796c8dcSSimon Schubert 	  else
4151c50c785cSJohn Marino 	    complaint (&symfile_complaints,
4152c50c785cSJohn Marino 		       _("unknown stabs symbol %s"), name);
41535796c8dcSSimon Schubert 	}
41545796c8dcSSimon Schubert 
41555796c8dcSSimon Schubert       if (! last_symtab_ended)
41565796c8dcSSimon Schubert 	{
4157*ef5ccd6cSJohn Marino 	  st = end_symtab (pst->texthigh, objfile,
4158*ef5ccd6cSJohn Marino 			   SECT_OFF_TEXT (objfile));
41595796c8dcSSimon Schubert 	  end_stabs ();
41605796c8dcSSimon Schubert 	}
41615796c8dcSSimon Schubert 
41625796c8dcSSimon Schubert       /* There used to be a call to sort_blocks here, but this should not
41635796c8dcSSimon Schubert          be necessary for stabs symtabs.  And as sort_blocks modifies the
41645796c8dcSSimon Schubert          start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
41655796c8dcSSimon Schubert          it did the wrong thing if the first procedure in a file was
41665796c8dcSSimon Schubert          generated via asm statements.  */
41675796c8dcSSimon Schubert 
41685796c8dcSSimon Schubert       /* Fill in procedure info next.  */
41695796c8dcSSimon Schubert       if (fh->cpd > 0)
41705796c8dcSSimon Schubert 	{
41715796c8dcSSimon Schubert 	  PDR *pr_block;
41725796c8dcSSimon Schubert 	  struct cleanup *old_chain;
41735796c8dcSSimon Schubert 	  char *pdr_ptr;
41745796c8dcSSimon Schubert 	  char *pdr_end;
41755796c8dcSSimon Schubert 	  PDR *pdr_in;
41765796c8dcSSimon Schubert 	  PDR *pdr_in_end;
41775796c8dcSSimon Schubert 
41785796c8dcSSimon Schubert 	  pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
41795796c8dcSSimon Schubert 	  old_chain = make_cleanup (xfree, pr_block);
41805796c8dcSSimon Schubert 
41815796c8dcSSimon Schubert 	  pdr_ptr = ((char *) debug_info->external_pdr
41825796c8dcSSimon Schubert 		     + fh->ipdFirst * external_pdr_size);
41835796c8dcSSimon Schubert 	  pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
41845796c8dcSSimon Schubert 	  pdr_in = pr_block;
41855796c8dcSSimon Schubert 	  for (;
41865796c8dcSSimon Schubert 	       pdr_ptr < pdr_end;
41875796c8dcSSimon Schubert 	       pdr_ptr += external_pdr_size, pdr_in++)
41885796c8dcSSimon Schubert 	    {
41895796c8dcSSimon Schubert 	      (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
41905796c8dcSSimon Schubert 
41915796c8dcSSimon Schubert 	      /* Determine lowest PDR address, the PDRs are not always
41925796c8dcSSimon Schubert 	         sorted.  */
41935796c8dcSSimon Schubert 	      if (pdr_in == pr_block)
41945796c8dcSSimon Schubert 		lowest_pdr_addr = pdr_in->adr;
41955796c8dcSSimon Schubert 	      else if (pdr_in->adr < lowest_pdr_addr)
41965796c8dcSSimon Schubert 		lowest_pdr_addr = pdr_in->adr;
41975796c8dcSSimon Schubert 	    }
41985796c8dcSSimon Schubert 
41995796c8dcSSimon Schubert 	  pdr_in = pr_block;
42005796c8dcSSimon Schubert 	  pdr_in_end = pdr_in + fh->cpd;
42015796c8dcSSimon Schubert 	  for (; pdr_in < pdr_in_end; pdr_in++)
42025796c8dcSSimon Schubert 	    parse_procedure (pdr_in, st, pst);
42035796c8dcSSimon Schubert 
42045796c8dcSSimon Schubert 	  do_cleanups (old_chain);
42055796c8dcSSimon Schubert 	}
42065796c8dcSSimon Schubert     }
42075796c8dcSSimon Schubert   else
42085796c8dcSSimon Schubert     {
42095796c8dcSSimon Schubert       /* This symbol table contains ordinary ecoff entries.  */
42105796c8dcSSimon Schubert 
4211a45ae5f8SJohn Marino       int maxlines, size;
42125796c8dcSSimon Schubert       EXTR *ext_ptr;
42135796c8dcSSimon Schubert 
42145796c8dcSSimon Schubert       if (fh == 0)
42155796c8dcSSimon Schubert 	{
42165796c8dcSSimon Schubert 	  maxlines = 0;
4217*ef5ccd6cSJohn Marino 	  st = new_symtab ("unknown", 0, objfile);
42185796c8dcSSimon Schubert 	}
42195796c8dcSSimon Schubert       else
42205796c8dcSSimon Schubert 	{
42215796c8dcSSimon Schubert 	  maxlines = 2 * fh->cline;
4222*ef5ccd6cSJohn Marino 	  st = new_symtab (pst->filename, maxlines, objfile);
42235796c8dcSSimon Schubert 
42245796c8dcSSimon Schubert 	  /* The proper language was already determined when building
42255796c8dcSSimon Schubert 	     the psymtab, use it.  */
42265796c8dcSSimon Schubert 	  st->language = PST_PRIVATE (pst)->pst_language;
42275796c8dcSSimon Schubert 	}
42285796c8dcSSimon Schubert 
42295796c8dcSSimon Schubert       psymtab_language = st->language;
42305796c8dcSSimon Schubert 
42315796c8dcSSimon Schubert       lines = LINETABLE (st);
42325796c8dcSSimon Schubert 
4233c50c785cSJohn Marino       /* Get a new lexical context.  */
42345796c8dcSSimon Schubert 
42355796c8dcSSimon Schubert       push_parse_stack ();
42365796c8dcSSimon Schubert       top_stack->cur_st = st;
42375796c8dcSSimon Schubert       top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
42385796c8dcSSimon Schubert 						STATIC_BLOCK);
42395796c8dcSSimon Schubert       BLOCK_START (top_stack->cur_block) = pst->textlow;
42405796c8dcSSimon Schubert       BLOCK_END (top_stack->cur_block) = 0;
42415796c8dcSSimon Schubert       top_stack->blocktype = stFile;
42425796c8dcSSimon Schubert       top_stack->cur_type = 0;
42435796c8dcSSimon Schubert       top_stack->procadr = 0;
42445796c8dcSSimon Schubert       top_stack->numargs = 0;
42455796c8dcSSimon Schubert       found_ecoff_debugging_info = 0;
42465796c8dcSSimon Schubert 
42475796c8dcSSimon Schubert       if (fh)
42485796c8dcSSimon Schubert 	{
42495796c8dcSSimon Schubert 	  char *sym_ptr;
42505796c8dcSSimon Schubert 	  char *sym_end;
42515796c8dcSSimon Schubert 
4252c50c785cSJohn Marino 	  /* Parse local symbols first.  */
42535796c8dcSSimon Schubert 	  sym_ptr = ((char *) debug_info->external_sym
42545796c8dcSSimon Schubert 		     + fh->isymBase * external_sym_size);
42555796c8dcSSimon Schubert 	  sym_end = sym_ptr + fh->csym * external_sym_size;
42565796c8dcSSimon Schubert 	  while (sym_ptr < sym_end)
42575796c8dcSSimon Schubert 	    {
42585796c8dcSSimon Schubert 	      SYMR sh;
42595796c8dcSSimon Schubert 	      int c;
42605796c8dcSSimon Schubert 
42615796c8dcSSimon Schubert 	      (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
42625796c8dcSSimon Schubert 	      c = parse_symbol (&sh,
42635796c8dcSSimon Schubert 				debug_info->external_aux + fh->iauxBase,
4264c50c785cSJohn Marino 				sym_ptr, fh->fBigendian,
4265*ef5ccd6cSJohn Marino 				pst->section_offsets, objfile);
42665796c8dcSSimon Schubert 	      sym_ptr += c * external_sym_size;
42675796c8dcSSimon Schubert 	    }
42685796c8dcSSimon Schubert 
42695796c8dcSSimon Schubert 	  /* Linenumbers.  At the end, check if we can save memory.
42705796c8dcSSimon Schubert 	     parse_lines has to look ahead an arbitrary number of PDR
42715796c8dcSSimon Schubert 	     structures, so we swap them all first.  */
42725796c8dcSSimon Schubert 	  if (fh->cpd > 0)
42735796c8dcSSimon Schubert 	    {
42745796c8dcSSimon Schubert 	      PDR *pr_block;
42755796c8dcSSimon Schubert 	      struct cleanup *old_chain;
42765796c8dcSSimon Schubert 	      char *pdr_ptr;
42775796c8dcSSimon Schubert 	      char *pdr_end;
42785796c8dcSSimon Schubert 	      PDR *pdr_in;
42795796c8dcSSimon Schubert 	      PDR *pdr_in_end;
42805796c8dcSSimon Schubert 
42815796c8dcSSimon Schubert 	      pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
42825796c8dcSSimon Schubert 
42835796c8dcSSimon Schubert 	      old_chain = make_cleanup (xfree, pr_block);
42845796c8dcSSimon Schubert 
42855796c8dcSSimon Schubert 	      pdr_ptr = ((char *) debug_info->external_pdr
42865796c8dcSSimon Schubert 			 + fh->ipdFirst * external_pdr_size);
42875796c8dcSSimon Schubert 	      pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
42885796c8dcSSimon Schubert 	      pdr_in = pr_block;
42895796c8dcSSimon Schubert 	      for (;
42905796c8dcSSimon Schubert 		   pdr_ptr < pdr_end;
42915796c8dcSSimon Schubert 		   pdr_ptr += external_pdr_size, pdr_in++)
42925796c8dcSSimon Schubert 		{
42935796c8dcSSimon Schubert 		  (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
42945796c8dcSSimon Schubert 
42955796c8dcSSimon Schubert 		  /* Determine lowest PDR address, the PDRs are not always
42965796c8dcSSimon Schubert 		     sorted.  */
42975796c8dcSSimon Schubert 		  if (pdr_in == pr_block)
42985796c8dcSSimon Schubert 		    lowest_pdr_addr = pdr_in->adr;
42995796c8dcSSimon Schubert 		  else if (pdr_in->adr < lowest_pdr_addr)
43005796c8dcSSimon Schubert 		    lowest_pdr_addr = pdr_in->adr;
43015796c8dcSSimon Schubert 		}
43025796c8dcSSimon Schubert 
4303c50c785cSJohn Marino 	      parse_lines (fh, pr_block, lines, maxlines,
4304c50c785cSJohn Marino 			   pst, lowest_pdr_addr);
43055796c8dcSSimon Schubert 	      if (lines->nitems < fh->cline)
43065796c8dcSSimon Schubert 		lines = shrink_linetable (lines);
43075796c8dcSSimon Schubert 
43085796c8dcSSimon Schubert 	      /* Fill in procedure info next.  */
43095796c8dcSSimon Schubert 	      pdr_in = pr_block;
43105796c8dcSSimon Schubert 	      pdr_in_end = pdr_in + fh->cpd;
43115796c8dcSSimon Schubert 	      for (; pdr_in < pdr_in_end; pdr_in++)
43125796c8dcSSimon Schubert 		parse_procedure (pdr_in, 0, pst);
43135796c8dcSSimon Schubert 
43145796c8dcSSimon Schubert 	      do_cleanups (old_chain);
43155796c8dcSSimon Schubert 	    }
43165796c8dcSSimon Schubert 	}
43175796c8dcSSimon Schubert 
4318a45ae5f8SJohn Marino       size = lines->nitems;
4319a45ae5f8SJohn Marino       if (size > 1)
4320a45ae5f8SJohn Marino 	--size;
4321a45ae5f8SJohn Marino       LINETABLE (st) = obstack_copy (&mdebugread_objfile->objfile_obstack,
4322a45ae5f8SJohn Marino 				     lines,
4323a45ae5f8SJohn Marino 				     (sizeof (struct linetable)
4324a45ae5f8SJohn Marino 				      + size * sizeof (lines->item)));
4325a45ae5f8SJohn Marino       xfree (lines);
43265796c8dcSSimon Schubert 
43275796c8dcSSimon Schubert       /* .. and our share of externals.
4328c50c785cSJohn Marino          XXX use the global list to speed up things here.  How?
43295796c8dcSSimon Schubert          FIXME, Maybe quit once we have found the right number of ext's?  */
43305796c8dcSSimon Schubert       top_stack->cur_st = st;
4331c50c785cSJohn Marino       top_stack->cur_block
4332c50c785cSJohn Marino 	= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
43335796c8dcSSimon Schubert 			     GLOBAL_BLOCK);
43345796c8dcSSimon Schubert       top_stack->blocktype = stFile;
43355796c8dcSSimon Schubert 
43365796c8dcSSimon Schubert       ext_ptr = PST_PRIVATE (pst)->extern_tab;
43375796c8dcSSimon Schubert       for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
4338c50c785cSJohn Marino 	parse_external (ext_ptr, fh->fBigendian,
4339*ef5ccd6cSJohn Marino 			pst->section_offsets, objfile);
43405796c8dcSSimon Schubert 
43415796c8dcSSimon Schubert       /* If there are undefined symbols, tell the user.
43425796c8dcSSimon Schubert          The alpha has an undefined symbol for every symbol that is
43435796c8dcSSimon Schubert          from a shared library, so tell the user only if verbose is on.  */
43445796c8dcSSimon Schubert       if (info_verbose && n_undef_symbols)
43455796c8dcSSimon Schubert 	{
43465796c8dcSSimon Schubert 	  printf_filtered (_("File %s contains %d unresolved references:"),
4347*ef5ccd6cSJohn Marino 			   symtab_to_filename_for_display (st),
4348*ef5ccd6cSJohn Marino 			   n_undef_symbols);
4349c50c785cSJohn Marino 	  printf_filtered ("\n\t%4d variables\n\t%4d "
4350c50c785cSJohn Marino 			   "procedures\n\t%4d labels\n",
43515796c8dcSSimon Schubert 			   n_undef_vars, n_undef_procs, n_undef_labels);
43525796c8dcSSimon Schubert 	  n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
43535796c8dcSSimon Schubert 
43545796c8dcSSimon Schubert 	}
43555796c8dcSSimon Schubert       pop_parse_stack ();
43565796c8dcSSimon Schubert 
43575796c8dcSSimon Schubert       st->primary = 1;
43585796c8dcSSimon Schubert 
43595796c8dcSSimon Schubert       sort_blocks (st);
43605796c8dcSSimon Schubert     }
43615796c8dcSSimon Schubert 
43625796c8dcSSimon Schubert   /* Now link the psymtab and the symtab.  */
43635796c8dcSSimon Schubert   pst->symtab = st;
43645796c8dcSSimon Schubert 
4365a45ae5f8SJohn Marino   mdebugread_objfile = NULL;
43665796c8dcSSimon Schubert }
43675796c8dcSSimon Schubert 
43685796c8dcSSimon Schubert /* Ancillary parsing procedures.  */
43695796c8dcSSimon Schubert 
43705796c8dcSSimon Schubert /* Return 1 if the symbol pointed to by SH has a cross reference
43715796c8dcSSimon Schubert    to an opaque aggregate type, else 0.  */
43725796c8dcSSimon Schubert 
43735796c8dcSSimon Schubert static int
has_opaque_xref(FDR * fh,SYMR * sh)43745796c8dcSSimon Schubert has_opaque_xref (FDR *fh, SYMR *sh)
43755796c8dcSSimon Schubert {
43765796c8dcSSimon Schubert   TIR tir;
43775796c8dcSSimon Schubert   union aux_ext *ax;
43785796c8dcSSimon Schubert   RNDXR rn[1];
43795796c8dcSSimon Schubert   unsigned int rf;
43805796c8dcSSimon Schubert 
43815796c8dcSSimon Schubert   if (sh->index == indexNil)
43825796c8dcSSimon Schubert     return 0;
43835796c8dcSSimon Schubert 
43845796c8dcSSimon Schubert   ax = debug_info->external_aux + fh->iauxBase + sh->index;
43855796c8dcSSimon Schubert   (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
43865796c8dcSSimon Schubert   if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
43875796c8dcSSimon Schubert     return 0;
43885796c8dcSSimon Schubert 
43895796c8dcSSimon Schubert   ax++;
43905796c8dcSSimon Schubert   (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
43915796c8dcSSimon Schubert   if (rn->rfd == 0xfff)
43925796c8dcSSimon Schubert     rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
43935796c8dcSSimon Schubert   else
43945796c8dcSSimon Schubert     rf = rn->rfd;
43955796c8dcSSimon Schubert   if (rf != -1)
43965796c8dcSSimon Schubert     return 0;
43975796c8dcSSimon Schubert   return 1;
43985796c8dcSSimon Schubert }
43995796c8dcSSimon Schubert 
44005796c8dcSSimon Schubert /* Lookup the type at relative index RN.  Return it in TPP
44015796c8dcSSimon Schubert    if found and in any event come up with its name PNAME.
44025796c8dcSSimon Schubert    BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
44035796c8dcSSimon Schubert    Return value says how many aux symbols we ate.  */
44045796c8dcSSimon Schubert 
44055796c8dcSSimon Schubert static int
cross_ref(int fd,union aux_ext * ax,struct type ** tpp,enum type_code type_code,char ** pname,int bigend,char * sym_name)4406c50c785cSJohn Marino cross_ref (int fd, union aux_ext *ax, struct type **tpp,
4407c50c785cSJohn Marino 	   enum type_code type_code,
4408c50c785cSJohn Marino 	   /* Use to alloc new type if none is found.  */
44095796c8dcSSimon Schubert 	   char **pname, int bigend, char *sym_name)
44105796c8dcSSimon Schubert {
44115796c8dcSSimon Schubert   RNDXR rn[1];
44125796c8dcSSimon Schubert   unsigned int rf;
44135796c8dcSSimon Schubert   int result = 1;
44145796c8dcSSimon Schubert   FDR *fh;
44155796c8dcSSimon Schubert   char *esh;
44165796c8dcSSimon Schubert   SYMR sh;
44175796c8dcSSimon Schubert   int xref_fd;
44185796c8dcSSimon Schubert   struct mdebug_pending *pend;
44195796c8dcSSimon Schubert 
44205796c8dcSSimon Schubert   *tpp = (struct type *) NULL;
44215796c8dcSSimon Schubert 
44225796c8dcSSimon Schubert   (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
44235796c8dcSSimon Schubert 
4424c50c785cSJohn Marino   /* Escape index means 'the next one'.  */
44255796c8dcSSimon Schubert   if (rn->rfd == 0xfff)
44265796c8dcSSimon Schubert     {
44275796c8dcSSimon Schubert       result++;
44285796c8dcSSimon Schubert       rf = AUX_GET_ISYM (bigend, ax + 1);
44295796c8dcSSimon Schubert     }
44305796c8dcSSimon Schubert   else
44315796c8dcSSimon Schubert     {
44325796c8dcSSimon Schubert       rf = rn->rfd;
44335796c8dcSSimon Schubert     }
44345796c8dcSSimon Schubert 
44355796c8dcSSimon Schubert   /* mips cc uses a rf of -1 for opaque struct definitions.
44365796c8dcSSimon Schubert      Set TYPE_FLAG_STUB for these types so that check_typedef will
44375796c8dcSSimon Schubert      resolve them if the struct gets defined in another compilation unit.  */
44385796c8dcSSimon Schubert   if (rf == -1)
44395796c8dcSSimon Schubert     {
44405796c8dcSSimon Schubert       *pname = "<undefined>";
4441c50c785cSJohn Marino       *tpp = init_type (type_code, 0, TYPE_FLAG_STUB,
4442a45ae5f8SJohn Marino 			(char *) NULL, mdebugread_objfile);
44435796c8dcSSimon Schubert       return result;
44445796c8dcSSimon Schubert     }
44455796c8dcSSimon Schubert 
44465796c8dcSSimon Schubert   /* mips cc uses an escaped rn->index of 0 for struct return types
44475796c8dcSSimon Schubert      of procedures that were compiled without -g.  These will always remain
44485796c8dcSSimon Schubert      undefined.  */
44495796c8dcSSimon Schubert   if (rn->rfd == 0xfff && rn->index == 0)
44505796c8dcSSimon Schubert     {
44515796c8dcSSimon Schubert       *pname = "<undefined>";
44525796c8dcSSimon Schubert       return result;
44535796c8dcSSimon Schubert     }
44545796c8dcSSimon Schubert 
44555796c8dcSSimon Schubert   /* Find the relative file descriptor and the symbol in it.  */
44565796c8dcSSimon Schubert   fh = get_rfd (fd, rf);
44575796c8dcSSimon Schubert   xref_fd = fh - debug_info->fdr;
44585796c8dcSSimon Schubert 
44595796c8dcSSimon Schubert   if (rn->index >= fh->csym)
44605796c8dcSSimon Schubert     {
44615796c8dcSSimon Schubert       /* File indirect entry is corrupt.  */
44625796c8dcSSimon Schubert       *pname = "<illegal>";
44635796c8dcSSimon Schubert       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
44645796c8dcSSimon Schubert       return result;
44655796c8dcSSimon Schubert     }
44665796c8dcSSimon Schubert 
44675796c8dcSSimon Schubert   /* If we have processed this symbol then we left a forwarding
44685796c8dcSSimon Schubert      pointer to the type in the pending list.  If not, we`ll put
44695796c8dcSSimon Schubert      it in a list of pending types, to be processed later when
44705796c8dcSSimon Schubert      the file will be.  In any event, we collect the name for the
44715796c8dcSSimon Schubert      type here.  */
44725796c8dcSSimon Schubert 
44735796c8dcSSimon Schubert   esh = ((char *) debug_info->external_sym
44745796c8dcSSimon Schubert 	 + ((fh->isymBase + rn->index)
44755796c8dcSSimon Schubert 	    * debug_swap->external_sym_size));
44765796c8dcSSimon Schubert   (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
44775796c8dcSSimon Schubert 
44785796c8dcSSimon Schubert   /* Make sure that this type of cross reference can be handled.  */
44795796c8dcSSimon Schubert   if ((sh.sc != scInfo
44805796c8dcSSimon Schubert        || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
44815796c8dcSSimon Schubert 	   && sh.st != stStruct && sh.st != stUnion
44825796c8dcSSimon Schubert 	   && sh.st != stEnum))
44835796c8dcSSimon Schubert       && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
44845796c8dcSSimon Schubert     {
44855796c8dcSSimon Schubert       /* File indirect entry is corrupt.  */
44865796c8dcSSimon Schubert       *pname = "<illegal>";
44875796c8dcSSimon Schubert       bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
44885796c8dcSSimon Schubert       return result;
44895796c8dcSSimon Schubert     }
44905796c8dcSSimon Schubert 
44915796c8dcSSimon Schubert   *pname = debug_info->ss + fh->issBase + sh.iss;
44925796c8dcSSimon Schubert 
44935796c8dcSSimon Schubert   pend = is_pending_symbol (fh, esh);
44945796c8dcSSimon Schubert   if (pend)
44955796c8dcSSimon Schubert     *tpp = pend->t;
44965796c8dcSSimon Schubert   else
44975796c8dcSSimon Schubert     {
44985796c8dcSSimon Schubert       /* We have not yet seen this type.  */
44995796c8dcSSimon Schubert 
45005796c8dcSSimon Schubert       if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
45015796c8dcSSimon Schubert 	{
45025796c8dcSSimon Schubert 	  TIR tir;
45035796c8dcSSimon Schubert 
45045796c8dcSSimon Schubert 	  /* alpha cc puts out a stTypedef with a sh.iss of zero for
45055796c8dcSSimon Schubert 	     two cases:
45065796c8dcSSimon Schubert 	     a) forward declarations of structs/unions/enums which are not
45075796c8dcSSimon Schubert 	     defined in this compilation unit.
45085796c8dcSSimon Schubert 	     For these the type will be void.  This is a bad design decision
45095796c8dcSSimon Schubert 	     as cross referencing across compilation units is impossible
45105796c8dcSSimon Schubert 	     due to the missing name.
45115796c8dcSSimon Schubert 	     b) forward declarations of structs/unions/enums/typedefs which
45125796c8dcSSimon Schubert 	     are defined later in this file or in another file in the same
45135796c8dcSSimon Schubert 	     compilation unit.  Irix5 cc uses a stIndirect symbol for this.
45145796c8dcSSimon Schubert 	     Simply cross reference those again to get the true type.
45155796c8dcSSimon Schubert 	     The forward references are not entered in the pending list and
45165796c8dcSSimon Schubert 	     in the symbol table.  */
45175796c8dcSSimon Schubert 
45185796c8dcSSimon Schubert 	  (*debug_swap->swap_tir_in) (bigend,
45195796c8dcSSimon Schubert 				      &(debug_info->external_aux
45205796c8dcSSimon Schubert 					+ fh->iauxBase + sh.index)->a_ti,
45215796c8dcSSimon Schubert 				      &tir);
45225796c8dcSSimon Schubert 	  if (tir.tq0 != tqNil)
45235796c8dcSSimon Schubert 	    complaint (&symfile_complaints,
45245796c8dcSSimon Schubert 		       _("illegal tq0 in forward typedef for %s"), sym_name);
45255796c8dcSSimon Schubert 	  switch (tir.bt)
45265796c8dcSSimon Schubert 	    {
45275796c8dcSSimon Schubert 	    case btVoid:
45285796c8dcSSimon Schubert 	      *tpp = init_type (type_code, 0, 0, (char *) NULL,
4529a45ae5f8SJohn Marino 				mdebugread_objfile);
45305796c8dcSSimon Schubert 	      *pname = "<undefined>";
45315796c8dcSSimon Schubert 	      break;
45325796c8dcSSimon Schubert 
45335796c8dcSSimon Schubert 	    case btStruct:
45345796c8dcSSimon Schubert 	    case btUnion:
45355796c8dcSSimon Schubert 	    case btEnum:
45365796c8dcSSimon Schubert 	      cross_ref (xref_fd,
45375796c8dcSSimon Schubert 			 (debug_info->external_aux
45385796c8dcSSimon Schubert 			  + fh->iauxBase + sh.index + 1),
45395796c8dcSSimon Schubert 			 tpp, type_code, pname,
45405796c8dcSSimon Schubert 			 fh->fBigendian, sym_name);
45415796c8dcSSimon Schubert 	      break;
45425796c8dcSSimon Schubert 
45435796c8dcSSimon Schubert 	    case btTypedef:
45445796c8dcSSimon Schubert 	      /* Follow a forward typedef.  This might recursively
45455796c8dcSSimon Schubert 	         call cross_ref till we get a non typedef'ed type.
45465796c8dcSSimon Schubert 	         FIXME: This is not correct behaviour, but gdb currently
45475796c8dcSSimon Schubert 	         cannot handle typedefs without type copying.  Type
45485796c8dcSSimon Schubert 	         copying is impossible as we might have mutual forward
45495796c8dcSSimon Schubert 	         references between two files and the copied type would not
45505796c8dcSSimon Schubert 	         get filled in when we later parse its definition.  */
45515796c8dcSSimon Schubert 	      *tpp = parse_type (xref_fd,
45525796c8dcSSimon Schubert 				 debug_info->external_aux + fh->iauxBase,
45535796c8dcSSimon Schubert 				 sh.index,
45545796c8dcSSimon Schubert 				 (int *) NULL,
45555796c8dcSSimon Schubert 				 fh->fBigendian,
45565796c8dcSSimon Schubert 				 debug_info->ss + fh->issBase + sh.iss);
45575796c8dcSSimon Schubert 	      add_pending (fh, esh, *tpp);
45585796c8dcSSimon Schubert 	      break;
45595796c8dcSSimon Schubert 
45605796c8dcSSimon Schubert 	    default:
45615796c8dcSSimon Schubert 	      complaint (&symfile_complaints,
45625796c8dcSSimon Schubert 			 _("illegal bt %d in forward typedef for %s"), tir.bt,
45635796c8dcSSimon Schubert 			 sym_name);
45645796c8dcSSimon Schubert 	      *tpp = init_type (type_code, 0, 0, (char *) NULL,
4565a45ae5f8SJohn Marino 				mdebugread_objfile);
45665796c8dcSSimon Schubert 	      break;
45675796c8dcSSimon Schubert 	    }
45685796c8dcSSimon Schubert 	  return result;
45695796c8dcSSimon Schubert 	}
45705796c8dcSSimon Schubert       else if (sh.st == stTypedef)
45715796c8dcSSimon Schubert 	{
45725796c8dcSSimon Schubert 	  /* Parse the type for a normal typedef.  This might recursively call
45735796c8dcSSimon Schubert 	     cross_ref till we get a non typedef'ed type.
45745796c8dcSSimon Schubert 	     FIXME: This is not correct behaviour, but gdb currently
45755796c8dcSSimon Schubert 	     cannot handle typedefs without type copying.  But type copying is
45765796c8dcSSimon Schubert 	     impossible as we might have mutual forward references between
45775796c8dcSSimon Schubert 	     two files and the copied type would not get filled in when
45785796c8dcSSimon Schubert 	     we later parse its definition.   */
45795796c8dcSSimon Schubert 	  *tpp = parse_type (xref_fd,
45805796c8dcSSimon Schubert 			     debug_info->external_aux + fh->iauxBase,
45815796c8dcSSimon Schubert 			     sh.index,
45825796c8dcSSimon Schubert 			     (int *) NULL,
45835796c8dcSSimon Schubert 			     fh->fBigendian,
45845796c8dcSSimon Schubert 			     debug_info->ss + fh->issBase + sh.iss);
45855796c8dcSSimon Schubert 	}
45865796c8dcSSimon Schubert       else
45875796c8dcSSimon Schubert 	{
45885796c8dcSSimon Schubert 	  /* Cross reference to a struct/union/enum which is defined
45895796c8dcSSimon Schubert 	     in another file in the same compilation unit but that file
45905796c8dcSSimon Schubert 	     has not been parsed yet.
45915796c8dcSSimon Schubert 	     Initialize the type only, it will be filled in when
45925796c8dcSSimon Schubert 	     it's definition is parsed.  */
4593a45ae5f8SJohn Marino 	  *tpp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
45945796c8dcSSimon Schubert 	}
45955796c8dcSSimon Schubert       add_pending (fh, esh, *tpp);
45965796c8dcSSimon Schubert     }
45975796c8dcSSimon Schubert 
45985796c8dcSSimon Schubert   /* We used one auxent normally, two if we got a "next one" rf.  */
45995796c8dcSSimon Schubert   return result;
46005796c8dcSSimon Schubert }
46015796c8dcSSimon Schubert 
46025796c8dcSSimon Schubert 
46035796c8dcSSimon Schubert /* Quick&dirty lookup procedure, to avoid the MI ones that require
4604c50c785cSJohn Marino    keeping the symtab sorted.  */
46055796c8dcSSimon Schubert 
46065796c8dcSSimon Schubert static struct symbol *
mylookup_symbol(char * name,struct block * block,domain_enum domain,enum address_class class)46075796c8dcSSimon Schubert mylookup_symbol (char *name, struct block *block,
46085796c8dcSSimon Schubert 		 domain_enum domain, enum address_class class)
46095796c8dcSSimon Schubert {
4610*ef5ccd6cSJohn Marino   struct block_iterator iter;
46115796c8dcSSimon Schubert   int inc;
46125796c8dcSSimon Schubert   struct symbol *sym;
46135796c8dcSSimon Schubert 
46145796c8dcSSimon Schubert   inc = name[0];
46155796c8dcSSimon Schubert   ALL_BLOCK_SYMBOLS (block, iter, sym)
46165796c8dcSSimon Schubert     {
46175796c8dcSSimon Schubert       if (SYMBOL_LINKAGE_NAME (sym)[0] == inc
46185796c8dcSSimon Schubert 	  && SYMBOL_DOMAIN (sym) == domain
46195796c8dcSSimon Schubert 	  && SYMBOL_CLASS (sym) == class
46205796c8dcSSimon Schubert 	  && strcmp (SYMBOL_LINKAGE_NAME (sym), name) == 0)
46215796c8dcSSimon Schubert 	return sym;
46225796c8dcSSimon Schubert     }
46235796c8dcSSimon Schubert 
46245796c8dcSSimon Schubert   block = BLOCK_SUPERBLOCK (block);
46255796c8dcSSimon Schubert   if (block)
46265796c8dcSSimon Schubert     return mylookup_symbol (name, block, domain, class);
46275796c8dcSSimon Schubert   return 0;
46285796c8dcSSimon Schubert }
46295796c8dcSSimon Schubert 
46305796c8dcSSimon Schubert 
46315796c8dcSSimon Schubert /* Add a new symbol S to a block B.  */
46325796c8dcSSimon Schubert 
46335796c8dcSSimon Schubert static void
add_symbol(struct symbol * s,struct symtab * symtab,struct block * b)46345796c8dcSSimon Schubert add_symbol (struct symbol *s, struct symtab *symtab, struct block *b)
46355796c8dcSSimon Schubert {
46365796c8dcSSimon Schubert   SYMBOL_SYMTAB (s) = symtab;
46375796c8dcSSimon Schubert   dict_add_symbol (BLOCK_DICT (b), s);
46385796c8dcSSimon Schubert }
46395796c8dcSSimon Schubert 
4640c50c785cSJohn Marino /* Add a new block B to a symtab S.  */
46415796c8dcSSimon Schubert 
46425796c8dcSSimon Schubert static void
add_block(struct block * b,struct symtab * s)46435796c8dcSSimon Schubert add_block (struct block *b, struct symtab *s)
46445796c8dcSSimon Schubert {
46455796c8dcSSimon Schubert   struct blockvector *bv = BLOCKVECTOR (s);
46465796c8dcSSimon Schubert 
46475796c8dcSSimon Schubert   bv = (struct blockvector *) xrealloc ((void *) bv,
46485796c8dcSSimon Schubert 					(sizeof (struct blockvector)
46495796c8dcSSimon Schubert 					 + BLOCKVECTOR_NBLOCKS (bv)
46505796c8dcSSimon Schubert 					 * sizeof (bv->block)));
46515796c8dcSSimon Schubert   if (bv != BLOCKVECTOR (s))
46525796c8dcSSimon Schubert     BLOCKVECTOR (s) = bv;
46535796c8dcSSimon Schubert 
46545796c8dcSSimon Schubert   BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
46555796c8dcSSimon Schubert }
46565796c8dcSSimon Schubert 
46575796c8dcSSimon Schubert /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
46585796c8dcSSimon Schubert    MIPS' linenumber encoding might need more than one byte
46595796c8dcSSimon Schubert    to describe it, LAST is used to detect these continuation lines.
46605796c8dcSSimon Schubert 
46615796c8dcSSimon Schubert    Combining lines with the same line number seems like a bad idea.
46625796c8dcSSimon Schubert    E.g: There could be a line number entry with the same line number after the
46635796c8dcSSimon Schubert    prologue and GDB should not ignore it (this is a better way to find
46645796c8dcSSimon Schubert    a prologue than mips_skip_prologue).
46655796c8dcSSimon Schubert    But due to the compressed line table format there are line number entries
46665796c8dcSSimon Schubert    for the same line which are needed to bridge the gap to the next
46675796c8dcSSimon Schubert    line number entry.  These entries have a bogus address info with them
46685796c8dcSSimon Schubert    and we are unable to tell them from intended duplicate line number
46695796c8dcSSimon Schubert    entries.
46705796c8dcSSimon Schubert    This is another reason why -ggdb debugging format is preferable.  */
46715796c8dcSSimon Schubert 
46725796c8dcSSimon Schubert static int
add_line(struct linetable * lt,int lineno,CORE_ADDR adr,int last)46735796c8dcSSimon Schubert add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
46745796c8dcSSimon Schubert {
46755796c8dcSSimon Schubert   /* DEC c89 sometimes produces zero linenos which confuse gdb.
46765796c8dcSSimon Schubert      Change them to something sensible.  */
46775796c8dcSSimon Schubert   if (lineno == 0)
46785796c8dcSSimon Schubert     lineno = 1;
46795796c8dcSSimon Schubert   if (last == 0)
4680c50c785cSJohn Marino     last = -2;			/* Make sure we record first line.  */
46815796c8dcSSimon Schubert 
4682c50c785cSJohn Marino   if (last == lineno)		/* Skip continuation lines.  */
46835796c8dcSSimon Schubert     return lineno;
46845796c8dcSSimon Schubert 
46855796c8dcSSimon Schubert   lt->item[lt->nitems].line = lineno;
46865796c8dcSSimon Schubert   lt->item[lt->nitems++].pc = adr << 2;
46875796c8dcSSimon Schubert   return lineno;
46885796c8dcSSimon Schubert }
46895796c8dcSSimon Schubert 
4690c50c785cSJohn Marino /* Sorting and reordering procedures.  */
46915796c8dcSSimon Schubert 
4692c50c785cSJohn Marino /* Blocks with a smaller low bound should come first.  */
46935796c8dcSSimon Schubert 
46945796c8dcSSimon Schubert static int
compare_blocks(const void * arg1,const void * arg2)46955796c8dcSSimon Schubert compare_blocks (const void *arg1, const void *arg2)
46965796c8dcSSimon Schubert {
46975796c8dcSSimon Schubert   LONGEST addr_diff;
46985796c8dcSSimon Schubert   struct block **b1 = (struct block **) arg1;
46995796c8dcSSimon Schubert   struct block **b2 = (struct block **) arg2;
47005796c8dcSSimon Schubert 
47015796c8dcSSimon Schubert   addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
47025796c8dcSSimon Schubert   if (addr_diff == 0)
47035796c8dcSSimon Schubert     return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
47045796c8dcSSimon Schubert   return addr_diff;
47055796c8dcSSimon Schubert }
47065796c8dcSSimon Schubert 
47075796c8dcSSimon Schubert /* Sort the blocks of a symtab S.
47085796c8dcSSimon Schubert    Reorder the blocks in the blockvector by code-address,
4709c50c785cSJohn Marino    as required by some MI search routines.  */
47105796c8dcSSimon Schubert 
47115796c8dcSSimon Schubert static void
sort_blocks(struct symtab * s)47125796c8dcSSimon Schubert sort_blocks (struct symtab *s)
47135796c8dcSSimon Schubert {
47145796c8dcSSimon Schubert   struct blockvector *bv = BLOCKVECTOR (s);
47155796c8dcSSimon Schubert 
4716*ef5ccd6cSJohn Marino   if (BLOCKVECTOR_NBLOCKS (bv) <= FIRST_LOCAL_BLOCK)
47175796c8dcSSimon Schubert     {
47185796c8dcSSimon Schubert       /* Cosmetic */
47195796c8dcSSimon Schubert       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
47205796c8dcSSimon Schubert 	BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
47215796c8dcSSimon Schubert       if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
47225796c8dcSSimon Schubert 	BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
47235796c8dcSSimon Schubert       return;
47245796c8dcSSimon Schubert     }
47255796c8dcSSimon Schubert   /*
47265796c8dcSSimon Schubert    * This is very unfortunate: normally all functions are compiled in
47275796c8dcSSimon Schubert    * the order they are found, but if the file is compiled -O3 things
47285796c8dcSSimon Schubert    * are very different.  It would be nice to find a reliable test
47295796c8dcSSimon Schubert    * to detect -O3 images in advance.
47305796c8dcSSimon Schubert    */
4731*ef5ccd6cSJohn Marino   if (BLOCKVECTOR_NBLOCKS (bv) > FIRST_LOCAL_BLOCK + 1)
47325796c8dcSSimon Schubert     qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
47335796c8dcSSimon Schubert 	   BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
47345796c8dcSSimon Schubert 	   sizeof (struct block *),
47355796c8dcSSimon Schubert 	   compare_blocks);
47365796c8dcSSimon Schubert 
47375796c8dcSSimon Schubert   {
47385796c8dcSSimon Schubert     CORE_ADDR high = 0;
47395796c8dcSSimon Schubert     int i, j = BLOCKVECTOR_NBLOCKS (bv);
47405796c8dcSSimon Schubert 
47415796c8dcSSimon Schubert     for (i = FIRST_LOCAL_BLOCK; i < j; i++)
47425796c8dcSSimon Schubert       if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
47435796c8dcSSimon Schubert 	high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
47445796c8dcSSimon Schubert     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
47455796c8dcSSimon Schubert   }
47465796c8dcSSimon Schubert 
47475796c8dcSSimon Schubert   BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
47485796c8dcSSimon Schubert     BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
47495796c8dcSSimon Schubert 
47505796c8dcSSimon Schubert   BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
47515796c8dcSSimon Schubert     BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
47525796c8dcSSimon Schubert   BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
47535796c8dcSSimon Schubert     BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
47545796c8dcSSimon Schubert }
47555796c8dcSSimon Schubert 
47565796c8dcSSimon Schubert 
4757c50c785cSJohn Marino /* Constructor/restructor/destructor procedures.  */
47585796c8dcSSimon Schubert 
47595796c8dcSSimon Schubert /* Allocate a new symtab for NAME.  Needs an estimate of how many
4760c50c785cSJohn Marino    linenumbers MAXLINES we'll put in it.  */
47615796c8dcSSimon Schubert 
47625796c8dcSSimon Schubert static struct symtab *
new_symtab(const char * name,int maxlines,struct objfile * objfile)4763c50c785cSJohn Marino new_symtab (const char *name, int maxlines, struct objfile *objfile)
47645796c8dcSSimon Schubert {
47655796c8dcSSimon Schubert   struct symtab *s = allocate_symtab (name, objfile);
47665796c8dcSSimon Schubert 
47675796c8dcSSimon Schubert   LINETABLE (s) = new_linetable (maxlines);
47685796c8dcSSimon Schubert 
4769c50c785cSJohn Marino   /* All symtabs must have at least two blocks.  */
47705796c8dcSSimon Schubert   BLOCKVECTOR (s) = new_bvect (2);
47715796c8dcSSimon Schubert   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK)
47725796c8dcSSimon Schubert     = new_block (NON_FUNCTION_BLOCK);
47735796c8dcSSimon Schubert   BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
47745796c8dcSSimon Schubert     = new_block (NON_FUNCTION_BLOCK);
47755796c8dcSSimon Schubert   BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
47765796c8dcSSimon Schubert     BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
47775796c8dcSSimon Schubert 
4778cf7f2e2dSJohn Marino   s->debugformat = "ECOFF";
47795796c8dcSSimon Schubert   return (s);
47805796c8dcSSimon Schubert }
47815796c8dcSSimon Schubert 
4782c50c785cSJohn Marino /* Allocate a new partial_symtab NAME.  */
47835796c8dcSSimon Schubert 
47845796c8dcSSimon Schubert static struct partial_symtab *
new_psymtab(char * name,struct objfile * objfile)47855796c8dcSSimon Schubert new_psymtab (char *name, struct objfile *objfile)
47865796c8dcSSimon Schubert {
47875796c8dcSSimon Schubert   struct partial_symtab *psymtab;
47885796c8dcSSimon Schubert 
47895796c8dcSSimon Schubert   psymtab = allocate_psymtab (name, objfile);
47905796c8dcSSimon Schubert   psymtab->section_offsets = objfile->section_offsets;
47915796c8dcSSimon Schubert 
4792c50c785cSJohn Marino   /* Keep a backpointer to the file's symbols.  */
47935796c8dcSSimon Schubert 
4794cf7f2e2dSJohn Marino   psymtab->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
4795cf7f2e2dSJohn Marino 						sizeof (struct symloc));
47965796c8dcSSimon Schubert   memset (psymtab->read_symtab_private, 0, sizeof (struct symloc));
47975796c8dcSSimon Schubert   CUR_BFD (psymtab) = cur_bfd;
47985796c8dcSSimon Schubert   DEBUG_SWAP (psymtab) = debug_swap;
47995796c8dcSSimon Schubert   DEBUG_INFO (psymtab) = debug_info;
48005796c8dcSSimon Schubert   PENDING_LIST (psymtab) = pending_list;
48015796c8dcSSimon Schubert 
48025796c8dcSSimon Schubert   /* The way to turn this into a symtab is to call...  */
4803*ef5ccd6cSJohn Marino   psymtab->read_symtab = mdebug_read_symtab;
48045796c8dcSSimon Schubert   return (psymtab);
48055796c8dcSSimon Schubert }
48065796c8dcSSimon Schubert 
48075796c8dcSSimon Schubert 
48085796c8dcSSimon Schubert /* Allocate a linetable array of the given SIZE.  Since the struct
48095796c8dcSSimon Schubert    already includes one item, we subtract one when calculating the
48105796c8dcSSimon Schubert    proper size to allocate.  */
48115796c8dcSSimon Schubert 
48125796c8dcSSimon Schubert static struct linetable *
new_linetable(int size)48135796c8dcSSimon Schubert new_linetable (int size)
48145796c8dcSSimon Schubert {
48155796c8dcSSimon Schubert   struct linetable *l;
48165796c8dcSSimon Schubert 
4817a45ae5f8SJohn Marino   if (size > 1)
4818a45ae5f8SJohn Marino     --size;
4819a45ae5f8SJohn Marino   size = size * sizeof (l->item) + sizeof (struct linetable);
48205796c8dcSSimon Schubert   l = (struct linetable *) xmalloc (size);
48215796c8dcSSimon Schubert   l->nitems = 0;
48225796c8dcSSimon Schubert   return l;
48235796c8dcSSimon Schubert }
48245796c8dcSSimon Schubert 
48255796c8dcSSimon Schubert /* Oops, too big.  Shrink it.  This was important with the 2.4 linetables,
48265796c8dcSSimon Schubert    I am not so sure about the 3.4 ones.
48275796c8dcSSimon Schubert 
48285796c8dcSSimon Schubert    Since the struct linetable already includes one item, we subtract one when
48295796c8dcSSimon Schubert    calculating the proper size to allocate.  */
48305796c8dcSSimon Schubert 
48315796c8dcSSimon Schubert static struct linetable *
shrink_linetable(struct linetable * lt)48325796c8dcSSimon Schubert shrink_linetable (struct linetable *lt)
48335796c8dcSSimon Schubert {
48345796c8dcSSimon Schubert   return (struct linetable *) xrealloc ((void *) lt,
48355796c8dcSSimon Schubert 					(sizeof (struct linetable)
48365796c8dcSSimon Schubert 					 + ((lt->nitems - 1)
48375796c8dcSSimon Schubert 					    * sizeof (lt->item))));
48385796c8dcSSimon Schubert }
48395796c8dcSSimon Schubert 
48405796c8dcSSimon Schubert /* Allocate and zero a new blockvector of NBLOCKS blocks.  */
48415796c8dcSSimon Schubert 
48425796c8dcSSimon Schubert static struct blockvector *
new_bvect(int nblocks)48435796c8dcSSimon Schubert new_bvect (int nblocks)
48445796c8dcSSimon Schubert {
48455796c8dcSSimon Schubert   struct blockvector *bv;
48465796c8dcSSimon Schubert   int size;
48475796c8dcSSimon Schubert 
48485796c8dcSSimon Schubert   size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
48495796c8dcSSimon Schubert   bv = (struct blockvector *) xzalloc (size);
48505796c8dcSSimon Schubert 
48515796c8dcSSimon Schubert   BLOCKVECTOR_NBLOCKS (bv) = nblocks;
48525796c8dcSSimon Schubert 
48535796c8dcSSimon Schubert   return bv;
48545796c8dcSSimon Schubert }
48555796c8dcSSimon Schubert 
48565796c8dcSSimon Schubert /* Allocate and zero a new block, and set its BLOCK_DICT.  If function
48575796c8dcSSimon Schubert    is non-zero, assume the block is associated to a function, and make
48585796c8dcSSimon Schubert    sure that the symbols are stored linearly; otherwise, store them
48595796c8dcSSimon Schubert    hashed.  */
48605796c8dcSSimon Schubert 
48615796c8dcSSimon Schubert static struct block *
new_block(enum block_type type)48625796c8dcSSimon Schubert new_block (enum block_type type)
48635796c8dcSSimon Schubert {
48645796c8dcSSimon Schubert   /* FIXME: carlton/2003-09-11: This should use allocate_block to
48655796c8dcSSimon Schubert      allocate the block.  Which, in turn, suggests that the block
48665796c8dcSSimon Schubert      should be allocated on an obstack.  */
48675796c8dcSSimon Schubert   struct block *retval = xzalloc (sizeof (struct block));
48685796c8dcSSimon Schubert 
48695796c8dcSSimon Schubert   if (type == FUNCTION_BLOCK)
48705796c8dcSSimon Schubert     BLOCK_DICT (retval) = dict_create_linear_expandable ();
48715796c8dcSSimon Schubert   else
48725796c8dcSSimon Schubert     BLOCK_DICT (retval) = dict_create_hashed_expandable ();
48735796c8dcSSimon Schubert 
48745796c8dcSSimon Schubert   return retval;
48755796c8dcSSimon Schubert }
48765796c8dcSSimon Schubert 
4877c50c785cSJohn Marino /* Create a new symbol with printname NAME.  */
48785796c8dcSSimon Schubert 
48795796c8dcSSimon Schubert static struct symbol *
new_symbol(char * name)48805796c8dcSSimon Schubert new_symbol (char *name)
48815796c8dcSSimon Schubert {
48825796c8dcSSimon Schubert   struct symbol *s = ((struct symbol *)
4883a45ae5f8SJohn Marino 		      obstack_alloc (&mdebugread_objfile->objfile_obstack,
48845796c8dcSSimon Schubert 				     sizeof (struct symbol)));
48855796c8dcSSimon Schubert 
48865796c8dcSSimon Schubert   memset (s, 0, sizeof (*s));
4887c50c785cSJohn Marino   SYMBOL_SET_LANGUAGE (s, psymtab_language);
4888a45ae5f8SJohn Marino   SYMBOL_SET_NAMES (s, name, strlen (name), 1, mdebugread_objfile);
48895796c8dcSSimon Schubert   return s;
48905796c8dcSSimon Schubert }
48915796c8dcSSimon Schubert 
4892c50c785cSJohn Marino /* Create a new type with printname NAME.  */
48935796c8dcSSimon Schubert 
48945796c8dcSSimon Schubert static struct type *
new_type(char * name)48955796c8dcSSimon Schubert new_type (char *name)
48965796c8dcSSimon Schubert {
48975796c8dcSSimon Schubert   struct type *t;
48985796c8dcSSimon Schubert 
4899a45ae5f8SJohn Marino   t = alloc_type (mdebugread_objfile);
49005796c8dcSSimon Schubert   TYPE_NAME (t) = name;
4901cf7f2e2dSJohn Marino   INIT_CPLUS_SPECIFIC (t);
49025796c8dcSSimon Schubert   return t;
49035796c8dcSSimon Schubert }
49045796c8dcSSimon Schubert 
49055796c8dcSSimon Schubert /* Read ECOFF debugging information from a BFD section.  This is
49065796c8dcSSimon Schubert    called from elfread.c.  It parses the section into a
49075796c8dcSSimon Schubert    ecoff_debug_info struct, and then lets the rest of the file handle
49085796c8dcSSimon Schubert    it as normal.  */
49095796c8dcSSimon Schubert 
49105796c8dcSSimon Schubert void
elfmdebug_build_psymtabs(struct objfile * objfile,const struct ecoff_debug_swap * swap,asection * sec)49115796c8dcSSimon Schubert elfmdebug_build_psymtabs (struct objfile *objfile,
49125796c8dcSSimon Schubert 			  const struct ecoff_debug_swap *swap, asection *sec)
49135796c8dcSSimon Schubert {
49145796c8dcSSimon Schubert   bfd *abfd = objfile->obfd;
49155796c8dcSSimon Schubert   struct ecoff_debug_info *info;
49165796c8dcSSimon Schubert   struct cleanup *back_to;
49175796c8dcSSimon Schubert 
49185796c8dcSSimon Schubert   /* FIXME: It's not clear whether we should be getting minimal symbol
49195796c8dcSSimon Schubert      information from .mdebug in an ELF file, or whether we will.
49205796c8dcSSimon Schubert      Re-initialize the minimal symbol reader in case we do.  */
49215796c8dcSSimon Schubert 
49225796c8dcSSimon Schubert   init_minimal_symbol_collection ();
49235796c8dcSSimon Schubert   back_to = make_cleanup_discard_minimal_symbols ();
49245796c8dcSSimon Schubert 
49255796c8dcSSimon Schubert   info = ((struct ecoff_debug_info *)
49265796c8dcSSimon Schubert 	  obstack_alloc (&objfile->objfile_obstack,
49275796c8dcSSimon Schubert 			 sizeof (struct ecoff_debug_info)));
49285796c8dcSSimon Schubert 
49295796c8dcSSimon Schubert   if (!(*swap->read_debug_info) (abfd, sec, info))
49305796c8dcSSimon Schubert     error (_("Error reading ECOFF debugging information: %s"),
49315796c8dcSSimon Schubert 	   bfd_errmsg (bfd_get_error ()));
49325796c8dcSSimon Schubert 
49335796c8dcSSimon Schubert   mdebug_build_psymtabs (objfile, swap, info);
49345796c8dcSSimon Schubert 
49355796c8dcSSimon Schubert   install_minimal_symbols (objfile);
49365796c8dcSSimon Schubert   do_cleanups (back_to);
49375796c8dcSSimon Schubert }
49385796c8dcSSimon Schubert 
49395796c8dcSSimon Schubert void
_initialize_mdebugread(void)49405796c8dcSSimon Schubert _initialize_mdebugread (void)
49415796c8dcSSimon Schubert {
49425796c8dcSSimon Schubert   basic_type_data = register_objfile_data ();
49435796c8dcSSimon Schubert }
4944