[llvm-branch-commits] [lldb] release/23.x: [lldb] Fix incorrect Python property bindings in SBExtensions. (#215283) (PR #215345)

Douglas Yung via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Aug 15 08:41:13 PDT 2026


https://github.com/dyung updated https://github.com/llvm/llvm-project/pull/215345

>From cf723481e1629d35db5c8f8a8a7afff0823ac889 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <e_ezike at apple.com>
Date: Mon, 10 Aug 2026 18:16:41 +0100
Subject: [PATCH] [lldb] Fix incorrect Python property bindings in
 SBExtensions. (#215283)

Several Python property definitions in the SB extension interface files
were incorrectly copy-pasted during the
["Don't use SWIG internals
refactor"](https://github.com/llvm/llvm-project/commit/89b658428bae3b749f174ca79f0fe390451d8f69)
causing properties to shadow earlier definitions instead of exposing new
functionalities.

Rename each duplicate to its intended property name and wire it to the
correct underlying method.
Add add new API tests to cover the issue.

- SBModule: compile_unit -> section.
- SBType: is_function -> is_reference.
- SBTypeSummary is_function_code -> is_function_name.

(cherry picked from commit 1fb48d1418cf55f398024c60af13436b806561f9)
---
 lldb/bindings/interface/SBModuleExtensions.i  |  2 +-
 lldb/bindings/interface/SBTypeExtensions.i    |  2 +-
 .../interface/SBTypeSummaryExtensions.i       |  2 +-
 .../compile_unit/TestCompileUnitAPI.py        | 12 +++++++++
 .../formatters/TestFormattersSBAPI.py         | 15 +++++++----
 lldb/test/API/python_api/type/TestTypeList.py | 26 +++++++++++++++++--
 lldb/test/API/python_api/type/main.cpp        |  1 +
 7 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/lldb/bindings/interface/SBModuleExtensions.i b/lldb/bindings/interface/SBModuleExtensions.i
index ded1adae3e6a1..4c018be2e8104 100644
--- a/lldb/bindings/interface/SBModuleExtensions.i
+++ b/lldb/bindings/interface/SBModuleExtensions.i
@@ -220,7 +220,7 @@ STRING_EXTENSION_OUTSIDE(SBModule)
         sections = property(get_sections_array, None, doc='''A read only property that returns a list() of lldb.SBSection objects contained in this module.''')
         compile_units = property(get_compile_units_array, None, doc='''A read only property that returns a list() of lldb.SBCompileUnit objects contained in this module.''')
         section = property(get_sections_access_object, None, doc='''A read only property that can be used to access symbols by index ("section = module.section[0]"), name ("sections = module.section[\'main\']"), or using a regular expression ("sections = module.section[re.compile(...)]"). The return value is a single lldb.SBSection object for array access, and a list() of lldb.SBSection objects for name and regular expression access''')
-        section = property(get_sections_access_object, None, doc='''A read only property that can be used to access compile units by index ("compile_unit = module.compile_unit[0]"), name ("compile_unit = module.compile_unit[\'main.cpp\']"), or using a regular expression ("compile_unit = module.compile_unit[re.compile(...)]"). The return value is a single lldb.SBCompileUnit object for array access or by full or partial path, and a list() of lldb.SBCompileUnit objects regular expressions.''')
+        compile_unit = property(get_compile_units_access_object, None, doc='''A read only property that can be used to access compile units by index ("compile_unit = module.compile_unit[0]"), name ("compile_unit = module.compile_unit[\'main.cpp\']"), or using a regular expression ("compile_unit = module.compile_unit[re.compile(...)]"). The return value is a single lldb.SBCompileUnit object for array access or by full or partial path, and a list() of lldb.SBCompileUnit objects regular expressions.''')
 
         def get_uuid(self):
             return uuid.UUID (self.GetUUIDString())
diff --git a/lldb/bindings/interface/SBTypeExtensions.i b/lldb/bindings/interface/SBTypeExtensions.i
index 85c9d5e26bf7e..a1a3f746e7cdf 100644
--- a/lldb/bindings/interface/SBTypeExtensions.i
+++ b/lldb/bindings/interface/SBTypeExtensions.i
@@ -58,7 +58,7 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBType, lldb::eDescriptionLevelBrief)
         size = property(GetByteSize, None, doc='''A read only property that returns size in bytes for this type as an integer.''')
         is_pointer = property(IsPointerType, None, doc='''A read only property that returns a boolean value that indicates if this type is a pointer type.''')
         is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a reference type.''')
-        is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a function type.''')
+        is_function = property(IsFunctionType, None, doc='''A read only property that returns a boolean value that indicates if this type is a function type.''')
         num_fields = property(GetNumberOfFields, None, doc='''A read only property that returns number of fields in this type as an integer.''')
         num_bases = property(GetNumberOfDirectBaseClasses, None, doc='''A read only property that returns number of direct base classes in this type as an integer.''')
         num_vbases = property(GetNumberOfVirtualBaseClasses, None, doc='''A read only property that returns number of virtual base classes in this type as an integer.''')
diff --git a/lldb/bindings/interface/SBTypeSummaryExtensions.i b/lldb/bindings/interface/SBTypeSummaryExtensions.i
index e8da4c5022ef4..cd49ebf8276c6 100644
--- a/lldb/bindings/interface/SBTypeSummaryExtensions.i
+++ b/lldb/bindings/interface/SBTypeSummaryExtensions.i
@@ -10,7 +10,7 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTypeSummary, lldb::eDescriptionLevelBrief)
             options = property(GetOptions, SetOptions)
             is_summary_string = property(IsSummaryString)
             is_function_name = property(IsFunctionName)
