From 62e0f4606bf9ae0788ccb121a0015cae403b08e1 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 30 May 2012 12:12:29 +0200 Subject: [PATCH] debugger: more precise matching for connection error messages Change-Id: Icd1821b4ded70242d8a7e09463461d340f277f6b Reviewed-by: hjk --- src/plugins/debugger/gdb/gdbengine.cpp | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 389551558e2..7d3c1de5c00 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -386,24 +386,37 @@ static bool isNameChar(char c) return (c >= 'a' && c <= 'z') || c == '-'; } +static bool contains(const QByteArray &message, const char *pattern, int size) +{ + const int s = message.size(); + if (s < size) + return false; + const int pos = message.indexOf(pattern); + if (pos == -1) + return false; + if (pos != 0 && message.at(pos - 1) != '\n') + return false; + if (pos + size != s && message.at(pos + size + 1) != '\n') + return false; + return true; +} + static bool isGdbConnectionError(const QByteArray &message) { - // // Handle messages gdb client produces when the target exits (gdbserver) // // we get this as response either to a specific command, e.g. // 31^error,msg="Remote connection closed" // or as informative output: // &Remote connection closed - // - const QByteArray trimmed = message.trimmed(); - if (trimmed == "Remote connection closed" - || trimmed == "Remote communication error. " - "Target disconnected.: No error." - || trimmed == "Quit") { - return true; - } - return false; + + const char msg1[] = "Remote connection closed"; + const char msg2[] = "Remote communication error. Target disconnected.: No error."; + const char msg3[] = "Quit"; + + return contains(message, msg1, sizeof(msg1) - 1) + || contains(message, msg2, sizeof(msg2) - 1) + || contains(message, msg3, sizeof(msg3) - 1); } void GdbEngine::handleResponse(const QByteArray &buff)