One of the great features in CodeWarrior for MCU10.x is the ability to read memory/variables while running (see “Live View for Variables and Memory“). This technology of ‘live view’ is based on the CodeWarrior debugger engine. How can I do something like this with stock GDB and Eclipse? What I need is a periodic update of variables/expressions/memory while the program on the board is running, without the need to stop the board with the debugger first:
The problem with normal GDB is: it cannot access the target while the application is running. Actually, this would be possible if the GDB server would support the asynchronous or non-stop mode. However, the GDB servers I’m using (P&E, Segger and OpenOCD) do not support this today (e.g. in Kinetis Design Studio v3.0.0) :-(.
But there is way to do something very similar. Still intrusive as it needs to stop the target, but at least I do not have to do this manually.
Approach for Periodic Update
The approach I’m presenting here is the following:
- I have a breakpoint set in the code which will be triggered on a periodic base (e.g. in a task or in a timer interrupt). That breakpoint will halt the target.
- The GDB debugger will write the variable/expression/memory value to the console.
- The target gets automatically resumed by the debugger and continues execution
- After a time period, it will run again into the breakpoint and continue with step 2 above.
I set a breakpoint in a periodic task, interrupt service routine, etc. Whenever the application hits that breakpoint, the gdb debugger will take control and I can dump my variable(s). For example I set such a breakpoint in a task (or timer interrupt) which will cause a hit every second:
Breakpoint with Custom Action
From the breakpoint view, I access the breakpoint properties:
Here I can create my breakpoint actions with the ‘New’ button:
In the ‘New’ dialog, I can create a ‘Resume Action’ with a delay of zero seconds:
Now I attach this resume action to my breakpoint:
Now I have a breakpoint which will automatically resume: it will stop, then automatically continue execution:
Press OK to close the dialog.
The breakpoint has now an added ‘+’ to indicate there is an action behind it:
GDB Automatic Display
Switch to the gdb (arm-none-eabi) console (use the small triangle menu) and pin that console, so it does not switch to another console:
💡 Really make sure you select the gdb (arm-none-eabi-gdb) console to type in the commands.
GDB has a cool feature called ‘automatic display‘: that way I can print the value of an expression (to see how it changes) when GDB stops. With
display <variable name>
it adds that variable to the list of auto-displays:
💡 See https://sourceware.org/gdb/onlinedocs/gdb/Output-Formats.html#Output-Formats how to use different formats. E.g. display/x counter displays the variable in hexadecimal format.
With this setup, I can run my target: the breakpoint will be hit, the debugger stops and it will print my variable(s):
I do not have to stop the debugger for this: all will be done as a side effect of the breakpoint :-).
I can use the display command as well to show expressions, like showing the task ready list of FreeRTOS:
I can as well show memory locations, e.g. to show the current SysTick counter value with
Having the ability to watch and variables or memory locations while the target is running is very useful. The approach presented here is stopping the target in the background, so it *is* intrusive. But this approach works very well for low frequencies. It does not need any special software library or hardware, it works with plain GDB and Eclipse. Other approaches I’m using are using FreeMaster or tracing data with FreeRTOS+Trace.
Happy Updating 🙂
- CodeWarrior Live View: https://mcuoneclipse.com/2013/01/27/live-view-for-variables-and-memory/
- Differences between CodeWarrior and Kinetis Design Studio: https://mcuoneclipse.com/2014/09/28/comparing-codewarrior-with-kinetis-design-studio/
- GDB non-stop mode: https://sourceware.org/gdb/onlinedocs/gdb/Non_002dStop-Mode.html
- Automatic Display with GDB: https://sourceware.org/gdb/onlinedocs/gdb/Auto-Display.html
- Tutorial using FreeMaster: https://mcuoneclipse.com/2013/08/24/tutorial-freemaster-visualization-and-run-time-debugging/