2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-06-09 16:13:47 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2010-06-09 16:13:47 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-06-09 16:13:47 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-06-09 16:13:47 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-06-09 16:13:47 +02:00
|
|
|
|
|
|
|
|
#include "qmlengine.h"
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
#include "interactiveinterpreter.h"
|
|
|
|
|
#include "qmlinspectoradapter.h"
|
2012-04-18 14:20:54 +02:00
|
|
|
#include "qmlinspectoragent.h"
|
2015-07-08 13:14:03 +02:00
|
|
|
#include "qmlv8debuggerclientconstants.h"
|
|
|
|
|
#include "qmlengineutils.h"
|
2010-06-09 16:13:47 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
#include <debugger/breakhandler.h>
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <debugger/debuggeractions.h>
|
|
|
|
|
#include <debugger/debuggercore.h>
|
|
|
|
|
#include <debugger/debuggerinternalconstants.h>
|
2014-10-17 13:40:04 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <debugger/debuggerstringutils.h>
|
|
|
|
|
#include <debugger/debuggertooltipmanager.h>
|
2015-07-08 13:14:03 +02:00
|
|
|
#include <debugger/sourcefileshandler.h>
|
|
|
|
|
#include <debugger/stackhandler.h>
|
2015-02-26 17:19:57 +01:00
|
|
|
#include <debugger/threaddata.h>
|
2015-07-08 13:14:03 +02:00
|
|
|
#include <debugger/watchhandler.h>
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <debugger/watchwindow.h>
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/helpmanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/applicationlauncher.h>
|
2014-10-17 13:40:04 +02:00
|
|
|
|
2011-11-30 15:23:02 +01:00
|
|
|
#include <qmljseditor/qmljseditorconstants.h>
|
2012-02-28 17:30:15 +01:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2012-10-08 13:17:10 +02:00
|
|
|
#include <qmljs/consolemanagerinterface.h>
|
2010-07-01 11:48:43 +02:00
|
|
|
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
#include <texteditor/texteditor.h>
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-15 17:49:04 +02:00
|
|
|
#include <utils/treemodel.h>
|
2015-07-08 13:14:03 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2011-11-30 15:23:02 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
2014-10-17 13:40:04 +02:00
|
|
|
#include <QDockWidget>
|
2015-07-08 13:14:03 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPlainTextEdit>
|
2015-07-08 13:14:03 +02:00
|
|
|
#include <QTimer>
|
2010-07-01 11:48:43 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
#define DEBUG_QML 0
|
2010-06-09 16:13:47 +02:00
|
|
|
#if DEBUG_QML
|
|
|
|
|
# define SDEBUG(s) qDebug() << s
|
|
|
|
|
#else
|
|
|
|
|
# define SDEBUG(s)
|
|
|
|
|
#endif
|
|
|
|
|
# define XSDEBUG(s) qDebug() << s
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
#define CB(callback) [this](const QVariantMap &r) { callback(r); }
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace QmlDebug;
|
2012-02-28 17:30:15 +01:00
|
|
|
using namespace QmlJS;
|
2015-07-08 13:14:03 +02:00
|
|
|
using namespace TextEditor;
|
2015-07-15 17:49:04 +02:00
|
|
|
using namespace Utils;
|
2011-01-12 14:26:50 +01:00
|
|
|
|
2010-06-09 16:13:47 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
enum Exceptions
|
2014-06-04 14:45:10 +02:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
NoExceptions,
|
|
|
|
|
UncaughtExceptions,
|
|
|
|
|
AllExceptions
|
|
|
|
|
};
|
2014-06-04 14:45:10 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
enum StepAction
|
2012-02-28 17:30:15 +01:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
Continue,
|
|
|
|
|
StepIn,
|
|
|
|
|
StepOut,
|
|
|
|
|
Next
|
|
|
|
|
};
|
2012-02-28 17:30:15 +01:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
struct QmlV8ObjectData
|
|
|
|
|
{
|
|
|
|
|
int handle;
|
|
|
|
|
QByteArray name;
|
|
|
|
|
QByteArray type;
|
|
|
|
|
QVariant value;
|
|
|
|
|
QVariantList properties;
|
|
|
|
|
};
|
2012-02-28 17:30:15 +01:00
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
typedef std::function<void(const QVariantMap &)> QmlCallback;
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
struct LookupData
|
|
|
|
|
{
|
|
|
|
|
QByteArray iname;
|
|
|
|
|
QString name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef QMultiHash<int, LookupData> LookupItems; // id -> (iname, exp)
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
class QmlEnginePrivate : QmlDebugClient
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QmlEnginePrivate(QmlEngine *engine_, QmlDebugConnection *connection_)
|
|
|
|
|
: QmlDebugClient(QLatin1String("V8Debugger"), connection_),
|
|
|
|
|
engine(engine_),
|
|
|
|
|
inspectorAdapter(engine, connection_),
|
|
|
|
|
connection(connection_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void sendMessage(const QByteArray &msg);
|
|
|
|
|
void messageReceived(const QByteArray &data);
|
|
|
|
|
void stateChanged(State state);
|
|
|
|
|
|
|
|
|
|
void continueDebugging(StepAction stepAction);
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
void evaluate(const QString expr, const QmlCallback &cb);
|
|
|
|
|
void lookup(const LookupItems &items);
|
2015-07-14 16:24:26 +02:00
|
|
|
void backtrace();
|
2015-07-14 16:59:46 +02:00
|
|
|
void updateLocals();
|
2015-07-10 11:06:27 +02:00
|
|
|
void scope(int number, int frameNumber = -1);
|
2015-07-08 13:14:03 +02:00
|
|
|
void scripts(int types = 4, const QList<int> ids = QList<int>(),
|
|
|
|
|
bool includeSource = false, const QVariant filter = QVariant());
|
|
|
|
|
|
|
|
|
|
void setBreakpoint(const QString type, const QString target,
|
|
|
|
|
bool enabled = true,int line = 0, int column = 0,
|
|
|
|
|
const QString condition = QString(), int ignoreCount = -1);
|
|
|
|
|
void clearBreakpoint(int breakpoint);
|
|
|
|
|
void setExceptionBreak(Exceptions type, bool enabled = false);
|
|
|
|
|
|
|
|
|
|
void flushSendBuffer();
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void handleBacktrace(const QVariantMap &response);
|
|
|
|
|
void handleLookup(const QVariantMap &response);
|
2015-07-14 16:59:46 +02:00
|
|
|
void handleExecuteDebuggerCommand(const QVariantMap &response);
|
2015-07-16 14:12:16 +02:00
|
|
|
void handleEvaluateExpression(const QVariantMap &response, const QByteArray &iname, const QString &expr);
|
2015-07-14 16:24:26 +02:00
|
|
|
void handleFrame(const QVariantMap &response);
|
|
|
|
|
void handleScope(const QVariantMap &response);
|
|
|
|
|
void handleVersion(const QVariantMap &response);
|
2015-07-13 13:36:28 +02:00
|
|
|
StackFrame extractStackFrame(const QVariant &bodyVal);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
bool canEvaluateScript(const QString &script);
|
|
|
|
|
void updateScriptSource(const QString &fileName, int lineOffset, int columnOffset, const QString &source);
|
2015-07-10 13:06:00 +02:00
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void runCommand(const DebuggerCommand &command, const QmlCallback &cb = QmlCallback());
|
2015-07-10 13:06:00 +02:00
|
|
|
void runDirectCommand(const QByteArray &type, const QByteArray &msg = QByteArray());
|
2012-02-28 17:30:15 +01:00
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
void clearRefs() { refVals.clear(); }
|
|
|
|
|
void memorizeRefs(const QVariant &refs);
|
|
|
|
|
QmlV8ObjectData extractData(const QVariant &data) const;
|
|
|
|
|
void insertSubItems(WatchItem *parent, const QVariantList &properties);
|
2015-07-14 16:59:46 +02:00
|
|
|
void checkForFinishedUpdate();
|
2015-07-13 13:36:28 +02:00
|
|
|
ConsoleItem *constructLogItemTree(ConsoleItem *parent, const QmlV8ObjectData &objectData);
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
public:
|
2015-07-13 13:36:28 +02:00
|
|
|
QHash<int, QmlV8ObjectData> refVals; // The mapping of target object handles to retrieved values.
|
2015-07-08 13:14:03 +02:00
|
|
|
int sequence = -1;
|
|
|
|
|
QmlEngine *engine;
|
|
|
|
|
QHash<BreakpointModelId, int> breakpoints;
|
|
|
|
|
QHash<int, BreakpointModelId> breakpointsSync;
|
|
|
|
|
QList<int> breakpointsTemp;
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
LookupItems currentlyLookingUp; // Id -> inames
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
//Cache
|
|
|
|
|
QList<int> currentFrameScopes;
|
|
|
|
|
QHash<int, int> stackIndexLookup;
|
|
|
|
|
|
|
|
|
|
StepAction previousStepAction = Continue;
|
|
|
|
|
|
|
|
|
|
QList<QByteArray> sendBuffer;
|
|
|
|
|
|
|
|
|
|
QHash<QString, QTextDocument*> sourceDocuments;
|
|
|
|
|
QHash<QString, QWeakPointer<BaseTextEditor> > sourceEditors;
|
|
|
|
|
InteractiveInterpreter interpreter;
|
|
|
|
|
ApplicationLauncher applicationLauncher;
|
|
|
|
|
QmlInspectorAdapter inspectorAdapter;
|
|
|
|
|
QmlOutputParser outputParser;
|
|
|
|
|
|
|
|
|
|
QTimer noDebugOutputTimer;
|
|
|
|
|
QHash<QString,Breakpoint> pendingBreakpoints;
|
|
|
|
|
QList<quint32> queryIds;
|
|
|
|
|
bool retryOnConnectFail = false;
|
|
|
|
|
bool automaticConnect = false;
|
|
|
|
|
|
|
|
|
|
QTimer connectionTimer;
|
|
|
|
|
QmlDebug::QmlDebugConnection *connection;
|
|
|
|
|
QmlDebug::QDebugMessageClient *msgClient = 0;
|
2015-07-14 16:24:26 +02:00
|
|
|
|
|
|
|
|
QHash<int, QmlCallback> callbackForToken;
|
2012-02-28 17:30:15 +01:00
|
|
|
};
|
2010-09-13 13:30:35 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
static void updateDocument(IDocument *document, const QTextDocument *textDocument)
|
2012-10-08 13:17:10 +02:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
if (auto baseTextDocument = qobject_cast<TextDocument *>(document))
|
|
|
|
|
baseTextDocument->document()->setPlainText(textDocument->toPlainText());
|
2012-10-08 13:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2010-06-09 16:13:47 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// QmlEngine
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngine *masterEngine)
|
2015-07-08 13:14:03 +02:00
|
|
|
: DebuggerEngine(startParameters),
|
|
|
|
|
d(new QmlEnginePrivate(this, new QmlDebugConnection(this)))
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2010-08-24 15:35:46 +02:00
|
|
|
setObjectName(QLatin1String("QmlEngine"));
|
2011-07-28 17:04:35 +02:00
|
|
|
|
2012-11-27 17:16:57 +01:00
|
|
|
if (masterEngine)
|
|
|
|
|
setMasterEngine(masterEngine);
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
connect(stackHandler(), &StackHandler::stackChanged,
|
|
|
|
|
this, &QmlEngine::updateCurrentContext);
|
|
|
|
|
connect(stackHandler(), &StackHandler::currentIndexChanged,
|
|
|
|
|
this, &QmlEngine::updateCurrentContext);
|
|
|
|
|
connect(inspectorView(), SIGNAL(currentIndexChanged(QModelIndex)),
|
2012-02-15 12:35:43 +01:00
|
|
|
SLOT(updateCurrentContext()));
|
2015-07-08 13:14:03 +02:00
|
|
|
connect(d->inspectorAdapter.agent(), &QmlInspectorAgent::expressionResult,
|
|
|
|
|
this, &QmlEngine::expressionEvaluated);
|
|
|
|
|
|
|
|
|
|
connect(&d->applicationLauncher, &ApplicationLauncher::processExited,
|
|
|
|
|
this, &QmlEngine::disconnected);
|
|
|
|
|
connect(&d->applicationLauncher, &ApplicationLauncher::appendMessage,
|
|
|
|
|
this, &QmlEngine::appendMessage);
|
|
|
|
|
connect(&d->applicationLauncher, &ApplicationLauncher::processStarted,
|
|
|
|
|
&d->noDebugOutputTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
|
|
|
|
|
|
|
|
|
|
d->outputParser.setNoOutputText(ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput());
|
|
|
|
|
connect(&d->outputParser, &QmlOutputParser::waitingForConnectionOnPort,
|
|
|
|
|
this, &QmlEngine::beginConnection);
|
|
|
|
|
connect(&d->outputParser, &QmlOutputParser::noOutputMessage,
|
|
|
|
|
this, [this] { tryToConnect(); });
|
|
|
|
|
connect(&d->outputParser, &QmlOutputParser::errorMessage,
|
|
|
|
|
this, &QmlEngine::appStartupFailed);
|
2011-10-31 16:42:31 +01:00
|
|
|
|
2012-05-09 14:56:04 +02:00
|
|
|
// Only wait 8 seconds for the 'Waiting for connection' on application output,
|
|
|
|
|
// then just try to connect (application output might be redirected / blocked)
|
2015-07-08 13:14:03 +02:00
|
|
|
d->noDebugOutputTimer.setSingleShot(true);
|
|
|
|
|
d->noDebugOutputTimer.setInterval(8000);
|
|
|
|
|
connect(&d->noDebugOutputTimer, SIGNAL(timeout()), this, SLOT(tryToConnect()));
|
2012-02-15 12:35:43 +01:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
if (auto mmIface = ModelManagerInterface::instance()) {
|
|
|
|
|
connect(mmIface, &ModelManagerInterface::documentUpdated,
|
|
|
|
|
this, &QmlEngine::documentUpdated);
|
2012-10-08 13:17:10 +02:00
|
|
|
}
|
2012-03-14 15:28:01 +01:00
|
|
|
// we won't get any debug output
|
2012-03-16 12:55:00 +01:00
|
|
|
if (startParameters.useTerminal) {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->noDebugOutputTimer.setInterval(0);
|
|
|
|
|
d->retryOnConnectFail = true;
|
|
|
|
|
d->automaticConnect = true;
|
2012-03-16 12:55:00 +01:00
|
|
|
}
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
if (auto consoleManager = ConsoleManagerInterface::instance())
|
|
|
|
|
consoleManager->setScriptEvaluator(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d->connectionTimer.setInterval(4000);
|
|
|
|
|
d->connectionTimer.setSingleShot(true);
|
|
|
|
|
connect(&d->connectionTimer, &QTimer::timeout,
|
|
|
|
|
this, &QmlEngine::checkConnectionState);
|
|
|
|
|
|
|
|
|
|
connect(d->connection, &QmlDebugConnection::stateMessage,
|
|
|
|
|
this, &QmlEngine::showConnectionStateMessage);
|
|
|
|
|
connect(d->connection, &QmlDebugConnection::errorMessage,
|
|
|
|
|
this, &QmlEngine::showConnectionErrorMessage);
|
|
|
|
|
connect(d->connection, &QmlDebugConnection::error,
|
|
|
|
|
this, &QmlEngine::connectionErrorOccurred);
|
|
|
|
|
connect(d->connection, &QmlDebugConnection::opened,
|
|
|
|
|
&d->connectionTimer, &QTimer::stop);
|
|
|
|
|
connect(d->connection, &QmlDebugConnection::opened,
|
|
|
|
|
this, &QmlEngine::connectionEstablished);
|
|
|
|
|
connect(d->connection, &QmlDebugConnection::closed,
|
|
|
|
|
this, &QmlEngine::disconnected);
|
|
|
|
|
|
|
|
|
|
d->msgClient = new QDebugMessageClient(d->connection);
|
|
|
|
|
connect(d->msgClient, &QDebugMessageClient::newState,
|
|
|
|
|
this, &QmlEngine::clientStateChanged);
|
|
|
|
|
connect(d->msgClient, &QDebugMessageClient::message,
|
|
|
|
|
this, &appendDebugOutput);
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlEngine::~QmlEngine()
|
2011-07-06 19:07:38 +02:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
QSet<IDocument *> documentsToClose;
|
2011-11-30 15:23:02 +01:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
QHash<QString, QWeakPointer<BaseTextEditor> >::iterator iter;
|
|
|
|
|
for (iter = d->sourceEditors.begin(); iter != d->sourceEditors.end(); ++iter) {
|
|
|
|
|
QWeakPointer<BaseTextEditor> textEditPtr = iter.value();
|
2011-11-30 15:23:02 +01:00
|
|
|
if (textEditPtr)
|
2014-08-15 16:23:32 +02:00
|
|
|
documentsToClose << textEditPtr.data()->document();
|
2011-11-30 15:23:02 +01:00
|
|
|
}
|
2015-07-08 13:14:03 +02:00
|
|
|
EditorManager::closeDocuments(documentsToClose.toList());
|
|
|
|
|
|
|
|
|
|
delete d;
|
2011-07-06 19:07:38 +02:00
|
|
|
}
|
2010-08-18 13:54:12 +02:00
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void QmlEngine::setupInferior()
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2012-01-13 15:00:04 +01:00
|
|
|
notifyInferiorSetupOk();
|
2012-03-22 13:00:56 +01:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
if (d->automaticConnect)
|
2012-03-22 13:00:56 +01:00
|
|
|
beginConnection();
|
2010-07-09 17:07:59 +02:00
|
|
|
}
|
2010-07-05 11:28:38 +02:00
|
|
|
|
2011-04-15 12:59:44 +02:00
|
|
|
void QmlEngine::appendMessage(const QString &msg, Utils::OutputFormat /* format */)
|
2010-12-03 16:18:50 +01:00
|
|
|
{
|
2011-02-21 17:01:40 +01:00
|
|
|
showMessage(msg, AppOutput); // FIXME: Redirect to RunControl
|
2010-12-03 16:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
void QmlEngine::connectionEstablished()
|
|
|
|
|
{
|
|
|
|
|
attemptBreakpointSynchronization();
|
|
|
|
|
|
2011-10-19 17:49:24 +02:00
|
|
|
if (state() == EngineRunRequested)
|
|
|
|
|
notifyEngineRunAndInferiorRunOk();
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
2010-11-15 17:09:28 +01:00
|
|
|
|
2012-03-14 15:28:01 +01:00
|
|
|
void QmlEngine::tryToConnect(quint16 port)
|
|
|
|
|
{
|
2012-03-16 12:55:00 +01:00
|
|
|
showMessage(QLatin1String("QML Debugger: No application output received in time, trying to connect ..."), LogStatus);
|
2015-07-08 13:14:03 +02:00
|
|
|
d->retryOnConnectFail = true;
|
2012-06-12 10:48:54 +02:00
|
|
|
if (state() == EngineRunRequested) {
|
|
|
|
|
if (isSlaveEngine()) {
|
|
|
|
|
// Probably cpp is being debugged and hence we did not get the output yet.
|
2013-04-10 15:03:02 +02:00
|
|
|
if (!masterEngine()->isDying()) {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->noDebugOutputTimer.setInterval(4000);
|
|
|
|
|
d->noDebugOutputTimer.start();
|
2013-04-10 15:03:02 +02:00
|
|
|
}
|
2012-06-12 10:48:54 +02:00
|
|
|
else
|
|
|
|
|
appStartupFailed(tr("No application output received in time"));
|
|
|
|
|
} else {
|
|
|
|
|
beginConnection(port);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->automaticConnect = true;
|
2012-06-12 10:48:54 +02:00
|
|
|
}
|
2012-03-14 15:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-21 15:47:55 +01:00
|
|
|
void QmlEngine::beginConnection(quint16 port)
|
2011-07-28 10:38:39 +02:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
d->noDebugOutputTimer.stop();
|
2012-03-22 13:00:56 +01:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
if (state() != EngineRunRequested && d->retryOnConnectFail)
|
2012-03-22 13:00:56 +01:00
|
|
|
return;
|
|
|
|
|
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, return);
|
2012-03-22 13:00:56 +01:00
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
QString host = runParameters().qmlServerAddress;
|
2012-11-06 15:46:19 +01:00
|
|
|
// Use localhost as default
|
|
|
|
|
if (host.isEmpty())
|
|
|
|
|
host = QLatin1String("localhost");
|
|
|
|
|
|
2013-07-11 12:04:34 +02:00
|
|
|
/*
|
|
|
|
|
* Let plugin-specific code override the port printed by the application. This is necessary
|
|
|
|
|
* in the case of port forwarding, when the port the application listens on is not the same that
|
|
|
|
|
* we want to connect to.
|
|
|
|
|
* NOTE: It is still necessary to wait for the output in that case, because otherwise we cannot
|
|
|
|
|
* be sure that the port is already open. The usual method of trying to connect repeatedly
|
|
|
|
|
* will not work, because the intermediate port is already open. So the connection
|
|
|
|
|
* will be accepted on that port but the forwarding to the target port will fail and
|
|
|
|
|
* the connection will be closed again (instead of returning the "connection refused"
|
|
|
|
|
* error that we expect).
|
|
|
|
|
*/
|
2015-05-27 13:59:56 +02:00
|
|
|
if (runParameters().qmlServerPort > 0)
|
|
|
|
|
port = runParameters().qmlServerPort;
|
2013-07-11 12:04:34 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
if (!d->connection || d->connection->isOpen())
|
|
|
|
|
return;
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
d->connection->connectToHost(host, port);
|
|
|
|
|
|
|
|
|
|
//A timeout to check the connection state
|
|
|
|
|
d->connectionTimer.start();
|
|
|
|
|
}
|
2013-07-11 12:04:34 +02:00
|
|
|
|
2012-03-14 15:33:33 +01:00
|
|
|
void QmlEngine::connectionStartupFailed()
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
if (d->retryOnConnectFail) {
|
2012-03-16 12:55:00 +01:00
|
|
|
// retry after 3 seconds ...
|
|
|
|
|
QTimer::singleShot(3000, this, SLOT(beginConnection()));
|
2012-03-14 15:28:01 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2011-10-13 15:32:42 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
QMessageBox *infoBox = new QMessageBox(ICore::mainWindow());
|
2011-02-24 10:03:44 +01:00
|
|
|
infoBox->setIcon(QMessageBox::Critical);
|
|
|
|
|
infoBox->setWindowTitle(tr("Qt Creator"));
|
2012-03-14 15:33:33 +01:00
|
|
|
infoBox->setText(tr("Could not connect to the in-process QML debugger."
|
|
|
|
|
"\nDo you want to retry?"));
|
|
|
|
|
infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel |
|
|
|
|
|
QMessageBox::Help);
|
|
|
|
|
infoBox->setDefaultButton(QMessageBox::Retry);
|
2011-02-24 10:03:44 +01:00
|
|
|
infoBox->setModal(true);
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
connect(infoBox, &QDialog::finished,
|
|
|
|
|
this, &QmlEngine::errorMessageBoxFinished);
|
2011-02-24 10:03:44 +01:00
|
|
|
|
|
|
|
|
infoBox->show();
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-14 15:33:33 +01:00
|
|
|
void QmlEngine::appStartupFailed(const QString &errorMessage)
|
|
|
|
|
{
|
2014-03-18 12:55:26 +01:00
|
|
|
QString error = tr("Could not connect to the in-process QML debugger."
|
|
|
|
|
"\n%1").arg(errorMessage);
|
|
|
|
|
|
|
|
|
|
if (isMasterEngine()) {
|
2015-07-08 13:14:03 +02:00
|
|
|
QMessageBox *infoBox = new QMessageBox(ICore::mainWindow());
|
2014-03-18 12:55:26 +01:00
|
|
|
infoBox->setIcon(QMessageBox::Critical);
|
|
|
|
|
infoBox->setWindowTitle(tr("Qt Creator"));
|
|
|
|
|
infoBox->setText(error);
|
|
|
|
|
infoBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Help);
|
|
|
|
|
infoBox->setDefaultButton(QMessageBox::Ok);
|
2015-07-08 13:14:03 +02:00
|
|
|
connect(infoBox, &QDialog::finished,
|
|
|
|
|
this, &QmlEngine::errorMessageBoxFinished);
|
2014-03-18 12:55:26 +01:00
|
|
|
infoBox->show();
|
|
|
|
|
} else {
|
|
|
|
|
showMessage(error, StatusBar);
|
|
|
|
|
}
|
2012-03-14 15:33:33 +01:00
|
|
|
|
|
|
|
|
notifyEngineRunFailed();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-23 13:03:22 +01:00
|
|
|
void QmlEngine::errorMessageBoxFinished(int result)
|
2011-02-24 10:03:44 +01:00
|
|
|
{
|
|
|
|
|
switch (result) {
|
2011-02-16 14:35:26 +01:00
|
|
|
case QMessageBox::Retry: {
|
2011-07-28 10:38:39 +02:00
|
|
|
beginConnection();
|
2011-02-16 14:35:26 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QMessageBox::Help: {
|
2015-07-08 13:14:03 +02:00
|
|
|
HelpManager::handleHelpRequest(QLatin1String("qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html"));
|
2011-02-24 10:03:44 +01:00
|
|
|
// fall through
|
2011-02-16 14:35:26 +01:00
|
|
|
}
|
|
|
|
|
default:
|
2011-10-19 17:49:24 +02:00
|
|
|
if (state() == InferiorRunOk) {
|
|
|
|
|
notifyInferiorSpontaneousStop();
|
|
|
|
|
notifyInferiorIll();
|
2012-03-14 15:33:33 +01:00
|
|
|
} else if (state() == EngineRunRequested) {
|
2012-02-23 13:03:22 +01:00
|
|
|
notifyEngineRunFailed();
|
2011-10-19 17:49:24 +02:00
|
|
|
}
|
2011-02-16 14:37:37 +01:00
|
|
|
break;
|
2011-02-16 14:35:26 +01:00
|
|
|
}
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
void QmlEngine::filterApplicationMessage(const QString &output, int /*channel*/) const
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
d->outputParser.processOutput(output);
|
2011-02-21 17:01:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::showMessage(const QString &msg, int channel, int timeout) const
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (channel == AppOutput || channel == AppError)
|
2015-07-08 13:14:03 +02:00
|
|
|
filterApplicationMessage(msg, channel);
|
2011-02-21 17:01:40 +01:00
|
|
|
DebuggerEngine::showMessage(msg, channel, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-30 15:23:02 +01:00
|
|
|
void QmlEngine::gotoLocation(const Location &location)
|
|
|
|
|
{
|
|
|
|
|
const QString fileName = location.fileName();
|
2013-04-25 13:05:27 +02:00
|
|
|
if (QUrl(fileName).isLocalFile()) {
|
2011-11-30 15:23:02 +01:00
|
|
|
// internal file from source files -> show generated .js
|
2015-07-08 13:14:03 +02:00
|
|
|
QTC_ASSERT(d->sourceDocuments.contains(fileName), return);
|
2011-11-30 15:23:02 +01:00
|
|
|
|
2011-12-21 10:22:55 +01:00
|
|
|
QString titlePattern = tr("JS Source for %1").arg(fileName);
|
2013-07-09 12:14:33 +02:00
|
|
|
//Check if there are open documents with the same title
|
2015-07-08 13:14:03 +02:00
|
|
|
foreach (IDocument *document, DocumentModel::openedDocuments()) {
|
2013-07-09 12:14:33 +02:00
|
|
|
if (document->displayName() == titlePattern) {
|
2015-07-08 13:14:03 +02:00
|
|
|
EditorManager::activateEditorForDocument(document);
|
2013-07-09 12:14:33 +02:00
|
|
|
return;
|
2011-12-21 10:22:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-08 13:14:03 +02:00
|
|
|
IEditor *editor = EditorManager::openEditorWithContents(
|
2013-07-09 12:14:33 +02:00
|
|
|
QmlJSEditor::Constants::C_QMLJSEDITOR_ID, &titlePattern);
|
|
|
|
|
if (editor) {
|
|
|
|
|
editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, true);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (auto plainTextEdit = qobject_cast<QPlainTextEdit *>(editor->widget()))
|
2013-07-09 12:14:33 +02:00
|
|
|
plainTextEdit->setReadOnly(true);
|
2015-07-08 13:14:03 +02:00
|
|
|
updateDocument(editor->document(), d->sourceDocuments.value(fileName));
|
2011-12-21 10:39:54 +01:00
|
|
|
}
|
2011-11-30 15:23:02 +01:00
|
|
|
} else {
|
|
|
|
|
DebuggerEngine::gotoLocation(location);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-15 17:09:28 +01:00
|
|
|
void QmlEngine::closeConnection()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
if (d->connectionTimer.isActive()) {
|
|
|
|
|
d->connectionTimer.stop();
|
|
|
|
|
} else {
|
|
|
|
|
if (d->connection)
|
|
|
|
|
d->connection->close();
|
|
|
|
|
}
|
2010-11-15 17:09:28 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void QmlEngine::runEngine()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2012-02-01 09:03:05 +01:00
|
|
|
if (!isSlaveEngine()) {
|
2015-05-27 13:59:56 +02:00
|
|
|
if (runParameters().startMode == AttachToRemoteServer)
|
2015-07-08 13:14:03 +02:00
|
|
|
d->noDebugOutputTimer.start();
|
2015-05-27 13:59:56 +02:00
|
|
|
else if (runParameters().startMode == AttachToRemoteProcess)
|
2012-02-27 10:04:34 +01:00
|
|
|
beginConnection();
|
|
|
|
|
else
|
2012-02-01 09:03:05 +01:00
|
|
|
startApplicationLauncher();
|
2012-03-14 15:28:01 +01:00
|
|
|
} else {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->noDebugOutputTimer.start();
|
2012-02-01 09:03:05 +01:00
|
|
|
}
|
2010-11-15 17:09:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::startApplicationLauncher()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
if (!d->applicationLauncher.isRunning()) {
|
2011-03-30 13:14:30 +02:00
|
|
|
appendMessage(tr("Starting %1 %2").arg(
|
2015-05-27 13:59:56 +02:00
|
|
|
QDir::toNativeSeparators(runParameters().executable),
|
|
|
|
|
runParameters().processArgs)
|
2011-03-30 13:14:30 +02:00
|
|
|
+ QLatin1Char('\n')
|
2011-04-15 12:59:44 +02:00
|
|
|
, Utils::NormalMessageFormat);
|
2015-07-08 13:14:03 +02:00
|
|
|
d->applicationLauncher.start(ApplicationLauncher::Gui,
|
2015-05-27 13:59:56 +02:00
|
|
|
runParameters().executable,
|
|
|
|
|
runParameters().processArgs);
|
2010-08-18 13:54:12 +02:00
|
|
|
}
|
2010-11-15 17:09:28 +01:00
|
|
|
}
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2010-11-15 17:09:28 +01:00
|
|
|
void QmlEngine::stopApplicationLauncher()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
if (d->applicationLauncher.isRunning()) {
|
|
|
|
|
disconnect(&d->applicationLauncher, &ApplicationLauncher::processExited,
|
|
|
|
|
this, &QmlEngine::disconnected);
|
|
|
|
|
d->applicationLauncher.stop();
|
2010-11-15 17:09:28 +01:00
|
|
|
}
|
2010-08-18 13:54:12 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-18 19:21:27 +02:00
|
|
|
void QmlEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
|
2010-09-16 17:08:07 +02:00
|
|
|
{
|
2014-09-18 19:21:27 +02:00
|
|
|
DebuggerEngine::notifyEngineRemoteSetupFinished(result);
|
2012-06-12 10:48:54 +02:00
|
|
|
|
2014-09-18 19:21:27 +02:00
|
|
|
if (result.success) {
|
|
|
|
|
if (result.qmlServerPort != InvalidPort)
|
2015-05-27 13:59:56 +02:00
|
|
|
runParameters().qmlServerPort = result.qmlServerPort;
|
2010-09-16 17:08:07 +02:00
|
|
|
|
2014-09-18 19:21:27 +02:00
|
|
|
notifyEngineSetupOk();
|
2012-01-31 13:23:05 +01:00
|
|
|
|
2014-09-18 19:21:27 +02:00
|
|
|
// The remote setup can take while especialy with mixed debugging.
|
|
|
|
|
// Just waiting for 8 seconds is not enough. Increase the timeout
|
|
|
|
|
// to 60 s
|
2015-07-08 13:14:03 +02:00
|
|
|
// In case we get an output the d->outputParser will start the connection.
|
|
|
|
|
d->noDebugOutputTimer.setInterval(60000);
|
2014-09-18 19:21:27 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (isMasterEngine())
|
2015-07-08 13:14:03 +02:00
|
|
|
QMessageBox::critical(ICore::dialogParent(), tr("Failed to start application"),
|
2014-09-18 19:21:27 +02:00
|
|
|
tr("Application startup failed: %1").arg(result.reason));
|
|
|
|
|
notifyEngineSetupFailed();
|
|
|
|
|
}
|
2010-09-16 17:08:07 +02:00
|
|
|
}
|
|
|
|
|
|
2013-04-18 10:01:05 +02:00
|
|
|
void QmlEngine::notifyEngineRemoteServerRunning(const QByteArray &serverChannel, int pid)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
quint16 qmlPort = serverChannel.toUInt(&ok);
|
|
|
|
|
if (ok)
|
2015-05-27 13:59:56 +02:00
|
|
|
runParameters().qmlServerPort = qmlPort;
|
2013-04-18 10:01:05 +02:00
|
|
|
else
|
2013-06-05 09:39:11 +02:00
|
|
|
qWarning() << tr("QML debugging port not set: Unable to convert %1 to unsigned int.").arg(QString::fromLatin1(serverChannel));
|
2013-04-18 10:01:05 +02:00
|
|
|
|
|
|
|
|
DebuggerEngine::notifyEngineRemoteServerRunning(serverChannel, pid);
|
|
|
|
|
notifyEngineSetupOk();
|
|
|
|
|
|
|
|
|
|
// The remote setup can take a while especially with mixed debugging.
|
2015-07-08 13:14:03 +02:00
|
|
|
// Just waiting for 8 seconds is not enough. Increase the timeout to 60 s.
|
|
|
|
|
// In case we get an output the d->outputParser will start the connection.
|
|
|
|
|
d->noDebugOutputTimer.setInterval(60000);
|
2013-04-18 10:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void QmlEngine::shutdownInferior()
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
// End session.
|
2015-07-10 13:06:00 +02:00
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "disconnect",
|
|
|
|
|
// }
|
|
|
|
|
d->runCommand(DISCONNECT);
|
2011-08-17 13:42:41 +02:00
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (isSlaveEngine())
|
2010-11-15 17:09:28 +01:00
|
|
|
resetLocation();
|
|
|
|
|
stopApplicationLauncher();
|
2012-03-06 09:21:27 +01:00
|
|
|
closeConnection();
|
2011-08-17 13:42:41 +02:00
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
notifyInferiorShutdownOk();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::shutdownEngine()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
clearExceptionSelection();
|
2013-07-16 14:17:32 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
if (auto consoleManager = ConsoleManagerInterface::instance())
|
|
|
|
|
consoleManager->setScriptEvaluator(0);
|
|
|
|
|
d->noDebugOutputTimer.stop();
|
2012-05-10 12:20:13 +02:00
|
|
|
|
|
|
|
|
// double check (ill engine?):
|
2010-11-15 17:09:28 +01:00
|
|
|
stopApplicationLauncher();
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2010-08-10 14:42:44 +02:00
|
|
|
notifyEngineShutdownOk();
|
2010-11-15 17:09:28 +01:00
|
|
|
if (!isSlaveEngine())
|
|
|
|
|
showMessage(QString(), StatusBar);
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-08 18:10:50 +02:00
|
|
|
void QmlEngine::setupEngine()
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2015-05-27 13:59:56 +02:00
|
|
|
if (runParameters().remoteSetupNeeded) {
|
2012-01-13 15:00:04 +01:00
|
|
|
// we need to get the port first
|
2012-01-31 13:23:05 +01:00
|
|
|
notifyEngineRequestRemoteSetup();
|
2012-01-13 15:00:04 +01:00
|
|
|
} else {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->applicationLauncher.setEnvironment(runParameters().environment);
|
|
|
|
|
d->applicationLauncher.setWorkingDirectory(runParameters().workingDirectory);
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2012-01-13 15:00:04 +01:00
|
|
|
// We can't do this in the constructore because runControl() isn't yet defined
|
2015-07-08 13:14:03 +02:00
|
|
|
connect(&d->applicationLauncher, &ApplicationLauncher::bringToForegroundRequested,
|
|
|
|
|
runControl(), &RunControl::bringApplicationToForeground,
|
2012-01-13 15:00:04 +01:00
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
|
|
|
|
|
notifyEngineSetupOk();
|
|
|
|
|
}
|
2010-07-01 11:48:43 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-09 16:13:47 +02:00
|
|
|
void QmlEngine::continueInferior()
|
|
|
|
|
{
|
2010-07-13 08:41:27 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
2015-07-08 13:14:03 +02:00
|
|
|
clearExceptionSelection();
|
|
|
|
|
d->continueDebugging(Continue);
|
2010-07-22 15:31:11 +02:00
|
|
|
resetLocation();
|
2010-07-13 08:41:27 +02:00
|
|
|
notifyInferiorRunRequested();
|
|
|
|
|
notifyInferiorRunOk();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::interruptInferior()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
showMessage(_(INTERRUPT), LogInput);
|
2015-07-10 13:06:00 +02:00
|
|
|
d->runDirectCommand(INTERRUPT);
|
2011-08-17 13:42:41 +02:00
|
|
|
notifyInferiorStopOk();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::executeStep()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
clearExceptionSelection();
|
|
|
|
|
d->continueDebugging(StepIn);
|
2010-07-13 08:41:27 +02:00
|
|
|
notifyInferiorRunRequested();
|
|
|
|
|
notifyInferiorRunOk();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::executeStepI()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
clearExceptionSelection();
|
|
|
|
|
d->continueDebugging(StepIn);
|
2010-07-13 08:41:27 +02:00
|
|
|
notifyInferiorRunRequested();
|
|
|
|
|
notifyInferiorRunOk();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::executeStepOut()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
clearExceptionSelection();
|
|
|
|
|
d->continueDebugging(StepOut);
|
2010-07-13 08:41:27 +02:00
|
|
|
notifyInferiorRunRequested();
|
|
|
|
|
notifyInferiorRunOk();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::executeNext()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
clearExceptionSelection();
|
|
|
|
|
d->continueDebugging(Next);
|
2010-07-13 08:41:27 +02:00
|
|
|
notifyInferiorRunRequested();
|
|
|
|
|
notifyInferiorRunOk();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::executeNextI()
|
|
|
|
|
{
|
2011-10-13 11:10:25 +02:00
|
|
|
executeNext();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-23 10:16:11 +01:00
|
|
|
void QmlEngine::executeRunToLine(const ContextData &data)
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2011-12-22 18:43:09 +01:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
2012-08-28 13:18:50 +02:00
|
|
|
showStatusMessage(tr("Run to line %1 (%2) requested...").arg(data.lineNumber).arg(data.fileName), 5000);
|
2011-12-22 18:43:09 +01:00
|
|
|
resetLocation();
|
2012-02-28 17:30:15 +01:00
|
|
|
ContextData modifiedData = data;
|
|
|
|
|
quint32 line = data.lineNumber;
|
|
|
|
|
quint32 column;
|
|
|
|
|
bool valid;
|
|
|
|
|
if (adjustBreakpointLineAndColumn(data.fileName, &line, &column, &valid))
|
|
|
|
|
modifiedData.lineNumber = line;
|
2015-07-08 13:14:03 +02:00
|
|
|
d->setBreakpoint(QString(_(SCRIPTREGEXP)), modifiedData.fileName,
|
|
|
|
|
true, modifiedData.lineNumber);
|
|
|
|
|
clearExceptionSelection();
|
|
|
|
|
d->continueDebugging(Continue);
|
|
|
|
|
|
2011-12-22 18:43:09 +01:00
|
|
|
notifyInferiorRunRequested();
|
|
|
|
|
notifyInferiorRunOk();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::executeRunToFunction(const QString &functionName)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(functionName)
|
|
|
|
|
XSDEBUG("FIXME: QmlEngine::executeRunToFunction()");
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 10:16:11 +01:00
|
|
|
void QmlEngine::executeJumpToLine(const ContextData &data)
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2011-02-23 10:16:11 +01:00
|
|
|
Q_UNUSED(data)
|
2010-06-09 16:13:47 +02:00
|
|
|
XSDEBUG("FIXME: QmlEngine::executeJumpToLine()");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::activateFrame(int index)
|
|
|
|
|
{
|
2011-10-17 15:23:42 +02:00
|
|
|
if (state() != InferiorStopOk && state() != InferiorUnrunnable)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
stackHandler()->setCurrentIndex(index);
|
2010-12-16 19:06:33 +01:00
|
|
|
gotoLocation(stackHandler()->frames().value(index));
|
2015-07-14 16:59:46 +02:00
|
|
|
|
|
|
|
|
d->updateLocals();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 16:37:57 +02:00
|
|
|
void QmlEngine::selectThread(ThreadId threadId)
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2012-10-19 16:37:57 +02:00
|
|
|
Q_UNUSED(threadId)
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
void QmlEngine::insertBreakpoint(Breakpoint bp)
|
2011-08-17 11:47:42 +02:00
|
|
|
{
|
2015-01-10 01:07:01 +01:00
|
|
|
BreakpointState state = bp.state();
|
|
|
|
|
QTC_ASSERT(state == BreakpointInsertRequested, qDebug() << bp << this << state);
|
|
|
|
|
bp.notifyBreakpointInsertProceeding();
|
2011-08-17 11:47:42 +02:00
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
const BreakpointParameters ¶ms = bp.parameters();
|
2012-02-28 17:30:15 +01:00
|
|
|
quint32 line = params.lineNumber;
|
|
|
|
|
quint32 column = 0;
|
|
|
|
|
if (params.type == BreakpointByFileAndLine) {
|
|
|
|
|
bool valid = false;
|
|
|
|
|
if (!adjustBreakpointLineAndColumn(params.fileName, &line, &column,
|
|
|
|
|
&valid)) {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->pendingBreakpoints.insertMulti(params.fileName, bp);
|
2012-02-28 17:30:15 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!valid)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
if (params.type == BreakpointAtJavaScriptThrow) {
|
|
|
|
|
bp.notifyBreakpointInsertOk();
|
|
|
|
|
d->setExceptionBreak(AllExceptions, params.enabled);
|
|
|
|
|
|
|
|
|
|
} else if (params.type == BreakpointByFileAndLine) {
|
|
|
|
|
d->setBreakpoint(QString(_(SCRIPTREGEXP)), params.fileName,
|
|
|
|
|
params.enabled, line, column,
|
|
|
|
|
QLatin1String(params.condition), params.ignoreCount);
|
|
|
|
|
|
|
|
|
|
} else if (params.type == BreakpointOnQmlSignalEmit) {
|
|
|
|
|
d->setBreakpoint(QString(_(EVENT)), params.functionName, params.enabled);
|
|
|
|
|
bp.notifyBreakpointInsertOk();
|
2011-08-17 11:47:42 +02:00
|
|
|
}
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
d->breakpointsSync.insert(d->sequence, bp.id());
|
2011-08-17 11:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
void QmlEngine::removeBreakpoint(Breakpoint bp)
|
2011-08-17 11:47:42 +02:00
|
|
|
{
|
2015-01-10 01:07:01 +01:00
|
|
|
const BreakpointParameters ¶ms = bp.parameters();
|
2012-02-28 17:30:15 +01:00
|
|
|
if (params.type == BreakpointByFileAndLine &&
|
2015-07-08 13:14:03 +02:00
|
|
|
d->pendingBreakpoints.contains(params.fileName)) {
|
|
|
|
|
auto it = d->pendingBreakpoints.find(params.fileName);
|
|
|
|
|
while (it != d->pendingBreakpoints.end() && it.key() == params.fileName) {
|
2015-01-10 01:07:01 +01:00
|
|
|
if (it.value() == bp.id()) {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->pendingBreakpoints.erase(it);
|
2012-02-28 17:30:15 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2015-01-10 01:07:01 +01:00
|
|
|
++it;
|
2012-02-28 17:30:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
BreakpointState state = bp.state();
|
|
|
|
|
QTC_ASSERT(state == BreakpointRemoveRequested, qDebug() << bp << this << state);
|
|
|
|
|
bp.notifyBreakpointRemoveProceeding();
|
2011-08-17 11:47:42 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
int breakpoint = d->breakpoints.value(bp.id());
|
|
|
|
|
d->breakpoints.remove(bp.id());
|
|
|
|
|
|
|
|
|
|
if (params.type == BreakpointAtJavaScriptThrow)
|
|
|
|
|
d->setExceptionBreak(AllExceptions);
|
|
|
|
|
else if (params.type == BreakpointOnQmlSignalEmit)
|
|
|
|
|
d->setBreakpoint(QString(_(EVENT)), params.functionName, false);
|
|
|
|
|
else
|
|
|
|
|
d->clearBreakpoint(breakpoint);
|
2011-08-17 11:47:42 +02:00
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
if (bp.state() == BreakpointRemoveProceeding)
|
|
|
|
|
bp.notifyBreakpointRemoveOk();
|
2011-08-17 11:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
void QmlEngine::changeBreakpoint(Breakpoint bp)
|
2011-08-17 11:47:42 +02:00
|
|
|
{
|
2015-01-10 01:07:01 +01:00
|
|
|
BreakpointState state = bp.state();
|
|
|
|
|
QTC_ASSERT(state == BreakpointChangeRequested, qDebug() << bp << this << state);
|
|
|
|
|
bp.notifyBreakpointChangeProceeding();
|
2011-08-17 11:47:42 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
const BreakpointParameters ¶ms = bp.parameters();
|
|
|
|
|
|
|
|
|
|
BreakpointResponse br = bp.response();
|
|
|
|
|
if (params.type == BreakpointAtJavaScriptThrow) {
|
|
|
|
|
d->setExceptionBreak(AllExceptions, params.enabled);
|
|
|
|
|
br.enabled = params.enabled;
|
|
|
|
|
bp.setResponse(br);
|
|
|
|
|
} else if (params.type == BreakpointOnQmlSignalEmit) {
|
|
|
|
|
d->setBreakpoint(QString(_(EVENT)), params.functionName, params.enabled);
|
|
|
|
|
br.enabled = params.enabled;
|
|
|
|
|
bp.setResponse(br);
|
2011-08-17 11:47:42 +02:00
|
|
|
} else {
|
2015-07-08 13:14:03 +02:00
|
|
|
//V8 supports only minimalistic changes in breakpoint
|
|
|
|
|
//Remove the breakpoint and add again
|
|
|
|
|
bp.notifyBreakpointChangeOk();
|
|
|
|
|
bp.removeBreakpoint();
|
|
|
|
|
BreakHandler *handler = d->engine->breakHandler();
|
|
|
|
|
handler->appendBreakpoint(params);
|
2011-08-17 11:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
if (bp.state() == BreakpointChangeProceeding)
|
|
|
|
|
bp.notifyBreakpointChangeOk();
|
2011-08-17 11:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-09 16:13:47 +02:00
|
|
|
void QmlEngine::attemptBreakpointSynchronization()
|
|
|
|
|
{
|
2011-08-17 11:47:42 +02:00
|
|
|
if (!stateAcceptsBreakpointChanges()) {
|
|
|
|
|
showMessage(_("BREAKPOINT SYNCHRONIZATION NOT POSSIBLE IN CURRENT STATE"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:33:11 +01:00
|
|
|
BreakHandler *handler = breakHandler();
|
2010-11-23 16:12:16 +01:00
|
|
|
|
2012-03-02 12:24:19 +01:00
|
|
|
DebuggerEngine *bpOwner = isSlaveEngine() ? masterEngine() : this;
|
2015-01-10 01:07:01 +01:00
|
|
|
foreach (Breakpoint bp, handler->unclaimedBreakpoints()) {
|
2010-11-23 16:12:16 +01:00
|
|
|
// Take ownership of the breakpoint. Requests insertion.
|
2015-01-10 01:07:01 +01:00
|
|
|
if (acceptsBreakpoint(bp))
|
|
|
|
|
bp.setEngine(bpOwner);
|
2010-11-23 16:12:16 +01:00
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
foreach (Breakpoint bp, handler->engineBreakpoints(bpOwner)) {
|
|
|
|
|
switch (bp.state()) {
|
2011-08-17 11:47:42 +02:00
|
|
|
case BreakpointNew:
|
|
|
|
|
// Should not happen once claimed.
|
|
|
|
|
QTC_CHECK(false);
|
|
|
|
|
continue;
|
|
|
|
|
case BreakpointInsertRequested:
|
2015-01-10 01:07:01 +01:00
|
|
|
insertBreakpoint(bp);
|
2011-08-17 11:47:42 +02:00
|
|
|
continue;
|
|
|
|
|
case BreakpointChangeRequested:
|
2015-01-10 01:07:01 +01:00
|
|
|
changeBreakpoint(bp);
|
2011-08-17 11:47:42 +02:00
|
|
|
continue;
|
|
|
|
|
case BreakpointRemoveRequested:
|
2015-01-10 01:07:01 +01:00
|
|
|
removeBreakpoint(bp);
|
2011-08-17 11:47:42 +02:00
|
|
|
continue;
|
|
|
|
|
case BreakpointChangeProceeding:
|
|
|
|
|
case BreakpointInsertProceeding:
|
|
|
|
|
case BreakpointRemoveProceeding:
|
|
|
|
|
case BreakpointInserted:
|
|
|
|
|
case BreakpointDead:
|
|
|
|
|
continue;
|
2010-11-30 11:35:17 +01:00
|
|
|
}
|
2015-01-10 01:07:01 +01:00
|
|
|
QTC_ASSERT(false, qDebug() << "UNKNOWN STATE" << bp << state());
|
2010-06-25 14:08:53 +02:00
|
|
|
}
|
|
|
|
|
|
2011-08-17 11:47:42 +02:00
|
|
|
DebuggerEngine::attemptBreakpointSynchronization();
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:07:01 +01:00
|
|
|
bool QmlEngine::acceptsBreakpoint(Breakpoint bp) const
|
2010-10-05 11:01:14 +02:00
|
|
|
{
|
2015-01-10 01:07:01 +01:00
|
|
|
if (!bp.parameters().isCppBreakpoint())
|
2011-09-13 12:47:46 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
//If it is a Cpp Breakpoint query if the type can be also handled by the debugger client
|
|
|
|
|
//TODO: enable setting of breakpoints before start of debug session
|
|
|
|
|
//For now, the event breakpoint can be set after the activeDebuggerClient is known
|
2011-09-28 17:55:48 +02:00
|
|
|
//This is because the older client does not support BreakpointOnQmlSignalHandler
|
2015-07-08 13:14:03 +02:00
|
|
|
BreakpointType type = bp.type();
|
|
|
|
|
return type == BreakpointOnQmlSignalEmit
|
|
|
|
|
|| type == BreakpointByFileAndLine
|
|
|
|
|
|| type == BreakpointAtJavaScriptThrow;
|
2010-10-05 11:01:14 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-09 16:13:47 +02:00
|
|
|
void QmlEngine::loadSymbols(const QString &moduleName)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(moduleName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::loadAllSymbols()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::reloadModules()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-30 15:23:02 +01:00
|
|
|
void QmlEngine::reloadSourceFiles()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
d->scripts(4, QList<int>(), true, QVariant());
|
2011-11-30 15:23:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-15 17:49:04 +02:00
|
|
|
void QmlEngine::updateAll()
|
|
|
|
|
{
|
|
|
|
|
d->updateLocals();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 16:13:47 +02:00
|
|
|
void QmlEngine::requestModuleSymbols(const QString &moduleName)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(moduleName)
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 18:07:11 +02:00
|
|
|
bool QmlEngine::canHandleToolTip(const DebuggerToolTipContext &) const
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2011-10-06 17:38:28 +02:00
|
|
|
// This is processed by QML inspector, which has dependencies to
|
2010-10-27 15:23:30 +02:00
|
|
|
// the qml js editor. Makes life easier.
|
2015-03-06 13:36:42 +01:00
|
|
|
// FIXME: Except that there isn't any attached.
|
2011-02-17 10:08:57 +01:00
|
|
|
return true;
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-19 12:42:53 +01:00
|
|
|
void QmlEngine::assignValueInDebugger(WatchItem *item,
|
2015-07-14 16:59:46 +02:00
|
|
|
const QString &expression, const QVariant &value)
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2012-05-23 14:55:48 +02:00
|
|
|
if (!expression.isEmpty()) {
|
2015-07-08 13:14:03 +02:00
|
|
|
if (item->isInspect() && d->inspectorAdapter.agent()) {
|
2015-07-14 16:59:46 +02:00
|
|
|
d->inspectorAdapter.agent()->assignValue(item, expression, value);
|
2015-07-08 13:14:03 +02:00
|
|
|
} else {
|
|
|
|
|
StackHandler *handler = stackHandler();
|
2015-07-14 16:59:46 +02:00
|
|
|
QString exp = QString(_("%1 = %2;")).arg(expression).arg(value.toString());
|
2015-07-08 13:14:03 +02:00
|
|
|
if (handler->isContentsValid() && handler->currentFrame().isUsable()) {
|
2015-07-14 16:59:46 +02:00
|
|
|
d->evaluate(exp, [this](const QVariantMap &) { d->updateLocals(); });
|
2015-07-08 13:14:03 +02:00
|
|
|
} else {
|
|
|
|
|
showMessage(QString(_("Cannot evaluate %1 in current stack frame")).arg(
|
|
|
|
|
expression), ConsoleOutput);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-22 19:06:26 +02:00
|
|
|
}
|
2010-06-09 16:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-15 17:14:29 +02:00
|
|
|
void QmlEngine::expandItem(const QByteArray &iname)
|
2010-06-09 16:13:47 +02:00
|
|
|
{
|
2015-06-08 18:07:11 +02:00
|
|
|
const WatchItem *item = watchHandler()->findItem(iname);
|
2015-07-15 17:14:29 +02:00
|
|
|
QTC_ASSERT(item, return);
|
2015-07-07 07:39:04 +02:00
|
|
|
|
2015-03-19 12:42:53 +01:00
|
|
|
if (item->isInspect()) {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->inspectorAdapter.agent()->updateWatchData(*item);
|
2012-04-18 14:20:54 +02:00
|
|
|
} else {
|
2015-07-15 17:14:29 +02:00
|
|
|
LookupItems items;
|
|
|
|
|
items.insert(int(item->id), {item->iname, item->name});
|
|
|
|
|
d->lookup(items);
|
2011-02-23 16:09:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 17:14:29 +02:00
|
|
|
void QmlEngine::updateItem(const QByteArray &iname)
|
|
|
|
|
{
|
|
|
|
|
const WatchItem *item = watchHandler()->findItem(iname);
|
|
|
|
|
QTC_ASSERT(item, return);
|
|
|
|
|
|
|
|
|
|
QString exp = QString::fromUtf8(item->exp);
|
2015-07-16 14:12:16 +02:00
|
|
|
d->evaluate(exp, [this, iname, exp](const QVariantMap &response) {
|
|
|
|
|
d->handleEvaluateExpression(response, iname, exp);
|
2015-07-15 17:14:29 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 18:07:11 +02:00
|
|
|
void QmlEngine::selectWatchData(const QByteArray &iname)
|
2012-11-23 13:35:44 +01:00
|
|
|
{
|
2015-03-19 12:42:53 +01:00
|
|
|
const WatchItem *item = watchHandler()->findItem(iname);
|
|
|
|
|
if (item && item->isInspect())
|
2015-07-08 13:14:03 +02:00
|
|
|
d->inspectorAdapter.agent()->watchDataSelected(item->id);
|
2012-11-23 13:35:44 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
static ConsoleItem *constructLogItemTree(ConsoleItem *parent,
|
|
|
|
|
const QVariant &result,
|
|
|
|
|
const QString &key = QString())
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2014-07-28 14:23:52 +02:00
|
|
|
bool sorted = boolSetting(SortStructMembers);
|
2012-10-04 14:54:59 +02:00
|
|
|
if (!result.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
|
2012-10-08 13:17:10 +02:00
|
|
|
ConsoleItem *item = new ConsoleItem(parent);
|
2012-10-04 14:54:59 +02:00
|
|
|
if (result.type() == QVariant::Map) {
|
|
|
|
|
if (key.isEmpty())
|
|
|
|
|
item->setText(_("Object"));
|
|
|
|
|
else
|
|
|
|
|
item->setText(key + _(" : Object"));
|
|
|
|
|
|
|
|
|
|
QMapIterator<QString, QVariant> i(result.toMap());
|
|
|
|
|
while (i.hasNext()) {
|
|
|
|
|
i.next();
|
2012-10-08 13:17:10 +02:00
|
|
|
ConsoleItem *child = constructLogItemTree(item, i.value(), i.key());
|
2012-10-04 14:54:59 +02:00
|
|
|
if (child)
|
|
|
|
|
item->insertChild(child, sorted);
|
|
|
|
|
}
|
|
|
|
|
} else if (result.type() == QVariant::List) {
|
|
|
|
|
if (key.isEmpty())
|
|
|
|
|
item->setText(_("List"));
|
|
|
|
|
else
|
|
|
|
|
item->setText(QString(_("[%1] : List")).arg(key));
|
|
|
|
|
QVariantList resultList = result.toList();
|
|
|
|
|
for (int i = 0; i < resultList.count(); i++) {
|
2012-10-08 13:17:10 +02:00
|
|
|
ConsoleItem *child = constructLogItemTree(item, resultList.at(i),
|
2012-10-04 14:54:59 +02:00
|
|
|
QString::number(i));
|
|
|
|
|
if (child)
|
|
|
|
|
item->insertChild(child, sorted);
|
|
|
|
|
}
|
|
|
|
|
} else if (result.canConvert(QVariant::String)) {
|
|
|
|
|
item->setText(result.toString());
|
|
|
|
|
} else {
|
|
|
|
|
item->setText(_("Unknown Value"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 16:19:55 +01:00
|
|
|
void QmlEngine::expressionEvaluated(quint32 queryId, const QVariant &result)
|
2012-02-15 12:35:43 +01:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
if (d->queryIds.contains(queryId)) {
|
|
|
|
|
d->queryIds.removeOne(queryId);
|
|
|
|
|
if (auto consoleManager = ConsoleManagerInterface::instance()) {
|
|
|
|
|
if (ConsoleItem *item = constructLogItemTree(consoleManager->rootItem(), result))
|
2012-10-04 14:54:59 +02:00
|
|
|
consoleManager->printToConsolePane(item);
|
|
|
|
|
}
|
2012-03-07 16:19:55 +01:00
|
|
|
}
|
2012-02-15 12:35:43 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-12 20:28:17 +01:00
|
|
|
bool QmlEngine::hasCapability(unsigned cap) const
|
2010-07-16 11:44:29 +02:00
|
|
|
{
|
2012-01-12 20:28:17 +01:00
|
|
|
return cap & (AddWatcherCapability
|
2011-12-22 18:43:09 +01:00
|
|
|
| AddWatcherWhileRunningCapability
|
2012-01-12 20:28:17 +01:00
|
|
|
| RunToLineCapability);
|
2010-07-16 11:44:29 +02:00
|
|
|
/*ReverseSteppingCapability | SnapshotCapability
|
|
|
|
|
| AutoDerefPointersCapability | DisassemblerCapability
|
|
|
|
|
| RegisterCapability | ShowMemoryCapability
|
|
|
|
|
| JumpToLineCapability | ReloadModuleCapability
|
|
|
|
|
| ReloadModuleSymbolsCapability | BreakOnThrowAndCatchCapability
|
|
|
|
|
| ReturnFromFunctionCapability
|
|
|
|
|
| CreateFullBacktraceCapability
|
|
|
|
|
| WatchpointCapability
|
|
|
|
|
| AddWatcherCapability;*/
|
2010-06-25 14:08:53 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-12 10:48:54 +02:00
|
|
|
void QmlEngine::quitDebugger()
|
|
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
d->noDebugOutputTimer.stop();
|
|
|
|
|
d->automaticConnect = false;
|
|
|
|
|
d->retryOnConnectFail = false;
|
2012-06-12 10:48:54 +02:00
|
|
|
DebuggerEngine::quitDebugger();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 14:42:44 +02:00
|
|
|
void QmlEngine::disconnected()
|
|
|
|
|
{
|
2010-11-10 11:39:01 +01:00
|
|
|
showMessage(tr("QML Debugger disconnected."), StatusBar);
|
2010-08-10 14:42:44 +02:00
|
|
|
notifyInferiorExited();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:58:49 +02:00
|
|
|
void QmlEngine::documentUpdated(Document::Ptr doc)
|
2012-02-28 17:30:15 +01:00
|
|
|
{
|
|
|
|
|
QString fileName = doc->fileName();
|
2015-07-08 13:14:03 +02:00
|
|
|
if (d->pendingBreakpoints.contains(fileName)) {
|
|
|
|
|
QList<Breakpoint> bps = d->pendingBreakpoints.values(fileName);
|
|
|
|
|
d->pendingBreakpoints.remove(fileName);
|
2015-01-10 01:07:01 +01:00
|
|
|
foreach (const Breakpoint bp, bps)
|
|
|
|
|
insertBreakpoint(bp);
|
2012-02-28 17:30:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 12:35:43 +01:00
|
|
|
void QmlEngine::updateCurrentContext()
|
|
|
|
|
{
|
2012-10-05 13:42:14 +02:00
|
|
|
QString context;
|
|
|
|
|
if (state() == InferiorStopOk) {
|
|
|
|
|
context = stackHandler()->currentFrame().function;
|
|
|
|
|
} else {
|
2015-07-08 13:14:03 +02:00
|
|
|
QModelIndex currentIndex = inspectorView()->currentIndex();
|
2015-03-19 12:42:53 +01:00
|
|
|
const WatchData *currentData = watchHandler()->watchItem(currentIndex);
|
2015-02-26 15:42:30 +01:00
|
|
|
if (!currentData)
|
|
|
|
|
return;
|
2015-03-19 12:42:53 +01:00
|
|
|
const WatchData *parentData = watchHandler()->watchItem(currentIndex.parent());
|
2015-07-08 13:14:03 +02:00
|
|
|
const WatchData *grandParentData = watchHandler()->watchItem(currentIndex.parent().parent());
|
2012-10-05 13:42:14 +02:00
|
|
|
if (currentData->id != parentData->id)
|
|
|
|
|
context = currentData->name;
|
|
|
|
|
else if (parentData->id != grandParentData->id)
|
|
|
|
|
context = parentData->name;
|
|
|
|
|
else
|
|
|
|
|
context = grandParentData->name;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
if (auto consoleManager = ConsoleManagerInterface::instance())
|
2013-10-17 14:52:10 +02:00
|
|
|
consoleManager->setContext(tr("Context:") + QLatin1Char(' ') + context);
|
2012-02-15 12:35:43 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
void QmlEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages languages)
|
2012-02-15 12:35:43 +01:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
if (!(languages & QmlLanguage))
|
2012-02-15 12:35:43 +01:00
|
|
|
return;
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
StackHandler *handler = stackHandler();
|
|
|
|
|
if (handler->isContentsValid() && handler->currentFrame().isUsable()) {
|
2015-07-14 16:59:46 +02:00
|
|
|
d->evaluate(command, CB(d->handleExecuteDebuggerCommand));
|
2015-07-08 13:14:03 +02:00
|
|
|
} else {
|
|
|
|
|
//Currently cannot evaluate if not in a javascript break
|
|
|
|
|
d->engine->showMessage(QString(_("Cannot evaluate %1 in current stack frame")).arg(
|
|
|
|
|
command), ConsoleOutput);
|
|
|
|
|
}
|
2010-08-26 16:02:41 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 13:17:10 +02:00
|
|
|
bool QmlEngine::evaluateScript(const QString &expression)
|
2012-02-15 12:35:43 +01:00
|
|
|
{
|
|
|
|
|
bool didEvaluate = true;
|
2012-10-04 14:54:59 +02:00
|
|
|
// Evaluate expression based on engine state
|
|
|
|
|
// When engine->state() == InferiorStopOk, the expression is sent to debuggerClient.
|
|
|
|
|
if (state() != InferiorStopOk) {
|
2015-07-08 13:14:03 +02:00
|
|
|
QModelIndex currentIndex = inspectorView()->currentIndex();
|
|
|
|
|
QmlInspectorAgent *agent = d->inspectorAdapter.agent();
|
2015-03-19 12:42:53 +01:00
|
|
|
quint32 queryId = agent->queryExpressionResult(watchHandler()->watchItem(currentIndex)->id,
|
2012-10-04 14:54:59 +02:00
|
|
|
expression);
|
|
|
|
|
if (queryId) {
|
2015-07-08 13:14:03 +02:00
|
|
|
d->queryIds.append(queryId);
|
2012-02-15 12:35:43 +01:00
|
|
|
} else {
|
2012-04-18 14:20:54 +02:00
|
|
|
didEvaluate = false;
|
2015-07-08 13:14:03 +02:00
|
|
|
if (auto consoleManager = ConsoleManagerInterface::instance()) {
|
2012-10-08 13:17:10 +02:00
|
|
|
consoleManager->printToConsolePane(ConsoleItem::ErrorType,
|
2012-10-04 14:54:59 +02:00
|
|
|
_("Error evaluating expression."));
|
|
|
|
|
}
|
2012-02-15 12:35:43 +01:00
|
|
|
}
|
2012-10-04 14:54:59 +02:00
|
|
|
} else {
|
|
|
|
|
executeDebuggerCommand(expression, QmlLanguage);
|
2012-02-15 12:35:43 +01:00
|
|
|
}
|
|
|
|
|
return didEvaluate;
|
|
|
|
|
}
|
2010-09-08 13:31:12 +02:00
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
void QmlEnginePrivate::updateScriptSource(const QString &fileName, int lineOffset, int columnOffset,
|
|
|
|
|
const QString &source)
|
2011-11-30 15:23:02 +01:00
|
|
|
{
|
|
|
|
|
QTextDocument *document = 0;
|
2015-07-08 13:14:03 +02:00
|
|
|
if (sourceDocuments.contains(fileName)) {
|
|
|
|
|
document = sourceDocuments.value(fileName);
|
2011-11-30 15:23:02 +01:00
|
|
|
} else {
|
|
|
|
|
document = new QTextDocument(this);
|
2015-07-08 13:14:03 +02:00
|
|
|
sourceDocuments.insert(fileName, document);
|
2011-11-30 15:23:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We're getting an unordered set of snippets that can even interleave
|
|
|
|
|
// Therefore we've to carefully update the existing document
|
|
|
|
|
|
|
|
|
|
QTextCursor cursor(document);
|
|
|
|
|
for (int i = 0; i < lineOffset; ++i) {
|
|
|
|
|
if (!cursor.movePosition(QTextCursor::NextBlock))
|
|
|
|
|
cursor.insertBlock();
|
|
|
|
|
}
|
|
|
|
|
QTC_CHECK(cursor.blockNumber() == lineOffset);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < columnOffset; ++i) {
|
|
|
|
|
if (!cursor.movePosition(QTextCursor::NextCharacter))
|
|
|
|
|
cursor.insertText(QLatin1String(" "));
|
|
|
|
|
}
|
|
|
|
|
QTC_CHECK(cursor.positionInBlock() == columnOffset);
|
|
|
|
|
|
|
|
|
|
QStringList lines = source.split(QLatin1Char('\n'));
|
|
|
|
|
foreach (QString line, lines) {
|
|
|
|
|
if (line.endsWith(QLatin1Char('\r')))
|
|
|
|
|
line.remove(line.size() -1, 1);
|
|
|
|
|
|
|
|
|
|
// line already there?
|
|
|
|
|
QTextCursor existingCursor(cursor);
|
|
|
|
|
existingCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
|
|
|
|
if (existingCursor.selectedText() != line)
|
|
|
|
|
cursor.insertText(line);
|
|
|
|
|
|
|
|
|
|
if (!cursor.movePosition(QTextCursor::NextBlock))
|
|
|
|
|
cursor.insertBlock();
|
|
|
|
|
}
|
2011-12-21 10:39:54 +01:00
|
|
|
|
|
|
|
|
//update open editors
|
|
|
|
|
QString titlePattern = tr("JS Source for %1").arg(fileName);
|
|
|
|
|
//Check if there are open editors with the same title
|
2015-07-08 13:14:03 +02:00
|
|
|
foreach (IDocument *doc, DocumentModel::openedDocuments()) {
|
2013-07-09 12:14:33 +02:00
|
|
|
if (doc->displayName() == titlePattern) {
|
|
|
|
|
updateDocument(doc, document);
|
2011-12-21 10:39:54 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
bool QmlEnginePrivate::canEvaluateScript(const QString &script)
|
2011-12-21 10:39:54 +01:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
interpreter.clearText();
|
|
|
|
|
interpreter.appendText(script);
|
|
|
|
|
return interpreter.canEvaluate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::connectionErrorOccurred(QDebugSupport::Error error)
|
|
|
|
|
{
|
|
|
|
|
// this is only an error if we are already connected and something goes wrong.
|
|
|
|
|
if (isConnected()) {
|
|
|
|
|
if (error == QDebugSupport::RemoteClosedConnectionError)
|
|
|
|
|
showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar);
|
|
|
|
|
|
|
|
|
|
if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits
|
|
|
|
|
notifyInferiorSpontaneousStop();
|
|
|
|
|
notifyInferiorIll();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
d->connectionTimer.stop();
|
|
|
|
|
connectionStartupFailed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::clientStateChanged(QmlDebugClient::State state)
|
|
|
|
|
{
|
|
|
|
|
QString serviceName;
|
|
|
|
|
float version = 0;
|
|
|
|
|
if (QmlDebugClient *client = qobject_cast<QmlDebugClient*>(sender())) {
|
|
|
|
|
serviceName = client->name();
|
|
|
|
|
version = client->remoteVersion();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logServiceStateChange(serviceName, version, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::checkConnectionState()
|
|
|
|
|
{
|
|
|
|
|
if (!isConnected()) {
|
|
|
|
|
closeConnection();
|
|
|
|
|
connectionStartupFailed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlEngine::isConnected() const
|
|
|
|
|
{
|
|
|
|
|
return d->connection->isOpen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::showConnectionStateMessage(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
showMessage(_("QML Debugger: ") + message, LogStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::showConnectionErrorMessage(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
showMessage(_("QML Debugger: ") + message, LogError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::logServiceStateChange(const QString &service, float version,
|
|
|
|
|
QmlDebugClient::State newState)
|
|
|
|
|
{
|
|
|
|
|
switch (newState) {
|
|
|
|
|
case QmlDebugClient::Unavailable: {
|
|
|
|
|
showConnectionStateMessage(_("Status of \"%1\" Version: %2 changed to 'unavailable'.").
|
|
|
|
|
arg(service).arg(QString::number(version)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QmlDebugClient::Enabled: {
|
|
|
|
|
showConnectionStateMessage(_("Status of \"%1\" Version: %2 changed to 'enabled'.").
|
|
|
|
|
arg(service).arg(QString::number(version)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case QmlDebugClient::NotConnected: {
|
|
|
|
|
showConnectionStateMessage(_("Status of \"%1\" Version: %2 changed to 'not connected'.").
|
|
|
|
|
arg(service).arg(QString::number(version)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEngine::logServiceActivity(const QString &service, const QString &logMessage)
|
|
|
|
|
{
|
|
|
|
|
showMessage(service + QLatin1Char(' ') + logMessage, LogDebug);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::continueDebugging(StepAction action)
|
|
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "continue",
|
|
|
|
|
// "arguments" : { "stepaction" : <"in", "next" or "out">,
|
|
|
|
|
// "stepcount" : <number of steps (default 1)>
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(CONTINEDEBUGGING);
|
|
|
|
|
|
|
|
|
|
if (action == StepIn)
|
|
|
|
|
cmd.arg(STEPACTION, IN);
|
|
|
|
|
else if (action == StepOut)
|
|
|
|
|
cmd.arg(STEPACTION, OUT);
|
|
|
|
|
else if (action == Next)
|
|
|
|
|
cmd.arg(STEPACTION, NEXT);
|
|
|
|
|
|
|
|
|
|
runCommand(cmd);
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
previousStepAction = action;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
void QmlEnginePrivate::evaluate(const QString expr, const QmlCallback &cb)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "evaluate",
|
|
|
|
|
// "arguments" : { "expression" : <expression to evaluate>,
|
|
|
|
|
// "frame" : <number>,
|
|
|
|
|
// "global" : <boolean>,
|
|
|
|
|
// "disable_break" : <boolean>,
|
|
|
|
|
// "additional_context" : [
|
|
|
|
|
// { "name" : <name1>, "handle" : <handle1> },
|
|
|
|
|
// { "name" : <name2>, "handle" : <handle2> },
|
|
|
|
|
// ...
|
|
|
|
|
// ]
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(EVALUATE);
|
|
|
|
|
|
|
|
|
|
cmd.arg(EXPRESSION, expr);
|
2015-07-14 16:59:46 +02:00
|
|
|
cmd.arg(FRAME, engine->stackHandler()->currentIndex());
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
runCommand(cmd, cb);
|
|
|
|
|
}
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-16 14:12:16 +02:00
|
|
|
void QmlEnginePrivate::handleEvaluateExpression(const QVariantMap &response,
|
|
|
|
|
const QByteArray &iname,
|
|
|
|
|
const QString &exp)
|
2015-07-14 16:59:46 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "evaluate",
|
|
|
|
|
// "body" : ...
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
QVariant bodyVal = response.value(_(BODY)).toMap();
|
|
|
|
|
QmlV8ObjectData body = extractData(bodyVal);
|
|
|
|
|
WatchHandler *watchHandler = engine->watchHandler();
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
auto item = new WatchItem(iname, exp);
|
|
|
|
|
item->exp = exp.toLatin1();
|
|
|
|
|
item->id = body.handle;
|
|
|
|
|
bool success = response.value(_("success")).toBool();
|
|
|
|
|
if (success) {
|
|
|
|
|
item->type = body.type;
|
|
|
|
|
item->value = body.value.toString();
|
|
|
|
|
item->wantsChildren = body.properties.count();
|
|
|
|
|
} else {
|
|
|
|
|
//Do not set type since it is unknown
|
|
|
|
|
item->setError(body.value.toString());
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
2015-07-14 16:59:46 +02:00
|
|
|
insertSubItems(item, body.properties);
|
2015-07-16 14:12:16 +02:00
|
|
|
watchHandler->insertItem(item);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
void QmlEnginePrivate::lookup(const LookupItems &items)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "lookup",
|
|
|
|
|
// "arguments" : { "handles" : <array of handles>,
|
|
|
|
|
// "includeSource" : <boolean indicating whether
|
|
|
|
|
// the source will be included when
|
|
|
|
|
// script objects are returned>,
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
if (items.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<int> handles = items.keys();
|
|
|
|
|
currentlyLookingUp += items;
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(LOOKUP);
|
|
|
|
|
cmd.arg(HANDLES, handles);
|
2015-07-14 16:24:26 +02:00
|
|
|
runCommand(cmd, CB(handleLookup));
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void QmlEnginePrivate::backtrace()
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "backtrace",
|
|
|
|
|
// "arguments" : { "fromFrame" : <number>
|
|
|
|
|
// "toFrame" : <number>
|
|
|
|
|
// "bottom" : <boolean, set to true if the bottom of the
|
|
|
|
|
// stack is requested>
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(BACKTRACE);
|
2015-07-14 16:24:26 +02:00
|
|
|
runCommand(cmd, CB(handleBacktrace));
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
void QmlEnginePrivate::updateLocals()
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "frame",
|
2015-07-14 16:59:46 +02:00
|
|
|
// "arguments" : { "number" : <frame number> }
|
2015-07-08 13:14:03 +02:00
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(FRAME);
|
2015-07-14 16:59:46 +02:00
|
|
|
cmd.arg(NUMBER, stackIndexLookup.value(engine->stackHandler()->currentIndex()));
|
2015-07-14 16:24:26 +02:00
|
|
|
runCommand(cmd, CB(handleFrame));
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::scope(int number, int frameNumber)
|
|
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "scope",
|
|
|
|
|
// "arguments" : { "number" : <scope number>
|
|
|
|
|
// "frameNumber" : <frame number, optional uses selected
|
|
|
|
|
// frame if missing>
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(SCOPE);
|
|
|
|
|
cmd.arg(NUMBER, number);
|
|
|
|
|
if (frameNumber != -1)
|
|
|
|
|
cmd.arg(FRAMENUMBER, frameNumber);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
runCommand(cmd, CB(handleScope));
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::scripts(int types, const QList<int> ids, bool includeSource,
|
|
|
|
|
const QVariant filter)
|
|
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "scripts",
|
|
|
|
|
// "arguments" : { "types" : <types of scripts to retrieve
|
|
|
|
|
// set bit 0 for native scripts
|
|
|
|
|
// set bit 1 for extension scripts
|
|
|
|
|
// set bit 2 for normal scripts
|
|
|
|
|
// (default is 4 for normal scripts)>
|
|
|
|
|
// "ids" : <array of id's of scripts to return. If this is not specified all scripts are requrned>
|
|
|
|
|
// "includeSource" : <boolean indicating whether the source code should be included for the scripts returned>
|
|
|
|
|
// "filter" : <string or number: filter string or script id.
|
|
|
|
|
// If a number is specified, then only the script with the same number as its script id will be retrieved.
|
|
|
|
|
// If a string is specified, then only scripts whose names contain the filter string will be retrieved.>
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(SCRIPTS);
|
|
|
|
|
cmd.arg(TYPES, types);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
if (ids.count())
|
|
|
|
|
cmd.arg(IDS, ids);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
if (includeSource)
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(INCLUDESOURCE, includeSource);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
if (filter.type() == QVariant::String)
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(FILTER, filter.toString());
|
2015-07-08 13:14:03 +02:00
|
|
|
else if (filter.type() == QVariant::Int)
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(FILTER, filter.toInt());
|
2015-07-08 13:14:03 +02:00
|
|
|
else
|
|
|
|
|
QTC_CHECK(!filter.isValid());
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
runCommand(cmd);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::setBreakpoint(const QString type, const QString target,
|
|
|
|
|
bool enabled, int line, int column,
|
|
|
|
|
const QString condition, int ignoreCount)
|
|
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "setbreakpoint",
|
|
|
|
|
// "arguments" : { "type" : <"function" or "script" or "scriptId" or "scriptRegExp">
|
|
|
|
|
// "target" : <function expression or script identification>
|
|
|
|
|
// "line" : <line in script or function>
|
|
|
|
|
// "column" : <character position within the line>
|
|
|
|
|
// "enabled" : <initial enabled state. True or false, default is true>
|
|
|
|
|
// "condition" : <string with break point condition>
|
|
|
|
|
// "ignoreCount" : <number specifying the number of break point hits to ignore, default value is 0>
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
if (type == _(EVENT)) {
|
|
|
|
|
QByteArray params;
|
|
|
|
|
QmlDebugStream rs(¶ms, QIODevice::WriteOnly);
|
|
|
|
|
rs << target.toUtf8() << enabled;
|
|
|
|
|
engine->showMessage(QString(_("%1 %2 %3")).arg(_(BREAKONSIGNAL), target, enabled ? _("enabled") : _("disabled")), LogInput);
|
2015-07-10 13:06:00 +02:00
|
|
|
runDirectCommand(BREAKONSIGNAL, params);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
} else {
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(SETBREAKPOINT);
|
|
|
|
|
cmd.arg(TYPE, type);
|
|
|
|
|
cmd.arg(ENABLED, enabled);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
if (type == _(SCRIPTREGEXP))
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(TARGET, Utils::FileName::fromString(target).fileName());
|
2015-07-08 13:14:03 +02:00
|
|
|
else
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(TARGET, target);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
if (line)
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(LINE, line - 1);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (column)
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(COLUMN, column - 1);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (!condition.isEmpty())
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(CONDITION, condition);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (ignoreCount != -1)
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(IGNORECOUNT, ignoreCount);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
runCommand(cmd);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::clearBreakpoint(int breakpoint)
|
|
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "clearbreakpoint",
|
|
|
|
|
// "arguments" : { "breakpoint" : <number of the break point to clear>
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(CLEARBREAKPOINT);
|
|
|
|
|
cmd.arg(BREAKPOINT, breakpoint);
|
|
|
|
|
runCommand(cmd);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::setExceptionBreak(Exceptions type, bool enabled)
|
|
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "request",
|
|
|
|
|
// "command" : "setexceptionbreak",
|
|
|
|
|
// "arguments" : { "type" : <string: "all", or "uncaught">,
|
|
|
|
|
// "enabled" : <optional bool: enables the break type if true>
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
DebuggerCommand cmd(SETEXCEPTIONBREAK);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (type == AllExceptions)
|
2015-07-10 11:06:27 +02:00
|
|
|
cmd.arg(TYPE, ALL);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
//Not Supported:
|
|
|
|
|
// else if (type == UncaughtExceptions)
|
|
|
|
|
// cmd.args(TYPE, UNCAUGHT);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
if (enabled)
|
|
|
|
|
cmd.arg(ENABLED, enabled);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-10 11:06:27 +02:00
|
|
|
runCommand(cmd);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
QmlV8ObjectData QmlEnginePrivate::extractData(const QVariant &data) const
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "handle" : <handle>,
|
|
|
|
|
// "type" : <"undefined", "null", "boolean", "number", "string", "object", "function" or "frame">
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// {"handle":<handle>,"type":"undefined"}
|
|
|
|
|
|
|
|
|
|
// {"handle":<handle>,"type":"null"}
|
|
|
|
|
|
|
|
|
|
// { "handle":<handle>,
|
|
|
|
|
// "type" : <"boolean", "number" or "string">
|
|
|
|
|
// "value" : <JSON encoded value>
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// {"handle":7,"type":"boolean","value":true}
|
|
|
|
|
|
|
|
|
|
// {"handle":8,"type":"number","value":42}
|
|
|
|
|
|
|
|
|
|
// { "handle" : <handle>,
|
|
|
|
|
// "type" : "object",
|
|
|
|
|
// "className" : <Class name, ECMA-262 property [[Class]]>,
|
|
|
|
|
// "constructorFunction" : {"ref":<handle>},
|
|
|
|
|
// "protoObject" : {"ref":<handle>},
|
|
|
|
|
// "prototypeObject" : {"ref":<handle>},
|
|
|
|
|
// "properties" : [ {"name" : <name>,
|
|
|
|
|
// "ref" : <handle>
|
|
|
|
|
// },
|
|
|
|
|
// ...
|
|
|
|
|
// ]
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// { "handle" : <handle>,
|
|
|
|
|
// "type" : "function",
|
|
|
|
|
// "className" : "Function",
|
|
|
|
|
// "constructorFunction" : {"ref":<handle>},
|
|
|
|
|
// "protoObject" : {"ref":<handle>},
|
|
|
|
|
// "prototypeObject" : {"ref":<handle>},
|
|
|
|
|
// "name" : <function name>,
|
|
|
|
|
// "inferredName" : <inferred function name for anonymous functions>
|
|
|
|
|
// "source" : <function source>,
|
|
|
|
|
// "script" : <reference to function script>,
|
|
|
|
|
// "scriptId" : <id of function script>,
|
|
|
|
|
// "position" : <function begin position in script>,
|
|
|
|
|
// "line" : <function begin source line in script>,
|
|
|
|
|
// "column" : <function begin source column in script>,
|
|
|
|
|
// "properties" : [ {"name" : <name>,
|
|
|
|
|
// "ref" : <handle>
|
|
|
|
|
// },
|
|
|
|
|
// ...
|
|
|
|
|
// ]
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
QmlV8ObjectData objectData;
|
|
|
|
|
const QVariantMap dataMap = data.toMap();
|
|
|
|
|
|
|
|
|
|
objectData.name = dataMap.value(_(NAME)).toByteArray();
|
|
|
|
|
|
|
|
|
|
if (dataMap.contains(_(REF))) {
|
|
|
|
|
objectData.handle = dataMap.value(_(REF)).toInt();
|
2015-07-13 13:36:28 +02:00
|
|
|
if (refVals.contains(objectData.handle)) {
|
2015-07-13 13:36:28 +02:00
|
|
|
QmlV8ObjectData data = refVals.value(objectData.handle);
|
2015-07-08 13:14:03 +02:00
|
|
|
objectData.type = data.type;
|
|
|
|
|
objectData.value = data.value;
|
|
|
|
|
objectData.properties = data.properties;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
objectData.handle = dataMap.value(_(HANDLE)).toInt();
|
|
|
|
|
QString type = dataMap.value(_(TYPE)).toString();
|
|
|
|
|
|
|
|
|
|
if (type == _("undefined")) {
|
|
|
|
|
objectData.type = QByteArray("undefined");
|
|
|
|
|
objectData.value = QVariant(_("undefined"));
|
|
|
|
|
|
|
|
|
|
} else if (type == _("null")) {
|
|
|
|
|
objectData.type = QByteArray("null");
|
|
|
|
|
objectData.value= QVariant(_("null"));
|
|
|
|
|
|
|
|
|
|
} else if (type == _("boolean")) {
|
|
|
|
|
objectData.type = QByteArray("boolean");
|
|
|
|
|
objectData.value = dataMap.value(_(VALUE));
|
|
|
|
|
|
|
|
|
|
} else if (type == _("number")) {
|
|
|
|
|
objectData.type = QByteArray("number");
|
|
|
|
|
objectData.value = dataMap.value(_(VALUE));
|
|
|
|
|
|
|
|
|
|
} else if (type == _("string")) {
|
|
|
|
|
objectData.type = QByteArray("string");
|
|
|
|
|
objectData.value = dataMap.value(_(VALUE));
|
|
|
|
|
|
|
|
|
|
} else if (type == _("object")) {
|
|
|
|
|
objectData.type = QByteArray("object");
|
|
|
|
|
objectData.value = dataMap.value(_("className"));
|
|
|
|
|
objectData.properties = dataMap.value(_("properties")).toList();
|
|
|
|
|
|
|
|
|
|
} else if (type == _("function")) {
|
|
|
|
|
objectData.type = QByteArray("function");
|
|
|
|
|
objectData.value = dataMap.value(_(NAME));
|
|
|
|
|
objectData.properties = dataMap.value(_("properties")).toList();
|
|
|
|
|
|
|
|
|
|
} else if (type == _("script")) {
|
|
|
|
|
objectData.type = QByteArray("script");
|
|
|
|
|
objectData.value = dataMap.value(_(NAME));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return objectData;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void QmlEnginePrivate::runCommand(const DebuggerCommand &command, const QmlCallback &cb)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
2015-07-10 11:06:27 +02:00
|
|
|
QByteArray msg = "{\"seq\":" + QByteArray::number(++sequence) + ","
|
|
|
|
|
+ "\"type\":\"request\","
|
|
|
|
|
+ "\"command\":\"" + command.function + "\","
|
|
|
|
|
+ "\"arguments\":{" + command.arguments() + "}}";
|
2015-07-14 16:24:26 +02:00
|
|
|
if (cb)
|
|
|
|
|
callbackForToken[sequence] = cb;
|
|
|
|
|
|
2015-07-10 13:06:00 +02:00
|
|
|
runDirectCommand(V8REQUEST, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::runDirectCommand(const QByteArray &type, const QByteArray &msg)
|
|
|
|
|
{
|
|
|
|
|
// Leave item as variable, serialization depends on it.
|
|
|
|
|
QByteArray cmd = V8DEBUG;
|
2011-11-30 15:23:02 +01:00
|
|
|
|
2015-07-10 13:06:00 +02:00
|
|
|
engine->showMessage(QString::fromLatin1("%1 %2").arg(_(type), _(msg)), LogInput);
|
2015-07-10 11:06:27 +02:00
|
|
|
|
|
|
|
|
QByteArray request;
|
|
|
|
|
QmlDebugStream rs(&request, QIODevice::WriteOnly);
|
|
|
|
|
rs << cmd << type << msg;
|
|
|
|
|
sendMessage(request);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
void QmlEnginePrivate::memorizeRefs(const QVariant &refs)
|
|
|
|
|
{
|
|
|
|
|
if (refs.isValid()) {
|
|
|
|
|
foreach (const QVariant &ref, refs.toList()) {
|
|
|
|
|
const QVariantMap refData = ref.toMap();
|
|
|
|
|
int handle = refData.value(_(HANDLE)).toInt();
|
2015-07-13 13:36:28 +02:00
|
|
|
refVals[handle] = extractData(refData);
|
2015-07-13 13:36:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
void QmlEnginePrivate::messageReceived(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
QmlDebugStream ds(data);
|
|
|
|
|
QByteArray command;
|
|
|
|
|
ds >> command;
|
|
|
|
|
|
|
|
|
|
if (command == V8DEBUG) {
|
|
|
|
|
QByteArray type;
|
|
|
|
|
QByteArray response;
|
|
|
|
|
ds >> type >> response;
|
|
|
|
|
|
|
|
|
|
engine->showMessage(QLatin1String(type), LogOutput);
|
|
|
|
|
if (type == CONNECT) {
|
|
|
|
|
//debugging session started
|
|
|
|
|
|
|
|
|
|
} else if (type == INTERRUPT) {
|
|
|
|
|
//debug break requested
|
|
|
|
|
|
|
|
|
|
} else if (type == BREAKONSIGNAL) {
|
|
|
|
|
//break on signal handler requested
|
|
|
|
|
|
|
|
|
|
} else if (type == V8MESSAGE) {
|
|
|
|
|
const QString responseString = QLatin1String(response);
|
|
|
|
|
SDEBUG(responseString);
|
|
|
|
|
engine->showMessage(QLatin1String(V8MESSAGE) + QLatin1Char(' ') + responseString, LogOutput);
|
|
|
|
|
|
|
|
|
|
const QVariantMap resp =
|
|
|
|
|
QJsonDocument::fromJson(responseString.toUtf8()).toVariant().toMap();
|
|
|
|
|
|
|
|
|
|
const QString type(resp.value(_(TYPE)).toString());
|
|
|
|
|
|
|
|
|
|
if (type == _("response")) {
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
const QString debugCommand(resp.value(_(COMMAND)).toString());
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
memorizeRefs(resp.value(_(REFS)));
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
bool success = resp.value(_("success")).toBool();
|
|
|
|
|
if (!success) {
|
|
|
|
|
SDEBUG("Request was unsuccessful");
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
int requestSeq = resp.value(_("request_seq")).toInt();
|
|
|
|
|
if (callbackForToken.contains(requestSeq)) {
|
|
|
|
|
callbackForToken[requestSeq](resp);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
} else if (debugCommand == _(DISCONNECT)) {
|
2015-07-08 13:14:03 +02:00
|
|
|
//debugging session ended
|
|
|
|
|
|
|
|
|
|
} else if (debugCommand == _(CONTINEDEBUGGING)) {
|
|
|
|
|
//do nothing, wait for next break
|
|
|
|
|
|
|
|
|
|
} else if (debugCommand == _(SETBREAKPOINT)) {
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "setbreakpoint",
|
|
|
|
|
// "body" : { "type" : <"function" or "script">
|
|
|
|
|
// "breakpoint" : <break point number of the new break point>
|
|
|
|
|
// }
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
int seq = resp.value(_("request_seq")).toInt();
|
|
|
|
|
const QVariantMap breakpointData = resp.value(_(BODY)).toMap();
|
|
|
|
|
int index = breakpointData.value(_("breakpoint")).toInt();
|
|
|
|
|
|
|
|
|
|
if (breakpointsSync.contains(seq)) {
|
|
|
|
|
BreakpointModelId id = breakpointsSync.take(seq);
|
|
|
|
|
breakpoints.insert(id, index);
|
|
|
|
|
|
|
|
|
|
//Is actual position info present? Then breakpoint was
|
|
|
|
|
//accepted
|
|
|
|
|
const QVariantList actualLocations =
|
|
|
|
|
breakpointData.value(_("actual_locations")).toList();
|
|
|
|
|
if (actualLocations.count()) {
|
|
|
|
|
//The breakpoint requested line should be same as
|
|
|
|
|
//actual line
|
|
|
|
|
BreakHandler *handler = engine->breakHandler();
|
|
|
|
|
Breakpoint bp = handler->breakpointById(id);
|
|
|
|
|
if (bp.state() != BreakpointInserted) {
|
|
|
|
|
BreakpointResponse br = bp.response();
|
|
|
|
|
br.lineNumber = breakpointData.value(_("line")).toInt() + 1;
|
|
|
|
|
bp.setResponse(br);
|
|
|
|
|
bp.notifyBreakpointInsertOk();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
breakpointsTemp.append(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (debugCommand == _(CLEARBREAKPOINT)) {
|
|
|
|
|
// DO NOTHING
|
|
|
|
|
|
|
|
|
|
} else if (debugCommand == _(SETEXCEPTIONBREAK)) {
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "setexceptionbreak",
|
|
|
|
|
// "body" : { "type" : <string: "all" or "uncaught" corresponding to the request.>,
|
|
|
|
|
// "enabled" : <bool: true if the break type is currently enabled as a result of the request>
|
|
|
|
|
// }
|
|
|
|
|
// "running" : true
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (debugCommand == _(SCRIPTS)) {
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "scripts",
|
|
|
|
|
// "body" : [ { "name" : <name of the script>,
|
|
|
|
|
// "id" : <id of the script>
|
|
|
|
|
// "lineOffset" : <line offset within the containing resource>
|
|
|
|
|
// "columnOffset" : <column offset within the containing resource>
|
|
|
|
|
// "lineCount" : <number of lines in the script>
|
|
|
|
|
// "data" : <optional data object added through the API>
|
|
|
|
|
// "source" : <source of the script if includeSource was specified in the request>
|
|
|
|
|
// "sourceStart" : <first 80 characters of the script if includeSource was not specified in the request>
|
|
|
|
|
// "sourceLength" : <total length of the script in characters>
|
|
|
|
|
// "scriptType" : <script type (see request for values)>
|
|
|
|
|
// "compilationType" : < How was this script compiled:
|
|
|
|
|
// 0 if script was compiled through the API
|
|
|
|
|
// 1 if script was compiled through eval
|
|
|
|
|
// >
|
|
|
|
|
// "evalFromScript" : <if "compilationType" is 1 this is the script from where eval was called>
|
|
|
|
|
// "evalFromLocation" : { line : < if "compilationType" is 1 this is the line in the script from where eval was called>
|
|
|
|
|
// column : < if "compilationType" is 1 this is the column in the script from where eval was called>
|
|
|
|
|
// ]
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
const QVariantList body = resp.value(_(BODY)).toList();
|
|
|
|
|
|
|
|
|
|
QStringList sourceFiles;
|
|
|
|
|
for (int i = 0; i < body.size(); ++i) {
|
|
|
|
|
const QVariantMap entryMap = body.at(i).toMap();
|
|
|
|
|
const int lineOffset = entryMap.value(QLatin1String("lineOffset")).toInt();
|
|
|
|
|
const int columnOffset = entryMap.value(QLatin1String("columnOffset")).toInt();
|
|
|
|
|
const QString name = entryMap.value(QLatin1String("name")).toString();
|
|
|
|
|
const QString source = entryMap.value(QLatin1String("source")).toString();
|
|
|
|
|
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!sourceFiles.contains(name))
|
|
|
|
|
sourceFiles << name;
|
|
|
|
|
|
|
|
|
|
updateScriptSource(name, lineOffset, columnOffset, source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<QString,QString> files;
|
|
|
|
|
foreach (const QString &file, sourceFiles) {
|
|
|
|
|
QString shortName = file;
|
|
|
|
|
QString fullName = engine->toFileInProject(file);
|
|
|
|
|
files.insert(shortName, fullName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
engine->sourceFilesHandler()->setSourceFiles(files);
|
|
|
|
|
//update open editors
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// DO NOTHING
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (type == _(EVENT)) {
|
|
|
|
|
const QString eventType(resp.value(_(EVENT)).toString());
|
|
|
|
|
|
|
|
|
|
if (eventType == _("break")) {
|
2015-07-13 13:36:28 +02:00
|
|
|
|
|
|
|
|
clearRefs();
|
2015-07-08 13:14:03 +02:00
|
|
|
const QVariantMap breakData = resp.value(_(BODY)).toMap();
|
|
|
|
|
const QString invocationText = breakData.value(_("invocationText")).toString();
|
|
|
|
|
const QString scriptUrl = breakData.value(_("script")).toMap().value(_("name")).toString();
|
|
|
|
|
const QString sourceLineText = breakData.value(_("sourceLineText")).toString();
|
|
|
|
|
|
|
|
|
|
bool inferiorStop = true;
|
|
|
|
|
|
|
|
|
|
QList<int> v8BreakpointIds;
|
|
|
|
|
{
|
|
|
|
|
const QVariantList v8BreakpointIdList = breakData.value(_("breakpoints")).toList();
|
|
|
|
|
foreach (const QVariant &breakpointId, v8BreakpointIdList)
|
|
|
|
|
v8BreakpointIds << breakpointId.toInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!v8BreakpointIds.isEmpty() && invocationText.startsWith(_("[anonymous]()"))
|
|
|
|
|
&& scriptUrl.endsWith(_(".qml"))
|
|
|
|
|
&& sourceLineText.trimmed().startsWith(QLatin1Char('('))) {
|
|
|
|
|
|
|
|
|
|
// we hit most likely the anonymous wrapper function automatically generated for bindings
|
|
|
|
|
// -> relocate the breakpoint to column: 1 and continue
|
|
|
|
|
|
|
|
|
|
int newColumn = sourceLineText.indexOf(QLatin1Char('(')) + 1;
|
|
|
|
|
BreakHandler *handler = engine->breakHandler();
|
|
|
|
|
|
|
|
|
|
foreach (int v8Id, v8BreakpointIds) {
|
|
|
|
|
const BreakpointModelId id = breakpoints.key(v8Id);
|
|
|
|
|
Breakpoint bp = handler->breakpointById(id);
|
|
|
|
|
if (bp.isValid()) {
|
|
|
|
|
const BreakpointParameters ¶ms = bp.parameters();
|
|
|
|
|
|
|
|
|
|
clearBreakpoint(v8Id);
|
|
|
|
|
setBreakpoint(QString(_(SCRIPTREGEXP)),
|
|
|
|
|
params.fileName,
|
|
|
|
|
params.enabled,
|
|
|
|
|
params.lineNumber,
|
|
|
|
|
newColumn,
|
|
|
|
|
QString(QString::fromLatin1(params.condition)),
|
|
|
|
|
params.ignoreCount);
|
|
|
|
|
breakpointsSync.insert(sequence, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continueDebugging(Continue);
|
|
|
|
|
inferiorStop = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Skip debug break if this is an internal function
|
|
|
|
|
if (sourceLineText == _(INTERNAL_FUNCTION)) {
|
|
|
|
|
continueDebugging(previousStepAction);
|
|
|
|
|
inferiorStop = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inferiorStop) {
|
|
|
|
|
//Update breakpoint data
|
|
|
|
|
BreakHandler *handler = engine->breakHandler();
|
|
|
|
|
foreach (int v8Id, v8BreakpointIds) {
|
|
|
|
|
const BreakpointModelId id = breakpoints.key(v8Id);
|
|
|
|
|
Breakpoint bp = handler->breakpointById(id);
|
|
|
|
|
if (bp) {
|
|
|
|
|
BreakpointResponse br = bp.response();
|
|
|
|
|
if (br.functionName.isEmpty()) {
|
|
|
|
|
br.functionName = invocationText;
|
|
|
|
|
bp.setResponse(br);
|
|
|
|
|
}
|
|
|
|
|
if (bp.state() != BreakpointInserted) {
|
|
|
|
|
br.lineNumber = breakData.value(
|
|
|
|
|
_("sourceLine")).toInt() + 1;
|
|
|
|
|
bp.setResponse(br);
|
|
|
|
|
bp.notifyBreakpointInsertOk();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (engine->state() == InferiorRunOk) {
|
|
|
|
|
foreach (const QVariant &breakpointId, v8BreakpointIds) {
|
|
|
|
|
if (breakpointsTemp.contains(breakpointId.toInt()))
|
|
|
|
|
clearBreakpoint(breakpointId.toInt());
|
|
|
|
|
}
|
|
|
|
|
engine->notifyInferiorSpontaneousStop();
|
|
|
|
|
backtrace();
|
|
|
|
|
} else if (engine->state() == InferiorStopOk) {
|
|
|
|
|
backtrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (eventType == _("exception")) {
|
|
|
|
|
const QVariantMap body = resp.value(_(BODY)).toMap();
|
|
|
|
|
int lineNumber = body.value(_("sourceLine")).toInt() + 1;
|
|
|
|
|
|
|
|
|
|
const QVariantMap script = body.value(_("script")).toMap();
|
|
|
|
|
QUrl fileUrl(script.value(_(NAME)).toString());
|
|
|
|
|
QString filePath = engine->toFileInProject(fileUrl);
|
|
|
|
|
|
|
|
|
|
const QVariantMap exception = body.value(_("exception")).toMap();
|
|
|
|
|
QString errorMessage = exception.value(_("text")).toString();
|
|
|
|
|
|
2015-07-09 15:32:56 +02:00
|
|
|
QStringList messages = highlightExceptionCode(lineNumber, filePath, errorMessage);
|
|
|
|
|
foreach (const QString msg, messages)
|
|
|
|
|
engine->showMessage(msg, ConsoleOutput);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
if (engine->state() == InferiorRunOk) {
|
|
|
|
|
engine->notifyInferiorSpontaneousStop();
|
|
|
|
|
backtrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (engine->state() == InferiorStopOk)
|
|
|
|
|
backtrace();
|
|
|
|
|
|
|
|
|
|
} else if (eventType == _("afterCompile")) {
|
|
|
|
|
//Currently break point relocation is disabled.
|
|
|
|
|
//Uncomment the line below when it will be enabled.
|
|
|
|
|
// listBreakpoints();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Sometimes we do not get event type!
|
|
|
|
|
//This is most probably due to a wrong eval expression.
|
|
|
|
|
//Redirect output to console.
|
|
|
|
|
if (eventType.isEmpty()) {
|
2015-07-14 16:59:46 +02:00
|
|
|
QmlV8ObjectData entry;
|
|
|
|
|
entry.type = "string";
|
|
|
|
|
entry.value = resp.value(_("message"));
|
|
|
|
|
if (auto consoleManager = ConsoleManagerInterface::instance()) {
|
|
|
|
|
if (ConsoleItem *item = constructLogItemTree(consoleManager->rootItem(), entry))
|
|
|
|
|
consoleManager->printToConsolePane(item);
|
|
|
|
|
}
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //EVENT
|
|
|
|
|
} //V8MESSAGE
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//DO NOTHING
|
|
|
|
|
}
|
2012-02-15 12:35:43 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void QmlEnginePrivate::handleBacktrace(const QVariantMap &response)
|
2012-02-28 17:30:15 +01:00
|
|
|
{
|
2015-07-08 13:14:03 +02:00
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "backtrace",
|
|
|
|
|
// "body" : { "fromFrame" : <number>
|
|
|
|
|
// "toFrame" : <number>
|
|
|
|
|
// "totalFrames" : <number>
|
|
|
|
|
// "frames" : <array of frames - see frame request for details>
|
|
|
|
|
// }
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
const QVariantMap body = response.value(_(BODY)).toMap();
|
2015-07-08 13:14:03 +02:00
|
|
|
const QVariantList frames = body.value(_("frames")).toList();
|
|
|
|
|
|
|
|
|
|
int fromFrameIndex = body.value(_("fromFrame")).toInt();
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(0 == fromFrameIndex, return);
|
|
|
|
|
|
|
|
|
|
StackHandler *stackHandler = engine->stackHandler();
|
|
|
|
|
StackFrames stackFrames;
|
|
|
|
|
int i = 0;
|
|
|
|
|
stackIndexLookup.clear();
|
|
|
|
|
foreach (const QVariant &frame, frames) {
|
2015-07-13 13:36:28 +02:00
|
|
|
StackFrame stackFrame = extractStackFrame(frame);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (stackFrame.level < 0)
|
|
|
|
|
continue;
|
|
|
|
|
stackIndexLookup.insert(i, stackFrame.level);
|
|
|
|
|
stackFrame.level = i;
|
|
|
|
|
stackFrames << stackFrame;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
stackHandler->setFrames(stackFrames);
|
2015-07-14 16:59:46 +02:00
|
|
|
stackHandler->setCurrentIndex(0);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
updateLocals();
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
StackFrame QmlEnginePrivate::extractStackFrame(const QVariant &bodyVal)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "frame",
|
|
|
|
|
// "body" : { "index" : <frame number>,
|
|
|
|
|
// "receiver" : <frame receiver>,
|
|
|
|
|
// "func" : <function invoked>,
|
|
|
|
|
// "script" : <script for the function>,
|
|
|
|
|
// "constructCall" : <boolean indicating whether the function was called as constructor>,
|
|
|
|
|
// "debuggerFrame" : <boolean indicating whether this is an internal debugger frame>,
|
|
|
|
|
// "arguments" : [ { name: <name of the argument - missing of anonymous argument>,
|
|
|
|
|
// value: <value of the argument>
|
|
|
|
|
// },
|
|
|
|
|
// ... <the array contains all the arguments>
|
|
|
|
|
// ],
|
|
|
|
|
// "locals" : [ { name: <name of the local variable>,
|
|
|
|
|
// value: <value of the local variable>
|
|
|
|
|
// },
|
|
|
|
|
// ... <the array contains all the locals>
|
|
|
|
|
// ],
|
|
|
|
|
// "position" : <source position>,
|
|
|
|
|
// "line" : <source line>,
|
|
|
|
|
// "column" : <source column within the line>,
|
|
|
|
|
// "sourceLineText" : <text for current source line>,
|
|
|
|
|
// "scopes" : [ <array of scopes, see scope request below for format> ],
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
const QVariantMap body = bodyVal.toMap();
|
|
|
|
|
|
|
|
|
|
StackFrame stackFrame;
|
|
|
|
|
stackFrame.level = body.value(_("index")).toInt();
|
|
|
|
|
//Do not insert the frame corresponding to the internal function
|
|
|
|
|
if (body.value(QLatin1String("sourceLineText")) == QLatin1String(INTERNAL_FUNCTION)) {
|
|
|
|
|
stackFrame.level = -1;
|
|
|
|
|
return stackFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
QmlV8ObjectData objectData = extractData(body.value(_("func")));
|
2015-07-08 13:14:03 +02:00
|
|
|
QString functionName = objectData.value.toString();
|
|
|
|
|
if (functionName.isEmpty())
|
|
|
|
|
functionName = tr("Anonymous Function");
|
|
|
|
|
stackFrame.function = functionName;
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
objectData = extractData(body.value(_("script")));
|
2015-07-08 13:14:03 +02:00
|
|
|
stackFrame.file = engine->toFileInProject(objectData.value.toString());
|
|
|
|
|
stackFrame.usable = QFileInfo(stackFrame.file).isReadable();
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
objectData = extractData(body.value(_("receiver")));
|
2015-07-08 13:14:03 +02:00
|
|
|
stackFrame.to = objectData.value.toString();
|
|
|
|
|
|
|
|
|
|
stackFrame.line = body.value(_("line")).toInt() + 1;
|
|
|
|
|
|
|
|
|
|
return stackFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void QmlEnginePrivate::handleFrame(const QVariantMap &response)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "frame",
|
|
|
|
|
// "body" : { "index" : <frame number>,
|
|
|
|
|
// "receiver" : <frame receiver>,
|
|
|
|
|
// "func" : <function invoked>,
|
|
|
|
|
// "script" : <script for the function>,
|
|
|
|
|
// "constructCall" : <boolean indicating whether the function was called as constructor>,
|
|
|
|
|
// "debuggerFrame" : <boolean indicating whether this is an internal debugger frame>,
|
|
|
|
|
// "arguments" : [ { name: <name of the argument - missing of anonymous argument>,
|
|
|
|
|
// value: <value of the argument>
|
|
|
|
|
// },
|
|
|
|
|
// ... <the array contains all the arguments>
|
|
|
|
|
// ],
|
|
|
|
|
// "locals" : [ { name: <name of the local variable>,
|
|
|
|
|
// value: <value of the local variable>
|
|
|
|
|
// },
|
|
|
|
|
// ... <the array contains all the locals>
|
|
|
|
|
// ],
|
|
|
|
|
// "position" : <source position>,
|
|
|
|
|
// "line" : <source line>,
|
|
|
|
|
// "column" : <source column within the line>,
|
|
|
|
|
// "sourceLineText" : <text for current source line>,
|
|
|
|
|
// "scopes" : [ <array of scopes, see scope request below for format> ],
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
2015-07-14 16:59:46 +02:00
|
|
|
QVariantMap body = response.value(_(BODY)).toMap();
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
StackHandler *stackHandler = engine->stackHandler();
|
|
|
|
|
WatchHandler * watchHandler = engine->watchHandler();
|
|
|
|
|
watchHandler->notifyUpdateStarted();
|
|
|
|
|
|
|
|
|
|
const int frameIndex = stackHandler->currentIndex();
|
|
|
|
|
if (frameIndex < 0)
|
|
|
|
|
return;
|
|
|
|
|
const StackFrame frame = stackHandler->currentFrame();
|
|
|
|
|
if (!frame.isUsable())
|
|
|
|
|
return;
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
// Always add a "this" variable
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
2015-07-16 14:12:16 +02:00
|
|
|
QByteArray iname = "local.this";
|
|
|
|
|
QString exp = QLatin1String("this");
|
|
|
|
|
|
|
|
|
|
auto item = new WatchItem(iname, exp);
|
2015-07-14 16:59:46 +02:00
|
|
|
QmlV8ObjectData objectData = extractData(body.value(_("receiver")));
|
2015-07-08 13:14:03 +02:00
|
|
|
item->id = objectData.handle;
|
|
|
|
|
item->type = objectData.type;
|
|
|
|
|
item->value = objectData.value.toString();
|
|
|
|
|
item->setHasChildren(objectData.properties.count());
|
|
|
|
|
// In case of global object, we do not get children
|
|
|
|
|
// Set children nevertheless and query later.
|
|
|
|
|
if (item->value == QLatin1String("global")) {
|
|
|
|
|
item->setHasChildren(true);
|
|
|
|
|
item->id = 0;
|
|
|
|
|
}
|
|
|
|
|
watchHandler->insertItem(item);
|
2015-07-16 14:12:16 +02:00
|
|
|
evaluate(exp, [this, iname, exp](const QVariantMap &response) {
|
|
|
|
|
handleEvaluateExpression(response, iname, exp);
|
|
|
|
|
});
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
currentFrameScopes.clear();
|
|
|
|
|
const QVariantList scopes = body.value(_("scopes")).toList();
|
2015-07-08 13:14:03 +02:00
|
|
|
foreach (const QVariant &scope, scopes) {
|
|
|
|
|
//Do not query for global types (0)
|
|
|
|
|
//Showing global properties increases clutter.
|
|
|
|
|
if (scope.toMap().value(_("type")).toInt() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
int scopeIndex = scope.toMap().value(_("index")).toInt();
|
|
|
|
|
currentFrameScopes.append(scopeIndex);
|
|
|
|
|
this->scope(scopeIndex);
|
|
|
|
|
}
|
|
|
|
|
engine->gotoLocation(stackHandler->currentFrame());
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
// Send watchers list
|
|
|
|
|
if (stackHandler->isContentsValid() && stackHandler->currentFrame().isUsable()) {
|
|
|
|
|
QStringList watchers = watchHandler->watchedExpressions();
|
|
|
|
|
foreach (const QString &exp, watchers) {
|
2015-07-16 14:12:16 +02:00
|
|
|
const QByteArray iname = watchHandler->watcherName(exp.toLatin1());
|
|
|
|
|
evaluate(exp, [this, iname, exp](const QVariantMap &response) {
|
|
|
|
|
handleEvaluateExpression(response, iname, exp);
|
2015-07-14 16:59:46 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Expand locals and watchers that were previously expanded
|
|
|
|
|
LookupItems itemsToLookup;
|
|
|
|
|
foreach (const QByteArray &iname, watchHandler->expandedINames()) {
|
|
|
|
|
const WatchItem *item = watchHandler->findItem(iname);
|
|
|
|
|
if (item && item->isLocal())
|
|
|
|
|
itemsToLookup.insert(int(item->id), {item->iname, item->name});
|
|
|
|
|
}
|
|
|
|
|
lookup(itemsToLookup);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void QmlEnginePrivate::handleScope(const QVariantMap &response)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "scope",
|
|
|
|
|
// "body" : { "index" : <index of this scope in the scope chain. Index 0 is the top scope
|
|
|
|
|
// and the global scope will always have the highest index for a
|
|
|
|
|
// frame>,
|
|
|
|
|
// "frameIndex" : <index of the frame>,
|
|
|
|
|
// "type" : <type of the scope:
|
|
|
|
|
// 0: Global
|
|
|
|
|
// 1: Local
|
|
|
|
|
// 2: With
|
|
|
|
|
// 3: Closure
|
|
|
|
|
// 4: Catch >,
|
|
|
|
|
// "object" : <the scope object defining the content of the scope.
|
|
|
|
|
// For local and closure scopes this is transient objects,
|
|
|
|
|
// which has a negative handle value>
|
|
|
|
|
// }
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
2015-07-14 16:24:26 +02:00
|
|
|
QVariantMap bodyMap = response.value(_(BODY)).toMap();
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
//Check if the frameIndex is same as current Stack Index
|
|
|
|
|
StackHandler *stackHandler = engine->stackHandler();
|
|
|
|
|
if (bodyMap.value(_("frameIndex")).toInt() != stackHandler->currentIndex())
|
|
|
|
|
return;
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
QmlV8ObjectData objectData = extractData(bodyMap.value(_("object")));
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
LookupItems itemsToLookup;
|
2015-07-08 13:14:03 +02:00
|
|
|
foreach (const QVariant &property, objectData.properties) {
|
2015-07-13 13:36:28 +02:00
|
|
|
QmlV8ObjectData localData = extractData(property);
|
2015-07-08 13:14:03 +02:00
|
|
|
auto item = new WatchItem;
|
|
|
|
|
item->exp = localData.name;
|
|
|
|
|
//Check for v8 specific local data
|
|
|
|
|
if (item->exp.startsWith('.') || item->exp.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
item->name = QLatin1String(item->exp);
|
|
|
|
|
item->iname = QByteArray("local.") + item->exp;
|
2015-07-14 16:59:46 +02:00
|
|
|
item->id = localData.handle;
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
if (localData.value.isValid()) {
|
|
|
|
|
item->type = localData.type;
|
|
|
|
|
item->value = localData.value.toString();
|
|
|
|
|
item->setHasChildren(localData.properties.count());
|
|
|
|
|
engine->watchHandler()->insertItem(item);
|
2012-10-08 13:17:10 +02:00
|
|
|
} else {
|
2015-07-14 16:59:46 +02:00
|
|
|
itemsToLookup.insert(int(item->id), {item->iname, item->name});
|
2012-10-08 13:17:10 +02:00
|
|
|
}
|
2012-02-28 17:30:15 +01:00
|
|
|
}
|
2015-07-14 16:59:46 +02:00
|
|
|
lookup(itemsToLookup);
|
|
|
|
|
checkForFinishedUpdate();
|
|
|
|
|
}
|
2015-07-08 13:14:03 +02:00
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
void QmlEnginePrivate::checkForFinishedUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (currentlyLookingUp.isEmpty())
|
2015-07-08 13:14:03 +02:00
|
|
|
engine->watchHandler()->notifyUpdateFinished();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
ConsoleItem *QmlEnginePrivate::constructLogItemTree(ConsoleItem *parent,
|
|
|
|
|
const QmlV8ObjectData &objectData)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
bool sorted = boolSetting(SortStructMembers);
|
|
|
|
|
if (!objectData.value.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
|
if (objectData.name.isEmpty())
|
|
|
|
|
text = objectData.value.toString();
|
|
|
|
|
else
|
|
|
|
|
text = QString(_("%1: %2")).arg(QString::fromLatin1(objectData.name))
|
|
|
|
|
.arg(objectData.value.toString());
|
|
|
|
|
|
|
|
|
|
ConsoleItem *item = new ConsoleItem(parent, ConsoleItem::UndefinedType, text);
|
|
|
|
|
|
|
|
|
|
QSet<QString> childrenFetched;
|
|
|
|
|
foreach (const QVariant &property, objectData.properties) {
|
2015-07-13 13:36:28 +02:00
|
|
|
const QmlV8ObjectData childObjectData = extractData(property);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (childObjectData.handle == objectData.handle)
|
|
|
|
|
continue;
|
2015-07-13 13:36:28 +02:00
|
|
|
ConsoleItem *child = constructLogItemTree(item, childObjectData);
|
2015-07-08 13:14:03 +02:00
|
|
|
if (child) {
|
|
|
|
|
const QString text = child->text();
|
|
|
|
|
if (childrenFetched.contains(text))
|
|
|
|
|
continue;
|
|
|
|
|
childrenFetched.insert(text);
|
|
|
|
|
item->insertChild(child, sorted);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 13:36:28 +02:00
|
|
|
void QmlEnginePrivate::insertSubItems(WatchItem *parent, const QVariantList &properties)
|
2015-07-09 15:32:56 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(parent, return);
|
|
|
|
|
foreach (const QVariant &property, properties) {
|
2015-07-13 13:36:28 +02:00
|
|
|
QmlV8ObjectData propertyData = extractData(property);
|
2015-07-09 15:32:56 +02:00
|
|
|
auto item = new WatchItem;
|
|
|
|
|
item->name = QString::fromUtf8(propertyData.name);
|
|
|
|
|
|
|
|
|
|
// Check for v8 specific local data
|
|
|
|
|
if (item->name.startsWith(QLatin1Char('.')) || item->name.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
if (parent->type == "object") {
|
|
|
|
|
if (parent->value == _("Array"))
|
|
|
|
|
item->exp = parent->exp + '[' + item->name.toLatin1() + ']';
|
|
|
|
|
else if (parent->value == _("Object"))
|
|
|
|
|
item->exp = parent->exp + '.' + item->name.toLatin1();
|
|
|
|
|
} else {
|
|
|
|
|
item->exp = item->name.toLatin1();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item->iname = parent->iname + '.' + item->name.toLatin1();
|
|
|
|
|
item->id = propertyData.handle;
|
|
|
|
|
item->type = propertyData.type;
|
|
|
|
|
item->value = propertyData.value.toString();
|
|
|
|
|
item->setHasChildren(propertyData.properties.count());
|
|
|
|
|
parent->appendChild(item);
|
|
|
|
|
}
|
2015-07-15 17:49:04 +02:00
|
|
|
|
|
|
|
|
if (boolSetting(SortStructMembers))
|
|
|
|
|
parent->sortChildren([](const TreeItem *item1, const TreeItem *item2) -> bool {
|
|
|
|
|
return static_cast<const WatchItem *>(item1)->name
|
|
|
|
|
< static_cast<const WatchItem *>(item2)->name;
|
|
|
|
|
});
|
2015-07-09 15:32:56 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:59:46 +02:00
|
|
|
void QmlEnginePrivate::handleExecuteDebuggerCommand(const QVariantMap &response)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
2015-07-14 16:59:46 +02:00
|
|
|
QmlV8ObjectData body = extractData(response.value(_(BODY)));
|
|
|
|
|
if (auto consoleManager = ConsoleManagerInterface::instance()) {
|
|
|
|
|
if (ConsoleItem *item = constructLogItemTree(consoleManager->rootItem(), body))
|
|
|
|
|
consoleManager->printToConsolePane(item);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
2015-07-14 16:59:46 +02:00
|
|
|
// Update the locals
|
|
|
|
|
foreach (int index, currentFrameScopes)
|
|
|
|
|
scope(index);
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void QmlEnginePrivate::handleLookup(const QVariantMap &response)
|
2015-07-08 13:14:03 +02:00
|
|
|
{
|
|
|
|
|
// { "seq" : <number>,
|
|
|
|
|
// "type" : "response",
|
|
|
|
|
// "request_seq" : <number>,
|
|
|
|
|
// "command" : "lookup",
|
|
|
|
|
// "body" : <array of serialized objects indexed using their handle>
|
|
|
|
|
// "running" : <is the VM running after sending this response>
|
|
|
|
|
// "success" : true
|
|
|
|
|
// }
|
2015-07-14 16:24:26 +02:00
|
|
|
const QVariantMap body = response.value(_(BODY)).toMap();
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
QStringList handlesList = body.keys();
|
2015-07-14 16:59:46 +02:00
|
|
|
foreach (const QString &handleString, handlesList) {
|
|
|
|
|
int handle = handleString.toInt();
|
|
|
|
|
QmlV8ObjectData bodyObjectData = extractData(body.value(handleString));
|
|
|
|
|
QList<LookupData> vals = currentlyLookingUp.values(handle);
|
|
|
|
|
currentlyLookingUp.remove(handle);
|
|
|
|
|
foreach (const LookupData &res, vals) {
|
2015-07-08 13:14:03 +02:00
|
|
|
auto item = new WatchItem;
|
2015-07-14 16:59:46 +02:00
|
|
|
item->iname = res.iname;
|
|
|
|
|
item->name = res.name;
|
|
|
|
|
item->id = handle;
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
item->type = bodyObjectData.type;
|
|
|
|
|
item->value = bodyObjectData.value.toString();
|
|
|
|
|
|
|
|
|
|
item->setHasChildren(bodyObjectData.properties.count());
|
2015-07-14 16:59:46 +02:00
|
|
|
insertSubItems(item, bodyObjectData.properties);
|
2015-07-08 13:14:03 +02:00
|
|
|
|
|
|
|
|
engine->watchHandler()->insertItem(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-14 16:59:46 +02:00
|
|
|
checkForFinishedUpdate();
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::stateChanged(State state)
|
|
|
|
|
{
|
|
|
|
|
engine->clientStateChanged(state);
|
|
|
|
|
|
|
|
|
|
if (state == QmlDebugClient::Enabled) {
|
|
|
|
|
/// Start session.
|
|
|
|
|
flushSendBuffer();
|
2015-07-10 13:06:00 +02:00
|
|
|
runDirectCommand(CONNECT);
|
|
|
|
|
runCommand(VERSION); // Only used for logging.
|
2015-07-08 13:14:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 16:24:26 +02:00
|
|
|
void QmlEnginePrivate::handleVersion(const QVariantMap &response)
|
|
|
|
|
{
|
|
|
|
|
engine->showMessage(QString(_("Using V8 Version: %1")).arg(
|
|
|
|
|
response.value(_(BODY)).toMap().
|
|
|
|
|
value(_("V8Version")).toString()), LogOutput);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
void QmlEnginePrivate::sendMessage(const QByteArray &msg)
|
|
|
|
|
{
|
|
|
|
|
if (state() == Enabled)
|
|
|
|
|
QmlDebugClient::sendMessage(msg);
|
|
|
|
|
else
|
|
|
|
|
sendBuffer.append(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlEnginePrivate::flushSendBuffer()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == Enabled, return);
|
|
|
|
|
foreach (const QByteArray &msg, sendBuffer)
|
|
|
|
|
QmlDebugClient::sendMessage(msg);
|
|
|
|
|
sendBuffer.clear();
|
2012-02-28 17:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerEngine *createQmlEngine(const DebuggerRunParameters &sp)
|
2011-01-12 12:10:12 +01:00
|
|
|
{
|
2012-08-15 14:33:39 +02:00
|
|
|
return new QmlEngine(sp);
|
2011-01-12 12:10:12 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 13:14:03 +02:00
|
|
|
} // Internal
|
|
|
|
|
} // Debugger
|