diff options
Diffstat (limited to 'src/processor/stackwalker_x86.cc')
-rw-r--r-- | src/processor/stackwalker_x86.cc | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/processor/stackwalker_x86.cc b/src/processor/stackwalker_x86.cc index e51bf3e8..a5819c86 100644 --- a/src/processor/stackwalker_x86.cc +++ b/src/processor/stackwalker_x86.cc @@ -37,44 +37,39 @@ #include "processor/stackwalker_x86.h" #include "processor/minidump.h" - namespace google_airbag { -StackwalkerX86::StackwalkerX86(MinidumpContext* context, - MemoryRegion* memory, - MinidumpModuleList* modules, - SymbolSupplier* supplier) +StackwalkerX86::StackwalkerX86(const MDRawContextX86 *context, + MemoryRegion *memory, + MinidumpModuleList *modules, + SymbolSupplier *supplier) : Stackwalker(memory, modules, supplier), - last_frame_pointer_(0) { + context_(context) { if (memory_->GetBase() + memory_->GetSize() - 1 > 0xffffffff) { // The x86 is a 32-bit CPU, the limits of the supplied stack are invalid. // Mark memory_ = NULL, which will cause stackwalking to fail. memory_ = NULL; } - - // If |context| is not an x86 context, context_ will be set to NULL, - // which will cause GetContextFrame to fail when called by Walk. - // For StackwalkerX86, |context| should only ever be an x86 context. - context_ = context->GetContextX86(); } -bool StackwalkerX86::GetContextFrame(StackFrame* frame) { +bool StackwalkerX86::GetContextFrame(StackFrame *frame) { if (!context_ || !memory_ || !frame) return false; // The frame and instruction pointers are stored directly in registers, // so pull them straight out of the CPU context structure. - frame->frame_pointer = last_frame_pointer_ = context_->ebp; + frame->frame_pointer = context_->ebp; frame->instruction = context_->eip; return true; } -bool StackwalkerX86::GetCallerFrame(StackFrame* frame) { - if (!memory_ || !frame) +bool StackwalkerX86::GetCallerFrame(StackFrame *frame, + const StackFrames *walked_frames) { + if (!memory_ || !frame || !walked_frames) return false; // The frame and instruction pointers for previous frames are saved on the @@ -93,24 +88,26 @@ bool StackwalkerX86::GetCallerFrame(StackFrame* frame) { // considerably more difficult, requiring debugging information. This // stackwalker doesn't attempt to solve that problem (at this point). + u_int32_t last_frame_pointer = walked_frames->back().frame_pointer; + // Don't pass frame.frame_pointer or frame.instruction directly // ReadMemory, because their types are too wide (64-bit), and we // specifically want to read 32-bit quantities for both. u_int32_t frame_pointer; - if (!memory_->GetMemoryAtAddress(last_frame_pointer_, &frame_pointer)) + if (!memory_->GetMemoryAtAddress(last_frame_pointer, &frame_pointer)) return false; // A caller frame must reside higher in memory than its callee frames. // Anything else is an error, or an indication that we've reached the // end of the stack. - if (frame_pointer <= last_frame_pointer_) + if (frame_pointer <= last_frame_pointer) return false; u_int32_t instruction; - if (!memory_->GetMemoryAtAddress(last_frame_pointer_ + 4, &instruction)) + if (!memory_->GetMemoryAtAddress(last_frame_pointer + 4, &instruction)) return false; - frame->frame_pointer = last_frame_pointer_ = frame_pointer; + frame->frame_pointer = frame_pointer; frame->instruction = instruction; return true; |