Program and Event Trace - 2024.2 English

MicroBlaze Processor Reference Guide (UG984)

Document ID
UG984
Release Date
2024-11-27
Version
2024.2 English

With extended debugging, MicroBlaze provides program and event trace, either storing information in the Embedded Trace Buffer or transmitting it to the MDM, to enable program execution tracing. The MDM is used when the parameter C_DEBUG_EXTERNAL_TRACE is set, allowing output of program trace from multiple processors using external interfaces.

The size of the Embedded Trace Buffer can be configured from 8 KB to 128 KB using the parameter C_DEBUG_TRACE_SIZE. The default buffer size with external trace is 8 KB, but it can also be configured from 32B to 256B to use distributed RAM. It is recommended to always keep the default 8 KB size, unless block RAM resources are very scarce. By setting C_DEBUG_TRACE_SIZE to 0 (None), program trace is disabled.

Program trace uses compression to reduce the amount of trace data, while still allowing reconstruction of the program execution flow or the entire processor software state. There are three main compression levels:

Complete trace
Stores complete trace information including cycle count for each executed instruction using 144 bits, ranging from 512 to 8192 items depending on the configured Embedded Trace Buffer size. Complete trace is not available when C_DEBUG_EXTERNAL_TRACE is set or with 64-bit MicroBlaze (C_DATA_SIZE = 64).
Program flow
Stores program flow changes, that is the sequence of branches taken or not taken, and the new program counter for indirect branches, interrupts, exceptions, and hardware breaks.

The program counter can also optionally be stored for return instructions to simplify program flow reconstruction, or for all taken branches to handle self-modifying code.

Data read from memory or fetched from AXI4-Stream interfaces might optionally be stored to allow reconstructing the entire processor software state, enabling reverse single step functionality. When the data access instruction is in a delay slot of a dynamic branch or return, the data is stored first followed by the branch target program counter. For data access instructions in delay slots of static branches, the program flow change is first saved followed by the data.

Events representing all program exceptions, interrupts, and breaks, as well as all cross-trigger events defined in Table 1 are also stored, to allow unambiguous decoding of program flow changes. Each event is preceded by a stored program counter.

Software can inject an event by using an “xori r0, rN, IMM” instruction. Typically this is used to trace operating system events like context switches and system calls, but it can be used by any program to trace significant events.

Program flow and cycle count
Stores the cycle count between instructions along with the same information as program flow alone, to also allow reconstruction of the program execution time.
Event Trace
Stores event trace information including cycle count events. Events include all program exceptions, interrupts, and breaks, as well as all cross-trigger events defined in Table 1. Each event is optionally preceded by a stored program counter.

The program counter can also optionally be stored for call instructions to trace function calls in the program, and for return instructions to trace function call returns.

Software can inject an event by using an “xori r0, rA, IMM” instruction. Typically this is used to trace operating system events like context switches and system calls, but it can be used by any program to trace significant events.

Tracing can be started using the Trace Command Register, by hitting a program breakpoint or watchpoint configured as a tracepoint in the Trace Control Register, or by a cross trigger event (seeTable 1).

Tracing is automatically stopped when the trace buffer becomes full, and can be stopped using the Trace Command Register or by a cross trigger event (see Table 1).

The cycle count can measure up to 32768 clock cycles when using complete trace, and up to 8192 cycles between instructions when using program flow and cycle count. If the cycle count exceeds this value, the Trace Status Register overflow bit is set to one.

It is possible to configure trace to halt the processor when the trace buffer becomes full or when the cycle count overflows. This allows continuous trace of the entire program flow, albeit not in real time due to the time required to read the trace buffer.

The debug registers used to configure and control tracing, and to read the Embedded Trace Buffer, are listed in the following table.

The DBG_CTRL value indicates the value to use in the MDM Debug Register Access Control Register to access the register, used with MDM software access to debug registers.

Table 1. MicroBlaze Program Trace Debug Registers
Register Name Size (bits) MDM Command DBG_CTRL Value R/W Description
Trace Control 22 0110 0001 4C215 W Set tracepoints, trace compression level and optionally stored trace information
Trace Command 4 0110 0010 4C403 W Command to clear trace buffer, start or stop trace, and sample number of current buffer items
Trace Status 18 0110 0011 4C611 R Read the sampled trace buffer status
Trace Data Read 1 18 0110 0110 4CC11 R Read the oldest item from the Embedded Trace Buffer
  1. This register is not available when C_DEBUG_EXTERNAL_TRACE is set.