Skip to content

Commit fd89299

Browse files
committed
[lldb] Fix crash when completing register names after program exit
Previously the following would crash: (lldb) run Process 2594053 launched: '/tmp/test.o' (aarch64) Process 2594053 exited with status = 0 (0x00000000) (lldb) register read <tab> As the completer assumed that the execution context would always have a register context. After a program has finished, it does not. Split out the generic parts of the test from the x86 specific tests, and added "register info" to both. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D154413
1 parent ac03e3f commit fd89299

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ void CommandCompletions::Registers(CommandInterpreter &interpreter,
611611

612612
RegisterContext *reg_ctx =
613613
interpreter.GetExecutionContext().GetRegisterContext();
614+
if (!reg_ctx)
615+
return;
616+
614617
const size_t reg_num = reg_ctx->GetRegisterCount();
615618
for (size_t reg_idx = 0; reg_idx < reg_num; ++reg_idx) {
616619
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);

lldb/test/API/functionalities/completion/TestCompletion.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,25 @@ def test_completion_type_formatter_delete(self):
736736
self.runCmd("type synthetic add -x Hoo -l test")
737737
self.complete_from_to("type synthetic delete ", ["Hoo"])
738738

739-
@skipIf(archs=no_match(["x86_64"]))
740-
def test_register_read_and_write_on_x86(self):
741-
"""Test the completion of the commands register read and write on x86"""
742-
739+
def test_register_no_complete(self):
743740
# The tab completion for "register read/write" won't work without a running process.
744741
self.complete_from_to("register read ", "register read ")
745742
self.complete_from_to("register write ", "register write ")
743+
self.complete_from_to("register info ", "register info ")
744+
745+
self.build()
746+
self.runCmd("target create {}".format(self.getBuildArtifact("a.out")))
747+
self.runCmd("run")
748+
749+
# Once a program has finished you have an execution context but no register
750+
# context so completion cannot work.
751+
self.complete_from_to("register read ", "register read ")
752+
self.complete_from_to("register write ", "register write ")
753+
self.complete_from_to("register info ", "register info ")
754+
755+
@skipIf(archs=no_match(["x86_64"]))
756+
def test_register_read_and_write_on_x86(self):
757+
"""Test the completion of the commands register read and write on x86"""
746758

747759
self.build()
748760
self.main_source_spec = lldb.SBFileSpec("main.cpp")

0 commit comments

Comments
 (0)