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
):
12 bugnumber
="llvm.org/pr21765, getpid() does not exist on Windows",
14 @expectedFailureNetBSD
15 def test_setpgid(self
):
19 def expr_syscall(self
):
20 # Create a target by the debugger.
21 target
= self
.createTestTarget()
23 listener
= lldb
.SBListener("my listener")
25 # launch the inferior and don't wait for it to stop
26 self
.dbg
.SetAsync(True)
27 error
= lldb
.SBError()
28 flags
= target
.GetLaunchInfo().GetLaunchFlags()
29 process
= target
.Launch(
36 None, # working directory
38 False, # Stop at entry
42 self
.assertTrue(process
and process
.IsValid(), PROCESS_IS_VALID
)
44 event
= lldb
.SBEvent()
46 # Give the child enough time to reach the syscall,
47 # while clearing out all the pending events.
48 # The last WaitForEvent call will time out after 2 seconds.
49 while listener
.WaitForEvent(2, event
):
52 # now the process should be running (blocked in the syscall)
53 self
.assertEqual(process
.GetState(), lldb
.eStateRunning
, "Process is running")
55 # send the process a signal
56 process
.SendAsyncInterrupt()
57 while listener
.WaitForEvent(2, event
):
60 # as a result the process should stop
61 # in all likelihood we have stopped in the middle of the sleep()
63 self
.assertEqual(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
64 thread
= process
.GetSelectedThread()
66 # try evaluating a couple of expressions in this state
67 self
.expect_expr("release_flag = 1", result_value
="1")
68 self
.expect_expr("(int)getpid()", result_value
=str(process
.GetProcessID()))
70 # and run the process to completion
74 while listener
.WaitForEvent(10, event
):
75 new_state
= lldb
.SBProcess
.GetStateFromEvent(event
)
76 if new_state
== lldb
.eStateExited
:
79 self
.assertState(process
.GetState(), lldb
.eStateExited
)
80 self
.assertEqual(process
.GetExitStatus(), 0)