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