[Lldb-commits] [lldb] c831cea - [LLDB] Fix "memory region --all" when there is no ABI plugin

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 23 05:32:46 PDT 2022


Author: David Spickett
Date: 2022-09-23T12:32:38Z
New Revision: c831cea5efaaafaa97e3faf3119da3362868f41a

URL: https://github.com/llvm/llvm-project/commit/c831cea5efaaafaa97e3faf3119da3362868f41a
DIFF: https://github.com/llvm/llvm-project/commit/c831cea5efaaafaa97e3faf3119da3362868f41a.diff

LOG: [LLDB] Fix "memory region --all" when there is no ABI plugin

There are two conditions for the loop exit. Either we hit LLDB_INVALID_ADDRESS
or the ABI tells us we are beyond mappable memory.

I made a mistake in that second part that meant if you had no ABI plugin
--all would stop on the first loop and return nothing.

If there's no ABI plugin we should only check for LLDB_INVALID_ADDRESS.

Depends on D134029

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D134030

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectMemory.cpp
    lldb/test/API/functionalities/memory-region/TestMemoryRegion.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 33c40a9ed8902..e42665b974156 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1821,7 +1821,7 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
              // When there are non-address bits the last range will not extend
              // to LLDB_INVALID_ADDRESS but to the max virtual address.
              // This prevents us looping forever if that is the case.
-             (abi && (abi->FixAnyAddress(addr) == addr))) {
+             (!abi || (abi->FixAnyAddress(addr) == addr))) {
         lldb_private::MemoryRegionInfo region_info;
         error = process_sp->GetMemoryRegionInfo(addr, region_info);
 

diff  --git a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
index 5e4c80bbb5767..2bced341d2429 100644
--- a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
+++ b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
@@ -160,4 +160,38 @@ def qMemoryRegionInfo(self, addr):
         interp.HandleCommand("memory region --all ", result)
         self.assertFalse(result.Succeeded())
         self.assertEqual(result.GetError(),
-                    "error: qMemoryRegionInfo is not supported\n")
\ No newline at end of file
+                    "error: qMemoryRegionInfo is not supported\n")
+
+    @skipIfAsan
+    def test_all_no_abi_plugin(self):
+        # There are two conditions for breaking the all loop. Either we get to
+        # LLDB_INVALID_ADDRESS, or the ABI plugin tells us we have got beyond
+        # the mappable range. If we don't have an ABI plugin, the option should still
+        # work and only check the first condition.
+
+        class MyResponder(MockGDBServerResponder):
+            def qMemoryRegionInfo(self, addr):
+                if addr == 0:
+                    return "start:0;size:100000000;"
+                # Goes until the end of memory.
+                if addr == 0x100000000:
+                    return "start:100000000;size:fffffffeffffffff;"
+
+        self.server.responder = MyResponder()
+        target = self.dbg.CreateTarget('')
+        if self.TraceOn():
+          self.runCmd("log enable gdb-remote packets")
+          self.addTearDownHook(
+                lambda: self.runCmd("log disable gdb-remote packets"))
+
+        process = self.connect(target)
+        lldbutil.expect_state_changes(self, self.dbg.GetListener(), process,
+                                      [lldb.eStateStopped])
+
+        interp = self.dbg.GetCommandInterpreter()
+        result = lldb.SBCommandReturnObject()
+        interp.HandleCommand("memory region --all ", result)
+        self.assertTrue(result.Succeeded())
+        self.assertEqual(result.GetOutput(),
+                    "[0x0000000000000000-0x0000000100000000) ---\n"
+                    "[0x0000000100000000-0xffffffffffffffff) ---\n")


        


More information about the lldb-commits mailing list