1 //===-- HistoryThread.cpp -------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/lldb-private.h"
11 #include "Plugins/Process/Utility/HistoryThread.h"
13 #include "Plugins/Process/Utility/HistoryUnwind.h"
14 #include "Plugins/Process/Utility/RegisterContextHistory.h"
16 #include "lldb/Target/Process.h"
17 #include "lldb/Target/StackFrameList.h"
18 #include "lldb/Utility/LLDBLog.h"
19 #include "lldb/Utility/Log.h"
24 using namespace lldb_private
;
28 HistoryThread::HistoryThread(lldb_private::Process
&process
, lldb::tid_t tid
,
29 std::vector
<lldb::addr_t
> pcs
,
30 bool pcs_are_call_addresses
)
31 : Thread(process
, tid
, true), m_framelist_mutex(), m_framelist(),
32 m_pcs(pcs
), m_extended_unwind_token(LLDB_INVALID_ADDRESS
), m_queue_name(),
33 m_thread_name(), m_originating_unique_thread_id(tid
),
34 m_queue_id(LLDB_INVALID_QUEUE_ID
) {
36 std::make_unique
<HistoryUnwind
>(*this, pcs
, pcs_are_call_addresses
);
37 Log
*log
= GetLog(LLDBLog::Object
);
38 LLDB_LOGF(log
, "%p HistoryThread::HistoryThread", static_cast<void *>(this));
43 HistoryThread::~HistoryThread() {
44 Log
*log
= GetLog(LLDBLog::Object
);
45 LLDB_LOGF(log
, "%p HistoryThread::~HistoryThread (tid=0x%" PRIx64
")",
46 static_cast<void *>(this), GetID());
50 lldb::RegisterContextSP
HistoryThread::GetRegisterContext() {
51 RegisterContextSP rctx
;
52 if (m_pcs
.size() > 0) {
53 rctx
= std::make_shared
<RegisterContextHistory
>(
54 *this, 0, GetProcess()->GetAddressByteSize(), m_pcs
[0]);
59 lldb::RegisterContextSP
60 HistoryThread::CreateRegisterContextForFrame(StackFrame
*frame
) {
61 return m_unwinder_up
->CreateRegisterContextForFrame(frame
);
64 lldb::StackFrameListSP
HistoryThread::GetStackFrameList() {
65 // FIXME do not throw away the lock after we acquire it..
66 std::unique_lock
<std::mutex
> lock(m_framelist_mutex
);
68 if (m_framelist
.get() == nullptr) {
70 std::make_shared
<StackFrameList
>(*this, StackFrameListSP(), true);
76 uint32_t HistoryThread::GetExtendedBacktraceOriginatingIndexID() {
77 if (m_originating_unique_thread_id
!= LLDB_INVALID_THREAD_ID
) {
78 if (GetProcess()->HasAssignedIndexIDToThread(
79 m_originating_unique_thread_id
)) {
80 return GetProcess()->AssignIndexIDToThread(
81 m_originating_unique_thread_id
);
84 return LLDB_INVALID_THREAD_ID
;