[Lldb-commits] [PATCH] D91723: [lldb] Fix that running a top level expression without a process fails with a cryptic error

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 11 08:07:36 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG71536fd03108: [lldb] Fix that running a top level expression without a process fails with a… (authored by teemperor).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91723

Files:
  lldb/source/Expression/UserExpression.cpp
  lldb/test/API/commands/expression/static-initializers/TestStaticInitializers.py
  lldb/test/API/commands/expression/top-level/TestTopLevelExprs.py
  lldb/test/API/lang/cpp/elaborated-types/TestElaboratedTypes.py


Index: lldb/test/API/lang/cpp/elaborated-types/TestElaboratedTypes.py
===================================================================
--- lldb/test/API/lang/cpp/elaborated-types/TestElaboratedTypes.py
+++ lldb/test/API/lang/cpp/elaborated-types/TestElaboratedTypes.py
@@ -34,7 +34,7 @@
         # Declare a template that can actually be instantiated.
         # FIXME: The error message here is incorrect.
         self.expect("expr --top-level -- template<typename T> struct $V {};",
-                    error=True, substrs=["Couldn't find $__lldb_expr() in the module"])
+                    error=True, substrs=["Top-level code needs to be inserted into a runnable target"])
         result = self.expect_expr("$V<::Struct> s; s",
                                   result_type="$V< ::Struct>")
         self.assertEqual(result.GetTypeName(), "$V<Struct>")
Index: lldb/test/API/commands/expression/top-level/TestTopLevelExprs.py
===================================================================
--- lldb/test/API/commands/expression/top-level/TestTopLevelExprs.py
+++ lldb/test/API/commands/expression/top-level/TestTopLevelExprs.py
@@ -91,3 +91,14 @@
         self.assertEqual(
             resultFromCode,
             resultFromTopLevel.GetValueAsUnsigned())
+
+    def test_top_level_expression_without_target(self):
+        self.expect("expr --top-level -- void func() {}", error=True,
+                    substrs=["Top-level code needs to be inserted into a runnable target"])
+
+        # FIXME: This doesn't actually generate any code, so LLDB should probably
+        # allow these expressions.
+        self.expect("expr --top-level -- template<typename T> struct StructT { T m; };", error=True,
+                    substrs=["Top-level code needs to be inserted into a runnable target"])
+        self.expect("expr --top-level -- struct Struct { int i; };", error=True,
+                    substrs=["Top-level code needs to be inserted into a runnable target"])
Index: lldb/test/API/commands/expression/static-initializers/TestStaticInitializers.py
===================================================================
--- lldb/test/API/commands/expression/static-initializers/TestStaticInitializers.py
+++ lldb/test/API/commands/expression/static-initializers/TestStaticInitializers.py
@@ -31,3 +31,8 @@
         # 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 initializer:"])
+
+    def test_without_process(self):
+        """ Test a static initializer without a running process. """
+        self.expect("expr -p -- int i = 0; struct Foo3 { Foo3() { ++i; } }; Foo3 f;", error=True,
+                    substrs=["Top-level code needs to be inserted into a runnable target"])
Index: lldb/source/Expression/UserExpression.cpp
===================================================================
--- lldb/source/Expression/UserExpression.cpp
+++ lldb/source/Expression/UserExpression.cpp
@@ -187,7 +187,12 @@
     }
   }
 
-  if (process == nullptr || !process->CanJIT())
+  // Explicitly force the IR interpreter to evaluate the expression when the
+  // there is no process that supports running the expression for us. Don't
+  // change the execution policy if we have the special top-level policy that
+  // doesn't contain any expression and there is nothing to interpret.
+  if (execution_policy != eExecutionPolicyTopLevel &&
+      (process == nullptr || !process->CanJIT()))
     execution_policy = eExecutionPolicyNever;
 
   // We need to set the expression execution thread here, turns out parse can


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91723.323027.patch
Type: text/x-patch
Size: 3697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210211/43dea2bd/attachment.bin>


More information about the lldb-commits mailing list