[LoopInterchange] Hoist isComputableLoopNest() in the control flow (#124247)
[llvm-project.git] / lldb / test / API / commands / expression / expr-in-syscall / TestExpressionInSyscall.py
blob9f9848912a11569bf248903ce616d17bb398b2dd
1 """Test that we are able to evaluate expressions when the inferior is blocked in a syscall"""
3 import lldb
4 from lldbsuite.test.decorators import *
5 from lldbsuite.test.lldbtest import *
6 from lldbsuite.test import lldbutil
9 class ExprSyscallTestCase(TestBase):
10 @expectedFailureAll(
11 oslist=["windows"],
12 bugnumber="llvm.org/pr21765, getpid() does not exist on Windows",
14 @expectedFailureNetBSD
15 def test_setpgid(self):
16 self.build()
17 self.expr_syscall()
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(
30 listener,
31 None, # argv
32 None, # envp
33 None, # stdin_path
34 None, # stdout_path
35 None, # stderr_path
36 None, # working directory
37 flags, # launch flags
38 False, # Stop at entry
39 error,
40 ) # error
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):
50 pass
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):
58 pass
60 # as a result the process should stop
61 # in all likelihood we have stopped in the middle of the sleep()
62 # syscall
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
71 process.Continue()
73 # process all events
74 while listener.WaitForEvent(10, event):
75 new_state = lldb.SBProcess.GetStateFromEvent(event)
76 if new_state == lldb.eStateExited:
77 break
79 self.assertState(process.GetState(), lldb.eStateExited)
80 self.assertEqual(process.GetExitStatus(), 0)