Re: Can GDB interact with serial ports on remote targets?

Paul_Koning
2015-02-20T16:21:34Z

> On Feb 20, 2015, at 10:45 AM, Brendan J <bhenryj0117@googlemail.com> wrote:
>
> Hi Luis, thanks for your response.
>
> Hmm, yes I now realise I was remotely aware of semihosting.
> Unfortunately my project is running on bare-metal (no OS, no u-boot or
> UEFI or anything) so I don't think semihosting is quite appropriate.
> As I understand it, typical use of semihosting goes like this:
>
> You're debugging an application on a remote target, and that target
> has an OS, and that OS has support for semihosting. The application
> issues a "read" system call, and the OS handles it by issuing a
> semihosting debug call (as opposed to actually reading the file or
> UART or whatever).
>
> That is to say, the system under debug needs to be modified to support
> semihosting, which I'd really like to avoid doing in my case. Please
> correct me if my understanding of semihosting is wrong.
>
> Otherwise, are there any other options?
>
> Thanks again for your help,
> Brendan

Brendan, what you’re trying to do is similar to what we needed on a dual CPU embedded system (one NetBSD, one custom RTOS). For our case, it was sufficient to be able to see output while running a debug session. We did this by making a very small tweak to the GDB remote protocol support: if it sees something that isn’t remote protocol, just display it on stdout. That allowed the unmodified OS UART code to send stuff, and have it display correctly. The only trouble is that sometimes output with # in it would get messed up, but that isn’t common in our case.

The other alternative, which is cleaner, is to tweak the OS UART driver slightly so it escapes OS output according to the GDB remote protocol. That’s pretty simple too. I’m not sure why we didn’t go that route; perhaps we missed it in the protocol spec. Or perhaps because the approach we used instead works across boot driver and OS startup code and running OS drivers, since none of them need to change.

If you do need both I and O, it looks like the semihosting stuff is what you need, and in the bare metal case the UART driver is probably the spot that needs to change for this. Those changes are probably pretty small, order of 100 lines perhaps. Smaller than the GDB remote protocol stub, most likely.

paul