From 70a21887f7bd0b38e7c0676d8b25cc8a9980e009 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Tue, 9 Jun 2020 14:47:14 +0200 Subject: [PATCH] [lldb] Test compatibility between a class type from a member function expr and its original version --- .../API/lang/cpp/this_class_type_mixing/Makefile | 3 ++ .../TestThisClassTypeMixing.py | 42 ++++++++++++++++++++++ .../API/lang/cpp/this_class_type_mixing/main.cpp | 11 ++++++ 3 files changed, 56 insertions(+) create mode 100644 lldb/test/API/lang/cpp/this_class_type_mixing/Makefile create mode 100644 lldb/test/API/lang/cpp/this_class_type_mixing/TestThisClassTypeMixing.py create mode 100644 lldb/test/API/lang/cpp/this_class_type_mixing/main.cpp diff --git a/lldb/test/API/lang/cpp/this_class_type_mixing/Makefile b/lldb/test/API/lang/cpp/this_class_type_mixing/Makefile new file mode 100644 index 0000000..99998b2 --- /dev/null +++ b/lldb/test/API/lang/cpp/this_class_type_mixing/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/lang/cpp/this_class_type_mixing/TestThisClassTypeMixing.py b/lldb/test/API/lang/cpp/this_class_type_mixing/TestThisClassTypeMixing.py new file mode 100644 index 0000000..8b09332 --- /dev/null +++ b/lldb/test/API/lang/cpp/this_class_type_mixing/TestThisClassTypeMixing.py @@ -0,0 +1,42 @@ +""" +Tests using a class type that originated from a member function evaluation +with the same class type outside a member function. + +When evaluating expressions in a class, LLDB modifies the type of the current +class by injecting a "$__lldb_expr" member function into the class. This +function should not cause the type to become incompatible with its original +definition without the "$__lldb_expr" member. +""" + +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.build() + lldbutil.run_to_source_breakpoint(self, "// break in member function", + lldb.SBFileSpec("main.cpp")) + + # Evaluate an expression in a member function. Store the type of the + # 'this' pointer in a persistent variable. + self.expect_expr("A $p = *this; $p", result_type="A") + + breakpoint = self.target().BreakpointCreateBySourceRegex( + "// break in main", lldb.SBFileSpec("main.cpp")) + self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0) + threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint) + self.assertEqual(len(threads), 1) + + # Evaluate expressions in the main function. Use the persistent type + # of "A" that came from an evaluation in a member function with a + # normal "A" type and make sure that LLDB can still evaluate + # expressions that reference both types at the same time. + self.expect_expr("$p.i + a.i", result_type="int", result_value="2") + self.expect_expr("a.i + $p.i", result_type="int", result_value="2") + self.expect_expr("a = $p; a.i", result_type="int", result_value="1") diff --git a/lldb/test/API/lang/cpp/this_class_type_mixing/main.cpp b/lldb/test/API/lang/cpp/this_class_type_mixing/main.cpp new file mode 100644 index 0000000..d76b7cb --- /dev/null +++ b/lldb/test/API/lang/cpp/this_class_type_mixing/main.cpp @@ -0,0 +1,11 @@ +struct A { + int i = 1; + int member_method() { + return i; // break in member function + } +}; +int main() { + A a; + int i = a.member_method(); + return i; // break in main +} -- 2.7.4