1 // Copyright 2013 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_riscv.h: riscv-specific stackwalker. 30 * 31 * Provides stack frames given riscv register context and a memory region 32 * corresponding to a riscv stack. 33 * 34 * Author: Iacopo Colonnelli 35 */ 36 37 #ifndef PROCESSOR_STACKWALKER_RISCV_H__ 38 #define PROCESSOR_STACKWALKER_RISCV_H__ 39 40 #include "google_breakpad/common/minidump_format.h" 41 #include "google_breakpad/processor/stackwalker.h" 42 43 namespace google_breakpad { 44 45 class CodeModules; 46 47 class StackwalkerRISCV : public Stackwalker { 48 public: 49 // Context is a riscv context object that gives access to riscv-specific 50 // register state corresponding to the innermost called frame to be 51 // included in the stack. The other arguments are passed directly 52 // through to the base Stackwalker constructor. 53 StackwalkerRISCV(const SystemInfo* system_info, 54 const MDRawContextRISCV* context, 55 MemoryRegion* memory, 56 const CodeModules* modules, 57 StackFrameSymbolizer* frame_symbolizer); 58 59 // Change the context validity mask of the frame returned by 60 // GetContextFrame to VALID. This is only for use by unit tests; the 61 // default behavior is correct for all application code. SetContextFrameValidity(int valid)62 void SetContextFrameValidity(int valid) { 63 context_frame_validity_ = valid; 64 } 65 66 private: 67 // Implementation of Stackwalker, using riscv context and stack conventions. 68 virtual StackFrame* GetContextFrame(); 69 virtual StackFrame* GetCallerFrame( 70 const CallStack* stack, bool stack_scan_allowed); 71 72 // Use cfi_frame_info (derived from STACK CFI records) to construct 73 // the frame that called frames.back(). The caller takes ownership 74 // of the returned frame. Return NULL on failure. 75 StackFrameRISCV* GetCallerByCFIFrameInfo( 76 const vector<StackFrame*>& frames, CFIFrameInfo* cfi_frame_info); 77 78 // Use the frame pointer. The caller takes ownership of the returned frame. 79 // Return NULL on failure. 80 StackFrameRISCV* GetCallerByFramePointer( 81 const vector<StackFrame*>& frames); 82 83 // Scan the stack for plausible return addresses. The caller takes ownership 84 // of the returned frame. Return NULL on failure. 85 StackFrameRISCV* GetCallerByStackScan( 86 const vector<StackFrame*>& frames); 87 88 // Stores the CPU context corresponding to the innermost stack frame to 89 // be returned by GetContextFrame. 90 const MDRawContextRISCV* context_; 91 92 // Validity mask for youngest stack frame. This is always 93 // CONTEXT_VALID_ALL in real use; it is only changeable for the sake of 94 // unit tests. 95 int context_frame_validity_; 96 }; 97 98 } // namespace google_breakpad 99 100 #endif // PROCESSOR_STACKWALKER_RISCV_H__ 101