Files
clang-p2996/lldb/test/API/functionalities/watchpoint/large-watchpoint/TestLargeWatchpoint.py
Jason Molenda 5953532615 [lldb] Add QSupported key to report watchpoint types supported (#80376)
debugserver on arm64 devices can manage both Byte Address Select
watchpoints (1-8 bytes) and MASK watchpoints (8 bytes-2 gigabytes). This
adds a SupportedWatchpointTypes key to the QSupported response from
debugserver with a list of these, so lldb can take full advantage of
them when creating larger regions with a single hardware watchpoint.

Also add documentation for this, and two other lldb extensions, to the
lldb-gdb-remote.txt documentation.

Re-enable TestLargeWatchpoint.py on Darwin systems when testing with the
in-tree built debugserver. I can remove the "in-tree built debugserver"
in the future when this new key is handled by an Xcode debugserver.
2024-02-05 18:45:01 -08:00

64 lines
2.2 KiB
Python

"""
Watch larger-than-8-bytes regions of memory, confirm that
writes to those regions are detected.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class UnalignedWatchpointTestCase(TestBase):
def continue_and_report_stop_reason(self, process, iter_str):
process.Continue()
self.assertIn(
process.GetState(), [lldb.eStateStopped, lldb.eStateExited], iter_str
)
thread = process.GetSelectedThread()
return thread.GetStopReason()
NO_DEBUG_INFO_TESTCASE = True
# debugserver on AArch64 has this feature.
@skipIf(archs=no_match(["arm64", "arm64e", "aarch64"]))
@skipUnlessDarwin
# debugserver only gained the ability to watch larger regions
# with this patch.
@skipIfOutOfTreeDebugserver
def test_large_watchpoint(self):
"""Test watchpoint that covers a large region of memory."""
self.build()
self.main_source_file = lldb.SBFileSpec("main.c")
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "break here", self.main_source_file
)
frame = thread.GetFrameAtIndex(0)
array_addr = frame.GetValueForVariablePath("array").GetValueAsUnsigned()
# watch 256 uint32_t elements in the middle of the array,
# don't assume that the heap allocated array is aligned
# to a 1024 byte boundary to begin with, force alignment.
wa_256_addr = (array_addr + 1024) & ~(1024 - 1)
err = lldb.SBError()
wp_opts = lldb.SBWatchpointOptions()
wp_opts.SetWatchpointTypeWrite(lldb.eWatchpointWriteTypeOnModify)
wp = target.WatchpointCreateByAddress(wa_256_addr, 1024, wp_opts, err)
self.assertTrue(wp.IsValid())
self.assertSuccess(err)
c_count = 0
reason = self.continue_and_report_stop_reason(process, "continue #%d" % c_count)
while reason == lldb.eStopReasonWatchpoint:
c_count = c_count + 1
reason = self.continue_and_report_stop_reason(
process, "continue #%d" % c_count
)
self.assertLessEqual(c_count, 16)
self.assertEqual(c_count, 16)