A traditional debugger allows you to inspect the system state once the system is halted, i.e., after an error has been detected, but doesn’t reveal the events leading to the error. To see this information, you need tracing.
Tracing means that the software’s behavior is recorded during run-time, allowing for later analysis of the trace. A hardware-generated trace (in the processor) gives you all details regarding the control-flow and doesn’t impact the execution of the traced system. However, it requires a special trace debugger unit and trace-enabled hardware in general. Software-generated tracing works on any hardware platform, and tracing can be active continuously during long testing sessions. Software-based tracing can even be deployed in production systems in many cases.
The software trace will use CPU cycles and RAM of the traced system, though, but this is often a reasonable tradeoff given the value of the resulting traces. Unless you have very strict timing requirement, down to the microsecond level, software tracing is simple, straightforward, and a perfectly viable solution. Let’s explore some of the myths surrounding this approach.
1. Tracing requires an advanced trace debugger.
This isn’t necessarily true; there are different kinds of tracing. Tools like the Linux Trace Tool (LTTng) and Percepio’s Tracealyzer rely on software-based tracing for systems using an RTOS, allowing for the capture of all relevant events in the RTOS kernel and any extra events you add in your application code. This kind of tracing doesn’t require any special hardware and can be used on essentially any system. The data is generated by software and stored in a local RAM buffer, or streamed to a PC using any communication port with sufficient performance.
2. Tracing is complicated to set up.
Software-based tracing is generally quite easy to set up—it’s typically done over a cup of coffee. You need to include the recorder library in your build, configure it to match your hardware, and enable the trace option in your RTOS. Then you’re ready to start tracing.