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    @skipIfDarwin # lldb-server not found correctly
15    @expectedFailureAll(oslist=["windows"]) # process modules not loaded
16    @add_test_categories(["lldb-server"])
17    def test_platform_process_connect(self):
18        self.build()
19
20        hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
21        listen_url = "[%s]:0"%hostname
22
23        port_file = self.getBuildArtifact("port")
24        commandline_args = [
25            "platform",
26            "--listen",
27            listen_url,
28            "--socket-file",
29            port_file,
30            "--",
31            self.getBuildArtifact("a.out"),
32            "foo"]
33        self.spawnSubprocess(
34            lldbgdbserverutils.get_lldb_server_exe(),
35            commandline_args)
36
37        socket_id = lldbutil.wait_for_file_on_target(self, port_file)
38
39        new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
40        self.dbg.SetSelectedPlatform(new_platform)
41
42        connect_url = "connect://[%s]:%s" % (hostname, socket_id)
43        self.runCmd("platform connect %s" % connect_url)
44
45        lldbutil.run_break_set_by_symbol(self, "main")
46        process = self.process()
47
48        process.Continue()
49
50        frame = self.frame()
51        self.assertEqual(frame.GetFunction().GetName(), "main")
52        self.assertEqual(frame.FindVariable("argc").GetValueAsSigned(), 2)
53        process.Continue()
54