2 Test calling an overriden method.
5 This verifies that LLDB is correctly building the method overrides table.
6 If this table is not built correctly then calls to overridden methods in
7 derived classes may generate references to non-existant vtable entries,
8 as the compiler treats the overridden method as a totally new virtual
10 <rdar://problem/14205774>
15 from lldbsuite.test.decorators import *
16 from lldbsuite.test.lldbtest import *
17 from lldbsuite.test import lldbutil
19 class ExprCommandCallOverriddenMethod(TestBase):
21 mydir = TestBase.compute_mydir(__file__)
24 # Call super's setUp().
26 # Find the line number to break for main.c.
27 self.line = line_number('main.cpp', '// Set breakpoint here')
29 def test_call_on_base(self):
30 """Test calls to overridden methods in derived classes."""
33 # Set breakpoint in main and run exe
34 self.runCmd("file " + self.getBuildArtifact("a.out"),
35 CURRENT_EXECUTABLE_SET)
36 lldbutil.run_break_set_by_file_and_line(
37 self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
39 self.runCmd("run", RUN_SUCCEEDED)
41 # Test call to method in base class (this should always work as the base
42 # class method is never an override).
43 self.expect("expr b->foo()", substrs=["= 2"])
45 # Test calling the base class.
46 self.expect("expr realbase.foo()", substrs=["= 1"])
48 @skipIfLinux # Returns wrong result code on some platforms.
49 def test_call_on_derived(self):
50 """Test calls to overridden methods in derived classes."""
53 # Set breakpoint in main and run exe
54 self.runCmd("file " + self.getBuildArtifact("a.out"),
55 CURRENT_EXECUTABLE_SET)
56 lldbutil.run_break_set_by_file_and_line(
57 self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
59 self.runCmd("run", RUN_SUCCEEDED)
61 # Test call to overridden method in derived class (this will fail if the
62 # overrides table is not correctly set up, as Derived::foo will be assigned
63 # a vtable entry that does not exist in the compiled program).
64 self.expect("expr d.foo()", substrs=["= 2"])
66 @skipIf(oslist=["linux"], archs=["aarch64"])
67 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr43707")
68 def test_call_on_temporary(self):
69 """Test calls to overridden methods in derived classes."""
72 # Set breakpoint in main and run exe
73 self.runCmd("file " + self.getBuildArtifact("a.out"),
74 CURRENT_EXECUTABLE_SET)
75 lldbutil.run_break_set_by_file_and_line(
76 self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
78 self.runCmd("run", RUN_SUCCEEDED)
80 # Test with locally constructed instances.
81 self.expect("expr Base().foo()", substrs=["= 1"])
82 self.expect("expr Derived().foo()", substrs=["= 2"])