[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)
via lldb-commits
lldb-commits at lists.llvm.org
Sun Jul 21 09:57:47 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Med Ismail Bennani (medismailben)
<details>
<summary>Changes</summary>
This patch introduces Scripted Platform, a new platform plugin that can be customized with a python script.
For now this can list processes described in the python script file but eventually, it will be used to spawn scripted processes and act as an interface between them.
This patch is also a less intrusive implementation of 2d53527.
It introduces a new PlatformMetadata held by every platform that contains various objects that might be used by a platform instance.
In its current form, the PlatformMetadata holds a reference to the Debugger and a ScriptedMetadata pointer. These are necessary in other to instanciate the scripted object that the ScriptedPlatform interacts with.
In order to make it less introsive with the rest of lldb's platform creation code, platform metadata are set after the platform creation, and requires to platform to reload them (using `Platform::ReloadMetadata`).
This approach has the tradeoff that the ScriptedPlaform instance is technically invalid and useless right after its creation. However, the user should never be in that situation, since we reload the platform metadata everytime with create or select the platform.
This work was previously reviewed in:
- https://reviews.llvm.org/D139252
- https://reviews.llvm.org/D142266
---
Patch is 46.91 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/99814.diff
35 Files Affected:
- (modified) lldb/bindings/interface/SBPlatformDocstrings.i (+12)
- (modified) lldb/bindings/python/python-swigsafecast.swig (+10)
- (modified) lldb/bindings/python/python-wrapper.swig (+36)
- (modified) lldb/examples/python/templates/scripted_platform.py (+8-5)
- (modified) lldb/include/lldb/API/SBDebugger.h (+2)
- (modified) lldb/include/lldb/API/SBPlatform.h (+3-1)
- (modified) lldb/include/lldb/API/SBProcess.h (+2)
- (modified) lldb/include/lldb/API/SBStructuredData.h (+1)
- (modified) lldb/include/lldb/API/SBTarget.h (+2)
- (modified) lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h (+5-2)
- (modified) lldb/include/lldb/Interpreter/OptionGroupPlatform.h (+8-2)
- (modified) lldb/include/lldb/Interpreter/ScriptInterpreter.h (+15-4)
- (modified) lldb/include/lldb/Target/Platform.h (+22)
- (modified) lldb/include/lldb/Utility/ScriptedMetadata.h (+2-2)
- (modified) lldb/source/API/SBPlatform.cpp (+31)
- (modified) lldb/source/Commands/CommandObjectPlatform.cpp (+15-2)
- (modified) lldb/source/Commands/CommandObjectPlatform.h (+1)
- (modified) lldb/source/Interpreter/ScriptInterpreter.cpp (+15)
- (modified) lldb/source/Plugins/Platform/CMakeLists.txt (+1)
- (added) lldb/source/Plugins/Platform/scripted/CMakeLists.txt (+8)
- (added) lldb/source/Plugins/Platform/scripted/ScriptedPlatform.cpp (+288)
- (added) lldb/source/Plugins/Platform/scripted/ScriptedPlatform.h (+84)
- (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.h (+1-1)
- (modified) lldb/source/Plugins/Process/scripted/ScriptedThread.cpp (-5)
- (modified) lldb/source/Plugins/Process/scripted/ScriptedThread.h (+5-1)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp (+20-7)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h (+4-1)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp (+45)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h (+23)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h (+3)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+5)
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h (+2)
- (modified) lldb/source/Target/Platform.cpp (+9-1)
- (modified) lldb/test/API/functionalities/scripted_platform/my_scripted_platform.py (+3)
- (modified) lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (+15)
``````````diff
diff --git a/lldb/bindings/interface/SBPlatformDocstrings.i b/lldb/bindings/interface/SBPlatformDocstrings.i
index ef09d5bce13fd..b8cdf21e90f82 100644
--- a/lldb/bindings/interface/SBPlatformDocstrings.i
+++ b/lldb/bindings/interface/SBPlatformDocstrings.i
@@ -29,3 +29,15 @@ and executable type. If the architecture or executable type do not match,
a suitable platform will be found automatically."
) lldb::SBPlatform;
+
+%feature("docstring", "
+Create a platform instance using a specific platform plugin name, debugger,
+script name and user-provided dictionary.
+
+:param platform_name: name of the platform plugin to use to create the platform
+:param debugger: debugger instance owning the platform
+:param script_name: name of the script class and module to use to create the platform
+:param dict: user-provided dictionary that can be used when instanciating a platform
+") lldb::SBPlatform (const char *, const lldb::SBDebugger&,
+ const char *, const lldb::SBStructuredData&);
+
diff --git a/lldb/bindings/python/python-swigsafecast.swig b/lldb/bindings/python/python-swigsafecast.swig
index 34f8c6f0ff8d3..f006101c4ce2d 100644
--- a/lldb/bindings/python/python-swigsafecast.swig
+++ b/lldb/bindings/python/python-swigsafecast.swig
@@ -104,6 +104,16 @@ PythonObject SWIGBridge::ToSWIGWrapper(lldb::DataExtractorSP data_sp) {
SWIGTYPE_p_lldb__SBData);
}
+PythonObject ToSWIGWrapper(lldb::ProcessLaunchInfoSP launch_info_sp) {
+ return ToSWIGHelper(new lldb::ProcessLaunchInfoSP(std::move(launch_info_sp)),
+ SWIGTYPE_p_lldb__SBLaunchInfo);
+}
+
+PythonObject ToSWIGWrapper(lldb::ProcessAttachInfoSP attach_info_sp) {
+ return ToSWIGHelper(new lldb::ProcessAttachInfoSP(std::move(attach_info_sp)),
+ SWIGTYPE_p_lldb__SBAttachInfo);
+}
+
ScopedPythonObject<lldb::SBCommandReturnObject>
SWIGBridge::ToSWIGWrapper(CommandReturnObject &cmd_retobj) {
return ScopedPythonObject<lldb::SBCommandReturnObject>(
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index 8f050643fa68b..24dafc7b3fcd8 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -675,6 +675,42 @@ void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyOb
return sb_ptr;
}
+void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBDebugger(PyObject * data) {
+ lldb::SBDebugger *sb_ptr = nullptr;
+
+ int valid_cast =
+ SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBDebugger, 0);
+
+ if (valid_cast == -1)
+ return NULL;
+
+ return sb_ptr;
+}
+
+void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBTarget(PyObject * data) {
+ lldb::SBTarget *sb_ptr = nullptr;
+
+ int valid_cast =
+ SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBTarget, 0);
+
+ if (valid_cast == -1)
+ return NULL;
+
+ return sb_ptr;
+}
+
+void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBProcess(PyObject * data) {
+ lldb::SBProcess *sb_ptr = nullptr;
+
+ int valid_cast =
+ SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBProcess, 0);
+
+ if (valid_cast == -1)
+ return NULL;
+
+ return sb_ptr;
+}
+
bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommand(
const char *python_function_name, const char *session_dictionary_name,
lldb::DebuggerSP debugger, const char *args,
diff --git a/lldb/examples/python/templates/scripted_platform.py b/lldb/examples/python/templates/scripted_platform.py
index 5805f99dea4ca..23073d4981ea5 100644
--- a/lldb/examples/python/templates/scripted_platform.py
+++ b/lldb/examples/python/templates/scripted_platform.py
@@ -60,14 +60,17 @@ def get_process_info(self, pid):
pass
@abstractmethod
- def attach_to_process(self, attach_info):
- """Attach to a process.
-
+ def attach_to_process(self, attach_info, target, debugger, error):
+ """ Attach to a process.
+
Args:
attach_info (lldb.SBAttachInfo): The information related to attach to a process.
-
+ target (lldb.SBTarget): The optional target that we are trying to attach to.
+ debugger (lldb.SBDebugger): The debugger instance.
+ error (lldb.SBError): A status object notifying if the attach succeeded.
+
Returns:
- lldb.SBError: A status object notifying if the attach succeeded.
+ lldb.SBProcess: The process that the platform attached to, or None.
"""
pass
diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h
index 84ea9c0f772e1..6cf95698bdb52 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -16,6 +16,7 @@
namespace lldb_private {
class CommandPluginInterfaceImplementation;
+class ScriptInterpreter;
namespace python {
class SWIGBridge;
}
@@ -492,6 +493,7 @@ class LLDB_API SBDebugger {
protected:
friend class lldb_private::CommandPluginInterfaceImplementation;
+ friend class lldb_private::ScriptInterpreter;
friend class lldb_private::python::SWIGBridge;
SBDebugger(const lldb::DebuggerSP &debugger_sp);
diff --git a/lldb/include/lldb/API/SBPlatform.h b/lldb/include/lldb/API/SBPlatform.h
index d63d2ed1eaba6..e6e990b08894c 100644
--- a/lldb/include/lldb/API/SBPlatform.h
+++ b/lldb/include/lldb/API/SBPlatform.h
@@ -17,7 +17,6 @@
struct PlatformConnectOptions;
struct PlatformShellCommand;
-class ProcessInstanceInfoMatch;
namespace lldb {
@@ -100,6 +99,9 @@ class LLDB_API SBPlatform {
SBPlatform(const char *platform_name);
+ SBPlatform(const char *platform_name, const SBDebugger &debugger,
+ const char *script_name, const SBStructuredData &dict);
+
SBPlatform(const SBPlatform &rhs);
SBPlatform &operator=(const SBPlatform &rhs);
diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h
index 778be79583990..dca16748714dd 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -17,6 +17,7 @@
#include <cstdio>
namespace lldb_private {
+class ScriptInterpreter;
namespace python {
class SWIGBridge;
}
@@ -597,6 +598,7 @@ class LLDB_API SBProcess {
friend class lldb_private::QueueImpl;
friend class lldb_private::python::SWIGBridge;
+ friend class lldb_private::ScriptInterpreter;
SBProcess(const lldb::ProcessSP &process_sp);
diff --git a/lldb/include/lldb/API/SBStructuredData.h b/lldb/include/lldb/API/SBStructuredData.h
index fc6e1ec95c7b8..94f41fdae3f42 100644
--- a/lldb/include/lldb/API/SBStructuredData.h
+++ b/lldb/include/lldb/API/SBStructuredData.h
@@ -111,6 +111,7 @@ class SBStructuredData {
protected:
friend class SBAttachInfo;
friend class SBLaunchInfo;
+ friend class SBPlatform;
friend class SBDebugger;
friend class SBTarget;
friend class SBProcess;
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 35c2ed9c20a23..038c7586dffe1 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -25,6 +25,7 @@
#include "lldb/API/SBWatchpointOptions.h"
namespace lldb_private {
+class ScriptInterpreter;
namespace python {
class SWIGBridge;
}
@@ -964,6 +965,7 @@ class LLDB_API SBTarget {
friend class SBVariablesOptions;
friend class lldb_private::python::SWIGBridge;
+ friend class lldb_private::ScriptInterpreter;
// Constructors are private, use static Target::Create function to create an
// instance of this class.
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
index 7feaa01fe89b8..4030196cc6f15 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
@@ -30,8 +30,11 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface {
return {};
}
- virtual Status AttachToProcess(lldb::ProcessAttachInfoSP attach_info) {
- return Status("ScriptedPlatformInterface cannot attach to a process");
+ virtual lldb::ProcessSP
+ AttachToProcess(lldb::ProcessAttachInfoSP attach_info_sp,
+ lldb::TargetSP target_sp, lldb::DebuggerSP debugger_sp,
+ Status &error) {
+ return {};
}
virtual Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) {
diff --git a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h
index 2ffd44f0035de..410b6bafe9af4 100644
--- a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h
+++ b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h
@@ -9,19 +9,20 @@
#ifndef LLDB_INTERPRETER_OPTIONGROUPPLATFORM_H
#define LLDB_INTERPRETER_OPTIONGROUPPLATFORM_H
+#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Utility/ConstString.h"
#include "llvm/Support/VersionTuple.h"
namespace lldb_private {
-
// PlatformOptionGroup
//
// Make platform options available to any commands that need the settings.
class OptionGroupPlatform : public OptionGroup {
public:
OptionGroupPlatform(bool include_platform_option)
- : m_include_platform_option(include_platform_option) {}
+ : m_include_platform_option(include_platform_option),
+ m_class_options("scripted platform", true, 'C', 'K', 'V', 0) {}
~OptionGroupPlatform() override = default;
@@ -61,12 +62,17 @@ class OptionGroupPlatform : public OptionGroup {
bool PlatformMatches(const lldb::PlatformSP &platform_sp) const;
+ OptionGroupPythonClassWithDict &GetScriptClassOptions() {
+ return m_class_options;
+ }
+
protected:
std::string m_platform_name;
std::string m_sdk_sysroot;
std::string m_sdk_build;
llvm::VersionTuple m_os_version;
bool m_include_platform_option;
+ OptionGroupPythonClassWithDict m_class_options;
};
} // namespace lldb_private
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 05f0d7f0955f3..f970cc2b97c81 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -12,11 +12,14 @@
#include "lldb/API/SBAttachInfo.h"
#include "lldb/API/SBBreakpoint.h"
#include "lldb/API/SBData.h"
+#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBError.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBLaunchInfo.h"
#include "lldb/API/SBMemoryRegionInfo.h"
+#include "lldb/API/SBProcess.h"
#include "lldb/API/SBStream.h"
+#include "lldb/API/SBTarget.h"
#include "lldb/Breakpoint/BreakpointOptions.h"
#include "lldb/Core/PluginInterface.h"
#include "lldb/Core/SearchFilter.h"
@@ -548,6 +551,10 @@ class ScriptInterpreter : public PluginInterface {
lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
+ virtual lldb::ScriptedPlatformInterfaceUP CreateScriptedPlatformInterface() {
+ return {};
+ }
+
virtual lldb::ScriptedProcessInterfaceUP CreateScriptedProcessInterface() {
return {};
}
@@ -565,10 +572,6 @@ class ScriptInterpreter : public PluginInterface {
return {};
}
- virtual lldb::ScriptedPlatformInterfaceUP GetScriptedPlatformInterface() {
- return {};
- }
-
virtual StructuredData::ObjectSP
CreateStructuredDataFromScriptObject(ScriptObject obj) {
return {};
@@ -586,6 +589,14 @@ class ScriptInterpreter : public PluginInterface {
lldb::BreakpointSP
GetOpaqueTypeFromSBBreakpoint(const lldb::SBBreakpoint &breakpoint) const;
+ lldb::DebuggerSP
+ GetOpaqueTypeFromSBDebugger(const lldb::SBDebugger &debugger) const;
+
+ lldb::TargetSP GetOpaqueTypeFromSBTarget(const lldb::SBTarget &target) const;
+
+ lldb::ProcessSP
+ GetOpaqueTypeFromSBProcess(const lldb::SBProcess &process) const;
+
lldb::ProcessAttachInfoSP
GetOpaqueTypeFromSBAttachInfo(const lldb::SBAttachInfo &attach_info) const;
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 5ed2fc33356d9..60252be9bcbcc 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -24,6 +24,7 @@
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/ScriptedMetadata.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/Timeout.h"
#include "lldb/Utility/UserIDResolver.h"
@@ -35,6 +36,7 @@
namespace lldb_private {
+class PlatformMetadata;
class ProcessInstanceInfo;
class ProcessInstanceInfoMatch;
typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
@@ -632,6 +634,10 @@ class Platform : public PluginInterface {
virtual const char *GetLocalCacheDirectory();
+ void SetMetadata(std::unique_ptr<PlatformMetadata> metadata);
+
+ virtual bool ReloadMetadata() { return true; }
+
virtual std::string GetPlatformSpecificConnectionInformation() { return ""; }
virtual llvm::ErrorOr<llvm::MD5::MD5Result>
@@ -962,6 +968,7 @@ class Platform : public PluginInterface {
bool m_calculated_trap_handlers;
const std::unique_ptr<ModuleCache> m_module_cache;
LocateModuleCallback m_locate_module_callback;
+ std::unique_ptr<PlatformMetadata> m_metadata;
/// Ask the Platform subclass to fill in the list of trap handler names
///
@@ -1003,6 +1010,21 @@ class Platform : public PluginInterface {
FileSpec GetModuleCacheRoot();
};
+class PlatformMetadata {
+public:
+ PlatformMetadata(Debugger &debugger, const ScriptedMetadata metadata);
+ ~PlatformMetadata() = default;
+
+ Debugger &GetDebugger() const { return m_debugger; }
+ const ScriptedMetadata GetScriptedMetadata() const {
+ return m_scripted_metadata;
+ }
+
+protected:
+ Debugger &m_debugger;
+ const ScriptedMetadata m_scripted_metadata;
+};
+
class PlatformList {
public:
PlatformList() = default;
diff --git a/lldb/include/lldb/Utility/ScriptedMetadata.h b/lldb/include/lldb/Utility/ScriptedMetadata.h
index 69c83edce909a..3990309080e87 100644
--- a/lldb/include/lldb/Utility/ScriptedMetadata.h
+++ b/lldb/include/lldb/Utility/ScriptedMetadata.h
@@ -15,8 +15,8 @@
namespace lldb_private {
class ScriptedMetadata {
public:
- ScriptedMetadata(llvm::StringRef class_name,
- StructuredData::DictionarySP dict_sp)
+ ScriptedMetadata(const llvm::StringRef class_name,
+ const StructuredData::DictionarySP dict_sp)
: m_class_name(class_name.data()), m_args_sp(dict_sp) {}
ScriptedMetadata(const ProcessInfo &process_info) {
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 3623fd35bcdf1..79cc0393fb548 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -15,6 +15,7 @@
#include "lldb/API/SBModuleSpec.h"
#include "lldb/API/SBPlatform.h"
#include "lldb/API/SBProcessInfoList.h"
+#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBTarget.h"
#include "lldb/API/SBUnixSignals.h"
#include "lldb/Host/File.h"
@@ -23,6 +24,7 @@
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/ScriptedMetadata.h"
#include "lldb/Utility/Status.h"
#include "llvm/Support/FileSystem.h"
@@ -299,6 +301,35 @@ SBPlatform::SBPlatform(const char *platform_name) {
m_opaque_sp = Platform::Create(platform_name);
}
+SBPlatform::SBPlatform(const char *platform_name, const SBDebugger &debugger,
+ const char *script_name, const SBStructuredData &dict)
+ : SBPlatform(platform_name) {
+ LLDB_INSTRUMENT_VA(this, platform_name, debugger, script_name, dict);
+
+ if (!m_opaque_sp)
+ return;
+
+ if (!script_name || !dict.IsValid() || !dict.m_impl_up)
+ return;
+
+ StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();
+
+ if (!obj_sp)
+ return;
+
+ StructuredData::DictionarySP dict_sp =
+ std::make_shared<StructuredData::Dictionary>(obj_sp);
+ if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
+ return;
+
+ const ScriptedMetadata scripted_metadata(script_name, dict_sp);
+
+ auto metadata =
+ std::make_unique<PlatformMetadata>(debugger.ref(), scripted_metadata);
+ m_opaque_sp->SetMetadata(std::move(metadata));
+ m_opaque_sp->ReloadMetadata();
+}
+
SBPlatform::SBPlatform(const SBPlatform &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 5b18f2b60e92d..4d2e7f8382744 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -154,8 +154,11 @@ class CommandObjectPlatformSelect : public CommandObjectParsed {
false) // Don't include the "--platform" option by passing false
{
m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1);
+ m_option_group.Append(&m_platform_options.GetScriptClassOptions(),
+ LLDB_OPT_SET_1 | LLDB_OPT_SET_2, LLDB_OPT_SET_ALL);
m_option_group.Finalize();
- AddSimpleArgumentList(eArgTypePlatform);
+ CommandArgumentData platform_arg{eArgTypePlatform, eArgRepeatPlain};
+ m_arguments.push_back({platform_arg});
}
~CommandObjectPlatformSelect() override = default;
@@ -180,7 +183,17 @@ class CommandObjectPlatformSelect : public CommandObjectParsed {
m_interpreter, ArchSpec(), select, error, platform_arch));
if (platform_sp) {
GetDebugger().GetPlatformList().SetSelectedPlatform(platform_sp);
-
+ OptionGroupPythonClassWithDict &script_class_opts =
+ m_platform_options.GetScriptClassOptions();
+ const ScriptedMetadata scripted_metadata(
+ script_class_opts.GetName(),
+ script_class_opts.GetStructuredData());
+
+ auto metadata = std::make_unique<PlatformMetadata>(GetDebugger(),
+ scripted_metadata);
+ platform_sp->SetMetadata(std::move(metadata));
+ if (!platform_sp->ReloadMetadata())
+ result.AppendError("platform couldn't reload metadata\n");
platform_sp->GetStatus(result.GetOutputStream());
result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
diff --git a/lldb/source/Commands/CommandObjectPlatform.h b/lldb/source/Commands/CommandObjectPlatform.h
index 86f55c7d9b085..a867be6a31e7a 100644
--- a/lldb/source/Commands/CommandObjectPlatform.h
+++ b/lldb/source/Commands/CommandObjectPlatform.h
@@ -10,6 +10,7 @@
#define LLDB_SOURCE_COMMANDS_COMMANDOBJECTPLATFORM_H
#include "lldb/Interpreter/CommandObjectMultiword.h"
+#include "lldb/Interpreter/OptionGroupPlatform.h"
namespace lldb_private {
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp
index fa23964a52ffe..ded146984f2b0 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -82,6 +82,21 @@ lldb::BreakpointSP ScriptInterpreter::GetOpaqueTypeFromSBBreakpoint(
return breakpoint.m_opaque_wp.lock();
}
+lldb::DebuggerSP ScriptInterpreter::GetOpaqueTypeFromSBDebugger(
+ const lldb::SBDebugger &debugger) const {
+ return debugger.m_opaque_sp;
+}
+
+lldb::TargetSP ScriptInterpreter::GetOpaqueTypeFromSBTarget(
+ const lldb::SBTarget &target) const {
+ return target.m_opaque_sp;
+}
+
+lldb::ProcessSP ScriptInterpreter::GetOpaqueTypeFromSBProcess(
+ const lldb::SBProcess &process) const {
+ return process.m_opaque_wp.lock();
+}
+
lldb::ProcessAttachInfoSP ScriptInterpreter::GetOpaqueTypeFromSBAttachInfo(
const lldb::SBAttachInfo &attach_info) const {
return attach_info.m_opaque_sp;
diff --git a/lldb/source/Plugins/Platform/CMakeLists.txt b/lldb/source/Plugins/Platform/CMakeLists.txt
index 6869587f917eb..094cc019a4821 100644
--- a/lldb/source/Plugins/Platform/CMakeLists.txt
+++ b/lldb/source/Plugins/Platform/CMakeLists.txt
@@ -7,4 +7,5 @@ add_subdirectory(NetBSD)
add_subdirectory(OpenBSD)
add_subdirectory(POSIX)
add_subdirectory(QemuUser)
+add_subdirectory(scripted)
add_subdirectory(Windows)
diff --git a/lldb/source/Plugins/Platform/scripted/CMakeLists.txt b/lldb/source/Plugins/Platform/scripted/CMakeLists.txt
new file mode 100644
index 0000000000000..96a38fdee14...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/99814
More information about the lldb-commits
mailing list