brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · a07b297 Raw
98 lines · python
1"""2Watch contiguous memory regions with separate watchpoints, check that lldb3correctly detect which watchpoint was hit for each one.4"""5 6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class ConsecutiveWatchpointsTestCase(TestBase):13    NO_DEBUG_INFO_TESTCASE = True14 15    def continue_and_report_stop_reason(self, process, iter_str):16        process.Continue()17        self.assertIn(18            process.GetState(), [lldb.eStateStopped, lldb.eStateExited], iter_str19        )20        thread = process.GetSelectedThread()21        return thread.GetStopReason()22 23    # debugserver only gained the ability to watch larger regions24    # with this patch.25    @skipIfOutOfTreeDebugserver26    def test_consecutive_watchpoints(self):27        """Test watchpoint that covers a large region of memory."""28        self.build()29        self.main_source_file = lldb.SBFileSpec("main.c")30        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(31            self, "break here", self.main_source_file32        )33 34        frame = thread.GetFrameAtIndex(0)35 36        field2_wp = (37            frame.locals["var"][0]38            .GetChildMemberWithName("field2")39            .Watch(True, False, True)40        )41        field3_wp = (42            frame.locals["var"][0]43            .GetChildMemberWithName("field3")44            .Watch(True, False, True)45        )46        field4_wp = (47            frame.locals["var"][0]48            .GetChildMemberWithName("field4")49            .Watch(True, False, True)50        )51        field5_wp = (52            frame.locals["var"][0]53            .GetChildMemberWithName("field5")54            .Watch(True, False, True)55        )56 57        # Require that the first two watchpoints58        # are set -- hopefully every machine running59        # the testsuite can support two watchpoints.60        self.assertTrue(field2_wp.IsValid())61        self.assertTrue(field3_wp.IsValid())62 63        reason = self.continue_and_report_stop_reason(process, "continue to field2 wp")64        self.assertEqual(reason, lldb.eStopReasonWatchpoint)65        stop_reason_watchpoint_id = (66            process.GetSelectedThread().GetStopReasonDataAtIndex(0)67        )68        self.assertEqual(stop_reason_watchpoint_id, field2_wp.GetID())69 70        reason = self.continue_and_report_stop_reason(process, "continue to field3 wp")71        self.assertEqual(reason, lldb.eStopReasonWatchpoint)72        stop_reason_watchpoint_id = (73            process.GetSelectedThread().GetStopReasonDataAtIndex(0)74        )75        self.assertEqual(stop_reason_watchpoint_id, field3_wp.GetID())76 77        # If we were able to set the second two watchpoints,78        # check that they are hit.  Some CI bots can only79        # create two watchpoints.80        if field4_wp.IsValid() and field5_wp.IsValid():81            reason = self.continue_and_report_stop_reason(82                process, "continue to field4 wp"83            )84            self.assertEqual(reason, lldb.eStopReasonWatchpoint)85            stop_reason_watchpoint_id = (86                process.GetSelectedThread().GetStopReasonDataAtIndex(0)87            )88            self.assertEqual(stop_reason_watchpoint_id, field4_wp.GetID())89 90            reason = self.continue_and_report_stop_reason(91                process, "continue to field5 wp"92            )93            self.assertEqual(reason, lldb.eStopReasonWatchpoint)94            stop_reason_watchpoint_id = (95                process.GetSelectedThread().GetStopReasonDataAtIndex(0)96            )97            self.assertEqual(stop_reason_watchpoint_id, field5_wp.GetID())98