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 do_until (self, args, until_lines, expected_linenum): 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 thread = self.common_setup(None) 52 53 cmd_interp = self.dbg.GetCommandInterpreter() 54 ret_obj = lldb.SBCommandReturnObject() 55 56 cmd_line = "thread until" 57 for line_num in until_lines: 58 cmd_line += " %d"%(line_num) 59 60 cmd_interp.HandleCommand(cmd_line, ret_obj) 61 self.assertTrue(ret_obj.Succeeded(), "'%s' failed: %s."%(cmd_line, ret_obj.GetError())) 62 63 frame = thread.frames[0] 64 line = frame.GetLineEntry().GetLine() 65 self.assertEqual(line, expected_linenum, 'Did not get the expected stop line number') 66 67 def test_hitting_one (self): 68 """Test thread step until - targeting one line and hitting it.""" 69 self.do_until(None, [self.less_than_two], self.less_than_two) 70 71 def test_targetting_two_hitting_first (self): 72 """Test thread step until - targeting two lines and hitting one.""" 73 self.do_until(["foo", "bar", "baz"], [self.less_than_two, self.greater_than_two], self.greater_than_two) 74 75 def test_targetting_two_hitting_second (self): 76 """Test thread step until - targeting two lines and hitting the other one.""" 77 self.do_until(None, [self.less_than_two, self.greater_than_two], self.less_than_two) 78 79 def test_missing_one (self): 80 """Test thread step until - targeting one line and missing it.""" 81 self.do_until(["foo", "bar", "baz"], [self.less_than_two], self.back_out_in_main) 82 83 84 85