DAP: Add stepIn and stepOut and stepOver

Change-Id: I7d2bb573c4fc359a4d07b4cff8867a47f9691392
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Artem Sokolovskii
2023-06-13 17:24:28 +02:00
parent d61f53e3c1
commit 9ad37a3c43
2 changed files with 124 additions and 44 deletions

View File

@@ -25,8 +25,10 @@
#include <utils/process.h>
#include <utils/qtcassert.h>
#include <coreplugin/idocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/messagebox.h>
#include <QDateTime>
@@ -173,64 +175,106 @@ void DapEngine::handleDabLaunch()
{
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
// CHECK_STATE(EngineRunRequested);
postDirectCommand(
{{"command", "launch"},
{"type", "request"},
// {"program", runParameters().inferior.command.executable().path()},
{"arguments",
QJsonObject{
{"noDebug", false},
{"program", runParameters().inferior.command.executable().path()},
{"__restart", ""}
}}});
postDirectCommand({
{"command", "launch"},
{"type", "request"},
{"arguments", QJsonObject{
{"noDebug", false},
{"program", runParameters().inferior.command.executable().path()},
{"__restart", ""}
}}
});
qDebug() << "handleDabLaunch";
}
void DapEngine::interruptInferior()
{
postDirectCommand({{"command", "pause"},
{"type", "request"}});
postDirectCommand({
{"command", "pause"},
{"type", "request"}
});
}
void DapEngine::dabStackTrace()
{
if (m_currentThreadId == -1)
return;
postDirectCommand({
{"command", "stackTrace"},
{"type", "request"},
{"arguments", QJsonObject{
{"threadId", m_currentThreadId},
{"startFrame", 0},
{"levels", 1}
}}
});
}
void DapEngine::executeStepIn(bool)
{
if (m_currentThreadId == -1)
return;
notifyInferiorRunRequested();
// postDirectCommand({{"command", "stepIn"},
// {"type", "request"},
// {"arguments",
// QJsonObject{
// {"threadId", 1}, // The ID of the client using this adapter.
// }}});
postDirectCommand({
{"command", "stepIn"},
{"type", "request"},
{"arguments", QJsonObject{
{"threadId", m_currentThreadId},
}}
});
notifyInferiorRunOk();
}
void DapEngine::executeStepOut()
{
if (m_currentThreadId == -1)
return;
notifyInferiorRunRequested();
postDirectCommand({
{"command", "stepOut"},
{"type", "request"},
{"arguments", QJsonObject{
{"threadId", m_currentThreadId},
}}
});
notifyInferiorRunOk();
// postDirectCommand("return");
}
void DapEngine::executeStepOver(bool)
{
if (m_currentThreadId == -1)
return;
notifyInferiorRunRequested();
postDirectCommand({
{"command", "next"},
{"type", "request"},
{"arguments", QJsonObject{
{"threadId", m_currentThreadId},
}}
});
notifyInferiorRunOk();
// postDirectCommand("next");
}
void DapEngine::continueInferior()
{
notifyInferiorRunRequested();
postDirectCommand({{"command", "continue"},
{"type", "request"},
{"arguments",
QJsonObject{
{"threadId", 1}, // The ID of the client using this adapter.
}}});
postDirectCommand({
{"command", "continue"},
{"type", "request"},
{"arguments", QJsonObject{
{"threadId", m_currentThreadId},
}}
});
}
void DapEngine::executeRunToLine(const ContextData &data)
@@ -306,14 +350,16 @@ void DapEngine::insertBreakpoint(const Breakpoint &bp)
}
}
postDirectCommand(
{{"command", "setBreakpoints"},
{"type", "request"},
{"arguments",
QJsonObject{{"source", QJsonObject{{"path", params.fileName.path()}}},
{"breakpoints", breakpoints}
}}});
postDirectCommand( {
{"command", "setBreakpoints"},
{"type", "request"},
{"arguments", QJsonObject{
{"source", QJsonObject{
{"path", params.fileName.path()}
}},
{"breakpoints", breakpoints}
}}
});
qDebug() << "insertBreakpoint" << bp->modelId() << bp->responseId();
}
@@ -356,11 +402,16 @@ void DapEngine::removeBreakpoint(const Breakpoint &bp)
breakpoints.append(jsonBp);
}
postDirectCommand({{"command", "setBreakpoints"},
{"type", "request"},
{"arguments",
QJsonObject{{"source", QJsonObject{{"path", params.fileName.path()}}},
{"breakpoints", breakpoints}}}});
postDirectCommand({
{"command", "setBreakpoints"},
{"type", "request"},
{"arguments", QJsonObject{
{"source", QJsonObject{
{"path", params.fileName.path()}
}},
{"breakpoints", breakpoints}
}}
});
qDebug() << "removeBreakpoint" << bp->modelId() << bp->responseId();
}
@@ -584,12 +635,32 @@ void DapEngine::handleOutput(const QJsonDocument &data)
return;
}
if (command == "stackTrace") {
QJsonArray stackFrames = ob.value("body").toObject().value("stackFrames").toArray();
if (stackFrames.isEmpty())
return;
QJsonObject stackFrame = stackFrames[0].toObject();
const FilePath file = FilePath::fromString(
stackFrame.value("source").toObject().value("path").toString());
const int line = stackFrame.value("line").toInt();
qDebug() << "stackTrace success" << file << line;
gotoLocation(Location(file, line));
return;
}
}
if (type == "event") {
const QString event = ob.value("event").toString();
const QJsonObject body = ob.value("body").toObject();
if (event == "exited") {
notifyInferiorExited();
m_proc.kill();
showMessage("exited", LogDebug);
return;
}
if (event == "output") {
const QString category = body.value("category").toString();
const QString output = body.value("output").toString();
@@ -617,14 +688,21 @@ void DapEngine::handleOutput(const QJsonDocument &data)
}
if (event == "stopped") {
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());
const BreakpointParameters &params
= breakHandler()->findBreakpointByResponseId(id)->requestedParameters();
gotoLocation(Location(params.fileName, params.textPosition));
}
if (body.value("reason").toString() == "pause"
|| body.value("reason").toString() == "step") {
dabStackTrace();
}
if (state() == InferiorStopRequested)
notifyInferiorStopOk();
else
@@ -671,7 +749,6 @@ void DapEngine::handleOutput(const QJsonDocument &data)
return;
}
showMessage("UNKNOWN EVENT:" + event);
return;
}