TestWatchpointCommandPython.py [plain text]
"""
Test 'watchpoint command'.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
import lldbutil
class WatchpointPythonCommandTestCase(TestBase):
mydir = os.path.join("functionalities", "watchpoint", "watchpoint_commands", "command")
def setUp(self):
TestBase.setUp(self)
self.source = 'main.cpp'
self.line = line_number(self.source, '// Set break point at this line.')
self.decl = line_number(self.source, '// Watchpoint variable declaration.')
self.exe_name = self.testMethodName
self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_watchpoint_command_with_dsym(self):
"""Test 'watchpoint command'."""
self.buildDsym(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
self.watchpoint_command()
@expectedFailureLinux @dwarf_test
def test_watchpoint_command_with_dwarf(self):
"""Test 'watchpoint command'."""
self.buildDwarf(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
self.watchpoint_command()
def watchpoint_command(self):
"""Do 'watchpoint command add'."""
exe = os.path.join(os.getcwd(), self.exe_name)
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("watchpoint set variable -w write global", WATCHPOINT_CREATED,
substrs = ['Watchpoint created', 'size = 4', 'type = w',
'%s:%d' % (self.source, self.decl)])
self.runCmd('watchpoint command add -s python 1 -o \'frame.EvaluateExpression("cookie = 777")\'')
self.expect("watchpoint command list 1",
substrs = ['frame.EvaluateExpression', 'cookie = 777'])
self.expect("watchpoint list -v",
substrs = ['hit_count = 0'])
self.runCmd("process continue")
self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
substrs = ['stop reason = watchpoint'])
self.expect("watchpoint list -v",
substrs = ['old value:', ' = 0',
'new value:', ' = 1'])
self.expect("frame variable --show-globals cookie",
substrs = ['(int32_t)', 'cookie = 777'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()