forked from qt-creator/qt-creator
Debugger: Better support for "raw" QByteArrays and char[]
Display 'cooked' character as well as numerical value in both decimal and hex. Task-number: QTCREATORBUG-15549 Change-Id: I7f8f9efe07573b452ff44501bfca5e29e9ab437c Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -535,25 +535,40 @@ static QString reformatInteger(quint64 value, int format, int size, bool isSigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format printable (char-type) characters
|
// Format printable (char-type) characters
|
||||||
static QString reformatCharacter(int code, int format, bool isSigned)
|
static QString reformatCharacter(int code, int size, bool isSigned)
|
||||||
{
|
{
|
||||||
const QString codeS = reformatInteger(code, format, 1, isSigned);
|
|
||||||
if (code < 0) // Append unsigned value.
|
|
||||||
return codeS + QLatin1String(" / ") + reformatInteger(256 + code, format, 1, false);
|
|
||||||
const QChar c = QChar(uint(code));
|
const QChar c = QChar(uint(code));
|
||||||
|
QString out;
|
||||||
if (c.isPrint())
|
if (c.isPrint())
|
||||||
return codeS + QLatin1String(" '") + c + QLatin1Char('\'');
|
out = QString::fromLatin1("'") + c + QLatin1String("' ");
|
||||||
switch (code) {
|
else if (code == 0)
|
||||||
case 0:
|
out = QLatin1String("'\\0'");
|
||||||
return codeS + QLatin1String(" '\\0'");
|
else if (code == '\r')
|
||||||
case '\r':
|
out = QLatin1String("'\\r'");
|
||||||
return codeS + QLatin1String(" '\\r'");
|
else if (code == '\n')
|
||||||
case '\t':
|
out = QLatin1String("'\\n'");
|
||||||
return codeS + QLatin1String(" '\\t'");
|
else if (code == '\t')
|
||||||
case '\n':
|
out = QLatin1String("'\\t'");
|
||||||
return codeS + QLatin1String(" '\\n'");
|
else
|
||||||
|
out = QLatin1String(" ");
|
||||||
|
|
||||||
|
out += QLatin1Char('\t');
|
||||||
|
|
||||||
|
if (isSigned) {
|
||||||
|
out += QString::number(code);
|
||||||
|
if (code < 0)
|
||||||
|
out += QString::fromLatin1("/%1 ").arg((1 << (8*size)) + code).left(2 + 2 * size);
|
||||||
|
else
|
||||||
|
out += QString(2 + 2 * size, QLatin1Char(' '));
|
||||||
|
} else {
|
||||||
|
out += QString::number(unsigned(code));
|
||||||
}
|
}
|
||||||
return codeS;
|
|
||||||
|
out += QLatin1Char('\t');
|
||||||
|
|
||||||
|
out += QString::fromLatin1("0x%1").arg(uint(code & ((1ULL << (8*size)) - 1)),
|
||||||
|
2 * size, 16, QLatin1Char('0'));
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString quoteUnprintable(const QString &str)
|
static QString quoteUnprintable(const QString &str)
|
||||||
@@ -616,11 +631,22 @@ static QString formattedValue(const WatchItem *item)
|
|||||||
|
|
||||||
// Append quoted, printable character also for decimal.
|
// Append quoted, printable character also for decimal.
|
||||||
// FIXME: This is unreliable.
|
// FIXME: This is unreliable.
|
||||||
if (item->type.endsWith("char") || item->type.endsWith("QChar")) {
|
if (item->type.endsWith("char")) {
|
||||||
bool ok;
|
bool ok;
|
||||||
const int code = item->value.toInt(&ok);
|
const int code = item->value.toInt(&ok);
|
||||||
bool isUnsigned = item->type == "unsigned char" || item->type == "uchar";
|
bool isUnsigned = item->type == "unsigned char" || item->type == "uchar";
|
||||||
return ok ? reformatCharacter(code, format, !isUnsigned) : item->value;
|
if (ok)
|
||||||
|
return reformatCharacter(code, 1, !isUnsigned);
|
||||||
|
} else if (item->type.endsWith("wchar_t")) {
|
||||||
|
bool ok;
|
||||||
|
const int code = item->value.toInt(&ok);
|
||||||
|
if (ok)
|
||||||
|
return reformatCharacter(code, 4, false);
|
||||||
|
} else if (item->type.endsWith("QChar")) {
|
||||||
|
bool ok;
|
||||||
|
const int code = item->value.toInt(&ok);
|
||||||
|
if (ok)
|
||||||
|
return reformatCharacter(code, 2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format == HexadecimalIntegerFormat
|
if (format == HexadecimalIntegerFormat
|
||||||
|
Reference in New Issue
Block a user