diff options
| author | Aman LaChapelle <aman.lachapelle@gmail.com> | 2026-01-29 11:38:50 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-29 11:38:50 -0800 |
| commit | 8122d0e4bc8b536e0bb6bb5fae97e8216986ee28 (patch) | |
| tree | 18e6a0f949d12effad947a4886b279d6c6a56f20 /lldb/source/Plugins/ScriptInterpreter/Python | |
| parent | 75f03a62d1f9b0081fff57ceebb29a3ae1560a61 (diff) | |
| download | llvm-8122d0e4bc8b536e0bb6bb5fae97e8216986ee28.zip llvm-8122d0e4bc8b536e0bb6bb5fae97e8216986ee28.tar.gz llvm-8122d0e4bc8b536e0bb6bb5fae97e8216986ee28.tar.bz2 | |
[lldb] Add conversions for SBValueList and SBValue to the python bridge. (#178574)
This patch adds support for:
- PyObject -> SBValueList (which was surprisingly not there before!)
- PyObject -> SBValue
- SBValue -> ValueObjectSP using the ScriptInterpreter
These three are the main remaining plumbing changes necessary before we can get to the meat of actually using ScriptedFrame to provide values to the printer/etc. Future patches build off this change in order to allow ScriptedFrames to provide variables and get values for variable expressions.
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
3 files changed, 53 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp index ba4473c..f5fd8b2 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp @@ -18,6 +18,7 @@ #include "../ScriptInterpreterPythonImpl.h" #include "ScriptedPythonInterface.h" #include "lldb/Symbol/SymbolContext.h" +#include "lldb/ValueObject/ValueObjectList.h" #include <optional> using namespace lldb; @@ -273,4 +274,41 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StackFrameListSP>( return m_interpreter.GetOpaqueTypeFromSBFrameList(*sb_frame_list); } +template <> +lldb::ValueObjectSP +ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectSP>( + python::PythonObject &p, Status &error) { + lldb::SBValue *sb_value = reinterpret_cast<lldb::SBValue *>( + python::LLDBSWIGPython_CastPyObjectToSBValue(p.get())); + if (!sb_value) { + error = Status::FromErrorStringWithFormat( + "couldn't cast lldb::SBValue to lldb::ValueObjectSP"); + return {}; + } + + return m_interpreter.GetOpaqueTypeFromSBValue(*sb_value); +} + +template <> +lldb::ValueObjectListSP +ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectListSP>( + python::PythonObject &p, Status &error) { + lldb::SBValueList *sb_value_list = reinterpret_cast<lldb::SBValueList *>( + python::LLDBSWIGPython_CastPyObjectToSBValueList(p.get())); + + if (!sb_value_list) { + error = Status::FromErrorStringWithFormat( + "couldn't cast lldb::SBValueList to lldb::ValueObjectListSP"); + return {}; + } + + lldb::ValueObjectListSP out = std::make_shared<ValueObjectList>(); + for (uint32_t i = 0, e = sb_value_list->GetSize(); i < e; ++i) { + SBValue value = sb_value_list->GetValueAtIndex(i); + out->Append(m_interpreter.GetOpaqueTypeFromSBValue(value)); + } + + return out; +} + #endif diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h index b737f94..5e3df8f 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h @@ -656,6 +656,10 @@ protected: return python::SWIGBridge::ToSWIGWrapper(arg); } + python::PythonObject Transform(lldb::ValueObjectSP arg) { + return python::SWIGBridge::ToSWIGWrapper(arg); + } + template <typename T, typename U> void ReverseTransform(T &original_arg, U transformed_arg, Status &error) { // If U is not a PythonObject, don't touch it! @@ -814,6 +818,16 @@ lldb::StackFrameListSP ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StackFrameListSP>( python::PythonObject &p, Status &error); +template <> +lldb::ValueObjectSP +ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectSP>( + python::PythonObject &p, Status &error); + +template <> +lldb::ValueObjectListSP +ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectListSP>( + python::PythonObject &p, Status &error); + } // namespace lldb_private #endif // LLDB_ENABLE_PYTHON diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h index 32948ff..9f68445 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h @@ -269,6 +269,7 @@ void *LLDBSWIGPython_CastPyObjectToSBThread(PyObject *data); void *LLDBSWIGPython_CastPyObjectToSBFrame(PyObject *data); void *LLDBSWIGPython_CastPyObjectToSBSymbolContext(PyObject *data); void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data); +void *LLDBSWIGPython_CastPyObjectToSBValueList(PyObject *data); void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data); void *LLDBSWIGPython_CastPyObjectToSBExecutionContext(PyObject *data); void *LLDBSWIGPython_CastPyObjectToSBFrameList(PyObject *data); |
