119370Spst/* Read a symbol table in ECOFF format (Third-Eye). 2130803Smarcel 3130803Smarcel Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 4130803Smarcel 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software 5130803Smarcel Foundation, Inc. 6130803Smarcel 719370Spst Original version contributed by Alessandro Forin (af@cs.cmu.edu) at 819370Spst CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor 919370Spst at Cygnus Support. 1019370Spst 1198944Sobrien This file is part of GDB. 1219370Spst 1398944Sobrien This program is free software; you can redistribute it and/or modify 1498944Sobrien it under the terms of the GNU General Public License as published by 1598944Sobrien the Free Software Foundation; either version 2 of the License, or 1698944Sobrien (at your option) any later version. 1719370Spst 1898944Sobrien This program is distributed in the hope that it will be useful, 1998944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 2098944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2198944Sobrien GNU General Public License for more details. 2219370Spst 2398944Sobrien You should have received a copy of the GNU General Public License 2498944Sobrien along with this program; if not, write to the Free Software 2598944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2698944Sobrien Boston, MA 02111-1307, USA. */ 2719370Spst 2819370Spst/* This module provides the function mdebug_build_psymtabs. It reads 2919370Spst ECOFF debugging information into partial symbol tables. The 3019370Spst debugging information is read from two structures. A struct 3119370Spst ecoff_debug_swap includes the sizes of each ECOFF structure and 3219370Spst swapping routines; these are fixed for a particular target. A 3319370Spst struct ecoff_debug_info points to the debugging information for a 3419370Spst particular object file. 3519370Spst 3619370Spst ECOFF symbol tables are mostly written in the byte order of the 3719370Spst target machine. However, one section of the table (the auxiliary 3819370Spst symbol information) is written in the host byte order. There is a 3919370Spst bit in the other symbol info which describes which host byte order 4019370Spst was used. ECOFF thereby takes the trophy from Intel `b.out' for 4119370Spst the most brain-dead adaptation of a file format to byte order. 4219370Spst 4319370Spst This module can read all four of the known byte-order combinations, 4419370Spst on any type of host. */ 4519370Spst 4619370Spst#include "defs.h" 4719370Spst#include "symtab.h" 4819370Spst#include "gdbtypes.h" 4919370Spst#include "gdbcore.h" 5019370Spst#include "objfiles.h" 51130803Smarcel#include "gdb_obstack.h" 5219370Spst#include "buildsym.h" 5319370Spst#include "stabsread.h" 5419370Spst#include "complaints.h" 5519370Spst#include "demangle.h" 56130803Smarcel#include "gdb_assert.h" 57130803Smarcel#include "block.h" 58130803Smarcel#include "dictionary.h" 5919370Spst 6019370Spst/* These are needed if the tm.h file does not contain the necessary 6119370Spst mips specific definitions. */ 6219370Spst 6319370Spst#ifndef MIPS_EFI_SYMBOL_NAME 6419370Spst#define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__" 6598944Sobrienextern void ecoff_relocate_efi (struct symbol *, CORE_ADDR); 6619370Spst#include "coff/sym.h" 6719370Spst#include "coff/symconst.h" 6898944Sobrientypedef struct mips_extra_func_info 6998944Sobrien { 7098944Sobrien long numargs; 7198944Sobrien PDR pdr; 7298944Sobrien } 7398944Sobrien *mips_extra_func_info_t; 7419370Spst#ifndef RA_REGNUM 7519370Spst#define RA_REGNUM 0 7619370Spst#endif 7719370Spst#endif 7819370Spst 7919370Spst#ifdef USG 8019370Spst#include <sys/types.h> 8119370Spst#endif 8219370Spst 8319370Spst#include "gdb_stat.h" 8419370Spst#include "gdb_string.h" 8519370Spst 8619370Spst#include "bfd.h" 8719370Spst 8819370Spst#include "coff/ecoff.h" /* COFF-like aspects of ecoff files */ 8919370Spst 9019370Spst#include "libaout.h" /* Private BFD a.out information. */ 9119370Spst#include "aout/aout64.h" 9219370Spst#include "aout/stab_gnu.h" /* STABS information */ 9319370Spst 9419370Spst#include "expression.h" 9598944Sobrien#include "language.h" /* For local_hex_string() */ 9619370Spst 9798944Sobrienextern void _initialize_mdebugread (void); 9846283Sdfr 9946283Sdfr/* Provide a way to test if we have both ECOFF and ELF symbol tables. 10046283Sdfr We use this define in order to know whether we should override a 10146283Sdfr symbol's ECOFF section with its ELF section. This is necessary in 10246283Sdfr case the symbol's ELF section could not be represented in ECOFF. */ 10346283Sdfr#define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ 10446283Sdfr && bfd_get_section_by_name (bfd, ".mdebug") != NULL) 10598944Sobrien 10646283Sdfr 10719370Spst/* We put a pointer to this structure in the read_symtab_private field 10819370Spst of the psymtab. */ 10919370Spst 11019370Spststruct symloc 11198944Sobrien { 11298944Sobrien /* Index of the FDR that this psymtab represents. */ 11398944Sobrien int fdr_idx; 11498944Sobrien /* The BFD that the psymtab was created from. */ 11598944Sobrien bfd *cur_bfd; 11698944Sobrien const struct ecoff_debug_swap *debug_swap; 11798944Sobrien struct ecoff_debug_info *debug_info; 11898944Sobrien struct mdebug_pending **pending_list; 11998944Sobrien /* Pointer to external symbols for this file. */ 12098944Sobrien EXTR *extern_tab; 12198944Sobrien /* Size of extern_tab. */ 12298944Sobrien int extern_count; 12398944Sobrien enum language pst_language; 12498944Sobrien }; 12598944Sobrien 12619370Spst#define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private) 12719370Spst#define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx) 12819370Spst#define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd) 12919370Spst#define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap) 13019370Spst#define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info) 13119370Spst#define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list) 13246283Sdfr 13346283Sdfr#define SC_IS_TEXT(sc) ((sc) == scText \ 13446283Sdfr || (sc) == scRConst \ 13546283Sdfr || (sc) == scInit \ 13646283Sdfr || (sc) == scFini) 13746283Sdfr#define SC_IS_DATA(sc) ((sc) == scData \ 13846283Sdfr || (sc) == scSData \ 13946283Sdfr || (sc) == scRData \ 14046283Sdfr || (sc) == scPData \ 14146283Sdfr || (sc) == scXData) 14246283Sdfr#define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon) 14398944Sobrien#define SC_IS_BSS(sc) ((sc) == scBss) 14498944Sobrien#define SC_IS_SBSS(sc) ((sc) == scSBss) 14546283Sdfr#define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined) 14619370Spst 14719370Spst/* Various complaints about symbol reading that don't abort the process */ 148130803Smarcelstatic void 149130803Smarcelindex_complaint (const char *arg1) 150130803Smarcel{ 151130803Smarcel complaint (&symfile_complaints, "bad aux index at symbol %s", arg1); 152130803Smarcel} 15319370Spst 154130803Smarcelstatic void 155130803Smarcelunknown_ext_complaint (const char *arg1) 156130803Smarcel{ 157130803Smarcel complaint (&symfile_complaints, "unknown external symbol %s", arg1); 158130803Smarcel} 15919370Spst 160130803Smarcelstatic void 161130803Smarcelbasic_type_complaint (int arg1, const char *arg2) 162130803Smarcel{ 163130803Smarcel complaint (&symfile_complaints, "cannot map ECOFF basic type 0x%x for %s", 164130803Smarcel arg1, arg2); 165130803Smarcel} 16619370Spst 167130803Smarcelstatic void 168130803Smarcelbad_tag_guess_complaint (const char *arg1) 169130803Smarcel{ 170130803Smarcel complaint (&symfile_complaints, "guessed tag type of %s incorrectly", arg1); 171130803Smarcel} 17219370Spst 173130803Smarcelstatic void 174130803Smarcelbad_rfd_entry_complaint (const char *arg1, int arg2, int arg3) 175130803Smarcel{ 176130803Smarcel complaint (&symfile_complaints, "bad rfd entry for %s: file %d, index %d", 177130803Smarcel arg1, arg2, arg3); 178130803Smarcel} 17919370Spst 180130803Smarcelstatic void 181130803Smarcelunexpected_type_code_complaint (const char *arg1) 182130803Smarcel{ 183130803Smarcel complaint (&symfile_complaints, "unexpected type code for %s", arg1); 184130803Smarcel} 18519370Spst 18619370Spst/* Macros and extra defs */ 18719370Spst 18819370Spst/* Puns: hard to find whether -g was used and how */ 18919370Spst 19019370Spst#define MIN_GLEVEL GLEVEL_0 19119370Spst#define compare_glevel(a,b) \ 19219370Spst (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \ 19319370Spst ((b) == GLEVEL_3) ? -1 : (int)((b) - (a))) 19419370Spst 19519370Spst/* Things that really are local to this module */ 19619370Spst 19719370Spst/* Remember what we deduced to be the source language of this psymtab. */ 19819370Spst 19919370Spststatic enum language psymtab_language = language_unknown; 20019370Spst 20119370Spst/* Current BFD. */ 20219370Spst 20319370Spststatic bfd *cur_bfd; 20419370Spst 20519370Spst/* How to parse debugging information for CUR_BFD. */ 20619370Spst 20719370Spststatic const struct ecoff_debug_swap *debug_swap; 20819370Spst 20919370Spst/* Pointers to debugging information for CUR_BFD. */ 21019370Spst 21119370Spststatic struct ecoff_debug_info *debug_info; 21219370Spst 21319370Spst/* Pointer to current file decriptor record, and its index */ 21419370Spst 21519370Spststatic FDR *cur_fdr; 21619370Spststatic int cur_fd; 21719370Spst 21819370Spst/* Index of current symbol */ 21919370Spst 22019370Spststatic int cur_sdx; 22119370Spst 22219370Spst/* Note how much "debuggable" this image is. We would like 22319370Spst to see at least one FDR with full symbols */ 22419370Spst 22546283Sdfrstatic int max_gdbinfo; 22646283Sdfrstatic int max_glevel; 22719370Spst 22819370Spst/* When examining .o files, report on undefined symbols */ 22919370Spst 23019370Spststatic int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs; 23119370Spst 23219370Spst/* Pseudo symbol to use when putting stabs into the symbol table. */ 23319370Spst 23419370Spststatic char stabs_symbol[] = STABS_SYMBOL; 23519370Spst 23619370Spst/* Types corresponding to mdebug format bt* basic types. */ 23719370Spst 23819370Spststatic struct type *mdebug_type_void; 23919370Spststatic struct type *mdebug_type_char; 24019370Spststatic struct type *mdebug_type_short; 24119370Spststatic struct type *mdebug_type_int_32; 24219370Spst#define mdebug_type_int mdebug_type_int_32 24319370Spststatic struct type *mdebug_type_int_64; 24419370Spststatic struct type *mdebug_type_long_32; 24519370Spststatic struct type *mdebug_type_long_64; 24619370Spststatic struct type *mdebug_type_long_long_64; 24719370Spststatic struct type *mdebug_type_unsigned_char; 24819370Spststatic struct type *mdebug_type_unsigned_short; 24919370Spststatic struct type *mdebug_type_unsigned_int_32; 25019370Spststatic struct type *mdebug_type_unsigned_int_64; 25119370Spststatic struct type *mdebug_type_unsigned_long_32; 25219370Spststatic struct type *mdebug_type_unsigned_long_64; 25319370Spststatic struct type *mdebug_type_unsigned_long_long_64; 25419370Spststatic struct type *mdebug_type_adr_32; 25519370Spststatic struct type *mdebug_type_adr_64; 25619370Spststatic struct type *mdebug_type_float; 25719370Spststatic struct type *mdebug_type_double; 25819370Spststatic struct type *mdebug_type_complex; 25919370Spststatic struct type *mdebug_type_double_complex; 26019370Spststatic struct type *mdebug_type_fixed_dec; 26119370Spststatic struct type *mdebug_type_float_dec; 26219370Spststatic struct type *mdebug_type_string; 26319370Spst 26419370Spst/* Types for symbols from files compiled without debugging info. */ 26519370Spst 26619370Spststatic struct type *nodebug_func_symbol_type; 26719370Spststatic struct type *nodebug_var_symbol_type; 26819370Spst 26919370Spst/* Nonzero if we have seen ecoff debugging info for a file. */ 27019370Spst 27119370Spststatic int found_ecoff_debugging_info; 27219370Spst 27319370Spst/* Forward declarations */ 27419370Spst 27598944Sobrienstatic int upgrade_type (int, struct type **, int, union aux_ext *, 27698944Sobrien int, char *); 27746283Sdfr 27898944Sobrienstatic void parse_partial_symbols (struct objfile *); 27946283Sdfr 28098944Sobrienstatic int has_opaque_xref (FDR *, SYMR *); 28146283Sdfr 28298944Sobrienstatic int cross_ref (int, union aux_ext *, struct type **, enum type_code, 28398944Sobrien char **, int, char *); 28446283Sdfr 28598944Sobrienstatic struct symbol *new_symbol (char *); 28646283Sdfr 28798944Sobrienstatic struct type *new_type (char *); 28846283Sdfr 289130803Smarcelenum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK }; 29019370Spst 291130803Smarcelstatic struct block *new_block (enum block_type); 29219370Spst 293130803Smarcelstatic struct symtab *new_symtab (char *, int, struct objfile *); 294130803Smarcel 29598944Sobrienstatic struct linetable *new_linetable (int); 29619370Spst 29798944Sobrienstatic struct blockvector *new_bvect (int); 29819370Spst 29998944Sobrienstatic struct type *parse_type (int, union aux_ext *, unsigned int, int *, 30098944Sobrien int, char *); 30119370Spst 302130803Smarcelstatic struct symbol *mylookup_symbol (char *, struct block *, domain_enum, 30398944Sobrien enum address_class); 30419370Spst 30598944Sobrienstatic void sort_blocks (struct symtab *); 30619370Spst 30798944Sobrienstatic struct partial_symtab *new_psymtab (char *, struct objfile *); 30819370Spst 30998944Sobrienstatic void psymtab_to_symtab_1 (struct partial_symtab *, char *); 31019370Spst 31198944Sobrienstatic void add_block (struct block *, struct symtab *); 31219370Spst 31398944Sobrienstatic void add_symbol (struct symbol *, struct block *); 31419370Spst 31598944Sobrienstatic int add_line (struct linetable *, int, CORE_ADDR, int); 31619370Spst 31798944Sobrienstatic struct linetable *shrink_linetable (struct linetable *); 31819370Spst 31998944Sobrienstatic void handle_psymbol_enumerators (struct objfile *, FDR *, int, 32098944Sobrien CORE_ADDR); 32119370Spst 32298944Sobrienstatic char *mdebug_next_symbol_text (struct objfile *); 32319370Spst 32419370Spst/* Address bounds for the signal trampoline in inferior, if any */ 32519370Spst 32619370SpstCORE_ADDR sigtramp_address, sigtramp_end; 32719370Spst 32819370Spst/* Allocate zeroed memory */ 32919370Spst 33098944Sobrienstatic void * 33198944Sobrienxzalloc (unsigned int size) 33219370Spst{ 33398944Sobrien void *p = xmalloc (size); 33419370Spst 33519370Spst memset (p, 0, size); 33619370Spst return p; 33719370Spst} 33819370Spst 33919370Spst/* Exported procedure: Builds a symtab from the PST partial one. 34019370Spst Restores the environment in effect when PST was created, delegates 34119370Spst most of the work to an ancillary procedure, and sorts 34219370Spst and reorders the symtab list at the end */ 34319370Spst 34419370Spststatic void 34598944Sobrienmdebug_psymtab_to_symtab (struct partial_symtab *pst) 34619370Spst{ 34719370Spst 34819370Spst if (!pst) 34919370Spst return; 35019370Spst 35119370Spst if (info_verbose) 35219370Spst { 35319370Spst printf_filtered ("Reading in symbols for %s...", pst->filename); 35419370Spst gdb_flush (gdb_stdout); 35519370Spst } 35619370Spst 35719370Spst next_symbol_text_func = mdebug_next_symbol_text; 35819370Spst 35919370Spst psymtab_to_symtab_1 (pst, pst->filename); 36019370Spst 36119370Spst /* Match with global symbols. This only needs to be done once, 36219370Spst after all of the symtabs and dependencies have been read in. */ 36319370Spst scan_file_globals (pst->objfile); 36419370Spst 36519370Spst if (info_verbose) 36619370Spst printf_filtered ("done.\n"); 36719370Spst} 36819370Spst 36919370Spst/* File-level interface functions */ 37019370Spst 37119370Spst/* Find a file descriptor given its index RF relative to a file CF */ 37219370Spst 37319370Spststatic FDR * 37498944Sobrienget_rfd (int cf, int rf) 37519370Spst{ 37619370Spst FDR *fdrs; 377130803Smarcel FDR *f; 37819370Spst RFDT rfd; 37919370Spst 38019370Spst fdrs = debug_info->fdr; 38119370Spst f = fdrs + cf; 38219370Spst /* Object files do not have the RFD table, all refs are absolute */ 38319370Spst if (f->rfdBase == 0) 38419370Spst return fdrs + rf; 38519370Spst (*debug_swap->swap_rfd_in) (cur_bfd, 38698944Sobrien ((char *) debug_info->external_rfd 38798944Sobrien + ((f->rfdBase + rf) 38898944Sobrien * debug_swap->external_rfd_size)), 38998944Sobrien &rfd); 39019370Spst return fdrs + rfd; 39119370Spst} 39219370Spst 39319370Spst/* Return a safer print NAME for a file descriptor */ 39419370Spst 39519370Spststatic char * 39698944Sobrienfdr_name (FDR *f) 39719370Spst{ 39819370Spst if (f->rss == -1) 39919370Spst return "<stripped file>"; 40019370Spst if (f->rss == 0) 40119370Spst return "<NFY>"; 40219370Spst return debug_info->ss + f->issBase + f->rss; 40319370Spst} 40419370Spst 40519370Spst 40619370Spst/* Read in and parse the symtab of the file OBJFILE. Symbols from 40719370Spst different sections are relocated via the SECTION_OFFSETS. */ 40819370Spst 40919370Spstvoid 41098944Sobrienmdebug_build_psymtabs (struct objfile *objfile, 41198944Sobrien const struct ecoff_debug_swap *swap, 41298944Sobrien struct ecoff_debug_info *info) 41319370Spst{ 41419370Spst cur_bfd = objfile->obfd; 41519370Spst debug_swap = swap; 41619370Spst debug_info = info; 41719370Spst 41898944Sobrien stabsread_new_init (); 41998944Sobrien buildsym_new_init (); 42098944Sobrien free_header_files (); 42198944Sobrien init_header_files (); 42298944Sobrien 42319370Spst /* Make sure all the FDR information is swapped in. */ 42419370Spst if (info->fdr == (FDR *) NULL) 42519370Spst { 42619370Spst char *fdr_src; 42719370Spst char *fdr_end; 42819370Spst FDR *fdr_ptr; 42919370Spst 430130803Smarcel info->fdr = (FDR *) obstack_alloc (&objfile->objfile_obstack, 43119370Spst (info->symbolic_header.ifdMax 43219370Spst * sizeof (FDR))); 43319370Spst fdr_src = info->external_fdr; 43419370Spst fdr_end = (fdr_src 43519370Spst + info->symbolic_header.ifdMax * swap->external_fdr_size); 43619370Spst fdr_ptr = info->fdr; 43719370Spst for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++) 43819370Spst (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr); 43919370Spst } 44019370Spst 44198944Sobrien parse_partial_symbols (objfile); 44219370Spst 44319370Spst#if 0 44419370Spst /* Check to make sure file was compiled with -g. If not, warn the 44519370Spst user of this limitation. */ 44619370Spst if (compare_glevel (max_glevel, GLEVEL_2) < 0) 44719370Spst { 44819370Spst if (max_gdbinfo == 0) 44919370Spst printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n", 45098944Sobrien objfile->name); 45119370Spst printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n"); 45219370Spst gdb_flush (gdb_stdout); 45319370Spst } 45419370Spst#endif 45519370Spst} 45619370Spst 45719370Spst/* Local utilities */ 45819370Spst 45919370Spst/* Map of FDR indexes to partial symtabs */ 46019370Spst 46119370Spststruct pst_map 46219370Spst{ 46319370Spst struct partial_symtab *pst; /* the psymtab proper */ 46419370Spst long n_globals; /* exported globals (external symbols) */ 46519370Spst long globals_offset; /* cumulative */ 46619370Spst}; 46719370Spst 46819370Spst 46919370Spst/* Utility stack, used to nest procedures and blocks properly. 47019370Spst It is a doubly linked list, to avoid too many alloc/free. 47119370Spst Since we might need it quite a few times it is NOT deallocated 47219370Spst after use. */ 47319370Spst 47419370Spststatic struct parse_stack 47598944Sobrien { 47698944Sobrien struct parse_stack *next, *prev; 47798944Sobrien struct symtab *cur_st; /* Current symtab. */ 47898944Sobrien struct block *cur_block; /* Block in it. */ 47919370Spst 48098944Sobrien /* What are we parsing. stFile, or stBlock are for files and 48198944Sobrien blocks. stProc or stStaticProc means we have seen the start of a 48298944Sobrien procedure, but not the start of the block within in. When we see 48398944Sobrien the start of that block, we change it to stNil, without pushing a 48498944Sobrien new block, i.e. stNil means both a procedure and a block. */ 48519370Spst 48698944Sobrien int blocktype; 48719370Spst 48898944Sobrien struct type *cur_type; /* Type we parse fields for. */ 48998944Sobrien int cur_field; /* Field number in cur_type. */ 49098944Sobrien CORE_ADDR procadr; /* Start addres of this procedure */ 49198944Sobrien int numargs; /* Its argument count */ 49298944Sobrien } 49319370Spst 49419370Spst *top_stack; /* Top stack ptr */ 49519370Spst 49619370Spst 49719370Spst/* Enter a new lexical context */ 49819370Spst 49919370Spststatic void 50098944Sobrienpush_parse_stack (void) 50119370Spst{ 50219370Spst struct parse_stack *new; 50319370Spst 50419370Spst /* Reuse frames if possible */ 50519370Spst if (top_stack && top_stack->prev) 50619370Spst new = top_stack->prev; 50719370Spst else 50819370Spst new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack)); 50919370Spst /* Initialize new frame with previous content */ 51019370Spst if (top_stack) 51119370Spst { 512130803Smarcel struct parse_stack *prev = new->prev; 51319370Spst 51419370Spst *new = *top_stack; 51519370Spst top_stack->prev = new; 51619370Spst new->prev = prev; 51719370Spst new->next = top_stack; 51819370Spst } 51919370Spst top_stack = new; 52019370Spst} 52119370Spst 52219370Spst/* Exit a lexical context */ 52319370Spst 52419370Spststatic void 52598944Sobrienpop_parse_stack (void) 52619370Spst{ 52719370Spst if (!top_stack) 52819370Spst return; 52919370Spst if (top_stack->next) 53019370Spst top_stack = top_stack->next; 53119370Spst} 53219370Spst 53319370Spst 53419370Spst/* Cross-references might be to things we haven't looked at 53519370Spst yet, e.g. type references. To avoid too many type 53619370Spst duplications we keep a quick fixup table, an array 53719370Spst of lists of references indexed by file descriptor */ 53819370Spst 53919370Spststruct mdebug_pending 54019370Spst{ 54119370Spst struct mdebug_pending *next; /* link */ 54219370Spst char *s; /* the unswapped symbol */ 54319370Spst struct type *t; /* its partial type descriptor */ 54419370Spst}; 54519370Spst 54619370Spst 54719370Spst/* The pending information is kept for an entire object file, and used 54819370Spst to be in the sym_private field. I took it out when I split 54919370Spst mdebugread from mipsread, because this might not be the only type 55019370Spst of symbols read from an object file. Instead, we allocate the 55119370Spst pending information table when we create the partial symbols, and 55219370Spst we store a pointer to the single table in each psymtab. */ 55319370Spst 55419370Spststatic struct mdebug_pending **pending_list; 55519370Spst 55619370Spst/* Check whether we already saw symbol SH in file FH */ 55719370Spst 55819370Spststatic struct mdebug_pending * 55998944Sobrienis_pending_symbol (FDR *fh, char *sh) 56019370Spst{ 56119370Spst int f_idx = fh - debug_info->fdr; 562130803Smarcel struct mdebug_pending *p; 56319370Spst 56419370Spst /* Linear search is ok, list is typically no more than 10 deep */ 56519370Spst for (p = pending_list[f_idx]; p; p = p->next) 56619370Spst if (p->s == sh) 56719370Spst break; 56819370Spst return p; 56919370Spst} 57019370Spst 57119370Spst/* Add a new symbol SH of type T */ 57219370Spst 57319370Spststatic void 57498944Sobrienadd_pending (FDR *fh, char *sh, struct type *t) 57519370Spst{ 57619370Spst int f_idx = fh - debug_info->fdr; 57719370Spst struct mdebug_pending *p = is_pending_symbol (fh, sh); 57819370Spst 57919370Spst /* Make sure we do not make duplicates */ 58019370Spst if (!p) 58119370Spst { 58219370Spst p = ((struct mdebug_pending *) 583130803Smarcel obstack_alloc (¤t_objfile->objfile_obstack, 58419370Spst sizeof (struct mdebug_pending))); 58519370Spst p->s = sh; 58619370Spst p->t = t; 58719370Spst p->next = pending_list[f_idx]; 58819370Spst pending_list[f_idx] = p; 58919370Spst } 59019370Spst} 59119370Spst 59219370Spst 59319370Spst/* Parsing Routines proper. */ 59419370Spst 59519370Spst/* Parse a single symbol. Mostly just make up a GDB symbol for it. 59619370Spst For blocks, procedures and types we open a new lexical context. 59719370Spst This is basically just a big switch on the symbol's type. Argument 59819370Spst AX is the base pointer of aux symbols for this file (fh->iauxBase). 59919370Spst EXT_SH points to the unswapped symbol, which is needed for struct, 60019370Spst union, etc., types; it is NULL for an EXTR. BIGEND says whether 60119370Spst aux symbols are big-endian or little-endian. Return count of 60219370Spst SYMR's handled (normally one). */ 60319370Spst 60419370Spststatic int 60598944Sobrienparse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, 60698944Sobrien struct section_offsets *section_offsets, struct objfile *objfile) 60719370Spst{ 60819370Spst const bfd_size_type external_sym_size = debug_swap->external_sym_size; 60998944Sobrien void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in; 61019370Spst char *name; 61119370Spst struct symbol *s; 61219370Spst struct block *b; 61319370Spst struct mdebug_pending *pend; 61419370Spst struct type *t; 61519370Spst struct field *f; 61619370Spst int count = 1; 61719370Spst enum address_class class; 61819370Spst TIR tir; 61919370Spst long svalue = sh->value; 62019370Spst int bitsize; 62119370Spst 62219370Spst if (ext_sh == (char *) NULL) 62319370Spst name = debug_info->ssext + sh->iss; 62419370Spst else 62519370Spst name = debug_info->ss + cur_fdr->issBase + sh->iss; 62619370Spst 62719370Spst switch (sh->sc) 62819370Spst { 62919370Spst case scText: 63046283Sdfr case scRConst: 63119370Spst /* Do not relocate relative values. 63298944Sobrien The value of a stEnd symbol is the displacement from the 63398944Sobrien corresponding start symbol value. 63498944Sobrien The value of a stBlock symbol is the displacement from the 63598944Sobrien procedure address. */ 63619370Spst if (sh->st != stEnd && sh->st != stBlock) 63798944Sobrien sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 63819370Spst break; 63919370Spst case scData: 64019370Spst case scSData: 64119370Spst case scRData: 64219370Spst case scPData: 64319370Spst case scXData: 64498944Sobrien sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); 64519370Spst break; 64619370Spst case scBss: 64719370Spst case scSBss: 64898944Sobrien sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile)); 64919370Spst break; 65019370Spst } 65119370Spst 65219370Spst switch (sh->st) 65319370Spst { 65419370Spst case stNil: 65519370Spst break; 65619370Spst 65719370Spst case stGlobal: /* external symbol, goes into global block */ 65819370Spst class = LOC_STATIC; 65919370Spst b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st), 66019370Spst GLOBAL_BLOCK); 66119370Spst s = new_symbol (name); 66219370Spst SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; 66319370Spst goto data; 66419370Spst 66519370Spst case stStatic: /* static data, goes into current block. */ 66619370Spst class = LOC_STATIC; 66719370Spst b = top_stack->cur_block; 66819370Spst s = new_symbol (name); 66998944Sobrien if (SC_IS_COMMON (sh->sc)) 67019370Spst { 67119370Spst /* It is a FORTRAN common block. At least for SGI Fortran the 67219370Spst address is not in the symbol; we need to fix it later in 67319370Spst scan_file_globals. */ 674130803Smarcel int bucket = hashname (DEPRECATED_SYMBOL_NAME (s)); 67519370Spst SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket]; 67619370Spst global_sym_chain[bucket] = s; 67719370Spst } 67819370Spst else 67919370Spst SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; 68019370Spst goto data; 68119370Spst 68219370Spst case stLocal: /* local variable, goes into current block */ 68319370Spst if (sh->sc == scRegister) 68419370Spst { 68519370Spst class = LOC_REGISTER; 68619370Spst svalue = ECOFF_REG_TO_REGNUM (svalue); 68719370Spst } 68819370Spst else 68919370Spst class = LOC_LOCAL; 69019370Spst b = top_stack->cur_block; 69119370Spst s = new_symbol (name); 69219370Spst SYMBOL_VALUE (s) = svalue; 69319370Spst 69419370Spst data: /* Common code for symbols describing data */ 695130803Smarcel SYMBOL_DOMAIN (s) = VAR_DOMAIN; 69619370Spst SYMBOL_CLASS (s) = class; 69719370Spst add_symbol (s, b); 69819370Spst 69919370Spst /* Type could be missing if file is compiled without debugging info. */ 70098944Sobrien if (SC_IS_UNDEF (sh->sc) 70146283Sdfr || sh->sc == scNil || sh->index == indexNil) 70219370Spst SYMBOL_TYPE (s) = nodebug_var_symbol_type; 70319370Spst else 70419370Spst SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name); 70519370Spst /* Value of a data symbol is its memory address */ 70619370Spst break; 70719370Spst 70819370Spst case stParam: /* arg to procedure, goes into current block */ 70919370Spst max_gdbinfo++; 71019370Spst found_ecoff_debugging_info = 1; 71119370Spst top_stack->numargs++; 71219370Spst 71319370Spst /* Special GNU C++ name. */ 71419370Spst if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0) 71519370Spst name = "this"; /* FIXME, not alloc'd in obstack */ 71619370Spst s = new_symbol (name); 71719370Spst 718130803Smarcel SYMBOL_DOMAIN (s) = VAR_DOMAIN; 71919370Spst switch (sh->sc) 72019370Spst { 72119370Spst case scRegister: 72219370Spst /* Pass by value in register. */ 72398944Sobrien SYMBOL_CLASS (s) = LOC_REGPARM; 72419370Spst svalue = ECOFF_REG_TO_REGNUM (svalue); 72519370Spst break; 72619370Spst case scVar: 72719370Spst /* Pass by reference on stack. */ 72898944Sobrien SYMBOL_CLASS (s) = LOC_REF_ARG; 72919370Spst break; 73019370Spst case scVarRegister: 73119370Spst /* Pass by reference in register. */ 73298944Sobrien SYMBOL_CLASS (s) = LOC_REGPARM_ADDR; 73319370Spst svalue = ECOFF_REG_TO_REGNUM (svalue); 73419370Spst break; 73519370Spst default: 73619370Spst /* Pass by value on stack. */ 73798944Sobrien SYMBOL_CLASS (s) = LOC_ARG; 73819370Spst break; 73919370Spst } 74019370Spst SYMBOL_VALUE (s) = svalue; 74119370Spst SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name); 74219370Spst add_symbol (s, top_stack->cur_block); 74319370Spst break; 74419370Spst 74519370Spst case stLabel: /* label, goes into current block */ 74619370Spst s = new_symbol (name); 747130803Smarcel SYMBOL_DOMAIN (s) = VAR_DOMAIN; /* so that it can be used */ 74819370Spst SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */ 74919370Spst SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; 75019370Spst SYMBOL_TYPE (s) = mdebug_type_int; 75119370Spst add_symbol (s, top_stack->cur_block); 75219370Spst break; 75319370Spst 75419370Spst case stProc: /* Procedure, usually goes into global block */ 75519370Spst case stStaticProc: /* Static procedure, goes into current block */ 756130803Smarcel /* For stProc symbol records, we need to check the storage class 757130803Smarcel as well, as only (stProc, scText) entries represent "real" 758130803Smarcel procedures - See the Compaq document titled "Object File / 759130803Smarcel Symbol Table Format Specification" for more information. 760130803Smarcel If the storage class is not scText, we discard the whole block 761130803Smarcel of symbol records for this stProc. */ 762130803Smarcel if (sh->st == stProc && sh->sc != scText) 763130803Smarcel { 764130803Smarcel char *ext_tsym = ext_sh; 765130803Smarcel int keep_counting = 1; 766130803Smarcel SYMR tsym; 767130803Smarcel 768130803Smarcel while (keep_counting) 769130803Smarcel { 770130803Smarcel ext_tsym += external_sym_size; 771130803Smarcel (*swap_sym_in) (cur_bfd, ext_tsym, &tsym); 772130803Smarcel count++; 773130803Smarcel switch (tsym.st) 774130803Smarcel { 775130803Smarcel case stParam: 776130803Smarcel break; 777130803Smarcel case stEnd: 778130803Smarcel keep_counting = 0; 779130803Smarcel break; 780130803Smarcel default: 781130803Smarcel complaint (&symfile_complaints, 782130803Smarcel "unknown symbol type 0x%x", sh->st); 783130803Smarcel break; 784130803Smarcel } 785130803Smarcel } 786130803Smarcel break; 787130803Smarcel } 78819370Spst s = new_symbol (name); 789130803Smarcel SYMBOL_DOMAIN (s) = VAR_DOMAIN; 79019370Spst SYMBOL_CLASS (s) = LOC_BLOCK; 79119370Spst /* Type of the return value */ 79298944Sobrien if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil) 79319370Spst t = mdebug_type_int; 79419370Spst else 79546283Sdfr { 79646283Sdfr t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name); 797130803Smarcel if (strcmp (name, "malloc") == 0 798130803Smarcel && TYPE_CODE (t) == TYPE_CODE_VOID) 79946283Sdfr { 80046283Sdfr /* I don't know why, but, at least under Alpha GNU/Linux, 80198944Sobrien when linking against a malloc without debugging 80298944Sobrien symbols, its read as a function returning void---this 80398944Sobrien is bad because it means we cannot call functions with 80498944Sobrien string arguments interactively; i.e., "call 80598944Sobrien printf("howdy\n")" would fail with the error message 80698944Sobrien "program has no memory available". To avoid this, we 80798944Sobrien patch up the type and make it void* 80898944Sobrien instead. (davidm@azstarnet.com) 80998944Sobrien */ 81046283Sdfr t = make_pointer_type (t, NULL); 81146283Sdfr } 81246283Sdfr } 81319370Spst b = top_stack->cur_block; 81419370Spst if (sh->st == stProc) 81519370Spst { 81619370Spst struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st); 81719370Spst /* The next test should normally be true, but provides a 81819370Spst hook for nested functions (which we don't want to make 81919370Spst global). */ 82019370Spst if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) 82119370Spst b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); 82219370Spst /* Irix 5 sometimes has duplicate names for the same 82319370Spst function. We want to add such names up at the global 82419370Spst level, not as a nested function. */ 82519370Spst else if (sh->value == top_stack->procadr) 82619370Spst b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); 82719370Spst } 82819370Spst add_symbol (s, b); 82919370Spst 83019370Spst /* Make a type for the procedure itself */ 83119370Spst SYMBOL_TYPE (s) = lookup_function_type (t); 83219370Spst 833130803Smarcel /* All functions in C++ have prototypes. For C we don't have enough 834130803Smarcel information in the debug info. */ 835130803Smarcel if (SYMBOL_LANGUAGE (s) == language_cplus) 836130803Smarcel TYPE_FLAGS (SYMBOL_TYPE (s)) |= TYPE_FLAG_PROTOTYPED; 837130803Smarcel 83819370Spst /* Create and enter a new lexical context */ 839130803Smarcel b = new_block (FUNCTION_BLOCK); 84019370Spst SYMBOL_BLOCK_VALUE (s) = b; 84119370Spst BLOCK_FUNCTION (b) = s; 84219370Spst BLOCK_START (b) = BLOCK_END (b) = sh->value; 84319370Spst BLOCK_SUPERBLOCK (b) = top_stack->cur_block; 84419370Spst add_block (b, top_stack->cur_st); 84519370Spst 84619370Spst /* Not if we only have partial info */ 84798944Sobrien if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil) 84819370Spst break; 84919370Spst 85019370Spst push_parse_stack (); 85119370Spst top_stack->cur_block = b; 85219370Spst top_stack->blocktype = sh->st; 85319370Spst top_stack->cur_type = SYMBOL_TYPE (s); 85419370Spst top_stack->cur_field = -1; 85519370Spst top_stack->procadr = sh->value; 85619370Spst top_stack->numargs = 0; 85719370Spst break; 85819370Spst 85919370Spst /* Beginning of code for structure, union, and enum definitions. 86098944Sobrien They all share a common set of local variables, defined here. */ 86119370Spst { 86219370Spst enum type_code type_code; 86319370Spst char *ext_tsym; 86419370Spst int nfields; 86519370Spst long max_value; 86619370Spst struct field *f; 86719370Spst 86819370Spst case stStruct: /* Start a block defining a struct type */ 86919370Spst type_code = TYPE_CODE_STRUCT; 87019370Spst goto structured_common; 87119370Spst 87219370Spst case stUnion: /* Start a block defining a union type */ 87319370Spst type_code = TYPE_CODE_UNION; 87419370Spst goto structured_common; 87519370Spst 87619370Spst case stEnum: /* Start a block defining an enum type */ 87719370Spst type_code = TYPE_CODE_ENUM; 87819370Spst goto structured_common; 87919370Spst 88019370Spst case stBlock: /* Either a lexical block, or some type */ 88198944Sobrien if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc)) 88219370Spst goto case_stBlock_code; /* Lexical block */ 88319370Spst 88419370Spst type_code = TYPE_CODE_UNDEF; /* We have a type. */ 88519370Spst 88619370Spst /* Common code for handling struct, union, enum, and/or as-yet- 88719370Spst unknown-type blocks of info about structured data. `type_code' 88819370Spst has been set to the proper TYPE_CODE, if we know it. */ 88919370Spst structured_common: 89019370Spst found_ecoff_debugging_info = 1; 89119370Spst push_parse_stack (); 89219370Spst top_stack->blocktype = stBlock; 89319370Spst 89419370Spst /* First count the number of fields and the highest value. */ 89519370Spst nfields = 0; 89619370Spst max_value = 0; 89719370Spst for (ext_tsym = ext_sh + external_sym_size; 89819370Spst ; 89919370Spst ext_tsym += external_sym_size) 90019370Spst { 90119370Spst SYMR tsym; 90219370Spst 90319370Spst (*swap_sym_in) (cur_bfd, ext_tsym, &tsym); 90419370Spst 90519370Spst switch (tsym.st) 90619370Spst { 90719370Spst case stEnd: 908130803Smarcel /* C++ encodes class types as structures where there the 909130803Smarcel methods are encoded as stProc. The scope of stProc 910130803Smarcel symbols also ends with stEnd, thus creating a risk of 911130803Smarcel taking the wrong stEnd symbol record as the end of 912130803Smarcel the current struct, which would cause GDB to undercount 913130803Smarcel the real number of fields in this struct. To make sure 914130803Smarcel we really reached the right stEnd symbol record, we 915130803Smarcel check the associated name, and match it against the 916130803Smarcel struct name. Since method names are mangled while 917130803Smarcel the class name is not, there is no risk of having a 918130803Smarcel method whose name is identical to the class name 919130803Smarcel (in particular constructor method names are different 920130803Smarcel from the class name). There is therefore no risk that 921130803Smarcel this check stops the count on the StEnd of a method. 922130803Smarcel 923130803Smarcel Also, assume that we're really at the end when tsym.iss 924130803Smarcel is 0 (issNull). */ 925130803Smarcel if (tsym.iss == issNull 926130803Smarcel || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss, 927130803Smarcel name) == 0) 928130803Smarcel goto end_of_fields; 929130803Smarcel break; 93019370Spst 93119370Spst case stMember: 93219370Spst if (nfields == 0 && type_code == TYPE_CODE_UNDEF) 93398944Sobrien { 93498944Sobrien /* If the type of the member is Nil (or Void), 93598944Sobrien without qualifiers, assume the tag is an 93698944Sobrien enumeration. 93798944Sobrien Alpha cc -migrate enums are recognized by a zero 93898944Sobrien index and a zero symbol value. 93998944Sobrien DU 4.0 cc enums are recognized by a member type of 94098944Sobrien btEnum without qualifiers and a zero symbol value. */ 94198944Sobrien if (tsym.index == indexNil 94298944Sobrien || (tsym.index == 0 && sh->value == 0)) 94398944Sobrien type_code = TYPE_CODE_ENUM; 94498944Sobrien else 94598944Sobrien { 94698944Sobrien (*debug_swap->swap_tir_in) (bigend, 94798944Sobrien &ax[tsym.index].a_ti, 94898944Sobrien &tir); 94998944Sobrien if ((tir.bt == btNil || tir.bt == btVoid 95098944Sobrien || (tir.bt == btEnum && sh->value == 0)) 95198944Sobrien && tir.tq0 == tqNil) 95298944Sobrien type_code = TYPE_CODE_ENUM; 95398944Sobrien } 95498944Sobrien } 95519370Spst nfields++; 95619370Spst if (tsym.value > max_value) 95719370Spst max_value = tsym.value; 95819370Spst break; 95919370Spst 96019370Spst case stBlock: 96119370Spst case stUnion: 96219370Spst case stEnum: 96319370Spst case stStruct: 96419370Spst { 96519370Spst#if 0 96619370Spst /* This is a no-op; is it trying to tell us something 96719370Spst we should be checking? */ 96898944Sobrien if (tsym.sc == scVariant); /*UNIMPLEMENTED */ 96919370Spst#endif 97019370Spst if (tsym.index != 0) 97119370Spst { 97219370Spst /* This is something like a struct within a 97398944Sobrien struct. Skip over the fields of the inner 97498944Sobrien struct. The -1 is because the for loop will 97598944Sobrien increment ext_tsym. */ 97619370Spst ext_tsym = ((char *) debug_info->external_sym 97719370Spst + ((cur_fdr->isymBase + tsym.index - 1) 97819370Spst * external_sym_size)); 97919370Spst } 98019370Spst } 98119370Spst break; 98219370Spst 98319370Spst case stTypedef: 98419370Spst /* mips cc puts out a typedef for struct x if it is not yet 98519370Spst defined when it encounters 98619370Spst struct y { struct x *xp; }; 98719370Spst Just ignore it. */ 98819370Spst break; 98919370Spst 99019370Spst case stIndirect: 99119370Spst /* Irix5 cc puts out a stIndirect for struct x if it is not 99219370Spst yet defined when it encounters 99319370Spst struct y { struct x *xp; }; 99419370Spst Just ignore it. */ 99519370Spst break; 99619370Spst 99719370Spst default: 998130803Smarcel complaint (&symfile_complaints, 999130803Smarcel "declaration block contains unhandled symbol type %d", 1000130803Smarcel tsym.st); 100119370Spst } 100219370Spst } 100319370Spst end_of_fields:; 100419370Spst 100519370Spst /* In an stBlock, there is no way to distinguish structs, 100619370Spst unions, and enums at this point. This is a bug in the 100719370Spst original design (that has been fixed with the recent 100819370Spst addition of the stStruct, stUnion, and stEnum symbol 100919370Spst types.) The way you can tell is if/when you see a variable 101019370Spst or field of that type. In that case the variable's type 101119370Spst (in the AUX table) says if the type is struct, union, or 101219370Spst enum, and points back to the stBlock here. So you can 101319370Spst patch the tag kind up later - but only if there actually is 101419370Spst a variable or field of that type. 101519370Spst 101619370Spst So until we know for sure, we will guess at this point. 101719370Spst The heuristic is: 101819370Spst If the first member has index==indexNil or a void type, 101919370Spst assume we have an enumeration. 102019370Spst Otherwise, if there is more than one member, and all 102119370Spst the members have offset 0, assume we have a union. 102219370Spst Otherwise, assume we have a struct. 102319370Spst 102419370Spst The heuristic could guess wrong in the case of of an 102519370Spst enumeration with no members or a union with one (or zero) 102619370Spst members, or when all except the last field of a struct have 102719370Spst width zero. These are uncommon and/or illegal situations, 102819370Spst and in any case guessing wrong probably doesn't matter 102919370Spst much. 103019370Spst 103119370Spst But if we later do find out we were wrong, we fixup the tag 103219370Spst kind. Members of an enumeration must be handled 103319370Spst differently from struct/union fields, and that is harder to 103419370Spst patch up, but luckily we shouldn't need to. (If there are 103519370Spst any enumeration members, we can tell for sure it's an enum 103619370Spst here.) */ 103719370Spst 103819370Spst if (type_code == TYPE_CODE_UNDEF) 103998944Sobrien { 104098944Sobrien if (nfields > 1 && max_value == 0) 104198944Sobrien type_code = TYPE_CODE_UNION; 104298944Sobrien else 104398944Sobrien type_code = TYPE_CODE_STRUCT; 104498944Sobrien } 104519370Spst 104619370Spst /* Create a new type or use the pending type. */ 104719370Spst pend = is_pending_symbol (cur_fdr, ext_sh); 104819370Spst if (pend == (struct mdebug_pending *) NULL) 104919370Spst { 105019370Spst t = new_type (NULL); 105119370Spst add_pending (cur_fdr, ext_sh, t); 105219370Spst } 105319370Spst else 105419370Spst t = pend->t; 105519370Spst 105619370Spst /* Do not set the tag name if it is a compiler generated tag name 105719370Spst (.Fxx or .xxfake or empty) for unnamed struct/union/enums. 105819370Spst Alpha cc puts out an sh->iss of zero for those. */ 105919370Spst if (sh->iss == 0 || name[0] == '.' || name[0] == '\0') 106019370Spst TYPE_TAG_NAME (t) = NULL; 106119370Spst else 1062130803Smarcel TYPE_TAG_NAME (t) = obconcat (¤t_objfile->objfile_obstack, 106319370Spst "", "", name); 106419370Spst 106519370Spst TYPE_CODE (t) = type_code; 106619370Spst TYPE_LENGTH (t) = sh->value; 106719370Spst TYPE_NFIELDS (t) = nfields; 106819370Spst TYPE_FIELDS (t) = f = ((struct field *) 106919370Spst TYPE_ALLOC (t, 107019370Spst nfields * sizeof (struct field))); 107119370Spst 107219370Spst if (type_code == TYPE_CODE_ENUM) 107319370Spst { 107419370Spst int unsigned_enum = 1; 107519370Spst 107619370Spst /* This is a non-empty enum. */ 107719370Spst 107819370Spst /* DEC c89 has the number of enumerators in the sh.value field, 107919370Spst not the type length, so we have to compensate for that 108019370Spst incompatibility quirk. 108119370Spst This might do the wrong thing for an enum with one or two 108219370Spst enumerators and gcc -gcoff -fshort-enums, but these cases 108319370Spst are hopefully rare enough. 108419370Spst Alpha cc -migrate has a sh.value field of zero, we adjust 108519370Spst that too. */ 108619370Spst if (TYPE_LENGTH (t) == TYPE_NFIELDS (t) 108719370Spst || TYPE_LENGTH (t) == 0) 108819370Spst TYPE_LENGTH (t) = TARGET_INT_BIT / HOST_CHAR_BIT; 108919370Spst for (ext_tsym = ext_sh + external_sym_size; 109019370Spst ; 109119370Spst ext_tsym += external_sym_size) 109219370Spst { 109319370Spst SYMR tsym; 109419370Spst struct symbol *enum_sym; 109519370Spst 109619370Spst (*swap_sym_in) (cur_bfd, ext_tsym, &tsym); 109719370Spst 109819370Spst if (tsym.st != stMember) 109919370Spst break; 110019370Spst 110146283Sdfr FIELD_BITPOS (*f) = tsym.value; 110246283Sdfr FIELD_TYPE (*f) = t; 110346283Sdfr FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss; 110446283Sdfr FIELD_BITSIZE (*f) = 0; 1105130803Smarcel FIELD_STATIC_KIND (*f) = 0; 110619370Spst 110719370Spst enum_sym = ((struct symbol *) 1108130803Smarcel obstack_alloc (¤t_objfile->objfile_obstack, 110919370Spst sizeof (struct symbol))); 111098944Sobrien memset (enum_sym, 0, sizeof (struct symbol)); 1111130803Smarcel DEPRECATED_SYMBOL_NAME (enum_sym) = 111246283Sdfr obsavestring (f->name, strlen (f->name), 1113130803Smarcel ¤t_objfile->objfile_obstack); 111419370Spst SYMBOL_CLASS (enum_sym) = LOC_CONST; 111519370Spst SYMBOL_TYPE (enum_sym) = t; 1116130803Smarcel SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN; 111719370Spst SYMBOL_VALUE (enum_sym) = tsym.value; 111819370Spst if (SYMBOL_VALUE (enum_sym) < 0) 111919370Spst unsigned_enum = 0; 112019370Spst add_symbol (enum_sym, top_stack->cur_block); 112119370Spst 112219370Spst /* Skip the stMembers that we've handled. */ 112319370Spst count++; 112419370Spst f++; 112519370Spst } 112619370Spst if (unsigned_enum) 112719370Spst TYPE_FLAGS (t) |= TYPE_FLAG_UNSIGNED; 112819370Spst } 112919370Spst /* make this the current type */ 113019370Spst top_stack->cur_type = t; 113119370Spst top_stack->cur_field = 0; 113219370Spst 113319370Spst /* Do not create a symbol for alpha cc unnamed structs. */ 113419370Spst if (sh->iss == 0) 113519370Spst break; 113619370Spst 113719370Spst /* gcc puts out an empty struct for an opaque struct definitions, 113819370Spst do not create a symbol for it either. */ 113919370Spst if (TYPE_NFIELDS (t) == 0) 114019370Spst { 114119370Spst TYPE_FLAGS (t) |= TYPE_FLAG_STUB; 114219370Spst break; 114319370Spst } 114419370Spst 114519370Spst s = new_symbol (name); 1146130803Smarcel SYMBOL_DOMAIN (s) = STRUCT_DOMAIN; 114719370Spst SYMBOL_CLASS (s) = LOC_TYPEDEF; 114819370Spst SYMBOL_VALUE (s) = 0; 114919370Spst SYMBOL_TYPE (s) = t; 115019370Spst add_symbol (s, top_stack->cur_block); 115119370Spst break; 115219370Spst 115319370Spst /* End of local variables shared by struct, union, enum, and 115419370Spst block (as yet unknown struct/union/enum) processing. */ 115519370Spst } 115619370Spst 115719370Spst case_stBlock_code: 115819370Spst found_ecoff_debugging_info = 1; 115919370Spst /* beginnning of (code) block. Value of symbol 116098944Sobrien is the displacement from procedure start */ 116119370Spst push_parse_stack (); 116219370Spst 116319370Spst /* Do not start a new block if this is the outermost block of a 116498944Sobrien procedure. This allows the LOC_BLOCK symbol to point to the 116598944Sobrien block with the local variables, so funcname::var works. */ 116619370Spst if (top_stack->blocktype == stProc 116719370Spst || top_stack->blocktype == stStaticProc) 116819370Spst { 116919370Spst top_stack->blocktype = stNil; 117019370Spst break; 117119370Spst } 117219370Spst 117319370Spst top_stack->blocktype = stBlock; 1174130803Smarcel b = new_block (NON_FUNCTION_BLOCK); 117519370Spst BLOCK_START (b) = sh->value + top_stack->procadr; 117619370Spst BLOCK_SUPERBLOCK (b) = top_stack->cur_block; 117719370Spst top_stack->cur_block = b; 117819370Spst add_block (b, top_stack->cur_st); 117919370Spst break; 118019370Spst 118119370Spst case stEnd: /* end (of anything) */ 118298944Sobrien if (sh->sc == scInfo || SC_IS_COMMON (sh->sc)) 118319370Spst { 118419370Spst /* Finished with type */ 118519370Spst top_stack->cur_type = 0; 118619370Spst } 118719370Spst else if (sh->sc == scText && 118819370Spst (top_stack->blocktype == stProc || 118919370Spst top_stack->blocktype == stStaticProc)) 119019370Spst { 119119370Spst /* Finished with procedure */ 119219370Spst struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st); 119319370Spst struct mips_extra_func_info *e; 1194130803Smarcel struct block *b = top_stack->cur_block; 119519370Spst struct type *ftype = top_stack->cur_type; 119619370Spst int i; 119719370Spst 119819370Spst BLOCK_END (top_stack->cur_block) += sh->value; /* size */ 119919370Spst 120019370Spst /* Make up special symbol to contain procedure specific info */ 120119370Spst s = new_symbol (MIPS_EFI_SYMBOL_NAME); 1202130803Smarcel SYMBOL_DOMAIN (s) = LABEL_DOMAIN; 120319370Spst SYMBOL_CLASS (s) = LOC_CONST; 120419370Spst SYMBOL_TYPE (s) = mdebug_type_void; 120519370Spst e = ((struct mips_extra_func_info *) 1206130803Smarcel obstack_alloc (¤t_objfile->objfile_obstack, 120719370Spst sizeof (struct mips_extra_func_info))); 120898944Sobrien memset (e, 0, sizeof (struct mips_extra_func_info)); 120919370Spst SYMBOL_VALUE (s) = (long) e; 121019370Spst e->numargs = top_stack->numargs; 121119370Spst e->pdr.framereg = -1; 121219370Spst add_symbol (s, top_stack->cur_block); 121319370Spst 121419370Spst /* f77 emits proc-level with address bounds==[0,0], 121519370Spst So look for such child blocks, and patch them. */ 121619370Spst for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++) 121719370Spst { 121819370Spst struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i); 121919370Spst if (BLOCK_SUPERBLOCK (b_bad) == b 122019370Spst && BLOCK_START (b_bad) == top_stack->procadr 122119370Spst && BLOCK_END (b_bad) == top_stack->procadr) 122219370Spst { 122319370Spst BLOCK_START (b_bad) = BLOCK_START (b); 122419370Spst BLOCK_END (b_bad) = BLOCK_END (b); 122519370Spst } 122619370Spst } 122719370Spst 122819370Spst if (TYPE_NFIELDS (ftype) <= 0) 122919370Spst { 123019370Spst /* No parameter type information is recorded with the function's 123198944Sobrien type. Set that from the type of the parameter symbols. */ 123219370Spst int nparams = top_stack->numargs; 123319370Spst int iparams; 123419370Spst struct symbol *sym; 123519370Spst 123619370Spst if (nparams > 0) 123719370Spst { 1238130803Smarcel struct dict_iterator iter; 123919370Spst TYPE_NFIELDS (ftype) = nparams; 124019370Spst TYPE_FIELDS (ftype) = (struct field *) 124119370Spst TYPE_ALLOC (ftype, nparams * sizeof (struct field)); 124298944Sobrien 1243130803Smarcel iparams = 0; 1244130803Smarcel ALL_BLOCK_SYMBOLS (b, iter, sym) 124519370Spst { 1246130803Smarcel if (iparams == nparams) 1247130803Smarcel break; 1248130803Smarcel 124919370Spst switch (SYMBOL_CLASS (sym)) 125019370Spst { 125119370Spst case LOC_ARG: 125219370Spst case LOC_REF_ARG: 125319370Spst case LOC_REGPARM: 125419370Spst case LOC_REGPARM_ADDR: 125519370Spst TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym); 125698944Sobrien TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; 125719370Spst iparams++; 125819370Spst break; 125919370Spst default: 126019370Spst break; 126119370Spst } 126219370Spst } 126319370Spst } 126419370Spst } 126519370Spst } 126619370Spst else if (sh->sc == scText && top_stack->blocktype == stBlock) 126719370Spst { 126819370Spst /* End of (code) block. The value of the symbol is the 126919370Spst displacement from the procedure`s start address of the 127019370Spst end of this block. */ 127119370Spst BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr; 127219370Spst } 127319370Spst else if (sh->sc == scText && top_stack->blocktype == stNil) 127419370Spst { 127519370Spst /* End of outermost block. Pop parse stack and ignore. The 127619370Spst following stEnd of stProc will take care of the block. */ 127719370Spst ; 127819370Spst } 127919370Spst else if (sh->sc == scText && top_stack->blocktype == stFile) 128019370Spst { 128119370Spst /* End of file. Pop parse stack and ignore. Higher 128219370Spst level code deals with this. */ 128319370Spst ; 128419370Spst } 128519370Spst else 1286130803Smarcel complaint (&symfile_complaints, 1287130803Smarcel "stEnd with storage class %d not handled", sh->sc); 128819370Spst 128919370Spst pop_parse_stack (); /* restore previous lexical context */ 129019370Spst break; 129119370Spst 129219370Spst case stMember: /* member of struct or union */ 129319370Spst f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++]; 129446283Sdfr FIELD_NAME (*f) = name; 129546283Sdfr FIELD_BITPOS (*f) = sh->value; 129619370Spst bitsize = 0; 129746283Sdfr FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index, &bitsize, bigend, name); 129846283Sdfr FIELD_BITSIZE (*f) = bitsize; 1299130803Smarcel FIELD_STATIC_KIND (*f) = 0; 130019370Spst break; 130119370Spst 130219370Spst case stIndirect: /* forward declaration on Irix5 */ 130319370Spst /* Forward declarations from Irix5 cc are handled by cross_ref, 130498944Sobrien skip them. */ 130519370Spst break; 130619370Spst 130719370Spst case stTypedef: /* type definition */ 130819370Spst found_ecoff_debugging_info = 1; 130919370Spst 131019370Spst /* Typedefs for forward declarations and opaque structs from alpha cc 131198944Sobrien are handled by cross_ref, skip them. */ 131219370Spst if (sh->iss == 0) 131319370Spst break; 131419370Spst 131519370Spst /* Parse the type or use the pending type. */ 131619370Spst pend = is_pending_symbol (cur_fdr, ext_sh); 131719370Spst if (pend == (struct mdebug_pending *) NULL) 131819370Spst { 131998944Sobrien t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name); 132019370Spst add_pending (cur_fdr, ext_sh, t); 132119370Spst } 132219370Spst else 132319370Spst t = pend->t; 132419370Spst 132519370Spst /* mips cc puts out a typedef with the name of the struct for forward 132698944Sobrien declarations. These should not go into the symbol table and 132798944Sobrien TYPE_NAME should not be set for them. 132898944Sobrien They can't be distinguished from an intentional typedef to 132998944Sobrien the same name however: 133098944Sobrien x.h: 133198944Sobrien struct x { int ix; int jx; }; 133298944Sobrien struct xx; 133398944Sobrien x.c: 133498944Sobrien typedef struct x x; 133598944Sobrien struct xx {int ixx; int jxx; }; 133698944Sobrien generates a cross referencing stTypedef for x and xx. 133798944Sobrien The user visible effect of this is that the type of a pointer 133898944Sobrien to struct foo sometimes is given as `foo *' instead of `struct foo *'. 133998944Sobrien The problem is fixed with alpha cc and Irix5 cc. */ 134019370Spst 134119370Spst /* However if the typedef cross references to an opaque aggregate, it 134298944Sobrien is safe to omit it from the symbol table. */ 134319370Spst 134419370Spst if (has_opaque_xref (cur_fdr, sh)) 134519370Spst break; 134619370Spst s = new_symbol (name); 1347130803Smarcel SYMBOL_DOMAIN (s) = VAR_DOMAIN; 134819370Spst SYMBOL_CLASS (s) = LOC_TYPEDEF; 134919370Spst SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block; 135019370Spst SYMBOL_TYPE (s) = t; 135119370Spst add_symbol (s, top_stack->cur_block); 135219370Spst 135319370Spst /* Incomplete definitions of structs should not get a name. */ 135419370Spst if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL 135519370Spst && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0 135698944Sobrien || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT 135719370Spst && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION))) 135819370Spst { 135919370Spst if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR 136019370Spst || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC) 136119370Spst { 136219370Spst /* If we are giving a name to a type such as "pointer to 136398944Sobrien foo" or "function returning foo", we better not set 136498944Sobrien the TYPE_NAME. If the program contains "typedef char 136598944Sobrien *caddr_t;", we don't want all variables of type char 136698944Sobrien * to print as caddr_t. This is not just a 136798944Sobrien consequence of GDB's type management; CC and GCC (at 136898944Sobrien least through version 2.4) both output variables of 136998944Sobrien either type char * or caddr_t with the type 137098944Sobrien refering to the stTypedef symbol for caddr_t. If a future 137198944Sobrien compiler cleans this up it GDB is not ready for it 137298944Sobrien yet, but if it becomes ready we somehow need to 137398944Sobrien disable this check (without breaking the PCC/GCC2.4 137498944Sobrien case). 137519370Spst 137698944Sobrien Sigh. 137719370Spst 137898944Sobrien Fortunately, this check seems not to be necessary 137998944Sobrien for anything except pointers or functions. */ 138019370Spst } 138119370Spst else 1382130803Smarcel TYPE_NAME (SYMBOL_TYPE (s)) = DEPRECATED_SYMBOL_NAME (s); 138319370Spst } 138419370Spst break; 138519370Spst 138619370Spst case stFile: /* file name */ 138719370Spst push_parse_stack (); 138819370Spst top_stack->blocktype = sh->st; 138919370Spst break; 139019370Spst 139119370Spst /* I`ve never seen these for C */ 139219370Spst case stRegReloc: 139319370Spst break; /* register relocation */ 139419370Spst case stForward: 139519370Spst break; /* forwarding address */ 139619370Spst case stConstant: 139719370Spst break; /* constant */ 139819370Spst default: 1399130803Smarcel complaint (&symfile_complaints, "unknown symbol type 0x%x", sh->st); 140019370Spst break; 140119370Spst } 140219370Spst 140319370Spst return count; 140419370Spst} 140519370Spst 140619370Spst/* Parse the type information provided in the raw AX entries for 140719370Spst the symbol SH. Return the bitfield size in BS, in case. 140819370Spst We must byte-swap the AX entries before we use them; BIGEND says whether 140919370Spst they are big-endian or little-endian (from fh->fBigendian). */ 141019370Spst 141119370Spststatic struct type * 141298944Sobrienparse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs, 141398944Sobrien int bigend, char *sym_name) 141419370Spst{ 141519370Spst /* Null entries in this map are treated specially */ 141619370Spst static struct type **map_bt[] = 141719370Spst { 141898944Sobrien &mdebug_type_void, /* btNil */ 141998944Sobrien &mdebug_type_adr_32, /* btAdr */ 142098944Sobrien &mdebug_type_char, /* btChar */ 142198944Sobrien &mdebug_type_unsigned_char, /* btUChar */ 142298944Sobrien &mdebug_type_short, /* btShort */ 142319370Spst &mdebug_type_unsigned_short, /* btUShort */ 142498944Sobrien &mdebug_type_int_32, /* btInt */ 142519370Spst &mdebug_type_unsigned_int_32, /* btUInt */ 142698944Sobrien &mdebug_type_long_32, /* btLong */ 142719370Spst &mdebug_type_unsigned_long_32, /* btULong */ 142898944Sobrien &mdebug_type_float, /* btFloat */ 142998944Sobrien &mdebug_type_double, /* btDouble */ 143098944Sobrien 0, /* btStruct */ 143198944Sobrien 0, /* btUnion */ 143298944Sobrien 0, /* btEnum */ 143398944Sobrien 0, /* btTypedef */ 143498944Sobrien 0, /* btRange */ 143598944Sobrien 0, /* btSet */ 143698944Sobrien &mdebug_type_complex, /* btComplex */ 143719370Spst &mdebug_type_double_complex, /* btDComplex */ 143898944Sobrien 0, /* btIndirect */ 143998944Sobrien &mdebug_type_fixed_dec, /* btFixedDec */ 144098944Sobrien &mdebug_type_float_dec, /* btFloatDec */ 144198944Sobrien &mdebug_type_string, /* btString */ 144298944Sobrien 0, /* btBit */ 144398944Sobrien 0, /* btPicture */ 144498944Sobrien &mdebug_type_void, /* btVoid */ 144598944Sobrien 0, /* DEC C++: Pointer to member */ 144698944Sobrien 0, /* DEC C++: Virtual function table */ 144798944Sobrien 0, /* DEC C++: Class (Record) */ 144898944Sobrien &mdebug_type_long_64, /* btLong64 */ 144919370Spst &mdebug_type_unsigned_long_64, /* btULong64 */ 145098944Sobrien &mdebug_type_long_long_64, /* btLongLong64 */ 145198944Sobrien &mdebug_type_unsigned_long_long_64, /* btULongLong64 */ 145298944Sobrien &mdebug_type_adr_64, /* btAdr64 */ 145398944Sobrien &mdebug_type_int_64, /* btInt64 */ 145419370Spst &mdebug_type_unsigned_int_64, /* btUInt64 */ 145519370Spst }; 145619370Spst 145719370Spst TIR t[1]; 145819370Spst struct type *tp = 0; 145919370Spst enum type_code type_code = TYPE_CODE_UNDEF; 146019370Spst 146119370Spst /* Handle undefined types, they have indexNil. */ 146219370Spst if (aux_index == indexNil) 146319370Spst return mdebug_type_int; 146419370Spst 146519370Spst /* Handle corrupt aux indices. */ 146619370Spst if (aux_index >= (debug_info->fdr + fd)->caux) 146719370Spst { 1468130803Smarcel index_complaint (sym_name); 146919370Spst return mdebug_type_int; 147019370Spst } 147119370Spst ax += aux_index; 147219370Spst 147319370Spst /* Use aux as a type information record, map its basic type. */ 147419370Spst (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t); 147519370Spst if (t->bt >= (sizeof (map_bt) / sizeof (*map_bt))) 147619370Spst { 1477130803Smarcel basic_type_complaint (t->bt, sym_name); 147819370Spst return mdebug_type_int; 147919370Spst } 148019370Spst if (map_bt[t->bt]) 148119370Spst { 148219370Spst tp = *map_bt[t->bt]; 148319370Spst } 148419370Spst else 148519370Spst { 148619370Spst tp = NULL; 148719370Spst /* Cannot use builtin types -- build our own */ 148819370Spst switch (t->bt) 148919370Spst { 149019370Spst case btStruct: 149119370Spst type_code = TYPE_CODE_STRUCT; 149219370Spst break; 149319370Spst case btUnion: 149419370Spst type_code = TYPE_CODE_UNION; 149519370Spst break; 149619370Spst case btEnum: 149719370Spst type_code = TYPE_CODE_ENUM; 149819370Spst break; 149919370Spst case btRange: 150019370Spst type_code = TYPE_CODE_RANGE; 150119370Spst break; 150219370Spst case btSet: 150319370Spst type_code = TYPE_CODE_SET; 150419370Spst break; 150519370Spst case btIndirect: 150619370Spst /* alpha cc -migrate uses this for typedefs. The true type will 150719370Spst be obtained by crossreferencing below. */ 150819370Spst type_code = TYPE_CODE_ERROR; 150919370Spst break; 151019370Spst case btTypedef: 151119370Spst /* alpha cc uses this for typedefs. The true type will be 151219370Spst obtained by crossreferencing below. */ 151319370Spst type_code = TYPE_CODE_ERROR; 151419370Spst break; 151519370Spst default: 1516130803Smarcel basic_type_complaint (t->bt, sym_name); 151719370Spst return mdebug_type_int; 151819370Spst } 151919370Spst } 152019370Spst 152119370Spst /* Move on to next aux */ 152219370Spst ax++; 152319370Spst 152419370Spst if (t->fBitfield) 152519370Spst { 152619370Spst int width = AUX_GET_WIDTH (bigend, ax); 1527130803Smarcel /* Inhibit core dumps if TIR is corrupted. */ 152898944Sobrien if (bs == (int *) NULL) 152919370Spst { 153019370Spst /* Alpha cc -migrate encodes char and unsigned char types 153119370Spst as short and unsigned short types with a field width of 8. 153219370Spst Enum types also have a field width which we ignore for now. */ 153319370Spst if (t->bt == btShort && width == 8) 153419370Spst tp = mdebug_type_char; 153519370Spst else if (t->bt == btUShort && width == 8) 153619370Spst tp = mdebug_type_unsigned_char; 153719370Spst else if (t->bt == btEnum) 153819370Spst ; 153919370Spst else 1540130803Smarcel complaint (&symfile_complaints, "can't handle TIR fBitfield for %s", 1541130803Smarcel sym_name); 154219370Spst } 154319370Spst else 154498944Sobrien *bs = width; 154519370Spst ax++; 154619370Spst } 154719370Spst 154819370Spst /* A btIndirect entry cross references to an aux entry containing 154919370Spst the type. */ 155019370Spst if (t->bt == btIndirect) 155119370Spst { 155219370Spst RNDXR rn[1]; 155319370Spst int rf; 155419370Spst FDR *xref_fh; 155519370Spst int xref_fd; 155619370Spst 155719370Spst (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn); 155819370Spst ax++; 155919370Spst if (rn->rfd == 0xfff) 156019370Spst { 156119370Spst rf = AUX_GET_ISYM (bigend, ax); 156219370Spst ax++; 156319370Spst } 156419370Spst else 156519370Spst rf = rn->rfd; 156619370Spst 156719370Spst if (rf == -1) 156819370Spst { 1569130803Smarcel complaint (&symfile_complaints, 1570130803Smarcel "unable to cross ref btIndirect for %s", sym_name); 157119370Spst return mdebug_type_int; 157219370Spst } 157319370Spst xref_fh = get_rfd (fd, rf); 157419370Spst xref_fd = xref_fh - debug_info->fdr; 157519370Spst tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase, 157698944Sobrien rn->index, (int *) NULL, xref_fh->fBigendian, sym_name); 157719370Spst } 157819370Spst 157919370Spst /* All these types really point to some (common) MIPS type 158019370Spst definition, and only the type-qualifiers fully identify 158119370Spst them. We'll make the same effort at sharing. */ 158219370Spst if (t->bt == btStruct || 158319370Spst t->bt == btUnion || 158419370Spst t->bt == btEnum || 158519370Spst 158698944Sobrien /* btSet (I think) implies that the name is a tag name, not a typedef 158798944Sobrien name. This apparently is a MIPS extension for C sets. */ 158819370Spst t->bt == btSet) 158919370Spst { 159019370Spst char *name; 159119370Spst 159219370Spst /* Try to cross reference this type, build new type on failure. */ 159319370Spst ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name); 159419370Spst if (tp == (struct type *) NULL) 159519370Spst tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile); 159619370Spst 159719370Spst /* DEC c89 produces cross references to qualified aggregate types, 159898944Sobrien dereference them. */ 159919370Spst while (TYPE_CODE (tp) == TYPE_CODE_PTR 160019370Spst || TYPE_CODE (tp) == TYPE_CODE_ARRAY) 1601130803Smarcel tp = TYPE_TARGET_TYPE (tp); 160219370Spst 160319370Spst /* Make sure that TYPE_CODE(tp) has an expected type code. 160498944Sobrien Any type may be returned from cross_ref if file indirect entries 160598944Sobrien are corrupted. */ 160619370Spst if (TYPE_CODE (tp) != TYPE_CODE_STRUCT 160719370Spst && TYPE_CODE (tp) != TYPE_CODE_UNION 160819370Spst && TYPE_CODE (tp) != TYPE_CODE_ENUM) 160919370Spst { 1610130803Smarcel unexpected_type_code_complaint (sym_name); 161119370Spst } 161219370Spst else 161319370Spst { 161419370Spst 161519370Spst /* Usually, TYPE_CODE(tp) is already type_code. The main 161619370Spst exception is if we guessed wrong re struct/union/enum. 161719370Spst But for struct vs. union a wrong guess is harmless, so 161819370Spst don't complain(). */ 161919370Spst if ((TYPE_CODE (tp) == TYPE_CODE_ENUM 162019370Spst && type_code != TYPE_CODE_ENUM) 162119370Spst || (TYPE_CODE (tp) != TYPE_CODE_ENUM 162219370Spst && type_code == TYPE_CODE_ENUM)) 162319370Spst { 1624130803Smarcel bad_tag_guess_complaint (sym_name); 162519370Spst } 162619370Spst 162719370Spst if (TYPE_CODE (tp) != type_code) 162819370Spst { 162919370Spst TYPE_CODE (tp) = type_code; 163019370Spst } 163119370Spst 163219370Spst /* Do not set the tag name if it is a compiler generated tag name 163398944Sobrien (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */ 163419370Spst if (name[0] == '.' || name[0] == '\0') 163519370Spst TYPE_TAG_NAME (tp) = NULL; 163619370Spst else if (TYPE_TAG_NAME (tp) == NULL 1637130803Smarcel || strcmp (TYPE_TAG_NAME (tp), name) != 0) 163819370Spst TYPE_TAG_NAME (tp) = obsavestring (name, strlen (name), 1639130803Smarcel ¤t_objfile->objfile_obstack); 164019370Spst } 164119370Spst } 164219370Spst 164319370Spst /* All these types really point to some (common) MIPS type 164419370Spst definition, and only the type-qualifiers fully identify 164519370Spst them. We'll make the same effort at sharing. 164619370Spst FIXME: We are not doing any guessing on range types. */ 164719370Spst if (t->bt == btRange) 164819370Spst { 164919370Spst char *name; 165019370Spst 165119370Spst /* Try to cross reference this type, build new type on failure. */ 165219370Spst ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name); 165319370Spst if (tp == (struct type *) NULL) 165419370Spst tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile); 165519370Spst 165619370Spst /* Make sure that TYPE_CODE(tp) has an expected type code. 165798944Sobrien Any type may be returned from cross_ref if file indirect entries 165898944Sobrien are corrupted. */ 165919370Spst if (TYPE_CODE (tp) != TYPE_CODE_RANGE) 166019370Spst { 1661130803Smarcel unexpected_type_code_complaint (sym_name); 166219370Spst } 166319370Spst else 166419370Spst { 166519370Spst /* Usually, TYPE_CODE(tp) is already type_code. The main 166619370Spst exception is if we guessed wrong re struct/union/enum. */ 166719370Spst if (TYPE_CODE (tp) != type_code) 166819370Spst { 1669130803Smarcel bad_tag_guess_complaint (sym_name); 167019370Spst TYPE_CODE (tp) = type_code; 167119370Spst } 1672130803Smarcel if (TYPE_NAME (tp) == NULL 1673130803Smarcel || strcmp (TYPE_NAME (tp), name) != 0) 167419370Spst TYPE_NAME (tp) = obsavestring (name, strlen (name), 1675130803Smarcel ¤t_objfile->objfile_obstack); 167619370Spst } 167719370Spst } 167819370Spst if (t->bt == btTypedef) 167919370Spst { 168019370Spst char *name; 168119370Spst 168219370Spst /* Try to cross reference this type, it should succeed. */ 168319370Spst ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name); 168419370Spst if (tp == (struct type *) NULL) 168519370Spst { 1686130803Smarcel complaint (&symfile_complaints, 1687130803Smarcel "unable to cross ref btTypedef for %s", sym_name); 168819370Spst tp = mdebug_type_int; 168919370Spst } 169019370Spst } 169119370Spst 169219370Spst /* Deal with range types */ 169319370Spst if (t->bt == btRange) 169419370Spst { 169519370Spst TYPE_NFIELDS (tp) = 2; 169619370Spst TYPE_FIELDS (tp) = ((struct field *) 169719370Spst TYPE_ALLOC (tp, 2 * sizeof (struct field))); 169819370Spst TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"), 1699130803Smarcel ¤t_objfile->objfile_obstack); 170019370Spst TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax); 170119370Spst ax++; 170219370Spst TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"), 1703130803Smarcel ¤t_objfile->objfile_obstack); 170419370Spst TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax); 170519370Spst ax++; 170619370Spst } 170719370Spst 170819370Spst /* Parse all the type qualifiers now. If there are more 170919370Spst than 6 the game will continue in the next aux */ 171019370Spst 171119370Spst while (1) 171219370Spst { 171319370Spst#define PARSE_TQ(tq) \ 171419370Spst if (t->tq != tqNil) \ 171519370Spst ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \ 171619370Spst else \ 171719370Spst break; 171819370Spst 171919370Spst PARSE_TQ (tq0); 172019370Spst PARSE_TQ (tq1); 172119370Spst PARSE_TQ (tq2); 172219370Spst PARSE_TQ (tq3); 172319370Spst PARSE_TQ (tq4); 172419370Spst PARSE_TQ (tq5); 172519370Spst#undef PARSE_TQ 172619370Spst 172719370Spst /* mips cc 2.x and gcc never put out continued aux entries. */ 172819370Spst if (!t->continued) 172919370Spst break; 173019370Spst 173119370Spst (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t); 173219370Spst ax++; 173319370Spst } 173419370Spst 173519370Spst /* Complain for illegal continuations due to corrupt aux entries. */ 173619370Spst if (t->continued) 1737130803Smarcel complaint (&symfile_complaints, "illegal TIR continued for %s", sym_name); 173898944Sobrien 173919370Spst return tp; 174019370Spst} 174119370Spst 174219370Spst/* Make up a complex type from a basic one. Type is passed by 174319370Spst reference in TPP and side-effected as necessary. The type 174419370Spst qualifier TQ says how to handle the aux symbols at AX for 174519370Spst the symbol SX we are currently analyzing. BIGEND says whether 174619370Spst aux symbols are big-endian or little-endian. 174719370Spst Returns the number of aux symbols we parsed. */ 174819370Spst 174919370Spststatic int 175098944Sobrienupgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend, 175198944Sobrien char *sym_name) 175219370Spst{ 175319370Spst int off; 175419370Spst struct type *t; 175519370Spst 175619370Spst /* Used in array processing */ 175719370Spst int rf, id; 175819370Spst FDR *fh; 175919370Spst struct type *range; 176019370Spst struct type *indx; 176119370Spst int lower, upper; 176219370Spst RNDXR rndx; 176319370Spst 176419370Spst switch (tq) 176519370Spst { 176619370Spst case tqPtr: 176719370Spst t = lookup_pointer_type (*tpp); 176819370Spst *tpp = t; 176919370Spst return 0; 177019370Spst 177119370Spst case tqProc: 177219370Spst t = lookup_function_type (*tpp); 177319370Spst *tpp = t; 177419370Spst return 0; 177519370Spst 177619370Spst case tqArray: 177719370Spst off = 0; 177819370Spst 177919370Spst /* Determine and record the domain type (type of index) */ 178019370Spst (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx); 178119370Spst id = rndx.index; 178219370Spst rf = rndx.rfd; 178319370Spst if (rf == 0xfff) 178419370Spst { 178519370Spst ax++; 178619370Spst rf = AUX_GET_ISYM (bigend, ax); 178719370Spst off++; 178819370Spst } 178919370Spst fh = get_rfd (fd, rf); 179019370Spst 179119370Spst indx = parse_type (fh - debug_info->fdr, 179219370Spst debug_info->external_aux + fh->iauxBase, 179319370Spst id, (int *) NULL, bigend, sym_name); 179419370Spst 179519370Spst /* The bounds type should be an integer type, but might be anything 179698944Sobrien else due to corrupt aux entries. */ 179719370Spst if (TYPE_CODE (indx) != TYPE_CODE_INT) 179819370Spst { 1799130803Smarcel complaint (&symfile_complaints, 1800130803Smarcel "illegal array index type for %s, assuming int", sym_name); 180119370Spst indx = mdebug_type_int; 180219370Spst } 180319370Spst 180419370Spst /* Get the bounds, and create the array type. */ 180519370Spst ax++; 180619370Spst lower = AUX_GET_DNLOW (bigend, ax); 180719370Spst ax++; 180819370Spst upper = AUX_GET_DNHIGH (bigend, ax); 180919370Spst ax++; 181019370Spst rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */ 181119370Spst 181219370Spst range = create_range_type ((struct type *) NULL, indx, 181319370Spst lower, upper); 181419370Spst 181519370Spst t = create_array_type ((struct type *) NULL, *tpp, range); 181619370Spst 181719370Spst /* We used to fill in the supplied array element bitsize 181898944Sobrien here if the TYPE_LENGTH of the target type was zero. 181998944Sobrien This happens for a `pointer to an array of anonymous structs', 182098944Sobrien but in this case the array element bitsize is also zero, 182198944Sobrien so nothing is gained. 182298944Sobrien And we used to check the TYPE_LENGTH of the target type against 182398944Sobrien the supplied array element bitsize. 182498944Sobrien gcc causes a mismatch for `pointer to array of object', 182598944Sobrien since the sdb directives it uses do not have a way of 182698944Sobrien specifying the bitsize, but it does no harm (the 182798944Sobrien TYPE_LENGTH should be correct) and we should be able to 182898944Sobrien ignore the erroneous bitsize from the auxiliary entry safely. 182998944Sobrien dbx seems to ignore it too. */ 183019370Spst 183119370Spst /* TYPE_FLAG_TARGET_STUB now takes care of the zero TYPE_LENGTH 183298944Sobrien problem. */ 183319370Spst if (TYPE_LENGTH (*tpp) == 0) 183419370Spst { 183519370Spst TYPE_FLAGS (t) |= TYPE_FLAG_TARGET_STUB; 183619370Spst } 183719370Spst 183819370Spst *tpp = t; 183919370Spst return 4 + off; 184019370Spst 184119370Spst case tqVol: 184219370Spst /* Volatile -- currently ignored */ 184319370Spst return 0; 184419370Spst 184519370Spst case tqConst: 184619370Spst /* Const -- currently ignored */ 184719370Spst return 0; 184819370Spst 184919370Spst default: 1850130803Smarcel complaint (&symfile_complaints, "unknown type qualifier 0x%x", tq); 185119370Spst return 0; 185219370Spst } 185319370Spst} 185419370Spst 185519370Spst 185619370Spst/* Parse a procedure descriptor record PR. Note that the procedure is 185719370Spst parsed _after_ the local symbols, now we just insert the extra 185819370Spst information we need into a MIPS_EFI_SYMBOL_NAME symbol that has 185919370Spst already been placed in the procedure's main block. Note also that 186019370Spst images that have been partially stripped (ld -x) have been deprived 186119370Spst of local symbols, and we have to cope with them here. FIRST_OFF is 186219370Spst the offset of the first procedure for this FDR; we adjust the 186319370Spst address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab 186419370Spst to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol 186519370Spst in question, or NULL to use top_stack->cur_block. */ 186619370Spst 186798944Sobrienstatic void parse_procedure (PDR *, struct symtab *, struct partial_symtab *); 186819370Spst 186919370Spststatic void 187098944Sobrienparse_procedure (PDR *pr, struct symtab *search_symtab, 187198944Sobrien struct partial_symtab *pst) 187219370Spst{ 187319370Spst struct symbol *s, *i; 187419370Spst struct block *b; 187519370Spst struct mips_extra_func_info *e; 187619370Spst char *sh_name; 187719370Spst 187819370Spst /* Simple rule to find files linked "-x" */ 187919370Spst if (cur_fdr->rss == -1) 188019370Spst { 188119370Spst if (pr->isym == -1) 188219370Spst { 188319370Spst /* Static procedure at address pr->adr. Sigh. */ 188419370Spst /* FIXME-32x64. assuming pr->adr fits in long. */ 1885130803Smarcel complaint (&symfile_complaints, 1886130803Smarcel "can't handle PDR for static proc at 0x%lx", 1887130803Smarcel (unsigned long) pr->adr); 188819370Spst return; 188919370Spst } 189019370Spst else 189119370Spst { 189219370Spst /* external */ 189319370Spst EXTR she; 189498944Sobrien 189519370Spst (*debug_swap->swap_ext_in) (cur_bfd, 189619370Spst ((char *) debug_info->external_ext 189719370Spst + (pr->isym 189819370Spst * debug_swap->external_ext_size)), 189919370Spst &she); 190019370Spst sh_name = debug_info->ssext + she.asym.iss; 190119370Spst } 190219370Spst } 190319370Spst else 190419370Spst { 190519370Spst /* Full symbols */ 190619370Spst SYMR sh; 190719370Spst 190819370Spst (*debug_swap->swap_sym_in) (cur_bfd, 190919370Spst ((char *) debug_info->external_sym 191019370Spst + ((cur_fdr->isymBase + pr->isym) 191119370Spst * debug_swap->external_sym_size)), 191219370Spst &sh); 191319370Spst sh_name = debug_info->ss + cur_fdr->issBase + sh.iss; 191419370Spst } 191519370Spst 191619370Spst if (search_symtab != NULL) 191719370Spst { 191819370Spst#if 0 191919370Spst /* This loses both in the case mentioned (want a static, find a global), 192098944Sobrien but also if we are looking up a non-mangled name which happens to 192198944Sobrien match the name of a mangled function. */ 192219370Spst /* We have to save the cur_fdr across the call to lookup_symbol. 192398944Sobrien If the pdr is for a static function and if a global function with 192498944Sobrien the same name exists, lookup_symbol will eventually read in the symtab 192598944Sobrien for the global function and clobber cur_fdr. */ 192619370Spst FDR *save_cur_fdr = cur_fdr; 1927130803Smarcel s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0, NULL); 192819370Spst cur_fdr = save_cur_fdr; 192919370Spst#else 193019370Spst s = mylookup_symbol 193119370Spst (sh_name, 193219370Spst BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK), 1933130803Smarcel VAR_DOMAIN, 193419370Spst LOC_BLOCK); 193519370Spst#endif 193619370Spst } 193719370Spst else 193819370Spst s = mylookup_symbol (sh_name, top_stack->cur_block, 1939130803Smarcel VAR_DOMAIN, LOC_BLOCK); 194019370Spst 194119370Spst if (s != 0) 194219370Spst { 194319370Spst b = SYMBOL_BLOCK_VALUE (s); 194419370Spst } 194519370Spst else 194619370Spst { 1947130803Smarcel complaint (&symfile_complaints, "PDR for %s, but no symbol", sh_name); 194819370Spst#if 1 194919370Spst return; 195019370Spst#else 195119370Spst/* FIXME -- delete. We can't do symbol allocation now; it's all done. */ 195219370Spst s = new_symbol (sh_name); 1953130803Smarcel SYMBOL_DOMAIN (s) = VAR_DOMAIN; 195419370Spst SYMBOL_CLASS (s) = LOC_BLOCK; 195519370Spst /* Donno its type, hope int is ok */ 195619370Spst SYMBOL_TYPE (s) = lookup_function_type (mdebug_type_int); 195719370Spst add_symbol (s, top_stack->cur_block); 195819370Spst /* Wont have symbols for this one */ 195919370Spst b = new_block (2); 196019370Spst SYMBOL_BLOCK_VALUE (s) = b; 196119370Spst BLOCK_FUNCTION (b) = s; 196219370Spst BLOCK_START (b) = pr->adr; 196319370Spst /* BOUND used to be the end of procedure's text, but the 196498944Sobrien argument is no longer passed in. */ 196519370Spst BLOCK_END (b) = bound; 196619370Spst BLOCK_SUPERBLOCK (b) = top_stack->cur_block; 196719370Spst add_block (b, top_stack->cur_st); 196819370Spst#endif 196919370Spst } 197019370Spst 1971130803Smarcel i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST); 197219370Spst 197319370Spst if (i) 197419370Spst { 197519370Spst e = (struct mips_extra_func_info *) SYMBOL_VALUE (i); 197619370Spst e->pdr = *pr; 197719370Spst e->pdr.isym = (long) s; 197819370Spst 197946283Sdfr /* GDB expects the absolute function start address for the 198098944Sobrien procedure descriptor in e->pdr.adr. 198198944Sobrien As the address in the procedure descriptor is usually relative, 198298944Sobrien we would have to relocate e->pdr.adr with cur_fdr->adr and 198398944Sobrien ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)). 198498944Sobrien Unfortunately cur_fdr->adr and e->pdr.adr are both absolute 198598944Sobrien in shared libraries on some systems, and on other systems 198698944Sobrien e->pdr.adr is sometimes offset by a bogus value. 198798944Sobrien To work around these problems, we replace e->pdr.adr with 198898944Sobrien the start address of the function. */ 198946283Sdfr e->pdr.adr = BLOCK_START (b); 199046283Sdfr 199119370Spst /* Correct incorrect setjmp procedure descriptor from the library 199298944Sobrien to make backtrace through setjmp work. */ 1993130803Smarcel if (e->pdr.pcreg == 0 1994130803Smarcel && strcmp (sh_name, "setjmp") == 0) 199519370Spst { 1996130803Smarcel complaint (&symfile_complaints, "fixing bad setjmp PDR from libc"); 199719370Spst e->pdr.pcreg = RA_REGNUM; 199819370Spst e->pdr.regmask = 0x80000000; 199919370Spst e->pdr.regoffset = -4; 200019370Spst } 200119370Spst } 200219370Spst 200319370Spst /* It would be reasonable that functions that have been compiled 200419370Spst without debugging info have a btNil type for their return value, 200519370Spst and functions that are void and are compiled with debugging info 200619370Spst have btVoid. 200719370Spst gcc and DEC f77 put out btNil types for both cases, so btNil is mapped 200819370Spst to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info' 200919370Spst case right. 201019370Spst The glevel field in cur_fdr could be used to determine the presence 201119370Spst of debugging info, but GCC doesn't always pass the -g switch settings 201219370Spst to the assembler and GAS doesn't set the glevel field from the -g switch 201319370Spst settings. 201419370Spst To work around these problems, the return value type of a TYPE_CODE_VOID 201519370Spst function is adjusted accordingly if no debugging info was found in the 201619370Spst compilation unit. */ 201798944Sobrien 201819370Spst if (processing_gcc_compilation == 0 201919370Spst && found_ecoff_debugging_info == 0 202019370Spst && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID) 202119370Spst SYMBOL_TYPE (s) = nodebug_func_symbol_type; 202219370Spst} 202319370Spst 202419370Spst/* Relocate the extra function info pointed to by the symbol table. */ 202519370Spst 202619370Spstvoid 202798944Sobrienecoff_relocate_efi (struct symbol *sym, CORE_ADDR delta) 202819370Spst{ 202919370Spst struct mips_extra_func_info *e; 203019370Spst 203119370Spst e = (struct mips_extra_func_info *) SYMBOL_VALUE (sym); 203298944Sobrien 203319370Spst e->pdr.adr += delta; 203419370Spst} 203519370Spst 203619370Spst/* Parse the external symbol ES. Just call parse_symbol() after 203719370Spst making sure we know where the aux are for it. 203819370Spst BIGEND says whether aux entries are big-endian or little-endian. 203919370Spst 204019370Spst This routine clobbers top_stack->cur_block and ->cur_st. */ 204119370Spst 204298944Sobrienstatic void parse_external (EXTR *, int, struct section_offsets *, 204398944Sobrien struct objfile *); 204419370Spst 204519370Spststatic void 204698944Sobrienparse_external (EXTR *es, int bigend, struct section_offsets *section_offsets, 204798944Sobrien struct objfile *objfile) 204819370Spst{ 204919370Spst union aux_ext *ax; 205019370Spst 205119370Spst if (es->ifd != ifdNil) 205219370Spst { 205319370Spst cur_fd = es->ifd; 205419370Spst cur_fdr = debug_info->fdr + cur_fd; 205519370Spst ax = debug_info->external_aux + cur_fdr->iauxBase; 205619370Spst } 205719370Spst else 205819370Spst { 205919370Spst cur_fdr = debug_info->fdr; 206019370Spst ax = 0; 206119370Spst } 206219370Spst 206319370Spst /* Reading .o files */ 206498944Sobrien if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil) 206519370Spst { 206619370Spst char *what; 206719370Spst switch (es->asym.st) 206819370Spst { 206919370Spst case stNil: 207019370Spst /* These are generated for static symbols in .o files, 207119370Spst ignore them. */ 207219370Spst return; 207319370Spst case stStaticProc: 207419370Spst case stProc: 207519370Spst what = "procedure"; 207619370Spst n_undef_procs++; 207719370Spst break; 207819370Spst case stGlobal: 207919370Spst what = "variable"; 208019370Spst n_undef_vars++; 208119370Spst break; 208219370Spst case stLabel: 208319370Spst what = "label"; 208419370Spst n_undef_labels++; 208519370Spst break; 208619370Spst default: 208719370Spst what = "symbol"; 208819370Spst break; 208919370Spst } 209019370Spst n_undef_symbols++; 209119370Spst /* FIXME: Turn this into a complaint? */ 209219370Spst if (info_verbose) 209319370Spst printf_filtered ("Warning: %s `%s' is undefined (in %s)\n", 209419370Spst what, debug_info->ssext + es->asym.iss, 209519370Spst fdr_name (cur_fdr)); 209619370Spst return; 209719370Spst } 209819370Spst 209919370Spst switch (es->asym.st) 210019370Spst { 210119370Spst case stProc: 210219370Spst case stStaticProc: 210319370Spst /* There is no need to parse the external procedure symbols. 210498944Sobrien If they are from objects compiled without -g, their index will 210598944Sobrien be indexNil, and the symbol definition from the minimal symbol 210698944Sobrien is preferrable (yielding a function returning int instead of int). 210798944Sobrien If the index points to a local procedure symbol, the local 210898944Sobrien symbol already provides the correct type. 210998944Sobrien Note that the index of the external procedure symbol points 211098944Sobrien to the local procedure symbol in the local symbol table, and 211198944Sobrien _not_ to the auxiliary symbol info. */ 211219370Spst break; 211319370Spst case stGlobal: 211419370Spst case stLabel: 211519370Spst /* Global common symbols are resolved by the runtime loader, 211698944Sobrien ignore them. */ 211798944Sobrien if (SC_IS_COMMON (es->asym.sc)) 211819370Spst break; 211919370Spst 212019370Spst /* Note that the case of a symbol with indexNil must be handled 212198944Sobrien anyways by parse_symbol(). */ 212298944Sobrien parse_symbol (&es->asym, ax, (char *) NULL, bigend, section_offsets, objfile); 212319370Spst break; 212419370Spst default: 212519370Spst break; 212619370Spst } 212719370Spst} 212819370Spst 212919370Spst/* Parse the line number info for file descriptor FH into 213019370Spst GDB's linetable LT. MIPS' encoding requires a little bit 213119370Spst of magic to get things out. Note also that MIPS' line 213219370Spst numbers can go back and forth, apparently we can live 213319370Spst with that and do not need to reorder our linetables */ 213419370Spst 213598944Sobrienstatic void parse_lines (FDR *, PDR *, struct linetable *, int, 213698944Sobrien struct partial_symtab *, CORE_ADDR); 213719370Spst 213819370Spststatic void 213998944Sobrienparse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines, 214098944Sobrien struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr) 214119370Spst{ 214219370Spst unsigned char *base; 214319370Spst int j, k; 214419370Spst int delta, count, lineno = 0; 214519370Spst 214619370Spst if (fh->cbLine == 0) 214719370Spst return; 214819370Spst 214919370Spst /* Scan by procedure descriptors */ 215019370Spst k = 0; 215119370Spst for (j = 0; j < fh->cpd; j++, pr++) 215219370Spst { 215319370Spst CORE_ADDR l; 215419370Spst CORE_ADDR adr; 215519370Spst unsigned char *halt; 215619370Spst 215719370Spst /* No code for this one */ 215819370Spst if (pr->iline == ilineNil || 215919370Spst pr->lnLow == -1 || pr->lnHigh == -1) 216019370Spst continue; 216119370Spst 216219370Spst /* Determine start and end address of compressed line bytes for 216398944Sobrien this procedure. */ 216419370Spst base = debug_info->line + fh->cbLineOffset; 216519370Spst if (j != (fh->cpd - 1)) 216698944Sobrien halt = base + pr[1].cbLineOffset; 216719370Spst else 216898944Sobrien halt = base + fh->cbLine; 216919370Spst base += pr->cbLineOffset; 217019370Spst 2171130803Smarcel adr = pst->textlow + pr->adr - lowest_pdr_addr; 217219370Spst 217319370Spst l = adr >> 2; /* in words */ 217498944Sobrien for (lineno = pr->lnLow; base < halt;) 217519370Spst { 217619370Spst count = *base & 0x0f; 217719370Spst delta = *base++ >> 4; 217819370Spst if (delta >= 8) 217919370Spst delta -= 16; 218019370Spst if (delta == -8) 218119370Spst { 218219370Spst delta = (base[0] << 8) | base[1]; 218319370Spst if (delta >= 0x8000) 218419370Spst delta -= 0x10000; 218519370Spst base += 2; 218619370Spst } 218719370Spst lineno += delta; /* first delta is 0 */ 218819370Spst 218919370Spst /* Complain if the line table overflows. Could happen 219019370Spst with corrupt binaries. */ 219119370Spst if (lt->nitems >= maxlines) 219219370Spst { 2193130803Smarcel complaint (&symfile_complaints, 2194130803Smarcel "guessed size of linetable for %s incorrectly", 2195130803Smarcel fdr_name (fh)); 219619370Spst break; 219719370Spst } 219819370Spst k = add_line (lt, lineno, l, k); 219919370Spst l += count + 1; 220019370Spst } 220119370Spst } 220219370Spst} 220319370Spst 2204130803Smarcelstatic void 2205130803Smarcelfunction_outside_compilation_unit_complaint (const char *arg1) 2206130803Smarcel{ 2207130803Smarcel complaint (&symfile_complaints, 2208130803Smarcel "function `%s' appears to be defined outside of all compilation units", 2209130803Smarcel arg1); 2210130803Smarcel} 2211130803Smarcel 221219370Spst/* Master parsing procedure for first-pass reading of file symbols 221319370Spst into a partial_symtab. */ 221419370Spst 221519370Spststatic void 221698944Sobrienparse_partial_symbols (struct objfile *objfile) 221719370Spst{ 221819370Spst const bfd_size_type external_sym_size = debug_swap->external_sym_size; 221919370Spst const bfd_size_type external_rfd_size = debug_swap->external_rfd_size; 222019370Spst const bfd_size_type external_ext_size = debug_swap->external_ext_size; 222198944Sobrien void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in; 222298944Sobrien void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in; 222398944Sobrien void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in; 222419370Spst int f_idx, s_idx; 222519370Spst HDRR *hdr = &debug_info->symbolic_header; 222619370Spst /* Running pointers */ 222719370Spst FDR *fh; 222819370Spst char *ext_out; 222919370Spst char *ext_out_end; 223019370Spst EXTR *ext_block; 2231130803Smarcel EXTR *ext_in; 223219370Spst EXTR *ext_in_end; 223319370Spst SYMR sh; 223419370Spst struct partial_symtab *pst; 223546283Sdfr int textlow_not_set = 1; 223619370Spst int past_first_source_file = 0; 223719370Spst 223819370Spst /* List of current psymtab's include files */ 223919370Spst char **psymtab_include_list; 224019370Spst int includes_allocated; 224119370Spst int includes_used; 224219370Spst EXTR *extern_tab; 224319370Spst struct pst_map *fdr_to_pst; 224419370Spst /* Index within current psymtab dependency list */ 224519370Spst struct partial_symtab **dependency_list; 224619370Spst int dependencies_used, dependencies_allocated; 224719370Spst struct cleanup *old_chain; 224819370Spst char *name; 224919370Spst enum language prev_language; 225019370Spst asection *text_sect; 225119370Spst int relocatable = 0; 225219370Spst 225319370Spst /* Irix 5.2 shared libraries have a fh->adr field of zero, but 225419370Spst the shared libraries are prelinked at a high memory address. 225519370Spst We have to adjust the start address of the object file for this case, 225619370Spst by setting it to the start address of the first procedure in the file. 225719370Spst But we should do no adjustments if we are debugging a .o file, where 225819370Spst the text section (and fh->adr) really starts at zero. */ 225919370Spst text_sect = bfd_get_section_by_name (cur_bfd, ".text"); 226019370Spst if (text_sect != NULL 226119370Spst && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC)) 226219370Spst relocatable = 1; 226319370Spst 2264130803Smarcel extern_tab = (EXTR *) obstack_alloc (&objfile->objfile_obstack, 226519370Spst sizeof (EXTR) * hdr->iextMax); 226619370Spst 226719370Spst includes_allocated = 30; 226819370Spst includes_used = 0; 226919370Spst psymtab_include_list = (char **) alloca (includes_allocated * 227019370Spst sizeof (char *)); 227119370Spst next_symbol_text_func = mdebug_next_symbol_text; 227219370Spst 227319370Spst dependencies_allocated = 30; 227419370Spst dependencies_used = 0; 227519370Spst dependency_list = 227619370Spst (struct partial_symtab **) alloca (dependencies_allocated * 227719370Spst sizeof (struct partial_symtab *)); 227819370Spst 227919370Spst last_source_file = NULL; 228019370Spst 228119370Spst /* 228219370Spst * Big plan: 228319370Spst * 228419370Spst * Only parse the Local and External symbols, and the Relative FDR. 228519370Spst * Fixup enough of the loader symtab to be able to use it. 228619370Spst * Allocate space only for the file's portions we need to 228719370Spst * look at. (XXX) 228819370Spst */ 228919370Spst 229019370Spst max_gdbinfo = 0; 229119370Spst max_glevel = MIN_GLEVEL; 229219370Spst 229319370Spst /* Allocate the map FDR -> PST. 229419370Spst Minor hack: -O3 images might claim some global data belongs 229519370Spst to FDR -1. We`ll go along with that */ 229619370Spst fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst); 229798944Sobrien old_chain = make_cleanup (xfree, fdr_to_pst); 229819370Spst fdr_to_pst++; 229919370Spst { 230098944Sobrien struct partial_symtab *pst = new_psymtab ("", objfile); 230119370Spst fdr_to_pst[-1].pst = pst; 230219370Spst FDR_IDX (pst) = -1; 230319370Spst } 230419370Spst 230519370Spst /* Allocate the global pending list. */ 230619370Spst pending_list = 230719370Spst ((struct mdebug_pending **) 2308130803Smarcel obstack_alloc (&objfile->objfile_obstack, 230919370Spst hdr->ifdMax * sizeof (struct mdebug_pending *))); 231098944Sobrien memset (pending_list, 0, 231119370Spst hdr->ifdMax * sizeof (struct mdebug_pending *)); 231219370Spst 231319370Spst /* Pass 0 over external syms: swap them in. */ 231419370Spst ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR)); 231598944Sobrien make_cleanup (xfree, ext_block); 231619370Spst 231719370Spst ext_out = (char *) debug_info->external_ext; 231819370Spst ext_out_end = ext_out + hdr->iextMax * external_ext_size; 231919370Spst ext_in = ext_block; 232019370Spst for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++) 232119370Spst (*swap_ext_in) (cur_bfd, ext_out, ext_in); 232219370Spst 232319370Spst /* Pass 1 over external syms: Presize and partition the list */ 232419370Spst ext_in = ext_block; 232519370Spst ext_in_end = ext_in + hdr->iextMax; 232619370Spst for (; ext_in < ext_in_end; ext_in++) 232719370Spst { 232819370Spst /* See calls to complain below. */ 232919370Spst if (ext_in->ifd >= -1 233019370Spst && ext_in->ifd < hdr->ifdMax 233119370Spst && ext_in->asym.iss >= 0 233219370Spst && ext_in->asym.iss < hdr->issExtMax) 233319370Spst fdr_to_pst[ext_in->ifd].n_globals++; 233419370Spst } 233519370Spst 233619370Spst /* Pass 1.5 over files: partition out global symbol space */ 233719370Spst s_idx = 0; 233819370Spst for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) 233919370Spst { 234019370Spst fdr_to_pst[f_idx].globals_offset = s_idx; 234119370Spst s_idx += fdr_to_pst[f_idx].n_globals; 234219370Spst fdr_to_pst[f_idx].n_globals = 0; 234319370Spst } 234419370Spst 234546283Sdfr /* ECOFF in ELF: 234619370Spst 234746283Sdfr For ECOFF in ELF, we skip the creation of the minimal symbols. 234846283Sdfr The ECOFF symbols should be a subset of the Elf symbols, and the 234946283Sdfr section information of the elf symbols will be more accurate. 235046283Sdfr FIXME! What about Irix 5's native linker? 235119370Spst 235246283Sdfr By default, Elf sections which don't exist in ECOFF 235346283Sdfr get put in ECOFF's absolute section by the gnu linker. 235446283Sdfr Since absolute sections don't get relocated, we 235546283Sdfr end up calculating an address different from that of 235646283Sdfr the symbol's minimal symbol (created earlier from the 235746283Sdfr Elf symtab). 235819370Spst 235946283Sdfr To fix this, either : 236046283Sdfr 1) don't create the duplicate symbol 236198944Sobrien (assumes ECOFF symtab is a subset of the ELF symtab; 236298944Sobrien assumes no side-effects result from ignoring ECOFF symbol) 236346283Sdfr 2) create it, only if lookup for existing symbol in ELF's minimal 236498944Sobrien symbols fails 236598944Sobrien (inefficient; 236698944Sobrien assumes no side-effects result from ignoring ECOFF symbol) 236746283Sdfr 3) create it, but lookup ELF's minimal symbol and use it's section 236898944Sobrien during relocation, then modify "uniqify" phase to merge and 236998944Sobrien eliminate the duplicate symbol 237098944Sobrien (highly inefficient) 237119370Spst 237246283Sdfr I've implemented #1 here... 237346283Sdfr Skip the creation of the minimal symbols based on the ECOFF 237446283Sdfr symbol table. */ 237546283Sdfr 237698944Sobrien /* Pass 2 over external syms: fill in external symbols */ 237798944Sobrien ext_in = ext_block; 237898944Sobrien ext_in_end = ext_in + hdr->iextMax; 237998944Sobrien for (; ext_in < ext_in_end; ext_in++) 238098944Sobrien { 238198944Sobrien enum minimal_symbol_type ms_type = mst_text; 238298944Sobrien CORE_ADDR svalue = ext_in->asym.value; 238346283Sdfr 238498944Sobrien /* The Irix 5 native tools seem to sometimes generate bogus 238598944Sobrien external symbols. */ 238698944Sobrien if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax) 238798944Sobrien { 2388130803Smarcel complaint (&symfile_complaints, 2389130803Smarcel "bad ifd for external symbol: %d (max %ld)", ext_in->ifd, 2390130803Smarcel hdr->ifdMax); 239198944Sobrien continue; 239298944Sobrien } 239398944Sobrien if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax) 239498944Sobrien { 2395130803Smarcel complaint (&symfile_complaints, 2396130803Smarcel "bad iss for external symbol: %ld (max %ld)", 2397130803Smarcel ext_in->asym.iss, hdr->issExtMax); 239898944Sobrien continue; 239998944Sobrien } 240019370Spst 240198944Sobrien extern_tab[fdr_to_pst[ext_in->ifd].globals_offset 240298944Sobrien + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in; 240346283Sdfr 240446283Sdfr 240598944Sobrien if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil) 240698944Sobrien continue; 240746283Sdfr 240846283Sdfr 240998944Sobrien /* Pass 3 over files, over local syms: fill in static symbols */ 241098944Sobrien name = debug_info->ssext + ext_in->asym.iss; 241198944Sobrien 241298944Sobrien /* Process ECOFF Symbol Types and Storage Classes */ 241398944Sobrien switch (ext_in->asym.st) 241498944Sobrien { 241598944Sobrien case stProc: 241698944Sobrien /* Beginnning of Procedure */ 241798944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 241898944Sobrien break; 241998944Sobrien case stStaticProc: 242098944Sobrien /* Load time only static procs */ 242198944Sobrien ms_type = mst_file_text; 242298944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 242398944Sobrien break; 242498944Sobrien case stGlobal: 242598944Sobrien /* External symbol */ 242698944Sobrien if (SC_IS_COMMON (ext_in->asym.sc)) 242798944Sobrien { 242898944Sobrien /* The value of a common symbol is its size, not its address. 242998944Sobrien Ignore it. */ 243046283Sdfr continue; 243198944Sobrien } 243298944Sobrien else if (SC_IS_DATA (ext_in->asym.sc)) 243398944Sobrien { 243498944Sobrien ms_type = mst_data; 243598944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 243698944Sobrien } 243798944Sobrien else if (SC_IS_BSS (ext_in->asym.sc)) 243898944Sobrien { 243998944Sobrien ms_type = mst_bss; 244098944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); 244198944Sobrien } 244298944Sobrien else if (SC_IS_SBSS (ext_in->asym.sc)) 244398944Sobrien { 244498944Sobrien ms_type = mst_bss; 244598944Sobrien svalue += ANOFFSET (objfile->section_offsets, 244698944Sobrien get_section_index (objfile, ".sbss")); 244798944Sobrien } 244898944Sobrien else 244998944Sobrien ms_type = mst_abs; 245098944Sobrien break; 245198944Sobrien case stLabel: 245298944Sobrien /* Label */ 245346283Sdfr 245498944Sobrien /* On certain platforms, some extra label symbols can be 245598944Sobrien generated by the linker. One possible usage for this kind 245698944Sobrien of symbols is to represent the address of the begining of a 245798944Sobrien given section. For instance, on Tru64 5.1, the address of 245898944Sobrien the _ftext label is the start address of the .text section. 245998944Sobrien 246098944Sobrien The storage class of these symbols is usually directly 246198944Sobrien related to the section to which the symbol refers. For 246298944Sobrien instance, on Tru64 5.1, the storage class for the _fdata 246398944Sobrien label is scData, refering to the .data section. 246498944Sobrien 246598944Sobrien It is actually possible that the section associated to the 246698944Sobrien storage class of the label does not exist. On True64 5.1 246798944Sobrien for instance, the libm.so shared library does not contain 246898944Sobrien any .data section, although it contains a _fpdata label 246998944Sobrien which storage class is scData... Since these symbols are 247098944Sobrien usually useless for the debugger user anyway, we just 247198944Sobrien discard these symbols. 247298944Sobrien */ 247398944Sobrien 247498944Sobrien if (SC_IS_TEXT (ext_in->asym.sc)) 247598944Sobrien { 247698944Sobrien if (objfile->sect_index_text == -1) 247798944Sobrien continue; 247898944Sobrien 247998944Sobrien ms_type = mst_file_text; 248098944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 248198944Sobrien } 248298944Sobrien else if (SC_IS_DATA (ext_in->asym.sc)) 248398944Sobrien { 248498944Sobrien if (objfile->sect_index_data == -1) 248598944Sobrien continue; 248698944Sobrien 248798944Sobrien ms_type = mst_file_data; 248898944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 248998944Sobrien } 249098944Sobrien else if (SC_IS_BSS (ext_in->asym.sc)) 249198944Sobrien { 249298944Sobrien if (objfile->sect_index_bss == -1) 249398944Sobrien continue; 249498944Sobrien 249598944Sobrien ms_type = mst_file_bss; 249698944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); 249798944Sobrien } 249898944Sobrien else if (SC_IS_SBSS (ext_in->asym.sc)) 249998944Sobrien { 250098944Sobrien const int sbss_sect_index = get_section_index (objfile, ".sbss"); 250198944Sobrien 250298944Sobrien if (sbss_sect_index == -1) 250398944Sobrien continue; 250498944Sobrien 250598944Sobrien ms_type = mst_file_bss; 250698944Sobrien svalue += ANOFFSET (objfile->section_offsets, sbss_sect_index); 250798944Sobrien } 250898944Sobrien else 250998944Sobrien ms_type = mst_abs; 251098944Sobrien break; 251198944Sobrien case stLocal: 251298944Sobrien case stNil: 251398944Sobrien /* The alpha has the section start addresses in stLocal symbols 251498944Sobrien whose name starts with a `.'. Skip those but complain for all 251598944Sobrien other stLocal symbols. 251698944Sobrien Irix6 puts the section start addresses in stNil symbols, skip 251798944Sobrien those too. */ 251898944Sobrien if (name[0] == '.') 251998944Sobrien continue; 252098944Sobrien /* Fall through. */ 252198944Sobrien default: 252298944Sobrien ms_type = mst_unknown; 2523130803Smarcel unknown_ext_complaint (name); 252498944Sobrien } 252598944Sobrien if (!ECOFF_IN_ELF (cur_bfd)) 252698944Sobrien prim_record_minimal_symbol (name, svalue, ms_type, objfile); 252798944Sobrien } 252898944Sobrien 252919370Spst /* Pass 3 over files, over local syms: fill in static symbols */ 253019370Spst for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) 253119370Spst { 253219370Spst struct partial_symtab *save_pst; 253319370Spst EXTR *ext_ptr; 253419370Spst CORE_ADDR textlow; 253519370Spst 253619370Spst cur_fdr = fh = debug_info->fdr + f_idx; 253719370Spst 253819370Spst if (fh->csym == 0) 253919370Spst { 254019370Spst fdr_to_pst[f_idx].pst = NULL; 254119370Spst continue; 254219370Spst } 254319370Spst 254419370Spst /* Determine the start address for this object file from the 254598944Sobrien file header and relocate it, except for Irix 5.2 zero fh->adr. */ 254619370Spst if (fh->cpd) 254719370Spst { 254819370Spst textlow = fh->adr; 254919370Spst if (relocatable || textlow != 0) 255098944Sobrien textlow += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 255119370Spst } 255219370Spst else 255319370Spst textlow = 0; 255498944Sobrien pst = start_psymtab_common (objfile, objfile->section_offsets, 255519370Spst fdr_name (fh), 255619370Spst textlow, 255719370Spst objfile->global_psymbols.next, 255819370Spst objfile->static_psymbols.next); 255919370Spst pst->read_symtab_private = ((char *) 2560130803Smarcel obstack_alloc (&objfile->objfile_obstack, 256119370Spst sizeof (struct symloc))); 256298944Sobrien memset (pst->read_symtab_private, 0, sizeof (struct symloc)); 256319370Spst 256419370Spst save_pst = pst; 256519370Spst FDR_IDX (pst) = f_idx; 256619370Spst CUR_BFD (pst) = cur_bfd; 256719370Spst DEBUG_SWAP (pst) = debug_swap; 256819370Spst DEBUG_INFO (pst) = debug_info; 256919370Spst PENDING_LIST (pst) = pending_list; 257019370Spst 257119370Spst /* The way to turn this into a symtab is to call... */ 257219370Spst pst->read_symtab = mdebug_psymtab_to_symtab; 257319370Spst 257419370Spst /* Set up language for the pst. 257519370Spst The language from the FDR is used if it is unambigious (e.g. cfront 257698944Sobrien with native cc and g++ will set the language to C). 257798944Sobrien Otherwise we have to deduce the language from the filename. 257898944Sobrien Native ecoff has every header file in a separate FDR, so 257998944Sobrien deduce_language_from_filename will return language_unknown for 258098944Sobrien a header file, which is not what we want. 258198944Sobrien But the FDRs for the header files are after the FDR for the source 258298944Sobrien file, so we can assign the language of the source file to the 258398944Sobrien following header files. Then we save the language in the private 258498944Sobrien pst data so that we can reuse it when building symtabs. */ 258519370Spst prev_language = psymtab_language; 258619370Spst 258719370Spst switch (fh->lang) 258819370Spst { 258919370Spst case langCplusplusV2: 259019370Spst psymtab_language = language_cplus; 259119370Spst break; 259219370Spst default: 259319370Spst psymtab_language = deduce_language_from_filename (fdr_name (fh)); 259419370Spst break; 259519370Spst } 259619370Spst if (psymtab_language == language_unknown) 259719370Spst psymtab_language = prev_language; 259819370Spst PST_PRIVATE (pst)->pst_language = psymtab_language; 259919370Spst 2600130803Smarcel pst->texthigh = pst->textlow; 260119370Spst 260219370Spst /* For stabs-in-ecoff files, the second symbol must be @stab. 260398944Sobrien This symbol is emitted by mips-tfile to signal that the 260498944Sobrien current object file uses encapsulated stabs instead of mips 260598944Sobrien ecoff for local symbols. (It is the second symbol because 260698944Sobrien the first symbol is the stFile used to signal the start of a 260798944Sobrien file). */ 260819370Spst processing_gcc_compilation = 0; 260919370Spst if (fh->csym >= 2) 261019370Spst { 261119370Spst (*swap_sym_in) (cur_bfd, 261219370Spst ((char *) debug_info->external_sym 261319370Spst + (fh->isymBase + 1) * external_sym_size), 261419370Spst &sh); 2615130803Smarcel if (strcmp (debug_info->ss + fh->issBase + sh.iss, 2616130803Smarcel stabs_symbol) == 0) 261719370Spst processing_gcc_compilation = 2; 261819370Spst } 261919370Spst 262019370Spst if (processing_gcc_compilation != 0) 262119370Spst { 262219370Spst for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) 262319370Spst { 262419370Spst int type_code; 262519370Spst char *namestring; 262619370Spst 262719370Spst (*swap_sym_in) (cur_bfd, 262819370Spst (((char *) debug_info->external_sym) 262998944Sobrien + (fh->isymBase + cur_sdx) * external_sym_size), 263019370Spst &sh); 263119370Spst type_code = ECOFF_UNMARK_STAB (sh.index); 263219370Spst if (!ECOFF_IS_STAB (&sh)) 263319370Spst { 263419370Spst if (sh.st == stProc || sh.st == stStaticProc) 263519370Spst { 263646283Sdfr CORE_ADDR procaddr; 263719370Spst long isym; 263898944Sobrien 263998944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 264019370Spst if (sh.st == stStaticProc) 264119370Spst { 264219370Spst namestring = debug_info->ss + fh->issBase + sh.iss; 264319370Spst prim_record_minimal_symbol_and_info (namestring, 264419370Spst sh.value, 264519370Spst mst_file_text, 264619370Spst NULL, 264798944Sobrien SECT_OFF_TEXT (objfile), 264846283Sdfr NULL, 264919370Spst objfile); 265019370Spst } 265119370Spst procaddr = sh.value; 265219370Spst 265319370Spst isym = AUX_GET_ISYM (fh->fBigendian, 265419370Spst (debug_info->external_aux 265519370Spst + fh->iauxBase 265619370Spst + sh.index)); 265719370Spst (*swap_sym_in) (cur_bfd, 265819370Spst ((char *) debug_info->external_sym 265919370Spst + ((fh->isymBase + isym - 1) 266019370Spst * external_sym_size)), 266119370Spst &sh); 266219370Spst if (sh.st == stEnd) 266319370Spst { 266446283Sdfr CORE_ADDR high = procaddr + sh.value; 266519370Spst 266698944Sobrien /* Kludge for Irix 5.2 zero fh->adr. */ 266719370Spst if (!relocatable 2668130803Smarcel && (pst->textlow == 0 || procaddr < pst->textlow)) 2669130803Smarcel pst->textlow = procaddr; 2670130803Smarcel if (high > pst->texthigh) 2671130803Smarcel pst->texthigh = high; 267219370Spst } 267319370Spst } 267419370Spst else if (sh.st == stStatic) 267519370Spst { 267619370Spst switch (sh.sc) 267719370Spst { 267819370Spst case scUndefined: 267946283Sdfr case scSUndefined: 268019370Spst case scNil: 268119370Spst case scAbs: 268219370Spst break; 268319370Spst 268419370Spst case scData: 268519370Spst case scSData: 268619370Spst case scRData: 268719370Spst case scPData: 268819370Spst case scXData: 268919370Spst namestring = debug_info->ss + fh->issBase + sh.iss; 269098944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 269119370Spst prim_record_minimal_symbol_and_info (namestring, 269219370Spst sh.value, 269319370Spst mst_file_data, 269419370Spst NULL, 269598944Sobrien SECT_OFF_DATA (objfile), 269646283Sdfr NULL, 269719370Spst objfile); 269819370Spst break; 269919370Spst 270019370Spst default: 270146283Sdfr /* FIXME! Shouldn't this use cases for bss, 270246283Sdfr then have the default be abs? */ 270319370Spst namestring = debug_info->ss + fh->issBase + sh.iss; 270498944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); 270519370Spst prim_record_minimal_symbol_and_info (namestring, 270619370Spst sh.value, 270719370Spst mst_file_bss, 270819370Spst NULL, 270998944Sobrien SECT_OFF_BSS (objfile), 271046283Sdfr NULL, 271119370Spst objfile); 271219370Spst break; 271319370Spst } 271419370Spst } 271519370Spst continue; 271619370Spst } 271746283Sdfr /* Handle stabs continuation */ 271846283Sdfr { 271946283Sdfr char *stabstring = debug_info->ss + fh->issBase + sh.iss; 272046283Sdfr int len = strlen (stabstring); 272198944Sobrien while (stabstring[len - 1] == '\\') 272246283Sdfr { 272346283Sdfr SYMR sh2; 272446283Sdfr char *stabstring1 = stabstring; 272546283Sdfr char *stabstring2; 272646283Sdfr int len2; 272746283Sdfr 272846283Sdfr /* Ignore continuation char from 1st string */ 272946283Sdfr len--; 273046283Sdfr 273146283Sdfr /* Read next stabstring */ 273246283Sdfr cur_sdx++; 273346283Sdfr (*swap_sym_in) (cur_bfd, 273446283Sdfr (((char *) debug_info->external_sym) 273598944Sobrien + (fh->isymBase + cur_sdx) 273646283Sdfr * external_sym_size), 273746283Sdfr &sh2); 273846283Sdfr stabstring2 = debug_info->ss + fh->issBase + sh2.iss; 273946283Sdfr len2 = strlen (stabstring2); 274046283Sdfr 274146283Sdfr /* Concatinate stabstring2 with stabstring1 */ 274246283Sdfr if (stabstring 274398944Sobrien && stabstring != debug_info->ss + fh->issBase + sh.iss) 274446283Sdfr stabstring = xrealloc (stabstring, len + len2 + 1); 274546283Sdfr else 274698944Sobrien { 274798944Sobrien stabstring = xmalloc (len + len2 + 1); 274898944Sobrien strcpy (stabstring, stabstring1); 274998944Sobrien } 275046283Sdfr strcpy (stabstring + len, stabstring2); 275146283Sdfr len += len2; 275246283Sdfr } 275346283Sdfr 275498944Sobrien switch (type_code) 275598944Sobrien { 275698944Sobrien char *p; 275798944Sobrien /* 275898944Sobrien * Standard, external, non-debugger, symbols 275998944Sobrien */ 276046283Sdfr 276198944Sobrien case N_TEXT | N_EXT: 276298944Sobrien case N_NBTEXT | N_EXT: 276398944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 276498944Sobrien goto record_it; 276598944Sobrien 276698944Sobrien case N_DATA | N_EXT: 276798944Sobrien case N_NBDATA | N_EXT: 276898944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 276998944Sobrien goto record_it; 277098944Sobrien 277198944Sobrien case N_BSS: 277298944Sobrien case N_BSS | N_EXT: 277398944Sobrien case N_NBBSS | N_EXT: 277498944Sobrien case N_SETV | N_EXT: /* FIXME, is this in BSS? */ 277598944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); 277698944Sobrien goto record_it; 277798944Sobrien 277898944Sobrien case N_ABS | N_EXT: 277998944Sobrien record_it: 278098944Sobrien continue; 278198944Sobrien 278298944Sobrien /* Standard, local, non-debugger, symbols */ 278398944Sobrien 278498944Sobrien case N_NBTEXT: 278598944Sobrien 278698944Sobrien /* We need to be able to deal with both N_FN or N_TEXT, 278798944Sobrien because we have no way of knowing whether the sys-supplied ld 278898944Sobrien or GNU ld was used to make the executable. Sequents throw 278998944Sobrien in another wrinkle -- they renumbered N_FN. */ 279098944Sobrien 279198944Sobrien case N_FN: 279298944Sobrien case N_FN_SEQ: 279398944Sobrien case N_TEXT: 279498944Sobrien continue; 279598944Sobrien 279698944Sobrien case N_DATA: 279798944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 279898944Sobrien goto record_it; 279998944Sobrien 280098944Sobrien case N_UNDF | N_EXT: 280198944Sobrien continue; /* Just undefined, not COMMON */ 280298944Sobrien 280398944Sobrien case N_UNDF: 280498944Sobrien continue; 280598944Sobrien 280698944Sobrien /* Lots of symbol types we can just ignore. */ 280798944Sobrien 280898944Sobrien case N_ABS: 280998944Sobrien case N_NBDATA: 281098944Sobrien case N_NBBSS: 281198944Sobrien continue; 281298944Sobrien 281398944Sobrien /* Keep going . . . */ 281498944Sobrien 281598944Sobrien /* 281698944Sobrien * Special symbol types for GNU 281798944Sobrien */ 281898944Sobrien case N_INDR: 281998944Sobrien case N_INDR | N_EXT: 282098944Sobrien case N_SETA: 282198944Sobrien case N_SETA | N_EXT: 282298944Sobrien case N_SETT: 282398944Sobrien case N_SETT | N_EXT: 282498944Sobrien case N_SETD: 282598944Sobrien case N_SETD | N_EXT: 282698944Sobrien case N_SETB: 282798944Sobrien case N_SETB | N_EXT: 282898944Sobrien case N_SETV: 282998944Sobrien continue; 283098944Sobrien 283198944Sobrien /* 283298944Sobrien * Debugger symbols 283398944Sobrien */ 283498944Sobrien 283598944Sobrien case N_SO: 283698944Sobrien { 283798944Sobrien CORE_ADDR valu; 283898944Sobrien static int prev_so_symnum = -10; 283998944Sobrien static int first_so_symnum; 284098944Sobrien char *p; 284198944Sobrien int prev_textlow_not_set; 284298944Sobrien 284398944Sobrien valu = sh.value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 284498944Sobrien 284598944Sobrien prev_textlow_not_set = textlow_not_set; 284698944Sobrien 284798944Sobrien#ifdef SOFUN_ADDRESS_MAYBE_MISSING 284898944Sobrien /* A zero value is probably an indication for the SunPRO 3.0 284998944Sobrien compiler. end_psymtab explicitly tests for zero, so 285098944Sobrien don't relocate it. */ 285198944Sobrien 285298944Sobrien if (sh.value == 0) 285398944Sobrien { 285498944Sobrien textlow_not_set = 1; 285598944Sobrien valu = 0; 285698944Sobrien } 285798944Sobrien else 285898944Sobrien textlow_not_set = 0; 285998944Sobrien#else 286098944Sobrien textlow_not_set = 0; 286198944Sobrien#endif 286298944Sobrien past_first_source_file = 1; 286398944Sobrien 286498944Sobrien if (prev_so_symnum != symnum - 1) 286598944Sobrien { /* Here if prev stab wasn't N_SO */ 286698944Sobrien first_so_symnum = symnum; 286798944Sobrien 286898944Sobrien if (pst) 286998944Sobrien { 287098944Sobrien pst = (struct partial_symtab *) 0; 287198944Sobrien includes_used = 0; 287298944Sobrien dependencies_used = 0; 287398944Sobrien } 287498944Sobrien } 287598944Sobrien 287698944Sobrien prev_so_symnum = symnum; 287798944Sobrien 287898944Sobrien /* End the current partial symtab and start a new one */ 287998944Sobrien 288098944Sobrien /* SET_NAMESTRING ();*/ 288198944Sobrien namestring = stabstring; 288298944Sobrien 288398944Sobrien /* Null name means end of .o file. Don't start a new one. */ 288498944Sobrien if (*namestring == '\000') 288598944Sobrien continue; 288698944Sobrien 288798944Sobrien /* Some compilers (including gcc) emit a pair of initial N_SOs. 288898944Sobrien The first one is a directory name; the second the file name. 288998944Sobrien If pst exists, is empty, and has a filename ending in '/', 289098944Sobrien we assume the previous N_SO was a directory name. */ 289198944Sobrien 289298944Sobrien p = strrchr (namestring, '/'); 289398944Sobrien if (p && *(p + 1) == '\000') 289498944Sobrien continue; /* Simply ignore directory name SOs */ 289598944Sobrien 289698944Sobrien /* Some other compilers (C++ ones in particular) emit useless 289798944Sobrien SOs for non-existant .c files. We ignore all subsequent SOs that 289898944Sobrien immediately follow the first. */ 289998944Sobrien 290098944Sobrien if (!pst) 290198944Sobrien pst = save_pst; 290298944Sobrien continue; 290398944Sobrien } 290498944Sobrien 290598944Sobrien case N_BINCL: 290698944Sobrien continue; 290798944Sobrien 290898944Sobrien case N_SOL: 290998944Sobrien { 291098944Sobrien enum language tmp_language; 291198944Sobrien /* Mark down an include file in the current psymtab */ 291298944Sobrien 291398944Sobrien /* SET_NAMESTRING ();*/ 291498944Sobrien namestring = stabstring; 291598944Sobrien 291698944Sobrien tmp_language = deduce_language_from_filename (namestring); 291798944Sobrien 291898944Sobrien /* Only change the psymtab's language if we've learned 291998944Sobrien something useful (eg. tmp_language is not language_unknown). 292098944Sobrien In addition, to match what start_subfile does, never change 292198944Sobrien from C++ to C. */ 292298944Sobrien if (tmp_language != language_unknown 292398944Sobrien && (tmp_language != language_c 292498944Sobrien || psymtab_language != language_cplus)) 292598944Sobrien psymtab_language = tmp_language; 292698944Sobrien 292798944Sobrien /* In C++, one may expect the same filename to come round many 292898944Sobrien times, when code is coming alternately from the main file 292998944Sobrien and from inline functions in other files. So I check to see 293098944Sobrien if this is a file we've seen before -- either the main 293198944Sobrien source file, or a previously included file. 293298944Sobrien 293398944Sobrien This seems to be a lot of time to be spending on N_SOL, but 293498944Sobrien things like "break c-exp.y:435" need to work (I 293598944Sobrien suppose the psymtab_include_list could be hashed or put 293698944Sobrien in a binary tree, if profiling shows this is a major hog). */ 2937130803Smarcel if (pst && strcmp (namestring, pst->filename) == 0) 293898944Sobrien continue; 293998944Sobrien { 2940130803Smarcel int i; 294198944Sobrien for (i = 0; i < includes_used; i++) 2942130803Smarcel if (strcmp (namestring, 2943130803Smarcel psymtab_include_list[i]) == 0) 294498944Sobrien { 294598944Sobrien i = -1; 294698944Sobrien break; 294798944Sobrien } 294898944Sobrien if (i == -1) 294998944Sobrien continue; 295098944Sobrien } 295198944Sobrien 295298944Sobrien psymtab_include_list[includes_used++] = namestring; 295398944Sobrien if (includes_used >= includes_allocated) 295498944Sobrien { 295598944Sobrien char **orig = psymtab_include_list; 295698944Sobrien 295798944Sobrien psymtab_include_list = (char **) 295898944Sobrien alloca ((includes_allocated *= 2) * 295998944Sobrien sizeof (char *)); 2960130803Smarcel memcpy (psymtab_include_list, orig, 296198944Sobrien includes_used * sizeof (char *)); 296298944Sobrien } 296398944Sobrien continue; 296498944Sobrien } 296598944Sobrien case N_LSYM: /* Typedef or automatic variable. */ 296698944Sobrien case N_STSYM: /* Data seg var -- static */ 296798944Sobrien case N_LCSYM: /* BSS " */ 296898944Sobrien case N_ROSYM: /* Read-only data seg var -- static. */ 296998944Sobrien case N_NBSTS: /* Gould nobase. */ 297098944Sobrien case N_NBLCS: /* symbols. */ 297198944Sobrien case N_FUN: 297298944Sobrien case N_GSYM: /* Global (extern) variable; can be 297398944Sobrien data or bss (sigh FIXME). */ 297498944Sobrien 297598944Sobrien /* Following may probably be ignored; I'll leave them here 297698944Sobrien for now (until I do Pascal and Modula 2 extensions). */ 297798944Sobrien 297898944Sobrien case N_PC: /* I may or may not need this; I 297998944Sobrien suspect not. */ 298098944Sobrien case N_M2C: /* I suspect that I can ignore this here. */ 298198944Sobrien case N_SCOPE: /* Same. */ 298298944Sobrien 298398944Sobrien /* SET_NAMESTRING ();*/ 298498944Sobrien namestring = stabstring; 298598944Sobrien p = (char *) strchr (namestring, ':'); 298698944Sobrien if (!p) 298798944Sobrien continue; /* Not a debugging symbol. */ 298898944Sobrien 298998944Sobrien 299098944Sobrien 299198944Sobrien /* Main processing section for debugging symbols which 299298944Sobrien the initial read through the symbol tables needs to worry 299398944Sobrien about. If we reach this point, the symbol which we are 299498944Sobrien considering is definitely one we are interested in. 299598944Sobrien p must also contain the (valid) index into the namestring 299698944Sobrien which indicates the debugging type symbol. */ 299798944Sobrien 299898944Sobrien switch (p[1]) 299998944Sobrien { 300098944Sobrien case 'S': 300198944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 300298944Sobrien#ifdef STATIC_TRANSFORM_NAME 300398944Sobrien namestring = STATIC_TRANSFORM_NAME (namestring); 300498944Sobrien#endif 300598944Sobrien add_psymbol_to_list (namestring, p - namestring, 3006130803Smarcel VAR_DOMAIN, LOC_STATIC, 300798944Sobrien &objfile->static_psymbols, 300898944Sobrien 0, sh.value, 300998944Sobrien psymtab_language, objfile); 301098944Sobrien continue; 301198944Sobrien case 'G': 301298944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 301398944Sobrien /* The addresses in these entries are reported to be 301498944Sobrien wrong. See the code that reads 'G's for symtabs. */ 301598944Sobrien add_psymbol_to_list (namestring, p - namestring, 3016130803Smarcel VAR_DOMAIN, LOC_STATIC, 301798944Sobrien &objfile->global_psymbols, 301898944Sobrien 0, sh.value, 301998944Sobrien psymtab_language, objfile); 302098944Sobrien continue; 302198944Sobrien 302298944Sobrien case 'T': 302398944Sobrien /* When a 'T' entry is defining an anonymous enum, it 302498944Sobrien may have a name which is the empty string, or a 302598944Sobrien single space. Since they're not really defining a 302698944Sobrien symbol, those shouldn't go in the partial symbol 302798944Sobrien table. We do pick up the elements of such enums at 302898944Sobrien 'check_enum:', below. */ 302998944Sobrien if (p >= namestring + 2 303098944Sobrien || (p == namestring + 1 303198944Sobrien && namestring[0] != ' ')) 303298944Sobrien { 303398944Sobrien add_psymbol_to_list (namestring, p - namestring, 3034130803Smarcel STRUCT_DOMAIN, LOC_TYPEDEF, 303598944Sobrien &objfile->static_psymbols, 303698944Sobrien sh.value, 0, 303798944Sobrien psymtab_language, objfile); 303898944Sobrien if (p[2] == 't') 303998944Sobrien { 304098944Sobrien /* Also a typedef with the same name. */ 304198944Sobrien add_psymbol_to_list (namestring, p - namestring, 3042130803Smarcel VAR_DOMAIN, LOC_TYPEDEF, 304398944Sobrien &objfile->static_psymbols, 304498944Sobrien sh.value, 0, 304598944Sobrien psymtab_language, objfile); 304698944Sobrien p += 1; 304798944Sobrien } 304898944Sobrien } 304998944Sobrien goto check_enum; 305098944Sobrien case 't': 305198944Sobrien if (p != namestring) /* a name is there, not just :T... */ 305298944Sobrien { 305398944Sobrien add_psymbol_to_list (namestring, p - namestring, 3054130803Smarcel VAR_DOMAIN, LOC_TYPEDEF, 305598944Sobrien &objfile->static_psymbols, 305698944Sobrien sh.value, 0, 305798944Sobrien psymtab_language, objfile); 305898944Sobrien } 305998944Sobrien check_enum: 306098944Sobrien /* If this is an enumerated type, we need to 306198944Sobrien add all the enum constants to the partial symbol 306298944Sobrien table. This does not cover enums without names, e.g. 306398944Sobrien "enum {a, b} c;" in C, but fortunately those are 306498944Sobrien rare. There is no way for GDB to find those from the 306598944Sobrien enum type without spending too much time on it. Thus 306698944Sobrien to solve this problem, the compiler needs to put out the 306798944Sobrien enum in a nameless type. GCC2 does this. */ 306898944Sobrien 306998944Sobrien /* We are looking for something of the form 307098944Sobrien <name> ":" ("t" | "T") [<number> "="] "e" 307198944Sobrien {<constant> ":" <value> ","} ";". */ 307298944Sobrien 307398944Sobrien /* Skip over the colon and the 't' or 'T'. */ 307498944Sobrien p += 2; 307598944Sobrien /* This type may be given a number. Also, numbers can come 307698944Sobrien in pairs like (0,26). Skip over it. */ 307798944Sobrien while ((*p >= '0' && *p <= '9') 307898944Sobrien || *p == '(' || *p == ',' || *p == ')' 307998944Sobrien || *p == '=') 308098944Sobrien p++; 308198944Sobrien 308298944Sobrien if (*p++ == 'e') 308398944Sobrien { 308498944Sobrien /* The aix4 compiler emits extra crud before the members. */ 308598944Sobrien if (*p == '-') 308698944Sobrien { 308798944Sobrien /* Skip over the type (?). */ 308898944Sobrien while (*p != ':') 308998944Sobrien p++; 309098944Sobrien 309198944Sobrien /* Skip over the colon. */ 309298944Sobrien p++; 309398944Sobrien } 309498944Sobrien 309598944Sobrien /* We have found an enumerated type. */ 309698944Sobrien /* According to comments in read_enum_type 309798944Sobrien a comma could end it instead of a semicolon. 309898944Sobrien I don't know where that happens. 309998944Sobrien Accept either. */ 310098944Sobrien while (*p && *p != ';' && *p != ',') 310198944Sobrien { 310298944Sobrien char *q; 310398944Sobrien 310498944Sobrien /* Check for and handle cretinous dbx symbol name 310598944Sobrien continuation! */ 310698944Sobrien if (*p == '\\' || (*p == '?' && p[1] == '\0')) 310798944Sobrien p = next_symbol_text (objfile); 310898944Sobrien 310998944Sobrien /* Point to the character after the name 311098944Sobrien of the enum constant. */ 311198944Sobrien for (q = p; *q && *q != ':'; q++) 311298944Sobrien ; 311398944Sobrien /* Note that the value doesn't matter for 311498944Sobrien enum constants in psymtabs, just in symtabs. */ 311598944Sobrien add_psymbol_to_list (p, q - p, 3116130803Smarcel VAR_DOMAIN, LOC_CONST, 311798944Sobrien &objfile->static_psymbols, 0, 311898944Sobrien 0, psymtab_language, objfile); 311998944Sobrien /* Point past the name. */ 312098944Sobrien p = q; 312198944Sobrien /* Skip over the value. */ 312298944Sobrien while (*p && *p != ',') 312398944Sobrien p++; 312498944Sobrien /* Advance past the comma. */ 312598944Sobrien if (*p) 312698944Sobrien p++; 312798944Sobrien } 312898944Sobrien } 312998944Sobrien continue; 313098944Sobrien case 'c': 313198944Sobrien /* Constant, e.g. from "const" in Pascal. */ 313298944Sobrien add_psymbol_to_list (namestring, p - namestring, 3133130803Smarcel VAR_DOMAIN, LOC_CONST, 313498944Sobrien &objfile->static_psymbols, sh.value, 313598944Sobrien 0, psymtab_language, objfile); 313698944Sobrien continue; 313798944Sobrien 313898944Sobrien case 'f': 313998944Sobrien if (! pst) 314098944Sobrien { 314198944Sobrien int name_len = p - namestring; 314298944Sobrien char *name = xmalloc (name_len + 1); 314398944Sobrien memcpy (name, namestring, name_len); 314498944Sobrien name[name_len] = '\0'; 3145130803Smarcel function_outside_compilation_unit_complaint (name); 314698944Sobrien xfree (name); 314798944Sobrien } 314898944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 314998944Sobrien add_psymbol_to_list (namestring, p - namestring, 3150130803Smarcel VAR_DOMAIN, LOC_BLOCK, 315198944Sobrien &objfile->static_psymbols, 315298944Sobrien 0, sh.value, 315398944Sobrien psymtab_language, objfile); 315498944Sobrien continue; 315598944Sobrien 315698944Sobrien /* Global functions were ignored here, but now they 315798944Sobrien are put into the global psymtab like one would expect. 315898944Sobrien They're also in the minimal symbol table. */ 315998944Sobrien case 'F': 316098944Sobrien if (! pst) 316198944Sobrien { 316298944Sobrien int name_len = p - namestring; 316398944Sobrien char *name = xmalloc (name_len + 1); 316498944Sobrien memcpy (name, namestring, name_len); 316598944Sobrien name[name_len] = '\0'; 3166130803Smarcel function_outside_compilation_unit_complaint (name); 316798944Sobrien xfree (name); 316898944Sobrien } 316998944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 317098944Sobrien add_psymbol_to_list (namestring, p - namestring, 3171130803Smarcel VAR_DOMAIN, LOC_BLOCK, 317298944Sobrien &objfile->global_psymbols, 317398944Sobrien 0, sh.value, 317498944Sobrien psymtab_language, objfile); 317598944Sobrien continue; 317698944Sobrien 317798944Sobrien /* Two things show up here (hopefully); static symbols of 317898944Sobrien local scope (static used inside braces) or extensions 317998944Sobrien of structure symbols. We can ignore both. */ 318098944Sobrien case 'V': 318198944Sobrien case '(': 318298944Sobrien case '0': 318398944Sobrien case '1': 318498944Sobrien case '2': 318598944Sobrien case '3': 318698944Sobrien case '4': 318798944Sobrien case '5': 318898944Sobrien case '6': 318998944Sobrien case '7': 319098944Sobrien case '8': 319198944Sobrien case '9': 319298944Sobrien case '-': 319398944Sobrien case '#': /* for symbol identification (used in live ranges) */ 319498944Sobrien continue; 319598944Sobrien 319698944Sobrien case ':': 319798944Sobrien /* It is a C++ nested symbol. We don't need to record it 319898944Sobrien (I don't think); if we try to look up foo::bar::baz, 319998944Sobrien then symbols for the symtab containing foo should get 320098944Sobrien read in, I think. */ 320198944Sobrien /* Someone says sun cc puts out symbols like 320298944Sobrien /foo/baz/maclib::/usr/local/bin/maclib, 320398944Sobrien which would get here with a symbol type of ':'. */ 320498944Sobrien continue; 320598944Sobrien 320698944Sobrien default: 320798944Sobrien /* Unexpected symbol descriptor. The second and subsequent stabs 320898944Sobrien of a continued stab can show up here. The question is 320998944Sobrien whether they ever can mimic a normal stab--it would be 321098944Sobrien nice if not, since we certainly don't want to spend the 321198944Sobrien time searching to the end of every string looking for 321298944Sobrien a backslash. */ 321398944Sobrien 3214130803Smarcel complaint (&symfile_complaints, 3215130803Smarcel "unknown symbol descriptor `%c'", p[1]); 321698944Sobrien 321798944Sobrien /* Ignore it; perhaps it is an extension that we don't 321898944Sobrien know about. */ 321998944Sobrien continue; 322098944Sobrien } 322198944Sobrien 322298944Sobrien case N_EXCL: 322398944Sobrien continue; 322498944Sobrien 322598944Sobrien case N_ENDM: 322698944Sobrien#ifdef SOFUN_ADDRESS_MAYBE_MISSING 3227130803Smarcel /* Solaris 2 end of module, finish current partial 3228130803Smarcel symbol table. END_PSYMTAB will set 3229130803Smarcel pst->texthigh to the proper value, which is 3230130803Smarcel necessary if a module compiled without 3231130803Smarcel debugging info follows this module. */ 323298944Sobrien if (pst) 323398944Sobrien { 323498944Sobrien pst = (struct partial_symtab *) 0; 323598944Sobrien includes_used = 0; 323698944Sobrien dependencies_used = 0; 323798944Sobrien } 323898944Sobrien#endif 323998944Sobrien continue; 324098944Sobrien 324198944Sobrien case N_RBRAC: 3242130803Smarcel if (sh.value > save_pst->texthigh) 3243130803Smarcel save_pst->texthigh = sh.value; 324498944Sobrien continue; 324598944Sobrien case N_EINCL: 324698944Sobrien case N_DSLINE: 324798944Sobrien case N_BSLINE: 324898944Sobrien case N_SSYM: /* Claim: Structure or union element. 324998944Sobrien Hopefully, I can ignore this. */ 325098944Sobrien case N_ENTRY: /* Alternate entry point; can ignore. */ 325198944Sobrien case N_MAIN: /* Can definitely ignore this. */ 325298944Sobrien case N_CATCH: /* These are GNU C++ extensions */ 325398944Sobrien case N_EHDECL: /* that can safely be ignored here. */ 325498944Sobrien case N_LENG: 325598944Sobrien case N_BCOMM: 325698944Sobrien case N_ECOMM: 325798944Sobrien case N_ECOML: 325898944Sobrien case N_FNAME: 325998944Sobrien case N_SLINE: 326098944Sobrien case N_RSYM: 326198944Sobrien case N_PSYM: 326298944Sobrien case N_LBRAC: 326398944Sobrien case N_NSYMS: /* Ultrix 4.0: symbol count */ 326498944Sobrien case N_DEFD: /* GNU Modula-2 */ 326598944Sobrien case N_ALIAS: /* SunPro F77: alias name, ignore for now. */ 326698944Sobrien 326798944Sobrien case N_OBJ: /* useless types from Solaris */ 326898944Sobrien case N_OPT: 326998944Sobrien /* These symbols aren't interesting; don't worry about them */ 327098944Sobrien 327198944Sobrien continue; 327298944Sobrien 327398944Sobrien default: 327498944Sobrien /* If we haven't found it yet, ignore it. It's probably some 327598944Sobrien new type we don't know about yet. */ 3276130803Smarcel complaint (&symfile_complaints, "unknown symbol type %s", 3277130803Smarcel local_hex_string (type_code)); /*CUR_SYMBOL_TYPE*/ 327898944Sobrien continue; 327998944Sobrien } 328098944Sobrien if (stabstring 328146283Sdfr && stabstring != debug_info->ss + fh->issBase + sh.iss) 328298944Sobrien xfree (stabstring); 328346283Sdfr } 328498944Sobrien /* end - Handle continuation */ 328519370Spst } 328619370Spst } 328719370Spst else 328819370Spst { 328919370Spst for (cur_sdx = 0; cur_sdx < fh->csym;) 329019370Spst { 329119370Spst char *name; 329219370Spst enum address_class class; 329319370Spst 329419370Spst (*swap_sym_in) (cur_bfd, 329519370Spst ((char *) debug_info->external_sym 329619370Spst + ((fh->isymBase + cur_sdx) 329719370Spst * external_sym_size)), 329819370Spst &sh); 329919370Spst 330019370Spst if (ECOFF_IS_STAB (&sh)) 330119370Spst { 330219370Spst cur_sdx++; 330319370Spst continue; 330419370Spst } 330519370Spst 330619370Spst /* Non absolute static symbols go into the minimal table. */ 330798944Sobrien if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil 330819370Spst || (sh.index == indexNil 330919370Spst && (sh.st != stStatic || sh.sc == scAbs))) 331019370Spst { 331119370Spst /* FIXME, premature? */ 331219370Spst cur_sdx++; 331319370Spst continue; 331419370Spst } 331519370Spst 331619370Spst name = debug_info->ss + fh->issBase + sh.iss; 331719370Spst 331819370Spst switch (sh.sc) 331919370Spst { 332019370Spst case scText: 332146283Sdfr case scRConst: 332219370Spst /* The value of a stEnd symbol is the displacement from the 332319370Spst corresponding start symbol value, do not relocate it. */ 332419370Spst if (sh.st != stEnd) 332598944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 332619370Spst break; 332719370Spst case scData: 332819370Spst case scSData: 332919370Spst case scRData: 333019370Spst case scPData: 333119370Spst case scXData: 333298944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 333319370Spst break; 333419370Spst case scBss: 333519370Spst case scSBss: 333698944Sobrien sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); 333719370Spst break; 333819370Spst } 333919370Spst 334019370Spst switch (sh.st) 334119370Spst { 334246283Sdfr CORE_ADDR high; 334346283Sdfr CORE_ADDR procaddr; 334419370Spst int new_sdx; 334519370Spst 334619370Spst case stStaticProc: 334719370Spst prim_record_minimal_symbol_and_info (name, sh.value, 334819370Spst mst_file_text, NULL, 334998944Sobrien SECT_OFF_TEXT (objfile), NULL, 335046283Sdfr objfile); 335119370Spst 335219370Spst /* FALLTHROUGH */ 335319370Spst 335419370Spst case stProc: 3355130803Smarcel /* Ignore all parameter symbol records. */ 3356130803Smarcel if (sh.index >= hdr->iauxMax) 3357130803Smarcel { 3358130803Smarcel /* Should not happen, but does when cross-compiling 3359130803Smarcel with the MIPS compiler. FIXME -- pull later. */ 3360130803Smarcel index_complaint (name); 3361130803Smarcel new_sdx = cur_sdx + 1; /* Don't skip at all */ 3362130803Smarcel } 3363130803Smarcel else 3364130803Smarcel new_sdx = AUX_GET_ISYM (fh->fBigendian, 3365130803Smarcel (debug_info->external_aux 3366130803Smarcel + fh->iauxBase 3367130803Smarcel + sh.index)); 3368130803Smarcel 3369130803Smarcel if (new_sdx <= cur_sdx) 3370130803Smarcel { 3371130803Smarcel /* This should not happen either... FIXME. */ 3372130803Smarcel complaint (&symfile_complaints, 3373130803Smarcel "bad proc end in aux found from symbol %s", 3374130803Smarcel name); 3375130803Smarcel new_sdx = cur_sdx + 1; /* Don't skip backward */ 3376130803Smarcel } 3377130803Smarcel 3378130803Smarcel /* For stProc symbol records, we need to check the 3379130803Smarcel storage class as well, as only (stProc, scText) 3380130803Smarcel entries represent "real" procedures - See the 3381130803Smarcel Compaq document titled "Object File / Symbol Table 3382130803Smarcel Format Specification" for more information. If the 3383130803Smarcel storage class is not scText, we discard the whole 3384130803Smarcel block of symbol records for this stProc. */ 3385130803Smarcel if (sh.st == stProc && sh.sc != scText) 3386130803Smarcel goto skip; 3387130803Smarcel 338819370Spst /* Usually there is a local and a global stProc symbol 338919370Spst for a function. This means that the function name 339019370Spst has already been entered into the mimimal symbol table 339119370Spst while processing the global symbols in pass 2 above. 339219370Spst One notable exception is the PROGRAM name from 339319370Spst f77 compiled executables, it is only put out as 339419370Spst local stProc symbol, and a global MAIN__ stProc symbol 339519370Spst points to it. It doesn't matter though, as gdb is 339619370Spst still able to find the PROGRAM name via the partial 339719370Spst symbol table, and the MAIN__ symbol via the minimal 339819370Spst symbol table. */ 339919370Spst if (sh.st == stProc) 340019370Spst add_psymbol_to_list (name, strlen (name), 3401130803Smarcel VAR_DOMAIN, LOC_BLOCK, 340219370Spst &objfile->global_psymbols, 340398944Sobrien 0, sh.value, psymtab_language, objfile); 340419370Spst else 340519370Spst add_psymbol_to_list (name, strlen (name), 3406130803Smarcel VAR_DOMAIN, LOC_BLOCK, 340719370Spst &objfile->static_psymbols, 340898944Sobrien 0, sh.value, psymtab_language, objfile); 340919370Spst 341019370Spst procaddr = sh.value; 341119370Spst 341219370Spst cur_sdx = new_sdx; 341319370Spst (*swap_sym_in) (cur_bfd, 341419370Spst ((char *) debug_info->external_sym 341519370Spst + ((fh->isymBase + cur_sdx - 1) 341619370Spst * external_sym_size)), 341719370Spst &sh); 341819370Spst if (sh.st != stEnd) 341919370Spst continue; 342019370Spst 342119370Spst /* Kludge for Irix 5.2 zero fh->adr. */ 342219370Spst if (!relocatable 3423130803Smarcel && (pst->textlow == 0 || procaddr < pst->textlow)) 3424130803Smarcel pst->textlow = procaddr; 342519370Spst 342619370Spst high = procaddr + sh.value; 3427130803Smarcel if (high > pst->texthigh) 3428130803Smarcel pst->texthigh = high; 342919370Spst continue; 343019370Spst 343119370Spst case stStatic: /* Variable */ 343298944Sobrien if (SC_IS_DATA (sh.sc)) 343319370Spst prim_record_minimal_symbol_and_info (name, sh.value, 343419370Spst mst_file_data, NULL, 343598944Sobrien SECT_OFF_DATA (objfile), 343646283Sdfr NULL, 343719370Spst objfile); 343819370Spst else 343919370Spst prim_record_minimal_symbol_and_info (name, sh.value, 344019370Spst mst_file_bss, NULL, 344198944Sobrien SECT_OFF_BSS (objfile), 344246283Sdfr NULL, 344319370Spst objfile); 344419370Spst class = LOC_STATIC; 344519370Spst break; 344619370Spst 344798944Sobrien case stIndirect: /* Irix5 forward declaration */ 344819370Spst /* Skip forward declarations from Irix5 cc */ 344919370Spst goto skip; 345019370Spst 345198944Sobrien case stTypedef: /* Typedef */ 345219370Spst /* Skip typedefs for forward declarations and opaque 345319370Spst structs from alpha and mips cc. */ 345419370Spst if (sh.iss == 0 || has_opaque_xref (fh, &sh)) 345519370Spst goto skip; 345619370Spst class = LOC_TYPEDEF; 345719370Spst break; 345819370Spst 345919370Spst case stConstant: /* Constant decl */ 346019370Spst class = LOC_CONST; 346119370Spst break; 346219370Spst 346319370Spst case stUnion: 346419370Spst case stStruct: 346519370Spst case stEnum: 346698944Sobrien case stBlock: /* { }, str, un, enum */ 346719370Spst /* Do not create a partial symbol for cc unnamed aggregates 346819370Spst and gcc empty aggregates. */ 346919370Spst if ((sh.sc == scInfo 347098944Sobrien || SC_IS_COMMON (sh.sc)) 347119370Spst && sh.iss != 0 347219370Spst && sh.index != cur_sdx + 2) 347319370Spst { 347419370Spst add_psymbol_to_list (name, strlen (name), 3475130803Smarcel STRUCT_DOMAIN, LOC_TYPEDEF, 347619370Spst &objfile->static_psymbols, 347746283Sdfr 0, (CORE_ADDR) 0, 347819370Spst psymtab_language, objfile); 347919370Spst } 348019370Spst handle_psymbol_enumerators (objfile, fh, sh.st, sh.value); 348119370Spst 348219370Spst /* Skip over the block */ 348319370Spst new_sdx = sh.index; 348419370Spst if (new_sdx <= cur_sdx) 348519370Spst { 348619370Spst /* This happens with the Ultrix kernel. */ 3487130803Smarcel complaint (&symfile_complaints, 3488130803Smarcel "bad aux index at block symbol %s", name); 348919370Spst new_sdx = cur_sdx + 1; /* Don't skip backward */ 349019370Spst } 349119370Spst cur_sdx = new_sdx; 349219370Spst continue; 349319370Spst 349419370Spst case stFile: /* File headers */ 349519370Spst case stLabel: /* Labels */ 349619370Spst case stEnd: /* Ends of files */ 349719370Spst goto skip; 349819370Spst 349919370Spst case stLocal: /* Local variables */ 350019370Spst /* Normally these are skipped because we skip over 350119370Spst all blocks we see. However, these can occur 350219370Spst as visible symbols in a .h file that contains code. */ 350319370Spst goto skip; 350419370Spst 350519370Spst default: 350619370Spst /* Both complaints are valid: one gives symbol name, 350719370Spst the other the offending symbol type. */ 3508130803Smarcel complaint (&symfile_complaints, "unknown local symbol %s", 3509130803Smarcel name); 3510130803Smarcel complaint (&symfile_complaints, "with type %d", sh.st); 351119370Spst cur_sdx++; 351219370Spst continue; 351319370Spst } 351419370Spst /* Use this gdb symbol */ 351519370Spst add_psymbol_to_list (name, strlen (name), 3516130803Smarcel VAR_DOMAIN, class, 351746283Sdfr &objfile->static_psymbols, 351846283Sdfr 0, sh.value, psymtab_language, objfile); 351919370Spst skip: 352019370Spst cur_sdx++; /* Go to next file symbol */ 352119370Spst } 352219370Spst 352319370Spst /* Now do enter the external symbols. */ 352419370Spst ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset]; 352519370Spst cur_sdx = fdr_to_pst[f_idx].n_globals; 352619370Spst PST_PRIVATE (save_pst)->extern_count = cur_sdx; 352719370Spst PST_PRIVATE (save_pst)->extern_tab = ext_ptr; 352819370Spst for (; --cur_sdx >= 0; ext_ptr++) 352919370Spst { 353019370Spst enum address_class class; 353119370Spst SYMR *psh; 353219370Spst char *name; 353319370Spst CORE_ADDR svalue; 353419370Spst 353519370Spst if (ext_ptr->ifd != f_idx) 353698944Sobrien internal_error (__FILE__, __LINE__, "failed internal consistency check"); 353719370Spst psh = &ext_ptr->asym; 353819370Spst 353919370Spst /* Do not add undefined symbols to the partial symbol table. */ 354098944Sobrien if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil) 354119370Spst continue; 354219370Spst 354319370Spst svalue = psh->value; 354419370Spst switch (psh->sc) 354519370Spst { 354619370Spst case scText: 354746283Sdfr case scRConst: 354898944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 354919370Spst break; 355019370Spst case scData: 355119370Spst case scSData: 355219370Spst case scRData: 355319370Spst case scPData: 355419370Spst case scXData: 355598944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 355619370Spst break; 355719370Spst case scBss: 355819370Spst case scSBss: 355998944Sobrien svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); 356019370Spst break; 356119370Spst } 356219370Spst 356319370Spst switch (psh->st) 356419370Spst { 356519370Spst case stNil: 356619370Spst /* These are generated for static symbols in .o files, 356719370Spst ignore them. */ 356819370Spst continue; 356919370Spst case stProc: 357019370Spst case stStaticProc: 357119370Spst /* External procedure symbols have been entered 357219370Spst into the minimal symbol table in pass 2 above. 357319370Spst Ignore them, as parse_external will ignore them too. */ 357419370Spst continue; 357519370Spst case stLabel: 357619370Spst class = LOC_LABEL; 357719370Spst break; 357819370Spst default: 3579130803Smarcel unknown_ext_complaint (debug_info->ssext + psh->iss); 358019370Spst /* Fall through, pretend it's global. */ 358119370Spst case stGlobal: 358219370Spst /* Global common symbols are resolved by the runtime loader, 358319370Spst ignore them. */ 358498944Sobrien if (SC_IS_COMMON (psh->sc)) 358519370Spst continue; 358619370Spst 358719370Spst class = LOC_STATIC; 358819370Spst break; 358919370Spst } 359019370Spst name = debug_info->ssext + psh->iss; 359119370Spst add_psymbol_to_list (name, strlen (name), 3592130803Smarcel VAR_DOMAIN, class, 359319370Spst &objfile->global_psymbols, 359419370Spst 0, svalue, 359519370Spst psymtab_language, objfile); 359619370Spst } 359719370Spst } 359819370Spst 359919370Spst /* Link pst to FDR. end_psymtab returns NULL if the psymtab was 360098944Sobrien empty and put on the free list. */ 360119370Spst fdr_to_pst[f_idx].pst = end_psymtab (save_pst, 360298944Sobrien psymtab_include_list, includes_used, 3603130803Smarcel -1, save_pst->texthigh, 360498944Sobrien dependency_list, dependencies_used, textlow_not_set); 360519370Spst includes_used = 0; 360619370Spst dependencies_used = 0; 360719370Spst 3608130803Smarcel if (objfile->ei.entry_point >= save_pst->textlow && 3609130803Smarcel objfile->ei.entry_point < save_pst->texthigh) 361019370Spst { 3611130803Smarcel objfile->ei.deprecated_entry_file_lowpc = save_pst->textlow; 3612130803Smarcel objfile->ei.deprecated_entry_file_highpc = save_pst->texthigh; 361319370Spst } 361419370Spst 361519370Spst /* The objfile has its functions reordered if this partial symbol 361698944Sobrien table overlaps any other partial symbol table. 361798944Sobrien We cannot assume a reordered objfile if a partial symbol table 361898944Sobrien is contained within another partial symbol table, as partial symbol 361998944Sobrien tables for include files with executable code are contained 362098944Sobrien within the partial symbol table for the including source file, 362198944Sobrien and we do not want to flag the objfile reordered for these cases. 362219370Spst 362398944Sobrien This strategy works well for Irix-5.2 shared libraries, but we 362498944Sobrien might have to use a more elaborate (and slower) algorithm for 362598944Sobrien other cases. */ 362619370Spst save_pst = fdr_to_pst[f_idx].pst; 362719370Spst if (save_pst != NULL 3628130803Smarcel && save_pst->textlow != 0 362919370Spst && !(objfile->flags & OBJF_REORDERED)) 363019370Spst { 363119370Spst ALL_OBJFILE_PSYMTABS (objfile, pst) 363298944Sobrien { 363398944Sobrien if (save_pst != pst 3634130803Smarcel && save_pst->textlow >= pst->textlow 3635130803Smarcel && save_pst->textlow < pst->texthigh 3636130803Smarcel && save_pst->texthigh > pst->texthigh) 363798944Sobrien { 363898944Sobrien objfile->flags |= OBJF_REORDERED; 363998944Sobrien break; 364098944Sobrien } 364198944Sobrien } 364219370Spst } 364319370Spst } 364419370Spst 364519370Spst /* Now scan the FDRs for dependencies */ 364619370Spst for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) 364719370Spst { 364819370Spst fh = f_idx + debug_info->fdr; 364919370Spst pst = fdr_to_pst[f_idx].pst; 365019370Spst 365198944Sobrien if (pst == (struct partial_symtab *) NULL) 365219370Spst continue; 365319370Spst 365419370Spst /* This should catch stabs-in-ecoff. */ 365519370Spst if (fh->crfd <= 1) 365619370Spst continue; 365719370Spst 365819370Spst /* Skip the first file indirect entry as it is a self dependency 365998944Sobrien for source files or a reverse .h -> .c dependency for header files. */ 366019370Spst pst->number_of_dependencies = 0; 366119370Spst pst->dependencies = 366219370Spst ((struct partial_symtab **) 3663130803Smarcel obstack_alloc (&objfile->objfile_obstack, 366419370Spst ((fh->crfd - 1) 366519370Spst * sizeof (struct partial_symtab *)))); 366619370Spst for (s_idx = 1; s_idx < fh->crfd; s_idx++) 366719370Spst { 366819370Spst RFDT rh; 366919370Spst 367019370Spst (*swap_rfd_in) (cur_bfd, 367119370Spst ((char *) debug_info->external_rfd 367219370Spst + (fh->rfdBase + s_idx) * external_rfd_size), 367319370Spst &rh); 367419370Spst if (rh < 0 || rh >= hdr->ifdMax) 367519370Spst { 3676130803Smarcel complaint (&symfile_complaints, "bad file number %ld", rh); 367719370Spst continue; 367819370Spst } 367919370Spst 368019370Spst /* Skip self dependencies of header files. */ 368119370Spst if (rh == f_idx) 368219370Spst continue; 368319370Spst 368419370Spst /* Do not add to dependeny list if psymtab was empty. */ 368598944Sobrien if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL) 368619370Spst continue; 368719370Spst pst->dependencies[pst->number_of_dependencies++] = fdr_to_pst[rh].pst; 368819370Spst } 368919370Spst } 369019370Spst 369119370Spst /* Remove the dummy psymtab created for -O3 images above, if it is 369219370Spst still empty, to enable the detection of stripped executables. */ 369319370Spst if (objfile->psymtabs->next == NULL 369419370Spst && objfile->psymtabs->number_of_dependencies == 0 369519370Spst && objfile->psymtabs->n_global_syms == 0 369619370Spst && objfile->psymtabs->n_static_syms == 0) 369719370Spst objfile->psymtabs = NULL; 369819370Spst do_cleanups (old_chain); 369919370Spst} 370019370Spst 370119370Spst/* If the current psymbol has an enumerated type, we need to add 370219370Spst all the the enum constants to the partial symbol table. */ 370319370Spst 370419370Spststatic void 370598944Sobrienhandle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype, 370698944Sobrien CORE_ADDR svalue) 370719370Spst{ 370819370Spst const bfd_size_type external_sym_size = debug_swap->external_sym_size; 370998944Sobrien void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in; 371019370Spst char *ext_sym = ((char *) debug_info->external_sym 371198944Sobrien + ((fh->isymBase + cur_sdx + 1) * external_sym_size)); 371219370Spst SYMR sh; 371319370Spst TIR tir; 371419370Spst 371519370Spst switch (stype) 371619370Spst { 371719370Spst case stEnum: 371819370Spst break; 371919370Spst 372019370Spst case stBlock: 372119370Spst /* It is an enumerated type if the next symbol entry is a stMember 372298944Sobrien and its auxiliary index is indexNil or its auxiliary entry 372398944Sobrien is a plain btNil or btVoid. 372498944Sobrien Alpha cc -migrate enums are recognized by a zero index and 372598944Sobrien a zero symbol value. 372698944Sobrien DU 4.0 cc enums are recognized by a member type of btEnum without 372798944Sobrien qualifiers and a zero symbol value. */ 372819370Spst (*swap_sym_in) (cur_bfd, ext_sym, &sh); 372919370Spst if (sh.st != stMember) 373019370Spst return; 373119370Spst 373219370Spst if (sh.index == indexNil 373319370Spst || (sh.index == 0 && svalue == 0)) 373419370Spst break; 373519370Spst (*debug_swap->swap_tir_in) (fh->fBigendian, 373619370Spst &(debug_info->external_aux 373719370Spst + fh->iauxBase + sh.index)->a_ti, 373819370Spst &tir); 373946283Sdfr if ((tir.bt != btNil 374046283Sdfr && tir.bt != btVoid 374146283Sdfr && (tir.bt != btEnum || svalue != 0)) 374246283Sdfr || tir.tq0 != tqNil) 374319370Spst return; 374419370Spst break; 374519370Spst 374619370Spst default: 374719370Spst return; 374819370Spst } 374919370Spst 375019370Spst for (;;) 375119370Spst { 375219370Spst char *name; 375319370Spst 375419370Spst (*swap_sym_in) (cur_bfd, ext_sym, &sh); 375519370Spst if (sh.st != stMember) 375619370Spst break; 375719370Spst name = debug_info->ss + cur_fdr->issBase + sh.iss; 375819370Spst 375919370Spst /* Note that the value doesn't matter for enum constants 376098944Sobrien in psymtabs, just in symtabs. */ 376119370Spst add_psymbol_to_list (name, strlen (name), 3762130803Smarcel VAR_DOMAIN, LOC_CONST, 376319370Spst &objfile->static_psymbols, 0, 376446283Sdfr (CORE_ADDR) 0, psymtab_language, objfile); 376519370Spst ext_sym += external_sym_size; 376619370Spst } 376719370Spst} 376819370Spst 376998944Sobrien/* Get the next symbol. OBJFILE is unused. */ 377098944Sobrien 377119370Spststatic char * 377298944Sobrienmdebug_next_symbol_text (struct objfile *objfile) 377319370Spst{ 377419370Spst SYMR sh; 377519370Spst 377619370Spst cur_sdx++; 377719370Spst (*debug_swap->swap_sym_in) (cur_bfd, 377819370Spst ((char *) debug_info->external_sym 377919370Spst + ((cur_fdr->isymBase + cur_sdx) 378019370Spst * debug_swap->external_sym_size)), 378119370Spst &sh); 378219370Spst return debug_info->ss + cur_fdr->issBase + sh.iss; 378319370Spst} 378419370Spst 378519370Spst/* Ancillary function to psymtab_to_symtab(). Does all the work 378619370Spst for turning the partial symtab PST into a symtab, recurring 378719370Spst first on all dependent psymtabs. The argument FILENAME is 378819370Spst only passed so we can see in debug stack traces what file 378919370Spst is being read. 379019370Spst 379119370Spst This function has a split personality, based on whether the 379219370Spst symbol table contains ordinary ecoff symbols, or stabs-in-ecoff. 379319370Spst The flow of control and even the memory allocation differs. FIXME. */ 379419370Spst 379519370Spststatic void 379698944Sobrienpsymtab_to_symtab_1 (struct partial_symtab *pst, char *filename) 379719370Spst{ 379819370Spst bfd_size_type external_sym_size; 379919370Spst bfd_size_type external_pdr_size; 380098944Sobrien void (*swap_sym_in) (bfd *, void *, SYMR *); 380198944Sobrien void (*swap_pdr_in) (bfd *, void *, PDR *); 380219370Spst int i; 380398944Sobrien struct symtab *st = NULL; 380419370Spst FDR *fh; 380519370Spst struct linetable *lines; 380619370Spst CORE_ADDR lowest_pdr_addr = 0; 380798944Sobrien int last_symtab_ended = 0; 380819370Spst 380919370Spst if (pst->readin) 381019370Spst return; 381119370Spst pst->readin = 1; 381219370Spst 381319370Spst /* Read in all partial symbtabs on which this one is dependent. 381419370Spst NOTE that we do have circular dependencies, sigh. We solved 381519370Spst that by setting pst->readin before this point. */ 381619370Spst 381719370Spst for (i = 0; i < pst->number_of_dependencies; i++) 381819370Spst if (!pst->dependencies[i]->readin) 381919370Spst { 382019370Spst /* Inform about additional files to be read in. */ 382119370Spst if (info_verbose) 382219370Spst { 382319370Spst fputs_filtered (" ", gdb_stdout); 382419370Spst wrap_here (""); 382519370Spst fputs_filtered ("and ", gdb_stdout); 382619370Spst wrap_here (""); 382719370Spst printf_filtered ("%s...", 382819370Spst pst->dependencies[i]->filename); 382919370Spst wrap_here (""); /* Flush output */ 383019370Spst gdb_flush (gdb_stdout); 383119370Spst } 383219370Spst /* We only pass the filename for debug purposes */ 383319370Spst psymtab_to_symtab_1 (pst->dependencies[i], 383419370Spst pst->dependencies[i]->filename); 383519370Spst } 383619370Spst 383719370Spst /* Do nothing if this is a dummy psymtab. */ 383819370Spst 383919370Spst if (pst->n_global_syms == 0 && pst->n_static_syms == 0 3840130803Smarcel && pst->textlow == 0 && pst->texthigh == 0) 384119370Spst return; 384219370Spst 384319370Spst /* Now read the symbols for this symtab */ 384419370Spst 384519370Spst cur_bfd = CUR_BFD (pst); 384619370Spst debug_swap = DEBUG_SWAP (pst); 384719370Spst debug_info = DEBUG_INFO (pst); 384819370Spst pending_list = PENDING_LIST (pst); 384919370Spst external_sym_size = debug_swap->external_sym_size; 385019370Spst external_pdr_size = debug_swap->external_pdr_size; 385119370Spst swap_sym_in = debug_swap->swap_sym_in; 385219370Spst swap_pdr_in = debug_swap->swap_pdr_in; 385319370Spst current_objfile = pst->objfile; 385419370Spst cur_fd = FDR_IDX (pst); 385519370Spst fh = ((cur_fd == -1) 385619370Spst ? (FDR *) NULL 385719370Spst : debug_info->fdr + cur_fd); 385819370Spst cur_fdr = fh; 385919370Spst 386019370Spst /* See comment in parse_partial_symbols about the @stabs sentinel. */ 386119370Spst processing_gcc_compilation = 0; 386219370Spst if (fh != (FDR *) NULL && fh->csym >= 2) 386319370Spst { 386419370Spst SYMR sh; 386519370Spst 386619370Spst (*swap_sym_in) (cur_bfd, 386719370Spst ((char *) debug_info->external_sym 386819370Spst + (fh->isymBase + 1) * external_sym_size), 386919370Spst &sh); 3870130803Smarcel if (strcmp (debug_info->ss + fh->issBase + sh.iss, 3871130803Smarcel stabs_symbol) == 0) 387219370Spst { 387319370Spst /* We indicate that this is a GCC compilation so that certain 387419370Spst features will be enabled in stabsread/dbxread. */ 387519370Spst processing_gcc_compilation = 2; 387619370Spst } 387719370Spst } 387819370Spst 387919370Spst if (processing_gcc_compilation != 0) 388019370Spst { 388119370Spst 388219370Spst /* This symbol table contains stabs-in-ecoff entries. */ 388319370Spst 388419370Spst /* Parse local symbols first */ 388519370Spst 388619370Spst if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */ 388719370Spst { 388819370Spst current_objfile = NULL; 388919370Spst return; 389019370Spst } 389119370Spst for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) 389219370Spst { 389319370Spst SYMR sh; 389419370Spst char *name; 389519370Spst CORE_ADDR valu; 389619370Spst 389719370Spst (*swap_sym_in) (cur_bfd, 389819370Spst (((char *) debug_info->external_sym) 389919370Spst + (fh->isymBase + cur_sdx) * external_sym_size), 390019370Spst &sh); 390119370Spst name = debug_info->ss + fh->issBase + sh.iss; 390219370Spst valu = sh.value; 390346283Sdfr /* XXX This is a hack. It will go away! */ 390446283Sdfr if (ECOFF_IS_STAB (&sh) || (name[0] == '#')) 390519370Spst { 390619370Spst int type_code = ECOFF_UNMARK_STAB (sh.index); 390719370Spst 390819370Spst /* We should never get non N_STAB symbols here, but they 390998944Sobrien should be harmless, so keep process_one_symbol from 391098944Sobrien complaining about them. */ 391119370Spst if (type_code & N_STAB) 391219370Spst { 391398944Sobrien /* If we found a trailing N_SO with no name, process 391498944Sobrien it here instead of in process_one_symbol, so we 391598944Sobrien can keep a handle to its symtab. The symtab 391698944Sobrien would otherwise be ended twice, once in 391798944Sobrien process_one_symbol, and once after this loop. */ 391898944Sobrien if (type_code == N_SO 391998944Sobrien && last_source_file 392098944Sobrien && previous_stab_code != (unsigned char) N_SO 392198944Sobrien && *name == '\000') 392298944Sobrien { 392398944Sobrien valu += ANOFFSET (pst->section_offsets, 392498944Sobrien SECT_OFF_TEXT (pst->objfile)); 392598944Sobrien previous_stab_code = N_SO; 392698944Sobrien st = end_symtab (valu, pst->objfile, 392798944Sobrien SECT_OFF_TEXT (pst->objfile)); 392898944Sobrien end_stabs (); 392998944Sobrien last_symtab_ended = 1; 393098944Sobrien } 393198944Sobrien else 393298944Sobrien { 393398944Sobrien last_symtab_ended = 0; 393498944Sobrien process_one_symbol (type_code, 0, valu, name, 393598944Sobrien pst->section_offsets, pst->objfile); 393698944Sobrien } 393719370Spst } 393846283Sdfr /* Similarly a hack. */ 393946283Sdfr else if (name[0] == '#') 394046283Sdfr { 394146283Sdfr process_one_symbol (N_SLINE, 0, valu, name, 394246283Sdfr pst->section_offsets, pst->objfile); 394346283Sdfr } 394419370Spst if (type_code == N_FUN) 394519370Spst { 394619370Spst /* Make up special symbol to contain 394719370Spst procedure specific info */ 394819370Spst struct mips_extra_func_info *e = 394998944Sobrien ((struct mips_extra_func_info *) 3950130803Smarcel obstack_alloc (¤t_objfile->objfile_obstack, 395198944Sobrien sizeof (struct mips_extra_func_info))); 395219370Spst struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME); 395319370Spst 395498944Sobrien memset (e, 0, sizeof (struct mips_extra_func_info)); 3955130803Smarcel SYMBOL_DOMAIN (s) = LABEL_DOMAIN; 395619370Spst SYMBOL_CLASS (s) = LOC_CONST; 395719370Spst SYMBOL_TYPE (s) = mdebug_type_void; 395819370Spst SYMBOL_VALUE (s) = (long) e; 395919370Spst e->pdr.framereg = -1; 396019370Spst add_symbol_to_list (s, &local_symbols); 396119370Spst } 396219370Spst } 396319370Spst else if (sh.st == stLabel) 396419370Spst { 396519370Spst if (sh.index == indexNil) 396619370Spst { 396719370Spst /* This is what the gcc2_compiled and __gnu_compiled_* 396819370Spst show up as. So don't complain. */ 396919370Spst ; 397019370Spst } 397119370Spst else 397219370Spst { 397319370Spst /* Handle encoded stab line number. */ 397498944Sobrien valu += ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)); 397519370Spst record_line (current_subfile, sh.index, valu); 397619370Spst } 397719370Spst } 397819370Spst else if (sh.st == stProc || sh.st == stStaticProc 397919370Spst || sh.st == stStatic || sh.st == stEnd) 398019370Spst /* These are generated by gcc-2.x, do not complain */ 398119370Spst ; 398219370Spst else 3983130803Smarcel complaint (&symfile_complaints, "unknown stabs symbol %s", name); 398419370Spst } 398519370Spst 398698944Sobrien if (! last_symtab_ended) 398798944Sobrien { 3988130803Smarcel st = end_symtab (pst->texthigh, pst->objfile, SECT_OFF_TEXT (pst->objfile)); 398998944Sobrien end_stabs (); 399098944Sobrien } 399198944Sobrien 399219370Spst /* There used to be a call to sort_blocks here, but this should not 399398944Sobrien be necessary for stabs symtabs. And as sort_blocks modifies the 399498944Sobrien start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK, 399598944Sobrien it did the wrong thing if the first procedure in a file was 399698944Sobrien generated via asm statements. */ 399719370Spst 399819370Spst /* Fill in procedure info next. */ 399919370Spst if (fh->cpd > 0) 400019370Spst { 400119370Spst PDR *pr_block; 400219370Spst struct cleanup *old_chain; 400319370Spst char *pdr_ptr; 400419370Spst char *pdr_end; 400519370Spst PDR *pdr_in; 400619370Spst PDR *pdr_in_end; 400719370Spst 400819370Spst pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR)); 400998944Sobrien old_chain = make_cleanup (xfree, pr_block); 401019370Spst 401119370Spst pdr_ptr = ((char *) debug_info->external_pdr 401219370Spst + fh->ipdFirst * external_pdr_size); 401319370Spst pdr_end = pdr_ptr + fh->cpd * external_pdr_size; 401419370Spst pdr_in = pr_block; 401519370Spst for (; 401619370Spst pdr_ptr < pdr_end; 401719370Spst pdr_ptr += external_pdr_size, pdr_in++) 401819370Spst { 401919370Spst (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in); 402019370Spst 402119370Spst /* Determine lowest PDR address, the PDRs are not always 402298944Sobrien sorted. */ 402319370Spst if (pdr_in == pr_block) 402419370Spst lowest_pdr_addr = pdr_in->adr; 402519370Spst else if (pdr_in->adr < lowest_pdr_addr) 402619370Spst lowest_pdr_addr = pdr_in->adr; 402719370Spst } 402819370Spst 402919370Spst pdr_in = pr_block; 403019370Spst pdr_in_end = pdr_in + fh->cpd; 403119370Spst for (; pdr_in < pdr_in_end; pdr_in++) 403246283Sdfr parse_procedure (pdr_in, st, pst); 403319370Spst 403419370Spst do_cleanups (old_chain); 403519370Spst } 403619370Spst } 403719370Spst else 403819370Spst { 403919370Spst /* This symbol table contains ordinary ecoff entries. */ 404019370Spst 404119370Spst int f_max; 404219370Spst int maxlines; 404319370Spst EXTR *ext_ptr; 404419370Spst 404519370Spst if (fh == 0) 404619370Spst { 404719370Spst maxlines = 0; 4048130803Smarcel st = new_symtab ("unknown", 0, pst->objfile); 404919370Spst } 405019370Spst else 405119370Spst { 405219370Spst maxlines = 2 * fh->cline; 4053130803Smarcel st = new_symtab (pst->filename, maxlines, pst->objfile); 405419370Spst 405519370Spst /* The proper language was already determined when building 405619370Spst the psymtab, use it. */ 405719370Spst st->language = PST_PRIVATE (pst)->pst_language; 405819370Spst } 405919370Spst 406019370Spst psymtab_language = st->language; 406119370Spst 406219370Spst lines = LINETABLE (st); 406319370Spst 406419370Spst /* Get a new lexical context */ 406519370Spst 406619370Spst push_parse_stack (); 406719370Spst top_stack->cur_st = st; 406819370Spst top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st), 406919370Spst STATIC_BLOCK); 4070130803Smarcel BLOCK_START (top_stack->cur_block) = pst->textlow; 407119370Spst BLOCK_END (top_stack->cur_block) = 0; 407219370Spst top_stack->blocktype = stFile; 407319370Spst top_stack->cur_type = 0; 407419370Spst top_stack->procadr = 0; 407519370Spst top_stack->numargs = 0; 407619370Spst found_ecoff_debugging_info = 0; 407719370Spst 407819370Spst if (fh) 407919370Spst { 408019370Spst char *sym_ptr; 408119370Spst char *sym_end; 408219370Spst 408319370Spst /* Parse local symbols first */ 408419370Spst sym_ptr = ((char *) debug_info->external_sym 408519370Spst + fh->isymBase * external_sym_size); 408619370Spst sym_end = sym_ptr + fh->csym * external_sym_size; 408719370Spst while (sym_ptr < sym_end) 408819370Spst { 408919370Spst SYMR sh; 409019370Spst int c; 409119370Spst 409219370Spst (*swap_sym_in) (cur_bfd, sym_ptr, &sh); 409319370Spst c = parse_symbol (&sh, 409419370Spst debug_info->external_aux + fh->iauxBase, 409598944Sobrien sym_ptr, fh->fBigendian, pst->section_offsets, pst->objfile); 409619370Spst sym_ptr += c * external_sym_size; 409719370Spst } 409819370Spst 409919370Spst /* Linenumbers. At the end, check if we can save memory. 410019370Spst parse_lines has to look ahead an arbitrary number of PDR 410119370Spst structures, so we swap them all first. */ 410219370Spst if (fh->cpd > 0) 410319370Spst { 410419370Spst PDR *pr_block; 410519370Spst struct cleanup *old_chain; 410619370Spst char *pdr_ptr; 410719370Spst char *pdr_end; 410819370Spst PDR *pdr_in; 410919370Spst PDR *pdr_in_end; 411019370Spst 411119370Spst pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR)); 411219370Spst 411398944Sobrien old_chain = make_cleanup (xfree, pr_block); 411419370Spst 411519370Spst pdr_ptr = ((char *) debug_info->external_pdr 411619370Spst + fh->ipdFirst * external_pdr_size); 411719370Spst pdr_end = pdr_ptr + fh->cpd * external_pdr_size; 411819370Spst pdr_in = pr_block; 411919370Spst for (; 412019370Spst pdr_ptr < pdr_end; 412119370Spst pdr_ptr += external_pdr_size, pdr_in++) 412219370Spst { 412319370Spst (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in); 412419370Spst 412519370Spst /* Determine lowest PDR address, the PDRs are not always 412619370Spst sorted. */ 412719370Spst if (pdr_in == pr_block) 412819370Spst lowest_pdr_addr = pdr_in->adr; 412919370Spst else if (pdr_in->adr < lowest_pdr_addr) 413019370Spst lowest_pdr_addr = pdr_in->adr; 413119370Spst } 413219370Spst 413319370Spst parse_lines (fh, pr_block, lines, maxlines, pst, lowest_pdr_addr); 413419370Spst if (lines->nitems < fh->cline) 413519370Spst lines = shrink_linetable (lines); 413619370Spst 413719370Spst /* Fill in procedure info next. */ 413819370Spst pdr_in = pr_block; 413919370Spst pdr_in_end = pdr_in + fh->cpd; 414019370Spst for (; pdr_in < pdr_in_end; pdr_in++) 414146283Sdfr parse_procedure (pdr_in, 0, pst); 414219370Spst 414319370Spst do_cleanups (old_chain); 414419370Spst } 414519370Spst } 414619370Spst 414719370Spst LINETABLE (st) = lines; 414819370Spst 414919370Spst /* .. and our share of externals. 415098944Sobrien XXX use the global list to speed up things here. how? 415198944Sobrien FIXME, Maybe quit once we have found the right number of ext's? */ 415219370Spst top_stack->cur_st = st; 415319370Spst top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st), 415419370Spst GLOBAL_BLOCK); 415519370Spst top_stack->blocktype = stFile; 415619370Spst 415719370Spst ext_ptr = PST_PRIVATE (pst)->extern_tab; 415819370Spst for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++) 415998944Sobrien parse_external (ext_ptr, fh->fBigendian, pst->section_offsets, pst->objfile); 416019370Spst 416119370Spst /* If there are undefined symbols, tell the user. 416298944Sobrien The alpha has an undefined symbol for every symbol that is 416398944Sobrien from a shared library, so tell the user only if verbose is on. */ 416419370Spst if (info_verbose && n_undef_symbols) 416519370Spst { 416619370Spst printf_filtered ("File %s contains %d unresolved references:", 416719370Spst st->filename, n_undef_symbols); 416819370Spst printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n", 416919370Spst n_undef_vars, n_undef_procs, n_undef_labels); 417019370Spst n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0; 417119370Spst 417219370Spst } 417319370Spst pop_parse_stack (); 417419370Spst 417519370Spst st->primary = 1; 417619370Spst 417719370Spst sort_blocks (st); 417819370Spst } 417919370Spst 418019370Spst /* Now link the psymtab and the symtab. */ 418119370Spst pst->symtab = st; 418219370Spst 418319370Spst current_objfile = NULL; 418419370Spst} 418519370Spst 418619370Spst/* Ancillary parsing procedures. */ 418719370Spst 418819370Spst/* Return 1 if the symbol pointed to by SH has a cross reference 418919370Spst to an opaque aggregate type, else 0. */ 419019370Spst 419119370Spststatic int 419298944Sobrienhas_opaque_xref (FDR *fh, SYMR *sh) 419319370Spst{ 419419370Spst TIR tir; 419519370Spst union aux_ext *ax; 419619370Spst RNDXR rn[1]; 419719370Spst unsigned int rf; 419819370Spst 419919370Spst if (sh->index == indexNil) 420019370Spst return 0; 420119370Spst 420219370Spst ax = debug_info->external_aux + fh->iauxBase + sh->index; 420319370Spst (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir); 420419370Spst if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum) 420519370Spst return 0; 420619370Spst 420719370Spst ax++; 420819370Spst (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn); 420919370Spst if (rn->rfd == 0xfff) 421019370Spst rf = AUX_GET_ISYM (fh->fBigendian, ax + 1); 421119370Spst else 421219370Spst rf = rn->rfd; 421319370Spst if (rf != -1) 421419370Spst return 0; 421519370Spst return 1; 421619370Spst} 421719370Spst 421819370Spst/* Lookup the type at relative index RN. Return it in TPP 421919370Spst if found and in any event come up with its name PNAME. 422019370Spst BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian). 422119370Spst Return value says how many aux symbols we ate. */ 422219370Spst 422319370Spststatic int 422498944Sobriencross_ref (int fd, union aux_ext *ax, struct type **tpp, enum type_code type_code, /* Use to alloc new type if none is found. */ 422598944Sobrien char **pname, int bigend, char *sym_name) 422619370Spst{ 422719370Spst RNDXR rn[1]; 422819370Spst unsigned int rf; 422919370Spst int result = 1; 423019370Spst FDR *fh; 423119370Spst char *esh; 423219370Spst SYMR sh; 423319370Spst int xref_fd; 423419370Spst struct mdebug_pending *pend; 423519370Spst 423698944Sobrien *tpp = (struct type *) NULL; 423719370Spst 423819370Spst (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn); 423919370Spst 424019370Spst /* Escape index means 'the next one' */ 424119370Spst if (rn->rfd == 0xfff) 424219370Spst { 424319370Spst result++; 424419370Spst rf = AUX_GET_ISYM (bigend, ax + 1); 424519370Spst } 424619370Spst else 424719370Spst { 424819370Spst rf = rn->rfd; 424919370Spst } 425019370Spst 425119370Spst /* mips cc uses a rf of -1 for opaque struct definitions. 425219370Spst Set TYPE_FLAG_STUB for these types so that check_typedef will 425319370Spst resolve them if the struct gets defined in another compilation unit. */ 425419370Spst if (rf == -1) 425519370Spst { 425619370Spst *pname = "<undefined>"; 425798944Sobrien *tpp = init_type (type_code, 0, TYPE_FLAG_STUB, (char *) NULL, current_objfile); 425819370Spst return result; 425919370Spst } 426019370Spst 426119370Spst /* mips cc uses an escaped rn->index of 0 for struct return types 426219370Spst of procedures that were compiled without -g. These will always remain 426319370Spst undefined. */ 426419370Spst if (rn->rfd == 0xfff && rn->index == 0) 426519370Spst { 426619370Spst *pname = "<undefined>"; 426719370Spst return result; 426819370Spst } 426919370Spst 427019370Spst /* Find the relative file descriptor and the symbol in it. */ 427119370Spst fh = get_rfd (fd, rf); 427219370Spst xref_fd = fh - debug_info->fdr; 427319370Spst 427419370Spst if (rn->index >= fh->csym) 427519370Spst { 427619370Spst /* File indirect entry is corrupt. */ 427719370Spst *pname = "<illegal>"; 4278130803Smarcel bad_rfd_entry_complaint (sym_name, xref_fd, rn->index); 427919370Spst return result; 428019370Spst } 428119370Spst 428219370Spst /* If we have processed this symbol then we left a forwarding 428319370Spst pointer to the type in the pending list. If not, we`ll put 428419370Spst it in a list of pending types, to be processed later when 428519370Spst the file will be. In any event, we collect the name for the 428619370Spst type here. */ 428719370Spst 428819370Spst esh = ((char *) debug_info->external_sym 428919370Spst + ((fh->isymBase + rn->index) 429019370Spst * debug_swap->external_sym_size)); 429119370Spst (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh); 429219370Spst 429319370Spst /* Make sure that this type of cross reference can be handled. */ 429419370Spst if ((sh.sc != scInfo 429519370Spst || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect 429619370Spst && sh.st != stStruct && sh.st != stUnion 429719370Spst && sh.st != stEnum)) 429898944Sobrien && (sh.st != stBlock || !SC_IS_COMMON (sh.sc))) 429919370Spst { 430019370Spst /* File indirect entry is corrupt. */ 430119370Spst *pname = "<illegal>"; 4302130803Smarcel bad_rfd_entry_complaint (sym_name, xref_fd, rn->index); 430319370Spst return result; 430419370Spst } 430519370Spst 430619370Spst *pname = debug_info->ss + fh->issBase + sh.iss; 430719370Spst 430819370Spst pend = is_pending_symbol (fh, esh); 430919370Spst if (pend) 431019370Spst *tpp = pend->t; 431119370Spst else 431219370Spst { 431319370Spst /* We have not yet seen this type. */ 431419370Spst 431519370Spst if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect) 431619370Spst { 431719370Spst TIR tir; 431819370Spst 431919370Spst /* alpha cc puts out a stTypedef with a sh.iss of zero for 432019370Spst two cases: 432119370Spst a) forward declarations of structs/unions/enums which are not 432298944Sobrien defined in this compilation unit. 432398944Sobrien For these the type will be void. This is a bad design decision 432498944Sobrien as cross referencing across compilation units is impossible 432598944Sobrien due to the missing name. 432619370Spst b) forward declarations of structs/unions/enums/typedefs which 432798944Sobrien are defined later in this file or in another file in the same 432898944Sobrien compilation unit. Irix5 cc uses a stIndirect symbol for this. 432998944Sobrien Simply cross reference those again to get the true type. 433019370Spst The forward references are not entered in the pending list and 433119370Spst in the symbol table. */ 433219370Spst 433319370Spst (*debug_swap->swap_tir_in) (bigend, 433419370Spst &(debug_info->external_aux 433519370Spst + fh->iauxBase + sh.index)->a_ti, 433619370Spst &tir); 433719370Spst if (tir.tq0 != tqNil) 4338130803Smarcel complaint (&symfile_complaints, 4339130803Smarcel "illegal tq0 in forward typedef for %s", sym_name); 434019370Spst switch (tir.bt) 434119370Spst { 434219370Spst case btVoid: 434319370Spst *tpp = init_type (type_code, 0, 0, (char *) NULL, 434419370Spst current_objfile); 434598944Sobrien *pname = "<undefined>"; 434619370Spst break; 434719370Spst 434819370Spst case btStruct: 434919370Spst case btUnion: 435019370Spst case btEnum: 435119370Spst cross_ref (xref_fd, 435219370Spst (debug_info->external_aux 435319370Spst + fh->iauxBase + sh.index + 1), 435419370Spst tpp, type_code, pname, 435519370Spst fh->fBigendian, sym_name); 435619370Spst break; 435719370Spst 435819370Spst case btTypedef: 435919370Spst /* Follow a forward typedef. This might recursively 436098944Sobrien call cross_ref till we get a non typedef'ed type. 436198944Sobrien FIXME: This is not correct behaviour, but gdb currently 436298944Sobrien cannot handle typedefs without type copying. Type 436398944Sobrien copying is impossible as we might have mutual forward 436498944Sobrien references between two files and the copied type would not 436598944Sobrien get filled in when we later parse its definition. */ 436619370Spst *tpp = parse_type (xref_fd, 436719370Spst debug_info->external_aux + fh->iauxBase, 436819370Spst sh.index, 436998944Sobrien (int *) NULL, 437019370Spst fh->fBigendian, 437119370Spst debug_info->ss + fh->issBase + sh.iss); 437219370Spst add_pending (fh, esh, *tpp); 437319370Spst break; 437419370Spst 437519370Spst default: 4376130803Smarcel complaint (&symfile_complaints, 4377130803Smarcel "illegal bt %d in forward typedef for %s", tir.bt, 4378130803Smarcel sym_name); 437919370Spst *tpp = init_type (type_code, 0, 0, (char *) NULL, 438019370Spst current_objfile); 438119370Spst break; 438219370Spst } 438319370Spst return result; 438419370Spst } 438519370Spst else if (sh.st == stTypedef) 438619370Spst { 438719370Spst /* Parse the type for a normal typedef. This might recursively call 438819370Spst cross_ref till we get a non typedef'ed type. 438919370Spst FIXME: This is not correct behaviour, but gdb currently 439019370Spst cannot handle typedefs without type copying. But type copying is 439119370Spst impossible as we might have mutual forward references between 439219370Spst two files and the copied type would not get filled in when 439319370Spst we later parse its definition. */ 439419370Spst *tpp = parse_type (xref_fd, 439519370Spst debug_info->external_aux + fh->iauxBase, 439619370Spst sh.index, 439798944Sobrien (int *) NULL, 439819370Spst fh->fBigendian, 439919370Spst debug_info->ss + fh->issBase + sh.iss); 440019370Spst } 440119370Spst else 440219370Spst { 440319370Spst /* Cross reference to a struct/union/enum which is defined 440419370Spst in another file in the same compilation unit but that file 440519370Spst has not been parsed yet. 440619370Spst Initialize the type only, it will be filled in when 440719370Spst it's definition is parsed. */ 440819370Spst *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile); 440919370Spst } 441019370Spst add_pending (fh, esh, *tpp); 441119370Spst } 441219370Spst 441319370Spst /* We used one auxent normally, two if we got a "next one" rf. */ 441419370Spst return result; 441519370Spst} 441619370Spst 441719370Spst 441819370Spst/* Quick&dirty lookup procedure, to avoid the MI ones that require 441919370Spst keeping the symtab sorted */ 442019370Spst 442119370Spststatic struct symbol * 4422130803Smarcelmylookup_symbol (char *name, struct block *block, 4423130803Smarcel domain_enum domain, enum address_class class) 442419370Spst{ 4425130803Smarcel struct dict_iterator iter; 4426130803Smarcel int inc; 442798944Sobrien struct symbol *sym; 442819370Spst 442919370Spst inc = name[0]; 4430130803Smarcel ALL_BLOCK_SYMBOLS (block, iter, sym) 443119370Spst { 4432130803Smarcel if (DEPRECATED_SYMBOL_NAME (sym)[0] == inc 4433130803Smarcel && SYMBOL_DOMAIN (sym) == domain 443419370Spst && SYMBOL_CLASS (sym) == class 4435130803Smarcel && strcmp (DEPRECATED_SYMBOL_NAME (sym), name) == 0) 443619370Spst return sym; 443719370Spst } 443898944Sobrien 443919370Spst block = BLOCK_SUPERBLOCK (block); 444019370Spst if (block) 4441130803Smarcel return mylookup_symbol (name, block, domain, class); 444219370Spst return 0; 444319370Spst} 444419370Spst 444519370Spst 4446130803Smarcel/* Add a new symbol S to a block B. */ 444719370Spst 444819370Spststatic void 444998944Sobrienadd_symbol (struct symbol *s, struct block *b) 445019370Spst{ 4451130803Smarcel dict_add_symbol (BLOCK_DICT (b), s); 445219370Spst} 445319370Spst 445419370Spst/* Add a new block B to a symtab S */ 445519370Spst 445619370Spststatic void 445798944Sobrienadd_block (struct block *b, struct symtab *s) 445819370Spst{ 445919370Spst struct blockvector *bv = BLOCKVECTOR (s); 446019370Spst 446198944Sobrien bv = (struct blockvector *) xrealloc ((void *) bv, 446219370Spst (sizeof (struct blockvector) 446319370Spst + BLOCKVECTOR_NBLOCKS (bv) 446419370Spst * sizeof (bv->block))); 446519370Spst if (bv != BLOCKVECTOR (s)) 446619370Spst BLOCKVECTOR (s) = bv; 446719370Spst 446819370Spst BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b; 446919370Spst} 447019370Spst 447119370Spst/* Add a new linenumber entry (LINENO,ADR) to a linevector LT. 447219370Spst MIPS' linenumber encoding might need more than one byte 447319370Spst to describe it, LAST is used to detect these continuation lines. 447419370Spst 447519370Spst Combining lines with the same line number seems like a bad idea. 447619370Spst E.g: There could be a line number entry with the same line number after the 447719370Spst prologue and GDB should not ignore it (this is a better way to find 447819370Spst a prologue than mips_skip_prologue). 447919370Spst But due to the compressed line table format there are line number entries 448019370Spst for the same line which are needed to bridge the gap to the next 448119370Spst line number entry. These entries have a bogus address info with them 448219370Spst and we are unable to tell them from intended duplicate line number 448319370Spst entries. 448419370Spst This is another reason why -ggdb debugging format is preferable. */ 448519370Spst 448619370Spststatic int 448798944Sobrienadd_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last) 448819370Spst{ 448919370Spst /* DEC c89 sometimes produces zero linenos which confuse gdb. 449019370Spst Change them to something sensible. */ 449119370Spst if (lineno == 0) 449219370Spst lineno = 1; 449319370Spst if (last == 0) 449419370Spst last = -2; /* make sure we record first line */ 449519370Spst 449619370Spst if (last == lineno) /* skip continuation lines */ 449719370Spst return lineno; 449819370Spst 449919370Spst lt->item[lt->nitems].line = lineno; 450019370Spst lt->item[lt->nitems++].pc = adr << 2; 450119370Spst return lineno; 450219370Spst} 450319370Spst 450419370Spst/* Sorting and reordering procedures */ 450519370Spst 450619370Spst/* Blocks with a smaller low bound should come first */ 450719370Spst 450819370Spststatic int 450998944Sobriencompare_blocks (const void *arg1, const void *arg2) 451019370Spst{ 4511130803Smarcel LONGEST addr_diff; 451219370Spst struct block **b1 = (struct block **) arg1; 451319370Spst struct block **b2 = (struct block **) arg2; 451419370Spst 451519370Spst addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2))); 451619370Spst if (addr_diff == 0) 451719370Spst return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1))); 451819370Spst return addr_diff; 451919370Spst} 452019370Spst 452119370Spst/* Sort the blocks of a symtab S. 452219370Spst Reorder the blocks in the blockvector by code-address, 452319370Spst as required by some MI search routines */ 452419370Spst 452519370Spststatic void 452698944Sobriensort_blocks (struct symtab *s) 452719370Spst{ 452819370Spst struct blockvector *bv = BLOCKVECTOR (s); 452919370Spst 453019370Spst if (BLOCKVECTOR_NBLOCKS (bv) <= 2) 453119370Spst { 453219370Spst /* Cosmetic */ 453319370Spst if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0) 453419370Spst BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0; 453519370Spst if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0) 453619370Spst BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0; 453719370Spst return; 453819370Spst } 453919370Spst /* 454019370Spst * This is very unfortunate: normally all functions are compiled in 454119370Spst * the order they are found, but if the file is compiled -O3 things 454219370Spst * are very different. It would be nice to find a reliable test 454319370Spst * to detect -O3 images in advance. 454419370Spst */ 454519370Spst if (BLOCKVECTOR_NBLOCKS (bv) > 3) 454619370Spst qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK), 454719370Spst BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK, 454819370Spst sizeof (struct block *), 454919370Spst compare_blocks); 455019370Spst 455119370Spst { 4552130803Smarcel CORE_ADDR high = 0; 4553130803Smarcel int i, j = BLOCKVECTOR_NBLOCKS (bv); 455419370Spst 455519370Spst for (i = FIRST_LOCAL_BLOCK; i < j; i++) 455619370Spst if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i))) 455719370Spst high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)); 455819370Spst BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high; 455919370Spst } 456019370Spst 456119370Spst BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 456219370Spst BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK)); 456319370Spst 456419370Spst BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 456519370Spst BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); 456619370Spst BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 456719370Spst BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); 456819370Spst} 456919370Spst 457019370Spst 457119370Spst/* Constructor/restructor/destructor procedures */ 457219370Spst 4573130803Smarcel/* Allocate a new symtab for NAME. Needs an estimate of how many 4574130803Smarcel linenumbers MAXLINES we'll put in it */ 457519370Spst 457619370Spststatic struct symtab * 4577130803Smarcelnew_symtab (char *name, int maxlines, struct objfile *objfile) 457819370Spst{ 457919370Spst struct symtab *s = allocate_symtab (name, objfile); 458019370Spst 458119370Spst LINETABLE (s) = new_linetable (maxlines); 458219370Spst 458319370Spst /* All symtabs must have at least two blocks */ 458419370Spst BLOCKVECTOR (s) = new_bvect (2); 4585130803Smarcel BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) 4586130803Smarcel = new_block (NON_FUNCTION_BLOCK); 4587130803Smarcel BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) 4588130803Smarcel = new_block (NON_FUNCTION_BLOCK); 458919370Spst BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) = 459019370Spst BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); 459119370Spst 459219370Spst s->free_code = free_linetable; 459346283Sdfr s->debugformat = obsavestring ("ECOFF", 5, 4594130803Smarcel &objfile->objfile_obstack); 459519370Spst return (s); 459619370Spst} 459719370Spst 459819370Spst/* Allocate a new partial_symtab NAME */ 459919370Spst 460019370Spststatic struct partial_symtab * 460198944Sobriennew_psymtab (char *name, struct objfile *objfile) 460219370Spst{ 460319370Spst struct partial_symtab *psymtab; 460419370Spst 460519370Spst psymtab = allocate_psymtab (name, objfile); 460698944Sobrien psymtab->section_offsets = objfile->section_offsets; 460719370Spst 460819370Spst /* Keep a backpointer to the file's symbols */ 460919370Spst 461019370Spst psymtab->read_symtab_private = ((char *) 4611130803Smarcel obstack_alloc (&objfile->objfile_obstack, 461219370Spst sizeof (struct symloc))); 461398944Sobrien memset (psymtab->read_symtab_private, 0, sizeof (struct symloc)); 461419370Spst CUR_BFD (psymtab) = cur_bfd; 461519370Spst DEBUG_SWAP (psymtab) = debug_swap; 461619370Spst DEBUG_INFO (psymtab) = debug_info; 461719370Spst PENDING_LIST (psymtab) = pending_list; 461819370Spst 461919370Spst /* The way to turn this into a symtab is to call... */ 462019370Spst psymtab->read_symtab = mdebug_psymtab_to_symtab; 462119370Spst return (psymtab); 462219370Spst} 462319370Spst 462419370Spst 462519370Spst/* Allocate a linetable array of the given SIZE. Since the struct 462619370Spst already includes one item, we subtract one when calculating the 462719370Spst proper size to allocate. */ 462819370Spst 462919370Spststatic struct linetable * 463098944Sobriennew_linetable (int size) 463119370Spst{ 463219370Spst struct linetable *l; 463319370Spst 463419370Spst size = (size - 1) * sizeof (l->item) + sizeof (struct linetable); 463519370Spst l = (struct linetable *) xmalloc (size); 463619370Spst l->nitems = 0; 463719370Spst return l; 463819370Spst} 463919370Spst 464019370Spst/* Oops, too big. Shrink it. This was important with the 2.4 linetables, 464119370Spst I am not so sure about the 3.4 ones. 464219370Spst 464319370Spst Since the struct linetable already includes one item, we subtract one when 464419370Spst calculating the proper size to allocate. */ 464519370Spst 464619370Spststatic struct linetable * 464798944Sobrienshrink_linetable (struct linetable *lt) 464819370Spst{ 464919370Spst 465098944Sobrien return (struct linetable *) xrealloc ((void *) lt, 465119370Spst (sizeof (struct linetable) 465219370Spst + ((lt->nitems - 1) 465319370Spst * sizeof (lt->item)))); 465419370Spst} 465519370Spst 465619370Spst/* Allocate and zero a new blockvector of NBLOCKS blocks. */ 465719370Spst 465819370Spststatic struct blockvector * 465998944Sobriennew_bvect (int nblocks) 466019370Spst{ 466119370Spst struct blockvector *bv; 466219370Spst int size; 466319370Spst 466419370Spst size = sizeof (struct blockvector) + nblocks * sizeof (struct block *); 466519370Spst bv = (struct blockvector *) xzalloc (size); 466619370Spst 466719370Spst BLOCKVECTOR_NBLOCKS (bv) = nblocks; 466819370Spst 466919370Spst return bv; 467019370Spst} 467119370Spst 4672130803Smarcel/* Allocate and zero a new block, and set its BLOCK_DICT. If function 4673130803Smarcel is non-zero, assume the block is associated to a function, and make 4674130803Smarcel sure that the symbols are stored linearly; otherwise, store them 4675130803Smarcel hashed. */ 467619370Spst 467719370Spststatic struct block * 4678130803Smarcelnew_block (enum block_type type) 467919370Spst{ 4680130803Smarcel /* FIXME: carlton/2003-09-11: This should use allocate_block to 4681130803Smarcel allocate the block. Which, in turn, suggests that the block 4682130803Smarcel should be allocated on an obstack. */ 4683130803Smarcel struct block *retval = xzalloc (sizeof (struct block)); 468419370Spst 4685130803Smarcel if (type == FUNCTION_BLOCK) 4686130803Smarcel BLOCK_DICT (retval) = dict_create_linear_expandable (); 4687130803Smarcel else 4688130803Smarcel BLOCK_DICT (retval) = dict_create_hashed_expandable (); 468919370Spst 4690130803Smarcel return retval; 469119370Spst} 469219370Spst 469319370Spst/* Create a new symbol with printname NAME */ 469419370Spst 469519370Spststatic struct symbol * 469698944Sobriennew_symbol (char *name) 469719370Spst{ 469819370Spst struct symbol *s = ((struct symbol *) 4699130803Smarcel obstack_alloc (¤t_objfile->objfile_obstack, 470019370Spst sizeof (struct symbol))); 470119370Spst 470298944Sobrien memset (s, 0, sizeof (*s)); 470319370Spst SYMBOL_LANGUAGE (s) = psymtab_language; 4704130803Smarcel SYMBOL_SET_NAMES (s, name, strlen (name), current_objfile); 470519370Spst return s; 470619370Spst} 470719370Spst 470819370Spst/* Create a new type with printname NAME */ 470919370Spst 471019370Spststatic struct type * 471198944Sobriennew_type (char *name) 471219370Spst{ 471319370Spst struct type *t; 471419370Spst 471519370Spst t = alloc_type (current_objfile); 471619370Spst TYPE_NAME (t) = name; 471719370Spst TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default; 471819370Spst return t; 471919370Spst} 472019370Spst 472119370Spst/* Read ECOFF debugging information from a BFD section. This is 472219370Spst called from elfread.c. It parses the section into a 472319370Spst ecoff_debug_info struct, and then lets the rest of the file handle 472419370Spst it as normal. */ 472519370Spst 472619370Spstvoid 472798944Sobrienelfmdebug_build_psymtabs (struct objfile *objfile, 472898944Sobrien const struct ecoff_debug_swap *swap, asection *sec) 472919370Spst{ 473019370Spst bfd *abfd = objfile->obfd; 473119370Spst struct ecoff_debug_info *info; 4732130803Smarcel struct cleanup *back_to; 473319370Spst 4734130803Smarcel /* FIXME: It's not clear whether we should be getting minimal symbol 4735130803Smarcel information from .mdebug in an ELF file, or whether we will. 4736130803Smarcel Re-initialize the minimal symbol reader in case we do. */ 4737130803Smarcel 4738130803Smarcel init_minimal_symbol_collection (); 4739130803Smarcel back_to = make_cleanup_discard_minimal_symbols (); 4740130803Smarcel 474119370Spst info = ((struct ecoff_debug_info *) 4742130803Smarcel obstack_alloc (&objfile->objfile_obstack, 474319370Spst sizeof (struct ecoff_debug_info))); 474419370Spst 474519370Spst if (!(*swap->read_debug_info) (abfd, sec, info)) 474619370Spst error ("Error reading ECOFF debugging information: %s", 474719370Spst bfd_errmsg (bfd_get_error ())); 474819370Spst 474998944Sobrien mdebug_build_psymtabs (objfile, swap, info); 4750130803Smarcel 4751130803Smarcel install_minimal_symbols (objfile); 4752130803Smarcel do_cleanups (back_to); 475319370Spst} 475419370Spst 475519370Spst 475619370Spst/* Things used for calling functions in the inferior. 475719370Spst These functions are exported to our companion 475819370Spst mips-tdep.c file and are here because they play 475919370Spst with the symbol-table explicitly. */ 476019370Spst 476119370Spst/* Sigtramp: make sure we have all the necessary information 476219370Spst about the signal trampoline code. Since the official code 476319370Spst from MIPS does not do so, we make up that information ourselves. 476419370Spst If they fix the library (unlikely) this code will neutralize itself. */ 476519370Spst 476619370Spst/* FIXME: This function is called only by mips-tdep.c. It needs to be 476719370Spst here because it calls functions defined in this file, but perhaps 476846283Sdfr this could be handled in a better way. Only compile it in when 476946283Sdfr tm-mips.h is included. */ 477019370Spst 477146283Sdfr#ifdef TM_MIPS_H 477246283Sdfr 477319370Spstvoid 477498944Sobrienfixup_sigtramp (void) 477519370Spst{ 477619370Spst struct symbol *s; 477719370Spst struct symtab *st; 477819370Spst struct block *b, *b0 = NULL; 477919370Spst 478019370Spst sigtramp_address = -1; 478119370Spst 478219370Spst /* We have to handle the following cases here: 478319370Spst a) The Mips library has a sigtramp label within sigvec. 478419370Spst b) Irix has a _sigtramp which we want to use, but it also has sigvec. */ 4785130803Smarcel s = lookup_symbol ("sigvec", 0, VAR_DOMAIN, 0, NULL); 478619370Spst if (s != 0) 478719370Spst { 478819370Spst b0 = SYMBOL_BLOCK_VALUE (s); 4789130803Smarcel s = lookup_symbol ("sigtramp", b0, VAR_DOMAIN, 0, NULL); 479019370Spst } 479119370Spst if (s == 0) 479219370Spst { 479319370Spst /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */ 4794130803Smarcel s = lookup_symbol ("_sigtramp", 0, VAR_DOMAIN, 0, NULL); 479519370Spst } 479619370Spst 479719370Spst /* But maybe this program uses its own version of sigvec */ 479819370Spst if (s == 0) 479919370Spst return; 480019370Spst 480119370Spst /* Did we or MIPSco fix the library ? */ 480219370Spst if (SYMBOL_CLASS (s) == LOC_BLOCK) 480319370Spst { 480419370Spst sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s)); 480519370Spst sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s)); 480619370Spst return; 480719370Spst } 480819370Spst 480919370Spst sigtramp_address = SYMBOL_VALUE (s); 481019370Spst sigtramp_end = sigtramp_address + 0x88; /* black magic */ 481119370Spst 481219370Spst /* But what symtab does it live in ? */ 481319370Spst st = find_pc_symtab (SYMBOL_VALUE (s)); 481419370Spst 481519370Spst /* 481619370Spst * Ok, there goes the fix: turn it into a procedure, with all the 481719370Spst * needed info. Note we make it a nested procedure of sigvec, 481819370Spst * which is the way the (assembly) code is actually written. 481919370Spst */ 4820130803Smarcel SYMBOL_DOMAIN (s) = VAR_DOMAIN; 482119370Spst SYMBOL_CLASS (s) = LOC_BLOCK; 482219370Spst SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL, 482319370Spst st->objfile); 482419370Spst TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = mdebug_type_void; 482519370Spst 482619370Spst /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */ 4827130803Smarcel b = new_block (NON_FUNCTION_BLOCK); 482819370Spst SYMBOL_BLOCK_VALUE (s) = b; 482919370Spst BLOCK_START (b) = sigtramp_address; 483019370Spst BLOCK_END (b) = sigtramp_end; 483119370Spst BLOCK_FUNCTION (b) = s; 483219370Spst BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0); 483319370Spst add_block (b, st); 483419370Spst sort_blocks (st); 483519370Spst 483619370Spst /* Make a MIPS_EFI_SYMBOL_NAME entry for it */ 483719370Spst { 483819370Spst struct mips_extra_func_info *e = 483998944Sobrien ((struct mips_extra_func_info *) 484098944Sobrien xzalloc (sizeof (struct mips_extra_func_info))); 484119370Spst 484219370Spst e->numargs = 0; /* the kernel thinks otherwise */ 484319370Spst e->pdr.frameoffset = 32; 484419370Spst e->pdr.framereg = SP_REGNUM; 484519370Spst /* Note that setting pcreg is no longer strictly necessary as 484619370Spst mips_frame_saved_pc is now aware of signal handler frames. */ 484719370Spst e->pdr.pcreg = PC_REGNUM; 484819370Spst e->pdr.regmask = -2; 484919370Spst /* Offset to saved r31, in the sigtramp case the saved registers 485019370Spst are above the frame in the sigcontext. 485119370Spst We have 4 alignment bytes, 12 bytes for onstack, mask and pc, 485219370Spst 32 * 4 bytes for the general registers, 12 bytes for mdhi, mdlo, ownedfp 485319370Spst and 32 * 4 bytes for the floating point registers. */ 485419370Spst e->pdr.regoffset = 4 + 12 + 31 * 4; 485519370Spst e->pdr.fregmask = -1; 485619370Spst /* Offset to saved f30 (first saved *double* register). */ 485719370Spst e->pdr.fregoffset = 4 + 12 + 32 * 4 + 12 + 30 * 4; 485819370Spst e->pdr.isym = (long) s; 485919370Spst e->pdr.adr = sigtramp_address; 486019370Spst 486119370Spst current_objfile = st->objfile; /* Keep new_symbol happy */ 486219370Spst s = new_symbol (MIPS_EFI_SYMBOL_NAME); 486319370Spst SYMBOL_VALUE (s) = (long) e; 4864130803Smarcel SYMBOL_DOMAIN (s) = LABEL_DOMAIN; 486519370Spst SYMBOL_CLASS (s) = LOC_CONST; 486619370Spst SYMBOL_TYPE (s) = mdebug_type_void; 486719370Spst current_objfile = NULL; 486819370Spst } 486919370Spst 4870130803Smarcel dict_add_symbol (BLOCK_DICT (b), s); 487119370Spst} 487219370Spst 487398944Sobrien#endif /* TM_MIPS_H */ 487446283Sdfr 487519370Spstvoid 487698944Sobrien_initialize_mdebugread (void) 487719370Spst{ 487819370Spst mdebug_type_void = 487919370Spst init_type (TYPE_CODE_VOID, 1, 488019370Spst 0, 488119370Spst "void", (struct objfile *) NULL); 488219370Spst mdebug_type_char = 488319370Spst init_type (TYPE_CODE_INT, 1, 488419370Spst 0, 488519370Spst "char", (struct objfile *) NULL); 488619370Spst mdebug_type_unsigned_char = 488719370Spst init_type (TYPE_CODE_INT, 1, 488819370Spst TYPE_FLAG_UNSIGNED, 488919370Spst "unsigned char", (struct objfile *) NULL); 489019370Spst mdebug_type_short = 489119370Spst init_type (TYPE_CODE_INT, 2, 489219370Spst 0, 489319370Spst "short", (struct objfile *) NULL); 489419370Spst mdebug_type_unsigned_short = 489519370Spst init_type (TYPE_CODE_INT, 2, 489619370Spst TYPE_FLAG_UNSIGNED, 489719370Spst "unsigned short", (struct objfile *) NULL); 489819370Spst mdebug_type_int_32 = 489919370Spst init_type (TYPE_CODE_INT, 4, 490019370Spst 0, 490119370Spst "int", (struct objfile *) NULL); 490219370Spst mdebug_type_unsigned_int_32 = 490319370Spst init_type (TYPE_CODE_INT, 4, 490419370Spst TYPE_FLAG_UNSIGNED, 490519370Spst "unsigned int", (struct objfile *) NULL); 490619370Spst mdebug_type_int_64 = 490719370Spst init_type (TYPE_CODE_INT, 8, 490819370Spst 0, 490919370Spst "int", (struct objfile *) NULL); 491019370Spst mdebug_type_unsigned_int_64 = 491119370Spst init_type (TYPE_CODE_INT, 8, 491219370Spst TYPE_FLAG_UNSIGNED, 491319370Spst "unsigned int", (struct objfile *) NULL); 491419370Spst mdebug_type_long_32 = 491519370Spst init_type (TYPE_CODE_INT, 4, 491619370Spst 0, 491719370Spst "long", (struct objfile *) NULL); 491819370Spst mdebug_type_unsigned_long_32 = 491919370Spst init_type (TYPE_CODE_INT, 4, 492019370Spst TYPE_FLAG_UNSIGNED, 492119370Spst "unsigned long", (struct objfile *) NULL); 492219370Spst mdebug_type_long_64 = 492319370Spst init_type (TYPE_CODE_INT, 8, 492419370Spst 0, 492519370Spst "long", (struct objfile *) NULL); 492619370Spst mdebug_type_unsigned_long_64 = 492719370Spst init_type (TYPE_CODE_INT, 8, 492819370Spst TYPE_FLAG_UNSIGNED, 492919370Spst "unsigned long", (struct objfile *) NULL); 493019370Spst mdebug_type_long_long_64 = 493119370Spst init_type (TYPE_CODE_INT, 8, 493219370Spst 0, 493319370Spst "long long", (struct objfile *) NULL); 493498944Sobrien mdebug_type_unsigned_long_long_64 = 493519370Spst init_type (TYPE_CODE_INT, 8, 493619370Spst TYPE_FLAG_UNSIGNED, 493719370Spst "unsigned long long", (struct objfile *) NULL); 493819370Spst mdebug_type_adr_32 = 493919370Spst init_type (TYPE_CODE_PTR, 4, 494019370Spst TYPE_FLAG_UNSIGNED, 494119370Spst "adr_32", (struct objfile *) NULL); 494219370Spst TYPE_TARGET_TYPE (mdebug_type_adr_32) = mdebug_type_void; 494319370Spst mdebug_type_adr_64 = 494419370Spst init_type (TYPE_CODE_PTR, 8, 494519370Spst TYPE_FLAG_UNSIGNED, 494619370Spst "adr_64", (struct objfile *) NULL); 494719370Spst TYPE_TARGET_TYPE (mdebug_type_adr_64) = mdebug_type_void; 494819370Spst mdebug_type_float = 494919370Spst init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, 495019370Spst 0, 495119370Spst "float", (struct objfile *) NULL); 495219370Spst mdebug_type_double = 495319370Spst init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, 495419370Spst 0, 495519370Spst "double", (struct objfile *) NULL); 495619370Spst mdebug_type_complex = 495719370Spst init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, 495819370Spst 0, 495919370Spst "complex", (struct objfile *) NULL); 496019370Spst TYPE_TARGET_TYPE (mdebug_type_complex) = mdebug_type_float; 496119370Spst mdebug_type_double_complex = 496219370Spst init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, 496319370Spst 0, 496419370Spst "double complex", (struct objfile *) NULL); 496519370Spst TYPE_TARGET_TYPE (mdebug_type_double_complex) = mdebug_type_double; 496619370Spst 496719370Spst /* Is a "string" the way btString means it the same as TYPE_CODE_STRING? 496819370Spst FIXME. */ 496919370Spst mdebug_type_string = 497019370Spst init_type (TYPE_CODE_STRING, 497119370Spst TARGET_CHAR_BIT / TARGET_CHAR_BIT, 497219370Spst 0, "string", 497319370Spst (struct objfile *) NULL); 497419370Spst 497519370Spst /* We use TYPE_CODE_INT to print these as integers. Does this do any 497619370Spst good? Would we be better off with TYPE_CODE_ERROR? Should 497719370Spst TYPE_CODE_ERROR print things in hex if it knows the size? */ 497819370Spst mdebug_type_fixed_dec = 497919370Spst init_type (TYPE_CODE_INT, 498019370Spst TARGET_INT_BIT / TARGET_CHAR_BIT, 498119370Spst 0, "fixed decimal", 498219370Spst (struct objfile *) NULL); 498319370Spst 498419370Spst mdebug_type_float_dec = 498519370Spst init_type (TYPE_CODE_ERROR, 498619370Spst TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, 498719370Spst 0, "floating decimal", 498819370Spst (struct objfile *) NULL); 498919370Spst 499019370Spst nodebug_func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0, 499119370Spst "<function, no debug info>", NULL); 499219370Spst TYPE_TARGET_TYPE (nodebug_func_symbol_type) = mdebug_type_int; 499319370Spst nodebug_var_symbol_type = 499419370Spst init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0, 499519370Spst "<variable, no debug info>", NULL); 499619370Spst} 4997