Skip to content

Conversation

@mdko
Copy link
Contributor

@mdko mdko commented Aug 22, 2025

People on my team coming from GDB continually try to use "inspect" to examine data, but this command doesn't exist. In GDB, "inspect" is a synonym for "print" (https://sourceware.org/gdb/current/onlinedocs/gdb.html/Data.html#Data), so I thought it was help with ergonomics if we additionally had an "inspect" alias in LLDB (mapping to "dwim-print", which is what LLDB's "print" alias maps to as well).

michristensen@my-machine build/Debug (inspect-alias-dwim) » ./bin/lldb
(lldb) help inspect
Print a variable or expression.  Expects 'raw' input (see 'help raw-input'.)

Syntax: inspect <variable-name>
  inspect <variable-name>
'inspect' is an abbreviation for 'dwim-print --'
(lldb) inspect 3+4
(int) 7

@mdko mdko requested a review from JDevlieghere as a code owner August 22, 2025 22:08
@llvmbot llvmbot added the lldb label Aug 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 22, 2025

@llvm/pr-subscribers-lldb

Author: Michael Christensen (mdko)

Changes

People on my team coming from GDB continually try to use "inspect" to examine data, but this command doesn't exist. In GDB, "inspect" is a synonym for "print" (https://sourceware.org/gdb/current/onlinedocs/gdb.html/Data.html#Data), so I thought it was help with ergonomics if we additionally had an "inspect" alias in LLDB (mapping to "dwim-print", which is what LLDB's "print" alias maps to as well).


Full diff: https://github.com/llvm/llvm-project/pull/155039.diff

2 Files Affected:

  • (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+1)
  • (modified) lldb/test/API/commands/dwim-print/TestDWIMPrint.py (+13)
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 650b754fd8ace..7ebcba6ffc8c9 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -432,6 +432,7 @@ void CommandInterpreter::Initialize() {
   if (cmd_obj_sp) {
     AddAlias("p", cmd_obj_sp, "--")->SetHelpLong("");
     AddAlias("print", cmd_obj_sp, "--")->SetHelpLong("");
+    AddAlias("inspect", cmd_obj_sp, "--")->SetHelpLong("");
     if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) {
       po->SetHelp("Evaluate an expression on the current thread.  Displays any "
                   "returned value with formatting "
diff --git a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py
index 492d49f008a9e..d1ebdc1eb1564 100644
--- a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py
+++ b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py
@@ -185,3 +185,16 @@ def test_direct_child_access(self):
             self, "break inside", lldb.SBFileSpec("main.cpp")
         )
         self._expect_cmd("dwim-print number", "frame variable")
+
+    def test_aliases(self):
+        interp = self.dbg.GetCommandInterpreter()
+        for alias in ["p", "print", "inspect"]:
+            result = lldb.SBCommandReturnObject()
+            interp.ResolveCommand(alias, result)
+            self.assertTrue(result.Succeeded(), result.GetError())
+            self.assertEqual(result.GetOutput(), "dwim-print --")
+
+        result = lldb.SBCommandReturnObject()
+        interp.ResolveCommand("po", result)
+        self.assertTrue(result.Succeeded(), result.GetError())
+        self.assertEqual(result.GetOutput(), "dwim-print -O  --")

@mdko
Copy link
Contributor Author

mdko commented Aug 22, 2025

@jimingham
Copy link
Collaborator

This seems a slippery slope. gdb generally has 3 or 4 different ways of spelling every command; I really don't want to add them all to lldb and make it harder to spell the native lldb commands. The lldb command set isn't that hard to learn...

I'm not super excited about adding this, but in any case I'd really rather not have this or any future additions of this sort be on by default. If we feel we really need to do this, then we should add an interpreter.emulate-gdb setting and have these additions gated by that. We should also make sure i is image not inspect so we don't make people have to change what they have been typing.

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add this for all lldb users.

@mdko
Copy link
Contributor Author

mdko commented Aug 23, 2025

@jimingham Fair point, thanks for the quick feedback. I will abandon these changes and stick with making this a local alias.

@mdko mdko closed this Aug 23, 2025
facebook-github-bot pushed a commit to facebook/hhvm that referenced this pull request Aug 28, 2025
Summary:
Add the commands* I added to the gdb-translator (D81056005) as actual aliases:
```
show {env,args}
unset
return
inspect
where
backtrace
info {break, threads, registers, all-registers, proc mappings, shared}
dump memory
```

If these are fine/useful, we can add them to the wider Meta-set of aliases later on. Note that I did try to add "inspect" to upstream, but was rejected (llvm/llvm-project#155039). So adding these as HHVM-usable, then possibly company-wide aliases, for now.

*I can't add things like "thread N", "frame N", or "set ..." since their prefixes are already commands in LLDB, and it would be pretty invasive to make a larger wrapper command right now. Note that LLDB already ships with "t N" and "f N" aliasing to "thread select N" and "frame select N".

Reviewed By: nt591

Differential Revision: D81153595

fbshipit-source-id: 0f9f3b58fd680715236297be60223244d62f7291
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants