Skip to content

Commit d2f686a

Browse files
committed
Fix unalinged watchpoints
1 parent 93bd859 commit d2f686a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ NativeProcessWindows::GetAuxvData() const {
292292

293293
llvm::Expected<llvm::ArrayRef<uint8_t>>
294294
NativeProcessWindows::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
295-
static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x3e, 0xd4}; // brk #0xf000
295+
static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x3e,
296+
0xd4}; // brk #0xf000
296297
static const uint8_t g_thumb_opcode[] = {0xfe, 0xde}; // udf #0xfe
297298

298299
switch (GetArchitecture().GetMachine()) {
@@ -309,9 +310,9 @@ NativeProcessWindows::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
309310
}
310311

311312
size_t NativeProcessWindows::GetSoftwareBreakpointPCOffset() {
312-
// Windows always reports an incremented PC after a breakpoint is hit,
313-
// even on ARM.
314-
return cantFail(GetSoftwareBreakpointTrapOpcode(0)).size();
313+
// Windows always reports an incremented PC after a breakpoint is hit,
314+
// even on ARM.
315+
return cantFail(GetSoftwareBreakpointTrapOpcode(0)).size();
315316
}
316317

317318
bool NativeProcessWindows::FindSoftwareBreakpoint(lldb::addr_t addr) {
@@ -463,6 +464,7 @@ NativeProcessWindows::OnDebugException(bool first_chance,
463464
switch (record.GetExceptionCode()) {
464465
case DWORD(STATUS_SINGLE_STEP):
465466
case STATUS_WX86_SINGLE_STEP: {
467+
#ifndef __aarch64__
466468
uint32_t wp_id = LLDB_INVALID_INDEX32;
467469
if (NativeThreadWindows *thread = GetThreadByID(record.GetThreadID())) {
468470
NativeRegisterContextWindows &reg_ctx = thread->GetRegisterContext();
@@ -483,6 +485,7 @@ NativeProcessWindows::OnDebugException(bool first_chance,
483485
}
484486
}
485487
if (wp_id == LLDB_INVALID_INDEX32)
488+
#endif
486489
StopThread(record.GetThreadID(), StopReason::eStopReasonTrace);
487490

488491
SetState(eStateStopped, true);
@@ -508,18 +511,28 @@ NativeProcessWindows::OnDebugException(bool first_chance,
508511
SetState(eStateStopped, true);
509512
return ExceptionResult::MaskException;
510513
} else {
514+
// This block of code will only be entered in case of a hardware
515+
// watchpoint or breakpoint hit on AArch64. However, we only handle
516+
// hardware watchpoints below as breakpoints are not yet supported.
511517
const std::vector<ULONG_PTR> &args = record.GetExceptionArguments();
512518
// Check that the ExceptionInformation array of EXCEPTION_RECORD
513519
// contains at least two elements: the first is a read-write flag
514520
// indicating the type of data access operation (read or write) while
515521
// the second contains the virtual address of the accessed data.
516522
if (args.size() >= 2) {
517523
uint32_t hw_id = LLDB_INVALID_INDEX32;
518-
reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
524+
Status error = reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
525+
if (error.Fail())
526+
LLDB_LOG(log,
527+
"received error while checking for watchpoint hits, pid = "
528+
"{0}, error = {1}",
529+
thread_id, error);
519530

520531
if (hw_id != LLDB_INVALID_INDEX32) {
521532
std::string desc =
522-
formatv("{0} {1} {2}", args[1], hw_id, exception_addr).str();
533+
formatv("{0} {1} {2}", reg_ctx.GetWatchpointAddress(hw_id),
534+
hw_id, exception_addr)
535+
.str();
523536
StopThread(thread_id, StopReason::eStopReasonWatchpoint, desc);
524537
SetState(eStateStopped, true);
525538
return ExceptionResult::MaskException;

0 commit comments

Comments
 (0)