debugger: more precise matching for connection error messages

Change-Id: Icd1821b4ded70242d8a7e09463461d340f277f6b
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2012-05-30 12:12:29 +02:00
committed by hjk
parent 6d04f3ce25
commit 62e0f4606b

View File

@@ -386,24 +386,37 @@ static bool isNameChar(char c)
return (c >= 'a' && c <= 'z') || 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) static bool isGdbConnectionError(const QByteArray &message)
{ {
//
// Handle messages gdb client produces when the target exits (gdbserver) // Handle messages gdb client produces when the target exits (gdbserver)
// //
// we get this as response either to a specific command, e.g. // we get this as response either to a specific command, e.g.
// 31^error,msg="Remote connection closed" // 31^error,msg="Remote connection closed"
// or as informative output: // or as informative output:
// &Remote connection closed // &Remote connection closed
//
const QByteArray trimmed = message.trimmed(); const char msg1[] = "Remote connection closed";
if (trimmed == "Remote connection closed" const char msg2[] = "Remote communication error. Target disconnected.: No error.";
|| trimmed == "Remote communication error. " const char msg3[] = "Quit";
"Target disconnected.: No error."
|| trimmed == "Quit") { return contains(message, msg1, sizeof(msg1) - 1)
return true; || contains(message, msg2, sizeof(msg2) - 1)
} || contains(message, msg3, sizeof(msg3) - 1);
return false;
} }
void GdbEngine::handleResponse(const QByteArray &buff) void GdbEngine::handleResponse(const QByteArray &buff)