2 Test that the run locker really does work to keep
3 us from running SB API that should only be run
4 while stopped. This test is mostly concerned with
5 what happens between launch and first stop.
9 import lldbsuite
.test
.lldbutil
as lldbutil
10 from lldbsuite
.test
.decorators
import *
11 from lldbsuite
.test
.lldbtest
import *
14 class TestRunLocker(TestBase
):
15 NO_DEBUG_INFO_TESTCASE
= True
17 @expectedFailureAll(oslist
=["windows"])
18 def test_run_locker(self
):
19 """Test that the run locker is set correctly when we launch"""
21 self
.runlocker_test(False)
23 @expectedFailureAll(oslist
=["windows"])
24 def test_run_locker_stop_at_entry(self
):
25 """Test that the run locker is set correctly when we launch"""
27 self
.runlocker_test(False)
30 # Call super's setUp().
32 self
.main_source_file
= lldb
.SBFileSpec("main.c")
34 def runlocker_test(self
, stop_at_entry
):
35 """The code to stop at entry handles events slightly differently, so
36 we test both versions of process launch."""
38 target
= lldbutil
.run_to_breakpoint_make_target(self
)
40 launch_info
= target
.GetLaunchInfo()
42 flags
= launch_info
.GetFlags()
43 launch_info
.SetFlags(flags | lldb
.eLaunchFlagStopAtEntry
)
45 error
= lldb
.SBError()
46 # We are trying to do things when the process is running, so
47 # we have to run the debugger asynchronously.
48 self
.dbg
.SetAsync(True)
50 listener
= lldb
.SBListener("test-run-lock-listener")
51 launch_info
.SetListener(listener
)
52 process
= target
.Launch(launch_info
, error
)
53 self
.assertSuccess(error
, "Launched the process")
55 event
= lldb
.SBEvent()
57 event_result
= listener
.WaitForEvent(10, event
)
58 self
.assertTrue(event_result
, "timed out waiting for launch")
59 state_type
= lldb
.SBProcess
.GetStateFromEvent(event
)
60 # We don't always see a launching...
61 if state_type
== lldb
.eStateLaunching
:
62 event_result
= listener
.WaitForEvent(10, event
)
64 event_result
, "Timed out waiting for running after launching"
66 state_type
= lldb
.SBProcess
.GetStateFromEvent(event
)
68 self
.assertState(state_type
, lldb
.eStateRunning
, "Didn't get a running event")
70 # We aren't checking the entry state, but just making sure
71 # the running state is set properly if we continue in this state.
74 event_result
= listener
.WaitForEvent(10, event
)
75 self
.assertTrue(event_result
, "Timed out waiting for stop at entry stop")
76 state_type
= lldb
.SBProcess
.GetStateFromEvent(event
)
77 self
.assertState(state_type
, eStateStopped
, "Stop at entry stopped")
80 # Okay, now the process is running, make sure we can't do things
81 # you aren't supposed to do while running, and that we get some
83 val
= target
.EvaluateExpression("SomethingToCall()")
84 error
= val
.GetError()
85 self
.assertTrue(error
.Fail(), "Failed to run expression")
87 "can't evaluate expressions when the process is running",
89 "Stopped by stop locker",
92 # This should also fail if we try to use the script interpreter directly:
93 interp
= self
.dbg
.GetCommandInterpreter()
94 result
= lldb
.SBCommandReturnObject()
95 ret
= interp
.HandleCommand(
96 "script var = lldb.frame.EvaluateExpression('SomethingToCall()'); var.GetError().GetCString()",
100 "can't evaluate expressions when the process is running", result
.GetOutput()