Add error propagation into Unwinder/Elf objects.
The backtrace offline code uses these error codes to diagnose errors.
In addtion, I've had cases where seeing these errors would help diagnose
failures.
This also allows us to add a few features to indicate why an unwind
terminated (such as max frames exceeded).
Bug: 65682279
Test: Updated unit tests pass.
Change-Id: If82b5092698e8a194016d670efff1320f9b44d50
diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp
index d711772..f70ed7b 100644
--- a/libunwindstack/Unwinder.cpp
+++ b/libunwindstack/Unwinder.cpp
@@ -78,6 +78,8 @@
void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip,
const std::vector<std::string>* map_suffixes_to_ignore) {
frames_.clear();
+ last_error_.code = ERROR_NONE;
+ last_error_.address = 0;
bool return_address_attempt = false;
bool adjust_pc = false;
@@ -95,6 +97,7 @@
rel_pc = regs_->pc();
adjusted_rel_pc = rel_pc;
adjusted_pc = rel_pc;
+ last_error_.code = ERROR_INVALID_MAP;
} else {
if (ShouldStop(map_suffixes_to_ignore, map_info->name)) {
break;
@@ -155,6 +158,7 @@
bool finished;
stepped = elf->Step(rel_pc, adjusted_pc, map_info->elf_offset, regs_,
process_memory_.get(), &finished);
+ elf->GetLastError(&last_error_);
if (stepped && finished) {
break;
}
@@ -180,10 +184,14 @@
}
} else {
return_address_attempt = false;
+ if (max_frames_ == frames_.size()) {
+ last_error_.code = ERROR_MAX_FRAMES_EXCEEDED;
+ }
}
// If the pc and sp didn't change, then consider everything stopped.
if (cur_pc == regs_->pc() && cur_sp == regs_->sp()) {
+ last_error_.code = ERROR_REPEATED_FRAME;
break;
}
}