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(); }
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(); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits