Skip to content

Commit 90d4354

Browse files
committed
[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.
1 parent 0838e33 commit 90d4354

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lldb/source/Commands/CommandObjectRegister.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ class CommandObjectRegisterInfo : public CommandObjectParsed {
406406
CommandObjectRegisterInfo(CommandInterpreter &interpreter)
407407
: CommandObjectParsed(interpreter, "register info",
408408
"View information about a register.", nullptr,
409-
eCommandRequiresRegContext |
410-
eCommandProcessMustBeLaunched) {
409+
eCommandRequiresFrame | eCommandRequiresRegContext |
410+
eCommandProcessMustBeLaunched |
411+
eCommandProcessMustBePaused) {
411412
SetHelpLong(R"(
412413
Name The name lldb uses for the register, optionally with an alias.
413414
Size The size of the register in bytes and again in bits.

lldb/test/API/commands/register/register/register_command/TestRegisters.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,16 @@ def test_fs_gs_base(self):
659659
pthread_self_val.GetValueAsUnsigned(0),
660660
"fs_base does not equal to pthread_self() value.",
661661
)
662+
663+
def test_process_must_be_stopped(self):
664+
"""Check that all register commands error when the process is not stopped."""
665+
self.build()
666+
exe = self.getBuildArtifact("a.out")
667+
pid = self.spawnSubprocess(exe, ["wait_for_attach"]).pid
668+
self.setAsync(True)
669+
self.runCmd("process attach --continue -p %d" % pid)
670+
671+
err_msg = "Command requires a process which is currently stopped."
672+
self.expect("register read pc", substrs=[err_msg], error=True)
673+
self.expect("register write pc 0", substrs=[err_msg], error=True)
674+
self.expect("register info pc", substrs=[err_msg], error=True)

0 commit comments

Comments
 (0)