In my previous blog post on real-time variable watch using Serial Wire Viewer (SWV/SWO) tracing, I outlined how Cortex-M devices can feed advanced debuggers with real-time updates on variable vales as the target system executes at full speed. This is implemented using a hardware supported real-time data access trace capability, not using polling, and thus all variable reads or writes are truly detected (provided buffer overflows don’t happen due to bandwidth problems).
In this blog article, I will extend upon this and explain how this capability can also be used to provide a true memory/variable access history trace log; showing you exactly which reads or writes have been made to a memory location or variable. This is incredibly useful, if for example a variable is inadvertently getting an illegal value and you cannot understand where this value is written to the variable, or why.
By enabling real-time variable watch monitoring on certain variables using the SWV event- and data- trace configuration dialog box according to my previous blog post, you are all set to benefit also from a complete variable read/write access history trace log.
Once you have enabled SWV trace recording and started execution, the top of the SWV Trace Data view in the Atollic TrueSTUDIO debugger shows the variable values updated in real-time. Select the desired variable being monitored in the top (Watch) part, and the bottom part (History) of the view will show all reads and/or writes that has been done to this variable or memory location. The memory access history trace log is even updated in real-time as the target system executes at full speed!
The power of this feature is not to be underestimated. A very common use-case is that a variable sometimes get an illegal value for unclear reasons. Perhaps there is a stack overflow corrupting the memory location of the variable, or some pointer error overwrites the variable with data, or there is a calculation bug in an assignment.
By studying the variable access history trace log, you can easily see exactly which write operation did write that faulty value. And not only that, provided that the SWV tracing is configured to emit also program counter (PC) values, the debugger also know what machine code instruction (and thus, which C line) made that faulty variable update.
In Atollic TrueSTUDIO, you can quite simply double-click on any variable access in the history trace log of the SWV Data Trace view, and the debugger immediately moves you to the responsible C line in the source code editor!
By using this and other Cortex-M Serial Wire Viewer debugger capabilities, embedded developers get an incredibly powerful tool-set at their disposal. This capability is included in popular Cortex-M devices, for example STMicroelectronics STM32, Freescale Kinetis, SiLabs/EneryMicro EFM32, etc.
On the debugger side, the Atollic TrueSTUDIO C/C++ IDE for ARM support this, in Eclipse using the gcc/gdb GNU tools, with both the Segger J-Link and ST-LINK debugger probes.
For more information on Serial Wire Viewer event- and data- tracing on Cortex-M devices, read this whitepaper: