Improved breakpoint handling in qmlv8debuggerclient

Breakpoints are resolved and set only after querying for their actual locations from v8 engine.

Change-Id: If119865f50d9f91a4930096751599a4f22bc9d26
Reviewed-on: http://codereview.qt.nokia.com/3406
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
This commit is contained in:
Aurindam Jana
2011-08-23 15:05:30 +02:00
parent a75c905687
commit 3edc756ad7
4 changed files with 70 additions and 55 deletions

View File

@@ -508,10 +508,6 @@ void QmlEngine::insertBreakpoint(BreakpointModelId id)
client->insertBreakpoint(id); client->insertBreakpoint(id);
} }
} }
if (handler->state(id) == BreakpointInsertProceeding) {
handler->notifyBreakpointInsertOk(id);
}
} }
void QmlEngine::removeBreakpoint(BreakpointModelId id) void QmlEngine::removeBreakpoint(BreakpointModelId id)

View File

@@ -246,23 +246,21 @@ void QmlV8DebuggerClient::insertBreakpoint(BreakpointModelId id)
void QmlV8DebuggerClient::removeBreakpoint(BreakpointModelId id) void QmlV8DebuggerClient::removeBreakpoint(BreakpointModelId id)
{ {
QList<int> breakpoints = d->breakpoints.values(id); int breakpoint = d->breakpoints.value(id);
d->breakpoints.remove(id); d->breakpoints.remove(id);
foreach (int bp, breakpoints) { QByteArray request;
QByteArray request;
JsonInputStream(request) << '{' << INITIALPARAMS ; JsonInputStream(request) << '{' << INITIALPARAMS ;
JsonInputStream(request) << ',' << "command" << ':' << "clearbreakpoint"; JsonInputStream(request) << ',' << "command" << ':' << "clearbreakpoint";
JsonInputStream(request) << ',' << "arguments" << ':'; JsonInputStream(request) << ',' << "arguments" << ':';
JsonInputStream(request) << '{' << "breakpoint" << ':' << bp; JsonInputStream(request) << '{' << "breakpoint" << ':' << breakpoint;
JsonInputStream(request) << '}'; JsonInputStream(request) << '}';
JsonInputStream(request) << '}'; JsonInputStream(request) << '}';
sendMessage(packMessage(request)); sendMessage(packMessage(request));
}
} }
void QmlV8DebuggerClient::changeBreakpoint(BreakpointModelId /*id*/) void QmlV8DebuggerClient::changeBreakpoint(BreakpointModelId /*id*/)
@@ -346,6 +344,17 @@ void QmlV8DebuggerClient::expandObject(const QByteArray &iname, quint64 objectId
} }
void QmlV8DebuggerClient::listBreakpoints()
{
QByteArray request;
JsonInputStream(request) << '{' << INITIALPARAMS ;
JsonInputStream(request) << ',' << "command" << ':' << "listbreakpoints";
JsonInputStream(request) << '}';
sendMessage(packMessage(request));
}
void QmlV8DebuggerClient::backtrace() void QmlV8DebuggerClient::backtrace()
{ {
QByteArray request; QByteArray request;
@@ -388,11 +397,16 @@ void QmlV8DebuggerClient::messageReceived(const QByteArray &data)
} else if (debugCommand == "setbreakpoint") { } else if (debugCommand == "setbreakpoint") {
int sequence = value.findChild("request_seq").toVariant().toInt(); int sequence = value.findChild("request_seq").toVariant().toInt();
int breakpoint = value.findChild("body").findChild("breakpoint").toVariant().toInt(); int breakpoint = value.findChild("body").findChild("breakpoint").toVariant().toInt();
d->breakpoints.insertMulti(d->breakpointsSync.take(sequence),breakpoint); BreakpointModelId id = d->breakpointsSync.take(sequence);
d->breakpoints.insert(id,breakpoint);
} else if (debugCommand == "evaluate") { } else if (debugCommand == "evaluate") {
setExpression(response); setExpression(response);
} else if (debugCommand == "listbreakpoints") {
updateBreakpoints(response);
backtrace();
} else { } else {
//TODO:: //TODO::
//qDebug() << Q_FUNC_INFO << value.toString(true,2); //qDebug() << Q_FUNC_INFO << value.toString(true,2);
@@ -402,8 +416,12 @@ void QmlV8DebuggerClient::messageReceived(const QByteArray &data)
QString event(value.findChild("event").toVariant().toString()); QString event(value.findChild("event").toVariant().toString());
if (event == "break") { if (event == "break") {
d->engine->inferiorSpontaneousStop(); //Check if this break is due to a breakpoint
backtrace(); QList<QVariant> breakpoints = value.findChild("body").findChild("breakpoints").toVariant().toList();
if (breakpoints.count()) {
d->engine->inferiorSpontaneousStop();
listBreakpoints();
}
} }
} }
} }
@@ -449,31 +467,6 @@ void QmlV8DebuggerClient::setStackFrames(QByteArray &message)
d->engine->stackHandler()->setFrames(ideStackFrames); d->engine->stackHandler()->setFrames(ideStackFrames);
QString fileName;
QString file;
QString function;
int line = -1;
if (!ideStackFrames.isEmpty()) {
file = ideStackFrames.at(0).file;
fileName = QFileInfo(file).fileName();
line = ideStackFrames.at(0).line;
function = ideStackFrames.at(0).function;
}
BreakHandler *handler = d->engine->breakHandler();
foreach (BreakpointModelId id, handler->engineBreakpointIds(d->engine)) {
QString processedFilename = QFileInfo(handler->fileName(id)).fileName();
if (processedFilename == fileName && handler->lineNumber(id) == line) {
QTC_ASSERT(handler->state(id) == BreakpointInserted,/**/);
BreakpointResponse br = handler->response(id);
br.fileName = file;
br.lineNumber = line;
br.functionName = function;
handler->setResponse(id, br);
}
}
if (!ideStackFrames.isEmpty()) { if (!ideStackFrames.isEmpty()) {
setLocals(0); setLocals(0);
d->engine->gotoLocation(ideStackFrames.value(0)); d->engine->gotoLocation(ideStackFrames.value(0));
@@ -571,25 +564,45 @@ void QmlV8DebuggerClient::setExpression(QByteArray &message)
int seq = response.findChild("request_seq").toVariant().toInt(); int seq = response.findChild("request_seq").toVariant().toInt();
//Console
if (!d->watches.contains(seq)) { if (!d->watches.contains(seq)) {
d->engine->showMessage(body.findChild("text").toVariant().toString(), ScriptConsoleOutput); d->engine->showMessage(body.findChild("text").toVariant().toString(), ScriptConsoleOutput);
return; return;
} }
//TODO::
// JsonValue refs = response.findChild("refs");
// JsonValue body = response.findChild("body");
// JsonValue details = body.childAt(0);
// int id = QString(details.name()).toInt(); //TODO: For watch point
// QByteArray prepend = d->locals.take(id); }
// JsonValue properties = details.findChild("properties"); void QmlV8DebuggerClient::updateBreakpoints(QByteArray &message)
// int propertiesCount = properties.childCount(); {
JsonValue response(message);
// for (int k = 0; k != propertiesCount; ++k) { JsonValue refs = response.findChild("refs");
// JsonValue property = properties.childAt(k); JsonValue body = response.findChild("body");
// setPropertyValue(refs,property,prepend);
// } QList<JsonValue> breakpoints = body.findChild("breakpoints").children();
BreakHandler *handler = d->engine->breakHandler();
foreach (const JsonValue &bp, breakpoints) {
int bpIndex = bp.findChild("number").toVariant().toInt();
BreakpointModelId id = d->breakpoints.key(bpIndex);
BreakpointResponse br = handler->response(id);
if (!br.pending)
continue;
br.hitCount = bp.findChild("hit_count").toVariant().toInt();
QList<JsonValue> actualLocations = bp.findChild("actual_locations").children();
foreach (const JsonValue &location, actualLocations) {
int line = location.findChild("line").toVariant().toInt() + 1; //Add the offset
br.lineNumber = line;
br.correctedLineNumber = line;
handler->setResponse(id,br);
handler->notifyBreakpointInsertOk(id);
}
}
} }
void QmlV8DebuggerClient::setPropertyValue(JsonValue &refs, JsonValue &property, QByteArray &prepend) void QmlV8DebuggerClient::setPropertyValue(JsonValue &refs, JsonValue &property, QByteArray &prepend)

