From 158e5ee82cd340149eee9ba8a9355f416285bfa4 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Wed, 13 May 2009 16:11:25 +0200
Subject: [PATCH] debugger: refactoring of the QObject dumper

signal lists still broken for 4.6
---
 share/qtcreator/gdbmacros/gdbmacros.cpp | 124 ++++++++++++------------
 1 file changed, 60 insertions(+), 64 deletions(-)

diff --git a/share/qtcreator/gdbmacros/gdbmacros.cpp b/share/qtcreator/gdbmacros/gdbmacros.cpp
index 809263c95c8..1778edad463 100644
--- a/share/qtcreator/gdbmacros/gdbmacros.cpp
+++ b/share/qtcreator/gdbmacros/gdbmacros.cpp
@@ -29,9 +29,6 @@
 
 #include <qglobal.h>
 
-// this relies on contents copied from qobject_p.h
-#define PRIVATE_OBJECT_ALLOWED 1
-
 #include <QtCore/QDateTime>
 #include <QtCore/QDebug>
 #include <QtCore/QDir>
@@ -146,68 +143,76 @@ int qtGhVersion = QT_VERSION;
 #   define NSY ""
 #endif
 
-#if PRIVATE_OBJECT_ALLOWED
-
 #if defined(QT_BEGIN_NAMESPACE)
 QT_BEGIN_NAMESPACE
 #endif
 
