[Lldb-commits] [lldb] [lldb] Add actionable feedback when overwriting a command fails (PR #76030)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Dec 20 01:37:43 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Felipe de Azevedo Piovezan (felipepiovezan)
<details>
<summary>Changes</summary>
If adding a user commands fails because a command with the same name already exists, we only say that "force replace is not set" without telling the user _how_ to set it. There are two ways to do so; this commit changes the error message to mention both.
---
Full diff: https://github.com/llvm/llvm-project/pull/76030.diff
2 Files Affected:
- (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+3-1)
- (modified) lldb/test/API/commands/command/script/TestCommandScript.py (+11)
``````````diff
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index e1275ce711fc17..3d5ecd0612a640 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1160,7 +1160,9 @@ Status CommandInterpreter::AddUserCommand(llvm::StringRef name,
if (UserCommandExists(name)) {
if (!can_replace) {
- result.SetErrorString("user command exists and force replace not set");
+ result.SetErrorString(
+ "user command exists and force replace not set by --overwrite or "
+ "'settings set interpreter.require-overwrite false'");
return result;
}
if (cmd_sp->IsMultiwordObject()) {
diff --git a/lldb/test/API/commands/command/script/TestCommandScript.py b/lldb/test/API/commands/command/script/TestCommandScript.py
index cac11834fa7364..1e1d9b728a965d 100644
--- a/lldb/test/API/commands/command/script/TestCommandScript.py
+++ b/lldb/test/API/commands/command/script/TestCommandScript.py
@@ -161,6 +161,17 @@ def cleanup():
)
self.expect("my_command", substrs=["a.out"])
+ # Test that without --overwrite we are not allowed to redefine the command.
+ self.expect(
+ "command script add my_command --class welcome.TargetnameCommand",
+ substrs=[
+ "cannot add command: user command exists and force replace not set",
+ "--overwrite",
+ "settings set interpreter.require-overwrite false",
+ ],
+ error=True,
+ )
+
self.runCmd("command script clear")
self.expect(
``````````
</details>
https://github.com/llvm/llvm-project/pull/76030
More information about the lldb-commits
mailing list