2 Test watchpoint list, enable, disable, and delete commands.
5 from __future__ import print_function
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
14 class WatchpointCommandsTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
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(self.source, '// Set break point at this line.')
25 self.line2 = line_number(self.source, '// Set 2nd break point for disable_then_enable test case.')
26 # And the watchpoint variable declaration line number.
27 self.decl = line_number(self.source, '// Watchpoint variable declaration.')
28 # Build dictionary to have unique executable names for each test method.
29 self.exe_name = self.testMethodName
30 self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
32 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
33 @expectedFailureWindows("llvm.org/pr24446") # WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows
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 = os.path.join(os.getcwd(), 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 (self, None, self.line, num_expected_locations=1)
46 self.runCmd("run", RUN_SUCCEEDED)
48 # We should be stopped again due to the breakpoint.
49 # The stop reason of the thread should be breakpoint.
50 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
52 'stop reason = breakpoint'])
54 # Now let's set a read_write-type watchpoint for 'global'.
55 # There should be two watchpoint hits (see main.c).
56 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
57 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
58 '%s:%d' % (self.source, self.decl)])
60 # Use the '-v' option to do verbose listing of the watchpoint.
61 # The hit count should be 0 initially.
62 self.expect("watchpoint list -v",
63 substrs = ['Number of supported hardware watchpoints:',
66 self.runCmd("process continue")
68 # We should be stopped again due to the watchpoint (read_write type).
69 # The stop reason of the thread should be watchpoint.
70 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
71 substrs = ['stop reason = watchpoint'])
73 self.runCmd("process continue")
75 # We should be stopped again due to the watchpoint (read_write type).
76 # The stop reason of the thread should be watchpoint.
77 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
78 substrs = ['stop reason = watchpoint'])
80 self.runCmd("process continue")
82 # There should be no more watchpoint hit and the process status should
84 self.expect("process status",
87 # Use the '-v' option to do verbose listing of the watchpoint.
88 # The hit count should now be 2.
89 self.expect("watchpoint list -v",
90 substrs = ['hit_count = 2'])
92 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
93 @expectedFailureWindows("llvm.org/pr24446") # WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows
94 def test_rw_watchpoint_delete(self):
95 """Test delete watchpoint and expect not to stop for watchpoint."""
96 self.build(dictionary=self.d)
97 self.setTearDownCleanup(dictionary=self.d)
99 exe = os.path.join(os.getcwd(), self.exe_name)
100 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
102 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
103 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
106 self.runCmd("run", RUN_SUCCEEDED)
108 # We should be stopped again due to the breakpoint.
109 # The stop reason of the thread should be breakpoint.
110 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
111 substrs = ['stopped',
112 'stop reason = breakpoint'])
114 # Now let's set a read_write-type watchpoint for 'global'.
115 # There should be two watchpoint hits (see main.c).
116 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
117 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
118 '%s:%d' % (self.source, self.decl)])
120 # Delete the watchpoint immediately, but set auto-confirm to true first.
121 self.runCmd("settings set auto-confirm true")
122 self.expect("watchpoint delete",
123 substrs = ['All watchpoints removed.'])
124 # Restore the original setting of auto-confirm.
125 self.runCmd("settings clear auto-confirm")
127 # Use the '-v' option to do verbose listing of the watchpoint.
128 self.runCmd("watchpoint list -v")
130 self.runCmd("process continue")
132 # There should be no more watchpoint hit and the process status should
134 self.expect("process status",
135 substrs = ['exited'])
137 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
138 @expectedFailureWindows("llvm.org/pr24446") # WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows
139 def test_rw_watchpoint_set_ignore_count(self):
140 """Test watchpoint ignore count and expect to not to stop at all."""
141 self.build(dictionary=self.d)
142 self.setTearDownCleanup(dictionary=self.d)
144 exe = os.path.join(os.getcwd(), self.exe_name)
145 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
147 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
148 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
151 self.runCmd("run", RUN_SUCCEEDED)
153 # We should be stopped again due to the breakpoint.
154 # The stop reason of the thread should be breakpoint.
155 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
156 substrs = ['stopped',
157 'stop reason = breakpoint'])
159 # Now let's set a read_write-type watchpoint for 'global'.
160 # There should be two watchpoint hits (see main.c).
161 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
162 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
163 '%s:%d' % (self.source, self.decl)])
165 # Set the ignore count of the watchpoint immediately.
166 self.expect("watchpoint ignore -i 2",
167 substrs = ['All watchpoints ignored.'])
169 # Use the '-v' option to do verbose listing of the watchpoint.
170 # Expect to find an ignore_count of 2.
171 self.expect("watchpoint list -v",
172 substrs = ['hit_count = 0', 'ignore_count = 2'])
174 self.runCmd("process continue")
176 # There should be no more watchpoint hit and the process status should
178 self.expect("process status",
179 substrs = ['exited'])
181 # Use the '-v' option to do verbose listing of the watchpoint.
182 # Expect to find a hit_count of 2 as well.
183 self.expect("watchpoint list -v",
184 substrs = ['hit_count = 2', 'ignore_count = 2'])
186 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
187 @expectedFailureWindows("llvm.org/pr24446") # WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows
188 def test_rw_disable_after_first_stop(self):
189 """Test read_write watchpoint but disable it after the first stop."""
190 self.build(dictionary=self.d)
191 self.setTearDownCleanup(dictionary=self.d)
193 exe = os.path.join(os.getcwd(), self.exe_name)
194 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
196 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
197 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
200 self.runCmd("run", RUN_SUCCEEDED)
202 # We should be stopped again due to the breakpoint.
203 # The stop reason of the thread should be breakpoint.
204 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
205 substrs = ['stopped',
206 'stop reason = breakpoint'])
208 # Now let's set a read_write-type watchpoint for 'global'.
209 # There should be two watchpoint hits (see main.c).
210 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
211 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
212 '%s:%d' % (self.source, self.decl)])
214 # Use the '-v' option to do verbose listing of the watchpoint.
215 # The hit count should be 0 initially.
216 self.expect("watchpoint list -v",
217 substrs = ['state = enabled', 'hit_count = 0'])
219 self.runCmd("process continue")
221 # We should be stopped again due to the watchpoint (read_write type).
222 # The stop reason of the thread should be watchpoint.
223 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
224 substrs = ['stop reason = watchpoint'])
226 # Before continuing, we'll disable the watchpoint, which means we won't
227 # stop again after this.
228 self.runCmd("watchpoint disable")
230 self.expect("watchpoint list -v",
231 substrs = ['state = disabled', 'hit_count = 1'])
233 self.runCmd("process continue")
235 # There should be no more watchpoint hit and the process status should
237 self.expect("process status",
238 substrs = ['exited'])
240 # Use the '-v' option to do verbose listing of the watchpoint.
241 # The hit count should be 1.
242 self.expect("watchpoint list -v",
243 substrs = ['hit_count = 1'])
245 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
246 @expectedFailureWindows("llvm.org/pr24446") # WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows
247 def test_rw_disable_then_enable(self):
248 """Test read_write watchpoint, disable initially, then enable it."""
249 self.build(dictionary=self.d)
250 self.setTearDownCleanup(dictionary=self.d)
252 exe = os.path.join(os.getcwd(), self.exe_name)
253 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
255 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
256 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
257 lldbutil.run_break_set_by_file_and_line (self, None, self.line2, num_expected_locations=1)
260 self.runCmd("run", RUN_SUCCEEDED)
262 # We should be stopped again due to the breakpoint.
263 # The stop reason of the thread should be breakpoint.
264 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
265 substrs = ['stopped',
266 'stop reason = breakpoint'])
268 # Now let's set a read_write-type watchpoint for 'global'.
269 # There should be two watchpoint hits (see main.c).
270 self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED,
271 substrs = ['Watchpoint created', 'size = 4', 'type = rw',
272 '%s:%d' % (self.source, self.decl)])
274 # Immediately, we disable the watchpoint. We won't be stopping due to a
275 # watchpoint after this.
276 self.runCmd("watchpoint disable")
278 # Use the '-v' option to do verbose listing of the watchpoint.
279 # The hit count should be 0 initially.
280 self.expect("watchpoint list -v",
281 substrs = ['state = disabled', 'hit_count = 0'])
283 self.runCmd("process continue")
285 # We should be stopped again due to the breakpoint.
286 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
287 substrs = ['stop reason = breakpoint'])
289 # Before continuing, we'll enable the watchpoint, which means we will
290 # stop again after this.
291 self.runCmd("watchpoint enable")
293 self.expect("watchpoint list -v",
294 substrs = ['state = enabled', 'hit_count = 0'])
296 self.runCmd("process continue")
298 # We should be stopped again due to the watchpoint (read_write type).
299 # The stop reason of the thread should be watchpoint.
300 self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
301 substrs = ['stop reason = watchpoint'])
303 self.runCmd("process continue")
305 # There should be no more watchpoint hit and the process status should
307 self.expect("process status",
308 substrs = ['exited'])
310 # Use the '-v' option to do verbose listing of the watchpoint.
311 # The hit count should be 1.
312 self.expect("watchpoint list -v",
313 substrs = ['hit_count = 1'])