[lldb-dev] LLDB use of G/g packets

Greg Clayton gclayton at apple.com
Mon Feb 11 10:28:48 PST 2013


On Feb 10, 2013, at 5:19 AM, Benjamin Kemper <kemperbenny at gmail.com> wrote:

> Hi,
> 
> I'm implementing a debugger backend that implements the gdb remote protocol and adding extensions to support LLDB also.
> 
> I've added support for the qRegisterInfo packet and I've noticed in the logs that LLDB uses the p/P packets instead of the G/g packets.

We normally don't need all registers, we just need a few. And all GDB servers we currently communicate with send most of these needed registers in the stop reply packets as "expedited" registers. So if you can afford to, try to expedite all registers in the stop reply packets. Why? Because the p/P and g/G packets are lame in that you have to send the "Hg<tid>" to select the current thread prior to sending them (unless you also support the LLDB thread suffix (respond with "OK" to "QThreadSuffixSupported"). So each register read/write turns into two packets that have to be sent.


> Is there a special reason why it uses multiple packets instead of one?

The main reason is when we make function calls, we read the current registers, and replace the registers required for function arguments one at a time. The GDB log is much more readable when we see individual registers being modified and read instead of seeing multiple writes of all registers when only one registers is changing. We subscribe to the mode where if you write a register and then read it back again, you will see what is in the register, not just some temporary copy of the registers that will eventually be written back down to the remote target when you resume. GDB does this caching, but you often won't see that your register write failed until you run and see a weird value come back after you program executes and stops. 

So the main reason is it makes the logs much clearer when debugging issues if we see the individual reads/writes.

LLDB could be made to be smarter so that if "p"/"P" is not supported, then it will fall back to using "g"/"G". The GDBRemoteRegisterContext.cpp file currently has a bool member variable called "m_read_all_at_once" which could be set to true if the the "p"/"P" packets aren't support.



> 
> Maybe I didn't implement enough "information" packets and LLDB doesn't know how to read g/G packets? If so, what packets are missing?

No, the info you have should be enough. We won't use the g/G packets unless we are going to run an expression and need to backup all registers and then restore them. Expedite as many register values as you can in your stop reply packets and in your "qThreadStopInfo" replies (if you haven't implemented this and are going to be debugging more than one thread, I highly suggest you implement the "qThreadStopInfo" packet soon).






More information about the lldb-dev mailing list