public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/5] readelf: Adjust print_ops formatting.
  2017-11-29 16:06 Various eu-readelf --debug-dump improvements Mark Wielaard
                   ` (2 preceding siblings ...)
  2017-11-29 16:06 ` [PATCH 2/5] readelf: Print abbrev code for DIE with --debug-dump=info Mark Wielaard
@ 2017-11-29 16:06 ` Mark Wielaard
  2017-11-29 16:06 ` [PATCH 3/5] readelf: Print actual file for decl_file and call_file attributes Mark Wielaard
  2017-12-10 16:00 ` Various eu-readelf --debug-dump improvements Mark Wielaard
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Wielaard @ 2017-11-29 16:06 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Use only 2 spaces for index (there are never 10000, the most seen in the
wild is 64). Adjust re-indenting after GNU_entry_value.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog                   |  5 ++++
 src/readelf.c                   | 58 ++++++++++++++++++++---------------------
 tests/ChangeLog                 |  7 +++++
 tests/run-readelf-dwz-multi.sh  | 32 +++++++++++------------
 tests/run-readelf-loc.sh        | 18 ++++++-------
 tests/run-readelf-zdebug-rel.sh | 18 ++++++-------
 tests/run-readelf-zdebug.sh     | 30 ++++++++++-----------
 7 files changed, 90 insertions(+), 78 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index c56c323..b88c319 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (print_ops): Use only2 space for index. re-indent +5
+	for DW_OP_GNU_entry_value.
+
 2017-11-21  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (attr_callback): Print attribute name and form in error
diff --git a/src/readelf.c b/src/readelf.c
index a9168d1..2faa1d5 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1,5 +1,5 @@
 /* Print information from ELF file in human-readable form.
-   Copyright (C) 1999-2016 Red Hat, Inc.
+   Copyright (C) 1999-2017 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 1999.
 
@@ -4152,7 +4152,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  CONSUME (addrsize);
 
 	  char *a = format_dwarf_addr (dwflmod, 0, addr, addr);
-	  printf ("%*s[%4" PRIuMAX "] %s %s\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %s\n",
 		  indent, "", (uintmax_t) offset, op_name, a);
 	  free (a);
 
@@ -4172,7 +4172,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  data += ref_size;
 	  CONSUME (ref_size);
 	  /* addr is a DIE offset, so format it as one.  */
-	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIxMAX "]\n",
+	  printf ("%*s[%2" PRIuMAX "] %s [%6" PRIxMAX "]\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, (uintmax_t) addr);
 	  offset += 1 + ref_size;
@@ -4184,7 +4184,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const1u:
 	  // XXX value might be modified by relocation
 	  NEED (1);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu8 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu8 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, *((uint8_t *) data));
 	  ++data;
@@ -4195,7 +4195,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const2u:
 	  NEED (2);
 	  // XXX value might be modified by relocation
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu16 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu16 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, read_2ubyte_unaligned (dbg, data));
 	  CONSUME (2);
@@ -4206,7 +4206,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const4u:
 	  NEED (4);
 	  // XXX value might be modified by relocation
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu32 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu32 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, read_4ubyte_unaligned (dbg, data));
 	  CONSUME (4);
@@ -4217,7 +4217,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const8u:
 	  NEED (8);
 	  // XXX value might be modified by relocation
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu64 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu64 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, (uint64_t) read_8ubyte_unaligned (dbg, data));
 	  CONSUME (8);
@@ -4228,7 +4228,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const1s:
 	  NEED (1);
 	  // XXX value might be modified by relocation
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRId8 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRId8 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, *((int8_t *) data));
 	  ++data;
@@ -4239,7 +4239,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const2s:
 	  NEED (2);
 	  // XXX value might be modified by relocation
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRId16 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRId16 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, read_2sbyte_unaligned (dbg, data));
 	  CONSUME (2);
@@ -4250,7 +4250,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const4s:
 	  NEED (4);
 	  // XXX value might be modified by relocation
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRId32 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRId32 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, read_4sbyte_unaligned (dbg, data));
 	  CONSUME (4);
@@ -4261,7 +4261,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_const8s:
 	  NEED (8);
 	  // XXX value might be modified by relocation
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRId64 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRId64 "\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, read_8sbyte_unaligned (dbg, data));
 	  CONSUME (8);
@@ -4277,7 +4277,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  uint64_t uleb;
 	  NEED (1);
 	  get_uleb128 (uleb, data, data + len);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu64 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu64 "\n",
 		  indent, "", (uintmax_t) offset, op_name, uleb);
 	  CONSUME (data - start);
 	  offset += 1 + (data - start);
@@ -4290,7 +4290,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  get_uleb128 (uleb, data, data + len);
 	  NEED (1);
 	  get_uleb128 (uleb2, data, data + len);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu64 ", %" PRIu64 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu64 ", %" PRIu64 "\n",
 		  indent, "", (uintmax_t) offset, op_name, uleb, uleb2);
 	  CONSUME (data - start);
 	  offset += 1 + (data - start);
@@ -4303,7 +4303,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  int64_t sleb;
 	  NEED (1);
 	  get_sleb128 (sleb, data, data + len);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRId64 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRId64 "\n",
 		  indent, "", (uintmax_t) offset, op_name, sleb);
 	  CONSUME (data - start);
 	  offset += 1 + (data - start);
@@ -4315,7 +4315,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  get_uleb128 (uleb, data, data + len);
 	  NEED (1);
 	  get_sleb128 (sleb, data, data + len);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu64 " %" PRId64 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu64 " %" PRId64 "\n",
 		  indent, "", (uintmax_t) offset, op_name, uleb, sleb);
 	  CONSUME (data - start);
 	  offset += 1 + (data - start);
@@ -4323,7 +4323,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 
 	case DW_OP_call2:
 	  NEED (2);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu16 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu16 "\n",
 		  indent, "", (uintmax_t) offset, op_name,
 		  read_2ubyte_unaligned (dbg, data));
 	  CONSUME (2);
@@ -4332,7 +4332,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 
 	case DW_OP_call4:
 	  NEED (4);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu32 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu32 "\n",
 		  indent, "", (uintmax_t) offset, op_name,
 		  read_4ubyte_unaligned (dbg, data));
 	  CONSUME (4);
@@ -4342,7 +4342,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	case DW_OP_skip:
 	case DW_OP_bra:
 	  NEED (2);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIuMAX "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIuMAX "\n",
 		  indent, "", (uintmax_t) offset, op_name,
 		  (uintmax_t) (offset + read_2sbyte_unaligned (dbg, data) + 3));
 	  CONSUME (2);
@@ -4354,7 +4354,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  start = data;
 	  NEED (1);
 	  get_uleb128 (uleb, data, data + len);
-	  printf ("%*s[%4" PRIuMAX "] %s: ",
+	  printf ("%*s[%2" PRIuMAX "] %s: ",
 		  indent, "", (uintmax_t) offset, op_name);
 	  NEED (uleb);
 	  print_block (uleb, data);
@@ -4378,7 +4378,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  NEED (1);
 	  get_sleb128 (sleb, data, data + len);
 
-	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIxMAX "] %+" PRId64 "\n",
+	  printf ("%*s[%2" PRIuMAX "] %s [%6" PRIxMAX "] %+" PRId64 "\n",
 		  indent, "", (intmax_t) offset,
 		  op_name, (uintmax_t) addr, sleb);
 	  CONSUME (data - start);
@@ -4390,10 +4390,10 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  start = data;
 	  NEED (1);
 	  get_uleb128 (uleb, data, data + len);
-	  printf ("%*s[%4" PRIuMAX "] %s:\n",
+	  printf ("%*s[%2" PRIuMAX "] %s:\n",
 		  indent, "", (uintmax_t) offset, op_name);
 	  NEED (uleb);
-	  print_ops (dwflmod, dbg, indent + 6, indent + 6, vers,
+	  print_ops (dwflmod, dbg, indent + 5, indent + 5, vers,
 		     addrsize, offset_size, cu, uleb, data);
 	  data += uleb;
 	  CONSUME (data - start);
@@ -4411,7 +4411,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  NEED (1);
 	  uint8_t usize = *(uint8_t *) data++;
 	  NEED (usize);
-	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIxMAX "] ",
+	  printf ("%*s[%2" PRIuMAX "] %s [%6" PRIxMAX "] ",
 		  indent, "", (uintmax_t) offset, op_name, uleb);
 	  print_block (usize, data);
 	  data += usize;
@@ -4429,7 +4429,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  get_uleb128 (uleb2, data, data + len);
 	  if (! print_unresolved_addresses && cu != NULL)
 	    uleb2 += cu->start;
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu64 " [%6" PRIx64 "]\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu64 " [%6" PRIx64 "]\n",
 		  indent, "", (uintmax_t) offset, op_name, uleb, uleb2);
 	  CONSUME (data - start);
 	  offset += 1 + (data - start);
@@ -4445,7 +4445,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  get_uleb128 (uleb, data, data + len);
 	  if (! print_unresolved_addresses && cu != NULL)
 	    uleb += cu->start;
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu8 " [%6" PRIxMAX "]\n",
+	  printf ("%*s[%2" PRIuMAX "] %s %" PRIu8 " [%6" PRIxMAX "]\n",
 		  indent, "", (uintmax_t) offset,
 		  op_name, usize, uleb);
 	  CONSUME (data - start);
@@ -4461,7 +4461,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  get_uleb128 (uleb, data, data + len);
 	  if (uleb != 0 && ! print_unresolved_addresses && cu != NULL)
 	    uleb += cu->start;
-	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIxMAX "]\n",
+	  printf ("%*s[%2" PRIuMAX "] %s [%6" PRIxMAX "]\n",
 		  indent, "", (uintmax_t) offset, op_name, uleb);
 	  CONSUME (data - start);
 	  offset += 1 + (data - start);
@@ -4474,7 +4474,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 	  uintmax_t param_off = (uintmax_t) read_4ubyte_unaligned (dbg, data);
 	  if (! print_unresolved_addresses && cu != NULL)
 	    param_off += cu->start;
-	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIxMAX "]\n",
+	  printf ("%*s[%2" PRIuMAX "] %s [%6" PRIxMAX "]\n",
 		  indent, "", (uintmax_t) offset, op_name, param_off);
 	  CONSUME (4);
 	  data += 4;
@@ -4483,7 +4483,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 
 	default:
 	  /* No Operand.  */
-	  printf ("%*s[%4" PRIuMAX "] %s\n",
+	  printf ("%*s[%2" PRIuMAX "] %s\n",
 		  indent, "", (uintmax_t) offset, op_name);
 	  ++offset;
 	  break;
@@ -4493,7 +4493,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
       continue;
 
     invalid:
-      printf (gettext ("%*s[%4" PRIuMAX "] %s  <TRUNCATED>\n"),
+      printf (gettext ("%*s[%2" PRIuMAX "] %s  <TRUNCATED>\n"),
 	      indent, "", (uintmax_t) offset, op_name);
       break;
     }
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 0162034..9633cd1 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
+	* run-readelf-dwz-multi.sh: Adjust expected ops index spaces.
+	* run-readelf-loc.sh: Likewise.
+	* run-readelf-zdebug-rel.sh: Likewise.
+	* run-readelf-zdebug.sh: Likewise.
+
 2017-11-16  Mark Wielaard  <mark@klomp.org>
 
 	* varlocs.c (main): Fix cfi_debug => cfi_debug_bias typo in assert.
diff --git a/tests/run-readelf-dwz-multi.sh b/tests/run-readelf-dwz-multi.sh
index 23ca944..139b8c1 100755
--- a/tests/run-readelf-dwz-multi.sh
+++ b/tests/run-readelf-dwz-multi.sh
@@ -107,7 +107,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
              low_pc               (addr) 0x00000000004006ac <main>
              high_pc              (udata) 44 (0x00000000004006d8)
              frame_base           (exprloc) 
-              [   0] call_frame_cfa
+              [ 0] call_frame_cfa
              GNU_all_tail_call_sites (flag_present) yes
              sibling              (ref_udata) [    6e]
  [    48]      formal_parameter
@@ -116,21 +116,21 @@ DWARF section [28] '.debug_info' at offset 0x1078:
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
-                [   0] fbreg -36
+                [ 0] fbreg -36
  [    56]      formal_parameter
                name                 (strp) "argv"
                decl_file            (data1) 1
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
-                [   0] fbreg -48
+                [ 0] fbreg -48
  [    61]      variable
                name                 (string) "b"
                decl_file            (data1) 1
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
-                [   0] fbreg -32
+                [ 0] fbreg -32
  [    6e]    pointer_type
              byte_size            (data1) 8
              type                 (ref_udata) [    2b]
@@ -168,7 +168,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
              low_pc               (addr) 0x00000000004006ac <main>
              high_pc              (udata) 44 (0x00000000004006d8)
              frame_base           (exprloc) 
-              [   0] call_frame_cfa
+              [ 0] call_frame_cfa
              GNU_all_tail_call_sites (flag_present) yes
              sibling              (ref_udata) [    6e]
  [    48]      formal_parameter
@@ -177,21 +177,21 @@ DWARF section [28] '.debug_info' at offset 0x1078:
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
-                [   0] fbreg -36
+                [ 0] fbreg -36
  [    56]      formal_parameter
                name                 (strp) "argv"
                decl_file            (data1) 1
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
-                [   0] fbreg -48
+                [ 0] fbreg -48
  [    61]      variable
                name                 (string) "b"
                decl_file            (data1) 1
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
-                [   0] fbreg -32
+                [ 0] fbreg -32
  [    6e]    pointer_type
              byte_size            (data1) 8
              type                 (ref_udata) [    2b]
@@ -225,7 +225,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              low_pc               (addr) +0x0000000000000670 <call_foo>
              high_pc              (udata) 23 (+0x0000000000000687)
              frame_base           (exprloc) 
-              [   0] call_frame_cfa
+              [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter
                name                 (string) "fb"
@@ -233,7 +233,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    76]
                location             (exprloc) 
-                [   0] fbreg -24
+                [ 0] fbreg -24
 EOF
 
 # Same as above, but find alt debug file in a .dwz subdir.
@@ -265,7 +265,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              low_pc               (addr) +0x0000000000000670 <call_foo>
              high_pc              (udata) 23 (+0x0000000000000687)
              frame_base           (exprloc) 
-              [   0] call_frame_cfa
+              [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter
                name                 (string) "fb"
@@ -273,7 +273,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    76]
                location             (exprloc) 
-                [   0] fbreg -24
+                [ 0] fbreg -24
 EOF
 mv .dwz/testfile_multi.dwz .
 rmdir .dwz
@@ -304,7 +304,7 @@ DWARF section [28] '.debug_info' at offset 0x1088:
              low_pc               (addr) 0x00000000004004ec <main>
              high_pc              (udata) 18 (0x00000000004004fe)
              frame_base           (exprloc) 
-              [   0] call_frame_cfa
+              [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter
                name                 (GNU_strp_alt) "argc"
@@ -312,21 +312,21 @@ DWARF section [28] '.debug_info' at offset 0x1088:
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    30]
                location             (exprloc) 
-                [   0] fbreg -36
+                [ 0] fbreg -36
  [    4f]      formal_parameter
                name                 (GNU_strp_alt) "argv"
                decl_file            (data1) 1
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    41]
                location             (exprloc) 
-                [   0] fbreg -48
+                [ 0] fbreg -48
  [    5d]      variable
                name                 (string) "fbb"
                decl_file            (data1) 1
                decl_line            (data1) 10
                type                 (GNU_ref_alt) [    14]
                location             (exprloc) 
-                [   0] fbreg -32
+                [ 0] fbreg -32
 EOF
 
 exit 0
diff --git a/tests/run-readelf-loc.sh b/tests/run-readelf-loc.sh
index 98870fc..3959d3d 100755
--- a/tests/run-readelf-loc.sh
+++ b/tests/run-readelf-loc.sh
@@ -63,9 +63,9 @@ testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ra
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  0x0000000000400480 <main>..0x000000000040048d <main+0xd> [   0] reg5
- [    23]  0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> [   0] reg5
- [    46]  0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> [   0] breg5 0
+ [     0]  0x0000000000400480 <main>..0x000000000040048d <main+0xd> [ 0] reg5
+ [    23]  0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> [ 0] reg5
+ [    46]  0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
  [     0]  0x0000000000400480 <main>..0x0000000000400482 <main+0x2>
@@ -79,9 +79,9 @@ testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=loc --debug-dump
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  0x0000000000400480..0x000000000040048d [   0] reg5
- [    23]  0x0000000000400485..0x000000000040048d [   0] reg5
- [    46]  0x00000000004004b2..0x00000000004004ba [   0] breg5 0
+ [     0]  0x0000000000400480..0x000000000040048d [ 0] reg5
+ [    23]  0x0000000000400485..0x000000000040048d [ 0] reg5
+ [    46]  0x00000000004004b2..0x00000000004004ba [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
  [     0]  0x0000000000400480..0x0000000000400482
@@ -95,9 +95,9 @@ testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc --debug-dump
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  000000000000000000..0x000000000000000d [   0] reg5
- [    23]  0x0000000000000005..0x000000000000000d [   0] reg5
- [    46]  0x0000000000000012..0x000000000000001a [   0] breg5 0
+ [     0]  000000000000000000..0x000000000000000d [ 0] reg5
+ [    23]  0x0000000000000005..0x000000000000000d [ 0] reg5
+ [    46]  0x0000000000000012..0x000000000000001a [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
  [     0]  000000000000000000..0x0000000000000002
diff --git a/tests/run-readelf-zdebug-rel.sh b/tests/run-readelf-zdebug-rel.sh
index 1232d63..082971e 100755
--- a/tests/run-readelf-zdebug-rel.sh
+++ b/tests/run-readelf-zdebug-rel.sh
@@ -69,7 +69,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
              low_pc               (addr) 000000000000000000
              high_pc              (data8) 24 (0x0000000000000018)
              frame_base           (exprloc) 
-              [   0] call_frame_cfa
+              [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
              sibling              (ref4) [    80]
  [    4e]      formal_parameter
@@ -84,7 +84,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
                decl_line            (data1) 4
                type                 (ref4) [    87]
                location             (exprloc) 
-                [   0] reg4
+                [ 0] reg4
  [    6a]      variable
                name                 (string) "a"
                decl_file            (data1) 1
@@ -97,7 +97,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
                decl_line            (data1) 7
                type                 (ref4) [    9a]
                location             (exprloc) 
-                [   0] reg5
+                [ 0] reg5
  [    80]    base_type
              byte_size            (data1) 4
              encoding             (data1) signed (5)
@@ -127,12 +127,12 @@ cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=i
 cat > loc.out << \EOF
 
 DWARF section [ 7] '.debug_loc' at offset 0x185:
- [     0]  000000000000000000..0x0000000000000003 [   0] reg5
-           0x0000000000000003..0x0000000000000010 [   0] breg5 -42
-                                                  [   2] stack_value
-           0x0000000000000010..0x0000000000000018 [   0] GNU_entry_value:
-       [   0] reg5
-                                                  [   3] stack_value
+ [     0]  000000000000000000..0x0000000000000003 [ 0] reg5
+           0x0000000000000003..0x0000000000000010 [ 0] breg5 -42
+                                                  [ 2] stack_value
+           0x0000000000000010..0x0000000000000018 [ 0] GNU_entry_value:
+      [ 0] reg5
+                                                  [ 3] stack_value
 EOF
 
 cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o
diff --git a/tests/run-readelf-zdebug.sh b/tests/run-readelf-zdebug.sh
index 37cf7ea..fc666fd 100755
--- a/tests/run-readelf-zdebug.sh
+++ b/tests/run-readelf-zdebug.sh
@@ -46,12 +46,12 @@ tempfiles loc.out aranges.out ranges.out macro.out line.out frame.out
 cat > loc.out << \EOF
 
 DWARF section [30] '.debug_loc' at offset 0xa17:
- [     0]  0x00000000004003c0..0x00000000004003c3 [   0] reg5
-           0x00000000004003c3..0x00000000004003d6 [   0] breg5 -42
-                                                  [   2] stack_value
-           0x00000000004003d6..0x00000000004003d9 [   0] GNU_entry_value:
-       [   0] reg5
-                                                  [   3] stack_value
+ [     0]  0x00000000004003c0..0x00000000004003c3 [ 0] reg5
+           0x00000000004003c3..0x00000000004003d6 [ 0] breg5 -42
+                                                  [ 2] stack_value
+           0x00000000004003d6..0x00000000004003d9 [ 0] GNU_entry_value:
+      [ 0] reg5
+                                                  [ 3] stack_value
 EOF
 
 cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug
@@ -476,15 +476,15 @@ Call frame information section [16] '.eh_frame' at offset 0x5b8:
      def_cfa_offset 24
      advance_loc 10 to 0x3b0
      def_cfa_expression 11
-          [   0] breg7 8
-          [   2] breg16 0
-          [   4] lit15
-          [   5] and
-          [   6] lit11
-          [   7] ge
-          [   8] lit3
-          [   9] shl
-          [  10] plus
+          [ 0] breg7 8
+          [ 2] breg16 0
+          [ 4] lit15
+          [ 5] and
+          [ 6] lit11
+          [ 7] ge
+          [ 8] lit3
+          [ 9] shl
+          [10] plus
      nop
      nop
      nop
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Various eu-readelf --debug-dump improvements
@ 2017-11-29 16:06 Mark Wielaard
  2017-11-29 16:06 ` [PATCH 5/5] readelf: Print CU, base address and unresolved .debug_loc entries Mark Wielaard
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Mark Wielaard @ 2017-11-29 16:06 UTC (permalink / raw)
  To: elfutils-devel

