65 lines · python
1"""2Test that the process continues running after we detach from it.3"""4 5import lldb6import time7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class DetachResumesTestCase(TestBase):13 NO_DEBUG_INFO_TESTCASE = True14 15 @skipIf(16 oslist=["windows"],17 archs=["x86_64"],18 bugnumber="github.com/llvm/llvm-project/issues/144891",19 )20 def test_detach_resumes(self):21 self.build()22 exe = self.getBuildArtifact()23 24 # The inferior will use this file to let us know it is ready to be25 # attached.26 sync_file_path = lldbutil.append_to_process_working_directory(27 self, "sync_file_%d" % (int(time.time()))28 )29 30 # And this one to let us know it is running after we've detached from31 # it.32 exit_file_path = lldbutil.append_to_process_working_directory(33 self, "exit_file_%d" % (int(time.time()))34 )35 36 popen = self.spawnSubprocess(37 self.getBuildArtifact(exe), [sync_file_path, exit_file_path]38 )39 lldbutil.wait_for_file_on_target(self, sync_file_path)40 41 self.runCmd("process attach -p " + str(popen.pid))42 43 # Set a breakpoint at a place that will be called by multiple threads44 # simultaneously. On systems (e.g. linux) where the debugger needs to45 # send signals to suspend threads, these signals will race with threads46 # hitting the breakpoint (and stopping on their own).47 bpno = lldbutil.run_break_set_by_symbol(self, "break_here")48 49 # And let the inferior know it can call the function.50 self.runCmd("expr -- wait_for_debugger_flag = false")51 52 self.runCmd("continue")53 54 self.expect(55 "thread list",56 STOPPED_DUE_TO_BREAKPOINT,57 substrs=["stopped", "stop reason = breakpoint"],58 )59 60 # Detach, the process should keep running after this, and not be stopped61 # by the signals that the debugger may have used to suspend the threads.62 self.runCmd("detach")63 64 lldbutil.wait_for_file_on_target(self, exit_file_path)65