1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
| """
Test watchpoint list, enable, disable, and delete commands.
"""
from __future__ import print_function
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class WatchpointCommandsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Our simple source filename.
self.source = 'main.c'
# Find the line number to break inside main().
self.line = line_number(
self.source, '// Set break point at this line.')
self.line2 = line_number(
self.source,
'// Set 2nd break point for disable_then_enable test case.')
# And the watchpoint variable declaration line number.
self.decl = line_number(self.source,
'// Watchpoint variable declaration.')
# Build dictionary to have unique executable names for each test
# method.
self.exe_name = self.testMethodName
self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
# Read-write watchpoints not supported on SystemZ
@expectedFailureAll(archs=['s390x'])
def test_rw_watchpoint(self):
"""Test read_write watchpoint and expect to stop two times."""
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = self.getBuildArtifact(self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a read_write-type watchpoint for 'global'.
# There should be two watchpoint hits (see main.c).
self.expect(
"watchpoint set variable -w read_write global",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = rw',
'%s:%d' %
(self.source,
self.decl)])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v",
substrs=['Number of supported hardware watchpoints:',
'hit_count = 0'])
self.runCmd("process continue")
# We should be stopped again due to the watchpoint (read_write type).
# The stop reason of the thread should be watchpoint.
self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stop reason = watchpoint'])
self.runCmd("process continue")
# We should be stopped again due to the watchpoint (read_write type).
# The stop reason of the thread should be watchpoint.
self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stop reason = watchpoint'])
self.runCmd("process continue")
# There should be no more watchpoint hit and the process status should
# be 'exited'.
self.expect("process status",
substrs=['exited'])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should now be 2.
self.expect("watchpoint list -v",
substrs=['hit_count = 2'])
# Read-write watchpoints not supported on SystemZ
@expectedFailureAll(archs=['s390x'])
def test_rw_watchpoint_delete(self):
"""Test delete watchpoint and expect not to stop for watchpoint."""
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = self.getBuildArtifact(self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a read_write-type watchpoint for 'global'.
# There should be two watchpoint hits (see main.c).
self.expect(
"watchpoint set variable -w read_write global",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = rw',
'%s:%d' %
(self.source,
self.decl)])
# Delete the watchpoint immediately, but set auto-confirm to true
# first.
self.runCmd("settings set auto-confirm true")
self.expect("watchpoint delete",
substrs=['All watchpoints removed.'])
# Restore the original setting of auto-confirm.
self.runCmd("settings clear auto-confirm")
# Use the '-v' option to do verbose listing of the watchpoint.
self.runCmd("watchpoint list -v")
self.runCmd("process continue")
# There should be no more watchpoint hit and the process status should
# be 'exited'.
self.expect("process status",
substrs=['exited'])
# Read-write watchpoints not supported on SystemZ
@expectedFailureAll(archs=['s390x'])
def test_rw_watchpoint_set_ignore_count(self):
"""Test watchpoint ignore count and expect to not to stop at all."""
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = self.getBuildArtifact(self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a read_write-type watchpoint for 'global'.
# There should be two watchpoint hits (see main.c).
self.expect(
"watchpoint set variable -w read_write global",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = rw',
'%s:%d' %
(self.source,
self.decl)])
# Set the ignore count of the watchpoint immediately.
self.expect("watchpoint ignore -i 2",
substrs=['All watchpoints ignored.'])
# Use the '-v' option to do verbose listing of the watchpoint.
# Expect to find an ignore_count of 2.
self.expect("watchpoint list -v",
substrs=['hit_count = 0', 'ignore_count = 2'])
self.runCmd("process continue")
# There should be no more watchpoint hit and the process status should
# be 'exited'.
self.expect("process status",
substrs=['exited'])
# Use the '-v' option to do verbose listing of the watchpoint.
# Expect to find a hit_count of 2 as well.
self.expect("watchpoint list -v",
substrs=['hit_count = 2', 'ignore_count = 2'])
# Read-write watchpoints not supported on SystemZ
@expectedFailureAll(archs=['s390x'])
def test_rw_disable_after_first_stop(self):
"""Test read_write watchpoint but disable it after the first stop."""
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = self.getBuildArtifact(self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a read_write-type watchpoint for 'global'.
# There should be two watchpoint hits (see main.c).
self.expect(
"watchpoint set variable -w read_write global",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = rw',
'%s:%d' %
(self.source,
self.decl)])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v",
substrs=['state = enabled', 'hit_count = 0'])
self.runCmd("process continue")
# We should be stopped again due to the watchpoint (read_write type).
# The stop reason of the thread should be watchpoint.
self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stop reason = watchpoint'])
# Before continuing, we'll disable the watchpoint, which means we won't
# stop again after this.
self.runCmd("watchpoint disable")
self.expect("watchpoint list -v",
substrs=['state = disabled', 'hit_count = 1'])
self.runCmd("process continue")
# There should be no more watchpoint hit and the process status should
# be 'exited'.
self.expect("process status",
substrs=['exited'])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 1.
self.expect("watchpoint list -v",
substrs=['hit_count = 1'])
# Read-write watchpoints not supported on SystemZ
@expectedFailureAll(archs=['s390x'])
def test_rw_disable_then_enable(self):
"""Test read_write watchpoint, disable initially, then enable it."""
self.build(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
exe = self.getBuildArtifact(self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint to set a watchpoint when stopped on the breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1)
lldbutil.run_break_set_by_file_and_line(
self, None, self.line2, num_expected_locations=1)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to the breakpoint.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# Now let's set a read_write-type watchpoint for 'global'.
# There should be two watchpoint hits (see main.c).
self.expect(
"watchpoint set variable -w read_write global",
WATCHPOINT_CREATED,
substrs=[
'Watchpoint created',
'size = 4',
'type = rw',
'%s:%d' %
(self.source,
self.decl)])
# Immediately, we disable the watchpoint. We won't be stopping due to a
# watchpoint after this.
self.runCmd("watchpoint disable")
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 0 initially.
self.expect("watchpoint list -v",
substrs=['state = disabled', 'hit_count = 0'])
self.runCmd("process continue")
# We should be stopped again due to the breakpoint.
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stop reason = breakpoint'])
# Before continuing, we'll enable the watchpoint, which means we will
# stop again after this.
self.runCmd("watchpoint enable")
self.expect("watchpoint list -v",
substrs=['state = enabled', 'hit_count = 0'])
self.runCmd("process continue")
# We should be stopped again due to the watchpoint (read_write type).
# The stop reason of the thread should be watchpoint.
self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
substrs=['stop reason = watchpoint'])
self.runCmd("process continue")
# There should be no more watchpoint hit and the process status should
# be 'exited'.
self.expect("process status",
substrs=['exited'])
# Use the '-v' option to do verbose listing of the watchpoint.
# The hit count should be 1.
self.expect("watchpoint list -v",
substrs=['hit_count = 1'])
|