[lldb-dev] How to handle "O XX..." reply packets from gdb servers like openocd

Pedro Alves via lldb-dev lldb-dev at lists.llvm.org
Thu Jan 4 09:14:14 PST 2018


On 01/03/2018 07:11 PM, Greg Clayton via lldb-dev wrote:
> 
>> On Jan 1, 2018, at 6:30 PM, Owen Shaw via lldb-dev <lldb-dev at lists.llvm.org> wrote:
>>
>> I dug into this a bit more, and these output reply packets seem to be
>> handled already, but only if the program is running.
> 
>> Since the relevant openocd commands are often issued when the program
>> paused, the reply packets aren't processed as expected.
>>
>> The spec does say that reply packets can happen "any time while the
>> program is running", so perhaps openocd is abusing the protocol, but
>> gdb handles the packets just fine when stopped.
> 
> Yes, LLDB is assuming that an "O" packet will only come during a continue command. "O" is for stdout output and it seems the rCmd assuming it will work. Why not just send back the text in response to the rCmd? Is some common code path being hit where it might send this text while running and also in response to the rCmd? I am confused by "O" packets are needed in response to the rCmd.

qRcmd was invented well before my time, but qRcmd provides support
for running random interpreter commands on the server, with the
resulting output being potentially long, unbounded.  Thus sending the
text back in response to qRcmd would require an unbounded packet buffer
and would potentially hit the max packet size.  So you'd need some
way to send partial output in chunks.  Which ends up being exactly what
you get by reusing "O".

> If the rCmd can't be fixed to just return the text without using "O" packets, 

The documentation of the qRcmd packet explicitly specifies that output
should be sent via "O" packets:

 https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html#index-qRcmd-packet

Sounds like OpenOCD is working as intended.

Pedro Alves


More information about the lldb-dev mailing list