/share/qtcreator/dumper/dumper.cpp
C++ | 3809 lines | 3347 code | 262 blank | 200 comment | 479 complexity | 22a4a2eb928155cb6332f220bac7630e MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /****************************************************************************
- **
- ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
- ** Contact: http://www.qt-project.org/legal
- **
- ** This file is part of Qt Creator.
- **
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and Digia. For licensing terms and
- ** conditions see http://qt.digia.com/licensing. For further information
- ** use the contact form at http://qt.digia.com/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 2.1 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 2.1 requirements
- ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
- **
- ** In addition, as a special exception, Digia gives you certain additional
- ** rights. These rights are described in the Digia Qt LGPL Exception
- ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
- **
- ****************************************************************************/
- #include <qglobal.h>
- #if USE_QT_CORE
- #include <QDateTime>
- #include <QDebug>
- #include <QDir>
- #include <QFile>
- #include <QFileInfo>
- #include <QHash>
- #include <QLinkedList>
- #include <QList>
- #include <QQueue>
- #include <QLocale>
- #include <QMap>
- #include <QMetaEnum>
- #include <QMetaObject>
- #include <QMetaProperty>
- #include <QPoint>
- #include <QPointF>
- #include <QPointer>
- #include <QRect>
- #include <QRectF>
- #include <QStack>
- #include <QSize>
- #include <QSizeF>
- #include <QString>
- #include <QStringList>
- #include <QTextCodec>
- #include <QTextStream>
- #include <QVector>
- #ifndef QT_BOOTSTRAPPED
- #include <QModelIndex>
- #if QT_VERSION >= 0x040500
- #include <QSharedPointer>
- #include <QSharedDataPointer>
- #include <QSharedData>
- #include <QWeakPointer>
- #endif
- #ifndef USE_QT_GUI
- # ifdef QT_GUI_LIB
- # define USE_QT_GUI 1
- # endif
- #endif
- #ifndef USE_QT_WIDGETS
- # if defined(QT_WIDGETS_LIB) || ((QT_VERSION < 0x050000) && defined(USE_QT_GUI))
- # define USE_QT_WIDGETS 1
- # endif
- #endif
- #ifdef USE_QT_GUI
- # include <QImage>
- # include <QRegion>
- # include <QPixmap>
- # include <QFont>
- # include <QColor>
- # include <QKeySequence>
- #endif
- #ifdef USE_QT_WIDGETS
- # include <QSizePolicy>
- # include <QWidget>
- # include <QApplication>
- #endif
- #endif // QT_BOOTSTRAPPED
- #endif // USE_QT_CORE
- #ifdef Q_OS_WIN
- # include <windows.h>
- #endif
- #include <list>
- #include <map>
- #include <string>
- #include <set>
- #include <vector>
- #include <stdio.h>
- #ifdef QT_BOOTSTRAPPED
- # define NS ""
- # define NSX "'"
- # define NSY "'"
- #else
- # include "dumper_p.h"
- #endif // QT_BOOTSTRAPPED
- #if QT_VERSION >= 0x050000
- # define MAP_WORKS 0
- #else
- # define MAP_WORKS 1
- #endif
- int qtGhVersion = QT_VERSION;
- /*!
- \class QDumper
- \brief Helper class for producing "nice" output in Qt Creator's debugger.
- \internal
- The whole "custom dumper" implementation is currently far less modular
- than it could be. But as the code is still in a flux, making it nicer
- from a pure archtectural point of view seems still be a waste of resources.
- Some hints:
- New dumpers for non-templated classes should be mentioned in
- \c{qDumpObjectData440()} in the \c{protocolVersion == 1} branch.
- Templated classes need extra support on the IDE level
- (see plugins/debugger/gdbengine.cpp) and should not be mentiond in
- \c{qDumpObjectData440()}.
- In any case, dumper processesing should end up in
- \c{handleProtocolVersion2and3()} and needs an entry in the big switch there.
- Next step is to create a suitable \c{static void qDumpFoo(QDumper &d)}
- function. At the bare minimum it should contain something like this:
- \c{
- const Foo &foo = *reinterpret_cast<const Foo *>(d.data);
- d.putItem("value", ...);
- d.putItem("type", "Foo");
- d.putItem("numchild", "0");
- }
- 'd.putItem(name, value)' roughly expands to:
- d.put((name)).put("=\"").put(value).put("\"";
- Useful (i.e. understood by the IDE) names include:
- \list
- \o "name" shows up in the first column in the Locals&Watchers view.
- \o "value" shows up in the second column.
- \o "valueencoded" should be set to "1" if the value is base64 encoded.
- Always base64-encode values that might use unprintable or otherwise
- "confuse" the protocol (like spaces and quotes). [A-Za-z0-9] is "safe".
- A value of "3" is used for base64-encoded UCS4, "2" denotes
- base64-encoded UTF16.
- \o "numchild" return the number of children in the view. Effectively, only
- 0 and != 0 will be used, so don't try too hard to get the number right.
- \endlist
- If the current item has children, it might be queried to produce information
- about these children. In this case the dumper should use something like this:
- \c{
- if (d.dumpChildren) {
- d.beginChildren();
- [...]
- d.endChildren();
- }
- */
- #if defined(QT_BEGIN_NAMESPACE)
- QT_BEGIN_NAMESPACE
- #endif
- const char *stdStringTypeC = "std::basic_string<char,std::char_traits<char>,std::allocator<char> >";
- const char *stdWideStringTypeUShortC = "std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >";
- #if defined(QT_BEGIN_NAMESPACE)
- QT_END_NAMESPACE
- #endif
- // This can be mangled typenames of nested templates, each char-by-char
- // comma-separated integer list...
- // The output buffer.
- #ifdef MACROSDEBUG
- Q_DECL_EXPORT char xDumpInBuffer[10000];
- Q_DECL_EXPORT char xDumpOutBuffer[1000000];
- # define inBuffer xDumpInBuffer
- # define outBuffer xDumpOutBuffer
- #else
- Q_DECL_EXPORT char qDumpInBuffer[10000];
- Q_DECL_EXPORT char qDumpOutBuffer[1000000];
- # define inBuffer qDumpInBuffer
- # define outBuffer qDumpOutBuffer
- #endif
- namespace {
- static QByteArray strPtrConst = "* const";
- static bool isPointerType(const QByteArray &type)
- {
- return type.endsWith('*') || type.endsWith(strPtrConst);
- }
- static QByteArray stripPointerType(const QByteArray &_type)
- {
- QByteArray type = _type;
- if (type.endsWith('*'))
- type.chop(1);
- if (type.endsWith(strPtrConst))
- type.chop(7);
- if (type.endsWith(' '))
- type.chop(1);
- return type;
- }
- // This is used to abort evaluation of custom data dumpers in a "coordinated"
- // way. Abortion will happen at the latest when we try to access a non-initialized
- // non-trivial object, so there is no way to prevent this from occurring at all
- // conceptually. Gdb will catch SIGSEGV and return to the calling frame.
- // This is just fine provided we only _read_ memory in the custom handlers below.
- // We don't use this code for MSVC/CDB anymore.
- volatile int qProvokeSegFaultHelper;
- static const void *addOffset(const void *p, int offset)
- {
- return offset + reinterpret_cast<const char *>(p);
- }
- static const void *deref(const void *p)
- {
- return *reinterpret_cast<const char* const*>(p);
- }
- #if USE_QT_CORE
- static const void *skipvtable(const void *p)
- {
- return sizeof(void *) + reinterpret_cast<const char *>(p);
- }
- static const void *dfunc(const void *p)
- {
- return deref(skipvtable(p));
- }
- #endif
- static bool isEqual(const char *s, const char *t)
- {
- return qstrcmp(s, t) == 0;
- }
- static bool startsWith(const char *s, const char *t)
- {
- while (char c = *t++)
- if (c != *s++)
- return false;
- return true;
- }
- // Check memory for read access and provoke segfault if nothing else helps.
- // On Windows, try to be less crash-prone by checking memory using WinAPI
- #ifdef Q_OS_WIN
- # define qCheckAccess(d) do { \
- if (IsBadReadPtr(d, 1)) \
- return; \
- qProvokeSegFaultHelper = *(char*)d; \
- } while (0)
- # define qCheckPointer(d) do { \
- if (d && IsBadReadPtr(d, 1)) \
- return; \
- if (d) qProvokeSegFaultHelper = *(char*)d; \
- } while (0)
- #else
- # define qCheckAccess(d) do { \
- if (!couldBePointer(d) && d != 0) \
- return; \
- qProvokeSegFaultHelper = *(char*)d; \
- } while (0)
- # define qCheckPointer(d) do { \
- if (!couldBePointer(d)) \
- return; \
- if (d) \
- qProvokeSegFaultHelper = *(char*)d; \
- } while (0)
- static bool couldBePointer(const void *p)
- {
- // we assume valid pointer to be 4-aligned at least.
- // So use this check only when this is guaranteed.
- // FIXME: this breaks e.g. in the QString dumper...
- const quintptr d = quintptr(p);
- //qDebug() << "CHECKING : " << p << ((d & 3) == 0 && (d > 1000 || d == 0));
- //return (d & 3) == 0 && (d > 1000 || d == 0);
- return d > 1000 || d == 0;
- }
- #endif
- #ifdef QT_NAMESPACE
- const char *stripNamespace(const char *type)
- {
- static const size_t nslen = strlen(NS);
- return startsWith(type, NS) ? type + nslen : type;
- }
- #else
- inline const char *stripNamespace(const char *type)
- {
- return type;
- }
- #endif
- static bool isSimpleType(const char *type)
- {
- switch (type[0]) {
- case 'c':
- return isEqual(type, "char");
- case 'd':
- return isEqual(type, "double");
- case 'f':
- return isEqual(type, "float");
- case 'i':
- return isEqual(type, "int");
- case 'l':
- return isEqual(type, "long") || startsWith(type, "long ");
- case 's':
- return isEqual(type, "short") || startsWith(type, "short ")
- || isEqual(type, "signed") || startsWith(type, "signed ");
- case 'u':
- return isEqual(type, "unsigned") || startsWith(type, "unsigned ");
- }
- return false;
- }
- static bool isStringType(const char *type)
- {
- return isEqual(type, NS "QString")
- || isEqual(type, NS "QByteArray")
- || isEqual(type, "std::string")
- || isEqual(type, "std::wstring")
- || isEqual(type, "wstring");
- }
- #if USE_QT_CORE
- static bool isMovableType(const char *type)
- {
- if (isPointerType(type))
- return true;
- if (isSimpleType(type))
- return true;
- type = stripNamespace(type);
- switch (type[1]) {
- case 'B':
- return isEqual(type, "QBrush")
- || isEqual(type, "QBitArray")
- || isEqual(type, "QByteArray") ;
- case 'C':
- return isEqual(type, "QCustomTypeInfo")
- || isEqual(type, "QChar");
- case 'D':
- return isEqual(type, "QDate")
- || isEqual(type, "QDateTime");
- case 'F':
- return isEqual(type, "QFileInfo")
- || isEqual(type, "QFixed")
- || isEqual(type, "QFixedPoint")
- || isEqual(type, "QFixedSize");
- case 'H':
- return isEqual(type, "QHashDummyValue");
- case 'I':
- return isEqual(type, "QIcon")
- || isEqual(type, "QImage");
- case 'L':
- return isEqual(type, "QLine")
- || isEqual(type, "QLineF")
- || isEqual(type, "QLatin1Char")
- || isEqual(type, "QLocal");
- case 'M':
- return isEqual(type, "QMatrix")
- || isEqual(type, "QModelIndex");
- case 'P':
- return isEqual(type, "QPoint")
- || isEqual(type, "QPointF")
- || isEqual(type, "QPen")
- || isEqual(type, "QPersistentModelIndex");
- case 'R':
- return isEqual(type, "QResourceRoot")
- || isEqual(type, "QRect")
- || isEqual(type, "QRectF")
- || isEqual(type, "QRegExp");
- case 'S':
- return isEqual(type, "QSize")
- || isEqual(type, "QSizeF")
- || isEqual(type, "QString");
- case 'T':
- return isEqual(type, "QTime")
- || isEqual(type, "QTextBlock");
- case 'U':
- return isEqual(type, "QUrl");
- case 'V':
- return isEqual(type, "QVariant");
- case 'X':
- return isEqual(type, "QXmlStreamAttribute")
- || isEqual(type, "QXmlStreamNamespaceDeclaration")
- || isEqual(type, "QXmlStreamNotationDeclaration")
- || isEqual(type, "QXmlStreamEntityDeclaration");
- }
- return false;
- }
- #endif
- struct QDumper
- {
- explicit QDumper();
- ~QDumper();
- // direct write to the output
- QDumper &put(long c);
- QDumper &put(int i);
- QDumper &put(double d);
- QDumper &put(float d);
- QDumper &put(unsigned long c);
- QDumper &put(unsigned int i);
- QDumper &put(const void *p);
- QDumper &put(qulonglong c);
- QDumper &put(long long c);
- QDumper &put(const char *str);
- QDumper &put(const QByteArray &ba);
- QDumper &put(const QString &str);
- QDumper &put(char c);
- // convienience functions for writing key="value" pairs:
- template <class Value>
- void putItem(const char *name, const Value &value)
- {
- putCommaIfNeeded();
- put(name).put('=').put('"').put(value).put('"');
- }
- void putItem(const char *name, const char *value, const char *setvalue)
- {
- if (!isEqual(value, setvalue))
- putItem(name, value);
- }
- // convienience functions for writing typical properties.
- // roughly equivalent to
- // beginHash();
- // putItem("name", name);
- // putItem("value", value);
- // putItem("type", NS "QString");
- // putItem("numchild", "0");
- // putItem("valueencoded", "2");
- // endHash();
- void putHash(const char *name, const QString &value);
- void putHash(const char *name, const QByteArray &value);
- void putHash(const char *name, int value);
- void putHash(const char *name, long value);
- void putHash(const char *name, bool value);
- void putHash(const char *name, QChar value);
- void putHash(const char *name, float value);
- void putHash(const char *name, double value);
- void putStringValue(const QString &value);
- void beginHash(); // start of data hash output
- void endHash(); // start of data hash output
- void beginChildren(const char *mainInnerType = 0); // start of children list
- void endChildren(); // end of children list
- 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
- // 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();
- void disarm();
- void putBase64Encoded(const char *buf, int n);
- void checkFill();
- // the dumper arguments
- int protocolVersion; // dumper protocol version
- int token; // some token to show on success
- const char *outerType; // object type
- const char *iname; // object name used for display
- const char *exp; // object expression
- const char *innerType; // 'inner type' for class templates
- const void *data; // pointer to raw data
- bool dumpChildren; // do we want to see children?
- // handling of nested templates
- void setupTemplateParameters();
- enum { maxTemplateParameters = 10 };
- const char *templateParameters[maxTemplateParameters + 1];
- // internal state
- int extraInt[4];
- bool success; // are we finished?
- bool full;
- int pos;
- const char *currentChildType;
- const char *currentChildNumChild;
- };
- QDumper::QDumper()
- {
- success = false;
- full = false;
- outBuffer[0] = 'f'; // marks output as 'wrong'
- pos = 1;
- currentChildType = 0;
- currentChildNumChild = 0;
- }
- QDumper::~QDumper()
- {
- outBuffer[pos++] = '\0';
- if (success)
- outBuffer[0] = (full ? '+' : 't');
- }
- void QDumper::setupTemplateParameters()
- {
- char *s = const_cast<char *>(innerType);
- int templateParametersCount = 1;
- templateParameters[0] = s;
- for (int i = 1; i != maxTemplateParameters + 1; ++i)
- templateParameters[i] = 0;
- while (*s) {
- while (*s && *s != '@')
- ++s;
- if (*s) {
- *s = '\0';
- ++s;
- templateParameters[templateParametersCount++] = s;
- }
- }
- while (templateParametersCount < maxTemplateParameters)
- templateParameters[templateParametersCount++] = 0;
- }
- QDumper &QDumper::put(char c)
- {
- checkFill();
- if (!full)
- outBuffer[pos++] = c;
- return *this;
- }
- QDumper &QDumper::put(unsigned long long c)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%llu", c);
- return *this;
- }
- QDumper &QDumper::put(long long c)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%lld", c);
- return *this;
- }
- QDumper &QDumper::put(unsigned long c)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%lu", c);
- return *this;
- }
- QDumper &QDumper::put(float d)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%f", d);
- return *this;
- }
- QDumper &QDumper::put(double d)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%f", d);
- return *this;
- }
- QDumper &QDumper::put(unsigned int i)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%u", i);
- return *this;
- }
- QDumper &QDumper::put(long c)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%ld", c);
- return *this;
- }
- QDumper &QDumper::put(int i)
- {
- checkFill();
- pos += sprintf(outBuffer + pos, "%d", i);
- return *this;
- }
- QDumper &QDumper::put(const void *p)
- {
- if (p) {
- // Pointer is 'long long' on WIN_64, only
- static const char *printFormat = sizeof(void *) == sizeof(long) ? "0x%lx" : "0x%llx";
- pos += sprintf(outBuffer + pos, printFormat, p);
- } else {
- pos += sprintf(outBuffer + pos, "<null>");
- }
- return *this;
- }
- QDumper &QDumper::put(const char *str)
- {
- if (!str)
- return put("<null>");
- while (*str)
- put(*(str++));
- return *this;
- }
- QDumper &QDumper::put(const QByteArray &ba)
- {
- putBase64Encoded(ba.constData(), ba.size());
- return *this;
- }
- QDumper &QDumper::put(const QString &str)
- {
- putBase64Encoded((const char *)str.constData(), 2 * str.size());
- return *this;
- }
- void QDumper::checkFill()
- {
- if (pos >= int(sizeof(outBuffer)) - 100)
- full = true;
- }
- void QDumper::putCommaIfNeeded()
- {
- if (pos == 0)
- return;
- char c = outBuffer[pos - 1];
- if (c == '}' || c == '"' || c == ']')
- put(',');
- }
- void QDumper::putBase64Encoded(const char *buf, int n)
- {
- const char alphabet[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef"
- "ghijklmn" "opqrstuv" "wxyz0123" "456789+/";
- const char padchar = '=';
- int padlen = 0;
- //int tmpsize = ((n * 4) / 3) + 3;
- int i = 0;
- while (i < n) {
- int chunk = 0;
- chunk |= int(uchar(buf[i++])) << 16;
- if (i == n) {
- padlen = 2;
- } else {
- chunk |= int(uchar(buf[i++])) << 8;
- if (i == n)
- padlen = 1;
- else
- chunk |= int(uchar(buf[i++]));
- }
- int j = (chunk & 0x00fc0000) >> 18;
- int k = (chunk & 0x0003f000) >> 12;
- int l = (chunk & 0x00000fc0) >> 6;
- int m = (chunk & 0x0000003f);
- put(alphabet[j]);
- put(alphabet[k]);
- put(padlen > 1 ? padchar : alphabet[l]);
- put(padlen > 0 ? padchar : alphabet[m]);
- }
- }
- void QDumper::putStringValue(const QString &str)
- {
- if (str.isNull()) {
- beginItem("value");
- putBase64Encoded("\"\" (null)", 9);
- endItem();
- putItem("valueencoded", "5");
- } else {
- putItem("value", str);
- putItem("valueencoded", "2");
- }
- }
- void QDumper::disarm()
- {
- success = true;
- }
- void QDumper::beginHash()
- {
- putCommaIfNeeded();
- put('{');
- }
- void QDumper::endHash()
- {
- put('}');
- }
- void QDumper::putEllipsis()
- {
- putCommaIfNeeded();
- put("{name=\"<incomplete>\",value=\"\",type=\"").put(innerType).put("\"}");
- }
- void QDumper::putItemCount(const char *name, int count)
- {
- putCommaIfNeeded();
- 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
- //
- void QDumper::beginItem(const char *name)
- {
- putCommaIfNeeded();
- put(name).put('=').put('"');
- }
- void QDumper::endItem()
- {
- put('"');
- }
- void QDumper::beginChildren(const char *mainInnerType)
- {
- if (mainInnerType) {
- putItem("childtype", mainInnerType);
- currentChildType = mainInnerType;
- if (isSimpleType(mainInnerType) || isStringType(mainInnerType)) {
- putItem("childnumchild", "0");
- currentChildNumChild = "0";
- } else if (isPointerType(mainInnerType)) {
- putItem("childnumchild", "1");
- currentChildNumChild = "1";
- }
- }
- putCommaIfNeeded();
- put("children=[");
- }
- void QDumper::endChildren()
- {
- put(']');
- currentChildType = 0;
- currentChildNumChild = 0;
- }
- // simple string property
- void QDumper::putHash(const char *name, const QString &value)
- {
- beginHash();
- putItem("name", name);
- putStringValue(value);
- putItem("type", NS "QString");
- putItem("numchild", "0");
- endHash();
- }
- void QDumper::putHash(const char *name, const QByteArray &value)
- {
- beginHash();
- putItem("name", name);
- putItem("value", value);
- putItem("type", NS "QByteArray");
- putItem("numchild", "0");
- putItem("valueencoded", "1");
- endHash();
- }
- // simple integer property
- void QDumper::putHash(const char *name, int value)
- {
- beginHash();
- putItem("name", name);
- putItem("value", value);
- putItem("type", "int");
- putItem("numchild", "0");
- endHash();
- }
- void QDumper::putHash(const char *name, long value)
- {
- beginHash();
- putItem("name", name);
- putItem("value", value);
- putItem("type", "long");
- putItem("numchild", "0");
- endHash();
- }
- void QDumper::putHash(const char *name, float value)
- {
- beginHash();
- putItem("name", name);
- putItem("value", value);
- putItem("type", "float");
- putItem("numchild", "0");
- endHash();
- }
- void QDumper::putHash(const char *name, double value)
- {
- beginHash();
- putItem("name", name);
- putItem("value", value);
- putItem("type", "double");
- putItem("numchild", "0");
- endHash();
- }
- // simple boolean property
- void QDumper::putHash(const char *name, bool value)
- {
- beginHash();
- putItem("name", name);
- putItem("value", (value ? "true" : "false"));
- putItem("type", "bool");
- putItem("numchild", "0");
- endHash();
- }
- // a single QChar
- void QDumper::putHash(const char *name, QChar value)
- {
- beginHash();
- putItem("name", name);
- putStringValue(QString(QLatin1String("'%1' (%2, 0x%3)"))
- .arg(value).arg(value.unicode()).arg(value.unicode(), 0, 16));
- putItem("type", NS "QChar");
- putItem("numchild", "0");
- endHash();
- }
- #define DUMPUNKNOWN_MESSAGE "<not in scope>"
- static void qDumpUnknown(QDumper &d, const char *why = 0)
- {
- if (!why)
- why = DUMPUNKNOWN_MESSAGE;
- d.putItem("value", why);
- d.putItem("valueeditable", "false");
- d.putItem("valueenabled", "false");
- d.putItem("numchild", "0", d.currentChildNumChild);
- d.disarm();
- }
- static void qDumpStdStringValue(QDumper &d, const std::string &str)
- {
- d.beginItem("value");
- d.putBase64Encoded(str.c_str(), str.size());
- d.endItem();
- d.putItem("valueencoded", "1");
- d.putItem("type", "std::string");
- d.putItem("numchild", "0", d.currentChildNumChild);
- }
- static void qDumpStdWStringValue(QDumper &d, const std::wstring &str)
- {
- d.beginItem("value");
- d.putBase64Encoded((const char *)str.c_str(), str.size() * sizeof(wchar_t));
- d.endItem();
- d.putItem("valueencoded", (sizeof(wchar_t) == 2 ? "2" : "3"));
- d.putItem("type", "std::wstring", d.currentChildType);
- d.putItem("numchild", "0", d.currentChildNumChild);
- }
- // Called by templates, so, not static.
- static void qDumpInnerQCharValue(QDumper &d, QChar c, const char *field)
- {
- char buf[30];
- sprintf(buf, "'?', ucs=%d", c.unicode());
- if (c.isPrint() && c.unicode() < 127)
- buf[1] = char(c.unicode());
- d.putCommaIfNeeded();
- d.putItem(field, buf);
- d.putItem("numchild", "0", d.currentChildNumChild);
- }
- static void qDumpInnerCharValue(QDumper &d, char c, const char *field)
- {
- char buf[30];
- sprintf(buf, "'?', ascii=%d", c);
- if (QChar(QLatin1Char(c)).isPrint() && c < 127)
- buf[1] = c;
- d.putCommaIfNeeded();
- d.putItem(field, buf);
- d.putItem("numchild", "0", d.currentChildNumChild);
- }
- void qDumpInnerValueHelper(QDumper &d, const char *type, const void *addr,
- const char *field = "value")
- {
- type = stripNamespace(type);
- switch (type[1]) {
- case 'h':
- if (isEqual(type, "char"))
- qDumpInnerCharValue(d, *(char *)addr, field);
- break;
- case 'l':
- if (isEqual(type, "float"))
- d.putItem(field, *(float*)addr);
- break;
- case 'n':
- if (isEqual(type, "int"))
- d.putItem(field, *(int*)addr);
- else if (isEqual(type, "unsigned") || isEqual(type, "unsigned int"))
- d.putItem(field, *(unsigned int*)addr);
- else if (isEqual(type, "unsigned char"))
- qDumpInnerCharValue(d, *(char *)addr, field);
- else if (isEqual(type, "unsigned long"))
- d.putItem(field, *(unsigned long*)addr);
- else if (isEqual(type, "unsigned long long"))
- d.putItem(field, *(qulonglong*)addr);
- break;
- case 'o':
- if (isEqual(type, "bool")) {
- switch (*(unsigned char*)addr) {
- case 0: d.putItem(field, "false"); break;
- case 1: d.putItem(field, "true"); break;
- default: d.putItem(field, *(unsigned char*)addr); break;
- }
- } else if (isEqual(type, "double"))
- d.putItem(field, *(double*)addr);
- else if (isEqual(type, "long"))
- d.putItem(field, *(long*)addr);
- else if (isEqual(type, "long long"))
- d.putItem(field, *(qulonglong*)addr);
- break;
- case 'B':
- if (isEqual(type, "QByteArray")) {
- d.putCommaIfNeeded();
- d.put(field).put("encoded=\"1\",");
- d.putItem(field, *(QByteArray*)addr);
- }
- break;
- case 'C':
- if (isEqual(type, "QChar"))
- qDumpInnerQCharValue(d, *(QChar*)addr, field);
- break;
- case 'L':
- if (startsWith(type, "QList<")) {
- const QListData *ldata = reinterpret_cast<const QListData*>(addr);
- d.putItemCount("value", ldata->size());
- d.putItem("valueeditable", "false");
- d.putItem("numchild", ldata->size());
- }
- break;
- case 'O':
- # ifndef QT_BOOTSTRAPPED
- if (isEqual(type, "QObject *")) {
- if (addr) {
- const QObject *ob = reinterpret_cast<const QObject *>(addr);
- d.putItem("addr", ob);
- d.putItem("value", ob->objectName());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QObject");
- d.putItem("displayedtype", ob->metaObject()->className());
- d.putItem("numchild", 1);
- } else {
- d.putItem("value", "0x0");
- d.putItem("type", NS "QObject *");
- d.putItem("numchild", 0);
- }
- }
- # endif
- break;
- case 'S':
- if (isEqual(type, "QString")) {
- d.putCommaIfNeeded();
- d.putItem(field, *(QString*)addr);
- d.put(',').put(field).put("encoded=\"2\"");
- }
- break;
- case 't':
- if (isEqual(type, "std::string")
- || isEqual(type, stdStringTypeC)) {
- d.putCommaIfNeeded();
- qDumpStdStringValue(d, *reinterpret_cast<const std::string*>(addr));
- } else if (isEqual(type, "std::wstring")
- || isEqual(type, stdWideStringTypeUShortC)) {
- qDumpStdWStringValue(d, *reinterpret_cast<const std::wstring*>(addr));
- }
- break;
- default:
- break;
- }
- }
- #if USE_QT_CORE
- static void qDumpInnerValue(QDumper &d, const char *type, const void *addr)
- {
- d.putItem("addr", addr);
- d.putItem("type", type, d.currentChildType);
- if (!type[0])
- return;
- return qDumpInnerValueHelper(d, type, addr);
- }
- #endif
- static void qDumpInnerValueOrPointer(QDumper &d,
- const char *type, const char *strippedtype, const void *addr)
- {
- if (strippedtype) {
- if (deref(addr)) {
- d.putItem("addr", deref(addr));
- d.putItem("type", strippedtype, d.currentChildType);
- qDumpInnerValueHelper(d, strippedtype, deref(addr));
- } else {
- d.putItem("addr", addr);
- d.putItem("type", strippedtype);
- d.putItem("value", "<null>");
- d.putItem("numchild", "0");
- }
- } else {
- d.putItem("addr", addr);
- d.putItem("type", type, d.currentChildType);
- qDumpInnerValueHelper(d, type, addr);
- }
- }
- //////////////////////////////////////////////////////////////////////////////
- #if USE_QT_CORE
- #ifndef QT_BOOTSTRAPPED
- struct ModelIndex { int r; int c; void *p; void *m; };
- static void qDumpQAbstractItem(QDumper &d)
- {
- QModelIndex mi;
- {
- ModelIndex *mm = reinterpret_cast<ModelIndex *>(&mi);
- memset(&mi, 0, sizeof(mi));
- static const char *printFormat = sizeof(void *) == sizeof(long) ?
- "%d,%d,0x%lx,0x%lx" : "%d,%d,0x%llx,0x%llx";
- sscanf(d.templateParameters[0], printFormat, &mm->r, &mm->c, &mm->p, &mm->m);
- }
- const QAbstractItemModel *m = mi.model();
- const int rowCount = m->rowCount(mi);
- if (rowCount < 0)
- return;
- const int columnCount = m->columnCount(mi);
- if (columnCount < 0)
- return;
- d.putItem("type", NS "QAbstractItem");
- d.beginItem("addr");
- d.put('$').put(mi.row()).put(',').put(mi.column()).put(',')
- .put(mi.internalPointer()).put(',').put(mi.model());
- d.endItem();
- //d.putItem("value", "(").put(rowCount).put(",").put(columnCount).put(")");
- d.putItem("value", m->data(mi, Qt::DisplayRole).toString());
- d.putItem("valueencoded", "2");
- d.putItem("numchild", rowCount * columnCount);
- if (d.dumpChildren) {
- d.beginChildren();
- for (int row = 0; row < rowCount; ++row) {
- for (int column = 0; column < columnCount; ++column) {
- QModelIndex child = m->index(row, column, mi);
- d.beginHash();
- d.beginItem("name");
- d.put("[").put(row).put(",").put(column).put("]");
- d.endItem();
- //d.putItem("numchild", (m->hasChildren(child) ? "1" : "0"));
- d.putItem("numchild", m->rowCount(child) * m->columnCount(child));
- d.beginItem("addr");
- d.put("$").put(child.row()).put(",").put(child.column()).put(",")
- .put(child.internalPointer()).put(",").put(child.model());
- d.endItem();
- d.putItem("type", NS "QAbstractItem");
- d.putItem("value", m->data(child, Qt::DisplayRole).toString());
- d.putItem("valueencoded", "2");
- d.endHash();
- }
- }
- /*
- d.beginHash();
- d.putItem("name", "DisplayRole");
- d.putItem("numchild", 0);
- d.putItem("value", m->data(mi, Qt::DisplayRole).toString());
- d.putItem("valueencoded", 2);
- d.putItem("type", NS "QString");
- d.endHash();
- */
- d.endChildren();
- }
- d.disarm();
- }
- static void qDumpQAbstractItemModel(QDumper &d)
- {
- const QAbstractItemModel &m = *reinterpret_cast<const QAbstractItemModel *>(d.data);
- const int rowCount = m.rowCount();
- if (rowCount < 0)
- return;
- const int columnCount = m.columnCount();
- if (columnCount < 0)
- return;
- d.putItem("type", NS "QAbstractItemModel");
- d.beginItem("value");
- d.put("(").put(rowCount).put(",").put(columnCount).put(")");
- d.endItem();
- d.putItem("numchild", "1");
- if (d.dumpChildren) {
- d.beginChildren();
- d.beginHash();
- d.putItem("numchild", "1");
- d.putItem("name", NS "QObject");
- d.putItem("addr", d.data);
- d.putItem("value", m.objectName());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QObject");
- d.putItem("displayedtype", m.metaObject()->className());
- d.endHash();
- for (int row = 0; row < rowCount; ++row) {
- for (int column = 0; column < columnCount; ++column) {
- QModelIndex mi = m.index(row, column);
- d.beginHash();
- d.beginItem("name");
- d.put("[").put(row).put(",").put(column).put("]");
- d.endItem();
- d.putItem("value", m.data(mi, Qt::DisplayRole).toString());
- d.putItem("valueencoded", "2");
- //d.putItem("numchild", (m.hasChildren(mi) ? "1" : "0"));
- d.putItem("numchild", m.rowCount(mi) * m.columnCount(mi));
- d.beginItem("addr");
- d.put("$").put(mi.row()).put(",").put(mi.column()).put(",");
- d.put(mi.internalPointer()).put(",").put(mi.model());
- d.endItem();
- d.putItem("type", NS "QAbstractItem");
- d.endHash();
- }
- }
- d.endChildren();
- }
- d.disarm();
- }
- #endif // QT_BOOTSTRAPPED
- static void qDumpQByteArray(QDumper &d)
- {
- qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
- const QByteArray &ba = *reinterpret_cast<const QByteArray *>(d.data);
- const int size = ba.size();
- if (size < 0)
- return;
- if (!ba.isEmpty()) {
- qCheckAccess(ba.constData());
- qCheckAccess(ba.constData() + size);
- }
- d.beginItem("value");
- if (size <= 100)
- d.put(ba);
- else
- d.put(ba.left(100)).put(" <size: ").put(size).put(", cut...>");
- d.endItem();
- d.putItem("valueencoded", "1");
- d.putItem("type", NS "QByteArray");
- d.putItem("numchild", size);
- if (d.dumpChildren) {
- d.putItem("childtype", "char");
- d.putItem("childnumchild", "0");
- d.beginChildren();
- char buf[20];
- for (int i = 0; i != size; ++i) {
- unsigned char c = ba.at(i);
- unsigned char u = (isprint(c) && c != '\'' && c != '"') ? c : '?';
- sprintf(buf, "%02x (%u '%c')", c, c, u);
- d.beginHash();
- d.putItem("value", buf);
- d.endHash();
- }
- d.endChildren();
- }
- d.disarm();
- }
- static void qDumpQChar(QDumper &d)
- {
- qDumpInnerQCharValue(d, *reinterpret_cast<const QChar *>(d.data), "value");
- d.disarm();
- }
- static void qDumpQDate(QDumper &d)
- {
- #ifdef QT_NO_DATESTRING
- qDumpUnknown(d);
- #else
- const QDate &date = *reinterpret_cast<const QDate *>(d.data);
- if (date.isNull()) {
- d.putItem("value", "(null)");
- d.putItem("type", NS "QDate");
- d.putItem("numchild", "0");
- return;
- }
- d.putItem("value", date.toString());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QDate");
- d.putItem("numchild", "1");
- if (d.dumpChildren) {
- d.beginChildren();
- d.putHash("isNull", date.isNull());
- d.putHash("toString", date.toString());
- # if QT_VERSION >= 0x040500
- d.putHash("toString_(ISO)", date.toString(Qt::ISODate));
- d.putHash("toString_(SystemLocale)", date.toString(Qt::SystemLocaleDate));
- d.putHash("toString_(Locale)", date.toString(Qt::LocaleDate));
- # endif
- d.endChildren();
- }
- d.disarm();
- #endif // ifdef QT_NO_DATESTRING
- }
- static void qDumpQTime(QDumper &d)
- {
- #ifdef QT_NO_DATESTRING
- qDumpUnknown(d);
- #else
- const QTime &date = *reinterpret_cast<const QTime *>(d.data);
- if (date.isNull()) {
- d.putItem("value", "(null)");
- d.putItem("type", NS "QTime");
- d.putItem("numchild", "0");
- return;
- }
- d.putItem("value", date.toString());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QTime");
- d.putItem("numchild", "1");
- if (d.dumpChildren) {
- d.beginChildren();
- d.putHash("isNull", date.isNull());
- d.putHash("toString", date.toString());
- # if QT_VERSION >= 0x040500
- d.putHash("toString_(ISO)", date.toString(Qt::ISODate));
- d.putHash("toString_(SystemLocale)", date.toString(Qt::SystemLocaleDate));
- d.putHash("toString_(Locale)", date.toString(Qt::LocaleDate));
- # endif
- d.endChildren();
- }
- d.disarm();
- #endif // ifdef QT_NO_DATESTRING
- }
- static void qDumpQDateTime(QDumper &d)
- {
- #ifdef QT_NO_DATESTRING
- qDumpUnknown(d);
- #else
- const QDateTime &date = *reinterpret_cast<const QDateTime *>(d.data);
- if (date.isNull()) {
- d.putItem("value", "(null)");
- d.putItem("type", NS "QDateTime");
- d.putItem("numchild", "0");
- d.disarm();
- return;
- }
- d.putItem("value", date.toString());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QDateTime");
- d.putItem("numchild", "1");
- if (d.dumpChildren) {
- d.beginChildren();
- d.putHash("toTime_t", (long)date.toTime_t());
- d.putHash("toString", date.toString());
- # if QT_VERSION >= 0x040500
- d.putHash("toString_(ISO)", date.toString(Qt::ISODate));
- d.putHash("toString_(SystemLocale)", date.toString(Qt::SystemLocaleDate));
- d.putHash("toString_(Locale)", date.toString(Qt::LocaleDate));
- # endif
- # if 0
- d.beginHash();
- d.putItem("name", "toUTC");
- d.putItem("exp", "((" NSX "QDateTime" NSY "*)").put(d.data).put(")"
- "->toTimeSpec('" NS "Qt::UTC')");
- d.putItem("type", NS "QDateTime");
- d.putItem("numchild", "1");
- d.endHash();
- # endif
- # if 0
- d.beginHash();
- d.putItem("name", "toLocalTime");
- d.putItem("exp", "((" NSX "QDateTime" NSY "*)").put(d.data).put(")"
- "->toTimeSpec('" NS "Qt::LocalTime')");
- d.putItem("type", NS "QDateTime");
- d.putItem("numchild", "1");
- d.endHash();
- # endif
- d.endChildren();
- }
- d.disarm();
- #endif // ifdef QT_NO_DATESTRING
- }
- static void qDumpQDir(QDumper &d)
- {
- const QDir &dir = *reinterpret_cast<const QDir *>(d.data);
- d.putItem("value", dir.path());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QDir");
- d.putItem("numchild", "3");
- if (d.dumpChildren) {
- d.beginChildren();
- d.putHash("absolutePath", dir.absolutePath());
- d.putHash("canonicalPath", dir.canonicalPath());
- d.endChildren();
- }
- d.disarm();
- }
- static void qDumpQFile(QDumper &d)
- {
- const QFile &file = *reinterpret_cast<const QFile *>(d.data);
- d.putItem("value", file.fileName());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QFile");
- d.putItem("numchild", "2");
- if (d.dumpChildren) {
- d.beginChildren();
- d.putHash("fileName", file.fileName());
- d.putHash("exists", file.exists());
- d.endChildren();
- }
- d.disarm();
- }
- static void qDumpQFileInfo(QDumper &d)
- {
- const QFileInfo &info = *reinterpret_cast<const QFileInfo *>(d.data);
- d.putItem("value", info.filePath());
- d.putItem("valueencoded", "2");
- d.putItem("type", NS "QFileInfo");
- d.putItem("numchild", "3");
- if (d.dumpChildren) {
- d.beginChildren();
- d.putHash("absolutePath", info.absolutePath());
- d.putHash("absoluteFilePath", info.absoluteFilePath());
- d.putHash("canonicalPath", info.canonicalPath());
- d.putHash("canonicalFilePath", info.canonicalFilePath());
- d.putHash("completeBaseName", info.completeBaseName());
- d.putHash("completeSuffix", info.completeSuffix());
- d.putHash("baseName", info.baseName());
- #ifdef Q_OS_MACX
- d.putHash("isBundle", info.isBundle());
- d.putHash("bundleName", info.bundleName());
- #endif
- d.putHash("fileName", info.fileName());
- d.putHash("filePath", info.filePath());
- d.putHash("group", info.group());
- d.putHash("owner", info.owner());
- d.putHash("path", info.path());
- d.putHash("groupid", (long)info.groupId());
- d.putHash("ownerid", (long)info.ownerId());
- //QFile::Permissions permissions () const
- long perms = info.permissions();
- d.beginHash();
- d.putItem("name", "permissions");
- d.putItem("value", " ");
- d.putItem("type", NS "QFile::Permissions");
- d.putItem("numchild", 10);
- d.beginChildren();
- d.putHash("ReadOwner", bool(perms & QFile::ReadOwner));
- d.putHash("WriteOwner", bool(perms & QFile::WriteOwner));
- d.putHash("ExeOwner", bool(perms & QFile::ExeOwner));
- d.putHash("ReadUser", bool(perms & QFile::ReadUser));
- d.putHash("WriteUser", bool(perms & QFile::WriteUser));
- d.putHash("ExeUser", bool(perms & QFile::ExeUser));
- d.putHash("ReadGroup", bool(perms & QFile::ReadGroup));
- d.putHash("WriteGroup", bool(perms & QFile::WriteGroup));
- d.putHash("ExeGroup", bool(perms & QFile::ExeGroup));
- d.putHash("ReadOther", bool(perms & QFile::ReadOther));
- d.putHash("WriteOther", bool(perms & QFile::WriteOther));
- d.putHash("ExeOther", bool(perms & QFile::ExeOther));
- d.endChildren();
- d.endHash();
- //QDir absoluteDir () const
- //QDir dir () const
- d.putHash("caching", info.caching());
- d.putHash("exists", info.exists());
- d.putHash("isAbsolute", info.isAbsolute());
- d.putHash("isDir", info.isDir());
- d.putHash("isExecutable", info.isExecutable());
- d.putHash("isFile", info.isFile());
- d.putHash("isHidden", info.isHidden());
- d.putHash("isReadable", info.isReadable());
- d.putHash("isRelative", info.isRelative());
- d.putHash("isRoot", info.isRoot());
- d.putHash("isSymLink", info.isSymLink());
- d.putHash("isWritable", info.isWritable());
- d.beginHash();
- d.putItem("name", "created");
- d.putItem("value", info.created().toString());
- d.putItem("valueencoded", "2");
- d.beginItem("exp");
- d.put("((" NSX "QFileInfo" NSY "*)").put(d.data).put(")->created()");
- d.endItem();
- d.putItem("type", NS "QDateTime");
- d.putItem("numchild", "1");
- d.endHash();
- d.beginHash();
- d.putItem("name", "lastModified");
- d.putItem("value", info.lastModified().toString());
- d.putItem("valueencoded", "2");
- d.beginItem("exp");
- d.put("((" NSX "QFileInfo" NSY "*)").put(d.data).put(")->lastModified()");
- d.endItem();
- d.putItem("type", NS "QDateTime");
- d.putItem("numchild", "1");
- d.endHash();
- d.beginHash();
- d.putItem("name", "lastRead");
- d.putItem("value", info.lastRead().toString());
- d.putItem("valueencoded", "2");
- d.beginItem("exp");
- d.put("((" NSX "QFileInfo" NSY "*)").put(d.data).put(")->lastRead()");
- d.endItem();
- d.putItem("type", NS "QDateTime");
- d.putItem("numchild", "1");
- d.endHash();
- d.endChildren();
- }
- d.disarm();
- }
- bool isOptimizedIntKey(const char *keyType)
- {
- return isEqual(keyType, "int")
- #if defined(Q_BYTE_ORDER) && Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- || isEqual(keyType, "short")
- || isEqual(keyType, "ushort")
- #endif
- || isEqual(keyType, "uint");
- }
- int hashOffset(bool optimizedIntKey, bool forKey, unsigned keySize, unsigned valueSize)
- {
- // int-key optimization, small value
- struct NodeOS { void *next; uint k; uint v; } nodeOS;
- // int-key optimiatzion, large value
- struct NodeOL { void *next; uint k; void *v; } nodeOL;
- // no optimization, small value
- struct NodeNS { void *next; uint h; uint k; uint v; } nodeNS;
- // no optimization, large value
- struct NodeNL { void *next; uint h; uint k; void *v; } nodeNL;
- // complex key
- struct NodeL { void *next; uint h; void *k; void *v; } nodeL;
- if (forKey) {
- // offsetof(...,...) not yet in Standard C++
- const ulong nodeOSk ( (char *)&nodeOS.k - (char *)&nodeOS );
- const ulong nodeOLk ( (char *)&nodeOL.k - (char *)&nodeOL );
- const ulong nodeNSk ( (char *)&nodeNS.k - (char *)&nodeNS );
- const ulong nodeNLk ( (char *)&nodeNL.k - (char *)&nodeNL );
- const ulong nodeLk ( (char *)&nodeL.k - (char *)&nodeL );
- if (optimizedIntKey)
- return valueSize > sizeof(int) ? nodeOLk : nodeOSk;
- if (keySize > sizeof(int))
- return nodeLk;
- return valueSize > sizeof(int) ? nodeNLk : nodeNSk;
- } else {
- const ulong nodeOSv ( (char *)&nodeOS.v - (char *)&nodeOS );
- const ulong nodeOLv ( (char *)&nodeOL.v - (char *)&nodeOL );
- const ulong nodeNSv ( (char *)&nodeNS.v - (char *)&nodeNS );
- const ulong nodeNLv ( (char *)&nodeNL.v - (char *)&nodeNL );
- const ulong nodeLv ( (char *)&nodeL.v - (char *)&nodeL );
- if (optimizedIntKey)
- return valueSize > sizeof(int) ? nodeOLv : nodeOSv;
- if (keySize > sizeof(int))
- return nodeLv;
- return valueSize > sizeof(int) ? nodeNLv : nodeNSv;
- }
- }
- static void qDumpQHash(QDumper &d)
- {
- qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
- const char *keyType = d.templateParameters[0];
- const char *valueType = d.templateParameters[1];
- QHashData *h = *reinterpret_cast<QHashData *const*>(d.data);
- qCheckPointer(h->fakeNext);
- qCheckPointer(h->buckets);
- unsigned keySize = d.extraInt[0];
- unsigned valueSize = d.extraInt[1];
- int n = h->size;
- if (n < 0)
- return;
- if (n > 0) {
- qCheckPointer(h->fakeNext);
- qCheckPointer(*h->buckets);
- }
- d.putItemCount("value", n);
- d.putItem("numchild", n);
- if (d.dumpChildren) {
- const bool isSimpleKey = isSimpleType(keyType);
- const bool isSimpleValue = isSimpleType(valueType);
- const bool opt = isOptimizedIntKey(keyType);
- const int keyOffset = hashOffset(opt, true, keySize, valueSize);
- const int valueOffset = hashOffset(opt, false, keySize, valueSize);
- #if 0
- d.beginItem("extra");
- d.put("isSimpleKey: ").put(isSimpleKey);
- d.put(" isSimpleValue: ").put(isSimpleValue);
- d.put(" valueType: '").put(isSimpleValue);
- d.put(" keySize: ").put(keyOffset);
- d.put(" valueOffset: ").put(valueOffset);
- d.put(" opt: ").put(opt);
- d.endItem();
- #endif
- QHashData::Node *node = h->firstNode();
- QHashData::Node *end = reinterpret_cast<QHashData::Node *>(h);
- int i = 0;
- d.beginChildren();
- while (node != end) {
- d.beginHash();
- qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key");
- qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
- if (isSimpleKey && isSimpleValue) {
- d.putItem("type", valueType);
- d.putItem("addr", addOffset(node, valueOffset));
- } else {
- d.putItem("addr", node);
- d.beginItem("type");
- d.put(NS "QHashNode<").put(keyType).put(",")
- .put(valueType).put(" >");
- d.endItem();
- }
- d.endHash();
- ++i;
- node = QHashData::nextNode(node);
- }
- d.endChildren();
- }
- d.disarm();
- }
- static void qDumpQHashNode(QDumper &d)
- {
- const QHashData *h = reinterpret_cast<const QHashData *>(d.data);
- const char *keyType = d.templateParameters[0];
- const char *valueType = d.templateParameters[1];
- unsigned keySize = d.extraInt[0];
- unsigned valueSize = d.extraInt[1];
- bool opt = isOptimizedIntKey(keyType);
- int keyOffset = hashOffset(opt, true, keySize, valueSize);
- int valueOffset = hashOffset(opt, false, keySize, valueSize);
- if (isSimpleType(valueType))
- qDumpInnerValueHelper(d, valueType, addOffset(h, valueOffset));
- else
- d.putItem("value", "");
- d.putItem("numchild", 2);
- if (d.dumpChildren) {
- // there is a hash specialization in case the keys are integers or shorts
- d.beginChildren();
- d.beginHash();
- d.putItem("name", "key");
- d.putItem("type", keyType);
- d.putItem("…
Large files files are truncated, but you can click here to view the full file