Debugger: Client for DeclarativeDebugger

A client for DeclarativeDebugger Service. The service is
a backport of QmlDebugger service.

Change-Id: I868a286756c2d6bcbb2f41904a13d7f691e9704c
Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
This commit is contained in:
Aurindam Jana
2012-09-28 14:40:57 +02:00
parent ceb9319e4b
commit bb00f59d66
10 changed files with 125 additions and 67 deletions

View File

@@ -76,8 +76,8 @@ void BaseEngineDebugClient::decode(QDataStream &ds,
QmlObjectData data; QmlObjectData data;
ds >> data; ds >> data;
int parentId = -1; int parentId = -1;
if (objectName() == QLatin1String("QmlDebugger") && // qt > 4.8.3
serviceVersion() >= Constants::CURRENT_SUPPORTED_VERSION ) if (objectName() != QLatin1String(Constants::QDECLARATIVE_ENGINE))
ds >> parentId; ds >> parentId;
o.m_debugId = data.objectId; o.m_debugId = data.objectId;
o.m_className = data.objectType; o.m_className = data.objectType;
@@ -184,19 +184,15 @@ void BaseEngineDebugClient::messageReceived(const QByteArray &data)
QDataStream ds(data); QDataStream ds(data);
int queryId; int queryId;
QByteArray type; QByteArray type;
ds >> type; ds >> type >> queryId;
if (type == "OBJECT_CREATED") { if (type == "OBJECT_CREATED") {
int engineId; int engineId;
int objectId; int objectId;
ds >> engineId >> objectId; int parentId;
emit newObject(engineId, objectId, -1); ds >> engineId >> objectId >> parentId;
return; emit newObject(engineId, objectId, parentId);
} } else if (type == "LIST_ENGINES_R") {
ds >> queryId;
if (type == "LIST_ENGINES_R") {
int count; int count;
ds >> count; ds >> count;
QList<EngineReference> engines; QList<EngineReference> engines;
@@ -398,7 +394,7 @@ quint32 BaseEngineDebugClient::setBindingForObject(
id = getId(); id = getId();
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_BINDING") << objectDebugId << propertyName ds << QByteArray("SET_BINDING") << id << objectDebugId << propertyName
<< bindingExpression << isLiteralValue << source << line; << bindingExpression << isLiteralValue << source << line;
sendMessage(message); sendMessage(message);
} }
@@ -414,7 +410,7 @@ quint32 BaseEngineDebugClient::resetBindingForObject(
id = getId(); id = getId();
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName; ds << QByteArray("RESET_BINDING") << id << objectDebugId << propertyName;
sendMessage(message); sendMessage(message);
} }
return id; return id;
@@ -429,7 +425,7 @@ quint32 BaseEngineDebugClient::setMethodBody(
id = getId(); id = getId();
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_METHOD_BODY") << objectDebugId ds << QByteArray("SET_METHOD_BODY") << id << objectDebugId
<< methodName << methodBody; << methodName << methodBody;
sendMessage(message); sendMessage(message);
} }

View File

