summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2018-01-22 23:53:56 +0000
committerLang Hames <lhames@gmail.com>2018-01-22 23:53:56 +0000
commit48b32f4cedc1021c774b68ddff1fb9b338c751c0 (patch)
tree5fd6dd96891c86213ac1f42896e776ef5e3ce76e /lldb/packages/Python/lldbsuite/test
parentac8217de8323cf7efe1da0fa24b4006c96d82f66 (diff)
downloadbcm5719-llvm-48b32f4cedc1021c774b68ddff1fb9b338c751c0.tar.gz
bcm5719-llvm-48b32f4cedc1021c774b68ddff1fb9b338c751c0.zip
[lldb] Fix some C++ virtual method call bugs in LLDB expression evaluation by
building method override tables for CXXMethodDecls in DWARFASTParserClang::CompleteTypeFromDWARF. C++ virtual method calls in LLDB expressions may fail if the override table for the method being called is not correct as IRGen will produce references to the wrong (or a missing) vtable entry. This patch does not fix calls to virtual methods with covariant return types as it mistakenly treats these as overloads, rather than overrides. This will be addressed in a future patch. Review: https://reviews.llvm.org/D41997 Partially fixes <rdar://problem/14205774> llvm-svn: 323163
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/Makefile8
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/TestCallOverriddenMethod.py47
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/main.cpp16
3 files changed, 71 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/Makefile b/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/Makefile
new file mode 100644
index 00000000000..9d4f3b7f141
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/Makefile
@@ -0,0 +1,8 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
+
+clean::
+ rm -rf $(wildcard *.o *.d *.dSYM)
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/TestCallOverriddenMethod.py b/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/TestCallOverriddenMethod.py
new file mode 100644
index 00000000000..54709e26ecb
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/TestCallOverriddenMethod.py
@@ -0,0 +1,47 @@
+"""
+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(self):
+ """Test calls to overridden methods in derived classes."""
+ self.build()
+
+ # Set breakpoint in main and run exe
+ self.runCmd("file 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()")
+
+ # 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()")
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/main.cpp b/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/main.cpp
new file mode 100644
index 00000000000..54ae705d297
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/call-overridden-method/main.cpp
@@ -0,0 +1,16 @@
+class Base {
+public:
+ virtual ~Base() {}
+ virtual void foo() {}
+};
+
+class Derived : public Base {
+public:
+ virtual void foo() {}
+};
+
+int main() {
+ Derived d;
+ Base *b = &d;
+ return 0; // Set breakpoint here
+}
OpenPOWER on IntegriCloud