View File

@@ -89,10 +89,12 @@ protected:
void messageReceived(const QByteArray &data); void messageReceived(const QByteArray &data);
private: private:
void listBreakpoints();
void backtrace(); void backtrace();
void setStackFrames(QByteArray &); void setStackFrames(QByteArray &);
void setLocals(int frameIndex); void setLocals(int frameIndex);
void setExpression(QByteArray &message); void setExpression(QByteArray &message);
void updateBreakpoints(QByteArray &message);
void expandLocal(QByteArray &message); void expandLocal(QByteArray &message);
void setPropertyValue(Json::JsonValue &refs, Json::JsonValue &property, QByteArray &prepend); void setPropertyValue(Json::JsonValue &refs, Json::JsonValue &property, QByteArray &prepend);
int indexInRef(const Json::JsonValue &refs, int refIndex); int indexInRef(const Json::JsonValue &refs, int refIndex);

View File

@@ -218,6 +218,10 @@ void QScriptDebuggerClient::insertBreakpoint(BreakpointModelId id)
bp.lineNumber = handler->lineNumber(id); bp.lineNumber = handler->lineNumber(id);
bp.functionName = handler->functionName(id).toUtf8(); bp.functionName = handler->functionName(id).toUtf8();
d->breakpoints.insert(bp); d->breakpoints.insert(bp);
if (handler->state(id) == BreakpointInsertProceeding) {
handler->notifyBreakpointInsertOk(id);
}
} }
void QScriptDebuggerClient::removeBreakpoint(BreakpointModelId id) void QScriptDebuggerClient::removeBreakpoint(BreakpointModelId id)