1 //===-- HistoryThread.cpp ---------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/lldb-private.h" 10 11 #include "Plugins/Process/Utility/HistoryThread.h" 12 13 #include "Plugins/Process/Utility/HistoryUnwind.h" 14 #include "Plugins/Process/Utility/RegisterContextHistory.h" 15 16 #include "lldb/Target/Process.h" 17 #include "lldb/Target/StackFrameList.h" 18 #include "lldb/Utility/Log.h" 19 20 #include <memory> 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 // Constructor 26 27 HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid, 28 std::vector<lldb::addr_t> pcs) 29 : Thread(process, tid, true), m_framelist_mutex(), m_framelist(), 30 m_pcs(pcs), 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_up.reset(new HistoryUnwind(*this, pcs)); 34 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); 35 LLDB_LOGF(log, "%p HistoryThread::HistoryThread", static_cast<void *>(this)); 36 } 37 38 // Destructor 39 40 HistoryThread::~HistoryThread() { 41 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); 42 LLDB_LOGF(log, "%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")", 43 static_cast<void *>(this), GetID()); 44 DestroyThread(); 45 } 46 47 lldb::RegisterContextSP HistoryThread::GetRegisterContext() { 48 RegisterContextSP rctx; 49 if (m_pcs.size() > 0) { 50 rctx = std::make_shared<RegisterContextHistory>( 51 *this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0]); 52 } 53 return rctx; 54 } 55 56 lldb::RegisterContextSP 57 HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) { 58 return m_unwinder_up->CreateRegisterContextForFrame(frame); 59 } 60 61 lldb::StackFrameListSP HistoryThread::GetStackFrameList() { 62 // FIXME do not throw away the lock after we acquire it.. 63 std::unique_lock<std::mutex> lock(m_framelist_mutex); 64 lock.unlock(); 65 if (m_framelist.get() == nullptr) { 66 m_framelist = 67 std::make_shared<StackFrameList>(*this, StackFrameListSP(), true); 68 } 69 70 return m_framelist; 71 } 72 73 uint32_t HistoryThread::GetExtendedBacktraceOriginatingIndexID() { 74 if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID) { 75 if (GetProcess()->HasAssignedIndexIDToThread( 76 m_originating_unique_thread_id)) { 77 return GetProcess()->AssignIndexIDToThread( 78 m_originating_unique_thread_id); 79 } 80 } 81 return LLDB_INVALID_THREAD_ID; 82 } 83