-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[lldb] Gardening in StreamAsynchronousIO (NFC) #127717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JDevlieghere
merged 1 commit into
llvm:main
from
JDevlieghere:StreamAsynchronousIO-gardening
Feb 19, 2025
Merged
[lldb] Gardening in StreamAsynchronousIO (NFC) #127717
JDevlieghere
merged 1 commit into
llvm:main
from
JDevlieghere:StreamAsynchronousIO-gardening
Feb 19, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A handful of minor improvements to StreamAsynchronousIO: - Document the class. - Use a named enum value to distinguishing between stdout and stderr. - Add missing period to comment. - Clear the string instead of assigning to it.
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesA handful of minor improvements to StreamAsynchronousIO:
Full diff: https://github.com/llvm/llvm-project/pull/127717.diff 3 Files Affected:
diff --git a/lldb/include/lldb/Core/StreamAsynchronousIO.h b/lldb/include/lldb/Core/StreamAsynchronousIO.h
index b7adbc42096ce..7ae65757e2d73 100644
--- a/lldb/include/lldb/Core/StreamAsynchronousIO.h
+++ b/lldb/include/lldb/Core/StreamAsynchronousIO.h
@@ -18,9 +18,17 @@
namespace lldb_private {
class Debugger;
+/// A stream meant for asynchronously printing output. Output is buffered until
+/// the stream is flushed or destroyed. Printing is handled by the currently
+/// active IOHandler, or the debugger's output or error stream if there is none.
class StreamAsynchronousIO : public Stream {
public:
- StreamAsynchronousIO(Debugger &debugger, bool for_stdout, bool colors);
+ enum ForSTDOUT : bool {
+ STDOUT = true,
+ STDERR = false,
+ };
+
+ StreamAsynchronousIO(Debugger &debugger, ForSTDOUT for_stdout);
~StreamAsynchronousIO() override;
@@ -32,7 +40,7 @@ class StreamAsynchronousIO : public Stream {
private:
Debugger &m_debugger;
std::string m_data;
- bool m_for_stdout;
+ ForSTDOUT m_for_stdout;
};
} // namespace lldb_private
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 18569e155b517..b8a0436e14968 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1321,11 +1321,13 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
}
StreamSP Debugger::GetAsyncOutputStream() {
- return std::make_shared<StreamAsynchronousIO>(*this, true, GetUseColor());
+ return std::make_shared<StreamAsynchronousIO>(*this,
+ StreamAsynchronousIO::STDOUT);
}
StreamSP Debugger::GetAsyncErrorStream() {
- return std::make_shared<StreamAsynchronousIO>(*this, false, GetUseColor());
+ return std::make_shared<StreamAsynchronousIO>(*this,
+ StreamAsynchronousIO::STDERR);
}
void Debugger::RequestInterrupt() {
diff --git a/lldb/source/Core/StreamAsynchronousIO.cpp b/lldb/source/Core/StreamAsynchronousIO.cpp
index c2c64b61ab726..dbd56a69675b4 100644
--- a/lldb/source/Core/StreamAsynchronousIO.cpp
+++ b/lldb/source/Core/StreamAsynchronousIO.cpp
@@ -14,20 +14,20 @@
using namespace lldb;
using namespace lldb_private;
-StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
- bool colors)
- : Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
- m_for_stdout(for_stdout) {}
+StreamAsynchronousIO::StreamAsynchronousIO(
+ Debugger &debugger, StreamAsynchronousIO::ForSTDOUT for_stdout)
+ : Stream(0, 4, eByteOrderBig, debugger.GetUseColor()), m_debugger(debugger),
+ m_data(), m_for_stdout(for_stdout) {}
StreamAsynchronousIO::~StreamAsynchronousIO() {
- // Flush when we destroy to make sure we display the data
+ // Flush when we destroy to make sure we display the data.
Flush();
}
void StreamAsynchronousIO::Flush() {
if (!m_data.empty()) {
m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
- m_data = std::string();
+ m_data.clear();
}
}
|
labath
approved these changes
Feb 19, 2025
JDevlieghere
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Mar 27, 2025
A handful of minor improvements to StreamAsynchronousIO: - Document the class. - Use a named enum value to distinguishing between stdout and stderr. - Add missing period to comment. - Clear the string instead of assigning to it. - Eliminate color argument. (cherry picked from commit 70e693c)
JDevlieghere
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Mar 28, 2025
A handful of minor improvements to StreamAsynchronousIO: - Document the class. - Use a named enum value to distinguishing between stdout and stderr. - Add missing period to comment. - Clear the string instead of assigning to it. - Eliminate color argument. (cherry picked from commit 70e693c)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A handful of minor improvements to StreamAsynchronousIO: