1import socket
2import gdbremote_testcase
3import lldbgdbserverutils
4from lldbsuite.test.decorators import *
5from lldbsuite.test.lldbtest import *
6from lldbsuite.test import lldbutil
7
8class TestPlatformProcessConnect(TestBase):
9    mydir = TestBase.compute_mydir(__file__)
10    NO_DEBUG_INFO_TESTCASE = True
11
12    @skipIfRemote
13    @expectedFailureAll(hostoslist=["windows"], triple='.*-android')
14    @skipIfWindows # lldb-server does not terminate correctly
15    @skipIfDarwin # lldb-server not found correctly
16    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Fails randomly
17    @add_test_categories(["lldb-server"])
18    def test_platform_process_connect(self):
19        self.build()
20
21        hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
22        listen_url = "[%s]:0"%hostname
23
24        port_file = self.getBuildArtifact("port")
25        commandline_args = [
26            "platform",
27            "--listen",
28            listen_url,
29            "--socket-file",
30            port_file,
31            "--",
32            self.getBuildArtifact("a.out"),
33            "foo"]
34        self.spawnSubprocess(
35            lldbgdbserverutils.get_lldb_server_exe(),
36            commandline_args)
37
38        socket_id = lldbutil.wait_for_file_on_target(self, port_file)
39
40        new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
41        self.dbg.SetSelectedPlatform(new_platform)
42
43        connect_url = "connect://[%s]:%s" % (hostname, socket_id)
44        self.runCmd("platform connect %s" % connect_url)
45
46        lldbutil.run_break_set_by_symbol(self, "main")
47        process = self.process()
48
49        process.Continue()
50
51        frame = self.frame()
52        self.assertEqual(frame.GetFunction().GetName(), "main")
53        self.assertEqual(frame.FindVariable("argc").GetValueAsSigned(), 2)
54        process.Continue()
55