Skip to content

Commit ebdfa92

Browse files
committed
[lldb] Gardening in StreamAsynchronousIO (NFC) (llvm#127717)
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)
1 parent b5c553d commit ebdfa92

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

lldb/include/lldb/Core/StreamAsynchronousIO.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@
1818
namespace lldb_private {
1919
class Debugger;
2020

21+
/// A stream meant for asynchronously printing output. Output is buffered until
22+
/// the stream is flushed or destroyed. Printing is handled by the currently
23+
/// active IOHandler, or the debugger's output or error stream if there is none.
2124
class StreamAsynchronousIO : public Stream {
2225
public:
23-
StreamAsynchronousIO(Debugger &debugger, bool for_stdout, bool colors);
26+
enum ForSTDOUT : bool {
27+
STDOUT = true,
28+
STDERR = false,
29+
};
30+
31+
StreamAsynchronousIO(Debugger &debugger, ForSTDOUT for_stdout);
2432

2533
~StreamAsynchronousIO() override;
2634

@@ -32,7 +40,7 @@ class StreamAsynchronousIO : public Stream {
3240
private:
3341
Debugger &m_debugger;
3442
std::string m_data;
35-
bool m_for_stdout;
43+
ForSTDOUT m_for_stdout;
3644
};
3745

3846
} // namespace lldb_private

lldb/source/Core/Debugger.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,13 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
13601360
}
13611361

13621362
StreamSP Debugger::GetAsyncOutputStream() {
1363-
return std::make_shared<StreamAsynchronousIO>(*this, true, GetUseColor());
1363+
return std::make_shared<StreamAsynchronousIO>(*this,
1364+
StreamAsynchronousIO::STDOUT);
13641365
}
13651366

13661367
StreamSP Debugger::GetAsyncErrorStream() {
1367-
return std::make_shared<StreamAsynchronousIO>(*this, false, GetUseColor());
1368+
return std::make_shared<StreamAsynchronousIO>(*this,
1369+
StreamAsynchronousIO::STDERR);
13681370
}
13691371

13701372
void Debugger::RequestInterrupt() {

lldb/source/Core/StreamAsynchronousIO.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
using namespace lldb;
1515
using namespace lldb_private;
1616

17-
StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
18-
bool colors)
19-
: Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
20-
m_for_stdout(for_stdout) {}
17+
StreamAsynchronousIO::StreamAsynchronousIO(
18+
Debugger &debugger, StreamAsynchronousIO::ForSTDOUT for_stdout)
19+
: Stream(0, 4, eByteOrderBig, debugger.GetUseColor()), m_debugger(debugger),
20+
m_data(), m_for_stdout(for_stdout) {}
2121

2222
StreamAsynchronousIO::~StreamAsynchronousIO() {
23-
// Flush when we destroy to make sure we display the data
23+
// Flush when we destroy to make sure we display the data.
2424
Flush();
2525
}
2626

2727
void StreamAsynchronousIO::Flush() {
2828
if (!m_data.empty()) {
2929
m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
30-
m_data = std::string();
30+
m_data.clear();
3131
}
3232
}
3333

0 commit comments

Comments
 (0)