1 from lldbsuite
.test
.decorators
import *
2 from lldbsuite
.test
.lldbtest
import *
4 import gdbremote_testcase
7 class LldbGdbServerTestCase(gdbremote_testcase
.GdbRemoteTestCaseBase
):
8 @skipIfWindows # no SIGSEGV support
9 @add_test_categories(["llgs"])
12 self
.set_inferior_startup_launch()
14 procs
= self
.prep_debug_monitor_and_inferior(
15 inferior_args
=["thread:segfault"] + thread_num
* ["thread:new"]
17 self
.test_sequence
.add_log_lines(
19 "read packet: $QNonStop:1#00",
20 "send packet: $OK#00",
22 "send packet: $OK#00",
26 self
.expect_gdbremote_sequence()
28 segv_signo
= lldbutil
.get_signal_number("SIGSEGV")
32 # we should get segfaults from all the threads
33 for segv_no
in range(thread_num
):
34 # first wait for the notification event
35 self
.reset_test_sequence()
36 self
.test_sequence
.add_log_lines(
40 "regex": r
"^%Stop:(T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);)",
41 "capture": {1: "packet", 2: "signo", 3: "thread_id"},
46 m
= self
.expect_gdbremote_sequence()
50 # then we may get events for the remaining threads
51 # (but note that not all threads may have been started yet)
53 self
.reset_test_sequence()
54 self
.test_sequence
.add_log_lines(
56 "read packet: $vStopped#00",
59 "regex": r
"^\$(OK|T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);)",
60 "capture": {1: "packet", 2: "signo", 3: "thread_id"},
65 m
= self
.expect_gdbremote_sequence()
66 if m
["packet"] == "OK":
74 signo
= int(t
["signo"], 16)
75 if signo
== segv_signo
:
76 segv_threads
.append(t
["thread_id"])
78 self
.assertEqual(signo
, 0)
79 other_threads
.append(t
["thread_id"])
81 # verify that exactly one thread segfaulted
82 self
.assertEqual(len(segv_threads
), 1)
83 # we should get only one segv from every thread
84 self
.assertNotIn(segv_threads
[0], all_segv_threads
)
85 all_segv_threads
.extend(segv_threads
)
86 # segv_threads + other_threads should always be a superset
87 # of all_threads, i.e. we should get states for all threads
89 self
.assertFalse(all_threads
.difference(other_threads
+ segv_threads
))
90 all_threads
.update(other_threads
+ segv_threads
)
92 # verify that `?` returns the same result
93 self
.reset_test_sequence()
94 self
.test_sequence
.add_log_lines(
102 self
.test_sequence
.add_log_lines(
106 "regex": r
"^\$(OK|T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);)",
107 "capture": {1: "packet", 2: "signo", 3: "thread_id"},
112 m
= self
.expect_gdbremote_sequence()
113 if m
["packet"] == "OK":
116 threads_verify
.append(m
)
117 self
.reset_test_sequence()
118 self
.test_sequence
.add_log_lines(
120 "read packet: $vStopped#00",
125 self
.assertEqual(threads
, threads_verify
)
127 self
.reset_test_sequence()
128 self
.test_sequence
.add_log_lines(
130 "read packet: $vCont;C{:02x}:{};c#00".format(
131 segv_signo
, segv_threads
[0]
133 "send packet: $OK#00",
137 self
.expect_gdbremote_sequence()
139 # finally, verify that all threads have started
140 self
.assertEqual(len(all_threads
), thread_num
+ 1)
142 @add_test_categories(["llgs"])
143 def test_vCtrlC(self
):
145 self
.set_inferior_startup_launch()
146 procs
= self
.prep_debug_monitor_and_inferior(inferior_args
=["thread:new"])
147 self
.test_sequence
.add_log_lines(
149 "read packet: $QNonStop:1#00",
150 "send packet: $OK#00",
151 "read packet: $c#63",
152 "send packet: $OK#00",
153 "read packet: $vCtrlC#00",
154 "send packet: $OK#00",
157 "regex": r
"^%Stop:T",
162 self
.expect_gdbremote_sequence()
164 @add_test_categories(["llgs"])
167 self
.set_inferior_startup_launch()
168 procs
= self
.prep_debug_monitor_and_inferior()
169 self
.test_sequence
.add_log_lines(
171 "read packet: $QNonStop:1#00",
172 "send packet: $OK#00",
173 "read packet: $c#63",
174 "send packet: $OK#00",
175 "send packet: %Stop:W00#00",
176 "read packet: $vStopped#00",
177 "send packet: $OK#00",
181 self
.expect_gdbremote_sequence()
183 @skipIfWindows # no clue, the result makes zero sense
184 @add_test_categories(["llgs"])
185 def test_exit_query(self
):
187 self
.set_inferior_startup_launch()
188 procs
= self
.prep_debug_monitor_and_inferior()
189 self
.test_sequence
.add_log_lines(
191 "read packet: $QNonStop:1#00",
192 "send packet: $OK#00",
193 "read packet: $c#63",
194 "send packet: $OK#00",
195 "send packet: %Stop:W00#00",
196 "read packet: $?#00",
197 "send packet: $W00#00",
198 "read packet: $vStopped#00",
199 "send packet: $OK#00",
203 self
.expect_gdbremote_sequence()
205 def multiple_resume_test(self
, second_command
):
207 self
.set_inferior_startup_launch()
208 procs
= self
.prep_debug_monitor_and_inferior(inferior_args
=["sleep:15"])
209 self
.test_sequence
.add_log_lines(
211 "read packet: $QNonStop:1#00",
212 "send packet: $OK#00",
213 "read packet: $c#63",
214 "send packet: $OK#00",
215 "read packet: ${}#00".format(second_command
),
216 "send packet: $E37#00",
220 self
.expect_gdbremote_sequence()
222 @add_test_categories(["llgs"])
223 def test_multiple_C(self
):
224 self
.multiple_resume_test("C05")
226 @add_test_categories(["llgs"])
227 def test_multiple_c(self
):
228 self
.multiple_resume_test("c")
230 @add_test_categories(["llgs"])
231 def test_multiple_s(self
):
232 self
.multiple_resume_test("s")
235 @add_test_categories(["llgs"])
236 def test_multiple_vCont(self
):
238 self
.set_inferior_startup_launch()
239 procs
= self
.prep_debug_monitor_and_inferior(
240 inferior_args
=["thread:new", "stop", "sleep:15"]
242 self
.test_sequence
.add_log_lines(
244 "read packet: $QNonStop:1#00",
245 "send packet: $OK#00",
246 "read packet: $c#63",
247 "send packet: $OK#00",
250 "regex": r
"^%Stop:T[0-9a-fA-F]{2}thread:([0-9a-fA-F]+);",
251 "capture": {1: "tid1"},
253 "read packet: $vStopped#63",
256 "regex": r
"^[$]T[0-9a-fA-F]{2}thread:([0-9a-fA-F]+);",
257 "capture": {1: "tid2"},
259 "read packet: $vStopped#63",
260 "send packet: $OK#00",
264 ret
= self
.expect_gdbremote_sequence()
266 self
.reset_test_sequence()
267 self
.test_sequence
.add_log_lines(
269 "read packet: $vCont;c:{}#00".format(ret
["tid1"]),
270 "send packet: $OK#00",
271 "read packet: $vCont;c:{}#00".format(ret
["tid2"]),
272 "send packet: $E37#00",
276 self
.expect_gdbremote_sequence()
278 @add_test_categories(["llgs"])
279 def test_vCont_then_stop(self
):
281 self
.set_inferior_startup_launch()
282 procs
= self
.prep_debug_monitor_and_inferior(inferior_args
=["sleep:15"])
283 self
.test_sequence
.add_log_lines(
285 "read packet: $QNonStop:1#00",
286 "send packet: $OK#00",
287 "read packet: $c#63",
288 "send packet: $OK#00",
289 "read packet: $vCont;t#00",
290 "send packet: $OK#00",
294 self
.expect_gdbremote_sequence()
296 def vCont_then_partial_stop_test(self
, run_both
):
298 self
.set_inferior_startup_launch()
299 procs
= self
.prep_debug_monitor_and_inferior(
300 inferior_args
=["thread:new", "stop", "sleep:15"]
302 self
.test_sequence
.add_log_lines(
304 "read packet: $QNonStop:1#00",
305 "send packet: $OK#00",
306 "read packet: $c#63",
307 "send packet: $OK#00",
310 "regex": r
"^%Stop:T[0-9a-fA-F]{2}thread:([0-9a-fA-F]+);",
311 "capture": {1: "tid1"},
313 "read packet: $vStopped#63",
316 "regex": r
"^[$]T[0-9a-fA-F]{2}thread:([0-9a-fA-F]+);",
317 "capture": {1: "tid2"},
319 "read packet: $vStopped#63",
320 "send packet: $OK#00",
324 ret
= self
.expect_gdbremote_sequence()
326 self
.reset_test_sequence()
328 self
.test_sequence
.add_log_lines(
330 "read packet: $vCont;c#00",
335 self
.test_sequence
.add_log_lines(
337 "read packet: $vCont;c:{}#00".format(ret
["tid1"]),
341 self
.test_sequence
.add_log_lines(
343 "send packet: $OK#00",
344 "read packet: $vCont;t:{}#00".format(ret
["tid2"]),
345 "send packet: $E03#00",
349 self
.expect_gdbremote_sequence()
352 @add_test_categories(["llgs"])
353 def test_vCont_then_partial_stop(self
):
354 self
.vCont_then_partial_stop_test(False)
357 @add_test_categories(["llgs"])
358 def test_vCont_then_partial_stop_run_both(self
):
359 self
.vCont_then_partial_stop_test(True)
362 @add_test_categories(["llgs"])
363 def test_stdio(self
):
365 self
.set_inferior_startup_launch()
366 # Since we can't easily ensure that lldb will send output in two parts,
367 # just put a stop in the middle. Since we don't clear vStdio,
368 # the second message won't be delivered immediately.
369 self
.prep_debug_monitor_and_inferior(
370 inferior_args
=["message 1", "stop", "message 2"]
372 self
.test_sequence
.add_log_lines(
374 "read packet: $QNonStop:1#00",
375 "send packet: $OK#00",
376 "read packet: $c#63",
377 "send packet: $OK#00",
378 {"direction": "send", "regex": r
"^%Stop:T.*"},
379 "read packet: $vStopped#00",
380 "send packet: $OK#00",
381 "read packet: $c#63",
382 "send packet: $OK#00",
383 "send packet: %Stop:W00#00",
387 ret
= self
.expect_gdbremote_sequence()
389 # We know there will be at least two messages, but there may be more.
390 # Loop until we have everything. The first message waiting for us in the
393 output
= self
._server
.get_raw_output_packet()
394 while not (b
"message 2\r\n" in output
):
395 self
._server
.send_packet(b
"vStdio")
396 output
+= self
._server
.get_raw_output_packet()
398 self
.assertGreaterEqual(count
, 2)
400 self
.reset_test_sequence()
401 self
.test_sequence
.add_log_lines(
403 "read packet: $vStdio#00",
404 "send packet: $OK#00",
405 "read packet: $vStopped#00",
406 "send packet: $OK#00",
410 self
.expect_gdbremote_sequence()
413 @add_test_categories(["llgs"])
414 def test_stop_reason_while_running(self
):
416 self
.set_inferior_startup_launch()
417 procs
= self
.prep_debug_monitor_and_inferior(
418 inferior_args
=["thread:new", "thread:new", "stop", "sleep:15"]
420 self
.test_sequence
.add_log_lines(
422 "read packet: $QNonStop:1#00",
423 "send packet: $OK#00",
424 # stop is used to synchronize starting threads
425 "read packet: $c#63",
426 "send packet: $OK#00",
427 {"direction": "send", "regex": "%Stop:T.*"},
428 "read packet: $c#63",
429 "send packet: $OK#00",
430 "read packet: $?#00",
431 "send packet: $OK#00",
435 self
.expect_gdbremote_sequence()
438 @add_test_categories(["llgs"])
439 def test_leave_nonstop(self
):
441 self
.set_inferior_startup_launch()
442 procs
= self
.prep_debug_monitor_and_inferior(
443 inferior_args
=["thread:new", "thread:new", "stop", "sleep:15"]
445 self
.test_sequence
.add_log_lines(
447 "read packet: $QNonStop:1#00",
448 "send packet: $OK#00",
449 # stop is used to synchronize starting threads
450 "read packet: $c#63",
451 "send packet: $OK#00",
452 {"direction": "send", "regex": "%Stop:T.*"},
453 "read packet: $c#63",
454 "send packet: $OK#00",
455 # verify that the threads are running now
456 "read packet: $?#00",
457 "send packet: $OK#00",
458 "read packet: $QNonStop:0#00",
459 "send packet: $OK#00",
460 # we should issue some random request now to verify that the stub
461 # did not send stop reasons -- we may verify whether notification
462 # queue was cleared while at it
463 "read packet: $vStopped#00",
464 "send packet: $Eff#00",
465 "read packet: $?#00",
466 {"direction": "send", "regex": "[$]T.*"},
470 self
.expect_gdbremote_sequence()