1 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
3 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class StepUntilTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
21 # Find the line numbers that we will step to in main:
22 self.main_source = "main.c"
23 self.less_than_two = line_number('main.c', 'Less than 2')
24 self.greater_than_two = line_number('main.c', 'Greater than or equal to 2.')
25 self.back_out_in_main = line_number('main.c', 'Back out in main')
27 def do_until (self, args, until_lines, expected_linenum):
29 exe = self.getBuildArtifact("a.out")
31 target = self.dbg.CreateTarget(exe)
32 self.assertTrue(target, VALID_TARGET)
34 main_source_spec = lldb.SBFileSpec(self.main_source)
35 break_before = target.BreakpointCreateBySourceRegex(
38 self.assertTrue(break_before, VALID_BREAKPOINT)
40 # Now launch the process, and do not stop at entry point.
41 process = target.LaunchSimple(
42 args, None, self.get_process_working_directory())
44 self.assertTrue(process, PROCESS_IS_VALID)
46 # The stop reason of the thread should be breakpoint.
47 threads = lldbutil.get_threads_stopped_at_breakpoint(
48 process, break_before)
51 self.fail("Failed to stop at first breakpoint in main.")
56 thread = self.common_setup(None)
58 cmd_interp = self.dbg.GetCommandInterpreter()
59 ret_obj = lldb.SBCommandReturnObject()
61 cmd_line = "thread until"
62 for line_num in until_lines:
63 cmd_line += " %d"%(line_num)
65 cmd_interp.HandleCommand(cmd_line, ret_obj)
66 self.assertTrue(ret_obj.Succeeded(), "'%s' failed: %s."%(cmd_line, ret_obj.GetError()))
68 frame = thread.frames[0]
69 line = frame.GetLineEntry().GetLine()
70 self.assertEqual(line, expected_linenum, 'Did not get the expected stop line number')
72 def test_hitting_one (self):
73 """Test thread step until - targeting one line and hitting it."""
74 self.do_until(None, [self.less_than_two], self.less_than_two)
76 def test_targetting_two_hitting_first (self):
77 """Test thread step until - targeting two lines and hitting one."""
78 self.do_until(["foo", "bar", "baz"], [self.less_than_two, self.greater_than_two], self.greater_than_two)
80 def test_targetting_two_hitting_second (self):
81 """Test thread step until - targeting two lines and hitting the other one."""
82 self.do_until(None, [self.less_than_two, self.greater_than_two], self.less_than_two)
84 def test_missing_one (self):
85 """Test thread step until - targeting one line and missing it."""
86 self.do_until(["foo", "bar", "baz"], [self.less_than_two], self.back_out_in_main)