QmlV8DebuggerClient: Introduce Debugger client states

Change List:
Introduced states to prevent possible race condition on the
service side which uses an event loop. Evaluations in QML
Script Console is reflected in the Locals Window.

Change-Id: I1b7644b856168fd59e1cf1d1498c7107d42f2af5
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
Aurindam Jana
2011-10-26 10:32:46 +02:00
parent f3c047a33c
commit 8cff1db82b
2 changed files with 49 additions and 22 deletions

View File

@@ -79,7 +79,7 @@ public:
sequence(-1), sequence(-1),
engine(0) engine(0)
{ {
q->reset(); q->resetState();
parser = m_scriptEngine.evaluate(_("JSON.parse")); parser = m_scriptEngine.evaluate(_("JSON.parse"));
stringifier = m_scriptEngine.evaluate(_("JSON.stringify")); stringifier = m_scriptEngine.evaluate(_("JSON.stringify"));
} }
@@ -134,6 +134,7 @@ public:
QScriptValue parser; QScriptValue parser;
QScriptValue stringifier; QScriptValue stringifier;
QmlV8DebuggerClient::V8DebuggerStates state;
int currentFrameIndex; int currentFrameIndex;
bool updateCurrentStackFrameIndex; bool updateCurrentStackFrameIndex;
private: private:
@@ -189,7 +190,7 @@ void QmlV8DebuggerClientPrivate::continueDebugging(QmlV8DebuggerClient::StepActi
int count) int count)
{ {
//First reset //First reset
q->reset(); q->resetState();
// { "seq" : <number>, // { "seq" : <number>,
// "type" : "request", // "type" : "request",
@@ -857,49 +858,50 @@ void QmlV8DebuggerClient::startSession()
void QmlV8DebuggerClient::endSession() void QmlV8DebuggerClient::endSession()
{ {
resetState();
d->disconnect(); d->disconnect();
} }
void QmlV8DebuggerClient::executeStep() void QmlV8DebuggerClient::executeStep()
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState);
d->continueDebugging(In); d->continueDebugging(In);
} }
void QmlV8DebuggerClient::executeStepOut() void QmlV8DebuggerClient::executeStepOut()
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState);
d->continueDebugging(Out); d->continueDebugging(Out);
} }
void QmlV8DebuggerClient::executeNext() void QmlV8DebuggerClient::executeNext()
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState);
d->continueDebugging(Next); d->continueDebugging(Next);
} }
void QmlV8DebuggerClient::executeStepI() void QmlV8DebuggerClient::executeStepI()
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState);
d->continueDebugging(In); d->continueDebugging(In);
} }
void QmlV8DebuggerClient::continueInferior() void QmlV8DebuggerClient::continueInferior()
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState);
d->continueDebugging(Continue); d->continueDebugging(Continue);
} }
void QmlV8DebuggerClient::interruptInferior() void QmlV8DebuggerClient::interruptInferior()
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState
|| d->state == QmlV8DebuggerClient::RunningState);
d->interrupt(); d->interrupt();
} }
void QmlV8DebuggerClient::activateFrame(int index) void QmlV8DebuggerClient::activateFrame(int index)
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState);
d->backtrace(index); d->backtrace(index);
} }
@@ -913,8 +915,8 @@ bool QmlV8DebuggerClient::acceptsBreakpoint(const BreakpointModelId &id)
void QmlV8DebuggerClient::insertBreakpoint(const BreakpointModelId &id) void QmlV8DebuggerClient::insertBreakpoint(const BreakpointModelId &id)
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState
|| d->state == QmlV8DebuggerClient::RunningState);
BreakHandler *handler = d->engine->breakHandler(); BreakHandler *handler = d->engine->breakHandler();
const BreakpointParameters &params = handler->breakpointData(id); const BreakpointParameters &params = handler->breakpointData(id);
@@ -942,8 +944,8 @@ void QmlV8DebuggerClient::insertBreakpoint(const BreakpointModelId &id)
void QmlV8DebuggerClient::removeBreakpoint(const BreakpointModelId &id) void QmlV8DebuggerClient::removeBreakpoint(const BreakpointModelId &id)
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState
|| d->state == QmlV8DebuggerClient::RunningState);
BreakHandler *handler = d->engine->breakHandler(); BreakHandler *handler = d->engine->breakHandler();
int breakpoint = d->breakpoints.value(id); int breakpoint = d->breakpoints.value(id);
@@ -958,8 +960,8 @@ void QmlV8DebuggerClient::removeBreakpoint(const BreakpointModelId &id)
void QmlV8DebuggerClient::changeBreakpoint(const BreakpointModelId &id) void QmlV8DebuggerClient::changeBreakpoint(const BreakpointModelId &id)
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState
|| d->state == QmlV8DebuggerClient::RunningState);
BreakHandler *handler = d->engine->breakHandler(); BreakHandler *handler = d->engine->breakHandler();
const BreakpointParameters &params = handler->breakpointData(id); const BreakpointParameters &params = handler->breakpointData(id);
@@ -1002,10 +1004,12 @@ void QmlV8DebuggerClient::updateWatchData(const WatchData &data)
void QmlV8DebuggerClient::executeDebuggerCommand(const QString &command) void QmlV8DebuggerClient::executeDebuggerCommand(const QString &command)
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState
|| d->state == QmlV8DebuggerClient::RunningState);
StackHandler *stackHandler = d->engine->stackHandler(); StackHandler *stackHandler = d->engine->stackHandler();
if (stackHandler->isContentsValid()) { if (stackHandler->isContentsValid()) {
//Set the state
d->state = QmlV8DebuggerClient::BacktraceRequestedState;
d->evaluate(command, false, false, stackHandler->currentIndex()); d->evaluate(command, false, false, stackHandler->currentIndex());
} else { } else {
//Currently cannot evaluate if not in a javascript break //Currently cannot evaluate if not in a javascript break
@@ -1021,7 +1025,7 @@ void QmlV8DebuggerClient::synchronizeWatchers(const QStringList &/*watchers*/)
void QmlV8DebuggerClient::expandObject(const QByteArray &iname, quint64 objectId) void QmlV8DebuggerClient::expandObject(const QByteArray &iname, quint64 objectId)
{ {
QTC_CHECK(d->state == QmlV8DebuggerClient::WaitingForRequestState);
d->locals.insertMulti(objectId, iname); d->locals.insertMulti(objectId, iname);
d->lookup(QList<int>() << objectId); d->lookup(QList<int>() << objectId);
} }
@@ -1168,10 +1172,23 @@ void QmlV8DebuggerClient::messageReceived(const QByteArray &data)
} }
if (resp.value(_("running")).toBool()) { if (resp.value(_("running")).toBool()) {
//DO NOTHING d->state = QmlV8DebuggerClient::RunningState;
SDEBUG(QString(_("State: %1")).arg(d->state));
} else { } else {
if (d->state == QmlV8DebuggerClient::RunningState) {
d->state = QmlV8DebuggerClient::BreakpointsRequestedState;
SDEBUG(QString(_("State: %1")).arg(d->state));
}
d->engine->inferiorSpontaneousStop(); d->engine->inferiorSpontaneousStop();
}
if (d->state == QmlV8DebuggerClient::BreakpointsRequestedState) {
d->state = QmlV8DebuggerClient::BacktraceRequestedState;
SDEBUG(QString(_("State: %1")).arg(d->state));
d->listBreakpoints(); d->listBreakpoints();
} else if (d->state == QmlV8DebuggerClient::BacktraceRequestedState) {
d->state = QmlV8DebuggerClient::WaitingForRequestState;
SDEBUG(QString(_("State: %1")).arg(d->state));
d->backtrace(d->currentFrameIndex); d->backtrace(d->currentFrameIndex);
} }
} else { } else {
@@ -1554,11 +1571,13 @@ void QmlV8DebuggerClient::clearExceptionSelection()
} }
void QmlV8DebuggerClient::reset() void QmlV8DebuggerClient::resetState()
{ {
clearExceptionSelection(); clearExceptionSelection();
d->currentFrameIndex = 0; d->currentFrameIndex = 0;
d->updateCurrentStackFrameIndex = true; d->updateCurrentStackFrameIndex = true;
d->state = QmlV8DebuggerClient::BreakpointsRequestedState;
SDEBUG(QString(_("State: %1")).arg(d->state));
} }
} // Internal } // Internal

View File

@@ -61,6 +61,14 @@ class QmlV8DebuggerClient : public QmlDebuggerClient
Next Next
}; };
enum V8DebuggerStates
{
RunningState,
BreakpointsRequestedState,
BacktraceRequestedState,
WaitingForRequestState
};
public: public:
explicit QmlV8DebuggerClient(QmlJsDebugClient::QDeclarativeDebugConnection *client); explicit QmlV8DebuggerClient(QmlJsDebugClient::QDeclarativeDebugConnection *client);
~QmlV8DebuggerClient(); ~QmlV8DebuggerClient();
@@ -116,7 +124,7 @@ private:
const QString &errorMessage); const QString &errorMessage);
void clearExceptionSelection(); void clearExceptionSelection();
void reset(); void resetState();
private: private:
QmlV8DebuggerClientPrivate *d; QmlV8DebuggerClientPrivate *d;