xref: /llvm-project/lldb/test/API/functionalities/gdb_remote_client/TestRestartBug.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1import lldb
2from lldbsuite.test.lldbtest import *
3from lldbsuite.test.decorators import *
4from lldbsuite.test.gdbclientutils import *
5from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
6
7
8class TestRestartBug(GDBRemoteTestBase):
9    @expectedFailureAll(bugnumber="llvm.org/pr24530")
10    def test(self):
11        """
12        Test auto-continue behavior when a process is interrupted to deliver
13        an "asynchronous" packet. This simulates the situation when a process
14        stops on its own just as lldb client is about to interrupt it. The
15        client should not auto-continue in this case, unless the user has
16        explicitly requested that we ignore signals of this type.
17        """
18
19        class MyResponder(MockGDBServerResponder):
20            continueCount = 0
21
22            def setBreakpoint(self, packet):
23                return "OK"
24
25            def interrupt(self):
26                # Simulate process stopping due to a raise(SIGINT) just as lldb
27                # is about to interrupt it.
28                return "T02reason:signal"
29
30            def cont(self):
31                self.continueCount += 1
32                if self.continueCount == 1:
33                    # No response, wait for the client to interrupt us.
34                    return None
35                return "W00"  # Exit
36
37        self.server.responder = MyResponder()
38        target = self.createTarget("a.yaml")
39        process = self.connect(target)
40        self.dbg.SetAsync(True)
41        process.Continue()
42
43        # resume the process and immediately try to set another breakpoint. When using the remote
44        # stub, this will trigger a request to stop the process.  Make sure we
45        # do not lose this signal.
46        bkpt = target.BreakpointCreateByAddress(0x1234)
47        self.assertTrue(bkpt.IsValid())
48        self.assertEqual(bkpt.GetNumLocations(), 1)
49
50        event = lldb.SBEvent()
51        while self.dbg.GetListener().WaitForEvent(2, event):
52            if self.TraceOn():
53                print(
54                    "Process changing state to:",
55                    self.dbg.StateAsCString(process.GetStateFromEvent(event)),
56                )
57            if process.GetStateFromEvent(event) == lldb.eStateExited:
58                break
59
60        # We should get only one continue packet as the client should not
61        # auto-continue after setting the breakpoint.
62        self.assertEqual(self.server.responder.continueCount, 1)
63        # And the process should end up in the stopped state.
64        self.assertState(process.GetState(), lldb.eStateStopped)
65