diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -647,6 +647,34 @@ } } + // Check if we have an unexpected byte and we need to flush all bad data + // that is in m_bytes, so we need to find the first byte that is a '+' + // (ACK), '-' (NACK), \x03 (CTRL+C interrupt), or '$' character (start of + // packet header) or of course, the end of the data in m_bytes... + const size_t bytes_len = m_bytes.size(); + bool done = false; + uint32_t idx; + for (idx = 0; !done && idx < bytes_len;) { + switch (m_bytes[idx]) { + case '+': + case '-': + case '\x03': + case '%': + case '$': + done = true; + break; + + default: + ++idx; + break; + } + } + if (idx) { + LLDB_LOGF(log, "GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'", + __FUNCTION__, idx, idx, m_bytes.c_str()); + m_bytes.erase(0, idx); + } + switch (m_bytes[0]) { case '+': // Look for ack case '-': // Look for cancel @@ -681,32 +709,9 @@ } break; - default: { - // We have an unexpected byte and we need to flush all bad data that is - // in m_bytes, so we need to find the first byte that is a '+' (ACK), '-' - // (NACK), \x03 (CTRL+C interrupt), or '$' character (start of packet - // header) or of course, the end of the data in m_bytes... - const size_t bytes_len = m_bytes.size(); - bool done = false; - uint32_t idx; - for (idx = 1; !done && idx < bytes_len; ++idx) { - switch (m_bytes[idx]) { - case '+': - case '-': - case '\x03': - case '%': - case '$': - done = true; - break; - - default: - break; - } - } - LLDB_LOGF(log, "GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'", - __FUNCTION__, idx - 1, idx - 1, m_bytes.c_str()); - m_bytes.erase(0, idx - 1); - } break; + default: + // no more bytes after junk + break; } if (content_length == std::string::npos) {