blob: bb8d312fdac34225a5c81d229b56717fdb42f3d3 [file] [log] [blame]
Jason Molenda02706c32013-11-08 04:59:54 +00001//===-- HistoryThread.cpp ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/lldb-private.h"
11
12#include "Plugins/Process/Utility/HistoryUnwind.h"
13#include "Plugins/Process/Utility/HistoryThread.h"
14#include "Plugins/Process/Utility/RegisterContextHistory.h"
15
Jason Molendaee87e752013-11-12 00:09:58 +000016#include "lldb/Core/Log.h"
Jason Molenda02706c32013-11-08 04:59:54 +000017#include "lldb/Target/StackFrameList.h"
18#include "lldb/Target/Process.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
23HistoryThread::HistoryThread (lldb_private::Process &process,
Jason Molenda8ee9cb52013-11-16 01:24:22 +000024 lldb::tid_t tid,
Jason Molenda02706c32013-11-08 04:59:54 +000025 std::vector<lldb::addr_t> pcs,
26 uint32_t stop_id,
27 bool stop_id_is_valid) :
28 Thread (process, LLDB_INVALID_THREAD_ID),
29 m_framelist_mutex(),
30 m_framelist(),
31 m_pcs (pcs),
32 m_stop_id (stop_id),
Jason Molendaa7b5afa2013-11-15 00:17:32 +000033 m_stop_id_is_valid (stop_id_is_valid),
Jason Molenda8ee9cb52013-11-16 01:24:22 +000034 m_extended_unwind_token (LLDB_INVALID_ADDRESS),
35 m_queue_name (),
36 m_thread_name (),
37 m_originating_unique_thread_id (tid)
Jason Molenda02706c32013-11-08 04:59:54 +000038{
39 m_unwinder_ap.reset (new HistoryUnwind (*this, pcs, stop_id, stop_id_is_valid));
Jason Molendaee87e752013-11-12 00:09:58 +000040 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
41 if (log)
42 log->Printf ("%p HistoryThread::HistoryThread", this);
Jason Molenda02706c32013-11-08 04:59:54 +000043}
44
45HistoryThread::~HistoryThread ()
46{
Jason Molendaee87e752013-11-12 00:09:58 +000047 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
48 if (log)
49 log->Printf ("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")", this, GetID());
50 DestroyThread();
Jason Molenda02706c32013-11-08 04:59:54 +000051}
52
53lldb::RegisterContextSP
54HistoryThread::GetRegisterContext ()
55{
56 RegisterContextSP rctx ;
57 if (m_pcs.size() > 0)
58 {
59 rctx.reset (new RegisterContextHistory (*this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0]));
60 }
61 return rctx;
62
63}
64
65lldb::RegisterContextSP
66HistoryThread::CreateRegisterContextForFrame (StackFrame *frame)
67{
68 return m_unwinder_ap->CreateRegisterContextForFrame (frame);
69}
70
71lldb::StackFrameListSP
72HistoryThread::GetStackFrameList ()
73{
74 Mutex::Locker (m_framelist_mutex);
75 if (m_framelist.get() == NULL)
76 {
77 m_framelist.reset (new StackFrameList (*this, StackFrameListSP(), true));
78 }
79
80 return m_framelist;
81}
Jason Molenda8ee9cb52013-11-16 01:24:22 +000082
83uint32_t
84HistoryThread::GetExtendedBacktraceOriginatingIndexID ()
85{
86 if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID)
87 {
88 if (GetProcess()->HasAssignedIndexIDToThread (m_originating_unique_thread_id))
89 {
90 return GetProcess()->AssignIndexIDToThread (m_originating_unique_thread_id);
91 }
92 }
93 return LLDB_INVALID_THREAD_ID;
94}