Index: lldb/include/lldb/Core/IOHandler.h =================================================================== --- lldb/include/lldb/Core/IOHandler.h +++ lldb/include/lldb/Core/IOHandler.h @@ -34,7 +34,7 @@ namespace repro { class DataRecorder; } -} +} // namespace lldb_private namespace curses { class Application; Index: lldb/source/Core/IOHandler.cpp =================================================================== --- lldb/source/Core/IOHandler.cpp +++ lldb/source/Core/IOHandler.cpp @@ -362,17 +362,22 @@ if (prompt == nullptr) prompt = GetPrompt(); - if (prompt && prompt[0]) { - if (m_output_sp) { - m_output_sp->Printf("%s", prompt); - m_output_sp->Flush(); - } + if (prompt && prompt[0] && m_output_sp) { + m_output_sp->Printf("%s", prompt); + m_output_sp->Flush(); } } Optional got_line = SplitLine(m_line_buffer); - if (!got_line && !m_input_sp) { + if (got_line) { + line = got_line.getValue(); + if (m_data_recorder) + m_data_recorder->Record(line, true); + return true; + } + + if (!m_input_sp) { // No more input file, we are done... SetIsDone(true); return false; @@ -381,24 +386,8 @@ FILE *in = GetInputFILE(); char buffer[256]; - if (!got_line && !in && m_input_sp) { - // there is no FILE*, fall back on just reading bytes from the stream. - while (!got_line) { - size_t bytes_read = sizeof(buffer); - Status error = m_input_sp->Read((void *)buffer, bytes_read); - if (error.Success() && !bytes_read) { - got_line = SplitLineEOF(m_line_buffer); - break; - } - if (error.Fail()) - break; - m_line_buffer += StringRef(buffer, bytes_read); - got_line = SplitLine(m_line_buffer); - } - } - - if (!got_line && in) { - while (!got_line) { + if (in) { + do { char *r = fgets(buffer, sizeof(buffer), in); #ifdef _WIN32 // ReadFile on Windows is supposed to set ERROR_OPERATION_ABORTED @@ -422,16 +411,30 @@ } m_line_buffer += buffer; got_line = SplitLine(m_line_buffer); - } + } while (!got_line); + } else { + // there is no FILE*, fall back on just reading bytes from the stream. + do { + size_t bytes_read = sizeof(buffer); + Status error = m_input_sp->Read((void *)buffer, bytes_read); + if (error.Success() && !bytes_read) { + got_line = SplitLineEOF(m_line_buffer); + break; + } + if (error.Fail()) + return false; + m_line_buffer += StringRef(buffer, bytes_read); + got_line = SplitLine(m_line_buffer); + } while (!got_line); } - if (got_line) { - line = got_line.getValue(); - if (m_data_recorder) - m_data_recorder->Record(line, true); - } + if (!got_line) + return false; - return (bool)got_line; + line = got_line.getValue(); + if (m_data_recorder) + m_data_recorder->Record(line, true); + return true; } #if LLDB_ENABLE_LIBEDIT