From: Simjees Abraham Date: Fri, 25 May 2012 07:02:44 +0000 (+0200) Subject: Debugger: Clearing the ObjectReferenceHash X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f50afbad6c6f8f4241db3c1d40c74c3aaa1fda83;p=konrad%2Fqtdeclarative.git Debugger: Clearing the ObjectReferenceHash ObjectReferenceHash is cleared when the Qml file is reloaded. Change-Id: I78da1d88cce2f04fe820f3af14b047cd562e90ed Reviewed-by: Aurindam Jana --- diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp index dbe5119..a42663e 100644 --- a/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp @@ -45,6 +45,7 @@ #include "inspecttool.h" #include +#include #include #include @@ -321,6 +322,8 @@ void QQuickViewInspector::reloadQmlFile(const QHash &change // Reset the selection since we are reloading the main qml setSelectedItems(QList()); + QQmlDebugService::clearObjectsFromHash(); + QHash debugCache; foreach (const QString &str, changesHash.keys()) diff --git a/src/qml/debugger/qqmldebugservice.cpp b/src/qml/debugger/qqmldebugservice.cpp index 511c854..d3d4df7 100644 --- a/src/qml/debugger/qqmldebugservice.cpp +++ b/src/qml/debugger/qqmldebugservice.cpp @@ -257,6 +257,13 @@ void QQmlDebugService::removeInvalidObjectsFromHash() } } +void QQmlDebugService::clearObjectsFromHash() +{ + ObjectReferenceHash *hash = objectReferenceHash(); + hash->ids.clear(); + hash->objects.clear(); +} + bool QQmlDebugService::isDebuggingEnabled() { return QQmlDebugServer::instance() != 0; diff --git a/src/qml/debugger/qqmldebugservice_p.h b/src/qml/debugger/qqmldebugservice_p.h index 4a0b52e..4fc37e6 100644 --- a/src/qml/debugger/qqmldebugservice_p.h +++ b/src/qml/debugger/qqmldebugservice_p.h @@ -88,6 +88,7 @@ public: static QList objectForLocationInfo(const QString &filename, int lineNumber, int columnNumber); static void removeInvalidObjectsFromHash(); + static void clearObjectsFromHash(); static QString objectToString(QObject *obj); diff --git a/tests/auto/qml/debugger/debugger.pro b/tests/auto/qml/debugger/debugger.pro index 81ca29a..8f90e4b 100644 --- a/tests/auto/qml/debugger/debugger.pro +++ b/tests/auto/qml/debugger/debugger.pro @@ -7,7 +7,8 @@ PUBLICTESTS += \ qqmlprofilerservice \ qpacketprotocol \ qv8profilerservice \ - qdebugmessageservice + qdebugmessageservice \ + qqmlenginedebuginspectorintegrationtest PRIVATETESTS += \ qqmldebugclient \ diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/data/qtquick2.qml b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/data/qtquick2.qml new file mode 100644 index 0000000..9c36e13 --- /dev/null +++ b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/data/qtquick2.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + +} diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro new file mode 100644 index 0000000..0ecb966 --- /dev/null +++ b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro @@ -0,0 +1,15 @@ +CONFIG += testcase +TARGET = tst_qqmlenginedebuginspectorintegration + +QT += qml testlib +macx:CONFIG -= app_bundle + +SOURCES += tst_qqmlenginedebuginspectorintegration.cpp + +INCLUDEPATH += ../shared +include(../../../shared/util.pri) +include(../shared/qqmlinspectorclient.pri) +include(../shared/qqmlenginedebugclient.pri) +include(../shared/debugutil.pri) + +TESTDATA = data/* diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp new file mode 100644 index 0000000..de34ba9 --- /dev/null +++ b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "../shared/debugutil_p.h" +#include "../../../shared/util.h" +#include "qqmlinspectorclient.h" +#include "qqmlenginedebugclient.h" + +#define PORT 3776 +#define STR_PORT "3776" + +class tst_QQmlEngineDebugInspectorIntegration : public QQmlDataTest +{ + Q_OBJECT + +public: + tst_QQmlEngineDebugInspectorIntegration() + : m_process(0) + , m_connection(0) + , m_inspectorClient(0) + , m_engineDebugClient(0) + { + } + + +private: + QmlDebugObjectReference findRootObject(); + + QQmlDebugProcess *m_process; + QQmlDebugConnection *m_connection; + QQmlInspectorClient *m_inspectorClient; + QQmlEngineDebugClient *m_engineDebugClient; + +private slots: + void init(); + void cleanup(); + + void connect(); + void clearObjectReferenceHashonReloadQml(); +}; + + +QmlDebugObjectReference tst_QQmlEngineDebugInspectorIntegration::findRootObject() +{ + bool success = false; + m_engineDebugClient->queryAvailableEngines(&success); + + QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())); + + m_engineDebugClient->queryRootContexts(m_engineDebugClient->engines()[0].debugId, &success); + QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())); + int count = m_engineDebugClient->rootContext().contexts.count(); + m_engineDebugClient->queryObject( + m_engineDebugClient->rootContext().contexts[count - 1].objects[0], &success); + QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())); + return m_engineDebugClient->object(); +} + + +void tst_QQmlEngineDebugInspectorIntegration::init() +{ + const QString argument = "-qmljsdebugger=port:"STR_PORT",block"; + + m_process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + + "/qmlscene"); + m_process->start(QStringList() << argument << testFile("qtquick2.qml")); + QVERIFY2(m_process->waitForSessionStart(), + "Could not launch application, or did not get 'Waiting for connection'."); + + QQmlDebugConnection *m_connection = new QQmlDebugConnection(this); + m_inspectorClient = new QQmlInspectorClient(m_connection); + m_engineDebugClient = new QQmlEngineDebugClient(m_connection); + + m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT); + bool ok = m_connection->waitForConnected(); + QVERIFY(ok); +} + +void tst_QQmlEngineDebugInspectorIntegration::cleanup() +{ + if (QTest::currentTestFailed()) { + qDebug() << "Process State:" << m_process->state(); + qDebug() << "Application Output:" << m_process->output(); + } + delete m_process; + delete m_engineDebugClient; + delete m_inspectorClient; +} + +void tst_QQmlEngineDebugInspectorIntegration::connect() +{ + QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled); + QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled); +} + +void tst_QQmlEngineDebugInspectorIntegration::clearObjectReferenceHashonReloadQml() +{ + QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled); + bool success = false; + QmlDebugObjectReference rootObject = findRootObject(); + const QString fileName = QFileInfo(rootObject.source.url.toString()).fileName(); + int lineNumber = rootObject.source.lineNumber; + int columnNumber = rootObject.source.columnNumber; + m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber, + columnNumber, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))); + + foreach (QmlDebugObjectReference child, rootObject.children) { + success = false; + lineNumber = child.source.lineNumber; + columnNumber = child.source.columnNumber; + m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber, + columnNumber, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))); + } + + QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled); + + QByteArray contents; + contents.append("import QtQuick 2.0\n" + "Text {" + "y: 10\n" + "text: \"test\"\n" + "}"); + + QHash changesHash; + changesHash.insert("test.qml", contents); + m_inspectorClient->reloadQml(changesHash); + QVERIFY(QQmlDebugTest::waitForSignal(m_inspectorClient, SIGNAL(responseReceived()))); + + lineNumber = rootObject.source.lineNumber; + columnNumber = rootObject.source.columnNumber; + success = false; + m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber, + columnNumber, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))); + + foreach (QmlDebugObjectReference child, rootObject.children) { + success = false; + lineNumber = child.source.lineNumber; + columnNumber = child.source.columnNumber; + m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber, + columnNumber, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))); + } +} + +QTEST_MAIN(tst_QQmlEngineDebugInspectorIntegration) + +#include "tst_qqmlenginedebuginspectorintegration.moc" diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro index 983fdb3..26dba8b 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro @@ -2,15 +2,12 @@ CONFIG += testcase TARGET = tst_qqmlenginedebugservice macx:CONFIG -= app_bundle -HEADERS += \ - qqmlenginedebugclient.h - SOURCES += \ - tst_qqmlenginedebugservice.cpp \ - qqmlenginedebugclient.cpp + tst_qqmlenginedebugservice.cpp INCLUDEPATH += ../shared include(../../../shared/util.pri) +include(../shared/qqmlenginedebugclient.pri) include(../shared/debugutil.pri) DEFINES += QT_QML_DEBUG_NO_WARNING diff --git a/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro b/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro index 1d42dde..5849d60 100644 --- a/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro +++ b/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro @@ -8,6 +8,7 @@ SOURCES += tst_qqmlinspector.cpp INCLUDEPATH += ../shared include(../../../shared/util.pri) +include(../shared/qqmlinspectorclient.pri) include(../shared/debugutil.pri) TESTDATA = data/* diff --git a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp index 5326a05..291939d 100644 --- a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp +++ b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp @@ -48,42 +48,12 @@ #include "../shared/debugutil_p.h" #include "../../../shared/util.h" +#include "qqmlinspectorclient.h" #define PORT 3772 #define STR_PORT "3772" -class QQmlInspectorClient : public QQmlDebugClient -{ - Q_OBJECT - -public: - QQmlInspectorClient(QQmlDebugConnection *connection) - : QQmlDebugClient(QLatin1String("QmlInspector"), connection) - , m_showAppOnTop(false) - , m_requestId(0) - , m_requestResult(false) - , m_responseId(-1) - { - } - - void setShowAppOnTop(bool showOnTop); - void reloadQml(const QHash &changesHash); - -signals: - void responseReceived(); -protected: - void messageReceived(const QByteArray &message); - -private: - bool m_showAppOnTop; - int m_requestId; - -public: - bool m_requestResult; - int m_responseId; - int m_reloadRequestId; -}; class tst_QQmlInspector : public QQmlDataTest { @@ -112,45 +82,6 @@ private slots: void reloadQml(); }; - -void QQmlInspectorClient::setShowAppOnTop(bool showOnTop) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("request") << m_requestId++ - << QByteArray("showAppOnTop") << showOnTop; - - sendMessage(message); -} - -void QQmlInspectorClient::reloadQml(const QHash &changesHash) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - m_reloadRequestId = m_requestId; - - ds << QByteArray("request") << m_requestId++ - << QByteArray("reload") << changesHash; - - sendMessage(message); -} - -void QQmlInspectorClient::messageReceived(const QByteArray &message) -{ - QDataStream ds(message); - QByteArray type; - ds >> type; - - if (type != QByteArray("response")) { - qDebug() << "Unhandled message of type" << type; - return; - } - - m_requestResult = false; - ds >> m_responseId >> m_requestResult; - emit responseReceived(); -} - void tst_QQmlInspector::init() { const QString argument = "-qmljsdebugger=port:"STR_PORT",block"; diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.cpp similarity index 100% rename from tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp rename to tests/auto/qml/debugger/shared/qqmlenginedebugclient.cpp diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.h similarity index 100% rename from tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h rename to tests/auto/qml/debugger/shared/qqmlenginedebugclient.h diff --git a/tests/auto/qml/debugger/shared/qqmlenginedebugclient.pri b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.pri new file mode 100644 index 0000000..a969b4f --- /dev/null +++ b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.pri @@ -0,0 +1,3 @@ +HEADERS += $$PWD/qqmlenginedebugclient.h + +SOURCES += $$PWD/qqmlenginedebugclient.cpp diff --git a/tests/auto/qml/debugger/shared/qqmlinspectorclient.cpp b/tests/auto/qml/debugger/shared/qqmlinspectorclient.cpp new file mode 100644 index 0000000..604e970 --- /dev/null +++ b/tests/auto/qml/debugger/shared/qqmlinspectorclient.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qqmlinspectorclient.h" + +void QQmlInspectorClient::setShowAppOnTop(bool showOnTop) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("request") << m_requestId++ + << QByteArray("showAppOnTop") << showOnTop; + + sendMessage(message); +} + +void QQmlInspectorClient::reloadQml(const QHash &changesHash) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + m_reloadRequestId = m_requestId; + + ds << QByteArray("request") << m_requestId++ + << QByteArray("reload") << changesHash; + + sendMessage(message); +} + +void QQmlInspectorClient::messageReceived(const QByteArray &message) +{ + QDataStream ds(message); + QByteArray type; + ds >> type; + + if (type != QByteArray("response")) { + qDebug() << "Unhandled message of type" << type; + return; + } + + m_requestResult = false; + ds >> m_responseId >> m_requestResult; + emit responseReceived(); +} diff --git a/tests/auto/qml/debugger/shared/qqmlinspectorclient.h b/tests/auto/qml/debugger/shared/qqmlinspectorclient.h new file mode 100644 index 0000000..5eb543e --- /dev/null +++ b/tests/auto/qml/debugger/shared/qqmlinspectorclient.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QQMLINSPECTORCLIENT_H +#define QQMLINSPECTORCLIENT_H + +#include "qqmldebugclient.h" + +class QQmlInspectorClient : public QQmlDebugClient +{ + Q_OBJECT + +public: + QQmlInspectorClient(QQmlDebugConnection *connection) + : QQmlDebugClient(QLatin1String("QmlInspector"), connection) + , m_showAppOnTop(false) + , m_requestId(0) + , m_requestResult(false) + , m_responseId(-1) + { + } + + void setShowAppOnTop(bool showOnTop); + void reloadQml(const QHash &changesHash); + +signals: + void responseReceived(); + +protected: + void messageReceived(const QByteArray &message); + +private: + bool m_showAppOnTop; + int m_requestId; + +public: + bool m_requestResult; + int m_responseId; + int m_reloadRequestId; +}; + +#endif // QQMLINSPECTORCLIENT_H diff --git a/tests/auto/qml/debugger/shared/qqmlinspectorclient.pri b/tests/auto/qml/debugger/shared/qqmlinspectorclient.pri new file mode 100644 index 0000000..c136e13 --- /dev/null +++ b/tests/auto/qml/debugger/shared/qqmlinspectorclient.pri @@ -0,0 +1,3 @@ +HEADERS += $$PWD/qqmlinspectorclient.h + +SOURCES += $$PWD/qqmlinspectorclient.cpp