2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-18 12:34:59 +01:00
|
|
|
#define QT_NO_CAST_FROM_ASCII
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "scriptengine.h"
|
|
|
|
|
|
2011-01-10 10:14:23 +01:00
|
|
|
#include "debuggerstartparameters.h"
|
2008-12-09 16:18:28 +01:00
|
|
|
#include "breakhandler.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "debuggerconstants.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
#include "debuggercore.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
#include "debuggerdialogs.h"
|
2010-07-07 14:36:17 +02:00
|
|
|
#include "debuggerstringutils.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "moduleshandler.h"
|
|
|
|
|
#include "registerhandler.h"
|
|
|
|
|
#include "stackhandler.h"
|
|
|
|
|
#include "watchhandler.h"
|
2009-04-29 17:52:19 +02:00
|
|
|
#include "watchutils.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-09 16:18:28 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-14 14:29:37 +02:00
|
|
|
#include <texteditor/itexteditor.h>
|
|
|
|
|
#include <coreplugin/ifile.h>
|
2010-01-15 17:30:26 +01:00
|
|
|
#include <coreplugin/scriptmanager/scriptmanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2009-05-14 14:29:37 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDateTime>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
|
2009-03-02 15:14:12 +01:00
|
|
|
#include <QtGui/QApplication>
|
2010-07-22 17:21:02 +02:00
|
|
|
#include <QtGui/QMessageBox>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QToolTip>
|
|
|
|
|
|
|
|
|
|
#include <QtScript/QScriptContext>
|
|
|
|
|
#include <QtScript/QScriptClassPropertyIterator>
|
|
|
|
|
#include <QtScript/QScriptContextInfo>
|
|
|
|
|
#include <QtScript/QScriptEngine>
|
|
|
|
|
#include <QtScript/QScriptEngineAgent>
|
|
|
|
|
#include <QtScript/QScriptValue>
|
|
|
|
|
#include <QtScript/QScriptValueIterator>
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
//#define DEBUG_SCRIPT 1
|
2009-04-07 11:24:00 +02:00
|
|
|
#if DEBUG_SCRIPT
|
|
|
|
|
# define SDEBUG(s) qDebug() << s
|
|
|
|
|
#else
|
|
|
|
|
# define SDEBUG(s)
|
|
|
|
|
#endif
|
2009-04-07 13:38:19 +02:00
|
|
|
# define XSDEBUG(s) qDebug() << s
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-09-23 10:45:32 +02:00
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ScriptEngine
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-09-23 10:45:32 +02:00
|
|
|
class ScriptAgent : public QScriptEngineAgent
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ScriptAgent(ScriptEngine *debugger, QScriptEngine *script);
|
|
|
|
|
~ScriptAgent() {}
|
|
|
|
|
|
|
|
|
|
void contextPop();
|
|
|
|
|
void contextPush();
|
|
|
|
|
void exceptionCatch(qint64 scriptId, const QScriptValue &exception);
|
|
|
|
|
void exceptionThrow(qint64 scriptId, const QScriptValue & exception,
|
|
|
|
|
bool hasHandler);
|
|
|
|
|
void functionEntry(qint64 scriptId);
|
|
|
|
|
void functionExit(qint64 scriptId, const QScriptValue &returnValue);
|
|
|
|
|
void positionChange(qint64 scriptId, int lineNumber, int columnNumber);
|
|
|
|
|
void scriptLoad(qint64 id, const QString &program, const QString &fileName,
|
|
|
|
|
int baseLineNumber);
|
|
|
|
|
void scriptUnload(qint64 id);
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void showMessage(const QString &msg);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
|
|
|
|
void maybeBreakNow(bool byFunction);
|
|
|
|
|
|
2010-01-29 21:33:57 +01:00
|
|
|
ScriptEngine *q;
|
2010-07-09 17:07:59 +02:00
|
|
|
int m_depth;
|
|
|
|
|
int m_contextDepth;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ScriptAgent::ScriptAgent(ScriptEngine *debugger, QScriptEngine *script)
|
2010-07-09 17:07:59 +02:00
|
|
|
: QScriptEngineAgent(script), q(debugger), m_depth(0), m_contextDepth(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{}
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void ScriptAgent::showMessage(const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
SDEBUG(msg);
|
|
|
|
|
q->showMessage(msg, LogMisc);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void ScriptAgent::contextPop()
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
//showMessage(_("ContextPop: %1").arg(m_contextDepth));
|
|
|
|
|
--m_contextDepth;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::contextPush()
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
++m_contextDepth;
|
|
|
|
|
//showMessage(_("ContextPush: %1 ").arg(m_contextDepth));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::exceptionCatch(qint64 scriptId, const QScriptValue & exception)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(scriptId)
|
|
|
|
|
Q_UNUSED(exception)
|
2010-07-09 17:07:59 +02:00
|
|
|
showMessage(_("An exception was caught on %1: '%2'").
|
|
|
|
|
arg(scriptId).arg(exception.toString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception,
|
|
|
|
|
bool hasHandler)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(scriptId)
|
|
|
|
|
Q_UNUSED(exception)
|
|
|
|
|
Q_UNUSED(hasHandler)
|
2010-07-09 17:07:59 +02:00
|
|
|
showMessage(_("An exception occurred on %1: '%2'").
|
|
|
|
|
arg(scriptId).arg(exception.toString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::functionEntry(qint64 scriptId)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(scriptId)
|
2010-07-09 17:07:59 +02:00
|
|
|
++m_depth;
|
|
|
|
|
//showMessage(_("Function entry occurred on %1, depth: %2").arg(scriptId));
|
2010-01-15 17:30:26 +01:00
|
|
|
q->checkForBreakCondition(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(scriptId)
|
|
|
|
|
Q_UNUSED(returnValue)
|
2010-07-09 17:07:59 +02:00
|
|
|
--m_depth;
|
|
|
|
|
//showMessage(_("Function exit occurred on %1: '%2'").
|
|
|
|
|
// arg(scriptId).arg(returnValue.toString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::positionChange(qint64 scriptId, int lineNumber, int columnNumber)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(scriptId)
|
|
|
|
|
Q_UNUSED(lineNumber)
|
|
|
|
|
Q_UNUSED(columnNumber)
|
2010-07-09 17:07:59 +02:00
|
|
|
//showMessage(_("Position: %1").arg(lineNumber));
|
2010-01-15 17:30:26 +01:00
|
|
|
q->checkForBreakCondition(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::scriptLoad(qint64 scriptId, const QString &program,
|
|
|
|
|
const QString &fileName, int baseLineNumber)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(scriptId)
|
|
|
|
|
Q_UNUSED(program)
|
|
|
|
|
Q_UNUSED(fileName)
|
|
|
|
|
Q_UNUSED(baseLineNumber)
|
2010-07-09 17:07:59 +02:00
|
|
|
showMessage(_("Loaded: %1 id: %2").arg(fileName).arg(scriptId));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::scriptUnload(qint64 scriptId)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(scriptId)
|
2010-07-09 17:07:59 +02:00
|
|
|
showMessage(_("Unload script id %1 ").arg(scriptId));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ScriptEngine
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
ScriptEngine::ScriptEngine(const DebuggerStartParameters &startParameters)
|
|
|
|
|
: DebuggerEngine(startParameters)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-08-24 15:35:46 +02:00
|
|
|
setObjectName(QLatin1String("ScriptEngine"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScriptEngine::~ScriptEngine()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::executeDebuggerCommand(const QString &command)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(command)
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("FIXME: ScriptEngine::executeDebuggerCommand()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void ScriptEngine::shutdownInferior()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorShutdownRequested, qDebug() << state());
|
|
|
|
|
SDEBUG("ScriptEngine::shutdownInferior()");
|
|
|
|
|
m_scriptEngine->setAgent(0);
|
|
|
|
|
//m_scriptAgent.reset(0);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = false;
|
2010-01-15 17:30:26 +01:00
|
|
|
if (m_scriptEngine->isEvaluating())
|
|
|
|
|
m_scriptEngine->abortEvaluation();
|
2010-07-09 17:07:59 +02:00
|
|
|
notifyInferiorShutdownOk();
|
|
|
|
|
}
|
2010-01-15 17:30:26 +01:00
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void ScriptEngine::shutdownEngine()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state());
|
2010-01-15 17:30:26 +01:00
|
|
|
m_scriptEngine->setAgent(0);
|
2010-07-09 17:07:59 +02:00
|
|
|
notifyEngineShutdownOk();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-08 18:10:50 +02:00
|
|
|
void ScriptEngine::setupEngine()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
2010-07-07 14:36:17 +02:00
|
|
|
showMessage(_("STARTING SCRIPT DEBUGGER"), LogMisc);
|
2010-01-15 17:30:26 +01:00
|
|
|
if (m_scriptEngine.isNull())
|
|
|
|
|
m_scriptEngine = Core::ICore::instance()->scriptManager()->scriptEngine();
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(!m_scriptAgent, /**/);
|
|
|
|
|
m_scriptAgent.reset(new ScriptAgent(this, m_scriptEngine.data()));
|
2010-01-15 17:30:26 +01:00
|
|
|
m_scriptEngine->setAgent(m_scriptAgent.data());
|
2010-07-09 17:07:59 +02:00
|
|
|
//m_scriptEngine->setAgent(new ScriptAgent(this, m_scriptEngine.data()));
|
2010-01-15 17:30:26 +01:00
|
|
|
/* Keep the gui alive (have the engine call processEvents() while the script
|
|
|
|
|
* is run in the foreground). */
|
2009-09-02 10:07:38 +02:00
|
|
|
m_scriptEngine->setProcessEventsInterval(1 /*ms*/);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = false;
|
|
|
|
|
m_scriptEngine->abortEvaluation();
|
2009-05-26 16:27:24 +02:00
|
|
|
|
2010-07-09 08:48:33 +02:00
|
|
|
notifyEngineSetupOk();
|
2010-07-08 18:10:50 +02:00
|
|
|
}
|
2010-01-15 17:30:26 +01:00
|
|
|
|
2010-07-08 18:10:50 +02:00
|
|
|
void ScriptEngine::setupInferior()
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2010-06-16 11:08:54 +02:00
|
|
|
m_scriptFileName = QFileInfo(startParameters().executable).absoluteFilePath();
|
2010-07-07 14:36:17 +02:00
|
|
|
showMessage(_("SCRIPT FILE: ") + m_scriptFileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
QFile scriptFile(m_scriptFileName);
|
2010-01-15 17:30:26 +01:00
|
|
|
if (!scriptFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
2010-07-22 17:21:02 +02:00
|
|
|
showMessageBox(QMessageBox::Critical, tr("Error:"),
|
|
|
|
|
_("Cannot open script file %1:\n%2").
|
|
|
|
|
arg(m_scriptFileName, scriptFile.errorString()));
|
|
|
|
|
notifyInferiorSetupFailed();
|
2009-09-10 13:09:42 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
QTextStream stream(&scriptFile);
|
|
|
|
|
m_scriptContents = stream.readAll();
|
|
|
|
|
scriptFile.close();
|
|
|
|
|
attemptBreakpointSynchronization();
|
2010-07-08 18:10:50 +02:00
|
|
|
notifyInferiorSetupOk();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::continueInferior()
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptEngine::continueInferior()");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-15 17:30:26 +01:00
|
|
|
static const char *qtExtensionsC[] = {
|
|
|
|
|
"qt.core", "qt.gui", "qt.xml", "qt.svg", "qt.network",
|
|
|
|
|
"qt.sql", "qt.opengl", "qt.webkit", "qt.xmlpatterns", "qt.uitools"
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void ScriptEngine::importExtensions()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-15 17:30:26 +01:00
|
|
|
SDEBUG("ScriptEngine::importExtensions()");
|
|
|
|
|
QStringList extensions;
|
|
|
|
|
const int extCount = sizeof(qtExtensionsC)/sizeof(const char *);
|
|
|
|
|
for (int e = 0; e < extCount; e++)
|
|
|
|
|
extensions.append(QLatin1String(qtExtensionsC[e]));
|
|
|
|
|
if (m_scriptEngine->importedExtensions().contains(extensions.front()))
|
2010-07-09 17:07:59 +02:00
|
|
|
return; // true;
|
2010-01-18 12:34:59 +01:00
|
|
|
QDir dir(QLatin1String("/home/apoenitz/dev/qtscriptgenerator"));
|
|
|
|
|
if (!dir.cd(QLatin1String("plugins"))) {
|
2009-04-07 16:39:17 +02:00
|
|
|
fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
|
2010-07-09 17:07:59 +02:00
|
|
|
return; // false;
|
2009-04-07 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
QStringList paths = qApp->libraryPaths();
|
|
|
|
|
paths << dir.absolutePath();
|
|
|
|
|
qApp->setLibraryPaths(paths);
|
|
|
|
|
QStringList failExtensions;
|
|
|
|
|
foreach (const QString &ext, extensions) {
|
|
|
|
|
QScriptValue ret = m_scriptEngine->importExtension(ext);
|
|
|
|
|
if (ret.isError())
|
|
|
|
|
failExtensions.append(ext);
|
|
|
|
|
}
|
|
|
|
|
if (!failExtensions.isEmpty()) {
|
|
|
|
|
if (failExtensions.size() == extensions.size()) {
|
|
|
|
|
qWarning("Failed to import Qt bindings!\n"
|
|
|
|
|
"Plugins directory searched: %s/script\n"
|
|
|
|
|
"Make sure that the bindings have been built, "
|
|
|
|
|
"and that this executable and the plugins are "
|
|
|
|
|
"using compatible Qt libraries.", qPrintable(dir.absolutePath()));
|
|
|
|
|
} else {
|
|
|
|
|
qWarning("Failed to import some Qt bindings: %s\n"
|
|
|
|
|
"Plugins directory searched: %s/script\n"
|
|
|
|
|
"Make sure that the bindings have been built, "
|
|
|
|
|
"and that this executable and the plugins are "
|
|
|
|
|
"using compatible Qt libraries.",
|
2010-07-23 16:05:56 +02:00
|
|
|
qPrintable(failExtensions.join(QLatin1String(", "))),
|
|
|
|
|
qPrintable(dir.absolutePath()));
|
2009-04-07 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-09 17:07:59 +02:00
|
|
|
return; // failExtensions.isEmpty();
|
2010-01-15 17:30:26 +01:00
|
|
|
}
|
2009-04-07 16:39:17 +02:00
|
|
|
|
2010-07-08 18:10:50 +02:00
|
|
|
void ScriptEngine::runEngine()
|
2010-01-15 17:30:26 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
|
|
|
|
notifyEngineRunAndInferiorRunOk();
|
2010-07-08 18:10:50 +02:00
|
|
|
showStatusMessage(tr("Running requested..."), 5000);
|
|
|
|
|
showMessage(QLatin1String("Running: ") + m_scriptFileName, LogMisc);
|
2010-01-15 17:30:26 +01:00
|
|
|
importExtensions();
|
2010-07-23 16:05:56 +02:00
|
|
|
const QScriptValue result =
|
|
|
|
|
m_scriptEngine->evaluate(m_scriptContents, m_scriptFileName);
|
2010-06-14 17:23:25 +02:00
|
|
|
QString msg;
|
2010-01-15 17:30:26 +01:00
|
|
|
if (m_scriptEngine->hasUncaughtException()) {
|
2010-07-09 17:07:59 +02:00
|
|
|
msg = _("An exception occurred during execution at line: %1\n%2\n")
|
2010-06-14 17:23:25 +02:00
|
|
|
.arg(m_scriptEngine->uncaughtExceptionLineNumber())
|
|
|
|
|
.arg(m_scriptEngine->uncaughtException().toString());
|
|
|
|
|
msg += m_scriptEngine->uncaughtExceptionBacktrace()
|
|
|
|
|
.join(QString(QLatin1Char('\n')));
|
2010-01-15 17:30:26 +01:00
|
|
|
} else {
|
2010-07-09 17:07:59 +02:00
|
|
|
msg = _("Evaluation returns '%1'").arg(result.toString());
|
2010-01-15 17:30:26 +01:00
|
|
|
}
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(msg, LogMisc);
|
2010-07-09 17:07:59 +02:00
|
|
|
showMessage(_("This was the outermost function."));
|
|
|
|
|
notifyInferiorExited();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::interruptInferior()
|
|
|
|
|
{
|
|
|
|
|
m_stopOnNextLine = true;
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("ScriptEngine::interruptInferior()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeStep()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-04-07 13:38:19 +02:00
|
|
|
//SDEBUG("ScriptEngine::stepExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeStepI()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-04-07 13:38:19 +02:00
|
|
|
//SDEBUG("ScriptEngine::stepIExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeStepOut()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-04-07 13:38:19 +02:00
|
|
|
//SDEBUG("ScriptEngine::stepOutExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeNext()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-04-07 13:38:19 +02:00
|
|
|
//SDEBUG("ScriptEngine::nextExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeNextI()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-04-07 13:38:19 +02:00
|
|
|
//SDEBUG("ScriptEngine::nextIExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeRunToLine(const QString &fileName, int lineNumber)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(fileName)
|
|
|
|
|
Q_UNUSED(lineNumber)
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("FIXME: ScriptEngine::runToLineExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeRunToFunction(const QString &functionName)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(functionName)
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("FIXME: ScriptEngine::runToFunctionExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 16:17:40 +01:00
|
|
|
void ScriptEngine::executeJumpToLine(const QString &fileName, int lineNumber)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
|
|
|
|
|
notifyInferiorRunRequested();
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(fileName)
|
|
|
|
|
Q_UNUSED(lineNumber)
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("FIXME: ScriptEngine::jumpToLineExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::activateFrame(int index)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(index)
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::selectThread(int index)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(index)
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-26 10:20:50 +01:00
|
|
|
bool ScriptEngine::acceptsBreakpoint(BreakpointId id) const
|
|
|
|
|
{
|
|
|
|
|
const QString fileName = breakHandler()->fileName(id);
|
|
|
|
|
return fileName.endsWith(QLatin1String(".js"));
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void ScriptEngine::attemptBreakpointSynchronization()
|
|
|
|
|
{
|
2010-11-10 16:33:11 +01:00
|
|
|
QTC_ASSERT(false, /* FIXME */);
|
|
|
|
|
/*
|
2010-06-16 11:08:54 +02:00
|
|
|
BreakHandler *handler = breakHandler();
|
2008-12-02 12:01:29 +01:00
|
|
|
bool updateNeeded = false;
|
|
|
|
|
for (int index = 0; index != handler->size(); ++index) {
|
|
|
|
|
BreakpointData *data = handler->at(index);
|
|
|
|
|
if (data->pending) {
|
|
|
|
|
data->pending = false; // FIXME
|
|
|
|
|
updateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
if (data->bpNumber.isEmpty()) {
|
2010-01-05 16:51:55 +01:00
|
|
|
data->bpNumber = QByteArray::number(index + 1);
|
2008-12-02 12:01:29 +01:00
|
|
|
updateNeeded = true;
|
|
|
|
|
}
|
2010-03-26 10:29:19 +01:00
|
|
|
if (!data->fileName.isEmpty() && data->markerFileName().isEmpty()) {
|
|
|
|
|
data->setMarkerFileName(data->fileName);
|
2010-09-21 14:26:45 +02:00
|
|
|
data->setMarkerLineNumber(data->lineNumber);
|
2008-12-02 12:01:29 +01:00
|
|
|
updateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (updateNeeded)
|
|
|
|
|
handler->updateMarkers();
|
2010-11-10 16:33:11 +01:00
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::loadSymbols(const QString &moduleName)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(moduleName)
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::loadAllSymbols()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::reloadModules()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-03 19:12:52 +02:00
|
|
|
void ScriptEngine::requestModuleSymbols(const QString & /*moduleName*/)
|
2009-04-15 12:01:58 +02:00
|
|
|
{
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Tooltip specific stuff
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-01-15 17:30:26 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
static WatchData m_toolTip;
|
|
|
|
|
static QPoint m_toolTipPos;
|
|
|
|
|
static QHash<QString, WatchData> m_toolTipCache;
|
|
|
|
|
|
2009-09-25 08:35:31 +02:00
|
|
|
void ScriptEngine::setToolTipExpression(const QPoint &mousePos,
|
|
|
|
|
TextEditor::ITextEditor *editor, int cursorPos)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(mousePos)
|
|
|
|
|
Q_UNUSED(editor)
|
|
|
|
|
Q_UNUSED(cursorPos)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
if (state() != InferiorStopOk) {
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("SUPPRESSING DEBUGGER TOOLTIP, INFERIOR NOT STOPPED");
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2009-05-14 14:29:37 +02:00
|
|
|
// Check mime type and get expression (borrowing some C++ - functions)
|
2009-09-25 08:35:31 +02:00
|
|
|
const QString javaScriptMimeType =
|
2010-01-15 17:36:49 +01:00
|
|
|
QLatin1String("application/javascript");
|
2009-05-14 14:29:37 +02:00
|
|
|
if (!editor->file() || editor->file()->mimeType() != javaScriptMimeType)
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-14 14:29:37 +02:00
|
|
|
int line;
|
|
|
|
|
int column;
|
|
|
|
|
QString exp = cppExpressionAt(editor, cursorPos, &line, &column);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (m_toolTipCache.contains(exp)) {
|
|
|
|
|
const WatchData & data = m_toolTipCache[exp];
|
|
|
|
|
q->watchHandler()->removeChildren(data.iname);
|
|
|
|
|
insertData(data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
QToolTip::hideText();
|
2010-01-18 12:34:59 +01:00
|
|
|
if (exp.isEmpty() || exp.startsWith(QLatin1Char('#'))) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QToolTip::hideText();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasLetterOrNumber(exp)) {
|
2009-04-17 21:11:52 +02:00
|
|
|
QToolTip::showText(m_toolTipPos, tr("'%1' contains no identifier").arg(exp));
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-18 12:34:59 +01:00
|
|
|
if (exp.startsWith(QLatin1Char('"')) && exp.endsWith(QLatin1Char('"'))) {
|
2009-04-17 21:11:52 +02:00
|
|
|
QToolTip::showText(m_toolTipPos, tr("String literal %1").arg(exp));
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-18 12:34:59 +01:00
|
|
|
if (exp.startsWith(QLatin1String("++")) || exp.startsWith(QLatin1String("--")))
|
|
|
|
|
exp.remove(0, 2);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-18 12:34:59 +01:00
|
|
|
if (exp.endsWith(QLatin1String("++")) || exp.endsWith(QLatin1String("--")))
|
|
|
|
|
exp.remove(0, 2);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-18 12:34:59 +01:00
|
|
|
if (exp.startsWith(QLatin1Char('<')) || exp.startsWith(QLatin1Char('[')))
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (hasSideEffects(exp)) {
|
|
|
|
|
QToolTip::showText(m_toolTipPos,
|
2009-04-08 12:11:30 +02:00
|
|
|
tr("Cowardly refusing to evaluate expression '%1' "
|
|
|
|
|
"with potential side effects").arg(exp));
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
2010-07-09 17:07:59 +02:00
|
|
|
//if (m_manager->status() != InferiorStopOk)
|
2008-12-02 12:01:29 +01:00
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// FIXME: 'exp' can contain illegal characters
|
|
|
|
|
m_toolTip = WatchData();
|
|
|
|
|
m_toolTip.exp = exp;
|
|
|
|
|
m_toolTip.name = exp;
|
|
|
|
|
m_toolTip.iname = tooltipIName;
|
|
|
|
|
insertData(m_toolTip);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Watch specific stuff
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-09-23 13:22:08 +02:00
|
|
|
void ScriptEngine::assignValueInDebugger(const Internal::WatchData *,
|
|
|
|
|
const QString &expression, const QVariant &value)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-23 13:22:08 +02:00
|
|
|
SDEBUG("ASSIGNING: " << (expression + QLatin1Char('=') + value.toString()));
|
|
|
|
|
m_scriptEngine->evaluate(expression + QLatin1Char('=') + value.toString());
|
2009-04-07 13:38:19 +02:00
|
|
|
updateLocals();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-15 17:30:26 +01:00
|
|
|
bool ScriptEngine::checkForBreakCondition(bool byFunction)
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
// FIXME: Should that ever happen after setAgent(0) in shutdownInferior()?
|
|
|
|
|
// In practice, it does, so chicken out.
|
|
|
|
|
if (targetState() == DebuggerFinished)
|
|
|
|
|
return false;
|
|
|
|
|
|
2010-01-15 17:30:26 +01:00
|
|
|
const QScriptContext *context = m_scriptEngine->currentContext();
|
|
|
|
|
const QScriptContextInfo info(context);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-15 17:30:26 +01:00
|
|
|
// Update breakpoints
|
|
|
|
|
const QString functionName = info.functionName();
|
|
|
|
|
const QString fileName = info.fileName();
|
2010-07-07 13:26:32 +02:00
|
|
|
const int lineNumber = byFunction
|
|
|
|
|
? info.functionStartLineNumber() : info.lineNumber();
|
2010-11-10 16:33:11 +01:00
|
|
|
SDEBUG(Q_FUNC_INFO << byFunction << functionName << lineNumber << fileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_stopOnNextLine) {
|
2010-01-15 17:30:26 +01:00
|
|
|
// Interrupt inferior
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopOnNextLine = false;
|
|
|
|
|
} else {
|
2010-01-15 17:30:26 +01:00
|
|
|
if (byFunction && functionName.isEmpty())
|
|
|
|
|
return false;
|
2010-11-10 16:33:11 +01:00
|
|
|
BreakHandler *handler = breakHandler();
|
|
|
|
|
BreakpointId id = byFunction ?
|
|
|
|
|
handler->findBreakpointByFunction(functionName) :
|
|
|
|
|
handler->findBreakpointByFileAndLine(fileName, lineNumber, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-07 13:26:32 +02:00
|
|
|
// Skip disabled breakpoint.
|
2010-11-10 16:33:11 +01:00
|
|
|
if (!handler->isEnabled(id))
|
2010-07-07 13:26:32 +02:00
|
|
|
return false;
|
|
|
|
|
|
2010-11-10 16:33:11 +01:00
|
|
|
BreakpointResponse br;
|
2010-07-07 13:26:32 +02:00
|
|
|
// We just run into a breakpoint.
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("RESOLVING BREAKPOINT AT " << fileName << lineNumber);
|
2010-11-15 17:04:29 +01:00
|
|
|
br.lineNumber = lineNumber;
|
|
|
|
|
br.fileName = fileName;
|
|
|
|
|
br.functionName = functionName;
|
2010-11-16 13:52:21 +01:00
|
|
|
handler->notifyBreakpointInsertOk(id);
|
2010-11-10 16:33:11 +01:00
|
|
|
handler->setResponse(id, br);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-09 17:07:59 +02:00
|
|
|
notifyInferiorSpontaneousStop();
|
2010-01-15 17:30:26 +01:00
|
|
|
SDEBUG("Stopped at " << lineNumber << fileName);
|
|
|
|
|
showStatusMessage(tr("Stopped at %1:%2.").arg(fileName).arg(lineNumber), 5000);
|
2010-12-16 19:06:33 +01:00
|
|
|
gotoLocation(Location(fileName, lineNumber));
|
2009-04-07 13:38:19 +02:00
|
|
|
updateLocals();
|
2010-01-15 17:30:26 +01:00
|
|
|
return true;
|
2009-04-07 13:38:19 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-07 13:38:19 +02:00
|
|
|
void ScriptEngine::updateLocals()
|
|
|
|
|
{
|
|
|
|
|
QScriptContext *context = m_scriptEngine->currentContext();
|
2010-06-16 11:08:54 +02:00
|
|
|
watchHandler()->beginCycle();
|
2010-07-09 17:07:59 +02:00
|
|
|
SDEBUG(Q_FUNC_INFO);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Build stack
|
2010-01-29 21:33:57 +01:00
|
|
|
//
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<StackFrame> stackFrames;
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (QScriptContext *c = context; c; c = c->parentContext(), ++i) {
|
2010-01-15 17:30:26 +01:00
|
|
|
const QScriptContextInfo info(c);
|
2008-12-02 12:01:29 +01:00
|
|
|
StackFrame frame;
|
|
|
|
|
frame.level = i;
|
|
|
|
|
frame.file = info.fileName();
|
|
|
|
|
frame.function = info.functionName();
|
|
|
|
|
frame.from = QString::number(info.functionStartLineNumber());
|
|
|
|
|
frame.to = QString::number(info.functionEndLineNumber());
|
|
|
|
|
frame.line = info.lineNumber();
|
|
|
|
|
if (frame.function.isEmpty())
|
2010-01-15 17:30:26 +01:00
|
|
|
frame.function = QLatin1String("<global scope>");
|
2008-12-02 12:01:29 +01:00
|
|
|
//frame.address = ...;
|
|
|
|
|
stackFrames.append(frame);
|
|
|
|
|
}
|
2010-06-16 11:08:54 +02:00
|
|
|
stackHandler()->setFrames(stackFrames);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//
|
2010-01-18 12:34:59 +01:00
|
|
|
// Build locals, deactivate agent meanwhile.
|
2008-12-02 12:01:29 +01:00
|
|
|
//
|
2010-01-18 12:34:59 +01:00
|
|
|
m_scriptEngine->setAgent(0);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
WatchData data;
|
2010-10-15 13:00:14 +02:00
|
|
|
data.id = m_watchIdCounter++;
|
|
|
|
|
m_watchIdToScriptValue.insert(data.id, context->activationObject());
|
2008-12-02 12:01:29 +01:00
|
|
|
data.iname = "local";
|
2010-07-09 17:07:59 +02:00
|
|
|
data.name = _(data.iname);
|
2010-10-15 13:00:14 +02:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
watchHandler()->beginCycle();
|
2009-09-02 13:19:47 +02:00
|
|
|
updateSubItem(data);
|
2010-06-16 11:08:54 +02:00
|
|
|
watchHandler()->endCycle();
|
2010-07-09 17:07:59 +02:00
|
|
|
// FIXME: Use an extra thread. This here is evil.
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = true;
|
2009-09-25 08:35:31 +02:00
|
|
|
showStatusMessage(tr("Stopped."), 5000);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (m_stopped) {
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("LOOPING");
|
2008-12-02 12:01:29 +01:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
}
|
2010-01-18 12:34:59 +01:00
|
|
|
// Clear any exceptions occurred during locals evaluation.
|
|
|
|
|
m_scriptEngine->clearExceptions();
|
|
|
|
|
m_scriptEngine->setAgent(m_scriptAgent.data());
|
2010-07-09 17:07:59 +02:00
|
|
|
notifyInferiorRunOk();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-13 08:32:12 +02:00
|
|
|
void ScriptEngine::updateWatchData(const WatchData &data, const WatchUpdateFlags &flags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-13 10:26:56 +02:00
|
|
|
Q_UNUSED(flags);
|
2009-06-17 16:00:03 +02:00
|
|
|
updateSubItem(data);
|
2010-01-18 12:34:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString msgDebugInsert(const WatchData &d0, const QList<WatchData>& children)
|
|
|
|
|
{
|
|
|
|
|
QString rc;
|
|
|
|
|
QTextStream str(&rc);
|
|
|
|
|
str << "INSERTING " << d0.toString() << '\n';
|
|
|
|
|
foreach(const WatchData &c, children)
|
|
|
|
|
str << " " << c.toString() << '\n';
|
|
|
|
|
return rc;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::updateSubItem(const WatchData &data0)
|
|
|
|
|
{
|
|
|
|
|
WatchData data = data0;
|
2010-01-18 12:34:59 +01:00
|
|
|
QList<WatchData> children;
|
2010-07-09 17:07:59 +02:00
|
|
|
//SDEBUG("\nUPDATE SUBITEM: " << data.toString() << data.scriptValue.toString());
|
2008-12-09 12:08:56 +01:00
|
|
|
QTC_ASSERT(data.isValid(), return);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-10-15 13:00:14 +02:00
|
|
|
const QScriptValue &ob = m_watchIdToScriptValue.value(data.id);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (data.isTypeNeeded() || data.isValueNeeded()) {
|
|
|
|
|
if (ob.isArray()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Array", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString(QLatin1Char(' ')));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isBool()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Bool", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(ob.toBool() ? QLatin1String("true") : QLatin1String("false"));
|
2009-06-22 11:35:08 +02:00
|
|
|
data.setHasChildren(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isDate()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Date", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(ob.toDateTime().toString());
|
2009-06-22 11:35:08 +02:00
|
|
|
data.setHasChildren(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isError()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Error", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString(QLatin1Char(' ')));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isFunction()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Function", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString(QLatin1Char(' ')));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isNull()) {
|
2010-01-18 12:34:59 +01:00
|
|
|
const QString nullValue = QLatin1String("<null>");
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("<null>", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(nullValue);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isNumber()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Number", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString::number(ob.toNumber()));
|
2009-06-22 11:35:08 +02:00
|
|
|
data.setHasChildren(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isObject()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Object", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString(QLatin1Char(' ')));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isQMetaObject()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("QMetaObject", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString(QLatin1Char(' ')));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isQObject()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("QObject", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString(QLatin1Char(' ')));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isRegExp()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("RegExp", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(ob.toRegExp().pattern());
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isString()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("String", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(ob.toString());
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isVariant()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("Variant", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QString(QLatin1Char(' ')));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ob.isUndefined()) {
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("<undefined>", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(QLatin1String("<unknown>"));
|
2009-09-02 13:19:47 +02:00
|
|
|
data.setHasChildren(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2010-01-18 12:34:59 +01:00
|
|
|
const QString unknown = QLatin1String("<unknown>");
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType("<unknown>", false);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setValue(unknown);
|
2009-09-02 13:19:47 +02:00
|
|
|
data.setHasChildren(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.isChildrenNeeded()) {
|
2010-10-15 13:00:14 +02:00
|
|
|
QScriptValueIterator it(ob);
|
2008-12-02 12:01:29 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
WatchData data1;
|
2010-01-18 12:34:59 +01:00
|
|
|
data1.iname = data.iname + '.' + it.name().toLatin1();
|
2010-01-05 16:51:55 +01:00
|
|
|
data1.exp = it.name().toLatin1();
|
2008-12-02 12:01:29 +01:00
|
|
|
data1.name = it.name();
|
2010-10-15 13:00:14 +02:00
|
|
|
data.id = m_watchIdCounter++;
|
|
|
|
|
m_watchIdToScriptValue.insert(data.id, it.value());
|
2010-06-16 11:08:54 +02:00
|
|
|
if (watchHandler()->isExpandedIName(data1.iname)) {
|
2008-12-02 12:01:29 +01:00
|
|
|
data1.setChildrenNeeded();
|
2010-01-18 12:34:59 +01:00
|
|
|
} else {
|
2008-12-02 12:01:29 +01:00
|
|
|
data1.setChildrenUnneeded();
|
2010-01-18 12:34:59 +01:00
|
|
|
}
|
|
|
|
|
children.push_back(data1);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setHasChildren(!children.isEmpty());
|
2008-12-02 12:01:29 +01:00
|
|
|
data.setChildrenUnneeded();
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-22 11:35:08 +02:00
|
|
|
if (data.isHasChildrenNeeded()) {
|
2010-10-15 13:00:14 +02:00
|
|
|
QScriptValueIterator it(ob);
|
2010-01-18 12:34:59 +01:00
|
|
|
data.setHasChildren(it.hasNext());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-18 12:34:59 +01:00
|
|
|
SDEBUG(msgDebugInsert(data, children));
|
2010-06-16 11:08:54 +02:00
|
|
|
watchHandler()->insertData(data);
|
2010-01-18 12:34:59 +01:00
|
|
|
if (!children.isEmpty())
|
2010-06-16 11:08:54 +02:00
|
|
|
watchHandler()->insertBulkData(children);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
DebuggerEngine *createScriptEngine(const DebuggerStartParameters &sp)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-06-16 11:08:54 +02:00
|
|
|
return new ScriptEngine(sp);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-09-23 10:45:32 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|