• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test thread stepping features in combination with frame select.
3"""
4
5import os, time
6import re
7import unittest2
8import lldb, lldbutil
9from lldbtest import *
10import lldbutil
11
12class ThreadSteppingTestCase(TestBase):
13
14    mydir = os.path.join("lang", "c", "stepping")
15
16    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17    @dsym_test
18    def test_step_out_with_dsym_and_run_command(self):
19        """Exercise thread step-out and frame select followed by thread step-out."""
20        self.buildDwarf()
21        self.thread_step_out()
22
23    @dwarf_test
24    def test_step_out_with_dwarf_and_run_command(self):
25        """Exercise thread step-out and frame select followed by thread step-out."""
26        self.buildDwarf()
27        self.thread_step_out()
28
29    def setUp(self):
30        # Call super's setUp().
31        TestBase.setUp(self)
32        # Find the line number to of function 'c'.
33        self.line1 = line_number('main.c', '// Find the line number of function "c" here.')
34        self.line2 = line_number('main.c', '// frame select 2, thread step-out while stopped at "c(1)"')
35        self.line3 = line_number('main.c', '// thread step-out while stopped at "c(2)"')
36        self.line4 = line_number('main.c', '// frame select 1, thread step-out while stopped at "c(3)"')
37
38    def thread_step_out(self):
39        """Exercise thread step-out and frame select followed by thread step-out."""
40        exe = os.path.join(os.getcwd(), "a.out")
41        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
42
43        # Create a breakpoint inside function 'c'.
44        lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line1, num_expected_locations=1, loc_exact=True)
45
46        # Now run the program.
47        self.runCmd("run", RUN_SUCCEEDED)
48
49        # The process should be stopped at this point.
50        self.expect("process status", PROCESS_STOPPED,
51            patterns = ['Process .* stopped'])
52
53        # The frame #0 should correspond to main.c:32, the executable statement
54        # in function name 'c'.  And frame #3 should point to main.c:37.
55        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
56            substrs = ["stop reason = breakpoint"],
57            patterns = ["frame #0.*main.c:%d" % self.line1,
58                        "frame #3.*main.c:%d" % self.line2])
59
60        # We want to move the pc to frame #3.  This can be accomplished by
61        # 'frame select 2', followed by 'thread step-out'.
62        self.runCmd("frame select 2")
63        self.runCmd("thread step-out")
64        self.expect("thread backtrace", STEP_OUT_SUCCEEDED,
65            substrs = ["stop reason = step out"],
66            patterns = ["frame #0.*main.c:%d" % self.line2])
67
68        # Let's move on to a single step-out case.
69        self.runCmd("process continue")
70
71        # The process should be stopped at this point.
72        self.expect("process status", PROCESS_STOPPED,
73            patterns = ['Process .* stopped'])
74        self.runCmd("thread step-out")
75        self.expect("thread backtrace", STEP_OUT_SUCCEEDED,
76            substrs = ["stop reason = step out"],
77            patterns = ["frame #0.*main.c:%d" % self.line3])
78
79        # Do another frame selct, followed by thread step-out.
80        self.runCmd("process continue")
81
82        # The process should be stopped at this point.
83        self.expect("process status", PROCESS_STOPPED,
84            patterns = ['Process .* stopped'])
85        self.runCmd("frame select 1")
86        self.runCmd("thread step-out")
87        self.expect("thread backtrace", STEP_OUT_SUCCEEDED,
88            substrs = ["stop reason = step out"],
89            patterns = ["frame #0.*main.c:%d" % self.line4])
90
91
92if __name__ == '__main__':
93    import atexit
94    lldb.SBDebugger.Initialize()
95    atexit.register(lambda: lldb.SBDebugger.Terminate())
96    unittest2.main()
97