summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Host/Host.h51
-rw-r--r--lldb/source/Host/common/Host.cpp21
-rw-r--r--lldb/source/Host/macosx/objcxx/Host.mm5
3 files changed, 46 insertions, 31 deletions
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index b289283e81f..2cb3aafc1af 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/include/lldb/Host/Host.h
@@ -195,28 +195,35 @@ public:
/// user experience
static Status ShellExpandArguments(ProcessLaunchInfo &launch_info);
- // TODO: Convert this function to take a StringRef.
- static Status RunShellCommand(
- const char *command, // Shouldn't be NULL
- const FileSpec &working_dir, // Pass empty FileSpec 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
- const Timeout<std::micro> &timeout, bool run_in_default_shell = true);
-
- static Status RunShellCommand(
- const Args &args,
- const FileSpec &working_dir, // Pass empty FileSpec 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
- const Timeout<std::micro> &timeout, bool run_in_default_shell = true);
+ /// Run a shell command.
+ /// \arg command shouldn't be NULL
+ /// \arg working_dir Pass empty FileSpec to use the current working directory
+ /// \arg status_ptr Pass NULL if you don't want the process exit status
+ /// \arg signo_ptr Pass NULL if you don't want the signal that caused the
+ /// process to exit
+ /// \arg command_output Pass NULL if you don't want the command output
+ /// \arg hide_stderr if this is false, redirect stderr to stdout
+ /// TODO: Convert this function to take a StringRef.
+ static Status RunShellCommand(const char *command,
+ const FileSpec &working_dir, int *status_ptr,
+ int *signo_ptr, std::string *command_output,
+ const Timeout<std::micro> &timeout,
+ bool run_in_default_shell = true,
+ bool hide_stderr = false);
+
+ /// Run a shell command.
+ /// \arg working_dir Pass empty FileSpec to use the current working directory
+ /// \arg status_ptr Pass NULL if you don't want the process exit status
+ /// \arg signo_ptr Pass NULL if you don't want the signal that caused the
+ /// process to exit
+ /// \arg command_output Pass NULL if you don't want the command output
+ /// \arg hide_stderr if this is false, redirect stderr to stdout
+ static Status RunShellCommand(const Args &args, const FileSpec &working_dir,
+ int *status_ptr, int *signo_ptr,
+ std::string *command_output,
+ const Timeout<std::micro> &timeout,
+ bool run_in_default_shell = true,
+ bool hide_stderr = false);
static bool OpenFileInExternalEditor(const FileSpec &file_spec,
uint32_t line_no);
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 1cb1c90db46..d3e41a2b044 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -462,16 +462,19 @@ Status Host::RunShellCommand(const char *command, const FileSpec &working_dir,
int *status_ptr, int *signo_ptr,
std::string *command_output_ptr,
const Timeout<std::micro> &timeout,
- bool run_in_default_shell) {
+ bool run_in_default_shell,
+ bool hide_stderr) {
return RunShellCommand(Args(command), working_dir, status_ptr, signo_ptr,
- command_output_ptr, timeout, run_in_default_shell);
+ command_output_ptr, timeout, run_in_default_shell,
+ hide_stderr);
}
Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
int *status_ptr, int *signo_ptr,
std::string *command_output_ptr,
const Timeout<std::micro> &timeout,
- bool run_in_default_shell) {
+ bool run_in_default_shell,
+ bool hide_stderr) {
Status error;
ProcessLaunchInfo launch_info;
launch_info.SetArchitecture(HostInfo::GetArchitecture());
@@ -509,16 +512,18 @@ Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
}
FileSpec output_file_spec(output_file_path.c_str());
-
+ // Set up file descriptors.
launch_info.AppendSuppressFileAction(STDIN_FILENO, true, false);
- if (output_file_spec) {
+ if (output_file_spec)
launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_spec, false,
true);
- launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
- } else {
+ else
launch_info.AppendSuppressFileAction(STDOUT_FILENO, false, true);
+
+ if (output_file_spec && !hide_stderr)
+ launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
+ else
launch_info.AppendSuppressFileAction(STDERR_FILENO, false, true);
- }
std::shared_ptr<ShellInfo> shell_info_sp(new ShellInfo());
const bool monitor_signals = false;
diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm
index 8b58b28802c..4994c813978 100644
--- a/lldb/source/Host/macosx/objcxx/Host.mm
+++ b/lldb/source/Host/macosx/objcxx/Host.mm
@@ -1364,8 +1364,11 @@ Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
launch_info.SetWorkingDirectory(working_dir);
}
}
+ bool run_in_default_shell = true;
+ bool hide_stderr = true;
RunShellCommand(expand_command, cwd, &status, nullptr, &output,
- std::chrono::seconds(10));
+ std::chrono::seconds(10), run_in_default_shell,
+ hide_stderr);
if (status != 0) {
error.SetErrorStringWithFormat("lldb-argdumper exited with error %d",
OpenPOWER on IntegriCloud