[Lldb-commits] [PATCH] D108888: Improve error messaging on process connect errors

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Aug 29 01:41:24 PDT 2021


jasonmolenda created this revision.
jasonmolenda added a reviewer: clayborg.
jasonmolenda added a project: LLDB.
Herald added a subscriber: JDevlieghere.
jasonmolenda requested review of this revision.

process connect (aka `gdb-remote`) isn't the clearest in its error messaging.  We have everything we need to distinguish between three common failure modes:  Nothing is listening to the port (or we could not reach the port), the remote side did not respond to the initial handshake packet quickly enough, or the remote connection accepts the connection and then drops it immediately (e.g. a debugserver might reject the connection because it is only accepting connections from certain hosts).

With this patch, we get

  (lldb) gdb-remote 7000
  error: Failed to connect port
  
  (lldb) gdb-remote 4000
  error: failed to get reply to handshake packet within timeout of 6.0 seconds
  
  (lldb) gdb-remote work-imacpro:4000
  error: Connection shut down by remote side while waiting for reply to initial handshake packet

and I think it's a little easier to understand the nature of the problem.  Just fixing a little thing that's bugged me for a while.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108888

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -82,6 +82,8 @@
 
   // Start the read thread after we send the handshake ack since if we fail to
   // send the handshake ack, there is no reason to continue...
+  std::chrono::steady_clock::time_point start_of_handshake =
+      std::chrono::steady_clock::now();
   if (SendAck()) {
     // Wait for any responses that might have been queued up in the remote
     // GDB server and flush them all
@@ -97,8 +99,24 @@
     if (QueryNoAckModeSupported()) {
       return true;
     } else {
-      if (error_ptr)
-        error_ptr->SetErrorString("failed to get reply to handshake packet");
+      std::chrono::steady_clock::time_point end_of_handshake =
+          std::chrono::steady_clock::now();
+      auto handshake_timeout =
+          std::chrono::duration<double>(end_of_handshake - start_of_handshake)
+              .count();
+      if (error_ptr) {
+        if (packet_result == PacketResult::ErrorDisconnected)
+          error_ptr->SetErrorString("Connection shut down by remote side "
+                                    "while waiting for reply to initial "
+                                    "handshake packet");
+        else if (packet_result == PacketResult::ErrorReplyTimeout)
+          error_ptr->SetErrorStringWithFormat(
+              "failed to get reply to handshake packet within timeout of "
+              "%.1f seconds",
+              handshake_timeout);
+        else
+          error_ptr->SetErrorString("failed to get reply to handshake packet");
+      }
     }
   } else {
     if (error_ptr)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108888.369311.patch
Type: text/x-patch
Size: 1835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210829/809b0a00/attachment.bin>


More information about the lldb-commits mailing list