1 // Copyright 2010 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 // stackwalker_amd64.h: amd64-specific stackwalker. 30 // 31 // Provides stack frames given amd64 register context and a memory region 32 // corresponding to a amd64 stack. 33 // 34 // Author: Mark Mentovai, Ted Mielczarek 35 36 37 #ifndef PROCESSOR_STACKWALKER_AMD64_H__ 38 #define PROCESSOR_STACKWALKER_AMD64_H__ 39 40 #include <vector> 41 42 #include "google_breakpad/common/breakpad_types.h" 43 #include "google_breakpad/common/minidump_format.h" 44 #include "google_breakpad/processor/stackwalker.h" 45 #include "google_breakpad/processor/stack_frame_cpu.h" 46 #include "processor/cfi_frame_info.h" 47 48 namespace google_breakpad { 49 50 class CodeModules; 51 52 class StackwalkerAMD64 : public Stackwalker { 53 public: 54 // context is a amd64 context object that gives access to amd64-specific 55 // register state corresponding to the innermost called frame to be 56 // included in the stack. The other arguments are passed directly through 57 // to the base Stackwalker constructor. 58 StackwalkerAMD64(const SystemInfo* system_info, 59 const MDRawContextAMD64* context, 60 MemoryRegion* memory, 61 const CodeModules* modules, 62 StackFrameSymbolizer* frame_symbolizer); 63 64 private: 65 // A STACK CFI-driven frame walker for the AMD64 66 typedef SimpleCFIWalker<uint64_t, MDRawContextAMD64> CFIWalker; 67 68 // Implementation of Stackwalker, using amd64 context (stack pointer in %rsp, 69 // stack base in %rbp) and stack conventions (saved stack pointer at 0(%rbp)) 70 virtual StackFrame* GetContextFrame(); 71 virtual StackFrame* GetCallerFrame(const CallStack* stack, 72 bool stack_scan_allowed); 73 74 // Use cfi_frame_info (derived from STACK CFI records) to construct 75 // the frame that called frames.back(). The caller takes ownership 76 // of the returned frame. Return NULL on failure. 77 StackFrameAMD64* GetCallerByCFIFrameInfo(const vector<StackFrame*>& frames, 78 CFIFrameInfo* cfi_frame_info); 79 80 // Assumes a traditional frame layout where the frame pointer has not been 81 // omitted. The expectation is that caller's %rbp is pushed to the stack 82 // after the return address of the callee, and that the callee's %rsp can 83 // be used to find the pushed %rbp. 84 // Caller owns the returned frame object. Returns NULL on failure. 85 StackFrameAMD64* GetCallerByFramePointerRecovery( 86 const vector<StackFrame*>& frames); 87 88 // Scan the stack for plausible return addresses. The caller takes ownership 89 // of the returned frame. Return NULL on failure. 90 StackFrameAMD64* GetCallerByStackScan(const vector<StackFrame*>& frames); 91 92 // Trying to simulate a return. The caller takes ownership of the returned 93 // frame. Return NULL on failure. 94 StackFrameAMD64* GetCallerBySimulatingReturn( 95 const vector<StackFrame*>& frames); 96 97 // Stores the CPU context corresponding to the innermost stack frame to 98 // be returned by GetContextFrame. 99 const MDRawContextAMD64* context_; 100 101 // Our register map, for cfi_walker_. 102 static const CFIWalker::RegisterSet cfi_register_map_[]; 103 104 // Our CFI frame walker. 105 const CFIWalker cfi_walker_; 106 }; 107 108 109 } // namespace google_breakpad 110 111 112 #endif // PROCESSOR_STACKWALKER_AMD64_H__ 113