diff options
7 files changed, 26 insertions, 18 deletions
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 3832265638d..aa1b6eee8aa 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -423,7 +423,7 @@ PlatformRemoteGDBServer::DebugProcess (lldb_private::ProcessLaunchInfo &launch_i // When remote debugging to iOS, we use a USB mux that always talks // to localhost, so we will need the remote debugserver to accept connections // only from localhost, no matter what our current hostname is - port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "localhost"); + port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "127.0.0.1"); } else { @@ -511,7 +511,7 @@ PlatformRemoteGDBServer::Attach (lldb_private::ProcessAttachInfo &attach_info, // When remote debugging to iOS, we use a USB mux that always talks // to localhost, so we will need the remote debugserver to accept connections // only from localhost, no matter what our current hostname is - port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "localhost"); + port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "127.0.0.1"); } else { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 72600d83593..e3bc9f145ea 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -722,19 +722,27 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *hostname, { // No host and port given, so lets listen on our end and make the debugserver // connect to us.. - error = StartListenThread ("localhost", 0); + error = StartListenThread ("127.0.0.1", 0); if (error.Fail()) return error; ConnectionFileDescriptor *connection = (ConnectionFileDescriptor *)GetConnection (); - out_port = connection->GetBoundPort(3); - assert (out_port != 0); - char port_cstr[32]; - snprintf(port_cstr, sizeof(port_cstr), "localhost:%i", out_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 - debugserver_args.AppendArgument("--reverse-connect"); - debugserver_args.AppendArgument(port_cstr); + // Wait for 10 seconds to resolve the bound port + out_port = connection->GetBoundPort(10); + if (out_port > 0) + { + char port_cstr[32]; + snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", out_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 + debugserver_args.AppendArgument("--reverse-connect"); + debugserver_args.AppendArgument(port_cstr); + } + else + { + error.SetErrorString ("failed to bind to port 0 on 127.0.0.1"); + return error; + } } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h index d8361113ddc..b11d3856320 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h @@ -271,7 +271,7 @@ protected: lldb_private::Error - StartListenThread (const char *hostname = "localhost", + StartListenThread (const char *hostname = "127.0.0.1", uint16_t port = 0); bool diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp index df95542d2c0..fbb72baf13e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp @@ -452,7 +452,7 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet // to actually have a hostname as far as the remote lldb that is connecting // to this lldb-platform is concerned response.PutCString ("hostname:"); - response.PutCStringAsRawHex8("localhost"); + response.PutCStringAsRawHex8("127.0.0.1"); response.PutChar(';'); #else // #if defined(__arm__) if (Host::GetHostname (s)) @@ -945,7 +945,7 @@ GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote // Spawn a debugserver and try to get the port it listens to. ProcessLaunchInfo debugserver_launch_info; if (hostname.empty()) - hostname = "localhost"; + hostname = "127.0.0.1"; Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); if (log) log->Printf("Launching debugserver with: %s:%u...\n", hostname.c_str(), port); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 1172222d62a..800bd257061 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -2604,7 +2604,7 @@ ProcessGDBRemote::LaunchAndConnectToDebugserver (const ProcessInfo &process_info #if defined (__APPLE__) && defined (__arm__) // On iOS, still do a local connection using a random port - const char *hostname = "localhost"; + const char *hostname = "127.0.0.1"; uint16_t port = get_random_port (); #else // Set hostname being NULL to do the reverse connect where debugserver diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index d6010fb22a5..cefc2f0ece0 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -744,7 +744,7 @@ const char * Platform::GetHostname () { if (IsHost()) - return "localhost"; + return "127.0.0.1"; if (m_name.empty()) return NULL; diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp index 4fb5077b2ba..9fdcceb7449 100644 --- a/lldb/tools/debugserver/source/debugserver.cpp +++ b/lldb/tools/debugserver/source/debugserver.cpp @@ -745,7 +745,7 @@ ConnectRemote (RNBRemote *remote, else { if (port != 0) - RNBLogSTDOUT ("Listening to port %i for a connection from %s...\n", port, host ? host : "localhost"); + RNBLogSTDOUT ("Listening to port %i for a connection from %s...\n", port, host ? host : "127.0.0.1"); if (unix_socket_name && unix_socket_name[0]) { if (remote->Comm().Listen(host, port, PortWasBoundCallbackUnixSocket, unix_socket_name) != rnb_success) @@ -1266,7 +1266,7 @@ main (int argc, char *argv[]) int items_scanned = ::sscanf (argv[0], "%i", &port); if (items_scanned == 1) { - host = "localhost"; + host = "127.0.0.1"; DNBLogDebug("host = '%s' port = %i", host.c_str(), port); } else if (argv[0][0] == '/') |