From c42e96618454a7315680a96718bf8d20a7f67e68 Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Mon, 8 Aug 2011 14:53:10 +0200
Subject: [PATCH] JSDebugger: Only hit breakpoints in user code

Check that the topmost stack entry is a user defined ScriptFunction.
This avoids hitting the anonymous functions used for bindings, e.g.

onClicked: Qt.quit()

leads to script code

(function onClicked() { Qt.quit(); })

which will be hit twice for the debugger: Once for the function call
itself, then for the execution of Qt.quit().

Change-Id: I4cb374782c93a26d97d4a717ce67d1fb2f6df438
Task-number: QTCREATORBUG-5090
Reviewed-on: http://codereview.qt.nokia.com/2746
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
---
 .../qml/qmljsdebugger/jsdebuggeragent.cpp     | 31 ++++++++++---------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/share/qtcreator/qml/qmljsdebugger/jsdebuggeragent.cpp b/share/qtcreator/qml/qmljsdebugger/jsdebuggeragent.cpp
index 770f5313484..87c917ca869 100644
--- a/share/qtcreator/qml/qmljsdebugger/jsdebuggeragent.cpp
+++ b/share/qtcreator/qml/qmljsdebugger/jsdebuggeragent.cpp
@@ -370,27 +370,28 @@ void JSDebuggerAgentPrivate::positionChange(qint64 scriptId, int lineNumber, int
 
     // check breakpoints
     if (!breakpoints.isEmpty()) {
-        QHash<qint64, QString>::const_iterator it = filenames.constFind(scriptId);
         QScriptContext *ctx = engine()->currentContext();
         QScriptContextInfo info(ctx);
-        if (it == filenames.constEnd()) {
-            // It is possible that the scripts are loaded before the agent is attached
-            QString filename = info.fileName();
 
-            JSAgentStackData frame;
-            frame.functionName = info.functionName().toUtf8();
+        if (info.functionType() == QScriptContextInfo::ScriptFunction) {
+            QHash<qint64, QString>::const_iterator it = filenames.constFind(scriptId);
+            if (it == filenames.constEnd()) {
+                // It is possible that the scripts are loaded before the agent is attached
+                QString filename = info.fileName();
 
-            QPair<QString, qint32> key = qMakePair(filename, lineNumber);
-            it = filenames.insert(scriptId, filename);
-        }
+                JSAgentStackData frame;
+                frame.functionName = info.functionName().toUtf8();
+                it = filenames.insert(scriptId, filename);
+            }
 
-        const QString filePath = it->toUtf8();
-        JSAgentBreakpoints bps = fileNameToBreakpoints.values(fileName(filePath)).toSet();
+            const QString filePath = it->toUtf8();
+            JSAgentBreakpoints bps = fileNameToBreakpoints.values(fileName(filePath)).toSet();
 
-        foreach (const JSAgentBreakpointData &bp, bps) {
-            if (bp.lineNumber == lineNumber) {
-                stopped();
-                return;
+            foreach (const JSAgentBreakpointData &bp, bps) {
+                if (bp.lineNumber == lineNumber) {
+                    stopped();
+                    return;
+                }
             }
         }
     }
-- 
GitLab