-            is_function_name = property(IsFunctionCode)
+            is_function_code = property(IsFunctionCode)
             summary_data = property(GetData)
         %}
 #endif
diff --git a/lldb/test/API/python_api/compile_unit/TestCompileUnitAPI.py b/lldb/test/API/python_api/compile_unit/TestCompileUnitAPI.py
index a12955adb7ce3..be3c996cb6733 100644
--- a/lldb/test/API/python_api/compile_unit/TestCompileUnitAPI.py
+++ b/lldb/test/API/python_api/compile_unit/TestCompileUnitAPI.py
@@ -33,6 +33,18 @@ def test(self):
         main_cu = sc_list.compile_units[0]
         self.assertTrue(main_cu.IsValid(), "Main executable CU is not valid")
 
+        a_mod: lldb.SBModule = target.FindModule(lldb.SBFileSpec("a.out"))
+        main_cu_by_index = a_mod.compile_unit[0]
+        self.assertTrue(main_cu_by_index.IsValid(), "Main executable CU is not valid")
+
+        main_cu_by_name = a_mod.compile_unit["main.c"]
+        self.assertTrue(main_cu_by_name.IsValid(), "Main executable CU is not valid")
+
+        main_cu_by_regex_list = a_mod.compile_unit[re.compile(r".*main.*")]
+        self.assertEqual(len(main_cu_by_regex_list), 1)
+        [main_cu_by_regex] = main_cu_by_regex_list
+        self.assertTrue(main_cu_by_regex.IsValid(), "Main executable CU is not valid")
+
         self.assertEqual(
             main_cu.FindLineEntryIndex(line_entry, True),
             main_cu.FindLineEntryIndex(
diff --git a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py
index f9230df873e25..8e53354915b69 100644
--- a/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py
+++ b/lldb/test/API/python_api/formatters/TestFormattersSBAPI.py
@@ -431,12 +431,17 @@ def cleanup():
         self.expect(
             "frame variable foo_ptr", matching=True, substrs=["hello scripted world"]
         )
-        new_category.AddTypeSummary(
-            lldb.SBTypeNameSpecifier("JustAStruct"),
-            lldb.SBTypeSummary.CreateWithScriptCode(
-                "return 'hello scripted world';", lldb.eTypeOptionSkipPointers
-            ),
+        jas_summary_code = lldb.SBTypeSummary.CreateWithScriptCode(
+            "return 'hello scripted world';", lldb.eTypeOptionSkipPointers
+        )
+        self.assertFalse(jas_summary_code.is_function_name)
+        self.assertTrue(jas_summary_code.is_function_code)
+        self.assertTrue(jas_summary_code.IsFunctionCode())
+
+        added_summary = new_category.AddTypeSummary(
+            lldb.SBTypeNameSpecifier("JustAStruct"), jas_summary_code
         )
+        self.assertTrue(added_summary)
         self.expect(
             "frame variable foo", matching=True, substrs=["hello scripted world"]
         )
diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py
index ff9690794d1b3..21f2cec2dea7d 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -258,6 +258,15 @@ def test(self):
         self.DebugSBType(myint_type)
         self.assertEqual(myint_arr_element_type, myint_type)
 
+        # Verify 'first_ref' is a reference and not a function.
+        first_ref: lldb.SBValue = frame0.FindVariable("first_ref")
+        self.assertTrue(first_ref, VALID_VARIABLE)
+        self.DebugSBValue(first_ref)
+        first_ref_type: lldb.SBType = first_ref.type
+        self.assertTrue(first_ref_type, VALID_TYPE)
+        self.assertTrue(first_ref_type.is_reference)
+        self.assertFalse(first_ref_type.is_function)
+
         # Test enum methods. Requires DW_AT_enum_class which was added in Dwarf 4.
         if int(lldbplatformutil.getDwarfVersion()) >= 4:
             enum_type = target.FindFirstType("EnumType")
@@ -321,13 +330,26 @@ def test_dynamic_values(self):
 
         static = polymorphic.GetStaticValue()
         self.DebugSBValue(static)
-        static_type = static.GetType().GetPointeeType()
+        static_type: lldb.SBType = static.GetType().GetPointeeType()
         self.DebugSBType(static_type)
-        nested = static_type.FindDirectNestedType("Nested")
+        nested: lldb.SBType = static_type.FindDirectNestedType("Nested")
         self.DebugSBType(nested)
         self.assertEqual(nested.GetName(), "PolymorphicBase::Nested")
         self.assertEqual(nested.GetTypedefedType().GetName(), "int")
 
+        # Verify PolymorphicBase 'get' function type is a function and not a reference.
+        get_function = lldb.SBTypeMemberFunction()
+        self.assertFalse(get_function, "get_function should not be valid")
+        for i in range(0, static_type.GetNumberOfMemberFunctions()):
+            mem_func = static_type.GetMemberFunctionAtIndex(i)
+            if mem_func.GetName() == "get":
+                get_function = mem_func
+                break
+        self.assertEqual(get_function.GetName(), "get")
+        get_function_type: lldb.SBType = get_function.GetType()
+        self.assertTrue(get_function_type.is_function)
+        self.assertFalse(get_function_type.is_reference)
+
     def test_GetByteAlign(self):
         """Exercise SBType::GetByteAlign"""
         self.build()
diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp
index 9de1988ec7efc..a2dc66edd3642 100644
--- a/lldb/test/API/python_api/type/main.cpp
+++ b/lldb/test/API/python_api/type/main.cpp
@@ -102,6 +102,7 @@ int main (int argc, char const *argv[])
 
     typedef int myint;
     myint myint_arr[] = {1, 2, 3};
+    int &first_ref = myint_arr[0];
 
     EnumType enum_type;
     ScopedEnumType scoped_enum_type;



More information about the llvm-branch-commits mailing list