While working on the DWARF5 support I found various cases where the
eu-readelf --debug-dump could be improved to provide a bit more information
that helped debug issues. The following changes are not DWARF5 specific,
but improve the --debug-dump output to make a more useful (IMHO).

[PATCH 1/5] readelf: Adjust print_ops formatting.

This simply makes the DWARF expressions a little more compact and the
indenting a bit more consistent. In particular it only uses two space
for the operand index (the max I found in the wild was 64, so reserving
4 spaces for possibly 9999 indexes seemed excessive.

[PATCH 2/5] readelf: Print abbrev code for DIE with --debug-dump=info.

This was really convenient when there seemed something wrong with
the DIE information. It is also helpful to see how many DIEs share
a particular abbrev. The output is now:

 [    29]    base_type            abbrev: 74
             byte_size            (data1) 8
             encoding             (data1) unsigned (7)
             name                 (strp) "long unsigned int"

So you can easily lookup the corresponding abbrev with --debug-dump=abbrev

 [   74] offset: 1019, children: no, tag: base_type
          attr: byte_size, form: data1, offset: 0x3fb
          attr: encoding, form: data1, offset: 0x3fd
          attr: name, form: strp, offset: 0x3ff

And note that almost all base_types share the same abbrev code.

[PATCH 3/5] readelf: Print actual file for decl_file and call_file.

This was very helpful to understand where something was really defined.
It simply resolves the file number from the stmt list, so you don't
have to do that by hand anymore. New output:

 [    4c]    typedef              abbrev: 26
             name                 (strp) "size_t"
             decl_file            (data1) stddef.h (13)
             decl_line            (data1) 216
             decl_column          (data1) 23
             type                 (ref4) [    29]

[PATCH 4/5] readelf: Print CU, base address and unresolved .debug_ranges.

We helpfully resolve the addresses to actual symbol+offsets whenever
possible, but this kind of obscured what the actual encoding was. And
it made the output a bit messy because addresses didn't line up. It now
also prints out the associated CU and the base address to the range list.

 CU [ 3582e] base: 0x000000000041de70 <ebl_machine_flag_name>
 [  c370] range 2a, 6a
          0x000000000041de9a <ebl_machine_flag_name+0x2a>..
          0x000000000041ded9 <ebl_machine_flag_name+0x69>
          range 80, e5
          0x000000000041def0 <ebl_machine_flag_name+0x80>..
          0x000000000041df54 <ebl_machine_flag_name+0xe4>
          range f8, 11a
          0x000000000041df68 <ebl_machine_flag_name+0xf8>..
          0x000000000041df89 <ebl_machine_flag_name+0x119>
 [  c3b0] range 91, 9f
          0x000000000041df01 <ebl_machine_flag_name+0x91>..
          0x000000000041df0e <ebl_machine_flag_name+0x9e>
          range a3, a6
          0x000000000041df13 <ebl_machine_flag_name+0xa3>..
          0x000000000041df15 <ebl_machine_flag_name+0xa5>

[PATCH 5/5] readelf: Print CU, base address and unresolved .debug_loc.

Like the .debug_ranges change, but including location list entries.
The new output is (IMHO) a big improvement:

CU [ 4a404] base: 0x000000000041f350 <__popcountdi2>
 [ 3c3e2] range 0, 24
          0x000000000041f350 <__popcountdi2>..
          0x000000000041f373 <__popcountdi2+0x23>
           [ 0] reg5
          range 24, 2b
          0x000000000041f374 <__popcountdi2+0x24>..
          0x000000000041f37a <__popcountdi2+0x2a>
           [ 0] reg5
          range 2b, 2e
          0x000000000041f37b <__popcountdi2+0x2b>..
          0x000000000041f37d <__popcountdi2+0x2d>
           [ 0] reg0
          range 2e, 3e
          0x000000000041f37e <__popcountdi2+0x2e>..
          0x000000000041f38d <__popcountdi2+0x3d>
           [ 0] GNU_entry_value:
                [ 0] reg5
           [ 3] GNU_entry_value:
                [ 0] reg5
           [ 6] lit1
           [ 7] shr
           [ 8] constu 6148914691236517205
           [18] and
           [19] minus
           [20] stack_value
          range 3e, 48
          0x000000000041f38e <__popcountdi2+0x3e>..
          0x000000000041f397 <__popcountdi2+0x47>
           [ 0] reg5
          range 48, 4b
          0x000000000041f398 <__popcountdi2+0x48>..
          0x000000000041f39a <__popcountdi2+0x4a>
           [ 0] breg0 0
           [ 2] constu 1085102592571150095
           [12] and
           [13] stack_value
          range 4b, 59
          0x000000000041f39b <__popcountdi2+0x4b>..
          0x000000000041f3a8 <__popcountdi2+0x58>
           [ 0] reg0
          range 59, 5e
          0x000000000041f3a9 <__popcountdi2+0x59>..
          0x000000000041f3ad <__popcountdi2+0x5d>
           [ 0] breg5 0
           [ 2] lit4
           [ 3] shr
           [ 4] breg5 0
           [ 6] plus
           [ 7] constu 1085102592571150095
           [17] and
           [18] stack_value

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] readelf: Print CU, base address and unresolved .debug_range entries.
  2017-11-29 16:06 Various eu-readelf --debug-dump improvements Mark Wielaard
  2017-11-29 16:06 ` [PATCH 5/5] readelf: Print CU, base address and unresolved .debug_loc entries Mark Wielaard
@ 2017-11-29 16:06 ` Mark Wielaard
  2017-11-29 16:06 ` [PATCH 2/5] readelf: Print abbrev code for DIE with --debug-dump=info Mark Wielaard
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Wielaard @ 2017-11-29 16:06 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Also adjust the formatting for the resolved addresses to print them
on separate lines so they nicely line up even when the addresses are
resolved to symbol+offset names.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog               |  5 +++++
 src/readelf.c               | 47 ++++++++++++++++++++++++++++++----------
 tests/ChangeLog             |  5 +++++
 tests/run-readelf-loc.sh    | 52 ++++++++++++++++++++++++++++++++++-----------
 tests/run-readelf-zdebug.sh |  4 +++-
 5 files changed, 89 insertions(+), 24 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 12cd571..3dd80fb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* readelf.c (print_debug_ranges_section): Print CU base and unresolved
+	addresses. Adjust formatting.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* readelf.c (attr_callback): Set valuestr to resolved file name
 	for DW_AT_decl_file and DW_AT_call_file.
 
diff --git a/src/readelf.c b/src/readelf.c
index 8661ba8..8e13462 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -5007,15 +5007,33 @@ print_debug_ranges_section (Dwfl_Module *dwflmod,
   Dwarf_Addr base = 0;
   unsigned char *const endp = (unsigned char *) data->d_buf + data->d_size;
   unsigned char *readp = data->d_buf;
+  Dwarf_CU *last_cu = NULL;
   while (readp < endp)
     {
       ptrdiff_t offset = readp - (unsigned char *) data->d_buf;
+      Dwarf_CU *cu;
 
       if (first && skip_listptr_hole (&known_rangelistptr, &listptr_idx,
-				      &address_size, NULL, &base, NULL,
+				      &address_size, NULL, &base, &cu,
 				      offset, &readp, endp))
 	continue;
 
+      if (last_cu != cu)
+	{
+	  char *basestr = format_dwarf_addr (dwflmod, address_size,
+					     base, base);
+	  Dwarf_Die cudie;
+	  if (dwarf_cu_die (cu, &cudie,
+			    NULL, NULL, NULL, NULL,
+			    NULL, NULL) == NULL)
+	    printf (gettext ("\n Unknown CU base: %s\n"), basestr);
+	  else
+	    printf (gettext ("\n CU [%6" PRIx64 "] base: %s\n"),
+		    dwarf_dieoffset (&cudie), basestr);
+	  free (basestr);
+	}
+      last_cu = cu;
+
       if (unlikely (data->d_size - offset < (size_t) address_size * 2))
 	{
 	  printf (gettext (" [%6tx]  <INVALID DATA>\n"), offset);
@@ -5040,29 +5058,36 @@ print_debug_ranges_section (Dwfl_Module *dwflmod,
       if (begin == (Dwarf_Addr) -1l) /* Base address entry.  */
 	{
 	  char *b = format_dwarf_addr (dwflmod, address_size, end, end);
-	  printf (gettext (" [%6tx]  base address %s\n"), offset, b);
+	  printf (gettext (" [%6tx] base address\n          %s\n"), offset, b);
 	  free (b);
 	  base = end;
 	}
       else if (begin == 0 && end == 0) /* End of list entry.  */
 	{
 	  if (first)
-	    printf (gettext (" [%6tx]  empty list\n"), offset);
+	    printf (gettext (" [%6tx] empty list\n"), offset);
 	  first = true;
 	}
       else
 	{
-	  char *b = format_dwarf_addr (dwflmod, address_size, base + begin,
-				       begin);
-	  char *e = format_dwarf_addr (dwflmod, address_size, base + end,
-				       end);
 	  /* We have an address range entry.  */
 	  if (first)		/* First address range entry in a list.  */
-	    printf (gettext (" [%6tx]  %s..%s\n"), offset, b, e);
+	    printf (" [%6tx] ", offset);
 	  else
-	    printf (gettext ("           %s..%s\n"), b, e);
-	  free (b);
-	  free (e);
+	    printf ("          ");
+
+	  printf ("range %" PRIx64 ", %" PRIx64 "\n", begin, end);
+	  if (! print_unresolved_addresses)
+	    {
+	      char *b = format_dwarf_addr (dwflmod, address_size, base + begin,
+					   base + begin);
+	      char *e = format_dwarf_addr (dwflmod, address_size,
+					   base + end - 1, base + end);
+	      printf ("          %s..\n", b);
+	      printf ("          %s\n", e);
+	      free (b);
+	      free (e);
+	    }
 
 	  first = false;
 	}
diff --git a/tests/ChangeLog b/tests/ChangeLog
index c9fc53a..4666dcc 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,10 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* run-readelf-loc.sh: Adjust expected range list output.
+	* run-readelf-zdebug.sh: Likewise.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* run-readelf-dwz-multi.sh: Add expected file names.
 	* run-readelf-zdebug-rel.sh: Likewise.
 
diff --git a/tests/run-readelf-loc.sh b/tests/run-readelf-loc.sh
index 3959d3d..4b666cf 100755
--- a/tests/run-readelf-loc.sh
+++ b/tests/run-readelf-loc.sh
@@ -68,10 +68,22 @@ DWARF section [33] '.debug_loc' at offset 0xd2a:
  [    46]  0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
- [     0]  0x0000000000400480 <main>..0x0000000000400482 <main+0x2>
-           0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd>
- [    30]  0x00000000004004ad <say+0xd>..0x00000000004004af <say+0xf>
-           0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a>
+
+ CU [     b] base: 0x0000000000400480 <main>
+ [     0] range 0, 2
+          0x0000000000400480 <main>..
+          0x0000000000400481 <main+0x1>
+          range 5, d
+          0x0000000000400485 <main+0x5>..
+          0x000000000040048c <main+0xc>
+
+ CU [    e0] base: 0x00000000004004a0 <say>
+ [    30] range d, f
+          0x00000000004004ad <say+0xd>..
+          0x00000000004004ae <say+0xe>
+          range 12, 1a
+          0x00000000004004b2 <say+0x12>..
+          0x00000000004004b9 <say+0x19>
 EOF
 
 # Don't resolve addresses to symbols.
@@ -84,10 +96,22 @@ DWARF section [33] '.debug_loc' at offset 0xd2a:
  [    46]  0x00000000004004b2..0x00000000004004ba [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
- [     0]  0x0000000000400480..0x0000000000400482
-           0x0000000000400485..0x000000000040048d
- [    30]  0x00000000004004ad..0x00000000004004af
-           0x00000000004004b2..0x00000000004004ba
+
+ CU [     b] base: 0x0000000000400480
+ [     0] range 0, 2
+          0x0000000000400480..
+          0x0000000000400481
+          range 5, d
+          0x0000000000400485..
+          0x000000000040048c
+
+ CU [    e0] base: 0x00000000004004a0
+ [    30] range d, f
+          0x00000000004004ad..
+          0x00000000004004ae
+          range 12, 1a
+          0x00000000004004b2..
+          0x00000000004004b9
 EOF
 
 # Produce "raw" unprocessed content.
@@ -100,10 +124,14 @@ DWARF section [33] '.debug_loc' at offset 0xd2a:
  [    46]  0x0000000000000012..0x000000000000001a [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
- [     0]  000000000000000000..0x0000000000000002
-           0x0000000000000005..0x000000000000000d
- [    30]  0x000000000000000d..0x000000000000000f
-           0x0000000000000012..0x000000000000001a
+
+ CU [     b] base: 0x0000000000400480
+ [     0] range 0, 2
+          range 5, d
+
+ CU [    e0] base: 0x00000000004004a0
+ [    30] range d, f
+          range 12, 1a
 EOF
 
 exit 0
diff --git a/tests/run-readelf-zdebug.sh b/tests/run-readelf-zdebug.sh
index fc666fd..7be9bee 100755
--- a/tests/run-readelf-zdebug.sh
+++ b/tests/run-readelf-zdebug.sh
@@ -80,7 +80,9 @@ cat aranges.out | sed -e "s/.debug_aranges' at offset 0xa65/.zdebug_aranges' at
 cat > ranges.out << \EOF
 
 DWARF section [32] '.debug_ranges' at offset 0xa95:
- [     0]  0x00000000004003c0..0x00000000004003d9
+
+ CU [     b] base: 000000000000000000
+ [     0] range 4003c0, 4003d9
 EOF
 
 cat ranges.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=ranges testfile-debug
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] readelf: Print CU, base address and unresolved .debug_loc entries.
  2017-11-29 16:06 Various eu-readelf --debug-dump improvements Mark Wielaard
@ 2017-11-29 16:06 ` Mark Wielaard
  2017-11-29 16:06 ` [PATCH 4/5] readelf: Print CU, base address and unresolved .debug_range entries Mark Wielaard
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Wielaard @ 2017-11-29 16:06 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Also adjust the formatting for the resolved addresses to print them
on separate lines so they nicely line up even when the addresses are
resolved to symbol+offset names. And print the operands starting on
a new line.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog                   |  5 ++++
 src/readelf.c                   | 51 ++++++++++++++++++++++++++++++-----------
 tests/ChangeLog                 |  6 +++++
 tests/run-readelf-loc.sh        | 51 +++++++++++++++++++++++++++++++++--------
 tests/run-readelf-zdebug-rel.sh | 17 +++++++++-----
 tests/run-readelf-zdebug.sh     | 17 +++++++++-----
 6 files changed, 112 insertions(+), 35 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 3dd80fb..612b365 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* readelf.c (print_debug_loc_section): Print CU base and unresolved
+	addresses. Adjust formatting.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* readelf.c (print_debug_ranges_section): Print CU base and unresolved
 	addresses. Adjust formatting.
 
diff --git a/src/readelf.c b/src/readelf.c
index 8e13462..bb48af9 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -7130,19 +7130,36 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
   uint_fast8_t offset_size = 4;
 
   bool first = true;
-  struct Dwarf_CU *cu = NULL;
   Dwarf_Addr base = 0;
   unsigned char *readp = data->d_buf;
   unsigned char *const endp = (unsigned char *) data->d_buf + data->d_size;
+  Dwarf_CU *last_cu = NULL;
   while (readp < endp)
     {
       ptrdiff_t offset = readp - (unsigned char *) data->d_buf;
+      Dwarf_CU *cu;
 
       if (first && skip_listptr_hole (&known_loclistptr, &listptr_idx,
 				      &address_size, &offset_size, &base,
 				      &cu, offset, &readp, endp))
 	continue;
 
+      if (last_cu != cu)
+       {
+	char *basestr = format_dwarf_addr (dwflmod, address_size,
+					   base, base);
+	Dwarf_Die cudie;
+	if (dwarf_cu_die (cu, &cudie,
+			  NULL, NULL, NULL, NULL,
+			  NULL, NULL) == NULL)
+	  printf (gettext ("\n Unknown CU base: %s\n"), basestr);
+	else
+	  printf (gettext ("\n CU [%6" PRIx64 "] base: %s\n"),
+		  dwarf_dieoffset (&cudie), basestr);
+	free (basestr);
+       }
+      last_cu = cu;
+
       if (unlikely (data->d_size - offset < (size_t) address_size * 2))
 	{
 	  printf (gettext (" [%6tx]  <INVALID DATA>\n"), offset);
@@ -7167,14 +7184,14 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
       if (begin == (Dwarf_Addr) -1l) /* Base address entry.  */
 	{
 	  char *b = format_dwarf_addr (dwflmod, address_size, end, end);
-	  printf (gettext (" [%6tx]  base address %s\n"), offset, b);
+	  printf (gettext (" [%6tx] base address\n          %s\n"), offset, b);
 	  free (b);
 	  base = end;
 	}
       else if (begin == 0 && end == 0) /* End of list entry.  */
 	{
 	  if (first)
-	    printf (gettext (" [%6tx]  empty list\n"), offset);
+	    printf (gettext (" [%6tx] empty list\n"), offset);
 	  first = true;
 	}
       else
@@ -7182,18 +7199,23 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
 	  /* We have a location expression entry.  */
 	  uint_fast16_t len = read_2ubyte_unaligned_inc (dbg, readp);
 
-	  char *b = format_dwarf_addr (dwflmod, address_size, base + begin,
-				       begin);
-	  char *e = format_dwarf_addr (dwflmod, address_size, base + end,
-				       end);
-
 	  if (first)		/* First entry in a list.  */
-	    printf (gettext (" [%6tx]  %s..%s"), offset, b, e);
+	    printf (" [%6tx] ", offset);
 	  else
-	    printf (gettext ("           %s..%s"), b, e);
+	    printf ("          ");
 
-	  free (b);
-	  free (e);
+	  printf ("range %" PRIx64 ", %" PRIx64 "\n", begin, end);
+	  if (! print_unresolved_addresses)
+	    {
+	      char *b = format_dwarf_addr (dwflmod, address_size, base + begin,
+					   base + begin);
+	      char *e = format_dwarf_addr (dwflmod, address_size,
+					   base + end - 1, base + end);
+	      printf ("          %s..\n", b);
+	      printf ("          %s\n", e);
+	      free (b);
+	      free (e);
+	    }
 
 	  if (endp - readp <= (ptrdiff_t) len)
 	    {
@@ -7201,8 +7223,9 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
 	      break;
 	    }
 
-	  print_ops (dwflmod, dbg, 1, 18 + (address_size * 4),
-		     3 /*XXX*/, address_size, offset_size, cu, len, readp);
+	  print_ops (dwflmod, dbg, 11, 11,
+		     cu != NULL ? cu->version : 3,
+		     address_size, offset_size, cu, len, readp);
 
 	  first = false;
 	  readp += len;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 4666dcc..cb0c977 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,11 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* run-readelf-loc.sh: Adjust expected loc list output.
+	* run-readelf-zdebug-rel.sh: Likewise.
+	* run-readelf-zdebug.sh: Likewise.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* run-readelf-loc.sh: Adjust expected range list output.
 	* run-readelf-zdebug.sh: Likewise.
 
diff --git a/tests/run-readelf-loc.sh b/tests/run-readelf-loc.sh
index 4b666cf..e5152df 100755
--- a/tests/run-readelf-loc.sh
+++ b/tests/run-readelf-loc.sh
@@ -63,9 +63,22 @@ testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ra
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  0x0000000000400480 <main>..0x000000000040048d <main+0xd> [ 0] reg5
- [    23]  0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> [ 0] reg5
- [    46]  0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> [ 0] breg5 0
+
+ CU [     b] base: 0x0000000000400480 <main>
+ [     0] range 0, d
+          0x0000000000400480 <main>..
+          0x000000000040048c <main+0xc>
+           [ 0] reg5
+ [    23] range 5, d
+          0x0000000000400485 <main+0x5>..
+          0x000000000040048c <main+0xc>
+           [ 0] reg5
+
+ CU [    e0] base: 0x00000000004004a0 <say>
+ [    46] range 12, 1a
+          0x00000000004004b2 <say+0x12>..
+          0x00000000004004b9 <say+0x19>
+           [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
 
@@ -91,9 +104,22 @@ testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=loc --debug-dump
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  0x0000000000400480..0x000000000040048d [ 0] reg5
- [    23]  0x0000000000400485..0x000000000040048d [ 0] reg5
- [    46]  0x00000000004004b2..0x00000000004004ba [ 0] breg5 0
+
+ CU [     b] base: 0x0000000000400480
+ [     0] range 0, d
+          0x0000000000400480..
+          0x000000000040048c
+           [ 0] reg5
+ [    23] range 5, d
+          0x0000000000400485..
+          0x000000000040048c
+           [ 0] reg5
+
+ CU [    e0] base: 0x00000000004004a0
+ [    46] range 12, 1a
+          0x00000000004004b2..
+          0x00000000004004b9
+           [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
 
@@ -119,9 +145,16 @@ testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc --debug-dump
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  000000000000000000..0x000000000000000d [ 0] reg5
- [    23]  0x0000000000000005..0x000000000000000d [ 0] reg5
- [    46]  0x0000000000000012..0x000000000000001a [ 0] breg5 0
+
+ CU [     b] base: 0x0000000000400480
+ [     0] range 0, d
+           [ 0] reg5
+ [    23] range 5, d
+           [ 0] reg5
+
+ CU [    e0] base: 0x00000000004004a0
+ [    46] range 12, 1a
+           [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
 
diff --git a/tests/run-readelf-zdebug-rel.sh b/tests/run-readelf-zdebug-rel.sh
index 2b57d05..ccccd82 100755
--- a/tests/run-readelf-zdebug-rel.sh
+++ b/tests/run-readelf-zdebug-rel.sh
@@ -127,12 +127,17 @@ cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=i
 cat > loc.out << \EOF
 
 DWARF section [ 7] '.debug_loc' at offset 0x185:
- [     0]  000000000000000000..0x0000000000000003 [ 0] reg5
-           0x0000000000000003..0x0000000000000010 [ 0] breg5 -42
-                                                  [ 2] stack_value
-           0x0000000000000010..0x0000000000000018 [ 0] GNU_entry_value:
-      [ 0] reg5
-                                                  [ 3] stack_value
+
+ CU [     b] base: 000000000000000000
+ [     0] range 0, 3
+           [ 0] reg5
+          range 3, 10
+           [ 0] breg5 -42
+           [ 2] stack_value
+          range 10, 18
+           [ 0] GNU_entry_value:
+                [ 0] reg5
+           [ 3] stack_value
 EOF
 
 cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o
diff --git a/tests/run-readelf-zdebug.sh b/tests/run-readelf-zdebug.sh
index 7be9bee..28128ad 100755
--- a/tests/run-readelf-zdebug.sh
+++ b/tests/run-readelf-zdebug.sh
@@ -46,12 +46,17 @@ tempfiles loc.out aranges.out ranges.out macro.out line.out frame.out
 cat > loc.out << \EOF
 
 DWARF section [30] '.debug_loc' at offset 0xa17:
- [     0]  0x00000000004003c0..0x00000000004003c3 [ 0] reg5
-           0x00000000004003c3..0x00000000004003d6 [ 0] breg5 -42
-                                                  [ 2] stack_value
-           0x00000000004003d6..0x00000000004003d9 [ 0] GNU_entry_value:
-      [ 0] reg5
-                                                  [ 3] stack_value
+
+ CU [     b] base: 000000000000000000
+ [     0] range 4003c0, 4003c3
+           [ 0] reg5
+          range 4003c3, 4003d6
+           [ 0] breg5 -42
+           [ 2] stack_value
+          range 4003d6, 4003d9
+           [ 0] GNU_entry_value:
+                [ 0] reg5
+           [ 3] stack_value
 EOF
 
 cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] readelf: Print actual file for decl_file and call_file attributes.
  2017-11-29 16:06 Various eu-readelf --debug-dump improvements Mark Wielaard
                   ` (3 preceding siblings ...)
  2017-11-29 16:06 ` [PATCH 1/5] readelf: Adjust print_ops formatting Mark Wielaard
@ 2017-11-29 16:06 ` Mark Wielaard
  2017-12-10 16:00 ` Various eu-readelf --debug-dump improvements Mark Wielaard
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Wielaard @ 2017-11-29 16:06 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

When we see a DW_AT_decl_file or DW_AT_call_file attribute print the
actual file name. The current interface gives us a full (absolute) patch,
but we only want to show the file name for now to not clutter the output
too much. This helps a lot when trying to determine where something was
declared if you are just looking at the DIE tree. Otherwise you'll have
to cross match the number by hand with the corresponding line table entry.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog                   |  5 +++++
 src/readelf.c                   | 22 ++++++++++++++++++++++
 tests/ChangeLog                 |  5 +++++
 tests/run-readelf-dwz-multi.sh  | 32 ++++++++++++++++----------------
 tests/run-readelf-zdebug-rel.sh | 10 +++++-----
 5 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index e7e598d..12cd571 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* readelf.c (attr_callback): Set valuestr to resolved file name
+	for DW_AT_decl_file and DW_AT_call_file.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* readelf.c (print_debug_units): Print abbrev code after DIE tag.
 
 2017-11-29  Mark Wielaard  <mark@klomp.org>
diff --git a/src/readelf.c b/src/readelf.c
index e9887c4..8661ba8 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6126,6 +6126,28 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 	case DW_AT_discr_list:
 	  valuestr = dwarf_discr_list_name (num);
 	  break;
+	case DW_AT_decl_file:
+	case DW_AT_call_file:
+	  {
+	    /* Try to get the actual file, the current interface only
+	       gives us full paths, but we only want to show the file
+	       name for now.  */
+	    Dwarf_Die cudie;
+	    if (dwarf_cu_die (cbargs->cu, &cudie,
+			      NULL, NULL, NULL, NULL, NULL, NULL) != NULL)
+	      {
+		Dwarf_Files *files;
+		size_t nfiles;
+		if (dwarf_getsrcfiles (&cudie, &files, &nfiles) == 0)
+		  {
+		    valuestr = dwarf_filesrc (files, num, NULL, NULL);
+		    char *filename = strrchr (valuestr, '/');
+		    if (filename != NULL)
+		      valuestr = filename + 1;
+		  }
+	      }
+	  }
+	  break;
 	default:
 	  /* Nothing.  */
 	  break;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index f522a69..c9fc53a 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,10 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* run-readelf-dwz-multi.sh: Add expected file names.
+	* run-readelf-zdebug-rel.sh: Likewise.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* run-readelf-dwz-multi.sh: Add expected abbrev codes.
 	* run-readelf-zdebug-rel.sh: Likewise.
 
diff --git a/tests/run-readelf-dwz-multi.sh b/tests/run-readelf-dwz-multi.sh
index 21456fd..4f317ac 100755
--- a/tests/run-readelf-dwz-multi.sh
+++ b/tests/run-readelf-dwz-multi.sh
@@ -100,7 +100,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
  [    31]    subprogram           abbrev: 3
              external             (flag_present) yes
              name                 (strp) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) main.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -112,21 +112,21 @@ DWARF section [28] '.debug_info' at offset 0x1078:
              sibling              (ref_udata) [    6e]
  [    48]      formal_parameter     abbrev: 8
                name                 (strp) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
                 [ 0] fbreg -36
  [    56]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
                 [ 0] fbreg -48
  [    61]      variable             abbrev: 7
                name                 (string) "b"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
@@ -161,7 +161,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
  [    31]    subprogram           abbrev: 3
              external             (flag_present) yes
              name                 (strp) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) main.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -173,21 +173,21 @@ DWARF section [28] '.debug_info' at offset 0x1078:
              sibling              (ref_udata) [    6e]
  [    48]      formal_parameter     abbrev: 8
                name                 (strp) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
                 [ 0] fbreg -36
  [    56]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
                 [ 0] fbreg -48
  [    61]      variable             abbrev: 7
                name                 (string) "b"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
@@ -218,7 +218,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
  [    2b]    subprogram           abbrev: 1
              external             (flag_present) yes
              name                 (strp) "call_foo"
-             decl_file            (data1) 1
+             decl_file            (data1) shared.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -229,7 +229,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter     abbrev: 4
                name                 (string) "fb"
-               decl_file            (data1) 1
+               decl_file            (data1) shared.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    76]
                location             (exprloc) 
@@ -258,7 +258,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
  [    2b]    subprogram           abbrev: 1
              external             (flag_present) yes
              name                 (strp) "call_foo"
-             decl_file            (data1) 1
+             decl_file            (data1) shared.c (1)
              decl_line            (data1) 3
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    3e]
@@ -269,7 +269,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter     abbrev: 4
                name                 (string) "fb"
-               decl_file            (data1) 1
+               decl_file            (data1) shared.c (1)
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    76]
                location             (exprloc) 
@@ -297,7 +297,7 @@ DWARF section [28] '.debug_info' at offset 0x1088:
  [    2b]    subprogram           abbrev: 4
              external             (flag_present) yes
              name                 (GNU_strp_alt) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) main.c (1)
              decl_line            (data1) 8
              prototyped           (flag_present) yes
              type                 (GNU_ref_alt) [    30]
@@ -308,21 +308,21 @@ DWARF section [28] '.debug_info' at offset 0x1088:
              GNU_all_call_sites   (flag_present) yes
  [    41]      formal_parameter     abbrev: 1
                name                 (GNU_strp_alt) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    30]
                location             (exprloc) 
                 [ 0] fbreg -36
  [    4f]      formal_parameter     abbrev: 1
                name                 (GNU_strp_alt) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    41]
                location             (exprloc) 
                 [ 0] fbreg -48
  [    5d]      variable             abbrev: 3
                name                 (string) "fbb"
-               decl_file            (data1) 1
+               decl_file            (data1) main.c (1)
                decl_line            (data1) 10
                type                 (GNU_ref_alt) [    14]
                location             (exprloc) 
diff --git a/tests/run-readelf-zdebug-rel.sh b/tests/run-readelf-zdebug-rel.sh
index 93201ae..2b57d05 100755
--- a/tests/run-readelf-zdebug-rel.sh
+++ b/tests/run-readelf-zdebug-rel.sh
@@ -62,7 +62,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
  [    2d]    subprogram           abbrev: 2
              external             (flag_present) yes
              name                 (strp) "main"
-             decl_file            (data1) 1
+             decl_file            (data1) testfile-zdebug-rel.c (1)
              decl_line            (data1) 4
              prototyped           (flag_present) yes
              type                 (ref4) [    80]
@@ -74,26 +74,26 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
              sibling              (ref4) [    80]
  [    4e]      formal_parameter     abbrev: 3
                name                 (strp) "argc"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 4
                type                 (ref4) [    80]
                location             (sec_offset) location list [     0]
  [    5d]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 4
                type                 (ref4) [    87]
                location             (exprloc) 
                 [ 0] reg4
  [    6a]      variable             abbrev: 5
                name                 (string) "a"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 6
                type                 (ref4) [    9a]
                const_value          (sdata) -9
  [    74]      variable             abbrev: 6
                name                 (string) "b"
-               decl_file            (data1) 1
+               decl_file            (data1) testfile-zdebug-rel.c (1)
                decl_line            (data1) 7
                type                 (ref4) [    9a]
                location             (exprloc) 
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] readelf: Print abbrev code for DIE with --debug-dump=info.
  2017-11-29 16:06 Various eu-readelf --debug-dump improvements Mark Wielaard
  2017-11-29 16:06 ` [PATCH 5/5] readelf: Print CU, base address and unresolved .debug_loc entries Mark Wielaard
  2017-11-29 16:06 ` [PATCH 4/5] readelf: Print CU, base address and unresolved .debug_range entries Mark Wielaard
@ 2017-11-29 16:06 ` Mark Wielaard
  2017-11-29 16:06 ` [PATCH 1/5] readelf: Adjust print_ops formatting Mark Wielaard
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Wielaard @ 2017-11-29 16:06 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

If there is anything wrong with a DIE it is useful to know what the abbrev
code was so you can lookup the abbrev description.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog                   |  4 +++
 src/readelf.c                   |  9 ++++---
 tests/ChangeLog                 |  5 ++++
 tests/run-readelf-dwz-multi.sh  | 60 ++++++++++++++++++++---------------------
 tests/run-readelf-zdebug-rel.sh | 22 +++++++--------
 5 files changed, 56 insertions(+), 44 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index b88c319..e7e598d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* readelf.c (print_debug_units): Print abbrev code after DIE tag.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* readelf.c (print_ops): Use only2 space for index. re-indent +5
 	for DW_OP_GNU_entry_value.
 
diff --git a/src/readelf.c b/src/readelf.c
index 2faa1d5..e9887c4 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6371,9 +6371,12 @@ print_debug_units (Dwfl_Module *dwflmod,
 	}
 
       if (!silent)
-	printf (" [%6" PRIx64 "]  %*s%s\n",
-		(uint64_t) offset, (int) (level * 2), "",
-		dwarf_tag_name (tag));
+	{
+	  unsigned int code = dwarf_getabbrevcode (dies[level].abbrev);
+	  printf (" [%6" PRIx64 "]  %*s%-20s abbrev: %u\n",
+		  (uint64_t) offset, (int) (level * 2), "",
+		  dwarf_tag_name (tag), code);
+	}
 
       /* Print the attribute values.  */
       args.level = level;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 9633cd1..f522a69 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,10 @@
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
+	* run-readelf-dwz-multi.sh: Add expected abbrev codes.
+	* run-readelf-zdebug-rel.sh: Likewise.
+
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
 	* run-readelf-dwz-multi.sh: Adjust expected ops index spaces.
 	* run-readelf-loc.sh: Likewise.
 	* run-readelf-zdebug-rel.sh: Likewise.
diff --git a/tests/run-readelf-dwz-multi.sh b/tests/run-readelf-dwz-multi.sh
index 139b8c1..21456fd 100755
--- a/tests/run-readelf-dwz-multi.sh
+++ b/tests/run-readelf-dwz-multi.sh
@@ -84,7 +84,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
  [Offset]
  Compilation unit at offset 0:
  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
- [     b]  compile_unit
+ [     b]  compile_unit         abbrev: 6
            producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g"
            language             (data1) C89 (1)
            name                 (strp) "main.c"
@@ -92,12 +92,12 @@ DWARF section [28] '.debug_info' at offset 0x1078:
            low_pc               (addr) 0x00000000004006ac <main>
            high_pc              (udata) 44 (0x00000000004006d8)
            stmt_list            (sec_offset) 0
- [    26]    imported_unit
+ [    26]    imported_unit        abbrev: 5
              import               (GNU_ref_alt) [     b]
- [    2b]    pointer_type
+ [    2b]    pointer_type         abbrev: 1
              byte_size            (data1) 8
              type                 (GNU_ref_alt) [    53]
- [    31]    subprogram
+ [    31]    subprogram           abbrev: 3
              external             (flag_present) yes
              name                 (strp) "main"
              decl_file            (data1) 1
@@ -110,28 +110,28 @@ DWARF section [28] '.debug_info' at offset 0x1078:
               [ 0] call_frame_cfa
              GNU_all_tail_call_sites (flag_present) yes
              sibling              (ref_udata) [    6e]
- [    48]      formal_parameter
+ [    48]      formal_parameter     abbrev: 8
                name                 (strp) "argc"
                decl_file            (data1) 1
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
                 [ 0] fbreg -36
- [    56]      formal_parameter
+ [    56]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
                decl_file            (data1) 1
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
                 [ 0] fbreg -48
- [    61]      variable
+ [    61]      variable             abbrev: 7
                name                 (string) "b"
                decl_file            (data1) 1
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
                 [ 0] fbreg -32
- [    6e]    pointer_type
+ [    6e]    pointer_type         abbrev: 2
              byte_size            (data1) 8
              type                 (ref_udata) [    2b]
 EOF
@@ -145,7 +145,7 @@ DWARF section [28] '.debug_info' at offset 0x1078:
  [Offset]
  Compilation unit at offset 0:
  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
- [     b]  compile_unit
+ [     b]  compile_unit         abbrev: 6
            producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g"
            language             (data1) C89 (1)
            name                 (strp) "main.c"
@@ -153,12 +153,12 @@ DWARF section [28] '.debug_info' at offset 0x1078:
            low_pc               (addr) 0x00000000004006ac <main>
            high_pc              (udata) 44 (0x00000000004006d8)
            stmt_list            (sec_offset) 0
- [    26]    imported_unit
+ [    26]    imported_unit        abbrev: 5
              import               (GNU_ref_alt) [     b]
- [    2b]    pointer_type
+ [    2b]    pointer_type         abbrev: 1
              byte_size            (data1) 8
              type                 (GNU_ref_alt) [    53]
- [    31]    subprogram
+ [    31]    subprogram           abbrev: 3
              external             (flag_present) yes
              name                 (strp) "main"
              decl_file            (data1) 1
@@ -171,28 +171,28 @@ DWARF section [28] '.debug_info' at offset 0x1078:
               [ 0] call_frame_cfa
              GNU_all_tail_call_sites (flag_present) yes
              sibling              (ref_udata) [    6e]
- [    48]      formal_parameter
+ [    48]      formal_parameter     abbrev: 8
                name                 (strp) "argc"
                decl_file            (data1) 1
                decl_line            (data1) 3
                type                 (GNU_ref_alt) [    3e]
                location             (exprloc) 
                 [ 0] fbreg -36
- [    56]      formal_parameter
+ [    56]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
                decl_file            (data1) 1
                decl_line            (data1) 3
                type                 (ref_udata) [    6e]
                location             (exprloc) 
                 [ 0] fbreg -48
- [    61]      variable
+ [    61]      variable             abbrev: 7
                name                 (string) "b"
                decl_file            (data1) 1
                decl_line            (data1) 5
                type                 (GNU_ref_alt) [    5a]
                location             (exprloc) 
                 [ 0] fbreg -32
- [    6e]    pointer_type
+ [    6e]    pointer_type         abbrev: 2
              byte_size            (data1) 8
              type                 (ref_udata) [    2b]
 EOF
@@ -205,7 +205,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
  [Offset]
  Compilation unit at offset 0:
  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
- [     b]  compile_unit
+ [     b]  compile_unit         abbrev: 3
            producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC"
            language             (data1) C89 (1)
            name                 (strp) "shared.c"
@@ -213,9 +213,9 @@ DWARF section [25] '.debug_info' at offset 0x106c:
            low_pc               (addr) +0x0000000000000670 <call_foo>
            high_pc              (udata) 23 (+0x0000000000000687)
            stmt_list            (sec_offset) 0
- [    26]    imported_unit
+ [    26]    imported_unit        abbrev: 2
              import               (GNU_ref_alt) [     b]
- [    2b]    subprogram
+ [    2b]    subprogram           abbrev: 1
              external             (flag_present) yes
              name                 (strp) "call_foo"
              decl_file            (data1) 1
@@ -227,7 +227,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              frame_base           (exprloc) 
               [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
- [    41]      formal_parameter
+ [    41]      formal_parameter     abbrev: 4
                name                 (string) "fb"
                decl_file            (data1) 1
                decl_line            (data1) 3
@@ -245,7 +245,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
  [Offset]
  Compilation unit at offset 0:
  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
- [     b]  compile_unit
+ [     b]  compile_unit         abbrev: 3
            producer             (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC"
            language             (data1) C89 (1)
            name                 (strp) "shared.c"
@@ -253,9 +253,9 @@ DWARF section [25] '.debug_info' at offset 0x106c:
            low_pc               (addr) +0x0000000000000670 <call_foo>
            high_pc              (udata) 23 (+0x0000000000000687)
            stmt_list            (sec_offset) 0
- [    26]    imported_unit
+ [    26]    imported_unit        abbrev: 2
              import               (GNU_ref_alt) [     b]
- [    2b]    subprogram
+ [    2b]    subprogram           abbrev: 1
              external             (flag_present) yes
              name                 (strp) "call_foo"
              decl_file            (data1) 1
@@ -267,7 +267,7 @@ DWARF section [25] '.debug_info' at offset 0x106c:
              frame_base           (exprloc) 
               [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
- [    41]      formal_parameter
+ [    41]      formal_parameter     abbrev: 4
                name                 (string) "fb"
                decl_file            (data1) 1
                decl_line            (data1) 3
@@ -284,7 +284,7 @@ DWARF section [28] '.debug_info' at offset 0x1088:
  [Offset]
  Compilation unit at offset 0:
  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
- [     b]  compile_unit
+ [     b]  compile_unit         abbrev: 5
            producer             (GNU_strp_alt) "GNU C 4.7.2 20121109 (Red Hat 4.7.2-8) -mtune=generic -march=x86-64 -g"
            language             (data1) C89 (1)
            name                 (GNU_strp_alt) "main.c"
@@ -292,9 +292,9 @@ DWARF section [28] '.debug_info' at offset 0x1088:
            low_pc               (addr) 0x00000000004004ec <main>
            high_pc              (udata) 18 (0x00000000004004fe)
            stmt_list            (sec_offset) 0
- [    26]    imported_unit
+ [    26]    imported_unit        abbrev: 2
              import               (GNU_ref_alt) [     b]
- [    2b]    subprogram
+ [    2b]    subprogram           abbrev: 4
              external             (flag_present) yes
              name                 (GNU_strp_alt) "main"
              decl_file            (data1) 1
@@ -306,21 +306,21 @@ DWARF section [28] '.debug_info' at offset 0x1088:
              frame_base           (exprloc) 
               [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
- [    41]      formal_parameter
+ [    41]      formal_parameter     abbrev: 1
                name                 (GNU_strp_alt) "argc"
                decl_file            (data1) 1
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    30]
                location             (exprloc) 
                 [ 0] fbreg -36
- [    4f]      formal_parameter
+ [    4f]      formal_parameter     abbrev: 1
                name                 (GNU_strp_alt) "argv"
                decl_file            (data1) 1
                decl_line            (data1) 8
                type                 (GNU_ref_alt) [    41]
                location             (exprloc) 
                 [ 0] fbreg -48
- [    5d]      variable
+ [    5d]      variable             abbrev: 3
                name                 (string) "fbb"
                decl_file            (data1) 1
                decl_line            (data1) 10
diff --git a/tests/run-readelf-zdebug-rel.sh b/tests/run-readelf-zdebug-rel.sh
index 082971e..93201ae 100755
--- a/tests/run-readelf-zdebug-rel.sh
+++ b/tests/run-readelf-zdebug-rel.sh
@@ -51,7 +51,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
  [Offset]
  Compilation unit at offset 0:
  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
- [     b]  compile_unit
+ [     b]  compile_unit         abbrev: 1
            producer             (strp) "GNU C11 5.3.1 20151207 (Red Hat 5.3.1-2) -mtune=generic -march=x86-64 -g -Og"
            language             (data1) C99 (12)
            name                 (strp) "testfile-zdebug-rel.c"
@@ -59,7 +59,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
            low_pc               (addr) 000000000000000000
            high_pc              (data8) 24 (0x0000000000000018)
            stmt_list            (sec_offset) 0
- [    2d]    subprogram
+ [    2d]    subprogram           abbrev: 2
              external             (flag_present) yes
              name                 (strp) "main"
              decl_file            (data1) 1
@@ -72,47 +72,47 @@ DWARF section [ 4] '.debug_info' at offset 0x58:
               [ 0] call_frame_cfa
              GNU_all_call_sites   (flag_present) yes
              sibling              (ref4) [    80]
- [    4e]      formal_parameter
+ [    4e]      formal_parameter     abbrev: 3
                name                 (strp) "argc"
                decl_file            (data1) 1
                decl_line            (data1) 4
                type                 (ref4) [    80]
                location             (sec_offset) location list [     0]
- [    5d]      formal_parameter
+ [    5d]      formal_parameter     abbrev: 4
                name                 (strp) "argv"
                decl_file            (data1) 1
                decl_line            (data1) 4
                type                 (ref4) [    87]
                location             (exprloc) 
                 [ 0] reg4
- [    6a]      variable
+ [    6a]      variable             abbrev: 5
                name                 (string) "a"
                decl_file            (data1) 1
                decl_line            (data1) 6
                type                 (ref4) [    9a]
                const_value          (sdata) -9
- [    74]      variable
+ [    74]      variable             abbrev: 6
                name                 (string) "b"
                decl_file            (data1) 1
                decl_line            (data1) 7
                type                 (ref4) [    9a]
                location             (exprloc) 
                 [ 0] reg5
- [    80]    base_type
+ [    80]    base_type            abbrev: 7
              byte_size            (data1) 4
              encoding             (data1) signed (5)
              name                 (string) "int"
- [    87]    pointer_type
+ [    87]    pointer_type         abbrev: 8
              byte_size            (data1) 8
              type                 (ref4) [    8d]
- [    8d]    pointer_type
+ [    8d]    pointer_type         abbrev: 8
              byte_size            (data1) 8
              type                 (ref4) [    93]
- [    93]    base_type
+ [    93]    base_type            abbrev: 9
              byte_size            (data1) 1
              encoding             (data1) signed_char (6)
              name                 (strp) "char"
- [    9a]    base_type
+ [    9a]    base_type            abbrev: 9
              byte_size            (data1) 8
              encoding             (data1) unsigned (7)
              name                 (strp) "long unsigned int"
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Various eu-readelf --debug-dump improvements
  2017-11-29 16:06 Various eu-readelf --debug-dump improvements Mark Wielaard
                   ` (4 preceding siblings ...)
  2017-11-29 16:06 ` [PATCH 3/5] readelf: Print actual file for decl_file and call_file attributes Mark Wielaard
@ 2017-12-10 16:00 ` Mark Wielaard
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Wielaard @ 2017-12-10 16:00 UTC (permalink / raw)
  To: elfutils-devel

