[Lldb-commits] [lldb] r295947 - Ensure lldb-server waits for child debug servers to start up when passing them a port number to listen on.

Howard Hellyer via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 23 00:49:49 PST 2017


Author: hhellyer
Date: Thu Feb 23 02:49:49 2017
New Revision: 295947

URL: http://llvm.org/viewvc/llvm-project?rev=295947&view=rev
Log:
Ensure lldb-server waits for child debug servers to start up when passing them a port number to listen on.

Summary:
When lldb-server is started with the -P <port> or -m/-M <min/max port> options to specify which ports are available for remote connections the child debug server is told what port it should listen on. In those cases lldb-server needs to wait for the child to report it’s port number as otherwise it can tell the lldb client that the child is up and listening before it is actually listening on that port. lldb-server already waits in the cases where a port wasn’t specified by waiting until the child reports the port it is using. It was skipping this synchronisation step when passed a port numbers as it knew what the port would be however it does need to ensure the child process has had time to open that port and waiting until the child reports the port number makes sure this has happened.

This patch just removes the one case where a child was spawned and lldb-server did not wait for it to report it’s port number before telling the client lldb process the child is ready to connect to.

This issue was discussed on lldb-dev in a thread here:
http://lists.llvm.org/pipermail/lldb-dev/2017-February/012002.html

Reviewers: clayborg

Reviewed By: clayborg

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D30255

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=295947&r1=295946&r2=295947&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Thu Feb 23 02:49:49 2017
@@ -1083,8 +1083,7 @@ Error GDBRemoteCommunication::StartDebug
     // port is null when debug server should listen on domain socket -
     // we're not interested in port value but rather waiting for debug server
     // to become available.
-    if (pass_comm_fd == -1 &&
-        ((port != nullptr && *port == 0) || port == nullptr)) {
+    if (pass_comm_fd == -1) {
       if (url) {
 // Create a temporary file to get the stdout/stderr and redirect the
 // output of the command into this file. We will later read this file
@@ -1256,11 +1255,21 @@ Error GDBRemoteCommunication::StartDebug
             port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
         if (error.Success() && (port != nullptr)) {
           assert(num_bytes > 0 && port_cstr[num_bytes - 1] == '\0');
-          *port = StringConvert::ToUInt32(port_cstr, 0);
-          if (log)
-            log->Printf("GDBRemoteCommunication::%s() "
-                        "debugserver listens %u port",
-                        __FUNCTION__, *port);
+          uint16_t child_port = StringConvert::ToUInt32(port_cstr, 0);
+          if (*port == 0 || *port == child_port) {
+            *port = child_port;
+            if (log)
+              log->Printf("GDBRemoteCommunication::%s() "
+                          "debugserver listens %u port",
+                          __FUNCTION__, *port);
+          } else {
+            if (log)
+              log->Printf("GDBRemoteCommunication::%s() "
+                          "debugserver listening on port "
+                          "%d but requested port was %d",
+                          __FUNCTION__, (uint32_t)child_port,
+                          (uint32_t)(*port));
+          }
         } else {
           if (log)
             log->Printf("GDBRemoteCommunication::%s() "




More information about the lldb-commits mailing list