From d1e0324b22e599d1eb50b938dde958436d6d8f4f Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 25 Feb 2015 13:01:45 +0100 Subject: [PATCH] Debugger: Fix GdbEngine state transitions for 'attach' ... to running process. Pretty much the same setup as for the terminal now, except that we are stopped in the end. Change-Id: I02c5bf52971dc97fd6393ee67349c9070dc08697 Reviewed-by: Friedemann Kleint Reviewed-by: Christian Stenger --- src/plugins/debugger/gdb/attachgdbadapter.cpp | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/plugins/debugger/gdb/attachgdbadapter.cpp b/src/plugins/debugger/gdb/attachgdbadapter.cpp index aef3139c49c..2028538a194 100644 --- a/src/plugins/debugger/gdb/attachgdbadapter.cpp +++ b/src/plugins/debugger/gdb/attachgdbadapter.cpp @@ -66,40 +66,49 @@ void GdbAttachEngine::setupEngine() void GdbAttachEngine::setupInferior() { QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state()); - const qint64 pid = startParameters().attachPID; - postCommand("attach " + QByteArray::number(pid), NoFlags, - [this](const DebuggerResponse &r) { handleAttach(r); }); // Task 254674 does not want to remove them //qq->breakHandler()->removeAllBreakpoints(); + handleInferiorPrepared(); } void GdbAttachEngine::runEngine() { QTC_ASSERT(state() == EngineRunRequested, qDebug() << state()); + const qint64 pid = startParameters().attachPID; + postCommand("attach " + QByteArray::number(pid), NoFlags, + [this](const DebuggerResponse &r) { handleAttach(r); }); showStatusMessage(tr("Attached to process %1.").arg(inferiorPid())); - notifyEngineRunAndInferiorStopOk(); - handleStop1(GdbMi()); } void GdbAttachEngine::handleAttach(const DebuggerResponse &response) { - QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state()); + QTC_ASSERT(state() == EngineRunRequested || state() == InferiorStopOk, + qDebug() << state()); switch (response.resultClass) { case ResultDone: case ResultRunning: showMessage(_("INFERIOR ATTACHED")); - showMessage(msgAttachedToStoppedInferior(), StatusBar); - handleInferiorPrepared(); + if (state() == EngineRunRequested) { + // FIXME: Really? Looks like we are always stopped already. + // We will get a '*stopped' later that we'll interpret as 'spontaneous' + // So acknowledge the current state and put a delayed 'continue' in the pipe. + showMessage(msgAttachedToStoppedInferior(), StatusBar); + notifyEngineRunAndInferiorRunOk(); + interruptInferior(); + } break; case ResultError: if (response.data["msg"].data() == "ptrace: Operation not permitted.") { - notifyInferiorSetupFailed(msgPtraceError(startParameters().startMode)); + showStatusMessage(tr("Failed to attach to application: %1") + .arg(msgPtraceError(startParameters().startMode))); + notifyEngineIll(); break; } // if msg != "ptrace: ..." fall through default: - QString msg = QString::fromLocal8Bit(response.data["msg"].data()); - notifyInferiorSetupFailed(msg); + showStatusMessage(tr("Failed to attach to application: %1") + .arg(QString::fromLocal8Bit(response.data["msg"].data()))); + notifyEngineIll(); } }