]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/expression_command/expr-in-syscall/TestExpressionInSyscall.py
Vendor import of lldb trunk r338150:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / expression_command / expr-in-syscall / TestExpressionInSyscall.py
1 """Test that we are able to evaluate expressions when the inferior is blocked in a syscall"""
2
3 from __future__ import print_function
4
5
6 import os
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class ExprSyscallTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     @expectedFailureAll(
18         oslist=["windows"],
19         bugnumber="llvm.org/pr21765, getpid() does not exist on Windows")
20     def test_setpgid(self):
21         self.build()
22         self.expr_syscall()
23
24     def expr_syscall(self):
25         exe = self.getBuildArtifact("a.out")
26
27         # Create a target by the debugger.
28         target = self.dbg.CreateTarget(exe)
29         self.assertTrue(target, VALID_TARGET)
30
31         listener = lldb.SBListener("my listener")
32
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,
37                                 None,      # argv
38                                 None,      # envp
39                                 None,      # stdin_path
40                                 None,      # stdout_path
41                                 None,      # stderr_path
42                                 None,      # working directory
43                                 0,         # launch flags
44                                 False,     # Stop at entry
45                                 error)     # error
46
47         self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
48
49         event = lldb.SBEvent()
50
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):
55             pass
56
57         # now the process should be running (blocked in the syscall)
58         self.assertEqual(
59             process.GetState(),
60             lldb.eStateRunning,
61             "Process is running")
62
63         # send the process a signal
64         process.SendAsyncInterrupt()
65         while listener.WaitForEvent(2, event):
66             pass
67
68         # as a result the process should stop
69         # in all likelihood we have stopped in the middle of the sleep()
70         # syscall
71         self.assertEqual(
72             process.GetState(),
73             lldb.eStateStopped,
74             PROCESS_STOPPED)
75         thread = process.GetSelectedThread()
76
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())])
81
82         # and run the process to completion
83         process.Continue()
84
85         # process all events
86         while listener.WaitForEvent(10, event):
87             new_state = lldb.SBProcess.GetStateFromEvent(event)
88             if new_state == lldb.eStateExited:
89                 break
90
91         self.assertEqual(process.GetState(), lldb.eStateExited)
92         self.assertEqual(process.GetExitStatus(), 0)