class ScriptInterpreterIORedirect {
public:
- /// Create an IO redirect with /dev/null as input, output and error file.
- static llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>> Create();
-
- /// Create an IO redirect that redirects the output to the command return
- /// object if set or to the debugger otherwise.
+ /// Create an IO redirect. If IO is enabled, this will redirects the output
+ /// to the command return object if set or to the debugger otherwise. If IO
+ /// is disabled, it will redirect all IO to /dev/null.
static llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
- Create(Debugger &debugger, CommandReturnObject *result);
+ Create(bool enable_io, Debugger &debugger, CommandReturnObject *result);
~ScriptInterpreterIORedirect();
}
llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
-ScriptInterpreterIORedirect::Create() {
+ScriptInterpreterIORedirect::Create(bool enable_io, Debugger &debugger,
+ CommandReturnObject *result) {
+ if (enable_io)
+ return std::unique_ptr<ScriptInterpreterIORedirect>(
+ new ScriptInterpreterIORedirect(debugger, result));
+
auto nullin = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL),
File::eOpenOptionRead);
if (!nullin)
new ScriptInterpreterIORedirect(std::move(*nullin), std::move(*nullout)));
}
-llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
-ScriptInterpreterIORedirect::Create(Debugger &debugger,
- CommandReturnObject *result) {
- return std::unique_ptr<ScriptInterpreterIORedirect>(
- new ScriptInterpreterIORedirect(debugger, result));
-}
-
ScriptInterpreterIORedirect::ScriptInterpreterIORedirect(
std::unique_ptr<File> input, std::unique_ptr<File> output)
: m_input_file_sp(std::move(input)),
// we use the following more complicated method to pass the command string
// directly down to Python.
llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
- io_redirect_or_error =
- options.GetEnableIO()
- ? ScriptInterpreterIORedirect::Create(m_debugger, result)
- : ScriptInterpreterIORedirect::Create();
+ io_redirect_or_error = ScriptInterpreterIORedirect::Create(
+ options.GetEnableIO(), m_debugger, result);
if (!io_redirect_or_error) {
if (result)
result->AppendErrorWithFormatv(