Files
qt-creator/src/plugins/debugger/script/scriptengine.cpp

796 lines
24 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** 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.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 12:01:29 +01:00
#include "scriptengine.h"
#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 "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
#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>
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>
#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>
2010-01-15 17:30:26 +01: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
# define XSDEBUG(s) qDebug() << s
2008-12-02 12:01:29 +01:00
namespace Debugger {
namespace Internal {
2008-12-02 12:01:29 +01:00
///////////////////////////////////////////////////////////////////////
//
// ScriptEngine
//
///////////////////////////////////////////////////////////////////////
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);
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)
{
Q_UNUSED(scriptId)
Q_UNUSED(exception)
2010-01-15 17:30:26 +01:00
const QString msg = QString::fromLatin1("An exception was caught on %1: '%2'").
arg(scriptId).arg(exception.toString());
SDEBUG(msg);
q->showDebuggerOutput(LogMisc, msg);
2008-12-02 12:01:29 +01:00
}
void ScriptAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception,
bool hasHandler)
{
Q_UNUSED(scriptId)
Q_UNUSED(exception)
Q_UNUSED(hasHandler)
2010-01-15 17:30:26 +01:00
const QString msg = QString::fromLatin1("An exception occurred on %1: '%2'").
arg(scriptId).arg(exception.toString());
SDEBUG(msg);
q->showDebuggerOutput(LogMisc, msg);
2008-12-02 12:01:29 +01:00
}
void ScriptAgent::functionEntry(qint64 scriptId)
{
Q_UNUSED(scriptId)
2010-01-15 17:30:26 +01:00
q->showDebuggerOutput(LogMisc, QString::fromLatin1("Function entry occurred on %1").arg(scriptId));
q->checkForBreakCondition(true);
2008-12-02 12:01:29 +01:00
}
void ScriptAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue)
{
Q_UNUSED(scriptId)
Q_UNUSED(returnValue)
2010-01-15 17:30:26 +01:00
const QString msg = QString::fromLatin1("Function exit occurred on %1: '%2'").arg(scriptId).arg(returnValue.toString());
SDEBUG(msg);
q->showDebuggerOutput(LogMisc, msg);
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);
Q_UNUSED(scriptId)
Q_UNUSED(lineNumber)
Q_UNUSED(columnNumber)
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)
{
Q_UNUSED(scriptId)
Q_UNUSED(program)
Q_UNUSED(fileName)
Q_UNUSED(baseLineNumber)
2010-01-15 17:30:26 +01:00
q->showDebuggerOutput(LogMisc, QString::fromLatin1("Loaded: %1 id: %2").arg(fileName).arg(scriptId));
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 *manager)
: IDebuggerEngine(manager)
2008-12-02 12:01:29 +01:00
{
}
ScriptEngine::~ScriptEngine()
{
}
void ScriptEngine::executeDebuggerCommand(const QString &command)
{
Q_UNUSED(command)
XSDEBUG("FIXME: ScriptEngine::executeDebuggerCommand()");
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::shutdown()
{
exitDebugger();
}
void ScriptEngine::exitDebugger()
{
2010-01-15 17:30:26 +01:00
if (state() == DebuggerNotReady)
return;
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;
2010-01-15 17:30:26 +01:00
if (m_scriptEngine->isEvaluating())
m_scriptEngine->abortEvaluation();
setState(InferiorShuttingDown);
setState(InferiorShutDown);
setState(EngineShuttingDown);
m_scriptEngine->setAgent(0);
setState(DebuggerNotReady);
2008-12-02 12:01:29 +01:00
}
2009-09-17 14:38:15 +02:00
void ScriptEngine::startDebugger(const DebuggerStartParametersPtr &sp)
2008-12-02 12:01:29 +01:00
{
2010-01-15 17:30:26 +01:00
setState(AdapterStarting);
if (m_scriptEngine.isNull())
m_scriptEngine = Core::ICore::instance()->scriptManager()->scriptEngine();
if (!m_scriptAgent)
2010-01-15 17:30:26 +01:00
m_scriptAgent.reset(new ScriptAgent(this, m_scriptEngine.data()));
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*/);
2008-12-02 12:01:29 +01:00
m_stopped = false;
m_stopOnNextLine = false;
m_scriptEngine->abortEvaluation();
2010-01-15 17:30:26 +01:00
setState(AdapterStarted);
setState(InferiorStarting);
m_scriptFileName = QFileInfo (sp->executable).absoluteFilePath();
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)) {
manager()->showDebuggerOutput(LogError, QString::fromLatin1("Cannot open %1: %2").
arg(m_scriptFileName, scriptFile.errorString()));
2009-09-10 13:09:42 +02:00
emit startFailed();
return;
}
2008-12-02 12:01:29 +01:00
QTextStream stream(&scriptFile);
m_scriptContents = stream.readAll();
scriptFile.close();
attemptBreakpointSynchronization();
setState(InferiorRunningRequested);
showStatusMessage(tr("Running requested..."), 5000);
2010-01-15 17:30:26 +01:00
manager()->showDebuggerOutput(LogMisc, QLatin1String("Running: ") + m_scriptFileName);
2009-04-07 11:24:00 +02:00
QTimer::singleShot(0, this, SLOT(runInferior()));
2009-09-10 13:09:42 +02:00
emit startSuccessful();
2008-12-02 12:01:29 +01:00
}
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;
}
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"
};
bool 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()))
return true;
QDir dir("/home/apoenitz/dev/qtscriptgenerator");
if (!dir.cd("plugins")) {
fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
2010-01-15 17:30:26 +01:00
return false;
}
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.",
qPrintable(failExtensions.join(", ")), qPrintable(dir.absolutePath()));
}
}
2010-01-15 17:30:26 +01:00
return failExtensions.isEmpty();
}
2010-01-15 17:30:26 +01:00
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();
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::interruptInferior()
{
m_stopped = false;
m_stopOnNextLine = true;
XSDEBUG("ScriptEngine::interruptInferior()");
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::stepExec()
{
//SDEBUG("ScriptEngine::stepExec()");
2008-12-02 12:01:29 +01:00
m_stopped = false;
m_stopOnNextLine = true;
}
void ScriptEngine::stepIExec()
{
//SDEBUG("ScriptEngine::stepIExec()");
2008-12-02 12:01:29 +01:00
m_stopped = false;
m_stopOnNextLine = true;
}
void ScriptEngine::stepOutExec()
{
//SDEBUG("ScriptEngine::stepOutExec()");
2008-12-02 12:01:29 +01:00
m_stopped = false;
m_stopOnNextLine = true;
}
void ScriptEngine::nextExec()
{
//SDEBUG("ScriptEngine::nextExec()");
2008-12-02 12:01:29 +01:00
m_stopped = false;
m_stopOnNextLine = true;
}
void ScriptEngine::nextIExec()
{
//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)
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)
XSDEBUG("FIXME: ScriptEngine::jumpToLineExec()");
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::activateFrame(int index)
{
Q_UNUSED(index)
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::selectThread(int index)
{
Q_UNUSED(index)
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::attemptBreakpointSynchronization()
{
BreakHandler *handler = manager()->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()) {
data->bpNumber = QByteArray::number(index + 1);
2008-12-02 12:01:29 +01:00
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::loadSymbols(const QString &moduleName)
{
Q_UNUSED(moduleName)
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::loadAllSymbols()
{
}
void ScriptEngine::reloadModules()
{
}
QList<Symbol> ScriptEngine::moduleSymbols(const QString & /*moduleName*/)
{
return QList<Symbol>();
}
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;
void ScriptEngine::setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor, int cursorPos)
2008-12-02 12:01:29 +01:00
{
Q_UNUSED(mousePos)
Q_UNUSED(editor)
Q_UNUSED(cursorPos)
2008-12-02 12:01:29 +01:00
if (state() != InferiorStopped) {
2009-04-07 11:24:00 +02:00
//SDEBUG("SUPPRESSING DEBUGGER TOOLTIP, INFERIOR NOT STOPPED");
2008-12-02 12:01:29 +01:00
return;
}
// Check mime type and get expression (borrowing some C++ - functions)
const QString javaScriptMimeType =
2010-01-15 17:36:49 +01:00
QLatin1String("application/javascript");
if (!editor->file() || editor->file()->mimeType() != javaScriptMimeType)
return;
2008-12-02 12:01:29 +01: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)) {
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('"')) {
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,
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() != InferiorStopped)
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
//
//////////////////////////////////////////////////////////////////////
void ScriptEngine::assignValueInDebugger(const QString &expression,
const QString &value)
{
XSDEBUG("ASSIGNING: " << expression + '=' + value);
m_scriptEngine->evaluate(expression + '=' + value);
updateLocals();
2008-12-02 12:01:29 +01:00
}
2010-01-15 17:30:26 +01:00
static BreakpointData *findBreakPointByFunction(BreakHandler *handler,
const QString &functionName)
2008-12-02 12:01:29 +01:00
{
2010-01-15 17:30:26 +01:00
const int count = handler->size();
for (int b = 0; b < count; b++) {
BreakpointData *data = handler->at(b);
if (data->funcName == functionName)
return data;
}
return 0;
}
2008-12-02 12:01:29 +01:00
2010-01-15 17:30:26 +01:00
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;
}
2008-12-02 12:01:29 +01:00
2010-01-15 17:30:26 +01:00
bool ScriptEngine::checkForBreakCondition(bool byFunction)
{
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();
const int lineNumber = byFunction? info.functionStartLineNumber() : info.lineNumber();
SDEBUG("checkForBreakCondition" << 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;
BreakpointData *data = byFunction ?
findBreakPointByFunction(manager()->breakHandler(), functionName) :
findBreakPointByFileName(manager()->breakHandler(), lineNumber, fileName);
if (!data)
return false;
2008-12-02 12:01:29 +01:00
// we just run into a breakpoint
2009-04-07 11:24:00 +02:00
//SDEBUG("RESOLVING BREAKPOINT AT " << fileName << lineNumber);
data->bpLineNumber = QByteArray::number(lineNumber);
2008-12-02 12:01:29 +01:00
data->bpFileName = fileName;
data->bpFuncName = functionName;
data->markerLineNumber = lineNumber;
data->markerFileName = fileName;
data->pending = false;
data->updateMarker();
}
2010-01-15 17:30:26 +01:00
setState(InferiorStopping);
setState(InferiorStopped);
2010-01-15 17:30:26 +01:00
SDEBUG("Stopped at " << lineNumber << fileName);
showStatusMessage(tr("Stopped at %1:%2.").arg(fileName).arg(lineNumber), 5000);
StackFrame frame;
frame.file = fileName;
frame.line = lineNumber;
manager()->gotoLocation(frame, true);
updateLocals();
2010-01-15 17:30:26 +01:00
return true;
}
2008-12-02 12:01:29 +01:00
void ScriptEngine::updateLocals()
{
QScriptContext *context = m_scriptEngine->currentContext();
manager()->watchHandler()->beginCycle();
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) {
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);
}
manager()->stackHandler()->setFrames(stackFrames);
2008-12-02 12:01:29 +01:00
//
// Build locals
//
WatchData data;
data.iname = "local";
data.name = "local";
data.scriptValue = context->activationObject();
manager()->watchHandler()->beginCycle();
updateSubItem(data);
manager()->watchHandler()->endCycle();
2008-12-02 12:01:29 +01:00
// FIXME: Use an extra thread. This here is evil
m_stopped = true;
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();
}
2009-04-07 11:24:00 +02:00
//SDEBUG("RUNNING AGAIN");
2008-12-02 12:01:29 +01:00
}
void ScriptEngine::updateWatchData(const WatchData &data)
2008-12-02 12:01:29 +01:00
{
updateSubItem(data);
//manager()->watchHandler()->rebuildModel();
2008-12-02 12:01:29 +01:00
}
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.setHasChildren(false);
2008-12-02 12:01:29 +01:00
} else if (ob.isDate()) {
data.setType("Date");
data.setValue(ob.toDateTime().toString().toUtf8());
data.setHasChildren(false);
2008-12-02 12:01:29 +01:00
} 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.setHasChildren(false);
2008-12-02 12:01:29 +01:00
} 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>");
data.setHasChildren(false);
2008-12-02 12:01:29 +01:00
} else {
data.setType("<unknown>");
data.setValue("<unknown>");
data.setHasChildren(false);
2008-12-02 12:01:29 +01:00
}
manager()->watchHandler()->insertData(data);
2008-12-02 12:01:29 +01:00
return;
}
if (data.isChildrenNeeded()) {
int numChild = 0;
QScriptValueIterator it(data.scriptValue);
while (it.hasNext()) {
it.next();
WatchData data1;
data1.iname = data.iname + "." + it.name().toLatin1();
data1.exp = it.name().toLatin1();
2008-12-02 12:01:29 +01:00
data1.name = it.name();
data1.scriptValue = it.value();
if (manager()->watchHandler()->isExpandedIName(data1.iname))
2008-12-02 12:01:29 +01:00
data1.setChildrenNeeded();
else
data1.setChildrenUnneeded();
manager()->watchHandler()->insertData(data1);
2008-12-02 12:01:29 +01:00
++numChild;
}
2009-04-07 11:24:00 +02:00
//SDEBUG(" ... CHILDREN: " << numChild);
data.setHasChildren(numChild > 0);
2008-12-02 12:01:29 +01:00
data.setChildrenUnneeded();
manager()->watchHandler()->insertData(data);
2008-12-02 12:01:29 +01:00
return;
}
if (data.isHasChildrenNeeded()) {
2008-12-02 12:01:29 +01:00
int numChild = 0;
QScriptValueIterator it(data.scriptValue);
while (it.hasNext()) {
it.next();
++numChild;
}
data.setHasChildren(numChild > 0);
2009-04-07 11:24:00 +02:00
//SDEBUG(" ... CHILDCOUNT: " << numChild);
manager()->watchHandler()->insertData(data);
2008-12-02 12:01:29 +01:00
return;
}
2008-12-09 12:08:56 +01:00
QTC_ASSERT(false, return);
2008-12-02 12:01:29 +01:00
}
2010-01-15 17:30:26 +01:00
void ScriptEngine::showDebuggerOutput(int channel, const QString &m)
{
manager()->showDebuggerOutput(channel, m);
}
IDebuggerEngine *createScriptEngine(DebuggerManager *manager)
2008-12-02 12:01:29 +01:00
{
return new ScriptEngine(manager);
2008-12-02 12:01:29 +01:00
}
} // namespace Internal
} // namespace Debugger