diff --git a/src/plugins/debugger/debuggerprotocol.h b/src/plugins/debugger/debuggerprotocol.h index 7038097619a..7f3bcd9653f 100644 --- a/src/plugins/debugger/debuggerprotocol.h +++ b/src/plugins/debugger/debuggerprotocol.h @@ -273,9 +273,9 @@ QString decodeData(const QString &baIn, const QString &encoding); // "Change Value Display Format". They are passed from the frontend to // 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. enum DisplayFormat @@ -313,6 +313,7 @@ enum DisplayFormat HexadecimalIntegerFormat = 23, // Frontend internal only BinaryIntegerFormat = 24, // Frontend internal only OctalIntegerFormat = 25, // Frontend internal only + CharCodeIntegerFormat = 28, // Frontend internal only CompactFloatFormat = 26, // Frontend internal only ScientificFloatFormat = 27 // Frontend internal only diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 1e347e67220..6d8561cc21a 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -620,6 +620,14 @@ template QString reformatInteger(IntType value, int format) return "(bin) " + QString::number(value, 2); case OctalIntegerFormat: 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 } @@ -750,7 +758,8 @@ static QString formattedValue(const WatchItem *item) if (format == HexadecimalIntegerFormat || format == DecimalIntegerFormat || format == OctalIntegerFormat - || format == BinaryIntegerFormat) { + || format == BinaryIntegerFormat + || format == CharCodeIntegerFormat) { bool isSigned = item->value.startsWith('-'); quint64 raw = isSigned ? quint64(item->value.toLongLong()) : item->value.toULongLong(); return reformatInteger(raw, format, item->size, isSigned); @@ -899,7 +908,8 @@ static QString displayName(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) result += QString::fromLatin1("@0x" + QByteArray::number(item->address, 16)); // if (origaddr) @@ -1003,6 +1013,7 @@ static DisplayFormats typeFormatList(const WatchItem *item) formats.append(HexadecimalIntegerFormat); formats.append(BinaryIntegerFormat); formats.append(OctalIntegerFormat); + formats.append(CharCodeIntegerFormat); } return formats; @@ -2074,6 +2085,7 @@ QString WatchModel::nameForFormat(int format) case HexadecimalIntegerFormat: return tr("Hexadecimal Integer"); case BinaryIntegerFormat: return tr("Binary Integer"); case OctalIntegerFormat: return tr("Octal Integer"); + case CharCodeIntegerFormat: return tr("Char Code Integer"); case CompactFloatFormat: return tr("Compact Float"); case ScientificFloatFormat: return tr("Scientific Float"); diff --git a/tests/manual/debugger/simple/simple_test_app.cpp b/tests/manual/debugger/simple/simple_test_app.cpp index d4df6f0411b..15ed0174182 100644 --- a/tests/manual/debugger/simple/simple_test_app.cpp +++ b/tests/manual/debugger/simple/simple_test_app.cpp @@ -4134,10 +4134,30 @@ namespace formats { 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() { testCharPointers(); testCharArrays(); + testCharsFromInteger(); testString(); }