[Lldb-commits] [lldb] r171854 - in /lldb/trunk: source/Plugins/Process/FreeBSD/ProcessMonitor.cpp source/Plugins/Process/FreeBSD/ProcessMonitor.h source/Plugins/Process/Linux/ProcessMonitor.cpp source/Plugins/Process/Linux/ProcessMonitor.h source/Plugins/Process/POSIX/ProcessPOSIX.cpp test/functionalities/process_launch/TestProcessLaunch.py
Daniel Malea
daniel.malea at intel.com
Tue Jan 8 06:49:23 PST 2013
Author: dmalea
Date: Tue Jan 8 08:49:22 2013
New Revision: 171854
URL: http://llvm.org/viewvc/llvm-project?rev=171854&view=rev
Log:
Implement -w flag to process launch (allow launching inferior process in different working directory) on Linux/FreeBSD
- fixes test case TestProcessLaunch
Modified:
lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
lldb/trunk/test/functionalities/process_launch/TestProcessLaunch.py
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=171854&r1=171853&r2=171854&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Tue Jan 8 08:49:22 2013
@@ -627,14 +627,16 @@
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()
{ }
@@ -665,6 +667,7 @@
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
+ const char *working_dir,
lldb_private::Error &error)
: m_process(static_cast<ProcessFreeBSD *>(process)),
m_operation_thread(LLDB_INVALID_HOST_THREAD),
@@ -678,7 +681,7 @@
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.
@@ -839,6 +842,7 @@
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::pid_t pid;
lldb::ThreadSP inferior;
@@ -853,6 +857,7 @@
eDupStdinFailed,
eDupStdoutFailed,
eDupStderrFailed,
+ eChdirFailed,
eExecFailed
};
@@ -887,6 +892,11 @@
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),
@@ -920,6 +930,9 @@
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;
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h?rev=171854&r1=171853&r2=171854&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h Tue Jan 8 08:49:22 2013
@@ -54,6 +54,7 @@
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
+ const char *working_dir,
lldb_private::Error &error);
ProcessMonitor(ProcessPOSIX *process,
@@ -210,7 +211,8 @@
char const **envp,
const char *stdin_path,
const char *stdout_path,
- const char *stderr_path);
+ const char *stderr_path,
+ const char *working_dir);
~LaunchArgs();
@@ -220,6 +222,7 @@
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
Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp?rev=171854&r1=171853&r2=171854&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp Tue Jan 8 08:49:22 2013
@@ -780,14 +780,16 @@
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 @@
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 @@
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 @@
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 @@
eDupStdinFailed,
eDupStdoutFailed,
eDupStderrFailed,
+ eChdirFailed,
eExecFailed
};
@@ -1042,6 +1047,11 @@
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 @@
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;
Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h?rev=171854&r1=171853&r2=171854&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Tue Jan 8 08:49:22 2013
@@ -56,6 +56,7 @@
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 @@
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 @@
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
Modified: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp?rev=171854&r1=171853&r2=171854&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp Tue Jan 8 08:49:22 2013
@@ -17,6 +17,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/State.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/DynamicLoader.h"
@@ -162,6 +163,16 @@
Error error;
assert(m_monitor == NULL);
+ const char* working_dir = launch_info.GetWorkingDirectory();
+ if (working_dir) {
+ FileSpec WorkingDir(working_dir, true);
+ if (!WorkingDir || WorkingDir.GetFileType() != FileSpec::eFileTypeDirectory)
+ {
+ error.SetErrorStringWithFormat("No such file or directory: %s", working_dir);
+ return error;
+ }
+ }
+
SetPrivateState(eStateLaunching);
const lldb_private::ProcessLaunchInfo::FileAction *file_action;
@@ -170,7 +181,7 @@
const char *stdin_path = NULL;
const char *stdout_path = NULL;
const char *stderr_path = NULL;
-
+
file_action = launch_info.GetFileActionForFD (STDIN_FILENO);
stdin_path = GetFilePath(file_action, stdin_path);
@@ -187,6 +198,7 @@
stdin_path,
stdout_path,
stderr_path,
+ working_dir,
error);
m_module = module;
Modified: lldb/trunk/test/functionalities/process_launch/TestProcessLaunch.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/process_launch/TestProcessLaunch.py?rev=171854&r1=171853&r2=171854&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/process_launch/TestProcessLaunch.py (original)
+++ lldb/trunk/test/functionalities/process_launch/TestProcessLaunch.py Tue Jan 8 08:49:22 2013
@@ -152,7 +152,7 @@
err_file_path)
self.expect(launch_command, error=True,
- startstr = "error: No such file or directory: %sz" % my_working_dir_path)
+ patterns = ["error:.* No such file or directory: %sz" % my_working_dir_path])
# Really launch the process
launch_command = "process launch -w %s -o %s -e %s" % (my_working_dir_path,
More information about the lldb-commits
mailing list