brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.8 KiB · afdc92d Raw
131 lines · python
1"""Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""2 3from lldbsuite.test.decorators import *4from lldbsuite.test.lldbtest import *5from lldbsuite.test import lldbutil6from lldbsuite.test_event.build_exception import BuildError7 8 9class StepUntilTestCase(TestBase):10    def setUp(self):11        # Call super's setUp().12        TestBase.setUp(self)13        # Find the line numbers that we will step to in main:14        self.main_source = "main.c"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 _common_setup(self, build_dict, args):29        self.build(dictionary=build_dict)30        exe = self.getBuildArtifact("a.out")31 32        target = self.dbg.CreateTarget(exe)33        self.assertTrue(target, VALID_TARGET)34 35        main_source_spec = lldb.SBFileSpec(self.main_source)36        break_before = target.BreakpointCreateBySourceRegex(37            "At the start", main_source_spec38        )39        self.assertTrue(break_before, VALID_BREAKPOINT)40 41        # Now launch the process, and do not stop at entry point.42        process = target.LaunchSimple(args, None, self.get_process_working_directory())43 44        self.assertTrue(process, PROCESS_IS_VALID)45 46        # The stop reason of the thread should be breakpoint.47        threads = lldbutil.get_threads_stopped_at_breakpoint(process, break_before)48 49        if len(threads) != 1:50            self.fail("Failed to stop at first breakpoint in main.")51 52        thread = threads[0]53        return thread54 55    def do_until(self, args, until_lines, expected_linenum):56        thread = self._common_setup(None, args)57 58        cmd_interp = self.dbg.GetCommandInterpreter()59        ret_obj = lldb.SBCommandReturnObject()60 61        cmd_line = "thread until"62        for line_num in until_lines:63            cmd_line += " %d" % (line_num)64 65        cmd_interp.HandleCommand(cmd_line, ret_obj)66        self.assertTrue(67            ret_obj.Succeeded(), "'%s' failed: %s." % (cmd_line, ret_obj.GetError())68        )69 70        frame = thread.frames[0]71        line = frame.GetLineEntry().GetLine()72        self.assertEqual(73            line, expected_linenum, "Did not get the expected stop line number"74        )75 76    def test_hitting_one(self):77        """Test thread step until - targeting one line and hitting it."""78        self.do_until(None, [self.less_than_two], self.less_than_two)79 80    def test_targetting_two_hitting_first(self):81        """Test thread step until - targeting two lines and hitting one."""82        self.do_until(83            ["foo", "bar", "baz"],84            [self.less_than_two, self.greater_than_two],85            self.greater_than_two,86        )87 88    def test_targetting_two_hitting_second(self):89        """Test thread step until - targeting two lines and hitting the other one."""90        self.do_until(91            None, [self.less_than_two, self.greater_than_two], self.less_than_two92        )93 94    def test_missing_one(self):95        """Test thread step until - targeting one line and missing it by stepping out to call site"""96        self.do_until(97            ["foo", "bar", "baz"], [self.less_than_two], self.back_out_in_main98        )99 100    @no_debug_info_test101    def test_bad_line(self):102        """Test that we get an error if attempting to step outside the current103        function"""104        thread = self._common_setup(None, None)105        self.expect(106            f"thread until {self.in_foo}",107            substrs=["Until target outside of the current function"],108            error=True,109        )110 111    @no_debug_info_test112    @skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])113    @skipIf(archs=no_match(["x86_64", "aarch64"]))114    @skipIf(compiler=no_match(["clang"]))115    def test_bad_line_discontinuous(self):116        """Test that we get an error if attempting to step outside the current117        function -- and the function is discontinuous"""118        try:119            self.build(dictionary=self._build_dict_for_discontinuity())120        except BuildError as ex:121            self.skipTest(f"failed to build with linker script.")122 123        _, _, thread, _ = lldbutil.run_to_source_breakpoint(124            self, "At the start", lldb.SBFileSpec(self.main_source)125        )126        self.expect(127            f"thread until {self.in_foo}",128            substrs=["Until target outside of the current function"],129            error=True,130        )131