153 lines · python
1from lldbsuite.test.decorators import *2from lldbsuite.test.lldbtest import *3from lldbsuite.test import lldbutil4from lldbsuite.test_event.build_exception import BuildError5 6 7class TestStepUntilAPI(TestBase):8 NO_DEBUG_INFO_TESTCASE = True9 10 def setUp(self):11 super().setUp()12 13 self.main_source = "main.c"14 self.main_spec = lldb.SBFileSpec(self.main_source)15 self.less_than_two = line_number("main.c", "Less than 2")16 self.greater_than_two = line_number("main.c", "Greater than or equal to 2.")17 self.back_out_in_main = line_number("main.c", "Back out in main")18 self.in_foo = line_number("main.c", "In foo")19 20 def _build_dict_for_discontinuity(self):21 return dict(22 CFLAGS_EXTRAS="-funique-basic-block-section-names "23 + "-ffunction-sections -fbasic-block-sections=list="24 + self.getSourcePath("function.list"),25 LD_EXTRAS="-Wl,--script=" + self.getSourcePath("symbol.order"),26 )27 28 def _do_until(self, build_dict, args, until_line, expected_line):29 self.build(dictionary=build_dict)30 launch_info = lldb.SBLaunchInfo(args)31 _, _, thread, _ = lldbutil.run_to_source_breakpoint(32 self, "At the start", self.main_spec, launch_info33 )34 35 self.assertSuccess(36 thread.StepOverUntil(self.frame(), self.main_spec, until_line)37 )38 39 self.runCmd("process status")40 41 line = self.frame().GetLineEntry().GetLine()42 self.assertEqual(43 line, expected_line, "Did not get the expected stop line number"44 )45 46 def _assertDiscontinuity(self):47 target = self.target()48 foo = target.FindFunctions("foo")49 self.assertEqual(len(foo), 1)50 foo = foo[0]51 52 call_me = self.target().FindFunctions("call_me")53 self.assertEqual(len(call_me), 1)54 call_me = call_me[0]55 56 foo_addr = foo.function.GetStartAddress().GetLoadAddress(target)57 found_before = False58 found_after = False59 for range in call_me.function.GetRanges():60 addr = range.GetBaseAddress().GetLoadAddress(target)61 if addr < foo_addr:62 found_before = True63 if addr > foo_addr:64 found_after = True65 66 self.assertTrue(67 found_before and found_after,68 "'foo' is not between 'call_me'" + str(foo) + str(call_me),69 )70 71 def test_hitting(self):72 """Test SBThread.StepOverUntil - targeting a line and hitting it."""73 self._do_until(None, None, self.less_than_two, self.less_than_two)74 75 @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])76 @skipIf(archs=no_match(["x86_64", "aarch64"]))77 @skipIf(compiler=no_match(["clang"]))78 def test_hitting_discontinuous(self):79 """Test SBThread.StepOverUntil - targeting a line and hitting it -- with80 discontinuous functions"""81 try:82 self._do_until(83 self._build_dict_for_discontinuity(),84 None,85 self.less_than_two,86 self.less_than_two,87 )88 except BuildError as ex:89 self.skipTest(f"failed to build with linker script.")90 91 self._assertDiscontinuity()92 93 def test_missing(self):94 """Test SBThread.StepOverUntil - targeting a line and missing it by stepping out to call site"""95 self._do_until(96 None, ["foo", "bar", "baz"], self.less_than_two, self.back_out_in_main97 )98 99 @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])100 @skipIf(archs=no_match(["x86_64", "aarch64"]))101 @skipIf(compiler=no_match(["clang"]))102 def test_missing_discontinuous(self):103 """Test SBThread.StepOverUntil - targeting a line and missing it by104 stepping out to call site -- with discontinuous functions"""105 try:106 self._do_until(107 self._build_dict_for_discontinuity(),108 ["foo", "bar", "baz"],109 self.less_than_two,110 self.back_out_in_main,111 )112 except BuildError as ex:113 self.skipTest(f"failed to build with linker script.")114 115 self._assertDiscontinuity()116 117 def test_bad_line(self):118 """Test that we get an error if attempting to step outside the current119 function"""120 self.build()121 _, _, thread, _ = lldbutil.run_to_source_breakpoint(122 self, "At the start", self.main_spec123 )124 self.assertIn(125 "step until target not in current function",126 thread.StepOverUntil(127 self.frame(), self.main_spec, self.in_foo128 ).GetCString(),129 )130 131 @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])132 @skipIf(archs=no_match(["x86_64", "aarch64"]))133 @skipIf(compiler=no_match(["clang"]))134 def test_bad_line_discontinuous(self):135 """Test that we get an error if attempting to step outside the current136 function -- and the function is discontinuous"""137 138 try:139 self.build(dictionary=self._build_dict_for_discontinuity())140 _, _, thread, _ = lldbutil.run_to_source_breakpoint(141 self, "At the start", self.main_spec142 )143 except BuildError as ex:144 self.skipTest(f"failed to build with linker script.")145 146 self.assertIn(147 "step until target not in current function",148 thread.StepOverUntil(149 self.frame(), self.main_spec, self.in_foo150 ).GetCString(),151 )152 self._assertDiscontinuity()153