1"""
2Test that step-inst over a crash behaves correctly.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class CrashDuringStepTestCase(TestBase):
14
15    def setUp(self):
16        TestBase.setUp(self)
17        self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
18
19    # IO error due to breakpoint at invalid address
20    @expectedFailureAll(triple=re.compile('^mips'))
21    @skipIf(oslist=['windows'], archs=['aarch64'])
22    def test_step_inst_with(self):
23        """Test thread creation during step-inst handling."""
24        self.build()
25        exe = self.getBuildArtifact("a.out")
26
27        target = self.dbg.CreateTarget(exe)
28        self.assertTrue(target and target.IsValid(), "Target is valid")
29
30        self.bp_num = lldbutil.run_break_set_by_file_and_line(
31            self, "main.cpp", self.breakpoint, num_expected_locations=1)
32
33        # Run the program.
34        process = target.LaunchSimple(
35            None, None, self.get_process_working_directory())
36        self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
37
38        # The stop reason should be breakpoint.
39        self.assertEqual(
40            process.GetState(),
41            lldb.eStateStopped,
42            PROCESS_STOPPED)
43        thread = lldbutil.get_stopped_thread(
44            process, lldb.eStopReasonBreakpoint)
45        self.assertTrue(thread.IsValid(), STOPPED_DUE_TO_BREAKPOINT)
46
47        # Keep stepping until the inferior crashes
48        while process.GetState() == lldb.eStateStopped and not lldbutil.is_thread_crashed(self, thread):
49            thread.StepInstruction(False)
50
51        self.assertEqual(
52            process.GetState(),
53            lldb.eStateStopped,
54            PROCESS_STOPPED)
55        self.assertTrue(
56            lldbutil.is_thread_crashed(
57                self,
58                thread),
59            "Thread has crashed")
60        process.Kill()
61