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 def test_with_end_line_deeper(self): 77 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 78 79 thread = self.get_to_start() 80 81 error = lldb.SBError() 82 thread.StepInto("modifyInt", self.end_line, error) 83 frame = thread.frames[0] 84 self.assertEqual(frame.name, "modifyInt", "Stepped to modifyInt.") 85 86 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343") 87 def test_with_command_and_block(self): 88 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 89 90 thread = self.get_to_start() 91 92 result = lldb.SBCommandReturnObject() 93 self.dbg.GetCommandInterpreter().HandleCommand( 94 'thread step-in -t "lotsOfArgs" -e block', result) 95 self.assertTrue( 96 result.Succeeded(), 97 "thread step-in command succeeded.") 98 99 frame = thread.frames[0] 100 self.assertEqual(frame.name, "lotsOfArgs", "Stepped to lotsOfArgs.") 101 102 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343") 103 def test_with_command_and_block_and_bad_name(self): 104 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms.""" 105 106 thread = self.get_to_start() 107 108 result = lldb.SBCommandReturnObject() 109 self.dbg.GetCommandInterpreter().HandleCommand( 110 'thread step-in -t "lotsOfArgsssss" -e block', result) 111 self.assertTrue( 112 result.Succeeded(), 113 "thread step-in command succeeded.") 114 115 frame = thread.frames[0] 116 117 self.assertEqual(frame.name, "main", "Stepped back out to main.") 118 # end_line is set to the line after the containing block. Check that 119 # we got there: 120 self.assertEqual(frame.line_entry.line, self.end_line, 121 "Got out of the block") 122