1 //===-- HistoryThread.cpp ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-private.h"
12 #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"
21 using namespace lldb_private;
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));
36 log->Printf("%p HistoryThread::HistoryThread", static_cast<void *>(this));
41 HistoryThread::~HistoryThread() {
42 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
44 log->Printf("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")",
45 static_cast<void *>(this), GetID());
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]));
58 lldb::RegisterContextSP
59 HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) {
60 return m_unwinder_ap->CreateRegisterContextForFrame(frame);
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);
67 if (m_framelist.get() == NULL) {
68 m_framelist.reset(new StackFrameList(*this, StackFrameListSP(), true));
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);
82 return LLDB_INVALID_THREAD_ID;