diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2025-02-19 20:32:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-19 20:32:00 -0800 |
commit | 58279d1ee1b567e8ca793d6d1eb6e0f1d5e7279e (patch) | |
tree | 4e1c25b423d78f003b9a781d7753600867465b9f /lldb/source/Interpreter/ScriptInterpreter.cpp | |
parent | 557628dbe6a935b1ad5e1bcfd51ac3a65e35d874 (diff) | |
download | llvm-58279d1ee1b567e8ca793d6d1eb6e0f1d5e7279e.zip llvm-58279d1ee1b567e8ca793d6d1eb6e0f1d5e7279e.tar.gz llvm-58279d1ee1b567e8ca793d6d1eb6e0f1d5e7279e.tar.bz2 |
[lldb] Synchronize the debuggers output & error streams
This patch improves the synchronization of the debugger's output and error
streams using two new abstractions: `LockableStreamFile` and
`LockedStreamFile`.
- `LockableStreamFile` is a wrapper around a `StreamFile` and a mutex. Client
cannot use the `StreamFile` without calling `Lock`, which returns a
`LockedStreamFile`.
- `LockedStreamFile` is an RAII object that locks the stream for the duration
of its existence. As long as you hold on to the returned object you are
permitted to write to the stream. The destruction of the object
automatically flush the output stream.
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreter.cpp')
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreter.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp index a392d57..4424b6c 100644 --- a/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/lldb/source/Interpreter/ScriptInterpreter.cpp @@ -206,7 +206,8 @@ ScriptInterpreterIORedirect::Create(bool enable_io, Debugger &debugger, ScriptInterpreterIORedirect::ScriptInterpreterIORedirect( std::unique_ptr<File> input, std::unique_ptr<File> output) : m_input_file_sp(std::move(input)), - m_output_file_sp(std::make_shared<StreamFile>(std::move(output))), + m_output_file_sp(std::make_shared<LockableStreamFile>(std::move(output), + m_output_mutex)), m_error_file_sp(m_output_file_sp), m_communication("lldb.ScriptInterpreterIORedirect.comm"), m_disconnect(false) {} @@ -240,7 +241,9 @@ ScriptInterpreterIORedirect::ScriptInterpreterIORedirect( m_disconnect = true; FILE *outfile_handle = fdopen(pipe.ReleaseWriteFileDescriptor(), "w"); - m_output_file_sp = std::make_shared<StreamFile>(outfile_handle, true); + m_output_file_sp = std::make_shared<LockableStreamFile>( + std::make_shared<StreamFile>(outfile_handle, NativeFile::Owned), + m_output_mutex); m_error_file_sp = m_output_file_sp; if (outfile_handle) ::setbuf(outfile_handle, nullptr); @@ -257,9 +260,9 @@ ScriptInterpreterIORedirect::ScriptInterpreterIORedirect( void ScriptInterpreterIORedirect::Flush() { if (m_output_file_sp) - m_output_file_sp->Flush(); + m_output_file_sp->Lock().Flush(); if (m_error_file_sp) - m_error_file_sp->Flush(); + m_error_file_sp->Lock().Flush(); } ScriptInterpreterIORedirect::~ScriptInterpreterIORedirect() { @@ -273,7 +276,7 @@ ScriptInterpreterIORedirect::~ScriptInterpreterIORedirect() { // Close the write end of the pipe since we are done with our one line // script. This should cause the read thread that output_comm is using to // exit. - m_output_file_sp->GetFile().Close(); + m_output_file_sp->GetUnlockedFile().Close(); // The close above should cause this thread to exit when it gets to the end // of file, so let it get all its data. m_communication.JoinReadThread(); |