1 //===-- HistoryUnwind.cpp ---------------------------------------*- 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 #include "lldb/lldb-private.h" 11 12 #include "Plugins/Process/Utility/RegisterContextHistory.h" 13 #include "Plugins/Process/Utility/HistoryUnwind.h" 14 15 #include "lldb/Target/StackFrame.h" 16 #include "lldb/Target/Thread.h" 17 #include "lldb/Target/Process.h" 18 #include "lldb/Target/Target.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 // Constructor 24 25 HistoryUnwind::HistoryUnwind (Thread &thread, 26 std::vector<lldb::addr_t> pcs, 27 bool stop_id_is_valid) : 28 Unwind (thread), 29 m_pcs (pcs), 30 m_stop_id_is_valid (stop_id_is_valid) 31 { 32 } 33 34 // Destructor 35 36 HistoryUnwind::~HistoryUnwind () 37 { 38 } 39 40 void 41 HistoryUnwind::DoClear () 42 { 43 std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); 44 m_pcs.clear(); 45 m_stop_id_is_valid = false; 46 } 47 48 lldb::RegisterContextSP 49 HistoryUnwind::DoCreateRegisterContextForFrame (StackFrame *frame) 50 { 51 RegisterContextSP rctx; 52 if (frame) 53 { 54 addr_t pc = frame->GetFrameCodeAddress().GetLoadAddress (&frame->GetThread()->GetProcess()->GetTarget()); 55 if (pc != LLDB_INVALID_ADDRESS) 56 { 57 rctx.reset (new RegisterContextHistory (*frame->GetThread().get(), frame->GetConcreteFrameIndex(), 58 frame->GetThread()->GetProcess()->GetAddressByteSize(), pc)); 59 } 60 } 61 return rctx; 62 } 63 64 bool 65 HistoryUnwind::DoGetFrameInfoAtIndex (uint32_t frame_idx, lldb::addr_t& cfa, lldb::addr_t& pc) 66 { 67 // FIXME do not throw away the lock after we acquire it.. 68 std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex); 69 guard.unlock(); 70 if (frame_idx < m_pcs.size()) 71 { 72 cfa = frame_idx; 73 pc = m_pcs[frame_idx]; 74 return true; 75 } 76 return false; 77 } 78 79 uint32_t 80 HistoryUnwind::DoGetFrameCount () 81 { 82 return m_pcs.size(); 83 } 84