1""" 2debugserver used to block replying to the 'D' packet 3till it had joined the profiling thread. If the profiling interval 4was too long, that would mean it would take longer than the packet 5timeout to reply, and the detach would time out. Make sure that doesn't 6happen. 7""" 8 9 10 11import lldb 12import lldbsuite.test.lldbutil as lldbutil 13from lldbsuite.test.lldbtest import * 14from lldbsuite.test.decorators import * 15import os 16import signal 17 18class TestDetachVrsProfile(TestBase): 19 20 mydir = TestBase.compute_mydir(__file__) 21 22 NO_DEBUG_INFO_TESTCASE = True 23 24 @skipUnlessDarwin 25 @skipIfOutOfTreeDebugserver 26 @skipIfReproducer 27 def test_profile_and_detach(self): 28 """There can be many tests in a test case - describe this test here.""" 29 self.build() 30 self.main_source_file = lldb.SBFileSpec("main.c") 31 self.do_profile_and_detach() 32 33 def do_profile_and_detach(self): 34 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 35 "Set a breakpoint here", self.main_source_file) 36 37 interp = self.dbg.GetCommandInterpreter() 38 result = lldb.SBCommandReturnObject() 39 40 # First make sure we are getting async data. Set a short interval, continue a bit and check: 41 interp.HandleCommand("process plugin packet send 'QSetEnableAsyncProfiling;enable:1;interval_usec:500000;scan_type=0x5;'", result) 42 self.assertTrue(result.Succeeded(), "process packet send failed: %s"%(result.GetError())) 43 44 # Run a bit to give us a change to collect profile data: 45 bkpt.SetIgnoreCount(1) 46 threads = lldbutil.continue_to_breakpoint(process, bkpt) 47 self.assertEqual(len(threads), 1, "Hit our breakpoint again.") 48 str = process.GetAsyncProfileData(1000) 49 self.assertTrue(len(str) > 0, "Got some profile data") 50 51 # Now make the profiling interval very long and try to detach. 52 interp.HandleCommand("process plugin packet send 'QSetEnableAsyncProfiling;enable:1;interval_usec:10000000;scan_type=0x5;'", result) 53 self.assertTrue(result.Succeeded(), "process packet send failed: %s"%(result.GetError())) 54 self.dbg.SetAsync(True) 55 listener = self.dbg.GetListener() 56 57 # We don't want to hit our breakpoint anymore. 58 bkpt.SetEnabled(False) 59 60 # Record our process pid so we can kill it since we are going to detach... 61 self.pid = process.GetProcessID() 62 def cleanup(): 63 self.dbg.SetAsync(False) 64 os.kill(self.pid, signal.SIGKILL) 65 self.addTearDownHook(cleanup) 66 67 process.Continue() 68 69 event = lldb.SBEvent() 70 success = listener.WaitForEventForBroadcaster(0, process.GetBroadcaster(), event) 71 self.assertTrue(success, "Got an event which should be running.") 72 event_state = process.GetStateFromEvent(event) 73 self.assertEqual(event_state, lldb.eStateRunning, "Got the running event") 74 75 # Now detach: 76 error = process.Detach() 77 self.assertTrue(error.Success(), "Detached successfully") 78