[Lldb-commits] [lldb] 70a2188 - [lldb] Test compatibility between a class type from a member function expr and its original version
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 9 06:50:14 PDT 2020
Author: Raphael Isemann
Date: 2020-06-09T15:48:00+02:00
New Revision: 70a21887f7bd0b38e7c0676d8b25cc8a9980e009
URL: https://github.com/llvm/llvm-project/commit/70a21887f7bd0b38e7c0676d8b25cc8a9980e009
DIFF: https://github.com/llvm/llvm-project/commit/70a21887f7bd0b38e7c0676d8b25cc8a9980e009.diff
LOG: [lldb] Test compatibility between a class type from a member function expr and its original version
Added:
lldb/test/API/lang/cpp/this_class_type_mixing/Makefile
lldb/test/API/lang/cpp/this_class_type_mixing/TestThisClassTypeMixing.py
lldb/test/API/lang/cpp/this_class_type_mixing/main.cpp
Modified:
Removed:
################################################################################
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 000000000000..99998b20bcb0
--- /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 000000000000..8b09332af3f5
--- /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 000000000000..d76b7cb29b1b
--- /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
+}
More information about the lldb-commits
mailing list