llvm-project
5f7f8aec - [lldb][Linux] Fix false watchpoint stop on single-step when hw debug regset read fails (#226880)

Commit
13 days ago
[lldb][Linux] Fix false watchpoint stop on single-step when hw debug regset read fails (#226880) On aarch64 Linux, the kernel reports instruction single-step exceptions as SIGTRAP/TRAP_HWBKPT. NativeProcessLinux::MonitorSIGTRAP 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 in two places, following the contract that `GetWatchpointHitIndex()` must always assign `wp_index` (`LLDB_INVALID_INDEX32` when there is no hit or on error), as the base class default and the other implementations already do: - `NativeRegisterContextDBReg::GetWatchpointHitIndex()` assigns `LLDB_INVALID_INDEX32` before any early return, so the error path leaves a defined value. This also stops the entry `LLDB_LOG` from reading an uninitialized `wp_index`. - `NativeProcessLinux::MonitorSIGTRAP` checks `error.Success()` before testing the `wp_index`/`bp_index` out-params, so an out-param is never read after a failed call. With these changes, when the hardware debug register read fails, execution falls through to normal trace-stop handling; genuine watchpoint hits behave exactly as before. On kernels without the hw-debug regsets, hardware watchpoints/breakpoints are unavailable anyway; software breakpoints (BRK) and single-stepping are unaffected. AI tool usage: I used an AI assistant to help analyze the root cause and draft this PR description. The code change and testing were done by me.
Author
Parents
Loading