• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class StepUntilTestCase(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18        # Find the line numbers that we will step to in main:
19        self.main_source = "main.c"
20        self.less_than_two = line_number('main.c', 'Less than 2')
21        self.greater_than_two = line_number('main.c', 'Greater than or equal to 2.')
22        self.back_out_in_main = line_number('main.c', 'Back out in main')
23
24    def do_until (self, args, until_lines, expected_linenum):
25        self.build()
26        exe = self.getBuildArtifact("a.out")
27
28        target = self.dbg.CreateTarget(exe)
29        self.assertTrue(target, VALID_TARGET)
30
31        main_source_spec = lldb.SBFileSpec(self.main_source)
32        break_before = target.BreakpointCreateBySourceRegex(
33            'At the start',
34            main_source_spec)
35        self.assertTrue(break_before, VALID_BREAKPOINT)
36
37        # Now launch the process, and do not stop at entry point.
38        process = target.LaunchSimple(
39            args, None, self.get_process_working_directory())
40
41        self.assertTrue(process, PROCESS_IS_VALID)
42
43        # The stop reason of the thread should be breakpoint.
44        threads = lldbutil.get_threads_stopped_at_breakpoint(
45            process, break_before)
46
47        if len(threads) != 1:
48            self.fail("Failed to stop at first breakpoint in main.")
49
50        thread = threads[0]
51        return thread
52
53        thread = self.common_setup(None)
54
55        cmd_interp = self.dbg.GetCommandInterpreter()
56        ret_obj = lldb.SBCommandReturnObject()
57
58        cmd_line = "thread until"
59        for line_num in until_lines:
60            cmd_line += " %d"%(line_num)
61
62        cmd_interp.HandleCommand(cmd_line, ret_obj)
63        self.assertTrue(ret_obj.Succeeded(), "'%s' failed: %s."%(cmd_line, ret_obj.GetError()))
64
65        frame = thread.frames[0]
66        line = frame.GetLineEntry().GetLine()
67        self.assertEqual(line, expected_linenum, 'Did not get the expected stop line number')
68
69    def test_hitting_one (self):
70        """Test thread step until - targeting one line and hitting it."""
71        self.do_until(None, [self.less_than_two], self.less_than_two)
72
73    def test_targetting_two_hitting_first (self):
74        """Test thread step until - targeting two lines and hitting one."""
75        self.do_until(["foo", "bar", "baz"], [self.less_than_two, self.greater_than_two], self.greater_than_two)
76
77    def test_targetting_two_hitting_second (self):
78        """Test thread step until - targeting two lines and hitting the other one."""
79        self.do_until(None, [self.less_than_two, self.greater_than_two], self.less_than_two)
80
81    def test_missing_one (self):
82        """Test thread step until - targeting one line and missing it."""
83        self.do_until(["foo", "bar", "baz"], [self.less_than_two], self.back_out_in_main)
84
85
86
87