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