diff options
| author | Mark Wielaard <[email protected]> | 2018-05-24 15:20:25 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2018-05-24 15:20:25 +0200 |
| commit | c2d14cc492aa7fd28740d5789fede64ce81a063b (patch) | |
| tree | 8dc6ce6af3e6720848debfabb4cde5ad2e1361b4 | |
| parent | 144b73c49acf3ed894e4635aedb9b0d1208ade2e (diff) | |
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 <[email protected]>
| -rw-r--r-- | libdw/ChangeLog | 5 | ||||
| -rw-r--r-- | libdw/dwarf_ranges.c | 6 | ||||
| -rw-r--r-- | libdw/libdw_findcu.c | 1 | ||||
| -rw-r--r-- | tests/ChangeLog | 7 | ||||
| -rw-r--r-- | tests/get-units-invalid.c | 7 | ||||
| -rwxr-xr-x | tests/run-all-dwarf-ranges.sh | 7 |
6 files changed, 29 insertions, 4 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 4db0f5c1..c302628e 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2018-05-24 Mark Wielaard <[email protected]> + + * dwarf_ranges.c (dwarf_ranges): Check for NULL cu. + * libdw_findcu.c (__libdw_intern_next_unit): Initialize ranges_base. + 2018-05-18 Mark Wielaard <[email protected]> * dwarf_formudata.c (__libdw_formptr): Handle the special case diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c index b0450cf3..52a61eea 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 d22ddae7..83c2eb14 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 a021a019..86bcf9db 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,6 +1,11 @@ +2018-05-24 Mark Wielaard <[email protected]> + + * get-units-invalid.c (main): Add check for invalid dwarf_ranges. + * run-all-dwarf-ranges.sh: Correct expected output. + 2018-05-18 Mark Wielaard <[email protected]> - * 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 9ec16ee0..58b32c0e 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 0bd641b0..ba5528d2 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 |
