1 //===-- Unwind.h ------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_Unwind_h_ 11 #define liblldb_Unwind_h_ 12 13 #include <mutex> 14 15 #include "lldb/lldb-private.h" 16 17 namespace lldb_private { 18 19 class Unwind { 20 protected: 21 //------------------------------------------------------------------ 22 // Classes that inherit from Unwind can see and modify these 23 //------------------------------------------------------------------ Unwind(Thread & thread)24 Unwind(Thread &thread) : m_thread(thread), m_unwind_mutex() {} 25 26 public: ~Unwind()27 virtual ~Unwind() {} 28 Clear()29 void Clear() { 30 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); 31 DoClear(); 32 } 33 GetFrameCount()34 uint32_t GetFrameCount() { 35 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); 36 return DoGetFrameCount(); 37 } 38 GetFramesUpTo(uint32_t end_idx)39 uint32_t GetFramesUpTo(uint32_t end_idx) { 40 lldb::addr_t cfa; 41 lldb::addr_t pc; 42 uint32_t idx; 43 44 for (idx = 0; idx < end_idx; idx++) { 45 if (!DoGetFrameInfoAtIndex(idx, cfa, pc)) { 46 break; 47 } 48 } 49 return idx; 50 } 51 GetFrameInfoAtIndex(uint32_t frame_idx,lldb::addr_t & cfa,lldb::addr_t & pc)52 bool GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, 53 lldb::addr_t &pc) { 54 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); 55 return DoGetFrameInfoAtIndex(frame_idx, cfa, pc); 56 } 57 CreateRegisterContextForFrame(StackFrame * frame)58 lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) { 59 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); 60 return DoCreateRegisterContextForFrame(frame); 61 } 62 GetThread()63 Thread &GetThread() { return m_thread; } 64 65 protected: 66 //------------------------------------------------------------------ 67 // Classes that inherit from Unwind can see and modify these 68 //------------------------------------------------------------------ 69 virtual void DoClear() = 0; 70 71 virtual uint32_t DoGetFrameCount() = 0; 72 73 virtual bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, 74 lldb::addr_t &pc) = 0; 75 76 virtual lldb::RegisterContextSP 77 DoCreateRegisterContextForFrame(StackFrame *frame) = 0; 78 79 Thread &m_thread; 80 std::recursive_mutex m_unwind_mutex; 81 82 private: 83 DISALLOW_COPY_AND_ASSIGN(Unwind); 84 }; 85 86 } // namespace lldb_private 87 88 #endif // liblldb_Unwind_h_ 89