[Lldb-commits] [PATCH] D70433: [lldb] Improve error message when running static initialisers in expression fails

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 19 04:41:29 PST 2019


teemperor created this revision.
teemperor added a reviewer: jingham.
Herald added subscribers: lldb-commits, JDevlieghere.
Herald added a project: LLDB.

The current error message is current `error: couldn't run static initializers: couldn't run static initializer: ` which
just doesn't make a lot of sense.

This patch removes the duplicate error message and tries to improve the error message (at least for this test
case).


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D70433

Files:
  lldb/packages/Python/lldbsuite/test/commands/expression/static-initializers/TestStaticInitializers.py
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Target/Process.cpp


Index: lldb/source/Target/Process.cpp
===================================================================
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -5304,13 +5304,14 @@
           }
         } while (false);
 
+        std::string error = s.GetString();
         if (event_explanation)
-          LLDB_LOGF(log,
-                    "Process::RunThreadPlan(): execution interrupted: %s %s",
-                    s.GetData(), event_explanation);
-        else
-          LLDB_LOGF(log, "Process::RunThreadPlan(): execution interrupted: %s",
-                    s.GetData());
+          error += " " + std::string(event_explanation);
+
+        diagnostic_manager.PutString(eDiagnosticSeverityError,
+                                     "Execution interrupted: " + error);
+        LLDB_LOGF(log, "Process::RunThreadPlan(): execution interrupted: %s",
+                  error.c_str());
       }
 
       if (should_unwind) {
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -658,7 +658,7 @@
       const char *error_cstr = static_init_error.AsCString();
       if (error_cstr && error_cstr[0])
         diagnostic_manager.Printf(eDiagnosticSeverityError,
-                                  "couldn't run static initializers: %s\n",
+                                  "couldn't run static initializers:\n%s\n",
                                   error_cstr);
       else
         diagnostic_manager.PutString(eDiagnosticSeverityError,
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -1378,8 +1378,10 @@
             exe_ctx, call_static_initializer, options, execution_errors);
 
     if (results != lldb::eExpressionCompleted) {
-      err.SetErrorStringWithFormat("couldn't run static initializer: %s",
-                                   execution_errors.GetString().c_str());
+      if (execution_errors.Diagnostics().empty())
+        err.SetErrorStringWithFormatv("ExpressionResults: {0}", results);
+      else
+        err.SetErrorStringWithFormatv("{0}", execution_errors.GetString());
       return err;
     }
   }
Index: lldb/packages/Python/lldbsuite/test/commands/expression/static-initializers/TestStaticInitializers.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/commands/expression/static-initializers/TestStaticInitializers.py
+++ lldb/packages/Python/lldbsuite/test/commands/expression/static-initializers/TestStaticInitializers.py
@@ -26,6 +26,5 @@
         lldbutil.run_to_source_breakpoint(self, '// break here',
                 lldb.SBFileSpec("main.cpp", False))
 
-        # FIXME: This error message is not even remotely helpful.
         self.expect("expr -p -- struct Foo2 { Foo2() { do_abort(); } }; Foo2 f;", error=True,
-                    substrs=["error: couldn't run static initializers: couldn't run static initializer:"])
+                    substrs=["error: couldn't run static initializers:\nerror: Execution interrupted: "])


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70433.230020.patch
Type: text/x-patch
Size: 3445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191119/aabef90e/attachment-0001.bin>


More information about the lldb-commits mailing list