xref: /qemu/tests/tcg/multiarch/gdbstub/late-attach.py (revision ffaf7f0376f8040ce9068d71ae9ae8722505c42e)
1*24c61663SIlya Leoshkevich"""Test attaching GDB to a running process.
2*24c61663SIlya Leoshkevich
3*24c61663SIlya LeoshkevichSPDX-License-Identifier: GPL-2.0-or-later
4*24c61663SIlya Leoshkevich"""
5*24c61663SIlya Leoshkevichfrom test_gdbstub import main, report
6*24c61663SIlya Leoshkevich
7*24c61663SIlya Leoshkevich
8*24c61663SIlya Leoshkevichdef run_test():
9*24c61663SIlya Leoshkevich    """Run through the tests one by one"""
10*24c61663SIlya Leoshkevich    try:
11*24c61663SIlya Leoshkevich        phase = gdb.parse_and_eval("phase").string()
12*24c61663SIlya Leoshkevich    except gdb.error:
13*24c61663SIlya Leoshkevich        # Assume the guest did not reach main().
14*24c61663SIlya Leoshkevich        phase = "start"
15*24c61663SIlya Leoshkevich
16*24c61663SIlya Leoshkevich    if phase == "start":
17*24c61663SIlya Leoshkevich        gdb.execute("break sigwait")
18*24c61663SIlya Leoshkevich        gdb.execute("continue")
19*24c61663SIlya Leoshkevich        phase = gdb.parse_and_eval("phase").string()
20*24c61663SIlya Leoshkevich    report(phase == "sigwait", "{} == \"sigwait\"".format(phase))
21*24c61663SIlya Leoshkevich
22*24c61663SIlya Leoshkevich    gdb.execute("signal SIGUSR1")
23*24c61663SIlya Leoshkevich
24*24c61663SIlya Leoshkevich    exitcode = int(gdb.parse_and_eval("$_exitcode"))
25*24c61663SIlya Leoshkevich    report(exitcode == 0, "{} == 0".format(exitcode))
26*24c61663SIlya Leoshkevich
27*24c61663SIlya Leoshkevich
28*24c61663SIlya Leoshkevichmain(run_test)
29