diff --git a/share/qtcreator/dumper/dumper.py b/share/qtcreator/dumper/dumper.py index 887f25c1a25..223490d9f25 100644 --- a/share/qtcreator/dumper/dumper.py +++ b/share/qtcreator/dumper/dumper.py @@ -67,8 +67,9 @@ Hex8EncodedLittleEndian, \ Hex2EncodedUtf8, \ Hex8EncodedBigEndian, \ Hex4EncodedBigEndian, \ -Hex4EncodedLittleEndianWithoutQuotes \ - = range(13) +Hex4EncodedLittleEndianWithoutQuotes, \ +Hex2EncodedLocal8Bit \ + = range(14) # Display modes StopDisplay, \ @@ -1364,12 +1365,9 @@ class Dumper: if value.type.code == gdb.TYPE_CODE_ARRAY: baseptr = value.cast(realtype.pointer()) - if format == 0 or format == 1: + if format == 0 or format == 1 or format == 2: # Explicityly requested Latin1 or UTF-8 formatting. - if format == 0: - f = Hex2EncodedLatin1 - else: - f = Hex2EncodedUtf8 + f = [Hex2EncodedLatin1, Hex2EncodedUtf8, Hex2EncodedLocal8Bit][format] self.putAddress(value.address) self.putType(realtype) self.putValue(encodeCharArray(value, 100), f) @@ -1484,6 +1482,14 @@ class Dumper: return if format == 3: + # Explicityly requested local 8 bit formatting. + self.putAddress(value.address) + self.putType(realtype) + self.putValue(encodeCharArray(value, 100), Hex2EncodedLocal8Bit) + self.putNumChild(0) + return + + if format == 4: # Explitly requested UTF-16 formatting. self.putAddress(value.address) self.putType(realtype) @@ -1491,7 +1497,7 @@ class Dumper: self.putNumChild(0) return - if format == 4: + if format == 5: # Explitly requested UCS-4 formatting. self.putAddress(value.address) self.putType(realtype) diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index f23aad883e9..012bd1ebfe6 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -717,12 +717,14 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const << tr("Raw pointer") << tr("Latin1 string") << tr("UTF8 string") + << tr("Local 8bit string") << tr("UTF16 string") << tr("UCS4 string"); if (data.type.contains("char[") || data.type.contains("char [")) return QStringList() << tr("Latin1 string") - << tr("UTF8 string"); + << tr("UTF8 string") + << tr("Local 8bit string"); bool ok = false; (void)data.value.toULongLong(&ok, 0); if ((isIntType(data.type) && data.type != "bool") || ok) diff --git a/src/plugins/debugger/watchutils.cpp b/src/plugins/debugger/watchutils.cpp index ba7304e164c..7356f31978a 100644 --- a/src/plugins/debugger/watchutils.cpp +++ b/src/plugins/debugger/watchutils.cpp @@ -559,27 +559,23 @@ QString decodeData(const QByteArray &ba, int encoding) case Hex2EncodedLatin1: { // 6, %02x encoded 8 bit Latin1 data const QChar doubleQuote(QLatin1Char('"')); const QByteArray decodedBa = QByteArray::fromHex(ba); - //qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n"; return doubleQuote + QString::fromLatin1(decodedBa) + doubleQuote; } case Hex4EncodedLittleEndian: { // 7, %04x encoded 16 bit data const QChar doubleQuote(QLatin1Char('"')); const QByteArray decodedBa = QByteArray::fromHex(ba); - //qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n"; return doubleQuote + QString::fromUtf16(reinterpret_cast (decodedBa.data()), decodedBa.size() / 2) + doubleQuote; } case Hex8EncodedLittleEndian: { // 8, %08x encoded 32 bit data const QChar doubleQuote(QLatin1Char('"')); const QByteArray decodedBa = QByteArray::fromHex(ba); - //qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n"; return doubleQuote + QString::fromUcs4(reinterpret_cast (decodedBa.data()), decodedBa.size() / 4) + doubleQuote; } - case Hex2EncodedUtf8: { // 9, %02x encoded 8 bit Utf-8 data + case Hex2EncodedUtf8: { // 9, %02x encoded 8 bit UTF-8 data const QChar doubleQuote(QLatin1Char('"')); const QByteArray decodedBa = QByteArray::fromHex(ba); - //qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n"; return doubleQuote + QString::fromUtf8(decodedBa) + doubleQuote; } case Hex8EncodedBigEndian: { // 10, %08x encoded 32 bit data @@ -593,7 +589,6 @@ QString decodeData(const QByteArray &ba, int encoding) decodedBa[i + 1] = decodedBa.at(i + 2); decodedBa[i + 2] = c; } - //qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n"; return doubleQuote + QString::fromUcs4(reinterpret_cast (decodedBa.data()), decodedBa.size() / 4) + doubleQuote; } @@ -605,16 +600,19 @@ QString decodeData(const QByteArray &ba, int encoding) decodedBa[i] = decodedBa.at(i + 1); decodedBa[i + 1] = c; } - //qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n"; return doubleQuote + QString::fromUtf16(reinterpret_cast (decodedBa.data()), decodedBa.size() / 2) + doubleQuote; } case Hex4EncodedLittleEndianWithoutQuotes: { // 12, see 7, without quotes const QByteArray decodedBa = QByteArray::fromHex(ba); - //qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n"; return QString::fromUtf16(reinterpret_cast (decodedBa.data()), decodedBa.size() / 2); } + case Hex2EncodedLocal8Bit: { // 13, %02x encoded 8 bit UTF-8 data + const QChar doubleQuote(QLatin1Char('"')); + const QByteArray decodedBa = QByteArray::fromHex(ba); + return doubleQuote + QString::fromLocal8Bit(decodedBa) + doubleQuote; + } } qDebug() << "ENCODING ERROR: " << encoding; return QCoreApplication::translate("Debugger", ""); diff --git a/src/plugins/debugger/watchutils.h b/src/plugins/debugger/watchutils.h index 37ce0169695..77239dd9790 100644 --- a/src/plugins/debugger/watchutils.h +++ b/src/plugins/debugger/watchutils.h @@ -68,7 +68,8 @@ enum DebuggerEncoding Hex2EncodedUtf8 = 9, Hex8EncodedBigEndian = 10, Hex4EncodedBigEndian = 11, - Hex4EncodedLittleEndianWithoutQuotes = 12 + Hex4EncodedLittleEndianWithoutQuotes = 12, + Hex2EncodedLocal8Bit = 13 }; bool isEditorDebuggable(Core::IEditor *editor); diff --git a/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp b/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp index d3e3d67b15b..121bfd79064 100644 --- a/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp +++ b/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp @@ -1689,29 +1689,66 @@ Foo testStruct() return f1; } -void testTypeFormats() -{ - // These tests should result in properly displayed umlauts in the - // Locals&Watchers view. It is only support on gdb with Python. - const char *s = "aöa"; - const wchar_t *w = L"aöa"; - QString u; - // <== break here - // All: Select UTF-8 in "Change Format for Type" in L&W context menu. - // Windows: Select UTF-16 in "Change Format for Type" in L&W context menu. - // Other: Select UCS-6 in "Change Format for Type" in L&W context menu. +namespace formats { - if (sizeof(wchar_t) == 4) - u = QString::fromUcs4((uint *)w); - else - u = QString::fromUtf16((ushort *)w); + void testString() + { + const wchar_t *w = L"aöa"; + QString u; + if (sizeof(wchar_t) == 4) + u = QString::fromUcs4((uint *)w); + else + u = QString::fromUtf16((ushort *)w); + // <== break here + // All: Select UTF-8 in "Change Format for Type" in L&W context menu. + // Windows: Select UTF-16 in "Change Format for Type" in L&W context menu. + // Other: Select UCS-6 in "Change Format for Type" in L&W context menu. + dummyStatement(&u, &w); + } - // Make sure to undo "Change Format". - Q_UNUSED(s); - Q_UNUSED(w); - dummyStatement(); -} + void testCharPointers() + { + // These tests should result in properly displayed umlauts in the + // Locals&Watchers view. It is only support on gdb with Python. + + const char *s = "aöa"; + const char *t = "a\xc3\xb6"; + const wchar_t *w = L"aöa"; + // <== break here + // All: Select UTF-8 in "Change Format for Type" in L&W context menu. + // Windows: Select UTF-16 in "Change Format for Type" in L&W context menu. + // Other: Select UCS-6 in "Change Format for Type" in L&W context menu. + + // Make sure to undo "Change Format". + dummyStatement(&s, &w); + dummyStatement(&t); + } + + void testCharArrays() + { + // These tests should result in properly displayed umlauts in the + // Locals&Watchers view. It is only support on gdb with Python. + + const char s[] = "aöa"; + const wchar_t w[] = L"aöa"; + // <== break here + // All: Select UTF-8 in "Change Format for Type" in L&W context menu. + // Windows: Select UTF-16 in "Change Format for Type" in L&W context menu. + // Other: Select UCS-6 in "Change Format for Type" in L&W context menu. + + // Make sure to undo "Change Format". + dummyStatement(&s, &w); + } + + void testFormats() + { + testCharPointers(); + testCharArrays(); + testString(); + } + +} // namespace formats void testQTextCursor() @@ -3187,7 +3224,8 @@ int main(int argc, char *argv[]) testStdStack(); testStdString(); testStdVector(); - testTypeFormats(); + + formats::testFormats(); testPassByReference(); testPlugin();