[lldb-dev] Failure connecting to lldb-server running in local virtual machine.

Howard Hellyer via lldb-dev lldb-dev at lists.llvm.org
Tue Feb 21 05:52:06 PST 2017


Greg Clayton <gclayton at apple.com> wrote on 16/02/2017 17:17:41:

> We seem to have a race condition here. Any help figuring out what 
> that might be would be great.

I think I've now identified the problem.

Normally in lldb-server when the child lldb-server process is launched 
inside GDBRemoteCommunication::StartDebugserverProcess the parent 
lldb-server waits for it to start up and write back the port is has 
selected to listen on a pipe.
When lldb-server specifies a port for the child to listen on (when we 
start lldb-server with -P <port> or -m <minport> and -M <maxport>) then it 
doesn't bother setting up that pipe as it knows what the port will be. 
However not listening means the parent can reply to the lldb client with 
the port number before the debugserver process is actually up and and 
listening on that port.

Simply making sure the pipe is always setup and used to read the port 
number from (even when lldb-server knows what it will be) ensures the 
child process is ready and allows me to connect reliably with an 
unmodified client lldb.

The one second delay in the client was fixing things as inside 
PlatformRemoteGDBServer::DebugProcess there is a retry to ConnectRemote 
and the delay gave time for the child process to begin before the retry. 
This also explains why more people weren't seeing this problem as it only 
applies if you use the -P or -m/-M options. I think I only found those by 
searching the code, they don't appear in the help for lldb-server when you 
run it and I didn't manage to find any docs.

Unless anyone points out a major flaw in the logic above I'll tidy up my 
fix and put a patch up on https://reviews.llvm.org/ in the next few days. 
The code for listening on a pipe from the child process is slightly 
different when __APPLE__ is defined so I need to verify the change on Mac 
and Linux. I'll probably just always read back the port and if it comes 
back as an unexpected value that may need to be a new error case.

Would you mind if I also raised a patch to update the documentation to 
include the -P and -m/-M options? (Both in the help when you run 
lldb-server and on www/remote.html.) I originally came to this problem 
because another team couldn't connect to a remote system with only certain 
ports open and found them the options they needed by reading the source 
and I think doing things like connecting to processes in a VM or docker 
container where these options are needed are becoming more common.
Thanks,

Howard.

Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20170221/00924520/attachment.html>


More information about the lldb-dev mailing list