From 4f46c4ca995eb931268291ef09014baa76d33add Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Mon, 10 Jun 2024 15:16:52 -0700 Subject: [PATCH] Fix "base" calculation for rangelists. This fixes finding inline functions in DWARF5. 1) if there's no base in the original DIE, use the one from the root of the TU: ```The applicable base address of a range list entry is determined by the closest preceding base address selection entry (see below) in the same range list. If there is no such selection entry, then the applicable base address defaults to the base address of the compilation unit``` 2) Fix base calculations for DWARFv5 which was using a local variable for the 'base' rather than the passed value. --- dwarf_die.cc | 1 - dwarf_unit.cc | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dwarf_die.cc b/dwarf_die.cc index 357076d..ab8ae77 100644 --- a/dwarf_die.cc +++ b/dwarf_die.cc @@ -488,7 +488,6 @@ Ranges::Ranges(const DIE &die, uintmax_t base) { // const auto &elf = die.getUnit()->dwarf->elf; // auto &addrs = elf->getDebugSection(".debug_addr", SHT_NULL); // XXX: would be used by the "x" ops below - uintmax_t base = 0; auto addrlen = die.getUnit()->addrlen; auto &unit = *die.getUnit(); for (bool done = false; !done;) { diff --git a/dwarf_unit.cc b/dwarf_unit.cc index 1c7e782..8a99fda 100644 --- a/dwarf_unit.cc +++ b/dwarf_unit.cc @@ -211,6 +211,12 @@ Unit::findAbbreviation(size_t code) const const std::unique_ptr & Unit::getRanges(const DIE &die, uintmax_t base) { + if (base == 0) { + const DIE::Attribute & low = root().attribute(DW_AT_low_pc); + if (low.valid()) + base = uintmax_t(low); + + } auto &ptr = rangesForOffset[die.offset]; if (ptr == nullptr) ptr = std::make_unique(die, base);