This is an archive of the discontinued LLVM Phabricator instance.

[lldb][Windows] Fix memory region base addresses when a range is split
ClosedPublic

Authored by DavidSpickett on Jul 7 2022, 3:59 AM.

Details

Summary

Previously we recorded AllocationBase as the base address of the region
we get from VirtualQueryEx. However, this is the base of the allocation,
which can later be split into more regions.

So you got stuff like:
[0x00007fff377c0000-0x00007fff377c1000) r-- PECOFF header
[0x00007fff377c0000-0x00007fff37840000) r-x .text
[0x00007fff377c0000-0x00007fff37870000) r-- .rdata

Where all the base addresses were the same.

Instead, use BaseAddress as the base of the region. So we get:
[0x00007fff377c0000-0x00007fff377c1000) r-- PECOFF header
[0x00007fff377c1000-0x00007fff37840000) r-x .text
[0x00007fff37840000-0x00007fff37870000) r-- .rdata

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-memory_basic_information

The added test checks for any overlapping regions which means
if we get the base or size wrong it'll fail. This logic
applies to any OS so the test isn't restricted to Windows.

Diff Detail

Event Timeline

DavidSpickett created this revision.Jul 7 2022, 3:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 3:59 AM
DavidSpickett requested review of this revision.Jul 7 2022, 3:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 3:59 AM
labath accepted this revision.Jul 7 2022, 4:40 AM

Looks good, thanks. I'd consider strengthening the test to look for overlapping address ranges instead of just identical base addresses.

lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
99

use self.process() instead

This revision is now accepted and ready to land.Jul 7 2022, 4:40 AM
  • Use self.process()
  • Check for overlapping regions instead of just the base addresses.
DavidSpickett edited the summary of this revision. (Show Details)Jul 7 2022, 6:50 AM
DavidSpickett marked an inline comment as done.
labath added inline comments.Jul 7 2022, 7:14 AM
lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
91

rename to test_region_overlap or something along those lines?

119

I don't see base_addresses defined anywhere. I guess this should just be assertFalse, and the overlap condition right?

Btw, can check for overlap with region_base < previous_end && previous_base < region_end.

DavidSpickett added inline comments.Jul 7 2022, 8:26 AM
lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
119

Completely missed that yes, I'll fix it up.

DavidSpickett marked 2 inline comments as done.Jul 7 2022, 8:38 AM

Fixed up in https://reviews.llvm.org/rGf3d43eca34d4. Next time I will remember to check what a test failure looks like.