printing scalars with objdump --debugging

Greg McGary gkm@work.mcgary.org
Thu Dec 20 20:49:00 GMT 2007


"objdump --debugging" handles scalars as the type VMA.  If VMA fits
within a host's long, scalars are printf'ed with "%lx", "%lu" or "%ld"
according to type.  If VMA doesn't fit in the host's long, scalars are
all printed as full-width hex.  This causes trouble for scripts that
digest the output, since output format depends on the cross-host where
objdump runs, e.g. ix86 vs. x86_64.  A naive fix is this:

diff -p -u binutils/prdbg.c.~1~ binutils/prdbg.c
--- binutils/prdbg.c.~1~	2007-08-06 12:56:14.000000000 -0700
+++ binutils/prdbg.c	2007-12-20 12:52:20.000000000 -0700
@@ -499,6 +499,15 @@ print_vma (bfd_vma vma, char *buf, bfd_b
       else
 	sprintf (buf, "%ld", (long) vma);
     }
+  if (sizeof (vma) <= sizeof (unsigned long long))
+    {
+      if (hexp)
+	sprintf (buf, "0x%llx", (unsigned long long) vma);
+      else if (unsignedp)
+	sprintf (buf, "%llu", (unsigned long long) vma);
+      else
+	sprintf (buf, "%lld", (long long) vma);
+    }
   else
     {
       buf[0] = '0';

I'll guess this is a potential portability problem for hosts that don't
support %ll formats, so it should be conditional on a flag generated
by configure.

Before I get involved with writing the configure test, I'd like to know if
you agree that the configure test is necessary, then if so, if this patch
will be acceptable when submitted with such test.

Greg



More information about the Binutils mailing list