forked from qt-creator/qt-creator
debugger: saner handling of unprintable chars in Locals&Expressions
Change-Id: Ia257356ec297dfa7766354d92538886ba2492b55 Reviewed-on: http://codereview.qt.nokia.com/2566 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -79,7 +79,6 @@ static int generationCounter = 0;
|
||||
|
||||
QHash<QByteArray, int> WatchHandler::m_watcherNames;
|
||||
QHash<QByteArray, int> WatchHandler::m_typeFormats;
|
||||
int WatchHandler::m_unprintableBase = 0;
|
||||
|
||||
static QByteArray stripTemplate(const QByteArray &ba)
|
||||
{
|
||||
@@ -87,6 +86,20 @@ static QByteArray stripTemplate(const QByteArray &ba)
|
||||
return pos == -1 ? ba : ba.left(pos);
|
||||
}
|
||||
|
||||
|
||||
static int m_unprintableBase = 8;
|
||||
|
||||
void WatchHandler::setUnprintableBase(int base)
|
||||
{
|
||||
m_unprintableBase = base;
|
||||
emitAllChanged();
|
||||
}
|
||||
|
||||
int WatchHandler::unprintableBase()
|
||||
{
|
||||
return m_unprintableBase;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// WatchItem
|
||||
@@ -327,7 +340,7 @@ template <class IntType> QString reformatInteger(IntType value, int format)
|
||||
}
|
||||
|
||||
// Format printable (char-type) characters
|
||||
static inline QString reformatCharacter(int code, int format)
|
||||
static QString reformatCharacter(int code, int format)
|
||||
{
|
||||
const QString codeS = reformatInteger(code, format);
|
||||
if (code < 0) // Append unsigned value.
|
||||
@@ -347,7 +360,26 @@ static inline QString reformatCharacter(int code, int format)
|
||||
return codeS;
|
||||
}
|
||||
|
||||
static inline QString formattedValue(const WatchData &data, int format)
|
||||
static QString quoteUnprintable(const QString &str)
|
||||
{
|
||||
if (WatchHandler::unprintableBase() == 0)
|
||||
return str;
|
||||
QString encoded;
|
||||
foreach (const QChar c, str) {
|
||||
if (c.isPrint()) {
|
||||
encoded += c;
|
||||
} else if (WatchHandler::unprintableBase() == 8) {
|
||||
encoded += QString("\\%1")
|
||||
.arg(c.unicode(), 3, 8, QLatin1Char('0'));
|
||||
} else {
|
||||
encoded += QString("\\u%1")
|
||||
.arg(c.unicode(), 4, 16, QLatin1Char('0'));
|
||||
}
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
static QString formattedValue(const WatchData &data, int format)
|
||||
{
|
||||
if (isIntType(data.type)) {
|
||||
if (data.value.isEmpty())
|
||||
@@ -379,7 +411,6 @@ static inline QString formattedValue(const WatchData &data, int format)
|
||||
}
|
||||
|
||||
QString result = data.value;
|
||||
result.replace(QLatin1Char('\n'), QLatin1String("\\n"));
|
||||
if (result.startsWith(QLatin1Char('<'))) {
|
||||
if (result == QLatin1String("<Edit>"))
|
||||
result = WatchHandler::tr("<Edit>");
|
||||
@@ -405,7 +436,7 @@ static inline QString formattedValue(const WatchData &data, int format)
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return quoteUnprintable(result);
|
||||
}
|
||||
|
||||
// Get a pointer address from pointer values reported by the debugger.
|
||||
@@ -674,21 +705,7 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (WatchHandler::m_unprintableBase == 0)
|
||||
return result;
|
||||
QString encoded;
|
||||
foreach (const QChar c, result) {
|
||||
if (c.isPrint()) {
|
||||
encoded += c;
|
||||
} else if (WatchHandler::m_unprintableBase == 8) {
|
||||
encoded += QString("\\%1")
|
||||
.arg(c.unicode(), 3, 8, QLatin1Char('0'));
|
||||
} else {
|
||||
encoded += QString("\\u%1")
|
||||
.arg(c.unicode(), 4, 16, QLatin1Char('0'));
|
||||
}
|
||||
}
|
||||
return encoded;
|
||||
return result;
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
|
||||
@@ -180,8 +180,8 @@ public:
|
||||
|
||||
void addTypeFormats(const QByteArray &type, const QStringList &formats);
|
||||
|
||||
void setUnprintableBase(int base) { m_unprintableBase = base; }
|
||||
int unprintableBase() const { return m_unprintableBase; }
|
||||
void setUnprintableBase(int base);
|
||||
static int unprintableBase();
|
||||
|
||||
QByteArray watcherName(const QByteArray &exp);
|
||||
void synchronizeWatchers();
|
||||
@@ -217,7 +217,6 @@ private:
|
||||
WatchModel *m_watchers;
|
||||
WatchModel *m_tooltips;
|
||||
DebuggerEngine *m_engine;
|
||||
static int m_unprintableBase;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -1642,6 +1642,11 @@ void testQString()
|
||||
{
|
||||
QString str = "Hello ";
|
||||
str += " big, ";
|
||||
str += "\t";
|
||||
str += "\r";
|
||||
str += "\n";
|
||||
str += QLatin1Char(0);
|
||||
str += QLatin1Char(1);
|
||||
str += " fat ";
|
||||
str += " World ";
|
||||
str += " World ";
|
||||
|
||||
Reference in New Issue
Block a user