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 <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2015-02-25 13:01:45 +01:00
parent 1b71e8a53d
commit d1e0324b22

View File

@@ -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"));
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);
handleInferiorPrepared();
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();
}
}