Skip to content

Commit cb82771

Browse files
[lldb] Add OS plugin property for reporting all threads (#123145)
Currently, an LLDB target option controls whether plugins report all threads. However, it seems natural for this knowledge could come from the plugin itself. To support this, this commits adds a virtual method to the plugin base class, making the Python OS query the target option to preserve existing behavior.
1 parent bb6e94a commit cb82771

File tree

10 files changed

+31
-7
lines changed

10 files changed

+31
-7
lines changed

lldb/include/lldb/Interpreter/Interfaces/OperatingSystemInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class OperatingSystemInterface : virtual public ScriptedThreadInterface {
2727
virtual std::optional<std::string> GetRegisterContextForTID(lldb::tid_t tid) {
2828
return std::nullopt;
2929
}
30+
31+
virtual std::optional<bool> DoesPluginReportAllThreads() { return {}; }
3032
};
3133
} // namespace lldb_private
3234

lldb/include/lldb/Target/OperatingSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class OperatingSystem : public PluginInterface {
6161

6262
virtual bool IsOperatingSystemPluginThread(const lldb::ThreadSP &thread_sp);
6363

64+
virtual bool DoesPluginReportAllThreads() = 0;
65+
6466
protected:
6567
// Member variables.
6668
Process

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,12 @@ lldb::ThreadSP OperatingSystemPython::CreateThread(lldb::tid_t tid,
386386
return ThreadSP();
387387
}
388388

389+
bool OperatingSystemPython::DoesPluginReportAllThreads() {
390+
// If the python plugin has a "DoesPluginReportAllThreads" method, use it.
391+
if (std::optional<bool> plugin_answer =
392+
m_operating_system_interface_sp->DoesPluginReportAllThreads())
393+
return *plugin_answer;
394+
return m_process->GetOSPluginReportsAllThreads();
395+
}
396+
389397
#endif // #if LLDB_ENABLE_PYTHON

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class OperatingSystemPython : public lldb_private::OperatingSystem {
6060
// Method for lazy creation of threads on demand
6161
lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override;
6262

63+
bool DoesPluginReportAllThreads() override;
64+
6365
protected:
6466
bool IsValid() const {
6567
return m_script_object_sp && m_script_object_sp->IsValid();

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
8282
return obj->GetAsString()->GetValue().str();
8383
}
8484

85+
std::optional<bool> OperatingSystemPythonInterface::DoesPluginReportAllThreads() {
86+
Status error;
87+
StructuredData::ObjectSP obj = Dispatch("does_plugin_report_all_threads", error);
88+
if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
89+
error))
90+
return {};
91+
92+
return obj->GetAsBoolean()->GetValue();
93+
}
94+
8595
void OperatingSystemPythonInterface::Initialize() {
8696
const std::vector<llvm::StringRef> ci_usages = {
8797
"settings set target.process.python-os-plugin-path <script-path>",

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class OperatingSystemPythonInterface
4545

4646
std::optional<std::string> GetRegisterContextForTID(lldb::tid_t tid) override;
4747

48+
std::optional<bool> DoesPluginReportAllThreads() override;
49+
4850
static void Initialize();
4951

5052
static void Terminate();

lldb/source/Target/Process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ void Process::UpdateThreadListIfNeeded() {
11821182
// See if the OS plugin reports all threads. If it does, then
11831183
// it is safe to clear unseen thread's plans here. Otherwise we
11841184
// should preserve them in case they show up again:
1185-
clear_unused_threads = GetOSPluginReportsAllThreads();
1185+
clear_unused_threads = os->DoesPluginReportAllThreads();
11861186

11871187
// Turn off dynamic types to ensure we don't run any expressions.
11881188
// Objective-C can run an expression to determine if a SBValue is a

lldb/source/Target/TargetProperties.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ let Definition = "process_experimental" in {
223223
def OSPluginReportsAllThreads: Property<"os-plugin-reports-all-threads", "Boolean">,
224224
Global,
225225
DefaultTrue,
226-
Desc<"Set to False if your OS Plugins doesn't report all threads on each stop.">;
226+
Desc<"Set to False if your Python OS Plugin doesn't report all threads on each stop.">;
227227
}
228228

229229
let Definition = "process" in {

lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/TestOSPluginStepping.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ def is_os_thread(self, thread):
4040
def run_python_os_step_missing_thread(self, do_prune):
4141
"""Test that the Python operating system plugin works correctly"""
4242

43-
# Our OS plugin does NOT report all threads:
44-
result = self.dbg.HandleCommand(
45-
"settings set process.experimental.os-plugin-reports-all-threads false"
46-
)
47-
4843
python_os_plugin_path = os.path.join(self.getSourceDir(), "operating_system.py")
4944
(target, self.process, thread, thread_bkpt) = lldbutil.run_to_source_breakpoint(
5045
self, "first stop in thread - do a step out", self.main_file

lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/operating_system.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def __init__(self, process):
3434
if not self.g_value.IsValid():
3535
print("Could not find g_value")
3636

37+
def does_plugin_report_all_threads(self):
38+
return False
39+
3740
def create_thread(self, tid, context):
3841
print("Called create thread with tid: ", tid)
3942
return None

0 commit comments

Comments
 (0)