Skip to content

[lldb] Fix SBMemoryRegionInfoListExtensions iter to yield unique refe… #144815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
%}
Expand Down
25 changes: 23 additions & 2 deletions lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Loading