[Lldb-commits] [PATCH] D129272: [lldb][Windows] Fix memory region base addresses when a range is split

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 7 06:50:00 PDT 2022


DavidSpickett updated this revision to Diff 442896.
DavidSpickett added a comment.

- Use self.process()
- Check for overlapping regions instead of just the base addresses.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129272/new/

https://reviews.llvm.org/D129272

Files:
  lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
  lldb/test/API/functionalities/memory-region/TestMemoryRegion.py


Index: lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
===================================================================
--- lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
+++ lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
@@ -27,7 +27,7 @@
             substrs=["memory region <address-expression>",
                      "memory region -a"])
 
-    def test(self):
+    def setup_program(self):
         self.build()
 
         # Set breakpoint in main and run
@@ -37,6 +37,9 @@
 
         self.runCmd("run", RUN_SUCCEEDED)
 
+    def test_command(self):
+        self.setup_program()
+
         interp = self.dbg.GetCommandInterpreter()
         result = lldb.SBCommandReturnObject()
 
@@ -84,3 +87,37 @@
         interp.HandleCommand("memory region --all", result)
         self.assertTrue(result.Succeeded())
         self.assertEqual(result.GetOutput(), all_regions)
+
+    def test_unique_base_addresses(self):
+        # In the past on Windows we were recording AllocationBase as the base address
+        # of the current region, not BaseAddress. So if a range of pages was split
+        # into regions you would see several regions with the same base address.
+        # This checks that this no longer happens (and it shouldn't happen on any
+        # other OS either).
+        self.setup_program()
+
+        regions = self.process().GetMemoryRegions()
+        num_regions = regions.GetSize()
+
+        if num_regions:
+            region = lldb.SBMemoryRegionInfo()
+            regions.GetMemoryRegionAtIndex(0, region)
+            previous_base = region.GetRegionBase()
+            previous_end = region.GetRegionEnd()
+
+            for idx in range(1, regions.GetSize()):
+                regions.GetMemoryRegionAtIndex(idx, region)
+
+                # Check that it does not overlap the previous region.
+                # This could happen if we got the base addresses or size wrong.
+                # Also catches the base addresses being the same.
+                region_base = region.GetRegionBase()
+                region_end = region.GetRegionEnd()
+
+                if (region_base >= previous_base and region_base < previous_end) \
+                    or (region_end > previous_base and region_end <= previous_end):
+                    self.assertFalse(base_address in base_addresses,
+                        "Unexpected overlapping memory region found.")
+
+                previous_base = region_base
+                previous_end = region_end
\ No newline at end of file
Index: lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
===================================================================
--- lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
+++ lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
@@ -441,7 +441,7 @@
   // AllocationBase is defined for MEM_COMMIT and MEM_RESERVE but not MEM_FREE.
   if (mem_info.State != MEM_FREE) {
     info.GetRange().SetRangeBase(
-        reinterpret_cast<addr_t>(mem_info.AllocationBase));
+        reinterpret_cast<addr_t>(mem_info.BaseAddress));
     info.GetRange().SetRangeEnd(reinterpret_cast<addr_t>(mem_info.BaseAddress) +
                                 mem_info.RegionSize);
     info.SetMapped(MemoryRegionInfo::eYes);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129272.442896.patch
Type: text/x-patch
Size: 3313 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220707/7fac860f/attachment.bin>


More information about the lldb-commits mailing list