📄 mipsread.c
字号:
/* Read a symbol table in MIPS' format (Third-Eye). Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU. Major work by Per Bothner and John Gilmore at Cygnus Support.This file is part of GDB.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* This module provides three functions: mipscoff_symfile_init, which initializes to read a symbol file; mipscoff_new_init, which discards existing cached information when all symbols are being discarded; and mipscoff_symfile_read, which reads a symbol table from a file. mipscoff_symfile_read only does the minimum work necessary for letting the user "name" things symbolically; it does not read the entire symtab. Instead, it reads the external and static symbols and puts them in partial symbol tables. When more extensive information is requested of a file, the corresponding partial symbol table is mutated into a full fledged symbol table by going back and reading the symbols for real. mipscoff_psymtab_to_symtab() is called indirectly through a pointer in the psymtab to do this. ECOFF symbol tables are mostly written in the byte order of the target machine. However, one section of the table (the auxiliary symbol information) is written in the host byte order. There is a bit in the other symbol info which describes which host byte order was used. ECOFF thereby takes the trophy from Intel `b.out' for the most brain-dead adaptation of a file format to byte order. This module can read all four of the known byte-order combinations, on any type of host. However, it does make (and check) the assumption that the external form of a symbol table structure (on disk) occupies the same number of bytes as the internal form (in a struct). Fixing this is possible but requires larger structural changes. */#define TM_FILE_OVERRIDE#include "defs.h"#include "tm-mips.h"#include "symtab.h"#include "gdbtypes.h"#include "gdbcore.h"#include "symfile.h"#include "objfiles.h"#include "obstack.h"#include "buildsym.h"#include "stabsread.h"#ifdef USG#include <sys/types.h>#define L_SET 0#define L_INCR 1#endif#include <sys/param.h>#include <sys/file.h>#include <sys/stat.h>#include "gdb-stabs.h"#include "coff/mips.h" /* COFF-like aspects of ecoff files */#include "coff/ecoff-ext.h" /* External forms of ecoff sym structures */#include "libbfd.h" /* FIXME Secret internal BFD stuff (bfd_read) */#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */#include "aout/aout64.h"#include "aout/stab_gnu.h" /* STABS information */struct coff_exec { struct external_filehdr f; struct external_aouthdr a;};/* These must match the corresponding definition in gcc/config/xm-mips.h. At some point, these should probably go into a shared include file, but currently gcc and gdb do not share any directories. */#define CODE_MASK 0x8F300#define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)#define MIPS_MARK_STAB(code) ((code)+CODE_MASK)#define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)#define STABS_SYMBOL "@stabs"/* Each partial symbol table entry contains a pointer to private data for the read_symtab() function to use when expanding a partial symbol table entry to a full symbol table entry. For mipsread this structure contains the index of the FDR that this psymtab represents and a pointer to the symbol table header HDRR from the symbol file that the psymtab was created from. */#define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)#define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)#define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)struct symloc { int fdr_idx; HDRR *cur_hdr; EXTR **extern_tab; /* Pointer to external symbols for this file. */ int extern_count; /* Size of extern_tab. */};/* Things we import explicitly from other modules */extern int info_verbose;/* Various complaints about symbol reading that don't abort the process */struct complaint bad_file_number_complaint = {"bad file number %d", 0, 0};struct complaint index_complaint = {"bad aux index at symbol %s", 0, 0};struct complaint aux_index_complaint = {"bad proc end in aux found from symbol %s", 0, 0};struct complaint unknown_ext_complaint = {"unknown external symbol %s", 0, 0};struct complaint unknown_sym_complaint = {"unknown local symbol %s", 0, 0};struct complaint unknown_st_complaint = {"with type %d", 0, 0};struct complaint block_overflow_complaint = {"block containing %s overfilled", 0, 0};struct complaint basic_type_complaint = {"cannot map MIPS basic type 0x%x", 0, 0};struct complaint unknown_type_qual_complaint = {"unknown type qualifier 0x%x", 0, 0};struct complaint array_bitsize_complaint = {"size of array target type not known, assuming %d bits", 0, 0};struct complaint bad_tag_guess_complaint = {"guessed tag type of %s incorrectly", 0, 0};struct complaint block_member_complaint = {"declaration block contains unhandled symbol type %d", 0, 0};struct complaint stEnd_complaint = {"stEnd with storage class %d not handled", 0, 0};struct complaint unknown_mips_symtype_complaint = {"unknown symbol type 0x%x", 0, 0};struct complaint stab_unknown_complaint = {"unknown stabs symbol %s", 0, 0};struct complaint pdr_for_nonsymbol_complaint = {"PDR for %s, but no symbol", 0, 0};struct complaint pdr_static_symbol_complaint = {"can't handle PDR for static proc at 0x%x", 0, 0};/* Macros and extra defs *//* Already-parsed symbols are marked specially */#define stParsed stType/* Puns: hard to find whether -g was used and how */#define MIN_GLEVEL GLEVEL_0#define compare_glevel(a,b) \ (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \ ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))/* When looking at .o files, avoid tripping over zero pointers. FIXME; places that use this should be fixed to convert from external to internal format, rather than examining in-place. */#define UNSAFE_DATA_ADDR(p) ((p) == 0)/* Things that really are local to this module *//* MIPS symtab header for the current file */static HDRR *cur_hdr;/* Pointer to current file decriptor record, and its index */static FDR *cur_fdr;static int cur_fd;/* Index of current symbol */static int cur_sdx;/* Note how much "debuggable" this image is. We would like to see at least one FDR with full symbols */static max_gdbinfo;static max_glevel;/* When examining .o files, report on undefined symbols */static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;/* Pseudo symbol to use when putting stabs into the symbol table. */static char stabs_symbol[] = STABS_SYMBOL;/* Extra builtin types */struct type *builtin_type_complex;struct type *builtin_type_double_complex;struct type *builtin_type_fixed_dec;struct type *builtin_type_float_dec;struct type *builtin_type_string;/* Forward declarations */static voidfixup_symtab PARAMS ((HDRR *, char *, file_ptr, bfd *));static voidread_mips_symtab PARAMS ((struct objfile *, struct section_offsets *));static voidread_the_mips_symtab PARAMS ((bfd *, CORE_ADDR *));static intupgrade_type PARAMS ((struct type **, int, union aux_ext *, int));static voidparse_partial_symbols PARAMS ((int, struct objfile *, struct section_offsets *));static intcross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **, int));static voidfixup_sigtramp PARAMS ((void));static struct symbol *new_symbol PARAMS ((char *));static struct type *new_type PARAMS ((char *));static struct block *new_block PARAMS ((int));static struct symtab *new_symtab PARAMS ((char *, int, int, struct objfile *));static struct linetable *new_linetable PARAMS ((int));static struct blockvector *new_bvect PARAMS ((int));static struct type *parse_type PARAMS ((union aux_ext *, int *, int));static struct symbol *mylookup_symbol PARAMS ((char *, struct block *, enum namespace, enum address_class));static struct block *shrink_block PARAMS ((struct block *, struct symtab *));static PTRxzalloc PARAMS ((unsigned int));static voidsort_blocks PARAMS ((struct symtab *));static intcompare_blocks PARAMS ((const void *, const void *));static struct partial_symtab *new_psymtab PARAMS ((char *, struct objfile *));#if 0static struct partial_symtab *parse_fdr PARAMS ((int, int, struct objfile *));#endifstatic voidpsymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));static voidadd_block PARAMS ((struct block *, struct symtab *));static voidadd_symbol PARAMS ((struct symbol *, struct block *));static intadd_line PARAMS ((struct linetable *, int, CORE_ADDR, int));static struct linetable *shrink_linetable PARAMS ((struct linetable *));static char *mips_next_symbol_text PARAMS ((void));/* Things we export to other modules *//* Address bounds for the signal trampoline in inferior, if any *//* FIXME: Nothing really seems to use this. Why is it here? */CORE_ADDR sigtramp_address, sigtramp_end;static voidmipscoff_new_init (ignore) struct objfile *ignore;{}static voidmipscoff_symfile_init (objfile) struct objfile *objfile;{ if (objfile -> sym_private != NULL) { mfree (objfile -> md, objfile -> sym_private); } objfile -> sym_private = NULL;}static voidmipscoff_symfile_read (objfile, section_offsets, mainline) struct objfile *objfile; struct section_offsets *section_offsets; int mainline;{ init_minimal_symbol_collection (); make_cleanup (discard_minimal_symbols, 0); /* Now that the executable file is positioned at symbol table, process it and define symbols accordingly. */ read_mips_symtab(objfile, section_offsets); /* Install any minimal symbols that have been collected as the current minimal symbols for this objfile. */ install_minimal_symbols (objfile);}/* Perform any local cleanups required when we are done with a particular objfile. I.E, we are in the process of discarding all symbol information for an objfile, freeing up all memory held for it, and unlinking the objfile struct from the global list of known objfiles. */static voidmipscoff_symfile_finish (objfile) struct objfile *objfile;{ if (objfile -> sym_private != NULL) { mfree (objfile -> md, objfile -> sym_private); } /* If we have a file symbol header lying around, blow it away. */ if (cur_hdr) { free ((PTR)cur_hdr); } cur_hdr = 0;}/* Allocate zeroed memory */static PTRxzalloc(size) unsigned int size;{ PTR p = xmalloc (size); memset (p, 0, size); return p;}/* Exported procedure: Builds a symtab from the PST partial one. Restores the environment in effect when PST was created, delegates most of the work to an ancillary procedure, and sorts and reorders the symtab list at the end */static voidmipscoff_psymtab_to_symtab(pst) struct partial_symtab *pst;{ if (!pst) return; if (info_verbose) { printf_filtered("Reading in symbols for %s...", pst->filename); fflush(stdout); } /* Restore the header and list of pending typedefs */ cur_hdr = CUR_HDR(pst); next_symbol_text_func = mips_next_symbol_text; psymtab_to_symtab_1(pst, pst->filename); /* Match with global symbols. This only needs to be done once, after all of the symtabs and dependencies have been read in. */ scan_file_globals (pst->objfile); if (info_verbose) printf_filtered("done.\n");}/* Exported procedure: Is PC in the signal trampoline code */intin_sigtramp(pc, ignore) CORE_ADDR pc; char *ignore; /* function name */{ if (sigtramp_address == 0) fixup_sigtramp(); return (pc >= sigtramp_address && pc < sigtramp_end);}/* File-level interface functions *//* Read the symtab information from file ABFD into memory. Also, return address just past end of our text segment in *END_OF_TEXT_SEGP. */static voidread_the_mips_symtab(abfd, end_of_text_segp) bfd *abfd; CORE_ADDR *end_of_text_segp;{ int stsize, st_hdrsize; file_ptr st_filptr; struct hdr_ext hdr_ext; HDRR st_hdr; /* Header for executable/object file we read symbols from */ struct coff_exec filhdr; int val; /* We need some info from the initial headers */ val = bfd_seek(abfd, (file_ptr) 0, L_SET);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -