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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfbaf36721783: [lldb] Show fix-it applied even if expression didn't evaluate succesfully (authored by augusto2112).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109908/new/

https://reviews.llvm.org/D109908

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


Index: lldb/test/API/commands/expression/fixits/main.cpp
===================================================================
--- lldb/test/API/commands/expression/fixits/main.cpp
+++ lldb/test/API/commands/expression/fixits/main.cpp
@@ -17,6 +17,7 @@
 {
   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;
 }
Index: lldb/test/API/commands/expression/fixits/TestFixIts.py
===================================================================
--- lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -82,6 +82,22 @@
             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")
Index: lldb/source/Commands/CommandObjectExpression.cpp
===================================================================
--- lldb/source/Commands/CommandObjectExpression.cpp
+++ lldb/source/Commands/CommandObjectExpression.cpp
@@ -421,9 +421,8 @@
   // 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109908.374650.patch
Type: text/x-patch
Size: 2850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210923/130d4c3a/attachment.bin>


More information about the lldb-commits mailing list