Skip to content

Commit 9f55dcf

Browse files
committed
[lldb] Redefine p alias to dwim-print command
Redefine the `p` alias to the `dwim-print` command instead of `expression`. See https://reviews.llvm.org/D138315 for the introduction of `dwim-print`. To summarize, `dwim-print` is, as the name suggests, a command for printing. How a value gets printed, is decided by `dwim-print`. In some cases, `dwim-print` will print values using the same means as `frame variable` (because it's generally more reliable and faster that `expression` evaluation), and in other cases `dwim-print` uses the same code path as `expression`. This change has been tested in two different ways: 1. Re-aliasing `p` to `dwim-print`, as in this patch 2. Redefinining the `expression` command to `CommandObjectDWIMPrint` Previously, many of the lldb's tests used `p`, and which meant a test run with `p` aliases to `dwim-print` was a good way to test `dwim-print`. However most of those tests were updated to use `expression` explicitly (in anticipation of this change). Now, the best way to test `dwim-print` is the second approach: ``` diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 373c894f34f5..9c943cd30c7c 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -539,7 +539,7 @@ void CommandInterpreter::LoadCommandDictionary() { REGISTER_COMMAND_OBJECT("diagnostics", CommandObjectDiagnostics); REGISTER_COMMAND_OBJECT("disassemble", CommandObjectDisassemble); REGISTER_COMMAND_OBJECT("dwim-print", CommandObjectDWIMPrint); - REGISTER_COMMAND_OBJECT("expression", CommandObjectExpression); + REGISTER_COMMAND_OBJECT("expression", CommandObjectDWIMPrint); REGISTER_COMMAND_OBJECT("frame", CommandObjectMultiwordFrame); REGISTER_COMMAND_OBJECT("gui", CommandObjectGUI); REGISTER_COMMAND_OBJECT("help", CommandObjectHelp); ``` When the test suite is run with this change, there are two main categories of test failures for specific to features that `dwim-print` intentionally doesn't support: 1. Top level expressions (`--top-level`/`-p`) 2. Multiline expressions In cases where the behavior of `expression` is needed, users can use `expression` at those times. Differential Revision: https://reviews.llvm.org/D145189 (cherry picked from commit a00801d)
1 parent 46b0845 commit 9f55dcf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,24 +412,21 @@ void CommandInterpreter::Initialize() {
412412

413413
alias_arguments_vector_sp = std::make_shared<OptionArgVector>();
414414

415-
cmd_obj_sp = GetCommandSPExact("expression");
415+
cmd_obj_sp = GetCommandSPExact("dwim-print");
416416
if (cmd_obj_sp) {
417417
AddAlias("p", cmd_obj_sp, "--")->SetHelpLong("");
418418
AddAlias("print", cmd_obj_sp, "--")->SetHelpLong("");
419-
AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
420419
if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) {
421420
po->SetHelp("Evaluate an expression on the current thread. Displays any "
422421
"returned value with formatting "
423422
"controlled by the type's author.");
424423
po->SetHelpLong("");
425424
}
425+
}
426426

427-
#ifdef LLDB_ENABLE_SWIFT
428-
// FIXME: Upstream the REPL command together with support for a default
429-
// language, similar to what exists for scripting.
430-
AddAlias("repl", cmd_obj_sp, "--repl --language swift -- ");
431-
#endif
432-
427+
cmd_obj_sp = GetCommandSPExact("expression");
428+
if (cmd_obj_sp) {
429+
AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
433430
CommandAlias *parray_alias =
434431
AddAlias("parray", cmd_obj_sp, "--element-count %1 --");
435432
if (parray_alias) {
@@ -447,6 +444,12 @@ void CommandInterpreter::Initialize() {
447444
"objects in memory, and will call po on them.");
448445
poarray_alias->SetHelpLong("");
449446
}
447+
448+
#ifdef LLDB_ENABLE_SWIFT
449+
// FIXME: Upstream the REPL command together with support for a default
450+
// language, similar to what exists for scripting.
451+
AddAlias("repl", cmd_obj_sp, "--repl --language swift -- ");
452+
#endif
450453
}
451454

452455
cmd_obj_sp = GetCommandSPExact("platform shell");

0 commit comments

Comments
 (0)