1"""
2Test thread stepping features in combination with frame select.
3"""
4
5
6
7import lldb
8from lldbsuite.test.lldbtest import *
9import lldbsuite.test.lldbutil as lldbutil
10
11
12class ThreadSteppingTestCase(TestBase):
13
14    def setUp(self):
15        # Call super's setUp().
16        TestBase.setUp(self)
17        # Find the line number to of function 'c'.
18        self.line1 = line_number(
19            'main.c', '// Find the line number of function "c" here.')
20        self.line2 = line_number(
21            'main.c', '// frame select 2, thread step-out while stopped at "c(1)"')
22        self.line3 = line_number(
23            'main.c', '// thread step-out while stopped at "c(2)"')
24        self.line4 = line_number(
25            'main.c', '// frame select 1, thread step-out while stopped at "c(3)"')
26
27    def test_step_out_with_run_command(self):
28        """Exercise thread step-out and frame select followed by thread step-out."""
29        self.build()
30        exe = self.getBuildArtifact("a.out")
31        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
32
33        # Create a breakpoint inside function 'c'.
34        lldbutil.run_break_set_by_file_and_line(
35            self, "main.c", self.line1, num_expected_locations=1, loc_exact=True)
36
37        # Now run the program.
38        self.runCmd("run", RUN_SUCCEEDED)
39
40        # The process should be stopped at this point.
41        self.expect("process status", PROCESS_STOPPED,
42                    patterns=['Process .* stopped'])
43
44        # The frame #0 should correspond to main.c:32, the executable statement
45        # in function name 'c'.  And frame #3 should point to main.c:37.
46        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
47                    substrs=["stop reason = breakpoint"],
48                    patterns=["frame #0.*main.c:%d" % self.line1,
49                              "frame #3.*main.c:%d" % self.line2])
50
51        # We want to move the pc to frame #3.  This can be accomplished by
52        # 'frame select 2', followed by 'thread step-out'.
53        self.runCmd("frame select 2")
54        self.runCmd("thread step-out")
55        self.expect("thread backtrace", STEP_OUT_SUCCEEDED,
56                    substrs=["stop reason = step out"],
57                    patterns=["frame #0.*main.c:%d" % self.line2])
58
59        # Let's move on to a single step-out case.
60        self.runCmd("process continue")
61
62        # The process should be stopped at this point.
63        self.expect("process status", PROCESS_STOPPED,
64                    patterns=['Process .* stopped'])
65        self.runCmd("thread step-out")
66        self.expect("thread backtrace", STEP_OUT_SUCCEEDED,
67                    substrs=["stop reason = step out"],
68                    patterns=["frame #0.*main.c:%d" % self.line3])
69
70        # Do another frame selct, followed by thread step-out.
71        self.runCmd("process continue")
72
73        # The process should be stopped at this point.
74        self.expect("process status", PROCESS_STOPPED,
75                    patterns=['Process .* stopped'])
76        self.runCmd("frame select 1")
77        self.runCmd("thread step-out")
78        self.expect("thread backtrace", STEP_OUT_SUCCEEDED,
79                    substrs=["stop reason = step out"],
80                    patterns=["frame #0.*main.c:%d" % self.line4])
81