13
13
14
14
#include " lldb/Target/Thread.h"
15
15
16
+ // / A memory thread with its own ID, optionally backed by a real thread.
17
+ // / Most methods of this class dispatch to the real thread if it is not null.
18
+ // / Notable exceptions are the methods calculating the StopInfo and
19
+ // / RegisterContext of the thread, those may query the OS plugin that created
20
+ // / the thread.
16
21
class ThreadMemory : public lldb_private ::Thread {
17
22
public:
18
23
ThreadMemory (lldb_private::Process &process, lldb::tid_t tid,
19
- const lldb::ValueObjectSP &thread_info_valobj_sp);
20
-
21
- ThreadMemory (lldb_private::Process &process, lldb::tid_t tid,
22
- llvm::StringRef name, llvm::StringRef queue,
23
- lldb::addr_t register_data_addr);
24
+ lldb::addr_t register_data_addr)
25
+ : Thread(process, tid), m_register_data_addr(register_data_addr) {}
24
26
25
27
~ThreadMemory () override ;
26
28
@@ -38,23 +40,82 @@ class ThreadMemory : public lldb_private::Thread {
38
40
}
39
41
40
42
const char *GetName () override {
41
- if (!m_name.empty ())
42
- return m_name.c_str ();
43
43
if (m_backing_thread_sp)
44
44
return m_backing_thread_sp->GetName ();
45
45
return nullptr ;
46
46
}
47
47
48
48
const char *GetQueueName () override {
49
- if (!m_queue.empty ())
50
- return m_queue.c_str ();
51
49
if (m_backing_thread_sp)
52
50
return m_backing_thread_sp->GetQueueName ();
53
51
return nullptr ;
54
52
}
55
53
56
54
void WillResume (lldb::StateType resume_state) override ;
57
55
56
+ void SetQueueName (const char *name) override {
57
+ if (m_backing_thread_sp)
58
+ m_backing_thread_sp->SetQueueName (name);
59
+ }
60
+
61
+ lldb::queue_id_t GetQueueID () override {
62
+ if (m_backing_thread_sp)
63
+ return m_backing_thread_sp->GetQueueID ();
64
+ return LLDB_INVALID_QUEUE_ID;
65
+ }
66
+
67
+ void SetQueueID (lldb::queue_id_t new_val) override {
68
+ if (m_backing_thread_sp)
69
+ m_backing_thread_sp->SetQueueID (new_val);
70
+ }
71
+
72
+ lldb::QueueKind GetQueueKind () override {
73
+ if (m_backing_thread_sp)
74
+ return m_backing_thread_sp->GetQueueKind ();
75
+ return lldb::eQueueKindUnknown;
76
+ }
77
+
78
+ void SetQueueKind (lldb::QueueKind kind) override {
79
+ if (m_backing_thread_sp)
80
+ m_backing_thread_sp->SetQueueKind (kind);
81
+ }
82
+
83
+ lldb::QueueSP GetQueue () override {
84
+ if (m_backing_thread_sp)
85
+ return m_backing_thread_sp->GetQueue ();
86
+ return lldb::QueueSP ();
87
+ }
88
+
89
+ lldb::addr_t GetQueueLibdispatchQueueAddress () override {
90
+ if (m_backing_thread_sp)
91
+ return m_backing_thread_sp->GetQueueLibdispatchQueueAddress ();
92
+ return LLDB_INVALID_ADDRESS;
93
+ }
94
+
95
+ void SetQueueLibdispatchQueueAddress (lldb::addr_t dispatch_queue_t ) override {
96
+ if (m_backing_thread_sp)
97
+ m_backing_thread_sp->SetQueueLibdispatchQueueAddress (dispatch_queue_t );
98
+ }
99
+
100
+ lldb_private::LazyBool GetAssociatedWithLibdispatchQueue () override {
101
+ if (m_backing_thread_sp)
102
+ return m_backing_thread_sp->GetAssociatedWithLibdispatchQueue ();
103
+ return lldb_private::eLazyBoolNo;
104
+ }
105
+
106
+ void SetAssociatedWithLibdispatchQueue (
107
+ lldb_private::LazyBool associated_with_libdispatch_queue) override {
108
+ if (m_backing_thread_sp)
109
+ m_backing_thread_sp->SetAssociatedWithLibdispatchQueue (
110
+ associated_with_libdispatch_queue);
111
+ }
112
+
113
+ bool ThreadHasQueueInformation () const override {
114
+ if (m_backing_thread_sp)
115
+ return m_backing_thread_sp->ThreadHasQueueInformation ();
116
+ return false ;
117
+ }
118
+
58
119
void DidResume () override {
59
120
if (m_backing_thread_sp)
60
121
m_backing_thread_sp->DidResume ();
@@ -68,8 +129,6 @@ class ThreadMemory : public lldb_private::Thread {
68
129
69
130
void RefreshStateAfterStop () override ;
70
131
71
- lldb::ValueObjectSP &GetValueObject () { return m_thread_info_valobj_sp; }
72
-
73
132
void ClearStackFrames () override ;
74
133
75
134
void ClearBackingThread () override {
@@ -79,34 +138,125 @@ class ThreadMemory : public lldb_private::Thread {
79
138
}
80
139
81
140
bool SetBackingThread (const lldb::ThreadSP &thread_sp) override {
82
- // printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(),
83
- // thread_sp->GetID());
84
141
m_backing_thread_sp = thread_sp;
85
142
thread_sp->SetBackedThread (*this );
86
- return ( bool )thread_sp ;
143
+ return thread_sp. get () ;
87
144
}
88
145
89
146
lldb::ThreadSP GetBackingThread () const override {
90
147
return m_backing_thread_sp;
91
148
}
92
149
93
- protected:
94
150
bool IsOperatingSystemPluginThread () const override { return true ; }
95
151
96
- // If this memory thread is actually represented by a thread from the
97
- // lldb_private::Process subclass, then fill in the thread here and
98
- // all APIs will be routed through this thread object. If m_backing_thread_sp
99
- // is empty, then this thread is simply in memory with no representation
100
- // through the process plug-in.
152
+ private:
153
+ lldb::addr_t m_register_data_addr;
101
154
lldb::ThreadSP m_backing_thread_sp;
102
- lldb::ValueObjectSP m_thread_info_valobj_sp;
155
+
156
+ ThreadMemory (const ThreadMemory &) = delete ;
157
+ const ThreadMemory &operator =(const ThreadMemory &) = delete ;
158
+ };
159
+
160
+ // / A ThreadMemory that optionally overrides the thread name.
161
+ class ThreadMemoryProvidingName : public ThreadMemory {
162
+ public:
163
+ ThreadMemoryProvidingName (lldb_private::Process &process, lldb::tid_t tid,
164
+ lldb::addr_t register_data_addr,
165
+ llvm::StringRef name)
166
+ : ThreadMemory(process, tid, register_data_addr), m_name(name) {}
167
+
168
+ const char *GetName () override {
169
+ if (!m_name.empty ())
170
+ return m_name.c_str ();
171
+ return ThreadMemory::GetName ();
172
+ }
173
+
174
+ ~ThreadMemoryProvidingName () override = default ;
175
+
176
+ private:
103
177
std::string m_name;
178
+ };
179
+
180
+ // / A ThreadMemoryProvidingName that optionally overrides queue information.
181
+ class ThreadMemoryProvidingNameAndQueue : public ThreadMemoryProvidingName {
182
+ public:
183
+ ThreadMemoryProvidingNameAndQueue (
184
+ lldb_private::Process &process, lldb::tid_t tid,
185
+ const lldb::ValueObjectSP &thread_info_valobj_sp);
186
+
187
+ ThreadMemoryProvidingNameAndQueue (lldb_private::Process &process,
188
+ lldb::tid_t tid, llvm::StringRef name,
189
+ llvm::StringRef queue,
190
+ lldb::addr_t register_data_addr);
191
+
192
+ ~ThreadMemoryProvidingNameAndQueue () override = default ;
193
+
194
+ const char *GetQueueName () override {
195
+ if (!m_queue.empty ())
196
+ return m_queue.c_str ();
197
+ return ThreadMemory::GetQueueName ();
198
+ }
199
+
200
+ // / TODO: this method should take into account the queue override.
201
+ void SetQueueName (const char *name) override { Thread::SetQueueName (name); }
202
+
203
+ // / TODO: this method should take into account the queue override.
204
+ lldb::queue_id_t GetQueueID () override { return Thread::GetQueueID (); }
205
+
206
+ // / TODO: this method should take into account the queue override.
207
+ void SetQueueID (lldb::queue_id_t new_val) override {
208
+ Thread::SetQueueID (new_val);
209
+ }
210
+
211
+ // / TODO: this method should take into account the queue override.
212
+ lldb::QueueKind GetQueueKind () override { return Thread::GetQueueKind (); }
213
+
214
+ // / TODO: this method should take into account the queue override.
215
+ void SetQueueKind (lldb::QueueKind kind) override {
216
+ Thread::SetQueueKind (kind);
217
+ }
218
+
219
+ // / TODO: this method should take into account the queue override.
220
+ lldb::QueueSP GetQueue () override { return Thread::GetQueue (); }
221
+
222
+ // / TODO: this method should take into account the queue override.
223
+ lldb::addr_t GetQueueLibdispatchQueueAddress () override {
224
+ return Thread::GetQueueLibdispatchQueueAddress ();
225
+ }
226
+
227
+ // / TODO: this method should take into account the queue override.
228
+ void SetQueueLibdispatchQueueAddress (lldb::addr_t dispatch_queue_t ) override {
229
+ Thread::SetQueueLibdispatchQueueAddress (dispatch_queue_t );
230
+ }
231
+
232
+ // / TODO: this method should take into account the queue override.
233
+ bool ThreadHasQueueInformation () const override {
234
+ return Thread::ThreadHasQueueInformation ();
235
+ }
236
+
237
+ // / TODO: this method should take into account the queue override.
238
+ lldb_private::LazyBool GetAssociatedWithLibdispatchQueue () override {
239
+ return Thread::GetAssociatedWithLibdispatchQueue ();
240
+ }
241
+
242
+ // / TODO: this method should take into account the queue override.
243
+ void SetAssociatedWithLibdispatchQueue (
244
+ lldb_private::LazyBool associated_with_libdispatch_queue) override {
245
+ Thread::SetAssociatedWithLibdispatchQueue (
246
+ associated_with_libdispatch_queue);
247
+ }
248
+
249
+ lldb::ValueObjectSP &GetValueObject () { return m_thread_info_valobj_sp; }
250
+
251
+ protected:
252
+ lldb::ValueObjectSP m_thread_info_valobj_sp;
104
253
std::string m_queue;
105
- lldb::addr_t m_register_data_addr;
106
254
107
255
private:
108
- ThreadMemory (const ThreadMemory &) = delete ;
109
- const ThreadMemory &operator =(const ThreadMemory &) = delete ;
256
+ ThreadMemoryProvidingNameAndQueue (const ThreadMemoryProvidingNameAndQueue &) =
257
+ delete ;
258
+ const ThreadMemoryProvidingNameAndQueue &
259
+ operator =(const ThreadMemoryProvidingNameAndQueue &) = delete ;
110
260
};
111
261
112
262
#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H
0 commit comments