]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / watchpoint / watchpoint_commands / TestWatchpointCommands.py
1 """
2 Test watchpoint list, enable, disable, and delete commands.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15 class WatchpointCommandsTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
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}
32
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)
40         
41         exe = os.path.join(os.getcwd(), self.exe_name)
42         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
43
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)
46
47         # Run the program.
48         self.runCmd("run", RUN_SUCCEEDED)
49
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,
53             substrs = ['stopped',
54                        'stop reason = breakpoint'])
55
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)])
61
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:',
66                        'hit_count = 0'])
67
68         self.runCmd("process continue")
69
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'])
74
75         self.runCmd("process continue")
76
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'])
81
82         self.runCmd("process continue")
83
84         # There should be no more watchpoint hit and the process status should
85         # be 'exited'.
86         self.expect("process status",
87             substrs = ['exited'])
88
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'])
93
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)
101         
102         exe = os.path.join(os.getcwd(), self.exe_name)
103         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
104
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)
107
108         # Run the program.
109         self.runCmd("run", RUN_SUCCEEDED)
110
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'])
116
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)])
122
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")
129
130         # Use the '-v' option to do verbose listing of the watchpoint.
131         self.runCmd("watchpoint list -v")
132
133         self.runCmd("process continue")
134
135         # There should be no more watchpoint hit and the process status should
136         # be 'exited'.
137         self.expect("process status",
138             substrs = ['exited'])
139
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)
147         
148         exe = os.path.join(os.getcwd(), self.exe_name)
149         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
150
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)
153
154         # Run the program.
155         self.runCmd("run", RUN_SUCCEEDED)
156
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'])
162
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)])
168
169         # Set the ignore count of the watchpoint immediately.
170         self.expect("watchpoint ignore -i 2",
171             substrs = ['All watchpoints ignored.'])
172
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'])
177
178         self.runCmd("process continue")
179
180         # There should be no more watchpoint hit and the process status should
181         # be 'exited'.
182         self.expect("process status",
183             substrs = ['exited'])
184
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'])
189
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)
197         
198         exe = os.path.join(os.getcwd(), self.exe_name)
199         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
200
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)
203
204         # Run the program.
205         self.runCmd("run", RUN_SUCCEEDED)
206
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'])
212
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)])
218
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'])
223
224         self.runCmd("process continue")
225
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'])
230
231         # Before continuing, we'll disable the watchpoint, which means we won't
232         # stop again after this.
233         self.runCmd("watchpoint disable")
234
235         self.expect("watchpoint list -v",
236             substrs = ['state = disabled', 'hit_count = 1'])
237
238         self.runCmd("process continue")
239
240         # There should be no more watchpoint hit and the process status should
241         # be 'exited'.
242         self.expect("process status",
243             substrs = ['exited'])
244
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'])
249
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)
257
258         exe = os.path.join(os.getcwd(), self.exe_name)
259         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
260
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)
264
265         # Run the program.
266         self.runCmd("run", RUN_SUCCEEDED)
267
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'])
273
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)])
279
280         # Immediately, we disable the watchpoint.  We won't be stopping due to a
281         # watchpoint after this.
282         self.runCmd("watchpoint disable")
283
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'])
288
289         self.runCmd("process continue")
290
291         # We should be stopped again due to the breakpoint.
292         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
293             substrs = ['stop reason = breakpoint'])
294
295         # Before continuing, we'll enable the watchpoint, which means we will
296         # stop again after this.
297         self.runCmd("watchpoint enable")
298
299         self.expect("watchpoint list -v",
300             substrs = ['state = enabled', 'hit_count = 0'])
301
302         self.runCmd("process continue")
303
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'])
308
309         self.runCmd("process continue")
310
311         # There should be no more watchpoint hit and the process status should
312         # be 'exited'.
313         self.expect("process status",
314             substrs = ['exited'])
315
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'])