2 Test lldb-mi -interpreter-exec command.
5 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class MiInterpreterExecTestCase(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 def test_lldbmi_target_create(self):
21 """Test that 'lldb-mi --interpreter' can create target by 'target create' command."""
23 self.spawnLldbMi(args=None)
25 # Test that "target create" loads executable
27 "-interpreter-exec console \"target create \\\"%s\\\"\"" %
31 # Test that executable was loaded properly
32 self.runCmd("-break-insert -f main")
33 self.expect("\^done,bkpt={number=\"1\"")
34 self.runCmd("-exec-run")
35 self.expect("\^running")
36 self.expect("\*stopped,reason=\"breakpoint-hit\"")
38 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
39 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
40 def test_lldbmi_breakpoint_set(self):
41 """Test that 'lldb-mi --interpreter' can set breakpoint by 'breakpoint set' command."""
43 self.spawnLldbMi(args=None)
46 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
49 # Test that "breakpoint set" sets a breakpoint
50 self.runCmd("-interpreter-exec console \"breakpoint set --name main\"")
52 self.expect("=breakpoint-created,bkpt={number=\"1\"")
54 # Test that breakpoint was set properly
55 self.runCmd("-exec-run")
56 self.expect("\^running")
57 self.expect("=breakpoint-modified,bkpt={number=\"1\"")
58 self.expect("\*stopped,reason=\"breakpoint-hit\"")
60 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
61 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
62 @expectedFlakeyLinux(bugnumber="llvm.org/pr25470")
63 def test_lldbmi_settings_set_target_run_args_before(self):
64 """Test that 'lldb-mi --interpreter' can set target arguments by 'setting set target.run-args' command before than target was created."""
66 self.spawnLldbMi(args=None)
68 # Test that "settings set target.run-args" passes arguments to executable
69 # FIXME: --arg1 causes an error
71 "-interpreter-exec console \"setting set target.run-args arg1 \\\"2nd arg\\\" third_arg fourth=\\\"4th arg\\\"\"")
75 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
79 self.runCmd("-exec-run")
80 self.expect("\^running")
82 # Test that arguments were passed properly
83 self.expect("@\"argc=5\\\\r\\\\n\"")
84 self.expect("@\"argv.0.=.*lldb-mi")
85 self.expect("@\"argv.1.=arg1\\\\r\\\\n\"")
86 self.expect("@\"argv.2.=2nd arg\\\\r\\\\n\"")
87 self.expect("@\"argv.3.=third_arg\\\\r\\\\n\"")
88 self.expect("@\"argv.4.=fourth=4th arg\\\\r\\\\n\"")
90 # Test that program exited normally
91 self.expect("\*stopped,reason=\"exited-normally\"")
93 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
94 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
97 bugnumber="Failing in ~9/600 dosep runs (build 3120-3122)")
98 def test_lldbmi_settings_set_target_run_args_after(self):
99 """Test that 'lldb-mi --interpreter' can set target arguments by 'setting set target.run-args' command after than target was created."""
101 self.spawnLldbMi(args=None)
104 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
105 self.expect("\^done")
107 # Test that "settings set target.run-args" passes arguments to executable
108 # FIXME: --arg1 causes an error
110 "-interpreter-exec console \"setting set target.run-args arg1 \\\"2nd arg\\\" third_arg fourth=\\\"4th arg\\\"\"")
111 self.expect("\^done")
114 line = line_number('main.cpp', '// BP_printf')
115 self.runCmd("-break-insert main.cpp:%d" % line)
116 self.expect("\^done,bkpt={number=\"1\"")
117 self.runCmd("-exec-run")
118 self.expect("\^running")
119 self.expect("\*stopped,reason=\"breakpoint-hit\"")
122 line = line_number('main.cpp', '// BP_return')
123 self.runCmd("-break-insert main.cpp:%d" % line)
124 self.expect("\^done,bkpt={number=\"2\"")
125 self.runCmd("-exec-continue")
126 self.expect("\^running")
128 # Test that arguments were passed properly
129 self.expect("@\"argc=5\\\\r\\\\n\"")
130 self.expect("@\"argv.0.=.*lldb-mi")
131 self.expect("@\"argv.1.=arg1\\\\r\\\\n\"")
132 self.expect("@\"argv.2.=2nd arg\\\\r\\\\n\"")
133 self.expect("@\"argv.3.=third_arg\\\\r\\\\n\"")
134 self.expect("@\"argv.4.=fourth=4th arg\\\\r\\\\n\"")
137 self.expect("\*stopped,reason=\"breakpoint-hit\"")
139 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
140 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
141 def test_lldbmi_process_launch(self):
142 """Test that 'lldb-mi --interpreter' can launch process by "process launch" command."""
144 self.spawnLldbMi(args=None)
147 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
148 self.expect("\^done")
151 self.runCmd("-break-insert -f main")
152 self.expect("\^done,bkpt={number=\"1\"")
154 # Test that "process launch" launches executable
155 self.runCmd("-interpreter-exec console \"process launch\"")
156 self.expect("\^done")
158 # Test that breakpoint hit
159 self.expect("\*stopped,reason=\"breakpoint-hit\"")
161 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
162 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
163 def test_lldbmi_thread_step_in(self):
164 """Test that 'lldb-mi --interpreter' can step in by "thread step-in" command."""
166 self.spawnLldbMi(args=None)
169 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
170 self.expect("\^done")
173 self.runCmd("-break-insert -f main")
174 self.expect("\^done,bkpt={number=\"1\"")
175 self.runCmd("-exec-run")
176 self.expect("\^running")
177 self.expect("\*stopped,reason=\"breakpoint-hit\"")
179 # Test that "thread step-in" steps into (or not) printf depending on debug info
180 # Note that message is different in Darwin and Linux:
181 # 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\"
183 # "*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\"
184 self.runCmd("-interpreter-exec console \"thread step-in\"")
185 self.expect("\^done")
186 it = self.expect(["@\"argc=1\\\\r\\\\n\"",
187 "\*stopped,reason=\"end-stepping-range\".+?func=\"(?!main).+?\""])
190 "\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
192 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
193 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
194 def test_lldbmi_thread_step_over(self):
195 """Test that 'lldb-mi --interpreter' can step over by "thread step-over" command."""
197 self.spawnLldbMi(args=None)
200 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
201 self.expect("\^done")
204 self.runCmd("-break-insert -f main")
205 self.expect("\^done,bkpt={number=\"1\"")
206 self.runCmd("-exec-run")
207 self.expect("\^running")
208 self.expect("\*stopped,reason=\"breakpoint-hit\"")
210 # Test that "thread step-over" steps over
211 self.runCmd("-interpreter-exec console \"thread step-over\"")
212 self.expect("\^done")
213 self.expect("@\"argc=1\\\\r\\\\n\"")
214 self.expect("\*stopped,reason=\"end-stepping-range\"")
216 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
217 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
218 @expectedFlakeyLinux("llvm.org/pr25470")
219 def test_lldbmi_thread_continue(self):
220 """Test that 'lldb-mi --interpreter' can continue execution by "thread continue" command."""
222 self.spawnLldbMi(args=None)
225 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
226 self.expect("\^done")
229 self.runCmd("-break-insert -f main")
230 self.expect("\^done,bkpt={number=\"1\"")
231 self.runCmd("-exec-run")
232 self.expect("\^running")
233 self.expect("\*stopped,reason=\"breakpoint-hit\"")
235 # Test that "thread continue" continues execution
236 self.runCmd("-interpreter-exec console \"thread continue\"")
237 self.expect("\^done")
238 self.expect("@\"argc=1\\\\r\\\\n")
239 self.expect("\*stopped,reason=\"exited-normally\"")