On Wed, 2017-11-29 at 17:05 +0100, Mark Wielaard wrote:
> While working on the DWARF5 support I found various cases where the
> eu-readelf --debug-dump could be improved to provide a bit more information
> that helped debug issues. The following changes are not DWARF5 specific,
> but improve the --debug-dump output to make a more useful (IMHO).
> 
> [PATCH 1/5] readelf: Adjust print_ops formatting.
> [PATCH 2/5] readelf: Print abbrev code for DIE with --debug-
> dump=info.
> [PATCH 3/5] readelf: Print actual file for decl_file and call_file.
> [PATCH 4/5] readelf: Print CU, base address and unresolved
> .debug_ranges.
> [PATCH 5/5] readelf: Print CU, base address and unresolved
> .debug_loc.

I pushed all five to master now.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-12-10 16:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 16:06 Various eu-readelf --debug-dump improvements Mark Wielaard
2017-11-29 16:06 ` [PATCH 5/5] readelf: Print CU, base address and unresolved .debug_loc entries Mark Wielaard
2017-11-29 16:06 ` [PATCH 4/5] readelf: Print CU, base address and unresolved .debug_range entries Mark Wielaard
2017-11-29 16:06 ` [PATCH 2/5] readelf: Print abbrev code for DIE with --debug-dump=info Mark Wielaard
2017-11-29 16:06 ` [PATCH 1/5] readelf: Adjust print_ops formatting Mark Wielaard
2017-11-29 16:06 ` [PATCH 3/5] readelf: Print actual file for decl_file and call_file attributes Mark Wielaard
2017-12-10 16:00 ` Various eu-readelf --debug-dump improvements Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).