Skip to content
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 @@ -7,7 +7,12 @@

def __iter__(self):
'''Iterate over all the memory regions in a lldb.SBMemoryRegionInfoList object.'''
return lldb_iter(self, 'GetSize', 'GetMemoryRegionAtIndex')
import lldb
size = self.GetSize()
region = lldb.SBMemoryRegionInfo()
for i in range(size):
self.GetMemoryRegionAtIndex(i, region)
yield region
Comment on lines -10 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add a getitem and repr like found in SBAddressRangeListExtensions.i:

    def __getitem__(self, idx):
      '''Get the address range at a given index in an lldb.SBAddressRangeList object.'''
      if not isinstance(idx, int):
        raise TypeError("unsupported index type: %s" % type(idx))
      count = len(self)
      if not (-count <= idx < count):
        raise IndexError("list index out of range")
      idx %= count
      return self.GetAddressRangeAtIndex(idx)

    def __repr__(self):
      import lldb
      stream = lldb.SBStream()
      self.GetDescription(stream, lldb.target if lldb.target else lldb.SBTarget())
      return stream.GetData()

%}
#endif
}
13 changes: 13 additions & 0 deletions lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,16 @@ def test_find_in_memory_unaligned(self):
)
self.assertSuccess(error)
self.assertEqual(addr, lldb.LLDB_INVALID_ADDRESS)

def test_memory_info_list_iterable(self):
"""Make sure the SBMemoryRegionInfoList is iterable"""
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)
try:
for info in info_list:
pass
except Exception:
self.fail("SBMemoryRegionInfoList is not iterable")
Loading