<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/144439>144439</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLDB] SBMemoryRegionInfoListExtensions re-uses reference and then mutates it.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Jlalond
</td>
</tr>
</table>
<pre>
In [SBMemoryRegionInfoListExtensions](https://github.com/llvm/llvm-project/blob/main/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i#L8), 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 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).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVVGP6jYT_TXmZURkTAjhgQf27scnqq1U7W3VRzROJsSVY0e2s8D--spO4LLbXq0aRYIk4zMzPud40Ht1MkRbtnpiq-cZDqG1bvuLRm1NPZO2vm4PBtjq6fvTr9RZd32lk7LmYBr7onz43yWQ8coaz1bPTJRtCL1nyx0Teyb2JxXaQWaV7ZjYa_12-5n3zv5FVWBiL7WVTOw7VCZ9rOOTVKZW5uSZ2CsTyDVYERP7r0rIFBPLl5KJDRPfILQErODHowrkjkdWcGgGUwVlDaA-49XDVZGufYr02KXwf-aICx015MjEKr6BHAIQVi1oa_u0uLImkAlgm_SoTG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