1 //===-- HistoryThread.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/HistoryThread.h" 13 #include "Plugins/Process/Utility/HistoryUnwind.h" 14 #include "Plugins/Process/Utility/RegisterContextHistory.h" 15 16 #include "lldb/Core/Log.h" 17 #include "lldb/Target/Process.h" 18 #include "lldb/Target/StackFrameList.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 // Constructor 24 25 HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid, 26 std::vector<lldb::addr_t> pcs, uint32_t stop_id, 27 bool stop_id_is_valid) 28 : Thread(process, tid, true), m_framelist_mutex(), m_framelist(), 29 m_pcs(pcs), m_stop_id(stop_id), m_stop_id_is_valid(stop_id_is_valid), 30 m_extended_unwind_token(LLDB_INVALID_ADDRESS), m_queue_name(), 31 m_thread_name(), m_originating_unique_thread_id(tid), 32 m_queue_id(LLDB_INVALID_QUEUE_ID) { 33 m_unwinder_ap.reset(new HistoryUnwind(*this, pcs, stop_id_is_valid)); 34 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); 35 if (log) 36 log->Printf("%p HistoryThread::HistoryThread", static_cast<void *>(this)); 37 } 38 39 // Destructor 40 41 HistoryThread::~HistoryThread() { 42 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); 43 if (log) 44 log->Printf("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")", 45 static_cast<void *>(this), GetID()); 46 DestroyThread(); 47 } 48 49 lldb::RegisterContextSP HistoryThread::GetRegisterContext() { 50 RegisterContextSP rctx; 51 if (m_pcs.size() > 0) { 52 rctx.reset(new RegisterContextHistory( 53 *this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0])); 54 } 55 return rctx; 56 } 57 58 lldb::RegisterContextSP 59 HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) { 60 return m_unwinder_ap->CreateRegisterContextForFrame(frame); 61 } 62 63 lldb::StackFrameListSP HistoryThread::GetStackFrameList() { 64 // FIXME do not throw away the lock after we acquire it.. 65 std::unique_lock<std::mutex> lock(m_framelist_mutex); 66 lock.unlock(); 67 if (m_framelist.get() == NULL) { 68 m_framelist.reset(new StackFrameList(*this, StackFrameListSP(), true)); 69 } 70 71 return m_framelist; 72 } 73 74 uint32_t HistoryThread::GetExtendedBacktraceOriginatingIndexID() { 75 if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID) { 76 if (GetProcess()->HasAssignedIndexIDToThread( 77 m_originating_unique_thread_id)) { 78 return GetProcess()->AssignIndexIDToThread( 79 m_originating_unique_thread_id); 80 } 81 } 82 return LLDB_INVALID_THREAD_ID; 83 } 84