On Sat, 2018-05-19 at 16:03 +0200, Mark Wielaard wrote:
> GNU DebugFission split dwarf handles DW_FORM_sec_offset specially for
> attributes that point to ranges. The .debug_ranges section is not in
> the .dwo file, but in the main/skeleton object file. The sec_offset is
> not relocated (in the ELF file), but is an offset against the skeleton
> DIE DW_AT_GNU_ranges_base attribute. dwarf_formudata is changed so it
> still looks like a normal offset ptr into the .debug_ranges section.
> dwarf_ranges is adapted to look for the .debug_ranges in the main object
> file. dwarf_highpc and dwarf_lowpc now handle the highpc and lowpc
> attributes being inherited for the split unit DIE from the skeleton.
>
> A new testcase is added to iterate over all ranges in a split GNU
> DebugFission file.
After double checking the test results after incorporating the full
DWARF5 rnglists support into readelf and libdw I found an embarrassing
bug. We didn't initialize the CU ranges_base causing some bad test
results. We also didn't handle bad DWARF correctly in one case. I am
pushing the following fixes for this.
From c2d14cc492aa7fd28740d5789fede64ce81a063b Mon Sep 17 00:00:00 2001
From: Mark Wielaard <m...@klomp.org>
Date: Thu, 24 May 2018 15:20:25 +0200
Subject: [PATCH] libdw: Initialize ranges_base, add invalid DWARF test and fix
expected output.
We never initialized the CU ranges_base, which meant we didn't actually
calculate it correctly. This caused bad ranges on some DIEs. The expected
output in the testcase was wrong. We also crashed on invalid dwarf.
Signed-off-by: Mark Wielaard <m...@klomp.org>
---
libdw/ChangeLog | 5 +++++
libdw/dwarf_ranges.c | 6 ++++++
libdw/libdw_findcu.c | 1 +
tests/ChangeLog | 7 ++++++-
tests/get-units-invalid.c | 7 +++++++
tests/run-all-dwarf-ranges.sh | 7 ++++---
6 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4db0f5c..c302628 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-24 Mark Wielaard <m...@klomp.org>
+
+ * dwarf_ranges.c (dwarf_ranges): Check for NULL cu.
+ * libdw_findcu.c (__libdw_intern_next_unit): Initialize ranges_base.
+
2018-05-18 Mark Wielaard <m...@klomp.org>
* dwarf_formudata.c (__libdw_formptr): Handle the special case
diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c
index b0450cf..52a61ee 100644
--- a/libdw/dwarf_ranges.c
+++ b/libdw/dwarf_ranges.c
@@ -123,6 +123,12 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
/* We have to look for a noncontiguous range. */
size_t secidx = IDX_debug_ranges;
Dwarf_CU *cu = die->cu;
+ if (cu == NULL)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+
const Elf_Data *d = cu->dbg->sectiondata[secidx];
if (d == NULL && cu->unit_type == DW_UT_split_compile)
{
diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
index d22ddae..83c2eb1 100644
--- a/libdw/libdw_findcu.c
+++ b/libdw/libdw_findcu.c
@@ -121,6 +121,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
newp->base_address = (Dwarf_Addr) -1;
newp->addr_base = (Dwarf_Off) -1;
newp->str_off_base = (Dwarf_Off) -1;
+ newp->ranges_base = (Dwarf_Off) -1;
newp->startp = data->d_buf + newp->start;
newp->endp = data->d_buf + newp->end;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index a021a01..86bcf9d 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,6 +1,11 @@
+2018-05-24 Mark Wielaard <m...@klomp.org>
+
+ * get-units-invalid.c (main): Add check for invalid dwarf_ranges.
+ * run-all-dwarf-ranges.sh: Correct expected output.
+
2018-05-18 Mark Wielaard <m...@klomp.org>
- * tests/Makefiles.am (check_PROGRAMS): Add all-dwarf-ranges.
+ * Makefiles.am (check_PROGRAMS): Add all-dwarf-ranges.
(TESTS): Add run-all-dwarf-ranges.sh.
(EXTRA_DIST): Add run-all-dwarf-ranges.sh,
testfilesplitranges4.debug.bz2, testfile-ranges-hello.dwo.bz2
diff --git a/tests/get-units-invalid.c b/tests/get-units-invalid.c
index 9ec16ee..58b32c0 100644
--- a/tests/get-units-invalid.c
+++ b/tests/get-units-invalid.c
@@ -79,6 +79,13 @@ main (int argc, char *argv[])
dwarf_diename (&result));
return -1;
}
+ Dwarf_Addr base, start, end;
+ if (dwarf_ranges (&subdie, 0, &base, &start, &end) != -1)
+ {
+ printf ("Should NOT have a ranges: %s\n",
+ dwarf_diename (&result));
+ return -1;
+ }
}
else if (unit_type == DW_UT_type)
printf ("subdie: %s\n", dwarf_diename (&subdie));
diff --git a/tests/run-all-dwarf-ranges.sh b/tests/run-all-dwarf-ranges.sh
index 0bd641b..ba5528d 100755
--- a/tests/run-all-dwarf-ranges.sh
+++ b/tests/run-all-dwarf-ranges.sh
@@ -37,11 +37,12 @@ die: world.c (11)
400500..400567
die: happy (1d)
- 8009e0..8009ff
- 8008e0..8008f7
+ 40051c..400526
+ 400530..400534
+ 400535..40053f
die: sad (1d)
- 400530..400534
+ 40051c..400526
400535..40053f
EOF
--
1.8.3.1