https://github.com/medismailben updated https://github.com/llvm/llvm-project/pull/209307
>From b17f4de333aded1c9d3b79dfb9875a5671f69fd0 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani <[email protected]> Date: Mon, 13 Jul 2026 14:15:43 -0700 Subject: [PATCH] [lldb] Expand ScriptedExtension coverage across scripted Python interfaces (NFC) This patch introduces `lldb::ScriptedExtension`, a single enum that names every scriptable extension point, and threads it through `PluginManager`'s scripted-interface registration: `RegisterPlugin` now takes a `ScriptedExtension`, `GetScriptedInterfaceExtensionAtIndex` exposes it, and every existing call site is updated to pass the right value. It also promotes `ScriptedThreadPythonInterface` and `ScriptedFramePythonInterface` to full plugins (with `Initialize` / `Terminate` and a `GetPluginName`) so they register with `PluginManager` under their own `ScriptedExtension` values, and cleans up an inheritance ambiguity this exposes in `OperatingSystemPythonInterface`. Signed-off-by: Med Ismail Bennani <[email protected]> --- lldb/include/lldb/Core/PluginManager.h | 4 ++++ lldb/include/lldb/lldb-enumerations.h | 15 +++++++++++++++ lldb/source/Core/PluginManager.cpp | 17 ++++++++++++++--- .../OperatingSystemPythonInterface.cpp | 3 ++- .../Interfaces/OperatingSystemPythonInterface.h | 2 +- .../ScriptInterpreterPythonInterfaces.cpp | 4 ++++ .../ScriptInterpreterPythonInterfaces.h | 1 + .../ScriptedBreakpointPythonInterface.cpp | 3 ++- .../ScriptedFrameProviderPythonInterface.cpp | 3 ++- .../Interfaces/ScriptedFramePythonInterface.cpp | 13 +++++++++++++ .../Interfaces/ScriptedFramePythonInterface.h | 13 ++++++++++++- .../Interfaces/ScriptedHookPythonInterface.cpp | 3 ++- .../ScriptedPlatformPythonInterface.cpp | 3 ++- .../ScriptedProcessPythonInterface.cpp | 3 ++- .../ScriptedStopHookPythonInterface.cpp | 6 ++++-- .../ScriptedThreadPlanPythonInterface.cpp | 3 ++- .../ScriptedThreadPythonInterface.cpp | 12 ++++++++++++ .../Interfaces/ScriptedThreadPythonInterface.h | 13 ++++++++++++- 18 files changed, 106 insertions(+), 15 deletions(-) diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index 95c88848e8167..9d36a9361dbc4 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -667,6 +667,7 @@ class PluginManager { // Scripted Interface static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ScriptedInterfaceCreateInstance create_callback, + lldb::ScriptedExtension extension, lldb::ScriptLanguage language, ScriptedInterfaceUsages usages); @@ -678,6 +679,9 @@ class PluginManager { static llvm::StringRef GetScriptedInterfaceDescriptionAtIndex(uint32_t idx); + static lldb::ScriptedExtension + GetScriptedInterfaceExtensionAtIndex(uint32_t idx); + static lldb::ScriptLanguage GetScriptedInterfaceLanguageAtIndex(uint32_t idx); static ScriptedInterfaceUsages diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index 5aad004cecbb5..4eb5e99d76224 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -255,6 +255,21 @@ enum ScriptLanguage { eScriptLanguageDefault = eScriptLanguagePython }; +/// Scripting interpreter types. +enum ScriptedExtension { + eScriptedExtensionInvalid = 0, + eScriptedExtensionOperatingSystem, + eScriptedExtensionScriptedPlatform, + eScriptedExtensionScriptedProcess, + eScriptedExtensionScriptedStopHook, + eScriptedExtensionScriptedBreakpoint, + eScriptedExtensionScriptedThreadPlan, + eScriptedExtensionScriptedFrameProvider, + eScriptedExtensionScriptedHook, + eScriptedExtensionScriptedThread, + eScriptedExtensionScriptedFrame, +}; + /// Register numbering types. // See RegisterContext::ConvertRegisterKindToRegisterNumber to convert any of // these to the lldb internal register numbering scheme (eRegisterKindLLDB). diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 89225495ae293..34b7f87b09af8 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -13,6 +13,7 @@ #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" #include "lldb/Interpreter/OptionValueProperties.h" +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Symbol/SaveCoreOptions.h" #include "lldb/Target/Process.h" #include "lldb/Utility/FileSpec.h" @@ -2058,12 +2059,14 @@ struct ScriptedInterfaceInstance : public PluginInstance<ScriptedInterfaceCreateInstance> { ScriptedInterfaceInstance(llvm::StringRef name, llvm::StringRef description, ScriptedInterfaceCreateInstance create_callback, + lldb::ScriptedExtension extension, lldb::ScriptLanguage language, ScriptedInterfaceUsages usages) : PluginInstance<ScriptedInterfaceCreateInstance>(name, description, create_callback), - language(language), usages(usages) {} + extension(extension), language(language), usages(usages) {} + lldb::ScriptedExtension extension; lldb::ScriptLanguage language; ScriptedInterfaceUsages usages; }; @@ -2078,9 +2081,10 @@ static ScriptedInterfaceInstances &GetScriptedInterfaceInstances() { bool PluginManager::RegisterPlugin( llvm::StringRef name, llvm::StringRef description, ScriptedInterfaceCreateInstance create_callback, - lldb::ScriptLanguage language, ScriptedInterfaceUsages usages) { + lldb::ScriptedExtension extension, lldb::ScriptLanguage language, + ScriptedInterfaceUsages usages) { return GetScriptedInterfaceInstances().RegisterPlugin( - name, description, create_callback, language, usages); + name, description, create_callback, extension, language, usages); } bool PluginManager::UnregisterPlugin( @@ -2101,6 +2105,13 @@ PluginManager::GetScriptedInterfaceDescriptionAtIndex(uint32_t index) { return GetScriptedInterfaceInstances().GetDescriptionAtIndex(index); } +lldb::ScriptedExtension +PluginManager::GetScriptedInterfaceExtensionAtIndex(uint32_t index) { + if (auto instance = GetScriptedInterfaceInstances().GetInstanceAtIndex(index)) + return instance->extension; + return ScriptedExtension::eScriptedExtensionInvalid; +} + lldb::ScriptLanguage PluginManager::GetScriptedInterfaceLanguageAtIndex(uint32_t idx) { if (auto instance = GetScriptedInterfaceInstances().GetInstanceAtIndex(idx)) diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp index 382a5288e223c..6a1bcf41ba9d5 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp @@ -94,7 +94,8 @@ void OperatingSystemPythonInterface::Initialize() { const std::vector<llvm::StringRef> api_usages = {}; PluginManager::RegisterPlugin( GetPluginNameStatic(), llvm::StringRef("Mock thread state"), - CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); + CreateInstance, eScriptedExtensionOperatingSystem, eScriptLanguagePython, + {ci_usages, api_usages}); } void OperatingSystemPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h index da49917bcdd05..b2d4510e625de 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h @@ -19,7 +19,7 @@ namespace lldb_private { class OperatingSystemPythonInterface : virtual public OperatingSystemInterface, virtual public ScriptedThreadPythonInterface, - public PluginInterface { + virtual public PluginInterface { public: OperatingSystemPythonInterface(ScriptInterpreterPythonImpl &interpreter); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.cpp index 9e0ee5f23735f..5f29b7c72957e 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.cpp @@ -28,6 +28,8 @@ void ScriptInterpreterPythonInterfaces::Initialize() { ScriptedBreakpointPythonInterface::Initialize(); ScriptedThreadPlanPythonInterface::Initialize(); ScriptedFrameProviderPythonInterface::Initialize(); + ScriptedThreadPythonInterface::Initialize(); + ScriptedFramePythonInterface::Initialize(); } void ScriptInterpreterPythonInterfaces::Terminate() { @@ -39,4 +41,6 @@ void ScriptInterpreterPythonInterfaces::Terminate() { ScriptedBreakpointPythonInterface::Terminate(); ScriptedThreadPlanPythonInterface::Terminate(); ScriptedFrameProviderPythonInterface::Terminate(); + ScriptedThreadPythonInterface::Terminate(); + ScriptedFramePythonInterface::Terminate(); } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.h index 032e62d7eab9e..6fb6039d30b0a 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.h @@ -21,6 +21,7 @@ #include "ScriptedProcessPythonInterface.h" #include "ScriptedStopHookPythonInterface.h" #include "ScriptedThreadPlanPythonInterface.h" +#include "ScriptedThreadPythonInterface.h" namespace lldb_private { class ScriptInterpreterPythonInterfaces : public PluginInterface { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedBreakpointPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedBreakpointPythonInterface.cpp index 4cd087b5e5e8c..dd93df2cd75bb 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedBreakpointPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedBreakpointPythonInterface.cpp @@ -143,7 +143,8 @@ void ScriptedBreakpointPythonInterface::Initialize() { GetPluginNameStatic(), llvm::StringRef("Create a breakpoint that chooses locations based on " "user-created callbacks"), - CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); + CreateInstance, eScriptedExtensionScriptedBreakpointResolver, + eScriptLanguagePython, {ci_usages, api_usages}); } void ScriptedBreakpointPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp index 815a7283ab644..f953fb21e0c49 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp @@ -116,7 +116,8 @@ void ScriptedFrameProviderPythonInterface::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), llvm::StringRef("Provide scripted stack frames for threads"), - CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); + CreateInstance, eScriptedExtensionScriptedFrameProvider, + eScriptLanguagePython, {ci_usages, api_usages}); } void ScriptedFrameProviderPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.cpp index 6cc5ebff2c10b..8a6dd2d322992 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.cpp @@ -8,6 +8,7 @@ #include "../lldb-python.h" +#include "lldb/Core/PluginManager.h" #include "lldb/Host/Config.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Utility/Log.h" @@ -194,3 +195,15 @@ ScriptedFramePythonInterface::GetValueObjectForVariableExpression( return val; } + +void ScriptedFramePythonInterface::Initialize() { + PluginManager::RegisterPlugin( + GetPluginNameStatic(), + "Provide frame state for scripted threads and frame providers.", + CreateInstance, eScriptedExtensionScriptedFrame, eScriptLanguagePython, + {}); +} + +void ScriptedFramePythonInterface::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); +} diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.h index 9320c6762b35f..ab48da85c16b5 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFramePythonInterface.h @@ -15,7 +15,8 @@ namespace lldb_private { class ScriptedFramePythonInterface : public ScriptedFrameInterface, - public ScriptedPythonInterface { + public ScriptedPythonInterface, + public PluginInterface { public: ScriptedFramePythonInterface(ScriptInterpreterPythonImpl &interpreter); @@ -57,6 +58,16 @@ class ScriptedFramePythonInterface : public ScriptedFrameInterface, lldb::ValueObjectSP GetValueObjectForVariableExpression(llvm::StringRef expr, uint32_t options, Status &status) override; + + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { + return "ScriptedFramePythonInterface"; + } + + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } }; } // namespace lldb_private diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedHookPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedHookPythonInterface.cpp index 09f5d91796bb4..df4146657c53e 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedHookPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedHookPythonInterface.cpp @@ -99,7 +99,8 @@ void ScriptedHookPythonInterface::Initialize() { GetPluginNameStatic(), llvm::StringRef("Perform actions on target lifecycle events (module " "load/unload, process stop)."), - CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); + CreateInstance, eScriptedExtensionScriptedHook, eScriptLanguagePython, + {ci_usages, api_usages}); } void ScriptedHookPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp index bd3ab07856ce4..ff0237e788e75 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp @@ -92,7 +92,8 @@ Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) { void ScriptedPlatformPythonInterface::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), "Mock platform and interact with its processes.", - CreateInstance, eScriptLanguagePython, {}); + CreateInstance, eScriptedExtensionScriptedPlatform, eScriptLanguagePython, + {}); } void ScriptedPlatformPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp index a071157447e35..faa9aa6964866 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp @@ -218,7 +218,8 @@ void ScriptedProcessPythonInterface::Initialize() { "SBTarget.Launch"}; PluginManager::RegisterPlugin( GetPluginNameStatic(), llvm::StringRef("Mock process state"), - CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); + CreateInstance, eScriptedExtensionScriptedProcess, eScriptLanguagePython, + {ci_usages, api_usages}); } void ScriptedProcessPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp index ca02e9070c4c2..7a9ce8b67ac1e 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp @@ -59,8 +59,10 @@ void ScriptedStopHookPythonInterface::Initialize() { const std::vector<llvm::StringRef> api_usages = {}; PluginManager::RegisterPlugin( GetPluginNameStatic(), - llvm::StringRef("Perform actions whenever the process stops, before control is returned to the user."), - CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); + llvm::StringRef("Perform actions whenever the process stops, before " + "control is returned to the user."), + CreateInstance, eScriptedExtensionScriptedStopHook, eScriptLanguagePython, + {ci_usages, api_usages}); } void ScriptedStopHookPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp index 007765daef818..b18823ea60960 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp @@ -109,7 +109,8 @@ void ScriptedThreadPlanPythonInterface::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), llvm::StringRef("Alter thread stepping logic and stop reason"), - CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); + CreateInstance, eScriptedExtensionScriptedThreadPlan, + eScriptLanguagePython, {ci_usages, api_usages}); } void ScriptedThreadPlanPythonInterface::Terminate() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp index 20f55c4de552c..4abb52182961d 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp @@ -8,6 +8,7 @@ #include "../lldb-python.h" +#include "lldb/Core/PluginManager.h" #include "lldb/Host/Config.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Utility/Log.h" @@ -157,3 +158,14 @@ lldb::ScriptedFrameInterfaceSP ScriptedThreadPythonInterface::CreateScriptedFrameInterface() { return m_interpreter.CreateScriptedFrameInterface(); } + +void ScriptedThreadPythonInterface::Initialize() { + PluginManager::RegisterPlugin( + GetPluginNameStatic(), "Provide thread state for a scripted process.", + CreateInstance, eScriptedExtensionScriptedThread, eScriptLanguagePython, + {}); +} + +void ScriptedThreadPythonInterface::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); +} diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h index 138bcad444aca..ba53b1f4c2921 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h @@ -15,7 +15,8 @@ namespace lldb_private { class ScriptedThreadPythonInterface : public ScriptedThreadInterface, - public ScriptedPythonInterface { + public ScriptedPythonInterface, + virtual public PluginInterface { public: ScriptedThreadPythonInterface(ScriptInterpreterPythonImpl &interpreter); @@ -50,6 +51,16 @@ class ScriptedThreadPythonInterface : public ScriptedThreadInterface, std::optional<std::string> GetScriptedFramePluginName() override; + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { + return "ScriptedThreadPythonInterface"; + } + + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + protected: lldb::ScriptedFrameInterfaceSP CreateScriptedFrameInterface() override; }; _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
