brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.6 KiB · 1315288 Raw
131 lines · python
1"""2Test that breakpoints do not affect stepping.3Check for correct StopReason when stepping to the line with breakpoint4which should be eStopReasonBreakpoint in general,5and eStopReasonPlanComplete when breakpoint's condition fails.6"""7 8import lldb9from lldbsuite.test.decorators import *10from lldbsuite.test.lldbtest import *11from lldbsuite.test import lldbutil12 13 14class StepOverBreakpointsTestCase(TestBase):15    def setUp(self):16        TestBase.setUp(self)17 18        self.build()19        exe = self.getBuildArtifact("a.out")20        src = lldb.SBFileSpec("main.cpp")21 22        # Create a target by the debugger.23        self.target = self.dbg.CreateTarget(exe)24        self.assertTrue(self.target, VALID_TARGET)25 26        # Setup four breakpoints, two of them with false condition27        self.line1 = line_number("main.cpp", "breakpoint_1")28        self.line4 = line_number("main.cpp", "breakpoint_4")29 30        self.breakpoint1 = self.target.BreakpointCreateByLocation(src, self.line1)31        self.assertTrue(32            self.breakpoint1 and self.breakpoint1.GetNumLocations() == 1,33            VALID_BREAKPOINT,34        )35 36        self.breakpoint2 = self.target.BreakpointCreateBySourceRegex(37            "breakpoint_2", src38        )39        self.breakpoint2.GetLocationAtIndex(0).SetCondition("false")40 41        self.breakpoint3 = self.target.BreakpointCreateBySourceRegex(42            "breakpoint_3", src43        )44        self.breakpoint3.GetLocationAtIndex(0).SetCondition("false")45 46        self.breakpoint4 = self.target.BreakpointCreateByLocation(src, self.line4)47 48        # Start debugging49        self.process = self.target.LaunchSimple(50            None, None, self.get_process_working_directory()51        )52        self.assertIsNotNone(self.process, PROCESS_IS_VALID)53        self.thread = lldbutil.get_one_thread_stopped_at_breakpoint(54            self.process, self.breakpoint155        )56        self.assertIsNotNone(self.thread, "Didn't stop at breakpoint 1.")57 58    def test_step_instruction(self):59        # Count instructions between breakpoint_1 and breakpoint_460        contextList = self.target.FindFunctions("main", lldb.eFunctionNameTypeAuto)61        self.assertEqual(contextList.GetSize(), 1)62        symbolContext = contextList.GetContextAtIndex(0)63        function = symbolContext.GetFunction()64        self.assertTrue(function)65        instructions = function.GetInstructions(self.target)66        addr_1 = self.breakpoint1.GetLocationAtIndex(0).GetAddress()67        addr_4 = self.breakpoint4.GetLocationAtIndex(0).GetAddress()68 69        # if third argument is true then the count will be the number of70        # instructions on which a breakpoint can be set.71        # start = addr_1, end = addr_4, canSetBreakpoint = True72        steps_expected = instructions.GetInstructionsCount(addr_1, addr_4, True)73        step_count = 074        # Step from breakpoint_1 to breakpoint_475        while True:76            self.thread.StepInstruction(True)77            step_count = step_count + 178            self.assertState(self.process.GetState(), lldb.eStateStopped)79            self.assertTrue(80                self.thread.GetStopReason() == lldb.eStopReasonPlanComplete81                or self.thread.GetStopReason() == lldb.eStopReasonBreakpoint82            )83            if self.thread.GetStopReason() == lldb.eStopReasonBreakpoint:84                # we should not stop on breakpoint_2 and _3 because they have false condition85                self.assertEqual(86                    self.thread.GetFrameAtIndex(0).GetLineEntry().GetLine(), self.line487                )88                # breakpoint_2 and _3 should not affect step count89                self.assertGreaterEqual(step_count, steps_expected)90                break91 92        # We did a `stepi` when we hit our last breakpoint, and the stepi was not93        # completed yet, so when we resume it will complete (running process.Continue()94        # would have the same result - we step one instruction and stop again when95        # our interrupted stepi completes).96        self.thread.StepInstruction(True)97        # Run the process until termination98        self.process.Continue()99        self.assertState(self.process.GetState(), lldb.eStateExited)100 101    @skipIf(bugnumber="llvm.org/pr31972", hostoslist=["windows"])102    def test_step_over(self):103        self.thread.StepOver()104        # We should be stopped at the breakpoint_2 line with stop plan complete reason105        self.assertState(self.process.GetState(), lldb.eStateStopped)106        self.assertStopReason(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete)107 108        self.thread.StepOver()109        # We should be stopped at the breakpoint_3 line with stop plan complete reason110        self.assertState(self.process.GetState(), lldb.eStateStopped)111        self.assertStopReason(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete)112 113        self.thread.StepOver()114        # We should be stopped at the breakpoint_4115        self.assertState(self.process.GetState(), lldb.eStateStopped)116        self.assertStopReason(self.thread.GetStopReason(), lldb.eStopReasonBreakpoint)117        thread1 = lldbutil.get_one_thread_stopped_at_breakpoint(118            self.process, self.breakpoint4119        )120        self.assertEqual(self.thread, thread1, "Didn't stop at breakpoint 4.")121 122        # Check that stepping does not affect breakpoint's hit count123        self.assertEqual(self.breakpoint1.GetHitCount(), 1)124        self.assertEqual(self.breakpoint2.GetHitCount(), 0)125        self.assertEqual(self.breakpoint3.GetHitCount(), 0)126        self.assertEqual(self.breakpoint4.GetHitCount(), 1)127 128        # Run the process until termination129        self.process.Continue()130        self.assertState(self.process.GetState(), lldb.eStateExited)131