blob: 83c98affdd02d23026d4a1e743c176f567296d74 [file] [log] [blame]
Pavel Labath2f474932015-06-17 23:28:55 +00001"""Test that we are able to evaluate expressions when the inferior is blocked in a syscall"""
2
Zachary Turner35d017f2015-10-23 17:04:29 +00003from __future__ import print_function
4
Zachary Turner77db4a82015-10-22 20:06:20 +00005import lldb_shared
6
Pavel Labath2f474932015-06-17 23:28:55 +00007import os
Pavel Labath2f474932015-06-17 23:28:55 +00008import lldb
9from lldbtest import *
10import lldbutil
11
12
13class ExprSyscallTestCase(TestBase):
14
15 mydir = TestBase.compute_mydir(__file__)
16
Zachary Turner608cb822015-09-11 20:00:00 +000017 @expectedFailureWindows("llvm.org/pr21765") # Also getpid() is not a function on Windows anyway
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000018 def test_setpgid(self):
19 self.build()
Pavel Labath2f474932015-06-17 23:28:55 +000020 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 Labathb3b1f462015-08-21 10:52:02 +000060 while listener.WaitForEvent(2, event):
Pavel Labath2f474932015-06-17 23:28:55 +000061 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 Berghammerb8d2e9e2015-07-06 10:02:56 +000076 while listener.WaitForEvent(10, event):
77 new_state = lldb.SBProcess.GetStateFromEvent(event)
78 if new_state == lldb.eStateExited:
79 break
Pavel Labath2f474932015-06-17 23:28:55 +000080
81 self.assertEqual(process.GetState(), lldb.eStateExited)
82 self.assertEqual(process.GetExitStatus(), 0)