[Lldb-commits] [PATCH] D134029: [LLDB] Properly return errors from "memory region --all"

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 16 05:53:29 PDT 2022


DavidSpickett created this revision.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When I wrote the initial version I forgot that a region being
unmapped is not an error. There are real errors that we don't
want to hide, such as the remote not supporting the
qMemoryRegionInfo packet (gdbserver does not).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134029

Files:
  lldb/source/Commands/CommandObjectMemory.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
@@ -8,6 +8,8 @@
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+from lldbsuite.test.gdbclientutils import MockGDBServerResponder
+from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
 
 
 class MemoryCommandRegion(TestBase):
@@ -126,3 +128,36 @@
 
                 previous_base = region_base
                 previous_end = region_end
+
+class MemoryCommandRegionAll(GDBRemoteTestBase):
+    NO_DEBUG_INFO_TESTCASE = True
+
+    def test_all_error(self):
+        # The --all option should keep looping until the end of the memory range.
+        # If there is an error it should be reported as if you were just asking
+        # for one region. In this case the error is the remote not supporting
+        # qMemoryRegionInfo.
+        # (a region being unmapped is not an error, we just get a result
+        # describing an unmapped range)
+        class MyResponder(MockGDBServerResponder):
+            def qMemoryRegionInfo(self, addr):
+                # Empty string means unsupported.
+                return ""
+
+        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.assertFalse(result.Succeeded())
+        self.assertEqual(result.GetError(),
+                    "error: qMemoryRegionInfo is not supported\n")
\ No newline at end of file
Index: lldb/source/Commands/CommandObjectMemory.cpp
===================================================================
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -1830,9 +1830,6 @@
           addr = region_info.GetRange().GetRangeEnd();
         }
       }
-
-      // Even if we read nothing, don't error for --all
-      error.Clear();
     } else {
       lldb_private::MemoryRegionInfo region_info;
       error = process_sp->GetMemoryRegionInfo(load_addr, region_info);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134029.460707.patch
Type: text/x-patch
Size: 2725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220916/666af4f3/attachment.bin>


More information about the lldb-commits mailing list