[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:10:24 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: LiRvs-Miria

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/226880.diff


1 Files Affected:

- (modified) lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp (+4-1) 


``````````diff
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())

``````````

</details>


https://github.com/llvm/llvm-project/pull/226880


More information about the lldb-commits mailing list