Where does STDOUT go with GDB, OopenOCD and semihosting?
Asked Answered
C

1

6

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 printfs.

Cotangent answered 27/9, 2019 at 0:2 Comment(2)
Did you figure this out?Pouter
Yes I did. Thank you for reminding me. See below.Cotangent
C
1

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.

Cotangent answered 16/5, 2020 at 21:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.