Description
In SBMemoryRegionInfoListExtensions, the __iter__
function always yields the same SBMemoryRegionInfo
reference, but each loop the content of the info will be updated.
Using the example that I wrote in the docs:
readable_regions = []
for region in exe_ctx.GetProcess().GetMemoryRegions():
if region.IsReadable():
readable_regions.append(region)
We end up with a list all to the same region
This is because in the iter:
def __iter__(self):
'''Iterate over all the memory regions in a lldb.SBMemoryRegionInfoList object.'''
import lldb
size = self.GetSize()
region = lldb.SBMemoryRegionInfo()
for i in range(size):
self.GetMemoryRegionAtIndex(i, region)
yield region
Region is a reference and if you assign it to anything, that new variable will be mutated in the next loop.
I filed this as an issue to communicate the bug because I assume a user has encountered this without realizing (because it's not very apparent).
Activity
Jlalond commentedon Jun 16, 2025
@satyajanga could you fix this?
llvmbot commentedon Jun 16, 2025
@llvm/issue-subscribers-lldb
Author: Jacob Lalonde (Jlalond)
Using the example that I wrote in the docs:
We end up with a list all to the same region
This is because in the iter:
Region is a reference, and we will in the contents every loop, but if you assign anything to this reference, it will then be mutated next loop.
I filed this as an issue to communicate the bug because I assume a user has encountered this without realizing (because it's not very apparent).
Jlalond commentedon Jun 16, 2025
@JDevlieghere & @DavidSpickett as an FYI.
zyn-li commentedon Jun 16, 2025
@Jlalond I can fix this, assign to me
Jlalond commentedon Jun 16, 2025
Sounds good, as @aperez mentioned to me offline, we should also update the test to assert about the elements after we've iterated
https://github.com/llvm/llvm-project/blob/main/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py#L165