llvm / llvm/llvm-project

[lldb] Hardware execution breakpoints not implemented on x86/x64 Linux

Open
#175,499 4 comments 0 reactions 0 assignees View on GitHub
backend:X86 enhancement lldb platform:linux
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Hardware execution breakpoints (`breakpoint set -H`) always fail on x86/x64 Linux because `NativeRegisterContextDBReg_x86` only implements watchpoints, not breakpoints.

Note: I am a bit surprised that it is not supported and there is no open issue for it. Hopefully it is not my skill/vision issue

## Reproduction

```
$ lldb ./helloworld
(lldb) b main
(lldb) r
(lldb) breakpoint set -a 0x555555555183 -H
warning: failed to set breakpoint site at 0x555555555183 for breakpoint 2.1: error: 9 sending the hardware breakpoint request
```

This happens even with no other hardware breakpoints set.

## Root Cause

[`NativeRegisterContextDBReg_x86`](https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.h#L16-L50) only implements watchpoint methods. It does not override `SetHardwareBreakpoint()` or `NumSupportedHardwareBreakpoints()`.

The call falls through to the [base class default](https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/common/NativeRegisterContext.cpp#L241-L246) which returns failure:

```cpp
uint32_t NativeRegisterContext::NumSupportedHardwareBreakpoints() { return 0; }

uint32_t NativeRegisterContext::SetHardwareBreakpoint(lldb::addr_t addr, size_t size) {
return LLDB_INVALID_INDEX32;
}
```

In contrast, [`NativeRegisterContextDBReg`](https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg.h#L28-L37) (used by ARM64/LoongArch) implements both breakpoints and watchpoints, and works correctly.

## Suggested Fix

Add hardware breakpoint support to `NativeRegisterContextDBReg_x86`, similar to the existing watchpoint implementation but using DR7 type bits `00` (execution) instead of `01`/`11` (data write/access).

Contributor guide

Open the contributing guide

Research direction

Start with lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.h and its existing watchpoint implementation, then inspect NativeRegisterContext.cpp and NativeRegisterContextDBReg.h for the related breakpoint behavior. Reproduce the failure with `breakpoint set -a 0x... -H` on x86/x64 Linux and compare the DR7 handling. Done means execution hardware breakpoints can be set and used successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.