[Lldb-commits] [PATCH] D151351: [lldb] Prevent dwim-print from showing kNoResult error

Dave Lee via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed May 24 10:36:37 PDT 2023


kastiglione created this revision.
kastiglione added reviewers: aprantl, jingham.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Expression evaluation for `void` valued expressions sets an error using the `kNoResult`
code. Like the `expression` command, `dwim-print` should also not print such errors.

Before:

  (lldb) dwim-print (void)printf("hi\n")
  hi
  Error: 'unknown error'

After:

  (lldb) dwim-print (void)printf("hi\n")
  hi

rdar://109746544


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151351

Files:
  lldb/source/Commands/CommandObjectDWIMPrint.cpp
  lldb/test/API/commands/dwim-print/TestDWIMPrint.py


Index: lldb/test/API/commands/dwim-print/TestDWIMPrint.py
===================================================================
--- lldb/test/API/commands/dwim-print/TestDWIMPrint.py
+++ lldb/test/API/commands/dwim-print/TestDWIMPrint.py
@@ -131,3 +131,9 @@
         self.runCmd("type summary add -e -s 'stub summary' Structure")
         self._expect_cmd(f"dwim-print s", "frame variable")
         self._expect_cmd(f"dwim-print (struct Structure)s", "expression")
+
+    def test_void_result(self):
+        """Test dwim-print does not surface an error message for void expressions."""
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c"))
+        self.expect("dwim-print (void)15", matching=False, patterns=["(?i)error"])
Index: lldb/source/Commands/CommandObjectDWIMPrint.cpp
===================================================================
--- lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -11,6 +11,7 @@
 #include "lldb/Core/ValueObject.h"
 #include "lldb/DataFormatters/DumpValueObjectOptions.h"
 #include "lldb/Expression/ExpressionVariable.h"
+#include "lldb/Expression/UserExpression.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandObject.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
@@ -135,7 +136,8 @@
                                         expr);
       }
 
-      valobj_sp->Dump(result.GetOutputStream(), dump_options);
+      if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
+        valobj_sp->Dump(result.GetOutputStream(), dump_options);
 
       if (suppress_result)
         if (auto result_var_sp =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151351.525252.patch
Type: text/x-patch
Size: 1710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230524/483274ce/attachment-0001.bin>


More information about the lldb-commits mailing list