2 Test watchpoint list, enable, disable, and delete commands.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class WatchpointCommandsTestCase(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
16 # Call super's setUp().
18 # Our simple source filename.
19 self
.source
= "main.c"
20 # Find the line number to break inside main().
21 self
.line
= line_number(self
.source
, "// Set break point at this line.")
22 self
.line2
= line_number(
23 self
.source
, "// Set 2nd break point for disable_then_enable test case."
25 # And the watchpoint variable declaration line number.
26 self
.decl
= line_number(self
.source
, "// Watchpoint variable declaration.")
27 # Build dictionary to have unique executable names for each test
29 self
.exe_name
= self
.testMethodName
30 self
.d
= {"C_SOURCES": self
.source
, "EXE": self
.exe_name
}
32 # Read-write watchpoints not supported on SystemZ
33 @expectedFailureAll(archs
=["s390x"])
34 def test_rw_watchpoint(self
):
35 """Test read_write watchpoint and expect to stop two times."""
36 self
.build(dictionary
=self
.d
)
37 self
.setTearDownCleanup(dictionary
=self
.d
)
39 exe
= self
.getBuildArtifact(self
.exe_name
)
40 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
42 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
43 lldbutil
.run_break_set_by_file_and_line(
44 self
, None, self
.line
, num_expected_locations
=1
48 self
.runCmd("run", RUN_SUCCEEDED
)
50 # We should be stopped again due to the breakpoint.
51 # The stop reason of the thread should be breakpoint.
54 STOPPED_DUE_TO_BREAKPOINT
,
55 substrs
=["stopped", "stop reason = breakpoint"],
58 # Now let's set a read_write-type watchpoint for 'global'.
59 # There should be two watchpoint hits (see main.c).
61 "watchpoint set variable -w read_write global",
67 "%s:%d" % (self
.source
, self
.decl
),
71 # Use the '-v' option to do verbose listing of the watchpoint.
72 # The hit count should be 0 initially.
75 substrs
=["Number of supported hardware watchpoints:", "hit_count = 0"],
78 self
.runCmd("process continue")
80 # We should be stopped again due to the watchpoint (read_write type).
81 # The stop reason of the thread should be watchpoint.
84 STOPPED_DUE_TO_WATCHPOINT
,
85 substrs
=["stop reason = watchpoint"],
88 self
.runCmd("process continue")
90 # We should be stopped again due to the watchpoint (read_write type).
91 # The stop reason of the thread should be watchpoint.
94 STOPPED_DUE_TO_WATCHPOINT
,
95 substrs
=["stop reason = watchpoint"],
98 self
.runCmd("process continue")
100 # There should be no more watchpoint hit and the process status should
102 self
.expect("process status", substrs
=["exited"])
104 # Use the '-v' option to do verbose listing of the watchpoint.
105 # The hit count should now be 2.
106 self
.expect("watchpoint list -v", substrs
=["hit_count = 2"])
108 # Read-write watchpoints not supported on SystemZ
109 @expectedFailureAll(archs
=["s390x"])
110 def test_rw_watchpoint_delete(self
):
111 """Test delete watchpoint and expect not to stop for watchpoint."""
113 lldbutil
.run_to_line_breakpoint(self
, lldb
.SBFileSpec(self
.source
), self
.line
)
115 # Now let's set a read_write-type watchpoint for 'global'.
116 # There should be two watchpoint hits (see main.c).
118 "watchpoint set variable -w read_write global",
121 "Watchpoint created",
124 "%s:%d" % (self
.source
, self
.decl
),
128 # Delete the watchpoint immediately, but set auto-confirm to true
130 self
.runCmd("settings set auto-confirm true")
131 self
.expect("watchpoint delete", substrs
=["All watchpoints removed."])
132 # Restore the original setting of auto-confirm.
133 self
.runCmd("settings clear auto-confirm")
135 target
= self
.dbg
.GetSelectedTarget()
136 self
.assertTrue(target
and not target
.GetNumWatchpoints())
138 # Now let's set a read_write-type watchpoint for 'global'.
139 # There should be two watchpoint hits (see main.c).
141 "watchpoint set variable -w read_write global",
144 "Watchpoint created",
147 "%s:%d" % (self
.source
, self
.decl
),
151 # Delete the watchpoint immediately using the force option.
152 self
.expect("watchpoint delete --force", substrs
=["All watchpoints removed."])
154 self
.assertTrue(target
and not target
.GetNumWatchpoints())
156 self
.runCmd("process continue")
158 # There should be no more watchpoint hit and the process status should
160 self
.expect("process status", substrs
=["exited"])
162 # Read-write watchpoints not supported on SystemZ
163 @expectedFailureAll(archs
=["s390x"])
164 def test_rw_watchpoint_set_ignore_count(self
):
165 """Test watchpoint ignore count and expect to not to stop at all."""
166 self
.build(dictionary
=self
.d
)
167 self
.setTearDownCleanup(dictionary
=self
.d
)
169 exe
= self
.getBuildArtifact(self
.exe_name
)
170 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
172 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
173 lldbutil
.run_break_set_by_file_and_line(
174 self
, None, self
.line
, num_expected_locations
=1
178 self
.runCmd("run", RUN_SUCCEEDED
)
180 # We should be stopped again due to the breakpoint.
181 # The stop reason of the thread should be breakpoint.
184 STOPPED_DUE_TO_BREAKPOINT
,
185 substrs
=["stopped", "stop reason = breakpoint"],
188 # Now let's set a read_write-type watchpoint for 'global'.
189 # There should be two watchpoint hits (see main.c).
191 "watchpoint set variable -w read_write global",
194 "Watchpoint created",
197 "%s:%d" % (self
.source
, self
.decl
),
201 # Set the ignore count of the watchpoint immediately.
202 self
.expect("watchpoint ignore -i 2", 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", substrs
=["hit_count = 0", "ignore_count = 2"])
208 self
.runCmd("process continue")
210 # There should be no more watchpoint hit and the process status should
212 self
.expect("process status", substrs
=["exited"])
214 # Use the '-v' option to do verbose listing of the watchpoint.
215 # Expect to find a hit_count of 2 as well.
216 self
.expect("watchpoint list -v", substrs
=["hit_count = 2", "ignore_count = 2"])
218 # Read-write watchpoints not supported on SystemZ
219 @expectedFailureAll(archs
=["s390x"])
220 def test_rw_disable_after_first_stop(self
):
221 """Test read_write watchpoint but disable it after the first stop."""
222 self
.build(dictionary
=self
.d
)
223 self
.setTearDownCleanup(dictionary
=self
.d
)
225 exe
= self
.getBuildArtifact(self
.exe_name
)
226 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
228 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
229 lldbutil
.run_break_set_by_file_and_line(
230 self
, None, self
.line
, num_expected_locations
=1
234 self
.runCmd("run", RUN_SUCCEEDED
)
236 # We should be stopped again due to the breakpoint.
237 # The stop reason of the thread should be breakpoint.
240 STOPPED_DUE_TO_BREAKPOINT
,
241 substrs
=["stopped", "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",
253 "%s:%d" % (self
.source
, self
.decl
),
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", substrs
=["state = enabled", "hit_count = 0"])
261 self
.runCmd("process continue")
263 # We should be stopped again due to the watchpoint (read_write type).
264 # The stop reason of the thread should be watchpoint.
267 STOPPED_DUE_TO_WATCHPOINT
,
268 substrs
=["stop reason = watchpoint"],
271 # Before continuing, we'll disable the watchpoint, which means we won't
272 # stop again after this.
273 self
.runCmd("watchpoint disable")
275 self
.expect("watchpoint list -v", substrs
=["state = disabled", "hit_count = 1"])
277 self
.runCmd("process continue")
279 # There should be no more watchpoint hit and the process status should
281 self
.expect("process status", substrs
=["exited"])
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", substrs
=["hit_count = 1"])
287 # Read-write watchpoints not supported on SystemZ
288 @expectedFailureAll(archs
=["s390x"])
289 def test_rw_disable_then_enable(self
):
290 """Test read_write watchpoint, disable initially, then enable it."""
291 self
.build(dictionary
=self
.d
)
292 self
.setTearDownCleanup(dictionary
=self
.d
)
294 exe
= self
.getBuildArtifact(self
.exe_name
)
295 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
297 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
298 lldbutil
.run_break_set_by_file_and_line(
299 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
306 self
.runCmd("run", RUN_SUCCEEDED
)
308 # We should be stopped again due to the breakpoint.
309 # The stop reason of the thread should be breakpoint.
312 STOPPED_DUE_TO_BREAKPOINT
,
313 substrs
=["stopped", "stop reason = breakpoint"],
316 # Now let's set a read_write-type watchpoint for 'global'.
317 # There should be two watchpoint hits (see main.c).
319 "watchpoint set variable -w read_write global",
322 "Watchpoint created",
325 "%s:%d" % (self
.source
, self
.decl
),
329 # Immediately, we disable the watchpoint. We won't be stopping due to a
330 # watchpoint after this.
331 self
.runCmd("watchpoint disable")
333 # Use the '-v' option to do verbose listing of the watchpoint.
334 # The hit count should be 0 initially.
335 self
.expect("watchpoint list -v", substrs
=["state = disabled", "hit_count = 0"])
337 self
.runCmd("process continue")
339 # We should be stopped again due to the breakpoint.
342 STOPPED_DUE_TO_BREAKPOINT
,
343 substrs
=["stop reason = breakpoint"],
346 # Before continuing, we'll enable the watchpoint, which means we will
347 # stop again after this.
348 self
.runCmd("watchpoint enable")
350 self
.expect("watchpoint list -v", substrs
=["state = enabled", "hit_count = 0"])
352 self
.runCmd("process continue")
354 # We should be stopped again due to the watchpoint (read_write type).
355 # The stop reason of the thread should be watchpoint.
358 STOPPED_DUE_TO_WATCHPOINT
,
359 substrs
=["stop reason = watchpoint"],
362 self
.runCmd("process continue")
364 # There should be no more watchpoint hit and the process status should
366 self
.expect("process status", substrs
=["exited"])
368 # Use the '-v' option to do verbose listing of the watchpoint.
369 # The hit count should be 1.
370 self
.expect("watchpoint list -v", substrs
=["hit_count = 1"])