1 """Test that we are able to evaluate expressions when the inferior is blocked in a syscall"""
4 from lldbsuite.test.decorators import *
5 from lldbsuite.test.lldbtest import *
6 from lldbsuite.test import lldbutil
9 class ExprSyscallTestCase(TestBase):
11 mydir = TestBase.compute_mydir(__file__)
15 bugnumber="llvm.org/pr21765, getpid() does not exist on Windows")
16 @expectedFailureNetBSD
17 def test_setpgid(self):
21 def expr_syscall(self):
22 exe = self.getBuildArtifact("a.out")
24 # Create a target by the debugger.
25 target = self.dbg.CreateTarget(exe)
26 self.assertTrue(target, VALID_TARGET)
28 listener = lldb.SBListener("my listener")
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,
39 None, # working directory
41 False, # Stop at entry
44 self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
46 event = lldb.SBEvent()
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):
54 # now the process should be running (blocked in the syscall)
60 # send the process a signal
61 process.SendAsyncInterrupt()
62 while listener.WaitForEvent(2, event):
65 # as a result the process should stop
66 # in all likelihood we have stopped in the middle of the sleep()
72 thread = process.GetSelectedThread()
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())])
79 # and run the process to completion
83 while listener.WaitForEvent(10, event):
84 new_state = lldb.SBProcess.GetStateFromEvent(event)
85 if new_state == lldb.eStateExited:
88 self.assertEqual(process.GetState(), lldb.eStateExited)
89 self.assertEqual(process.GetExitStatus(), 0)