forked from qt-creator/qt-creator
Script: Some refactoring.
This commit is contained in:
@@ -231,15 +231,15 @@ bool ScriptManagerPrivate::runScript(const QString &script, QString *errorMessag
|
|||||||
return !failed;
|
return !failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptManagerPrivate::ensureEngineInitialized()
|
ScriptManager::QScriptEnginePtr ScriptManagerPrivate::ensureEngineInitialized()
|
||||||
{
|
{
|
||||||
if (m_engine)
|
if (!m_engine.isNull())
|
||||||
return;
|
return m_engine;
|
||||||
m_engine = new QScriptEngine(this);
|
m_engine = QScriptEnginePtr(new QScriptEngine(this));
|
||||||
// register QObjects that occur as properties
|
// register QObjects that occur as properties
|
||||||
SharedTools::registerQObject<QMainWindow>(m_engine);
|
SharedTools::registerQObject<QMainWindow>(m_engine.data());
|
||||||
SharedTools::registerQObject<QStatusBar>(m_engine);
|
SharedTools::registerQObject<QStatusBar>(m_engine.data());
|
||||||
SharedTools::registerQObject<QSettings>(m_engine);
|
SharedTools::registerQObject<QSettings>(m_engine.data());
|
||||||
// WB interfaces
|
// WB interfaces
|
||||||
// SharedTools::registerQObjectInterface<Core::MessageManager, MessageManagerPrototype>(m_engine);
|
// SharedTools::registerQObjectInterface<Core::MessageManager, MessageManagerPrototype>(m_engine);
|
||||||
|
|
||||||
@@ -248,17 +248,17 @@ void ScriptManagerPrivate::ensureEngineInitialized()
|
|||||||
// SharedTools::registerQObjectInterface<Core::FileManager, FileManagerPrototype>(m_engine);
|
// SharedTools::registerQObjectInterface<Core::FileManager, FileManagerPrototype>(m_engine);
|
||||||
|
|
||||||
// SharedTools::registerQObjectInterface<Core::IEditor, EditorPrototype>(m_engine);
|
// SharedTools::registerQObjectInterface<Core::IEditor, EditorPrototype>(m_engine);
|
||||||
qScriptRegisterSequenceMetaType<QList<Core::IEditor *> >(m_engine);
|
qScriptRegisterSequenceMetaType<QList<Core::IEditor *> >(m_engine.data());
|
||||||
|
|
||||||
// SharedTools::registerQObjectInterface<Core::EditorGroup, EditorGroupPrototype>(m_engine);
|
// SharedTools::registerQObjectInterface<Core::EditorGroup, EditorGroupPrototype>(m_engine);
|
||||||
qScriptRegisterSequenceMetaType<QList<Core::EditorGroup *> >(m_engine);
|
qScriptRegisterSequenceMetaType<QList<Core::EditorGroup *> >(m_engine.data());
|
||||||
|
|
||||||
SharedTools::registerQObjectInterface<Core::EditorManager, EditorManagerPrototype>(m_engine);
|
SharedTools::registerQObjectInterface<Core::EditorManager, EditorManagerPrototype>(m_engine.data());
|
||||||
|
|
||||||
// SharedTools::registerQObjectInterface<Core::ICore, CorePrototype>(m_engine);
|
// SharedTools::registerQObjectInterface<Core::ICore, CorePrototype>(m_engine);
|
||||||
|
|
||||||
// Make "core" available
|
// Make "core" available
|
||||||
m_engine->globalObject().setProperty(QLatin1String("core"), qScriptValueFromValue(m_engine, Core::ICore::instance()));
|
m_engine->globalObject().setProperty(QLatin1String("core"), qScriptValueFromValue(m_engine.data(), Core::ICore::instance()));
|
||||||
|
|
||||||
// CLASSIC: registerInterfaceWithDefaultPrototype<Core::MessageManager, MessageManagerPrototype>(m_engine);
|
// CLASSIC: registerInterfaceWithDefaultPrototype<Core::MessageManager, MessageManagerPrototype>(m_engine);
|
||||||
|
|
||||||
@@ -284,9 +284,10 @@ void ScriptManagerPrivate::ensureEngineInitialized()
|
|||||||
m_engine->globalObject().setProperty(QLatin1String("getOpenFileName"), m_engine->newFunction(fileBox<QFileDialog::AcceptOpen, QFileDialog::ExistingFile> , 2));
|
m_engine->globalObject().setProperty(QLatin1String("getOpenFileName"), m_engine->newFunction(fileBox<QFileDialog::AcceptOpen, QFileDialog::ExistingFile> , 2));
|
||||||
m_engine->globalObject().setProperty(QLatin1String("getSaveFileName"), m_engine->newFunction(fileBox<QFileDialog::AcceptSave, QFileDialog::AnyFile> , 2));
|
m_engine->globalObject().setProperty(QLatin1String("getSaveFileName"), m_engine->newFunction(fileBox<QFileDialog::AcceptSave, QFileDialog::AnyFile> , 2));
|
||||||
m_engine->globalObject().setProperty(QLatin1String("getExistingDirectory"), m_engine->newFunction(fileBox<QFileDialog::AcceptSave, QFileDialog::DirectoryOnly> , 2));
|
m_engine->globalObject().setProperty(QLatin1String("getExistingDirectory"), m_engine->newFunction(fileBox<QFileDialog::AcceptSave, QFileDialog::DirectoryOnly> , 2));
|
||||||
|
return m_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScriptManagerPrivate::engineError(QScriptEngine *scriptEngine)
|
QString ScriptManagerPrivate::engineError(const QScriptEnginePtr &scriptEngine)
|
||||||
{
|
{
|
||||||
QScriptValue error = scriptEngine->evaluate(QLatin1String("Error"));
|
QScriptValue error = scriptEngine->evaluate(QLatin1String("Error"));
|
||||||
if (error.isValid())
|
if (error.isValid())
|
||||||
|
|||||||
@@ -34,7 +34,11 @@
|
|||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtScript/QScriptEngine>
|
#include <QtCore/QSharedPointer>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QScriptEngine;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
@@ -47,6 +51,8 @@ class CORE_EXPORT ScriptManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
typedef QSharedPointer<QScriptEngine> QScriptEnginePtr;
|
||||||
|
|
||||||
// A stack frame as returned by a failed invocation (exception)
|
// A stack frame as returned by a failed invocation (exception)
|
||||||
// fileName may be empty. lineNumber can be 0 for the top frame (goof-up?).
|
// fileName may be empty. lineNumber can be 0 for the top frame (goof-up?).
|
||||||
struct StackFrame {
|
struct StackFrame {
|
||||||
@@ -62,6 +68,8 @@ public:
|
|||||||
// Run a script
|
// Run a script
|
||||||
virtual bool runScript(const QString &script, QString *errorMessage, Stack *errorStack) = 0;
|
virtual bool runScript(const QString &script, QString *errorMessage, Stack *errorStack) = 0;
|
||||||
virtual bool runScript(const QString &script, QString *errorMessage) = 0;
|
virtual bool runScript(const QString &script, QString *errorMessage) = 0;
|
||||||
|
|
||||||
|
virtual QScriptEnginePtr scriptEngine() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -47,13 +47,14 @@ public:
|
|||||||
|
|
||||||
bool runScript(const QString &script, QString *errorMessage, Stack *stack);
|
bool runScript(const QString &script, QString *errorMessage, Stack *stack);
|
||||||
bool runScript(const QString &script, QString *errorMessage);
|
bool runScript(const QString &script, QString *errorMessage);
|
||||||
|
virtual QScriptEnginePtr scriptEngine() { return ensureEngineInitialized(); }
|
||||||
|
|
||||||
static QString engineError(QScriptEngine *scriptEngine);
|
static QString engineError(const QScriptEnginePtr &scriptEngine);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ensureEngineInitialized();
|
QScriptEnginePtr ensureEngineInitialized();
|
||||||
|
|
||||||
QScriptEngine *m_engine;
|
QScriptEnginePtr m_engine;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -45,6 +45,8 @@
|
|||||||
|
|
||||||
#include <texteditor/itexteditor.h>
|
#include <texteditor/itexteditor.h>
|
||||||
#include <coreplugin/ifile.h>
|
#include <coreplugin/ifile.h>
|
||||||
|
#include <coreplugin/scriptmanager/scriptmanager.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
@@ -64,7 +66,7 @@
|
|||||||
#include <QtScript/QScriptValue>
|
#include <QtScript/QScriptValue>
|
||||||
#include <QtScript/QScriptValueIterator>
|
#include <QtScript/QScriptValueIterator>
|
||||||
|
|
||||||
//#define DEBUG_SCRIPT 1
|
// #define DEBUG_SCRIPT 1
|
||||||
#if DEBUG_SCRIPT
|
#if DEBUG_SCRIPT
|
||||||
# define SDEBUG(s) qDebug() << s
|
# define SDEBUG(s) qDebug() << s
|
||||||
#else
|
#else
|
||||||
@@ -124,7 +126,10 @@ void ScriptAgent::exceptionCatch(qint64 scriptId, const QScriptValue & exception
|
|||||||
{
|
{
|
||||||
Q_UNUSED(scriptId)
|
Q_UNUSED(scriptId)
|
||||||
Q_UNUSED(exception)
|
Q_UNUSED(exception)
|
||||||
SDEBUG("ScriptAgent::exceptionCatch: " << scriptId << &exception);
|
const QString msg = QString::fromLatin1("An exception was caught on %1: '%2'").
|
||||||
|
arg(scriptId).arg(exception.toString());
|
||||||
|
SDEBUG(msg);
|
||||||
|
q->showDebuggerOutput(LogMisc, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception,
|
void ScriptAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception,
|
||||||
@@ -133,21 +138,26 @@ void ScriptAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception,
|
|||||||
Q_UNUSED(scriptId)
|
Q_UNUSED(scriptId)
|
||||||
Q_UNUSED(exception)
|
Q_UNUSED(exception)
|
||||||
Q_UNUSED(hasHandler)
|
Q_UNUSED(hasHandler)
|
||||||
SDEBUG("ScriptAgent::exceptionThrow: " << scriptId << &exception
|
const QString msg = QString::fromLatin1("An exception occurred on %1: '%2'").
|
||||||
<< hasHandler);
|
arg(scriptId).arg(exception.toString());
|
||||||
|
SDEBUG(msg);
|
||||||
|
q->showDebuggerOutput(LogMisc, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAgent::functionEntry(qint64 scriptId)
|
void ScriptAgent::functionEntry(qint64 scriptId)
|
||||||
{
|
{
|
||||||
Q_UNUSED(scriptId)
|
Q_UNUSED(scriptId)
|
||||||
q->maybeBreakNow(true);
|
q->showDebuggerOutput(LogMisc, QString::fromLatin1("Function entry occurred on %1").arg(scriptId));
|
||||||
|
q->checkForBreakCondition(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue)
|
void ScriptAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue)
|
||||||
{
|
{
|
||||||
Q_UNUSED(scriptId)
|
Q_UNUSED(scriptId)
|
||||||
Q_UNUSED(returnValue)
|
Q_UNUSED(returnValue)
|
||||||
SDEBUG("ScriptAgent::functionExit: " << scriptId << &returnValue);
|
const QString msg = QString::fromLatin1("Function exit occurred on %1: '%2'").arg(scriptId).arg(returnValue.toString());
|
||||||
|
SDEBUG(msg);
|
||||||
|
q->showDebuggerOutput(LogMisc, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAgent::positionChange(qint64 scriptId, int lineNumber, int columnNumber)
|
void ScriptAgent::positionChange(qint64 scriptId, int lineNumber, int columnNumber)
|
||||||
@@ -156,7 +166,7 @@ void ScriptAgent::positionChange(qint64 scriptId, int lineNumber, int columnNumb
|
|||||||
Q_UNUSED(scriptId)
|
Q_UNUSED(scriptId)
|
||||||
Q_UNUSED(lineNumber)
|
Q_UNUSED(lineNumber)
|
||||||
Q_UNUSED(columnNumber)
|
Q_UNUSED(columnNumber)
|
||||||
q->maybeBreakNow(false);
|
q->checkForBreakCondition(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAgent::scriptLoad(qint64 scriptId, const QString &program,
|
void ScriptAgent::scriptLoad(qint64 scriptId, const QString &program,
|
||||||
@@ -166,8 +176,7 @@ void ScriptAgent::scriptLoad(qint64 scriptId, const QString &program,
|
|||||||
Q_UNUSED(program)
|
Q_UNUSED(program)
|
||||||
Q_UNUSED(fileName)
|
Q_UNUSED(fileName)
|
||||||
Q_UNUSED(baseLineNumber)
|
Q_UNUSED(baseLineNumber)
|
||||||
SDEBUG("ScriptAgent::scriptLoad: " << program << fileName
|
q->showDebuggerOutput(LogMisc, QString::fromLatin1("Loaded: %1 id: %2").arg(fileName).arg(scriptId));
|
||||||
<< baseLineNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAgent::scriptUnload(qint64 scriptId)
|
void ScriptAgent::scriptUnload(qint64 scriptId)
|
||||||
@@ -186,9 +195,6 @@ void ScriptAgent::scriptUnload(qint64 scriptId)
|
|||||||
ScriptEngine::ScriptEngine(DebuggerManager *manager)
|
ScriptEngine::ScriptEngine(DebuggerManager *manager)
|
||||||
: IDebuggerEngine(manager)
|
: IDebuggerEngine(manager)
|
||||||
{
|
{
|
||||||
// created in startDebugger()
|
|
||||||
m_scriptEngine = 0;
|
|
||||||
m_scriptAgent = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEngine::~ScriptEngine()
|
ScriptEngine::~ScriptEngine()
|
||||||
@@ -208,30 +214,45 @@ void ScriptEngine::shutdown()
|
|||||||
|
|
||||||
void ScriptEngine::exitDebugger()
|
void ScriptEngine::exitDebugger()
|
||||||
{
|
{
|
||||||
|
if (state() == DebuggerNotReady)
|
||||||
|
return;
|
||||||
SDEBUG("ScriptEngine::exitDebugger()");
|
SDEBUG("ScriptEngine::exitDebugger()");
|
||||||
m_stopped = false;
|
m_stopped = false;
|
||||||
m_stopOnNextLine = false;
|
m_stopOnNextLine = false;
|
||||||
|
if (m_scriptEngine->isEvaluating())
|
||||||
m_scriptEngine->abortEvaluation();
|
m_scriptEngine->abortEvaluation();
|
||||||
manager()->notifyInferiorExited();
|
setState(InferiorShuttingDown);
|
||||||
|
setState(InferiorShutDown);
|
||||||
|
|
||||||
|
setState(EngineShuttingDown);
|
||||||
|
m_scriptEngine->setAgent(0);
|
||||||
|
setState(DebuggerNotReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::startDebugger(const DebuggerStartParametersPtr &sp)
|
void ScriptEngine::startDebugger(const DebuggerStartParametersPtr &sp)
|
||||||
{
|
{
|
||||||
if (!m_scriptEngine)
|
setState(AdapterStarting);
|
||||||
m_scriptEngine = new QScriptEngine(this);
|
if (m_scriptEngine.isNull())
|
||||||
|
m_scriptEngine = Core::ICore::instance()->scriptManager()->scriptEngine();
|
||||||
if (!m_scriptAgent)
|
if (!m_scriptAgent)
|
||||||
m_scriptAgent = new ScriptAgent(this, m_scriptEngine);
|
m_scriptAgent.reset(new ScriptAgent(this, m_scriptEngine.data()));
|
||||||
m_scriptEngine->setAgent(m_scriptAgent);
|
m_scriptEngine->setAgent(m_scriptAgent.data());
|
||||||
|
/* Keep the gui alive (have the engine call processEvents() while the script
|
||||||
|
* is run in the foreground). */
|
||||||
m_scriptEngine->setProcessEventsInterval(1 /*ms*/);
|
m_scriptEngine->setProcessEventsInterval(1 /*ms*/);
|
||||||
|
|
||||||
m_stopped = false;
|
m_stopped = false;
|
||||||
m_stopOnNextLine = false;
|
m_stopOnNextLine = false;
|
||||||
m_scriptEngine->abortEvaluation();
|
m_scriptEngine->abortEvaluation();
|
||||||
|
|
||||||
QFileInfo fi(sp->executable);
|
setState(AdapterStarted);
|
||||||
m_scriptFileName = fi.absoluteFilePath();
|
setState(InferiorStarting);
|
||||||
|
|
||||||
|
m_scriptFileName = QFileInfo (sp->executable).absoluteFilePath();
|
||||||
QFile scriptFile(m_scriptFileName);
|
QFile scriptFile(m_scriptFileName);
|
||||||
if (!scriptFile.open(QIODevice::ReadOnly)) {
|
if (!scriptFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
||||||
|
manager()->showDebuggerOutput(LogError, QString::fromLatin1("Cannot open %1: %2").
|
||||||
|
arg(m_scriptFileName, scriptFile.errorString()));
|
||||||
emit startFailed();
|
emit startFailed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -241,6 +262,7 @@ void ScriptEngine::startDebugger(const DebuggerStartParametersPtr &sp)
|
|||||||
attemptBreakpointSynchronization();
|
attemptBreakpointSynchronization();
|
||||||
setState(InferiorRunningRequested);
|
setState(InferiorRunningRequested);
|
||||||
showStatusMessage(tr("Running requested..."), 5000);
|
showStatusMessage(tr("Running requested..."), 5000);
|
||||||
|
manager()->showDebuggerOutput(LogMisc, QLatin1String("Running: ") + m_scriptFileName);
|
||||||
QTimer::singleShot(0, this, SLOT(runInferior()));
|
QTimer::singleShot(0, this, SLOT(runInferior()));
|
||||||
emit startSuccessful();
|
emit startSuccessful();
|
||||||
}
|
}
|
||||||
@@ -252,34 +274,28 @@ void ScriptEngine::continueInferior()
|
|||||||
m_stopOnNextLine = false;
|
m_stopOnNextLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::runInferior()
|
static const char *qtExtensionsC[] = {
|
||||||
|
"qt.core", "qt.gui", "qt.xml", "qt.svg", "qt.network",
|
||||||
|
"qt.sql", "qt.opengl", "qt.webkit", "qt.xmlpatterns", "qt.uitools"
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ScriptEngine::importExtensions()
|
||||||
{
|
{
|
||||||
//QDir dir(QApplication::applicationDirPath());
|
SDEBUG("ScriptEngine::importExtensions()");
|
||||||
//if (dir.dirName() == QLatin1String("debug") || dir.dirName() == QLatin1String("release"))
|
QStringList extensions;
|
||||||
// dir.cdUp();
|
const int extCount = sizeof(qtExtensionsC)/sizeof(const char *);
|
||||||
//dir.cdUp();
|
for (int e = 0; e < extCount; e++)
|
||||||
//dir.cdUp();
|
extensions.append(QLatin1String(qtExtensionsC[e]));
|
||||||
|
if (m_scriptEngine->importedExtensions().contains(extensions.front()))
|
||||||
|
return true;
|
||||||
QDir dir("/home/apoenitz/dev/qtscriptgenerator");
|
QDir dir("/home/apoenitz/dev/qtscriptgenerator");
|
||||||
if (!dir.cd("plugins")) {
|
if (!dir.cd("plugins")) {
|
||||||
fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
|
fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
QStringList paths = qApp->libraryPaths();
|
QStringList paths = qApp->libraryPaths();
|
||||||
paths << dir.absolutePath();
|
paths << dir.absolutePath();
|
||||||
qApp->setLibraryPaths(paths);
|
qApp->setLibraryPaths(paths);
|
||||||
|
|
||||||
SDEBUG("ScriptEngine::runInferior()");
|
|
||||||
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;
|
QStringList failExtensions;
|
||||||
foreach (const QString &ext, extensions) {
|
foreach (const QString &ext, extensions) {
|
||||||
QScriptValue ret = m_scriptEngine->importExtension(ext);
|
QScriptValue ret = m_scriptEngine->importExtension(ext);
|
||||||
@@ -302,8 +318,26 @@ void ScriptEngine::runInferior()
|
|||||||
qPrintable(failExtensions.join(", ")), qPrintable(dir.absolutePath()));
|
qPrintable(failExtensions.join(", ")), qPrintable(dir.absolutePath()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return failExtensions.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue result = m_scriptEngine->evaluate(m_scriptContents, m_scriptFileName);
|
void ScriptEngine::runInferior()
|
||||||
|
{
|
||||||
|
SDEBUG("ScriptEngine::runInferior()");
|
||||||
|
importExtensions();
|
||||||
|
setState(InferiorRunning);
|
||||||
|
const QScriptValue result = m_scriptEngine->evaluate(m_scriptContents, m_scriptFileName);
|
||||||
|
setState(InferiorStopping);
|
||||||
|
setState(InferiorStopped);
|
||||||
|
if (m_scriptEngine->hasUncaughtException()) {
|
||||||
|
QString msg = QString::fromLatin1("An exception occurred during execution at line: %1\n%2\n").
|
||||||
|
arg(m_scriptEngine->uncaughtExceptionLineNumber()).arg(m_scriptEngine->uncaughtException().toString());
|
||||||
|
msg += m_scriptEngine->uncaughtExceptionBacktrace().join(QString(QLatin1Char('\n')));
|
||||||
|
showDebuggerOutput(LogMisc, msg);
|
||||||
|
} else {
|
||||||
|
showDebuggerOutput(LogMisc, QString::fromLatin1("Evaluation returns '%1'").arg(result.toString()));
|
||||||
|
}
|
||||||
|
exitDebugger();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::interruptInferior()
|
void ScriptEngine::interruptInferior()
|
||||||
@@ -427,6 +461,7 @@ QList<Symbol> ScriptEngine::moduleSymbols(const QString & /*moduleName*/)
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
static WatchData m_toolTip;
|
static WatchData m_toolTip;
|
||||||
static QPoint m_toolTipPos;
|
static QPoint m_toolTipPos;
|
||||||
static QHash<QString, WatchData> m_toolTipCache;
|
static QHash<QString, WatchData> m_toolTipCache;
|
||||||
@@ -521,44 +556,55 @@ void ScriptEngine::assignValueInDebugger(const QString &expression,
|
|||||||
updateLocals();
|
updateLocals();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::maybeBreakNow(bool byFunction)
|
static BreakpointData *findBreakPointByFunction(BreakHandler *handler,
|
||||||
|
const QString &functionName)
|
||||||
{
|
{
|
||||||
QScriptContext *context = m_scriptEngine->currentContext();
|
const int count = handler->size();
|
||||||
QScriptContextInfo info(context);
|
for (int b = 0; b < count; b++) {
|
||||||
|
BreakpointData *data = handler->at(b);
|
||||||
|
if (data->funcName == functionName)
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BreakpointData *findBreakPointByFileName(BreakHandler *handler,
|
||||||
|
int lineNumber,
|
||||||
|
const QString &fileName)
|
||||||
|
{
|
||||||
|
const int count = handler->size();
|
||||||
|
for (int b = 0; b < count; b++) {
|
||||||
|
BreakpointData *data = handler->at(b);
|
||||||
|
if (lineNumber == data->lineNumber.toInt() && fileName == data->fileName)
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptEngine::checkForBreakCondition(bool byFunction)
|
||||||
|
{
|
||||||
|
const QScriptContext *context = m_scriptEngine->currentContext();
|
||||||
|
const QScriptContextInfo info(context);
|
||||||
|
|
||||||
//
|
|
||||||
// Update breakpoints
|
// Update breakpoints
|
||||||
//
|
const QString functionName = info.functionName();
|
||||||
QString functionName = info.functionName();
|
const QString fileName = info.fileName();
|
||||||
QString fileName = info.fileName();
|
const int lineNumber = byFunction? info.functionStartLineNumber() : info.lineNumber();
|
||||||
int lineNumber = info.lineNumber();
|
SDEBUG("checkForBreakCondition" << byFunction << functionName << lineNumber << fileName);
|
||||||
if (byFunction)
|
|
||||||
lineNumber = info.functionStartLineNumber();
|
|
||||||
|
|
||||||
BreakHandler *handler = manager()->breakHandler();
|
|
||||||
|
|
||||||
if (m_stopOnNextLine) {
|
if (m_stopOnNextLine) {
|
||||||
|
// Interrupt inferior
|
||||||
m_stopOnNextLine = false;
|
m_stopOnNextLine = false;
|
||||||
} else {
|
} else {
|
||||||
int index = 0;
|
if (byFunction && functionName.isEmpty())
|
||||||
for (; index != handler->size(); ++index) {
|
return false;
|
||||||
BreakpointData *data = handler->at(index);
|
BreakpointData *data = byFunction ?
|
||||||
if (byFunction) {
|
findBreakPointByFunction(manager()->breakHandler(), functionName) :
|
||||||
if (!functionName.isEmpty() && data->funcName == functionName)
|
findBreakPointByFileName(manager()->breakHandler(), lineNumber, fileName);
|
||||||
break;
|
if (!data)
|
||||||
} else {
|
return false;
|
||||||
if (info.lineNumber() == data->lineNumber.toInt()
|
|
||||||
&& fileName == data->fileName)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index == handler->size())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// we just run into a breakpoint
|
// we just run into a breakpoint
|
||||||
//SDEBUG("RESOLVING BREAKPOINT AT " << fileName << lineNumber);
|
//SDEBUG("RESOLVING BREAKPOINT AT " << fileName << lineNumber);
|
||||||
BreakpointData *data = handler->at(index);
|
|
||||||
data->bpLineNumber = QByteArray::number(lineNumber);
|
data->bpLineNumber = QByteArray::number(lineNumber);
|
||||||
data->bpFileName = fileName;
|
data->bpFileName = fileName;
|
||||||
data->bpFuncName = functionName;
|
data->bpFuncName = functionName;
|
||||||
@@ -567,15 +613,17 @@ void ScriptEngine::maybeBreakNow(bool byFunction)
|
|||||||
data->pending = false;
|
data->pending = false;
|
||||||
data->updateMarker();
|
data->updateMarker();
|
||||||
}
|
}
|
||||||
|
setState(InferiorStopping);
|
||||||
setState(InferiorStopped);
|
setState(InferiorStopped);
|
||||||
showStatusMessage(tr("Stopped."), 5000);
|
SDEBUG("Stopped at " << lineNumber << fileName);
|
||||||
|
showStatusMessage(tr("Stopped at %1:%2.").arg(fileName).arg(lineNumber), 5000);
|
||||||
|
|
||||||
StackFrame frame;
|
StackFrame frame;
|
||||||
frame.file = fileName;
|
frame.file = fileName;
|
||||||
frame.line = lineNumber;
|
frame.line = lineNumber;
|
||||||
manager()->gotoLocation(frame, true);
|
manager()->gotoLocation(frame, true);
|
||||||
updateLocals();
|
updateLocals();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::updateLocals()
|
void ScriptEngine::updateLocals()
|
||||||
@@ -590,7 +638,7 @@ void ScriptEngine::updateLocals()
|
|||||||
QList<StackFrame> stackFrames;
|
QList<StackFrame> stackFrames;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (QScriptContext *c = context; c; c = c->parentContext(), ++i) {
|
for (QScriptContext *c = context; c; c = c->parentContext(), ++i) {
|
||||||
QScriptContextInfo info(c);
|
const QScriptContextInfo info(c);
|
||||||
StackFrame frame;
|
StackFrame frame;
|
||||||
frame.level = i;
|
frame.level = i;
|
||||||
frame.file = info.fileName();
|
frame.file = info.fileName();
|
||||||
@@ -598,9 +646,8 @@ void ScriptEngine::updateLocals()
|
|||||||
frame.from = QString::number(info.functionStartLineNumber());
|
frame.from = QString::number(info.functionStartLineNumber());
|
||||||
frame.to = QString::number(info.functionEndLineNumber());
|
frame.to = QString::number(info.functionEndLineNumber());
|
||||||
frame.line = info.lineNumber();
|
frame.line = info.lineNumber();
|
||||||
|
|
||||||
if (frame.function.isEmpty())
|
if (frame.function.isEmpty())
|
||||||
frame.function = "<global scope>";
|
frame.function = QLatin1String("<global scope>");
|
||||||
//frame.address = ...;
|
//frame.address = ...;
|
||||||
stackFrames.append(frame);
|
stackFrames.append(frame);
|
||||||
}
|
}
|
||||||
@@ -736,6 +783,11 @@ void ScriptEngine::updateSubItem(const WatchData &data0)
|
|||||||
QTC_ASSERT(false, return);
|
QTC_ASSERT(false, return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEngine::showDebuggerOutput(int channel, const QString &m)
|
||||||
|
{
|
||||||
|
manager()->showDebuggerOutput(channel, m);
|
||||||
|
}
|
||||||
|
|
||||||
IDebuggerEngine *createScriptEngine(DebuggerManager *manager)
|
IDebuggerEngine *createScriptEngine(DebuggerManager *manager)
|
||||||
{
|
{
|
||||||
return new ScriptEngine(manager);
|
return new ScriptEngine(manager);
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
#include <QtCore/QPoint>
|
#include <QtCore/QPoint>
|
||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtCore/QSharedPointer>
|
||||||
|
#include <QtCore/QScopedPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
@@ -103,18 +105,22 @@ private:
|
|||||||
void reloadFullStack() {}
|
void reloadFullStack() {}
|
||||||
|
|
||||||
bool supportsThreads() const { return true; }
|
bool supportsThreads() const { return true; }
|
||||||
void maybeBreakNow(bool byFunction);
|
bool checkForBreakCondition(bool byFunction);
|
||||||
void updateWatchData(const WatchData &data);
|
void updateWatchData(const WatchData &data);
|
||||||
void updateLocals();
|
void updateLocals();
|
||||||
void updateSubItem(const WatchData &data);
|
void updateSubItem(const WatchData &data);
|
||||||
|
|
||||||
|
Q_SLOT void showDebuggerOutput(int channel, const QString &m);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ScriptAgent;
|
friend class ScriptAgent;
|
||||||
|
|
||||||
QScriptEngine *m_scriptEngine;
|
bool importExtensions();
|
||||||
|
|
||||||
|
QSharedPointer<QScriptEngine> m_scriptEngine;
|
||||||
QString m_scriptContents;
|
QString m_scriptContents;
|
||||||
QString m_scriptFileName;
|
QString m_scriptFileName;
|
||||||
ScriptAgent *m_scriptAgent;
|
QScopedPointer<ScriptAgent> m_scriptAgent;
|
||||||
|
|
||||||
bool m_stopped;
|
bool m_stopped;
|
||||||
bool m_stopOnNextLine;
|
bool m_stopOnNextLine;
|
||||||
|
|||||||
Reference in New Issue
Block a user