blob: fc3b1f158d70b711111df384ea4f95fa4797f4c0 [file] [log] [blame]
Jason Molenda02706c32013-11-08 04:59:54 +00001//===-- HistoryThread.cpp ---------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Jason Molenda02706c32013-11-08 04:59:54 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/lldb-private.h"
10
Jason Molenda02706c32013-11-08 04:59:54 +000011#include "Plugins/Process/Utility/HistoryThread.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000012#include "Plugins/Process/Utility/HistoryUnwind.h"
Jason Molenda02706c32013-11-08 04:59:54 +000013#include "Plugins/Process/Utility/RegisterContextHistory.h"
14
Jason Molenda02706c32013-11-08 04:59:54 +000015#include "lldb/Target/Process.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000016#include "lldb/Target/StackFrameList.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000017#include "lldb/Utility/Log.h"
Jason Molenda02706c32013-11-08 04:59:54 +000018
19using namespace lldb;
20using namespace lldb_private;
21
Jason Molendaa8ff5432014-03-06 06:31:18 +000022// Constructor
23
Kate Stoneb9c1b512016-09-06 20:57:50 +000024HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid,
25 std::vector<lldb::addr_t> pcs, uint32_t stop_id,
26 bool stop_id_is_valid)
27 : Thread(process, tid, true), m_framelist_mutex(), m_framelist(),
28 m_pcs(pcs), m_stop_id(stop_id), m_stop_id_is_valid(stop_id_is_valid),
29 m_extended_unwind_token(LLDB_INVALID_ADDRESS), m_queue_name(),
30 m_thread_name(), m_originating_unique_thread_id(tid),
31 m_queue_id(LLDB_INVALID_QUEUE_ID) {
32 m_unwinder_ap.reset(new HistoryUnwind(*this, pcs, stop_id_is_valid));
33 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
34 if (log)
35 log->Printf("%p HistoryThread::HistoryThread", static_cast<void *>(this));
Jason Molenda02706c32013-11-08 04:59:54 +000036}
37
Jason Molendaa8ff5432014-03-06 06:31:18 +000038// Destructor
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040HistoryThread::~HistoryThread() {
41 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
42 if (log)
43 log->Printf("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")",
44 static_cast<void *>(this), GetID());
45 DestroyThread();
46}
47
48lldb::RegisterContextSP HistoryThread::GetRegisterContext() {
49 RegisterContextSP rctx;
50 if (m_pcs.size() > 0) {
51 rctx.reset(new RegisterContextHistory(
52 *this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0]));
53 }
54 return rctx;
Jason Molenda02706c32013-11-08 04:59:54 +000055}
56
57lldb::RegisterContextSP
Kate Stoneb9c1b512016-09-06 20:57:50 +000058HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) {
59 return m_unwinder_ap->CreateRegisterContextForFrame(frame);
Jason Molenda02706c32013-11-08 04:59:54 +000060}
61
Kate Stoneb9c1b512016-09-06 20:57:50 +000062lldb::StackFrameListSP HistoryThread::GetStackFrameList() {
63 // FIXME do not throw away the lock after we acquire it..
64 std::unique_lock<std::mutex> lock(m_framelist_mutex);
65 lock.unlock();
66 if (m_framelist.get() == NULL) {
67 m_framelist.reset(new StackFrameList(*this, StackFrameListSP(), true));
68 }
69
70 return m_framelist;
Jason Molenda02706c32013-11-08 04:59:54 +000071}
72
Kate Stoneb9c1b512016-09-06 20:57:50 +000073uint32_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);
Jason Molenda02706c32013-11-08 04:59:54 +000079 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 }
81 return LLDB_INVALID_THREAD_ID;
Jason Molenda8ee9cb52013-11-16 01:24:22 +000082}