diff --git a/src/plugins/debugger/gdb/attachgdbadapter.cpp b/src/plugins/debugger/gdb/attachgdbadapter.cpp
index 661f558d265986458a0ce6f37c9dd800f08a0fd3..484828d2a1af9669f7330a623bbaaf39b789afae 100644
--- a/src/plugins/debugger/gdb/attachgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/attachgdbadapter.cpp
@@ -95,10 +95,9 @@ void AttachGdbAdapter::startInferior()
 
 void AttachGdbAdapter::handleAttach(const GdbResponse &response)
 {
-    QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
     if (response.resultClass == GdbResultDone) {
-        setState(InferiorStopped);
-        debugMessage(_("INFERIOR STARTED"));
+        QTC_ASSERT(state() == InferiorStopped, qDebug() << state());
+        debugMessage(_("INFERIOR ATTACHED"));
         showStatusMessage(msgAttachedToStoppedInferior());
         m_engine->updateAll();
     } else {
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 31dbee86758b7b821d19835e4c06c402f5fd4497..1372c47005817fd62dbac432be318a9d3ff44507 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -1007,7 +1007,13 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
     const QByteArray reason = data.findChild("reason").data();
 
     if (isExitedReason(reason)) {
-        QTC_ASSERT(state() == InferiorRunning, /**/);
+        if (state() == InferiorRunning) {
+            setState(InferiorStopping);
+        } else {
+            // The user triggered a stop, but meanwhile the app simply exited ...
+            QTC_ASSERT(state() == InferiorStopping, qDebug() << state());
+        }
+        setState(InferiorStopped);
         QString msg;
         if (reason == "exited") {
             msg = tr("Program exited with exit code %1.")
@@ -1040,6 +1046,16 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
         return;
     }
 
+    if (state() == InferiorRunning) {
+        // Stop triggered by a breakpoint or otherwise not directly
+        // initiated by the user.
+        setState(InferiorStopping);
+    } else {
+        QTC_ASSERT(state() == InferiorStopping || state() == InferiorStarting,
+                   qDebug() << state());
+    }
+    setState(InferiorStopped);
+
     const QByteArray &msg = data.findChild("consolestreamoutput").data();
     if (msg.contains("Stopped due to shared library event") || reason.isEmpty()) {
         if (theDebuggerBoolSetting(SelectedPluginBreakpoints)) {
@@ -1129,7 +1145,6 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
     // MAC yields sometimes:
     // >3661*stopped,time={wallclock="0.00658",user="0.00142",
     // system="0.00136",start="1218810678.805432",end="1218810678.812011"}
-    setState(InferiorStopped);
     showStatusMessage(tr("Run to Function finished. Stopped."));
     StackFrame f = parseStackFrame(data.findChild("frame"), 0);
     gotoLocation(f, true);
@@ -1171,6 +1186,7 @@ void GdbEngine::handleStop1(const GdbMi &data)
             GdbMi frameData = data.findChild("frame");
             if (frameData.findChild("func").data() == "_start"
                 && frameData.findChild("from").data() == "/lib/ld-linux.so.2") {
+                setState(InferiorRunningRequested);
                 postCommand(_("-exec-continue"), RunRequest, CB(handleExecContinue));
                 return;
             }
@@ -1209,14 +1225,6 @@ void GdbEngine::handleStop2(const GdbResponse &response)
 
 void GdbEngine::handleStop2(const GdbMi &data)
 {
-    if (state() == InferiorRunning) {
-        // Stop triggered by a breakpoint or otherwise not directly
-        // initiated by the user.
-        setState(InferiorStopping);
-    }
-    setState(InferiorStopped);
-    showStatusMessage(tr("Stopped."), 5000);
-
     // Sometimes we get some interesting extra information. Grab it.
     GdbMi frame = data.findChild("frame");
     GdbMi shortName = frame.findChild("file");
diff --git a/src/plugins/debugger/gdb/remotegdbadapter.cpp b/src/plugins/debugger/gdb/remotegdbadapter.cpp
index 632a28309c8d5e829858d3bb06b2e2c414a24e03..27b0031cbf7829a1d27ad30be004e2e3bb09efa2 100644
--- a/src/plugins/debugger/gdb/remotegdbadapter.cpp
+++ b/src/plugins/debugger/gdb/remotegdbadapter.cpp
@@ -213,12 +213,11 @@ void RemoteGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
 
 void RemoteGdbAdapter::handleTargetRemote(const GdbResponse &record)
 {
-    QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
     if (record.resultClass == GdbResultDone) {
+        QTC_ASSERT(state() == InferiorStopped, qDebug() << state());
         // gdb server will stop the remote application itself.
         debugMessage(_("INFERIOR STARTED"));
         showStatusMessage(msgAttachedToStoppedInferior());
-        setState(InferiorStopped);
         m_engine->continueInferior();
     } else {
         // 16^error,msg="hd:5555: Connection timed out."