1 """Test that we are able to evaluate expressions when the inferior is blocked in a syscall"""
3 from __future__ import print_function
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class ExprSyscallTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
19 bugnumber="llvm.org/pr21765, getpid() does not exist on Windows")
20 def test_setpgid(self):
24 def expr_syscall(self):
25 exe = self.getBuildArtifact("a.out")
27 # Create a target by the debugger.
28 target = self.dbg.CreateTarget(exe)
29 self.assertTrue(target, VALID_TARGET)
31 listener = lldb.SBListener("my listener")
33 # launch the inferior and don't wait for it to stop
34 self.dbg.SetAsync(True)
35 error = lldb.SBError()
36 process = target.Launch(listener,
42 None, # working directory
44 False, # Stop at entry
47 self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
49 event = lldb.SBEvent()
51 # Give the child enough time to reach the syscall,
52 # while clearing out all the pending events.
53 # The last WaitForEvent call will time out after 2 seconds.
54 while listener.WaitForEvent(2, event):
57 # now the process should be running (blocked in the syscall)
63 # send the process a signal
64 process.SendAsyncInterrupt()
65 while listener.WaitForEvent(2, event):
68 # as a result the process should stop
69 # in all likelihood we have stopped in the middle of the sleep()
75 thread = process.GetSelectedThread()
77 # try evaluating a couple of expressions in this state
78 self.expect("expr release_flag = 1", substrs=[" = 1"])
79 self.expect("print (int)getpid()",
80 substrs=[str(process.GetProcessID())])
82 # and run the process to completion
86 while listener.WaitForEvent(10, event):
87 new_state = lldb.SBProcess.GetStateFromEvent(event)
88 if new_state == lldb.eStateExited:
91 self.assertEqual(process.GetState(), lldb.eStateExited)
92 self.assertEqual(process.GetExitStatus(), 0)