forked from qt-creator/qt-creator
DAP: Refactor dap responses handling
Change-Id: Iebc16d7e497b4f3a1deec6f52f7b89815c2cde3b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -141,23 +141,10 @@ void DapEngine::shutdownEngine()
|
||||
m_dataGenerator->kill();
|
||||
}
|
||||
|
||||
// From the docs:
|
||||
// The sequence of events/requests is as follows:
|
||||
// * adapters sends initialized event (after the initialize request has returned)
|
||||
// * client sends zero or more setBreakpoints requests
|
||||
// * client sends one setFunctionBreakpoints request
|
||||
// (if corresponding capability supportsFunctionBreakpoints is true)
|
||||
// * client sends a setExceptionBreakpoints request if one or more exceptionBreakpointFilters
|
||||
// have been defined (or if supportsConfigurationDoneRequest is not true)
|
||||
// * client sends other future configuration requests
|
||||
// * client sends one configurationDone request to indicate the end of the configuration.
|
||||
|
||||
void DapEngine::handleDapStarted()
|
||||
{
|
||||
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state());
|
||||
|
||||
// CHECK_STATE(EngineRunRequested);
|
||||
|
||||
postDirectCommand({
|
||||
{"command", "initialize"},
|
||||
{"type", "request"},
|
||||
@@ -174,8 +161,6 @@ void DapEngine::handleDapConfigurationDone()
|
||||
{
|
||||
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state());
|
||||
|
||||
// CHECK_STATE(EngineRunRequested);
|
||||
|
||||
postDirectCommand({
|
||||
{"command", "configurationDone"},
|
||||
{"type", "request"}
|
||||
@@ -402,7 +387,7 @@ void DapEngine::insertBreakpoint(const Breakpoint &bp)
|
||||
}}
|
||||
});
|
||||
|
||||
notifyBreakpointChangeOk(bp);
|
||||
notifyBreakpointInsertOk(bp);
|
||||
qCDebug(dapEngineLog) << "insertBreakpoint" << bp->modelId() << bp->responseId();
|
||||
}
|
||||
|
||||
@@ -662,10 +647,26 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
|
||||
const QJsonValue t = ob.value("type");
|
||||
const QString type = t.toString();
|
||||
qCDebug(dapEngineLog) << "response" << ob;
|
||||
|
||||
qCDebug(dapEngineLog) << "dap response" << ob;
|
||||
|
||||
if (type == "response") {
|
||||
const QString command = ob.value("command").toString();
|
||||
handleResponse(ob);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == "event") {
|
||||
handleEvent(ob);
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage("UNKNOWN TYPE:" + type);
|
||||
}
|
||||
|
||||
void DapEngine::handleResponse(const QJsonObject &response)
|
||||
{
|
||||
const QString command = response.value("command").toString();
|
||||
|
||||
if (command == "configurationDone") {
|
||||
showMessage("configurationDone", LogDebug);
|
||||
qCDebug(dapEngineLog) << "configurationDone success";
|
||||
@@ -681,7 +682,42 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
}
|
||||
|
||||
if (command == "stackTrace") {
|
||||
QJsonArray stackFrames = ob.value("body").toObject().value("stackFrames").toArray();
|
||||
handleStackTraceResponse(response);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "scopes") {
|
||||
handleScopesResponse(response);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "variables") {
|
||||
auto variables = response.value("body").toObject().value("variables").toArray();
|
||||
refreshLocals(variables);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "stepIn" || command == "stepOut" || command == "next") {
|
||||
if (response.value("success").toBool()) {
|
||||
showMessage(command, LogDebug);
|
||||
notifyInferiorRunOk();
|
||||
} else {
|
||||
notifyInferiorRunFailed();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "threads") {
|
||||
handleThreadsResponse(response);
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage("UNKNOWN RESPONSE:" + command);
|
||||
}
|
||||
|
||||
void DapEngine::handleStackTraceResponse(const QJsonObject &response)
|
||||
{
|
||||
QJsonArray stackFrames = response.value("body").toObject().value("stackFrames").toArray();
|
||||
if (stackFrames.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -694,13 +730,15 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
|
||||
refreshStack(stackFrames);
|
||||
dapScopes(stackFrame.value("id").toInt());
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "scopes") {
|
||||
if (ob.value("success").toBool()) {
|
||||
auto scopes = ob.value("body").toObject().value("scopes").toArray();
|
||||
for (auto scope : scopes) {
|
||||
void DapEngine::handleScopesResponse(const QJsonObject &response)
|
||||
{
|
||||
if (!response.value("success").toBool())
|
||||
return;
|
||||
|
||||
QJsonArray scopes = response.value("body").toObject().value("scopes").toArray();
|
||||
for (const QJsonValueRef &scope : scopes) {
|
||||
const QString name = scope.toObject().value("name").toString();
|
||||
const int variablesReference = scope.toObject().value("variablesReference").toInt();
|
||||
qCDebug(dapEngineLog) << "scoped success" << name << variablesReference;
|
||||
@@ -713,31 +751,16 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (command == "variables") {
|
||||
auto variables = ob.value("body").toObject().value("variables").toArray();
|
||||
refreshLocals(variables);
|
||||
}
|
||||
|
||||
if (command == "stepIn" || command == "stepOut" || command == "next") {
|
||||
if (ob.value("success").toBool()) {
|
||||
showMessage(command, LogDebug);
|
||||
notifyInferiorRunOk();
|
||||
} else {
|
||||
notifyInferiorRunFailed();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "threads") {
|
||||
QJsonArray threads = ob.value("body").toObject().value("threads").toArray();
|
||||
void DapEngine::handleThreadsResponse(const QJsonObject &response)
|
||||
{
|
||||
QJsonArray threads = response.value("body").toObject().value("threads").toArray();
|
||||
|
||||
if (threads.isEmpty())
|
||||
return;
|
||||
|
||||
ThreadsHandler *handler = threadsHandler();
|
||||
for (auto thread : threads) {
|
||||
for (const QJsonValueRef &thread : threads) {
|
||||
ThreadData threadData;
|
||||
threadData.id = QString::number(thread.toObject().value("id").toInt());
|
||||
threadData.name = thread.toObject().value("name").toString();
|
||||
@@ -745,23 +768,21 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
}
|
||||
|
||||
if (m_currentThreadId)
|
||||
handler->setCurrentThread(
|
||||
threadsHandler()->threadForId(QString::number(m_currentThreadId)));
|
||||
return;
|
||||
}
|
||||
handler->setCurrentThread(threadsHandler()->threadForId(QString::number(m_currentThreadId)));
|
||||
}
|
||||
|
||||
if (type == "event") {
|
||||
const QString event = ob.value("event").toString();
|
||||
const QJsonObject body = ob.value("body").toObject();
|
||||
void DapEngine::handleEvent(const QJsonObject &event)
|
||||
{
|
||||
const QString eventType = event.value("event").toString();
|
||||
const QJsonObject body = event.value("body").toObject();
|
||||
showMessage(eventType, LogDebug);
|
||||
|
||||
if (event == "exited") {
|
||||
if (eventType == "exited") {
|
||||
notifyInferiorExited();
|
||||
showMessage("exited", LogDebug);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == "output") {
|
||||
if (eventType == "output") {
|
||||
const QString category = body.value("category").toString();
|
||||
const QString output = body.value("output").toString();
|
||||
if (category == "stdout")
|
||||
@@ -772,22 +793,41 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
showMessage(output, LogDebug);
|
||||
return;
|
||||
}
|
||||
qCDebug(dapEngineLog) << data;
|
||||
|
||||
if (event == "initialized") {
|
||||
showMessage(event, LogDebug);
|
||||
if (eventType == "initialized") {
|
||||
qCDebug(dapEngineLog) << "initialize success";
|
||||
handleDapLaunch();
|
||||
handleDapConfigurationDone();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == "stopped") {
|
||||
if (eventType == "stopped") {
|
||||
handleStoppedEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventType == "thread") {
|
||||
threads();
|
||||
if (body.value("reason").toString() == "started" && body.value("threadId").toInt() == 1)
|
||||
claimInitialBreakpoints();
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventType == "breakpoint") {
|
||||
handleBreakpointEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage("UNKNOWN EVENT:" + eventType);
|
||||
}
|
||||
|
||||
void DapEngine::handleStoppedEvent(const QJsonObject &event)
|
||||
{
|
||||
const QJsonObject body = event.value("body").toObject();
|
||||
m_currentThreadId = body.value("threadId").toInt();
|
||||
showMessage(event, LogDebug);
|
||||
|
||||
if (body.value("reason").toString() == "breakpoint") {
|
||||
QString id = QString::number(
|
||||
body.value("hitBreakpointIds").toArray().first().toInteger());
|
||||
QString id = QString::number(body.value("hitBreakpointIds").toArray().first().toInteger());
|
||||
|
||||
Breakpoint bp = breakHandler()->findBreakpointByResponseId(id);
|
||||
if (bp) {
|
||||
@@ -803,21 +843,13 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
|
||||
dapStackTrace();
|
||||
threads();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == "thread") {
|
||||
// threads(); // breaks cmake debugging for now
|
||||
|
||||
showMessage(event, LogDebug);
|
||||
if (body.value("reason").toString() == "started" && body.value("threadId").toInt() == 1)
|
||||
claimInitialBreakpoints();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == "breakpoint") {
|
||||
showMessage(event, LogDebug);
|
||||
void DapEngine::handleBreakpointEvent(const QJsonObject &event)
|
||||
{
|
||||
const QJsonObject body = event.value("body").toObject();
|
||||
QJsonObject breakpoint = body.value("breakpoint").toObject();
|
||||
|
||||
Breakpoint bp = breakHandler()->findBreakpointByResponseId(
|
||||
QString::number(breakpoint.value("id").toInt()));
|
||||
qCDebug(dapEngineLog) << "breakpoint id :" << breakpoint.value("id").toInt();
|
||||
@@ -843,14 +875,6 @@ void DapEngine::handleOutput(const QJsonDocument &data)
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage("UNKNOWN EVENT:" + event);
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage("UNKNOWN TYPE:" + type);
|
||||
}
|
||||
|
||||
void DapEngine::refreshLocals(const QJsonArray &variables)
|
||||
|
||||
@@ -117,8 +117,18 @@ protected:
|
||||
void handleDapDone();
|
||||
void readDapStandardOutput();
|
||||
void readDapStandardError();
|
||||
|
||||
void handleOutput(const QJsonDocument &data);
|
||||
void handleResponse(const QString &ba);
|
||||
|
||||
void handleResponse(const QJsonObject &response);
|
||||
void handleStackTraceResponse(const QJsonObject &response);
|
||||
void handleScopesResponse(const QJsonObject &response);
|
||||
void handleThreadsResponse(const QJsonObject &response);
|
||||
|
||||
void handleEvent(const QJsonObject &event);
|
||||
void handleBreakpointEvent(const QJsonObject &event);
|
||||
void handleStoppedEvent(const QJsonObject &event);
|
||||
|
||||
void updateAll() override;
|
||||
void updateLocals() override;
|
||||
void connectDataGeneratorSignals();
|
||||
|
||||
@@ -1179,7 +1179,6 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(const QStringList &arguments)
|
||||
m_startCmakeAction.setText(Tr::tr("Start CMake Debugging"));
|
||||
m_startCmakeAction.setEnabled(true);
|
||||
m_startCmakeAction.setIcon(startIcon(true));
|
||||
m_startCmakeAction.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
m_startCmakeAction.setVisible(true);
|
||||
|
||||
m_perspectiveCmake->addToolBarAction(&m_startCmakeAction);
|
||||
|
||||
Reference in New Issue
Block a user