jgorbe created this revision.
jgorbe added reviewers: clayborg, labath.

127.0.0.1 doesn't work in machines configured with IPv6-only networking.


https://reviews.llvm.org/D62980

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


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -1078,7 +1078,7 @@
       } else {
         // No host and port given, so lets listen on our end and make the
         // debugserver connect to us..
-        error = StartListenThread("127.0.0.1", 0);
+        error = StartListenThread("localhost", 0);
         if (error.Fail()) {
           if (log)
             log->Printf("GDBRemoteCommunication::%s() unable to start listen "
@@ -1093,7 +1093,7 @@
         uint16_t port_ = 
connection->GetListeningPort(std::chrono::seconds(10));
         if (port_ > 0) {
           char port_cstr[32];
-          snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", port_);
+          snprintf(port_cstr, sizeof(port_cstr), "localhost:%i", port_);
           // Send the host and port down that debugserver and specify an option
           // so that it connects back to the port we are listening to in this
           // process
@@ -1102,7 +1102,7 @@
           if (port)
             *port = port_;
         } else {
-          error.SetErrorString("failed to bind to port 0 on 127.0.0.1");
+          error.SetErrorString("failed to bind to port 0 on localhost");
           if (log)
             log->Printf("GDBRemoteCommunication::%s() failed: %s", 
__FUNCTION__,
                         error.AsCString());
@@ -1269,7 +1269,7 @@
   const int backlog = 5;
   TCPSocket listen_socket(true, child_processes_inherit);
   if (llvm::Error error =
-          listen_socket.Listen("127.0.0.1:0", backlog).ToError())
+          listen_socket.Listen("localhost:0", backlog).ToError())
     return error;
 
   Socket *accept_socket;
@@ -1278,7 +1278,7 @@
 
   llvm::SmallString<32> remote_addr;
   llvm::raw_svector_ostream(remote_addr)
-      << "connect://127.0.0.1:" << listen_socket.GetLocalPortNumber();
+      << "connect://localhost:" << listen_socket.GetLocalPortNumber();
 
   std::unique_ptr<ConnectionFileDescriptor> conn_up(
       new ConnectionFileDescriptor());


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -1078,7 +1078,7 @@
       } else {
         // No host and port given, so lets listen on our end and make the
         // debugserver connect to us..
-        error = StartListenThread("127.0.0.1", 0);
+        error = StartListenThread("localhost", 0);
         if (error.Fail()) {
           if (log)
             log->Printf("GDBRemoteCommunication::%s() unable to start listen "
@@ -1093,7 +1093,7 @@
         uint16_t port_ = connection->GetListeningPort(std::chrono::seconds(10));
         if (port_ > 0) {
           char port_cstr[32];
-          snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", port_);
+          snprintf(port_cstr, sizeof(port_cstr), "localhost:%i", port_);
           // Send the host and port down that debugserver and specify an option
           // so that it connects back to the port we are listening to in this
           // process
@@ -1102,7 +1102,7 @@
           if (port)
             *port = port_;
         } else {
-          error.SetErrorString("failed to bind to port 0 on 127.0.0.1");
+          error.SetErrorString("failed to bind to port 0 on localhost");
           if (log)
             log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
                         error.AsCString());
@@ -1269,7 +1269,7 @@
   const int backlog = 5;
   TCPSocket listen_socket(true, child_processes_inherit);
   if (llvm::Error error =
-          listen_socket.Listen("127.0.0.1:0", backlog).ToError())
+          listen_socket.Listen("localhost:0", backlog).ToError())
     return error;
 
   Socket *accept_socket;
@@ -1278,7 +1278,7 @@
 
   llvm::SmallString<32> remote_addr;
   llvm::raw_svector_ostream(remote_addr)
-      << "connect://127.0.0.1:" << listen_socket.GetLocalPortNumber();
+      << "connect://localhost:" << listen_socket.GetLocalPortNumber();
 
   std::unique_ptr<ConnectionFileDescriptor> conn_up(
       new ConnectionFileDescriptor());
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] D... Jorge Gorbe Moya via Phabricator via lldb-commits

Reply via email to