1"""Test the 'step target' feature.""" 2 3 4import lldb 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10class TestStepTarget(TestBase): 11 12 mydir = TestBase.compute_mydir(__file__) 13 14 def setUp(self): 15 # Call super's setUp(). 16 TestBase.setUp(self) 17 # Find the line numbers that we will step to in main: 18 self.main_source = "main.c" 19 self.end_line = line_number(self.main_source, "All done") 20 21 @add_test_categories(['pyapi']) 22 def get_to_start(self): 23 self.build() 24 exe = self.getBuildArtifact("a.out") 25 26 target = self.dbg.CreateTarget(exe) 27 self.assertTrue(target, VALID_TARGET) 28 29 self.main_source_spec = lldb.SBFileSpec(self.main_source) 30 31 break_in_main = target.BreakpointCreateBySourceRegex( 32 'Break here to try targetted stepping', self.main_source_spec) 33 self.assertTrue(break_in_main, VALID_BREAKPOINT) 34 self.assertGreater(break_in_main.GetNumLocations(), 0, "Has locations.") 35 36 # Now launch the process, and do not stop at entry point. 37 process = target.LaunchSimple( 38 None, None, self.get_process_working_directory()) 39 40 self.assertTrue(process, PROCESS_IS_VALID) 41 42 # The stop reason of the thread should be breakpoint. 43 threads = lldbutil.get_threads_stopped_at_breakpoint( 44 process, break_in_main) 45 46 if len(threads) != 1: 47 self.fail("Failed to stop at first breakpoint in main.") 48 49 thread = threads[0] 50 return thread 51 52 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343") 53 def test_with_end_line(self): 54 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 55 56 thread = self.get_to_start() 57 58 error = lldb.SBError() 59 thread.StepInto("lotsOfArgs", self.end_line, error) 60 frame = thread.frames[0] 61 62 self.assertEqual(frame.name, "lotsOfArgs", "Stepped to lotsOfArgs.") 63 64 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343") 65 def test_with_end_line_bad_name(self): 66 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 67 68 thread = self.get_to_start() 69 70 error = lldb.SBError() 71 thread.StepInto("lotsOfArgssss", self.end_line, error) 72 frame = thread.frames[0] 73 self.assertEqual(frame.line_entry.line, self.end_line, 74 "Stepped to the block end.") 75 76 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343") 77 def test_with_end_line_deeper(self): 78 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 79 80 thread = self.get_to_start() 81 82 error = lldb.SBError() 83 thread.StepInto("modifyInt", self.end_line, error) 84 frame = thread.frames[0] 85 self.assertEqual(frame.name, "modifyInt", "Stepped to modifyInt.") 86 87 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343") 88 def test_with_command_and_block(self): 89 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 90 91 thread = self.get_to_start() 92 93 result = lldb.SBCommandReturnObject() 94 self.dbg.GetCommandInterpreter().HandleCommand( 95 'thread step-in -t "lotsOfArgs" -e block', result) 96 self.assertTrue( 97 result.Succeeded(), 98 "thread step-in command succeeded.") 99 100 frame = thread.frames[0] 101 self.assertEqual(frame.name, "lotsOfArgs", "Stepped to lotsOfArgs.") 102 103 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343") 104 def test_with_command_and_block_and_bad_name(self): 105 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 106 107 thread = self.get_to_start() 108 109 result = lldb.SBCommandReturnObject() 110 self.dbg.GetCommandInterpreter().HandleCommand( 111 'thread step-in -t "lotsOfArgsssss" -e block', result) 112 self.assertTrue( 113 result.Succeeded(), 114 "thread step-in command succeeded.") 115 116 frame = thread.frames[0] 117 118 self.assertEqual(frame.name, "main", "Stepped back out to main.") 119 # end_line is set to the line after the containing block. Check that 120 # we got there: 121 self.assertEqual(frame.line_entry.line, self.end_line, 122 "Got out of the block") 123