1""" 2Test that a variable watchpoint should only hit when in scope. 3""" 4 5 6 7import unittest2 8import lldb 9from lldbsuite.test.lldbtest import * 10import lldbsuite.test.lldbutil as lldbutil 11from lldbsuite.test.decorators import * 12 13 14class WatchedVariableHitWhenInScopeTestCase(TestBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 NO_DEBUG_INFO_TESTCASE = True 18 19 # This test depends on not tracking watchpoint expression hits if we have 20 # left the watchpoint scope. We will provide such an ability at some point 21 # but the way this was done was incorrect, and it is unclear that for the 22 # most part that's not what folks mostly want, so we have to provide a 23 # clearer API to express this. 24 25 def setUp(self): 26 # Call super's setUp(). 27 TestBase.setUp(self) 28 # Our simple source filename. 29 self.source = 'main.c' 30 self.exe_name = self.testMethodName 31 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} 32 33 # Test hangs due to a kernel bug, see fdfeff0f in the linux kernel for details 34 @skipIfTargetAndroid(api_levels=list(range(25+1)), archs=["aarch64", "arm"]) 35 @skipIf 36 def test_watched_var_should_only_hit_when_in_scope(self): 37 """Test that a variable watchpoint should only hit when in scope.""" 38 self.build(dictionary=self.d) 39 self.setTearDownCleanup(dictionary=self.d) 40 41 exe = self.getBuildArtifact(self.exe_name) 42 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 43 44 # Add a breakpoint to set a watchpoint when stopped in main. 45 lldbutil.run_break_set_by_symbol( 46 self, "main", num_expected_locations=-1) 47 48 # Run the program. 49 self.runCmd("run", RUN_SUCCEEDED) 50 51 # We should be stopped again due to the breakpoint. 52 # The stop reason of the thread should be breakpoint. 53 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 54 substrs=['stopped', 55 'stop reason = breakpoint']) 56 57 # Now let's set a watchpoint for 'c.a'. 58 # There should be only one watchpoint hit (see main.c). 59 self.expect("watchpoint set variable c.a", WATCHPOINT_CREATED, 60 substrs=['Watchpoint created', 'size = 4', 'type = w']) 61 62 # Use the '-v' option to do verbose listing of the watchpoint. 63 # The hit count should be 0 initially. 64 self.expect("watchpoint list -v", 65 substrs=['hit_count = 0']) 66 67 self.runCmd("process continue") 68 69 # We should be stopped again due to the watchpoint (write type), but 70 # only once. The stop reason of the thread should be watchpoint. 71 self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, 72 substrs=['stopped', 73 'stop reason = watchpoint']) 74 75 self.runCmd("process continue") 76 # Don't expect the read of 'global' to trigger a stop exception. 77 # The process status should be 'exited'. 78 self.expect("process status", 79 substrs=['exited']) 80 81 # Use the '-v' option to do verbose listing of the watchpoint. 82 # The hit count should now be 1. 83 self.expect("watchpoint list -v", 84 substrs=['hit_count = 1']) 85