diff --git a/share/qtcreator/gdbmacros/gdbmacros.cpp b/share/qtcreator/gdbmacros/gdbmacros.cpp index 63fa934a2e7ae69746ac447a098faeed70dbbbe3..36f68f5d08c6104c587162651bc9c4e75e5d9699 100644 --- a/share/qtcreator/gdbmacros/gdbmacros.cpp +++ b/share/qtcreator/gdbmacros/gdbmacros.cpp @@ -157,19 +157,6 @@ int qtGhVersion = QT_VERSION; */ -#undef NS -#ifdef QT_NAMESPACE -# define STRINGIFY0(s) #s -# define STRINGIFY1(s) STRINGIFY0(s) -# define NS STRINGIFY1(QT_NAMESPACE) "::" -# define NSX "'" STRINGIFY1(QT_NAMESPACE) "::" -# define NSY "'" -#else -# define NS "" -# define NSX "" -# define NSY "" -#endif - #if defined(QT_BEGIN_NAMESPACE) QT_BEGIN_NAMESPACE #endif diff --git a/share/qtcreator/gdbmacros/gdbmacros_p.h b/share/qtcreator/gdbmacros/gdbmacros_p.h index c1aebd425eaa9e62375b3e5661a3d0b53fdc6cea..dc756597cf817488d8716c74e82667b3654239fb 100644 --- a/share/qtcreator/gdbmacros/gdbmacros_p.h +++ b/share/qtcreator/gdbmacros/gdbmacros_p.h @@ -44,6 +44,19 @@ #include <QtCore/QObject> +#undef NS +#ifdef QT_NAMESPACE +# define STRINGIFY0(s) #s +# define STRINGIFY1(s) STRINGIFY0(s) +# define NS STRINGIFY1(QT_NAMESPACE) "::" +# define NSX "'" STRINGIFY1(QT_NAMESPACE) "::" +# define NSY "'" +#else +# define NS "" +# define NSX "" +# define NSY "" +#endif + #if defined(QT_BEGIN_NAMESPACE) QT_BEGIN_NAMESPACE #endif diff --git a/tests/auto/debugger/main.cpp b/tests/auto/debugger/main.cpp index c7aa75897b340ac9ca9dcd7b5438ac027fd08e1d..ada35ff8a12601a81cbfad33101b824e1803ccb3 100644 --- a/tests/auto/debugger/main.cpp +++ b/tests/auto/debugger/main.cpp @@ -147,6 +147,7 @@ private slots: void dumpQFile(); void dumpQFileInfo(); void dumpQHash(); + void dumpQHashNode(); void dumpQImage(); void dumpQImageData(); void dumpQList_int(); @@ -154,6 +155,7 @@ private slots: void dumpQList_QString(); void dumpQList_QString3(); void dumpQList_Int3(); + void dumpQLocale(); void dumpQMap(); void dumpQMapNode(); void dumpQObject(); @@ -193,8 +195,10 @@ private: void dumpQDateTimeHelper(QDateTime &d); void dumpQDirHelper(QDir &d); void dumpQFileHelper(const QString &name, bool exists); + template <typename K, typename V> void dumpQHashNodeHelper(QHash<K, V> &hash); void dumpQImageHelper(QImage &img); void dumpQImageDataHelper(QImage &img); + void dumpQLocaleHelper(QLocale &loc); template <typename K, typename V> void dumpQMapHelper(QMap<K, V> &m); template <typename K, typename V> void dumpQMapNodeHelper(QMap<K, V> &m); void dumpQObjectChildListHelper(QObject &o); @@ -488,6 +492,13 @@ static const QByteArray generateQStringSpec(const QString& str) append("',type='"NS"QString',numchild='0',valueencoded='2'"); } +static const QByteArray generateQCharSpec(const QChar& ch) +{ + return QByteArray("value='").append(utfToBase64(QString(QLatin1String("'%1' (%2, 0x%3)")). + arg(ch).arg(ch.unicode()).arg(ch.unicode(), 0, 16))). + append("',valueencoded='2',type='"NS"QChar',numchild='0'"); +} + static const QByteArray generateBoolSpec(bool b) { return QByteArray("value=").append(boolToVal(b)).append(",type='bool',numchild='0'"); @@ -510,6 +521,12 @@ static const QByteArray generateIntSpec(int n) return generateIntegerSpec(n, "int"); } +const QString createExp(const void *ptr, const QString &type, const QString &method) +{ + return QString("exp='((").append(NSX).append(type).append(NSY).append("*)"). + append(ptrToBa(ptr)).append(")->").append(method).append("()'"); +} + // Helper functions. #ifdef Q_CC_MSVC @@ -924,7 +941,6 @@ void tst_Debugger::dumpQFileInfo() append("{name='isBundle',").append(generateBoolSpec(fi.isBundle()).append("},"). append("{name='bundleName',").append(generateQStringSpec(fi.bundleName())).append("'},"). #endif - append("{name='completeSuffix',").append(generateQStringSpec(fi.completeSuffix())).append("},"). append("{name='fileName',").append(generateQStringSpec(fi.fileName())).append("},"). append("{name='filePath',").append(generateQStringSpec(fi.filePath())).append("},"). append("{name='group',").append(generateQStringSpec(fi.group())).append("},"). @@ -946,26 +962,15 @@ void tst_Debugger::dumpQFileInfo() append("{name='isSymLink',").append(generateBoolSpec(fi.isSymLink())).append("},"). append("{name='isWritable',").append(generateBoolSpec(fi.isWritable())).append("},"). append("{name='created',value='").append(utfToBase64(fi.created().toString())). - append("',valueencoded='2',type='"NS"QDateTime',numchild='1'},"). - -#if 0 - ??? - 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(); -#endif - - append("]"); - - - // testDumper(expected, &fi, NS"QFileInfo", true); + append("',valueencoded='2',").append(createExp(&fi, "QFileInfo", "created")). + append(",type='"NS"QDateTime',numchild='1'},").append("{name='lastModified',value='"). + append(utfToBase64(fi.lastModified().toString())).append("',valueencoded='2',"). + append(createExp(&fi, "QFileInfo", "lastModified")). + append(",type='"NS"QDateTime',numchild='1'},"). + append("{name='lastRead',value='").append(utfToBase64(fi.lastRead().toString())). + append("',valueencoded='2',").append(createExp(&fi, "QFileInfo", "lastRead")). + append(",type='"NS"QDateTime',numchild='1'}]"); + testDumper(expected, &fi, NS"QFileInfo", true); } void tst_Debugger::dumpQHash() @@ -977,6 +982,50 @@ void tst_Debugger::dumpQHash() hash.insert("!", QList<int>() << 1 << 2); } +template <typename K, typename V> + void tst_Debugger::dumpQHashNodeHelper(QHash<K, V> &hash) +{ + typename QHash<K, V>::iterator it = hash.begin(); + typedef QHashNode<K, V> HashNode; + HashNode *node = + reinterpret_cast<HashNode *>(reinterpret_cast<char *>(const_cast<K *>(&it.key())) - + offsetof(HashNode, key)); + const K &key = it.key(); + const V &val = it.value(); + QByteArray expected("value='"); + if (isSimpleType(val)) + expected.append(valToString(val)); + expected.append("',numchild='2',children=[{name='key',type='"). + append(typeToString(key)).append("',addr='").append(ptrToBa(&key)). + append("'},{name='value',type='").append(typeToString(val)). + append("',addr='").append(ptrToBa(&val)).append("'}]"); + testDumper(expected, node, NS"QHashNode", true, + getMapType(it.key(), it.value()), "", sizeof(it.key()), sizeof(it.value())); +} + +void tst_Debugger::dumpQHashNode() +{ + // Case 1: simple type -> simple type. + QHash<int, int> hash1; + hash1[2] = 3; + dumpQHashNodeHelper(hash1); + + // Case 2: simple type -> composite type. + QHash<int, QString> hash2; + hash2[5] = "String 7"; + dumpQHashNodeHelper(hash2); + + // Case 3: composite type -> simple type + QHash<QString, int> hash3; + hash3["String 11"] = 13; + dumpQHashNodeHelper(hash3); + + // Case 4: composite type -> composite type + QHash<QString, QString> hash4; + hash4["String 17"] = "String 19"; + dumpQHashNodeHelper(hash4); +} + void tst_Debugger::dumpQImageHelper(QImage &img) { QByteArray expected = QByteArray("value='("). @@ -1102,6 +1151,42 @@ void tst_Debugger::dumpQList_QString3() &s3list, NS"QList", true, "QString3"); } +void tst_Debugger::dumpQLocaleHelper(QLocale &loc) +{ + QByteArray expected = QByteArray("value='").append(valToString(loc.name())). + append("',type='"NS"QLocale',numchild='8',children=[{name='country',"). + append(createExp(&loc, "QLocale", "country")).append("},{name='language',"). + append(createExp(&loc, "QLocale", "language")).append("},{name='measurementSystem',"). + append(createExp(&loc, "QLocale", "measurementSystem")). + append("},{name='numberOptions',").append(createExp(&loc, "QLocale", "numberOptions")). + append("},{name='timeFormat_(short)',"). + append(generateQStringSpec(loc.timeFormat(QLocale::ShortFormat))). + append("},{name='timeFormat_(long)',").append(generateQStringSpec(loc.timeFormat())). + append("},{name='decimalPoint',").append(generateQCharSpec(loc.decimalPoint())). + append("},{name='exponential',").append(generateQCharSpec(loc.exponential())). + append("},{name='percent',").append(generateQCharSpec(loc.percent())). + append("},{name='zeroDigit',").append(generateQCharSpec(loc.zeroDigit())). + append("},{name='groupSeparator',").append(generateQCharSpec(loc.groupSeparator())). + append("},{name='negativeSign',").append(generateQCharSpec(loc.negativeSign())). + append("}]"); + testDumper(expected, &loc, NS"QLocale", true); +} + +void tst_Debugger::dumpQLocale() +{ + QLocale english(QLocale::English); + dumpQLocaleHelper(english); + + QLocale german(QLocale::German); + dumpQLocaleHelper(german); + + QLocale chinese(QLocale::Chinese); + dumpQLocaleHelper(chinese); + + QLocale swahili(QLocale::Swahili); + dumpQLocaleHelper(swahili); +} + template <typename K, typename V> const QByteArray getMapType(K keyDummy, V valDummy) { return QByteArray(typeToString(keyDummy)) + "@" + QByteArray(typeToString(valDummy));