DAP: Add attach function to gdb dap engine

Change-Id: Id1c886cf3bbdbf85d4eed39f288107fc71317496
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Artem Sokolovskii
2023-09-08 16:05:22 +02:00
parent 3a3bf41eef
commit 578e4c13fd
5 changed files with 61 additions and 12 deletions

View File

@@ -120,7 +120,16 @@ void DapEngine::handleDapStarted()
qCDebug(dapEngineLog) << "handleDapStarted";
}
void DapEngine::handleDapConfigurationDone()
void DapEngine::handleDapInitialize()
{
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state());
m_dapClient->sendLaunch(runParameters().inferior.command.executable());
qCDebug(dapEngineLog) << "handleDapLaunch";
}
void DapEngine::handleDapEventInitialized()
{
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state());
@@ -129,14 +138,9 @@ void DapEngine::handleDapConfigurationDone()
qCDebug(dapEngineLog) << "handleDapConfigurationDone";
}
void DapEngine::handleDapInitialize()
void DapEngine::handleDapConfigurationDone()
{
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state());
m_dapClient->sendLaunch(runParameters().inferior.command.executable());
qCDebug(dapEngineLog) << "handleDapLaunch";
notifyEngineRunAndInferiorRunOk();
}
void DapEngine::interruptInferior()
@@ -480,6 +484,12 @@ void DapEngine::handleResponse(DapResponseType type, const QJsonObject &response
{
const QString command = response.value("command").toString();
if (response.contains("success") && !response.value("success").toBool()) {
showMessage(QString("DAP COMMAND FAILED: %1").arg(command));
qCDebug(dapEngineLog) << "DAP COMMAND FAILED:" << command;
return;
}
switch (type) {
case DapResponseType::Initialize:
qCDebug(dapEngineLog) << "initialize success";
@@ -488,7 +498,7 @@ void DapEngine::handleResponse(DapResponseType type, const QJsonObject &response
case DapResponseType::ConfigurationDone:
showMessage("configurationDone", LogDebug);
qCDebug(dapEngineLog) << "configurationDone success";
notifyEngineRunAndInferiorRunOk();
handleDapConfigurationDone();
break;
case DapResponseType::Continue:
showMessage("continue", LogDebug);
@@ -597,7 +607,7 @@ void DapEngine::handleEvent(DapEventType type, const QJsonObject &event)
case DapEventType::Initialized:
qCDebug(dapEngineLog) << "initialize success";
claimInitialBreakpoints();
handleDapConfigurationDone();
handleDapEventInitialized();
break;
case DapEventType::Stopped:
handleStoppedEvent(event);

View File

@@ -85,7 +85,8 @@ protected:
void handleDapStarted();
virtual void handleDapInitialize();
void handleDapConfigurationDone();
void handleDapEventInitialized();
virtual void handleDapConfigurationDone();
void dapRemoveBreakpoint(const Breakpoint &bp);
void dapInsertBreakpoint(const Breakpoint &bp);

View File

@@ -93,12 +93,43 @@ GdbDapEngine::GdbDapEngine()
setDebuggerType("DAP");
}
void GdbDapEngine::handleDapInitialize()
{
if (!isLocalAttachEngine()) {
DapEngine::handleDapInitialize();
return;
}
QTC_ASSERT(state() == EngineRunRequested, qCDebug(dapEngineLog) << state());
m_dapClient->postRequest("attach", QJsonObject{{"__restart", ""}});
qCDebug(dapEngineLog) << "handleDapAttach";
}
bool GdbDapEngine::isLocalAttachEngine() const
{
return runParameters().startMode == AttachToLocalProcess;
}
void GdbDapEngine::handleDapConfigurationDone()
{
if (!isLocalAttachEngine()) {
DapEngine::handleDapConfigurationDone();
return;
}
notifyEngineRunAndInferiorStopOk();
}
void GdbDapEngine::setupEngine()
{
QTC_ASSERT(state() == EngineSetupRequested, qCDebug(dapEngineLog) << state());
const DebuggerRunParameters &rp = runParameters();
const CommandLine cmd{rp.debugger.command.executable(), {"-i", "dap"}};
CommandLine cmd{rp.debugger.command.executable(), {"-i", "dap"}};
if (isLocalAttachEngine())
cmd.addArgs({"-p", QString::number(rp.attachPID.pid())});
QVersionNumber oldestVersion(14, 0, 50);
QVersionNumber version = QVersionNumber::fromString(rp.version);

View File

@@ -14,6 +14,11 @@ public:
private:
void setupEngine() override;
void handleDapInitialize() override;
void handleDapConfigurationDone() override;
bool isLocalAttachEngine() const;
};
} // Debugger::Internal

View File

@@ -88,6 +88,8 @@ public:
connect(m_timer, &QTimer::timeout, this, [this]() {
m_socket.connectToHost(m_hostName, m_port);
m_socket.waitForConnected();
qCDebug(dapEngineLog) << "proc id" << m_proc.processId();
if (m_socket.state() == QTcpSocket::ConnectedState)
m_timer->stop();