From fbaf36721783c3bcbd45f81294e6980eaef165e4 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Thu, 16 Sep 2021 16:26:49 -0300 Subject: [PATCH] [lldb] Show fix-it applied even if expression didn't evaluate succesfully If we applied a fix-it before evaluating an expression and that expression didn't evaluate correctly, we should still tell users about the fix-it we applied since that may be the reason why it didn't work correctly. Differential Revision: https://reviews.llvm.org/D109908 --- lldb/source/Commands/CommandObjectExpression.cpp | 5 ++--- lldb/test/API/commands/expression/fixits/TestFixIts.py | 16 ++++++++++++++++ lldb/test/API/commands/expression/fixits/main.cpp | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index bf62f3f2..a93cc15b 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -421,9 +421,8 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr, // We only tell you about the FixIt if we applied it. The compiler errors // will suggest the FixIt if it parsed. if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) { - if (success == eExpressionCompleted) - error_stream.Printf(" Fix-it applied, fixed expression was: \n %s\n", - m_fixed_expression.c_str()); + error_stream.Printf(" Fix-it applied, fixed expression was: \n %s\n", + m_fixed_expression.c_str()); } if (result_valobj_sp) { diff --git a/lldb/test/API/commands/expression/fixits/TestFixIts.py b/lldb/test/API/commands/expression/fixits/TestFixIts.py index a2e4564..686f56a 100644 --- a/lldb/test/API/commands/expression/fixits/TestFixIts.py +++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py @@ -82,6 +82,22 @@ class ExprCommandWithFixits(TestBase): error_string.find("my_pointer->second.a") != -1, "Fix was right") + def test_with_target_error_applies_fixit(self): + """ Check that applying a Fix-it which fails to execute correctly still + prints that the Fix-it was applied. """ + self.build() + (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'Stop here to evaluate expressions', + lldb.SBFileSpec("main.cpp")) + # Enable fix-its as they were intentionally disabled by TestBase.setUp. + self.runCmd("settings set target.auto-apply-fixits true") + ret_val = lldb.SBCommandReturnObject() + result = self.dbg.GetCommandInterpreter().HandleCommand("expression null_pointer.first", ret_val) + self.assertEqual(result, lldb.eReturnStatusFailed, ret_val.GetError()) + + self.assertIn("Fix-it applied, fixed expression was:", ret_val.GetError()) + self.assertIn("null_pointer->first", ret_val.GetError()) + # The final function call runs into SIGILL on aarch64-linux. @expectedFailureAll(archs=["aarch64"], oslist=["freebsd", "linux"], bugnumber="llvm.org/pr49407") diff --git a/lldb/test/API/commands/expression/fixits/main.cpp b/lldb/test/API/commands/expression/fixits/main.cpp index 371d833..0162ed2 100644 --- a/lldb/test/API/commands/expression/fixits/main.cpp +++ b/lldb/test/API/commands/expression/fixits/main.cpp @@ -17,6 +17,7 @@ main() { struct MyStruct my_struct = {10, {20, 30}}; struct MyStruct *my_pointer = &my_struct; + struct MyStruct *null_pointer = nullptr; printf ("Stop here to evaluate expressions: %d %d %p\n", my_pointer->first, my_pointer->second.a, my_pointer); return 0; } -- 2.7.4