]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiInterpreterExec.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / tools / lldb-mi / interpreter / TestMiInterpreterExec.py
1 """
2 Test lldb-mi -interpreter-exec command.
3 """
4
5 from __future__ import print_function
6
7
8 import lldbmi_testcase
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class MiInterpreterExecTestCase(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     def test_lldbmi_target_create(self):
21         """Test that 'lldb-mi --interpreter' can create target by 'target create' command."""
22
23         self.spawnLldbMi(args=None)
24
25         # Test that "target create" loads executable
26         self.runCmd(
27             "-interpreter-exec console \"target create \\\"%s\\\"\"" %
28             self.myexe)
29         self.expect("\^done")
30
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\"")
37
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."""
42
43         self.spawnLldbMi(args=None)
44
45         # Load executable
46         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
47         self.expect("\^done")
48
49         # Test that "breakpoint set" sets a breakpoint
50         self.runCmd("-interpreter-exec console \"breakpoint set --name main\"")
51         self.expect("\^done")
52         self.expect("=breakpoint-created,bkpt={number=\"1\"")
53
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\"")
59
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."""
65
66         self.spawnLldbMi(args=None)
67
68         # Test that "settings set target.run-args" passes arguments to executable
69         # FIXME: --arg1 causes an error
70         self.runCmd(
71             "-interpreter-exec console \"setting set target.run-args arg1 \\\"2nd arg\\\" third_arg fourth=\\\"4th arg\\\"\"")
72         self.expect("\^done")
73
74         # Load executable
75         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
76         self.expect("\^done")
77
78         # Run
79         self.runCmd("-exec-run")
80         self.expect("\^running")
81
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\"")
89
90         # Test that program exited normally
91         self.expect("\*stopped,reason=\"exited-normally\"")
92
93     @skipIfWindows  # llvm.org/pr24452: Get lldb-mi tests working on Windows
94     @skipIfFreeBSD  # llvm.org/pr22411: Failure presumably due to known thread races
95     @expectedFailureAll(
96         oslist=["linux"],
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."""
100
101         self.spawnLldbMi(args=None)
102
103         # Load executable
104         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
105         self.expect("\^done")
106
107         # Test that "settings set target.run-args" passes arguments to executable
108         # FIXME: --arg1 causes an error
109         self.runCmd(
110             "-interpreter-exec console \"setting set target.run-args arg1 \\\"2nd arg\\\" third_arg fourth=\\\"4th arg\\\"\"")
111         self.expect("\^done")
112
113         # Run to BP_printf
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\"")
120
121         # Run to BP_return
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")
127
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\"")
135
136         # Hit BP_return
137         self.expect("\*stopped,reason=\"breakpoint-hit\"")
138
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."""
143
144         self.spawnLldbMi(args=None)
145
146         # Load executable
147         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
148         self.expect("\^done")
149
150         # Set breakpoint
151         self.runCmd("-break-insert -f main")
152         self.expect("\^done,bkpt={number=\"1\"")
153
154         # Test that "process launch" launches executable
155         self.runCmd("-interpreter-exec console \"process launch\"")
156         self.expect("\^done")
157
158         # Test that breakpoint hit
159         self.expect("\*stopped,reason=\"breakpoint-hit\"")
160
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."""
165
166         self.spawnLldbMi(args=None)
167
168         # Load executable
169         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
170         self.expect("\^done")
171
172         # Run to main
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\"")
178
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\"
182         # Linux:
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).+?\""])
188         if it == 0:
189             self.expect(
190                 "\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
191
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."""
196
197         self.spawnLldbMi(args=None)
198
199         # Load executable
200         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
201         self.expect("\^done")
202
203         # Run to main
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\"")
209
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\"")
215
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."""
221
222         self.spawnLldbMi(args=None)
223
224         # Load executable
225         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
226         self.expect("\^done")
227
228         # Run to main
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\"")
234
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\"")