[Lldb-commits] [lldb] r177790 - Change debugserver to open the socket it listens
Jason Molenda
jmolenda at apple.com
Fri Mar 22 17:44:22 PDT 2013
Author: jmolenda
Date: Fri Mar 22 19:44:22 2013
New Revision: 177790
URL: http://llvm.org/viewvc/llvm-project?rev=177790&view=rev
Log:
Change debugserver to open the socket it listens
to in INADDR_LOOPBACK mode by default ("localhost only")
instead of INADDR_ANY ("accept connections from any system").
Add a new command line argument to debugserver, --open-connection
or -H which will enable the previous behavior. It would be used
if you were doing two-system debugging, with lldb running on one
system and debugserver running on the other. But it is a less
common workflow and should not be the default.
<rdar://problem/12583284>
Modified:
lldb/trunk/tools/debugserver/source/RNBSocket.cpp
lldb/trunk/tools/debugserver/source/RNBSocket.h
lldb/trunk/tools/debugserver/source/debugserver.cpp
Modified: lldb/trunk/tools/debugserver/source/RNBSocket.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBSocket.cpp?rev=177790&r1=177789&r2=177790&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBSocket.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBSocket.cpp Fri Mar 22 19:44:22 2013
@@ -31,7 +31,7 @@
This function blocks while waiting for that connection. */
rnb_err_t
-RNBSocket::Listen (in_port_t port, PortBoundCallback callback, const void *callback_baton)
+RNBSocket::Listen (in_port_t port, PortBoundCallback callback, const void *callback_baton, bool localhost_only)
{
//DNBLogThreadedIf(LOG_RNB_COMM, "%8u RNBSocket::%s called", (uint32_t)m_timer.ElapsedMicroSeconds(true), __FUNCTION__);
// Disconnect without saving errno
@@ -56,7 +56,14 @@ RNBSocket::Listen (in_port_t port, PortB
sa.sin_len = sizeof sa;
sa.sin_family = AF_INET;
sa.sin_port = htons (port);
- sa.sin_addr.s_addr = htonl (INADDR_ANY);
+ if (localhost_only)
+ {
+ sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+ }
+ else
+ {
+ sa.sin_addr.s_addr = htonl (INADDR_ANY);
+ }
int error = ::bind (listen_fd, (struct sockaddr *) &sa, sizeof(sa));
if (error == -1)
Modified: lldb/trunk/tools/debugserver/source/RNBSocket.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBSocket.h?rev=177790&r1=177789&r2=177790&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBSocket.h (original)
+++ lldb/trunk/tools/debugserver/source/RNBSocket.h Fri Mar 22 19:44:22 2013
@@ -43,7 +43,7 @@ public:
Disconnect (false);
}
- rnb_err_t Listen (in_port_t port, PortBoundCallback callback, const void *callback_baton);
+ rnb_err_t Listen (in_port_t port, PortBoundCallback callback, const void *callback_baton, bool localhost_only);
rnb_err_t Connect (const char *host, uint16_t port);
rnb_err_t useFD(int fd);
Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=177790&r1=177789&r2=177790&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/debugserver.cpp (original)
+++ lldb/trunk/tools/debugserver/source/debugserver.cpp Fri Mar 22 19:44:22 2013
@@ -684,13 +684,13 @@ PortWasBoundCallback (const void *baton,
}
static int
-StartListening (RNBRemote *remote, int listen_port, const char *unix_socket_name)
+StartListening (RNBRemote *remote, int listen_port, const char *unix_socket_name, bool localhost_only)
{
if (!remote->Comm().IsConnected())
{
if (listen_port != 0)
RNBLogSTDOUT ("Listening to port %i...\n", listen_port);
- if (remote->Comm().Listen(listen_port, PortWasBoundCallback, unix_socket_name) != rnb_success)
+ if (remote->Comm().Listen(listen_port, PortWasBoundCallback, unix_socket_name, localhost_only) != rnb_success)
{
RNBLogSTDERR ("Failed to get connection from a remote gdb process.\n");
return 0;
@@ -786,6 +786,7 @@ static struct option g_long_options[] =
{ "working-dir", required_argument, NULL, 'W' }, // The working directory that the inferior process should have (only if debugserver launches the process)
{ "platform", required_argument, NULL, 'p' }, // Put this executable into a remote platform mode
{ "unix-socket", required_argument, NULL, 'u' }, // If we need to handshake with our parent process, an option will be passed down that specifies a unix socket name to use
+ { "open-connection", no_argument, NULL, 'H' }, // If debugserver is listening to a TCP port, allow connections from any host (as opposed to just "localhost" connections)
{ NULL, 0, NULL, 0 }
};
@@ -841,6 +842,7 @@ main (int argc, char *argv[])
useconds_t waitfor_interval = 1000; // Time in usecs between process lists polls when waiting for a process by name, default 1 msec.
useconds_t waitfor_duration = 0; // Time in seconds to wait for a process by name, 0 means wait forever.
bool no_stdio = false;
+ bool localhost_only = true;
#if !defined (DNBLOG_ENABLED)
compile_options += "(no-logging) ";
@@ -1080,7 +1082,10 @@ main (int argc, char *argv[])
case 'u':
unix_socket_name.assign (optarg);
break;
-
+
+ case 'H':
+ localhost_only = false;
+ break;
}
}
@@ -1286,7 +1291,7 @@ main (int argc, char *argv[])
#endif
if (listen_port != INT32_MAX)
{
- if (!StartListening (remote, listen_port, unix_socket_name.c_str()))
+ if (!StartListening (remote, listen_port, unix_socket_name.c_str(), localhost_only))
mode = eRNBRunLoopModeExit;
}
else if (str[0] == '/')
@@ -1399,7 +1404,7 @@ main (int argc, char *argv[])
{
if (listen_port != INT32_MAX)
{
- if (!StartListening (remote, listen_port, unix_socket_name.c_str()))
+ if (!StartListening (remote, listen_port, unix_socket_name.c_str(), localhost_only))
mode = eRNBRunLoopModeExit;
}
else if (str[0] == '/')
@@ -1424,7 +1429,7 @@ main (int argc, char *argv[])
{
if (listen_port != INT32_MAX)
{
- if (!StartListening (remote, listen_port, unix_socket_name.c_str()))
+ if (!StartListening (remote, listen_port, unix_socket_name.c_str(), localhost_only))
mode = eRNBRunLoopModeExit;
}
else if (str[0] == '/')
@@ -1451,7 +1456,7 @@ main (int argc, char *argv[])
case eRNBRunLoopModePlatformMode:
if (listen_port != INT32_MAX)
{
- if (!StartListening (remote, listen_port, unix_socket_name.c_str()))
+ if (!StartListening (remote, listen_port, unix_socket_name.c_str(), localhost_only))
mode = eRNBRunLoopModeExit;
}
else if (str[0] == '/')
More information about the lldb-commits
mailing list