This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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] readelf: Print DW_FORM_sdata values as signed numbers.


Printing DW_FORM_sdata numbers as unsigned values is misleading.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog |    5 +++++
 src/readelf.c |   34 +++++++++++++++++++++++++++-------
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 80be466..c166267 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-05  Mark Wielaard  <mjw@redhat.com>
+
+	* readelf.c (attr_callback): Print DW_FORM_sdata values as signed
+	numbers.
+
 2014-02-24  Mark Wielaard  <mjw@redhat.com>
 
 	* readelf (print_phdr): Check there is a SHT_PROGBITS section at the
diff --git a/src/readelf.c b/src/readelf.c
index 63675c6..d2efbae 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -5732,14 +5732,34 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 		  dwarf_form_name (form), (uintmax_t) num, a);
 	  free (a);
 	}
-      else if (valuestr == NULL)
-	printf ("           %*s%-20s (%s) %" PRIuMAX "\n",
-		(int) (level * 2), "", dwarf_attr_name (attr),
-		dwarf_form_name (form), (uintmax_t) num);
       else
-	printf ("           %*s%-20s (%s) %s (%" PRIuMAX ")\n",
-		(int) (level * 2), "", dwarf_attr_name (attr),
-		dwarf_form_name (form), valuestr, (uintmax_t) num);
+	{
+	  Dwarf_Sword snum = 0;
+	  if (form == DW_FORM_sdata)
+	    if (unlikely (dwarf_formsdata (attrp, &snum) != 0))
+	      goto attrval_out;
+
+	  if (valuestr == NULL)
+	    {
+	      printf ("           %*s%-20s (%s)",
+		      (int) (level * 2), "", dwarf_attr_name (attr),
+		      dwarf_form_name (form));
+	      if (form == DW_FORM_sdata)
+		printf (" %" PRIdMAX "\n", (intmax_t) snum);
+	      else
+		printf (" %" PRIuMAX "\n", (uintmax_t) num);
+	    }
+	  else
+	    {
+	      printf ("           %*s%-20s (%s) %s",
+		      (int) (level * 2), "", dwarf_attr_name (attr),
+		      dwarf_form_name (form), valuestr);
+	      if (form == DW_FORM_sdata)
+		printf (" (%" PRIdMAX ")\n", (intmax_t) snum);
+	      else
+		printf (" (%" PRIuMAX ")\n", (uintmax_t) num);
+	    }
+	}
       break;
 
     case DW_FORM_flag:
-- 
1.7.1


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