From f9eea7e1ece035a33e767917dab8e2a26041e5fd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@nokia.com> Date: Thu, 18 Nov 2010 15:40:07 +0100 Subject: [PATCH] Debugger: Fix broken display of containers with truncated item count. Introduce convention '<>10 items>' meaning <more than 10 items>. Task-number: QTCREATORBUG-3132 --- share/qtcreator/gdbmacros/gdbmacros.cpp | 26 ++++++++++++++++--------- src/plugins/debugger/watchhandler.cpp | 11 +++++++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/share/qtcreator/gdbmacros/gdbmacros.cpp b/share/qtcreator/gdbmacros/gdbmacros.cpp index d1bf4126336..665231f4fa7 100644 --- a/share/qtcreator/gdbmacros/gdbmacros.cpp +++ b/share/qtcreator/gdbmacros/gdbmacros.cpp @@ -490,8 +490,10 @@ struct QDumper void beginItem(const char *name); // start of named item, ready to accept value void endItem(); // end of named item, used after value output is complete - // convienience for putting "<n items>" + // convenience for putting "<n items>" void putItemCount(const char *name, int count); + // convenience for putting "<>n items>" (more than X items) + void putTruncatedItemCount(const char *name, int count); void putCommaIfNeeded(); // convienience function for writing the last item of an abbreviated list void putEllipsis(); @@ -753,6 +755,11 @@ void QDumper::putItemCount(const char *name, int count) put(name).put("=\"<").put(count).put(" items>\""); } +void QDumper::putTruncatedItemCount(const char *name, int count) +{ + putCommaIfNeeded(); + put(name).put("=\"<>").put(count).put(" items>\""); +} // // Some helpers to keep the dumper code short @@ -3148,16 +3155,18 @@ static void qDumpStdList(QDumper &d) p = deref(addOffset(p, sizeof(void*))); qCheckAccess(p); #endif - int nn = 0; + std::list<int>::size_type nn = 0; + const std::list<int>::size_type maxItems = 100; std::list<int>::const_iterator it = list.begin(); const std::list<int>::const_iterator cend = list.end(); - for (; nn < 101 && it != cend; ++nn, ++it) + for (; nn < maxItems && it != cend; ++nn, ++it) qCheckAccess(it.operator->()); - if (nn > 100) - d.putItem("value", "<more than 100 items>"); - else + if (it != cend) { + d.putTruncatedItemCount("value", nn); + } else { d.putItemCount("value", nn); + } d.putItem("numchild", nn); d.putItem("valueeditable", "false"); @@ -3167,7 +3176,7 @@ static void qDumpStdList(QDumper &d) isPointerType(d.innerType) ? strippedInnerType.data() : 0; d.beginChildren(d.innerType); it = list.begin(); - for (int i = 0; i < 1000 && it != cend; ++i, ++it) { + for (std::list<int>::size_type i = 0; i < maxItems && it != cend; ++i, ++it) { d.beginHash(); qDumpInnerValueOrPointer(d, d.innerType, stripped, it.operator->()); d.endHash(); @@ -3250,7 +3259,6 @@ static void qDumpStdMapHelper(QDumper &d) for (int i = 0; i < nn && i < 10 && it != cend; ++i, ++it) qCheckAccess(it.operator->()); - const QByteArray strippedInnerType = stripPointerType(d.innerType); d.putItem("numchild", nn); d.putItemCount("value", nn); d.putItem("valueeditable", "false"); @@ -3399,7 +3407,7 @@ static void qDumpStdSet(QDumper &d) #ifdef Q_CC_MSVC // As the set implementation inherits from a base class // depending on the key, use something equivalent to iterate it. - const int innerSize = d.extraInt[0]; + const size_t innerSize = d.extraInt[0]; if (innerSize == sizeof(int)) { qDumpStdSetHelper<int>(d); return; diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 488de4223dc..484b3a2a903 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -481,8 +481,15 @@ static inline QString formattedValue(const WatchData &data, int format) else if (result == QLatin1String("<not accessible>")) result = WatchHandler::tr("<not accessible>"); else if (result.endsWith(" items>")) { - const int size = result.mid(1, result.indexOf(' ') - 1).toInt(); - result = WatchHandler::tr("<%n items>", 0, size); + // '<10 items>' or '<>10 items>' (more than) + bool ok; + const bool moreThan = result.at(1) == QLatin1Char('>'); + const int numberPos = moreThan ? 2 : 1; + const int size = result.mid(numberPos, result.indexOf(' ') - numberPos).toInt(&ok); + QTC_ASSERT(ok, qWarning("WatchHandler: Invalid item count '%s'", qPrintable(result)) ; ) + result = moreThan ? + WatchHandler::tr("<more than %n items>", 0, size) : + WatchHandler::tr("<%n items>", 0, size); } } return result; -- GitLab