1 //===-- ThreadMemory.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_ThreadMemory_h_
11 #define liblldb_ThreadMemory_h_
12 
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Target/Thread.h"
18 
19 class ThreadMemory :
20     public lldb_private::Thread
21 {
22 public:
23     ThreadMemory (lldb_private::Process &process,
24                   lldb::tid_t tid,
25                   const lldb::ValueObjectSP &thread_info_valobj_sp);
26 
27     ThreadMemory (lldb_private::Process &process,
28                   lldb::tid_t tid,
29                   const char *name,
30                   const char *queue,
31                   lldb::addr_t register_data_addr);
32 
33     ~ThreadMemory() override;
34 
35     lldb::RegisterContextSP
36     GetRegisterContext() override;
37 
38     lldb::RegisterContextSP
39     CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
40 
41     bool
42     CalculateStopInfo() override;
43 
44     const char *
45     GetInfo() override
46     {
47         if (m_backing_thread_sp)
48             m_backing_thread_sp->GetInfo();
49         return NULL;
50     }
51 
52     const char *
53     GetName() override
54     {
55         if (!m_name.empty())
56             return m_name.c_str();
57         if (m_backing_thread_sp)
58             m_backing_thread_sp->GetName();
59         return NULL;
60     }
61 
62     const char *
63     GetQueueName() override
64     {
65         if (!m_queue.empty())
66             return m_queue.c_str();
67         if (m_backing_thread_sp)
68             m_backing_thread_sp->GetQueueName();
69         return NULL;
70     }
71 
72     void
73     WillResume(lldb::StateType resume_state) override;
74 
75     void
76     DidResume() override
77     {
78         if (m_backing_thread_sp)
79             m_backing_thread_sp->DidResume();
80     }
81 
82     lldb::user_id_t
83     GetProtocolID() const override
84     {
85         if (m_backing_thread_sp)
86             return m_backing_thread_sp->GetProtocolID();
87         return Thread::GetProtocolID();
88     }
89 
90     void
91     RefreshStateAfterStop() override;
92 
93     lldb::ValueObjectSP &
94     GetValueObject ()
95     {
96         return m_thread_info_valobj_sp;
97     }
98 
99     void
100     ClearStackFrames() override;
101 
102     void
103     ClearBackingThread() override
104     {
105         m_backing_thread_sp.reset();
106     }
107 
108     bool
109     SetBackingThread(const lldb::ThreadSP &thread_sp) override
110     {
111         //printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(), thread_sp->GetID());
112         m_backing_thread_sp = thread_sp;
113         return (bool)thread_sp;
114     }
115 
116     lldb::ThreadSP
117     GetBackingThread() const override
118     {
119         return m_backing_thread_sp;
120     }
121 
122 protected:
123     bool
124     IsOperatingSystemPluginThread() const override
125     {
126         return true;
127     }
128 
129     // If this memory thread is actually represented by a thread from the
130     // lldb_private::Process subclass, then fill in the thread here and
131     // all APIs will be routed through this thread object. If m_backing_thread_sp
132     // is empty, then this thread is simply in memory with no representation
133     // through the process plug-in.
134     lldb::ThreadSP m_backing_thread_sp;
135     lldb::ValueObjectSP m_thread_info_valobj_sp;
136     std::string m_name;
137     std::string m_queue;
138     lldb::addr_t m_register_data_addr;
139 
140 private:
141     DISALLOW_COPY_AND_ASSIGN (ThreadMemory);
142 };
143 
144 #endif // liblldb_ThreadMemory_h_
145