xref: /llvm-project/lldb/test/API/functionalities/deleted-executable/TestDeletedExecutable.py (revision 2084330e41d301cf9eaa3495d8968bff70846c7b)
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
15    mydir = TestBase.compute_mydir(__file__)
16    NO_DEBUG_INFO_TESTCASE = True
17
18    @skipIfWindows # cannot delete a running executable
19    @expectedFailureAll(oslist=["linux"],
20        triple=no_match('aarch64-.*-android'))
21        # determining the architecture of the process fails
22    @expectedFailureNetBSD
23    @skipIfReproducer # File synchronization is not supported during replay.
24    def test(self):
25        self.build()
26        exe = self.getBuildArtifact("a.out")
27
28        # Use a file as a synchronization point between test and inferior.
29        pid_file_path = lldbutil.append_to_process_working_directory(self,
30            "token_pid_%d" % (int(os.getpid())))
31        self.addTearDownHook(
32            lambda: self.run_platform_command(
33                "rm %s" %
34                (pid_file_path)))
35
36        # Spawn a new process
37        popen = self.spawnSubprocess(exe, [pid_file_path])
38        self.addTearDownHook(self.cleanupSubprocesses)
39
40        # Wait until process has fully started up.
41        pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
42
43        # Now we can safely remove the executable and test if we can attach.
44        os.remove(exe)
45
46        self.runCmd("process attach -p " + str(popen.pid))
47        self.runCmd("kill")
48