[Lldb-commits] [lldb] [lldb] Require paused process and frame for "register info" command (PR #67124)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 22 07:47:41 PDT 2023


https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/67124

>From 90d4354a0305b9a88fee8e25292ecc3dcec5723d Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 22 Sep 2023 12:26:24 +0000
Subject: [PATCH 1/2] [lldb] Require paused process and frame for "register
 info" command

Prior to this the command would simply crash when run on a running
process.

Of the three register commands, "info" was the only one missing these
requirements. On some level it makes sense because you're not going
to read a value or modify anything, but practically I think lldb
assumes any time you're going to access register related stuff,
the process should be paused.

I noticed this debugging with a remote gdb stub, so I've recreated
that scenario using attach in a new test case.
---
 lldb/source/Commands/CommandObjectRegister.cpp      |  5 +++--
 .../register/register_command/TestRegisters.py      | 13 +++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp
index a0e88f6ab4ba27d..6e6071fd54606d0 100644
--- a/lldb/source/Commands/CommandObjectRegister.cpp
+++ b/lldb/source/Commands/CommandObjectRegister.cpp
@@ -406,8 +406,9 @@ class CommandObjectRegisterInfo : public CommandObjectParsed {
   CommandObjectRegisterInfo(CommandInterpreter &interpreter)
       : CommandObjectParsed(interpreter, "register info",
                             "View information about a register.", nullptr,
-                            eCommandRequiresRegContext |
-                                eCommandProcessMustBeLaunched) {
+                            eCommandRequiresFrame | eCommandRequiresRegContext |
+                                eCommandProcessMustBeLaunched |
+                                eCommandProcessMustBePaused) {
     SetHelpLong(R"(
 Name             The name lldb uses for the register, optionally with an alias.
 Size             The size of the register in bytes and again in bits.
diff --git a/lldb/test/API/commands/register/register/register_command/TestRegisters.py b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index 2e5c82a26cf1b9d..0ad9b8b24b3585c 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -659,3 +659,16 @@ def test_fs_gs_base(self):
             pthread_self_val.GetValueAsUnsigned(0),
             "fs_base does not equal to pthread_self() value.",
         )
+
+    def test_process_must_be_stopped(self):
+        """Check that all register commands error when the process is not stopped."""
+        self.build()
+        exe = self.getBuildArtifact("a.out")
+        pid = self.spawnSubprocess(exe, ["wait_for_attach"]).pid
+        self.setAsync(True)
+        self.runCmd("process attach --continue -p %d" % pid)
+
+        err_msg = "Command requires a process which is currently stopped."
+        self.expect("register read pc", substrs=[err_msg], error=True)
+        self.expect("register write pc 0", substrs=[err_msg], error=True)
+        self.expect("register info pc", substrs=[err_msg], error=True)

>From f54d3905320bc354a3bd7cf8ad9c9f091afda736 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 22 Sep 2023 14:47:06 +0000
Subject: [PATCH 2/2] Note the need for async mode

---
 .../commands/register/register/register_command/TestRegisters.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/test/API/commands/register/register/register_command/TestRegisters.py b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index 0ad9b8b24b3585c..f2ee3c4a047a269 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -665,6 +665,7 @@ def test_process_must_be_stopped(self):
         self.build()
         exe = self.getBuildArtifact("a.out")
         pid = self.spawnSubprocess(exe, ["wait_for_attach"]).pid
+        # Async so we can enter commands while the process is running.
         self.setAsync(True)
         self.runCmd("process attach --continue -p %d" % pid)
 



More information about the lldb-commits mailing list