From 8122d0e4bc8b536e0bb6bb5fae97e8216986ee28 Mon Sep 17 00:00:00 2001 From: Aman LaChapelle Date: Thu, 29 Jan 2026 11:38:50 -0800 Subject: [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. --- .../Python/Interfaces/ScriptedPythonInterface.cpp | 38 ++++++++++++++++++++++ .../Python/Interfaces/ScriptedPythonInterface.h | 14 ++++++++ 2 files changed, 52 insertions(+) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/Interfaces') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp index ba4473cf9ec4..f5fd8b2d2d80 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 using namespace lldb; @@ -273,4 +274,41 @@ ScriptedPythonInterface::ExtractValueFromPythonObject( return m_interpreter.GetOpaqueTypeFromSBFrameList(*sb_frame_list); } +template <> +lldb::ValueObjectSP +ScriptedPythonInterface::ExtractValueFromPythonObject( + python::PythonObject &p, Status &error) { + lldb::SBValue *sb_value = reinterpret_cast( + 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( + python::PythonObject &p, Status &error) { + lldb::SBValueList *sb_value_list = reinterpret_cast( + 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(); + 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 b737f945845f..5e3df8f18c2b 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 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( python::PythonObject &p, Status &error); +template <> +lldb::ValueObjectSP +ScriptedPythonInterface::ExtractValueFromPythonObject( + python::PythonObject &p, Status &error); + +template <> +lldb::ValueObjectListSP +ScriptedPythonInterface::ExtractValueFromPythonObject( + python::PythonObject &p, Status &error); + } // namespace lldb_private #endif // LLDB_ENABLE_PYTHON -- cgit v1.2.3