DavidSpickett created this revision. Herald added subscribers: pengfei, kristof.beyls. Herald added a project: All. DavidSpickett requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
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" there as well. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D154413 Files: lldb/source/Commands/CommandCompletions.cpp lldb/test/API/functionalities/completion/TestCompletion.py Index: lldb/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -736,13 +736,25 @@ self.runCmd("type synthetic add -x Hoo -l test") self.complete_from_to("type synthetic delete ", ["Hoo"]) - @skipIf(archs=no_match(["x86_64"])) - def test_register_read_and_write_on_x86(self): - """Test the completion of the commands register read and write on x86""" - + def test_register_no_complete(self): # The tab completion for "register read/write" won't work without a running process. self.complete_from_to("register read ", "register read ") self.complete_from_to("register write ", "register write ") + self.complete_from_to("register info ", "register info ") + + self.build() + self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) + self.runCmd("run") + + # Once a program has finished you have an execution context but no register + # context so completion cannot work. + self.complete_from_to("register read ", "register read ") + self.complete_from_to("register write ", "register write ") + self.complete_from_to("register info ", "register info ") + + @skipIf(archs=no_match(["x86_64"])) + def test_register_read_and_write_on_x86(self): + """Test the completion of the commands register read and write on x86""" self.build() self.main_source_spec = lldb.SBFileSpec("main.cpp") Index: lldb/source/Commands/CommandCompletions.cpp =================================================================== --- lldb/source/Commands/CommandCompletions.cpp +++ lldb/source/Commands/CommandCompletions.cpp @@ -611,6 +611,9 @@ RegisterContext *reg_ctx = interpreter.GetExecutionContext().GetRegisterContext(); + if (!reg_ctx) + return; + const size_t reg_num = reg_ctx->GetRegisterCount(); for (size_t reg_idx = 0; reg_idx < reg_num; ++reg_idx) { const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
Index: lldb/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -736,13 +736,25 @@ self.runCmd("type synthetic add -x Hoo -l test") self.complete_from_to("type synthetic delete ", ["Hoo"]) - @skipIf(archs=no_match(["x86_64"])) - def test_register_read_and_write_on_x86(self): - """Test the completion of the commands register read and write on x86""" - + def test_register_no_complete(self): # The tab completion for "register read/write" won't work without a running process. self.complete_from_to("register read ", "register read ") self.complete_from_to("register write ", "register write ") + self.complete_from_to("register info ", "register info ") + + self.build() + self.runCmd("target create {}".format(self.getBuildArtifact("a.out"))) + self.runCmd("run") + + # Once a program has finished you have an execution context but no register + # context so completion cannot work. + self.complete_from_to("register read ", "register read ") + self.complete_from_to("register write ", "register write ") + self.complete_from_to("register info ", "register info ") + + @skipIf(archs=no_match(["x86_64"])) + def test_register_read_and_write_on_x86(self): + """Test the completion of the commands register read and write on x86""" self.build() self.main_source_spec = lldb.SBFileSpec("main.cpp") Index: lldb/source/Commands/CommandCompletions.cpp =================================================================== --- lldb/source/Commands/CommandCompletions.cpp +++ lldb/source/Commands/CommandCompletions.cpp @@ -611,6 +611,9 @@ RegisterContext *reg_ctx = interpreter.GetExecutionContext().GetRegisterContext(); + if (!reg_ctx) + return; + const size_t reg_num = reg_ctx->GetRegisterCount(); for (size_t reg_idx = 0; reg_idx < reg_num; ++reg_idx) { const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits