I got it to work using Orbuculum as a helper program.
To get the output visible in same terminal as GDB, and to easily start everything at the same time, I start GDB like this:
arm-none-eabi-gdb \
-iex 'target extended | openocd -f interface/stlink.cfg -f target/stm32f3x.cfg -c "gdb_port pipe"' \
-iex 'mon halt' \
-iex 'mon tpiu config internal swo.log uart false 2000000' \
-iex 'shell bash -m -c "orbuculum -f swo.log &"' \
-iex 'shell bash -m -c "orbcat -c 0,%c &"' \
firmware.elf
The -iex
parameter tells gdb to immediately execute a command when starting. Here is what the commands do:
target extended ...
starts openocd and uses a pipe to communicate between it and gdb.
mon halt
tells OpenOCD to stop any executing program.
mon tpiu ...
configures OpenOCD to receive the trace output and to write it to swo.log
file.
shell bash -m "orbuculum ...
starts the Orbuculum server and tells it to read from swo.log
. The &
makes it run on the background, while bash -m
runs it in separate process group so that ctrl-c
within GDB doesn't accidentally stop it.
shell bash -m "orbcat ...
starts Orbuculum tool to read any output from ITM port 0 and write that as characters to the terminal.
And here is what it looks like:
GNU gdb (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.50.20181213-git
....
Reading symbols from firmware.elf...
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: firmware.elf
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800011c msp: 0x10001000
Boot
ADC ch 1 val -100
ADC ch 3 val 0
ADC ch 4 val 3
ADC ch 1 val 4091
.....
There are also other useful tools in the Orbuculum suite. For example orbtop -e firmware.elf
shows the places where execution time is being spent.