From 2402b3213c2f10d5033b31df3a0e59e4ad151fbd Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Sat, 27 Jul 2024 17:29:56 -0700 Subject: [PATCH] [lldb] Add ScriptedProcess to `scripting template list` This patch is a follow-up to bccff3baeff8 which adds the `ScriptedProcess` extension to the `scripting template list` command as well as its description. Signed-off-by: Med Ismail Bennani --- .../Python/Interfaces/CMakeLists.txt | 2 +- .../CMakeLists.txt | 16 ++++++++ .../ScriptedProcessPythonInterface.cpp | 39 +++++++++++++++---- .../ScriptedProcessPythonInterface.h | 18 +++++++-- .../Python/ScriptInterpreterPython.cpp | 2 +- 5 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => ScriptedProcessPythonInterface}/ScriptedProcessPythonInterface.cpp (85%) rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => ScriptedProcessPythonInterface}/ScriptedProcessPythonInterface.h (88%) diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt index 8c7e92bead32c8..eb22a960b53454 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt @@ -21,7 +21,6 @@ endif() add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces ScriptedPythonInterface.cpp - ScriptedProcessPythonInterface.cpp ScriptedThreadPythonInterface.cpp LINK_LIBS @@ -38,5 +37,6 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces add_subdirectory(OperatingSystemPythonInterface) add_subdirectory(ScriptedPlatformPythonInterface) +add_subdirectory(ScriptedProcessPythonInterface) add_subdirectory(ScriptedThreadPlanPythonInterface) diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt new file mode 100644 index 00000000000000..66ed041853f675 --- /dev/null +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt @@ -0,0 +1,16 @@ +add_lldb_library(lldbPluginScriptInterpreterPythonScriptedProcessPythonInterface PLUGIN + + ScriptedProcessPythonInterface.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbInterpreter + lldbTarget + lldbPluginScriptInterpreterPython + ${Python3_LIBRARIES} + ${LLDB_LIBEDIT_LIBS} + + LINK_COMPONENTS + Support + ) diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp similarity index 85% rename from lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp rename to lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp index 313c597ce48f3c..f4fba0848fe272 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp @@ -6,11 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "lldb/Core/PluginManager.h" #include "lldb/Host/Config.h" -#if LLDB_ENABLE_PYTHON -// LLDB Python header must be included first -#include "../lldb-python.h" -#endif #include "lldb/Target/Process.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Status.h" @@ -18,10 +15,16 @@ #if LLDB_ENABLE_PYTHON -#include "../SWIGPythonBridge.h" -#include "../ScriptInterpreterPythonImpl.h" +// clang-format off +// LLDB Python header must be included first +#include "../../lldb-python.h" +//clang-format on + +#include "../../SWIGPythonBridge.h" +#include "../../ScriptInterpreterPythonImpl.h" +#include "../ScriptedThreadPythonInterface.h" #include "ScriptedProcessPythonInterface.h" -#include "ScriptedThreadPythonInterface.h" + #include using namespace lldb; @@ -29,6 +32,8 @@ using namespace lldb_private; using namespace lldb_private::python; using Locker = ScriptInterpreterPythonImpl::Locker; +LLDB_PLUGIN_DEFINE_ADV(ScriptedProcessPythonInterface, ScriptInterpreterPythonScriptedProcessPythonInterface) + ScriptedProcessPythonInterface::ScriptedProcessPythonInterface( ScriptInterpreterPythonImpl &interpreter) : ScriptedProcessInterface(), ScriptedPythonInterface(interpreter) {} @@ -208,4 +213,24 @@ StructuredData::DictionarySP ScriptedProcessPythonInterface::GetMetadata() { return dict; } +void ScriptedProcessPythonInterface::Initialize() { + const std::vector ci_usages = { + "process attach -C [-k key -v value ...]", + "process launch -C [-k key -v value ...]"}; + const std::vector api_usages = { + "SBAttachInfo.SetScriptedProcessClassName", + "SBAttachInfo.SetScriptedProcessDictionary", + "SBTarget.Attach", + "SBLaunchInfo.SetScriptedProcessClassName", + "SBLaunchInfo.SetScriptedProcessDictionary", + "SBTarget.Launch"}; + PluginManager::RegisterPlugin( + GetPluginNameStatic(), llvm::StringRef("Mock process state"), + CreateInstance, eScriptLanguagePython, {ci_usages, api_usages}); +} + +void ScriptedProcessPythonInterface::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); +} + #endif diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h similarity index 88% rename from lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h rename to lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h index c75caa9340f250..bb27734739f43a 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h @@ -10,16 +10,18 @@ #define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPROCESSPYTHONINTERFACE_H #include "lldb/Host/Config.h" +#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h" #if LLDB_ENABLE_PYTHON -#include "ScriptedPythonInterface.h" -#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h" +#include "../ScriptedPythonInterface.h" + #include namespace lldb_private { class ScriptedProcessPythonInterface : public ScriptedProcessInterface, - public ScriptedPythonInterface { + public ScriptedPythonInterface, + public PluginInterface { public: ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter); @@ -67,6 +69,16 @@ class ScriptedProcessPythonInterface : public ScriptedProcessInterface, StructuredData::DictionarySP GetMetadata() override; + static void Initialize(); + + static void Terminate(); + + static llvm::StringRef GetPluginNameStatic() { + return "ScriptedProcessPythonInterface"; + } + + llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } + private: lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override; }; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index d34fdf14122f26..a78c76b5f94ff7 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -16,7 +16,7 @@ #include "Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.h" #include "Interfaces/ScriptedPlatformPythonInterface/ScriptedPlatformPythonInterface.h" -#include "Interfaces/ScriptedProcessPythonInterface.h" +#include "Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h" #include "Interfaces/ScriptedThreadPlanPythonInterface/ScriptedThreadPlanPythonInterface.h" #include "PythonDataObjects.h" #include "PythonReadline.h"