summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method')
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/Makefile6
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py82
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp18
3 files changed, 106 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/Makefile
new file mode 100644
index 00000000000..31f2d5e8fc2
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
+
+clean::
+ rm -rf $(wildcard *.o *.d *.dSYM)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py
new file mode 100644
index 00000000000..57987c8cb36
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py
@@ -0,0 +1,82 @@
+"""
+Test calling an overriden method.
+
+Note:
+ This verifies that LLDB is correctly building the method overrides table.
+ If this table is not built correctly then calls to overridden methods in
+ derived classes may generate references to non-existant vtable entries,
+ as the compiler treats the overridden method as a totally new virtual
+ method definition.
+ <rdar://problem/14205774>
+
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class ExprCommandCallOverriddenMethod(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break for main.c.
+ self.line = line_number('main.cpp', '// Set breakpoint here')
+
+ def test_call_on_base(self):
+ """Test calls to overridden methods in derived classes."""
+ self.build()
+
+ # Set breakpoint in main and run exe
+ self.runCmd("file " + self.getBuildArtifact("a.out"),
+ CURRENT_EXECUTABLE_SET)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Test call to method in base class (this should always work as the base
+ # class method is never an override).
+ self.expect("expr b->foo()", substrs=["= 2"])
+
+ # Test calling the base class.
+ self.expect("expr realbase.foo()", substrs=["= 1"])
+
+ @skipIfLinux # Returns wrong result code on some platforms.
+ def test_call_on_derived(self):
+ """Test calls to overridden methods in derived classes."""
+ self.build()
+
+ # Set breakpoint in main and run exe
+ self.runCmd("file " + self.getBuildArtifact("a.out"),
+ CURRENT_EXECUTABLE_SET)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Test call to overridden method in derived class (this will fail if the
+ # overrides table is not correctly set up, as Derived::foo will be assigned
+ # a vtable entry that does not exist in the compiled program).
+ self.expect("expr d.foo()", substrs=["= 2"])
+
+ @skipIf(oslist=["linux"], archs=["aarch64"])
+ @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr43707")
+ def test_call_on_temporary(self):
+ """Test calls to overridden methods in derived classes."""
+ self.build()
+
+ # Set breakpoint in main and run exe
+ self.runCmd("file " + self.getBuildArtifact("a.out"),
+ CURRENT_EXECUTABLE_SET)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Test with locally constructed instances.
+ self.expect("expr Base().foo()", substrs=["= 1"])
+ self.expect("expr Derived().foo()", substrs=["= 2"])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp
new file mode 100644
index 00000000000..87997fa354c
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/main.cpp
@@ -0,0 +1,18 @@
+class Base {
+public:
+ virtual ~Base() {}
+ virtual int foo() { return 1; }
+};
+
+class Derived : public Base {
+public:
+ virtual int foo() { return 2; }
+};
+
+int main() {
+ Base realbase;
+ realbase.foo();
+ Derived d;
+ Base *b = &d;
+ return 0; // Set breakpoint here
+}