[COMMITTED] readelf: Use dwarf_form_name for printing (unknown) forms.

2018-01-01 Thread Mark Wielaard
A quick first commit of the year to make (error) output more consistent
in readelf:

Use dwarf_form_name consistently to print forms. attr_callback was
using its own string conversion, print_debug_macro_section was using
dwarf_form_string instead of dwarf_form_name.

The difference between dwarf_form_string and dwarf_form_name is that
the first returns NULL if the form is unknown and the second returns
an hexadecimal string representation in that case.

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog | 5 +
 src/readelf.c | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 9d6ec830..49b0cc03 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-01  Mark Wielaard  
+
+   * readelf.c (attr_callback): Use dwarf_form_name for unknown forms.
+   (print_debug_macro_section): Print form using dwarf_form_name.
+
 2017-12-28  Mark Wielaard  
 
* readelf.c (print_debug_units): Print DIE offset in error message
diff --git a/src/readelf.c b/src/readelf.c
index ee9c7e1d..4bdaef20 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6306,9 +6306,9 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 default:
   if (cbargs->silent)
break;
-  printf ("   %*s%-20s (form: %#x) ???\n",
+  printf ("   %*s%-20s (%s) ???\n",
  (int) (level * 2), "", dwarf_attr_name (attr),
- (int) form);
+ dwarf_form_name (form));
   break;
 }
 
@@ -7552,7 +7552,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod 
__attribute__ ((unused)),
  if (readp + 1 > readendp)
goto invalid_data;
  unsigned int form = *readp++;
- printf (" %s", dwarf_form_string (form));
+ printf (" %s", dwarf_form_name (form));
  if (form != DW_FORM_data1
  && form != DW_FORM_data2
  && form != DW_FORM_data4
-- 
2.14.3



Re: Simpler abbrev parsing using less memory

2018-01-01 Thread Mark Wielaard
On Tue, Dec 26, 2017 at 08:38:38PM +0100, Mark Wielaard wrote:
> [PATCH 1/2] libdw: New get_uleb128_unchecked to use with already
>checked Dwarf_Abbrev.
> 
> So the first patch introduces a get_uleb128_unchecked function that
> is used for re-reading such uleb128 values.
> 
> The second patch reduces the size of the struct Dwarf_Abbrev by not
> storing the attrcnt and by using bitfields for has_children and code.
> 
> [PATCH 2/2] libdw: Reduce size of struct Dwarf_Abbrev.

I pushed both patches to master.