From 5406f11a2b77b1088f8d9b9a525f25b204cfbad7 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 22 Feb 2024 17:30:39 +0100 Subject: [PATCH] Debugger: Robustify lldb line parser The original version might have missed to recognize a @\r\n combination or multi-byte UTF-8 code units when they were split across to readyRead() handlers. Change-Id: Ib543fa0070b63d25b44be429a3759964d65e878e Reviewed-by: Marcus Tillmanns Reviewed-by: Alessandro Portale Reviewed-by: --- src/plugins/debugger/lldb/lldbengine.cpp | 25 ++++++++++++++---------- src/plugins/debugger/lldb/lldbengine.h | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp index deb42544a87..1bb409bf948 100644 --- a/src/plugins/debugger/lldb/lldbengine.cpp +++ b/src/plugins/debugger/lldb/lldbengine.cpp @@ -841,18 +841,23 @@ void LldbEngine::readLldbStandardError() void LldbEngine::readLldbStandardOutput() { - QByteArray outba = m_lldbProc.readAllRawStandardOutput(); - outba.replace("\r\n", "\n"); - QString out = QString::fromUtf8(outba); - showMessage(out, LogOutput); + const QByteArray out = m_lldbProc.readAllRawStandardOutput(); + showMessage(QString::fromUtf8(out), LogOutput); m_inbuffer.append(out); while (true) { - int pos = m_inbuffer.indexOf("@\n"); - if (pos == -1) - break; - QString response = m_inbuffer.left(pos).trimmed(); - m_inbuffer = m_inbuffer.mid(pos + 2); - emit outputReady(response); + if (int pos = m_inbuffer.indexOf("@\n"); pos >= 0) { + const QByteArray response = m_inbuffer.left(pos).trimmed(); + m_inbuffer = m_inbuffer.mid(pos + 2); + emit outputReady(QString::fromUtf8(response)); + continue; + } + if (int pos = m_inbuffer.indexOf("@\r\n"); pos >= 0) { + const QByteArray response = m_inbuffer.left(pos).trimmed(); + m_inbuffer = m_inbuffer.mid(pos + 3); + emit outputReady(QString::fromUtf8(response)); + continue; + } + break; } } diff --git a/src/plugins/debugger/lldb/lldbengine.h b/src/plugins/debugger/lldb/lldbengine.h index db11af9c104..57cbd1e7c75 100644 --- a/src/plugins/debugger/lldb/lldbengine.h +++ b/src/plugins/debugger/lldb/lldbengine.h @@ -111,7 +111,7 @@ private: private: DebuggerCommand m_lastDebuggableCommand; - QString m_inbuffer; + QByteArray m_inbuffer; QString m_scriptFileName; Utils::Process m_lldbProc;