2 Test C++ virtual function and virtual inheritance.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
17 return "'expression %s' matches the output (from compiled code): %s" % (
21 class CppVirtualMadness(TestBase):
23 mydir = TestBase.compute_mydir(__file__)
25 # This is the pattern by design to match the "my_expr = 'value'" output from
26 # printf() stmts (see main.cpp).
27 pattern = re.compile("^([^=]*) = '([^=]*)'$")
30 # Call super's setUp().
32 # Find the line number to break for main.cpp.
33 self.source = 'main.cpp'
34 self.line = line_number(self.source, '// Set first breakpoint here.')
38 bugnumber="llvm.org/pr16808 lldb does not call the correct virtual function with icc.")
39 def test_virtual_madness(self):
40 """Test that expression works correctly with virtual inheritance as well as virtual function."""
43 # Bring the program to the point where we can issue a series of
44 # 'expression' command to compare against the golden output.
45 self.dbg.SetAsync(False)
47 # Create a target by the debugger.
48 target = self.dbg.CreateTarget("a.out")
49 self.assertTrue(target, VALID_TARGET)
51 # Create the breakpoint inside function 'main'.
52 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
53 self.assertTrue(breakpoint, VALID_BREAKPOINT)
55 # Now launch the process, and do not stop at entry point.
56 process = target.LaunchSimple(
57 None, None, self.get_process_working_directory())
58 self.assertTrue(process, PROCESS_IS_VALID)
60 self.assertTrue(process.GetState() == lldb.eStateStopped)
61 thread = lldbutil.get_stopped_thread(
62 process, lldb.eStopReasonBreakpoint)
65 "There should be a thread stopped due to breakpoint condition")
67 # First, capture the golden output from the program itself.
68 golden = thread.GetFrameAtIndex(0).FindVariable("golden")
71 "Encountered an error reading the process's golden variable")
72 error = lldb.SBError()
73 golden_str = process.ReadCStringFromMemory(
74 golden.AddressOf().GetValueAsUnsigned(), 4096, error)
75 self.assertTrue(error.Success())
76 self.assertTrue("c_as_C" in golden_str)
78 # This golden list contains a list of "my_expr = 'value' pairs extracted
79 # from the golden output.
82 # Scan the golden output line by line, looking for the pattern:
86 for line in golden_str.split(os.linesep):
87 match = self.pattern.search(line)
89 my_expr, val = match.group(1), match.group(2)
90 gl.append((my_expr, val))
91 #print("golden list:", gl)
93 # Now iterate through the golden list, comparing against the output from
95 for my_expr, val in gl:
97 self.runCmd("expression %s" % my_expr)
98 output = self.res.GetOutput()
100 # The expression output must match the oracle.
101 self.expect(output, Msg(my_expr, val), exe=False,