This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH 4/5] readelf: Print CU, base address and unresolved .debug_range entries.
- From: Mark Wielaard <mark at klomp dot org>
- To: elfutils-devel at sourceware dot org
- Cc: Mark Wielaard <mark at klomp dot org>
- Date: Wed, 29 Nov 2017 17:05:52 +0100
- Subject: [PATCH 4/5] readelf: Print CU, base address and unresolved .debug_range entries.
- Authentication-results: sourceware.org; auth=none
- References: <1511971553-30135-1-git-send-email-mark@klomp.org>
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