1from __future__ import print_function 2import lldb 3import unittest 4from lldbsuite.test.lldbtest import * 5from lldbsuite.test.decorators import * 6from lldbsuite.test.gdbclientutils import * 7from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase 8 9 10class TestMultiprocess(GDBRemoteTestBase): 11 12 mydir = TestBase.compute_mydir(__file__) 13 14 def base_test(self, variant): 15 class MyResponder(MockGDBServerResponder): 16 def __init__(self): 17 super().__init__() 18 self.first = True 19 self.detached = None 20 self.property = "{}-events+".format(variant) 21 22 def qSupported(self, client_supported): 23 assert "multiprocess+" in client_supported 24 assert self.property in client_supported 25 return "{};multiprocess+;{}".format( 26 super().qSupported(client_supported), self.property) 27 28 def qfThreadInfo(self): 29 return "mp400.10200" 30 31 def cont(self): 32 if self.first: 33 self.first = False 34 return ("T0fthread:p400.10200;reason:{0};{0}:p401.10400;" 35 .format(variant)) 36 return "W00" 37 38 def D(self, packet): 39 self.detached = packet 40 return "OK" 41 42 self.server.responder = MyResponder() 43 target = self.dbg.CreateTarget('') 44 if self.TraceOn(): 45 self.runCmd("log enable gdb-remote packets") 46 self.addTearDownHook( 47 lambda: self.runCmd("log disable gdb-remote packets")) 48 process = self.connect(target) 49 process.Continue() 50 self.assertRegex(self.server.responder.detached, r"D;0*401") 51 52 def test_fork(self): 53 self.base_test("fork") 54 55 def test_vfork(self): 56 self.base_test("vfork") 57