xref: /llvm-project/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py (revision 4cc8f2a017c76af25234afc7c380550e9c93135c)
1"""
2Test process attach when executable was deleted.
3"""
4
5
6
7import os
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13class TestDeletedExecutable(TestBase):
14    NO_DEBUG_INFO_TESTCASE = True
15
16    @skipIfWindows # cannot delete a running executable
17    @expectedFailureAll(oslist=["linux"],
18        triple=no_match('aarch64-.*-android'))
19        # determining the architecture of the process fails
20    def test(self):
21        self.build()
22        exe = self.getBuildArtifact("a.out")
23
24        # Use a file as a synchronization point between test and inferior.
25        pid_file_path = lldbutil.append_to_process_working_directory(self,
26            "token_pid_%d" % (int(os.getpid())))
27        self.addTearDownHook(
28            lambda: self.run_platform_command(
29                "rm %s" %
30                (pid_file_path)))
31
32        # Spawn a new process
33        popen = self.spawnSubprocess(exe, [pid_file_path])
34
35        # Wait until process has fully started up.
36        pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
37
38        # Now we can safely remove the executable and test if we can attach.
39        os.remove(exe)
40
41        self.runCmd("process attach -p " + str(popen.pid))
42        self.runCmd("kill")
43