PageRenderTime 134ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/share/qtcreator/dumper/dumper.cpp

https://bitbucket.org/kpozn/qt-creator-py-reborn
C++ | 3812 lines | 3347 code | 262 blank | 203 comment | 479 complexity | 06d9224422c78910876a1048c0151946 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**************************************************************************
  2. **
  3. ** This file is part of Qt Creator
  4. **
  5. ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
  6. **
  7. ** Contact: Nokia Corporation (qt-info@nokia.com)
  8. **
  9. **
  10. ** GNU Lesser General Public License Usage
  11. **
  12. ** This file may be used under the terms of the GNU Lesser General Public
  13. ** License version 2.1 as published by the Free Software Foundation and
  14. ** appearing in the file LICENSE.LGPL included in the packaging of this file.
  15. ** Please review the following information to ensure the GNU Lesser General
  16. ** Public License version 2.1 requirements will be met:
  17. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  18. **
  19. ** In addition, as a special exception, Nokia gives you certain additional
  20. ** rights. These rights are described in the Nokia Qt LGPL Exception
  21. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  22. **
  23. ** Other Usage
  24. **
  25. ** Alternatively, this file may be used in accordance with the terms and
  26. ** conditions contained in a signed written agreement between you and Nokia.
  27. **
  28. ** If you have questions regarding the use of this file, please contact
  29. ** Nokia at qt-info@nokia.com.
  30. **
  31. **************************************************************************/
  32. #include <qglobal.h>
  33. #if USE_QT_CORE
  34. #include <QDateTime>
  35. #include <QDebug>
  36. #include <QDir>
  37. #include <QFile>
  38. #include <QFileInfo>
  39. #include <QHash>
  40. #include <QLinkedList>
  41. #include <QList>
  42. #include <QQueue>
  43. #include <QLocale>
  44. #include <QMap>
  45. #include <QMetaEnum>
  46. #include <QMetaObject>
  47. #include <QMetaProperty>
  48. #include <QPoint>
  49. #include <QPointF>
  50. #include <QPointer>
  51. #include <QRect>
  52. #include <QRectF>
  53. #include <QStack>
  54. #include <QSize>
  55. #include <QSizeF>
  56. #include <QString>
  57. #include <QStringList>
  58. #include <QTextCodec>
  59. #include <QTextStream>
  60. #include <QVector>
  61. #ifndef QT_BOOTSTRAPPED
  62. #include <QModelIndex>
  63. #if QT_VERSION >= 0x040500
  64. #include <QSharedPointer>
  65. #include <QSharedDataPointer>
  66. #include <QSharedData>
  67. #include <QWeakPointer>
  68. #endif
  69. #ifndef USE_QT_GUI
  70. # ifdef QT_GUI_LIB
  71. # define USE_QT_GUI 1
  72. # endif
  73. #endif
  74. #ifndef USE_QT_WIDGETS
  75. # if defined(QT_WIDGETS_LIB) || ((QT_VERSION < 0x050000) && defined(USE_QT_GUI))
  76. # define USE_QT_WIDGETS 1
  77. # endif
  78. #endif
  79. #ifdef USE_QT_GUI
  80. # include <QImage>
  81. # include <QRegion>
  82. # include <QPixmap>
  83. # include <QFont>
  84. # include <QColor>
  85. # include <QKeySequence>
  86. #endif
  87. #ifdef USE_QT_WIDGETS
  88. # include <QSizePolicy>
  89. # include <QWidget>
  90. # include <QApplication>
  91. #endif
  92. #endif // QT_BOOTSTRAPPED
  93. #endif // USE_QT_CORE
  94. #ifdef Q_OS_WIN
  95. # include <windows.h>
  96. #endif
  97. #include <list>
  98. #include <map>
  99. #include <string>
  100. #include <set>
  101. #include <vector>
  102. #include <stdio.h>
  103. #ifdef QT_BOOTSTRAPPED
  104. # define NS ""
  105. # define NSX "'"
  106. # define NSY "'"
  107. #else
  108. # include "dumper_p.h"
  109. #endif // QT_BOOTSTRAPPED
  110. #if QT_VERSION >= 0x050000
  111. # define MAP_WORKS 0
  112. #else
  113. # define MAP_WORKS 1
  114. #endif
  115. int qtGhVersion = QT_VERSION;
  116. /*!
  117. \class QDumper
  118. \brief Helper class for producing "nice" output in Qt Creator's debugger.
  119. \internal
  120. The whole "custom dumper" implementation is currently far less modular
  121. than it could be. But as the code is still in a flux, making it nicer
  122. from a pure archtectural point of view seems still be a waste of resources.
  123. Some hints:
  124. New dumpers for non-templated classes should be mentioned in
  125. \c{qDumpObjectData440()} in the \c{protocolVersion == 1} branch.
  126. Templated classes need extra support on the IDE level
  127. (see plugins/debugger/gdbengine.cpp) and should not be mentiond in
  128. \c{qDumpObjectData440()}.
  129. In any case, dumper processesing should end up in
  130. \c{handleProtocolVersion2and3()} and needs an entry in the big switch there.
  131. Next step is to create a suitable \c{static void qDumpFoo(QDumper &d)}
  132. function. At the bare minimum it should contain something like this:
  133. \c{
  134. const Foo &foo = *reinterpret_cast<const Foo *>(d.data);
  135. d.putItem("value", ...);
  136. d.putItem("type", "Foo");
  137. d.putItem("numchild", "0");
  138. }
  139. 'd.putItem(name, value)' roughly expands to:
  140. d.put((name)).put("=\"").put(value).put("\"";
  141. Useful (i.e. understood by the IDE) names include:
  142. \list
  143. \o "name" shows up in the first column in the Locals&Watchers view.
  144. \o "value" shows up in the second column.
  145. \o "valueencoded" should be set to "1" if the value is base64 encoded.
  146. Always base64-encode values that might use unprintable or otherwise
  147. "confuse" the protocol (like spaces and quotes). [A-Za-z0-9] is "safe".
  148. A value of "3" is used for base64-encoded UCS4, "2" denotes
  149. base64-encoded UTF16.
  150. \o "numchild" return the number of children in the view. Effectively, only
  151. 0 and != 0 will be used, so don't try too hard to get the number right.
  152. \endlist
  153. If the current item has children, it might be queried to produce information
  154. about these children. In this case the dumper should use something like this:
  155. \c{
  156. if (d.dumpChildren) {
  157. d.beginChildren();
  158. [...]
  159. d.endChildren();
  160. }
  161. */
  162. #if defined(QT_BEGIN_NAMESPACE)
  163. QT_BEGIN_NAMESPACE
  164. #endif
  165. const char *stdStringTypeC = "std::basic_string<char,std::char_traits<char>,std::allocator<char> >";
  166. const char *stdWideStringTypeUShortC = "std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >";
  167. #if defined(QT_BEGIN_NAMESPACE)
  168. QT_END_NAMESPACE
  169. #endif
  170. // This can be mangled typenames of nested templates, each char-by-char
  171. // comma-separated integer list...
  172. // The output buffer.
  173. #ifdef MACROSDEBUG
  174. Q_DECL_EXPORT char xDumpInBuffer[10000];
  175. Q_DECL_EXPORT char xDumpOutBuffer[1000000];
  176. # define inBuffer xDumpInBuffer
  177. # define outBuffer xDumpOutBuffer
  178. #else
  179. Q_DECL_EXPORT char qDumpInBuffer[10000];
  180. Q_DECL_EXPORT char qDumpOutBuffer[1000000];
  181. # define inBuffer qDumpInBuffer
  182. # define outBuffer qDumpOutBuffer
  183. #endif
  184. namespace {
  185. static QByteArray strPtrConst = "* const";
  186. static bool isPointerType(const QByteArray &type)
  187. {
  188. return type.endsWith('*') || type.endsWith(strPtrConst);
  189. }
  190. static QByteArray stripPointerType(const QByteArray &_type)
  191. {
  192. QByteArray type = _type;
  193. if (type.endsWith('*'))
  194. type.chop(1);
  195. if (type.endsWith(strPtrConst))
  196. type.chop(7);
  197. if (type.endsWith(' '))
  198. type.chop(1);
  199. return type;
  200. }
  201. // This is used to abort evaluation of custom data dumpers in a "coordinated"
  202. // way. Abortion will happen at the latest when we try to access a non-initialized
  203. // non-trivial object, so there is no way to prevent this from occurring at all
  204. // conceptually. Gdb will catch SIGSEGV and return to the calling frame.
  205. // This is just fine provided we only _read_ memory in the custom handlers below.
  206. // We don't use this code for MSVC/CDB anymore.
  207. volatile int qProvokeSegFaultHelper;
  208. static const void *addOffset(const void *p, int offset)
  209. {
  210. return offset + reinterpret_cast<const char *>(p);
  211. }
  212. static const void *deref(const void *p)
  213. {
  214. return *reinterpret_cast<const char* const*>(p);
  215. }
  216. #if USE_QT_CORE
  217. static const void *skipvtable(const void *p)
  218. {
  219. return sizeof(void *) + reinterpret_cast<const char *>(p);
  220. }
  221. static const void *dfunc(const void *p)
  222. {
  223. return deref(skipvtable(p));
  224. }
  225. #endif
  226. static bool isEqual(const char *s, const char *t)
  227. {
  228. return qstrcmp(s, t) == 0;
  229. }
  230. static bool startsWith(const char *s, const char *t)
  231. {
  232. while (char c = *t++)
  233. if (c != *s++)
  234. return false;
  235. return true;
  236. }
  237. // Check memory for read access and provoke segfault if nothing else helps.
  238. // On Windows, try to be less crash-prone by checking memory using WinAPI
  239. #ifdef Q_OS_WIN
  240. # define qCheckAccess(d) do { \
  241. if (IsBadReadPtr(d, 1)) \
  242. return; \
  243. qProvokeSegFaultHelper = *(char*)d; \
  244. } while (0)
  245. # define qCheckPointer(d) do { \
  246. if (d && IsBadReadPtr(d, 1)) \
  247. return; \
  248. if (d) qProvokeSegFaultHelper = *(char*)d; \
  249. } while (0)
  250. #else
  251. # define qCheckAccess(d) do { \
  252. if (!couldBePointer(d) && d != 0) \
  253. return; \
  254. qProvokeSegFaultHelper = *(char*)d; \
  255. } while (0)
  256. # define qCheckPointer(d) do { \
  257. if (!couldBePointer(d)) \
  258. return; \
  259. if (d) \
  260. qProvokeSegFaultHelper = *(char*)d; \
  261. } while (0)
  262. static bool couldBePointer(const void *p)
  263. {
  264. // we assume valid pointer to be 4-aligned at least.
  265. // So use this check only when this is guaranteed.
  266. // FIXME: this breaks e.g. in the QString dumper...
  267. const quintptr d = quintptr(p);
  268. //qDebug() << "CHECKING : " << p << ((d & 3) == 0 && (d > 1000 || d == 0));
  269. //return (d & 3) == 0 && (d > 1000 || d == 0);
  270. return d > 1000 || d == 0;
  271. }
  272. #endif
  273. #ifdef QT_NAMESPACE
  274. const char *stripNamespace(const char *type)
  275. {
  276. static const size_t nslen = strlen(NS);
  277. return startsWith(type, NS) ? type + nslen : type;
  278. }
  279. #else
  280. inline const char *stripNamespace(const char *type)
  281. {
  282. return type;
  283. }
  284. #endif
  285. static bool isSimpleType(const char *type)
  286. {
  287. switch (type[0]) {
  288. case 'c':
  289. return isEqual(type, "char");
  290. case 'd':
  291. return isEqual(type, "double");
  292. case 'f':
  293. return isEqual(type, "float");
  294. case 'i':
  295. return isEqual(type, "int");
  296. case 'l':
  297. return isEqual(type, "long") || startsWith(type, "long ");
  298. case 's':
  299. return isEqual(type, "short") || startsWith(type, "short ")
  300. || isEqual(type, "signed") || startsWith(type, "signed ");
  301. case 'u':
  302. return isEqual(type, "unsigned") || startsWith(type, "unsigned ");
  303. }
  304. return false;
  305. }
  306. static bool isStringType(const char *type)
  307. {
  308. return isEqual(type, NS "QString")
  309. || isEqual(type, NS "QByteArray")
  310. || isEqual(type, "std::string")
  311. || isEqual(type, "std::wstring")
  312. || isEqual(type, "wstring");
  313. }
  314. #if USE_QT_CORE
  315. static bool isMovableType(const char *type)
  316. {
  317. if (isPointerType(type))
  318. return true;
  319. if (isSimpleType(type))
  320. return true;
  321. type = stripNamespace(type);
  322. switch (type[1]) {
  323. case 'B':
  324. return isEqual(type, "QBrush")
  325. || isEqual(type, "QBitArray")
  326. || isEqual(type, "QByteArray") ;
  327. case 'C':
  328. return isEqual(type, "QCustomTypeInfo")
  329. || isEqual(type, "QChar");
  330. case 'D':
  331. return isEqual(type, "QDate")
  332. || isEqual(type, "QDateTime");
  333. case 'F':
  334. return isEqual(type, "QFileInfo")
  335. || isEqual(type, "QFixed")
  336. || isEqual(type, "QFixedPoint")
  337. || isEqual(type, "QFixedSize");
  338. case 'H':
  339. return isEqual(type, "QHashDummyValue");
  340. case 'I':
  341. return isEqual(type, "QIcon")
  342. || isEqual(type, "QImage");
  343. case 'L':
  344. return isEqual(type, "QLine")
  345. || isEqual(type, "QLineF")
  346. || isEqual(type, "QLatin1Char")
  347. || isEqual(type, "QLocal");
  348. case 'M':
  349. return isEqual(type, "QMatrix")
  350. || isEqual(type, "QModelIndex");
  351. case 'P':
  352. return isEqual(type, "QPoint")
  353. || isEqual(type, "QPointF")
  354. || isEqual(type, "QPen")
  355. || isEqual(type, "QPersistentModelIndex");
  356. case 'R':
  357. return isEqual(type, "QResourceRoot")
  358. || isEqual(type, "QRect")
  359. || isEqual(type, "QRectF")
  360. || isEqual(type, "QRegExp");
  361. case 'S':
  362. return isEqual(type, "QSize")
  363. || isEqual(type, "QSizeF")
  364. || isEqual(type, "QString");
  365. case 'T':
  366. return isEqual(type, "QTime")
  367. || isEqual(type, "QTextBlock");
  368. case 'U':
  369. return isEqual(type, "QUrl");
  370. case 'V':
  371. return isEqual(type, "QVariant");
  372. case 'X':
  373. return isEqual(type, "QXmlStreamAttribute")
  374. || isEqual(type, "QXmlStreamNamespaceDeclaration")
  375. || isEqual(type, "QXmlStreamNotationDeclaration")
  376. || isEqual(type, "QXmlStreamEntityDeclaration");
  377. }
  378. return false;
  379. }
  380. #endif
  381. struct QDumper
  382. {
  383. explicit QDumper();
  384. ~QDumper();
  385. // direct write to the output
  386. QDumper &put(long c);
  387. QDumper &put(int i);
  388. QDumper &put(double d);
  389. QDumper &put(float d);
  390. QDumper &put(unsigned long c);
  391. QDumper &put(unsigned int i);
  392. QDumper &put(const void *p);
  393. QDumper &put(qulonglong c);
  394. QDumper &put(long long c);
  395. QDumper &put(const char *str);
  396. QDumper &put(const QByteArray &ba);
  397. QDumper &put(const QString &str);
  398. QDumper &put(char c);
  399. // convienience functions for writing key="value" pairs:
  400. template <class Value>
  401. void putItem(const char *name, const Value &value)
  402. {
  403. putCommaIfNeeded();
  404. put(name).put('=').put('"').put(value).put('"');
  405. }
  406. void putItem(const char *name, const char *value, const char *setvalue)
  407. {
  408. if (!isEqual(value, setvalue))
  409. putItem(name, value);
  410. }
  411. // convienience functions for writing typical properties.
  412. // roughly equivalent to
  413. // beginHash();
  414. // putItem("name", name);
  415. // putItem("value", value);
  416. // putItem("type", NS "QString");
  417. // putItem("numchild", "0");
  418. // putItem("valueencoded", "2");
  419. // endHash();
  420. void putHash(const char *name, const QString &value);
  421. void putHash(const char *name, const QByteArray &value);
  422. void putHash(const char *name, int value);
  423. void putHash(const char *name, long value);
  424. void putHash(const char *name, bool value);
  425. void putHash(const char *name, QChar value);
  426. void putHash(const char *name, float value);
  427. void putHash(const char *name, double value);
  428. void putStringValue(const QString &value);
  429. void beginHash(); // start of data hash output
  430. void endHash(); // start of data hash output
  431. void beginChildren(const char *mainInnerType = 0); // start of children list
  432. void endChildren(); // end of children list
  433. void beginItem(const char *name); // start of named item, ready to accept value
  434. void endItem(); // end of named item, used after value output is complete
  435. // convenience for putting "<n items>"
  436. void putItemCount(const char *name, int count);
  437. // convenience for putting "<>n items>" (more than X items)
  438. void putTruncatedItemCount(const char *name, int count);
  439. void putCommaIfNeeded();
  440. // convienience function for writing the last item of an abbreviated list
  441. void putEllipsis();
  442. void disarm();
  443. void putBase64Encoded(const char *buf, int n);
  444. void checkFill();
  445. // the dumper arguments
  446. int protocolVersion; // dumper protocol version
  447. int token; // some token to show on success
  448. const char *outerType; // object type
  449. const char *iname; // object name used for display
  450. const char *exp; // object expression
  451. const char *innerType; // 'inner type' for class templates
  452. const void *data; // pointer to raw data
  453. bool dumpChildren; // do we want to see children?
  454. // handling of nested templates
  455. void setupTemplateParameters();
  456. enum { maxTemplateParameters = 10 };
  457. const char *templateParameters[maxTemplateParameters + 1];
  458. // internal state
  459. int extraInt[4];
  460. bool success; // are we finished?
  461. bool full;
  462. int pos;
  463. const char *currentChildType;
  464. const char *currentChildNumChild;
  465. };
  466. QDumper::QDumper()
  467. {
  468. success = false;
  469. full = false;
  470. outBuffer[0] = 'f'; // marks output as 'wrong'
  471. pos = 1;
  472. currentChildType = 0;
  473. currentChildNumChild = 0;
  474. }
  475. QDumper::~QDumper()
  476. {
  477. outBuffer[pos++] = '\0';
  478. if (success)
  479. outBuffer[0] = (full ? '+' : 't');
  480. }
  481. void QDumper::setupTemplateParameters()
  482. {
  483. char *s = const_cast<char *>(innerType);
  484. int templateParametersCount = 1;
  485. templateParameters[0] = s;
  486. for (int i = 1; i != maxTemplateParameters + 1; ++i)
  487. templateParameters[i] = 0;
  488. while (*s) {
  489. while (*s && *s != '@')
  490. ++s;
  491. if (*s) {
  492. *s = '\0';
  493. ++s;
  494. templateParameters[templateParametersCount++] = s;
  495. }
  496. }
  497. while (templateParametersCount < maxTemplateParameters)
  498. templateParameters[templateParametersCount++] = 0;
  499. }
  500. QDumper &QDumper::put(char c)
  501. {
  502. checkFill();
  503. if (!full)
  504. outBuffer[pos++] = c;
  505. return *this;
  506. }
  507. QDumper &QDumper::put(unsigned long long c)
  508. {
  509. checkFill();
  510. pos += sprintf(outBuffer + pos, "%llu", c);
  511. return *this;
  512. }
  513. QDumper &QDumper::put(long long c)
  514. {
  515. checkFill();
  516. pos += sprintf(outBuffer + pos, "%lld", c);
  517. return *this;
  518. }
  519. QDumper &QDumper::put(unsigned long c)
  520. {
  521. checkFill();
  522. pos += sprintf(outBuffer + pos, "%lu", c);
  523. return *this;
  524. }
  525. QDumper &QDumper::put(float d)
  526. {
  527. checkFill();
  528. pos += sprintf(outBuffer + pos, "%f", d);
  529. return *this;
  530. }
  531. QDumper &QDumper::put(double d)
  532. {
  533. checkFill();
  534. pos += sprintf(outBuffer + pos, "%f", d);
  535. return *this;
  536. }
  537. QDumper &QDumper::put(unsigned int i)
  538. {
  539. checkFill();
  540. pos += sprintf(outBuffer + pos, "%u", i);
  541. return *this;
  542. }
  543. QDumper &QDumper::put(long c)
  544. {
  545. checkFill();
  546. pos += sprintf(outBuffer + pos, "%ld", c);
  547. return *this;
  548. }
  549. QDumper &QDumper::put(int i)
  550. {
  551. checkFill();
  552. pos += sprintf(outBuffer + pos, "%d", i);
  553. return *this;
  554. }
  555. QDumper &QDumper::put(const void *p)
  556. {
  557. if (p) {
  558. // Pointer is 'long long' on WIN_64, only
  559. static const char *printFormat = sizeof(void *) == sizeof(long) ? "0x%lx" : "0x%llx";
  560. pos += sprintf(outBuffer + pos, printFormat, p);
  561. } else {
  562. pos += sprintf(outBuffer + pos, "<null>");
  563. }
  564. return *this;
  565. }
  566. QDumper &QDumper::put(const char *str)
  567. {
  568. if (!str)
  569. return put("<null>");
  570. while (*str)
  571. put(*(str++));
  572. return *this;
  573. }
  574. QDumper &QDumper::put(const QByteArray &ba)
  575. {
  576. putBase64Encoded(ba.constData(), ba.size());
  577. return *this;
  578. }
  579. QDumper &QDumper::put(const QString &str)
  580. {
  581. putBase64Encoded((const char *)str.constData(), 2 * str.size());
  582. return *this;
  583. }
  584. void QDumper::checkFill()
  585. {
  586. if (pos >= int(sizeof(outBuffer)) - 100)
  587. full = true;
  588. }
  589. void QDumper::putCommaIfNeeded()
  590. {
  591. if (pos == 0)
  592. return;
  593. char c = outBuffer[pos - 1];
  594. if (c == '}' || c == '"' || c == ']')
  595. put(',');
  596. }
  597. void QDumper::putBase64Encoded(const char *buf, int n)
  598. {
  599. const char alphabet[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef"
  600. "ghijklmn" "opqrstuv" "wxyz0123" "456789+/";
  601. const char padchar = '=';
  602. int padlen = 0;
  603. //int tmpsize = ((n * 4) / 3) + 3;
  604. int i = 0;
  605. while (i < n) {
  606. int chunk = 0;
  607. chunk |= int(uchar(buf[i++])) << 16;
  608. if (i == n) {
  609. padlen = 2;
  610. } else {
  611. chunk |= int(uchar(buf[i++])) << 8;
  612. if (i == n)
  613. padlen = 1;
  614. else
  615. chunk |= int(uchar(buf[i++]));
  616. }
  617. int j = (chunk & 0x00fc0000) >> 18;
  618. int k = (chunk & 0x0003f000) >> 12;
  619. int l = (chunk & 0x00000fc0) >> 6;
  620. int m = (chunk & 0x0000003f);
  621. put(alphabet[j]);
  622. put(alphabet[k]);
  623. put(padlen > 1 ? padchar : alphabet[l]);
  624. put(padlen > 0 ? padchar : alphabet[m]);
  625. }
  626. }
  627. void QDumper::putStringValue(const QString &str)
  628. {
  629. if (str.isNull()) {
  630. beginItem("value");
  631. putBase64Encoded("\"\" (null)", 9);
  632. endItem();
  633. putItem("valueencoded", "5");
  634. } else {
  635. putItem("value", str);
  636. putItem("valueencoded", "2");
  637. }
  638. }
  639. void QDumper::disarm()
  640. {
  641. success = true;
  642. }
  643. void QDumper::beginHash()
  644. {
  645. putCommaIfNeeded();
  646. put('{');
  647. }
  648. void QDumper::endHash()
  649. {
  650. put('}');
  651. }
  652. void QDumper::putEllipsis()
  653. {
  654. putCommaIfNeeded();
  655. put("{name=\"<incomplete>\",value=\"\",type=\"").put(innerType).put("\"}");
  656. }
  657. void QDumper::putItemCount(const char *name, int count)
  658. {
  659. putCommaIfNeeded();
  660. put(name).put("=\"<").put(count).put(" items>\"");
  661. }
  662. void QDumper::putTruncatedItemCount(const char *name, int count)
  663. {
  664. putCommaIfNeeded();
  665. put(name).put("=\"<>").put(count).put(" items>\"");
  666. }
  667. //
  668. // Some helpers to keep the dumper code short
  669. //
  670. void QDumper::beginItem(const char *name)
  671. {
  672. putCommaIfNeeded();
  673. put(name).put('=').put('"');
  674. }
  675. void QDumper::endItem()
  676. {
  677. put('"');
  678. }
  679. void QDumper::beginChildren(const char *mainInnerType)
  680. {
  681. if (mainInnerType) {
  682. putItem("childtype", mainInnerType);
  683. currentChildType = mainInnerType;
  684. if (isSimpleType(mainInnerType) || isStringType(mainInnerType)) {
  685. putItem("childnumchild", "0");
  686. currentChildNumChild = "0";
  687. } else if (isPointerType(mainInnerType)) {
  688. putItem("childnumchild", "1");
  689. currentChildNumChild = "1";
  690. }
  691. }
  692. putCommaIfNeeded();
  693. put("children=[");
  694. }
  695. void QDumper::endChildren()
  696. {
  697. put(']');
  698. currentChildType = 0;
  699. currentChildNumChild = 0;
  700. }
  701. // simple string property
  702. void QDumper::putHash(const char *name, const QString &value)
  703. {
  704. beginHash();
  705. putItem("name", name);
  706. putStringValue(value);
  707. putItem("type", NS "QString");
  708. putItem("numchild", "0");
  709. endHash();
  710. }
  711. void QDumper::putHash(const char *name, const QByteArray &value)
  712. {
  713. beginHash();
  714. putItem("name", name);
  715. putItem("value", value);
  716. putItem("type", NS "QByteArray");
  717. putItem("numchild", "0");
  718. putItem("valueencoded", "1");
  719. endHash();
  720. }
  721. // simple integer property
  722. void QDumper::putHash(const char *name, int value)
  723. {
  724. beginHash();
  725. putItem("name", name);
  726. putItem("value", value);
  727. putItem("type", "int");
  728. putItem("numchild", "0");
  729. endHash();
  730. }
  731. void QDumper::putHash(const char *name, long value)
  732. {
  733. beginHash();
  734. putItem("name", name);
  735. putItem("value", value);
  736. putItem("type", "long");
  737. putItem("numchild", "0");
  738. endHash();
  739. }
  740. void QDumper::putHash(const char *name, float value)
  741. {
  742. beginHash();
  743. putItem("name", name);
  744. putItem("value", value);
  745. putItem("type", "float");
  746. putItem("numchild", "0");
  747. endHash();
  748. }
  749. void QDumper::putHash(const char *name, double value)
  750. {
  751. beginHash();
  752. putItem("name", name);
  753. putItem("value", value);
  754. putItem("type", "double");
  755. putItem("numchild", "0");
  756. endHash();
  757. }
  758. // simple boolean property
  759. void QDumper::putHash(const char *name, bool value)
  760. {
  761. beginHash();
  762. putItem("name", name);
  763. putItem("value", (value ? "true" : "false"));
  764. putItem("type", "bool");
  765. putItem("numchild", "0");
  766. endHash();
  767. }
  768. // a single QChar
  769. void QDumper::putHash(const char *name, QChar value)
  770. {
  771. beginHash();
  772. putItem("name", name);
  773. putStringValue(QString(QLatin1String("'%1' (%2, 0x%3)"))
  774. .arg(value).arg(value.unicode()).arg(value.unicode(), 0, 16));
  775. putItem("type", NS "QChar");
  776. putItem("numchild", "0");
  777. endHash();
  778. }
  779. #define DUMPUNKNOWN_MESSAGE "<not in scope>"
  780. static void qDumpUnknown(QDumper &d, const char *why = 0)
  781. {
  782. if (!why)
  783. why = DUMPUNKNOWN_MESSAGE;
  784. d.putItem("value", why);
  785. d.putItem("valueeditable", "false");
  786. d.putItem("valueenabled", "false");
  787. d.putItem("numchild", "0", d.currentChildNumChild);
  788. d.disarm();
  789. }
  790. static void qDumpStdStringValue(QDumper &d, const std::string &str)
  791. {
  792. d.beginItem("value");
  793. d.putBase64Encoded(str.c_str(), str.size());
  794. d.endItem();
  795. d.putItem("valueencoded", "1");
  796. d.putItem("type", "std::string");
  797. d.putItem("numchild", "0", d.currentChildNumChild);
  798. }
  799. static void qDumpStdWStringValue(QDumper &d, const std::wstring &str)
  800. {
  801. d.beginItem("value");
  802. d.putBase64Encoded((const char *)str.c_str(), str.size() * sizeof(wchar_t));
  803. d.endItem();
  804. d.putItem("valueencoded", (sizeof(wchar_t) == 2 ? "2" : "3"));
  805. d.putItem("type", "std::wstring", d.currentChildType);
  806. d.putItem("numchild", "0", d.currentChildNumChild);
  807. }
  808. // Called by templates, so, not static.
  809. static void qDumpInnerQCharValue(QDumper &d, QChar c, const char *field)
  810. {
  811. char buf[30];
  812. sprintf(buf, "'?', ucs=%d", c.unicode());
  813. if (c.isPrint() && c.unicode() < 127)
  814. buf[1] = char(c.unicode());
  815. d.putCommaIfNeeded();
  816. d.putItem(field, buf);
  817. d.putItem("numchild", "0", d.currentChildNumChild);
  818. }
  819. static void qDumpInnerCharValue(QDumper &d, char c, const char *field)
  820. {
  821. char buf[30];
  822. sprintf(buf, "'?', ascii=%d", c);
  823. if (QChar(QLatin1Char(c)).isPrint() && c < 127)
  824. buf[1] = c;
  825. d.putCommaIfNeeded();
  826. d.putItem(field, buf);
  827. d.putItem("numchild", "0", d.currentChildNumChild);
  828. }
  829. void qDumpInnerValueHelper(QDumper &d, const char *type, const void *addr,
  830. const char *field = "value")
  831. {
  832. type = stripNamespace(type);
  833. switch (type[1]) {
  834. case 'h':
  835. if (isEqual(type, "char"))
  836. qDumpInnerCharValue(d, *(char *)addr, field);
  837. break;
  838. case 'l':
  839. if (isEqual(type, "float"))
  840. d.putItem(field, *(float*)addr);
  841. break;
  842. case 'n':
  843. if (isEqual(type, "int"))
  844. d.putItem(field, *(int*)addr);
  845. else if (isEqual(type, "unsigned") || isEqual(type, "unsigned int"))
  846. d.putItem(field, *(unsigned int*)addr);
  847. else if (isEqual(type, "unsigned char"))
  848. qDumpInnerCharValue(d, *(char *)addr, field);
  849. else if (isEqual(type, "unsigned long"))
  850. d.putItem(field, *(unsigned long*)addr);
  851. else if (isEqual(type, "unsigned long long"))
  852. d.putItem(field, *(qulonglong*)addr);
  853. break;
  854. case 'o':
  855. if (isEqual(type, "bool")) {
  856. switch (*(unsigned char*)addr) {
  857. case 0: d.putItem(field, "false"); break;
  858. case 1: d.putItem(field, "true"); break;
  859. default: d.putItem(field, *(unsigned char*)addr); break;
  860. }
  861. } else if (isEqual(type, "double"))
  862. d.putItem(field, *(double*)addr);
  863. else if (isEqual(type, "long"))
  864. d.putItem(field, *(long*)addr);
  865. else if (isEqual(type, "long long"))
  866. d.putItem(field, *(qulonglong*)addr);
  867. break;
  868. case 'B':
  869. if (isEqual(type, "QByteArray")) {
  870. d.putCommaIfNeeded();
  871. d.put(field).put("encoded=\"1\",");
  872. d.putItem(field, *(QByteArray*)addr);
  873. }
  874. break;
  875. case 'C':
  876. if (isEqual(type, "QChar"))
  877. qDumpInnerQCharValue(d, *(QChar*)addr, field);
  878. break;
  879. case 'L':
  880. if (startsWith(type, "QList<")) {
  881. const QListData *ldata = reinterpret_cast<const QListData*>(addr);
  882. d.putItemCount("value", ldata->size());
  883. d.putItem("valueeditable", "false");
  884. d.putItem("numchild", ldata->size());
  885. }
  886. break;
  887. case 'O':
  888. # ifndef QT_BOOTSTRAPPED
  889. if (isEqual(type, "QObject *")) {
  890. if (addr) {
  891. const QObject *ob = reinterpret_cast<const QObject *>(addr);
  892. d.putItem("addr", ob);
  893. d.putItem("value", ob->objectName());
  894. d.putItem("valueencoded", "2");
  895. d.putItem("type", NS "QObject");
  896. d.putItem("displayedtype", ob->metaObject()->className());
  897. d.putItem("numchild", 1);
  898. } else {
  899. d.putItem("value", "0x0");
  900. d.putItem("type", NS "QObject *");
  901. d.putItem("numchild", 0);
  902. }
  903. }
  904. # endif
  905. break;
  906. case 'S':
  907. if (isEqual(type, "QString")) {
  908. d.putCommaIfNeeded();
  909. d.putItem(field, *(QString*)addr);
  910. d.put(',').put(field).put("encoded=\"2\"");
  911. }
  912. break;
  913. case 't':
  914. if (isEqual(type, "std::string")
  915. || isEqual(type, stdStringTypeC)) {
  916. d.putCommaIfNeeded();
  917. qDumpStdStringValue(d, *reinterpret_cast<const std::string*>(addr));
  918. } else if (isEqual(type, "std::wstring")
  919. || isEqual(type, stdWideStringTypeUShortC)) {
  920. qDumpStdWStringValue(d, *reinterpret_cast<const std::wstring*>(addr));
  921. }
  922. break;
  923. default:
  924. break;
  925. }
  926. }
  927. #if USE_QT_CORE
  928. static void qDumpInnerValue(QDumper &d, const char *type, const void *addr)
  929. {
  930. d.putItem("addr", addr);
  931. d.putItem("type", type, d.currentChildType);
  932. if (!type[0])
  933. return;
  934. return qDumpInnerValueHelper(d, type, addr);
  935. }
  936. #endif
  937. static void qDumpInnerValueOrPointer(QDumper &d,
  938. const char *type, const char *strippedtype, const void *addr)
  939. {
  940. if (strippedtype) {
  941. if (deref(addr)) {
  942. d.putItem("addr", deref(addr));
  943. d.putItem("type", strippedtype, d.currentChildType);
  944. qDumpInnerValueHelper(d, strippedtype, deref(addr));
  945. } else {
  946. d.putItem("addr", addr);
  947. d.putItem("type", strippedtype);
  948. d.putItem("value", "<null>");
  949. d.putItem("numchild", "0");
  950. }
  951. } else {
  952. d.putItem("addr", addr);
  953. d.putItem("type", type, d.currentChildType);
  954. qDumpInnerValueHelper(d, type, addr);
  955. }
  956. }
  957. //////////////////////////////////////////////////////////////////////////////
  958. #if USE_QT_CORE
  959. #ifndef QT_BOOTSTRAPPED
  960. struct ModelIndex { int r; int c; void *p; void *m; };
  961. static void qDumpQAbstractItem(QDumper &d)
  962. {
  963. QModelIndex mi;
  964. {
  965. ModelIndex *mm = reinterpret_cast<ModelIndex *>(&mi);
  966. memset(&mi, 0, sizeof(mi));
  967. static const char *printFormat = sizeof(void *) == sizeof(long) ?
  968. "%d,%d,0x%lx,0x%lx" : "%d,%d,0x%llx,0x%llx";
  969. sscanf(d.templateParameters[0], printFormat, &mm->r, &mm->c, &mm->p, &mm->m);
  970. }
  971. const QAbstractItemModel *m = mi.model();
  972. const int rowCount = m->rowCount(mi);
  973. if (rowCount < 0)
  974. return;
  975. const int columnCount = m->columnCount(mi);
  976. if (columnCount < 0)
  977. return;
  978. d.putItem("type", NS "QAbstractItem");
  979. d.beginItem("addr");
  980. d.put('$').put(mi.row()).put(',').put(mi.column()).put(',')
  981. .put(mi.internalPointer()).put(',').put(mi.model());
  982. d.endItem();
  983. //d.putItem("value", "(").put(rowCount).put(",").put(columnCount).put(")");
  984. d.putItem("value", m->data(mi, Qt::DisplayRole).toString());
  985. d.putItem("valueencoded", "2");
  986. d.putItem("numchild", rowCount * columnCount);
  987. if (d.dumpChildren) {
  988. d.beginChildren();
  989. for (int row = 0; row < rowCount; ++row) {
  990. for (int column = 0; column < columnCount; ++column) {
  991. QModelIndex child = m->index(row, column, mi);
  992. d.beginHash();
  993. d.beginItem("name");
  994. d.put("[").put(row).put(",").put(column).put("]");
  995. d.endItem();
  996. //d.putItem("numchild", (m->hasChildren(child) ? "1" : "0"));
  997. d.putItem("numchild", m->rowCount(child) * m->columnCount(child));
  998. d.beginItem("addr");
  999. d.put("$").put(child.row()).put(",").put(child.column()).put(",")
  1000. .put(child.internalPointer()).put(",").put(child.model());
  1001. d.endItem();
  1002. d.putItem("type", NS "QAbstractItem");
  1003. d.putItem("value", m->data(child, Qt::DisplayRole).toString());
  1004. d.putItem("valueencoded", "2");
  1005. d.endHash();
  1006. }
  1007. }
  1008. /*
  1009. d.beginHash();
  1010. d.putItem("name", "DisplayRole");
  1011. d.putItem("numchild", 0);
  1012. d.putItem("value", m->data(mi, Qt::DisplayRole).toString());
  1013. d.putItem("valueencoded", 2);
  1014. d.putItem("type", NS "QString");
  1015. d.endHash();
  1016. */
  1017. d.endChildren();
  1018. }
  1019. d.disarm();
  1020. }
  1021. static void qDumpQAbstractItemModel(QDumper &d)
  1022. {
  1023. const QAbstractItemModel &m = *reinterpret_cast<const QAbstractItemModel *>(d.data);
  1024. const int rowCount = m.rowCount();
  1025. if (rowCount < 0)
  1026. return;
  1027. const int columnCount = m.columnCount();
  1028. if (columnCount < 0)
  1029. return;
  1030. d.putItem("type", NS "QAbstractItemModel");
  1031. d.beginItem("value");
  1032. d.put("(").put(rowCount).put(",").put(columnCount).put(")");
  1033. d.endItem();
  1034. d.putItem("numchild", "1");
  1035. if (d.dumpChildren) {
  1036. d.beginChildren();
  1037. d.beginHash();
  1038. d.putItem("numchild", "1");
  1039. d.putItem("name", NS "QObject");
  1040. d.putItem("addr", d.data);
  1041. d.putItem("value", m.objectName());
  1042. d.putItem("valueencoded", "2");
  1043. d.putItem("type", NS "QObject");
  1044. d.putItem("displayedtype", m.metaObject()->className());
  1045. d.endHash();
  1046. for (int row = 0; row < rowCount; ++row) {
  1047. for (int column = 0; column < columnCount; ++column) {
  1048. QModelIndex mi = m.index(row, column);
  1049. d.beginHash();
  1050. d.beginItem("name");
  1051. d.put("[").put(row).put(",").put(column).put("]");
  1052. d.endItem();
  1053. d.putItem("value", m.data(mi, Qt::DisplayRole).toString());
  1054. d.putItem("valueencoded", "2");
  1055. //d.putItem("numchild", (m.hasChildren(mi) ? "1" : "0"));
  1056. d.putItem("numchild", m.rowCount(mi) * m.columnCount(mi));
  1057. d.beginItem("addr");
  1058. d.put("$").put(mi.row()).put(",").put(mi.column()).put(",");
  1059. d.put(mi.internalPointer()).put(",").put(mi.model());
  1060. d.endItem();
  1061. d.putItem("type", NS "QAbstractItem");
  1062. d.endHash();
  1063. }
  1064. }
  1065. d.endChildren();
  1066. }
  1067. d.disarm();
  1068. }
  1069. #endif // QT_BOOTSTRAPPED
  1070. static void qDumpQByteArray(QDumper &d)
  1071. {
  1072. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  1073. const QByteArray &ba = *reinterpret_cast<const QByteArray *>(d.data);
  1074. const int size = ba.size();
  1075. if (size < 0)
  1076. return;
  1077. if (!ba.isEmpty()) {
  1078. qCheckAccess(ba.constData());
  1079. qCheckAccess(ba.constData() + size);
  1080. }
  1081. d.beginItem("value");
  1082. if (size <= 100)
  1083. d.put(ba);
  1084. else
  1085. d.put(ba.left(100)).put(" <size: ").put(size).put(", cut...>");
  1086. d.endItem();
  1087. d.putItem("valueencoded", "1");
  1088. d.putItem("type", NS "QByteArray");
  1089. d.putItem("numchild", size);
  1090. if (d.dumpChildren) {
  1091. d.putItem("childtype", "char");
  1092. d.putItem("childnumchild", "0");
  1093. d.beginChildren();
  1094. char buf[20];
  1095. for (int i = 0; i != size; ++i) {
  1096. unsigned char c = ba.at(i);
  1097. unsigned char u = (isprint(c) && c != '\'' && c != '"') ? c : '?';
  1098. sprintf(buf, "%02x (%u '%c')", c, c, u);
  1099. d.beginHash();
  1100. d.putItem("value", buf);
  1101. d.endHash();
  1102. }
  1103. d.endChildren();
  1104. }
  1105. d.disarm();
  1106. }
  1107. static void qDumpQChar(QDumper &d)
  1108. {
  1109. qDumpInnerQCharValue(d, *reinterpret_cast<const QChar *>(d.data), "value");
  1110. d.disarm();
  1111. }
  1112. static void qDumpQDate(QDumper &d)
  1113. {
  1114. #ifdef QT_NO_DATESTRING
  1115. qDumpUnknown(d);
  1116. #else
  1117. const QDate &date = *reinterpret_cast<const QDate *>(d.data);
  1118. if (date.isNull()) {
  1119. d.putItem("value", "(null)");
  1120. d.putItem("type", NS "QDate");
  1121. d.putItem("numchild", "0");
  1122. return;
  1123. }
  1124. d.putItem("value", date.toString());
  1125. d.putItem("valueencoded", "2");
  1126. d.putItem("type", NS "QDate");
  1127. d.putItem("numchild", "1");
  1128. if (d.dumpChildren) {
  1129. d.beginChildren();
  1130. d.putHash("isNull", date.isNull());
  1131. d.putHash("toString", date.toString());
  1132. # if QT_VERSION >= 0x040500
  1133. d.putHash("toString_(ISO)", date.toString(Qt::ISODate));
  1134. d.putHash("toString_(SystemLocale)", date.toString(Qt::SystemLocaleDate));
  1135. d.putHash("toString_(Locale)", date.toString(Qt::LocaleDate));
  1136. # endif
  1137. d.endChildren();
  1138. }
  1139. d.disarm();
  1140. #endif // ifdef QT_NO_DATESTRING
  1141. }
  1142. static void qDumpQTime(QDumper &d)
  1143. {
  1144. #ifdef QT_NO_DATESTRING
  1145. qDumpUnknown(d);
  1146. #else
  1147. const QTime &date = *reinterpret_cast<const QTime *>(d.data);
  1148. if (date.isNull()) {
  1149. d.putItem("value", "(null)");
  1150. d.putItem("type", NS "QTime");
  1151. d.putItem("numchild", "0");
  1152. return;
  1153. }
  1154. d.putItem("value", date.toString());
  1155. d.putItem("valueencoded", "2");
  1156. d.putItem("type", NS "QTime");
  1157. d.putItem("numchild", "1");
  1158. if (d.dumpChildren) {
  1159. d.beginChildren();
  1160. d.putHash("isNull", date.isNull());
  1161. d.putHash("toString", date.toString());
  1162. # if QT_VERSION >= 0x040500
  1163. d.putHash("toString_(ISO)", date.toString(Qt::ISODate));
  1164. d.putHash("toString_(SystemLocale)", date.toString(Qt::SystemLocaleDate));
  1165. d.putHash("toString_(Locale)", date.toString(Qt::LocaleDate));
  1166. # endif
  1167. d.endChildren();
  1168. }
  1169. d.disarm();
  1170. #endif // ifdef QT_NO_DATESTRING
  1171. }
  1172. static void qDumpQDateTime(QDumper &d)
  1173. {
  1174. #ifdef QT_NO_DATESTRING
  1175. qDumpUnknown(d);
  1176. #else
  1177. const QDateTime &date = *reinterpret_cast<const QDateTime *>(d.data);
  1178. if (date.isNull()) {
  1179. d.putItem("value", "(null)");
  1180. d.putItem("type", NS "QDateTime");
  1181. d.putItem("numchild", "0");
  1182. d.disarm();
  1183. return;
  1184. }
  1185. d.putItem("value", date.toString());
  1186. d.putItem("valueencoded", "2");
  1187. d.putItem("type", NS "QDateTime");
  1188. d.putItem("numchild", "1");
  1189. if (d.dumpChildren) {
  1190. d.beginChildren();
  1191. d.putHash("toTime_t", (long)date.toTime_t());
  1192. d.putHash("toString", date.toString());
  1193. # if QT_VERSION >= 0x040500
  1194. d.putHash("toString_(ISO)", date.toString(Qt::ISODate));
  1195. d.putHash("toString_(SystemLocale)", date.toString(Qt::SystemLocaleDate));
  1196. d.putHash("toString_(Locale)", date.toString(Qt::LocaleDate));
  1197. # endif
  1198. # if 0
  1199. d.beginHash();
  1200. d.putItem("name", "toUTC");
  1201. d.putItem("exp", "((" NSX "QDateTime" NSY "*)").put(d.data).put(")"
  1202. "->toTimeSpec('" NS "Qt::UTC')");
  1203. d.putItem("type", NS "QDateTime");
  1204. d.putItem("numchild", "1");
  1205. d.endHash();
  1206. # endif
  1207. # if 0
  1208. d.beginHash();
  1209. d.putItem("name", "toLocalTime");
  1210. d.putItem("exp", "((" NSX "QDateTime" NSY "*)").put(d.data).put(")"
  1211. "->toTimeSpec('" NS "Qt::LocalTime')");
  1212. d.putItem("type", NS "QDateTime");
  1213. d.putItem("numchild", "1");
  1214. d.endHash();
  1215. # endif
  1216. d.endChildren();
  1217. }
  1218. d.disarm();
  1219. #endif // ifdef QT_NO_DATESTRING
  1220. }
  1221. static void qDumpQDir(QDumper &d)
  1222. {
  1223. const QDir &dir = *reinterpret_cast<const QDir *>(d.data);
  1224. d.putItem("value", dir.path());
  1225. d.putItem("valueencoded", "2");
  1226. d.putItem("type", NS "QDir");
  1227. d.putItem("numchild", "3");
  1228. if (d.dumpChildren) {
  1229. d.beginChildren();
  1230. d.putHash("absolutePath", dir.absolutePath());
  1231. d.putHash("canonicalPath", dir.canonicalPath());
  1232. d.endChildren();
  1233. }
  1234. d.disarm();
  1235. }
  1236. static void qDumpQFile(QDumper &d)
  1237. {
  1238. const QFile &file = *reinterpret_cast<const QFile *>(d.data);
  1239. d.putItem("value", file.fileName());
  1240. d.putItem("valueencoded", "2");
  1241. d.putItem("type", NS "QFile");
  1242. d.putItem("numchild", "2");
  1243. if (d.dumpChildren) {
  1244. d.beginChildren();
  1245. d.putHash("fileName", file.fileName());
  1246. d.putHash("exists", file.exists());
  1247. d.endChildren();
  1248. }
  1249. d.disarm();
  1250. }
  1251. static void qDumpQFileInfo(QDumper &d)
  1252. {
  1253. const QFileInfo &info = *reinterpret_cast<const QFileInfo *>(d.data);
  1254. d.putItem("value", info.filePath());
  1255. d.putItem("valueencoded", "2");
  1256. d.putItem("type", NS "QFileInfo");
  1257. d.putItem("numchild", "3");
  1258. if (d.dumpChildren) {
  1259. d.beginChildren();
  1260. d.putHash("absolutePath", info.absolutePath());
  1261. d.putHash("absoluteFilePath", info.absoluteFilePath());
  1262. d.putHash("canonicalPath", info.canonicalPath());
  1263. d.putHash("canonicalFilePath", info.canonicalFilePath());
  1264. d.putHash("completeBaseName", info.completeBaseName());
  1265. d.putHash("completeSuffix", info.completeSuffix());
  1266. d.putHash("baseName", info.baseName());
  1267. #ifdef Q_OS_MACX
  1268. d.putHash("isBundle", info.isBundle());
  1269. d.putHash("bundleName", info.bundleName());
  1270. #endif
  1271. d.putHash("fileName", info.fileName());
  1272. d.putHash("filePath", info.filePath());
  1273. d.putHash("group", info.group());
  1274. d.putHash("owner", info.owner());
  1275. d.putHash("path", info.path());
  1276. d.putHash("groupid", (long)info.groupId());
  1277. d.putHash("ownerid", (long)info.ownerId());
  1278. //QFile::Permissions permissions () const
  1279. long perms = info.permissions();
  1280. d.beginHash();
  1281. d.putItem("name", "permissions");
  1282. d.putItem("value", " ");
  1283. d.putItem("type", NS "QFile::Permissions");
  1284. d.putItem("numchild", 10);
  1285. d.beginChildren();
  1286. d.putHash("ReadOwner", bool(perms & QFile::ReadOwner));
  1287. d.putHash("WriteOwner", bool(perms & QFile::WriteOwner));
  1288. d.putHash("ExeOwner", bool(perms & QFile::ExeOwner));
  1289. d.putHash("ReadUser", bool(perms & QFile::ReadUser));
  1290. d.putHash("WriteUser", bool(perms & QFile::WriteUser));
  1291. d.putHash("ExeUser", bool(perms & QFile::ExeUser));
  1292. d.putHash("ReadGroup", bool(perms & QFile::ReadGroup));
  1293. d.putHash("WriteGroup", bool(perms & QFile::WriteGroup));
  1294. d.putHash("ExeGroup", bool(perms & QFile::ExeGroup));
  1295. d.putHash("ReadOther", bool(perms & QFile::ReadOther));
  1296. d.putHash("WriteOther", bool(perms & QFile::WriteOther));
  1297. d.putHash("ExeOther", bool(perms & QFile::ExeOther));
  1298. d.endChildren();
  1299. d.endHash();
  1300. //QDir absoluteDir () const
  1301. //QDir dir () const
  1302. d.putHash("caching", info.caching());
  1303. d.putHash("exists", info.exists());
  1304. d.putHash("isAbsolute", info.isAbsolute());
  1305. d.putHash("isDir", info.isDir());
  1306. d.putHash("isExecutable", info.isExecutable());
  1307. d.putHash("isFile", info.isFile());
  1308. d.putHash("isHidden", info.isHidden());
  1309. d.putHash("isReadable", info.isReadable());
  1310. d.putHash("isRelative", info.isRelative());
  1311. d.putHash("isRoot", info.isRoot());
  1312. d.putHash("isSymLink", info.isSymLink());
  1313. d.putHash("isWritable", info.isWritable());
  1314. d.beginHash();
  1315. d.putItem("name", "created");
  1316. d.putItem("value", info.created().toString());
  1317. d.putItem("valueencoded", "2");
  1318. d.beginItem("exp");
  1319. d.put("((" NSX "QFileInfo" NSY "*)").put(d.data).put(")->created()");
  1320. d.endItem();
  1321. d.putItem("type", NS "QDateTime");
  1322. d.putItem("numchild", "1");
  1323. d.endHash();
  1324. d.beginHash();
  1325. d.putItem("name", "lastModified");
  1326. d.putItem("value", info.lastModified().toString());
  1327. d.putItem("valueencoded", "2");
  1328. d.beginItem("exp");
  1329. d.put("((" NSX "QFileInfo" NSY "*)").put(d.data).put(")->lastModified()");
  1330. d.endItem();
  1331. d.putItem("type", NS "QDateTime");
  1332. d.putItem("numchild", "1");
  1333. d.endHash();
  1334. d.beginHash();
  1335. d.putItem("name", "lastRead");
  1336. d.putItem("value", info.lastRead().toString());
  1337. d.putItem("valueencoded", "2");
  1338. d.beginItem("exp");
  1339. d.put("((" NSX "QFileInfo" NSY "*)").put(d.data).put(")->lastRead()");
  1340. d.endItem();
  1341. d.putItem("type", NS "QDateTime");
  1342. d.putItem("numchild", "1");
  1343. d.endHash();
  1344. d.endChildren();
  1345. }
  1346. d.disarm();
  1347. }
  1348. bool isOptimizedIntKey(const char *keyType)
  1349. {
  1350. return isEqual(keyType, "int")
  1351. #if defined(Q_BYTE_ORDER) && Q_BYTE_ORDER == Q_LITTLE_ENDIAN
  1352. || isEqual(keyType, "short")
  1353. || isEqual(keyType, "ushort")
  1354. #endif
  1355. || isEqual(keyType, "uint");
  1356. }
  1357. int hashOffset(bool optimizedIntKey, bool forKey, unsigned keySize, unsigned valueSize)
  1358. {
  1359. // int-key optimization, small value
  1360. struct NodeOS { void *next; uint k; uint v; } nodeOS;
  1361. // int-key optimiatzion, large value
  1362. struct NodeOL { void *next; uint k; void *v; } nodeOL;
  1363. // no optimization, small value
  1364. struct NodeNS { void *next; uint h; uint k; uint v; } nodeNS;
  1365. // no optimization, large value
  1366. struct NodeNL { void *next; uint h; uint k; void *v; } nodeNL;
  1367. // complex key
  1368. struct NodeL { void *next; uint h; void *k; void *v; } nodeL;
  1369. if (forKey) {
  1370. // offsetof(...,...) not yet in Standard C++
  1371. const ulong nodeOSk ( (char *)&nodeOS.k - (char *)&nodeOS );
  1372. const ulong nodeOLk ( (char *)&nodeOL.k - (char *)&nodeOL );
  1373. const ulong nodeNSk ( (char *)&nodeNS.k - (char *)&nodeNS );
  1374. const ulong nodeNLk ( (char *)&nodeNL.k - (char *)&nodeNL );
  1375. const ulong nodeLk ( (char *)&nodeL.k - (char *)&nodeL );
  1376. if (optimizedIntKey)
  1377. return valueSize > sizeof(int) ? nodeOLk : nodeOSk;
  1378. if (keySize > sizeof(int))
  1379. return nodeLk;
  1380. return valueSize > sizeof(int) ? nodeNLk : nodeNSk;
  1381. } else {
  1382. const ulong nodeOSv ( (char *)&nodeOS.v - (char *)&nodeOS );
  1383. const ulong nodeOLv ( (char *)&nodeOL.v - (char *)&nodeOL );
  1384. const ulong nodeNSv ( (char *)&nodeNS.v - (char *)&nodeNS );
  1385. const ulong nodeNLv ( (char *)&nodeNL.v - (char *)&nodeNL );
  1386. const ulong nodeLv ( (char *)&nodeL.v - (char *)&nodeL );
  1387. if (optimizedIntKey)
  1388. return valueSize > sizeof(int) ? nodeOLv : nodeOSv;
  1389. if (keySize > sizeof(int))
  1390. return nodeLv;
  1391. return valueSize > sizeof(int) ? nodeNLv : nodeNSv;
  1392. }
  1393. }
  1394. static void qDumpQHash(QDumper &d)
  1395. {
  1396. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  1397. const char *keyType = d.templateParameters[0];
  1398. const char *valueType = d.templateParameters[1];
  1399. QHashData *h = *reinterpret_cast<QHashData *const*>(d.data);
  1400. qCheckPointer(h->fakeNext);
  1401. qCheckPointer(h->buckets);
  1402. unsigned keySize = d.extraInt[0];
  1403. unsigned valueSize = d.extraInt[1];
  1404. int n = h->size;
  1405. if (n < 0)
  1406. return;
  1407. if (n > 0) {
  1408. qCheckPointer(h->fakeNext);
  1409. qCheckPointer(*h->buckets);
  1410. }
  1411. d.putItemCount("value", n);
  1412. d.putItem("numchild", n);
  1413. if (d.dumpChildren) {
  1414. const bool isSimpleKey = isSimpleType(keyType);
  1415. const bool isSimpleValue = isSimpleType(valueType);
  1416. const bool opt = isOptimizedIntKey(keyType);
  1417. const int keyOffset = hashOffset(opt, true, keySize, valueSize);
  1418. const int valueOffset = hashOffset(opt, false, keySize, valueSize);
  1419. #if 0
  1420. d.beginItem("extra");
  1421. d.put("isSimpleKey: ").put(isSimpleKey);
  1422. d.put(" isSimpleValue: ").put(isSimpleValue);
  1423. d.put(" valueType: '").put(isSimpleValue);
  1424. d.put(" keySize: ").put(keyOffset);
  1425. d.put(" valueOffset: ").put(valueOffset);
  1426. d.put(" opt: ").put(opt);
  1427. d.endItem();
  1428. #endif
  1429. QHashData::Node *node = h->firstNode();
  1430. QHashData::Node *end = reinterpret_cast<QHashData::Node *>(h);
  1431. int i = 0;
  1432. d.beginChildren();
  1433. while (node != end) {
  1434. d.beginHash();
  1435. qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key");
  1436. qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
  1437. if (isSimpleKey && isSimpleValue) {
  1438. d.putItem("type", valueType);
  1439. d.putItem("addr", addOffset(node, valueOffset));
  1440. } else {
  1441. d.putItem("addr", node);
  1442. d.beginItem("type");
  1443. d.put(NS "QHashNode<").put(keyType).put(",")
  1444. .put(valueType).put(" >");
  1445. d.endItem();
  1446. }
  1447. d.endHash();
  1448. ++i;
  1449. node = QHashData::nextNode(node);
  1450. }
  1451. d.endChildren();
  1452. }
  1453. d.disarm();
  1454. }
  1455. static void qDumpQHashNode(QDumper &d)
  1456. {
  1457. const QHashData *h = reinterpret_cast<const QHashData *>(d.data);
  1458. const char *keyType = d.templateParameters[0];
  1459. const char *valueType = d.templateParameters[1];
  1460. unsigned keySize = d.extraInt[0];
  1461. unsigned valueSize = d.extraInt[1];
  1462. bool opt = isOptimizedIntKey(keyType);
  1463. int keyOffset = hashOffset(opt, true, keySize, valueSize);
  1464. int valueOffset = hashOffset(opt, false, keySize, valueSize);
  1465. if (isSimpleType(valueType))
  1466. qDumpInnerValueHelper(d, valueType, addOffset(h, valueOffset));
  1467. else
  1468. d.putItem("value", "");
  1469. d.putItem("numchild", 2);
  1470. if (d.dumpChildren) {
  1471. // there is a hash specialization in case the keys are integers or shorts
  1472. d.beginChildren();
  1473. d.beginHash();
  1474. d.putItem("name", "key");
  1475. d.putItem("type", keyType);
  1476. d.putItem("addr", addOffset(h, keyOffset));
  1477. d.endHash();
  1478. d.beginHash();
  1479. d.putItem("name", "value");
  1480. d.putItem("type", valueType);
  1481. d.putItem("addr", addOffset(h, valueOffset));
  1482. d.endHash();
  1483. d.endChildren();
  1484. }
  1485. d.disarm();
  1486. }
  1487. #if USE_QT_GUI
  1488. static void qDumpQImage(QDumper &d)
  1489. {
  1490. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  1491. const QImage &im = *reinterpret_cast<const QImage *>(d.data);
  1492. d.beginItem("value");
  1493. d.put("(").put(im.width()).put("x").put(im.height()).put(")");
  1494. d.endItem();
  1495. d.putItem("type", NS "QImage");
  1496. d.putItem("numchild", "0");
  1497. #if 0
  1498. if (d.dumpChildren) {
  1499. d.beginChildren();
  1500. d.beginHash();
  1501. d.putItem("name", "data");
  1502. d.putItem("type", NS "QImageData");
  1503. d.putItem("addr", d.data);
  1504. d.endHash();
  1505. d.endChildren();
  1506. }
  1507. #endif
  1508. d.disarm();
  1509. }
  1510. #endif
  1511. #if USE_QT_GUI
  1512. static void qDumpQImageData(QDumper &d)
  1513. {
  1514. const QImage &im = *reinterpret_cast<const QImage *>(d.data);
  1515. const QByteArray ba(QByteArray::fromRawData((const char*)im.bits(), im.numBytes()));
  1516. d.putItem("type", NS "QImageData");
  1517. d.putItem("numchild", "0");
  1518. #if 1
  1519. d.putItem("value", "<hover here>");
  1520. d.putItem("valuetooltipencoded", "1");
  1521. d.putItem("valuetooltipsize", ba.size());
  1522. d.putItem("valuetooltip", ba);
  1523. #else
  1524. d.putItem("valueencoded", "1");
  1525. d.putItem("value", ba);
  1526. #endif
  1527. d.disarm();
  1528. }
  1529. #endif
  1530. static void qDumpQList(QDumper &d)
  1531. {
  1532. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  1533. // This uses the knowledge that QList<T> has only a single member
  1534. // of type union { QListData p; QListData::Data *d; };
  1535. const QListData &pdata = *reinterpret_cast<const QListData*>(d.data);
  1536. const int nn = pdata.size();
  1537. if (nn < 0)
  1538. return;
  1539. const bool innerTypeIsPointer = isPointerType(d.innerType);
  1540. const int n = qMin(nn, 1000);
  1541. if (nn > 0) {
  1542. if (pdata.d->begin < 0)
  1543. return;
  1544. if (pdata.d->begin > pdata.d->end)
  1545. return;
  1546. #if QT_VERSION >= 0x050000
  1547. if (pdata.d->ref.atomic._q_value <= 0)
  1548. return;
  1549. #elif QT_VERSION >= 0x040400
  1550. if (pdata.d->ref._q_value <= 0)
  1551. return;
  1552. #endif
  1553. qCheckAccess(pdata.d->array);
  1554. // Additional checks on pointer arrays
  1555. if (innerTypeIsPointer)
  1556. for (int i = 0; i != n; ++i)
  1557. if (const void *p = pdata.d->array + i + pdata.d->begin)
  1558. qCheckPointer(deref(p));
  1559. }
  1560. d.putItemCount("value", nn);
  1561. d.putItem("valueeditable", "false");
  1562. d.putItem("numchild", n);
  1563. if (d.dumpChildren) {
  1564. const unsigned innerSize = d.extraInt[0];
  1565. QByteArray strippedInnerType = stripPointerType(d.innerType);
  1566. // The exact condition here is:
  1567. // QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic
  1568. // but this data is available neither in the compiled binary nor
  1569. // in the frontend.
  1570. // So as first approximation only do the 'isLarge' check:
  1571. bool isInternal = innerSize <= int(sizeof(void*))
  1572. && isMovableType(d.innerType);
  1573. d.putItem("internal", (int)isInternal);
  1574. d.beginChildren(n ? d.innerType : 0);
  1575. for (int i = 0; i != n; ++i) {
  1576. d.beginHash();
  1577. if (innerTypeIsPointer) {
  1578. void *p = pdata.d->array + i + pdata.d->begin;
  1579. if (*(void**)p) {
  1580. //d.putItem("value","@").put(p);
  1581. qDumpInnerValue(d, strippedInnerType.data(), deref(p));
  1582. } else {
  1583. d.putItem("value", "<null>");
  1584. d.putItem("numchild", "0");
  1585. }
  1586. } else {
  1587. void *p = pdata.d->array + i + pdata.d->begin;
  1588. if (isInternal) {
  1589. //qDumpInnerValue(d, d.innerType, p);
  1590. d.putItem("addr", p);
  1591. qDumpInnerValueHelper(d, d.innerType, p);
  1592. } else {
  1593. //qDumpInnerValue(d, d.innerType, deref(p));
  1594. d.putItem("addr", deref(p));
  1595. qDumpInnerValueHelper(d, d.innerType, deref(p));
  1596. }
  1597. }
  1598. d.endHash();
  1599. }
  1600. if (n < nn)
  1601. d.putEllipsis();
  1602. d.endChildren();
  1603. }
  1604. d.disarm();
  1605. }
  1606. static void qDumpQLinkedList(QDumper &d)
  1607. {
  1608. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  1609. // This uses the knowledge that QLinkedList<T> has only a single member
  1610. // of type union { QLinkedListData *d; QLinkedListNode<T> *e; };
  1611. const QLinkedListData *ldata =
  1612. reinterpret_cast<const QLinkedListData*>(deref(d.data));
  1613. int nn = ldata->size;
  1614. if (nn < 0)
  1615. return;
  1616. int n = nn;
  1617. d.putItemCount("value", n);
  1618. d.putItem("valueeditable", "false");
  1619. d.putItem("numchild", n);
  1620. if (d.dumpChildren) {
  1621. //unsigned innerSize = d.extraInt[0];
  1622. //bool innerTypeIsPointer = isPointerType(d.innerType);
  1623. QByteArray strippedInnerType = stripPointerType(d.innerType);
  1624. const char *stripped =
  1625. isPointerType(d.innerType) ? strippedInnerType.data() : 0;
  1626. if (n > 1000)
  1627. n = 1000;
  1628. d.beginChildren(d.innerType);
  1629. const void *p = deref(ldata);
  1630. for (int i = 0; i != n; ++i) {
  1631. d.beginHash();
  1632. const void *addr = addOffset(p, 2 * sizeof(void*));
  1633. qDumpInnerValueOrPointer(d, d.innerType, stripped, addr);
  1634. p = deref(p);
  1635. d.endHash();
  1636. }
  1637. if (n < nn)
  1638. d.putEllipsis();
  1639. d.endChildren();
  1640. }
  1641. d.disarm();
  1642. }
  1643. static void qDumpQLocale(QDumper &d)
  1644. {
  1645. const QLocale &locale = *reinterpret_cast<const QLocale *>(d.data);
  1646. d.putItem("value", locale.name());
  1647. d.putItem("valueencoded", "2");
  1648. d.putItem("type", NS "QLocale");
  1649. d.putItem("numchild", "8");
  1650. if (d.dumpChildren) {
  1651. d.beginChildren();
  1652. d.beginHash();
  1653. d.putItem("name", "country");
  1654. d.beginItem("exp");
  1655. d.put("((" NSX "QLocale" NSY "*)").put(d.data).put(")->country()");
  1656. d.endItem();
  1657. d.endHash();
  1658. d.beginHash();
  1659. d.putItem("name", "language");
  1660. d.beginItem("exp");
  1661. d.put("((" NSX "QLocale" NSY "*)").put(d.data).put(")->language()");
  1662. d.endItem();
  1663. d.endHash();
  1664. d.beginHash();
  1665. d.putItem("name", "measurementSystem");
  1666. d.beginItem("exp");
  1667. d.put("((" NSX "QLocale" NSY "*)").put(d.data).put(")->measurementSystem()");
  1668. d.endItem();
  1669. d.endHash();
  1670. d.beginHash();
  1671. d.putItem("name", "numberOptions");
  1672. d.beginItem("exp");
  1673. d.put("((" NSX "QLocale" NSY "*)").put(d.data).put(")->numberOptions()");
  1674. d.endItem();
  1675. d.endHash();
  1676. d.putHash("timeFormat_(short)", locale.timeFormat(QLocale::ShortFormat));
  1677. d.putHash("timeFormat_(long)", locale.timeFormat(QLocale::LongFormat));
  1678. d.putHash("decimalPoint", locale.decimalPoint());
  1679. d.putHash("exponential", locale.exponential());
  1680. d.putHash("percent", locale.percent());
  1681. d.putHash("zeroDigit", locale.zeroDigit());
  1682. d.putHash("groupSeparator", locale.groupSeparator());
  1683. d.putHash("negativeSign", locale.negativeSign());
  1684. d.endChildren();
  1685. }
  1686. d.disarm();
  1687. }
  1688. #if MAP_WORKS
  1689. static void qDumpQMapNode(QDumper &d)
  1690. {
  1691. const QMapData *h = reinterpret_cast<const QMapData *>(d.data);
  1692. const char *keyType = d.templateParameters[0];
  1693. const char *valueType = d.templateParameters[1];
  1694. qCheckAccess(h->backward);
  1695. qCheckAccess(h->forward[0]);
  1696. d.putItem("value", "");
  1697. d.putItem("numchild", 2);
  1698. if (d.dumpChildren) {
  1699. unsigned mapnodesize = d.extraInt[2];
  1700. unsigned valueOff = d.extraInt[3];
  1701. unsigned keyOffset = 2 * sizeof(void*) - mapnodesize;
  1702. unsigned valueOffset = 2 * sizeof(void*) - mapnodesize + valueOff;
  1703. d.beginChildren();
  1704. d.beginHash();
  1705. d.putItem("name", "key");
  1706. qDumpInnerValue(d, keyType, addOffset(h, keyOffset));
  1707. d.endHash();
  1708. d.beginHash();
  1709. d.putItem("name", "value");
  1710. qDumpInnerValue(d, valueType, addOffset(h, valueOffset));
  1711. d.endHash();
  1712. d.endChildren();
  1713. }
  1714. d.disarm();
  1715. }
  1716. static void qDumpQMap(QDumper &d)
  1717. {
  1718. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  1719. QMapData *h = *reinterpret_cast<QMapData *const*>(d.data);
  1720. const char *keyType = d.templateParameters[0];
  1721. const char *valueType = d.templateParameters[1];
  1722. int n = h->size;
  1723. if (n < 0)
  1724. return;
  1725. if (n > 0) {
  1726. qCheckAccess(h->backward);
  1727. qCheckAccess(h->forward[0]);
  1728. qCheckPointer(h->backward->backward);
  1729. qCheckPointer(h->forward[0]->backward);
  1730. }
  1731. d.putItemCount("value", n);
  1732. d.putItem("numchild", n);
  1733. if (d.dumpChildren) {
  1734. //unsigned keySize = d.extraInt[0];
  1735. //unsigned valueSize = d.extraInt[1];
  1736. unsigned mapnodesize = d.extraInt[2];
  1737. unsigned valueOff = d.extraInt[3];
  1738. bool isSimpleKey = isSimpleType(keyType);
  1739. bool isSimpleValue = isSimpleType(valueType);
  1740. // both negative:
  1741. int keyOffset = 2 * sizeof(void*) - int(mapnodesize);
  1742. int valueOffset = 2 * sizeof(void*) - int(mapnodesize) + valueOff;
  1743. d.beginItem("extra");
  1744. d.put("simplekey: ").put(isSimpleKey).put(" isSimpleValue: ").put(isSimpleValue);
  1745. d.put(" keyOffset: ").put(keyOffset).put(" valueOffset: ").put(valueOffset);
  1746. d.put(" mapnodesize: ").put(mapnodesize);
  1747. d.endItem();
  1748. d.beginChildren();
  1749. QMapData::Node *node = reinterpret_cast<QMapData::Node *>(h->forward[0]);
  1750. QMapData::Node *end = reinterpret_cast<QMapData::Node *>(h);
  1751. int i = 0;
  1752. while (node != end) {
  1753. d.beginHash();
  1754. qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key");
  1755. qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
  1756. if (isSimpleKey && isSimpleValue) {
  1757. d.putItem("type", valueType);
  1758. d.putItem("addr", addOffset(node, valueOffset));
  1759. } else {
  1760. #if QT_VERSION >= 0x040500
  1761. d.putItem("addr", node);
  1762. // actually, any type (even 'char') will do...
  1763. d.beginItem("type");
  1764. d.put(NS "QMapNode<").put(keyType).put(",");
  1765. d.put(valueType).put(" >");
  1766. d.endItem();
  1767. #else
  1768. d.beginItem("type");
  1769. d.put(NS "QMapData::Node<").put(keyType).put(",");
  1770. d.put(valueType).put(" >");
  1771. d.endItem();
  1772. d.beginItem("exp");
  1773. d.put("*('" NS "QMapData::Node<").put(keyType).put(",");
  1774. d.put(valueType).put(" >'*)").put(node);
  1775. d.endItem();
  1776. #endif
  1777. }
  1778. d.endHash();
  1779. ++i;
  1780. node = node->forward[0];
  1781. }
  1782. d.endChildren();
  1783. }
  1784. d.disarm();
  1785. }
  1786. static void qDumpQMultiMap(QDumper &d)
  1787. {
  1788. qDumpQMap(d);
  1789. }
  1790. #endif // MAP_WORKS
  1791. #ifndef QT_BOOTSTRAPPED
  1792. static void qDumpQModelIndex(QDumper &d)
  1793. {
  1794. const QModelIndex *mi = reinterpret_cast<const QModelIndex *>(d.data);
  1795. d.putItem("type", NS "QModelIndex");
  1796. if (mi->isValid()) {
  1797. d.beginItem("value");
  1798. d.put("(").put(mi->row()).put(", ").put(mi->column()).put(")");
  1799. d.endItem();
  1800. d.putItem("numchild", 5);
  1801. if (d.dumpChildren) {
  1802. d.beginChildren();
  1803. d.putHash("row", mi->row());
  1804. d.putHash("column", mi->column());
  1805. d.beginHash();
  1806. d.putItem("name", "parent");
  1807. const QModelIndex parent = mi->parent();
  1808. d.beginItem("value");
  1809. if (parent.isValid())
  1810. d.put("(").put(parent.row()).put(", ").put(parent.column()).put(")");
  1811. else
  1812. d.put("<invalid>");
  1813. d.endItem();
  1814. d.beginItem("exp");
  1815. d.put("((" NSX "QModelIndex" NSY "*)").put(d.data).put(")->parent()");
  1816. d.endItem();
  1817. d.putItem("type", NS "QModelIndex");
  1818. d.putItem("numchild", "1");
  1819. d.endHash();
  1820. d.putHash("internalId", QString::number(mi->internalId(), 10));
  1821. d.beginHash();
  1822. d.putItem("name", "model");
  1823. d.putItem("value", static_cast<const void *>(mi->model()));
  1824. d.putItem("type", NS "QAbstractItemModel*");
  1825. d.putItem("numchild", "1");
  1826. d.endHash();
  1827. d.endChildren();
  1828. }
  1829. } else {
  1830. d.putItem("value", "<invalid>");
  1831. d.putItem("numchild", 0);
  1832. }
  1833. d.disarm();
  1834. }
  1835. static void qDumpQObject(QDumper &d)
  1836. {
  1837. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  1838. const QObject *ob = reinterpret_cast<const QObject *>(d.data);
  1839. const QMetaObject *mo = ob->metaObject();
  1840. d.putItem("value", ob->objectName());
  1841. d.putItem("valueencoded", "2");
  1842. d.putItem("type", NS "QObject");
  1843. d.putItem("displayedtype", mo->className());
  1844. d.putItem("numchild", 4);
  1845. if (d.dumpChildren) {
  1846. int slotCount = 0;
  1847. int signalCount = 0;
  1848. for (int i = mo->methodCount(); --i >= 0; ) {
  1849. QMetaMethod::MethodType mt = mo->method(i).methodType();
  1850. signalCount += (mt == QMetaMethod::Signal);
  1851. slotCount += (mt == QMetaMethod::Slot);
  1852. }
  1853. d.beginChildren();
  1854. d.beginHash();
  1855. d.putItem("name", "properties");
  1856. // using 'addr' does not work in gdb as 'exp' is recreated as
  1857. // (type *)addr, and here we have different 'types':
  1858. // QObject vs QObjectPropertyList!
  1859. d.putItem("addr", d.data);
  1860. d.putItem("type", NS "QObjectPropertyList");
  1861. d.putItemCount("value", mo->propertyCount());
  1862. d.putItem("numchild", mo->propertyCount());
  1863. d.endHash();
  1864. d.beginHash();
  1865. d.putItem("name", "signals");
  1866. d.putItem("addr", d.data);
  1867. d.putItem("type", NS "QObjectSignalList");
  1868. d.putItemCount("value", signalCount);
  1869. d.putItem("numchild", signalCount);
  1870. d.endHash();
  1871. d.beginHash();
  1872. d.putItem("name", "slots");
  1873. d.putItem("addr", d.data);
  1874. d.putItem("type", NS "QObjectSlotList");
  1875. d.putItemCount("value", slotCount);
  1876. d.putItem("numchild", slotCount);
  1877. d.endHash();
  1878. const QObjectList objectChildren = ob->children();
  1879. if (!objectChildren.empty()) {
  1880. d.beginHash();
  1881. d.putItem("name", "children");
  1882. d.putItem("addr", d.data);
  1883. d.putItem("type", NS "QObjectChildList");
  1884. d.putItemCount("value", objectChildren.size());
  1885. d.putItem("numchild", objectChildren.size());
  1886. d.endHash();
  1887. }
  1888. d.beginHash();
  1889. d.putItem("name", "parent");
  1890. qDumpInnerValueHelper(d, NS "QObject *", ob->parent());
  1891. d.endHash();
  1892. #if 1
  1893. d.beginHash();
  1894. d.putItem("name", "className");
  1895. d.putItem("value", ob->metaObject()->className());
  1896. d.putItem("type", "");
  1897. d.putItem("numchild", "0");
  1898. d.endHash();
  1899. #endif
  1900. d.endChildren();
  1901. }
  1902. d.disarm();
  1903. }
  1904. #endif // QT_BOOTSTRAPPED
  1905. #if USE_QT_GUI
  1906. static const char *sizePolicyEnumValue(QSizePolicy::Policy p)
  1907. {
  1908. switch (p) {
  1909. case QSizePolicy::Fixed:
  1910. return "Fixed";
  1911. case QSizePolicy::Minimum:
  1912. return "Minimum";
  1913. case QSizePolicy::Maximum:
  1914. return "Maximum";
  1915. case QSizePolicy::Preferred:
  1916. return "Preferred";
  1917. case QSizePolicy::Expanding:
  1918. return "Expanding";
  1919. case QSizePolicy::MinimumExpanding:
  1920. return "MinimumExpanding";
  1921. case QSizePolicy::Ignored:
  1922. break;
  1923. }
  1924. return "Ignored";
  1925. }
  1926. static QString sizePolicyValue(const QSizePolicy &sp)
  1927. {
  1928. QString rc;
  1929. QTextStream str(&rc);
  1930. // Display as in Designer
  1931. str << '[' << sizePolicyEnumValue(sp.horizontalPolicy())
  1932. << ", " << sizePolicyEnumValue(sp.verticalPolicy())
  1933. << ", " << sp.horizontalStretch() << ", " << sp.verticalStretch() << ']';
  1934. return rc;
  1935. }
  1936. #endif
  1937. static void qDumpQVariantHelper(const QVariant *v, QString *value,
  1938. QString *exp, int *numchild)
  1939. {
  1940. switch (v->type()) {
  1941. case QVariant::Invalid:
  1942. *value = QLatin1String("<invalid>");
  1943. *numchild = 0;
  1944. break;
  1945. case QVariant::String:
  1946. *value = QLatin1Char('"') + v->toString() + QLatin1Char('"');
  1947. *numchild = 0;
  1948. break;
  1949. # if QT_VERSION >= 0x040500
  1950. case QVariant::StringList:
  1951. *exp = QString(QLatin1String("(*('" NS "QStringList'*)%1)"))
  1952. .arg((quintptr)v);
  1953. *numchild = v->toStringList().size();
  1954. break;
  1955. # endif
  1956. case QVariant::Int:
  1957. *value = QString::number(v->toInt());
  1958. *numchild= 0;
  1959. break;
  1960. case QVariant::Double:
  1961. *value = QString::number(v->toDouble());
  1962. *numchild = 0;
  1963. break;
  1964. # ifndef QT_BOOTSTRAPPED
  1965. case QVariant::Point: {
  1966. const QPoint p = v->toPoint();
  1967. *value = QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y());
  1968. }
  1969. *numchild = 0;
  1970. break;
  1971. case QVariant::Size: {
  1972. const QSize size = v->toSize();
  1973. *value = QString::fromLatin1("%1x%2")
  1974. .arg(size.width()).arg(size.height());
  1975. }
  1976. *numchild = 0;
  1977. break;
  1978. case QVariant::Rect: {
  1979. const QRect rect = v->toRect();
  1980. *value = QString::fromLatin1("%1x%2+%3+%4")
  1981. .arg(rect.width()).arg(rect.height())
  1982. .arg(rect.x()).arg(rect.y());
  1983. }
  1984. *numchild = 0;
  1985. break;
  1986. case QVariant::PointF: {
  1987. const QPointF p = v->toPointF();
  1988. *value = QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y());
  1989. }
  1990. *numchild = 0;
  1991. break;
  1992. case QVariant::SizeF: {
  1993. const QSizeF size = v->toSizeF();
  1994. *value = QString::fromLatin1("%1x%2")
  1995. .arg(size.width()).arg(size.height());
  1996. }
  1997. *numchild = 0;
  1998. break;
  1999. case QVariant::RectF: {
  2000. const QRectF rect = v->toRectF();
  2001. *value = QString::fromLatin1("%1x%2+%3+%4")
  2002. .arg(rect.width()).arg(rect.height())
  2003. .arg(rect.x()).arg(rect.y());
  2004. }
  2005. *numchild = 0;
  2006. break;
  2007. # endif // QT_BOOTSTRAPPED
  2008. # if USE_QT_GUI
  2009. case QVariant::Font:
  2010. *value = qvariant_cast<QFont>(*v).toString();
  2011. break;
  2012. case QVariant::Color:
  2013. *value = qvariant_cast<QColor>(*v).name();
  2014. break;
  2015. case QVariant::KeySequence:
  2016. # ifndef QT_NO_SHORTCUT
  2017. *value = qvariant_cast<QKeySequence>(*v).toString();
  2018. # else
  2019. *value = QString::fromLatin1("Disabled by QT_NO_SHORTCUT");
  2020. # endif
  2021. break;
  2022. case QVariant::SizePolicy:
  2023. *value = sizePolicyValue(qvariant_cast<QSizePolicy>(*v));
  2024. break;
  2025. # endif
  2026. default: {
  2027. static const char *qTypeFormat = sizeof(void *) == sizeof(long)
  2028. ? "'" NS "%s " NS "qVariantValue<" NS "%s >'(*('" NS "QVariant'*)0x%lx)"
  2029. : "'" NS "%s " NS "qVariantValue<" NS "%s >'(*('" NS "QVariant'*)0x%llx)";
  2030. static const char *nonQTypeFormat = sizeof(void *) == sizeof(long)
  2031. ? "'%s " NS "qVariantValue<%s >'(*('" NS "QVariant'*)0x%lx)"
  2032. : "'%s " NS "qVariantValue<%s >'(*('" NS "QVariant'*)0x%llx)";
  2033. char buf[1000];
  2034. const char *format = (v->typeName()[0] == 'Q') ? qTypeFormat : nonQTypeFormat;
  2035. qsnprintf(buf, sizeof(buf) - 1, format, v->typeName(), v->typeName(), v);
  2036. *exp = QLatin1String(buf);
  2037. *numchild = 1;
  2038. break;
  2039. }
  2040. }
  2041. }
  2042. static void qDumpQVariant(QDumper &d, const QVariant *v)
  2043. {
  2044. QString value;
  2045. QString exp;
  2046. int numchild = 0;
  2047. qDumpQVariantHelper(v, &value, &exp, &numchild);
  2048. bool isInvalid = (v->typeName() == 0);
  2049. if (isInvalid) {
  2050. d.putItem("value", "(invalid)");
  2051. } else if (value.isEmpty()) {
  2052. d.beginItem("value");
  2053. d.put("(").put(v->typeName()).put(") ");
  2054. d.endItem();
  2055. } else {
  2056. QByteArray ba;
  2057. ba += '(';
  2058. ba += v->typeName();
  2059. ba += ") ";
  2060. ba += qPrintable(value);
  2061. d.putItem("value", ba);
  2062. d.putItem("valueencoded", "5");
  2063. }
  2064. d.putItem("type", NS "QVariant");
  2065. if (isInvalid || !numchild) {
  2066. d.putItem("numchild", "0");
  2067. } else {
  2068. d.putItem("numchild", "1");
  2069. if (d.dumpChildren) {
  2070. d.beginChildren();
  2071. d.beginHash();
  2072. d.putItem("name", "value");
  2073. if (!exp.isEmpty())
  2074. d.putItem("exp", qPrintable(exp));
  2075. if (!value.isEmpty()) {
  2076. d.putItem("value", value);
  2077. d.putItem("valueencoded", "4");
  2078. }
  2079. d.putItem("type", v->typeName());
  2080. d.putItem("numchild", numchild);
  2081. d.endHash();
  2082. d.endChildren();
  2083. }
  2084. }
  2085. d.disarm();
  2086. }
  2087. static inline void qDumpQVariant(QDumper &d)
  2088. {
  2089. qCheckAccess(d.data);
  2090. qDumpQVariant(d, reinterpret_cast<const QVariant *>(d.data));
  2091. }
  2092. // Meta enumeration helpers
  2093. static inline void dumpMetaEnumType(QDumper &d, const QMetaEnum &me)
  2094. {
  2095. QByteArray type = me.scope();
  2096. if (!type.isEmpty())
  2097. type += "::";
  2098. type += me.name();
  2099. d.putItem("type", type.constData());
  2100. }
  2101. static inline void dumpMetaEnumValue(QDumper &d, const QMetaProperty &mop,
  2102. int value)
  2103. {
  2104. const QMetaEnum me = mop.enumerator();
  2105. dumpMetaEnumType(d, me);
  2106. if (const char *enumValue = me.valueToKey(value)) {
  2107. d.putItem("value", enumValue);
  2108. } else {
  2109. d.putItem("value", value);
  2110. }
  2111. d.putItem("numchild", 0);
  2112. }
  2113. static inline void dumpMetaFlagValue(QDumper &d, const QMetaProperty &mop,
  2114. int value)
  2115. {
  2116. const QMetaEnum me = mop.enumerator();
  2117. dumpMetaEnumType(d, me);
  2118. const QByteArray flagsValue = me.valueToKeys(value);
  2119. if (flagsValue.isEmpty()) {
  2120. d.putItem("value", value);
  2121. } else {
  2122. d.putItem("value", flagsValue.constData());
  2123. }
  2124. d.putItem("numchild", 0);
  2125. }
  2126. #ifndef QT_BOOTSTRAPPED
  2127. static void qDumpQObjectProperty(QDumper &d)
  2128. {
  2129. const QObject *ob = (const QObject *)d.data;
  2130. const QMetaObject *mob = ob->metaObject();
  2131. // extract "local.Object.property"
  2132. QString iname = d.iname;
  2133. const int dotPos = iname.lastIndexOf(QLatin1Char('.'));
  2134. if (dotPos == -1)
  2135. return;
  2136. iname.remove(0, dotPos + 1);
  2137. const int index = mob->indexOfProperty(iname.toAscii());
  2138. if (index == -1)
  2139. return;
  2140. const QMetaProperty mop = mob->property(index);
  2141. const QVariant value = mop.read(ob);
  2142. const bool isInteger = value.type() == QVariant::Int;
  2143. if (isInteger && mop.isEnumType()) {
  2144. dumpMetaEnumValue(d, mop, value.toInt());
  2145. } else if (isInteger && mop.isFlagType()) {
  2146. dumpMetaFlagValue(d, mop, value.toInt());
  2147. } else {
  2148. qDumpQVariant(d, &value);
  2149. }
  2150. d.disarm();
  2151. }
  2152. static void qDumpQObjectPropertyList(QDumper &d)
  2153. {
  2154. const QObject *ob = (const QObject *)d.data;
  2155. const QMetaObject *mo = ob->metaObject();
  2156. const int propertyCount = mo->propertyCount();
  2157. d.putItem("addr", "<synthetic>");
  2158. d.putItem("type", NS "QObjectPropertyList");
  2159. d.putItem("numchild", propertyCount);
  2160. d.putItemCount("value", propertyCount);
  2161. if (d.dumpChildren) {
  2162. d.beginChildren();
  2163. for (int i = propertyCount; --i >= 0; ) {
  2164. const QMetaProperty & prop = mo->property(i);
  2165. d.beginHash();
  2166. d.putItem("name", prop.name());
  2167. switch (prop.type()) {
  2168. case QVariant::String:
  2169. d.putItem("type", prop.typeName());
  2170. d.putItem("value", prop.read(ob).toString());
  2171. d.putItem("valueencoded", "2");
  2172. d.putItem("numchild", "0");
  2173. break;
  2174. case QVariant::Bool:
  2175. d.putItem("type", prop.typeName());
  2176. d.putItem("value", (prop.read(ob).toBool() ? "true" : "false"));
  2177. d.putItem("numchild", "0");
  2178. break;
  2179. case QVariant::Int:
  2180. if (prop.isEnumType()) {
  2181. dumpMetaEnumValue(d, prop, prop.read(ob).toInt());
  2182. } else if (prop.isFlagType()) {
  2183. dumpMetaFlagValue(d, prop, prop.read(ob).toInt());
  2184. } else {
  2185. d.putItem("value", prop.read(ob).toInt());
  2186. d.putItem("numchild", "0");
  2187. }
  2188. break;
  2189. default:
  2190. d.putItem("addr", d.data);
  2191. d.putItem("type", NS "QObjectProperty");
  2192. d.putItem("numchild", "1");
  2193. break;
  2194. }
  2195. d.endHash();
  2196. }
  2197. d.endChildren();
  2198. }
  2199. d.disarm();
  2200. }
  2201. static QByteArray methodSignature(const QMetaMethod &method)
  2202. {
  2203. #if QT_VERSION >= 0x050000
  2204. return method.methodSignature();
  2205. #else
  2206. return QByteArray(method.signature());
  2207. #endif
  2208. }
  2209. static void qDumpQObjectMethodList(QDumper &d)
  2210. {
  2211. const QObject *ob = (const QObject *)d.data;
  2212. const QMetaObject *mo = ob->metaObject();
  2213. d.putItem("addr", "<synthetic>");
  2214. d.putItem("type", NS "QObjectMethodList");
  2215. d.putItem("numchild", mo->methodCount());
  2216. if (d.dumpChildren) {
  2217. d.putItem("childtype", NS "QMetaMethod::Method");
  2218. d.putItem("childnumchild", "0");
  2219. d.beginChildren();
  2220. for (int i = 0; i != mo->methodCount(); ++i) {
  2221. const QMetaMethod & method = mo->method(i);
  2222. int mt = method.methodType();
  2223. const QByteArray sig = methodSignature(method);
  2224. d.beginHash();
  2225. d.beginItem("name");
  2226. d.put(i).put(" ").put(mo->indexOfMethod(sig));
  2227. d.put(" ").put(sig);
  2228. d.endItem();
  2229. d.beginItem("value");
  2230. d.put((mt == QMetaMethod::Signal ? "<Signal>" : "<Slot>"));
  2231. d.put(" (").put(mt).put(")");
  2232. d.endItem();
  2233. d.endHash();
  2234. }
  2235. d.endChildren();
  2236. }
  2237. d.disarm();
  2238. }
  2239. static const char *qConnectionType(uint type)
  2240. {
  2241. Qt::ConnectionType connType = static_cast<Qt::ConnectionType>(type);
  2242. const char *output = "unknown";
  2243. switch (connType) {
  2244. case Qt::AutoConnection: output = "auto"; break;
  2245. case Qt::DirectConnection: output = "direct"; break;
  2246. case Qt::QueuedConnection: output = "queued"; break;
  2247. case Qt::BlockingQueuedConnection: output = "blockingqueued"; break;
  2248. #if QT_VERSION < 0x050000
  2249. case 3: output = "autocompat"; break;
  2250. #endif
  2251. #if QT_VERSION >= 0x040600
  2252. case Qt::UniqueConnection: break; // Can't happen.
  2253. #endif
  2254. };
  2255. return output;
  2256. }
  2257. #if QT_VERSION < 0x040400
  2258. #else
  2259. static const ConnectionList &qConnectionList(const QObject *ob, int signalNumber)
  2260. {
  2261. static const ConnectionList emptyList;
  2262. const ObjectPrivate *p = reinterpret_cast<const ObjectPrivate *>(dfunc(ob));
  2263. if (!p->connectionLists)
  2264. return emptyList;
  2265. typedef QVector<ConnectionList> ConnLists;
  2266. const ConnLists *lists = reinterpret_cast<const ConnLists *>(p->connectionLists);
  2267. // there's an optimization making the lists only large enough to hold the
  2268. // last non-empty item
  2269. if (signalNumber >= lists->size())
  2270. return emptyList;
  2271. return lists->at(signalNumber);
  2272. }
  2273. #endif
  2274. // Write party involved in a slot/signal element,
  2275. // avoid to recursion to self.
  2276. static inline void qDumpQObjectConnectionPart(QDumper &d,
  2277. const QObject *owner,
  2278. const QObject *partner,
  2279. int number, const char *namePostfix)
  2280. {
  2281. d.beginHash();
  2282. d.beginItem("name");
  2283. d.put(number).put(namePostfix);
  2284. d.endItem();
  2285. if (partner == owner) {
  2286. d.putItem("value", "<this>");
  2287. d.putItem("type", owner->metaObject()->className());
  2288. d.putItem("numchild", 0);
  2289. d.putItem("addr", owner);
  2290. } else {
  2291. qDumpInnerValueHelper(d, NS "QObject *", partner);
  2292. }
  2293. d.endHash();
  2294. }
  2295. static void qDumpQObjectSignal(QDumper &d)
  2296. {
  2297. unsigned signalNumber = d.extraInt[0];
  2298. d.putItem("addr", "<synthetic>");
  2299. d.putItem("numchild", "1");
  2300. d.putItem("type", NS "QObjectSignal");
  2301. #if QT_VERSION >= 0x040400
  2302. if (d.dumpChildren) {
  2303. const QObject *ob = reinterpret_cast<const QObject *>(d.data);
  2304. d.beginChildren();
  2305. const ConnectionList &connList = qConnectionList(ob, signalNumber);
  2306. for (int i = 0; i != connList.size(); ++i) {
  2307. const Connection &conn = connectionAt(connList, i);
  2308. qDumpQObjectConnectionPart(d, ob, conn.receiver, i, " receiver");
  2309. d.beginHash();
  2310. d.beginItem("name");
  2311. d.put(i).put(" slot");
  2312. d.endItem();
  2313. d.putItem("type", "");
  2314. if (conn.receiver)
  2315. d.putItem("value", methodSignature(conn.receiver->metaObject()
  2316. ->method(conn.method_())));
  2317. else
  2318. d.putItem("value", "<invalid receiver>");
  2319. d.putItem("numchild", "0");
  2320. d.endHash();
  2321. d.beginHash();
  2322. d.beginItem("name");
  2323. d.put(i).put(" type");
  2324. d.endItem();
  2325. d.putItem("type", "");
  2326. d.beginItem("value");
  2327. d.put("<").put(qConnectionType(conn.connectionType)).put(" connection>");
  2328. d.endItem();
  2329. d.putItem("numchild", "0");
  2330. d.endHash();
  2331. }
  2332. d.endChildren();
  2333. d.putItem("numchild", connList.size());
  2334. }
  2335. #endif
  2336. d.disarm();
  2337. }
  2338. static void qDumpQObjectSignalList(QDumper &d)
  2339. {
  2340. const QObject *ob = reinterpret_cast<const QObject *>(d.data);
  2341. const QMetaObject *mo = ob->metaObject();
  2342. int count = 0;
  2343. const int methodCount = mo->methodCount();
  2344. for (int i = methodCount; --i >= 0; )
  2345. count += (mo->method(i).methodType() == QMetaMethod::Signal);
  2346. d.putItem("type", NS "QObjectSignalList");
  2347. d.putItemCount("value", count);
  2348. d.putItem("addr", d.data);
  2349. d.putItem("numchild", count);
  2350. #if QT_VERSION >= 0x040400
  2351. if (d.dumpChildren) {
  2352. d.beginChildren();
  2353. for (int i = 0; i != methodCount; ++i) {
  2354. const QMetaMethod & method = mo->method(i);
  2355. if (method.methodType() == QMetaMethod::Signal) {
  2356. int k = mo->indexOfSignal(methodSignature(method));
  2357. const ConnectionList &connList = qConnectionList(ob, k);
  2358. d.beginHash();
  2359. d.putItem("name", k);
  2360. d.putItem("value", methodSignature(method));
  2361. d.putItem("numchild", connList.size());
  2362. d.putItem("addr", d.data);
  2363. d.putItem("type", NS "QObjectSignal");
  2364. d.endHash();
  2365. }
  2366. }
  2367. d.endChildren();
  2368. }
  2369. #endif
  2370. d.disarm();
  2371. }
  2372. static void qDumpQObjectSlot(QDumper &d)
  2373. {
  2374. int slotNumber = d.extraInt[0];
  2375. d.putItem("addr", d.data);
  2376. d.putItem("numchild", "1");
  2377. d.putItem("type", NS "QObjectSlot");
  2378. #if QT_VERSION >= 0x040400
  2379. if (d.dumpChildren) {
  2380. d.beginChildren();
  2381. int numchild = 0;
  2382. const QObject *ob = reinterpret_cast<const QObject *>(d.data);
  2383. const ObjectPrivate *p = reinterpret_cast<const ObjectPrivate *>(dfunc(ob));
  2384. #if QT_VERSION >= 0x040600
  2385. int s = 0;
  2386. for (SenderList senderList = p->senders; senderList != 0;
  2387. senderList = senderList->next, ++s) {
  2388. const QObject *sender = senderList->sender;
  2389. int signal = senderList->method_(); // FIXME: 'method' is wrong.
  2390. #else
  2391. for (int s = 0; s != p->senders.size(); ++s) {
  2392. const QObject *sender = senderAt(p->senders, s);
  2393. int signal = signalAt(p->senders, s);
  2394. #endif
  2395. const ConnectionList &connList = qConnectionList(sender, signal);
  2396. for (int i = 0; i != connList.size(); ++i) {
  2397. const Connection &conn = connectionAt(connList, i);
  2398. if (conn.receiver == ob && conn.method_() == slotNumber) {
  2399. ++numchild;
  2400. QMetaMethod method = sender->metaObject()->method(signal);
  2401. qDumpQObjectConnectionPart(d, ob, sender, s, " sender");
  2402. d.beginHash();
  2403. d.beginItem("name");
  2404. d.put(s).put(" signal");
  2405. d.endItem();
  2406. d.putItem("type", "");
  2407. d.putItem("value", methodSignature(method));
  2408. d.putItem("numchild", "0");
  2409. d.endHash();
  2410. d.beginHash();
  2411. d.beginItem("name");
  2412. d.put(s).put(" type");
  2413. d.endItem();
  2414. d.putItem("type", "");
  2415. d.beginItem("value");
  2416. d.put("<").put(qConnectionType(conn.method_()));
  2417. d.put(" connection>");
  2418. d.endItem();
  2419. d.putItem("numchild", "0");
  2420. d.endHash();
  2421. }
  2422. }
  2423. }
  2424. d.endChildren();
  2425. d.putItem("numchild", numchild);
  2426. }
  2427. #endif
  2428. d.disarm();
  2429. }
  2430. static void qDumpQObjectSlotList(QDumper &d)
  2431. {
  2432. const QObject *ob = reinterpret_cast<const QObject *>(d.data);
  2433. #if QT_VERSION >= 0x040400
  2434. const ObjectPrivate *p = reinterpret_cast<const ObjectPrivate *>(dfunc(ob));
  2435. #endif
  2436. const QMetaObject *mo = ob->metaObject();
  2437. int count = 0;
  2438. const int methodCount = mo->methodCount();
  2439. for (int i = methodCount; --i >= 0; )
  2440. count += (mo->method(i).methodType() == QMetaMethod::Slot);
  2441. d.putItem("numchild", count);
  2442. d.putItemCount("value", count);
  2443. d.putItem("type", NS "QObjectSlotList");
  2444. if (d.dumpChildren) {
  2445. d.beginChildren();
  2446. #if QT_VERSION >= 0x040400
  2447. for (int i = 0; i != methodCount; ++i) {
  2448. QMetaMethod method = mo->method(i);
  2449. if (method.methodType() == QMetaMethod::Slot) {
  2450. d.beginHash();
  2451. QByteArray sig = methodSignature(method);
  2452. int k = mo->indexOfSlot(sig);
  2453. d.putItem("name", k);
  2454. d.putItem("value", sig);
  2455. // count senders. expensive...
  2456. int numchild = 0;
  2457. #if QT_VERSION >= 0x040600
  2458. int s = 0;
  2459. for (SenderList senderList = p->senders; senderList != 0;
  2460. senderList = senderList->next, ++s) {
  2461. const QObject *sender = senderList->sender;
  2462. int signal = senderList->method_(); // FIXME: 'method' is wrong.
  2463. #else
  2464. for (int s = 0; s != p->senders.size(); ++s) {
  2465. const QObject *sender = senderAt(p->senders, s);
  2466. int signal = signalAt(p->senders, s);
  2467. #endif
  2468. const ConnectionList &connList = qConnectionList(sender, signal);
  2469. for (int c = 0; c != connList.size(); ++c) {
  2470. const Connection &conn = connectionAt(connList, c);
  2471. if (conn.receiver == ob && conn.method_() == k)
  2472. ++numchild;
  2473. }
  2474. }
  2475. d.putItem("numchild", numchild);
  2476. d.putItem("addr", d.data);
  2477. d.putItem("type", NS "QObjectSlot");
  2478. d.endHash();
  2479. }
  2480. }
  2481. #endif
  2482. d.endChildren();
  2483. }
  2484. d.disarm();
  2485. }
  2486. static void qDumpQObjectChildList(QDumper &d)
  2487. {
  2488. const QObject *ob = reinterpret_cast<const QObject *>(d.data);
  2489. const QObjectList children = ob->children();
  2490. const int size = children.size();
  2491. d.putItem("numchild", size);
  2492. d.putItemCount("value", size);
  2493. d.putItem("type", NS "QObjectChildList");
  2494. if (d.dumpChildren) {
  2495. d.beginChildren();
  2496. for (int i = 0; i != size; ++i) {
  2497. d.beginHash();
  2498. qDumpInnerValueHelper(d, NS "QObject *", children.at(i));
  2499. d.endHash();
  2500. }
  2501. d.endChildren();
  2502. }
  2503. d.disarm();
  2504. }
  2505. #endif // QT_BOOTSTRAPPED
  2506. #if USE_QT_GUI
  2507. static void qDumpQPixmap(QDumper &d)
  2508. {
  2509. const QPixmap &im = *reinterpret_cast<const QPixmap *>(d.data);
  2510. d.beginItem("value");
  2511. d.put("(").put(im.width()).put("x").put(im.height()).put(")");
  2512. d.endItem();
  2513. d.putItem("type", NS "QPixmap");
  2514. d.putItem("numchild", "0");
  2515. d.disarm();
  2516. }
  2517. #endif
  2518. #ifndef QT_BOOTSTRAPPED
  2519. static void qDumpQPoint(QDumper &d)
  2520. {
  2521. const QPoint &pnt = *reinterpret_cast<const QPoint *>(d.data);
  2522. d.beginItem("value");
  2523. d.put("(").put(pnt.x()).put(", ").put(pnt.y()).put(")");
  2524. d.endItem();
  2525. d.putItem("type", NS "QPoint");
  2526. d.putItem("numchild", "2");
  2527. if (d.dumpChildren) {
  2528. d.beginChildren();
  2529. d.putHash("x", pnt.x());
  2530. d.putHash("y", pnt.y());
  2531. d.endChildren();
  2532. }
  2533. d.disarm();
  2534. }
  2535. static void qDumpQPointF(QDumper &d)
  2536. {
  2537. const QPointF &pnt = *reinterpret_cast<const QPointF *>(d.data);
  2538. d.beginItem("value");
  2539. d.put("(").put(pnt.x()).put(", ").put(pnt.y()).put(")");
  2540. d.endItem();
  2541. d.putItem("type", NS "QPointF");
  2542. d.putItem("numchild", "2");
  2543. if (d.dumpChildren) {
  2544. d.beginChildren();
  2545. d.putHash("x", pnt.x());
  2546. d.putHash("y", pnt.y());
  2547. d.endChildren();
  2548. }
  2549. d.disarm();
  2550. }
  2551. static void qDumpQRect(QDumper &d)
  2552. {
  2553. const QRect &rc = *reinterpret_cast<const QRect *>(d.data);
  2554. d.beginItem("value");
  2555. d.put("(").put(rc.width()).put("x").put(rc.height());
  2556. if (rc.x() >= 0)
  2557. d.put("+");
  2558. d.put(rc.x());
  2559. if (rc.y() >= 0)
  2560. d.put("+");
  2561. d.put(rc.y());
  2562. d.put(")");
  2563. d.endItem();
  2564. d.putItem("type", NS "QRect");
  2565. d.putItem("numchild", "4");
  2566. if (d.dumpChildren) {
  2567. d.beginChildren();
  2568. d.putHash("x", rc.x());
  2569. d.putHash("y", rc.y());
  2570. d.putHash("width", rc.width());
  2571. d.putHash("height", rc.height());
  2572. d.endChildren();
  2573. }
  2574. d.disarm();
  2575. }
  2576. static void qDumpQRectF(QDumper &d)
  2577. {
  2578. const QRectF &rc = *reinterpret_cast<const QRectF *>(d.data);
  2579. d.beginItem("value");
  2580. d.put("(").put(rc.width()).put("x").put(rc.height());
  2581. if (rc.x() >= 0)
  2582. d.put("+");
  2583. d.put(rc.x());
  2584. if (rc.y() >= 0)
  2585. d.put("+");
  2586. d.put(rc.y());
  2587. d.put(")");
  2588. d.endItem();
  2589. d.putItem("type", NS "QRectF");
  2590. d.putItem("numchild", "4");
  2591. if (d.dumpChildren) {
  2592. d.beginChildren();
  2593. d.putHash("x", rc.x());
  2594. d.putHash("y", rc.y());
  2595. d.putHash("width", rc.width());
  2596. d.putHash("height", rc.height());
  2597. d.endChildren();
  2598. }
  2599. d.disarm();
  2600. }
  2601. #endif
  2602. static void qDumpQSet(QDumper &d)
  2603. {
  2604. // This uses the knowledge that QHash<T> has only a single member
  2605. // of union { QHashData *d; QHashNode<Key, T> *e; };
  2606. QHashData *hd = *(QHashData**)d.data;
  2607. QHashData::Node *node = hd->firstNode();
  2608. int n = hd->size;
  2609. if (n < 0)
  2610. return;
  2611. if (n > 0) {
  2612. qCheckAccess(node);
  2613. qCheckPointer(node->next);
  2614. }
  2615. d.putItemCount("value", n);
  2616. d.putItem("valueeditable", "false");
  2617. d.putItem("numchild", 2 * n);
  2618. if (d.dumpChildren) {
  2619. d.beginChildren();
  2620. int i = 0;
  2621. for (int bucket = 0; bucket != hd->numBuckets && i <= 10000; ++bucket) {
  2622. for (node = hd->buckets[bucket]; node->next; node = node->next) {
  2623. d.beginHash();
  2624. d.putItem("type", d.innerType);
  2625. d.beginItem("exp");
  2626. d.put("(('" NS "QHashNode<").put(d.innerType
  2627. ).put("," NS "QHashDummyValue>'*)"
  2628. ).put(static_cast<const void*>(node)).put(")->key");
  2629. d.endItem();
  2630. d.endHash();
  2631. ++i;
  2632. if (i > 10000) {
  2633. d.putEllipsis();
  2634. break;
  2635. }
  2636. }
  2637. }
  2638. d.endChildren();
  2639. }
  2640. d.disarm();
  2641. }
  2642. #ifndef QT_BOOTSTRAPPED
  2643. #if QT_VERSION >= 0x040500
  2644. static void qDumpQSharedPointer(QDumper &d)
  2645. {
  2646. const QSharedPointer<int> &ptr =
  2647. *reinterpret_cast<const QSharedPointer<int> *>(d.data);
  2648. if (ptr.isNull()) {
  2649. d.putItem("value", "<null>");
  2650. d.putItem("valueeditable", "false");
  2651. d.putItem("numchild", 0);
  2652. d.disarm();
  2653. return;
  2654. }
  2655. if (isSimpleType(d.innerType))
  2656. qDumpInnerValueHelper(d, d.innerType, ptr.data());
  2657. else
  2658. d.putItem("value", "");
  2659. d.putItem("valueeditable", "false");
  2660. d.putItem("numchild", 1);
  2661. if (d.dumpChildren) {
  2662. d.beginChildren();
  2663. d.beginHash();
  2664. d.putItem("name", "data");
  2665. qDumpInnerValue(d, d.innerType, ptr.data());
  2666. d.endHash();
  2667. const int v = sizeof(void *);
  2668. d.beginHash();
  2669. const void *weak = addOffset(deref(addOffset(d.data, v)), v);
  2670. d.putItem("name", "weakref");
  2671. d.putItem("value", *static_cast<const int *>(weak));
  2672. d.putItem("type", "int");
  2673. d.putItem("addr", weak);
  2674. d.putItem("numchild", "0");
  2675. d.endHash();
  2676. d.beginHash();
  2677. const void *strong = addOffset(weak, sizeof(int));
  2678. d.putItem("name", "strongref");
  2679. d.putItem("value", *static_cast<const int *>(strong));
  2680. d.putItem("type", "int");
  2681. d.putItem("addr", strong);
  2682. d.putItem("numchild", "0");
  2683. d.endHash();
  2684. d.endChildren();
  2685. }
  2686. d.disarm();
  2687. }
  2688. #endif // QT_VERSION >= 0x040500
  2689. #endif // QT_BOOTSTRAPPED
  2690. static void qDumpQSize(QDumper &d)
  2691. {
  2692. const QSize s = *reinterpret_cast<const QSize *>(d.data);
  2693. d.beginItem("value");
  2694. d.put("(").put(s.width()).put("x").put(s.height()).put(")");
  2695. d.endItem();
  2696. d.putItem("type", NS "QSize");
  2697. d.putItem("numchild", "2");
  2698. if (d.dumpChildren) {
  2699. d.beginChildren();
  2700. d.putHash("w", s.width());
  2701. d.putHash("h", s.height());
  2702. d.endChildren();
  2703. }
  2704. d.disarm();
  2705. }
  2706. static void qDumpQSizeF(QDumper &d)
  2707. {
  2708. const QSizeF s = *reinterpret_cast<const QSizeF *>(d.data);
  2709. d.beginItem("value");
  2710. d.put("(").put(s.width()).put("x").put(s.height()).put(")");
  2711. d.endItem();
  2712. d.putItem("type", NS "QSizeF");
  2713. d.putItem("numchild", "2");
  2714. if (d.dumpChildren) {
  2715. d.beginChildren();
  2716. d.putHash("w", s.width());
  2717. d.putHash("h", s.height());
  2718. d.endChildren();
  2719. }
  2720. d.disarm();
  2721. }
  2722. static void qDumpQString(QDumper &d)
  2723. {
  2724. //qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  2725. const QString &str = *reinterpret_cast<const QString *>(d.data);
  2726. const int size = str.size();
  2727. if (size < 0)
  2728. return;
  2729. if (size) {
  2730. const QChar *unicode = str.unicode();
  2731. qCheckAccess(unicode);
  2732. qCheckAccess(unicode + size);
  2733. if (!unicode[size].isNull()) // must be '\0' terminated
  2734. return;
  2735. }
  2736. d.putStringValue(str);
  2737. d.putItem("type", NS "QString");
  2738. //d.putItem("editvalue", str); // handled generically below
  2739. d.putItem("numchild", "0");
  2740. d.disarm();
  2741. }
  2742. static void qDumpQStringList(QDumper &d)
  2743. {
  2744. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  2745. const QStringList &list = *reinterpret_cast<const QStringList *>(d.data);
  2746. int n = list.size();
  2747. if (n < 0)
  2748. return;
  2749. if (n > 0) {
  2750. qCheckAccess(&list.front());
  2751. qCheckAccess(&list.back());
  2752. }
  2753. d.putItemCount("value", n);
  2754. d.putItem("valueeditable", "false");
  2755. d.putItem("numchild", n);
  2756. if (d.dumpChildren) {
  2757. if (n > 1000)
  2758. n = 1000;
  2759. d.beginChildren(n ? NS "QString" : 0);
  2760. for (int i = 0; i != n; ++i) {
  2761. d.beginHash();
  2762. d.putStringValue(list.at(i));
  2763. d.endHash();
  2764. }
  2765. if (n < list.size())
  2766. d.putEllipsis();
  2767. d.endChildren();
  2768. }
  2769. d.disarm();
  2770. }
  2771. static void qDumpQTextCodec(QDumper &d)
  2772. {
  2773. qCheckPointer(deref(d.data));
  2774. const QTextCodec &codec = *reinterpret_cast<const QTextCodec *>(d.data);
  2775. d.putItem("value", codec.name());
  2776. d.putItem("valueencoded", "1");
  2777. d.putItem("type", NS "QTextCodec");
  2778. d.putItem("numchild", "2");
  2779. if (d.dumpChildren) {
  2780. d.beginChildren();
  2781. d.putHash("name", codec.name());
  2782. d.putHash("mibEnum", codec.mibEnum());
  2783. d.endChildren();
  2784. }
  2785. d.disarm();
  2786. }
  2787. static void qDumpQVector(QDumper &d)
  2788. {
  2789. qCheckAccess(deref(d.data)); // is the d-ptr de-referenceable and valid
  2790. #if QT_VERSION >= 0x050000
  2791. QArrayData *v = *reinterpret_cast<QArrayData *const*>(d.data);
  2792. const unsigned typeddatasize = (char *)(&v->offset) - (char *)v;
  2793. #else
  2794. QVectorData *v = *reinterpret_cast<QVectorData *const*>(d.data);
  2795. QVectorTypedData<int> *dummy = 0;
  2796. const unsigned typeddatasize = (char*)(&dummy->array) - (char*)dummy;
  2797. #endif
  2798. // Try to provoke segfaults early to prevent the frontend
  2799. // from asking for unavailable child details
  2800. int nn = v->size;
  2801. if (nn < 0)
  2802. return;
  2803. const bool innerIsPointerType = isPointerType(d.innerType);
  2804. const unsigned innersize = d.extraInt[0];
  2805. const int n = qMin(nn, 1000);
  2806. // Check pointers
  2807. if (innerIsPointerType && nn > 0)
  2808. for (int i = 0; i != n; ++i)
  2809. if (const void *p = addOffset(v, i * innersize + typeddatasize))
  2810. qCheckPointer(deref(p));
  2811. d.putItemCount("value", nn);
  2812. d.putItem("valueeditable", "false");
  2813. d.putItem("numchild", nn);
  2814. if (d.dumpChildren) {
  2815. QByteArray strippedInnerType = stripPointerType(d.innerType);
  2816. const char *stripped = innerIsPointerType ? strippedInnerType.data() : 0;
  2817. d.beginChildren(d.innerType);
  2818. for (int i = 0; i != n; ++i) {
  2819. d.beginHash();
  2820. qDumpInnerValueOrPointer(d, d.innerType, stripped,
  2821. addOffset(v, i * innersize + typeddatasize));
  2822. d.endHash();
  2823. }
  2824. if (n < nn)
  2825. d.putEllipsis();
  2826. d.endChildren();
  2827. }
  2828. d.disarm();
  2829. }
  2830. #ifndef QT_BOOTSTRAPPED
  2831. #if QT_VERSION >= 0x040500
  2832. static void qDumpQWeakPointer(QDumper &d)
  2833. {
  2834. const int v = sizeof(void *);
  2835. const void *value = deref(addOffset(d.data, v));
  2836. const void *data = deref(d.data);
  2837. if (value == 0 || data == 0) {
  2838. d.putItem("value", "<null>");
  2839. d.putItem("valueeditable", "false");
  2840. d.putItem("numchild", 0);
  2841. d.disarm();
  2842. return;
  2843. }
  2844. if (isSimpleType(d.innerType))
  2845. qDumpInnerValueHelper(d, d.innerType, value);
  2846. else
  2847. d.putItem("value", "");
  2848. d.putItem("valueeditable", "false");
  2849. d.putItem("numchild", 1);
  2850. if (d.dumpChildren) {
  2851. d.beginChildren();
  2852. d.beginHash();
  2853. d.putItem("name", "data");
  2854. qDumpInnerValue(d, d.innerType, value);
  2855. d.endHash();
  2856. d.beginHash();
  2857. const void *weak = addOffset(deref(d.data), v);
  2858. d.putItem("name", "weakref");
  2859. d.putItem("value", *static_cast<const int *>(weak));
  2860. d.putItem("type", "int");
  2861. d.putItem("addr", weak);
  2862. d.putItem("numchild", "0");
  2863. d.endHash();
  2864. d.beginHash();
  2865. const void *strong = addOffset(weak, sizeof(int));
  2866. d.putItem("name", "strongref");
  2867. d.putItem("value", *static_cast<const int *>(strong));
  2868. d.putItem("type", "int");
  2869. d.putItem("addr", strong);
  2870. d.putItem("numchild", "0");
  2871. d.endHash();
  2872. d.endChildren();
  2873. }
  2874. d.disarm();
  2875. }
  2876. #endif // QT_VERSION >= 0x040500
  2877. #endif // QT_BOOTSTRAPPED
  2878. #endif // QT_CORE
  2879. static void qDumpStdList(QDumper &d)
  2880. {
  2881. const std::list<int> &list = *reinterpret_cast<const std::list<int> *>(d.data);
  2882. const void *p = d.data;
  2883. qCheckAccess(p);
  2884. p = deref(p);
  2885. qCheckAccess(p);
  2886. p = deref(p);
  2887. qCheckAccess(p);
  2888. p = deref(addOffset(d.data, sizeof(void*)));
  2889. qCheckAccess(p);
  2890. p = deref(addOffset(p, sizeof(void*)));
  2891. qCheckAccess(p);
  2892. p = deref(addOffset(p, sizeof(void*)));
  2893. qCheckAccess(p);
  2894. std::list<int>::size_type nn = 0;
  2895. const std::list<int>::size_type maxItems = 100;
  2896. std::list<int>::const_iterator it = list.begin();
  2897. const std::list<int>::const_iterator cend = list.end();
  2898. for (; nn < maxItems && it != cend; ++nn, ++it)
  2899. qCheckAccess(it.operator->());
  2900. if (it != cend) {
  2901. d.putTruncatedItemCount("value", nn);
  2902. } else {
  2903. d.putItemCount("value", nn);
  2904. }
  2905. d.putItem("numchild", nn);
  2906. d.putItem("valueeditable", "false");
  2907. if (d.dumpChildren) {
  2908. QByteArray strippedInnerType = stripPointerType(d.innerType);
  2909. const char *stripped =
  2910. isPointerType(d.innerType) ? strippedInnerType.data() : 0;
  2911. d.beginChildren(d.innerType);
  2912. it = list.begin();
  2913. for (std::list<int>::size_type i = 0; i < maxItems && it != cend; ++i, ++it) {
  2914. d.beginHash();
  2915. qDumpInnerValueOrPointer(d, d.innerType, stripped, it.operator->());
  2916. d.endHash();
  2917. }
  2918. if (it != list.end())
  2919. d.putEllipsis();
  2920. d.endChildren();
  2921. }
  2922. d.disarm();
  2923. }
  2924. /* Dump out an arbitrary map. To iterate the map,
  2925. * it is cast to a map of <KeyType,Value>. 'int' can be used for both
  2926. * for all types if the implementation does not depend on the types
  2927. * which is the case for GNU STL. The implementation used by MS VC, however,
  2928. * does depend on the key/value type, so, special cases need to be hardcoded. */
  2929. template <class KeyType, class ValueType>
  2930. static void qDumpStdMapHelper(QDumper &d)
  2931. {
  2932. typedef std::map<KeyType, ValueType> DummyType;
  2933. const DummyType &map = *reinterpret_cast<const DummyType*>(d.data);
  2934. const char *keyType = d.templateParameters[0];
  2935. const char *valueType = d.templateParameters[1];
  2936. const void *p = d.data;
  2937. qCheckAccess(p);
  2938. const int nn = map.size();
  2939. if (nn < 0)
  2940. return;
  2941. typename DummyType::const_iterator it = map.begin();
  2942. const typename DummyType::const_iterator cend = map.end();
  2943. for (int i = 0; i < nn && i < 10 && it != cend; ++i, ++it)
  2944. qCheckAccess(it.operator->());
  2945. d.putItem("numchild", nn);
  2946. d.putItemCount("value", nn);
  2947. d.putItem("valueeditable", "false");
  2948. d.putItem("valueoffset", d.extraInt[2]);
  2949. // HACK: we need a properly const qualified version of the
  2950. // std::pair used. We extract it from the allocator parameter
  2951. // (#4, "std::allocator<std::pair<key, value> >")
  2952. // as it is there, and, equally importantly, in an order that
  2953. // gdb accepts when fed with it.
  2954. char *pairType = (char *)(d.templateParameters[3]) + 15;
  2955. pairType[strlen(pairType) - 2] = 0;
  2956. d.putItem("pairtype", pairType);
  2957. if (d.dumpChildren) {
  2958. bool isSimpleKey = isSimpleType(keyType);
  2959. bool isSimpleValue = isSimpleType(valueType);
  2960. int valueOffset = d.extraInt[2];
  2961. d.beginItem("extra");
  2962. d.put("isSimpleKey: ").put(isSimpleKey);
  2963. d.put(" isSimpleValue: ").put(isSimpleValue);
  2964. d.put(" valueType: '").put(valueType);
  2965. d.put(" valueOffset: ").put(valueOffset);
  2966. d.endItem();
  2967. d.beginChildren(d.innerType);
  2968. it = map.begin();
  2969. for (int i = 0; i < 1000 && it != cend; ++i, ++it) {
  2970. d.beginHash();
  2971. const void *node = it.operator->();
  2972. qDumpInnerValueHelper(d, keyType, node, "key");
  2973. qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
  2974. if (isSimpleKey && isSimpleValue) {
  2975. d.putItem("type", valueType);
  2976. d.putItem("addr", addOffset(node, valueOffset));
  2977. d.putItem("numchild", 0);
  2978. } else {
  2979. d.putItem("addr", node);
  2980. d.putItem("type", pairType);
  2981. d.putItem("numchild", 2);
  2982. }
  2983. d.endHash();
  2984. }
  2985. if (it != map.end())
  2986. d.putEllipsis();
  2987. d.endChildren();
  2988. }
  2989. d.disarm();
  2990. }
  2991. static void qDumpStdMap(QDumper &d)
  2992. {
  2993. qDumpStdMapHelper<int,int>(d);
  2994. }
  2995. /* Dump out an arbitrary set. To iterate the set,
  2996. * it is cast to a set of <KeyType>. 'int' can be used
  2997. * for all types if the implementation does not depend on the key type
  2998. * which is the case for GNU STL. The implementation used by MS VC, however,
  2999. * does depend on the key type, so, special cases need to be hardcoded. */
  3000. template <class KeyType>
  3001. static void qDumpStdSetHelper(QDumper &d)
  3002. {
  3003. typedef std::set<KeyType> DummyType;
  3004. const DummyType &set = *reinterpret_cast<const DummyType*>(d.data);
  3005. const void *p = d.data;
  3006. qCheckAccess(p);
  3007. const int nn = set.size();
  3008. if (nn < 0)
  3009. return;
  3010. typename DummyType::const_iterator it = set.begin();
  3011. const typename DummyType::const_iterator cend = set.end();
  3012. for (int i = 0; i < nn && i < 10 && it != cend; ++i, ++it)
  3013. qCheckAccess(it.operator->());
  3014. d.putItemCount("value", nn);
  3015. d.putItem("valueeditable", "false");
  3016. d.putItem("numchild", nn);
  3017. d.putItem("valueoffset", d.extraInt[0]);
  3018. if (d.dumpChildren) {
  3019. int valueOffset = 0; // d.extraInt[0];
  3020. QByteArray strippedInnerType = stripPointerType(d.innerType);
  3021. const char *stripped =
  3022. isPointerType(d.innerType) ? strippedInnerType.data() : 0;
  3023. d.beginItem("extra");
  3024. d.put("valueOffset: ").put(valueOffset);
  3025. d.endItem();
  3026. d.beginChildren(d.innerType);
  3027. it = set.begin();
  3028. for (int i = 0; i < 1000 && it != cend; ++i, ++it) {
  3029. const void *node = it.operator->();
  3030. d.beginHash();
  3031. qDumpInnerValueOrPointer(d, d.innerType, stripped, node);
  3032. d.endHash();
  3033. }
  3034. if (it != set.end())
  3035. d.putEllipsis();
  3036. d.endChildren();
  3037. }
  3038. d.disarm();
  3039. }
  3040. static void qDumpStdSet(QDumper &d)
  3041. {
  3042. qDumpStdSetHelper<int>(d);
  3043. }
  3044. static void qDumpStdString(QDumper &d)
  3045. {
  3046. const std::string &str = *reinterpret_cast<const std::string *>(d.data);
  3047. const std::string::size_type size = str.size();
  3048. if (int(size) < 0)
  3049. return;
  3050. if (size) {
  3051. qCheckAccess(str.c_str());
  3052. qCheckAccess(str.c_str() + size - 1);
  3053. }
  3054. qDumpStdStringValue(d, str);
  3055. d.disarm();
  3056. }
  3057. static void qDumpStdWString(QDumper &d)
  3058. {
  3059. const std::wstring &str = *reinterpret_cast<const std::wstring *>(d.data);
  3060. const std::wstring::size_type size = str.size();
  3061. if (int(size) < 0)
  3062. return;
  3063. if (size) {
  3064. qCheckAccess(str.c_str());
  3065. qCheckAccess(str.c_str() + size - 1);
  3066. }
  3067. qDumpStdWStringValue(d, str);
  3068. d.disarm();
  3069. }
  3070. static void qDumpStdVector(QDumper &d)
  3071. {
  3072. // Correct type would be something like:
  3073. // std::_Vector_base<int,std::allocator<int, std::allocator<int> >>::_Vector_impl
  3074. struct VectorImpl {
  3075. char *start;
  3076. char *finish;
  3077. char *end_of_storage;
  3078. };
  3079. const VectorImpl *v = static_cast<const VectorImpl *>(d.data);
  3080. // Try to provoke segfaults early to prevent the frontend
  3081. // from asking for unavailable child details
  3082. int nn = (v->finish - v->start) / d.extraInt[0];
  3083. if (nn < 0)
  3084. return;
  3085. if (nn > 0) {
  3086. qCheckAccess(v->start);
  3087. qCheckAccess(v->finish);
  3088. qCheckAccess(v->end_of_storage);
  3089. }
  3090. int n = nn;
  3091. d.putItemCount("value", n);
  3092. d.putItem("valueeditable", "false");
  3093. d.putItem("numchild", n);
  3094. if (d.dumpChildren) {
  3095. unsigned innersize = d.extraInt[0];
  3096. QByteArray strippedInnerType = stripPointerType(d.innerType);
  3097. const char *stripped =
  3098. isPointerType(d.innerType) ? strippedInnerType.data() : 0;
  3099. if (n > 1000)
  3100. n = 1000;
  3101. d.beginChildren(n ? d.innerType : 0);
  3102. for (int i = 0; i != n; ++i) {
  3103. d.beginHash();
  3104. qDumpInnerValueOrPointer(d, d.innerType, stripped,
  3105. addOffset(v->start, i * innersize));
  3106. d.endHash();
  3107. }
  3108. if (n < nn)
  3109. d.putEllipsis();
  3110. d.endChildren();
  3111. }
  3112. d.disarm();
  3113. }
  3114. static void qDumpStdVectorBool(QDumper &d)
  3115. {
  3116. // FIXME
  3117. return qDumpStdVector(d);
  3118. }
  3119. static void handleProtocolVersion2and3(QDumper &d)
  3120. {
  3121. if (!d.outerType[0]) {
  3122. qDumpUnknown(d);
  3123. return;
  3124. }
  3125. d.setupTemplateParameters();
  3126. d.putItem("iname", d.iname);
  3127. if (d.data)
  3128. d.putItem("addr", d.data);
  3129. #ifdef QT_NO_QDATASTREAM
  3130. if (d.protocolVersion == 3) {
  3131. QVariant::Type type = QVariant::nameToType(d.outerType);
  3132. if (type != QVariant::Invalid) {
  3133. QVariant v(type, d.data);
  3134. QByteArray ba;
  3135. QDataStream ds(&ba, QIODevice::WriteOnly);
  3136. ds << v;
  3137. d.putItem("editvalue", ba);
  3138. }
  3139. }
  3140. #endif
  3141. const char *type = stripNamespace(d.outerType);
  3142. // type[0] is usually 'Q', so don't use it
  3143. switch (type[1]) {
  3144. case 'a':
  3145. if (isEqual(type, "map"))
  3146. qDumpStdMap(d);
  3147. break;
  3148. case 'e':
  3149. if (isEqual(type, "vector"))
  3150. qDumpStdVector(d);
  3151. else if (isEqual(type, "set"))
  3152. qDumpStdSet(d);
  3153. break;
  3154. case 'i':
  3155. if (isEqual(type, "list"))
  3156. qDumpStdList(d);
  3157. break;
  3158. case 's':
  3159. if (isEqual(type, "wstring"))
  3160. qDumpStdWString(d);
  3161. break;
  3162. case 't':
  3163. if (isEqual(type, "std::vector"))
  3164. qDumpStdVector(d);
  3165. else if (isEqual(type, "std::vector::bool"))
  3166. qDumpStdVectorBool(d);
  3167. else if (isEqual(type, "std::list"))
  3168. qDumpStdList(d);
  3169. else if (isEqual(type, "std::map"))
  3170. qDumpStdMap(d);
  3171. else if (isEqual(type, "std::set"))
  3172. qDumpStdSet(d);
  3173. else if (isEqual(type, "std::string") || isEqual(type, "string"))
  3174. qDumpStdString(d);
  3175. else if (isEqual(type, "std::wstring"))
  3176. qDumpStdWString(d);
  3177. break;
  3178. #if USE_QT_CORE
  3179. case 'A':
  3180. # ifndef QT_BOOTSTRAPPED
  3181. if (isEqual(type, "QAbstractItemModel"))
  3182. qDumpQAbstractItemModel(d);
  3183. else if (isEqual(type, "QAbstractItem"))
  3184. qDumpQAbstractItem(d);
  3185. # endif
  3186. break;
  3187. case 'B':
  3188. if (isEqual(type, "QByteArray"))
  3189. qDumpQByteArray(d);
  3190. break;
  3191. case 'C':
  3192. if (isEqual(type, "QChar"))
  3193. qDumpQChar(d);
  3194. break;
  3195. case 'D':
  3196. if (isEqual(type, "QDate"))
  3197. qDumpQDate(d);
  3198. else if (isEqual(type, "QDateTime"))
  3199. qDumpQDateTime(d);
  3200. else if (isEqual(type, "QDir"))
  3201. qDumpQDir(d);
  3202. break;
  3203. case 'F':
  3204. # ifndef QT_BOOTSTRAPPED
  3205. if (isEqual(type, "QFile"))
  3206. qDumpQFile(d);
  3207. else if (isEqual(type, "QFileInfo"))
  3208. qDumpQFileInfo(d);
  3209. # endif
  3210. break;
  3211. case 'H':
  3212. if (isEqual(type, "QHash"))
  3213. qDumpQHash(d);
  3214. else if (isEqual(type, "QHashNode"))
  3215. qDumpQHashNode(d);
  3216. break;
  3217. case 'I':
  3218. # if USE_QT_GUI
  3219. if (isEqual(type, "QImage"))
  3220. qDumpQImage(d);
  3221. else if (isEqual(type, "QImageData"))
  3222. qDumpQImageData(d);
  3223. # endif
  3224. break;
  3225. case 'L':
  3226. # ifndef QT_BOOTSTRAPPED
  3227. if (isEqual(type, "QList"))
  3228. qDumpQList(d);
  3229. else if (isEqual(type, "QLinkedList"))
  3230. qDumpQLinkedList(d);
  3231. else if (isEqual(type, "QLocale"))
  3232. qDumpQLocale(d);
  3233. # endif
  3234. break;
  3235. case 'M':
  3236. # ifndef QT_BOOTSTRAPPED
  3237. if (isEqual(type, "QModelIndex"))
  3238. qDumpQModelIndex(d);
  3239. # if MAP_WORKS
  3240. else if (isEqual(type, "QMap"))
  3241. qDumpQMap(d);
  3242. else if (isEqual(type, "QMapNode"))
  3243. qDumpQMapNode(d);
  3244. else if (isEqual(type, "QMultiMap"))
  3245. qDumpQMultiMap(d);
  3246. # endif
  3247. # endif
  3248. break;
  3249. case 'O':
  3250. # ifndef QT_BOOTSTRAPPED
  3251. if (isEqual(type, "QObject"))
  3252. qDumpQObject(d);
  3253. else if (isEqual(type, "QObjectPropertyList"))
  3254. qDumpQObjectPropertyList(d);
  3255. else if (isEqual(type, "QObjectProperty"))
  3256. qDumpQObjectProperty(d);
  3257. else if (isEqual(type, "QObjectMethodList"))
  3258. qDumpQObjectMethodList(d);
  3259. else if (isEqual(type, "QObjectSignalList"))
  3260. qDumpQObjectSignalList(d);
  3261. else if (isEqual(type, "QObjectSignal"))
  3262. qDumpQObjectSignal(d);
  3263. else if (isEqual(type, "QObjectSlot"))
  3264. qDumpQObjectSlot(d);
  3265. else if (isEqual(type, "QObjectSlotList"))
  3266. qDumpQObjectSlotList(d);
  3267. else if (isEqual(type, "QObjectChildList"))
  3268. qDumpQObjectChildList(d);
  3269. # endif
  3270. break;
  3271. case 'P':
  3272. # if USE_QT_GUI
  3273. if (isEqual(type, "QPixmap"))
  3274. qDumpQPixmap(d);
  3275. # endif
  3276. # ifndef QT_BOOTSTRAPPED
  3277. if (isEqual(type, "QPoint"))
  3278. qDumpQPoint(d);
  3279. else if (isEqual(type, "QPointF"))
  3280. qDumpQPointF(d);
  3281. # endif
  3282. break;
  3283. case 'R':
  3284. # ifndef QT_BOOTSTRAPPED
  3285. if (isEqual(type, "QRect"))
  3286. qDumpQRect(d);
  3287. else if (isEqual(type, "QRectF"))
  3288. qDumpQRectF(d);
  3289. # endif
  3290. break;
  3291. case 'S':
  3292. if (isEqual(type, "QString"))
  3293. qDumpQString(d);
  3294. else if (isEqual(type, "QStringList"))
  3295. qDumpQStringList(d);
  3296. # ifndef QT_BOOTSTRAPPED
  3297. else if (isEqual(type, "QSet"))
  3298. qDumpQSet(d);
  3299. else if (isEqual(type, "QStack"))
  3300. qDumpQVector(d);
  3301. # if QT_VERSION >= 0x040500
  3302. else if (isEqual(type, "QSharedPointer"))
  3303. qDumpQSharedPointer(d);
  3304. # endif
  3305. # endif // QT_BOOTSTRAPPED
  3306. else if (isEqual(type, "QSize"))
  3307. qDumpQSize(d);
  3308. else if (isEqual(type, "QSizeF"))
  3309. qDumpQSizeF(d);
  3310. break;
  3311. case 'T':
  3312. # ifndef QT_BOOTSTRAPPED
  3313. if (isEqual(type, "QTextCodec"))
  3314. qDumpQTextCodec(d);
  3315. # endif
  3316. if (isEqual(type, "QTime"))
  3317. qDumpQTime(d);
  3318. break;
  3319. case 'V':
  3320. # ifndef QT_BOOTSTRAPPED
  3321. if (isEqual(type, "QVariantList")) { // resolve typedef
  3322. d.outerType = "QList";
  3323. d.innerType = "QVariant";
  3324. d.extraInt[0] = sizeof(QVariant);
  3325. qDumpQList(d);
  3326. } else if (isEqual(type, "QVariant")) {
  3327. qDumpQVariant(d);
  3328. } else if (isEqual(type, "QVector")) {
  3329. qDumpQVector(d);
  3330. }
  3331. # endif
  3332. break;
  3333. case 'W':
  3334. # ifndef QT_BOOTSTRAPPED
  3335. # if QT_VERSION >= 0x040500
  3336. if (isEqual(type, "QWeakPointer"))
  3337. qDumpQWeakPointer(d);
  3338. # endif
  3339. # endif
  3340. break;
  3341. #endif
  3342. }
  3343. if (!d.success)
  3344. qDumpUnknown(d);
  3345. }
  3346. } // anonymous namespace
  3347. #if USE_QT_GUI
  3348. extern "C" Q_DECL_EXPORT
  3349. void *watchPoint(int x, int y)
  3350. {
  3351. return QApplication::widgetAt(x, y);
  3352. }
  3353. #endif
  3354. extern "C" Q_DECL_EXPORT
  3355. void *qDumpObjectData440(
  3356. int protocolVersion,
  3357. int token,
  3358. const void *data,
  3359. int dumpChildren,
  3360. int extraInt0,
  3361. int extraInt1,
  3362. int extraInt2,
  3363. int extraInt3)
  3364. {
  3365. //sleep(20);
  3366. if (protocolVersion == 1) {
  3367. QDumper d;
  3368. d.protocolVersion = protocolVersion;
  3369. d.token = token;
  3370. // This is a list of all available dumpers. Note that some templates
  3371. // currently require special hardcoded handling in the debugger plugin.
  3372. // They are mentioned here nevertheless. For types that are not listed
  3373. // here, dumpers won't be used.
  3374. d.put("dumpers=["
  3375. "\"" NS "QAbstractItem\","
  3376. "\"" NS "QAbstractItemModel\","
  3377. "\"" NS "QByteArray\","
  3378. "\"" NS "QChar\","
  3379. "\"" NS "QDate\","
  3380. "\"" NS "QDateTime\","
  3381. "\"" NS "QDir\","
  3382. "\"" NS "QFile\","
  3383. "\"" NS "QFileInfo\","
  3384. "\"" NS "QHash\","
  3385. "\"" NS "QHashNode\","
  3386. "\"" NS "QImage\","
  3387. //"\"" NS "QImageData\","
  3388. "\"" NS "QLinkedList\","
  3389. "\"" NS "QList\","
  3390. "\"" NS "QLocale\","
  3391. #if MAP_WORKS
  3392. "\"" NS "QMap\","
  3393. "\"" NS "QMapNode\","
  3394. #endif
  3395. "\"" NS "QModelIndex\","
  3396. "\"" NS "QObject\","
  3397. "\"" NS "QObjectMethodList\"," // hack to get nested properties display
  3398. "\"" NS "QObjectProperty\","
  3399. "\"" NS "QObjectPropertyList\","
  3400. "\"" NS "QObjectSignal\","
  3401. "\"" NS "QObjectSignalList\","
  3402. "\"" NS "QObjectSlot\","
  3403. "\"" NS "QObjectSlotList\","
  3404. "\"" NS "QObjectChildList\","
  3405. "\"" NS "QPoint\","
  3406. "\"" NS "QPointF\","
  3407. "\"" NS "QRect\","
  3408. "\"" NS "QRectF\","
  3409. //"\"" NS "QRegion\","
  3410. "\"" NS "QSet\","
  3411. "\"" NS "QSize\","
  3412. "\"" NS "QSizeF\","
  3413. "\"" NS "QStack\","
  3414. "\"" NS "QString\","
  3415. "\"" NS "QStringList\","
  3416. "\"" NS "QTextCodec\","
  3417. "\"" NS "QTime\","
  3418. "\"" NS "QVariant\","
  3419. "\"" NS "QVariantList\","
  3420. "\"" NS "QVector\","
  3421. #if QT_VERSION >= 0x040500
  3422. #if MAP_WORKS
  3423. "\"" NS "QMultiMap\","
  3424. #endif
  3425. "\"" NS "QSharedPointer\","
  3426. "\"" NS "QWeakPointer\","
  3427. #endif
  3428. #if USE_QT_GUI
  3429. "\"" NS "QPixmap\","
  3430. "\"" NS "QWidget\","
  3431. #endif
  3432. #ifdef Q_OS_WIN
  3433. "\"basic_string\","
  3434. "\"list\","
  3435. "\"map\","
  3436. "\"set\","
  3437. "\"vector\","
  3438. #endif
  3439. "\"string\","
  3440. "\"wstring\","
  3441. "\"std::basic_string\","
  3442. "\"std::list\","
  3443. "\"std::map\","
  3444. "\"std::set\","
  3445. "\"std::string\","
  3446. "\"std::vector\","
  3447. "\"std::wstring\","
  3448. "]");
  3449. d.put(",qtversion=["
  3450. "\"").put(((QT_VERSION >> 16) & 255)).put("\","
  3451. "\"").put(((QT_VERSION >> 8) & 255)).put("\","
  3452. "\"").put(((QT_VERSION) & 255)).put("\"]");
  3453. d.put(",namespace=\"" NS "\",");
  3454. d.put("dumperversion=\"1.3\",");
  3455. d.disarm();
  3456. }
  3457. else if (protocolVersion == 2 || protocolVersion == 3) {
  3458. QDumper d;
  3459. d.protocolVersion = protocolVersion;
  3460. d.token = token;
  3461. d.data = data;
  3462. d.dumpChildren = dumpChildren;
  3463. d.extraInt[0] = extraInt0;
  3464. d.extraInt[1] = extraInt1;
  3465. d.extraInt[2] = extraInt2;
  3466. d.extraInt[3] = extraInt3;
  3467. const char *inbuffer = inBuffer;
  3468. d.outerType = inbuffer; while (*inbuffer) ++inbuffer; ++inbuffer;
  3469. d.iname = inbuffer; while (*inbuffer) ++inbuffer; ++inbuffer;
  3470. d.exp = inbuffer; while (*inbuffer) ++inbuffer; ++inbuffer;
  3471. d.innerType = inbuffer; while (*inbuffer) ++inbuffer; ++inbuffer;
  3472. d.iname = inbuffer; while (*inbuffer) ++inbuffer; ++inbuffer;
  3473. #if 0
  3474. qDebug() << "data=" << d.data << "dumpChildren=" << d.dumpChildren
  3475. << " extra=" << d.extraInt[0] << d.extraInt[1] << d.extraInt[2] << d.extraInt[3]
  3476. << d.outerType << d.iname << d.exp << d.iname;
  3477. #endif
  3478. handleProtocolVersion2and3(d);
  3479. }
  3480. else {
  3481. #if USE_QT_CORE
  3482. # ifndef QT_BOOTSTRAPPED
  3483. qDebug() << "Unsupported protocol version" << protocolVersion;
  3484. # endif
  3485. #endif
  3486. }
  3487. return outBuffer;
  3488. }