Commit 63439a5f authored by hjk's avatar hjk

Debugger: move MI decoding to debuggerprotocol.{h,cpp}

Change-Id: I9d2eaf43b66f0db74ba2584157d6df8280d76652
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
parent b57e3724
......@@ -29,11 +29,10 @@
#include "debuggerprotocol.h"
#include <utils/qtcassert.h>
#include <QByteArray>
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QRegExp>
#include <QTextStream>
#include <ctype.h>
......@@ -181,7 +180,7 @@ void GdbMi::parseValue(const char *&from, const char *to)
void GdbMi::parseTuple(const char *&from, const char *to)
{
//qDebug() << "parseTuple: " << QByteArray(from, to - from);
QTC_CHECK(*from == '{');
//QTC_CHECK(*from == '{');
++from;
parseTuple_helper(from, to);
}
......@@ -209,7 +208,7 @@ void GdbMi::parseTuple_helper(const char *&from, const char *to)
void GdbMi::parseList(const char *&from, const char *to)
{
//qDebug() << "parseList: " << QByteArray(from, to - from);
QTC_CHECK(*from == '[');
//QTC_CHECK(*from == '[');
++from;
m_type = List;
skipCommas(from, to);
......@@ -429,5 +428,151 @@ void extractGdbVersion(const QString &msg,
*gdbBuildVersion = build.section(dot, 1, 1).toInt();
}
//////////////////////////////////////////////////////////////////////////////////
//
// 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);
return doubleQuote + QString::fromLatin1(decodedBa) + doubleQuote;
}
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());
return date.toString(Qt::TextDate);
}
case MillisecondsSinceMidnight: {
const QTime time = timeFromData(ba.toInt());
return time.toString(Qt::TextDate);
}
case JulianDateAndMillisecondsSinceMidnight: {
const int p = ba.indexOf('/');
const QDate date = dateFromData(ba.left(p).toInt());
const QTime time = timeFromData(ba.mid(p + 1 ).toInt());
return QDateTime(date, time).toString(Qt::TextDate);
}
}
qDebug() << "ENCODING ERROR: " << encoding;
return QCoreApplication::translate("Debugger", "<Encoding error>");
}
} // namespace Internal
} // namespace Debugger
......@@ -174,6 +174,51 @@ public:
void extractGdbVersion(const QString &msg,
int *gdbVersion, int *gdbBuildVersion, bool *isMacGdb, bool *isQnxGdb);
// Keep in sync with dumper.py
enum DebuggerEncoding
{
Unencoded8Bit = 0,
Base64Encoded8BitWithQuotes = 1,
Base64Encoded16BitWithQuotes = 2,
Base64Encoded32BitWithQuotes = 3,
Base64Encoded16Bit = 4,
Base64Encoded8Bit = 5,
Hex2EncodedLatin1WithQuotes = 6,
Hex4EncodedLittleEndianWithQuotes = 7,
Hex8EncodedLittleEndianWithQuotes = 8,
Hex2EncodedUtf8WithQuotes = 9,
Hex8EncodedBigEndian = 10,
Hex4EncodedBigEndianWithQuotes = 11,
Hex4EncodedLittleEndianWithoutQuotes = 12,
Hex2EncodedLocal8BitWithQuotes = 13,
JulianDate = 14,
MillisecondsSinceMidnight = 15,
JulianDateAndMillisecondsSinceMidnight = 16,
Hex2EncodedInt1 = 17,
Hex2EncodedInt2 = 18,
Hex2EncodedInt4 = 19,
Hex2EncodedInt8 = 20,
Hex2EncodedUInt1 = 21,
Hex2EncodedUInt2 = 22,
Hex2EncodedUInt4 = 23,
Hex2EncodedUInt8 = 24,
Hex2EncodedFloat4 = 25,
Hex2EncodedFloat8 = 26
};
// Keep in sync with dumper.py, symbolgroupvalue.cpp of CDB
enum DebuggerDisplay {
StopDisplay = 0,
DisplayImageData = 1,
DisplayUtf16String = 2,
DisplayImageFile = 3,
DisplayProcess = 4,
DisplayLatin1String = 5,
DisplayUtf8String = 6
};
// Decode string data as returned by the dumper helpers.
QString decodeData(const QByteArray &baIn, int encoding);
} // namespace Internal
} // namespace Debugger
......
......@@ -30,13 +30,14 @@
#include "watchhandler.h"
#include "breakhandler.h"
#include "debuggerinternalconstants.h"
#include "debuggeractions.h"
#include "debuggercore.h"
#include "debuggerengine.h"
#include "debuggerdialogs.h"
#include "watchutils.h"
#include "debuggerengine.h"
#include "debuggerinternalconstants.h"
#include "debuggerprotocol.h"
#include "imageviewer.h"
#include "watchutils.h"
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
......
......@@ -558,145 +558,6 @@ QByteArray gdbQuoteTypes(const QByteArray &type)
// Utilities to decode string data returned by the dumper helpers.
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);
return doubleQuote + QString::fromLatin1(decodedBa) + doubleQuote;
}
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());
return date.toString(Qt::TextDate);
}
case MillisecondsSinceMidnight: {
const QTime time = timeFromData(ba.toInt());
return time.toString(Qt::TextDate);
}
case JulianDateAndMillisecondsSinceMidnight: {
const int p = ba.indexOf('/');
const QDate date = dateFromData(ba.left(p).toInt());
const QTime time = timeFromData(ba.mid(p + 1 ).toInt());
return QDateTime(date, time).toString(Qt::TextDate);
}
}
qDebug() << "ENCODING ERROR: " << encoding;
return QCoreApplication::translate("Debugger", "<Encoding error>");
}
template <class T>
void decodeArrayHelper(QList<WatchData> *list, const WatchData &tmplate,
......
......@@ -51,49 +51,6 @@ namespace Internal {
class WatchData;
class GdbMi;
// Keep in sync with dumper.py
enum DebuggerEncoding
{
Unencoded8Bit = 0,
Base64Encoded8BitWithQuotes = 1,
Base64Encoded16BitWithQuotes = 2,
Base64Encoded32BitWithQuotes = 3,
Base64Encoded16Bit = 4,
Base64Encoded8Bit = 5,
Hex2EncodedLatin1WithQuotes = 6,
Hex4EncodedLittleEndianWithQuotes = 7,
Hex8EncodedLittleEndianWithQuotes = 8,
Hex2EncodedUtf8WithQuotes = 9,
Hex8EncodedBigEndian = 10,
Hex4EncodedBigEndianWithQuotes = 11,
Hex4EncodedLittleEndianWithoutQuotes = 12,
Hex2EncodedLocal8BitWithQuotes = 13,
JulianDate = 14,
MillisecondsSinceMidnight = 15,
JulianDateAndMillisecondsSinceMidnight = 16,
Hex2EncodedInt1 = 17,
Hex2EncodedInt2 = 18,
Hex2EncodedInt4 = 19,
Hex2EncodedInt8 = 20,
Hex2EncodedUInt1 = 21,
Hex2EncodedUInt2 = 22,
Hex2EncodedUInt4 = 23,
Hex2EncodedUInt8 = 24,
Hex2EncodedFloat4 = 25,
Hex2EncodedFloat8 = 26
};
// Keep in sync with dumper.py, symbolgroupvalue.cpp of CDB
enum DebuggerDisplay {
StopDisplay = 0,
DisplayImageData = 1,
DisplayUtf16String = 2,
DisplayImageFile = 3,
DisplayProcess = 4,
DisplayLatin1String = 5,
DisplayUtf8String = 6
};
bool isEditorDebuggable(Core::IEditor *editor);
QByteArray dotEscape(QByteArray str);
QString currentTime();
......@@ -114,8 +71,6 @@ bool isIntType(const QByteArray &type);
QString formatToolTipAddress(quint64 a);
QString quoteUnprintableLatin1(const QByteArray &ba);
// Editor tooltip support
bool isCppEditor(Core::IEditor *editor);
QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
......@@ -124,8 +79,6 @@ QString removeObviousSideEffects(const QString &exp);
QString fixCppExpression(const QString &exp);
QString cppFunctionAt(const QString &fileName, int line);
// Decode string data as returned by the dumper helpers.
QString decodeData(const QByteArray &baIn, int encoding);
// Decode string data as returned by the dumper helpers.
void decodeArray(WatchData *list, const WatchData &tmplate,
const QByteArray &rawData, int encoding);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment