120 lines · python
1"""Test the 'step target' feature."""2 3 4import lldb5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 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_spec30 )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 thread47 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 self.do_command_and_block()87 self.do_command_and_block(True)88 89 def do_command_and_block(self, use_regexp_step=False):90 thread = self.get_to_start()91 92 if use_regexp_step:93 self.expect("s lotsOfArgs")94 else:95 self.expect('thread step-in -t "lotsOfArgs" -e block')96 97 frame = thread.frames[0]98 self.assertEqual(frame.name, "lotsOfArgs", "Stepped to lotsOfArgs.")99 100 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343")101 def test_with_command_and_block_and_bad_name(self):102 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""103 self.do_with_command_and_block_and_bad_name()104 self.do_with_command_and_block_and_bad_name(True)105 106 def do_with_command_and_block_and_bad_name(self, use_regexp_step=False):107 thread = self.get_to_start()108 109 if use_regexp_step:110 self.expect("s lotsOfArgsssss")111 else:112 self.expect('thread step-in -t "lotsOfArgsssss" -e block')113 114 frame = thread.frames[0]115 116 self.assertEqual(frame.name, "main", "Stepped back out to main.")117 # end_line is set to the line after the containing block. Check that118 # we got there:119 self.assertEqual(frame.line_entry.line, self.end_line, "Got out of the block")120