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 def test_setpgid(self): 18 self.build() 19 self.expr_syscall() 20 21 def expr_syscall(self): 22 exe = self.getBuildArtifact("a.out") 23 24 # Create a target by the debugger. 25 target = self.dbg.CreateTarget(exe) 26 self.assertTrue(target, VALID_TARGET) 27 28 listener = lldb.SBListener("my listener") 29 30 # launch the inferior and don't wait for it to stop 31 self.dbg.SetAsync(True) 32 error = lldb.SBError() 33 process = target.Launch(listener, 34 None, # argv 35 None, # envp 36 None, # stdin_path 37 None, # stdout_path 38 None, # stderr_path 39 None, # working directory 40 0, # launch flags 41 False, # Stop at entry 42 error) # error 43 44 self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) 45 46 event = lldb.SBEvent() 47 48 # Give the child enough time to reach the syscall, 49 # while clearing out all the pending events. 50 # The last WaitForEvent call will time out after 2 seconds. 51 while listener.WaitForEvent(2, event): 52 pass 53 54 # now the process should be running (blocked in the syscall) 55 self.assertEqual( 56 process.GetState(), 57 lldb.eStateRunning, 58 "Process is running") 59 60 # send the process a signal 61 process.SendAsyncInterrupt() 62 while listener.WaitForEvent(2, event): 63 pass 64 65 # as a result the process should stop 66 # in all likelihood we have stopped in the middle of the sleep() 67 # syscall 68 self.assertEqual( 69 process.GetState(), 70 lldb.eStateStopped, 71 PROCESS_STOPPED) 72 thread = process.GetSelectedThread() 73 74 # try evaluating a couple of expressions in this state 75 self.expect("expr release_flag = 1", substrs=[" = 1"]) 76 self.expect("print (int)getpid()", 77 substrs=[str(process.GetProcessID())]) 78 79 # and run the process to completion 80 process.Continue() 81 82 # process all events 83 while listener.WaitForEvent(10, event): 84 new_state = lldb.SBProcess.GetStateFromEvent(event) 85 if new_state == lldb.eStateExited: 86 break 87 88 self.assertEqual(process.GetState(), lldb.eStateExited) 89 self.assertEqual(process.GetExitStatus(), 0) 90