/* objdump.c -- dump information about an object file.
- Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ 2000, 2001
Free Software Foundation, Inc.
This file is part of GNU Binutils.
#include "getopt.h"
#include "progress.h"
#include "bucomm.h"
-#include <ctype.h>
+#include "safe-ctype.h"
#include "dis-asm.h"
#include "libiberty.h"
#include "demangle.h"
/* Static declarations. */
-static void
-usage PARAMS ((FILE *, int));
-
-static void
-nonfatal PARAMS ((const char *));
-
-static void
-display_file PARAMS ((char *filename, char *target));
-
-static void
-dump_section_header PARAMS ((bfd *, asection *, PTR));
-
-static void
-dump_headers PARAMS ((bfd *));
-
-static void
-dump_data PARAMS ((bfd *abfd));
-
-static void
-dump_relocs PARAMS ((bfd *abfd));
-
-static void
-dump_dynamic_relocs PARAMS ((bfd * abfd));
-
-static void
-dump_reloc_set PARAMS ((bfd *, asection *, arelent **, long));
-
-static void
-dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
-
-static void
-dump_bfd_header PARAMS ((bfd *));
-
-static void
-dump_bfd_private_header PARAMS ((bfd *));
-
-static void
-display_bfd PARAMS ((bfd *abfd));
-
-static void
-display_target_list PARAMS ((void));
-
-static void
-display_info_table PARAMS ((int, int));
-
-static void
-display_target_tables PARAMS ((void));
-
-static void
-display_info PARAMS ((void));
-
-static void
-objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *, boolean));
-
-static void
-objdump_print_symname PARAMS ((bfd *, struct disassemble_info *, asymbol *));
-
-static asymbol *
-find_symbol_for_address PARAMS ((bfd *, asection *, bfd_vma, boolean, long *));
-
-static void
-objdump_print_addr_with_sym PARAMS ((bfd *, asection *, asymbol *, bfd_vma,
- struct disassemble_info *, boolean));
-
-static void
-objdump_print_addr PARAMS ((bfd_vma, struct disassemble_info *, boolean));
-
-static void
-objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
-
-static void
-show_line PARAMS ((bfd *, asection *, bfd_vma));
-
-static void
-disassemble_bytes PARAMS ((struct disassemble_info *, disassembler_ftype,
- boolean, bfd_byte *, bfd_vma, bfd_vma,
- arelent ***, arelent **));
-
-static void
-disassemble_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 long
-remove_useless_symbols PARAMS ((asymbol **, long));
-
-static int
-compare_symbols PARAMS ((const PTR, const PTR));
-
-static int
-compare_relocs PARAMS ((const PTR, const PTR));
-
-static void
-dump_stabs PARAMS ((bfd *));
-
-static boolean
-read_section_stabs PARAMS ((bfd *, const char *, const char *));
-
-static void
-print_section_stabs PARAMS ((bfd *, const char *, const char *));
+static void usage PARAMS ((FILE *, int));
+static void nonfatal PARAMS ((const char *));
+static void display_file PARAMS ((char *filename, char *target));
+static void dump_section_header PARAMS ((bfd *, asection *, PTR));
+static void dump_headers PARAMS ((bfd *));
+static void dump_data PARAMS ((bfd *abfd));
+static void dump_relocs PARAMS ((bfd *abfd));
+static void dump_dynamic_relocs PARAMS ((bfd * abfd));
+static void dump_reloc_set PARAMS ((bfd *, asection *, arelent **, long));
+static void dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
+static void dump_bfd_header PARAMS ((bfd *));
+static void dump_bfd_private_header PARAMS ((bfd *));
+static void dump_bfd PARAMS ((bfd *));
+static void display_bfd PARAMS ((bfd *abfd));
+static void display_target_list PARAMS ((void));
+static void display_info_table PARAMS ((int, int));
+static void display_target_tables PARAMS ((void));
+static void display_info PARAMS ((void));
+static void objdump_print_value
+ PARAMS ((bfd_vma, struct disassemble_info *, boolean));
+static void objdump_print_symname
+ PARAMS ((bfd *, struct disassemble_info *, asymbol *));
+static asymbol *find_symbol_for_address
+ PARAMS ((bfd *, asection *, bfd_vma, boolean, long *));
+static void objdump_print_addr_with_sym
+ PARAMS ((bfd *, asection *, asymbol *, bfd_vma,
+ struct disassemble_info *, boolean));
+static void objdump_print_addr
+ PARAMS ((bfd_vma, struct disassemble_info *, boolean));
+static void objdump_print_address
+ PARAMS ((bfd_vma, struct disassemble_info *));
+static int objdump_symbol_at_address
+ PARAMS ((bfd_vma, struct disassemble_info *));
+static void show_line PARAMS ((bfd *, asection *, bfd_vma));
+static void disassemble_bytes
+ PARAMS ((struct disassemble_info *, disassembler_ftype, boolean,
+ bfd_byte *, bfd_vma, bfd_vma, arelent ***, arelent **));
+static void disassemble_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 long remove_useless_symbols PARAMS ((asymbol **, long));
+static int compare_symbols PARAMS ((const PTR, const PTR));
+static int compare_relocs PARAMS ((const PTR, const PTR));
+static void dump_stabs PARAMS ((bfd *));
+static boolean read_section_stabs PARAMS ((bfd *, const char *, const char *));
+static void print_section_stabs PARAMS ((bfd *, const char *, const char *));
\f
static void
usage (stream, status)
FILE *stream;
int status;
{
- fprintf (stream, _("Usage: %s <switches> file(s)\n"), program_name);
- fprintf (stream, _(" At least one of the following switches must be given:\n"));
+ 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 the STABS contents of an ELF format 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\
+ -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 <o> Pass text <o> on to the disassembler\n\
+ -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 Decode mangled/processed symbol names\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\
+ -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\
+ --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
\n"));
list_supported_targets (program_name, stream);
-
+ list_supported_architectures (program_name, stream);
+
disassembler_usage (stream);
}
if (status == 0)
- fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
+ fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
exit (status);
}
{"architecture", required_argument, NULL, 'm'},
{"archive-headers", no_argument, NULL, 'a'},
{"debugging", no_argument, NULL, 'g'},
- {"demangle", no_argument, NULL, 'C'},
+ {"demangle", optional_argument, NULL, 'C'},
{"disassemble", no_argument, NULL, 'd'},
{"disassemble-all", no_argument, NULL, 'D'},
{"disassembler-options", required_argument, NULL, 'M'},
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));
+ bfd_printf_vma (abfd, bfd_get_section_vma (abfd, section));
printf (" ");
- printf_vma (section->lma);
- printf (" %08lx 2**%u", section->filepos,
+ bfd_printf_vma (abfd, section->lma);
+ printf (" %08lx 2**%u", (unsigned long) section->filepos,
bfd_get_section_alignment (abfd, section));
if (! wide_output)
printf ("\n ");
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_CLINK, "CLINK");
PF (SEC_SMALL_DATA, "SMALL_DATA");
PF (SEC_SHARED, "SHARED");
+ PF (SEC_ARCH_BIT_0, "ARCH_BIT_0");
if ((section->flags & SEC_LINK_ONCE) != 0)
{
{
char buf[30];
char *p;
+ struct objdump_disasm_info *aux
+ = (struct objdump_disasm_info *) info->application_data;
- sprintf_vma (buf, vma);
+ bfd_sprintf_vma (aux->abfd, buf, vma);
if (! skip_zeroes)
p = buf;
else
/* sprintf to a "stream" */
static int
-#ifdef ANSI_PROTOTYPES
-objdump_sprintf (SFILE *f, const char *format, ...)
-#else
-objdump_sprintf (va_alist)
- va_dcl
-#endif
+objdump_sprintf VPARAMS ((SFILE *f, const char *format, ...))
{
-#ifndef ANSI_PROTOTYPES
- SFILE *f;
- const char *format;
-#endif
char *buf;
- va_list args;
size_t n;
-#ifdef ANSI_PROTOTYPES
- va_start (args, format);
-#else
- va_start (args);
- f = va_arg (args, SFILE *);
- format = va_arg (args, const char *);
-#endif
+ VA_OPEN (args, format);
+ VA_FIXEDARG (args, SFILE *, f);
+ VA_FIXEDARG (args, const char *, format);
vasprintf (&buf, format, args);
- va_end (args);
-
if (buf == NULL)
{
+ va_end (args);
fatal (_("Out of virtual memory"));
}
free (buf);
+ VA_CLOSE (args);
return n;
}
/* The number of zeroes we want to see before we start skipping them.
The number is arbitrarily chosen. */
+#ifndef SKIP_ZEROES
#define SKIP_ZEROES (8)
+#endif
/* The number of zeroes to skip at the end of a section. If the
number of zeroes at the end is between SKIP_ZEROES_AT_END and
attempt to avoid disassembling zeroes inserted by section
alignment. */
+#ifndef SKIP_ZEROES_AT_END
#define SKIP_ZEROES_AT_END (3)
+#endif
/* Disassemble some data in memory between given values. */
char buf[30];
char *s;
- sprintf_vma (buf, section->vma +
- bfd_section_size (section->owner, section) / opb);
+ bfd_sprintf_vma
+ (aux->abfd, buf,
+ (section->vma
+ + bfd_section_size (section->owner, section) / opb));
s = buf;
while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0'
&& s[4] == '0')
done_dot = false;
if (with_line_numbers || with_source_code)
- show_line (aux->abfd, section, addr_offset);
+ /* The line number tables will refer to unadjusted
+ section VMAs, so we must undo any VMA modifications
+ when calling show_line. */
+ show_line (aux->abfd, section, addr_offset - adjust_section_vma);
if (! prefix_addresses)
{
char *s;
- sprintf_vma (buf, section->vma + addr_offset);
+ bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset);
for (s = buf + skip_addr_chars; *s == '0'; s++)
*s = ' ';
if (*s == '\0')
info->bytes_per_line = 0;
info->bytes_per_chunk = 0;
+#ifdef DISASSEMBLER_NEEDS_RELOCS
/* FIXME: This is wrong. It tests the number of octets
in the last instruction, not the current one. */
if (*relppp < relppend
&& (**relppp)->address >= addr_offset
- && (**relppp)->address < addr_offset + octets / opb)
+ && (**relppp)->address <= addr_offset + octets / opb)
info->flags = INSN_HAS_RELOC;
else
+#endif
info->flags = 0;
octets = (*disassemble_fn) (section->vma + addr_offset, info);
for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j)
{
- if (isprint (data[j]))
+ if (ISPRINT (data[j]))
buf[j - addr_offset * opb] = data[j];
else
buf[j - addr_offset * opb] = '.';
putchar ('\n');
j = addr_offset * opb + pb;
- sprintf_vma (buf, section->vma + j / opb);
+ bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
for (s = buf + skip_addr_chars; *s == '0'; s++)
*s = ' ';
if (*s == '\0')
need_nl = true;
}
- if (dump_reloc_info
- && (section->flags & SEC_RELOC) != 0)
+ if ((section->flags & SEC_RELOC) != 0
+#ifndef DISASSEMBLER_NEEDS_RELOCS
+ && dump_reloc_info
+#endif
+ )
{
while ((*relppp) < relppend
&& ((**relppp)->address >= (bfd_vma) addr_offset
&& (**relppp)->address < (bfd_vma) addr_offset + octets / opb))
+#ifdef DISASSEMBLER_NEEDS_RELOCS
+ if (! dump_reloc_info)
+ ++(*relppp);
+ else
+#endif
{
arelent *q;
if (only != (char *) NULL && strcmp (only, section->name) != 0)
continue;
- if (dump_reloc_info
- && (section->flags & SEC_RELOC) != 0)
+ if ((section->flags & SEC_RELOC) != 0
+#ifndef DISASSEMBLER_NEEDS_RELOCS
+ && dump_reloc_info
+#endif
+ )
{
long relsize;
disasm_info.buffer = data;
disasm_info.buffer_vma = section->vma;
disasm_info.buffer_length = datasize;
+ disasm_info.section = section;
if (start_address == (bfd_vma) -1
|| start_address < disasm_info.buffer_vma)
addr_offset = 0;
else
printf ("%-6d", type);
printf (" %-6d %-6d ", other, desc);
- printf_vma (value);
+ bfd_printf_vma (abfd, value);
printf (" %-6lu", strx);
/* Symbols with type == 0 (N_UNDF) specify the length of the
match or a section followed by a number. */
if (strncmp (stabsect_name, s->name, len) == 0
&& (s->name[len] == '\000'
- || isdigit ((unsigned char) s->name[len])))
+ || ISDIGIT (s->name[len])))
{
if (read_section_stabs (abfd, s->name, strsect_name))
{
PF (D_PAGED, "D_PAGED");
PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
printf (_("\nstart address 0x"));
- printf_vma (abfd->start_address);
+ bfd_printf_vma (abfd, abfd->start_address);
printf ("\n");
}
\f
if (j >= stop_offset * opb)
printf (" ");
else
- printf ("%c", isprint (data[j]) ? data[j] : '.');
+ printf ("%c", ISPRINT (data[j]) ? data[j] : '.');
}
putchar ('\n');
}
if (width == 0)
{
char buf[30];
- sprintf_vma (buf, (bfd_vma) -1);
+ bfd_sprintf_vma (abfd, buf, (bfd_vma) -1);
width = strlen (buf) - 7;
}
printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
}
if (sym_name)
{
- printf_vma (q->address);
+ bfd_printf_vma (abfd, q->address);
if (q->howto->name)
printf (" %-16s ", q->howto->name);
else
{
if (section_name == (CONST char *) NULL)
section_name = "*unknown*";
- printf_vma (q->address);
+ bfd_printf_vma (abfd, q->address);
printf (" %-16s [%s]",
q->howto->name,
section_name);
if (q->addend)
{
printf ("+0x");
- printf_vma (q->addend);
+ bfd_printf_vma (abfd, q->addend);
}
printf ("\n");
}
}
\f
/* The length of the longest architecture name + 1. */
-#define LONGEST_ARCH sizeof("rs6000:6000")
+#define LONGEST_ARCH sizeof("powerpc:common")
static const char *
endian_string (endian)
static void
display_target_list ()
{
- extern bfd_target *bfd_target_vector[];
+ extern const bfd_target *const *bfd_target_vector;
char *dummy_name;
int t;
dummy_name = make_temp_file (NULL);
for (t = 0; bfd_target_vector[t]; t++)
{
- bfd_target *p = bfd_target_vector[t];
+ const bfd_target *p = bfd_target_vector[t];
bfd *abfd = bfd_openw (dummy_name, p->name);
int a;
{
if (bfd_get_error () != bfd_error_invalid_operation)
nonfatal (p->name);
- bfd_close (abfd);
+ bfd_close_all_done (abfd);
continue;
}
if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
printf (" %s\n",
bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
- bfd_close (abfd);
+ bfd_close_all_done (abfd);
}
unlink (dummy_name);
free (dummy_name);
int first;
int last;
{
- extern bfd_target *bfd_target_vector[];
+ extern const bfd_target *const *bfd_target_vector;
int t, a;
char *dummy_name;
bfd_printable_arch_mach (a, 0));
for (t = first; t < last && bfd_target_vector[t]; t++)
{
- bfd_target *p = bfd_target_vector[t];
+ const bfd_target *p = bfd_target_vector[t];
boolean ok = true;
bfd *abfd = bfd_openw (dummy_name, p->name);
putchar (' ');
}
if (abfd != NULL)
- bfd_close (abfd);
+ bfd_close_all_done (abfd);
}
putchar ('\n');
}
display_target_tables ()
{
int t, columns;
- extern bfd_target *bfd_target_vector[];
+ extern const bfd_target *const *bfd_target_vector;
char *colum;
columns = 0;
#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
setlocale (LC_MESSAGES, "");
+#endif
+#if defined (HAVE_SETLOCALE)
+ setlocale (LC_CTYPE, "");
#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
break;
case 'C':
do_demangle = true;
+ if (optarg != NULL)
+ {
+ enum demangling_styles style;
+
+ style = cplus_demangle_name_to_style (optarg);
+ if (style == unknown_demangling)
+ fatal (_("unknown demangling style `%s'"),
+ optarg);
+
+ cplus_demangle_set_style (style);
+ }
break;
case 'w':
wide_output = true;