[Lldb-commits] [lldb] 91728b9 - [lldb] Don't print IRForTarget errors directly to the console

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 12 01:27:57 PDT 2020


Author: Raphael Isemann
Date: 2020-06-12T10:27:25+02:00
New Revision: 91728b9172bfd2a2eccc9dc2ef3462f931579aff

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

LOG: [lldb] Don't print IRForTarget errors directly to the console

Summary:

When we get an error back from IRForTarget we directly print that error to the
debugger output stream instead of putting it in the result object. The result
object only gets a vague "The expression could not be prepared to run in the
target" error message that doesn't actually tell the user what went wrong.

This patch just puts the IRForTarget errors into the status object that is
returned to the caller instead of directly printing it to the debugger. Also
updates one test that now can actually check for the error message it is
supposed to check for (instead of the default error which is all we had before).

Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D81654

Added: 
    

Modified: 
    lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/test/API/lang/objc/modules-non-objc-target/TestObjCModulesNonObjCTarget.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 14dd0656bf82..90dfbe288767 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -1323,18 +1323,13 @@ lldb_private::Status ClangExpressionParser::PrepareForExecution(
       type_system_helper->DeclMap(); // result can be NULL
 
   if (decl_map) {
-    Target *target = exe_ctx.GetTargetPtr();
-    auto &error_stream = target->GetDebugger().GetErrorStream();
+    StreamString error_stream;
     IRForTarget ir_for_target(decl_map, m_expr.NeedsVariableResolution(),
                               *execution_unit_sp, error_stream,
                               function_name.AsCString());
 
-    bool ir_can_run =
-        ir_for_target.runOnModule(*execution_unit_sp->GetModule());
-
-    if (!ir_can_run) {
-      err.SetErrorString(
-          "The expression could not be prepared to run in the target");
+    if (!ir_for_target.runOnModule(*execution_unit_sp->GetModule())) {
+      err.SetErrorString(error_stream.GetString());
       return err;
     }
 

diff  --git a/lldb/test/API/lang/objc/modules-non-objc-target/TestObjCModulesNonObjCTarget.py b/lldb/test/API/lang/objc/modules-non-objc-target/TestObjCModulesNonObjCTarget.py
index 18283f6d2b33..42d852f5763e 100644
--- a/lldb/test/API/lang/objc/modules-non-objc-target/TestObjCModulesNonObjCTarget.py
+++ b/lldb/test/API/lang/objc/modules-non-objc-target/TestObjCModulesNonObjCTarget.py
@@ -23,4 +23,4 @@ def test(self):
         # be prepared to run in the target but it should at least not crash LLDB.
         self.expect('expr --lang objc -- [NSString stringWithFormat:@"%d", 1];',
                     error=True,
-                    substrs=["error: The expression could not be prepared to run in the target"])
+                    substrs=["Rewriting an Objective-C constant string requires CFStringCreateWithBytes"])


        


More information about the lldb-commits mailing list