brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 41b309f Raw
40 lines · python
1"""2Test process attach when executable was deleted.3"""4 5 6import os7import lldb8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10from lldbsuite.test import lldbutil11 12 13class TestDeletedExecutable(TestBase):14    NO_DEBUG_INFO_TESTCASE = True15 16    @skipIfWindows  # cannot delete a running executable17    def test(self):18        self.build()19        exe = self.getBuildArtifact("a.out")20 21        # Use a file as a synchronization point between test and inferior.22        pid_file_path = lldbutil.append_to_process_working_directory(23            self, "token_pid_%d" % (int(os.getpid()))24        )25        self.addTearDownHook(26            lambda: self.run_platform_command("rm %s" % (pid_file_path))27        )28 29        # Spawn a new process30        popen = self.spawnSubprocess(exe, [pid_file_path])31 32        # Wait until process has fully started up.33        pid = lldbutil.wait_for_file_on_target(self, pid_file_path)34 35        # Now we can safely remove the executable and test if we can attach.36        os.remove(exe)37 38        self.runCmd("process attach -p " + str(popen.pid))39        self.runCmd("kill")40