2 Test lldb-mi -exec-xxx commands.
5 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
14 class MiExecTestCase(lldbmi_testcase.MiTestCaseBase):
16 mydir = TestBase.compute_mydir(__file__)
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."""
24 self.spawnLldbMi(args = None)
27 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
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)
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."""
42 self.spawnLldbMi(args = None)
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\"")
49 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
53 self.runCmd("-exec-arguments arg1")
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\"")
63 # Test that arguments were passed
64 self.runCmd("-data-evaluate-expression argc")
65 self.expect("\^done,value=\"2\"")
67 # Test that program may be aborted
68 self.runCmd("-exec-abort")
70 self.expect("\*stopped,reason=\"exited-normally\"")
72 # Test that program can be run again
73 self.runCmd("-exec-run")
74 self.expect("\^running")
75 self.expect("\*stopped,reason=\"breakpoint-hit\"")
77 # Test that arguments were passed again
78 self.runCmd("-data-evaluate-expression argc")
79 self.expect("\^done,value=\"2\"")
81 # Test that program may be aborted again
82 self.runCmd("-exec-abort")
84 self.expect("\*stopped,reason=\"exited-normally\"")
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."""
91 self.spawnLldbMi(args = None)
94 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
98 self.runCmd("-exec-arguments --arg1 \"2nd arg\" third_arg fourth=\"4th arg\"")
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\"")
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\\\\\\\"\"")
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."""
133 self.spawnLldbMi(args = None)
136 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
137 self.expect("\^done")
140 self.runCmd("-exec-arguments arg1")
141 self.expect("\^done")
142 self.runCmd("-exec-arguments")
143 self.expect("\^done")
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\"")
152 # Check argc to see if arg passed
153 self.runCmd("-data-evaluate-expression argc")
154 self.expect("\^done,value=\"1\"")
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."""
161 self.spawnLldbMi(args = None)
164 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
165 self.expect("\^done")
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\"")
174 # Warning: the following is sensitive to the lines in the source
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\"")
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\"")
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\"")
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\"")
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")
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")
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."""
213 self.spawnLldbMi(args = None)
216 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
217 self.expect("\^done")
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\"")
226 # Warning: the following is sensitive to the lines in the
227 # source and optimizations
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\"")
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)\"")
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)\"")
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)\"")
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")
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")
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."""
268 self.spawnLldbMi(args = None)
271 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
272 self.expect("\^done")
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\"")
281 # Warning: the following is sensitive to the lines in the source
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
293 self.runCmd("-exec-finish")
294 self.expect("\^running")
295 self.expect("\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
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\"")
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.*?\"")
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.*?\"")
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")
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")
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."""
336 self.spawnLldbMi(args = None)
339 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
340 self.expect("\^done")
342 # Warning: the following is sensitive to the lines in the
343 # source and optimizations
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\"")
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\"")
357 # Test that -exec-step-instruction steps over non branching
359 self.runCmd("-exec-step-instruction --thread 1 --frame 0")
360 self.expect("\^running")
361 self.expect("\*stopped,reason=\"end-stepping-range\".+?main\.cpp\"")
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.*?\"")
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.*?\"")
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.*?\"")
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")
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")
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."""
397 self.spawnLldbMi(args = None)
400 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
401 self.expect("\^done")
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\"")
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\"")
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\"")
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\"")
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.*?\"")
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\"")
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")
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")
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\"")
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\"")