[Lldb-commits] [lldb] [lldb] Unifying Scripted Affordance Interfaces (wip) (PR #68052)
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 23 17:14:21 PDT 2023
https://github.com/medismailben updated https://github.com/llvm/llvm-project/pull/68052
>From cd6c231c27d60e92549365422224f8758c945e5a Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <ismail at bennani.ma>
Date: Mon, 23 Oct 2023 15:08:19 -0700
Subject: [PATCH] [lldb/Interpreter] Make ScriptedInterface Object creation
more generic
This patch changes the way plugin objects used with Scripted Interfaces
are created.
Instead of implementing a different SWIG method to create the object for
every scripted interface, this patch makes the creation more generic by
re-using some of the ScriptedPythonInterface templated Dispatch code.
This patch also improves error handling of the object creation by
returning an `llvm::Expected`.
Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>
---
lldb/bindings/python/python-wrapper.swig | 43 ---------
.../Interfaces/ScriptedInterface.h | 5 -
.../Interfaces/ScriptedPlatformInterface.h | 6 +-
.../Interfaces/ScriptedProcessInterface.h | 6 +-
.../Interfaces/ScriptedThreadInterface.h | 6 +-
.../Process/scripted/ScriptedProcess.cpp | 9 +-
.../Process/scripted/ScriptedThread.cpp | 13 ++-
.../ScriptedPlatformPythonInterface.cpp | 26 ++----
.../ScriptedPlatformPythonInterface.h | 2 +-
.../ScriptedProcessPythonInterface.cpp | 26 ++----
.../ScriptedProcessPythonInterface.h | 2 +-
.../Interfaces/ScriptedPythonInterface.h | 92 ++++++++++++++++++-
.../ScriptedThreadPythonInterface.cpp | 36 ++------
.../ScriptedThreadPythonInterface.h | 2 +-
.../Python/SWIGPythonBridge.h | 6 --
.../Python/PythonTestSuite.cpp | 18 ++--
16 files changed, 145 insertions(+), 153 deletions(-)
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index cb54901e66d03c6..17bc7b1f2198709 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -229,49 +229,6 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateCommandObject
return pfunc(SWIGBridge::ToSWIGWrapper(std::move(debugger_sp)), dict);
}
-PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedObject(
- const char *python_class_name, const char *session_dictionary_name,
- lldb::ExecutionContextRefSP exe_ctx_sp,
- const lldb_private::StructuredDataImpl &args_impl,
- std::string &error_string) {
- if (python_class_name == NULL || python_class_name[0] == '\0' ||
- !session_dictionary_name)
- return PythonObject();
-
- PyErr_Cleaner py_err_cleaner(true);
-
- auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
- session_dictionary_name);
- auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(
- python_class_name, dict);
-
- if (!pfunc.IsAllocated()) {
- error_string.append("could not find script class: ");
- error_string.append(python_class_name);
- return PythonObject();
- }
-
- llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
- if (!arg_info) {
- llvm::handleAllErrors(
- arg_info.takeError(),
- [&](PythonException &E) { error_string.append(E.ReadBacktrace()); },
- [&](const llvm::ErrorInfoBase &E) {
- error_string.append(E.message());
- });
- return PythonObject();
- }
-
- PythonObject result = {};
- if (arg_info.get().max_positional_args == 2) {
- result = pfunc(SWIGBridge::ToSWIGWrapper(exe_ctx_sp), SWIGBridge::ToSWIGWrapper(args_impl));
- } else {
- error_string.assign("wrong number of arguments in __init__, should be 2 "
- "(not including self)");
- }
- return result;
-}
-
PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedThreadPlan(
const char *python_class_name, const char *session_dictionary_name,
const lldb_private::StructuredDataImpl &args_impl,
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 948f763e95ecea4..2406f0f1f9aee27 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -25,11 +25,6 @@ class ScriptedInterface {
ScriptedInterface() = default;
virtual ~ScriptedInterface() = default;
- virtual StructuredData::GenericSP
- CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
- StructuredData::DictionarySP args_sp,
- StructuredData::Generic *script_obj = nullptr) = 0;
-
StructuredData::GenericSP GetScriptObjectInstance() {
return m_object_instance_sp;
}
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
index c687cabfe0c1278..a361d713cca8ac1 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
@@ -19,11 +19,11 @@
namespace lldb_private {
class ScriptedPlatformInterface : virtual public ScriptedInterface {
public:
- StructuredData::GenericSP
+ virtual llvm::Expected<StructuredData::GenericSP>
CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
- StructuredData::Generic *script_obj = nullptr) override {
- return {};
+ StructuredData::Generic *script_obj = nullptr) {
+ llvm_unreachable("unimplemented!");
}
virtual StructuredData::DictionarySP ListProcesses() { return {}; }
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h
index 68756c4d9ac858d..cbbfa83f70ff68f 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h
@@ -21,11 +21,11 @@
namespace lldb_private {
class ScriptedProcessInterface : virtual public ScriptedInterface {
public:
- StructuredData::GenericSP
+ virtual llvm::Expected<StructuredData::GenericSP>
CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
- StructuredData::Generic *script_obj = nullptr) override {
- return {};
+ StructuredData::Generic *script_obj = nullptr) {
+ llvm_unreachable("unimplemented!");
}
virtual StructuredData::DictionarySP GetCapabilities() { return {}; }
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h
index 781df51a213229a..75ec4e45bc5436a 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h
@@ -20,11 +20,11 @@
namespace lldb_private {
class ScriptedThreadInterface : virtual public ScriptedInterface {
public:
- StructuredData::GenericSP
+ virtual llvm::Expected<StructuredData::GenericSP>
CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
- StructuredData::Generic *script_obj = nullptr) override {
- return {};
+ StructuredData::Generic *script_obj = nullptr) {
+ llvm_unreachable("unimplemented!");
}
virtual lldb::tid_t GetThreadID() { return LLDB_INVALID_THREAD_ID; }
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index e99a2a08bd50d8f..e0e6693399dec3a 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -108,10 +108,17 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
ExecutionContext exe_ctx(target_sp, /*get_process=*/false);
// Create process script object
- StructuredData::GenericSP object_sp = GetInterface().CreatePluginObject(
+ auto obj_or_err = GetInterface().CreatePluginObject(
m_scripted_metadata.GetClassName(), exe_ctx,
m_scripted_metadata.GetArgsSP());
+ if (!obj_or_err) {
+ error.SetErrorString("Failed to create script object.");
+ return;
+ }
+
+ StructuredData::GenericSP object_sp = *obj_or_err;
+
if (!object_sp || !object_sp->IsValid()) {
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
__FUNCTION__,
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index 684375957d24760..362a6e2674b19f9 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -56,14 +56,17 @@ ScriptedThread::Create(ScriptedProcess &process,
}
ExecutionContext exe_ctx(process);
- StructuredData::GenericSP owned_script_object_sp =
- scripted_thread_interface->CreatePluginObject(
- thread_class_name, exe_ctx, process.m_scripted_metadata.GetArgsSP(),
- script_object);
+ auto obj_or_err = scripted_thread_interface->CreatePluginObject(
+ thread_class_name, exe_ctx, process.m_scripted_metadata.GetArgsSP(),
+ script_object);
- if (!owned_script_object_sp)
+ if (!obj_or_err) {
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Failed to create script object.");
+ }
+
+ StructuredData::GenericSP owned_script_object_sp = *obj_or_err;
+
if (!owned_script_object_sp->IsValid())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Created script object is invalid.");
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp
index 9bed33516915d08..9ba4731032bd354 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp
@@ -29,29 +29,15 @@ ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
-StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
+llvm::Expected<StructuredData::GenericSP>
+ScriptedPlatformPythonInterface::CreatePluginObject(
llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
- if (class_name.empty())
- return {};
-
- StructuredDataImpl args_impl(args_sp);
- std::string error_string;
-
- Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
- Locker::FreeLock);
-
- lldb::ExecutionContextRefSP exe_ctx_ref_sp =
+ ExecutionContextRefSP exe_ctx_ref_sp =
std::make_shared<ExecutionContextRef>(exe_ctx);
-
- PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedObject(
- class_name.str().c_str(), m_interpreter.GetDictionaryName(),
- exe_ctx_ref_sp, args_impl, error_string);
-
- m_object_instance_sp =
- StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
-
- return m_object_instance_sp;
+ StructuredDataImpl sd_impl(args_sp);
+ return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
+ exe_ctx_ref_sp, sd_impl);
}
StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
index 02deecd15ede062..e04f2d02ab1d120 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
@@ -22,7 +22,7 @@ class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
public:
ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);
- StructuredData::GenericSP
+ llvm::Expected<StructuredData::GenericSP>
CreatePluginObject(const llvm::StringRef class_name,
ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
index 63a4db1ff5973e7..e86b34d6b930e4e 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
@@ -33,29 +33,15 @@ ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedProcessInterface(), ScriptedPythonInterface(interpreter) {}
-StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject(
+llvm::Expected<StructuredData::GenericSP>
+ScriptedProcessPythonInterface::CreatePluginObject(
llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
- if (class_name.empty())
- return {};
-
- StructuredDataImpl args_impl(args_sp);
- std::string error_string;
-
- Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
- Locker::FreeLock);
-
- lldb::ExecutionContextRefSP exe_ctx_ref_sp =
+ ExecutionContextRefSP exe_ctx_ref_sp =
std::make_shared<ExecutionContextRef>(exe_ctx);
-
- PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedObject(
- class_name.str().c_str(), m_interpreter.GetDictionaryName(),
- exe_ctx_ref_sp, args_impl, error_string);
-
- m_object_instance_sp =
- StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
-
- return m_object_instance_sp;
+ StructuredDataImpl sd_impl(args_sp);
+ return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
+ exe_ctx_ref_sp, sd_impl);
}
StructuredData::DictionarySP ScriptedProcessPythonInterface::GetCapabilities() {
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
index 11330f5591b74e6..f3cff619f6624f0 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
@@ -23,7 +23,7 @@ class ScriptedProcessPythonInterface : public ScriptedProcessInterface,
public:
ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter);
- StructuredData::GenericSP
+ llvm::Expected<StructuredData::GenericSP>
CreatePluginObject(const llvm::StringRef class_name,
ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index 9163b8f6aede7d1..f5e1a06830680bc 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -32,6 +32,84 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter);
~ScriptedPythonInterface() override = default;
+ template <typename... Args>
+ llvm::Expected<StructuredData::GenericSP>
+ CreatePluginObject(llvm::StringRef class_name,
+ StructuredData::Generic *script_obj, Args... args) {
+ using namespace python;
+ using Locker = ScriptInterpreterPythonImpl::Locker;
+
+ std::string error_string;
+ if (class_name.empty() &&
+ llvm::StringRef(m_interpreter.GetDictionaryName()).empty() &&
+ !script_obj)
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "ScriptedPythonInterface::CreatePluginObject - missing script class "
+ "name, dictionary or object.");
+
+ Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+ PythonObject result = {};
+
+ if (!script_obj) {
+ auto dict =
+ PythonModule::MainModule().ResolveName<python::PythonDictionary>(
+ m_interpreter.GetDictionaryName());
+ auto pfunc =
+ PythonObject::ResolveNameWithDictionary<python::PythonCallable>(
+ class_name, dict);
+
+ if (!pfunc.IsAllocated()) {
+ error_string.append("Could not find script class: ");
+ error_string.append(class_name);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ error_string);
+ }
+
+ std::tuple<Args...> original_args = std::forward_as_tuple(args...);
+ auto transformed_args = TransformArgs(original_args);
+
+ llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
+ if (!arg_info) {
+ llvm::handleAllErrors(
+ arg_info.takeError(),
+ [&](PythonException &E) { error_string.append(E.ReadBacktrace()); },
+ [&](const llvm::ErrorInfoBase &E) {
+ error_string.append(E.message());
+ });
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ error_string);
+ }
+
+ llvm::Expected<PythonObject> expected_return_object =
+ llvm::make_error<llvm::StringError>("Not initialized.",
+ llvm::inconvertibleErrorCode());
+
+ std::apply(
+ [&pfunc, &expected_return_object](auto &&...args) {
+ llvm::consumeError(expected_return_object.takeError());
+ expected_return_object = pfunc(args...);
+ },
+ transformed_args);
+
+ if (llvm::Error e = expected_return_object.takeError())
+ return e;
+ result = std::move(expected_return_object.get());
+ } else
+ result = PythonObject(PyRefType::Borrowed,
+ static_cast<PyObject *>(script_obj->GetValue()));
+
+ if (!result.IsValid())
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "python object result is invalid.");
+
+ m_object_instance_sp = StructuredData::GenericSP(
+ new StructuredPythonObject(std::move(result)));
+ return m_object_instance_sp;
+ }
+
protected:
template <typename T = StructuredData::ObjectSP>
T ExtractValueFromPythonObject(python::PythonObject &p, Status &error) {
@@ -83,10 +161,6 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
PythonObject py_return = std::move(expected_return_object.get());
- if (!py_return.IsAllocated())
- return ErrorWithMessage<T>(caller_signature, "Returned object is null.",
- error);
-
// Now that we called the python method with the transformed arguments,
// we need to interate again over both the original and transformed
// parameter pack, and transform back the parameter that were passed in
@@ -97,6 +171,8 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
caller_signature,
"Couldn't re-assign reference and pointer arguments.", error);
+ if (!py_return.IsAllocated())
+ return {};
return ExtractValueFromPythonObject<T>(py_return, error);
}
@@ -122,6 +198,14 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
return python::SWIGBridge::ToSWIGWrapper(arg);
}
+ python::PythonObject Transform(const StructuredDataImpl &arg) {
+ return python::SWIGBridge::ToSWIGWrapper(arg);
+ }
+
+ python::PythonObject Transform(lldb::ExecutionContextRefSP arg) {
+ return python::SWIGBridge::ToSWIGWrapper(arg);
+ }
+
python::PythonObject Transform(lldb::ProcessAttachInfoSP arg) {
return python::SWIGBridge::ToSWIGWrapper(arg);
}
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp
index 6addcd46e045efc..18e268527eb2fb5 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp
@@ -29,37 +29,15 @@ ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
-StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(
+llvm::Expected<StructuredData::GenericSP>
+ScriptedThreadPythonInterface::CreatePluginObject(
const llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
- if (class_name.empty() && !script_obj)
- return {};
-
- StructuredDataImpl args_impl(args_sp);
- std::string error_string;
-
- Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
- Locker::FreeLock);
-
- PythonObject ret_val;
-
- if (!script_obj) {
- lldb::ExecutionContextRefSP exe_ctx_ref_sp =
- std::make_shared<ExecutionContextRef>(exe_ctx);
- ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedObject(
- class_name.str().c_str(), m_interpreter.GetDictionaryName(),
- exe_ctx_ref_sp, args_impl, error_string);
- } else
- ret_val = PythonObject(PyRefType::Borrowed,
- static_cast<PyObject *>(script_obj->GetValue()));
-
- if (!ret_val)
- return {};
-
- m_object_instance_sp =
- StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
-
- return m_object_instance_sp;
+ ExecutionContextRefSP exe_ctx_ref_sp =
+ std::make_shared<ExecutionContextRef>(exe_ctx);
+ StructuredDataImpl sd_impl(args_sp);
+ return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
+ exe_ctx_ref_sp, sd_impl);
}
lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h
index b63760fd5b5713d..b7b7439461a03d6 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h
@@ -23,7 +23,7 @@ class ScriptedThreadPythonInterface : public ScriptedThreadInterface,
public:
ScriptedThreadPythonInterface(ScriptInterpreterPythonImpl &interpreter);
- StructuredData::GenericSP
+ llvm::Expected<StructuredData::GenericSP>
CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
StructuredData::Generic *script_obj = nullptr) override;
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
index 630ab293cf939ea..7cdd5577919ba8d 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
@@ -116,12 +116,6 @@ class SWIGBridge {
// callbacks. Although these are scripting-language specific, their definition
// depends on the public API.
- static python::PythonObject LLDBSwigPythonCreateScriptedObject(
- const char *python_class_name, const char *session_dictionary_name,
- lldb::ExecutionContextRefSP exe_ctx_sp,
- const lldb_private::StructuredDataImpl &args_impl,
- std::string &error_string);
-
static llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction(
const char *python_function_name, const char *session_dictionary_name,
const lldb::StackFrameSP &sb_frame,
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
index 14fe69fe70a3fa8..9dd845f435a07e3 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -231,14 +231,6 @@ lldb_private::python::SWIGBridge::LLDBSWIGPythonCreateOSPlugin(
return python::PythonObject();
}
-python::PythonObject
-lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedObject(
- const char *python_class_name, const char *session_dictionary_name,
- lldb::ExecutionContextRefSP exe_ctx_sp, const StructuredDataImpl &args_impl,
- std::string &error_string) {
- return python::PythonObject();
-}
-
python::PythonObject
lldb_private::python::SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer(
const char *python_class_name, const char *session_dictionary_name) {
@@ -321,3 +313,13 @@ python::PythonObject
lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::DataExtractorSP) {
return python::PythonObject();
}
+
+python::PythonObject
+lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ExecutionContextRefSP) {
+ return python::PythonObject();
+}
+
+python::PythonObject
+lldb_private::python::SWIGBridge::ToSWIGWrapper(const StructuredDataImpl &) {
+ return python::PythonObject();
+}
More information about the lldb-commits
mailing list