Enabling ConsoleOutput
in more places
#51
Labels
API-non-breaking
Non-breaking API change
design-required
Getting this right will require some thought
new-api
Add a new feature to the API (possibly non-breaking)
At the moment,
gdbstub
only exposesConsoleOutput
in one place: as part of thehandle_monitor_cmd
interface. That said, this functionality of "print text from the target to the client terminal" isn't some special feature of the monitor command interface, and is also supported as a bog-standard Stop Reply Packet (namely, theO XX...
packet).Moreover, based on a very brief skim through the
gdb
client source code, it seems that the GDB client might be resilient enough to acceptO
packets at any time, not just as a response toqRcmd
and as a stop reply packet! Note that this behavior is not formalized by the spec, but if it works, then it opens the door to some very cool functionality...EDIT: of course, there's also the Host I/O packet interface, which enables writing to the host console via a standard
write(1, buf, len)
interface. Admittedly, this can only be used in the same context as regularO xx
stop reply packets, so aside from the benefit of using less bandwidth (as it uses the binary data transfer protocol vs. the 2-char ascii per byte protocol), it's not that much better.With these bits of info in mind, there are a few ways
gdbstub
could expand exposeConsoleOutput
in more places:1. Exposing
ConsoleOutput
as part of the currentresume()
interfaces.This should be pretty straightforward, and could be implemented similar to the current monitor command
ConsoleOutput
(i.e: using a callback).Note that this will require an API change to add the additional function parameter.
2. Exposing a "global" handle to send
O XX...
packets.At the time of writing, I don't have a concrete idea of how to implement this (especially for
no_std
targets), but I was thinking the API could look something like this:IMPORTANT NOTE: because the underlying GDB protocol doesn't support sending console output packets at totally arbitrary points during execution (e.g: in the middle of writing out some other, longer packet), calling
output!
will require buffering + differing output until such a time when it's reasonable to flush. In other words, the globaloutput!
interface will have to be non blocking. This is in contrast to theqRcmd
or theresume
implementations, which can immediately output the data.Two final comments:
std/alloc
only, as my gut feeling is that it'll be incredibly tricky to get the lifetimes / locking right without the use ofArc
. That said, this is just a gut feeling, and it very well might be the case that once someone takes a crack at an implementation, a more obvious solution will present itself.no_std
implementation is possible, it may need to be feature-gated to avoid ballooning the binary size.The text was updated successfully, but these errors were encountered: