80 lines · python
1"""Test that we are able to evaluate expressions when the inferior is blocked in a syscall"""2 3import lldb4from lldbsuite.test.decorators import *5from lldbsuite.test.lldbtest import *6from lldbsuite.test import lldbutil7 8 9class ExprSyscallTestCase(TestBase):10 @expectedFailureNetBSD11 def test_setpgid(self):12 self.build()13 14 # Create a target by the debugger.15 target = self.createTestTarget()16 17 listener = lldb.SBListener("my listener")18 19 # launch the inferior and don't wait for it to stop20 self.dbg.SetAsync(True)21 error = lldb.SBError()22 flags = target.GetLaunchInfo().GetLaunchFlags()23 process = target.Launch(24 listener,25 None, # argv26 None, # envp27 None, # stdin_path28 None, # stdout_path29 None, # stderr_path30 None, # working directory31 flags, # launch flags32 False, # Stop at entry33 error,34 ) # error35 36 self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)37 38 event = lldb.SBEvent()39 40 # Give the child enough time to reach the syscall,41 # while clearing out all the pending events.42 # The last WaitForEvent call will time out after 2 seconds.43 while listener.WaitForEvent(2, event):44 pass45 46 # now the process should be running (blocked in the syscall)47 self.assertEqual(process.GetState(), lldb.eStateRunning, "Process is running")48 49 # send the process a signal50 process.SendAsyncInterrupt()51 while listener.WaitForEvent(2, event):52 pass53 54 # as a result the process should stop55 # in all likelihood we have stopped in the middle of the sleep()56 # syscall57 self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)58 thread = process.GetSelectedThread()59 60 # try evaluating a couple of expressions in this state61 self.expect_expr("release_flag = 1", result_value="1")62 func = (63 "GetCurrentProcessId"64 if lldbplatformutil.getPlatform() == "windows"65 else "getpid"66 )67 self.expect_expr(f"(int){func}()", result_value=str(process.GetProcessID()))68 69 # and run the process to completion70 process.Continue()71 72 # process all events73 while listener.WaitForEvent(10, event):74 new_state = lldb.SBProcess.GetStateFromEvent(event)75 if new_state == lldb.eStateExited:76 break77 78 self.assertState(process.GetState(), lldb.eStateExited)79 self.assertEqual(process.GetExitStatus(), 0)80