2023-01-03 15:12:43 +01:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
#include "dapengine.h"
|
2023-08-15 16:48:15 +02:00
|
|
|
|
2023-08-08 15:37:39 +02:00
|
|
|
#include "cmakedapengine.h"
|
2023-08-15 16:48:15 +02:00
|
|
|
#include "dapclient.h"
|
2023-08-08 15:37:39 +02:00
|
|
|
#include "gdbdapengine.h"
|
2023-08-25 15:40:18 +02:00
|
|
|
#include "pydapengine.h"
|
2023-01-03 15:12:43 +01:00
|
|
|
|
|
|
|
#include <debugger/breakhandler.h>
|
|
|
|
#include <debugger/debuggeractions.h>
|
|
|
|
#include <debugger/debuggercore.h>
|
|
|
|
#include <debugger/debuggerdialogs.h>
|
2023-07-04 16:32:37 +02:00
|
|
|
#include <debugger/debuggerinternalconstants.h>
|
|
|
|
#include <debugger/debuggermainwindow.h>
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <debugger/debuggerplugin.h>
|
|
|
|
#include <debugger/debuggerprotocol.h>
|
2023-07-04 16:32:37 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <debugger/debuggertooltipmanager.h>
|
|
|
|
#include <debugger/debuggertr.h>
|
|
|
|
#include <debugger/moduleshandler.h>
|
|
|
|
#include <debugger/procinterrupt.h>
|
|
|
|
#include <debugger/registerhandler.h>
|
|
|
|
#include <debugger/sourceutils.h>
|
|
|
|
#include <debugger/stackhandler.h>
|
|
|
|
#include <debugger/threaddata.h>
|
|
|
|
#include <debugger/watchhandler.h>
|
|
|
|
#include <debugger/watchutils.h>
|
|
|
|
|
2023-07-04 16:32:37 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
#include <utils/environment.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2023-07-27 16:26:15 +02:00
|
|
|
#include <utils/temporarydirectory.h>
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-06-13 17:24:28 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2023-06-13 17:24:28 +02:00
|
|
|
#include <coreplugin/idocument.h>
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <coreplugin/messagebox.h>
|
|
|
|
|
2023-07-04 16:32:37 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
#include <projectexplorer/buildsystem.h>
|
2023-08-08 15:37:39 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2023-08-03 14:39:33 +02:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2023-07-04 16:32:37 +02:00
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
2023-06-27 16:57:51 +02:00
|
|
|
#include <QLocalSocket>
|
2023-01-03 15:12:43 +01:00
|
|
|
#include <QThread>
|
2023-06-27 16:57:51 +02:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QVariant>
|
2023-01-03 15:12:43 +01:00
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
namespace Debugger::Internal {
|
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
VariablesHandler::VariablesHandler(DapEngine *dapEngine)
|
|
|
|
: m_dapEngine(dapEngine)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void VariablesHandler::addVariable(const QString &iname, int variablesReference)
|
|
|
|
{
|
|
|
|
VariableItem varItem = {iname, variablesReference};
|
|
|
|
bool wasEmpty = m_queue.empty();
|
|
|
|
bool inserted = false;
|
|
|
|
|
|
|
|
for (auto i = m_queue.begin(); i != m_queue.end(); ++i) {
|
|
|
|
if (i->iname > iname) {
|
|
|
|
m_queue.insert(i, varItem);
|
|
|
|
inserted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!inserted)
|
|
|
|
m_queue.push_back(varItem);
|
|
|
|
|
|
|
|
if (wasEmpty) {
|
|
|
|
startHandling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VariablesHandler::handleNext()
|
|
|
|
{
|
|
|
|
if (m_queue.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_queue.pop_front();
|
|
|
|
startHandling();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VariablesHandler::startHandling()
|
|
|
|
{
|
|
|
|
if (m_queue.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentVarItem = m_queue.front();
|
|
|
|
|
|
|
|
WatchItem *watchItem = m_dapEngine->watchHandler()->findItem(m_currentVarItem.iname);
|
|
|
|
int variablesReference = m_currentVarItem.variablesReference;
|
|
|
|
|
|
|
|
if (variablesReference == -1 && watchItem && watchItem->iname.startsWith("watch.")
|
|
|
|
&& watchItem->iname.split('.').size() == 2) {
|
|
|
|
watchItem->removeChildren();
|
|
|
|
m_dapEngine->dapClient()->evaluateVariable(watchItem->name,
|
|
|
|
m_dapEngine->currentStackFrameId());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variablesReference == -1) {
|
|
|
|
if (watchItem) {
|
|
|
|
variablesReference = watchItem->variablesReference;
|
|
|
|
} else {
|
|
|
|
handleNext();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variablesReference == 0) {
|
|
|
|
handleNext();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dapEngine->dapClient()->variables(variablesReference);
|
|
|
|
}
|
|
|
|
|
|
|
|
DapEngine::DapEngine()
|
|
|
|
: m_variablesHandler(std::make_unique<VariablesHandler>(this))
|
|
|
|
{}
|
|
|
|
|
2023-04-06 14:20:01 +02:00
|
|
|
void DapEngine::executeDebuggerCommand(const QString &/*command*/)
|
2023-01-03 15:12:43 +01:00
|
|
|
{
|
2023-09-12 10:44:57 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStopOk, qCDebug(logCategory()) << state());
|
2023-01-03 15:12:43 +01:00
|
|
|
// if (state() == DebuggerNotReady) {
|
|
|
|
// showMessage("DAP PROCESS NOT RUNNING, PLAIN CMD IGNORED: " + command);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// QTC_ASSERT(m_proc.isRunning(), notifyEngineIll());
|
|
|
|
// postDirectCommand(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::runCommand(const DebuggerCommand &cmd)
|
|
|
|
{
|
|
|
|
if (state() == EngineSetupRequested) { // cmd has been triggered too early
|
|
|
|
showMessage("IGNORED COMMAND: " + cmd.function);
|
|
|
|
return;
|
|
|
|
}
|
2023-08-15 16:48:15 +02:00
|
|
|
QTC_ASSERT(m_dapClient->dataProvider()->isRunning(), notifyEngineIll());
|
2023-01-03 15:12:43 +01:00
|
|
|
// postDirectCommand(cmd.args.toObject());
|
|
|
|
// const QByteArray data = QJsonDocument(cmd.args.toObject()).toJson(QJsonDocument::Compact);
|
|
|
|
// m_proc.writeRaw("Content-Length: " + QByteArray::number(data.size()) + "\r\n" + data + "\r\n");
|
|
|
|
|
|
|
|
// showMessage(QString::fromUtf8(data), LogInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::shutdownInferior()
|
|
|
|
{
|
2023-09-12 10:44:57 +02:00
|
|
|
QTC_ASSERT(state() == InferiorShutdownRequested, qCDebug(logCategory()) << state());
|
2023-06-27 16:57:51 +02:00
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendDisconnect();
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "DapEngine::shutdownInferior()";
|
2023-01-03 15:12:43 +01:00
|
|
|
notifyInferiorShutdownFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::shutdownEngine()
|
|
|
|
{
|
2023-09-12 10:44:57 +02:00
|
|
|
QTC_ASSERT(state() == EngineShutdownRequested, qCDebug(logCategory()) << state());
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendTerminate();
|
2023-06-27 16:57:51 +02:00
|
|
|
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "DapEngine::shutdownEngine()";
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->dataProvider()->kill();
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
2023-06-16 15:28:50 +02:00
|
|
|
void DapEngine::handleDapStarted()
|
2023-01-03 15:12:43 +01:00
|
|
|
{
|
2023-08-25 15:40:18 +02:00
|
|
|
notifyEngineSetupOk();
|
2023-09-12 10:44:57 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendInitialize();
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "handleDapStarted";
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
2023-09-08 16:05:22 +02:00
|
|
|
void DapEngine::handleDapInitialize()
|
2023-01-03 15:12:43 +01:00
|
|
|
{
|
2023-09-12 10:44:57 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-09-08 16:05:22 +02:00
|
|
|
m_dapClient->sendLaunch(runParameters().inferior.command.executable());
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "handleDapLaunch";
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
2023-09-08 16:05:22 +02:00
|
|
|
void DapEngine::handleDapEventInitialized()
|
2023-01-03 15:12:43 +01:00
|
|
|
{
|
2023-09-12 10:44:57 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qCDebug(logCategory()) << state());
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-09-08 16:05:22 +02:00
|
|
|
m_dapClient->sendConfigurationDone();
|
2023-08-15 16:48:15 +02:00
|
|
|
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "handleDapConfigurationDone";
|
2023-09-08 16:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::handleDapConfigurationDone()
|
|
|
|
{
|
|
|
|
notifyEngineRunAndInferiorRunOk();
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::interruptInferior()
|
|
|
|
{
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendPause();
|
2023-06-15 15:27:33 +02:00
|
|
|
}
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
void DapEngine::executeStepIn(bool)
|
|
|
|
{
|
2023-06-13 17:24:28 +02:00
|
|
|
if (m_currentThreadId == -1)
|
|
|
|
return;
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
notifyInferiorRunRequested();
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendStepIn(m_currentThreadId);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::executeStepOut()
|
|
|
|
{
|
2023-06-13 17:24:28 +02:00
|
|
|
if (m_currentThreadId == -1)
|
|
|
|
return;
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
notifyInferiorRunRequested();
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendStepOut(m_currentThreadId);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::executeStepOver(bool)
|
|
|
|
{
|
2023-06-13 17:24:28 +02:00
|
|
|
if (m_currentThreadId == -1)
|
|
|
|
return;
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
notifyInferiorRunRequested();
|
2023-06-13 17:24:28 +02:00
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendStepOver(m_currentThreadId);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::continueInferior()
|
|
|
|
{
|
2023-04-06 14:20:01 +02:00
|
|
|
notifyInferiorRunRequested();
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->sendContinue(m_currentThreadId);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::executeRunToLine(const ContextData &data)
|
|
|
|
{
|
2023-08-11 13:04:41 +02:00
|
|
|
// Add one-shot breakpoint
|
|
|
|
BreakpointParameters bp;
|
|
|
|
bp.oneShot = true;
|
|
|
|
if (data.address) {
|
|
|
|
bp.type = BreakpointByAddress;
|
|
|
|
bp.address = data.address;
|
|
|
|
} else {
|
|
|
|
bp.type = BreakpointByFileAndLine;
|
|
|
|
bp.fileName = data.fileName;
|
|
|
|
bp.textPosition = data.textPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointManager::createBreakpointForEngine(bp, this);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::executeRunToFunction(const QString &functionName)
|
|
|
|
{
|
|
|
|
Q_UNUSED(functionName)
|
|
|
|
QTC_CHECK("FIXME: DapEngine::runToFunctionExec()" && false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::executeJumpToLine(const ContextData &data)
|
|
|
|
{
|
|
|
|
Q_UNUSED(data)
|
|
|
|
QTC_CHECK("FIXME: DapEngine::jumpToLineExec()" && false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::activateFrame(int frameIndex)
|
|
|
|
{
|
|
|
|
if (state() != InferiorStopOk && state() != InferiorUnrunnable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
StackHandler *handler = stackHandler();
|
|
|
|
QTC_ASSERT(frameIndex < handler->stackSize(), return);
|
|
|
|
handler->setCurrentIndex(frameIndex);
|
|
|
|
gotoLocation(handler->currentFrame());
|
2023-09-21 10:17:07 +02:00
|
|
|
|
|
|
|
m_currentStackFrameId = handler->currentFrame().debuggerId;
|
|
|
|
m_dapClient->scopes(m_currentStackFrameId);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::selectThread(const Thread &thread)
|
|
|
|
{
|
|
|
|
Q_UNUSED(thread)
|
2023-08-09 17:08:54 +02:00
|
|
|
m_currentThreadId = thread->id().toInt();
|
|
|
|
threadsHandler()->setCurrentThread(thread);
|
|
|
|
updateLocals();
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DapEngine::acceptsBreakpoint(const BreakpointParameters &) const
|
|
|
|
{
|
|
|
|
return true; // FIXME: Too bold.
|
|
|
|
}
|
|
|
|
|
2023-09-05 10:29:22 +02:00
|
|
|
static QJsonObject createBreakpoint(const BreakpointParameters ¶ms)
|
2023-04-06 14:20:01 +02:00
|
|
|
{
|
|
|
|
if (params.fileName.isEmpty())
|
|
|
|
return QJsonObject();
|
|
|
|
|
|
|
|
QJsonObject bp;
|
2023-06-06 15:44:59 +02:00
|
|
|
bp["line"] = params.textPosition.line;
|
2023-04-06 14:20:01 +02:00
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
void DapEngine::insertBreakpoint(const Breakpoint &bp)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(bp, return);
|
|
|
|
QTC_CHECK(bp->state() == BreakpointInsertionRequested);
|
|
|
|
notifyBreakpointInsertProceeding(bp);
|
|
|
|
|
2023-08-10 12:25:59 +02:00
|
|
|
dapInsertBreakpoint(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::dapInsertBreakpoint(const Breakpoint &bp)
|
|
|
|
{
|
2023-04-06 14:20:01 +02:00
|
|
|
bp->setResponseId(QString::number(m_nextBreakpointId++));
|
2023-08-10 12:25:59 +02:00
|
|
|
const BreakpointParameters ¶ms = bp->requestedParameters();
|
2023-04-06 14:20:01 +02:00
|
|
|
|
|
|
|
QJsonArray breakpoints;
|
|
|
|
for (const auto &breakpoint : breakHandler()->breakpoints()) {
|
2023-09-05 10:29:22 +02:00
|
|
|
const BreakpointParameters &bpParams = breakpoint->requestedParameters();
|
|
|
|
QJsonObject jsonBp = createBreakpoint(bpParams);
|
|
|
|
if (!jsonBp.isEmpty() && params.fileName.path() == bpParams.fileName.path()) {
|
2023-04-06 14:20:01 +02:00
|
|
|
breakpoints.append(jsonBp);
|
|
|
|
}
|
|
|
|
}
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->setBreakpoints(breakpoints, params.fileName);
|
2023-04-06 14:20:01 +02:00
|
|
|
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "insertBreakpoint" << bp->modelId() << bp->responseId();
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::updateBreakpoint(const Breakpoint &bp)
|
|
|
|
{
|
2023-08-10 12:25:59 +02:00
|
|
|
BreakpointParameters parameters = bp->requestedParameters();
|
2023-04-06 14:20:01 +02:00
|
|
|
notifyBreakpointChangeProceeding(bp);
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-08-10 12:25:59 +02:00
|
|
|
if (parameters.enabled != bp->isEnabled()) {
|
|
|
|
if (bp->isEnabled())
|
|
|
|
dapRemoveBreakpoint(bp);
|
|
|
|
else
|
|
|
|
dapInsertBreakpoint(bp);
|
|
|
|
}
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::removeBreakpoint(const Breakpoint &bp)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(bp, return);
|
|
|
|
QTC_CHECK(bp->state() == BreakpointRemoveRequested);
|
2023-04-06 14:20:01 +02:00
|
|
|
notifyBreakpointRemoveProceeding(bp);
|
|
|
|
|
2023-08-10 12:25:59 +02:00
|
|
|
dapRemoveBreakpoint(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::dapRemoveBreakpoint(const Breakpoint &bp)
|
|
|
|
{
|
2023-01-03 15:12:43 +01:00
|
|
|
const BreakpointParameters ¶ms = bp->requestedParameters();
|
2023-04-06 14:20:01 +02:00
|
|
|
|
|
|
|
QJsonArray breakpoints;
|
2023-08-15 16:48:15 +02:00
|
|
|
for (const auto &breakpoint : breakHandler()->breakpoints()) {
|
2023-09-05 10:29:22 +02:00
|
|
|
const BreakpointParameters &bpParams = breakpoint->requestedParameters();
|
|
|
|
if (breakpoint->responseId() != bp->responseId() && params.fileName == bpParams.fileName) {
|
|
|
|
QJsonObject jsonBp = createBreakpoint(bpParams);
|
2023-04-06 14:20:01 +02:00
|
|
|
breakpoints.append(jsonBp);
|
|
|
|
}
|
2023-08-15 16:48:15 +02:00
|
|
|
}
|
2023-04-06 14:20:01 +02:00
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->setBreakpoints(breakpoints, params.fileName);
|
2023-01-03 15:12:43 +01:00
|
|
|
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "removeBreakpoint" << bp->modelId() << bp->responseId();
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::loadSymbols(const Utils::FilePath &/*moduleName*/)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::loadAllSymbols()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::reloadModules()
|
|
|
|
{
|
|
|
|
runCommand({"listModules"});
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::refreshModules(const GdbMi &modules)
|
|
|
|
{
|
|
|
|
ModulesHandler *handler = modulesHandler();
|
|
|
|
handler->beginUpdateAll();
|
|
|
|
for (const GdbMi &item : modules) {
|
|
|
|
Module module;
|
|
|
|
module.moduleName = item["name"].data();
|
|
|
|
QString path = item["value"].data();
|
|
|
|
int pos = path.indexOf("' from '");
|
|
|
|
if (pos != -1) {
|
|
|
|
path = path.mid(pos + 8);
|
|
|
|
if (path.size() >= 2)
|
|
|
|
path.chop(2);
|
|
|
|
} else if (path.startsWith("<module '")
|
2023-06-27 16:57:51 +02:00
|
|
|
&& path.endsWith("' (built-in)>")) {
|
2023-01-03 15:12:43 +01:00
|
|
|
path = "(builtin)";
|
|
|
|
}
|
|
|
|
module.modulePath = FilePath::fromString(path);
|
|
|
|
handler->updateModule(module);
|
|
|
|
}
|
|
|
|
handler->endUpdateAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::refreshState(const GdbMi &reportedState)
|
|
|
|
{
|
|
|
|
QString newState = reportedState.data();
|
|
|
|
if (newState == "stopped") {
|
|
|
|
notifyInferiorSpontaneousStop();
|
|
|
|
updateAll();
|
|
|
|
} else if (newState == "inferiorexited") {
|
|
|
|
notifyInferiorExited();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::refreshLocation(const GdbMi &reportedLocation)
|
|
|
|
{
|
|
|
|
StackFrame frame;
|
|
|
|
frame.file = FilePath::fromString(reportedLocation["file"].data());
|
|
|
|
frame.line = reportedLocation["line"].toInt();
|
|
|
|
frame.usable = frame.file.isReadableFile();
|
|
|
|
if (state() == InferiorRunOk) {
|
|
|
|
showMessage(QString("STOPPED AT: %1:%2").arg(frame.file.toUserOutput()).arg(frame.line));
|
|
|
|
gotoLocation(frame);
|
|
|
|
notifyInferiorSpontaneousStop();
|
|
|
|
updateAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::refreshSymbols(const GdbMi &symbols)
|
|
|
|
{
|
|
|
|
QString moduleName = symbols["module"].data();
|
|
|
|
Symbols syms;
|
|
|
|
for (const GdbMi &item : symbols["symbols"]) {
|
|
|
|
Symbol symbol;
|
|
|
|
symbol.name = item["name"].data();
|
|
|
|
syms.append(symbol);
|
|
|
|
}
|
|
|
|
showModuleSymbols(FilePath::fromString(moduleName), syms);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DapEngine::canHandleToolTip(const DebuggerToolTipContext &) const
|
|
|
|
{
|
|
|
|
return state() == InferiorStopOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::updateItem(const QString &iname)
|
|
|
|
{
|
2023-08-30 14:41:33 +02:00
|
|
|
WatchItem *item = watchHandler()->findItem(iname);
|
2023-09-22 11:48:23 +02:00
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
if (item && m_variablesHandler->currentItem().iname != item->iname)
|
|
|
|
m_variablesHandler->addVariable(item->iname, item->variablesReference);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
2023-09-22 11:48:23 +02:00
|
|
|
void DapEngine::reexpandItems(const QSet<QString> &inames)
|
|
|
|
{
|
2023-09-25 16:08:16 +02:00
|
|
|
QSet<QString> expandedInames = inames;
|
|
|
|
for (auto inames : watchHandler()->watcherNames().keys())
|
|
|
|
expandedInames.insert(watchHandler()->watcherName(inames));
|
|
|
|
|
|
|
|
QList<QString> inamesVector = expandedInames.values().toVector();
|
2023-09-22 11:48:23 +02:00
|
|
|
inamesVector.sort();
|
|
|
|
|
|
|
|
for (const QString &iname : inamesVector) {
|
2023-09-25 16:08:16 +02:00
|
|
|
if (iname.startsWith("local.") || iname.startsWith("watch."))
|
|
|
|
m_variablesHandler->addVariable(iname, -1);
|
2023-09-22 11:48:23 +02:00
|
|
|
}
|
2023-09-25 16:08:16 +02:00
|
|
|
}
|
2023-09-22 11:48:23 +02:00
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
void DapEngine::doUpdateLocals(const UpdateParameters ¶ms)
|
|
|
|
{
|
|
|
|
m_variablesHandler->addVariable(params.partialVariable, -1);
|
2023-09-22 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
QString DapEngine::errorMessage(QProcess::ProcessError error) const
|
|
|
|
{
|
|
|
|
switch (error) {
|
|
|
|
case QProcess::FailedToStart:
|
|
|
|
return Tr::tr("The DAP process failed to start. Either the "
|
|
|
|
"invoked program \"%1\" is missing, or you may have insufficient "
|
|
|
|
"permissions to invoke the program.")
|
2023-08-15 16:48:15 +02:00
|
|
|
.arg(m_dapClient->dataProvider()->executable());
|
2023-01-03 15:12:43 +01:00
|
|
|
case QProcess::Crashed:
|
|
|
|
return Tr::tr("The DAP process crashed some time after starting "
|
|
|
|
"successfully.");
|
|
|
|
case QProcess::Timedout:
|
|
|
|
return Tr::tr("The last waitFor...() function timed out. "
|
|
|
|
"The state of QProcess is unchanged, and you can try calling "
|
|
|
|
"waitFor...() again.");
|
|
|
|
case QProcess::WriteError:
|
|
|
|
return Tr::tr("An error occurred when attempting to write "
|
|
|
|
"to the DAP process. For example, the process may not be running, "
|
|
|
|
"or it may have closed its input channel.");
|
|
|
|
case QProcess::ReadError:
|
|
|
|
return Tr::tr("An error occurred when attempting to read from "
|
|
|
|
"the DAP process. For example, the process may not be running.");
|
|
|
|
default:
|
|
|
|
return Tr::tr("An unknown error in the DAP process occurred.") + ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::handleDapDone()
|
|
|
|
{
|
2023-08-15 16:48:15 +02:00
|
|
|
if (m_dapClient->dataProvider()->result() == ProcessResult::StartFailed) {
|
2023-01-03 15:12:43 +01:00
|
|
|
notifyEngineSetupFailed();
|
|
|
|
showMessage("ADAPTER START FAILED");
|
2023-08-15 16:48:15 +02:00
|
|
|
ICore::showWarningWithOptions(Tr::tr("Adapter start failed"),
|
|
|
|
m_dapClient->dataProvider()->exitMessage());
|
2023-01-03 15:12:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
const QProcess::ProcessError error = m_dapClient->dataProvider()->error();
|
2023-01-03 15:12:43 +01:00
|
|
|
if (error != QProcess::UnknownError) {
|
|
|
|
showMessage("HANDLE DAP ERROR");
|
|
|
|
if (error != QProcess::Crashed)
|
|
|
|
AsynchronousMessageBox::critical(Tr::tr("DAP I/O Error"), errorMessage(error));
|
|
|
|
if (error == QProcess::FailedToStart)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
showMessage(QString("DAP PROCESS FINISHED, status %1, code %2")
|
2023-08-15 16:48:15 +02:00
|
|
|
.arg(m_dapClient->dataProvider()->exitStatus()).arg(m_dapClient->dataProvider()->exitCode()));
|
2023-01-03 15:12:43 +01:00
|
|
|
notifyEngineSpontaneousShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::readDapStandardError()
|
|
|
|
{
|
2023-08-15 16:48:15 +02:00
|
|
|
QString err = m_dapClient->dataProvider()->readAllStandardError();
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "DAP STDERR:" << err;
|
2023-01-03 15:12:43 +01:00
|
|
|
//qWarning() << "Unexpected DAP stderr:" << err;
|
|
|
|
showMessage("Unexpected DAP stderr: " + err);
|
|
|
|
//handleOutput(err);
|
|
|
|
}
|
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
void DapEngine::handleResponse(DapResponseType type, const QJsonObject &response)
|
2023-08-09 14:09:02 +02:00
|
|
|
{
|
|
|
|
const QString command = response.value("command").toString();
|
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
switch (type) {
|
2023-08-25 15:40:18 +02:00
|
|
|
case DapResponseType::Initialize:
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "initialize success";
|
2023-08-25 15:40:18 +02:00
|
|
|
handleDapInitialize();
|
|
|
|
break;
|
2023-08-15 16:48:15 +02:00
|
|
|
case DapResponseType::ConfigurationDone:
|
2023-08-09 14:09:02 +02:00
|
|
|
showMessage("configurationDone", LogDebug);
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "configurationDone success";
|
2023-09-08 16:05:22 +02:00
|
|
|
handleDapConfigurationDone();
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
|
|
|
case DapResponseType::Continue:
|
2023-08-09 14:09:02 +02:00
|
|
|
showMessage("continue", LogDebug);
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "continue success";
|
2023-08-09 14:09:02 +02:00
|
|
|
notifyInferiorRunOk();
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
|
|
|
case DapResponseType::StackTrace:
|
2023-08-09 14:09:02 +02:00
|
|
|
handleStackTraceResponse(response);
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
|
|
|
case DapResponseType::Scopes:
|
2023-08-09 14:09:02 +02:00
|
|
|
handleScopesResponse(response);
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
|
|
|
case DapResponseType::Variables: {
|
2023-08-09 14:09:02 +02:00
|
|
|
auto variables = response.value("body").toObject().value("variables").toArray();
|
|
|
|
refreshLocals(variables);
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-08-15 16:48:15 +02:00
|
|
|
case DapResponseType::StepIn:
|
|
|
|
case DapResponseType::StepOut:
|
|
|
|
case DapResponseType::StepOver:
|
2023-08-09 14:09:02 +02:00
|
|
|
if (response.value("success").toBool()) {
|
|
|
|
showMessage(command, LogDebug);
|
2023-01-03 15:12:43 +01:00
|
|
|
notifyInferiorRunOk();
|
2023-08-09 14:09:02 +02:00
|
|
|
} else {
|
|
|
|
notifyInferiorRunFailed();
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
|
|
|
case DapResponseType::DapThreads:
|
2023-08-09 14:09:02 +02:00
|
|
|
handleThreadsResponse(response);
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
2023-09-25 16:08:16 +02:00
|
|
|
case DapResponseType::Evaluate:
|
|
|
|
handleEvaluateResponse(response);
|
|
|
|
break;
|
2023-08-15 16:48:15 +02:00
|
|
|
default:
|
|
|
|
showMessage("UNKNOWN RESPONSE:" + command);
|
|
|
|
};
|
2023-09-25 16:08:16 +02:00
|
|
|
|
|
|
|
if (response.contains("success") && !response.value("success").toBool()) {
|
|
|
|
showMessage(QString("DAP COMMAND FAILED: %1").arg(command));
|
|
|
|
qCDebug(logCategory()) << "DAP COMMAND FAILED:" << command;
|
|
|
|
return;
|
|
|
|
}
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-06-16 15:28:50 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
void DapEngine::handleStackTraceResponse(const QJsonObject &response)
|
|
|
|
{
|
|
|
|
QJsonArray stackFrames = response.value("body").toObject().value("stackFrames").toArray();
|
|
|
|
if (stackFrames.isEmpty())
|
|
|
|
return;
|
2023-06-15 15:27:33 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
QJsonObject stackFrame = stackFrames[0].toObject();
|
|
|
|
const FilePath file = FilePath::fromString(
|
|
|
|
stackFrame.value("source").toObject().value("path").toString());
|
|
|
|
const int line = stackFrame.value("line").toInt();
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "stackTrace success" << file << line;
|
2023-08-09 14:09:02 +02:00
|
|
|
gotoLocation(Location(file, line));
|
2023-06-16 15:28:50 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
refreshStack(stackFrames);
|
2023-09-21 10:17:07 +02:00
|
|
|
m_currentStackFrameId = stackFrame.value("id").toInt();
|
|
|
|
m_dapClient->scopes(m_currentStackFrameId);
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-06-16 15:28:50 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
void DapEngine::handleScopesResponse(const QJsonObject &response)
|
|
|
|
{
|
|
|
|
if (!response.value("success").toBool())
|
|
|
|
return;
|
|
|
|
|
2023-09-01 14:08:26 +02:00
|
|
|
watchHandler()->notifyUpdateStarted();
|
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
QJsonArray scopes = response.value("body").toObject().value("scopes").toArray();
|
|
|
|
for (const QJsonValueRef &scope : scopes) {
|
|
|
|
const QString name = scope.toObject().value("name").toString();
|
2023-09-01 14:08:26 +02:00
|
|
|
if (name == "Registers")
|
|
|
|
continue;
|
2023-09-25 16:08:16 +02:00
|
|
|
m_variablesHandler->addVariable("", scope.toObject().value("variablesReference").toInt());
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-09-01 14:08:26 +02:00
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
if (m_variablesHandler->queueSize() == 0) {
|
2023-09-21 10:17:07 +02:00
|
|
|
watchHandler()->notifyUpdateFinished();
|
|
|
|
}
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-06-15 15:27:33 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
void DapEngine::handleThreadsResponse(const QJsonObject &response)
|
|
|
|
{
|
|
|
|
QJsonArray threads = response.value("body").toObject().value("threads").toArray();
|
2023-06-16 15:28:50 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
if (threads.isEmpty())
|
|
|
|
return;
|
2023-06-15 15:27:33 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
ThreadsHandler *handler = threadsHandler();
|
|
|
|
for (const QJsonValueRef &thread : threads) {
|
|
|
|
ThreadData threadData;
|
|
|
|
threadData.id = QString::number(thread.toObject().value("id").toInt());
|
|
|
|
threadData.name = thread.toObject().value("name").toString();
|
|
|
|
handler->updateThread(threadData);
|
|
|
|
}
|
2023-06-15 15:27:33 +02:00
|
|
|
|
2023-08-17 14:50:36 +02:00
|
|
|
if (m_currentThreadId) {
|
|
|
|
Thread thread = threadsHandler()->threadForId(QString::number(m_currentThreadId));
|
|
|
|
if (thread && thread != threadsHandler()->currentThread())
|
|
|
|
handler->setCurrentThread(thread);
|
|
|
|
}
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
void DapEngine::handleEvaluateResponse(const QJsonObject &response)
|
|
|
|
{
|
|
|
|
WatchItem *watchItem = watchHandler()->findItem(
|
|
|
|
m_variablesHandler->currentItem().iname);
|
|
|
|
if (watchItem
|
|
|
|
&& response.value("body").toObject().contains("variablesReference")) {
|
|
|
|
watchItem->variablesReference
|
|
|
|
= response.value("body").toObject().value("variablesReference").toInt();
|
|
|
|
watchItem->value
|
|
|
|
= response.value("body").toObject().value("result").toString();
|
|
|
|
watchItem->type = response.value("body").toObject().value("type").toString();
|
|
|
|
watchItem->wantsChildren = watchItem->variablesReference > 0;
|
|
|
|
|
|
|
|
watchItem->updateValueCache();
|
|
|
|
watchItem->update();
|
|
|
|
|
|
|
|
m_variablesHandler->addVariable(watchItem->iname,
|
|
|
|
watchItem->variablesReference);
|
|
|
|
}
|
|
|
|
m_variablesHandler->handleNext();
|
|
|
|
}
|
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
void DapEngine::handleEvent(DapEventType type, const QJsonObject &event)
|
2023-08-09 14:09:02 +02:00
|
|
|
{
|
|
|
|
const QString eventType = event.value("event").toString();
|
|
|
|
const QJsonObject body = event.value("body").toObject();
|
|
|
|
showMessage(eventType, LogDebug);
|
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
switch (type) {
|
|
|
|
case DapEventType::Initialized:
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "initialize success";
|
2023-08-25 15:40:18 +02:00
|
|
|
claimInitialBreakpoints();
|
2023-09-08 16:05:22 +02:00
|
|
|
handleDapEventInitialized();
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
|
|
|
case DapEventType::Stopped:
|
|
|
|
handleStoppedEvent(event);
|
|
|
|
break;
|
|
|
|
case DapEventType::Exited:
|
2023-08-09 14:09:02 +02:00
|
|
|
notifyInferiorExited();
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
|
|
|
case DapEventType::DapThread:
|
|
|
|
m_dapClient->threads();
|
|
|
|
if (body.value("reason").toString() == "started" && body.value("threadId").toInt() == 1)
|
|
|
|
claimInitialBreakpoints();
|
|
|
|
break;
|
|
|
|
case DapEventType::DapBreakpoint:
|
|
|
|
handleBreakpointEvent(event);
|
|
|
|
break;
|
|
|
|
case DapEventType::Output: {
|
2023-08-09 14:09:02 +02:00
|
|
|
const QString category = body.value("category").toString();
|
|
|
|
const QString output = body.value("output").toString();
|
|
|
|
if (category == "stdout")
|
|
|
|
showMessage(output, AppOutput);
|
|
|
|
else if (category == "stderr")
|
|
|
|
showMessage(output, AppError);
|
|
|
|
else
|
|
|
|
showMessage(output, LogDebug);
|
2023-08-15 16:48:15 +02:00
|
|
|
break;
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-08-15 16:48:15 +02:00
|
|
|
default:
|
|
|
|
showMessage("UNKNOWN EVENT:" + eventType);
|
|
|
|
};
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-06-15 15:27:33 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
void DapEngine::handleStoppedEvent(const QJsonObject &event)
|
|
|
|
{
|
|
|
|
const QJsonObject body = event.value("body").toObject();
|
|
|
|
m_currentThreadId = body.value("threadId").toInt();
|
2023-04-06 14:20:01 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
if (body.value("reason").toString() == "breakpoint") {
|
|
|
|
QString id = QString::number(body.value("hitBreakpointIds").toArray().first().toInteger());
|
|
|
|
|
|
|
|
Breakpoint bp = breakHandler()->findBreakpointByResponseId(id);
|
|
|
|
if (bp) {
|
|
|
|
const BreakpointParameters ¶ms = bp->requestedParameters();
|
|
|
|
gotoLocation(Location(params.fileName, params.textPosition));
|
2023-08-11 13:04:41 +02:00
|
|
|
if (params.oneShot)
|
|
|
|
removeBreakpoint(bp);
|
2023-04-06 14:20:01 +02:00
|
|
|
}
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-04-06 14:20:01 +02:00
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
if (state() == InferiorStopRequested)
|
|
|
|
notifyInferiorStopOk();
|
|
|
|
else
|
|
|
|
notifyInferiorSpontaneousStop();
|
|
|
|
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->stackTrace(m_currentThreadId);
|
|
|
|
m_dapClient->threads();
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "breakpoint id :" << breakpoint.value("id").toInt();
|
2023-08-09 14:09:02 +02:00
|
|
|
|
2023-08-10 12:25:59 +02:00
|
|
|
if (bp) {
|
|
|
|
BreakpointParameters parameters = bp->requestedParameters();
|
|
|
|
if (parameters.enabled != bp->isEnabled()) {
|
|
|
|
parameters.pending = false;
|
|
|
|
bp->setParameters(parameters);
|
|
|
|
notifyBreakpointChangeOk(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
if (body.value("reason").toString() == "new") {
|
|
|
|
if (breakpoint.value("verified").toBool()) {
|
|
|
|
notifyBreakpointInsertOk(bp);
|
2023-08-11 13:04:41 +02:00
|
|
|
const BreakpointParameters ¶ms = bp->requestedParameters();
|
|
|
|
if (params.oneShot)
|
|
|
|
continueInferior();
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "breakpoint inserted";
|
2023-08-09 14:09:02 +02:00
|
|
|
} else {
|
|
|
|
notifyBreakpointInsertFailed(bp);
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "breakpoint insertion failed";
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
2023-01-03 15:12:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-09 14:09:02 +02:00
|
|
|
if (body.value("reason").toString() == "removed") {
|
|
|
|
if (breakpoint.value("verified").toBool()) {
|
|
|
|
notifyBreakpointRemoveOk(bp);
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "breakpoint removed";
|
2023-08-09 14:09:02 +02:00
|
|
|
} else {
|
|
|
|
notifyBreakpointRemoveFailed(bp);
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "breakpoint remove failed";
|
2023-08-09 14:09:02 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
2023-06-16 15:28:50 +02:00
|
|
|
void DapEngine::refreshLocals(const QJsonArray &variables)
|
|
|
|
{
|
2023-09-25 16:08:16 +02:00
|
|
|
WatchItem *currentItem = watchHandler()->findItem(m_variablesHandler->currentItem().iname);
|
|
|
|
if (currentItem && currentItem->iname.startsWith("watch"))
|
|
|
|
currentItem->removeChildren();
|
|
|
|
|
2023-06-16 15:28:50 +02:00
|
|
|
for (auto variable : variables) {
|
|
|
|
WatchItem *item = new WatchItem;
|
|
|
|
const QString name = variable.toObject().value("name").toString();
|
2023-09-25 16:08:16 +02:00
|
|
|
|
|
|
|
item->iname = (currentItem ? currentItem->iname : "local") + "."
|
|
|
|
+ name;
|
2023-06-16 15:28:50 +02:00
|
|
|
item->name = name;
|
|
|
|
item->type = variable.toObject().value("type").toString();
|
|
|
|
item->value = variable.toObject().value("value").toString();
|
|
|
|
item->address = variable.toObject().value("address").toInt();
|
|
|
|
item->type = variable.toObject().value("type").toString();
|
2023-09-25 16:08:16 +02:00
|
|
|
item->variablesReference = variable.toObject().value("variablesReference").toInt();
|
|
|
|
item->wantsChildren = item->variablesReference > 0;
|
2023-07-13 13:43:59 +02:00
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
qCDebug(logCategory()) << "variable" << item->iname << item->variablesReference;
|
|
|
|
if (currentItem)
|
|
|
|
currentItem->appendChild(item);
|
2023-08-17 16:34:36 +02:00
|
|
|
else
|
2023-09-25 16:08:16 +02:00
|
|
|
watchHandler()->insertItem(item);
|
2023-06-16 15:28:50 +02:00
|
|
|
}
|
2023-07-13 13:43:59 +02:00
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
QModelIndex idx = watchHandler()->model()->indexForItem(currentItem);
|
|
|
|
if (currentItem && idx.isValid() && idx.data(LocalsExpandedRole).toBool()) {
|
|
|
|
emit watchHandler()->model()->inameIsExpanded(currentItem->iname);
|
|
|
|
emit watchHandler()->model()->itemIsExpanded(idx);
|
2023-09-22 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
if (m_variablesHandler->queueSize() == 1 && currentItem == nullptr) {
|
|
|
|
watchHandler()->notifyUpdateFinished();
|
2023-09-01 14:08:26 +02:00
|
|
|
}
|
2023-07-13 13:43:59 +02:00
|
|
|
|
2023-09-25 16:08:16 +02:00
|
|
|
m_variablesHandler->handleNext();
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
2023-06-16 15:28:50 +02:00
|
|
|
void DapEngine::refreshStack(const QJsonArray &stackFrames)
|
2023-01-03 15:12:43 +01:00
|
|
|
{
|
|
|
|
StackHandler *handler = stackHandler();
|
|
|
|
StackFrames frames;
|
2023-06-16 15:28:50 +02:00
|
|
|
for (const auto &value : stackFrames) {
|
2023-01-03 15:12:43 +01:00
|
|
|
StackFrame frame;
|
2023-06-16 15:28:50 +02:00
|
|
|
QJsonObject item = value.toObject();
|
|
|
|
frame.level = item.value("id").toString();
|
|
|
|
frame.function = item.value("name").toString();
|
|
|
|
frame.line = item.value("line").toInt();
|
|
|
|
QJsonObject source = item.value("source").toObject();
|
|
|
|
frame.file = FilePath::fromString(source.value("path").toString());
|
|
|
|
frame.address = item.value("instructionPointerReference").toInt();
|
|
|
|
frame.usable = frame.file.isReadableFile();
|
2023-09-21 10:17:07 +02:00
|
|
|
frame.debuggerId = item.value("id").toInt();
|
2023-01-03 15:12:43 +01:00
|
|
|
frames.append(frame);
|
|
|
|
}
|
2023-06-16 15:28:50 +02:00
|
|
|
handler->setFrames(frames, false);
|
2023-01-03 15:12:43 +01:00
|
|
|
|
|
|
|
int index = stackHandler()->firstUsableIndex();
|
|
|
|
handler->setCurrentIndex(index);
|
|
|
|
if (index >= 0 && index < handler->stackSize())
|
|
|
|
gotoLocation(handler->frameAt(index));
|
|
|
|
}
|
|
|
|
|
2023-08-09 17:08:54 +02:00
|
|
|
void DapEngine::reloadFullStack()
|
|
|
|
{
|
|
|
|
updateAll();
|
|
|
|
}
|
|
|
|
|
2023-01-03 15:12:43 +01:00
|
|
|
void DapEngine::updateAll()
|
|
|
|
{
|
|
|
|
runCommand({"stackListFrames"});
|
|
|
|
updateLocals();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::updateLocals()
|
|
|
|
{
|
2023-08-15 16:48:15 +02:00
|
|
|
m_dapClient->stackTrace(m_currentThreadId);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DapEngine::hasCapability(unsigned cap) const
|
|
|
|
{
|
|
|
|
return cap & (ReloadModuleCapability
|
2023-06-27 16:57:51 +02:00
|
|
|
| BreakConditionCapability
|
2023-08-11 13:04:41 +02:00
|
|
|
| ShowModuleSymbolsCapability
|
2023-09-22 11:48:23 +02:00
|
|
|
| RunToLineCapability
|
|
|
|
| AddWatcherCapability);
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DapEngine::claimInitialBreakpoints()
|
|
|
|
{
|
|
|
|
BreakpointManager::claimBreakpointsForEngine(this);
|
2023-09-12 10:44:57 +02:00
|
|
|
qCDebug(logCategory()) << "claimInitialBreakpoints";
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
2023-08-08 15:37:39 +02:00
|
|
|
void DapEngine::connectDataGeneratorSignals()
|
|
|
|
{
|
2023-08-15 16:48:15 +02:00
|
|
|
if (!m_dapClient)
|
2023-08-08 15:37:39 +02:00
|
|
|
return;
|
|
|
|
|
2023-08-17 13:32:55 +02:00
|
|
|
connect(m_dapClient, &DapClient::started, this, &DapEngine::handleDapStarted);
|
|
|
|
connect(m_dapClient, &DapClient::done, this, &DapEngine::handleDapDone);
|
|
|
|
connect(m_dapClient,
|
2023-08-15 16:48:15 +02:00
|
|
|
&DapClient::readyReadStandardError,
|
2023-08-08 15:37:39 +02:00
|
|
|
this,
|
|
|
|
&DapEngine::readDapStandardError);
|
2023-08-15 16:48:15 +02:00
|
|
|
|
2023-08-17 13:32:55 +02:00
|
|
|
connect(m_dapClient, &DapClient::responseReady, this, &DapEngine::handleResponse);
|
|
|
|
connect(m_dapClient, &DapClient::eventReady, this, &DapEngine::handleEvent);
|
2023-08-08 15:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DebuggerEngine *createDapEngine(Utils::Id runMode)
|
2023-01-03 15:12:43 +01:00
|
|
|
{
|
2023-08-25 15:40:18 +02:00
|
|
|
if (runMode == ProjectExplorer::Constants::DAP_CMAKE_DEBUG_RUN_MODE)
|
2023-08-08 15:37:39 +02:00
|
|
|
return new CMakeDapEngine;
|
2023-08-25 15:40:18 +02:00
|
|
|
if (runMode == ProjectExplorer::Constants::DAP_GDB_DEBUG_RUN_MODE)
|
|
|
|
return new GdbDapEngine;
|
|
|
|
if (runMode == ProjectExplorer::Constants::DAP_PY_DEBUG_RUN_MODE)
|
|
|
|
return new PyDapEngine;
|
2023-08-08 15:37:39 +02:00
|
|
|
|
2023-08-25 15:40:18 +02:00
|
|
|
return nullptr;
|
2023-01-03 15:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Debugger::Internal
|