diff options
| author | Pavel Labath <pavel@labath.sk> | 2024-09-04 11:30:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-04 11:30:58 +0200 |
| commit | cc5c526c80a4cacf7ed5b7fbe50072594ec1aeaf (patch) | |
| tree | f299a8b6d8b298d7072bbbb3279098ccce0627d4 /lldb/test/API/functionalities/memory/holes/TestMemoryHoles.py | |
| parent | afb6dafc6b680fb204d40c7fee4b339aa8471010 (diff) | |
[lldb] Fix and speedup the `memory find` command (#104193)
This patch fixes an issue where the `memory find` command would
effectively stop searching after encountering a memory read error (which
could happen due to unreadable memory), without giving any indication
that it has done so (it would just print it could not find the pattern).
To make matters worse, it would not terminate after encountering this
error, but rather proceed to slowly increment the address pointer, which
meant that searching a large region could take a very long time (and
give the appearance that lldb is actually searching for the thing).
The patch fixes this first problem by detecting read errors and
skipping over (using GetMemoryRegionInfo) the unreadable parts of memory
and resuming the search after them. It also reads the memory in bulk
(`max(sizeof(pattern))`), which speeds up the search significantly (up
to 6x for live processes, 18x for core files).
Diffstat (limited to 'lldb/test/API/functionalities/memory/holes/TestMemoryHoles.py')
| -rw-r--r-- | lldb/test/API/functionalities/memory/holes/TestMemoryHoles.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lldb/test/API/functionalities/memory/holes/TestMemoryHoles.py b/lldb/test/API/functionalities/memory/holes/TestMemoryHoles.py index 1c2c90d483ea..c61ae15b9dda 100644 --- a/lldb/test/API/functionalities/memory/holes/TestMemoryHoles.py +++ b/lldb/test/API/functionalities/memory/holes/TestMemoryHoles.py @@ -43,6 +43,9 @@ class MemoryHolesTestCase(TestBase): # inside the holes we've deliberately left empty. self.memory = self.frame().FindVariable("mem_with_holes").GetValueAsUnsigned() self.pagesize = self.frame().FindVariable("pagesize").GetValueAsUnsigned() + self.num_pages = ( + self.target().FindFirstGlobalVariable("num_pages").GetValueAsUnsigned() + ) positions = self.frame().FindVariable("positions") self.positions = [ positions.GetChildAtIndex(i).GetValueAsUnsigned() @@ -58,3 +61,13 @@ class MemoryHolesTestCase(TestBase): self.assertEqual(len(content), self.pagesize) self.assertEqual(content[0:7], b"needle\0") self.assertTrue(error.Fail()) + + def test_memory_find(self): + self._prepare_inferior() + + matches = [f"data found at location: {p:#x}" for p in self.positions] + self.expect( + f'memory find --count {len(self.positions)+1} --string "needle" ' + f"{self.memory:#x} {self.memory+self.pagesize*self.num_pages:#x}", + substrs=matches + ["no more matches within the range"], + ) |
