This is the mail archive of the binutils@sources.redhat.com 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]

Re: objdump --full-contents truncates addresses to long


On Mar 25, 2003, Ian Lance Taylor <ian at airs dot com> wrote:

> Doesn't this make the output particularly ugly when dumping object
> files?  Perhaps the code could use bfd_sprintf_vma and strip off
> excess leading zeroes, while retaining even spacing?

Here's a patch.  It's a bit more cluttered than it had to be, due to
my being maybe overly paranoid in avoiding buffer overflows and on not
willing to rely on the undocumented behavior of bfd_sprintf_vma, that
currently always print strings with the same length, when given the
same bfd.  No regressions in the testsuite this time (yay!).  Ok to
install?

Index: binutils/ChangeLog
from  Alexandre Oliva  <aoliva at redhat dot com>

	* objdump.c (dump_data): Don't truncate the address to long; make
	the width large enough, and uniform for all entries in a section.

Index: binutils/objdump.c
===================================================================
RCS file: /cvs/uberbaum/binutils/objdump.c,v
retrieving revision 1.64
diff -u -p -r1.64 objdump.c
--- binutils/objdump.c 24 Mar 2003 11:28:35 -0000 1.64
+++ binutils/objdump.c 27 Mar 2003 04:17:28 -0000
@@ -2227,6 +2227,9 @@ dump_data (abfd)
 	{
 	  if (section->flags & SEC_HAS_CONTENTS)
 	    {
+	      char buf[64];
+	      int count, width;
+	      
 	      printf (_("Contents of section %s:\n"), section->name);
 
 	      if (bfd_section_size (abfd, section) == 0)
@@ -2253,13 +2256,47 @@ dump_data (abfd)
 		  if (stop_offset > bfd_section_size (abfd, section) / opb)
 		    stop_offset = bfd_section_size (abfd, section) / opb;
 		}
+
+	      width = 4;
+
+	      bfd_sprintf_vma (abfd, buf, start_offset + section->vma);
+	      if (strlen (buf) >= sizeof (buf))
+		abort ();
+	      count = 0;
+	      while (buf[count] == '0' && buf[count+1] != '\0')
+		count++;
+	      count = strlen (buf) - count;
+	      if (count > width)
+		width = count;
+
+	      bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1);
+	      if (strlen (buf) >= sizeof (buf))
+		abort ();
+	      count = 0;
+	      while (buf[count] == '0' && buf[count+1] != '\0')
+		count++;
+	      count = strlen (buf) - count;
+	      if (count > width)
+		width = count;
+
 	      for (addr_offset = start_offset;
 		   addr_offset < stop_offset; addr_offset += onaline / opb)
 		{
 		  bfd_size_type j;
 
-		  printf (" %04lx ", (unsigned long int)
-			  (addr_offset + section->vma));
+		  bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma));
+		  count = strlen (buf);
+		  if (count >= sizeof (buf))
+		    abort ();
+		  putchar (' ');
+		  while (count < width)
+		    {
+		      putchar ('0');
+		      count++;
+		    }
+		  fputs (buf + count - width, stdout);
+		  putchar (' ');
+
 		  for (j = addr_offset * opb;
 		       j < addr_offset * opb + onaline; j++)
 		    {
-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva at {redhat dot com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva at {lsd dot ic dot unicamp dot br, gnu.org}
Free Software Evangelist                Professional serial bug killer

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