[Lldb-commits] [PATCH] D126081: [lldb] Fix spurious lldb_assert in PrintCommandOutput
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri May 20 11:46:46 PDT 2022
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, teemperor, mib.
Herald added a project: All.
JDevlieghere requested review of this revision.
When the string passed to PrintCommandOutput doesn't end with a newline, `writte`n will exceed `size` and result in an lldbassert. After 8e776bb660dda6c51ce7ca6cea641db1f47aa9cf <https://reviews.llvm.org/rG8e776bb660dda6c51ce7ca6cea641db1f47aa9cf> we don't really need `written` anymore and we can check whether `str` is empty instead.
https://reviews.llvm.org/D126081
Files:
lldb/source/Interpreter/CommandInterpreter.cpp
Index: lldb/source/Interpreter/CommandInterpreter.cpp
===================================================================
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2989,22 +2989,18 @@
lldb::StreamFileSP stream = is_stdout ? io_handler.GetOutputStreamFileSP()
: io_handler.GetErrorStreamFileSP();
// Split the output into lines and poll for interrupt requests
- size_t size = str.size();
- while (size > 0 && !WasInterrupted()) {
+ while (!str.empty() && !WasInterrupted()) {
llvm::StringRef line;
- size_t written = 0;
std::tie(line, str) = str.split('\n');
{
std::lock_guard<std::recursive_mutex> guard(io_handler.GetOutputMutex());
- written += stream->Write(line.data(), line.size());
- written += stream->Write("\n", 1);
+ stream->Write(line.data(), line.size());
+ stream->Write("\n", 1);
}
- lldbassert(size >= written);
- size -= written;
}
std::lock_guard<std::recursive_mutex> guard(io_handler.GetOutputMutex());
- if (size > 0)
+ if (!str.empty())
stream->Printf("\n... Interrupted.\n");
stream->Flush();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126081.431015.patch
Type: text/x-patch
Size: 1206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220520/f16025d8/attachment.bin>
More information about the lldb-commits
mailing list