Skip to content

Commit 2054114

Browse files
Zhiyuan Lizyn-li
authored andcommitted
[lldb] Fix SBMemoryRegionInfoListExtensions iter to yield unique references
1 parent 8c3fbaf commit 2054114

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
'''Iterate over all the memory regions in a lldb.SBMemoryRegionInfoList object.'''
1010
import lldb
1111
size = self.GetSize()
12-
region = lldb.SBMemoryRegionInfo()
1312
for i in range(size):
13+
region = lldb.SBMemoryRegionInfo()
1414
self.GetMemoryRegionAtIndex(i, region)
1515
yield region
1616
%}

lldb/test/API/python_api/find_in_memory/TestFindInMemory.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,33 @@ def test_find_in_memory_unaligned(self):
154154
self.assertEqual(addr, lldb.LLDB_INVALID_ADDRESS)
155155

156156
def test_memory_info_list_iterable(self):
157-
"""Make sure the SBMemoryRegionInfoList is iterable"""
157+
"""Make sure the SBMemoryRegionInfoList is iterable and each yielded object is unique"""
158158
self.assertTrue(self.process, PROCESS_IS_VALID)
159159
self.assertState(self.process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
160160

161161
info_list = self.process.GetMemoryRegions()
162162
self.assertTrue(info_list.GetSize() > 0)
163+
164+
collected_info = []
163165
try:
164166
for info in info_list:
165-
pass
167+
collected_info.append(info)
166168
except Exception:
167169
self.fail("SBMemoryRegionInfoList is not iterable")
170+
171+
for i in range(len(collected_info)):
172+
region = lldb.SBMemoryRegionInfo()
173+
info_list.GetMemoryRegionAtIndex(i, region)
174+
175+
self.assertEqual(
176+
collected_info[i],
177+
region,
178+
f"items {i}: iterator data should match index access data",
179+
)
180+
181+
if len(collected_info) >= 2:
182+
self.assertNotEqual(
183+
collected_info[0].GetRegionBase(),
184+
collected_info[1].GetRegionBase(),
185+
"Different items should have different base addresses",
186+
)

0 commit comments

Comments
 (0)