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