* objdump.c (display_file_offsets): New variable.

(long_options): Add -F/--file-offsets.
  (objdump_print_addr_with_sym): If displaying file offsets, print
  the offset of the given address.
  (disassemble_bytes): If displaying file offsets, tell the user how
  many zeroes are skipped and the file offset of the point where
  dumping resumes.
  (disassemble_section): Only display the name of the section if
  data is going to be dumped from it.
  (main): Handle new option.  Produce error messages if the start or
  stop addresses do not make sense.
  * doc/binutils.texi: Document the new feature.
  * NEWS: Mention the new feature.
This commit is contained in:
Nick Clifton 2008-02-22 09:42:58 +00:00
parent f736769e93
commit 98ec6e7266
4 changed files with 57 additions and 5 deletions

View File

@ -1,3 +1,19 @@
2008-02-22 Nick Clifton <nickc@redhat.com>
* objdump.c (display_file_offsets): New variable.
(long_options): Add -F/--file-offsets.
(objdump_print_addr_with_sym): If displaying file offsets, print
the offset of the given address.
(disassemble_bytes): If displaying file offsets, tell the user how
many zeroes are skipped and the file offset of the point where
dumping resumes.
(disassemble_section): Only display the name of the section if
data is going to be dumped from it.
(main): Handle new option. Produce error messages if the start or
stop addresses do not make sense.
* doc/binutils.texi: Document the new feature.
* NEWS: Mention the new feature.
2008-02-15 Chu Li <chul@cn.fujitsu.com>
Nick Clifton <nickc@redhat.com>

View File

@ -1,4 +1,6 @@
-*- text -*-
* Added -F switch to objdump to include file offsets in the disassembly.
* Added -c switch to readelf to allow string dumps of archive symbol index.
* Support for SSE5 has been added to the i386 port.
@ -6,6 +8,7 @@
* Added -p switch to readelf to allow string dumps of sections.
Changes in 2.18:
* Resolved 37 coding problems in bfd including static array overruns, null
pointer dereferences and use of a malloc buffer after it has been freed, as
revealed by static analysis donated by Coverity, Inc. (http://scan.coverity.com).

View File

@ -11,7 +11,7 @@
@copying
@c man begin COPYRIGHT
Copyright @copyright{} 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
@ -1572,6 +1572,7 @@ objdump [@option{-a}|@option{--archive-headers}]
[@option{-z}|@option{--disassemble-zeroes}]
[@option{-EB}|@option{-EL}|@option{--endian=}@{big | little @}]
[@option{-f}|@option{--file-headers}]
[@option{-F}|@option{--file-offsets}]
[@option{--file-start-context}]
[@option{-g}|@option{--debugging}]
[@option{-e}|@option{--debugging-tags}]
@ -1715,6 +1716,15 @@ does not describe endianness information, such as S-records.
Display summary information from the overall header of
each of the @var{objfile} files.
@item -F
@itemx --file-offsets
@cindex object file offsets
When disassembling sections, whenever a symbol is displayed, also
display the file offset of the region of data that is about to be
dumped. If zeroes are being skipped, then when disassembly resumes,
tell the user how many zeroes were skipped and the file offset of the
location from where the disassembly resumes.
@item --file-start-context
@cindex source code context
Specify that when displaying interlisted source code/disassembly

View File

@ -110,6 +110,7 @@ static int dump_debugging_tags; /* --debugging-tags */
static int dump_special_syms = 0; /* --special-syms */
static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
static int file_start_context = 0; /* --file-start-context */
static bfd_boolean display_file_offsets;/* -F */
/* Pointer to an array of section names provided by
one or more "-j secname" command line options. */
@ -217,6 +218,7 @@ usage (FILE *stream, int status)
--file-start-context Include context from start of file (with -S)\n\
-I, --include=DIR Add DIR to search list for source files\n\
-l, --line-numbers Include line numbers and filenames in output\n\
-F, --file-offsets Include file offsets when displaying information\n\
-C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
The STYLE, if specified, can be `auto', `gnu',\n\
`lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
@ -267,6 +269,7 @@ static struct option long_options[]=
{"dynamic-syms", no_argument, NULL, 'T'},
{"endian", required_argument, NULL, OPTION_ENDIAN},
{"file-headers", no_argument, NULL, 'f'},
{"file-offsets", no_argument, NULL, 'F'},
{"file-start-context", no_argument, &file_start_context, 1},
{"full-contents", no_argument, NULL, 's'},
{"headers", no_argument, NULL, 'h'},
@ -859,6 +862,10 @@ objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
}
(*info->fprintf_func) (info->stream, ">");
}
if (display_file_offsets)
info->fprintf_func (info->stream, " (File Offset: 0x%lx)",
(long int)(sec->filepos + (vma - sec->vma)));
}
/* Print an address (VMA), symbolically if possible.
@ -1391,8 +1398,6 @@ disassemble_bytes (struct disassemble_info * info,
|| (z == stop_offset * opb &&
z - addr_offset * opb < skip_zeroes_at_end)))
{
printf ("\t...\n");
/* If there are more nonzero octets to follow, we only skip
zeroes in multiples of 4, to try to avoid running over
the start of an instruction which happens to start with
@ -1401,6 +1406,16 @@ disassemble_bytes (struct disassemble_info * info,
z = addr_offset * opb + ((z - addr_offset * opb) &~ 3);
octets = z - addr_offset * opb;
/* If we are going to display more data, and we are displaying
file offsets, then tell the user how many zeroes we skip
and the file offset from where we resume dumping. */
if (display_file_offsets && ((addr_offset + (octets / opb)) < stop_offset))
printf ("\t... (skipping %d zeroes, resuming at file offset: 0x%lx)\n",
octets / opb,
(long int)(section->filepos + (addr_offset + (octets / opb))));
else
printf ("\t...\n");
}
else
{
@ -1783,7 +1798,8 @@ disassemble_section (bfd *abfd, asection *section, void *info)
&& (*rel_pp)->address < rel_offset + addr_offset)
++rel_pp;
printf (_("Disassembly of section %s:\n"), section->name);
if (addr_offset < stop_offset)
printf (_("\nDisassembly of section %s:\n"), section->name);
/* Find the nearest symbol forwards from our current position. */
paux->require_sec = TRUE;
@ -3068,7 +3084,7 @@ main (int argc, char **argv)
bfd_init ();
set_default_bfd_target ();
while ((c = getopt_long (argc, argv, "pib:m:M:VvCdDlfaHhrRtTxsSI:j:wE:zgeGW",
while ((c = getopt_long (argc, argv, "pib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW",
long_options, (int *) 0))
!= EOF)
{
@ -3095,6 +3111,9 @@ main (int argc, char **argv)
}
only [only_used++] = optarg;
break;
case 'F':
display_file_offsets = TRUE;
break;
case 'l':
with_line_numbers = TRUE;
break;
@ -3123,9 +3142,13 @@ main (int argc, char **argv)
break;
case OPTION_START_ADDRESS:
start_address = parse_vma (optarg, "--start-address");
if ((stop_address != (bfd_vma) -1) && stop_address <= start_address)
fatal (_("error: the start address should be before the end address"));
break;
case OPTION_STOP_ADDRESS:
stop_address = parse_vma (optarg, "--stop-address");
if ((start_address != (bfd_vma) -1) && stop_address <= start_address)
fatal (_("error: the stop address should be after the start address"));
break;
case 'E':
if (strcmp (optarg, "B") == 0)