2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@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
|
|
|
|
|
|
|
|
#include "scriptengine.h"
|
|
|
|
|
|
2009-03-02 13:08:30 +01:00
|
|
|
#include "debuggerdialogs.h"
|
2008-12-09 16:18:28 +01:00
|
|
|
#include "breakhandler.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "debuggerconstants.h"
|
|
|
|
|
#include "debuggermanager.h"
|
|
|
|
|
#include "disassemblerhandler.h"
|
|
|
|
|
#include "moduleshandler.h"
|
|
|
|
|
#include "registerhandler.h"
|
|
|
|
|
#include "stackhandler.h"
|
|
|
|
|
#include "watchhandler.h"
|
2009-04-29 17:52:19 +02:00
|
|
|
#include "watchutils.h"
|
2009-04-15 12:01:58 +02:00
|
|
|
#include "moduleshandler.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 <qtscripteditor/qtscripteditorconstants.h>
|
|
|
|
|
|
|
|
|
|
#include <texteditor/itexteditor.h>
|
|
|
|
|
#include <coreplugin/ifile.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDateTime>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QAction>
|
2009-03-02 15:14:12 +01:00
|
|
|
#include <QtGui/QApplication>
|
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>
|
|
|
|
|
|
|
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace Debugger::Internal;
|
|
|
|
|
using namespace Debugger::Constants;
|
|
|
|
|
|
2009-04-07 11:24:00 +02:00
|
|
|
//#define DEBUG_SCRIPT 1
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ScriptEngine
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class Debugger::Internal::ScriptAgent : public QScriptEngineAgent
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void maybeBreakNow(bool byFunction);
|
|
|
|
|
|
|
|
|
|
ScriptEngine *q;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ScriptAgent::ScriptAgent(ScriptEngine *debugger, QScriptEngine *script)
|
|
|
|
|
: QScriptEngineAgent(script), q(debugger)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::contextPop()
|
|
|
|
|
{
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptAgent::contextPop: ");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::contextPush()
|
|
|
|
|
{
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptAgent::contextPush: ");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::exceptionCatch(qint64 scriptId, const QScriptValue & exception)
|
|
|
|
|
{
|
2009-04-07 11:24:00 +02:00
|
|
|
Q_UNUSED(scriptId);
|
|
|
|
|
Q_UNUSED(exception);
|
|
|
|
|
SDEBUG("ScriptAgent::exceptionCatch: " << scriptId << &exception);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception,
|
|
|
|
|
bool hasHandler)
|
|
|
|
|
{
|
2009-04-07 11:24:00 +02:00
|
|
|
Q_UNUSED(scriptId);
|
|
|
|
|
Q_UNUSED(exception);
|
|
|
|
|
Q_UNUSED(hasHandler);
|
|
|
|
|
SDEBUG("ScriptAgent::exceptionThrow: " << scriptId << &exception
|
|
|
|
|
<< hasHandler);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::functionEntry(qint64 scriptId)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(scriptId);
|
|
|
|
|
q->maybeBreakNow(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue)
|
|
|
|
|
{
|
2009-04-07 11:24:00 +02:00
|
|
|
Q_UNUSED(scriptId);
|
|
|
|
|
Q_UNUSED(returnValue);
|
|
|
|
|
SDEBUG("ScriptAgent::functionExit: " << scriptId << &returnValue);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::positionChange(qint64 scriptId, int lineNumber, int columnNumber)
|
|
|
|
|
{
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptAgent::position: " << lineNumber);
|
2008-12-02 12:01:29 +01:00
|
|
|
Q_UNUSED(scriptId);
|
|
|
|
|
Q_UNUSED(lineNumber);
|
|
|
|
|
Q_UNUSED(columnNumber);
|
|
|
|
|
q->maybeBreakNow(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::scriptLoad(qint64 scriptId, const QString &program,
|
|
|
|
|
const QString &fileName, int baseLineNumber)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(scriptId);
|
|
|
|
|
Q_UNUSED(program);
|
|
|
|
|
Q_UNUSED(fileName);
|
|
|
|
|
Q_UNUSED(baseLineNumber);
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptAgent::scriptLoad: " << program << fileName
|
|
|
|
|
<< baseLineNumber);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptAgent::scriptUnload(qint64 scriptId)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(scriptId);
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptAgent::scriptUnload: " << scriptId);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ScriptEngine
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
ScriptEngine::ScriptEngine(DebuggerManager *parent)
|
|
|
|
|
{
|
|
|
|
|
q = parent;
|
|
|
|
|
qq = parent->engineInterface();
|
|
|
|
|
m_scriptEngine = new QScriptEngine(this);
|
|
|
|
|
m_scriptAgent = new ScriptAgent(this, m_scriptEngine);
|
|
|
|
|
m_scriptEngine->setAgent(m_scriptAgent);
|
|
|
|
|
m_scriptEngine->setProcessEventsInterval(1 /*ms*/);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScriptEngine::~ScriptEngine()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::executeDebuggerCommand(const QString &command)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(command);
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("FIXME: ScriptEngine::executeDebuggerCommand()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::shutdown()
|
|
|
|
|
{
|
|
|
|
|
exitDebugger();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::exitDebugger()
|
|
|
|
|
{
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptEngine::exitDebugger()");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = false;
|
|
|
|
|
m_scriptEngine->abortEvaluation();
|
|
|
|
|
qq->notifyInferiorExited();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScriptEngine::startDebugger()
|
|
|
|
|
{
|
|
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = false;
|
|
|
|
|
m_scriptEngine->abortEvaluation();
|
2009-05-25 16:22:11 +02:00
|
|
|
const QSharedPointer<DebuggerStartParameters> sp = q->startParameters();
|
|
|
|
|
QFileInfo fi(sp->executable);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_scriptFileName = fi.absoluteFilePath();
|
|
|
|
|
QFile scriptFile(m_scriptFileName);
|
|
|
|
|
if (!scriptFile.open(QIODevice::ReadOnly))
|
|
|
|
|
return false;
|
|
|
|
|
QTextStream stream(&scriptFile);
|
|
|
|
|
m_scriptContents = stream.readAll();
|
|
|
|
|
scriptFile.close();
|
|
|
|
|
attemptBreakpointSynchronization();
|
2009-04-07 11:24:00 +02:00
|
|
|
qq->notifyInferiorRunningRequested();
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(runInferior()));
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::continueInferior()
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::runInferior()
|
|
|
|
|
{
|
2009-04-07 16:39:17 +02:00
|
|
|
//QDir dir(QApplication::applicationDirPath());
|
|
|
|
|
//if (dir.dirName() == QLatin1String("debug") || dir.dirName() == QLatin1String("release"))
|
|
|
|
|
// dir.cdUp();
|
|
|
|
|
//dir.cdUp();
|
|
|
|
|
//dir.cdUp();
|
|
|
|
|
QDir dir("/home/apoenitz/dev/qtscriptgenerator");
|
|
|
|
|
if (!dir.cd("plugins")) {
|
|
|
|
|
fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QStringList paths = qApp->libraryPaths();
|
|
|
|
|
paths << dir.absolutePath();
|
|
|
|
|
qApp->setLibraryPaths(paths);
|
|
|
|
|
|
2009-04-07 11:24:00 +02:00
|
|
|
SDEBUG("ScriptEngine::runInferior()");
|
2009-04-07 16:39:17 +02:00
|
|
|
QStringList extensions;
|
|
|
|
|
extensions << "qt.core"
|
|
|
|
|
<< "qt.gui"
|
|
|
|
|
<< "qt.xml"
|
|
|
|
|
<< "qt.svg"
|
|
|
|
|
<< "qt.network"
|
|
|
|
|
<< "qt.sql"
|
|
|
|
|
<< "qt.opengl"
|
|
|
|
|
<< "qt.webkit"
|
|
|
|
|
<< "qt.xmlpatterns"
|
|
|
|
|
<< "qt.uitools";
|
|
|
|
|
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.",
|
|
|
|
|
qPrintable(failExtensions.join(", ")), qPrintable(dir.absolutePath()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QScriptValue result = m_scriptEngine->evaluate(m_scriptContents, m_scriptFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::interruptInferior()
|
|
|
|
|
{
|
|
|
|
|
m_stopped = false;
|
|
|
|
|
m_stopOnNextLine = true;
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("ScriptEngine::interruptInferior()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::stepExec()
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::stepIExec()
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::stepOutExec()
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::nextExec()
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::nextIExec()
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::runToLineExec(const QString &fileName, int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::runToFunctionExec(const QString &functionName)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(functionName);
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("FIXME: ScriptEngine::runToFunctionExec()");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::jumpToLineExec(const QString &fileName, int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::selectThread(int index)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::attemptBreakpointSynchronization()
|
|
|
|
|
{
|
|
|
|
|
BreakHandler *handler = qq->breakHandler();
|
|
|
|
|
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()) {
|
|
|
|
|
data->bpNumber = QString::number(index + 1);
|
|
|
|
|
updateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
if (!data->fileName.isEmpty() && data->markerFileName.isEmpty()) {
|
|
|
|
|
data->markerFileName = data->fileName;
|
|
|
|
|
data->markerLineNumber = data->lineNumber.toInt();
|
|
|
|
|
updateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (updateNeeded)
|
|
|
|
|
handler->updateMarkers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::reloadDisassembler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::loadSymbols(const QString &moduleName)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(moduleName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::loadAllSymbols()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::reloadModules()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-15 12:01:58 +02:00
|
|
|
QList<Symbol> ScriptEngine::moduleSymbols(const QString & /*moduleName*/)
|
|
|
|
|
{
|
|
|
|
|
return QList<Symbol>();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Tooltip specific stuff
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
static WatchData m_toolTip;
|
|
|
|
|
static QPoint m_toolTipPos;
|
|
|
|
|
static QHash<QString, WatchData> m_toolTipCache;
|
|
|
|
|
|
2009-05-14 14:29:37 +02:00
|
|
|
void ScriptEngine::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-14 14:29:37 +02:00
|
|
|
Q_UNUSED(mousePos);
|
|
|
|
|
Q_UNUSED(editor);
|
|
|
|
|
Q_UNUSED(cursorPos);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (q->status() != DebuggerInferiorStopped) {
|
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)
|
|
|
|
|
const QString javaScriptMimeType = QLatin1String(QtScriptEditor::Constants::C_QTSCRIPTEDITOR_MIMETYPE);
|
|
|
|
|
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();
|
|
|
|
|
if (exp.isEmpty() || exp.startsWith("#")) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exp.startsWith('"') && exp.endsWith('"')) {
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exp.startsWith("++") || exp.startsWith("--"))
|
|
|
|
|
exp = exp.mid(2);
|
|
|
|
|
|
|
|
|
|
if (exp.endsWith("++") || exp.endsWith("--"))
|
|
|
|
|
exp = exp.mid(2);
|
|
|
|
|
|
|
|
|
|
if (exp.startsWith("<") || exp.startsWith("["))
|
|
|
|
|
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
|
|
|
|
|
//if (m_manager->status() != DebuggerInferiorStopped)
|
|
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::assignValueInDebugger(const QString &expression,
|
|
|
|
|
const QString &value)
|
|
|
|
|
{
|
2009-04-07 13:38:19 +02:00
|
|
|
XSDEBUG("ASSIGNING: " << expression + '=' + value);
|
|
|
|
|
m_scriptEngine->evaluate(expression + '=' + value);
|
|
|
|
|
updateLocals();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::maybeBreakNow(bool byFunction)
|
|
|
|
|
{
|
|
|
|
|
QScriptContext *context = m_scriptEngine->currentContext();
|
|
|
|
|
QScriptContextInfo info(context);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Update breakpoints
|
|
|
|
|
//
|
|
|
|
|
QString functionName = info.functionName();
|
|
|
|
|
QString fileName = info.fileName();
|
|
|
|
|
int lineNumber = info.lineNumber();
|
|
|
|
|
if (byFunction)
|
|
|
|
|
lineNumber = info.functionStartLineNumber();
|
|
|
|
|
|
|
|
|
|
BreakHandler *handler = qq->breakHandler();
|
|
|
|
|
|
|
|
|
|
if (m_stopOnNextLine) {
|
|
|
|
|
m_stopOnNextLine = false;
|
|
|
|
|
} else {
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (; index != handler->size(); ++index) {
|
|
|
|
|
BreakpointData *data = handler->at(index);
|
|
|
|
|
if (byFunction) {
|
|
|
|
|
if (!functionName.isEmpty() && data->funcName == functionName)
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
if (info.lineNumber() == data->lineNumber.toInt()
|
|
|
|
|
&& fileName == data->fileName)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index == handler->size())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// we just run into a breakpoint
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("RESOLVING BREAKPOINT AT " << fileName << lineNumber);
|
2008-12-02 12:01:29 +01:00
|
|
|
BreakpointData *data = handler->at(index);
|
|
|
|
|
data->bpLineNumber = QString::number(lineNumber);
|
|
|
|
|
data->bpFileName = fileName;
|
|
|
|
|
data->bpFuncName = functionName;
|
|
|
|
|
data->markerLineNumber = lineNumber;
|
|
|
|
|
data->markerFileName = fileName;
|
|
|
|
|
data->pending = false;
|
|
|
|
|
data->updateMarker();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qq->notifyInferiorStopped();
|
|
|
|
|
q->gotoLocation(fileName, lineNumber, true);
|
2009-04-07 13:38:19 +02:00
|
|
|
updateLocals();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-07 13:38:19 +02:00
|
|
|
void ScriptEngine::updateLocals()
|
|
|
|
|
{
|
|
|
|
|
QScriptContext *context = m_scriptEngine->currentContext();
|
2008-12-02 12:01:29 +01:00
|
|
|
qq->watchHandler()->reinitializeWatchers();
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("UPDATE LOCALS");
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Build stack
|
|
|
|
|
//
|
|
|
|
|
QList<StackFrame> stackFrames;
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (QScriptContext *c = context; c; c = c->parentContext(), ++i) {
|
|
|
|
|
QScriptContextInfo info(c);
|
|
|
|
|
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())
|
|
|
|
|
frame.function = "<global scope>";
|
|
|
|
|
//frame.address = ...;
|
|
|
|
|
stackFrames.append(frame);
|
|
|
|
|
}
|
|
|
|
|
qq->stackHandler()->setFrames(stackFrames);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Build locals
|
|
|
|
|
//
|
|
|
|
|
WatchData data;
|
|
|
|
|
data.iname = "local";
|
|
|
|
|
data.name = "local";
|
|
|
|
|
data.scriptValue = context->activationObject();
|
|
|
|
|
qq->watchHandler()->insertData(data);
|
|
|
|
|
updateWatchModel();
|
|
|
|
|
|
|
|
|
|
// FIXME: Use an extra thread. This here is evil
|
|
|
|
|
m_stopped = true;
|
|
|
|
|
while (m_stopped) {
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("LOOPING");
|
2008-12-02 12:01:29 +01:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
}
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("RUNNING AGAIN");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::updateWatchModel()
|
|
|
|
|
{
|
|
|
|
|
while (true) {
|
|
|
|
|
QList<WatchData> list = qq->watchHandler()->takeCurrentIncompletes();
|
|
|
|
|
if (list.isEmpty())
|
|
|
|
|
break;
|
|
|
|
|
foreach (const WatchData &data, list)
|
|
|
|
|
updateSubItem(data);
|
|
|
|
|
}
|
|
|
|
|
qq->watchHandler()->rebuildModel();
|
|
|
|
|
q->showStatusMessage(tr("Stopped."), 5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScriptEngine::updateSubItem(const WatchData &data0)
|
|
|
|
|
{
|
|
|
|
|
WatchData data = data0;
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG("\nUPDATE SUBITEM: " << data.toString());
|
2008-12-09 12:08:56 +01:00
|
|
|
QTC_ASSERT(data.isValid(), return);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (data.isTypeNeeded() || data.isValueNeeded()) {
|
|
|
|
|
QScriptValue ob = data.scriptValue;
|
|
|
|
|
if (ob.isArray()) {
|
|
|
|
|
data.setType("Array");
|
|
|
|
|
data.setValue(" ");
|
|
|
|
|
} else if (ob.isBool()) {
|
|
|
|
|
data.setType("Bool");
|
|
|
|
|
data.setValue(ob.toBool() ? "true" : "false");
|
|
|
|
|
data.setChildCount(0);
|
|
|
|
|
} else if (ob.isDate()) {
|
|
|
|
|
data.setType("Date");
|
|
|
|
|
data.setValue(ob.toDateTime().toString().toUtf8());
|
|
|
|
|
data.setChildCount(0);
|
|
|
|
|
} else if (ob.isError()) {
|
|
|
|
|
data.setType("Error");
|
|
|
|
|
data.setValue(" ");
|
|
|
|
|
} else if (ob.isFunction()) {
|
|
|
|
|
data.setType("Function");
|
|
|
|
|
data.setValue(" ");
|
|
|
|
|
} else if (ob.isNull()) {
|
|
|
|
|
data.setType("<null>");
|
|
|
|
|
data.setValue("<null>");
|
|
|
|
|
} else if (ob.isNumber()) {
|
|
|
|
|
data.setType("Number");
|
|
|
|
|
data.setValue(QString::number(ob.toNumber()).toUtf8());
|
|
|
|
|
data.setChildCount(0);
|
|
|
|
|
} else if (ob.isObject()) {
|
|
|
|
|
data.setType("Object");
|
|
|
|
|
data.setValue(" ");
|
|
|
|
|
} else if (ob.isQMetaObject()) {
|
|
|
|
|
data.setType("QMetaObject");
|
|
|
|
|
data.setValue(" ");
|
|
|
|
|
} else if (ob.isQObject()) {
|
|
|
|
|
data.setType("QObject");
|
|
|
|
|
data.setValue(" ");
|
|
|
|
|
} else if (ob.isRegExp()) {
|
|
|
|
|
data.setType("RegExp");
|
|
|
|
|
data.setValue(ob.toRegExp().pattern().toUtf8());
|
|
|
|
|
} else if (ob.isString()) {
|
|
|
|
|
data.setType("String");
|
|
|
|
|
data.setValue(ob.toString().toUtf8());
|
|
|
|
|
} else if (ob.isVariant()) {
|
|
|
|
|
data.setType("Variant");
|
|
|
|
|
data.setValue(" ");
|
|
|
|
|
} else if (ob.isUndefined()) {
|
|
|
|
|
data.setType("<undefined>");
|
|
|
|
|
data.setValue("<unknown>");
|
|
|
|
|
} else {
|
|
|
|
|
data.setType("<unknown>");
|
|
|
|
|
data.setValue("<unknown>");
|
|
|
|
|
}
|
|
|
|
|
qq->watchHandler()->insertData(data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.isChildrenNeeded()) {
|
|
|
|
|
int numChild = 0;
|
|
|
|
|
QScriptValueIterator it(data.scriptValue);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
WatchData data1;
|
|
|
|
|
data1.iname = data.iname + "." + it.name();
|
2009-04-07 13:38:19 +02:00
|
|
|
data1.exp = it.name();
|
2008-12-02 12:01:29 +01:00
|
|
|
data1.name = it.name();
|
|
|
|
|
data1.scriptValue = it.value();
|
|
|
|
|
if (qq->watchHandler()->isExpandedIName(data1.iname))
|
|
|
|
|
data1.setChildrenNeeded();
|
|
|
|
|
else
|
|
|
|
|
data1.setChildrenUnneeded();
|
|
|
|
|
qq->watchHandler()->insertData(data1);
|
|
|
|
|
++numChild;
|
|
|
|
|
}
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG(" ... CHILDREN: " << numChild);
|
2008-12-02 12:01:29 +01:00
|
|
|
data.setChildCount(numChild);
|
|
|
|
|
data.setChildrenUnneeded();
|
|
|
|
|
qq->watchHandler()->insertData(data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.isChildCountNeeded()) {
|
|
|
|
|
int numChild = 0;
|
|
|
|
|
QScriptValueIterator it(data.scriptValue);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
++numChild;
|
|
|
|
|
}
|
|
|
|
|
data.setChildCount(numChild);
|
2009-04-07 11:24:00 +02:00
|
|
|
//SDEBUG(" ... CHILDCOUNT: " << numChild);
|
2008-12-02 12:01:29 +01:00
|
|
|
qq->watchHandler()->insertData(data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-09 12:08:56 +01:00
|
|
|
QTC_ASSERT(false, return);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-17 09:03:32 +02:00
|
|
|
IDebuggerEngine *createScriptEngine(DebuggerManager *parent, QList<Core::IOptionsPage*> *)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return new ScriptEngine(parent);
|
|
|
|
|
}
|
|
|
|
|
|