Skip to content

Conversation

@bzcheeseman
Copy link
Contributor

@bzcheeseman bzcheeseman commented Jan 29, 2026

Stacked PRs:


[lldb] Add conversions for SBValueList and SBValue to the python bridge.

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.

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.

stack-info: PR: #178574, branch: users/bzcheeseman/stack/5
@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2026

@llvm/pr-subscribers-lldb

Author: Aman LaChapelle (bzcheeseman)

Changes

Stacked PRs:

  • #178575
  • ->#178574
  • #178573

[lldb] Add conversions for SBValueList and SBValue to the python bridge.

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.


Full diff: https://github.com/llvm/llvm-project/pull/178574.diff

6 Files Affected:

  • (modified) lldb/bindings/python/python-wrapper.swig (+12)
  • (modified) lldb/include/lldb/Interpreter/ScriptInterpreter.h (+3)
  • (modified) lldb/source/Interpreter/ScriptInterpreter.cpp (+10)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp (+38)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h (+14)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h (+1)
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index 0ba152166522b..bf59569920470 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -545,6 +545,18 @@ void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject * data
   return sb_ptr;
 }
 
+void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValueList(PyObject * data) {
+  lldb::SBValueList *sb_ptr = NULL;
+
+  int valid_cast =
+      SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBValueList, 0);
+
+  if (valid_cast == -1)
+    return NULL;
+
+  return sb_ptr;
+}
+
 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *
                                                                     data) {
   lldb::SBMemoryRegionInfo *sb_ptr = NULL;
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 0b91d6756552d..557d73a415452 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -609,6 +609,9 @@ class ScriptInterpreter : public PluginInterface {
   lldb::StackFrameListSP
   GetOpaqueTypeFromSBFrameList(const lldb::SBFrameList &exe_ctx) const;
 
+  lldb::ValueObjectSP
+  GetOpaqueTypeFromSBValue(const lldb::SBValue &value) const;
+
 protected:
   Debugger &m_debugger;
   lldb::ScriptLanguage m_script_lang;
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 7bad10ff3ea61..f8f989c9e00c9 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -15,6 +15,7 @@
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StringList.h"
+#include "lldb/ValueObject/ValueObject.h"
 #if defined(_WIN32)
 #include "lldb/Host/windows/ConnectionGenericFileWindows.h"
 #endif
@@ -162,6 +163,15 @@ lldb::StackFrameListSP ScriptInterpreter::GetOpaqueTypeFromSBFrameList(
   return frame_list.m_opaque_sp;
 }
 
+lldb::ValueObjectSP
+ScriptInterpreter::GetOpaqueTypeFromSBValue(const lldb::SBValue &value) const {
+  if (!value.m_opaque_sp)
+    return lldb::ValueObjectSP();
+  
+  lldb_private::ValueLocker locker;
+  return locker.GetLockedSP(*value.m_opaque_sp);
+}
+
 lldb::ScriptLanguage
 ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
   if (language.equals_insensitive(LanguageToString(eScriptLanguageNone)))
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
index ba4473cf9ec4d..f5fd8b2d2d802 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 b737f945845f6..5e3df8f18c2be 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -656,6 +656,10 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
     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 32948ffd30023..9f68445d0d72b 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);

@github-actions
Copy link

github-actions bot commented Jan 29, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@bzcheeseman bzcheeseman marked this pull request as draft January 29, 2026 05:18
@bzcheeseman bzcheeseman changed the base branch from users/bzcheeseman/stack/4 to main January 29, 2026 05:18
@bzcheeseman bzcheeseman force-pushed the users/bzcheeseman/stack/5 branch from be1b9d1 to f938075 Compare January 29, 2026 05:18
@bzcheeseman bzcheeseman changed the base branch from main to users/bzcheeseman/stack/4 January 29, 2026 05:18
@bzcheeseman bzcheeseman marked this pull request as ready for review January 29, 2026 05:19
@bzcheeseman bzcheeseman marked this pull request as draft January 29, 2026 06:20
@bzcheeseman bzcheeseman changed the base branch from users/bzcheeseman/stack/4 to main January 29, 2026 06:20
@bzcheeseman bzcheeseman changed the base branch from main to users/bzcheeseman/stack/4 January 29, 2026 06:20
@bzcheeseman bzcheeseman marked this pull request as ready for review January 29, 2026 06:20
@bzcheeseman bzcheeseman marked this pull request as draft January 29, 2026 16:31
@bzcheeseman bzcheeseman changed the base branch from users/bzcheeseman/stack/4 to main January 29, 2026 16:31
@bzcheeseman bzcheeseman force-pushed the users/bzcheeseman/stack/5 branch from f938075 to 10310df Compare January 29, 2026 16:31
@bzcheeseman bzcheeseman changed the base branch from main to users/bzcheeseman/stack/4 January 29, 2026 16:31
@bzcheeseman bzcheeseman marked this pull request as ready for review January 29, 2026 16:32
@bzcheeseman bzcheeseman marked this pull request as draft January 29, 2026 16:33
@bzcheeseman bzcheeseman changed the base branch from users/bzcheeseman/stack/4 to main January 29, 2026 16:33
@bzcheeseman bzcheeseman force-pushed the users/bzcheeseman/stack/5 branch from 10310df to f4b8187 Compare January 29, 2026 16:33
@bzcheeseman bzcheeseman changed the base branch from main to users/bzcheeseman/stack/4 January 29, 2026 16:33
@bzcheeseman bzcheeseman marked this pull request as ready for review January 29, 2026 16:33
Copy link
Member

@medismailben medismailben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. I'd have added GetOpaqueTypeFromSBValueList for completeness while working on this.

@bzcheeseman bzcheeseman marked this pull request as draft January 29, 2026 18:30
@bzcheeseman bzcheeseman changed the base branch from users/bzcheeseman/stack/4 to main January 29, 2026 18:30
@bzcheeseman bzcheeseman force-pushed the users/bzcheeseman/stack/5 branch from f4b8187 to 116ba6a Compare January 29, 2026 18:30
@bzcheeseman bzcheeseman changed the base branch from main to users/bzcheeseman/stack/4 January 29, 2026 18:30
@bzcheeseman bzcheeseman marked this pull request as ready for review January 29, 2026 18:30
@bzcheeseman
Copy link
Contributor Author

This looks fine to me. I'd have added GetOpaqueTypeFromSBValueList for completeness while working on this.

I didn't have a use case for it, and I was trying to keep the diff minimal 🤷🏽 if you'd prefer I am happy to add it

Base automatically changed from users/bzcheeseman/stack/4 to main January 29, 2026 19:12
@bzcheeseman bzcheeseman force-pushed the users/bzcheeseman/stack/5 branch from 116ba6a to 86dd09a Compare January 29, 2026 19:12
@bzcheeseman bzcheeseman merged commit 8122d0e into main Jan 29, 2026
8 of 9 checks passed
@bzcheeseman bzcheeseman deleted the users/bzcheeseman/stack/5 branch January 29, 2026 19:38
honeygoyal pushed a commit to honeygoyal/llvm-project that referenced this pull request Jan 30, 2026
…ge. (llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants