From d554aa86b76a0c1da1ebcec9a5a03aebe1ca085f Mon Sep 17 00:00:00 2001
From: Olivier Goffart <olivier.goffart@nokia.com>
Date: Thu, 22 Jul 2010 15:22:46 +0200
Subject: [PATCH] QML JS Debugger: clicking on the stackstrace shows the locals
 of this context

---
 src/plugins/debugger/qml/qmlengine.cpp        | 23 ++++++++++++++---
 src/tools/qml/qmlobserver/jsdebuggeragent.cpp | 25 +++++++++++++++++++
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp
index 8bb0d7fae7d..a179db2efe6 100644
--- a/src/plugins/debugger/qml/qmlengine.cpp
+++ b/src/plugins/debugger/qml/qmlengine.cpp
@@ -430,7 +430,13 @@ void QmlEngine::executeJumpToLine(const QString &fileName, int lineNumber)
 void QmlEngine::activateFrame(int index)
 {
     Q_UNUSED(index)
-    qDebug() << Q_FUNC_INFO << index;
+
+    QByteArray reply;
+    QDataStream rs(&reply, QIODevice::WriteOnly);
+    rs << QByteArray("ACTIVATE_FRAME");
+    rs << index;
+    sendMessage(reply);
+
     gotoLocation(stackHandler()->frames().value(index), true);
 }
 
@@ -585,8 +591,6 @@ void QmlEngine::messageReceived(const QByteArray &message)
     QByteArray command;
     stream >> command;
 
-    qDebug() << "RECEIVED COMMAND: " << command;
-
     showMessage(_("RECEIVED RESPONSE: ") + quoteUnprintableLatin1(message));
     if (command == "STOPPED") {
         notifyInferiorSpontaneousStop();
@@ -647,6 +651,19 @@ void QmlEngine::messageReceived(const QByteArray &message)
             if (watchHandler()->expandedINames().contains(data.iname)) 
                 expandObject(data.iname, data.objectId);
         }
+    } else if (command == "LOCALS") {
+        QList<WatchData> locals;
+        int frameId;
+        stream >> frameId >> locals;
+        watchHandler()->beginCycle();
+        foreach (WatchData data, locals) {
+            data.iname = "local." + data.exp;
+            qDebug() << data.iname << data.value;
+            watchHandler()->insertData(data);
+            if (watchHandler()->expandedINames().contains(data.iname))
+                expandObject(data.iname, data.objectId);
+        }
+        watchHandler()->endCycle();
     } else {
         qDebug() << Q_FUNC_INFO << "Unknown command: " << command;
     }
diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
index 51ecea7dd6c..57f8eb97b66 100644
--- a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
+++ b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
@@ -335,7 +335,32 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
         rs << QByteArray("EXPANDED") << requestId << result;
         sendMessage(reply);
         state = oldState;
+    } else if (command == "ACTIVATE_FRAME") {
+        State oldState = state;
+        state = Stopped;
+
+        int frameId;
+        ds >> frameId;
+
+        int deep = 0;
+        QScriptContext *ctx = engine()->currentContext();
+        while (ctx && deep < frameId) {
+            ctx = ctx->parentContext();
+            deep++;
+        }
+
+        QList<JSAgentWatchData> locals;
+        if (ctx)
+            locals = expandObject(ctx->activationObject());
+        recordKnownObjects(locals);
 
+        // Clear any exceptions occurred during locals evaluation.
+        engine()->clearExceptions();
+
+        QByteArray reply;
+        QDataStream rs(&reply, QIODevice::WriteOnly);
+        rs << QByteArray("LOCALS") << frameId << locals;
+        sendMessage(reply);
     } else {
         qDebug() << Q_FUNC_INFO << "Unknown command" << command;
     }
-- 
GitLab