2 Test watchpoint list, enable, disable, and delete commands.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class WatchpointCommandsTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
16 NO_DEBUG_INFO_TESTCASE = True
19 # Call super's setUp().
21 # Our simple source filename.
22 self.source = 'main.c'
23 # Find the line number to break inside main().
24 self.line = line_number(
25 self.source, '// Set break point at this line.')
26 self.line2 = line_number(
28 '// Set 2nd break point for disable_then_enable test case.')
29 # And the watchpoint variable declaration line number.
30 self.decl = line_number(self.source,
31 '// Watchpoint variable declaration.')
32 # Build dictionary to have unique executable names for each test
34 self.exe_name = self.testMethodName
35 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
37 # Read-write watchpoints not supported on SystemZ
38 @expectedFailureAll(archs=['s390x'])
39 def test_rw_watchpoint(self):
40 """Test read_write watchpoint and expect to stop two times."""
41 self.build(dictionary=self.d)
42 self.setTearDownCleanup(dictionary=self.d)
44 exe = self.getBuildArtifact(self.exe_name)
45 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
47 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
48 lldbutil.run_break_set_by_file_and_line(
49 self, None, self.line, num_expected_locations=1)
52 self.runCmd("run", RUN_SUCCEEDED)
54 # We should be stopped again due to the breakpoint.
55 # The stop reason of the thread should be breakpoint.
56 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
58 'stop reason = breakpoint'])
60 # Now let's set a read_write-type watchpoint for 'global'.
61 # There should be two watchpoint hits (see main.c).
63 "watchpoint set variable -w read_write global",
73 # Use the '-v' option to do verbose listing of the watchpoint.
74 # The hit count should be 0 initially.
75 self.expect("watchpoint list -v",
76 substrs=['Number of supported hardware watchpoints:',
79 self.runCmd("process continue")
81 # We should be stopped again due to the watchpoint (read_write type).
82 # The stop reason of the thread should be watchpoint.
83 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
84 substrs=['stop reason = watchpoint'])
86 self.runCmd("process continue")
88 # We should be stopped again due to the watchpoint (read_write type).
89 # The stop reason of the thread should be watchpoint.
90 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
91 substrs=['stop reason = watchpoint'])
93 self.runCmd("process continue")
95 # There should be no more watchpoint hit and the process status should
97 self.expect("process status",
100 # Use the '-v' option to do verbose listing of the watchpoint.
101 # The hit count should now be 2.
102 self.expect("watchpoint list -v",
103 substrs=['hit_count = 2'])
105 # Read-write watchpoints not supported on SystemZ
106 @expectedFailureAll(archs=['s390x'])
107 def test_rw_watchpoint_delete(self):
108 """Test delete watchpoint and expect not to stop for watchpoint."""
110 lldbutil.run_to_line_breakpoint(self, lldb.SBFileSpec(self.source),
113 # Now let's set a read_write-type watchpoint for 'global'.
114 # There should be two watchpoint hits (see main.c).
116 "watchpoint set variable -w read_write global",
119 'Watchpoint created',
126 # Delete the watchpoint immediately, but set auto-confirm to true
128 self.runCmd("settings set auto-confirm true")
129 self.expect("watchpoint delete",
130 substrs=['All watchpoints removed.'])
131 # Restore the original setting of auto-confirm.
132 self.runCmd("settings clear auto-confirm")
134 target = self.dbg.GetSelectedTarget()
135 self.assertTrue(target and not target.GetNumWatchpoints())
137 # Now let's set a read_write-type watchpoint for 'global'.
138 # There should be two watchpoint hits (see main.c).
140 "watchpoint set variable -w read_write global",
143 'Watchpoint created',
151 # Delete the watchpoint immediately using the force option.
152 self.expect("watchpoint delete --force",
153 substrs=['All watchpoints removed.'])
155 self.assertTrue(target and not target.GetNumWatchpoints())
157 self.runCmd("process continue")
159 # There should be no more watchpoint hit and the process status should
161 self.expect("process status",
164 # Read-write watchpoints not supported on SystemZ
165 @expectedFailureAll(archs=['s390x'])
166 def test_rw_watchpoint_set_ignore_count(self):
167 """Test watchpoint ignore count and expect to not to stop at all."""
168 self.build(dictionary=self.d)
169 self.setTearDownCleanup(dictionary=self.d)
171 exe = self.getBuildArtifact(self.exe_name)
172 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
174 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
175 lldbutil.run_break_set_by_file_and_line(
176 self, None, self.line, num_expected_locations=1)
179 self.runCmd("run", RUN_SUCCEEDED)
181 # We should be stopped again due to the breakpoint.
182 # The stop reason of the thread should be breakpoint.
183 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
185 'stop reason = breakpoint'])
187 # Now let's set a read_write-type watchpoint for 'global'.
188 # There should be two watchpoint hits (see main.c).
190 "watchpoint set variable -w read_write global",
193 'Watchpoint created',
200 # Set the ignore count of the watchpoint immediately.
201 self.expect("watchpoint ignore -i 2",
202 substrs=['All watchpoints ignored.'])
204 # Use the '-v' option to do verbose listing of the watchpoint.
205 # Expect to find an ignore_count of 2.
206 self.expect("watchpoint list -v",
207 substrs=['hit_count = 0', 'ignore_count = 2'])
209 self.runCmd("process continue")
211 # There should be no more watchpoint hit and the process status should
213 self.expect("process status",
216 # Use the '-v' option to do verbose listing of the watchpoint.
217 # Expect to find a hit_count of 2 as well.
218 self.expect("watchpoint list -v",
219 substrs=['hit_count = 2', 'ignore_count = 2'])
221 # Read-write watchpoints not supported on SystemZ
222 @expectedFailureAll(archs=['s390x'])
223 def test_rw_disable_after_first_stop(self):
224 """Test read_write watchpoint but disable it after the first stop."""
225 self.build(dictionary=self.d)
226 self.setTearDownCleanup(dictionary=self.d)
228 exe = self.getBuildArtifact(self.exe_name)
229 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
231 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
232 lldbutil.run_break_set_by_file_and_line(
233 self, None, self.line, num_expected_locations=1)
236 self.runCmd("run", RUN_SUCCEEDED)
238 # We should be stopped again due to the breakpoint.
239 # The stop reason of the thread should be breakpoint.
240 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
242 'stop reason = breakpoint'])
244 # Now let's set a read_write-type watchpoint for 'global'.
245 # There should be two watchpoint hits (see main.c).
247 "watchpoint set variable -w read_write global",
250 'Watchpoint created',
257 # Use the '-v' option to do verbose listing of the watchpoint.
258 # The hit count should be 0 initially.
259 self.expect("watchpoint list -v",
260 substrs=['state = enabled', 'hit_count = 0'])
262 self.runCmd("process continue")
264 # We should be stopped again due to the watchpoint (read_write type).
265 # The stop reason of the thread should be watchpoint.
266 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
267 substrs=['stop reason = watchpoint'])
269 # Before continuing, we'll disable the watchpoint, which means we won't
270 # stop again after this.
271 self.runCmd("watchpoint disable")
273 self.expect("watchpoint list -v",
274 substrs=['state = disabled', 'hit_count = 1'])
276 self.runCmd("process continue")
278 # There should be no more watchpoint hit and the process status should
280 self.expect("process status",
283 # Use the '-v' option to do verbose listing of the watchpoint.
284 # The hit count should be 1.
285 self.expect("watchpoint list -v",
286 substrs=['hit_count = 1'])
288 # Read-write watchpoints not supported on SystemZ
289 @expectedFailureAll(archs=['s390x'])
290 def test_rw_disable_then_enable(self):
291 """Test read_write watchpoint, disable initially, then enable it."""
292 self.build(dictionary=self.d)
293 self.setTearDownCleanup(dictionary=self.d)
295 exe = self.getBuildArtifact(self.exe_name)
296 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
298 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
299 lldbutil.run_break_set_by_file_and_line(
300 self, None, self.line, num_expected_locations=1)
301 lldbutil.run_break_set_by_file_and_line(
302 self, None, self.line2, num_expected_locations=1)
305 self.runCmd("run", RUN_SUCCEEDED)
307 # We should be stopped again due to the breakpoint.
308 # The stop reason of the thread should be breakpoint.
309 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
311 'stop reason = breakpoint'])
313 # Now let's set a read_write-type watchpoint for 'global'.
314 # There should be two watchpoint hits (see main.c).
316 "watchpoint set variable -w read_write global",
319 'Watchpoint created',
326 # Immediately, we disable the watchpoint. We won't be stopping due to a
327 # watchpoint after this.
328 self.runCmd("watchpoint disable")
330 # Use the '-v' option to do verbose listing of the watchpoint.
331 # The hit count should be 0 initially.
332 self.expect("watchpoint list -v",
333 substrs=['state = disabled', 'hit_count = 0'])
335 self.runCmd("process continue")
337 # We should be stopped again due to the breakpoint.
338 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
339 substrs=['stop reason = breakpoint'])
341 # Before continuing, we'll enable the watchpoint, which means we will
342 # stop again after this.
343 self.runCmd("watchpoint enable")
345 self.expect("watchpoint list -v",
346 substrs=['state = enabled', 'hit_count = 0'])
348 self.runCmd("process continue")
350 # We should be stopped again due to the watchpoint (read_write type).
351 # The stop reason of the thread should be watchpoint.
352 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
353 substrs=['stop reason = watchpoint'])
355 self.runCmd("process continue")
357 # There should be no more watchpoint hit and the process status should
359 self.expect("process status",
362 # Use the '-v' option to do verbose listing of the watchpoint.
363 # The hit count should be 1.
364 self.expect("watchpoint list -v",
365 substrs=['hit_count = 1'])