Author: Dave Lee Date: 2023-05-30T15:38:42-07:00 New Revision: 061a839033dc5f11c4e43fb64ed49cc85e1e5f32
URL: https://github.com/llvm/llvm-project/commit/061a839033dc5f11c4e43fb64ed49cc85e1e5f32 DIFF: https://github.com/llvm/llvm-project/commit/061a839033dc5f11c4e43fb64ed49cc85e1e5f32.diff LOG: [lldb] Prevent dwim-print from showing kNoResult error 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 Differential Revision: https://reviews.llvm.org/D151351 Added: Modified: lldb/source/Commands/CommandObjectDWIMPrint.cpp lldb/test/API/commands/dwim-print/TestDWIMPrint.py Removed: ################################################################################ diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp index 8fc702a1a220e..7cb95fd622ba1 100644 --- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp +++ b/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 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command, 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 = diff --git a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py index f2799ef53d49c..9cb99a2a817d6 100644 --- a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py +++ b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py @@ -138,3 +138,9 @@ def test_summary_strings(self): 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"]) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits