From e133073a7e8ae28b0b0d5c0c29ea7941767744d8 Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Wed, 14 Dec 2011 12:50:41 +0100 Subject: [PATCH] QV8DebugService: Add breakaftercompile Add breakaftercompile command that will set the v8::DebugBreak() whenever a new script is compiled. Change-Id: Id9027066826b6de621058d3170fa628463ef0152 Reviewed-by: Kai Koehne --- src/declarative/debugger/qv8debugservice.cpp | 25 ++++++++++++++----- src/declarative/debugger/qv8debugservice_p.h | 3 ++- .../tst_qdeclarativedebugjs.cpp | 28 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/declarative/debugger/qv8debugservice.cpp b/src/declarative/debugger/qv8debugservice.cpp index 39c991f..2fd54dc 100644 --- a/src/declarative/debugger/qv8debugservice.cpp +++ b/src/declarative/debugger/qv8debugservice.cpp @@ -41,7 +41,6 @@ #include "qv8debugservice_p.h" #include "qdeclarativedebugservice_p_p.h" -#include #include #include @@ -55,6 +54,7 @@ const char *V8_DEBUGGER_KEY_DISCONNECT = "disconnect"; const char *V8_DEBUGGER_KEY_REQUEST = "v8request"; const char *V8_DEBUGGER_KEY_V8MESSAGE = "v8message"; const char *V8_DEBUGGER_KEY_BREAK_ON_SIGNAL = "breakonsignal"; +const char *V8_DEBUGGER_KEY_BREAK_AFTER_COMPILE = "breakaftercompile"; QT_BEGIN_NAMESPACE @@ -82,7 +82,7 @@ void DebugMessageHandler(const v8::Debug::Message& message) if (event != v8::Break && event != v8::Exception && event != v8::AfterCompile && event != v8::BeforeCompile) return; - v8ServiceInstancePtr->debugMessageHandler(QJSConverter::toString(message.GetJSON())); + v8ServiceInstancePtr->debugMessageHandler(QJSConverter::toString(message.GetJSON()), event); } class QV8DebugServicePrivate : public QDeclarativeDebugServicePrivate @@ -90,6 +90,7 @@ class QV8DebugServicePrivate : public QDeclarativeDebugServicePrivate public: QV8DebugServicePrivate() : connectReceived(false) + , breakAfterCompile(false) , engine(0) { } @@ -99,7 +100,7 @@ public: static QByteArray packMessage(const QString &type, const QString &message = QString()); bool connectReceived; - + bool breakAfterCompile; QMutex initializeMutex; QStringList breakOnSignals; const QV8Engine *engine; @@ -149,13 +150,18 @@ void QV8DebugService::setEngine(const QV8Engine *engine) //V8 DEBUG SERVICE PROTOCOL //
//
: "V8DEBUG" -// : ("connect", "disconnect", "interrupt", "v8request", "v8message", "breakonsignal") +// : ("connect", "disconnect", "interrupt", "v8request", "v8message", +// "breakonsignal", "breakaftercompile") // : For _v8request_ and _v8message_ it is the JSON request string. // For _breakonsignal_ it is +// For _breakaftercompile_ it is // Empty string for the other types -void QV8DebugService::debugMessageHandler(const QString &message) +void QV8DebugService::debugMessageHandler(const QString &message, const v8::DebugEvent &event) { + Q_D(QV8DebugService); sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_V8MESSAGE), message)); + if (event == v8::AfterCompile && d->breakAfterCompile) + scheduledDebugBreak(true); } @@ -211,9 +217,11 @@ void QV8DebugService::statusChanged(QDeclarativeDebugService::Status newStatus) //V8 DEBUG SERVICE PROTOCOL //
//
: "V8DEBUG" -// : ("connect", "disconnect", "interrupt", "v8request", "v8message", "breakonsignal") +// : ("connect", "disconnect", "interrupt", "v8request", "v8message", +// "breakonsignal", "breakaftercompile") // : For _v8request_ and _v8message_ it is the JSON request string. // For _breakonsignal_ it is +// For _breakaftercompile_ it is // Empty string for the other types // executed in the debugger thread void QV8DebugService::messageReceived(const QByteArray &message) @@ -259,6 +267,11 @@ void QV8DebugService::messageReceived(const QByteArray &message) else d->breakOnSignals.removeOne(signalName); sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_BREAK_ON_SIGNAL))); + + } else if (type == V8_DEBUGGER_KEY_BREAK_AFTER_COMPILE) { + QDataStream rs(data); + rs >> d->breakAfterCompile; + sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_BREAK_AFTER_COMPILE))); } } } diff --git a/src/declarative/debugger/qv8debugservice_p.h b/src/declarative/debugger/qv8debugservice_p.h index 9430f95..923a446 100644 --- a/src/declarative/debugger/qv8debugservice_p.h +++ b/src/declarative/debugger/qv8debugservice_p.h @@ -54,6 +54,7 @@ // #include "qdeclarativedebugservice_p.h" +#include QT_BEGIN_HEADER @@ -74,7 +75,7 @@ public: static QV8DebugService *instance(); static void initialize(const QV8Engine *engine); - void debugMessageHandler(const QString &message); + void debugMessageHandler(const QString &message, const v8::DebugEvent &event); void signalEmitted(const QString &signal); diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp index 8b40b64..0f9da03 100644 --- a/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp @@ -107,6 +107,7 @@ const char *GARBAGECOLLECTOR = "gc"; const char *CONNECT = "connect"; const char *INTERRUPT = "interrupt"; +const char *BREAKAFTERCOMPILE = "breakaftercompile"; const char *REQUEST = "request"; const char *IN = "in"; @@ -172,6 +173,7 @@ private slots: void connect(); void interrupt(); + void breakAfterCompile(); void getVersion(); void getVersionWhenAttaching(); @@ -267,6 +269,7 @@ public: void connect(); void interrupt(); + void breakAfterCompile(bool enabled); void continueDebugging(StepAction stepAction, int stepCount = 1); void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); @@ -297,6 +300,7 @@ signals: void enabled(); void connected(); void interruptRequested(); + void breakAfterCompileRequested(); void result(); void stopped(); @@ -327,6 +331,14 @@ void QJSDebugClient::interrupt() sendMessage(packMessage(INTERRUPT)); } +void QJSDebugClient::breakAfterCompile(bool enabled) +{ + QByteArray request; + QDataStream rs(&request, QIODevice::WriteOnly); + rs << enabled; + sendMessage(packMessage(BREAKAFTERCOMPILE, request)); +} + void QJSDebugClient::continueDebugging(StepAction action, int count) { // { "seq" : , @@ -935,6 +947,10 @@ void QJSDebugClient::messageReceived(const QByteArray &data) event == "exception") emit stopped(); } + + } else if (type == BREAKAFTERCOMPILE) { + emit breakAfterCompileRequested(); + } } } @@ -1051,6 +1067,18 @@ void tst_QDeclarativeDebugJS::interrupt() QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(interruptRequested()))); } +void tst_QDeclarativeDebugJS::breakAfterCompile() +{ + //void breakAfterCompile(bool enabled) + + QVERIFY(init()); + client->breakAfterCompile(true); + client->connect(); + + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(breakAfterCompileRequested()))); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); +} + void tst_QDeclarativeDebugJS::getVersion() { //void version() -- 2.7.4