From 91b6d329fe74143c75ccd53b1e6a2a129c113a7a Mon Sep 17 00:00:00 2001 From: Olivier Goffart <olivier.goffart@nokia.com> Date: Fri, 23 Jul 2010 18:40:12 +0200 Subject: [PATCH] QML JS Debugger: Break when there is an uncaught exception --- src/plugins/debugger/qml/qmlengine.cpp | 12 ++++++++++++ src/tools/qml/qmlobserver/jsdebuggeragent.cpp | 16 +++++++++------- src/tools/qml/qmlobserver/jsdebuggeragent.h | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index 1e41f08c0bc..884ca96b600 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -59,6 +59,7 @@ #include <QtGui/QMainWindow> #include <QtGui/QMessageBox> #include <QtGui/QToolTip> +#include <QtGui/QTextDocument> #include <QtNetwork/QTcpSocket> #include <QtNetwork/QHostAddress> @@ -75,6 +76,7 @@ # define XSDEBUG(s) qDebug() << s + namespace Debugger { namespace Internal { @@ -656,6 +658,16 @@ void QmlEngine::messageReceived(const QByteArray &message) Debugger::DebuggerUISwitcher *uiSwitcher = Debugger::DebuggerUISwitcher::instance(); uiSwitcher->setActiveLanguage("C++"); + bool becauseOfexception; + stream >> becauseOfexception; + if (becauseOfexception) { + QString error; + stream >> error; + + QString msg = tr("<p>An Uncaught Exception occured in <i>%1</i>:</p><p>%2</p>").arg(stackFrames.value(0).file, Qt::escape(error)); + showMessageBox(QMessageBox::Information, tr("Uncaught Exception"), msg); + } + } else if (command == "RESULT") { WatchData data; diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp index e6007676e99..8681624a057 100644 --- a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp +++ b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp @@ -303,9 +303,9 @@ void JSDebuggerAgent::exceptionThrow(qint64 scriptId, bool hasHandler) { Q_UNUSED(scriptId); - Q_UNUSED(exception); - Q_UNUSED(hasHandler); -/* ... */ +// qDebug() << Q_FUNC_INFO << exception.toString() << hasHandler; + if (!hasHandler && state != Stopped) + stopped(true, exception); } /*! @@ -427,7 +427,7 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message) QDeclarativeDebugService::messageReceived(message); } -void JSDebuggerAgent::stopped() +void JSDebuggerAgent::stopped(bool becauseOfException, const QScriptValue& exception) { knownObjectIds.clear(); state = Stopped; @@ -464,12 +464,14 @@ void JSDebuggerAgent::stopped() QList<JSAgentWatchData> locals = getLocals(engine()->currentContext()); - // Clear any exceptions occurred during locals evaluation. - engine()->clearExceptions(); + if (!becauseOfException) { + // Clear any exceptions occurred during locals evaluation. + engine()->clearExceptions(); + } QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("STOPPED") << backtrace << watches << locals; + rs << QByteArray("STOPPED") << backtrace << watches << locals << becauseOfException << exception.toString(); sendMessage(reply); loop.exec(QEventLoop::ExcludeUserInputEvents); diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.h b/src/tools/qml/qmlobserver/jsdebuggeragent.h index 93d4b75095c..acd7b18c92f 100644 --- a/src/tools/qml/qmlobserver/jsdebuggeragent.h +++ b/src/tools/qml/qmlobserver/jsdebuggeragent.h @@ -54,6 +54,7 @@ // #include <QtScript/qscriptengineagent.h> +#include <QtScript/QScriptValue> #include <QtCore/QEventLoop> #include <QtCore/QSet> #include <private/qdeclarativedebugservice_p.h> @@ -118,7 +119,7 @@ private: int stepCount; void continueExec(); - void stopped(); + void stopped(bool becauseOfException = false, const QScriptValue &exception = QScriptValue()); void recordKnownObjects(const QList<JSAgentWatchData> &); -- GitLab