This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Redefine p alias to dwim-print command
ClosedPublic

Authored by kastiglione on Mar 2 2023, 2:04 PM.

Details

Summary

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.

Diff Detail

Event Timeline

kastiglione created this revision.Mar 2 2023, 2:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2023, 2:04 PM
kastiglione requested review of this revision.Mar 2 2023, 2:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2023, 2:04 PM

So, one could say that (right now) this patch is NFC for end-users, because dwim-print supports all use-cases that the old p alias supported?

aprantl accepted this revision.Mar 2 2023, 2:17 PM

So from my point of view, this is a good path forward, so assuming that the other reviewers agree, this LGTM.

This revision is now accepted and ready to land.Mar 2 2023, 2:17 PM

So, one could say that (right now) this patch is NFC for end-users, because dwim-print supports all use-cases that the old p alias supported?

Correct.

This revision was automatically updated to reflect the committed changes.