⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objdump.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 5 页
字号:
/* objdump.c -- dump information about an object file.   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,   2000, 2001   Free Software Foundation, Inc.This file is part of GNU Binutils.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, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#include "bfd.h"#include "getopt.h"#include "progress.h"#include "bucomm.h"#include <ctype.h>#include "dis-asm.h"#include "libiberty.h"#include "demangle.h"#include "debug.h"#include "budbg.h"/* Internal headers for the ELF .stab-dump code - sorry.  */#define	BYTES_IN_WORD	32#include "aout/aout64.h"#ifdef NEED_DECLARATION_FPRINTF/* This is needed by INIT_DISASSEMBLE_INFO.  */extern int fprintf PARAMS ((FILE *, const char *, ...));#endif/* Exit status.  */static int exit_status = 0;static char *default_target = NULL;	/* default at runtime */static int show_version = 0;		/* show the version number */static int dump_section_contents;	/* -s */static int dump_section_headers;	/* -h */static boolean dump_file_header;	/* -f */static int dump_symtab;			/* -t */static int dump_dynamic_symtab;		/* -T */static int dump_reloc_info;		/* -r */static int dump_dynamic_reloc_info;	/* -R */static int dump_ar_hdrs;		/* -a */static int dump_private_headers;	/* -p */static int prefix_addresses;		/* --prefix-addresses */static int with_line_numbers;		/* -l */static boolean with_source_code;	/* -S */static int show_raw_insn;		/* --show-raw-insn */static int dump_stab_section_info;	/* --stabs */static int do_demangle;			/* -C, --demangle */static boolean disassemble;		/* -d */static boolean disassemble_all;		/* -D */static int disassemble_zeroes;		/* --disassemble-zeroes */static boolean formats_info;		/* -i */static char *only;			/* -j secname */static int wide_output;			/* -w */static bfd_vma start_address = (bfd_vma) -1; /* --start-address */static bfd_vma stop_address = (bfd_vma) -1;  /* --stop-address */static int dump_debugging;		/* --debugging */static bfd_vma adjust_section_vma = 0;	/* --adjust-vma */static int file_start_context = 0;      /* --file-start-context *//* Extra info to pass to the disassembler address printing function.  */struct objdump_disasm_info {  bfd *abfd;  asection *sec;  boolean require_sec;};/* Architecture to disassemble for, or default if NULL.  */static char *machine = (char *) NULL;/* Target specific options to the disassembler.  */static char *disassembler_options = (char *) NULL;/* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN.  */static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;/* The symbol table.  */static asymbol **syms;/* Number of symbols in `syms'.  */static long symcount = 0;/* The sorted symbol table.  */static asymbol **sorted_syms;/* Number of symbols in `sorted_syms'.  */static long sorted_symcount = 0;/* The dynamic symbol table.  */static asymbol **dynsyms;/* Number of symbols in `dynsyms'.  */static long dynsymcount = 0;/* Static declarations.  */static voidusage PARAMS ((FILE *, int));static voidnonfatal PARAMS ((const char *));static voiddisplay_file PARAMS ((char *filename, char *target));static voiddump_section_header PARAMS ((bfd *, asection *, PTR));static voiddump_headers PARAMS ((bfd *));static voiddump_data PARAMS ((bfd *abfd));static voiddump_relocs PARAMS ((bfd *abfd));static voiddump_dynamic_relocs PARAMS ((bfd * abfd));static voiddump_reloc_set PARAMS ((bfd *, asection *, arelent **, long));static voiddump_symbols PARAMS ((bfd *abfd, boolean dynamic));static voiddump_bfd_header PARAMS ((bfd *));static voiddump_bfd_private_header PARAMS ((bfd *));static voiddisplay_bfd PARAMS ((bfd *abfd));static voiddisplay_target_list PARAMS ((void));static voiddisplay_info_table PARAMS ((int, int));static voiddisplay_target_tables PARAMS ((void));static voiddisplay_info PARAMS ((void));static voidobjdump_print_value PARAMS ((bfd_vma, struct disassemble_info *, boolean));static voidobjdump_print_symname PARAMS ((bfd *, struct disassemble_info *, asymbol *));static asymbol *find_symbol_for_address PARAMS ((bfd *, asection *, bfd_vma, boolean, long *));static voidobjdump_print_addr_with_sym PARAMS ((bfd *, asection *, asymbol *, bfd_vma,				     struct disassemble_info *, boolean));static voidobjdump_print_addr PARAMS ((bfd_vma, struct disassemble_info *, boolean));static voidobjdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));static voidshow_line PARAMS ((bfd *, asection *, bfd_vma));static voiddisassemble_bytes PARAMS ((struct disassemble_info *, disassembler_ftype,			   boolean, bfd_byte *, bfd_vma, bfd_vma,			   arelent ***, arelent **));static voiddisassemble_data PARAMS ((bfd *));static const char *endian_string PARAMS ((enum bfd_endian));static asymbol **slurp_symtab PARAMS ((bfd *));static asymbol **slurp_dynamic_symtab PARAMS ((bfd *));static longremove_useless_symbols PARAMS ((asymbol **, long));static intcompare_symbols PARAMS ((const PTR, const PTR));static intcompare_relocs PARAMS ((const PTR, const PTR));static voiddump_stabs PARAMS ((bfd *));static booleanread_section_stabs PARAMS ((bfd *, const char *, const char *));static voidprint_section_stabs PARAMS ((bfd *, const char *, const char *));static voidusage (stream, status)     FILE *stream;     int status;{  fprintf (stream, _("Usage: %s OPTION... FILE...\n"), program_name);  fprintf (stream, _("Display information from object FILE.\n"));  fprintf (stream, _("\n At least one of the following switches must be given:\n"));  fprintf (stream, _("\  -a, --archive-headers    Display archive header information\n\  -f, --file-headers       Display the contents of the overall file header\n\  -p, --private-headers    Display object format specific file header contents\n\  -h, --[section-]headers  Display the contents of the section headers\n\  -x, --all-headers        Display the contents of all headers\n\  -d, --disassemble        Display assembler contents of executable sections\n\  -D, --disassemble-all    Display assembler contents of all sections\n\  -S, --source             Intermix source code with disassembly\n\  -s, --full-contents      Display the full contents of all sections requested\n\  -g, --debugging          Display debug information in object file\n\  -G, --stabs              Display (in raw form) any STABS info in the file\n\  -t, --syms               Display the contents of the symbol table(s)\n\  -T, --dynamic-syms       Display the contents of the dynamic symbol table\n\  -r, --reloc              Display the relocation entries in the file\n\  -R, --dynamic-reloc      Display the dynamic relocation entries in the file\n\  -V, --version            Display this program's version number\n\  -i, --info               List object formats and architectures supported\n\  -H, --help               Display this information\n\"));  if (status != 2)    {      fprintf (stream, _("\n The following switches are optional:\n"));      fprintf (stream, _("\  -b, --target=BFDNAME           Specify the target object format as BFDNAME\n\  -m, --architecture=MACHINE     Specify the target architecture as MACHINE\n\  -j, --section=NAME             Only display information for section NAME\n\  -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\  -EB --endian=big               Assume big endian format when disassembling\n\  -EL --endian=little            Assume little endian format when disassembling\n\      --file-start-context       Include context from start of file (with -S)\n\  -l, --line-numbers             Include line numbers and filenames in output\n\  -C, --demangle[=STYLE]         Decode mangled/processed symbol names\n\                                  The STYLE, if specified, can be `auto', 'gnu',\n\                                  'lucid', 'arm', 'hp', 'edg', or 'gnu-new-abi'\n\  -w, --wide                     Format output for more than 80 columns\n\  -z, --disassemble-zeroes       Do not skip blocks of zeroes when disassembling\n\      --start-address=ADDR       Only process data whoes address is >= ADDR\n\      --stop-address=ADDR        Only process data whoes address is <= ADDR\n\      --prefix-addresses         Print complete address alongside disassembly\n\      --[no-]show-raw-insn       Display hex alongside symbolic disassembly\n\      --adjust-vma=OFFSET        Add OFFSET to all displayed section addresses\n\\n"));      list_supported_targets (program_name, stream);      disassembler_usage (stream);    }  if (status == 0)    fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);  exit (status);}/* 150 isn't special; it's just an arbitrary non-ASCII char value.  */#define OPTION_ENDIAN (150)#define OPTION_START_ADDRESS (OPTION_ENDIAN + 1)#define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)#define OPTION_ADJUST_VMA (OPTION_STOP_ADDRESS + 1)static struct option long_options[]={  {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA},  {"all-headers", no_argument, NULL, 'x'},  {"private-headers", no_argument, NULL, 'p'},  {"architecture", required_argument, NULL, 'm'},  {"archive-headers", no_argument, NULL, 'a'},  {"debugging", no_argument, NULL, 'g'},  {"demangle", optional_argument, NULL, 'C'},  {"disassemble", no_argument, NULL, 'd'},  {"disassemble-all", no_argument, NULL, 'D'},  {"disassembler-options", required_argument, NULL, 'M'},  {"disassemble-zeroes", no_argument, NULL, 'z'},  {"dynamic-reloc", no_argument, NULL, 'R'},  {"dynamic-syms", no_argument, NULL, 'T'},  {"endian", required_argument, NULL, OPTION_ENDIAN},  {"file-headers", no_argument, NULL, 'f'},  {"file-start-context", no_argument, &file_start_context, 1},  {"full-contents", no_argument, NULL, 's'},  {"headers", no_argument, NULL, 'h'},  {"help", no_argument, NULL, 'H'},  {"info", no_argument, NULL, 'i'},  {"line-numbers", no_argument, NULL, 'l'},  {"no-show-raw-insn", no_argument, &show_raw_insn, -1},  {"prefix-addresses", no_argument, &prefix_addresses, 1},  {"reloc", no_argument, NULL, 'r'},  {"section", required_argument, NULL, 'j'},  {"section-headers", no_argument, NULL, 'h'},  {"show-raw-insn", no_argument, &show_raw_insn, 1},  {"source", no_argument, NULL, 'S'},  {"stabs", no_argument, NULL, 'G'},  {"start-address", required_argument, NULL, OPTION_START_ADDRESS},  {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},  {"syms", no_argument, NULL, 't'},  {"target", required_argument, NULL, 'b'},  {"version", no_argument, NULL, 'V'},  {"wide", no_argument, NULL, 'w'},  {0, no_argument, 0, 0}};static voidnonfatal (msg)     const char *msg;{  bfd_nonfatal (msg);  exit_status = 1;}static voiddump_section_header (abfd, section, ignored)     bfd *abfd ATTRIBUTE_UNUSED;     asection *section;     PTR ignored ATTRIBUTE_UNUSED;{  char *comma = "";  unsigned int opb = bfd_octets_per_byte (abfd);  printf ("%3d %-13s %08lx  ", section->index,	  bfd_get_section_name (abfd, section),	  (unsigned long) bfd_section_size (abfd, section) / opb);  printf_vma (bfd_get_section_vma (abfd, section));  printf ("  ");  printf_vma (section->lma);  printf ("  %08lx  2**%u", section->filepos,	  bfd_get_section_alignment (abfd, section));  if (! wide_output)    printf ("\n                ");  printf ("  ");#define PF(x, y) \  if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }  PF (SEC_HAS_CONTENTS, "CONTENTS");  PF (SEC_ALLOC, "ALLOC");  PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");  PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");  PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");  PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");  PF (SEC_LOAD, "LOAD");  PF (SEC_RELOC, "RELOC");#ifdef SEC_BALIGN  PF (SEC_BALIGN, "BALIGN");#endif  PF (SEC_READONLY, "READONLY");  PF (SEC_CODE, "CODE");  PF (SEC_DATA, "DATA");  PF (SEC_ROM, "ROM");  PF (SEC_DEBUGGING, "DEBUGGING");  PF (SEC_NEVER_LOAD, "NEVER_LOAD");  PF (SEC_EXCLUDE, "EXCLUDE");  PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");  PF (SEC_BLOCK, "BLOCK");  PF (SEC_CLINK, "CLINK");  PF (SEC_SMALL_DATA, "SMALL_DATA");  PF (SEC_SHARED, "SHARED");  if ((section->flags & SEC_LINK_ONCE) != 0)    {      const char *ls;      switch (section->flags & SEC_LINK_DUPLICATES)	{	default:	  abort ();	case SEC_LINK_DUPLICATES_DISCARD:	  ls = "LINK_ONCE_DISCARD";	  break;	case SEC_LINK_DUPLICATES_ONE_ONLY:	  ls = "LINK_ONCE_ONE_ONLY";	  break;	case SEC_LINK_DUPLICATES_SAME_SIZE:	  ls = "LINK_ONCE_SAME_SIZE";	  break;	case SEC_LINK_DUPLICATES_SAME_CONTENTS:	  ls = "LINK_ONCE_SAME_CONTENTS";	  break;	}      printf ("%s%s", comma, ls);      if (section->comdat != NULL)	printf (" (COMDAT %s %ld)", section->comdat->name,		section->comdat->symbol);      comma = ", ";    }  printf ("\n");#undef PF}static voiddump_headers (abfd)     bfd *abfd;{  printf (_("Sections:\n"));#ifndef BFD64  printf (_("Idx Name          Size      VMA       LMA       File off  Algn"));#else  printf (_("Idx Name          Size      VMA               LMA               File off  Algn"));#endif  if (wide_output)    printf (_("  Flags"));  printf ("\n");  bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);}static asymbol **slurp_symtab (abfd)     bfd *abfd;{  asymbol **sy = (asymbol **) NULL;  long storage;  if (!(bfd_get_file_flags (abfd) & HAS_SYMS))    {      non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));      symcount = 0;      return NULL;    }  storage = bfd_get_symtab_upper_bound (abfd);  if (storage < 0)    bfd_fatal (bfd_get_filename (abfd));  if (storage)    {      sy = (asymbol **) xmalloc (storage);    }  symcount = bfd_canonicalize_symtab (abfd, sy);  if (symcount < 0)    bfd_fatal (bfd_get_filename (abfd));  if (symcount == 0)    non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));  return sy;}/* Read in the dynamic symbols.  */static asymbol **slurp_dynamic_symtab (abfd)     bfd *abfd;{  asymbol **sy = (asymbol **) NULL;  long storage;  storage = bfd_get_dynamic_symtab_upper_bound (abfd);  if (storage < 0)    {      if (!(bfd_get_file_flags (abfd) & DYNAMIC))	{	  non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));	  dynsymcount = 0;	  return NULL;	}      bfd_fatal (bfd_get_filename (abfd));    }  if (storage)    {      sy = (asymbol **) xmalloc (storage);    }  dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);  if (dynsymcount < 0)    bfd_fatal (bfd_get_filename (abfd));  if (dynsymcount == 0)    non_fatal (_("%s: No dynamic symbols"), bfd_get_filename (abfd));  return sy;}/* Filter out (in place) symbols that are useless for disassembly.   COUNT is the number of elements in SYMBOLS.   Return the number of useful symbols. */static longremove_useless_symbols (symbols, count)     asymbol **symbols;     long count;{  register asymbol **in_ptr = symbols, **out_ptr = symbols;  while (--count >= 0)    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -