68 lines · python
1"""2Test that ConnectRemote sets ShouldDetach flag correctly.3 4When connecting to a remote process that stops after connection,5the process should be marked for detach (not kill) on destruction.6"""7 8import lldb9from lldbsuite.test.lldbtest import *10from lldbsuite.test.decorators import *11from lldbsuite.test.gdbclientutils import *12from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase13from lldbsuite.test import lldbutil14 15 16class TestConnectRemoteDetach(GDBRemoteTestBase):17 """Test that ConnectRemote properly sets ShouldDetach flag."""18 19 class StoppedResponder(MockGDBServerResponder):20 """A responder that returns a stopped process."""21 22 def qfThreadInfo(self):23 return "m1"24 25 def qsThreadInfo(self):26 return "l"27 28 def qC(self):29 return "QC1"30 31 def haltReason(self):32 # Return that we're stopped33 return "T05thread:1;"34 35 def cont(self):36 # Stay stopped37 return "T05thread:1;"38 39 def D(self):40 # Detach packet: this is what we want to verify gets called.41 return "OK"42 43 def k(self):44 # Kill packet: this is what we want to verify doesn't get called.45 raise RuntimeError("should not receive k(ill) packet")46 47 def test_connect_remote_sets_detach(self):48 """Test that ConnectRemote to a stopped process sets ShouldDetach."""49 self.server.responder = self.StoppedResponder()50 51 target = self.createTarget("a.yaml")52 process = self.connect(target)53 54 # Wait for the process to be in stopped state after connecting.55 # When ConnectRemote connects to a remote process that is stopped,56 # it should call SetShouldDetach(true) before CompleteAttach().57 lldbutil.expect_state_changes(58 self, self.dbg.GetListener(), process, [lldb.eStateStopped]59 )60 61 # Now destroy the process. Because ShouldDetach was set to true62 # during ConnectRemote, this should send a 'D' (detach) packet63 # rather than a 'k' (kill) packet when the process is destroyed.64 process.Destroy()65 66 # Verify that the (D)etach packet was sent.67 self.assertPacketLogReceived(["D"])68