Fix incorrect usage of relative pcs.
When stepping, it's necessary to use both the unaltered relative pc
and the adjusted relative pc. If the adjusted pc is not used, the
wrong unwind information can be used.
Added new offline unit tests that take real data and verifies that it
unwinds properly.
Fix a bug in the map code that would not properly parse map data for
a 64 bit process when done in a 32 bit process.
Fix bug in eh_frame processing that didn't adjust the pc correctly.
Fix unit tests related to the pc adjustment.
Bug: 69475565
Test: Passes libbacktrace/libunwindstack unit tests.
Test: Run debuggerd -b on processes on a hikey.
Change-Id: Ic501a1c4549c5f61d2742a7105c42a960f2c892b
diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp
index 0c65895..48e33ee 100644
--- a/libunwindstack/Elf.cpp
+++ b/libunwindstack/Elf.cpp
@@ -104,8 +104,8 @@
}
// The relative pc is always relative to the start of the map from which it comes.
-bool Elf::Step(uint64_t rel_pc, uint64_t elf_offset, Regs* regs, Memory* process_memory,
- bool* finished) {
+bool Elf::Step(uint64_t rel_pc, uint64_t adjusted_rel_pc, uint64_t elf_offset, Regs* regs,
+ Memory* process_memory, bool* finished) {
if (!valid_) {
return false;
}
@@ -117,16 +117,16 @@
}
// Adjust the load bias to get the real relative pc.
- if (rel_pc < load_bias_) {
+ if (adjusted_rel_pc < load_bias_) {
return false;
}
- rel_pc -= load_bias_;
+ adjusted_rel_pc -= load_bias_;
// Lock during the step which can update information in the object.
std::lock_guard<std::mutex> guard(lock_);
- return interface_->Step(rel_pc, regs, process_memory, finished) ||
+ return interface_->Step(adjusted_rel_pc, regs, process_memory, finished) ||
(gnu_debugdata_interface_ &&
- gnu_debugdata_interface_->Step(rel_pc, regs, process_memory, finished));
+ gnu_debugdata_interface_->Step(adjusted_rel_pc, regs, process_memory, finished));
}
bool Elf::IsValidElf(Memory* memory) {