summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/Linux
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/Process/Linux')
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp103
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.h33
-rw-r--r--lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp58
-rw-r--r--lldb/source/Plugins/Process/Linux/ProcessMonitor.h33
4 files changed, 117 insertions, 110 deletions
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index b3956eb662c..210888b2118 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -954,17 +954,17 @@ NativeProcessLinux::Monitor::RunMonitor(void *arg)
NativeProcessLinux::LaunchArgs::LaunchArgs(Module *module,
char const **argv,
char const **envp,
- const std::string &stdin_path,
- const std::string &stdout_path,
- const std::string &stderr_path,
- const char *working_dir,
+ const FileSpec &stdin_file_spec,
+ const FileSpec &stdout_file_spec,
+ const FileSpec &stderr_file_spec,
+ const FileSpec &working_dir,
const ProcessLaunchInfo &launch_info)
: m_module(module),
m_argv(argv),
m_envp(envp),
- m_stdin_path(stdin_path),
- m_stdout_path(stdout_path),
- m_stderr_path(stderr_path),
+ m_stdin_file_spec(stdin_file_spec),
+ m_stdout_file_spec(stdout_file_spec),
+ m_stderr_file_spec(stderr_file_spec),
m_working_dir(working_dir),
m_launch_info(launch_info)
{
@@ -989,50 +989,52 @@ NativeProcessLinux::LaunchProcess (
Error error;
// Verify the working directory is valid if one was specified.
- const char* working_dir = launch_info.GetWorkingDirectory ();
- if (working_dir)
+ FileSpec working_dir{launch_info.GetWorkingDirectory()};
+ if (working_dir &&
+ (!working_dir.ResolvePath() ||
+ working_dir.GetFileType() != FileSpec::eFileTypeDirectory))
{
- FileSpec working_dir_fs (working_dir, true);
- if (!working_dir_fs || working_dir_fs.GetFileType () != FileSpec::eFileTypeDirectory)
- {
- error.SetErrorStringWithFormat ("No such file or directory: %s", working_dir);
- return error;
- }
+ error.SetErrorStringWithFormat ("No such file or directory: %s",
+ working_dir.GetCString());
+ return error;
}
const FileAction *file_action;
- // Default of NULL will mean to use existing open file descriptors.
- std::string stdin_path;
- std::string stdout_path;
- std::string stderr_path;
+ // Default of empty will mean to use existing open file descriptors.
+ FileSpec stdin_file_spec{};
+ FileSpec stdout_file_spec{};
+ FileSpec stderr_file_spec{};
file_action = launch_info.GetFileActionForFD (STDIN_FILENO);
if (file_action)
- stdin_path = file_action->GetPath ();
+ stdin_file_spec = file_action->GetFileSpec();
file_action = launch_info.GetFileActionForFD (STDOUT_FILENO);
if (file_action)
- stdout_path = file_action->GetPath ();
+ stdout_file_spec = file_action->GetFileSpec();
file_action = launch_info.GetFileActionForFD (STDERR_FILENO);
if (file_action)
- stderr_path = file_action->GetPath ();
+ stderr_file_spec = file_action->GetFileSpec();
if (log)
{
- if (!stdin_path.empty ())
- log->Printf ("NativeProcessLinux::%s setting STDIN to '%s'", __FUNCTION__, stdin_path.c_str ());
+ if (stdin_file_spec)
+ log->Printf ("NativeProcessLinux::%s setting STDIN to '%s'",
+ __FUNCTION__, stdin_file_spec.GetCString());
else
log->Printf ("NativeProcessLinux::%s leaving STDIN as is", __FUNCTION__);
- if (!stdout_path.empty ())
- log->Printf ("NativeProcessLinux::%s setting STDOUT to '%s'", __FUNCTION__, stdout_path.c_str ());
+ if (stdout_file_spec)
+ log->Printf ("NativeProcessLinux::%s setting STDOUT to '%s'",
+ __FUNCTION__, stdout_file_spec.GetCString());
else
log->Printf ("NativeProcessLinux::%s leaving STDOUT as is", __FUNCTION__);
- if (!stderr_path.empty ())
- log->Printf ("NativeProcessLinux::%s setting STDERR to '%s'", __FUNCTION__, stderr_path.c_str ());
+ if (stderr_file_spec)
+ log->Printf ("NativeProcessLinux::%s setting STDERR to '%s'",
+ __FUNCTION__, stderr_file_spec.GetCString());
else
log->Printf ("NativeProcessLinux::%s leaving STDERR as is", __FUNCTION__);
}
@@ -1061,9 +1063,9 @@ NativeProcessLinux::LaunchProcess (
exe_module,
launch_info.GetArguments ().GetConstArgumentVector (),
launch_info.GetEnvironmentEntries ().GetConstArgumentVector (),
- stdin_path,
- stdout_path,
- stderr_path,
+ stdin_file_spec,
+ stdout_file_spec,
+ stderr_file_spec,
working_dir,
launch_info,
error);
@@ -1141,10 +1143,10 @@ NativeProcessLinux::LaunchInferior (
Module *module,
const char *argv[],
const char *envp[],
- const std::string &stdin_path,
- const std::string &stdout_path,
- const std::string &stderr_path,
- const char *working_dir,
+ const FileSpec &stdin_file_spec,
+ const FileSpec &stdout_file_spec,
+ const FileSpec &stderr_file_spec,
+ const FileSpec &working_dir,
const ProcessLaunchInfo &launch_info,
Error &error)
{
@@ -1154,10 +1156,12 @@ NativeProcessLinux::LaunchInferior (
SetState (eStateLaunching);
std::unique_ptr<LaunchArgs> args(
- new LaunchArgs(
- module, argv, envp,
- stdin_path, stdout_path, stderr_path,
- working_dir, launch_info));
+ new LaunchArgs(module, argv, envp,
+ stdin_file_spec,
+ stdout_file_spec,
+ stderr_file_spec,
+ working_dir,
+ launch_info));
StartMonitorThread ([&] (Error &e) { return Launch(args.get(), e); }, error);
if (!error.Success ())
@@ -1226,7 +1230,7 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error)
const char **argv = args->m_argv;
const char **envp = args->m_envp;
- const char *working_dir = args->m_working_dir;
+ const FileSpec working_dir = args->m_working_dir;
lldb_utility::PseudoTerminal terminal;
const size_t err_len = 1024;
@@ -1286,16 +1290,16 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error)
}
// Dup file descriptors if needed.
- if (!args->m_stdin_path.empty ())
- if (!DupDescriptor(args->m_stdin_path.c_str (), STDIN_FILENO, O_RDONLY))
+ if (args->m_stdin_file_spec)
+ if (!DupDescriptor(args->m_stdin_file_spec, STDIN_FILENO, O_RDONLY))
exit(eDupStdinFailed);
- if (!args->m_stdout_path.empty ())
- if (!DupDescriptor(args->m_stdout_path.c_str (), STDOUT_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ if (args->m_stdout_file_spec)
+ if (!DupDescriptor(args->m_stdout_file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
exit(eDupStdoutFailed);
- if (!args->m_stderr_path.empty ())
- if (!DupDescriptor(args->m_stderr_path.c_str (), STDERR_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
+ if (args->m_stderr_file_spec)
+ if (!DupDescriptor(args->m_stderr_file_spec, STDERR_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
exit(eDupStderrFailed);
// Close everything besides stdin, stdout, and stderr that has no file
@@ -1305,8 +1309,7 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error)
close(fd);
// Change working directory
- if (working_dir != NULL && working_dir[0])
- if (0 != ::chdir(working_dir))
+ if (working_dir && 0 != ::chdir(working_dir.GetCString()))
exit(eChdirFailed);
// Disable ASLR if requested.
@@ -3310,9 +3313,9 @@ NativeProcessLinux::Detach(lldb::tid_t tid)
}
bool
-NativeProcessLinux::DupDescriptor(const char *path, int fd, int flags)
+NativeProcessLinux::DupDescriptor(const FileSpec &file_spec, int fd, int flags)
{
- int target_fd = open(path, flags, 0666);
+ int target_fd = open(file_spec.GetCString(), flags, 0666);
if (target_fd == -1)
return false;
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
index 71482e62ca2..137f7fdf8a9 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -17,6 +17,7 @@
#include "lldb/Core/ArchSpec.h"
#include "lldb/lldb-types.h"
#include "lldb/Host/Debug.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Target/MemoryRegionInfo.h"
@@ -195,21 +196,21 @@ namespace process_linux {
LaunchArgs(Module *module,
char const **argv,
char const **envp,
- const std::string &stdin_path,
- const std::string &stdout_path,
- const std::string &stderr_path,
- const char *working_dir,
+ const FileSpec &stdin_file_spec,
+ const FileSpec &stdout_file_spec,
+ const FileSpec &stderr_file_spec,
+ const FileSpec &working_dir,
const ProcessLaunchInfo &launch_info);
~LaunchArgs();
- Module *m_module; // The executable image to launch.
- char const **m_argv; // Process arguments.
- char const **m_envp; // Process environment.
- const std::string &m_stdin_path; // Redirect stdin if not empty.
- const std::string &m_stdout_path; // Redirect stdout if not empty.
- const std::string &m_stderr_path; // Redirect stderr if not empty.
- const char *m_working_dir; // Working directory or NULL.
+ Module *m_module; // The executable image to launch.
+ char const **m_argv; // Process arguments.
+ char const **m_envp; // Process environment.
+ const FileSpec m_stdin_file_spec; // Redirect stdin if not empty.
+ const FileSpec m_stdout_file_spec; // Redirect stdout if not empty.
+ const FileSpec m_stderr_file_spec; // Redirect stderr if not empty.
+ const FileSpec m_working_dir; // Working directory or empty.
const ProcessLaunchInfo &m_launch_info;
};
@@ -227,10 +228,10 @@ namespace process_linux {
Module *module,
char const *argv[],
char const *envp[],
- const std::string &stdin_path,
- const std::string &stdout_path,
- const std::string &stderr_path,
- const char *working_dir,
+ const FileSpec &stdin_file_spec,
+ const FileSpec &stdout_file_spec,
+ const FileSpec &stderr_file_spec,
+ const FileSpec &working_dir,
const ProcessLaunchInfo &launch_info,
Error &error);
@@ -252,7 +253,7 @@ namespace process_linux {
SetDefaultPtraceOpts(const lldb::pid_t);
static bool
- DupDescriptor(const char *path, int fd, int flags);
+ DupDescriptor(const FileSpec &file_spec, int fd, int flags);
static void *
MonitorThread(void *baton);
diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
index a4063e53d41..d5341f19f9f 100644
--- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
+++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
@@ -1185,18 +1185,18 @@ ProcessMonitor::LaunchArgs::LaunchArgs(ProcessMonitor *monitor,
lldb_private::Module *module,
char const **argv,
char const **envp,
- const char *stdin_path,
- const char *stdout_path,
- const char *stderr_path,
- const char *working_dir,
+ const FileSpec &stdin_file_spec,
+ const FileSpec &stdout_file_spec,
+ const FileSpec &stderr_file_spec,
+ const FileSpec &working_dir,
const lldb_private::ProcessLaunchInfo &launch_info)
: OperationArgs(monitor),
m_module(module),
m_argv(argv),
m_envp(envp),
- m_stdin_path(stdin_path),
- m_stdout_path(stdout_path),
- m_stderr_path(stderr_path),
+ m_stdin_file_spec(stdin_file_spec),
+ m_stdout_file_spec(stdout_file_spec),
+ m_stderr_file_spec(stderr_file_spec),
m_working_dir(working_dir),
m_launch_info(launch_info)
{
@@ -1228,10 +1228,10 @@ ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
Module *module,
const char *argv[],
const char *envp[],
- const char *stdin_path,
- const char *stdout_path,
- const char *stderr_path,
- const char *working_dir,
+ const FileSpec &stdin_file_spec,
+ const FileSpec &stdout_file_spec,
+ const FileSpec &stderr_file_spec,
+ const FileSpec &working_dir,
const lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Error &error)
: m_process(static_cast<ProcessLinux *>(process)),
@@ -1242,8 +1242,11 @@ ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
m_operation(0)
{
std::unique_ptr<LaunchArgs> args(new LaunchArgs(this, module, argv, envp,
- stdin_path, stdout_path, stderr_path,
- working_dir, launch_info));
+ stdin_file_spec,
+ stdout_file_spec,
+ stderr_file_spec,
+ working_dir,
+ launch_info));
sem_init(&m_operation_pending, 0, 0);
sem_init(&m_operation_done, 0, 0);
@@ -1378,10 +1381,10 @@ ProcessMonitor::Launch(LaunchArgs *args)
ProcessLinux &process = monitor->GetProcess();
const char **argv = args->m_argv;
const char **envp = args->m_envp;
- const char *stdin_path = args->m_stdin_path;
- const char *stdout_path = args->m_stdout_path;
- const char *stderr_path = args->m_stderr_path;
- const char *working_dir = args->m_working_dir;
+ const FileSpec &stdin_file_spec = args->m_stdin_file_spec;
+ const FileSpec &stdout_file_spec = args->m_stdout_file_spec;
+ const FileSpec &stderr_file_spec = args->m_stderr_file_spec;
+ const FileSpec &working_dir = args->m_working_dir;
lldb_utility::PseudoTerminal terminal;
const size_t err_len = 1024;
@@ -1436,22 +1439,21 @@ ProcessMonitor::Launch(LaunchArgs *args)
//
// FIXME: If two or more of the paths are the same we needlessly open
// the same file multiple times.
- if (stdin_path != NULL && stdin_path[0])
- if (!DupDescriptor(stdin_path, STDIN_FILENO, O_RDONLY))
+ if (stdin_file_spec)
+ if (!DupDescriptor(stdin_file_spec, STDIN_FILENO, O_RDONLY))
exit(eDupStdinFailed);
- if (stdout_path != NULL && stdout_path[0])
- if (!DupDescriptor(stdout_path, STDOUT_FILENO, O_WRONLY | O_CREAT))
+ if (stdout_file_spec)
+ if (!DupDescriptor(stdout_file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT))
exit(eDupStdoutFailed);
- if (stderr_path != NULL && stderr_path[0])
- if (!DupDescriptor(stderr_path, STDERR_FILENO, O_WRONLY | O_CREAT))
+ if (stderr_file_spec)
+ if (!DupDescriptor(stderr_file_spec, STDERR_FILENO, O_WRONLY | O_CREAT))
exit(eDupStderrFailed);
// Change working directory
- if (working_dir != NULL && working_dir[0])
- if (0 != ::chdir(working_dir))
- exit(eChdirFailed);
+ if (working_dir && 0 != ::chdir(working_dir.GetCString()))
+ exit(eChdirFailed);
// Disable ASLR if requested.
if (args->m_launch_info.GetFlags ().Test (lldb::eLaunchFlagDisableASLR))
@@ -2402,9 +2404,9 @@ ProcessMonitor::Detach(lldb::tid_t tid)
}
bool
-ProcessMonitor::DupDescriptor(const char *path, int fd, int flags)
+ProcessMonitor::DupDescriptor(const FileSpec &file_spec, int fd, int flags)
{
- int target_fd = open(path, flags, 0666);
+ int target_fd = open(file_spec.GetCString(), flags, 0666);
if (target_fd == -1)
return false;
diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h
index a399856bde3..8fc97bc1953 100644
--- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h
+++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h
@@ -17,6 +17,7 @@
// C++ Includes
// Other libraries and framework includes
#include "lldb/lldb-types.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Mutex.h"
@@ -58,10 +59,10 @@ public:
lldb_private::Module *module,
char const *argv[],
char const *envp[],
- const char *stdin_path,
- const char *stdout_path,
- const char *stderr_path,
- const char *working_dir,
+ const lldb_private::FileSpec &stdin_file_spec,
+ const lldb_private::FileSpec &stdout_file_spec,
+ const lldb_private::FileSpec &stderr_file_spec,
+ const lldb_private::FileSpec &working_dir,
const lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Error &error);
@@ -251,21 +252,21 @@ private:
lldb_private::Module *module,
char const **argv,
char const **envp,
- const char *stdin_path,
- const char *stdout_path,
- const char *stderr_path,
- const char *working_dir,
+ const lldb_private::FileSpec &stdin_file_spec,
+ const lldb_private::FileSpec &stdout_file_spec,
+ const lldb_private::FileSpec &stderr_file_spec,
+ const lldb_private::FileSpec &working_dir,
const lldb_private::ProcessLaunchInfo &launch_info);
~LaunchArgs();
- lldb_private::Module *m_module; // The executable image to launch.
- char const **m_argv; // Process arguments.
- char const **m_envp; // Process environment.
- const char *m_stdin_path; // Redirect stdin or NULL.
- const char *m_stdout_path; // Redirect stdout or NULL.
- const char *m_stderr_path; // Redirect stderr or NULL.
- const char *m_working_dir; // Working directory or NULL.
+ lldb_private::Module *m_module; // The executable image to launch.
+ char const **m_argv; // Process arguments.
+ char const **m_envp; // Process environment.
+ const lldb_private::FileSpec m_stdin_file_spec; // Redirect stdin or empty.
+ const lldb_private::FileSpec m_stdout_file_spec; // Redirect stdout or empty.
+ const lldb_private::FileSpec m_stderr_file_spec; // Redirect stderr or empty.
+ const lldb_private::FileSpec m_working_dir; // Working directory or empty.
const lldb_private::ProcessLaunchInfo &m_launch_info;
};
@@ -304,7 +305,7 @@ private:
ServeOperation(OperationArgs *args);
static bool
- DupDescriptor(const char *path, int fd, int flags);
+ DupDescriptor(const lldb_private::FileSpec &file_spec, int fd, int flags);
static bool
MonitorCallback(void *callback_baton,
OpenPOWER on IntegriCloud