Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class OperatingSystemInterface : virtual public ScriptedThreadInterface {
virtual std::optional<std::string> GetRegisterContextForTID(lldb::tid_t tid) {
return std::nullopt;
}

virtual std::optional<bool> DoesPluginReportAllThreads() { return {}; }
};
} // namespace lldb_private

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/OperatingSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class OperatingSystem : public PluginInterface {

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

virtual bool DoesPluginReportAllThreads() = 0;

protected:
// Member variables.
Process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,12 @@ lldb::ThreadSP OperatingSystemPython::CreateThread(lldb::tid_t tid,
return ThreadSP();
}

bool OperatingSystemPython::DoesPluginReportAllThreads() {
// If the python plugin has a "DoesPluginReportAllThreads" method, use it.
if (std::optional<bool> plugin_answer =
m_operating_system_interface_sp->DoesPluginReportAllThreads())
return *plugin_answer;
return m_process->GetOSPluginReportsAllThreads();
}

#endif // #if LLDB_ENABLE_PYTHON
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class OperatingSystemPython : public lldb_private::OperatingSystem {
// Method for lazy creation of threads on demand
lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override;

bool DoesPluginReportAllThreads() override;

protected:
bool IsValid() const {
return m_script_object_sp && m_script_object_sp->IsValid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
return obj->GetAsString()->GetValue().str();
}

std::optional<bool> OperatingSystemPythonInterface::DoesPluginReportAllThreads() {
Status error;
StructuredData::ObjectSP obj = Dispatch("does_plugin_report_all_threads", error);
if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
error))
return {};

return obj->GetAsBoolean()->GetValue();
}

void OperatingSystemPythonInterface::Initialize() {
const std::vector<llvm::StringRef> ci_usages = {
"settings set target.process.python-os-plugin-path <script-path>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class OperatingSystemPythonInterface

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

std::optional<bool> DoesPluginReportAllThreads() override;

static void Initialize();

static void Terminate();
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ void Process::UpdateThreadListIfNeeded() {
// See if the OS plugin reports all threads. If it does, then
// it is safe to clear unseen thread's plans here. Otherwise we
// should preserve them in case they show up again:
clear_unused_threads = GetOSPluginReportsAllThreads();
clear_unused_threads = os->DoesPluginReportAllThreads();

// Turn off dynamic types to ensure we don't run any expressions.
// Objective-C can run an expression to determine if a SBValue is a
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/TargetProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ let Definition = "process_experimental" in {
def OSPluginReportsAllThreads: Property<"os-plugin-reports-all-threads", "Boolean">,
Global,
DefaultTrue,
Desc<"Set to False if your OS Plugins doesn't report all threads on each stop.">;
Desc<"Set to False if your Python OS Plugin doesn't report all threads on each stop.">;
}

let Definition = "process" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ def is_os_thread(self, thread):
def run_python_os_step_missing_thread(self, do_prune):
"""Test that the Python operating system plugin works correctly"""

# Our OS plugin does NOT report all threads:
result = self.dbg.HandleCommand(
"settings set process.experimental.os-plugin-reports-all-threads false"
)

python_os_plugin_path = os.path.join(self.getSourceDir(), "operating_system.py")
(target, self.process, thread, thread_bkpt) = lldbutil.run_to_source_breakpoint(
self, "first stop in thread - do a step out", self.main_file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def __init__(self, process):
if not self.g_value.IsValid():
print("Could not find g_value")

def does_plugin_report_all_threads(self):
return False
Copy link
Contributor Author

@felipepiovezan felipepiovezan Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I have changed this to True and observed the test failing


def create_thread(self, tid, context):
print("Called create thread with tid: ", tid)
return None
Expand Down
Loading