diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-07-08 03:09:07 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-07-08 03:09:07 (GMT) |
commit | 76a1804b0fff9ffd092a551defe448d3e9d4346e (patch) | |
tree | 8907d76f7f3e0d1263dea252914c660e4cf37200 /src | |
parent | 4ec4ba7bde9ac321640c3e0c7b186f0b044423b7 (diff) | |
download | Qt-76a1804b0fff9ffd092a551defe448d3e9d4346e.zip Qt-76a1804b0fff9ffd092a551defe448d3e9d4346e.tar.gz Qt-76a1804b0fff9ffd092a551defe448d3e9d4346e.tar.bz2 |
Allow the debugger to modify method bodies
QTBUG-11933
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/debugger/qdeclarativedebug.cpp | 36 | ||||
-rw-r--r-- | src/declarative/debugger/qdeclarativedebug_p.h | 19 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeenginedebug.cpp | 55 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeenginedebug_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativevmemetaobject.cpp | 30 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativevmemetaobject_p.h | 2 |
6 files changed, 108 insertions, 35 deletions
diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp index e4a991b..0c0cf2e 100644 --- a/src/declarative/debugger/qdeclarativedebug.cpp +++ b/src/declarative/debugger/qdeclarativedebug.cpp @@ -562,31 +562,37 @@ QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult return query; } -QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, - const QString &propertyName, - const QVariant &bindingExpression, - bool isLiteralValue, - QObject *parent) +bool QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue) { Q_D(QDeclarativeEngineDebug); - QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent); if (d->client->isConnected() && objectDebugId != -1) { - query->m_client = this; - query->m_expr = bindingExpression; - int queryId = d->getId(); - query->m_queryId = queryId; - d->expressionQuery.insert(queryId, query); - QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("SET_BINDING") << queryId << objectDebugId << propertyName << bindingExpression << isLiteralValue; + ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue; d->client->sendMessage(message); + return true; } else { - query->m_state = QDeclarativeDebugQuery::Error; + return false; } +} - return query; +bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &methodName, + const QString &methodBody) +{ + Q_D(QDeclarativeEngineDebug); + + if (d->client->isConnected() && objectDebugId != -1) { + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody; + d->client->sendMessage(message); + return true; + } else { + return false; + } } QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent) diff --git a/src/declarative/debugger/qdeclarativedebug_p.h b/src/declarative/debugger/qdeclarativedebug_p.h index 007cbd7..9c38184 100644 --- a/src/declarative/debugger/qdeclarativedebug_p.h +++ b/src/declarative/debugger/qdeclarativedebug_p.h @@ -94,11 +94,10 @@ public: QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent = 0); - QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, - const QString &propertyName, - const QVariant &bindingExpression, - bool isLiteralValue, - QObject *parent = 0); + bool setBindingForObject(int objectDebugId, const QString &propertyName, + const QVariant &bindingExpression, bool isLiteralValue); + bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody); + private: Q_DECLARE_PRIVATE(QDeclarativeEngineDebug) }; @@ -202,11 +201,6 @@ public: private: friend class QDeclarativeEngineDebugPrivate; - QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, - const QString &propertyName, - const QVariant &bindingExpression, - bool isLiteralValue, - QObject *parent); QUrl m_url; int m_lineNumber; int m_columnNumber; @@ -224,11 +218,6 @@ public: QString name() const; private: - QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, - const QString &propertyName, - const QVariant &bindingExpression, - bool isLiteralValue, - QObject *parent); friend class QDeclarativeEngineDebugPrivate; int m_debugId; QString m_name; diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index d765649..acd7ab6 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -50,6 +50,8 @@ #include "private/qdeclarativecontext_p.h" #include "private/qdeclarativewatcher_p.h" #include "private/qdeclarativevaluetype_p.h" +#include "private/qdeclarativevmemetaobject_p.h" +#include "private/qdeclarativeexpression_p.h" #include <QtCore/qdebug.h> #include <QtCore/qmetaobject.h> @@ -453,20 +455,25 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) sendMessage(reply); } else if (type == "SET_BINDING") { - int queryId; int objectId; QString propertyName; QVariant expr; bool isLiteralValue; - ds >> queryId >> objectId >> propertyName >> expr >> isLiteralValue; + ds >> objectId >> propertyName >> expr >> isLiteralValue; setBinding(objectId, propertyName, expr, isLiteralValue); + } else if (type == "SET_METHOD_BODY") { + int objectId; + QString methodName; + QString methodBody; + ds >> objectId >> methodName >> methodBody; + setMethodBody(objectId, methodName, methodBody); } } void QDeclarativeEngineDebugServer::setBinding(int objectId, - const QString &propertyName, - const QVariant &expression, - bool isLiteralValue) + const QString &propertyName, + const QVariant &expression, + bool isLiteralValue) { QObject *object = objectForId(objectId); QDeclarativeContext *context = qmlContext(object); @@ -493,7 +500,45 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId, } } } +} + +void QDeclarativeEngineDebugServer::setMethodBody(int objectId, const QString &method, const QString &body) +{ + QObject *object = objectForId(objectId); + QDeclarativeContext *context = qmlContext(object); + if (!object || !context || !context->engine()) + return; + QDeclarativeContextData *contextData = QDeclarativeContextData::get(context); + if (!contextData) + return; + + QDeclarativePropertyCache::Data dummy; + QDeclarativePropertyCache::Data *prop = + QDeclarativePropertyCache::property(context->engine(), object, method, dummy); + + if (!prop || !(prop->flags & QDeclarativePropertyCache::Data::IsVMEFunction)) + return; + + QMetaMethod metaMethod = object->metaObject()->method(prop->coreIndex); + QList<QByteArray> paramNames = metaMethod.parameterNames(); + + QString paramStr; + for (int ii = 0; ii < paramNames.count(); ++ii) { + if (ii != 0) paramStr.append(QLatin1String(",")); + paramStr.append(QString::fromUtf8(paramNames.at(ii))); + } + + QString jsfunction = QLatin1String("(function ") + method + QLatin1String("(") + paramStr + + QLatin1String(") {"); + jsfunction += body; + jsfunction += QLatin1String("\n})"); + + QDeclarativeVMEMetaObject *vmeMetaObject = + static_cast<QDeclarativeVMEMetaObject*>(QObjectPrivate::get(object)->metaObject); + Q_ASSERT(vmeMetaObject); // the fact we found the property above should guarentee this + int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex); + vmeMetaObject->setVmeMethod(prop->coreIndex, QDeclarativeExpressionPrivate::evalInObjectScope(contextData, object, jsfunction, contextData->url.toString(), lineNumber, 0)); } void QDeclarativeEngineDebugServer::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value) diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h index b3c23bd..ce6df0d 100644 --- a/src/declarative/qml/qdeclarativeenginedebug_p.h +++ b/src/declarative/qml/qdeclarativeenginedebug_p.h @@ -108,6 +108,7 @@ private: QDeclarativeObjectProperty propertyData(QObject *, int); QVariant valueContents(const QVariant &defaultValue) const; void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue); + void setMethodBody(int objectId, const QString &method, const QString &body); static QList<QDeclarativeEngine *> m_engines; QDeclarativeWatcher *m_watch; diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp index 7aea7cb..689ed92 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject.cpp +++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp @@ -751,6 +751,22 @@ void QDeclarativeVMEMetaObject::registerInterceptor(int index, int valueIndex, Q interceptors.insert(index, qMakePair(valueIndex, interceptor)); } +int QDeclarativeVMEMetaObject::vmeMethodLineNumber(int index) +{ + if (index < methodOffset) { + Q_ASSERT(parent); + return static_cast<QDeclarativeVMEMetaObject *>(parent)->vmeMethodLineNumber(index); + } + + int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount; + Q_ASSERT(index >= (methodOffset + plainSignals) && index < (methodOffset + plainSignals + metaData->methodCount)); + + int rawIndex = index - methodOffset - plainSignals; + + QDeclarativeVMEMetaData::MethodData *data = metaData->methodData() + rawIndex; + return data->lineNumber; +} + QScriptValue QDeclarativeVMEMetaObject::vmeMethod(int index) { if (index < methodOffset) { @@ -762,6 +778,20 @@ QScriptValue QDeclarativeVMEMetaObject::vmeMethod(int index) return method(index - methodOffset - plainSignals); } +void QDeclarativeVMEMetaObject::setVmeMethod(int index, const QScriptValue &value) +{ + if (index < methodOffset) { + Q_ASSERT(parent); + return static_cast<QDeclarativeVMEMetaObject *>(parent)->setVmeMethod(index, value); + } + int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount; + Q_ASSERT(index >= (methodOffset + plainSignals) && index < (methodOffset + plainSignals + metaData->methodCount)); + + if (!methods) + methods = new QScriptValue[metaData->methodCount]; + methods[index - methodOffset - plainSignals] = value; +} + QScriptValue QDeclarativeVMEMetaObject::vmeProperty(int index) { if (index < propOffset) { diff --git a/src/declarative/qml/qdeclarativevmemetaobject_p.h b/src/declarative/qml/qdeclarativevmemetaobject_p.h index 4fc3269..20ca80b 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject_p.h +++ b/src/declarative/qml/qdeclarativevmemetaobject_p.h @@ -121,6 +121,8 @@ public: void registerInterceptor(int index, int valueIndex, QDeclarativePropertyValueInterceptor *interceptor); QScriptValue vmeMethod(int index); + int vmeMethodLineNumber(int index); + void setVmeMethod(int index, const QScriptValue &); QScriptValue vmeProperty(int index); void setVMEProperty(int index, const QScriptValue &); |