"""Test breakpoint on a class constructor; and variable list the this object."""
import os, time
import unittest2
import lldb
import lldbutil
from lldbtest import *
import lldbutil
class ClassTypesTestCase(TestBase):
mydir = os.path.join("lang", "cpp", "class_types")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_with_dsym_and_run_command(self):
"""Test 'frame variable this' when stopped on a class constructor."""
self.buildDsym()
self.class_types()
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@python_api_test
@dsym_test
def test_with_dsym_and_python_api(self):
"""Use Python APIs to create a breakpoint by (filespec, line)."""
self.buildDsym()
self.breakpoint_creation_by_filespec_python()
@dwarf_test
def test_with_dwarf_and_run_command(self):
"""Test 'frame variable this' when stopped on a class constructor."""
self.buildDwarf()
self.class_types()
@python_api_test
@dwarf_test
def test_with_dwarf_and_python_api(self):
"""Use Python APIs to create a breakpoint by (filespec, line)."""
self.buildDwarf()
self.breakpoint_creation_by_filespec_python()
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_with_dsym_and_expr_parser(self):
"""Test 'frame variable this' and 'expr this' when stopped inside a constructor."""
self.buildDsym()
self.class_types_expr_parser()
@dwarf_test
def test_with_dwarf_and_expr_parser(self):
"""Test 'frame variable this' and 'expr this' when stopped inside a constructor."""
self.buildDwarf()
self.class_types_expr_parser()
def setUp(self):
TestBase.setUp(self)
self.line = line_number('main.cpp', '// Set break point at this line.')
def class_types(self):
"""Test 'frame variable this' when stopped on a class constructor."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1)
self.runCmd("run", RUN_SUCCEEDED)
self.runCmd("process status")
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
'stop reason = breakpoint'])
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
self.expect("frame variable --show-types this", VARIABLES_DISPLAYED_CORRECTLY,
substrs = ['C *',
' this = '])
def breakpoint_creation_by_filespec_python(self):
"""Use Python APIs to create a breakpoint by (filespec, line)."""
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
filespec = target.GetExecutable()
self.assertTrue(filespec, VALID_FILESPEC)
fsDir = filespec.GetDirectory()
fsFile = filespec.GetFilename()
self.assertTrue(fsDir == os.getcwd() and fsFile == "a.out",
"FileSpec matches the executable")
bpfilespec = lldb.SBFileSpec("main.cpp", False)
breakpoint = target.BreakpointCreateByLocation(bpfilespec, self.line)
self.assertTrue(breakpoint, VALID_BREAKPOINT)
self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False,
substrs = ['main.cpp',
str(self.line)])
process = target.LaunchSimple(None, None, os.getcwd())
if not process:
self.fail("SBTarget.Launch() failed")
if process.GetState() != lldb.eStateStopped:
self.fail("Process should be in the 'stopped' state, "
"instead the actual state is: '%s'" %
lldbutil.state_type_to_str(process.GetState()))
thread = process.GetThreadAtIndex(0)
if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
from lldbutil import stop_reason_to_str
self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
stop_reason_to_str(thread.GetStopReason()))
self.expect("%s:%d" % (lldbutil.get_filenames(thread)[0],
lldbutil.get_line_numbers(thread)[0]),
"Break correctly at main.cpp:%d" % self.line, exe=False,
startstr = "main.cpp:")
self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
process.Continue()
def class_types_expr_parser(self):
"""Test 'frame variable this' and 'expr this' when stopped inside a constructor."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=-1)
self.runCmd("run", RUN_SUCCEEDED)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
'stop reason = breakpoint'])
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
self.runCmd("register read pc")
self.runCmd("thread step-over")
self.expect("frame variable this",VARIABLES_DISPLAYED_CORRECTLY,
substrs = ['C *'])
self.runCmd("register read pc")
self.runCmd("expr m_c_int")
self.expect("frame variable --show-types this->m_c_int", VARIABLES_DISPLAYED_CORRECTLY,
startstr = '(int) this->m_c_int = 66')
self.expect("expression this", VARIABLES_DISPLAYED_CORRECTLY,
substrs = ['C *'])
self.expect("expression this->m_c_int", VARIABLES_DISPLAYED_CORRECTLY,
patterns = ['\(int\) \$[0-9]+ = 66'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()