diff options
Diffstat (limited to 'lldb/tools/debugserver')
| -rw-r--r-- | lldb/tools/debugserver/source/DNB.cpp | 17 | ||||
| -rw-r--r-- | lldb/tools/debugserver/source/MacOSX/MachProcess.cpp | 28 | ||||
| -rw-r--r-- | lldb/tools/debugserver/source/debugserver.cpp | 28 |
3 files changed, 53 insertions, 20 deletions
diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp index 92cdf582039..fab4741ac10 100644 --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -185,8 +185,21 @@ DNBProcessLaunch (const char *path, char *err_str, size_t err_len) { - DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv = %p, envp = %p, launch_flavor = %u, disable_aslr = %d, err = %p, err_len = %zu) called...", __FUNCTION__, path, argv, envp, launch_flavor, disable_aslr, err_str, err_len); - + DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv = %p, envp = %p, working_dir=%s, stdin=%s, stdout=%s, stderr=%s, no-stdio=%i, launch_flavor = %u, disable_aslr = %d, err = %p, err_len = %zu) called...", + __FUNCTION__, + path, + argv, + envp, + working_directory, + stdin_path, + stdout_path, + stderr_path, + no_stdio, + launch_flavor, + disable_aslr, + err_str, + err_len); + if (err_str && err_len > 0) err_str[0] = '\0'; struct stat path_stat; diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp index 8b4c61b433b..12c981bccb4 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp @@ -1625,7 +1625,16 @@ MachProcess::PosixSpawnChildForPTraceDebugging { posix_spawnattr_t attr; short flags; - DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv=%p, envp=%p, process )", __FUNCTION__, path, argv, envp); + DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv=%p, envp=%p, working_dir=%s, stdin=%s, stdout=%s stderr=%s, no-stdio=%i)", + __FUNCTION__, + path, + argv, + envp, + working_directory, + stdin_path, + stdout_path, + stderr_path, + no_stdio); err.SetError( ::posix_spawnattr_init (&attr), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) @@ -1703,9 +1712,9 @@ MachProcess::PosixSpawnChildForPTraceDebugging } else { - int slave_fd_err = open (stderr_path ? stderr_path : "/dev/null", O_RDWR , 0); - int slave_fd_in = open (stdin_path ? stdin_path : "/dev/null", O_RDONLY, 0); - int slave_fd_out = open (stdout_path ? stdout_path : "/dev/null", O_WRONLY, 0); + int slave_fd_err = open (stderr_path ? stderr_path : "/dev/null", O_NOCTTY | O_CREAT | O_RDWR , 0640); + int slave_fd_in = open (stdin_path ? stdin_path : "/dev/null", O_NOCTTY | O_RDONLY); + int slave_fd_out = open (stdout_path ? stdout_path : "/dev/null", O_NOCTTY | O_CREAT | O_WRONLY , 0640); err.SetError( ::posix_spawn_file_actions_adddup2(&file_actions, slave_fd_err, STDERR_FILENO), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) @@ -1719,12 +1728,23 @@ MachProcess::PosixSpawnChildForPTraceDebugging if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) err.LogThreaded("::posix_spawn_file_actions_adddup2 ( &file_actions, filedes = %d, newfiledes = STDOUT_FILENO )", slave_fd_out); } + + // TODO: Verify if we can set the working directory back immediately + // after the posix_spawnp call without creating a race condition??? + if (working_directory) + ::chdir (working_directory); + err.SetError( ::posix_spawnp (&pid, path, &file_actions, &attr, (char * const*)argv, (char * const*)envp), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) err.LogThreaded("::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, &file_actions, &attr, argv, envp); } else { + // TODO: Verify if we can set the working directory back immediately + // after the posix_spawnp call without creating a race condition??? + if (working_directory) + ::chdir (working_directory); + err.SetError( ::posix_spawnp (&pid, path, NULL, &attr, (char * const*)argv, (char * const*)envp), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) err.LogThreaded("::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, NULL, &attr, argv, envp); diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp index 49f1f0c9f10..f3a4b69c5e6 100644 --- a/lldb/tools/debugserver/source/debugserver.cpp +++ b/lldb/tools/debugserver/source/debugserver.cpp @@ -651,14 +651,14 @@ static struct option g_long_options[] = { "waitfor-interval", required_argument, NULL, 'i' }, // Time in usecs to wait between sampling the pid list when waiting for a process by name { "waitfor-duration", required_argument, NULL, 'd' }, // The time in seconds to wait for a process to show up by name { "native-regs", no_argument, NULL, 'r' }, // Specify to use the native registers instead of the gdb defaults for the architecture. - { "stdio-path", required_argument, NULL, 's' }, // Set the STDIO path to be used when launching applications (STDIN, STDOUT and STDERR) - { "stdin-path", required_argument, NULL, 'I' }, // Set the STDIN path to be used when launching applications - { "stdout-path", required_argument, NULL, 'O' }, // Set the STDIN path to be used when launching applications - { "stderr-path", required_argument, NULL, 'E' }, // Set the STDIN path to be used when launching applications - { "no-stdio", no_argument, NULL, 'n' }, // Do not set up any stdio (perhaps the program is a GUI program) - { "setsid", no_argument, NULL, 'S' }, // call setsid() to make debugserver run in its own sessions + { "stdio-path", required_argument, NULL, 's' }, // Set the STDIO path to be used when launching applications (STDIN, STDOUT and STDERR) (only if debugserver launches the process) + { "stdin-path", required_argument, NULL, 'I' }, // Set the STDIN path to be used when launching applications (only if debugserver launches the process) + { "stdout-path", required_argument, NULL, 'O' }, // Set the STDIN path to be used when launching applications (only if debugserver launches the process) + { "stderr-path", required_argument, NULL, 'E' }, // Set the STDIN path to be used when launching applications (only if debugserver launches the process) + { "no-stdio", no_argument, NULL, 'n' }, // Do not set up any stdio (perhaps the program is a GUI program) (only if debugserver launches the process) + { "setsid", no_argument, NULL, 'S' }, // call setsid() to make debugserver run in its own session { "disable-aslr", no_argument, NULL, 'D' }, // Use _POSIX_SPAWN_DISABLE_ASLR to avoid shared library randomization - { "chdir", no_argument, NULL, 'c' }, // Use _POSIX_SPAWN_DISABLE_ASLR to avoid shared library randomization + { "working-dir", required_argument, NULL, 'W' }, // The working directory that the inferior process should have (only if debugserver launches the process) { NULL, 0, NULL, 0 } }; @@ -699,7 +699,7 @@ main (int argc, char *argv[]) std::string stdout_path; std::string stderr_path; std::string arch_name; - std::string working_directory; // The new working directory to use for the inferior + std::string working_dir; // The new working directory to use for the inferior 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; @@ -785,9 +785,9 @@ main (int argc, char *argv[]) } break; - case 'c': + case 'W': if (optarg && optarg[0]) - working_directory.assign(optarg); + working_dir.assign(optarg); break; case 'x': @@ -826,7 +826,7 @@ main (int argc, char *argv[]) else if (strcasecmp(optarg, "stderr") == 0) log_file = stderr; else - log_file = fopen(optarg, "w+"); + log_file = fopen(optarg, "w"); if (log_file == NULL) { @@ -938,11 +938,11 @@ main (int argc, char *argv[]) return -1; } - if (!working_directory.empty()) + if (!working_dir.empty()) { - if (remote->Context().SetWorkingDirectory (working_directory.c_str()) == false) + if (remote->Context().SetWorkingDirectory (working_dir.c_str()) == false) { - RNBLogSTDERR ("error: working directory doesn't exist '%s'.\n", working_directory.c_str()); + RNBLogSTDERR ("error: working directory doesn't exist '%s'.\n", working_dir.c_str()); exit (8); } } |

