1"""
2This tests that we do not lose control of the inferior, while doing an instruction-level step
3over a thread creation instruction.
4"""
5
6
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class CreateDuringInstructionStepTestCase(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17    NO_DEBUG_INFO_TESTCASE = True
18
19    @skipUnlessPlatform(['linux'])
20    @expectedFailureAndroid('llvm.org/pr24737', archs=['arm'])
21    @skipIf(oslist=["linux"], archs=["arm"], bugnumber="llvm.org/pr24737")
22    def test_step_inst(self):
23        self.build(dictionary=self.getBuildFlags())
24        exe = self.getBuildArtifact("a.out")
25        target = self.dbg.CreateTarget(exe)
26        self.assertTrue(target and target.IsValid(), "Target is valid")
27
28        # This should create a breakpoint in the stepping thread.
29        breakpoint = target.BreakpointCreateByName("main")
30        self.assertTrue(
31            breakpoint and breakpoint.IsValid(),
32            "Breakpoint is valid")
33
34        # Run the program.
35        process = target.LaunchSimple(
36            None, None, self.get_process_working_directory())
37        self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
38
39        # The stop reason of the thread should be breakpoint.
40        self.assertEqual(
41            process.GetState(),
42            lldb.eStateStopped,
43            PROCESS_STOPPED)
44
45        threads = lldbutil.get_threads_stopped_at_breakpoint(
46            process, breakpoint)
47        self.assertEqual(len(threads), 1, STOPPED_DUE_TO_BREAKPOINT)
48
49        thread = threads[0]
50        self.assertTrue(thread and thread.IsValid(), "Thread is valid")
51
52        # Make sure we see only one threads
53        self.assertEqual(
54            process.GetNumThreads(),
55            1,
56            'Number of expected threads and actual threads do not match.')
57
58        # Keep stepping until we see the thread creation
59        while process.GetNumThreads() < 2:
60            thread.StepInstruction(False)
61            self.assertEqual(
62                process.GetState(),
63                lldb.eStateStopped,
64                PROCESS_STOPPED)
65            self.assertEqual(
66                thread.GetStopReason(),
67                lldb.eStopReasonPlanComplete,
68                "Step operation succeeded")
69            if self.TraceOn():
70                self.runCmd("disassemble --pc")
71
72        if self.TraceOn():
73            self.runCmd("thread list")
74
75        # We have successfully caught thread creation. Now just run to
76        # completion
77        process.Continue()
78
79        # At this point, the inferior process should have exited.
80        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
81