-class QVariant;
-class QThreadData;
-class QObjectConnectionListVector;
-
-class QObjectPrivate : public QObjectData
-{
-    Q_DECLARE_PUBLIC(QObject)
+struct Sender { QObject *sender; int signal; int ref; };
 
-public:
-    QObjectPrivate() {}
-    virtual ~QObjectPrivate() {}
+#if QT_VERSION < 0x040600
+    struct Connection
+    {
+        QObject *receiver;
+        int method;
+        uint connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking
+        QBasicAtomicPointer<int> argumentTypes;
+    };
 
-    // preserve binary compatibility with code compiled without Qt 3 support
-    QList<QObject *> pendingChildInsertedEvents; // unused
+    typedef QList<Connection> ConnectionList;
+    typedef QList<Sender> SenderList;
 
-    // id of the thread that owns the object
-    QThreadData *threadData;
+    const Connection &connectionAt(const ConnectionList &l, int i) { return l.at(i); }
+    const QObject *senderAt(const SenderList &l, int i) { return l.at(i).sender; }
+    int signalAt(const SenderList &l, int i) { return l.at(i).signal; }
+#endif
 
-    struct Sender
+#if QT_VERSION >= 0x040600
+    struct Connection
     {
         QObject *sender;
-        int signal;
-        int ref;
+        QObject *receiver;
+        int method;
+        uint connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking
+        QBasicAtomicPointer<int> argumentTypes;
     };
 
-    Sender *currentSender; // object currently activating the object
-    QObject *currentChildBeingDeleted;
+    typedef QList<Connection *> ConnectionList;
+    typedef ConnectionList SenderList;
+
+    const Connection &connectionAt(const ConnectionList &l, int i) { return *l.at(i); }
+    const QObject *senderAt(const SenderList &l, int i) { return l.at(i)->sender; }
+    // FIXME: 'method' is wrong
+    int signalAt(const SenderList &l, int i) { return l.at(i)->method; }
+#endif
+
+class QObjectPrivate : public QObjectData
+{
+public:
+    QObjectPrivate() {}
+    virtual ~QObjectPrivate() {}
+
+    QList<QObject *> pendingChildInsertedEvents;
+    void *threadData;
+    void *currentSender;
+    void *currentChildBeingDeleted;
 
     QList<QPointer<QObject> > eventFilters;
 
-    struct ExtraData;
-    ExtraData *extraData;
+    void *extraData;
     mutable quint32 connectedSignals;
 
     QString objectName;
 
-    struct Connection
-    {
-        QObject *receiver;
-        int method;
-        uint connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking
-        QBasicAtomicPointer<int> argumentTypes;
-    };
-    typedef QList<Connection> ConnectionList;
-
-    QObjectConnectionListVector *connectionLists;
-    QList<Sender> senders;
+    void *connectionLists;
+    SenderList senders;
     int *deleteWatch;
 };
 
+
 #if defined(QT_BEGIN_NAMESPACE)
 QT_END_NAMESPACE
 #endif
 
-#endif // PRIVATE_OBJECT_ALLOWED
-
 
 // This can be mangled typenames of nested templates, each char-by-char
 // comma-separated integer list...
@@ -1584,7 +1589,6 @@ static void qDumpQObject(QDumper &d)
             P(d, "type", NS"QList<"NS"QObjectPrivateSender>");
         d.endHash();
 #endif
-#if PRIVATE_OBJECT_ALLOWED
         d.beginHash();
             P(d, "name", "signals");
             P(d, "exp", "*(class '"NS"QObject'*)" << d.data);
@@ -1599,7 +1603,6 @@ static void qDumpQObject(QDumper &d)
             P(d, "value", "<" << slotCount << " items>");
             P(d, "numchild", slotCount);
         d.endHash();
-#endif
         if (childrenOffset) {
             d.beginHash();
             P(d, "name", "children");
@@ -1692,7 +1695,6 @@ static void qDumpQObjectMethodList(QDumper &d)
     d.disarm();
 }
 
-#if PRIVATE_OBJECT_ALLOWED
 const char * qConnectionTypes[] ={
     "auto",
     "direct",
@@ -1702,13 +1704,13 @@ const char * qConnectionTypes[] ={
 };
 
 #if QT_VERSION >= 0x040400
-static const QObjectPrivate::ConnectionList &qConnectionList(const QObject *ob, int signalNumber)
+static const ConnectionList &qConnectionList(const QObject *ob, int signalNumber)
 {
-    static const QObjectPrivate::ConnectionList emptyList;
+    static const ConnectionList emptyList;
     const QObjectPrivate *p = reinterpret_cast<const QObjectPrivate *>(dfunc(ob));
     if (!p->connectionLists)
         return emptyList;
-    typedef QVector<QObjectPrivate::ConnectionList> ConnLists;
+    typedef QVector<ConnectionList> ConnLists;
     const ConnLists *lists = reinterpret_cast<const ConnLists *>(p->connectionLists);
     // there's an optimization making the lists only large enough to hold the
     // last non-empty item
@@ -1730,9 +1732,9 @@ static void qDumpQObjectSignal(QDumper &d)
     if (d.dumpChildren) {
         const QObject *ob = reinterpret_cast<const QObject *>(d.data);
         d << ",children=[";
-        const QObjectPrivate::ConnectionList &connList = qConnectionList(ob, signalNumber);
+        const ConnectionList &connList = qConnectionList(ob, signalNumber);
         for (int i = 0; i != connList.size(); ++i) {
-            const QObjectPrivate::Connection &conn = connList.at(i);
+            const Connection &conn = connectionAt(connList, i);
             d.beginHash();
                 P(d, "name", i << " receiver");
                 qDumpInnerValueHelper(d, NS"QObject *", conn.receiver);
@@ -1776,7 +1778,7 @@ static void qDumpQObjectSignalList(QDumper &d)
             const QMetaMethod & method = mo->method(i);
             if (method.methodType() == QMetaMethod::Signal) {
                 int k = mo->indexOfSignal(method.signature());
-                const QObjectPrivate::ConnectionList &connList = qConnectionList(ob, k);
+                const ConnectionList &connList = qConnectionList(ob, k);
                 d.beginHash();
                 P(d, "name", k);
                 P(d, "value", method.signature());
@@ -1808,18 +1810,17 @@ static void qDumpQObjectSlot(QDumper &d)
         const QObject *ob = reinterpret_cast<const QObject *>(d.data);
         const QObjectPrivate *p = reinterpret_cast<const QObjectPrivate *>(dfunc(ob));
         for (int s = 0; s != p->senders.size(); ++s) {
-            const QObjectPrivate::Sender &sender = p->senders.at(s);
-            const QObjectPrivate::ConnectionList &connList
-                = qConnectionList(sender.sender, sender.signal);
+            const QObject *sender = senderAt(p->senders, s);
+            int signal = signalAt(p->senders, s);
+            const ConnectionList &connList = qConnectionList(sender, signal);
             for (int i = 0; i != connList.size(); ++i) {
-                const QObjectPrivate::Connection &conn = connList.at(i);
+                const Connection &conn = connectionAt(connList, i);
                 if (conn.receiver == ob && conn.method == slotNumber) {
                     ++numchild;
-                    const QMetaMethod & method =
-                        sender.sender->metaObject()->method(sender.signal);
+                    const QMetaMethod &method = sender->metaObject()->method(signal);
                     d.beginHash();
                         P(d, "name", s << " sender");
-                        qDumpInnerValueHelper(d, NS"QObject *", sender.sender);
+                        qDumpInnerValueHelper(d, NS"QObject *", sender);
                     d.endHash();
                     d.beginHash();
                         P(d, "name", s << " signal");
@@ -1871,11 +1872,11 @@ static void qDumpQObjectSlotList(QDumper &d)
                 // count senders. expensive...
                 int numchild = 0;
                 for (int s = 0; s != p->senders.size(); ++s) {
-                    const QObjectPrivate::Sender & sender = p->senders.at(s);
-                    const QObjectPrivate::ConnectionList &connList
-                        = qConnectionList(sender.sender, sender.signal);
+                    const QObject *sender = senderAt(p->senders, s);
+                    int signal = signalAt(p->senders, s);
+                    const ConnectionList &connList = qConnectionList(sender, signal);
                     for (int c = 0; c != connList.size(); ++c) {
-                        const QObjectPrivate::Connection &conn = connList.at(c);
+                        const Connection &conn = connectionAt(connList, c);
                         if (conn.receiver == ob && conn.method == k)
                             ++numchild;
                     }
@@ -1891,7 +1892,6 @@ static void qDumpQObjectSlotList(QDumper &d)
 #endif
     d.disarm();
 }
-#endif // PRIVATE_OBJECT_ALLOWED
 
 
 static void qDumpQPixmap(QDumper &d)
@@ -2581,7 +2581,6 @@ static void handleProtocolVersion2and3(QDumper & d)
                 qDumpQObjectPropertyList(d);
             else if (isEqual(type, "QObjectMethodList"))
                 qDumpQObjectMethodList(d);
-            #if PRIVATE_OBJECT_ALLOWED
             else if (isEqual(type, "QObjectSignal"))
                 qDumpQObjectSignal(d);
             else if (isEqual(type, "QObjectSignalList"))
@@ -2590,7 +2589,6 @@ static void handleProtocolVersion2and3(QDumper & d)
                 qDumpQObjectSlot(d);
             else if (isEqual(type, "QObjectSlotList"))
                 qDumpQObjectSlotList(d);
-            #endif
             break;
         case 'P':
             if (isEqual(type, "QPixmap"))
@@ -2700,12 +2698,10 @@ void *qDumpObjectData440(
             "\""NS"QObject\","
             "\""NS"QObjectMethodList\","   // hack to get nested properties display
             "\""NS"QObjectPropertyList\","
-#if PRIVATE_OBJECT_ALLOWED
             "\""NS"QObjectSignal\","
             "\""NS"QObjectSignalList\","
             "\""NS"QObjectSlot\","
             "\""NS"QObjectSlotList\","
-#endif // PRIVATE_OBJECT_ALLOWED
             // << "\""NS"QRegion\","
             "\""NS"QSet\","
             "\""NS"QSharedPointer\","
-- 
GitLab