aboutsummaryrefslogtreecommitdiff
path: root/lldb/tools/debugserver/source/debugserver.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2016-08-12 16:46:18 +0000
committerGreg Clayton <gclayton@apple.com>2016-08-12 16:46:18 +0000
commitc6c420fca14d9eac716c2099514bcfcaea94809c (patch)
tree22239e938218c4fa3d60d967aa4fff42936121eb /lldb/tools/debugserver/source/debugserver.cpp
parent623c4c1572ab07864ad9efd37e672eca60707675 (diff)
downloadllvm-c6c420fca14d9eac716c2099514bcfcaea94809c.zip
llvm-c6c420fca14d9eac716c2099514bcfcaea94809c.tar.gz
llvm-c6c420fca14d9eac716c2099514bcfcaea94809c.tar.bz2
Switch over to using socketpair for local debugserver connections as they are twice as fast as TCP sockets (on macOS at least).
This change opens a socket pair and passes the second socket pair file descriptor down to the debugserver binary using a new option: "--fd=N" where N is the file descriptor. This file descriptor gets passed via posix_spawn() so that there is no need to do any bind/listen or bind/accept calls and eliminates the hanshake unix socket that is used to pass the result of the actual port that ends up being used so it can save time on launch as well as being faster. This is currently only enabled on __APPLE__ builds. Other OSs should try modifying the #define from ProcessGDBRemote.cpp but the first person will need to port the --fd option over to lldb-server. Any OSs that enable USE_SOCKETPAIR_FOR_LOCAL_CONNECTION in their native builds can use the socket pair stuff. The #define is Apple only right now, but looks like: #if defined (__APPLE__) #define USE_SOCKETPAIR_FOR_LOCAL_CONNECTION 1 #endif <rdar://problem/27814880> llvm-svn: 278524
Diffstat (limited to 'lldb/tools/debugserver/source/debugserver.cpp')
-rw-r--r--lldb/tools/debugserver/source/debugserver.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp
index a22f046..e9ddbf4 100644
--- a/lldb/tools/debugserver/source/debugserver.cpp
+++ b/lldb/tools/debugserver/source/debugserver.cpp
@@ -872,6 +872,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
+ { "fd", required_argument, NULL, 'FDSC' }, // A file descriptor was passed to this process when spawned that is already open and ready for communication
{ "named-pipe", required_argument, NULL, 'P' },
{ "reverse-connect", no_argument, NULL, 'R' },
{ "env", required_argument, NULL, 'e' }, // When debugserver launches the process, set a single environment entry as specified by the option value ("./debugserver -e FOO=1 -e BAR=2 localhost:1234 -- /bin/ls")
@@ -949,6 +950,7 @@ main (int argc, char *argv[])
int ch;
int long_option_index = 0;
int debug = 0;
+ int communication_fd = -1;
std::string compile_options;
std::string waitfor_pid_name; // Wait for a process that starts with this name
std::string attach_pid_name;
@@ -1248,6 +1250,12 @@ main (int argc, char *argv[])
remote->Context().PushEnvironment(env_entry);
}
break;
+
+ case 'FDSC':
+ // File descriptor passed to this process during fork/exec and is already
+ // open and ready for communication.
+ communication_fd = atoi(optarg);
+ break;
}
}
@@ -1324,7 +1332,7 @@ main (int argc, char *argv[])
char str[PATH_MAX];
str[0] = '\0';
- if (g_lockdown_opt == 0 && g_applist_opt == 0)
+ if (g_lockdown_opt == 0 && g_applist_opt == 0 && communication_fd == -1)
{
// Make sure we at least have port
if (argc < 1)
@@ -1475,6 +1483,15 @@ main (int argc, char *argv[])
if (remote->Comm().OpenFile (str))
mode = eRNBRunLoopModeExit;
}
+ else if (communication_fd >= 0)
+ {
+ // We were passed a file descriptor to use during fork/exec that is already open
+ // in our process, so lets just use it!
+ if (remote->Comm().useFD(communication_fd))
+ mode = eRNBRunLoopModeExit;
+ else
+ remote->StartReadRemoteDataThread();
+ }
if (mode != eRNBRunLoopModeExit)
{
@@ -1600,6 +1617,16 @@ main (int argc, char *argv[])
if (remote->Comm().OpenFile (str))
mode = eRNBRunLoopModeExit;
}
+ else if (communication_fd >= 0)
+ {
+ // We were passed a file descriptor to use during fork/exec that is already open
+ // in our process, so lets just use it!
+ if (remote->Comm().useFD(communication_fd))
+ mode = eRNBRunLoopModeExit;
+ else
+ remote->StartReadRemoteDataThread();
+ }
+
if (mode != eRNBRunLoopModeExit)
RNBLogSTDOUT ("Waiting for debugger instructions for process %d.\n", attach_pid);
}
@@ -1625,6 +1652,15 @@ main (int argc, char *argv[])
if (remote->Comm().OpenFile (str))
mode = eRNBRunLoopModeExit;
}
+ else if (communication_fd >= 0)
+ {
+ // We were passed a file descriptor to use during fork/exec that is already open
+ // in our process, so lets just use it!
+ if (remote->Comm().useFD(communication_fd))
+ mode = eRNBRunLoopModeExit;
+ else
+ remote->StartReadRemoteDataThread();
+ }
if (mode != eRNBRunLoopModeExit)
{
@@ -1657,6 +1693,15 @@ main (int argc, char *argv[])
if (remote->Comm().OpenFile (str))
mode = eRNBRunLoopModeExit;
}
+ else if (communication_fd >= 0)
+ {
+ // We were passed a file descriptor to use during fork/exec that is already open
+ // in our process, so lets just use it!
+ if (remote->Comm().useFD(communication_fd))
+ mode = eRNBRunLoopModeExit;
+ else
+ remote->StartReadRemoteDataThread();
+ }
if (mode != eRNBRunLoopModeExit)
mode = RNBRunLoopPlatform (remote);