From 10fd550d308d5dbcf7a3068f1f76d5f0f1a56661 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Wed, 15 Jul 2020 13:55:32 +0200 Subject: [PATCH] [lldb] Make expect_expr fall back to the dummy target if no target is selected Summary: Currently expect_expr will not run the expression if no target is selected. This patch changes this behavior so that expect_expr will instead fall back to the dummy target similar to what the `expression` command is doing. This way we don't have to compile an empty executable to be able to use `expect_expr` (which is a waste of resources for tests that just test generic type system features). As a test I modernized the TestTypeOfDeclTypeExpr into a Python test + expect_expr (as it relied on the dummy target fallback of the expression command). Reviewers: labath, JDevlieghere Reviewed By: labath Subscribers: abidh Differential Revision: https://reviews.llvm.org/D83388 --- lldb/packages/Python/lldbsuite/test/lldbtest.py | 7 ++++++- lldb/test/API/lang/cpp/typeof/TestTypeOfDeclTypeExpr.py | 14 ++++++++++++++ lldb/test/Shell/Expr/TestTypeOfDeclTypeExpr.test | 13 ------------- 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 lldb/test/API/lang/cpp/typeof/TestTypeOfDeclTypeExpr.py delete mode 100644 lldb/test/Shell/Expr/TestTypeOfDeclTypeExpr.test diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 9c32bdb..280e02f 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -2456,7 +2456,12 @@ FileCheck output: options.SetLanguage(frame.GuessLanguage()) eval_result = self.frame().EvaluateExpression(expr, options) else: - eval_result = self.target().EvaluateExpression(expr, options) + target = self.target() + # If there is no selected target, run the expression in the dummy + # target. + if not target.IsValid(): + target = self.dbg.GetDummyTarget() + eval_result = target.EvaluateExpression(expr, options) self.assertSuccess(eval_result.GetError()) diff --git a/lldb/test/API/lang/cpp/typeof/TestTypeOfDeclTypeExpr.py b/lldb/test/API/lang/cpp/typeof/TestTypeOfDeclTypeExpr.py new file mode 100644 index 0000000..9c5289c --- /dev/null +++ b/lldb/test/API/lang/cpp/typeof/TestTypeOfDeclTypeExpr.py @@ -0,0 +1,14 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + self.expect_expr("int i; __typeof__(i) j = 1; j", result_type="typeof (i)", result_value="1") + self.expect_expr("int i; typeof(i) j = 1; j", result_type="typeof (i)", result_value="1") + self.expect_expr("int i; decltype(i) j = 1; j", result_type="decltype(i)", result_value="1") diff --git a/lldb/test/Shell/Expr/TestTypeOfDeclTypeExpr.test b/lldb/test/Shell/Expr/TestTypeOfDeclTypeExpr.test deleted file mode 100644 index c156ae5..0000000 --- a/lldb/test/Shell/Expr/TestTypeOfDeclTypeExpr.test +++ /dev/null @@ -1,13 +0,0 @@ -# RUN: %lldb -b -s %s | FileCheck %s - -expression int i; __typeof__(i) j = 1; j -# CHECK: (lldb) expression int i; __typeof__(i) j = 1; j -# CHECK-NEXT: (typeof (i)) {{.*}} = 1 - -expression int i; typeof(i) j = 1; j -# CHECK: (lldb) expression int i; typeof(i) j = 1; j -# CHECK-NEXT: (typeof (i)) {{.*}} = 1 - -expression int i; decltype(i) j = 1; j -# CHECK: (lldb) expression int i; decltype(i) j = 1; j -# CHECK-NEXT: (decltype(i)) {{.*}} = 1 -- 2.7.4