1"""Test that we are able to evaluate expressions when the inferior is blocked in a syscall""" 2 3import lldb 4from lldbsuite.test.decorators import * 5from lldbsuite.test.lldbtest import * 6from lldbsuite.test import lldbutil 7 8 9class ExprSyscallTestCase(TestBase): 10 11 mydir = TestBase.compute_mydir(__file__) 12 13 @expectedFailureAll( 14 oslist=["windows"], 15 bugnumber="llvm.org/pr21765, getpid() does not exist on Windows") 16 @expectedFailureNetBSD 17 @skipIfReproducer 18 def test_setpgid(self): 19 self.build() 20 self.expr_syscall() 21 22 def expr_syscall(self): 23 exe = self.getBuildArtifact("a.out") 24 25 # Create a target by the debugger. 26 target = self.dbg.CreateTarget(exe) 27 self.assertTrue(target, VALID_TARGET) 28 29 listener = lldb.SBListener("my listener") 30 31 # launch the inferior and don't wait for it to stop 32 self.dbg.SetAsync(True) 33 error = lldb.SBError() 34 process = target.Launch(listener, 35 None, # argv 36 None, # envp 37 None, # stdin_path 38 None, # stdout_path 39 None, # stderr_path 40 None, # working directory 41 0, # launch flags 42 False, # Stop at entry 43 error) # error 44 45 self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) 46 47 event = lldb.SBEvent() 48 49 # Give the child enough time to reach the syscall, 50 # while clearing out all the pending events. 51 # The last WaitForEvent call will time out after 2 seconds. 52 while listener.WaitForEvent(2, event): 53 pass 54 55 # now the process should be running (blocked in the syscall) 56 self.assertEqual( 57 process.GetState(), 58 lldb.eStateRunning, 59 "Process is running") 60 61 # send the process a signal 62 process.SendAsyncInterrupt() 63 while listener.WaitForEvent(2, event): 64 pass 65 66 # as a result the process should stop 67 # in all likelihood we have stopped in the middle of the sleep() 68 # syscall 69 self.assertEqual( 70 process.GetState(), 71 lldb.eStateStopped, 72 PROCESS_STOPPED) 73 thread = process.GetSelectedThread() 74 75 # try evaluating a couple of expressions in this state 76 self.expect("expr release_flag = 1", substrs=[" = 1"]) 77 self.expect("print (int)getpid()", 78 substrs=[str(process.GetProcessID())]) 79 80 # and run the process to completion 81 process.Continue() 82 83 # process all events 84 while listener.WaitForEvent(10, event): 85 new_state = lldb.SBProcess.GetStateFromEvent(event) 86 if new_state == lldb.eStateExited: 87 break 88 89 self.assertEqual(process.GetState(), lldb.eStateExited) 90 self.assertEqual(process.GetExitStatus(), 0) 91