Skip to content

[LLDB] SBMemoryRegionInfoListExtensions re-uses reference and then mutates it. #144439

Open
@Jlalond

Description

@Jlalond

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

Image

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).

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions