Introduction to using trace
See also:
Reasons for using trace
By using trace, you can inspect the program flow up to a specific state, for instance an application crash, and use the trace data to locate the origin of the problem. Trace data can be useful for locating programming errors that have irregular symptoms and occur sporadically.
Reasons for using the trace triggers and filters
By using trace trigger and filter conditions, you can select the interesting parts of your source code and use the trace buffer in the trace probe more efficiently. Trace triggers—Trace Start Trigger and Trace Stop Trigger breakpoints—specify for example a code section for which you want to collect trace data. A trace filter specifies conditions that, when fulfilled, activate the trace data collection during execution.
Briefly about trace
To use trace in C-SPY requires that your target system can generate trace data. Once generated, C-SPY can collect it and you can visualize and analyze the data in various windows and dialog boxes.
C-SPY supports collecting trace data from these target systems:
Devices with support for ETM (Embedded Trace Macrocell)—ETM trace
Devices with support for the SWD (Serial Wire Debug) interface using the SWO (Serial Wire Output) communication channel—SWO trace
For some cores and devices, the C-SPY simulator
Depending on your target system, different types of trace data can be generated.
ETM trace
ETM (Embedded Trace Macrocell) real-time trace is a continuously collected sequence of every executed instruction for a selected portion of the execution. It is only possible to collect as much data as the trace buffer can hold. The trace buffer can be located either in the debug probe or on-chip (ETB or ETR). The trace buffer collects trace data in real time, but the data is not displayed in the C-SPY windows until after the execution has stopped.
PTM trace
PTM (Program Trace Macrocell) is an alternative implementation of the trace logic used in some Arm Cortex cores. The functionality is the same as ETM trace.
Throughout this document, the term ETM also applies to PTM unless otherwise stated.
ETB trace
ETB (Embedded Trace Buffer) trace is an on-chip trace buffer. For ETB trace, the trace buffer has a designated memory area with a predefined size.
ETR trace
ETR (Embedded Trace Router) trace is a trace variant that uses an on-chip trace buffer. For ETR trace, the trace buffer shares the RAM memory with your application code and is configured in the project options.
MTB trace
MTB trace (Micro Trace Buffer) is a simplified trace variant that uses an on-chip trace buffer. For MTB trace, the trace buffer shares the RAM memory with your application code.
MTB trace gives access to instruction trace on some devices based on the Cortex-M0+ and M23 cores.
SWO trace
SWO trace is a sequence of events of various kinds, generated by the on-chip debug hardware. The events are transmitted in real time from the target system over the SWO communication channel. This means that the C-SPY windows are continuously updated while the target system is executing. The most important events are:
PC sampling
The hardware can sample and transmit the value of the program counter at regular intervals. This is not a continuous sequence of executed instructions (like ETM trace), but a sparse regular sampling of the
PC. A modern CPU typically executes millions of instructions per second, while the PC sampling rate is usually counted in thousands per second.Interrupt logs
The hardware can generate and transmit data related to the execution of interrupts, generating events when entering and leaving an interrupt handler routine.
Data logs
Using Data Log breakpoints, the hardware can be configured to generate and transmit events whenever a certain variable, or simply an address range, is accessed by the CPU.
SWOチャンネルの処理量には制限があります。よって、PCサンプリング、割り込み、指定した変数へのアクセスの頻度のいずれかが高い場合、通常は上記のすべての機能を同時に使用することはできません。
トレースプローブでSWO通信チャンネルを使用する場合、データはトレースバッファで収集され、実行が停止した後に表示されます。
Trace features in C-SPY
In C-SPY, you can use the trace-related windows—Trace, Function Trace, Timeline, and Find in Trace. Depending on your C-SPY driver, you can set various types of trace breakpoints and triggers to control the collection of trace data.
If you use the C-SPY I-jet driver, the C-SPY J-Link/J-Trace driver, the C-SPY ST-LINK driver, or the C-SPY TI XDS driver, you have access to windows such as the Interrupt Log, Interrupt Log Summary, Data Log, and Data Log Summary windows.
Tip
When you are debugging, two buttons labeled ETM and SWO, respectively, are visible on the IDE main window toolbar. If either of these buttons are green, it means that the corresponding trace hardware is generating trace data. For detailed tooltip information about which C-SPY features have requested trace data generation, simply point at the button with the mouse pointer. This is useful, for example, if your SWO communication channel often overflows because too many of the C-SPY features are currently using trace data. Clicking on the buttons opens the corresponding setup dialog boxes.
In addition, several other features in C-SPY also use trace data, features such as the Profiler, Code coverage, and Instruction profiling.
Requirements for using trace
The C-SPY simulator supports trace-related functionality for some cores and devices. If supported, there are no further specific requirements.
Note
The specific set of debug components you are using (hardware, a debug probe, and a C-SPY driver) determine which trace features in C-SPY that are supported.
Requirements for using MTB (Micro Trace Buffer) trace
To use MTB trace, you need an M0+ or M23 device with MTB, and one of these alternatives:
An I-jet in-circuit debugging probe
The C-SPY CMSIS-DAP driver and a device that supports CMSIS-DAP
A J-Link debug probe
Requirements for using SWO trace
To use SWO trace you need an I-jet or I-jet Trace in-circuit debugging probe, a J-Link, J-Trace, an ST-LINK, or a TI XDS debug probe that supports the SWO communication channel and a device that supports the SWD/SWO interface.
Requirements for using the trace triggers and trace filters
The trace triggering and trace filtering features are available for ETM, ETB, ETR, and PTM trace, but not for SWO or MTB trace.
Different processors, cores, and debug probes might limit the number of available trace triggers and filters.