aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp82
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h48
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp)32
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h)16
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp)34
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h)15
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp)4
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h)223
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp)42
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h (renamed from contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h)15
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp20
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h2
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h6
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp211
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h18
15 files changed, 457 insertions, 311 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp
new file mode 100644
index 000000000000..c162c7367c65
--- /dev/null
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp
@@ -0,0 +1,82 @@
+//===-- ScriptedThreadPythonInterface.cpp ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/Config.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/lldb-enumerations.h"
+
+#if LLDB_ENABLE_PYTHON
+
+// LLDB Python header must be included first
+#include "../lldb-python.h"
+
+#include "../SWIGPythonBridge.h"
+#include "../ScriptInterpreterPythonImpl.h"
+#include "OperatingSystemPythonInterface.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::python;
+using Locker = ScriptInterpreterPythonImpl::Locker;
+
+OperatingSystemPythonInterface::OperatingSystemPythonInterface(
+ ScriptInterpreterPythonImpl &interpreter)
+ : OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {}
+
+llvm::Expected<StructuredData::GenericSP>
+OperatingSystemPythonInterface::CreatePluginObject(
+ llvm::StringRef class_name, ExecutionContext &exe_ctx,
+ StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
+ return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
+ exe_ctx.GetProcessSP());
+}
+
+StructuredData::DictionarySP
+OperatingSystemPythonInterface::CreateThread(lldb::tid_t tid,
+ lldb::addr_t context) {
+ Status error;
+ StructuredData::DictionarySP dict = Dispatch<StructuredData::DictionarySP>(
+ "create_thread", error, tid, context);
+
+ if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
+ error))
+ return {};
+
+ return dict;
+}
+
+StructuredData::ArraySP OperatingSystemPythonInterface::GetThreadInfo() {
+ Status error;
+ StructuredData::ArraySP arr =
+ Dispatch<StructuredData::ArraySP>("get_thread_info", error);
+
+ if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
+ error))
+ return {};
+
+ return arr;
+}
+
+StructuredData::DictionarySP OperatingSystemPythonInterface::GetRegisterInfo() {
+ return ScriptedThreadPythonInterface::GetRegisterInfo();
+}
+
+std::optional<std::string>
+OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
+ Status error;
+ StructuredData::ObjectSP obj = Dispatch("get_register_data", error, tid);
+
+ if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
+ error))
+ return {};
+
+ return obj->GetAsString()->GetValue().str();
+}
+
+#endif
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
new file mode 100644
index 000000000000..da7bbf13b1d5
--- /dev/null
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
@@ -0,0 +1,48 @@
+//===-- OperatingSystemPythonInterface.h ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "ScriptedThreadPythonInterface.h"
+#include "lldb/Interpreter/Interfaces/OperatingSystemInterface.h"
+#include <optional>
+
+namespace lldb_private {
+class OperatingSystemPythonInterface
+ : virtual public OperatingSystemInterface,
+ virtual public ScriptedThreadPythonInterface {
+public:
+ OperatingSystemPythonInterface(ScriptInterpreterPythonImpl &interpreter);
+
+ llvm::Expected<StructuredData::GenericSP>
+ CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
+ StructuredData::DictionarySP args_sp,
+ StructuredData::Generic *script_obj = nullptr) override;
+
+ llvm::SmallVector<llvm::StringLiteral> GetAbstractMethods() const override {
+ return llvm::SmallVector<llvm::StringLiteral>({"get_thread_info"});
+ }
+
+ StructuredData::DictionarySP CreateThread(lldb::tid_t tid,
+ lldb::addr_t context) override;
+
+ StructuredData::ArraySP GetThreadInfo() override;
+
+ StructuredData::DictionarySP GetRegisterInfo() override;
+
+ std::optional<std::string> GetRegisterContextForTID(lldb::tid_t tid) override;
+};
+} // namespace lldb_private
+
+#endif // LLDB_ENABLE_PYTHON
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp
index a0c55874c70a..9ba4731032bd 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp
@@ -14,10 +14,10 @@
#if LLDB_ENABLE_PYTHON
// LLDB Python header must be included first
-#include "lldb-python.h"
+#include "../lldb-python.h"
-#include "SWIGPythonBridge.h"
-#include "ScriptInterpreterPythonImpl.h"
+#include "../SWIGPythonBridge.h"
+#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedPlatformPythonInterface.h"
using namespace lldb;
@@ -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/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
index 1e3ad9962325..0842d3a00342 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
@@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
-#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPLATFORMPYTHONINTERFACE_H
#include "lldb/Host/Config.h"
#if LLDB_ENABLE_PYTHON
#include "ScriptedPythonInterface.h"
-#include "lldb/Interpreter/ScriptedPlatformInterface.h"
+#include "lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h"
namespace lldb_private {
class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
@@ -22,12 +22,18 @@ 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,
StructuredData::Generic *script_obj = nullptr) override;
+ llvm::SmallVector<llvm::StringLiteral> GetAbstractMethods() const override {
+ return llvm::SmallVector<llvm::StringLiteral>(
+ {"list_processes", "attach_to_process", "launch_process",
+ "kill_process"});
+ }
+
StructuredData::DictionarySP ListProcesses() override;
StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override;
@@ -41,4 +47,4 @@ public:
} // namespace lldb_private
#endif // LLDB_ENABLE_PYTHON
-#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPLATFORMPYTHONINTERFACE_H
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
index 019924fa1971..e86b34d6b930 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
@@ -9,7 +9,7 @@
#include "lldb/Host/Config.h"
#if LLDB_ENABLE_PYTHON
// LLDB Python header must be included first
-#include "lldb-python.h"
+#include "../lldb-python.h"
#endif
#include "lldb/Target/Process.h"
#include "lldb/Utility/Log.h"
@@ -18,8 +18,8 @@
#if LLDB_ENABLE_PYTHON
-#include "SWIGPythonBridge.h"
-#include "ScriptInterpreterPythonImpl.h"
+#include "../SWIGPythonBridge.h"
+#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedProcessPythonInterface.h"
#include "ScriptedThreadPythonInterface.h"
#include <optional>
@@ -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() {
@@ -199,7 +185,7 @@ ScriptedProcessPythonInterface::GetScriptedThreadPluginName() {
lldb::ScriptedThreadInterfaceSP
ScriptedProcessPythonInterface::CreateScriptedThreadInterface() {
- return std::make_shared<ScriptedThreadPythonInterface>(m_interpreter);
+ return m_interpreter.CreateScriptedThreadInterface();
}
StructuredData::DictionarySP ScriptedProcessPythonInterface::GetMetadata() {
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
index ff03eab07648..c75caa9340f2 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
@@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
-#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPROCESSPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPROCESSPYTHONINTERFACE_H
#include "lldb/Host/Config.h"
#if LLDB_ENABLE_PYTHON
#include "ScriptedPythonInterface.h"
-#include "lldb/Interpreter/ScriptedProcessInterface.h"
+#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h"
#include <optional>
namespace lldb_private {
@@ -23,12 +23,17 @@ 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,
StructuredData::Generic *script_obj = nullptr) override;
+ llvm::SmallVector<llvm::StringLiteral> GetAbstractMethods() const override {
+ return llvm::SmallVector<llvm::StringLiteral>(
+ {"read_memory_at_address", "is_alive", "get_scripted_thread_plugin"});
+ }
+
StructuredData::DictionarySP GetCapabilities() override;
Status Attach(const ProcessAttachInfo &attach_info) override;
@@ -68,4 +73,4 @@ private:
} // namespace lldb_private
#endif // LLDB_ENABLE_PYTHON
-#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPROCESSPYTHONINTERFACE_H
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
index 1e36a81fde54..6f22503b279c 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
@@ -13,9 +13,9 @@
#if LLDB_ENABLE_PYTHON
// LLDB Python header must be included first
-#include "lldb-python.h"
+#include "../lldb-python.h"
-#include "ScriptInterpreterPythonImpl.h"
+#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedPythonInterface.h"
#include <optional>
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index 4d0645d18aca..163659234466 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPYTHONINTERFACE_H
-#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPYTHONINTERFACE_H
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPYTHONINTERFACE_H
#if LLDB_ENABLE_PYTHON
@@ -18,12 +18,12 @@
#include <utility>
#include "lldb/Host/Config.h"
-#include "lldb/Interpreter/ScriptedInterface.h"
+#include "lldb/Interpreter/Interfaces/ScriptedInterface.h"
#include "lldb/Utility/DataBufferHeap.h"
-#include "PythonDataObjects.h"
-#include "SWIGPythonBridge.h"
-#include "ScriptInterpreterPythonImpl.h"
+#include "../PythonDataObjects.h"
+#include "../SWIGPythonBridge.h"
+#include "../ScriptInterpreterPythonImpl.h"
namespace lldb_private {
class ScriptInterpreterPythonImpl;
@@ -32,6 +32,196 @@ public:
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter);
~ScriptedPythonInterface() override = default;
+ enum class AbstractMethodCheckerCases {
+ eNotImplemented,
+ eNotAllocated,
+ eNotCallable,
+ eValid
+ };
+
+ llvm::Expected<std::map<llvm::StringLiteral, AbstractMethodCheckerCases>>
+ CheckAbstractMethodImplementation(
+ const python::PythonDictionary &class_dict) const {
+
+ using namespace python;
+
+ std::map<llvm::StringLiteral, AbstractMethodCheckerCases> checker;
+#define SET_ERROR_AND_CONTINUE(method_name, error) \
+ { \
+ checker[method_name] = error; \
+ continue; \
+ }
+
+ for (const llvm::StringLiteral &method_name : GetAbstractMethods()) {
+ if (!class_dict.HasKey(method_name))
+ SET_ERROR_AND_CONTINUE(method_name,
+ AbstractMethodCheckerCases::eNotImplemented)
+ auto callable_or_err = class_dict.GetItem(method_name);
+ if (!callable_or_err)
+ SET_ERROR_AND_CONTINUE(method_name,
+ AbstractMethodCheckerCases::eNotAllocated)
+ if (!PythonCallable::Check(callable_or_err.get().get()))
+ SET_ERROR_AND_CONTINUE(method_name,
+ AbstractMethodCheckerCases::eNotCallable)
+ checker[method_name] = AbstractMethodCheckerCases::eValid;
+ }
+
+#undef HANDLE_ERROR
+
+ return checker;
+ }
+
+ 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;
+
+ auto create_error = [](std::string message) {
+ return llvm::createStringError(llvm::inconvertibleErrorCode(), message);
+ };
+
+ bool has_class_name = !class_name.empty();
+ bool has_interpreter_dict =
+ !(llvm::StringRef(m_interpreter.GetDictionaryName()).empty());
+ if (!has_class_name && !has_interpreter_dict && !script_obj) {
+ if (!has_class_name)
+ return create_error("Missing script class name.");
+ else if (!has_interpreter_dict)
+ return create_error("Invalid script interpreter dictionary.");
+ else
+ return create_error("Missing scripting object.");
+ }
+
+ Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+ PythonObject result = {};
+
+ if (script_obj) {
+ result = PythonObject(PyRefType::Borrowed,
+ static_cast<PyObject *>(script_obj->GetValue()));
+ } else {
+ auto dict =
+ PythonModule::MainModule().ResolveName<python::PythonDictionary>(
+ m_interpreter.GetDictionaryName());
+ if (!dict.IsAllocated())
+ return create_error(
+ llvm::formatv("Could not find interpreter dictionary: %s",
+ m_interpreter.GetDictionaryName()));
+
+ auto init =
+ PythonObject::ResolveNameWithDictionary<python::PythonCallable>(
+ class_name, dict);
+ if (!init.IsAllocated())
+ return create_error(llvm::formatv("Could not find script class: %s",
+ class_name.data()));
+
+ std::tuple<Args...> original_args = std::forward_as_tuple(args...);
+ auto transformed_args = TransformArgs(original_args);
+
+ std::string error_string;
+ llvm::Expected<PythonCallable::ArgInfo> arg_info = init.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 =
+ create_error("Resulting object is not initialized.");
+
+ std::apply(
+ [&init, &expected_return_object](auto &&...args) {
+ llvm::consumeError(expected_return_object.takeError());
+ expected_return_object = init(args...);
+ },
+ transformed_args);
+
+ if (!expected_return_object)
+ return expected_return_object.takeError();
+ result = expected_return_object.get();
+ }
+
+ if (!result.IsValid())
+ return create_error("Resulting object is not a valid Python Object.");
+ if (!result.HasAttribute("__class__"))
+ return create_error("Resulting object doesn't have '__class__' member.");
+
+ PythonObject obj_class = result.GetAttributeValue("__class__");
+ if (!obj_class.IsValid())
+ return create_error("Resulting class object is not a valid.");
+ if (!obj_class.HasAttribute("__name__"))
+ return create_error(
+ "Resulting object class doesn't have '__name__' member.");
+ PythonString obj_class_name =
+ obj_class.GetAttributeValue("__name__").AsType<PythonString>();
+
+ PythonObject object_class_mapping_proxy =
+ obj_class.GetAttributeValue("__dict__");
+ if (!obj_class.HasAttribute("__dict__"))
+ return create_error(
+ "Resulting object class doesn't have '__dict__' member.");
+
+ PythonCallable dict_converter = PythonModule::BuiltinsModule()
+ .ResolveName("dict")
+ .AsType<PythonCallable>();
+ if (!dict_converter.IsAllocated())
+ return create_error(
+ "Python 'builtins' module doesn't have 'dict' class.");
+
+ PythonDictionary object_class_dict =
+ dict_converter(object_class_mapping_proxy).AsType<PythonDictionary>();
+ if (!object_class_dict.IsAllocated())
+ return create_error("Coudn't create dictionary from resulting object "
+ "class mapping proxy object.");
+
+ auto checker_or_err = CheckAbstractMethodImplementation(object_class_dict);
+ if (!checker_or_err)
+ return checker_or_err.takeError();
+
+ for (const auto &method_checker : *checker_or_err)
+ switch (method_checker.second) {
+ case AbstractMethodCheckerCases::eNotImplemented:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "Abstract method {0}.{1} not implemented.",
+ obj_class_name.GetString(), method_checker.first);
+ break;
+ case AbstractMethodCheckerCases::eNotAllocated:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "Abstract method {0}.{1} not allocated.",
+ obj_class_name.GetString(), method_checker.first);
+ break;
+ case AbstractMethodCheckerCases::eNotCallable:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "Abstract method {0}.{1} not callable.",
+ obj_class_name.GetString(), method_checker.first);
+ break;
+ case AbstractMethodCheckerCases::eValid:
+ LLDB_LOG(GetLog(LLDBLog::Script),
+ "Abstract method {0}.{1} implemented & valid.",
+ obj_class_name.GetString(), method_checker.first);
+ break;
+ }
+
+ for (const auto &method_checker : *checker_or_err)
+ if (method_checker.second != AbstractMethodCheckerCases::eValid)
+ return create_error(
+ llvm::formatv("Abstract method {0}.{1} missing. Enable lldb "
+ "script log for more details.",
+ obj_class_name.GetString(), method_checker.first));
+
+ 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 +273,6 @@ protected:
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 +283,8 @@ protected:
caller_signature,
"Couldn't re-assign reference and pointer arguments.", error);
+ if (!py_return.IsAllocated())
+ return {};
return ExtractValueFromPythonObject<T>(py_return, error);
}
@@ -122,6 +310,18 @@ protected:
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::ProcessSP arg) {
+ return python::SWIGBridge::ToSWIGWrapper(arg);
+ }
+
python::PythonObject Transform(lldb::ProcessAttachInfoSP arg) {
return python::SWIGBridge::ToSWIGWrapper(arg);
}
@@ -146,7 +346,6 @@ protected:
original_arg = ExtractValueFromPythonObject<T>(transformed_arg, error);
}
-
void ReverseTransform(bool &original_arg,
python::PythonObject transformed_arg, Status &error) {
python::PythonBoolean boolean_arg = python::PythonBoolean(
@@ -254,4 +453,4 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<
} // namespace lldb_private
#endif // LLDB_ENABLE_PYTHON
-#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPYTHONINTERFACE_H
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPYTHONINTERFACE_H
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp
index 5603a1541314..18e268527eb2 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp
@@ -13,10 +13,10 @@
#if LLDB_ENABLE_PYTHON
// LLDB Python header must be included first
-#include "lldb-python.h"
+#include "../lldb-python.h"
-#include "SWIGPythonBridge.h"
-#include "ScriptInterpreterPythonImpl.h"
+#include "../SWIGPythonBridge.h"
+#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedThreadPythonInterface.h"
#include <optional>
@@ -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/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h
index eac4941f8814..5676f7f1d675 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.h
@@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDTHREADPYTHONINTERFACE_H
-#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDTHREADPYTHONINTERFACE_H
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPYTHONINTERFACE_H
#include "lldb/Host/Config.h"
#if LLDB_ENABLE_PYTHON
#include "ScriptedPythonInterface.h"
-#include "lldb/Interpreter/ScriptedProcessInterface.h"
+#include "lldb/Interpreter/Interfaces/ScriptedThreadInterface.h"
#include <optional>
namespace lldb_private {
@@ -23,11 +23,16 @@ 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;
+ llvm::SmallVector<llvm::StringLiteral> GetAbstractMethods() const override {
+ return llvm::SmallVector<llvm::StringLiteral>(
+ {"get_stop_reason", "get_register_context"});
+ }
+
lldb::tid_t GetThreadID() override;
std::optional<std::string> GetName() override;
@@ -49,4 +54,4 @@ public:
} // namespace lldb_private
#endif // LLDB_ENABLE_PYTHON
-#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDTHREADPYTHONINTERFACE_H
+#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPYTHONINTERFACE_H
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index eee2f6f5d43f..ea0a1cdff40f 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -71,7 +71,9 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&obj) {
}
static bool python_is_finalizing() {
-#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
+#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13) || (PY_MAJOR_VERSION > 3)
+ return Py_IsFinalizing();
+#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
return _Py_Finalizing != nullptr;
#else
return _Py_IsFinalizing();
@@ -661,6 +663,20 @@ bool PythonDictionary::Check(PyObject *py_obj) {
return PyDict_Check(py_obj);
}
+bool PythonDictionary::HasKey(const llvm::Twine &key) const {
+ if (!IsValid())
+ return false;
+
+ PythonString key_object(key.isSingleStringRef() ? key.getSingleStringRef()
+ : key.str());
+
+ if (int res = PyDict_Contains(m_py_obj, key_object.get()) > 0)
+ return res;
+
+ PyErr_Print();
+ return false;
+}
+
uint32_t PythonDictionary::GetSize() const {
if (IsValid())
return PyDict_Size(m_py_obj);
@@ -1344,7 +1360,7 @@ llvm::Expected<FileSP> PythonFile::ConvertToFile(bool borrowed) {
FileSP file_sp;
if (borrowed) {
- // In this case we we don't need to retain the python
+ // In this case we don't need to retain the python
// object at all.
file_sp = std::make_shared<NativeFile>(fd, options.get(), false);
} else {
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 012f16e95e77..82eee76e42b2 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -562,6 +562,8 @@ public:
static bool Check(PyObject *py_obj);
+ bool HasKey(const llvm::Twine &key) const;
+
uint32_t GetSize() const;
PythonList GetKeys() const;
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
index 630ab293cf93..7cdd5577919b 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
@@ -116,12 +116,6 @@ public:
// 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/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 55b7a73712c4..ef7a2c128a22 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -14,12 +14,14 @@
// LLDB Python header must be included first
#include "lldb-python.h"
+#include "Interfaces/OperatingSystemPythonInterface.h"
+#include "Interfaces/ScriptedPlatformPythonInterface.h"
+#include "Interfaces/ScriptedProcessPythonInterface.h"
+#include "Interfaces/ScriptedThreadPythonInterface.h"
#include "PythonDataObjects.h"
#include "PythonReadline.h"
#include "SWIGPythonBridge.h"
#include "ScriptInterpreterPythonImpl.h"
-#include "ScriptedPlatformPythonInterface.h"
-#include "ScriptedProcessPythonInterface.h"
#include "lldb/API/SBError.h"
#include "lldb/API/SBFrame.h"
@@ -177,18 +179,31 @@ private:
return;
#endif
+// `PyEval_ThreadsInitialized` was deprecated in Python 3.9 and removed in
+// Python 3.13. It has been returning `true` always since Python 3.7.
+#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9) || (PY_MAJOR_VERSION < 3)
if (PyEval_ThreadsInitialized()) {
+#else
+ if (true) {
+#endif
Log *log = GetLog(LLDBLog::Script);
m_was_already_initialized = true;
m_gil_state = PyGILState_Ensure();
LLDB_LOGV(log, "Ensured PyGILState. Previous state = {0}locked\n",
m_gil_state == PyGILState_UNLOCKED ? "un" : "");
+
+// `PyEval_InitThreads` was deprecated in Python 3.9 and removed in
+// Python 3.13.
+#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 9) || (PY_MAJOR_VERSION < 3)
return;
}
// InitThreads acquires the GIL if it hasn't been called before.
PyEval_InitThreads();
+#else
+ }
+#endif
}
PyGILState_STATE m_gil_state = PyGILState_UNLOCKED;
@@ -412,8 +427,6 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
m_active_io_handler(eIOHandlerNone), m_session_is_active(false),
m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0),
m_command_thread_state(nullptr) {
- m_scripted_platform_interface_up =
- std::make_unique<ScriptedPlatformPythonInterface>(*this);
m_dictionary_name.append("_dict");
StreamString run_string;
@@ -582,10 +595,6 @@ void ScriptInterpreterPythonImpl::LeaveSession() {
// up believing we have no thread state and PyImport_AddModule will crash if
// that is the case - since that seems to only happen when destroying the
// SBDebugger, we can make do without clearing up stdout and stderr
-
- // rdar://problem/11292882
- // When the current thread state is NULL, PyThreadState_Get() issues a fatal
- // error.
if (PyThreadState_GetDict()) {
PythonDictionary &sys_module_dict = GetSysModuleDictionary();
if (sys_module_dict.IsValid()) {
@@ -1519,6 +1528,16 @@ ScriptInterpreterPythonImpl::CreateScriptedProcessInterface() {
return std::make_unique<ScriptedProcessPythonInterface>(*this);
}
+ScriptedThreadInterfaceSP
+ScriptInterpreterPythonImpl::CreateScriptedThreadInterface() {
+ return std::make_shared<ScriptedThreadPythonInterface>(*this);
+}
+
+OperatingSystemInterfaceSP
+ScriptInterpreterPythonImpl::CreateOperatingSystemInterface() {
+ return std::make_shared<OperatingSystemPythonInterface>(*this);
+}
+
StructuredData::ObjectSP
ScriptInterpreterPythonImpl::CreateStructuredDataFromScriptObject(
ScriptObject obj) {
@@ -1530,159 +1549,6 @@ ScriptInterpreterPythonImpl::CreateStructuredDataFromScriptObject(
return py_obj.CreateStructuredObject();
}
-StructuredData::GenericSP
-ScriptInterpreterPythonImpl::OSPlugin_CreatePluginObject(
- const char *class_name, lldb::ProcessSP process_sp) {
- if (class_name == nullptr || class_name[0] == '\0')
- return StructuredData::GenericSP();
-
- if (!process_sp)
- return StructuredData::GenericSP();
-
- Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
- PythonObject ret_val = SWIGBridge::LLDBSWIGPythonCreateOSPlugin(
- class_name, m_dictionary_name.c_str(), process_sp);
-
- return StructuredData::GenericSP(
- new StructuredPythonObject(std::move(ret_val)));
-}
-
-StructuredData::DictionarySP ScriptInterpreterPythonImpl::OSPlugin_RegisterInfo(
- StructuredData::ObjectSP os_plugin_object_sp) {
- Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
-
- if (!os_plugin_object_sp)
- return {};
-
- StructuredData::Generic *generic = os_plugin_object_sp->GetAsGeneric();
- if (!generic)
- return {};
-
- PythonObject implementor(PyRefType::Borrowed,
- (PyObject *)generic->GetValue());
-
- if (!implementor.IsAllocated())
- return {};
-
- llvm::Expected<PythonObject> expected_py_return =
- implementor.CallMethod("get_register_info");
-
- if (!expected_py_return) {
- llvm::consumeError(expected_py_return.takeError());
- return {};
- }
-
- PythonObject py_return = std::move(expected_py_return.get());
-
- if (py_return.get()) {
- PythonDictionary result_dict(PyRefType::Borrowed, py_return.get());
- return result_dict.CreateStructuredDictionary();
- }
- return StructuredData::DictionarySP();
-}
-
-StructuredData::ArraySP ScriptInterpreterPythonImpl::OSPlugin_ThreadsInfo(
- StructuredData::ObjectSP os_plugin_object_sp) {
- Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
- if (!os_plugin_object_sp)
- return {};
-
- StructuredData::Generic *generic = os_plugin_object_sp->GetAsGeneric();
- if (!generic)
- return {};
-
- PythonObject implementor(PyRefType::Borrowed,
- (PyObject *)generic->GetValue());
-
- if (!implementor.IsAllocated())
- return {};
-
- llvm::Expected<PythonObject> expected_py_return =
- implementor.CallMethod("get_thread_info");
-
- if (!expected_py_return) {
- llvm::consumeError(expected_py_return.takeError());
- return {};
- }
-
- PythonObject py_return = std::move(expected_py_return.get());
-
- if (py_return.get()) {
- PythonList result_list(PyRefType::Borrowed, py_return.get());
- return result_list.CreateStructuredArray();
- }
- return StructuredData::ArraySP();
-}
-
-StructuredData::StringSP
-ScriptInterpreterPythonImpl::OSPlugin_RegisterContextData(
- StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t tid) {
- Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
-
- if (!os_plugin_object_sp)
- return {};
-
- StructuredData::Generic *generic = os_plugin_object_sp->GetAsGeneric();
- if (!generic)
- return {};
- PythonObject implementor(PyRefType::Borrowed,
- (PyObject *)generic->GetValue());
-
- if (!implementor.IsAllocated())
- return {};
-
- llvm::Expected<PythonObject> expected_py_return =
- implementor.CallMethod("get_register_data", tid);
-
- if (!expected_py_return) {
- llvm::consumeError(expected_py_return.takeError());
- return {};
- }
-
- PythonObject py_return = std::move(expected_py_return.get());
-
- if (py_return.get()) {
- PythonBytes result(PyRefType::Borrowed, py_return.get());
- return result.CreateStructuredString();
- }
- return {};
-}
-
-StructuredData::DictionarySP ScriptInterpreterPythonImpl::OSPlugin_CreateThread(
- StructuredData::ObjectSP os_plugin_object_sp, lldb::tid_t tid,
- lldb::addr_t context) {
- Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
-
- if (!os_plugin_object_sp)
- return {};
-
- StructuredData::Generic *generic = os_plugin_object_sp->GetAsGeneric();
- if (!generic)
- return {};
-
- PythonObject implementor(PyRefType::Borrowed,
- (PyObject *)generic->GetValue());
-
- if (!implementor.IsAllocated())
- return {};
-
- llvm::Expected<PythonObject> expected_py_return =
- implementor.CallMethod("create_thread", tid, context);
-
- if (!expected_py_return) {
- llvm::consumeError(expected_py_return.takeError());
- return {};
- }
-
- PythonObject py_return = std::move(expected_py_return.get());
-
- if (py_return.get()) {
- PythonDictionary result_dict(PyRefType::Borrowed, py_return.get());
- return result_dict.CreateStructuredDictionary();
- }
- return StructuredData::DictionarySP();
-}
-
StructuredData::ObjectSP ScriptInterpreterPythonImpl::CreateScriptedThreadPlan(
const char *class_name, const StructuredDataImpl &args_data,
std::string &error_str, lldb::ThreadPlanSP thread_plan_sp) {
@@ -1783,7 +1649,7 @@ lldb::StateType ScriptInterpreterPythonImpl::ScriptedThreadPlanGetRunState(
bool
ScriptInterpreterPythonImpl::ScriptedThreadPlanGetStopDescription(
- StructuredData::ObjectSP implementor_sp, lldb_private::Stream *stream,
+ StructuredData::ObjectSP implementor_sp, lldb_private::Stream *stream,
bool &script_error) {
StructuredData::Generic *generic = nullptr;
if (implementor_sp)
@@ -2442,24 +2308,11 @@ ConstString ScriptInterpreterPythonImpl::GetSyntheticTypeName(
}
PythonObject py_return = std::move(expected_py_return.get());
+ if (!py_return.IsAllocated() || !PythonString::Check(py_return.get()))
+ return {};
- ConstString ret_val;
- bool got_string = false;
- std::string buffer;
-
- if (py_return.IsAllocated() && PythonString::Check(py_return.get())) {
- PythonString py_string(PyRefType::Borrowed, py_return.get());
- llvm::StringRef return_data(py_string.GetString());
- if (!return_data.empty()) {
- buffer.assign(return_data.data(), return_data.size());
- got_string = true;
- }
- }
-
- if (got_string)
- ret_val.SetCStringWithLength(buffer.c_str(), buffer.size());
-
- return ret_val;
+ PythonString type_name(PyRefType::Borrowed, py_return.get());
+ return ConstString(type_name.GetString());
}
bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword(
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
index 01db6c520300..a33499816d8d 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -134,23 +134,9 @@ public:
lldb::ScriptedProcessInterfaceUP CreateScriptedProcessInterface() override;
- StructuredData::GenericSP
- OSPlugin_CreatePluginObject(const char *class_name,
- lldb::ProcessSP process_sp) override;
-
- StructuredData::DictionarySP
- OSPlugin_RegisterInfo(StructuredData::ObjectSP os_plugin_object_sp) override;
+ lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override;
- StructuredData::ArraySP
- OSPlugin_ThreadsInfo(StructuredData::ObjectSP os_plugin_object_sp) override;
-
- StructuredData::StringSP
- OSPlugin_RegisterContextData(StructuredData::ObjectSP os_plugin_object_sp,
- lldb::tid_t thread_id) override;
-
- StructuredData::DictionarySP
- OSPlugin_CreateThread(StructuredData::ObjectSP os_plugin_object_sp,
- lldb::tid_t tid, lldb::addr_t context) override;
+ lldb::OperatingSystemInterfaceSP CreateOperatingSystemInterface() override;
StructuredData::ObjectSP
LoadPluginModule(const FileSpec &file_spec,