From 17b1fa1618dc974afd19c26fbd0088e6d70c96fa Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 12 Oct 2022 11:59:26 +0200 Subject: [PATCH] Debugger: Fix interrupting with cdb It turns out sending ctrl+c events to cdb results in inconsistent behavior when trying to interrupt with the range from interrupting twice to not at all. Use the previous method of using signal operation for local debugging, and use the ctrl+c event only when cdb is attached to a remote server. Fixes: QTCREATORBUG-28279 Change-Id: Iccd2016685ba707b375aebfd88eccc253dde1d1d Reviewed-by: Christian Stenger --- src/plugins/debugger/cdb/cdbengine.cpp | 24 ++++++++++++++++++++++++ src/plugins/debugger/cdb/cdbengine.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index 7740d0f0208..05560351597 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -763,6 +763,18 @@ void CdbEngine::interruptInferior() doInterruptInferior(); } +void CdbEngine::handleDoInterruptInferior(const QString &errorMessage) +{ + if (errorMessage.isEmpty()) { + showMessage("Interrupted " + QString::number(inferiorPid())); + } else { + showMessage(errorMessage, LogError); + notifyInferiorStopFailed(); + } + m_signalOperation->disconnect(this); + m_signalOperation.clear(); +} + void CdbEngine::doInterruptInferior(const InterruptCallback &callback) { const bool requestInterrupt = m_stopMode == NoStopRequested; @@ -779,6 +791,18 @@ void CdbEngine::doInterruptInferior(const InterruptCallback &callback) if (!requestInterrupt) return; // we already requested a stop no need to interrupt twice showMessage(QString("Interrupting process %1...").arg(inferiorPid()), LogMisc); + + QTC_ASSERT(!m_signalOperation, notifyInferiorStopFailed(); return); + if (m_effectiveStartMode != AttachToRemoteServer && device()) { + m_signalOperation = device()->signalOperation(); + if (m_signalOperation) { + connect(m_signalOperation.data(), &DeviceProcessSignalOperation::finished, + this, &CdbEngine::handleDoInterruptInferior); + m_signalOperation->setDebuggerCommand(runParameters().debugger.command.executable()); + m_signalOperation->interruptProcess(inferiorPid()); + return; + } + } m_process.interrupt(); } diff --git a/src/plugins/debugger/cdb/cdbengine.h b/src/plugins/debugger/cdb/cdbengine.h index 27a3cd3d410..108cc64d160 100644 --- a/src/plugins/debugger/cdb/cdbengine.h +++ b/src/plugins/debugger/cdb/cdbengine.h @@ -85,6 +85,8 @@ private: void createFullBacktrace(); + void handleDoInterruptInferior(const QString &errorMessage); + typedef QPair SourcePathMapping; struct NormalizedSourceFileName // Struct for caching mapped/normalized source files. { @@ -175,6 +177,7 @@ private: //! Debugger accessible (expecting commands) bool m_accessible = false; StopMode m_stopMode = NoStopRequested; + ProjectExplorer::DeviceProcessSignalOperation::Ptr m_signalOperation; int m_nextCommandToken = 0; QHash m_commandForToken; QString m_currentBuiltinResponse;