brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 45d855f Raw
84 lines · python
1import os2import socket3import shutil4import lldbgdbserverutils5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 9 10class TestPlatformProcessLaunchGDBServer(TestBase):11    NO_DEBUG_INFO_TESTCASE = True12 13    def _launch_and_connect(self, exe):14        hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]15        listen_url = "[%s]:0" % hostname16 17        port_file = self.getBuildArtifact("port")18        commandline_args = [19            "platform",20            "--listen",21            listen_url,22            "--socket-file",23            port_file,24        ]25 26        self.spawnSubprocess(exe, commandline_args)27        socket_id = lldbutil.wait_for_file_on_target(self, port_file)28 29        new_platform = lldb.SBPlatform("remote-" + self.getPlatform())30        self.dbg.SetSelectedPlatform(new_platform)31 32        connect_url = "connect://[%s]:%s" % (hostname, socket_id)33        self.runCmd("platform connect %s" % connect_url)34 35        wd = self.getBuildArtifact("wd")36        os.mkdir(wd)37        new_platform.SetWorkingDirectory(wd)38 39    @skipIfRemote40    # Windows cannot delete the executable while it is running.41    # On Darwin we may be using debugserver.42    @skipUnlessPlatform(["linux"])43    @add_test_categories(["lldb-server"])44    def test_launch_error(self):45        """46        Check that errors while handling qLaunchGDBServer are reported to the47        user.  Though this isn't a platform command in itself, the best way to48        test it is from Python because we can juggle multiple processes more49        easily.50        """51 52        self.build()53 54        # Run lldb-server from a new location.55        new_lldb_server = self.getBuildArtifact("lldb-server")56        shutil.copy(lldbgdbserverutils.get_lldb_server_exe(), new_lldb_server)57        self._launch_and_connect(new_lldb_server)58 59        # Now, remove our new lldb-server so that when it tries to invoke itself as a60        # gdbserver, it fails.61        os.remove(new_lldb_server)62 63        self.runCmd("target create {}".format(self.getBuildArtifact("a.out")))64        self.expect("run", substrs=["unable to launch a GDB server on"], error=True)65 66    @skipIfRemote67    @skipIfDarwin  # Uses debugserver for debugging68    @add_test_categories(["lldb-server"])69    def test_launch_with_unusual_process_name(self):70        """71        Test that lldb-server can launch a debug session when running under an72        unusual name (or under a symlink which resolves to an unusal name).73        """74 75        self.build()76 77        # Run lldb-server from a new location.78        new_lldb_server = self.getBuildArtifact("obfuscated-server")79        shutil.copy(lldbgdbserverutils.get_lldb_server_exe(), new_lldb_server)80        self._launch_and_connect(new_lldb_server)81 82        self.runCmd("target create {}".format(self.getBuildArtifact("a.out")))83        self.expect("run", substrs=["exited with status = 0"])84