[Lldb-commits] [lldb] fbaf367 - [lldb] Show fix-it applied even if expression didn't evaluate succesfully

Augusto Noronha via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 23 12:46:00 PDT 2021


Author: Augusto Noronha
Date: 2021-09-23T16:45:04-03:00
New Revision: fbaf36721783c3bcbd45f81294e6980eaef165e4

URL: https://github.com/llvm/llvm-project/commit/fbaf36721783c3bcbd45f81294e6980eaef165e4
DIFF: https://github.com/llvm/llvm-project/commit/fbaf36721783c3bcbd45f81294e6980eaef165e4.diff

LOG: [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

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectExpression.cpp
    lldb/test/API/commands/expression/fixits/TestFixIts.py
    lldb/test/API/commands/expression/fixits/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index bf62f3f297cc..a93cc15b0ff3 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 a2e4564f7078..686f56ad7974 100644
--- a/lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -82,6 +82,22 @@ def test_with_target(self):
             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 371d8333763b..0162ed24bd84 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;
 }


        


More information about the lldb-commits mailing list