2 Test watchpoint list, enable, disable, and delete commands.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
15 class WatchpointCommandsTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
22 # Our simple source filename.
23 self.source = 'main.c'
24 # Find the line number to break inside main().
25 self.line = line_number(self.source, '// Set break point at this line.')
26 self.line2 = line_number(self.source, '// Set 2nd break point for disable_then_enable test case.')
27 # And the watchpoint variable declaration line number.
28 self.decl = line_number(self.source, '// Watchpoint variable declaration.')
29 # Build dictionary to have unique executable names for each test method.
30 self.exe_name = self.testMethodName
31 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
33 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
34 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
35 @expectedFailureAll(archs=['s390x']) # Read-write watchpoints not supported on SystemZ
36 def test_rw_watchpoint(self):
37 """Test read_write watchpoint and expect to stop two times."""
38 self.build(dictionary=self.d)
39 self.setTearDownCleanup(dictionary=self.d)
41 exe = os.path.join(os.getcwd(), self.exe_name)
42 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
44 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
45 lldbutil.run_break_set_by_file_and_line (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.
52 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
54 'stop reason = breakpoint'])
56 # Now let's set a read_write-type watchpoint for 'global'.
57 # There should be two watchpoint hits (see main.c).
58 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
59 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
60 '%s:%d' % (self.source, self.decl)])
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 = ['Number of supported hardware watchpoints:',
68 self.runCmd("process continue")
70 # We should be stopped again due to the watchpoint (read_write type).
71 # The stop reason of the thread should be watchpoint.
72 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
73 substrs = ['stop reason = watchpoint'])
75 self.runCmd("process continue")
77 # We should be stopped again due to the watchpoint (read_write type).
78 # The stop reason of the thread should be watchpoint.
79 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
80 substrs = ['stop reason = watchpoint'])
82 self.runCmd("process continue")
84 # There should be no more watchpoint hit and the process status should
86 self.expect("process status",
89 # Use the '-v' option to do verbose listing of the watchpoint.
90 # The hit count should now be 2.
91 self.expect("watchpoint list -v",
92 substrs = ['hit_count = 2'])
94 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
95 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
96 @expectedFailureAll(archs=['s390x']) # Read-write watchpoints not supported on SystemZ
97 def test_rw_watchpoint_delete(self):
98 """Test delete watchpoint and expect not to stop for watchpoint."""
99 self.build(dictionary=self.d)
100 self.setTearDownCleanup(dictionary=self.d)
102 exe = os.path.join(os.getcwd(), self.exe_name)
103 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
105 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
106 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
109 self.runCmd("run", RUN_SUCCEEDED)
111 # We should be stopped again due to the breakpoint.
112 # The stop reason of the thread should be breakpoint.
113 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
114 substrs = ['stopped',
115 'stop reason = breakpoint'])
117 # Now let's set a read_write-type watchpoint for 'global'.
118 # There should be two watchpoint hits (see main.c).
119 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
120 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
121 '%s:%d' % (self.source, self.decl)])
123 # Delete the watchpoint immediately, but set auto-confirm to true first.
124 self.runCmd("settings set auto-confirm true")
125 self.expect("watchpoint delete",
126 substrs = ['All watchpoints removed.'])
127 # Restore the original setting of auto-confirm.
128 self.runCmd("settings clear auto-confirm")
130 # Use the '-v' option to do verbose listing of the watchpoint.
131 self.runCmd("watchpoint list -v")
133 self.runCmd("process continue")
135 # There should be no more watchpoint hit and the process status should
137 self.expect("process status",
138 substrs = ['exited'])
140 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
141 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
142 @expectedFailureAll(archs=['s390x']) # Read-write watchpoints not supported on SystemZ
143 def test_rw_watchpoint_set_ignore_count(self):
144 """Test watchpoint ignore count and expect to not to stop at all."""
145 self.build(dictionary=self.d)
146 self.setTearDownCleanup(dictionary=self.d)
148 exe = os.path.join(os.getcwd(), self.exe_name)
149 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
151 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
152 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
155 self.runCmd("run", RUN_SUCCEEDED)
157 # We should be stopped again due to the breakpoint.
158 # The stop reason of the thread should be breakpoint.
159 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
160 substrs = ['stopped',
161 'stop reason = breakpoint'])
163 # Now let's set a read_write-type watchpoint for 'global'.
164 # There should be two watchpoint hits (see main.c).
165 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
166 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
167 '%s:%d' % (self.source, self.decl)])
169 # Set the ignore count of the watchpoint immediately.
170 self.expect("watchpoint ignore -i 2",
171 substrs = ['All watchpoints ignored.'])
173 # Use the '-v' option to do verbose listing of the watchpoint.
174 # Expect to find an ignore_count of 2.
175 self.expect("watchpoint list -v",
176 substrs = ['hit_count = 0', 'ignore_count = 2'])
178 self.runCmd("process continue")
180 # There should be no more watchpoint hit and the process status should
182 self.expect("process status",
183 substrs = ['exited'])
185 # Use the '-v' option to do verbose listing of the watchpoint.
186 # Expect to find a hit_count of 2 as well.
187 self.expect("watchpoint list -v",
188 substrs = ['hit_count = 2', 'ignore_count = 2'])
190 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
191 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
192 @expectedFailureAll(archs=['s390x']) # Read-write watchpoints not supported on SystemZ
193 def test_rw_disable_after_first_stop(self):
194 """Test read_write watchpoint but disable it after the first stop."""
195 self.build(dictionary=self.d)
196 self.setTearDownCleanup(dictionary=self.d)
198 exe = os.path.join(os.getcwd(), self.exe_name)
199 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
201 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
202 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
205 self.runCmd("run", RUN_SUCCEEDED)
207 # We should be stopped again due to the breakpoint.
208 # The stop reason of the thread should be breakpoint.
209 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
210 substrs = ['stopped',
211 'stop reason = breakpoint'])
213 # Now let's set a read_write-type watchpoint for 'global'.
214 # There should be two watchpoint hits (see main.c).
215 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
216 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
217 '%s:%d' % (self.source, self.decl)])
219 # Use the '-v' option to do verbose listing of the watchpoint.
220 # The hit count should be 0 initially.
221 self.expect("watchpoint list -v",
222 substrs = ['state = enabled', 'hit_count = 0'])
224 self.runCmd("process continue")
226 # We should be stopped again due to the watchpoint (read_write type).
227 # The stop reason of the thread should be watchpoint.
228 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
229 substrs = ['stop reason = watchpoint'])
231 # Before continuing, we'll disable the watchpoint, which means we won't
232 # stop again after this.
233 self.runCmd("watchpoint disable")
235 self.expect("watchpoint list -v",
236 substrs = ['state = disabled', 'hit_count = 1'])
238 self.runCmd("process continue")
240 # There should be no more watchpoint hit and the process status should
242 self.expect("process status",
243 substrs = ['exited'])
245 # Use the '-v' option to do verbose listing of the watchpoint.
246 # The hit count should be 1.
247 self.expect("watchpoint list -v",
248 substrs = ['hit_count = 1'])
250 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
251 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
252 @expectedFailureAll(archs=['s390x']) # Read-write watchpoints not supported on SystemZ
253 def test_rw_disable_then_enable(self):
254 """Test read_write watchpoint, disable initially, then enable it."""
255 self.build(dictionary=self.d)
256 self.setTearDownCleanup(dictionary=self.d)
258 exe = os.path.join(os.getcwd(), self.exe_name)
259 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
261 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
262 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
263 lldbutil.run_break_set_by_file_and_line (self, None, self.line2, num_expected_locations=1)
266 self.runCmd("run", RUN_SUCCEEDED)
268 # We should be stopped again due to the breakpoint.
269 # The stop reason of the thread should be breakpoint.
270 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
271 substrs = ['stopped',
272 'stop reason = breakpoint'])
274 # Now let's set a read_write-type watchpoint for 'global'.
275 # There should be two watchpoint hits (see main.c).
276 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
277 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
278 '%s:%d' % (self.source, self.decl)])
280 # Immediately, we disable the watchpoint. We won't be stopping due to a
281 # watchpoint after this.
282 self.runCmd("watchpoint disable")
284 # Use the '-v' option to do verbose listing of the watchpoint.
285 # The hit count should be 0 initially.
286 self.expect("watchpoint list -v",
287 substrs = ['state = disabled', 'hit_count = 0'])
289 self.runCmd("process continue")
291 # We should be stopped again due to the breakpoint.
292 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
293 substrs = ['stop reason = breakpoint'])
295 # Before continuing, we'll enable the watchpoint, which means we will
296 # stop again after this.
297 self.runCmd("watchpoint enable")
299 self.expect("watchpoint list -v",
300 substrs = ['state = enabled', 'hit_count = 0'])
302 self.runCmd("process continue")
304 # We should be stopped again due to the watchpoint (read_write type).
305 # The stop reason of the thread should be watchpoint.
306 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
307 substrs = ['stop reason = watchpoint'])
309 self.runCmd("process continue")
311 # There should be no more watchpoint hit and the process status should
313 self.expect("process status",
314 substrs = ['exited'])
316 # Use the '-v' option to do verbose listing of the watchpoint.
317 # The hit count should be 1.
318 self.expect("watchpoint list -v",
319 substrs = ['hit_count = 1'])