brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 8db242a Raw
63 lines · python
1"""2Watch larger-than-8-bytes regions of memory, confirm that3writes to those regions are detected.4"""5 6 7import lldb8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10from lldbsuite.test import lldbutil11 12 13class UnalignedWatchpointTestCase(TestBase):14    def continue_and_report_stop_reason(self, process, iter_str):15        process.Continue()16        self.assertIn(17            process.GetState(), [lldb.eStateStopped, lldb.eStateExited], iter_str18        )19        thread = process.GetSelectedThread()20        return thread.GetStopReason()21 22    NO_DEBUG_INFO_TESTCASE = True23 24    # debugserver on AArch64 has this feature.25    @skipIf(archs=no_match(["arm64", "arm64e", "aarch64"]))26    @skipUnlessDarwin27 28    # debugserver only gained the ability to watch larger regions29    # with this patch.30    def test_large_watchpoint(self):31        """Test watchpoint that covers a large region of memory."""32        self.build()33        self.main_source_file = lldb.SBFileSpec("main.c")34        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(35            self, "break here", self.main_source_file36        )37 38        frame = thread.GetFrameAtIndex(0)39 40        array_addr = frame.GetValueForVariablePath("array").GetValueAsUnsigned()41 42        # watch 256 uint32_t elements in the middle of the array,43        # don't assume that the heap allocated array is aligned44        # to a 1024 byte boundary to begin with, force alignment.45        wa_256_addr = (array_addr + 1024) & ~(1024 - 1)46        err = lldb.SBError()47        wp_opts = lldb.SBWatchpointOptions()48        wp_opts.SetWatchpointTypeWrite(lldb.eWatchpointWriteTypeOnModify)49        wp = target.WatchpointCreateByAddress(wa_256_addr, 1024, wp_opts, err)50        self.assertTrue(wp.IsValid())51        self.assertSuccess(err)52 53        c_count = 054        reason = self.continue_and_report_stop_reason(process, "continue #%d" % c_count)55        while reason == lldb.eStopReasonWatchpoint:56            c_count = c_count + 157            reason = self.continue_and_report_stop_reason(58                process, "continue #%d" % c_count59            )60            self.assertLessEqual(c_count, 16)61 62        self.assertEqual(c_count, 16)63