On the x86 architecture, a debug register is a special-purpose processor register used for program debugging. There are six debug registers, named DR0 through DR7 (with DR4 and DR5 serving as obsolete synonyms for DR6 and DR7). These registers allow programmers to selectively enable various debug conditions associated with a set of four debug addresses. They are privileged resources; the MOV instructions that access them can only be executed at privilege level zero.
DR0 through DR3 — Breakpoint Address Registers
Each of these four registers holds the linear address associated with one of four hardware breakpoint conditions. Each breakpoint condition is further defined by control bits in DR7. The addresses are linear addresses; if paging is enabled, they are translated to physical addresses by the processor's paging mechanism. Because different tasks may have different linear-to-physical mappings, DR7 provides both global (all tasks) and local (current task only) enable bits for each breakpoint.
DR6 — Debug Status Register
DR6 reports which debug conditions have occurred. When the processor detects an enabled debug exception, it sets the corresponding bits before entering the debug exception handler. Key bits include:
| Bit(s) | Name | Description |
|---|---|---|
| 0–3 | B0–B3 | Breakpoint #0–#3 condition detected |
| 13 | BD | Debug register access detected (next instruction accesses a debug register) |
| 14 | BS | Single-step execution (enabled by EFLAGS.TF) |
| 15 | BT | Task switch breakpoint (TSS has T flag set) |
| 16 | RTM | (Intel TSX only) Debug exception inside/outside RTM transaction |
Bits 13, 14, and 15 of DR6 are never cleared by hardware; debug handlers should manually clear them before returning to the interrupted task.
DR7 — Debug Control Register
DR7 controls the four address breakpoint conditions and specifies the type and size of each breakpoint. It has two levels of enabling:
- Local enable bits (L0–L3): Automatically reset at every task switch.
- Global enable bits (G0–G3): Not reset by task switches; used for conditions global to all tasks.
Key control fields include:
| Bits | Name | Description |
|---|---|---|
| 0–7 | L0–L3, G0–G3 | Local/global enable for breakpoints #0–#3 |
| 13 | GD | General Detect Enable — causes a debug exception on any access to DR0–DR7 |
| 17:16, 21:20, 25:24, 29:28 | R/W0–R/W3 | Breakpoint condition type |
| 19:18, 23:22, 27:26, 31:30 | LEN0–LEN3 | Breakpoint length |
Breakpoint conditions (R/W field):
| Value | Condition |
|---|---|
00b |
Instruction execution only |
01b |
Data writes only |
10b |
I/O reads and writes (only if CR4.DE=1) |
11b |
Data reads and writes |
Breakpoint lengths (LEN field):
| Value | Length |
|---|---|
00b |
1 byte |
01b |
2 bytes |
10b |
8 bytes (64-bit mode only) |
11b |
4 bytes |
For instruction execution breakpoints, the length must be set to 00b (1 byte).
DR4 and DR5
DR4 and DR5 are not real registers. On processors supporting the CR4.DE bit (Intel Pentium and later):
- CR4.DE = 0: DR4 and DR5 alias to DR6 and DR7, respectively.
- CR4.DE = 1: Accessing DR4 or DR5 results in an invalid opcode (#UD) exception.
On processors without CR4.DE, behavior is officially undefined; they are usually aliased to DR6/DR7, though exceptions exist and have been used for CPU identification.
Usage Notes
- Debug registers are accessed via variants of the MOV instruction at privilege level 0 only; attempts at other privilege levels cause a general protection fault.
- On the 80386, enabling exact breakpoints (bits 9:8 of DR7) caused data breakpoint exceptions to be raised as trap-type exceptions for the instruction performing the data access, at a significant performance cost. On later processors, breakpoints are always exact and these bits are ignored by the CPU.
- Setting bit 12 of DR7 modifies breakpoint, single-stepping, and general-detect behavior to break to in-circuit emulation (Intel 386/486) or System Management Mode (AMD/IBM 386/486).