2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2013-01-24 10:38:40 +01:00
|
|
|
#include "debuggerprotocol.h"
|
2008-12-09 16:18:28 +01:00
|
|
|
|
2013-01-24 11:19:15 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDateTime>
|
2012-04-17 08:01:25 +02:00
|
|
|
#include <QDebug>
|
2013-07-09 14:19:45 -07:00
|
|
|
#include <QHostAddress>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-04 20:49:40 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2013-06-20 12:14:30 +02:00
|
|
|
uchar fromhex(uchar c)
|
|
|
|
|
{
|
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
|
return c - '0';
|
|
|
|
|
if (c >= 'a' && c <= 'z')
|
|
|
|
|
return 10 + c - 'a';
|
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
|
return 10 + c - 'A';
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-10 13:51:42 +01:00
|
|
|
void skipCommas(const char *&from, const char *to)
|
|
|
|
|
{
|
|
|
|
|
while (*from == ',' && from != to)
|
|
|
|
|
++from;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-23 14:34:01 +01:00
|
|
|
QTextStream &operator<<(QTextStream &os, const GdbMi &mi)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return os << mi.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-21 11:12:12 +01:00
|
|
|
void GdbMi::parseResultOrValue(const char *&from, const char *to)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-04 20:49:40 +02:00
|
|
|
while (from != to && isspace(*from))
|
2008-12-02 12:01:29 +01:00
|
|
|
++from;
|
|
|
|
|
|
2009-01-21 11:12:12 +01:00
|
|
|
//qDebug() << "parseResultOrValue: " << QByteArray(from, to - from);
|
2008-12-02 12:01:29 +01:00
|
|
|
parseValue(from, to);
|
|
|
|
|
if (isValid()) {
|
2009-05-18 14:15:25 +02:00
|
|
|
//qDebug() << "no valid result in " << QByteArray(from, to - from);
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (from == to || *from == '(')
|
|
|
|
|
return;
|
2009-01-21 11:12:12 +01:00
|
|
|
const char *ptr = from;
|
2008-12-02 12:01:29 +01:00
|
|
|
while (ptr < to && *ptr != '=') {
|
|
|
|
|
//qDebug() << "adding" << QChar(*ptr) << "to name";
|
|
|
|
|
++ptr;
|
|
|
|
|
}
|
|
|
|
|
m_name = QByteArray(from, ptr - from);
|
|
|
|
|
from = ptr;
|
|
|
|
|
if (from < to && *from == '=') {
|
|
|
|
|
++from;
|
|
|
|
|
parseValue(from, to);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-21 11:12:12 +01:00
|
|
|
QByteArray GdbMi::parseCString(const char *&from, const char *to)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
QByteArray result;
|
2009-05-18 14:15:25 +02:00
|
|
|
//qDebug() << "parseCString: " << QByteArray(from, to - from);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (*from != '"') {
|
|
|
|
|
qDebug() << "MI Parse Error, double quote expected";
|
2009-05-04 20:49:40 +02:00
|
|
|
++from; // So we don't hang
|
2008-12-02 12:01:29 +01:00
|
|
|
return QByteArray();
|
|
|
|
|
}
|
2009-01-21 11:12:12 +01:00
|
|
|
const char *ptr = from;
|
2008-12-02 12:01:29 +01:00
|
|
|
++ptr;
|
|
|
|
|
while (ptr < to) {
|
|
|
|
|
if (*ptr == '"') {
|
|
|
|
|
++ptr;
|
|
|
|
|
result = QByteArray(from + 1, ptr - from - 2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-05-04 20:49:40 +02:00
|
|
|
if (*ptr == '\\') {
|
2008-12-02 12:01:29 +01:00
|
|
|
++ptr;
|
2009-05-04 20:49:40 +02:00
|
|
|
if (ptr == to) {
|
|
|
|
|
qDebug() << "MI Parse Error, unterminated backslash escape";
|
|
|
|
|
from = ptr; // So we don't hang
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
++ptr;
|
|
|
|
|
}
|
2009-05-04 20:49:40 +02:00
|
|
|
from = ptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-04 20:49:40 +02:00
|
|
|
int idx = result.indexOf('\\');
|
|
|
|
|
if (idx >= 0) {
|
|
|
|
|
char *dst = result.data() + idx;
|
|
|
|
|
const char *src = dst + 1, *end = result.data() + result.length();
|
|
|
|
|
do {
|
|
|
|
|
char c = *src++;
|
|
|
|
|
switch (c) {
|
|
|
|
|
case 'a': *dst++ = '\a'; break;
|
|
|
|
|
case 'b': *dst++ = '\b'; break;
|
|
|
|
|
case 'f': *dst++ = '\f'; break;
|
|
|
|
|
case 'n': *dst++ = '\n'; break;
|
|
|
|
|
case 'r': *dst++ = '\r'; break;
|
|
|
|
|
case 't': *dst++ = '\t'; break;
|
|
|
|
|
case 'v': *dst++ = '\v'; break;
|
|
|
|
|
case '"': *dst++ = '"'; break;
|
|
|
|
|
case '\\': *dst++ = '\\'; break;
|
2013-06-20 12:14:30 +02:00
|
|
|
case 'x': {
|
|
|
|
|
c = *src++;
|
|
|
|
|
int chars = 0;
|
|
|
|
|
uchar prod = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
uchar val = fromhex(c);
|
|
|
|
|
if (val == uchar(-1))
|
|
|
|
|
break;
|
|
|
|
|
prod = prod * 16 + val;
|
|
|
|
|
if (++chars == 3 || src == end)
|
|
|
|
|
break;
|
|
|
|
|
c = *src++;
|
|
|
|
|
}
|
|
|
|
|
if (!chars) {
|
|
|
|
|
qDebug() << "MI Parse Error, unrecognized hex escape";
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
*dst++ = prod;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-05-04 20:49:40 +02:00
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
int chars = 0;
|
|
|
|
|
uchar prod = 0;
|
|
|
|
|
forever {
|
|
|
|
|
if (c < '0' || c > '7') {
|
|
|
|
|
--src;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
prod = prod * 8 + c - '0';
|
|
|
|
|
if (++chars == 3 || src == end)
|
|
|
|
|
break;
|
|
|
|
|
c = *src++;
|
|
|
|
|
}
|
|
|
|
|
if (!chars) {
|
|
|
|
|
qDebug() << "MI Parse Error, unrecognized backslash escape";
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
*dst++ = prod;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (src != end) {
|
|
|
|
|
char c = *src++;
|
|
|
|
|
if (c == '\\')
|
|
|
|
|
break;
|
|
|
|
|
*dst++ = c;
|
|
|
|
|
}
|
|
|
|
|
} while (src != end);
|
|
|
|
|
*dst = 0;
|
|
|
|
|
result.truncate(dst - result.data());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-21 11:12:12 +01:00
|
|
|
void GdbMi::parseValue(const char *&from, const char *to)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-18 14:15:25 +02:00
|
|
|
//qDebug() << "parseValue: " << QByteArray(from, to - from);
|
2008-12-02 12:01:29 +01:00
|
|
|
switch (*from) {
|
2009-04-06 14:33:45 +02:00
|
|
|
case '{':
|
|
|
|
|
parseTuple(from, to);
|
|
|
|
|
break;
|
|
|
|
|
case '[':
|
|
|
|
|
parseList(from, to);
|
|
|
|
|
break;
|
|
|
|
|
case '"':
|
|
|
|
|
m_type = Const;
|
|
|
|
|
m_data = parseCString(from, to);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-21 11:12:12 +01:00
|
|
|
void GdbMi::parseTuple(const char *&from, const char *to)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-18 14:15:25 +02:00
|
|
|
//qDebug() << "parseTuple: " << QByteArray(from, to - from);
|
2013-01-24 11:19:15 +01:00
|
|
|
//QTC_CHECK(*from == '{');
|
2008-12-02 12:01:29 +01:00
|
|
|
++from;
|
|
|
|
|
parseTuple_helper(from, to);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-21 11:12:12 +01:00
|
|
|
void GdbMi::parseTuple_helper(const char *&from, const char *to)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-10 13:51:42 +01:00
|
|
|
skipCommas(from, to);
|
2009-05-18 14:15:25 +02:00
|
|
|
//qDebug() << "parseTuple_helper: " << QByteArray(from, to - from);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_type = Tuple;
|
|
|
|
|
while (from < to) {
|
|
|
|
|
if (*from == '}') {
|
|
|
|
|
++from;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
GdbMi child;
|
|
|
|
|
child.parseResultOrValue(from, to);
|
|
|
|
|
//qDebug() << "\n=======\n" << qPrintable(child.toString()) << "\n========\n";
|
|
|
|
|
if (!child.isValid())
|
|
|
|
|
return;
|
|
|
|
|
m_children += child;
|
2010-02-10 13:51:42 +01:00
|
|
|
skipCommas(from, to);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-21 11:12:12 +01:00
|
|
|
void GdbMi::parseList(const char *&from, const char *to)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-18 14:15:25 +02:00
|
|
|
//qDebug() << "parseList: " << QByteArray(from, to - from);
|
2013-01-24 11:19:15 +01:00
|
|
|
//QTC_CHECK(*from == '[');
|
2008-12-02 12:01:29 +01:00
|
|
|
++from;
|
|
|
|
|
m_type = List;
|
2010-02-10 13:51:42 +01:00
|
|
|
skipCommas(from, to);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (from < to) {
|
|
|
|
|
if (*from == ']') {
|
|
|
|
|
++from;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
GdbMi child;
|
|
|
|
|
child.parseResultOrValue(from, to);
|
|
|
|
|
if (child.isValid())
|
|
|
|
|
m_children += child;
|
2010-02-10 13:51:42 +01:00
|
|
|
skipCommas(from, to);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QByteArray ind(int indent)
|
|
|
|
|
{
|
|
|
|
|
return QByteArray(2 * indent, ' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbMi::dumpChildren(QByteArray * str, bool multiline, int indent) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_children.size(); ++i) {
|
|
|
|
|
if (i != 0) {
|
|
|
|
|
*str += ',';
|
|
|
|
|
if (multiline)
|
|
|
|
|
*str += '\n';
|
|
|
|
|
}
|
|
|
|
|
if (multiline)
|
|
|
|
|
*str += ind(indent);
|
|
|
|
|
*str += m_children.at(i).toString(multiline, indent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-24 10:25:32 +02:00
|
|
|
QByteArray GdbMi::escapeCString(const QByteArray &ba)
|
2009-04-06 14:47:15 +02:00
|
|
|
{
|
2012-08-24 10:25:32 +02:00
|
|
|
QByteArray ret;
|
2009-05-04 20:49:40 +02:00
|
|
|
ret.reserve(ba.length() * 2);
|
|
|
|
|
for (int i = 0; i < ba.length(); ++i) {
|
2012-08-24 10:25:32 +02:00
|
|
|
const uchar c = ba.at(i);
|
2009-05-04 20:49:40 +02:00
|
|
|
switch (c) {
|
2012-08-24 10:25:32 +02:00
|
|
|
case '\\': ret += "\\\\"; break;
|
|
|
|
|
case '\a': ret += "\\a"; break;
|
|
|
|
|
case '\b': ret += "\\b"; break;
|
|
|
|
|
case '\f': ret += "\\f"; break;
|
|
|
|
|
case '\n': ret += "\\n"; break;
|
|
|
|
|
case '\r': ret += "\\r"; break;
|
|
|
|
|
case '\t': ret += "\\t"; break;
|
|
|
|
|
case '\v': ret += "\\v"; break;
|
|
|
|
|
case '"': ret += "\\\""; break;
|
2009-05-04 20:49:40 +02:00
|
|
|
default:
|
|
|
|
|
if (c < 32 || c == 127) {
|
2012-08-24 10:25:32 +02:00
|
|
|
ret += '\\';
|
|
|
|
|
ret += ('0' + (c >> 6));
|
|
|
|
|
ret += ('0' + ((c >> 3) & 7));
|
|
|
|
|
ret += ('0' + (c & 7));
|
2009-05-04 20:49:40 +02:00
|
|
|
} else {
|
2012-08-24 10:25:32 +02:00
|
|
|
ret += c;
|
2009-05-04 20:49:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
2009-04-06 14:47:15 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QByteArray GdbMi::toString(bool multiline, int indent) const
|
|
|
|
|
{
|
|
|
|
|
QByteArray result;
|
|
|
|
|
switch (m_type) {
|
2009-04-06 14:33:45 +02:00
|
|
|
case Invalid:
|
|
|
|
|
if (multiline)
|
|
|
|
|
result += ind(indent) + "Invalid\n";
|
|
|
|
|
else
|
|
|
|
|
result += "Invalid";
|
|
|
|
|
break;
|
2010-01-29 21:33:57 +01:00
|
|
|
case Const:
|
2009-04-06 14:33:45 +02:00
|
|
|
if (!m_name.isEmpty())
|
2010-02-02 17:09:41 +01:00
|
|
|
result += m_name + '=';
|
|
|
|
|
result += '"' + escapeCString(m_data) + '"';
|
2009-04-06 14:33:45 +02:00
|
|
|
break;
|
|
|
|
|
case Tuple:
|
|
|
|
|
if (!m_name.isEmpty())
|
2010-02-02 17:09:41 +01:00
|
|
|
result += m_name + '=';
|
2009-04-06 14:33:45 +02:00
|
|
|
if (multiline) {
|
|
|
|
|
result += "{\n";
|
|
|
|
|
dumpChildren(&result, multiline, indent + 1);
|
2010-02-02 17:09:41 +01:00
|
|
|
result += '\n' + ind(indent) + '}';
|
2009-04-06 14:33:45 +02:00
|
|
|
} else {
|
2010-02-02 17:09:41 +01:00
|
|
|
result += '{';
|
2009-04-06 14:33:45 +02:00
|
|
|
dumpChildren(&result, multiline, indent + 1);
|
2010-02-02 17:09:41 +01:00
|
|
|
result += '}';
|
2009-04-06 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case List:
|
|
|
|
|
if (!m_name.isEmpty())
|
2010-02-02 17:09:41 +01:00
|
|
|
result += m_name + '=';
|
2009-04-06 14:33:45 +02:00
|
|
|
if (multiline) {
|
|
|
|
|
result += "[\n";
|
|
|
|
|
dumpChildren(&result, multiline, indent + 1);
|
2010-02-02 17:09:41 +01:00
|
|
|
result += '\n' + ind(indent) + ']';
|
2009-04-06 14:33:45 +02:00
|
|
|
} else {
|
2010-02-02 17:09:41 +01:00
|
|
|
result += '[';
|
2009-04-06 14:33:45 +02:00
|
|
|
dumpChildren(&result, multiline, indent + 1);
|
2010-02-02 17:09:41 +01:00
|
|
|
result += ']';
|
2009-04-06 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbMi::fromString(const QByteArray &ba)
|
|
|
|
|
{
|
2009-01-21 11:12:12 +01:00
|
|
|
const char *from = ba.constBegin();
|
|
|
|
|
const char *to = ba.constEnd();
|
2008-12-02 12:01:29 +01:00
|
|
|
parseResultOrValue(from, to);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-30 15:17:34 +01:00
|
|
|
void GdbMi::fromStringMultiple(const QByteArray &ba)
|
|
|
|
|
{
|
|
|
|
|
const char *from = ba.constBegin();
|
|
|
|
|
const char *to = ba.constEnd();
|
|
|
|
|
parseTuple_helper(from, to);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-03 18:26:10 +02:00
|
|
|
GdbMi GdbMi::operator[](const char *name) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-05-03 18:26:10 +02:00
|
|
|
for (int i = 0, n = m_children.size(); i < n; ++i)
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_children.at(i).m_name == name)
|
|
|
|
|
return m_children.at(i);
|
|
|
|
|
return GdbMi();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-10 18:58:06 +02:00
|
|
|
qulonglong GdbMi::toAddress() const
|
|
|
|
|
{
|
|
|
|
|
QByteArray ba = m_data;
|
|
|
|
|
if (ba.endsWith('L'))
|
|
|
|
|
ba.chop(1);
|
|
|
|
|
if (ba.startsWith('*') || ba.startsWith('@'))
|
|
|
|
|
ba = ba.mid(1);
|
2011-05-11 15:24:50 +02:00
|
|
|
return ba.toULongLong(0, 0);
|
2011-05-10 18:58:06 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2009-09-24 11:16:00 +02:00
|
|
|
// GdbResponse
|
2008-12-02 12:01:29 +01:00
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-10-12 12:00:07 +02:00
|
|
|
QByteArray GdbResponse::stringFromResultClass(GdbResultClass resultClass)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
switch (resultClass) {
|
|
|
|
|
case GdbResultDone: return "done";
|
|
|
|
|
case GdbResultRunning: return "running";
|
|
|
|
|
case GdbResultConnected: return "connected";
|
|
|
|
|
case GdbResultError: return "error";
|
|
|
|
|
case GdbResultExit: return "exit";
|
|
|
|
|
default: return "unknown";
|
|
|
|
|
}
|
2010-12-16 12:05:48 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-09-24 11:16:00 +02:00
|
|
|
QByteArray GdbResponse::toString() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
QByteArray result;
|
|
|
|
|
if (token != -1)
|
|
|
|
|
result = QByteArray::number(token);
|
|
|
|
|
result += '^';
|
|
|
|
|
result += stringFromResultClass(resultClass);
|
|
|
|
|
if (data.isValid())
|
|
|
|
|
result += ',' + data.toString();
|
|
|
|
|
result += '\n';
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-27 15:41:52 +02:00
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// GdbResponse
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
void extractGdbVersion(const QString &msg,
|
2012-02-10 07:42:44 +01:00
|
|
|
int *gdbVersion, int *gdbBuildVersion, bool *isMacGdb, bool *isQnxGdb)
|
2010-05-27 15:41:52 +02:00
|
|
|
{
|
|
|
|
|
const QChar dot(QLatin1Char('.'));
|
|
|
|
|
|
2013-06-04 08:44:10 +02:00
|
|
|
const bool ignoreParenthesisContent = msg.contains(QLatin1String("rubenvb"));
|
|
|
|
|
const QChar parOpen(QLatin1Char('('));
|
|
|
|
|
const QChar parClose(QLatin1Char(')'));
|
|
|
|
|
|
2010-05-27 15:41:52 +02:00
|
|
|
QString cleaned;
|
|
|
|
|
QString build;
|
|
|
|
|
bool inClean = true;
|
2013-06-04 08:44:10 +02:00
|
|
|
bool inParenthesis = false;
|
2010-05-27 15:41:52 +02:00
|
|
|
foreach (QChar c, msg) {
|
|
|
|
|
if (inClean && !cleaned.isEmpty() && c != dot && (c.isPunct() || c.isSpace()))
|
|
|
|
|
inClean = false;
|
2013-06-04 08:44:10 +02:00
|
|
|
if (ignoreParenthesisContent) {
|
|
|
|
|
if (!inParenthesis && c == parOpen)
|
|
|
|
|
inParenthesis = true;
|
|
|
|
|
if (inParenthesis && c == parClose)
|
|
|
|
|
inParenthesis = false;
|
|
|
|
|
if (inParenthesis)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-05-27 15:41:52 +02:00
|
|
|
if (inClean) {
|
|
|
|
|
if (c.isDigit())
|
|
|
|
|
cleaned.append(c);
|
|
|
|
|
else if (!cleaned.isEmpty() && !cleaned.endsWith(dot))
|
|
|
|
|
cleaned.append(dot);
|
|
|
|
|
} else {
|
|
|
|
|
if (c.isDigit())
|
|
|
|
|
build.append(c);
|
|
|
|
|
else if (!build.isEmpty() && !build.endsWith(dot))
|
|
|
|
|
build.append(dot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*isMacGdb = msg.contains(QLatin1String("Apple version"));
|
2012-02-15 14:39:47 +01:00
|
|
|
*isQnxGdb = msg.contains(QLatin1String("qnx"));
|
2010-05-27 15:41:52 +02:00
|
|
|
|
|
|
|
|
*gdbVersion = 10000 * cleaned.section(dot, 0, 0).toInt()
|
|
|
|
|
+ 100 * cleaned.section(dot, 1, 1).toInt()
|
|
|
|
|
+ 1 * cleaned.section(dot, 2, 2).toInt();
|
|
|
|
|
if (cleaned.count(dot) >= 3)
|
|
|
|
|
*gdbBuildVersion = cleaned.section(dot, 3, 3).toInt();
|
|
|
|
|
else
|
|
|
|
|
*gdbBuildVersion = build.section(dot, 0, 0).toInt();
|
|
|
|
|
|
|
|
|
|
if (*isMacGdb)
|
|
|
|
|
*gdbBuildVersion = build.section(dot, 1, 1).toInt();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-24 11:19:15 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Decoding
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
static QString quoteUnprintableLatin1(const QByteArray &ba)
|
|
|
|
|
{
|
|
|
|
|
QString res;
|
|
|
|
|
char buf[10];
|
|
|
|
|
for (int i = 0, n = ba.size(); i != n; ++i) {
|
|
|
|
|
const unsigned char c = ba.at(i);
|
|
|
|
|
if (isprint(c)) {
|
|
|
|
|
res += QLatin1Char(c);
|
|
|
|
|
} else {
|
|
|
|
|
qsnprintf(buf, sizeof(buf) - 1, "\\%x", int(c));
|
|
|
|
|
res += QLatin1String(buf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QDate dateFromData(int jd)
|
|
|
|
|
{
|
|
|
|
|
return jd ? QDate::fromJulianDay(jd) : QDate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QTime timeFromData(int ms)
|
|
|
|
|
{
|
|
|
|
|
return ms == -1 ? QTime() : QTime(0, 0, 0, 0).addMSecs(ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString decodeData(const QByteArray &ba, int encoding)
|
|
|
|
|
{
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case Unencoded8Bit: // 0
|
|
|
|
|
return quoteUnprintableLatin1(ba);
|
|
|
|
|
case Base64Encoded8BitWithQuotes: { // 1, used for QByteArray
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QString rc = doubleQuote;
|
|
|
|
|
rc += quoteUnprintableLatin1(QByteArray::fromBase64(ba));
|
|
|
|
|
rc += doubleQuote;
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
case Base64Encoded16BitWithQuotes: { // 2, used for QString
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromBase64(ba);
|
|
|
|
|
QString rc = doubleQuote;
|
|
|
|
|
rc += QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2);
|
|
|
|
|
rc += doubleQuote;
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
case Base64Encoded32BitWithQuotes: { // 3
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromBase64(ba);
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QString rc = doubleQuote;
|
|
|
|
|
rc += QString::fromUcs4(reinterpret_cast<const uint *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 4);
|
|
|
|
|
rc += doubleQuote;
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
case Base64Encoded16Bit: { // 4, without quotes (see 2)
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromBase64(ba);
|
|
|
|
|
return QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2);
|
|
|
|
|
}
|
|
|
|
|
case Base64Encoded8Bit: { // 5, without quotes (see 1)
|
|
|
|
|
return quoteUnprintableLatin1(QByteArray::fromBase64(ba));
|
|
|
|
|
}
|
|
|
|
|
case Hex2EncodedLatin1WithQuotes: { // 6, %02x encoded 8 bit Latin1 data
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
2013-02-11 17:58:52 +01:00
|
|
|
return doubleQuote + QString::fromLatin1(decodedBa, decodedBa.size()) + doubleQuote;
|
2013-01-24 11:19:15 +01:00
|
|
|
}
|
|
|
|
|
case Hex4EncodedLittleEndianWithQuotes: { // 7, %04x encoded 16 bit data
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
return doubleQuote + QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2) + doubleQuote;
|
|
|
|
|
}
|
|
|
|
|
case Hex8EncodedLittleEndianWithQuotes: { // 8, %08x encoded 32 bit data
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
return doubleQuote + QString::fromUcs4(reinterpret_cast<const uint *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 4) + doubleQuote;
|
|
|
|
|
}
|
|
|
|
|
case Hex2EncodedUtf8WithQuotes: { // 9, %02x encoded 8 bit UTF-8 data
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
return doubleQuote + QString::fromUtf8(decodedBa) + doubleQuote;
|
|
|
|
|
}
|
|
|
|
|
case Hex8EncodedBigEndian: { // 10, %08x encoded 32 bit data
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
for (int i = 0; i < decodedBa.size() - 3; i += 4) {
|
|
|
|
|
char c = decodedBa.at(i);
|
|
|
|
|
decodedBa[i] = decodedBa.at(i + 3);
|
|
|
|
|
decodedBa[i + 3] = c;
|
|
|
|
|
c = decodedBa.at(i + 1);
|
|
|
|
|
decodedBa[i + 1] = decodedBa.at(i + 2);
|
|
|
|
|
decodedBa[i + 2] = c;
|
|
|
|
|
}
|
|
|
|
|
return doubleQuote + QString::fromUcs4(reinterpret_cast<const uint *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 4) + doubleQuote;
|
|
|
|
|
}
|
|
|
|
|
case Hex4EncodedBigEndianWithQuotes: { // 11, %04x encoded 16 bit data
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
for (int i = 0; i < decodedBa.size(); i += 2) {
|
|
|
|
|
char c = decodedBa.at(i);
|
|
|
|
|
decodedBa[i] = decodedBa.at(i + 1);
|
|
|
|
|
decodedBa[i + 1] = c;
|
|
|
|
|
}
|
|
|
|
|
return doubleQuote + QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2) + doubleQuote;
|
|
|
|
|
}
|
|
|
|
|
case Hex4EncodedLittleEndianWithoutQuotes: { // 12, see 7, without quotes
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
return QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2);
|
|
|
|
|
}
|
|
|
|
|
case Hex2EncodedLocal8BitWithQuotes: { // 13, %02x encoded 8 bit UTF-8 data
|
|
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
return doubleQuote + QString::fromLocal8Bit(decodedBa) + doubleQuote;
|
|
|
|
|
}
|
|
|
|
|
case JulianDate: { // 14, an integer count
|
|
|
|
|
const QDate date = dateFromData(ba.toInt());
|
2013-11-11 14:19:00 +01:00
|
|
|
return date.isValid() ? date.toString(Qt::TextDate) : QLatin1String("(invalid)");
|
2013-01-24 11:19:15 +01:00
|
|
|
}
|
|
|
|
|
case MillisecondsSinceMidnight: {
|
|
|
|
|
const QTime time = timeFromData(ba.toInt());
|
2013-11-11 14:19:00 +01:00
|
|
|
return time.isValid() ? time.toString(Qt::TextDate) : QLatin1String("(invalid)");
|
2013-01-24 11:19:15 +01:00
|
|
|
}
|
|
|
|
|
case JulianDateAndMillisecondsSinceMidnight: {
|
|
|
|
|
const int p = ba.indexOf('/');
|
|
|
|
|
const QDate date = dateFromData(ba.left(p).toInt());
|
|
|
|
|
const QTime time = timeFromData(ba.mid(p + 1 ).toInt());
|
2013-11-11 14:19:00 +01:00
|
|
|
const QDateTime dateTime = QDateTime(date, time);
|
|
|
|
|
return dateTime.isValid() ? dateTime.toString(Qt::TextDate) : QLatin1String("(invalid)");
|
2013-01-24 11:19:15 +01:00
|
|
|
}
|
2013-07-09 14:19:45 -07:00
|
|
|
case IPv6AddressAndHexScopeId: { // 27, 16 hex-encoded bytes, "%" and the string-encoded scope
|
|
|
|
|
const int p = ba.indexOf('%');
|
|
|
|
|
QHostAddress ip6(QString::fromLatin1(p == -1 ? ba : ba.left(p)));
|
|
|
|
|
if (ip6.isNull())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const QByteArray scopeId = p == -1 ? QByteArray() : QByteArray::fromHex(ba.mid(p + 1));
|
|
|
|
|
if (!scopeId.isEmpty())
|
|
|
|
|
ip6.setScopeId(QString::fromUtf16(reinterpret_cast<const ushort *>(scopeId.constData()),
|
|
|
|
|
scopeId.length() / 2));
|
|
|
|
|
return ip6.toString();
|
|
|
|
|
}
|
2013-09-26 16:29:13 +02:00
|
|
|
case Hex2EncodedUtf8WithoutQuotes: { // 28, %02x encoded 8 bit UTF-8 data without quotes
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
return QString::fromUtf8(decodedBa);
|
|
|
|
|
}
|
2013-10-22 13:51:35 +02:00
|
|
|
case MillisecondsSinceEpoch: {
|
2013-11-12 15:25:10 +01:00
|
|
|
bool ok = false;
|
|
|
|
|
const qint64 ms = ba.toLongLong(&ok);
|
|
|
|
|
if (!ok)
|
|
|
|
|
return QLatin1String(ba);
|
2013-10-22 13:51:35 +02:00
|
|
|
QDateTime d;
|
|
|
|
|
d.setTimeSpec(Qt::UTC);
|
|
|
|
|
d.setMSecsSinceEpoch(ms);
|
2013-11-11 14:19:00 +01:00
|
|
|
return d.isValid() ? d.toString(Qt::TextDate) : QLatin1String("(invalid)");
|
2013-10-22 13:51:35 +02:00
|
|
|
}
|
2013-01-24 11:19:15 +01:00
|
|
|
}
|
|
|
|
|
qDebug() << "ENCODING ERROR: " << encoding;
|
|
|
|
|
return QCoreApplication::translate("Debugger", "<Encoding error>");
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|