1 //===-- HistoryThread.cpp ---------------------------------------*- C++ -*-===//
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/Log.h"
23 using namespace lldb_private;
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));
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());
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]);
56 lldb::RegisterContextSP
57 HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) {
58 return m_unwinder_up->CreateRegisterContextForFrame(frame);
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);
65 if (m_framelist.get() == nullptr) {
67 std::make_shared<StackFrameList>(*this, StackFrameListSP(), true);
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);
81 return LLDB_INVALID_THREAD_ID;