Pavel Labath | 2f47493 | 2015-06-17 23:28:55 +0000 | [diff] [blame] | 1 | """Test that we are able to evaluate expressions when the inferior is blocked in a syscall""" |
| 2 | |
Zachary Turner | 35d017f | 2015-10-23 17:04:29 +0000 | [diff] [blame] | 3 | from __future__ import print_function |
| 4 | |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 5 | import lldb_shared |
| 6 | |
Pavel Labath | 2f47493 | 2015-06-17 23:28:55 +0000 | [diff] [blame] | 7 | import os |
Pavel Labath | 2f47493 | 2015-06-17 23:28:55 +0000 | [diff] [blame] | 8 | import lldb |
| 9 | from lldbtest import * |
| 10 | import lldbutil |
| 11 | |
| 12 | |
| 13 | class ExprSyscallTestCase(TestBase): |
| 14 | |
| 15 | mydir = TestBase.compute_mydir(__file__) |
| 16 | |
Zachary Turner | 608cb82 | 2015-09-11 20:00:00 +0000 | [diff] [blame] | 17 | @expectedFailureWindows("llvm.org/pr21765") # Also getpid() is not a function on Windows anyway |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 18 | def test_setpgid(self): |
| 19 | self.build() |
Pavel Labath | 2f47493 | 2015-06-17 23:28:55 +0000 | [diff] [blame] | 20 | self.expr_syscall() |
| 21 | |
| 22 | def expr_syscall(self): |
| 23 | exe = os.path.join(os.getcwd(), 'a.out') |
| 24 | |
| 25 | # Create a target by the debugger. |
| 26 | target = self.dbg.CreateTarget(exe) |
| 27 | self.assertTrue(target, VALID_TARGET) |
| 28 | |
| 29 | listener = lldb.SBListener("my listener") |
| 30 | |
| 31 | # launch the inferior and don't wait for it to stop |
| 32 | self.dbg.SetAsync(True) |
| 33 | error = lldb.SBError() |
| 34 | process = target.Launch (listener, |
| 35 | None, # argv |
| 36 | None, # envp |
| 37 | None, # stdin_path |
| 38 | None, # stdout_path |
| 39 | None, # stderr_path |
| 40 | None, # working directory |
| 41 | 0, # launch flags |
| 42 | False, # Stop at entry |
| 43 | error) # error |
| 44 | |
| 45 | self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) |
| 46 | |
| 47 | event = lldb.SBEvent() |
| 48 | |
| 49 | # Give the child enough time to reach the syscall, |
| 50 | # while clearing out all the pending events. |
| 51 | # The last WaitForEvent call will time out after 2 seconds. |
| 52 | while listener.WaitForEvent(2, event): |
| 53 | pass |
| 54 | |
| 55 | # now the process should be running (blocked in the syscall) |
| 56 | self.assertEqual(process.GetState(), lldb.eStateRunning, "Process is running") |
| 57 | |
| 58 | # send the process a signal |
| 59 | process.SendAsyncInterrupt() |
Pavel Labath | b3b1f46 | 2015-08-21 10:52:02 +0000 | [diff] [blame] | 60 | while listener.WaitForEvent(2, event): |
Pavel Labath | 2f47493 | 2015-06-17 23:28:55 +0000 | [diff] [blame] | 61 | pass |
| 62 | |
| 63 | # as a result the process should stop |
| 64 | # in all likelihood we have stopped in the middle of the sleep() syscall |
| 65 | self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) |
| 66 | thread = process.GetSelectedThread() |
| 67 | |
| 68 | # try evaluating a couple of expressions in this state |
| 69 | self.expect("expr release_flag = 1", substrs = [" = 1"]) |
| 70 | self.expect("print (int)getpid()", substrs = [str(process.GetProcessID())]) |
| 71 | |
| 72 | # and run the process to completion |
| 73 | process.Continue() |
| 74 | |
| 75 | # process all events |
Tamas Berghammer | b8d2e9e | 2015-07-06 10:02:56 +0000 | [diff] [blame] | 76 | while listener.WaitForEvent(10, event): |
| 77 | new_state = lldb.SBProcess.GetStateFromEvent(event) |
| 78 | if new_state == lldb.eStateExited: |
| 79 | break |
Pavel Labath | 2f47493 | 2015-06-17 23:28:55 +0000 | [diff] [blame] | 80 | |
| 81 | self.assertEqual(process.GetState(), lldb.eStateExited) |
| 82 | self.assertEqual(process.GetExitStatus(), 0) |