[Lldb-commits] [lldb] Make SBMemoryRegionInfoList iterable with Python SWIG (PR #117358)
https://github.com/lukejriddle updated https://github.com/llvm/llvm-project/pull/117358 >From c4a4b658daac89204d9e03ad5ef7a3cd7b474325 Mon Sep 17 00:00:00 2001 From: Luke Riddle Date: Fri, 22 Nov 2024 10:23:43 -0800 Subject: [PATCH 1/2] Make SBMemeoryRegionInfoList iterable with Python SWIG --- lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i b/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i index 49d49110de7ff9..29c0179c0ffe3e 100644 --- a/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i +++ b/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i @@ -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 %} #endif } >From a6fe10a7c68df2f5f8bed606c190777d505e820c Mon Sep 17 00:00:00 2001 From: Luke Riddle Date: Fri, 22 Nov 2024 11:37:13 -0800 Subject: [PATCH 2/2] Add unit test for SBMemoryRegionInfoList iter --- .../python_api/find_in_memory/TestFindInMemory.py | 13 + 1 file changed, 13 insertions(+) diff --git a/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py b/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py index 04e807c5c6201d..1ef37d2ec98988 100644 --- a/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py +++ b/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py @@ -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") ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Make SBMemoryRegionInfoList iterable with Python SWIG (PR #117358)
https://github.com/lukejriddle ready_for_review https://github.com/llvm/llvm-project/pull/117358 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Make SBMemoryRegionInfoList iterable with Python SWIG (PR #117358)
https://github.com/lukejriddle created https://github.com/llvm/llvm-project/pull/117358 This PR fixes a simple SWIG issue with SBMemoryRegionInfoList not being iterable out-of-the-box. This is mostly because of limitations to the `lldb_iter` function, which doesn't allow for specifying arguments to the size / iter functions passed. Before: ``` (lldb) script Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D. >>> for region in lldb.process.GetMemoryRegions(): ... print(region) ... Traceback (most recent call last): File "", line 1, in File "/opt/llvm/stable/Toolchains/llvm-sand.xctoolchain/usr/lib/python3.10/site-packages/lldb/__init__.py", line 114, in lldb_iter yield elem(i) TypeError: SBMemoryRegionInfoList.GetMemoryRegionAtIndex() missing 1 required positional argument: 'region_info' ``` After: ``` (lldb) script Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D. >>> for region in lldb.process.GetMemoryRegions(): ... print(region) ... [0x0020-0x002cf000 R--] [0x002cf000-0x00597000 R-X] [0x00597000-0x005ad000 R--] [0x005ad000-0x005b1000 RW-] [0x005b1000-0x00b68000 RW-] [0x7fff7000-0x8fff7000 RW-] [0x02008fff7000-0x10007fff8000 RW-] [0x5030-0x5031 RW-] [0x503e-0x503e0001 RW-] [0x5040-0x5041 RW-] [0x504e-0x504e0001 RW-] [0x50d0-0x50d1 RW-] [0x50de-0x50de0001 RW-] [0x50e0-0x50e1 RW-] [0x50ee-0x50ee0001 RW-] [0x5110-0x5111 RW-] [0x511e-0x511e0001 RW-] [0x5130-0x5131 RW-] ... ``` >From c4a4b658daac89204d9e03ad5ef7a3cd7b474325 Mon Sep 17 00:00:00 2001 From: Luke Riddle Date: Fri, 22 Nov 2024 10:23:43 -0800 Subject: [PATCH] Make SBMemeoryRegionInfoList iterable with Python SWIG --- lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i b/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i index 49d49110de7ff9..29c0179c0ffe3e 100644 --- a/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i +++ b/lldb/bindings/interface/SBMemoryRegionInfoListExtensions.i @@ -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 %} #endif } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Make SBMemoryRegionInfoList iterable with Python SWIG (PR #117358)
lukejriddle wrote: > @lukejriddle Can we add a test for this? We just want to have a test case > that iterates the regions. Done https://github.com/llvm/llvm-project/pull/117358 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits