[Lldb-commits] [lldb] [LLDB] Support enabling/disabling InstrumentationRuntime plugins during a debug session (PR #190083)
Dan Liew via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 7 13:53:42 PDT 2026
================
@@ -2464,7 +2489,36 @@ PluginManager::GetInstrumentationRuntimePluginInfo() {
}
bool PluginManager::SetInstrumentationRuntimePluginEnabled(llvm::StringRef name,
bool enable) {
- return GetInstrumentationRuntimeInstances().SetInstanceEnabled(name, enable);
+ if (!GetInstrumentationRuntimeInstances().SetInstanceEnabled(name, enable))
+ return false;
+
+ // Find the `InstrumentationRuntimeType` from the plugin name
+ auto type_cb = GetInstrumentationRuntimeInstances().GetTypeCallbackForName(
+ name, /*enabled_only=*/false);
+ if (!type_cb)
+ return false;
+ auto instrumentation_ty = type_cb();
+
+ // Notify all alive processes to enable/disable the plugin
+ bool success = true;
+ for (size_t di = 0; di < Debugger::GetNumDebuggers(); ++di) {
+ DebuggerSP debugger_sp = Debugger::GetDebuggerAtIndex(di);
+ if (!debugger_sp)
----------------
delcypher wrote:
For my own reference the patch I made was something like. I'll try to fix other issues and come back to this one.
```
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index fa4483c93e639..fe400a3f1312a 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -54,6 +54,7 @@
#include <cassert>
#include <cstddef>
#include <cstdio>
+#include <functional>
namespace llvm {
class raw_ostream;
@@ -136,6 +137,8 @@ public:
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index);
+ static void ForEachDebugger(std::function<void(lldb::DebuggerSP)> callback);
+
static bool FormatDisassemblerAddress(const FormatEntity::Entry *format,
const SymbolContext *sc,
const SymbolContext *prev_sc,
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index e1b2ce1b063e0..9aec2e88c1348 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1603,6 +1603,16 @@ lldb::DebuggerSP Debugger::GetDebuggerAtIndex(size_t index) {
return nullptr;
}
+void Debugger::ForEachDebugger(std::function<void(DebuggerSP)> callback) {
+ std::lock_guard<std::mutex> guard(GetDebuggerListMutex());
+ if (!g_debugger_list_ptr)
+ return;
+ for (const auto &debugger_sp : *g_debugger_list_ptr) {
+ if (debugger_sp)
+ callback(debugger_sp);
+ }
+}
+
DebuggerSP Debugger::FindDebuggerWithID(lldb::user_id_t id) {
std::lock_guard<std::mutex> guard(GetDebuggerListMutex());
if (!g_debugger_list_ptr)
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index fa42877bfa6b9..ef7c6868f94e0 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -2502,22 +2502,15 @@ bool PluginManager::SetInstrumentationRuntimePluginEnabled(llvm::StringRef name,
// Notify all alive processes to enable/disable the plugin.
bool failed = false;
- for (size_t di = 0; di < Debugger::GetNumDebuggers(); ++di) {
- DebuggerSP debugger_sp = Debugger::GetDebuggerAtIndex(di);
- if (!debugger_sp)
- continue;
- TargetList &target_list = debugger_sp->GetTargetList();
- for (size_t ti = 0; ti < target_list.GetNumTargets(); ++ti) {
- TargetSP target_sp = target_list.GetTargetAtIndex(ti);
- if (!target_sp)
- continue;
+ Debugger::ForEachDebugger([&](DebuggerSP debugger_sp) {
+ for (const auto &target_sp : debugger_sp->GetTargetList().Targets()) {
ProcessSP process_sp = target_sp->GetProcessSP();
if (!process_sp || !process_sp->IsAlive())
continue;
failed |= llvm::errorToBool(process_sp->SetInstrumentationRuntimeEnabled(
instrumentation_ty, enable));
}
- }
+ });
return !failed;
}
```
https://github.com/llvm/llvm-project/pull/190083
More information about the lldb-commits
mailing list