@@ -27,18 +27,18 @@
** **
**************************************************************************/ **************************************************************************/
#include "qmlenginedebugclient.h" #include "declarativeenginedebugclient.h"
#include "qmldebugconstants.h" #include "qmldebugconstants.h"
namespace QmlDebug { namespace QmlDebug {
QmlEngineDebugClient::QmlEngineDebugClient( DeclarativeEngineDebugClient::DeclarativeEngineDebugClient(
QmlDebugConnection *connection) QmlDebugConnection *connection)
: BaseEngineDebugClient(QLatin1String(Constants::QML_DEBUGGER), connection) : BaseEngineDebugClient(QLatin1String(Constants::QDECLARATIVE_ENGINE), connection)
{ {
} }
quint32 QmlEngineDebugClient::setBindingForObject( quint32 DeclarativeEngineDebugClient::setBindingForObject(
int objectDebugId, int objectDebugId,
const QString &propertyName, const QString &propertyName,
const QVariant &bindingExpression, const QVariant &bindingExpression,
@@ -50,14 +50,14 @@ quint32 QmlEngineDebugClient::setBindingForObject(
id = getId(); id = getId();
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_BINDING") << id << objectDebugId << propertyName ds << QByteArray("SET_BINDING") << objectDebugId << propertyName
<< bindingExpression << isLiteralValue << source << line; << bindingExpression << isLiteralValue << source << line;
sendMessage(message); sendMessage(message);
} }
return id; return id;
} }
quint32 QmlEngineDebugClient::resetBindingForObject( quint32 DeclarativeEngineDebugClient::resetBindingForObject(
int objectDebugId, int objectDebugId,
const QString &propertyName) const QString &propertyName)
{ {
@@ -66,13 +66,13 @@ quint32 QmlEngineDebugClient::resetBindingForObject(
id = getId(); id = getId();
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("RESET_BINDING") << id << objectDebugId << propertyName; ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName;
sendMessage(message); sendMessage(message);
} }
return id; return id;
} }
quint32 QmlEngineDebugClient::setMethodBody( quint32 DeclarativeEngineDebugClient::setMethodBody(
int objectDebugId, const QString &methodName, int objectDebugId, const QString &methodName,
const QString &methodBody) const QString &methodBody)
{ {
@@ -81,26 +81,24 @@ quint32 QmlEngineDebugClient::setMethodBody(
id = getId(); id = getId();
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_METHOD_BODY") << id << objectDebugId ds << QByteArray("SET_METHOD_BODY") << objectDebugId
<< methodName << methodBody; << methodName << methodBody;
sendMessage(message); sendMessage(message);
} }
return id; return id;
} }
void QmlEngineDebugClient::messageReceived(const QByteArray &data) void DeclarativeEngineDebugClient::messageReceived(const QByteArray &data)
{ {
QDataStream ds(data); QDataStream ds(data);
int queryId;
QByteArray type; QByteArray type;
ds >> type >> queryId; ds >> type;
if (type == "OBJECT_CREATED") { if (type == "OBJECT_CREATED") {
int engineId; int engineId;
int objectId; int objectId;
int parentId; ds >> engineId >> objectId;
ds >> engineId >> objectId >> parentId; emit newObject(engineId, objectId, -1);
emit newObject(engineId, objectId, parentId);
return; return;
} else { } else {
BaseEngineDebugClient::messageReceived(data); BaseEngineDebugClient::messageReceived(data);

View File

@@ -40,10 +40,18 @@ class QMLDEBUG_EXPORT DeclarativeEngineDebugClient : public BaseEngineDebugClien
{ {
Q_OBJECT Q_OBJECT
public: public:
DeclarativeEngineDebugClient(QmlDebugConnection *conn) explicit DeclarativeEngineDebugClient(QmlDebugConnection *conn);
: BaseEngineDebugClient(QLatin1String("QDeclarativeEngine"), conn)
{ quint32 setBindingForObject(int objectDebugId, const QString &propertyName,
} const QVariant &bindingExpression,
bool isLiteralValue,
QString source, int line);
quint32 resetBindingForObject(int objectDebugId, const QString &propertyName);
quint32 setMethodBody(int objectDebugId, const QString &methodName,
const QString &methodBody);
protected:
void messageReceived(const QByteArray &data);
}; };
} // namespace QmlDebug } // namespace QmlDebug

View File

@@ -0,0 +1,51 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
** 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.
**
** 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.
**
**
**************************************************************************/
#ifndef DECLARATIVEENGINEDEBUGCLIENTV2_H
#define DECLARATIVEENGINEDEBUGCLIENTV2_H
#include "baseenginedebugclient.h"
namespace QmlDebug {
class QmlDebugConnection;
class QMLDEBUG_EXPORT DeclarativeEngineDebugClientV2 : public BaseEngineDebugClient
{
Q_OBJECT
public:
explicit DeclarativeEngineDebugClientV2(QmlDebugConnection *conn)
: BaseEngineDebugClient(QLatin1String("DeclarativeDebugger"), conn)
{
}
};
} // namespace QmlDebug
#endif // DECLARATIVEENGINEDEBUGCLIENTV2_H

View File

@@ -11,6 +11,7 @@ HEADERS += \
$$PWD/qmldebugclient.h \ $$PWD/qmldebugclient.h \
$$PWD/baseenginedebugclient.h \ $$PWD/baseenginedebugclient.h \
$$PWD/declarativeenginedebugclient.h \ $$PWD/declarativeenginedebugclient.h \
$$PWD/declarativeenginedebugclientv2.h \
$$PWD/qmloutputparser.h \ $$PWD/qmloutputparser.h \
$$PWD/qmldebug_global.h \ $$PWD/qmldebug_global.h \
$$PWD/qmlprofilereventtypes.h \ $$PWD/qmlprofilereventtypes.h \
@@ -32,8 +33,8 @@ SOURCES += \
$$PWD/qpacketprotocol.cpp \ $$PWD/qpacketprotocol.cpp \
$$PWD/qv8profilerclient.cpp \ $$PWD/qv8profilerclient.cpp \
$$PWD/qdebugmessageclient.cpp \ $$PWD/qdebugmessageclient.cpp \
$$PWD/qmlenginedebugclient.cpp \
$$PWD/basetoolsclient.cpp \ $$PWD/basetoolsclient.cpp \
$$PWD/declarativetoolsclient.cpp \ $$PWD/declarativetoolsclient.cpp \
$$PWD/qmltoolsclient.cpp $$PWD/qmltoolsclient.cpp \
$$PWD/declarativeenginedebugclient.cpp

View File

@@ -20,7 +20,9 @@ QtcLibrary {
"baseenginedebugclient.h", "baseenginedebugclient.h",
"basetoolsclient.cpp", "basetoolsclient.cpp",
"basetoolsclient.h", "basetoolsclient.h",
"declarativeenginedebugclient.cpp",
"declarativeenginedebugclient.h", "declarativeenginedebugclient.h",
"declarativeenginedebugclientv2.h",
"declarativetoolsclient.cpp", "declarativetoolsclient.cpp",
"declarativetoolsclient.h", "declarativetoolsclient.h",
"qdebugmessageclient.cpp", "qdebugmessageclient.cpp",
@@ -37,7 +39,6 @@ QtcLibrary {
"qmlprofilertraceclient.h", "qmlprofilertraceclient.h",
"qpacketprotocol.cpp", "qpacketprotocol.cpp",
"qpacketprotocol.h", "qpacketprotocol.h",
"qmlenginedebugclient.cpp",
"qmlenginedebugclient.h", "qmlenginedebugclient.h",
"qv8profilerclient.cpp", "qv8profilerclient.cpp",
"qv8profilerclient.h", "qv8profilerclient.h",

View File

@@ -42,8 +42,7 @@ const char STR_IGNORING_DEBUGGER[] = "Ignoring \"-qmljsdebugger=";
const char STR_IGNORING_DEBUGGER2[] = "Ignoring\"-qmljsdebugger="; // There is (was?) a bug in one of the error strings - safest to handle both const char STR_IGNORING_DEBUGGER2[] = "Ignoring\"-qmljsdebugger="; // There is (was?) a bug in one of the error strings - safest to handle both
const char STR_CONNECTION_ESTABLISHED[] = "Connection established"; const char STR_CONNECTION_ESTABLISHED[] = "Connection established";
const char QML_DEBUGGER[] = "QmlDebugger"; const char QDECLARATIVE_ENGINE[] = "QDeclarativeEngine";
const float CURRENT_SUPPORTED_VERSION = 2.0;
} // namespace Constants } // namespace Constants
} // namespace QmlDebug } // namespace QmlDebug

View File

@@ -40,18 +40,10 @@ class QMLDEBUG_EXPORT QmlEngineDebugClient : public BaseEngineDebugClient
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QmlEngineDebugClient(QmlDebugConnection *conn); explicit QmlEngineDebugClient(QmlDebugConnection *conn)
: BaseEngineDebugClient(QLatin1String("QmlDebugger"), conn)
quint32 setBindingForObject(int objectDebugId, const QString &propertyName, {
const QVariant &bindingExpression, }
bool isLiteralValue,
QString source, int line);
quint32 resetBindingForObject(int objectDebugId, const QString &propertyName);
quint32 setMethodBody(int objectDebugId, const QString &methodName,
const QString &methodBody);
protected:
void messageReceived(const QByteArray &data);
}; };
} // namespace QmlDebug } // namespace QmlDebug

