Add an option for debugserver to propagate its environment to programs it launches using the --forward-env or -F:

% ./debugserver --forward-env localhost:1234 -- /bin/ls
% ./debugserver -F localhost:1234 -- /bin/ls

Also allow new environment variables to be set using the "--env" or "-e":

% ./debugserver --env FOO=1 --env BAR=2 localhost:1234 -- /bin/ls
% ./debugserver -e FOO=1 -e BAR=2 localhost:1234 -- /bin/ls

<rdar://problem/17350654> 

llvm-svn: 211200
This commit is contained in:
Greg Clayton
2014-06-18 18:26:50 +00:00
parent 989574ca99
commit ce1843bcd6

View File

@@ -23,6 +23,7 @@
#include <netinet/tcp.h>
#include <sys/un.h>
#include <sys/types.h>
#include <crt_externs.h> // for _NSGetEnviron()
#include "CFString.h"
#include "DNB.h"
@@ -862,6 +863,8 @@ static struct option g_long_options[] =
{ "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
{ "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")
{ "forward-env", no_argument, NULL, 'F' }, // When debugserver launches the process, forward debugserver's current environment variables to the child process ("./debugserver -F localhost:1234 -- /bin/ls"
{ NULL, 0, NULL, 0 }
};
@@ -1193,6 +1196,21 @@ main (int argc, char *argv[])
named_pipe_path.assign (optarg);
break;
case 'e':
// Pass a single specified environment variable down to the process that gets launched
remote->Context().PushEnvironment(optarg);
break;
case 'F':
// Pass the current environment down to the process that gets launched
{
char **host_env = *_NSGetEnviron();
char *env_entry;
size_t i;
for (i=0; (env_entry = host_env[i]) != NULL; ++i)
remote->Context().PushEnvironment(env_entry);
}
break;
}
}