[Lldb-commits] [lldb] [lldb] Fix false watchpoint stop on single-step when hw debug regset read fails (PR #226880)

via lldb-commits lldb-commits at lists.llvm.org
Sun Sep 27 21:09:20 PDT 2026


https://github.com/LiRvs-Miria created https://github.com/llvm/llvm-project/pull/226880

On aarch64 Linux, the kernel reports instruction single-step exceptions as SIGTRAP/TRAP_HWBKPT. NativeProcessLinux handles si_code 0, TRAP_TRACE and TRAP_HWBKPT in the same case, so every instruction-level stop goes through GetWatchpointHitIndex().

NativeRegisterContextLinux_arm64::GetWatchpointHitIndex() reads the hardware debug registers via PTRACE_GETREGSET(NT_ARM_HW_WATCH / NT_ARM_HW_BREAK). On kernels where those regsets are unavailable, the read fails with EINVAL and GetWatchpointHitIndex() returns an error without assigning wp_index. NativeProcessLinux declares wp_index uninitialized, logs the error, and then still tests it.

Observed behavior on Cortex-A35, OpenWrt, PREEMPT_RT 6.1.82-rt27:
- lldb-dap next/stepOver advances a single instruction (PC + 4)
- the stopped event reports description "watchpoint -1", reason "breakpoint"

Fix: Initialize wp_index to LLDB_INVALID_INDEX32. If the hardware debug register read fails, execution falls through to normal trace-stop handling.

>From 8a5e87230d9a77abef864d1e1d088ac8e1c51612 Mon Sep 17 00:00:00 2001
From: LiRvs-Miria <1753531985 at qq.com>
Date: Mon, 28 Sep 2026 11:58:55 +0800
Subject: [PATCH] [lldb] Fix false watchpoint stop on single-step when hw debug
 regset read fails

On aarch64 single-step is reported as TRAP_HWBKPT, so every step enters
the watchpoint query path. If GetWatchpointHitIndex() fails without
setting wp_index (e.g. NT_ARM_HW_WATCH unavailable), the uninitialized
value makes NativeProcessLinux report a bogus watchpoint hit.

Initialize wp_index to LLDB_INVALID_INDEX32 so the failure falls
through to normal trace-stop handling.
---
 lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index fd7c2557a1fc0..d31044b9da908 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -759,7 +759,10 @@ void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
   case TRAP_HWBKPT: // We receive this on watchpoint hit
   {
     // If a watchpoint was hit, report it
-    uint32_t wp_index;
+    // GetWatchpointHitIndex() may fail without setting wp_index, e.g. when
+    // the hardware debug regset is unavailable. Initialize it so the failure
+    // path falls through instead of reporting a bogus watchpoint hit
+    uint32_t wp_index = LLDB_INVALID_INDEX32;
     Status error = thread.GetRegisterContext().GetWatchpointHitIndex(
         wp_index, (uintptr_t)info.si_addr);
     if (error.Fail())



More information about the lldb-commits mailing list