This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Objdump: display file offsets whilst dumping via -s


Hi Guys,

  I am applying the attached patch to extend objdump's new file offset
  display feature so that it works when dumping sections via the -s
  command line option.

Cheers
  Nick

binutils/ChangeLog
2008-02-26  Nick Clifton  <nickc@redhat.com>

	* objdump.c (objdump_print_addr): If displaying file offsets, show
	the offset even if there are no symbols available.
	(dump_section): Display nothing if none of the section is going to
	be dumped.  Display the file offset, if requested, of the location
	from where the dump starts.
	* doc/binutils.texi (objdump): Mention that dumping via the -s
	switch is also affected by the -F option.

Index: binutils/objdump.c
===================================================================
RCS file: /cvs/src/src/binutils/objdump.c,v
retrieving revision 1.137
diff -c -3 -p -r1.137 objdump.c
*** binutils/objdump.c	22 Feb 2008 09:42:58 -0000	1.137
--- binutils/objdump.c	26 Feb 2008 08:27:02 -0000
*************** objdump_print_addr_with_sym (bfd *abfd, 
*** 864,870 ****
      }
  
    if (display_file_offsets)
!     info->fprintf_func (info->stream, " (File Offset: 0x%lx)",
  			(long int)(sec->filepos + (vma - sec->vma)));
  }
  
--- 864,870 ----
      }
  
    if (display_file_offsets)
!     info->fprintf_func (info->stream, _(" (File Offset: 0x%lx)"),
  			(long int)(sec->filepos + (vma - sec->vma)));
  }
  
*************** objdump_print_addr (bfd_vma vma,
*** 877,894 ****
  		    bfd_boolean skip_zeroes)
  {
    struct objdump_disasm_info *aux;
!   asymbol *sym = NULL; /* Initialize to avoid compiler warning.  */
    bfd_boolean skip_find = FALSE;
  
    if (sorted_symcount < 1)
      {
        (*info->fprintf_func) (info->stream, "0x");
        objdump_print_value (vma, info, skip_zeroes);
        return;
      }
  
-   aux = (struct objdump_disasm_info *) info->application_data;
- 
    if (aux->reloc != NULL
        && aux->reloc->sym_ptr_ptr != NULL
        && * aux->reloc->sym_ptr_ptr != NULL)
--- 877,898 ----
  		    bfd_boolean skip_zeroes)
  {
    struct objdump_disasm_info *aux;
!   asymbol *sym;
    bfd_boolean skip_find = FALSE;
  
+   aux = (struct objdump_disasm_info *) info->application_data;
+ 
    if (sorted_symcount < 1)
      {
        (*info->fprintf_func) (info->stream, "0x");
        objdump_print_value (vma, info, skip_zeroes);
+ 
+       if (display_file_offsets)
+ 	info->fprintf_func (info->stream, _(" (File Offset: 0x%lx)"),
+ 			    (long int)(aux->sec->filepos + (vma - aux->sec->vma)));
        return;
      }
  
    if (aux->reloc != NULL
        && aux->reloc->sym_ptr_ptr != NULL
        && * aux->reloc->sym_ptr_ptr != NULL)
*************** dump_section (bfd *abfd, asection *secti
*** 2464,2475 ****
    if ((datasize = bfd_section_size (abfd, section)) == 0)
      return;
  
-   printf (_("Contents of section %s:\n"), section->name);
- 
-   data = xmalloc (datasize);
- 
-   bfd_get_section_contents (abfd, section, data, 0, datasize);
- 
    /* Compute the address range to display.  */
    if (start_address == (bfd_vma) -1
        || start_address < section->vma)
--- 2468,2473 ----
*************** dump_section (bfd *abfd, asection *secti
*** 2490,2495 ****
--- 2488,2505 ----
  	stop_offset = datasize / opb;
      }
  
+   if (start_offset >= stop_offset)
+     return;
+   
+   printf (_("Contents of section %s:"), section->name);
+   if (display_file_offsets)
+     printf (_("  (Starting at file offset: 0x%lx)"), (long int)(section->filepos + start_offset));
+   printf ("\n");
+ 
+   data = xmalloc (datasize);
+ 
+   bfd_get_section_contents (abfd, section, data, 0, datasize);
+ 
    width = 4;
  
    bfd_sprintf_vma (abfd, buf, start_offset + section->vma);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]