[Lldb-commits] [PATCH] D53010: Add an alias "var" for "frame var" and "vo" for "frame var -O"

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 8 18:42:53 PDT 2018

jingham created this revision.
Herald added subscribers: lldb-commits, abidh.

"expression" is a hugely inefficient way to get the value of a local variable.  There are a few cases where "frame variable" and "expression" will produce different results on the same expression (e.g. "foo->bar" when foo has an -> operator overload).  But in general, if you are printing a local var, "frame var" is way more efficient.  I've been trying to teach people to use 'frame var' more when it is appropriate, and it was suggested that adding a top-level alias for it might make the command easier to find and remember.

This patch adds two aliases:

var - frame var
vo  - frame var -O

The latter is for our ObjC friends who often see the object description, rather than the object's ivars, as the primary source of information about the object.

I also added some caveats to the frame var help page.




Index: source/Interpreter/CommandInterpreter.cpp
--- source/Interpreter/CommandInterpreter.cpp
+++ source/Interpreter/CommandInterpreter.cpp
@@ -386,6 +386,13 @@
   if (cmd_obj_sp) {
     AddAlias("rbreak", cmd_obj_sp, "--func-regex %1");
+  cmd_obj_sp = GetCommandSPExact("frame variable", false);
+  if (cmd_obj_sp) {
+    AddAlias("var", cmd_obj_sp);
+    AddAlias("vo", cmd_obj_sp, "--object-description");
+  }
 void CommandInterpreter::Clear() {
Index: source/Commands/CommandObjectFrame.cpp
--- source/Commands/CommandObjectFrame.cpp
+++ source/Commands/CommandObjectFrame.cpp
@@ -427,7 +427,17 @@
             "arguments and local variables in scope. Names of argument, "
             "local, file static and file global variables can be specified. "
             "Children of aggregate variables can be specified such as "
-            "'var->child.x'.",
+            "'var->child.x'.  The -> and [] operators in 'frame variable' do "
+            "not invoke operator overloads if they exist, but directly access "
+            "the specified element.  If you want to trigger operator overloads "
+            "use the expression command to print the variable instead."
+            "\nIt is worth noting that except for overloaded "
+            "operators, when printing local variables 'expr local_var' and "
+            "'frame var local_var' produce the same "
+            "results.  However, 'frame variable' is more efficient, since it "
+            "uses debug information and memory reads directly, rather than "
+            "parsing and evaluating an expression, which may even involve "
+            "JITing and running code in the target program.",
             nullptr, eCommandRequiresFrame | eCommandTryTargetAPILock |
                          eCommandProcessMustBeLaunched |
                          eCommandProcessMustBePaused | eCommandRequiresProcess),

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53010.168742.patch
Type: text/x-patch
Size: 2040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181009/e8f697cb/attachment.bin>

More information about the lldb-commits mailing list