LLDB mainline
ThreadMemory.h
Go to the documentation of this file.
1//===-- ThreadMemory.h ------------------------------------------*- C++ -*-===//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H
11
12#include <string>
13
14#include "lldb/Target/Thread.h"
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.
22public:
24 lldb::addr_t register_data_addr)
25 : Thread(process, tid), m_register_data_addr(register_data_addr) {}
26
27 ~ThreadMemory() override;
28
30
33
34 bool CalculateStopInfo() override;
35
36 const char *GetInfo() override {
38 return m_backing_thread_sp->GetInfo();
39 return nullptr;
40 }
41
42 const char *GetName() override {
44 return m_backing_thread_sp->GetName();
45 return nullptr;
46 }
47
48 const char *GetQueueName() override {
50 return m_backing_thread_sp->GetQueueName();
51 return nullptr;
52 }
53
54 void WillResume(lldb::StateType resume_state) override;
55
56 void SetQueueName(const char *name) override {
58 m_backing_thread_sp->SetQueueName(name);
59 }
60
63 return m_backing_thread_sp->GetQueueID();
65 }
66
67 void SetQueueID(lldb::queue_id_t new_val) override {
69 m_backing_thread_sp->SetQueueID(new_val);
70 }
71
74 return m_backing_thread_sp->GetQueueKind();
76 }
77
78 void SetQueueKind(lldb::QueueKind kind) override {
80 m_backing_thread_sp->SetQueueKind(kind);
81 }
82
85 return m_backing_thread_sp->GetQueue();
86 return lldb::QueueSP();
87 }
88
91 return m_backing_thread_sp->GetQueueLibdispatchQueueAddress();
93 }
94
95 void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override {
97 m_backing_thread_sp->SetQueueLibdispatchQueueAddress(dispatch_queue_t);
98 }
99
102 return m_backing_thread_sp->GetAssociatedWithLibdispatchQueue();
104 }
105
107 lldb_private::LazyBool associated_with_libdispatch_queue) override {
109 m_backing_thread_sp->SetAssociatedWithLibdispatchQueue(
110 associated_with_libdispatch_queue);
111 }
112
113 bool ThreadHasQueueInformation() const override {
115 return m_backing_thread_sp->ThreadHasQueueInformation();
116 return false;
117 }
118
119 void DidResume() override {
121 m_backing_thread_sp->DidResume();
122 }
123
126 return m_backing_thread_sp->GetProtocolID();
127 return Thread::GetProtocolID();
128 }
129
130 void RefreshStateAfterStop() override;
131
132 void ClearStackFrames() override;
133
134 void ClearBackingThread() override {
136 m_backing_thread_sp->ClearBackedThread();
137 m_backing_thread_sp.reset();
138 }
139
140 bool SetBackingThread(const lldb::ThreadSP &thread_sp) override {
141 m_backing_thread_sp = thread_sp;
142 thread_sp->SetBackedThread(*this);
143 return thread_sp.get();
144 }
145
147 return m_backing_thread_sp;
148 }
149
150 bool IsOperatingSystemPluginThread() const override { return true; }
151
152private:
155
156 ThreadMemory(const ThreadMemory &) = delete;
157 const ThreadMemory &operator=(const ThreadMemory &) = delete;
158};
159
160/// A ThreadMemory that optionally overrides the thread name.
162public:
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
176private:
177 std::string m_name;
178};
179
180/// A ThreadMemoryProvidingName that optionally overrides queue information.
182public:
185 const lldb::ValueObjectSP &thread_info_valobj_sp);
186
188 lldb::tid_t tid, llvm::StringRef name,
189 llvm::StringRef queue,
190 lldb::addr_t register_data_addr);
191
193
194 const char *GetQueueName() override {
195 if (!m_queue.empty())
196 return m_queue.c_str();
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.
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.
239 return Thread::GetAssociatedWithLibdispatchQueue();
240 }
241
242 /// TODO: this method should take into account the queue override.
244 lldb_private::LazyBool associated_with_libdispatch_queue) override {
245 Thread::SetAssociatedWithLibdispatchQueue(
246 associated_with_libdispatch_queue);
247 }
248
250
251protected:
253 std::string m_queue;
254
255private:
257 delete;
260};
261
262#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H
void SetQueueID(lldb::queue_id_t new_val) override
TODO: this method should take into account the queue override.
lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() override
TODO: this method should take into account the queue override.
lldb::ValueObjectSP & GetValueObject()
lldb::ValueObjectSP m_thread_info_valobj_sp
void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override
TODO: this method should take into account the queue override.
void SetAssociatedWithLibdispatchQueue(lldb_private::LazyBool associated_with_libdispatch_queue) override
TODO: this method should take into account the queue override.
lldb::QueueKind GetQueueKind() override
TODO: this method should take into account the queue override.
ThreadMemoryProvidingNameAndQueue(const ThreadMemoryProvidingNameAndQueue &)=delete
const char * GetQueueName() override
Retrieve the Queue name for the queue currently using this Thread.
bool ThreadHasQueueInformation() const override
TODO: this method should take into account the queue override.
lldb::QueueSP GetQueue() override
TODO: this method should take into account the queue override.
void SetQueueName(const char *name) override
TODO: this method should take into account the queue override.
void SetQueueKind(lldb::QueueKind kind) override
TODO: this method should take into account the queue override.
lldb::queue_id_t GetQueueID() override
TODO: this method should take into account the queue override.
ThreadMemoryProvidingNameAndQueue(lldb_private::Process &process, lldb::tid_t tid, const lldb::ValueObjectSP &thread_info_valobj_sp)
const ThreadMemoryProvidingNameAndQueue & operator=(const ThreadMemoryProvidingNameAndQueue &)=delete
~ThreadMemoryProvidingNameAndQueue() override=default
lldb::addr_t GetQueueLibdispatchQueueAddress() override
TODO: this method should take into account the queue override.
~ThreadMemoryProvidingName() override=default
ThreadMemoryProvidingName(lldb_private::Process &process, lldb::tid_t tid, lldb::addr_t register_data_addr, llvm::StringRef name)
const char * GetName() override
void SetQueueKind(lldb::QueueKind kind) override
lldb::addr_t m_register_data_addr
const char * GetInfo() override
lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() override
Whether this thread can be associated with a libdispatch queue.
void DidResume() override
void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override
ThreadMemory(lldb_private::Process &process, lldb::tid_t tid, lldb::addr_t register_data_addr)
lldb::addr_t GetQueueLibdispatchQueueAddress() override
Retrieve the address of the libdispatch_queue_t struct for queue currently using this Thread.
lldb::ThreadSP GetBackingThread() const override
const ThreadMemory & operator=(const ThreadMemory &)=delete
bool IsOperatingSystemPluginThread() const override
lldb::ThreadSP m_backing_thread_sp
const char * GetQueueName() override
Retrieve the Queue name for the queue currently using this Thread.
lldb::RegisterContextSP GetRegisterContext() override
lldb::QueueKind GetQueueKind() override
Retrieve the Queue kind for the queue currently using this Thread.
lldb::QueueSP GetQueue() override
Retrieve the Queue for this thread, if any.
void SetQueueID(lldb::queue_id_t new_val) override
void RefreshStateAfterStop() override
const char * GetName() override
void SetAssociatedWithLibdispatchQueue(lldb_private::LazyBool associated_with_libdispatch_queue) override
ThreadMemory(const ThreadMemory &)=delete
void SetQueueName(const char *name) override
lldb::queue_id_t GetQueueID() override
Retrieve the Queue ID for the queue currently using this Thread.
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
void ClearBackingThread() override
bool ThreadHasQueueInformation() const override
Whether this Thread already has all the Queue information cached or not.
bool CalculateStopInfo() override
Ask the thread subclass to set its stop info.
~ThreadMemory() override
bool SetBackingThread(const lldb::ThreadSP &thread_sp) override
void WillResume(lldb::StateType resume_state) override
lldb::user_id_t GetProtocolID() const override
void ClearStackFrames() override
A plug-in interface definition class for debugging a process.
Definition Process.h:357
This base class provides an interface to stack frames.
Definition StackFrame.h:44
Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id=false)
Constructor.
Definition Thread.cpp:219
#define LLDB_INVALID_QUEUE_ID
#define LLDB_INVALID_ADDRESS
std::shared_ptr< lldb_private::Queue > QueueSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
StateType
Process and Thread States.
QueueKind
Queue type.
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
uint64_t tid_t
Definition lldb-types.h:84
uint64_t queue_id_t
Definition lldb-types.h:90