summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Host/Host.h9
-rw-r--r--lldb/source/Host/common/Host.cpp32
-rw-r--r--lldb/source/Host/macosx/Host.mm13
-rw-r--r--lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py21
4 files changed, 55 insertions, 20 deletions
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index 860747fd208..374f8963334 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/include/lldb/Host/Host.h
@@ -268,6 +268,15 @@ public:
std::string *command_output, // Pass NULL if you don't want the command output
uint32_t timeout_sec,
bool run_in_default_shell = true);
+
+ static Error
+ RunShellCommand (const Args& args,
+ const char *working_dir, // Pass NULL to use the current working directory
+ int *status_ptr, // Pass NULL if you don't want the process exit status
+ int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
+ std::string *command_output, // Pass NULL if you don't want the command output
+ uint32_t timeout_sec,
+ bool run_in_default_shell = true);
static lldb::DataBufferSP
GetAuxvData (lldb_private::Process *process);
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 9920291f44c..e0a60c2965f 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -552,6 +552,18 @@ Host::RunShellCommand (const char *command,
uint32_t timeout_sec,
bool run_in_default_shell)
{
+ return RunShellCommand(Args(command), working_dir, status_ptr, signo_ptr, command_output_ptr, timeout_sec, run_in_default_shell);
+}
+
+Error
+Host::RunShellCommand (const Args &args,
+ const char *working_dir,
+ int *status_ptr,
+ int *signo_ptr,
+ std::string *command_output_ptr,
+ uint32_t timeout_sec,
+ bool run_in_default_shell)
+{
Error error;
ProcessLaunchInfo launch_info;
launch_info.SetArchitecture(HostInfo::GetArchitecture());
@@ -559,10 +571,10 @@ Host::RunShellCommand (const char *command,
{
// Run the command in a shell
launch_info.SetShell(HostInfo::GetDefaultShell());
- launch_info.GetArguments().AppendArgument(command);
+ launch_info.GetArguments().AppendArguments(args);
const bool localhost = true;
const bool will_debug = false;
- const bool first_arg_is_full_shell_command = true;
+ const bool first_arg_is_full_shell_command = false;
launch_info.ConvertArgumentsForLaunchingInShell (error,
localhost,
will_debug,
@@ -572,7 +584,6 @@ Host::RunShellCommand (const char *command,
else
{
// No shell, just run it
- Args args (command);
const bool first_arg_is_executable = true;
launch_info.SetArguments(args, first_arg_is_executable);
}
@@ -580,7 +591,7 @@ Host::RunShellCommand (const char *command,
if (working_dir)
launch_info.SetWorkingDirectory(working_dir);
llvm::SmallString<PATH_MAX> output_file_path;
-
+
if (command_output_ptr)
{
// Create a temporary file to get the stdout/stderr and redirect the
@@ -618,10 +629,10 @@ Host::RunShellCommand (const char *command,
error = LaunchProcess (launch_info);
const lldb::pid_t pid = launch_info.GetProcessID();
-
+
if (error.Success() && pid == LLDB_INVALID_PROCESS_ID)
error.SetErrorString("failed to get process ID");
-
+
if (error.Success())
{
// The process successfully launched, so we can defer ownership of
@@ -640,7 +651,7 @@ Host::RunShellCommand (const char *command,
if (timed_out)
{
error.SetErrorString("timed out waiting for shell command to complete");
-
+
// Kill the process since it didn't complete within the timeout specified
Kill (pid, SIGKILL);
// Wait for the monitor callback to get the message
@@ -653,10 +664,10 @@ Host::RunShellCommand (const char *command,
{
if (status_ptr)
*status_ptr = shell_info->status;
-
+
if (signo_ptr)
*signo_ptr = shell_info->signo;
-
+
if (command_output_ptr)
{
command_output_ptr->clear();
@@ -678,7 +689,7 @@ Host::RunShellCommand (const char *command,
}
shell_info->can_delete.SetValue(true, eBroadcastAlways);
}
-
+
FileSpec output_file_spec(output_file_path.c_str(), false);
if (FileSystem::GetFileExists(output_file_spec))
FileSystem::Unlink(output_file_path.c_str());
@@ -688,7 +699,6 @@ Host::RunShellCommand (const char *command,
return error;
}
-
// LaunchProcessPosixSpawn for Apple, Linux, FreeBSD and other GLIBC
// systems
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm
index 86f9d712857..79efb9fc20b 100644
--- a/lldb/source/Host/macosx/Host.mm
+++ b/lldb/source/Host/macosx/Host.mm
@@ -1352,18 +1352,13 @@ Host::ShellExpandArguments (ProcessLaunchInfo &launch_info)
error.SetErrorString("could not find argdumper tool");
return error;
}
-
- std::string quoted_cmd_string;
- launch_info.GetArguments().GetQuotedCommandString(quoted_cmd_string);
- StreamString expand_command;
-
- expand_command.Printf("%s %s",
- expand_tool_spec.GetPath().c_str(),
- quoted_cmd_string.c_str());
+
+ Args expand_command(expand_tool_spec.GetPath().c_str());
+ expand_command.AppendArguments (launch_info.GetArguments());
int status;
std::string output;
- RunShellCommand(expand_command.GetData(), launch_info.GetWorkingDirectory(), &status, nullptr, &output, 10);
+ RunShellCommand(expand_command, launch_info.GetWorkingDirectory(), &status, nullptr, &output, 10);
if (status != 0)
{
diff --git a/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py b/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py
index 313606144d7..dbbaa72bb53 100644
--- a/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py
+++ b/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py
@@ -84,6 +84,27 @@ class LaunchWithShellExpandTestCase(TestBase):
self.expect("frame variable argv[1]", substrs=['foo bar'])
+ self.runCmd("process kill")
+
+ self.runCmd('process launch -X true -w %s -- foo\ bar' % (os.getcwd()))
+
+ process = self.process()
+
+ self.assertTrue(process.GetState() == lldb.eStateStopped,
+ STOPPED_DUE_TO_BREAKPOINT)
+
+ thread = process.GetThreadAtIndex (0)
+
+ self.assertTrue (thread.IsValid(),
+ "Process stopped at 'main' should have a valid thread");
+
+ stop_reason = thread.GetStopReason()
+
+ self.assertTrue (stop_reason == lldb.eStopReasonBreakpoint,
+ "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint");
+
+ self.expect("frame variable argv[1]", substrs=['foo bar'])
+
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
OpenPOWER on IntegriCloud