From ed062e85f0988345a83af5fd24956e6b50db7739 Mon Sep 17 00:00:00 2001 From: Martin Bohacek <mbohacek@blackberry.com> Date: Thu, 26 Sep 2013 16:29:13 +0200 Subject: [PATCH] Debugger: add support for dumping non-ASCII UTF-8 QChar Change-Id: I87d9557c1e5b945972ddf3f63f8cb064514a3b54 Reviewed-by: hjk <hjk121@nokiamail.com> --- share/qtcreator/debugger/dumper.py | 7 ++++--- share/qtcreator/debugger/gdbbridge.py | 16 --------------- share/qtcreator/debugger/qttypes.py | 24 +++++++++++------------ src/plugins/debugger/debuggerprotocol.cpp | 4 ++++ src/plugins/debugger/debuggerprotocol.h | 3 ++- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/share/qtcreator/debugger/dumper.py b/share/qtcreator/debugger/dumper.py index 71c1682f4ae..09f22cd0bb5 100644 --- a/share/qtcreator/debugger/dumper.py +++ b/share/qtcreator/debugger/dumper.py @@ -456,7 +456,7 @@ def cleanAddress(addr): # Some "Enums" -# Encodings. Keep that synchronized with DebuggerEncoding in watchutils.h +# Encodings. Keep that synchronized with DebuggerEncoding in debuggerprotocol.h Unencoded8Bit, \ Base64Encoded8BitWithQuotes, \ Base64Encoded16BitWithQuotes, \ @@ -484,8 +484,9 @@ Hex2EncodedUInt4, \ Hex2EncodedUInt8, \ Hex2EncodedFloat4, \ Hex2EncodedFloat8, \ -IPv6AddressAndHexScopeId \ - = range(28) +IPv6AddressAndHexScopeId, \ +Hex2EncodedUtf8WithoutQuotes \ + = range(29) # Display modes. Keep that synchronized with DebuggerDisplay in watchutils.h StopDisplay, \ diff --git a/share/qtcreator/debugger/gdbbridge.py b/share/qtcreator/debugger/gdbbridge.py index a53961ca9f3..f8b0eb3ab9b 100644 --- a/share/qtcreator/debugger/gdbbridge.py +++ b/share/qtcreator/debugger/gdbbridge.py @@ -397,22 +397,6 @@ def importPlainDumpers(args): registerCommand("importPlainDumpers", importPlainDumpers) - - -# Fails on Windows. -try: - import curses.ascii - def printableChar(ucs): - if curses.ascii.isprint(ucs): - return ucs - return '?' -except: - def printableChar(ucs): - if ucs >= 32 and ucs <= 126: - return ucs - return '?' - - #gdb.Value.child = impl_Value_child # Fails on SimulatorQt. diff --git a/share/qtcreator/debugger/qttypes.py b/share/qtcreator/debugger/qttypes.py index 91364a246a0..b4661a90cee 100644 --- a/share/qtcreator/debugger/qttypes.py +++ b/share/qtcreator/debugger/qttypes.py @@ -49,22 +49,20 @@ def qdump__QByteArray(d, value): d.putArrayData(d.charType(), data, size) -# Fails on Windows. -try: - import curses.ascii - def printableChar(ucs): - if curses.ascii.isprint(ucs): - return ucs - return '?' -except: - def printableChar(ucs): - if ucs >= 32 and ucs <= 126: - return ucs - return '?' +def str2Utf8hex2(s): + # Returns UTF-8 hex-data of string suitable for QByteArray::fromHex() + ret = [] + for c in s.encode('utf-8'): + ret.append('%02x' % ord(c)) + return ''.join(ret) def qdump__QChar(d, value): ucs = int(value["ucs"]) - d.putValue("'%c' (%d)" % (printableChar(ucs), ucs)) + if ucs < 32: + ch = '?' + else: + ch = unichr(ucs) + d.putValue(str2Utf8hex2(u"'%s' (%d)" % (ch, ucs)), Hex2EncodedUtf8WithoutQuotes) d.putNumChild(0) diff --git a/src/plugins/debugger/debuggerprotocol.cpp b/src/plugins/debugger/debuggerprotocol.cpp index bb89c9adfe9..13335773326 100644 --- a/src/plugins/debugger/debuggerprotocol.cpp +++ b/src/plugins/debugger/debuggerprotocol.cpp @@ -624,6 +624,10 @@ QString decodeData(const QByteArray &ba, int encoding) scopeId.length() / 2)); return ip6.toString(); } + case Hex2EncodedUtf8WithoutQuotes: { // 28, %02x encoded 8 bit UTF-8 data without quotes + const QByteArray decodedBa = QByteArray::fromHex(ba); + return QString::fromUtf8(decodedBa); + } } qDebug() << "ENCODING ERROR: " << encoding; return QCoreApplication::translate("Debugger", "<Encoding error>"); diff --git a/src/plugins/debugger/debuggerprotocol.h b/src/plugins/debugger/debuggerprotocol.h index bb91af698ab..6bce7e1aec6 100644 --- a/src/plugins/debugger/debuggerprotocol.h +++ b/src/plugins/debugger/debuggerprotocol.h @@ -203,7 +203,8 @@ enum DebuggerEncoding Hex2EncodedUInt8 = 24, Hex2EncodedFloat4 = 25, Hex2EncodedFloat8 = 26, - IPv6AddressAndHexScopeId = 27 + IPv6AddressAndHexScopeId = 27, + Hex2EncodedUtf8WithoutQuotes = 28 }; // Keep in sync with dumper.py, symbolgroupvalue.cpp of CDB -- GitLab