brintos

brintos / llvm-project-archived public Read only

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