diff options
author | Greg Clayton <gclayton@apple.com> | 2012-04-14 01:42:46 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-04-14 01:42:46 +0000 |
commit | d1cf11a74df14374c8be20dd43e805d2dfb1de07 (patch) | |
tree | 8d93d9fd95aa1825bf1ae394233bee05208c16f4 /lldb/source/Target/Process.cpp | |
parent | f5c87882a01b733a98a0138688d2ff0c9e586848 (diff) | |
download | bcm5719-llvm-d1cf11a74df14374c8be20dd43e805d2dfb1de07.tar.gz bcm5719-llvm-d1cf11a74df14374c8be20dd43e805d2dfb1de07.zip |
Added a new host function that allows us to run shell command and get the output from them along with the status and signal:
Error
Host::RunShellCommand (const char *command,
const char *working_dir,
int *status_ptr,
int *signo_ptr,
std::string *command_output_ptr,
uint32_t timeout_sec);
This will allow us to use this functionality in the host lldb_private::Platform, and also use it in our lldb-platform binary. It leverages the existing code in Host::LaunchProcess and ProcessLaunchInfo.
llvm-svn: 154730
Diffstat (limited to 'lldb/source/Target/Process.cpp')
-rw-r--r-- | lldb/source/Target/Process.cpp | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 93619b062cd..c32b4b1305f 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -303,7 +303,10 @@ ProcessLaunchInfo::FinalizeFileActions (Target *target, bool default_to_use_pty) bool -ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error, bool localhost) +ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error, + bool localhost, + bool will_debug, + bool first_arg_is_full_shell_command) { error.Clear(); @@ -334,37 +337,56 @@ ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error, bool local Args shell_arguments; std::string safe_arg; shell_arguments.AppendArgument (shell_executable); - StreamString shell_command; shell_arguments.AppendArgument ("-c"); - shell_command.PutCString ("exec"); - if (GetArchitecture().IsValid()) - { - shell_command.Printf(" /usr/bin/arch -arch %s", GetArchitecture().GetArchitectureName()); - // Set the resume count to 2: - // 1 - stop in shell - // 2 - stop in /usr/bin/arch - // 3 - then we will stop in our program - SetResumeCount(2); - } - else + + StreamString shell_command; + if (will_debug) { - // Set the resume count to 1: - // 1 - stop in shell - // 2 - then we will stop in our program - SetResumeCount(1); + shell_command.PutCString ("exec"); + if (GetArchitecture().IsValid()) + { + shell_command.Printf(" /usr/bin/arch -arch %s", GetArchitecture().GetArchitectureName()); + // Set the resume count to 2: + // 1 - stop in shell + // 2 - stop in /usr/bin/arch + // 3 - then we will stop in our program + SetResumeCount(2); + } + else + { + // Set the resume count to 1: + // 1 - stop in shell + // 2 - then we will stop in our program + SetResumeCount(1); + } } const char **argv = GetArguments().GetConstArgumentVector (); if (argv) { - for (size_t i=0; argv[i] != NULL; ++i) + if (first_arg_is_full_shell_command) { - const char *arg = Args::GetShellSafeArgument (argv[i], safe_arg); - shell_command.Printf(" %s", arg); + // There should only be one argument that is the shell command itself to be used as is + if (argv[0] && !argv[1]) + shell_command.Printf("%s", argv[0]); + else + return false; + } + else + { + for (size_t i=0; argv[i] != NULL; ++i) + { + const char *arg = Args::GetShellSafeArgument (argv[i], safe_arg); + shell_command.Printf(" %s", arg); + } } + shell_arguments.AppendArgument (shell_command.GetString().c_str()); } - shell_arguments.AppendArgument (shell_command.GetString().c_str()); - + else + { + return false; + } + m_executable.SetFile(shell_executable, false); m_arguments = shell_arguments; return true; |