2 Test some lldb command abbreviations.
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
import lldbutil
11 class ExecTestCase(TestBase
):
12 NO_DEBUG_INFO_TESTCASE
= True
15 archs
=["i386"], oslist
=no_match(["freebsd"]), bugnumber
="rdar://28656532"
18 oslist
=["ios", "tvos", "watchos", "bridgeos"],
19 bugnumber
="rdar://problem/34559552",
20 ) # this exec test has problems on ios systems
21 @expectedFailureNetBSD
22 @skipIfAsan # rdar://problem/43756823
24 def test_hitting_exec(self
):
28 archs
=["i386"], oslist
=no_match(["freebsd"]), bugnumber
="rdar://28656532"
31 oslist
=["ios", "tvos", "watchos", "bridgeos"],
32 bugnumber
="rdar://problem/34559552",
33 ) # this exec test has problems on ios systems
34 @expectedFailureNetBSD
35 @skipIfAsan # rdar://problem/43756823
37 def test_skipping_exec(self
):
40 def do_test(self
, skip_exec
):
42 exe
= self
.getBuildArtifact("a.out")
43 secondprog
= self
.getBuildArtifact("secondprog")
46 target
= self
.dbg
.CreateTarget(exe
)
48 lldbutil
.install_to_target(self
, secondprog
)
50 # Create any breakpoints we need
51 breakpoint1
= target
.BreakpointCreateBySourceRegex(
52 "Set breakpoint 1 here", lldb
.SBFileSpec("main.c", False)
54 self
.assertTrue(breakpoint1
, VALID_BREAKPOINT
)
55 breakpoint2
= target
.BreakpointCreateBySourceRegex(
56 "Set breakpoint 2 here", lldb
.SBFileSpec("secondprog.cpp", False)
58 self
.assertTrue(breakpoint2
, VALID_BREAKPOINT
)
61 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
62 self
.assertTrue(process
, PROCESS_IS_VALID
)
65 self
.runCmd("settings show target.process.stop-on-exec", check
=False)
67 self
.dbg
.HandleCommand("settings set target.process.stop-on-exec false")
71 "settings set target.process.stop-on-exec false", check
=False
74 # Execute the cleanup function during test case tear down.
75 self
.addTearDownHook(cleanup
)
77 # The stop reason of the thread should be breakpoint.
79 process
.GetState(), lldb
.eStateStopped
, STOPPED_DUE_TO_BREAKPOINT
82 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, breakpoint1
)
83 self
.assertEqual(len(threads
), 1)
85 # We had a deadlock tearing down the TypeSystemMap on exec, but only if some
86 # expression had been evaluated. So make sure we do that here so the teardown
90 value
= thread
.frames
[0].EvaluateExpression("1 + 2")
91 self
.assertTrue(value
.IsValid(), "Expression evaluated successfully")
92 int_value
= value
.GetValueAsSigned()
93 self
.assertEqual(int_value
, 3, "Expression got the right result.")
95 # Run and we should stop due to exec
100 process
.GetState(), lldb
.eStateExited
, "Process should not have exited!"
105 "Process should be stopped at __dyld_start",
108 threads
= lldbutil
.get_stopped_threads(process
, lldb
.eStopReasonExec
)
109 self
.assertEqual(len(threads
), 1, "We got a thread stopped for exec.")
111 # Run and we should stop at breakpoint in main after exec
114 self
.assertState(process
.GetState(), lldb
.eStateStopped
)
115 for t
in process
.threads
:
116 if t
.stop_reason
!= lldb
.eStopReasonNone
:
117 self
.assertStopReason(
118 t
.stop_reason
, lldb
.eStopReasonBreakpoint
, "Unexpected stop reason"
122 if t
.stop_reason
!= lldb
.eStopReasonBreakpoint
:
125 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, breakpoint2
)
126 self
.assertEqual(len(threads
), 1, "Stopped at breakpoint in exec'ed process.")
129 archs
=["i386"], oslist
=no_match(["freebsd"]), bugnumber
="rdar://28656532"
132 oslist
=["ios", "tvos", "watchos", "bridgeos"],
133 bugnumber
="rdar://problem/34559552",
134 ) # this exec test has problems on ios systems
135 @expectedFailureNetBSD
136 @skipIfAsan # rdar://problem/43756823
138 def test_correct_thread_plan_state_before_exec(self
):
140 In this test we make sure that the Thread* cache in the ThreadPlans
141 is cleared correctly when performing exec
145 exe
= self
.getBuildArtifact("a.out")
146 target
= self
.dbg
.CreateTarget(exe
)
148 lldbutil
.install_to_target(self
, self
.getBuildArtifact("secondprog"))
150 (target
, process
, thread
, breakpoint1
) = lldbutil
.run_to_source_breakpoint(
151 self
, "Set breakpoint 1 here", lldb
.SBFileSpec("main.c", False)
154 # The stop reason of the thread should be breakpoint.
156 process
.GetState(), lldb
.eStateStopped
, STOPPED_DUE_TO_BREAKPOINT
159 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, breakpoint1
)
160 self
.assertEqual(len(threads
), 1)
162 # We perform an instruction step, which effectively sets the cache of the base
163 # thread plan, which should be cleared when a new thread list appears.
165 # Continuing after this instruction step will trigger a call to
166 # ThreadPlan::ShouldReportRun, which sets the ThreadPlan's Thread cache to
167 # the old Thread* value. In Process::UpdateThreadList we are clearing this
168 # cache in preparation for the new ThreadList.
170 # Not doing this stepping will cause LLDB to first execute a private single step
171 # past the current breakpoint, which eventually avoids the call to ShouldReportRun,
172 # thus not setting the cache to its invalid value.
173 thread
.StepInstruction(False)
175 # Run and we should stop due to exec
176 breakpoint2
= target
.BreakpointCreateBySourceRegex(
177 "Set breakpoint 2 here", lldb
.SBFileSpec("secondprog.cpp", False)
183 process
.GetState(), lldb
.eStateExited
, "Process should not have exited!"
188 "Process should be stopped at __dyld_start",
191 threads
= lldbutil
.get_stopped_threads(process
, lldb
.eStopReasonExec
)
192 self
.assertEqual(len(threads
), 1, "We got a thread stopped for exec.")
194 # Run and we should stop at breakpoint in main after exec
197 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, breakpoint2
)
198 self
.assertEqual(len(threads
), 1, "Stopped at breakpoint in exec'ed process.")