|
| 1 | +from __future__ import print_function |
| 2 | +import lldb |
| 3 | +from lldbsuite.test.lldbtest import * |
| 4 | +from lldbsuite.test.decorators import * |
| 5 | +from gdbclientutils import * |
| 6 | + |
| 7 | + |
| 8 | +class TestHaltFails(GDBRemoteTestBase): |
| 9 | + |
| 10 | + class MyResponder(MockGDBServerResponder): |
| 11 | + |
| 12 | + def setBreakpoint(self, packet): |
| 13 | + return "OK" |
| 14 | + |
| 15 | + def interrupt(self): |
| 16 | + # Simulate process waiting longer than the interrupt |
| 17 | + # timeout to stop, then sending the reply. |
| 18 | + time.sleep(14) |
| 19 | + return "T02reason:signal" |
| 20 | + |
| 21 | + def cont(self): |
| 22 | + # No response, wait for the client to interrupt us. |
| 23 | + return None |
| 24 | + |
| 25 | + def wait_for_and_check_event(self, wait_time, value): |
| 26 | + event = lldb.SBEvent() |
| 27 | + got_event = self.dbg.GetListener().WaitForEvent(wait_time, event) |
| 28 | + self.assertTrue(got_event, "Failed to get event after wait") |
| 29 | + self.assertTrue(lldb.SBProcess.EventIsProcessEvent(event), "Event was not a process event") |
| 30 | + event_type = lldb.SBProcess.GetStateFromEvent(event) |
| 31 | + self.assertEqual(event_type, value) |
| 32 | + |
| 33 | + def get_to_running(self): |
| 34 | + self.server.responder = self.MyResponder() |
| 35 | + self.target = self.createTarget("a.yaml") |
| 36 | + process = self.connect(self.target) |
| 37 | + self.dbg.SetAsync(True) |
| 38 | + |
| 39 | + # There should be a stopped event, consume that: |
| 40 | + self.wait_for_and_check_event(2, lldb.eStateStopped) |
| 41 | + process.Continue() |
| 42 | + |
| 43 | + # There should be a running event, consume that: |
| 44 | + self.wait_for_and_check_event(2, lldb.eStateRunning) |
| 45 | + return process |
| 46 | + |
| 47 | + @skipIfReproducer # FIXME: Unexpected packet during (passive) replay |
| 48 | + def test_destroy_while_running(self): |
| 49 | + process = self.get_to_running() |
| 50 | + process.Destroy() |
| 51 | + |
| 52 | + # Again pretend that after failing to be interrupted, we delivered the stop |
| 53 | + # and make sure we still exit properly. |
| 54 | + self.wait_for_and_check_event(14, lldb.eStateExited) |
| 55 | + |
| 56 | + @skipIfReproducer # FIXME: Unexpected packet during (passive) replay |
| 57 | + def test_async_interrupt(self): |
| 58 | + """ |
| 59 | + Test that explicitly calling AsyncInterrupt, which then fails, leads |
| 60 | + to an "eStateExited" state. |
| 61 | + """ |
| 62 | + process = self.get_to_running() |
| 63 | + # Now do the interrupt: |
| 64 | + process.SendAsyncInterrupt() |
| 65 | + |
| 66 | + # That should have caused the Halt to time out and we should |
| 67 | + # be in eStateExited: |
| 68 | + self.wait_for_and_check_event(15, lldb.eStateExited) |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
0 commit comments