Intel 64 and IA-32 Architectures Software Developers Manual Volume 3B, System Programming Guide Part 2

Table Of Contents
Vol. 3 18-29
DEBUGGING AND PERFORMANCE MONITORING
When the processor generates a a debug exception (#DB), it automatically clears the
LBR flag before executing the exception handler. This action does not clear previously
stored LBR stack MSRs. The branch record for the last four taken branches, interrupts
and/or exceptions are retained for analysis.
A debugger can use the linear addresses in the LBR stack to re-set breakpoints in the
breakpoint address registers (DR0 through DR3). This allows a backward trace from
the manifestation of a particular bug toward its source.
If the LBR flag is cleared and TR flag in the MSR_DEBUGCTLA MSR remains set, the
processor will continue to update LBR stack MSRs. This is because BTM information
must be generated from entries in the LBR stack (see 14.5.5). A #DB does not auto-
matically clear the TR flag.
18.7.5 Single-Stepping on Branches, Exceptions, and Interrupts
When software sets both the BTF flag in the MSR_DEBUGCTLA MSR and the TF flag in
the EFLAGS register, the processor generates a single-step debug exception the next
time it takes a branch, services an interrupt, or generates an exception. This mecha-
nism allows the debugger to single-step on control transfers caused by branches,
interrupts, and exceptions. This “control-flow single stepping” helps isolate a bug to
a particular block of code before instruction single-stepping further narrows the
search. If the BTF flag is set when the processor generates a debug exception, the
processor clears the BTF flag along with the TF flag. The debugger must reset the BTF
and TF flags before resuming program execution to continue control-flow single step-
ping.
18.7.6 Branch Trace Messages
Setting the TR flag in the MSR_DEBUGCTLA (see Figure 18-6), IA32_DEBUGCTL (see
Figure 18-8), or MSR_DEBUGCTLB (see Figure 18-10) MSR enables branch trace
messages (BTMs). Thereafter, when the processor detects a branch, exception, or
interrupt, it sends a branch record out on the system bus as a BTM. A debugging
device that is monitoring the system bus can read these messages and synchronize
operations with taken branch, interrupt, and exception events.
When interrupts or exceptions occur in conjunction with a taken branch, additional
BTMs are sent out on the bus, as described in Section 18.7.4, “Monitoring Branches,
Exceptions, and Interrupts.
Setting this flag (BTS) alone can greatly reduce the performance of the processor.
CPL-qualified branch trace storing mechanism can help mitigate the performance
impact of sending/logging branch trace messages. See Section 18.7.1, “CPL-Quali-
fied Branch Trace Mechanism.
Unlike the P6 family processors, the Pentium 4, Atom, and Intel Xeon processors can
collect branch records in the LBR stack MSRs while at the same time sending/storing