]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py
Vendor import of lldb trunk r256945:
[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.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14 class WatchpointCommandsTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
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}
31
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)
38         
39         exe = os.path.join(os.getcwd(), self.exe_name)
40         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
41
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)
44
45         # Run the program.
46         self.runCmd("run", RUN_SUCCEEDED)
47
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,
51             substrs = ['stopped',
52                        'stop reason = breakpoint'])
53
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)])
59
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:',
64                        'hit_count = 0'])
65
66         self.runCmd("process continue")
67
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'])
72
73         self.runCmd("process continue")
74
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'])
79
80         self.runCmd("process continue")
81
82         # There should be no more watchpoint hit and the process status should
83         # be 'exited'.
84         self.expect("process status",
85             substrs = ['exited'])
86
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'])
91
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)
98         
99         exe = os.path.join(os.getcwd(), self.exe_name)
100         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
101
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)
104
105         # Run the program.
106         self.runCmd("run", RUN_SUCCEEDED)
107
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'])
113
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)])
119
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")
126
127         # Use the '-v' option to do verbose listing of the watchpoint.
128         self.runCmd("watchpoint list -v")
129
130         self.runCmd("process continue")
131
132         # There should be no more watchpoint hit and the process status should
133         # be 'exited'.
134         self.expect("process status",
135             substrs = ['exited'])
136
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)
143         
144         exe = os.path.join(os.getcwd(), self.exe_name)
145         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
146
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)
149
150         # Run the program.
151         self.runCmd("run", RUN_SUCCEEDED)
152
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'])
158
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)])
164
165         # Set the ignore count of the watchpoint immediately.
166         self.expect("watchpoint ignore -i 2",
167             substrs = ['All watchpoints ignored.'])
168
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'])
173
174         self.runCmd("process continue")
175
176         # There should be no more watchpoint hit and the process status should
177         # be 'exited'.
178         self.expect("process status",
179             substrs = ['exited'])
180
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'])
185
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)
192         
193         exe = os.path.join(os.getcwd(), self.exe_name)
194         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
195
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)
198
199         # Run the program.
200         self.runCmd("run", RUN_SUCCEEDED)
201
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'])
207
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)])
213
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'])
218
219         self.runCmd("process continue")
220
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'])
225
226         # Before continuing, we'll disable the watchpoint, which means we won't
227         # stop again after this.
228         self.runCmd("watchpoint disable")
229
230         self.expect("watchpoint list -v",
231             substrs = ['state = disabled', 'hit_count = 1'])
232
233         self.runCmd("process continue")
234
235         # There should be no more watchpoint hit and the process status should
236         # be 'exited'.
237         self.expect("process status",
238             substrs = ['exited'])
239
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'])
244
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)
251
252         exe = os.path.join(os.getcwd(), self.exe_name)
253         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
254
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)
258
259         # Run the program.
260         self.runCmd("run", RUN_SUCCEEDED)
261
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'])
267
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)])
273
274         # Immediately, we disable the watchpoint.  We won't be stopping due to a
275         # watchpoint after this.
276         self.runCmd("watchpoint disable")
277
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'])
282
283         self.runCmd("process continue")
284
285         # We should be stopped again due to the breakpoint.
286         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
287             substrs = ['stop reason = breakpoint'])
288
289         # Before continuing, we'll enable the watchpoint, which means we will
290         # stop again after this.
291         self.runCmd("watchpoint enable")
292
293         self.expect("watchpoint list -v",
294             substrs = ['state = enabled', 'hit_count = 0'])
295
296         self.runCmd("process continue")
297
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'])
302
303         self.runCmd("process continue")
304
305         # There should be no more watchpoint hit and the process status should
306         # be 'exited'.
307         self.expect("process status",
308             substrs = ['exited'])
309
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'])