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    def base_test(self, variant):
13        class MyResponder(MockGDBServerResponder):
14            def __init__(self):
15                super().__init__()
16                self.first = True
17                self.detached = None
18                self.property = "{}-events+".format(variant)
19
20            def qSupported(self, client_supported):
21                assert "multiprocess+" in client_supported
22                assert self.property in client_supported
23                return "{};multiprocess+;{}".format(
24                    super().qSupported(client_supported), self.property)
25
26            def qfThreadInfo(self):
27                return "mp400.10200"
28
29            def cont(self):
30                if self.first:
31                    self.first = False
32                    return ("T0fthread:p400.10200;reason:{0};{0}:p401.10400;"
33                            .format(variant))
34                return "W00"
35
36            def D(self, packet):
37                self.detached = packet
38                return "OK"
39
40        self.server.responder = MyResponder()
41        target = self.dbg.CreateTarget('')
42        if self.TraceOn():
43          self.runCmd("log enable gdb-remote packets")
44          self.addTearDownHook(
45                lambda: self.runCmd("log disable gdb-remote packets"))
46        process = self.connect(target)
47        process.Continue()
48        self.assertRegex(self.server.responder.detached, r"D;0*401")
49
50    def test_fork(self):
51        self.base_test("fork")
52
53    def test_vfork(self):
54        self.base_test("vfork")
55