libunwindstack: Support signal frame CIEs.
Mark a CIE with a S in its augmentation string as signal frame.
This allows the code to properly handle signal frame data if none
of the signal frame pattern matchers work.
For a signal frame, DwarfSectionImpl<AddressType>::Eval needs to
continue the unwinding even if PC is zero. A zero PC means that the
program has crashed, and we should try to recover the real PC using the
return address on the stack or LR. This behavior is tested by
UnwindOffline.signal_{x86,x86_64}, which modify the libc.so files
so that the signal frame pattern matcher fails and the CIE/FDE
data is used instead.
Test: libunwindstack_test
Change-Id: I4655b070028fd984345311a5e743796f8c30ed36
diff --git a/libunwindstack/DwarfSection.cpp b/libunwindstack/DwarfSection.cpp
index bf86e6e..ad25e80 100644
--- a/libunwindstack/DwarfSection.cpp
+++ b/libunwindstack/DwarfSection.cpp
@@ -37,7 +37,8 @@
DwarfSection::DwarfSection(Memory* memory) : memory_(memory) {}
-bool DwarfSection::Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished) {
+bool DwarfSection::Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished,
+ bool* is_signal_frame) {
// Lookup the pc in the cache.
auto it = loc_regs_.upper_bound(pc);
if (it == loc_regs_.end() || pc < it->second.pc_start) {
@@ -59,6 +60,8 @@
it = loc_regs_.emplace(loc_regs.pc_end, std::move(loc_regs)).first;
}
+ *is_signal_frame = it->second.cie->is_signal_frame;
+
// Now eval the actual registers.
return Eval(it->second.cie, process_memory, it->second, regs, finished);
}
@@ -241,6 +244,9 @@
return false;
}
break;
+ case 'S':
+ cie->is_signal_frame = true;
+ break;
}
}
return true;
@@ -558,8 +564,10 @@
cur_regs->set_pc((*cur_regs)[cie->return_address_register]);
}
- // If the pc was set to zero, consider this the final frame.
- *finished = (cur_regs->pc() == 0) ? true : false;
+ // If the pc was set to zero, consider this the final frame. Exception: if
+ // this is the sigreturn frame, then we want to try to recover the real PC
+ // using the return address (from LR or the stack), so keep going.
+ *finished = (cur_regs->pc() == 0 && !cie->is_signal_frame) ? true : false;
cur_regs->set_sp(eval_info.cfa);