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/Commands/CommandObjectTarget.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/Commands/CommandObjectTarget.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 71ddc8d..bd9470b 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -57,6 +57,7 @@ #include "lldb/Utility/Timer.h" #include "lldb/ValueObject/ValueObjectVariable.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" #include "lldb/lldb-private-enumerations.h" #include "clang/Frontend/CompilerInstance.h" @@ -4923,11 +4924,13 @@ Filter Options: protected: void IOHandlerActivated(IOHandler &io_handler, bool interactive) override { - StreamFileSP output_sp(io_handler.GetOutputStreamFileSP()); - if (output_sp && interactive) { - output_sp->PutCString( - "Enter your stop hook command(s). Type 'DONE' to end.\n"); - output_sp->Flush(); + if (interactive) { + if (lldb::LockableStreamFileSP output_sp = + io_handler.GetOutputStreamFileSP()) { + LockedStreamFile locked_stream = output_sp->Lock(); + locked_stream.PutCString( + "Enter your stop hook command(s). Type 'DONE' to end.\n"); + } } } @@ -4935,12 +4938,12 @@ protected: std::string &line) override { if (m_stop_hook_sp) { if (line.empty()) { - StreamFileSP error_sp(io_handler.GetErrorStreamFileSP()); - if (error_sp) { - error_sp->Printf("error: stop hook #%" PRIu64 - " aborted, no commands.\n", - m_stop_hook_sp->GetID()); - error_sp->Flush(); + if (lldb::LockableStreamFileSP error_sp = + io_handler.GetErrorStreamFileSP()) { + LockedStreamFile locked_stream = error_sp->Lock(); + locked_stream.Printf("error: stop hook #%" PRIu64 + " aborted, no commands.\n", + m_stop_hook_sp->GetID()); } GetTarget().UndoCreateStopHook(m_stop_hook_sp->GetID()); } else { @@ -4949,11 +4952,11 @@ protected: static_cast<Target::StopHookCommandLine *>(m_stop_hook_sp.get()); hook_ptr->SetActionFromString(line); - StreamFileSP output_sp(io_handler.GetOutputStreamFileSP()); - if (output_sp) { - output_sp->Printf("Stop hook #%" PRIu64 " added.\n", - m_stop_hook_sp->GetID()); - output_sp->Flush(); + if (lldb::LockableStreamFileSP output_sp = + io_handler.GetOutputStreamFileSP()) { + LockedStreamFile locked_stream = output_sp->Lock(); + locked_stream.Printf("Stop hook #%" PRIu64 " added.\n", + m_stop_hook_sp->GetID()); } } m_stop_hook_sp.reset(); |