summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/Linux
diff options
context:
space:
mode:
authorDaniel Malea <daniel.malea@intel.com>2013-01-08 14:49:22 +0000
committerDaniel Malea <daniel.malea@intel.com>2013-01-08 14:49:22 +0000
commit6217d2ae379b2c6b64bf558321eca40bf1368be4 (patch)
treee3fc2ed988becd900645745e4feb83936346e8ca /lldb/source/Plugins/Process/Linux
parent7daa1a22014c9b5a400dba5e6cfb0ff7cc94b443 (diff)
downloadbcm5719-llvm-6217d2ae379b2c6b64bf558321eca40bf1368be4.tar.gz
bcm5719-llvm-6217d2ae379b2c6b64bf558321eca40bf1368be4.zip
Implement -w flag to process launch (allow launching inferior process in different working directory) on Linux/FreeBSD
- fixes test case TestProcessLaunch llvm-svn: 171854
Diffstat (limited to 'lldb/source/Plugins/Process/Linux')
-rw-r--r--lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp19
-rw-r--r--lldb/source/Plugins/Process/Linux/ProcessMonitor.h5
2 files changed, 20 insertions, 4 deletions
diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
index 50beddcd9d0..b71f0f94469 100644
--- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
+++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
@@ -780,14 +780,16 @@ ProcessMonitor::LaunchArgs::LaunchArgs(ProcessMonitor *monitor,
char const **envp,
const char *stdin_path,
const char *stdout_path,
- const char *stderr_path)
+ const char *stderr_path,
+ const char *working_dir)
: 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_stderr_path(stderr_path),
+ m_working_dir(working_dir) { }
ProcessMonitor::LaunchArgs::~LaunchArgs()
{ }
@@ -818,6 +820,7 @@ ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
+ const char *working_dir,
lldb_private::Error &error)
: m_process(static_cast<ProcessLinux *>(process)),
m_operation_thread(LLDB_INVALID_HOST_THREAD),
@@ -830,7 +833,7 @@ ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
std::auto_ptr<LaunchArgs> args;
args.reset(new LaunchArgs(this, module, argv, envp,
- stdin_path, stdout_path, stderr_path));
+ stdin_path, stdout_path, stderr_path, working_dir));
// Server/client descriptors.
if (!EnableIPC())
@@ -976,6 +979,7 @@ ProcessMonitor::Launch(LaunchArgs *args)
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;
lldb_utility::PseudoTerminal terminal;
const size_t err_len = 1024;
@@ -1010,6 +1014,7 @@ ProcessMonitor::Launch(LaunchArgs *args)
eDupStdinFailed,
eDupStdoutFailed,
eDupStderrFailed,
+ eChdirFailed,
eExecFailed
};
@@ -1042,6 +1047,11 @@ ProcessMonitor::Launch(LaunchArgs *args)
if (!DupDescriptor(stderr_path, 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);
+
// Execute. We should never return.
execve(argv[0],
const_cast<char *const *>(argv),
@@ -1075,6 +1085,9 @@ ProcessMonitor::Launch(LaunchArgs *args)
case eDupStderrFailed:
args->m_error.SetErrorString("Child open stderr failed.");
break;
+ case eChdirFailed:
+ args->m_error.SetErrorString("Child failed to set working directory.");
+ break;
case eExecFailed:
args->m_error.SetErrorString("Child exec failed.");
break;
diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h
index b154a6d1222..4fefae23035 100644
--- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h
+++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h
@@ -56,6 +56,7 @@ public:
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
+ const char *working_dir,
lldb_private::Error &error);
ProcessMonitor(ProcessPOSIX *process,
@@ -200,7 +201,8 @@ private:
char const **envp,
const char *stdin_path,
const char *stdout_path,
- const char *stderr_path);
+ const char *stderr_path,
+ const char *working_dir);
~LaunchArgs();
@@ -210,6 +212,7 @@ private:
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.
};
void
OpenPOWER on IntegriCloud