I am trying to figure out semihostong on ARM (STM32042). I can see printf
output if I run openocd
directly from a command line and connect to it from gdb
over TCP. But if I launch openocd
from inside gdb
, the output goes to some big /dev/null in the sky.
If I launch openocd
myself with
$ openocd -f interface/stlink-v2-1.cfg -f target/stm32f0x.cfg
and connect to it from gdb
like so
(gdb) target remote localhost:3333
I see printf
output in the opeocd
terminal. But if I launch openocd
from within gdb
as this link suggests,
(gdb) target remote | openocd -f interface/stlink-v2-1.cfg -f target/stm32f0x.cfg -c "gdb_port pipe"
I see all the openocd
debug messages (e.g., xPSR: 0xc1000000 pc: 0x08001648 msp: 0x20001800, semihosting
), but not my printf
s.
It turned out slightly more complicated than I wanted. Apparently, it is impossible to launch GDB and OpenOCD in a pipe; they need bidirectional communication over a socket. Because it takes two separate command invocations, and because the configuration for GDB is more than a one-liner, I pulled this into a little repository of its own:
https://github.com/arikrupnik/semihosting-ut
The repo has code that routes stdout to the console, but it does more than that. I've been using it extensively for unit tests on the ARM target for http://www.dish.tc, and have found it very useful. I'm happy to answer questions about it.