Commit eb1b3fb0 authored by hjk's avatar hjk Committed by hjk
Browse files

debugger: make local 8 bit available for displaying char *

Change-Id: I4608f3f861b8f06889199e0401e3b7569587be11
Reviewed-on: http://codereview.qt.nokia.com/1232

Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 98c11649
......@@ -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)
......
......@@ -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)
......
......@@ -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<const ushort *>
(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<const uint *>
(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<const uint *>
(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<const ushort *>
(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<const ushort *>
(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", "<Encoding error>");
......
......@@ -68,7 +68,8 @@ enum DebuggerEncoding
Hex2EncodedUtf8 = 9,
Hex8EncodedBigEndian = 10,
Hex4EncodedBigEndian = 11,
Hex4EncodedLittleEndianWithoutQuotes = 12
Hex4EncodedLittleEndianWithoutQuotes = 12,
Hex2EncodedLocal8Bit = 13
};
bool isEditorDebuggable(Core::IEditor *editor);
......
......@@ -1689,29 +1689,66 @@ Foo testStruct()
return f1;
}
void testTypeFormats()
{
namespace formats {
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);
}
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";
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.
if (sizeof(wchar_t) == 4)
u = QString::fromUcs4((uint *)w);
else
u = QString::fromUtf16((ushort *)w);
// 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".
Q_UNUSED(s);
Q_UNUSED(w);
dummyStatement();
}
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();
......
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