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 TestCStepping(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
18 def getCategories(self):
19 return ['basic_process']
22 # Call super's setUp().
24 # Find the line numbers that we will step to in main:
25 self.main_source = "main.c"
26 self.less_than_two = line_number('main.c', 'Less than 2')
27 self.greater_than_two = line_number('main.c', 'Greater than or equal to 2.')
28 self.back_out_in_main = line_number('main.c', 'Back out in main')
30 def do_until (self, args, until_lines, expected_linenum):
32 exe = os.path.join(os.getcwd(), "a.out")
34 target = self.dbg.CreateTarget(exe)
35 self.assertTrue(target, VALID_TARGET)
37 main_source_spec = lldb.SBFileSpec(self.main_source)
38 break_before = target.BreakpointCreateBySourceRegex(
41 self.assertTrue(break_before, VALID_BREAKPOINT)
43 # Now launch the process, and do not stop at entry point.
44 process = target.LaunchSimple(
45 args, None, self.get_process_working_directory())
47 self.assertTrue(process, PROCESS_IS_VALID)
49 # The stop reason of the thread should be breakpoint.
50 threads = lldbutil.get_threads_stopped_at_breakpoint(
51 process, break_before)
54 self.fail("Failed to stop at first breakpoint in main.")
59 thread = self.common_setup(None)
61 cmd_interp = self.dbg.GetCommandInterpreter()
62 ret_obj = lldb.SBCommandReturnObject()
64 cmd_line = "thread until"
65 for line_num in until_lines:
66 cmd_line += " %d"%(line_num)
68 cmd_interp.HandleCommand(cmd_line, ret_obj)
69 self.assertTrue(ret_obj.Succeeded(), "'%s' failed: %s."%(cmd_line, ret_obj.GetError()))
71 frame = thread.frames[0]
72 line = frame.GetLineEntry().GetLine()
73 self.assertEqual(line, expected_linenum, 'Did not get the expected stop line number')
75 def test_hitting_one (self):
76 """Test thread step until - targeting one line and hitting it."""
77 self.do_until(None, [self.less_than_two], self.less_than_two)
79 def test_targetting_two_hitting_first (self):
80 """Test thread step until - targeting two lines and hitting one."""
81 self.do_until(["foo", "bar", "baz"], [self.less_than_two, self.greater_than_two], self.greater_than_two)
83 def test_targetting_two_hitting_second (self):
84 """Test thread step until - targeting two lines and hitting the other one."""
85 self.do_until(None, [self.less_than_two, self.greater_than_two], self.less_than_two)
87 def test_missing_one (self):
88 """Test thread step until - targeting one line and missing it."""
89 self.do_until(["foo", "bar", "baz"], [self.less_than_two], self.back_out_in_main)