From 27382f753cdf253c7875a2bc1f9040e905868a3d Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 28 Aug 2009 15:36:52 +0200
Subject: [PATCH] debuger: fix insertion of nested WatchData

---
 share/qtcreator/gdbmacros/gdbmacros.cpp  |  2 +-
 src/plugins/debugger/debuggermanager.cpp |  5 +++--
 src/plugins/debugger/gdb/gdbengine.cpp   | 26 ++++++++++++++++--------
 src/plugins/debugger/gdb/gdbengine.h     |  3 ++-
 src/plugins/debugger/watchhandler.cpp    |  2 +-
 5 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/share/qtcreator/gdbmacros/gdbmacros.cpp b/share/qtcreator/gdbmacros/gdbmacros.cpp
index e0a59d43c21..ab84fed5f80 100644
--- a/share/qtcreator/gdbmacros/gdbmacros.cpp
+++ b/share/qtcreator/gdbmacros/gdbmacros.cpp
@@ -2834,7 +2834,7 @@ static void qDumpQSharedPointer(QDumper &d)
 
 static void qDumpQString(QDumper &d)
 {
-    qCheckAccess(deref(d.data));
+    //qCheckAccess(deref(d.data));
     const QString &str = *reinterpret_cast<const QString *>(d.data);
 
     const int size = str.size();
diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp
index 6f1391015b1..ad77ef80e3c 100644
--- a/src/plugins/debugger/debuggermanager.cpp
+++ b/src/plugins/debugger/debuggermanager.cpp
@@ -316,9 +316,10 @@ void DebuggerManager::init()
     // Tooltip
     //QTreeView *tooltipView = qobject_cast<QTreeView *>(m_tooltipWindow);
     //tooltipView->setModel(m_watchHandler->model(TooltipsWatch));
-
+    //qRegisterMetaType<WatchData>("Debugger::Internal::WatchData");
+    qRegisterMetaType<WatchData>("WatchData");
     connect(m_watchHandler, SIGNAL(watchDataUpdateNeeded(WatchData)),
-        this, SLOT(updateWatchData(WatchData)));
+        this, SLOT(updateWatchData(WatchData)), Qt::QueuedConnection);
 
     m_continueAction = new QAction(this);
     m_continueAction->setText(tr("Continue"));
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 6fbba11e083..99718326c24 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -83,7 +83,7 @@ namespace Internal {
 using namespace Debugger::Constants;
 
 //#define DEBUG_PENDING  1
-//#define DEBUG_SUBITEM  1
+#define DEBUG_SUBITEM  1
 
 #if DEBUG_PENDING
 #   define PENDING_DEBUG(s) qDebug() << s
@@ -2958,6 +2958,10 @@ void GdbEngine::runDebuggingHelper(const WatchData &data0, bool dumpChildren)
 
 void GdbEngine::createGdbVariable(const WatchData &data)
 {
+    if (data.iname == _("local.flist.0")) {
+        int i = 1;
+        Q_UNUSED(i);
+    }
     postCommand(_("-var-delete \"%1\"").arg(data.iname), WatchUpdate);
     QString exp = data.exp;
     if (exp.isEmpty() && data.addr.startsWith(__("0x")))
@@ -3401,11 +3405,17 @@ void GdbEngine::handleDebuggingHelperValue2(const GdbResultRecord &record,
 
     setWatchDataType(data, record.data.findChild("type"));
     setWatchDataDisplayedType(data, record.data.findChild("displaytype"));
-    handleChildren(data, contents);
+    QList<WatchData> list;
+    handleChildren(data, contents, &list);
+    //for (int i = 0; i != list.size(); ++i)
+    //    qDebug() << "READ: " << list.at(i).toString();
+    qq->watchHandler()->insertBulkData(list);
 }
 
-void GdbEngine::handleChildren(const WatchData &data0, const GdbMi &item)
+void GdbEngine::handleChildren(const WatchData &data0, const GdbMi &item,
+    QList<WatchData> *list)
 {
+    //qDebug() << "HANDLE CHILDREN: " << data0.toString() << item.toString();
     WatchData data = data0;
     if (!qq->watchHandler()->isExpandedIName(data.iname))
         data.setChildrenUnneeded();
@@ -3432,16 +3442,16 @@ void GdbEngine::handleChildren(const WatchData &data0, const GdbMi &item)
     setWatchDataValueToolTip(data, item.findChild("valuetooltip"),
         item.findChild("valuetooltipencoded").data().toInt());
     setWatchDataValueDisabled(data, item.findChild("valuedisabled"));
+    //qDebug() << "HANDLE CHILDREN: " << data.toString();
+    list->append(data);
 
     // try not to repeat data too often
     WatchData childtemplate;
     setWatchDataType(childtemplate, item.findChild("childtype"));
     setWatchDataChildCount(childtemplate, item.findChild("childnumchild"));
-    //qDebug() << "CHILD TEMPLATE:" << childtemplate.toString();
+    qDebug() << "CHILD TEMPLATE:" << childtemplate.toString();
 
-    qq->watchHandler()->insertData(data); 
     int i = 0;
-    QList<WatchData> list;
     foreach (GdbMi child, children.children()) {
         WatchData data1 = childtemplate;
         GdbMi name = child.findChild("name");
@@ -3463,11 +3473,9 @@ void GdbEngine::handleChildren(const WatchData &data0, const GdbMi &item)
             //data1.name += " (" + skey + ")";
             data1.name = skey;
         }
-        handleChildren(data1, child);
-        list.append(data1);
+        handleChildren(data1, child, list);
         ++i;
     }
-    qq->watchHandler()->insertBulkData(list); 
 }
 
 void GdbEngine::handleDebuggingHelperValue3(const GdbResultRecord &record,
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index b041c63eb2b..07ef3bb8b8a 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -241,7 +241,8 @@ private:
     void debugMessage(const QString &msg);
     bool showToolTip();
 
-    void handleChildren(const WatchData &parent, const GdbMi &child);
+    void handleChildren(const WatchData &parent, const GdbMi &child,
+        QList<WatchData> *insertions);
     const bool m_dumperInjectionLoad;
 
     OutputCollector m_outputCollector;
diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index 3ab57db6fd6..fd6745014b9 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -1003,7 +1003,7 @@ void WatchHandler::insertBulkData(const QList<WatchData> &list)
 {
     if (list.isEmpty())
         return;
-    QHash<QString, QList<WatchData> > hash;
+    QMap<QString, QList<WatchData> > hash;
 
     foreach (const WatchData &data, list) {
         if (data.isSomethingNeeded())
-- 
GitLab