1 //===-- HistoryThread.h -----------------------------------------*- 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 #ifndef liblldb_HistoryThread_h_
11 #define liblldb_HistoryThread_h_
12 
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/lldb-private.h"
18 #include "lldb/Host/Mutex.h"
19 #include "lldb/Core/Broadcaster.h"
20 #include "lldb/Core/Event.h"
21 #include "lldb/Core/UserID.h"
22 #include "lldb/Core/UserSettingsController.h"
23 #include "lldb/Target/ExecutionContextScope.h"
24 #include "lldb/Target/StackFrameList.h"
25 #include "lldb/Target/Thread.h"
26 
27 namespace lldb_private {
28 
29 //----------------------------------------------------------------------
30 /// @class HistoryThread HistoryThread.h "HistoryThread.h"
31 /// @brief A thread object representing a backtrace from a previous point in the process execution
32 ///
33 /// This subclass of Thread is used to provide a backtrace from earlier in
34 /// process execution.  It is given a backtrace list of pc addresses and
35 /// optionally a stop_id of when those pc addresses were collected, and it will
36 /// create stack frames for them.
37 //----------------------------------------------------------------------
38 
39 class HistoryThread : public lldb_private::Thread
40 {
41 public:
42     HistoryThread (lldb_private::Process &process, lldb::tid_t tid, std::vector<lldb::addr_t> pcs, uint32_t stop_id, bool stop_id_is_valid);
43 
44     ~HistoryThread() override;
45 
46     lldb::RegisterContextSP
47     GetRegisterContext() override;
48 
49     lldb::RegisterContextSP
50     CreateRegisterContextForFrame(StackFrame *frame) override;
51 
52     void
53     RefreshStateAfterStop() override { }
54 
55     bool
56     CalculateStopInfo() override
57     {
58         return false;
59     }
60 
61     void
62     SetExtendedBacktraceToken(uint64_t token) override
63     {
64         m_extended_unwind_token = token;
65     }
66 
67     uint64_t
68     GetExtendedBacktraceToken() override
69     {
70         return m_extended_unwind_token;
71     }
72 
73     const char *
74     GetQueueName() override
75     {
76         return m_queue_name.c_str();
77     }
78 
79     void
80     SetQueueName(const char *name) override
81     {
82         m_queue_name = name;
83     }
84 
85     lldb::queue_id_t
86     GetQueueID() override
87     {
88         return m_queue_id;
89     }
90 
91     void
92     SetQueueID(lldb::queue_id_t queue) override
93     {
94         m_queue_id = queue;
95     }
96 
97     const char *
98     GetThreadName ()
99     {
100         return m_thread_name.c_str();
101     }
102 
103     uint32_t
104     GetExtendedBacktraceOriginatingIndexID() override;
105 
106     void
107     SetThreadName (const char *name)
108     {
109         m_thread_name = name;
110     }
111 
112     const char *
113     GetName() override
114     {
115         return m_thread_name.c_str();
116     }
117 
118     void
119     SetName(const char *name) override
120     {
121         m_thread_name = name;
122     }
123 
124 protected:
125     virtual lldb::StackFrameListSP
126     GetStackFrameList ();
127 
128     mutable Mutex               m_framelist_mutex;
129     lldb::StackFrameListSP      m_framelist;
130     std::vector<lldb::addr_t>   m_pcs;
131     uint32_t                    m_stop_id;
132     bool                        m_stop_id_is_valid;
133 
134     uint64_t                    m_extended_unwind_token;
135     std::string                 m_queue_name;
136     std::string                 m_thread_name;
137     lldb::tid_t                 m_originating_unique_thread_id;
138     lldb::queue_id_t            m_queue_id;
139 };
140 
141 } // namespace lldb_private
142 
143 #endif // liblldb_HistoryThread_h_
144