]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / tools / lldb-mi / control / TestMiExec.py
1 """
2 Test lldb-mi -exec-xxx commands.
3 """
4
5 from __future__ import print_function
6
7
8
9 import lldbmi_testcase
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
13
14 class MiExecTestCase(lldbmi_testcase.MiTestCaseBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
19     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
20     @expectedFailureAll(oslist=["linux"], bugnumber="llvm.org/pr25000: lldb-mi does not receive broadcasted notification from Core/Process about process stopped")
21     def test_lldbmi_exec_run(self):
22         """Test that 'lldb-mi --interpreter' can stop at entry."""
23
24         self.spawnLldbMi(args = None)
25
26         # Load executable
27         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
28         self.expect("\^done")
29
30         # Test that program is stopped at entry
31         self.runCmd("-exec-run --start")
32         self.expect("\^running")
33         self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGSTOP\",signal-meaning=\"Stop\",.*?thread-id=\"1\",stopped-threads=\"all\"")
34         # Test that lldb-mi is ready to execute next commands
35         self.expect(self.child_prompt, exactly = True)
36
37     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
38     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
39     def test_lldbmi_exec_abort(self):
40         """Test that 'lldb-mi --interpreter' works for -exec-abort."""
41
42         self.spawnLldbMi(args = None)
43
44         # Test that -exec-abort fails on invalid process
45         self.runCmd("-exec-abort")
46         self.expect("\^error,msg=\"Command 'exec-abort'\. Invalid process during debug session\"")
47
48         # Load executable
49         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
50         self.expect("\^done")
51
52         # Set arguments
53         self.runCmd("-exec-arguments arg1")
54         self.expect("\^done")
55
56         # Run to main
57         self.runCmd("-break-insert -f main")
58         self.expect("\^done,bkpt={number=\"1\"")
59         self.runCmd("-exec-run")
60         self.expect("\^running")
61         self.expect("\*stopped,reason=\"breakpoint-hit\"")
62
63         # Test that arguments were passed
64         self.runCmd("-data-evaluate-expression argc")
65         self.expect("\^done,value=\"2\"")
66
67         # Test that program may be aborted
68         self.runCmd("-exec-abort")
69         self.expect("\^done")
70         self.expect("\*stopped,reason=\"exited-normally\"")
71
72         # Test that program can be run again
73         self.runCmd("-exec-run")
74         self.expect("\^running")
75         self.expect("\*stopped,reason=\"breakpoint-hit\"")
76
77         # Test that arguments were passed again
78         self.runCmd("-data-evaluate-expression argc")
79         self.expect("\^done,value=\"2\"")
80
81         # Test that program may be aborted again
82         self.runCmd("-exec-abort")
83         self.expect("\^done")
84         self.expect("\*stopped,reason=\"exited-normally\"")
85
86     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
87     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
88     def test_lldbmi_exec_arguments_set(self):
89         """Test that 'lldb-mi --interpreter' can pass args using -exec-arguments."""
90
91         self.spawnLldbMi(args = None)
92
93         # Load executable
94         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
95         self.expect("\^done")
96
97         # Set arguments
98         self.runCmd("-exec-arguments --arg1 \"2nd arg\" third_arg fourth=\"4th arg\"")
99         self.expect("\^done")
100
101         # Run to main
102         self.runCmd("-break-insert -f main")
103         self.expect("\^done,bkpt={number=\"1\"")
104         self.runCmd("-exec-run")
105         self.expect("\^running")
106         self.expect("\*stopped,reason=\"breakpoint-hit\"")
107
108         # Check argc and argv to see if arg passed
109         self.runCmd("-data-evaluate-expression argc")
110         self.expect("\^done,value=\"5\"")
111         #self.runCmd("-data-evaluate-expression argv[1]")
112         #self.expect("\^done,value=\"--arg1\"")
113         self.runCmd("-interpreter-exec command \"print argv[1]\"")
114         self.expect("\"--arg1\"")
115         #self.runCmd("-data-evaluate-expression argv[2]")
116         #self.expect("\^done,value=\"2nd arg\"")
117         self.runCmd("-interpreter-exec command \"print argv[2]\"")
118         self.expect("\"2nd arg\"")
119         #self.runCmd("-data-evaluate-expression argv[3]")
120         #self.expect("\^done,value=\"third_arg\"")
121         self.runCmd("-interpreter-exec command \"print argv[3]\"")
122         self.expect("\"third_arg\"")
123         #self.runCmd("-data-evaluate-expression argv[4]")
124         #self.expect("\^done,value=\"fourth=\\\\\\\"4th arg\\\\\\\"\"")
125         self.runCmd("-interpreter-exec command \"print argv[4]\"")
126         self.expect("\"fourth=\\\\\\\"4th arg\\\\\\\"\"")
127
128     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
129     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
130     def test_lldbmi_exec_arguments_reset(self):
131         """Test that 'lldb-mi --interpreter' can reset previously set args using -exec-arguments."""
132
133         self.spawnLldbMi(args = None)
134
135         # Load executable
136         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
137         self.expect("\^done")
138
139         # Set arguments
140         self.runCmd("-exec-arguments arg1")
141         self.expect("\^done")
142         self.runCmd("-exec-arguments")
143         self.expect("\^done")
144
145         # Run to main
146         self.runCmd("-break-insert -f main")
147         self.expect("\^done,bkpt={number=\"1\"")
148         self.runCmd("-exec-run")
149         self.expect("\^running")
150         self.expect("\*stopped,reason=\"breakpoint-hit\"")
151
152         # Check argc to see if arg passed
153         self.runCmd("-data-evaluate-expression argc")
154         self.expect("\^done,value=\"1\"")
155
156     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
157     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
158     def test_lldbmi_exec_next(self):
159         """Test that 'lldb-mi --interpreter' works for stepping."""
160
161         self.spawnLldbMi(args = None)
162
163         # Load executable
164         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
165         self.expect("\^done")
166
167         # Run to main
168         self.runCmd("-break-insert -f main")
169         self.expect("\^done,bkpt={number=\"1\"")
170         self.runCmd("-exec-run")
171         self.expect("\^running")
172         self.expect("\*stopped,reason=\"breakpoint-hit\"")
173
174         # Warning: the following is sensitive to the lines in the source
175
176         # Test -exec-next
177         self.runCmd("-exec-next --thread 1 --frame 0")
178         self.expect("\^running")
179         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"29\"")
180
181         # Test that --thread is optional
182         self.runCmd("-exec-next --frame 0")
183         self.expect("\^running")
184         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"30\"")
185
186         # Test that --frame is optional
187         self.runCmd("-exec-next --thread 1")
188         self.expect("\^running")
189         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"31\"")
190
191         # Test that both --thread and --frame are optional
192         self.runCmd("-exec-next")
193         self.expect("\^running")
194         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"32\"")
195
196         # Test that an invalid --thread is handled
197         self.runCmd("-exec-next --thread 0")
198         self.expect("\^error,message=\"error: Thread index 0 is out of range")
199         self.runCmd("-exec-next --thread 10")
200         self.expect("\^error,message=\"error: Thread index 10 is out of range")
201
202         # Test that an invalid --frame is handled
203         # FIXME: no error is returned
204         self.runCmd("-exec-next --frame 10")
205         #self.expect("\^error: Frame index 10 is out of range")
206
207     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
208     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
209     @expectedFailureAll(archs=["i[3-6]86"], bugnumber="xfail to get buildbot green, failing config: i386 binary running on ubuntu 14.04 x86_64")
210     def test_lldbmi_exec_next_instruction(self):
211         """Test that 'lldb-mi --interpreter' works for instruction stepping."""
212
213         self.spawnLldbMi(args = None)
214
215         # Load executable
216         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
217         self.expect("\^done")
218
219         # Run to main
220         self.runCmd("-break-insert -f main")
221         self.expect("\^done,bkpt={number=\"1\"")
222         self.runCmd("-exec-run")
223         self.expect("\^running")
224         self.expect("\*stopped,reason=\"breakpoint-hit\"")
225
226         # Warning: the following is sensitive to the lines in the
227         # source and optimizations
228
229         # Test -exec-next-instruction
230         self.runCmd("-exec-next-instruction --thread 1 --frame 0")
231         self.expect("\^running")
232         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"28\"")
233
234         # Test that --thread is optional
235         self.runCmd("-exec-next-instruction --frame 0")
236         self.expect("\^running")
237         # Depending on compiler, it can stop at different line
238         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"(28|29)\"")
239
240         # Test that --frame is optional
241         self.runCmd("-exec-next-instruction --thread 1")
242         self.expect("\^running")
243         # Depending on compiler, it can stop at different line
244         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"(29|30)\"")
245
246         # Test that both --thread and --frame are optional
247         self.runCmd("-exec-next-instruction")
248         self.expect("\^running")
249         # Depending on compiler, it can stop at different line
250         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"(29|30|31)\"")
251
252         # Test that an invalid --thread is handled
253         self.runCmd("-exec-next-instruction --thread 0")
254         self.expect("\^error,message=\"error: Thread index 0 is out of range")
255         self.runCmd("-exec-next-instruction --thread 10")
256         self.expect("\^error,message=\"error: Thread index 10 is out of range")
257
258         # Test that an invalid --frame is handled
259         # FIXME: no error is returned
260         self.runCmd("-exec-next-instruction --frame 10")
261         #self.expect("\^error: Frame index 10 is out of range")
262
263     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
264     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
265     def test_lldbmi_exec_step(self):
266         """Test that 'lldb-mi --interpreter' works for stepping into."""
267
268         self.spawnLldbMi(args = None)
269
270         # Load executable
271         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
272         self.expect("\^done")
273
274         # Run to main
275         self.runCmd("-break-insert -f main")
276         self.expect("\^done,bkpt={number=\"1\"")
277         self.runCmd("-exec-run")
278         self.expect("\^running")
279         self.expect("\*stopped,reason=\"breakpoint-hit\"")
280
281         # Warning: the following is sensitive to the lines in the source
282
283         # Test that -exec-step steps into (or not) printf depending on debug info
284         # Note that message is different in Darwin and Linux:
285         # Darwin: "*stopped,reason=\"end-stepping-range\",frame={addr=\"0x[0-9a-f]+\",func=\"main\",args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value="0x[0-9a-f]+\"}],file=\"main.cpp\",fullname=\".+main.cpp\",line=\"\d\"},thread-id=\"1\",stopped-threads=\"all\"
286         # Linux:  "*stopped,reason=\"end-stepping-range\",frame={addr="0x[0-9a-f]+\",func=\"__printf\",args=[{name=\"format\",value=\"0x[0-9a-f]+\"}],file=\"printf.c\",fullname=\".+printf.c\",line="\d+"},thread-id=\"1\",stopped-threads=\"all\"
287         self.runCmd("-exec-step --thread 1 --frame 0")
288         self.expect("\^running")
289         it = self.expect([ "\*stopped,reason=\"end-stepping-range\".+?func=\"main\"",
290                            "\*stopped,reason=\"end-stepping-range\".+?func=\"(?!main).+?\"" ])
291         # Exit from printf if needed
292         if it == 1:
293             self.runCmd("-exec-finish")
294             self.expect("\^running")
295             self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
296
297         # Test that -exec-step steps into g_MyFunction and back out
298         # (and that --thread is optional)
299         self.runCmd("-exec-step --frame 0")
300         self.expect("\^running")
301         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"g_MyFunction.*?\"")
302         # Use -exec-finish here to make sure that control reaches the caller.
303         # -exec-step can keep us in the g_MyFunction for gcc
304         self.runCmd("-exec-finish --frame 0")
305         self.expect("\^running")
306         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"30\"")
307
308         # Test that -exec-step steps into s_MyFunction
309         # (and that --frame is optional)
310         self.runCmd("-exec-step --thread 1")
311         self.expect("\^running")
312         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\".*?s_MyFunction.*?\"")
313
314         # Test that -exec-step steps into g_MyFunction from inside
315         # s_MyFunction (and that both --thread and --frame are optional)
316         self.runCmd("-exec-step")
317         self.expect("\^running")
318         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"g_MyFunction.*?\"")
319
320         # Test that an invalid --thread is handled
321         self.runCmd("-exec-step --thread 0")
322         self.expect("\^error,message=\"error: Thread index 0 is out of range")
323         self.runCmd("-exec-step --thread 10")
324         self.expect("\^error,message=\"error: Thread index 10 is out of range")
325
326         # Test that an invalid --frame is handled
327         # FIXME: no error is returned
328         self.runCmd("-exec-step --frame 10")
329         #self.expect("\^error: Frame index 10 is out of range")
330
331     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
332     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
333     def test_lldbmi_exec_step_instruction(self):
334         """Test that 'lldb-mi --interpreter' works for instruction stepping into."""
335
336         self.spawnLldbMi(args = None)
337
338         # Load executable
339         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
340         self.expect("\^done")
341
342         # Warning: the following is sensitive to the lines in the
343         # source and optimizations
344
345         # Run to main
346         self.runCmd("-break-insert -f main")
347         self.expect("\^done,bkpt={number=\"1\"")
348         self.runCmd("-exec-run")
349         self.expect("\^running")
350         self.expect("\*stopped,reason=\"breakpoint-hit\"")
351
352         # Test that -exec-next steps over printf
353         self.runCmd("-exec-next --thread 1 --frame 0")
354         self.expect("\^running")
355         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"29\"")
356
357         # Test that -exec-step-instruction steps over non branching
358         # instruction
359         self.runCmd("-exec-step-instruction --thread 1 --frame 0")
360         self.expect("\^running")
361         self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\"")
362
363         # Test that -exec-step-instruction steps into g_MyFunction
364         # instruction (and that --thread is optional)
365         self.runCmd("-exec-step-instruction --frame 0")
366         self.expect("\^running")
367         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"g_MyFunction.*?\"")
368
369         # Test that -exec-step-instruction steps over non branching
370         # (and that --frame is optional)
371         self.runCmd("-exec-step-instruction --thread 1")
372         self.expect("\^running")
373         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"g_MyFunction.*?\"")
374
375         # Test that -exec-step-instruction steps into g_MyFunction
376         # (and that both --thread and --frame are optional)
377         self.runCmd("-exec-step-instruction")
378         self.expect("\^running")
379         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"g_MyFunction.*?\"")
380
381         # Test that an invalid --thread is handled
382         self.runCmd("-exec-step-instruction --thread 0")
383         self.expect("\^error,message=\"error: Thread index 0 is out of range")
384         self.runCmd("-exec-step-instruction --thread 10")
385         self.expect("\^error,message=\"error: Thread index 10 is out of range")
386
387         # Test that an invalid --frame is handled
388         # FIXME: no error is returned
389         self.runCmd("-exec-step-instruction --frame 10")
390         #self.expect("\^error: Frame index 10 is out of range")
391
392     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
393     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
394     def test_lldbmi_exec_finish(self):
395         """Test that 'lldb-mi --interpreter' works for -exec-finish."""
396
397         self.spawnLldbMi(args = None)
398
399         # Load executable
400         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
401         self.expect("\^done")
402
403         # Set BP at g_MyFunction and run to BP
404         self.runCmd("-break-insert -f g_MyFunction")
405         self.expect("\^done,bkpt={number=\"1\"")
406         self.runCmd("-exec-run")
407         self.expect("\^running")
408         self.expect("\*stopped,reason=\"breakpoint-hit\"")
409
410         # Test that -exec-finish returns from g_MyFunction
411         self.runCmd("-exec-finish --thread 1 --frame 0")
412         self.expect("\^running")
413         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
414
415         # Run to BP inside s_MyFunction call
416         self.runCmd("-break-insert s_MyFunction")
417         self.expect("\^done,bkpt={number=\"2\"")
418         self.runCmd("-exec-continue")
419         self.expect("\^running")
420         self.expect("\*stopped,reason=\"breakpoint-hit\"")
421
422         # Test that -exec-finish hits BP at g_MyFunction call inside
423         # s_MyFunction (and that --thread is optional)
424         self.runCmd("-exec-finish --frame 0")
425         self.expect("\^running")
426         self.expect("\*stopped,reason=\"breakpoint-hit\"")
427
428         # Test that -exec-finish returns from g_MyFunction call inside
429         # s_MyFunction (and that --frame is optional)
430         self.runCmd("-exec-finish --thread 1")
431         self.expect("\^running")
432         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\".*?s_MyFunction.*?\"")
433
434         # Test that -exec-finish returns from s_MyFunction
435         # (and that both --thread and --frame are optional)
436         self.runCmd("-exec-finish")
437         self.expect("\^running")
438         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
439
440         # Test that an invalid --thread is handled
441         self.runCmd("-exec-finish --thread 0")
442         self.expect("\^error,message=\"error: Thread index 0 is out of range")
443         self.runCmd("-exec-finish --thread 10")
444         self.expect("\^error,message=\"error: Thread index 10 is out of range")
445
446         # Test that an invalid --frame is handled
447         # FIXME: no error is returned
448         #self.runCmd("-exec-finish --frame 10")
449         #self.expect("\^error: Frame index 10 is out of range")
450
451         # Set BP at printf and run to BP
452         self.runCmd("-break-insert -f printf")
453         self.expect("\^done,bkpt={number=\"3\"")
454         self.runCmd("-exec-continue")
455         self.expect("\^running")
456         self.expect("\*stopped,reason=\"breakpoint-hit\"")
457
458         ## Test that -exec-finish returns from printf
459         self.runCmd("-exec-finish --thread 1 --frame 0")
460         self.expect("\^running")
461         self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")