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