Skip to content

Conversation

@JDevlieghere
Copy link
Member

Add a class property for the version string. This allows you to use access the version string through lldb.SBDebugger.version instead of having to call lldb.SBDebugger.GetVersionString().

Add a class property for the version string. This allows you to use
access the version string through `lldb.SBDebugger.version` instead of
having to call `lldb.SBDebugger.GetVersionString()`.
@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

Add a class property for the version string. This allows you to use access the version string through lldb.SBDebugger.version instead of having to call lldb.SBDebugger.GetVersionString().


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

2 Files Affected:

  • (modified) lldb/bindings/interface/SBDebuggerExtensions.i (+13)
  • (modified) lldb/test/API/python_api/debugger/TestDebuggerAPI.py (+8)
diff --git a/lldb/bindings/interface/SBDebuggerExtensions.i b/lldb/bindings/interface/SBDebuggerExtensions.i
index ff2a0359b1363..7895fcdd72468 100644
--- a/lldb/bindings/interface/SBDebuggerExtensions.i
+++ b/lldb/bindings/interface/SBDebuggerExtensions.i
@@ -45,4 +45,17 @@ STRING_EXTENSION_OUTSIDE(SBDebugger)
     lldb::FileSP GetErrorFileHandle() {
         return self->GetErrorFile().GetFile();
     }
+
+#ifdef SWIGPYTHON
+    %pythoncode %{
+        class staticproperty:
+            def __init__(self, func):
+                self.func = func
+            def __get__(self, instance, owner):
+                return self.func()
+        @staticproperty
+        def version():
+            return SBDebugger.GetVersionString()
+    %}
+#endif
 }
diff --git a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
index 646ccce36530d..43f45f330ee2a 100644
--- a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
+++ b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
@@ -286,3 +286,11 @@ def remove_bar(dbg_id):
             ('remove bar ret', False), # remove_bar should fail, because it's already invoked and removed
             ('foo called', original_dbg_id), # foo should be called
         ])
+
+    def test_version(self):
+        instance_str = self.dbg.GetVersionString()
+        class_str = lldb.SBDebugger.GetVersionString()
+        property_str = lldb.SBDebugger.version
+
+        self.assertEqual(instance_str, class_str)
+        self.assertEqual(class_str, property_str)


#ifdef SWIGPYTHON
%pythoncode %{
class staticproperty:
Copy link
Member

Choose a reason for hiding this comment

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

neat

@JDevlieghere JDevlieghere merged commit 37b0b0f into llvm:main Jun 27, 2025
9 checks passed
@JDevlieghere JDevlieghere deleted the python-version-class-property branch June 27, 2025 15:30
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.

3 participants