1""" 2Test watchpoint modify command to set condition on a watchpoint. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class WatchpointConditionCmdTestCase(TestBase): 14 NO_DEBUG_INFO_TESTCASE = True 15 16 def setUp(self): 17 # Call super's setUp(). 18 TestBase.setUp(self) 19 # Our simple source filename. 20 self.source = 'main.cpp' 21 # Find the line number to break inside main(). 22 self.line = line_number( 23 self.source, '// Set break point at this line.') 24 # And the watchpoint variable declaration line number. 25 self.decl = line_number(self.source, 26 '// Watchpoint variable declaration.') 27 # Build dictionary to have unique executable names for each test 28 # method. 29 self.exe_name = self.testMethodName 30 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} 31 32 def test_watchpoint_cond(self): 33 """Test watchpoint condition.""" 34 self.build(dictionary=self.d) 35 self.setTearDownCleanup(dictionary=self.d) 36 37 exe = self.getBuildArtifact(self.exe_name) 38 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 39 40 # Add a breakpoint to set a watchpoint when stopped on the breakpoint. 41 lldbutil.run_break_set_by_file_and_line( 42 self, None, self.line, num_expected_locations=1) 43 44 # Run the program. 45 self.runCmd("run", RUN_SUCCEEDED) 46 47 # We should be stopped again due to the breakpoint. 48 # The stop reason of the thread should be breakpoint. 49 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 50 substrs=['stopped', 51 'stop reason = breakpoint']) 52 53 # Now let's set a write-type watchpoint for 'global'. 54 # With a condition of 'global==5'. 55 self.expect( 56 "watchpoint set variable -w write global", 57 WATCHPOINT_CREATED, 58 substrs=[ 59 'Watchpoint created', 60 'size = 4', 61 'type = w', 62 '%s:%d' % 63 (self.source, 64 self.decl)]) 65 66 self.runCmd("watchpoint modify -c 'global==5'") 67 68 # Use the '-v' option to do verbose listing of the watchpoint. 69 # The hit count should be 0 initially. 70 self.expect("watchpoint list -v", 71 substrs=['global==5', 'hit_count = 0']) 72 73 self.runCmd("process continue") 74 75 # We should be stopped again due to the watchpoint (write type). 76 # The stop reason of the thread should be watchpoint. 77 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, 78 substrs=['stop reason = watchpoint']) 79 self.expect("frame variable --show-globals global", 80 substrs=['(int32_t)', 'global = 5']) 81 82 # Use the '-v' option to do verbose listing of the watchpoint. 83 # The hit count should now be 2. 84 self.expect("watchpoint list -v", 85 substrs=['hit_count = 5']) 86