[Lldb-commits] [lldb] [lldb] Fix SBMemoryRegionInfoListExtensions iter to yield unique refe… (PR #144815)

via lldb-commits lldb-commits at lists.llvm.org
Sat Jun 21 00:22:38 PDT 2025


https://github.com/zyn-li updated https://github.com/llvm/llvm-project/pull/144815

>From 3ebb051ac739ec50b4be727cc3e555a78b14d7b8 Mon Sep 17 00:00:00 2001
From: Zhiyuan Li <zynli at meta.com>
Date: Wed, 18 Jun 2025 16:49:12 -0700
Subject: [PATCH] [lldb] Fix SBMemoryRegionInfoListExtensions iter to yield
 unique references

---
 .../SBMemoryRegionInfoListExtensions.i        |  2 +-
 .../find_in_memory/TestFindInMemory.py        | 25 +++++++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i b/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i
index 29c0179c0ffe3..f565f45880119 100644
--- a/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i
+++ b/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i
@@ -9,8 +9,8 @@
       '''Iterate over all the memory regions in a lldb.SBMemoryRegionInfoList object.'''
       import lldb
       size = self.GetSize()
-      region = lldb.SBMemoryRegionInfo()
       for i in range(size):
+        region = lldb.SBMemoryRegionInfo()
         self.GetMemoryRegionAtIndex(i, region)
         yield region
     %}
diff --git a/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py b/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
index 1ef37d2ec9898..74de46dee98a5 100644
--- a/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
+++ b/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
@@ -154,14 +154,35 @@ def test_find_in_memory_unaligned(self):
         self.assertEqual(addr, lldb.LLDB_INVALID_ADDRESS)
 
     def test_memory_info_list_iterable(self):
-        """Make sure the SBMemoryRegionInfoList is iterable"""
+        """Make sure the SBMemoryRegionInfoList is iterable and each yielded object is unique"""
         self.assertTrue(self.process, PROCESS_IS_VALID)
         self.assertState(self.process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
 
         info_list = self.process.GetMemoryRegions()
         self.assertTrue(info_list.GetSize() > 0)
+
+        collected_info = []
         try:
             for info in info_list:
-                pass
+                collected_info.append(info)
         except Exception:
             self.fail("SBMemoryRegionInfoList is not iterable")
+
+        for i in range(len(collected_info)):
+            region = lldb.SBMemoryRegionInfo()
+            info_list.GetMemoryRegionAtIndex(i, region)
+
+            self.assertEqual(
+                collected_info[i],
+                region,
+                f"items {i}: iterator data should match index access data",
+            )
+
+        self.assertTrue(
+            len(collected_info) >= 2, "Test requires at least 2 memory regions"
+        )
+        self.assertNotEqual(
+            collected_info[0].GetRegionBase(),
+            collected_info[1].GetRegionBase(),
+            "Different items should have different base addresses",
+        )



More information about the lldb-commits mailing list