Debugger: Add a "Char Code Integer"

Fixes: QTCREATORBUG-22849
Change-Id: Id601eb5cbe1211cff595f04b5910a21f1ba33128
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2021-12-10 11:03:32 +01:00
parent 035ba1c10e
commit e8ae475fcf
3 changed files with 37 additions and 4 deletions

View File

@@ -273,9 +273,9 @@ QString decodeData(const QString &baIn, const QString &encoding);
// "Change Value Display Format". They are passed from the frontend to // "Change Value Display Format". They are passed from the frontend to
// the dumpers. // the dumpers.
// //
// Keep in sync with dumper.py. // Keep in sync with share/qtcreator/debugger/utils.py
// //
// \note Add new enum values only at the end, as the numeric values are // \note Add new enum values only with increasing numeric values as they are
// persisted in user settings. // persisted in user settings.
enum DisplayFormat enum DisplayFormat
@@ -313,6 +313,7 @@ enum DisplayFormat
HexadecimalIntegerFormat = 23, // Frontend internal only HexadecimalIntegerFormat = 23, // Frontend internal only
BinaryIntegerFormat = 24, // Frontend internal only BinaryIntegerFormat = 24, // Frontend internal only
OctalIntegerFormat = 25, // Frontend internal only OctalIntegerFormat = 25, // Frontend internal only
CharCodeIntegerFormat = 28, // Frontend internal only
CompactFloatFormat = 26, // Frontend internal only CompactFloatFormat = 26, // Frontend internal only
ScientificFloatFormat = 27 // Frontend internal only ScientificFloatFormat = 27 // Frontend internal only

View File

@@ -620,6 +620,14 @@ template <class IntType> QString reformatInteger(IntType value, int format)
return "(bin) " + QString::number(value, 2); return "(bin) " + QString::number(value, 2);
case OctalIntegerFormat: case OctalIntegerFormat:
return "(oct) " + QString::number(value, 8); return "(oct) " + QString::number(value, 8);
case CharCodeIntegerFormat: {
QString res = "\"";
while (value > 0) {
res = QChar(ushort(value & 255)) + res;
value /= 256;
}
return "\"" + res;
}
} }
return QString::number(value, 10); // not reached return QString::number(value, 10); // not reached
} }
@@ -750,7 +758,8 @@ static QString formattedValue(const WatchItem *item)
if (format == HexadecimalIntegerFormat if (format == HexadecimalIntegerFormat
|| format == DecimalIntegerFormat || format == DecimalIntegerFormat
|| format == OctalIntegerFormat || format == OctalIntegerFormat
|| format == BinaryIntegerFormat) { || format == BinaryIntegerFormat
|| format == CharCodeIntegerFormat) {
bool isSigned = item->value.startsWith('-'); bool isSigned = item->value.startsWith('-');
quint64 raw = isSigned ? quint64(item->value.toLongLong()) : item->value.toULongLong(); quint64 raw = isSigned ? quint64(item->value.toLongLong()) : item->value.toULongLong();
return reformatInteger(raw, format, item->size, isSigned); return reformatInteger(raw, format, item->size, isSigned);
@@ -899,7 +908,8 @@ static QString displayName(const WatchItem *item)
static QString displayValue(const WatchItem *item) static QString displayValue(const WatchItem *item)
{ {
QString result = watchModel(item)->removeNamespaces(truncateValue(formattedValue(item))); QString result = truncateValue(formattedValue(item));
result = watchModel(item)->removeNamespaces(result);
if (result.isEmpty() && item->address) if (result.isEmpty() && item->address)
result += QString::fromLatin1("@0x" + QByteArray::number(item->address, 16)); result += QString::fromLatin1("@0x" + QByteArray::number(item->address, 16));
// if (origaddr) // if (origaddr)
@@ -1003,6 +1013,7 @@ static DisplayFormats typeFormatList(const WatchItem *item)
formats.append(HexadecimalIntegerFormat); formats.append(HexadecimalIntegerFormat);
formats.append(BinaryIntegerFormat); formats.append(BinaryIntegerFormat);
formats.append(OctalIntegerFormat); formats.append(OctalIntegerFormat);
formats.append(CharCodeIntegerFormat);
} }
return formats; return formats;
@@ -2074,6 +2085,7 @@ QString WatchModel::nameForFormat(int format)
case HexadecimalIntegerFormat: return tr("Hexadecimal Integer"); case HexadecimalIntegerFormat: return tr("Hexadecimal Integer");
case BinaryIntegerFormat: return tr("Binary Integer"); case BinaryIntegerFormat: return tr("Binary Integer");
case OctalIntegerFormat: return tr("Octal Integer"); case OctalIntegerFormat: return tr("Octal Integer");
case CharCodeIntegerFormat: return tr("Char Code Integer");
case CompactFloatFormat: return tr("Compact Float"); case CompactFloatFormat: return tr("Compact Float");
case ScientificFloatFormat: return tr("Scientific Float"); case ScientificFloatFormat: return tr("Scientific Float");

View File

@@ -4134,10 +4134,30 @@ namespace formats {
dummyStatement(&s, &w, &t); dummyStatement(&s, &w, &t);
} }
void testCharsFromInteger()
{
// These tests should result in properly displayed Four Character Codes
// https://en.wikipedia.org/wiki/FourCC
unsigned i = 1886144836;
unsigned long long l = 1886144836;
BREAK_HERE;
// CheckType i unsigned int.
// Select "Char Code Integer" for "Change Format for Type" in L&W context menu.
// Check i "pIID" unsigned int
// Check l "pIID" unsigned long long
// Make sure to undo "Change Format".
dummyStatement(&i, &l);
}
void testFormats() void testFormats()
{ {
testCharPointers(); testCharPointers();
testCharArrays(); testCharArrays();
testCharsFromInteger();
testString(); testString();
} }