Re: Remote protocol question: the documentation says '?' is not required, but maybe it is?

Maciej W. Rozycki
2020-07-21T19:34:35Z

On Tue, 21 Jul 2020, Reuben Thomas wrote:

> > FYI, I do believe `?' is indeed mandatory, as GDB needs to figure out the
> > initial state of the remote target as it has connected to it, and there is
> > no other way.
>
> It seems to be more complicated than that. In principle, '?' isn't needed
> in principle to figure out the initial state: the T packet, or in my
> current case, the S packet tells GDB the signal, and yet GDB still asks for
> it again with '?'. The signal that caused the remote to halt is not going
> to change until the next 'c', so there's no need for GDB to ask for it
> again; and yet it does.

I take you mean a `T' or `S' stop reply, right?

Well, such replies are only expected by GDB in response to specific
packets, which are all listed at the top of Section E.3 "Stop Reply
Packets". If you issue an unsolicited stop reply from your debug stub,
then at best GDB will ignore it and at worst GDB will get confused.

> It looks indeed as if not supporting '?' will mean trouble. Further, around
> line 4580, we find:
>
> /* Ack any packet which the remote side has already sent. */
> remote_serial_write ("+", 1);
>
> so it looks as though the first packet the stub sends is ignored.

Indeed, GDB may have connected to the remote stub, say, over a serial
line, so stale data may have already been buffered by serial hardware or
the OS and anything on the fly is not considered valid data until both
ends have synchronised.

HTH,

Maciej