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