2 Test that a variable watchpoint should only hit when in scope.
9 from lldbsuite.test.lldbtest import *
10 import lldbsuite.test.lldbutil as lldbutil
11 from lldbsuite.test.decorators import *
14 class WatchedVariableHitWhenInScopeTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
17 NO_DEBUG_INFO_TESTCASE = True
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.
26 # Call super's setUp().
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}
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"])
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)
41 exe = self.getBuildArtifact(self.exe_name)
42 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
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)
49 self.runCmd("run", RUN_SUCCEEDED)
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,
55 'stop reason = breakpoint'])
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'])
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'])
67 self.runCmd("process continue")
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,
73 'stop reason = watchpoint'])
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",
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'])