Skip to content

Commit c8e7e22

Browse files
[lldb] Add APIs enabling OperatingSystem plugins to update ThreadPlanStack
At the end of Process::UpdateThreadListIfNeeded, we see this comment: ``` // Now update the plan stack map. // If we do have an OS plugin, any absent real threads in the // m_thread_list have already been removed from the ThreadPlanStackMap. // So any remaining threads are OS Plugin threads, and those we want to // preserve in case they show up again. m_thread_plans.Update(m_thread_list, clear_unused_threads); ``` In other words, if a OS plugin maps a real thread to a plugin thread, the plugin is expected to remove the thread plan of the real thread from `m_thread_plans`. However, it is impossible to do so today: the APIs are simply not there. In fact, plugins don't even have access to `m_thread_plans`. This is not a problem for plugins who "report all threads", since LLDB will then clean up plans for any threads that are not present in the new list of threads (mapped real threads won't be in the new list). For plugins that do _not_ report all threads, this is a problem. There are two pieces missing here: A) The `OperatingSystem::UpdateThreadList` function needs access to m_thread_plans. B) ThreadPlanStack needs to expose the TIDs it currently knows about, since its methods (like Find, Erase) are all TID-based. This commit provides these pieces so that future commits (and plugins) may make use of them. Point A is currently addressed by passing m_thread_plans as a function argument to OperatingSystem::UpdateThreadList, however it would have been possible to make it public through an accessor method in Process.
1 parent dac06e7 commit c8e7e22

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

lldb/include/lldb/Target/OperatingSystem.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "lldb/lldb-private.h"
1515

1616
namespace lldb_private {
17+
class ThreadPlanStackMap;
1718

1819
/// \class OperatingSystem OperatingSystem.h "lldb/Target/OperatingSystem.h"
1920
/// A plug-in interface definition class for halted OS helpers.
@@ -45,7 +46,8 @@ class OperatingSystem : public PluginInterface {
4546
// Plug-in Methods
4647
virtual bool UpdateThreadList(ThreadList &old_thread_list,
4748
ThreadList &real_thread_list,
48-
ThreadList &new_thread_list) = 0;
49+
ThreadList &new_thread_list,
50+
ThreadPlanStackMap &plan_stack_map) = 0;
4951

5052
virtual void ThreadWasSelected(Thread *thread) = 0;
5153

lldb/include/lldb/Target/ThreadPlanStack.h

+7
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ class ThreadPlanStackMap {
179179

180180
bool PrunePlansForTID(lldb::tid_t tid);
181181

182+
std::vector<lldb::tid_t> GetKnownTIDs() const {
183+
std::vector<lldb::tid_t> TIDs;
184+
for (auto &plan_stack : m_plans_up_container)
185+
TIDs.push_back(plan_stack->GetTID());
186+
return TIDs;
187+
}
188+
182189
private:
183190
Process &m_process;
184191
mutable std::recursive_mutex m_stack_map_mutex;

lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ DynamicRegisterInfo *OperatingSystemPython::GetDynamicRegisterInfo() {
163163

164164
bool OperatingSystemPython::UpdateThreadList(ThreadList &old_thread_list,
165165
ThreadList &core_thread_list,
166-
ThreadList &new_thread_list) {
166+
ThreadList &new_thread_list,
167+
ThreadPlanStackMap &) {
167168
if (!m_interpreter || !m_operating_system_interface_sp)
168169
return false;
169170

lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ class OperatingSystemPython : public lldb_private::OperatingSystem {
4444
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
4545

4646
// lldb_private::OperatingSystem Methods
47-
bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
48-
lldb_private::ThreadList &real_thread_list,
49-
lldb_private::ThreadList &new_thread_list) override;
47+
bool
48+
UpdateThreadList(lldb_private::ThreadList &old_thread_list,
49+
lldb_private::ThreadList &real_thread_list,
50+
lldb_private::ThreadList &new_thread_list,
51+
lldb_private::ThreadPlanStackMap &plan_stack_map) override;
5052

5153
void ThreadWasSelected(lldb_private::Thread *thread) override;
5254

lldb/source/Target/Process.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,9 @@ void Process::UpdateThreadListIfNeeded() {
12021202
real_thread_list, // The actual thread list full of threads
12031203
// created by each lldb_private::Process
12041204
// subclass
1205-
new_thread_list); // The new thread list that we will show to the
1205+
new_thread_list, // The new thread list that we will show to the
12061206
// user that gets filled in
1207+
m_thread_plans);
12071208

12081209
if (saved_prefer_dynamic != lldb::eNoDynamicValues)
12091210
target.SetPreferDynamicValue(saved_prefer_dynamic);

0 commit comments

Comments
 (0)