diff options
author | Greg Clayton <gclayton@apple.com> | 2014-07-02 21:10:39 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2014-07-02 21:10:39 +0000 |
commit | 100eb93f89cc8d9a177e0af7aca8e778a24d62de (patch) | |
tree | 97b75bdf6c52f34ee43ca0a3b3047ef1879a6035 /lldb/source/Interpreter/ScriptInterpreterPython.cpp | |
parent | ac64d2b064e18604525d6cd6ea08654dcf961a43 (diff) | |
download | bcm5719-llvm-100eb93f89cc8d9a177e0af7aca8e778a24d62de.tar.gz bcm5719-llvm-100eb93f89cc8d9a177e0af7aca8e778a24d62de.zip |
Add host layer support for pipes.
Windows does support pipes, but they do so in a slightly different way. Added a Host layer which abstracts the use of pipes into a new Pipe class that everyone can use.
Windows benefits include:
- Being able to interrupt running processes when IO is directly hooked up
- being able to interrupt long running python scripts
- being able to interrupt anything based on ConnectionFileDescriptor
llvm-svn: 212220
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp')
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index ef0d71b5c6f..8120c4b3562 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -32,6 +32,7 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/Timer.h" #include "lldb/Host/Host.h" +#include "lldb/Host/Pipe.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/PythonDataObjects.h" @@ -580,8 +581,7 @@ ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObjec StreamFileSP output_file_sp; StreamFileSP error_file_sp; Communication output_comm ("lldb.ScriptInterpreterPython.ExecuteOneLine.comm"); - int pipe_fds[2] = { -1, -1 }; - + bool join_read_thread = false; if (options.GetEnableIO()) { if (result) @@ -589,21 +589,17 @@ ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObjec input_file_sp = debugger.GetInputFile(); // Set output to a temporary file so we can forward the results on to the result object -#ifdef _MSC_VER - // pipe is not supported on windows so default to a fail condition - int err = 1; -#else - int err = pipe(pipe_fds); -#endif - if (err == 0) + Pipe pipe; + if (pipe.Open()) { - std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor(pipe_fds[0], true)); + std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor(pipe.ReleaseReadFileDescriptor(), true)); if (conn_ap->IsConnected()) { output_comm.SetConnection(conn_ap.release()); output_comm.SetReadThreadBytesReceivedCallback(ReadThreadBytesReceived, &result->GetOutputStream()); output_comm.StartReadThread(); - FILE *outfile_handle = fdopen (pipe_fds[1], "w"); + join_read_thread = true; + FILE *outfile_handle = fdopen (pipe.ReleaseWriteFileDescriptor(), "w"); output_file_sp.reset(new StreamFile(outfile_handle, true)); error_file_sp = output_file_sp; if (outfile_handle) @@ -672,7 +668,7 @@ ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObjec if (out_file != err_file) ::fflush (err_file); - if (pipe_fds[0] != -1) + if (join_read_thread) { // Close the write end of the pipe since we are done with our // one line script. This should cause the read thread that |