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 =
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 =
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits