Currently on Darwin arm64 systems using debugserver, if you watch a memory region and a large write starts before the watched region, and extends in to the watched region, we will have a watchpoint exception but the address reported may be the start of the access -- before the watched memory range. In this case, lldb will not recognize which watchpoint to disable to step past the watchpoint and execution will stop, leaving the user to disable/stepi/re-enable manually.
This patch takes the trap address (FAR register) and finds the nearest watchpoint if it is not contained in any watched region. It also parses the ESR register flags and if the processor reported the watchpoint index number instead of an address in the FAR register, handle that. Send (1) an address within the watched mem range, (2) the watchpoint hardware index, and (3) the actual trap address which may exist outside a watched mem range to lldb in a description string in the stop packet.
Add a test case that has a uint8_t[8] array, watches a one-byte element in that array, and then does a 64-bit write to the entire array - so our FAR address may be the start of the uint8_t[8] array, and confirm that lldb correctly associates this with the watchpoint we set.
This patch depends on https://reviews.llvm.org/D147816 ("Clarify how watchpoint description in stop packets work, fix AArch64 unintended behavior") being present. Without that patch, when we have a trap address outside the range of all watched memory ranges, lldb will silently continue past this watchpoint. Correct behavior on MIPS targets, but not on AArch64.
Can you add here why "correctly associating" is not as easy as it sounds.
"This requires lldb to handle...".