2 Test C++ virtual function and virtual inheritance.
5 from __future__ import print_function
10 from lldbsuite.test.lldbtest import *
11 import lldbsuite.test.lldbutil as lldbutil
14 return "'expression %s' matches the output (from compiled code): %s" % (expr, val)
16 class CppVirtualMadness(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
20 # This is the pattern by design to match the "my_expr = 'value'" output from
21 # printf() stmts (see main.cpp).
22 pattern = re.compile("^([^=]*) = '([^=]*)'$")
25 PRINTF_OUTPUT_GROKKED = "The printf output from compiled code is parsed correctly"
28 # Call super's setUp().
30 # Find the line number to break for main.cpp.
31 self.source = 'main.cpp'
32 self.line = line_number(self.source, '// Set first breakpoint here.')
34 @expectedFailureIcc('llvm.org/pr16808') # lldb does not call the correct virtual function with icc
35 @expectedFailureAll(oslist=['windows'])
36 def test_virtual_madness(self):
37 """Test that expression works correctly with virtual inheritance as well as virtual function."""
40 # Bring the program to the point where we can issue a series of
41 # 'expression' command to compare against the golden output.
42 self.dbg.SetAsync(False)
44 # Create a target by the debugger.
45 target = self.dbg.CreateTarget("a.out")
46 self.assertTrue(target, VALID_TARGET)
48 # Create the breakpoint inside function 'main'.
49 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
50 self.assertTrue(breakpoint, VALID_BREAKPOINT)
52 # Now launch the process, and do not stop at entry point.
53 process = target.LaunchSimple (None, None, self.get_process_working_directory())
54 self.assertTrue(process, PROCESS_IS_VALID)
56 self.assertTrue(process.GetState() == lldb.eStateStopped)
57 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
58 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
60 # First, capture the golden output from the program itself from the
61 # series of printf statements.
62 stdout = process.GetSTDOUT(1024)
64 self.assertIsNotNone(stdout, "Encountered an error reading the process's output")
66 # This golden list contains a list of "my_expr = 'value' pairs extracted
67 # from the golden output.
70 # Scan the golden output line by line, looking for the pattern:
74 for line in stdout.split(os.linesep):
75 match = self.pattern.search(line)
77 my_expr, val = match.group(1), match.group(2)
78 gl.append((my_expr, val))
79 #print("golden list:", gl)
81 # Now iterate through the golden list, comparing against the output from
83 for my_expr, val in gl:
85 self.runCmd("expression %s" % my_expr)
86 output = self.res.GetOutput()
88 # The expression output must match the oracle.
89 self.expect(output, Msg(my_expr, val), exe=False,