ed17d9b36b6b0fb4e2bcd88e29d0a16173ceb677
[openbsd] /
1 """
2 Test process attach when executable was deleted.
3 """
4
5
6
7 import os
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13 class 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     def test(self):
24         self.build()
25         exe = self.getBuildArtifact("a.out")
26
27         # Use a file as a synchronization point between test and inferior.
28         pid_file_path = lldbutil.append_to_process_working_directory(self,
29             "token_pid_%d" % (int(os.getpid())))
30         self.addTearDownHook(
31             lambda: self.run_platform_command(
32                 "rm %s" %
33                 (pid_file_path)))
34
35         # Spawn a new process
36         popen = self.spawnSubprocess(exe, [pid_file_path])
37         self.addTearDownHook(self.cleanupSubprocesses)
38
39         # Wait until process has fully started up.
40         pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
41
42         # Now we can safely remove the executable and test if we can attach.
43         os.remove(exe)
44
45         self.runCmd("process attach -p " + str(popen.pid))
46         self.runCmd("kill")