View File

@@ -42,6 +42,7 @@
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <qmldebug/declarativeenginedebugclient.h> #include <qmldebug/declarativeenginedebugclient.h>
#include <qmldebug/declarativeenginedebugclientv2.h>
#include <qmldebug/declarativetoolsclient.h> #include <qmldebug/declarativetoolsclient.h>
#include <qmldebug/qmlenginedebugclient.h> #include <qmldebug/qmlenginedebugclient.h>
#include <qmldebug/qmltoolsclient.h> #include <qmldebug/qmltoolsclient.h>
@@ -96,13 +97,23 @@ QmlInspectorAdapter::QmlInspectorAdapter(QmlAdapter *debugAdapter,
connect(engineClient2, SIGNAL(newStatus(QmlDebug::ClientStatus)), connect(engineClient2, SIGNAL(newStatus(QmlDebug::ClientStatus)),
this, SLOT(engineClientStatusChanged(QmlDebug::ClientStatus))); this, SLOT(engineClientStatusChanged(QmlDebug::ClientStatus)));
DeclarativeEngineDebugClientV2 *engineClient3
= new DeclarativeEngineDebugClientV2(connection);
connect(engineClient3, SIGNAL(newStatus(QmlDebug::ClientStatus)),
this, SLOT(clientStatusChanged(QmlDebug::ClientStatus)));
connect(engineClient3, SIGNAL(newStatus(QmlDebug::ClientStatus)),
this, SLOT(engineClientStatusChanged(QmlDebug::ClientStatus)));
m_engineClients.insert(engineClient1->name(), engineClient1); m_engineClients.insert(engineClient1->name(), engineClient1);
m_engineClients.insert(engineClient2->name(), engineClient2); m_engineClients.insert(engineClient2->name(), engineClient2);
m_engineClients.insert(engineClient3->name(), engineClient3);
if (engineClient1->status() == QmlDebug::Enabled) if (engineClient1->status() == QmlDebug::Enabled)
setActiveEngineClient(engineClient1); setActiveEngineClient(engineClient1);
if (engineClient2->status() == QmlDebug::Enabled) if (engineClient2->status() == QmlDebug::Enabled)
setActiveEngineClient(engineClient2); setActiveEngineClient(engineClient2);
if (engineClient3->status() == QmlDebug::Enabled)
setActiveEngineClient(engineClient3);
DeclarativeToolsClient *toolsClient1 = new DeclarativeToolsClient(connection); DeclarativeToolsClient *toolsClient1 = new DeclarativeToolsClient(connection);
connect(toolsClient1, SIGNAL(newStatus(QmlDebug::ClientStatus)), connect(toolsClient1, SIGNAL(newStatus(QmlDebug::ClientStatus)),

View File

@@ -42,6 +42,7 @@
#include <QElapsedTimer> #include <QElapsedTimer>
using namespace QmlDebug; using namespace QmlDebug;
using namespace QmlDebug::Constants;
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
@@ -476,7 +477,7 @@ void QmlInspectorAgent::newObject(int engineId, int objectId, int /*parentId*/)
return; return;
m_newObjectsCreated = true; m_newObjectsCreated = true;
if (m_engineClient->objectName() == QLatin1String(QmlDebug::Constants::QML_DEBUGGER)) if (m_engineClient->objectName() != QLatin1String(QDECLARATIVE_ENGINE))
fetchObject(objectId); fetchObject(objectId);
else else
m_delayQueryTimer.start(); m_delayQueryTimer.start();
@@ -595,13 +596,13 @@ void QmlInspectorAgent::fetchObjectsInContextRecursive(const ContextReference &c
foreach (const ObjectReference & obj, context.objects()) { foreach (const ObjectReference & obj, context.objects()) {
using namespace QmlDebug::Constants; using namespace QmlDebug::Constants;
if (m_engineClient->objectName() == QLatin1String(QML_DEBUGGER) && // qt <= 4.8.3
m_engineClient->serviceVersion() >= CURRENT_SUPPORTED_VERSION) { if (m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
//Fetch only root objects m_objectTreeQueryIds << m_engineClient->queryObjectRecursive(obj.debugId());
} else {
// Fetch only root objects for qt > 4.8.3
if (obj.parentId() == -1) if (obj.parentId() == -1)
fetchObject(obj.debugId()); fetchObject(obj.debugId());
} else {
m_objectTreeQueryIds << m_engineClient->queryObjectRecursive(obj.debugId());
} }
} }
foreach (const ContextReference &child, context.contexts()) foreach (const ContextReference &child, context.contexts())
@@ -628,8 +629,8 @@ void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
ObjectReference last; ObjectReference last;
QStack<QmlDebug::ObjectReference> stack; QStack<QmlDebug::ObjectReference> stack;
// 4.x // qt <= 4.8.3
if (m_newObjectsCreated && m_engineClient->objectName() != QLatin1String(QmlDebug::Constants::QML_DEBUGGER)) { if (m_newObjectsCreated && m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
// We need to reverse the stack as the root objects // We need to reverse the stack as the root objects
// are pushed to the bottom since they are fetched first. // are pushed to the bottom since they are fetched first.
// The child objects need to placed in the correct position and therefore // The child objects need to placed in the correct position and therefore
@@ -645,8 +646,8 @@ void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
int parentId = last.parentId(); int parentId = last.parentId();
QByteArray parentIname; QByteArray parentIname;
// 4.x // qt <= 4.8.3
if (m_engineClient->objectName() != QLatin1String(QmlDebug::Constants::QML_DEBUGGER)) { if (m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
QHashIterator<int, QList<int> > i(m_debugIdChildIds); QHashIterator<int, QList<int> > i(m_debugIdChildIds);
while (i.hasNext()) { while (i.hasNext()) {
i.next(); i.next();
@@ -662,8 +663,8 @@ void QmlInspectorAgent::objectTreeFetched(const ObjectReference &object)
fetchObject(parentId); fetchObject(parentId);
return; return;
} }
// 5.x // qt > 4.8.3
if (m_engineClient->objectName() == QLatin1String(QmlDebug::Constants::QML_DEBUGGER) if (m_engineClient->objectName() != QLatin1String(QDECLARATIVE_ENGINE)
&& m_newObjectsCreated && parentIname.isEmpty()) { && m_newObjectsCreated && parentIname.isEmpty()) {
if (watchData.count()) if (watchData.count())
break; break;
@@ -735,13 +736,13 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
m_debugIdHash[file][location].append(ref.debugId()); m_debugIdHash[file][location].append(ref.debugId());
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum)); m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
// 4.x // qt <= 4.8.3
if (m_newObjectsCreated && m_engineClient->objectName() != QLatin1String(QmlDebug::Constants::QML_DEBUGGER)) { if (m_newObjectsCreated && m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
QList<int> childIds; QList<int> childIds;
foreach (const ObjectReference &c, ref.children()) { foreach (const ObjectReference &c, ref.children()) {
childIds << c.debugId(); childIds << c.debugId();
} }
// For 4.x, we do not get the parentId. Hence, store the child ids // For qt <= 4.8.3, we do not get the parentId. Hence, store the child ids
// to look up correct insertion places later // to look up correct insertion places later
m_debugIdChildIds.insert(ref.debugId(), childIds); m_debugIdChildIds.insert(ref.debugId(), childIds);
} }
@@ -877,8 +878,8 @@ void QmlInspectorAgent::clearObjectTree()
m_debugIdToIname.clear(); m_debugIdToIname.clear();
m_debugIdChildIds.clear(); m_debugIdChildIds.clear();
m_objectStack.clear(); m_objectStack.clear();
// reset only for 5.x. // reset only for qt > 4.8.3.
if (m_engineClient->objectName() == QLatin1String(QmlDebug::Constants::QML_DEBUGGER)) if (m_engineClient->objectName() != QLatin1String(QDECLARATIVE_ENGINE))
m_newObjectsCreated = false; m_newObjectsCreated = false;
removeAllObjectWatches(); removeAllObjectWatches();