diff --git a/src/plugins/debugger/gdb/tcftrkgdbadapter.cpp b/src/plugins/debugger/gdb/tcftrkgdbadapter.cpp
index cf2b8c3..a42f31e 100644
--- a/src/plugins/debugger/gdb/tcftrkgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/tcftrkgdbadapter.cpp
@@ -628,11 +628,7 @@ void TcfTrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
     else if (cmd == "k" || cmd.startsWith("vKill")) {
         // Kill inferior process
         logMessage(msgGdbPacket(QLatin1String("kill")));
-        // Requires id of main thread to terminate.
-        // Note that calling 'Settings|set|removeExecutable' crashes TCF TRK,
-        // so, it is apparently not required.
-        m_trkDevice->sendRunControlTerminateCommand(TcfTrkCallback(),
-                                                    mainThreadContextId());
+        sendRunControlTerminateCommand();
     }
 
     else if (cmd.startsWith('m')) {
@@ -941,6 +937,28 @@ void TcfTrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
     }
 }
 
+void TcfTrkGdbAdapter::sendRunControlTerminateCommand()
+{
+    // Requires id of main thread to terminate.
+    // Note that calling 'Settings|set|removeExecutable' crashes TCF TRK,
+    // so, it is apparently not required.
+    m_trkDevice->sendRunControlTerminateCommand(TcfTrkCallback(this, &TcfTrkGdbAdapter::handleRunControlTerminate),
+                                                mainThreadContextId());
+}
+
+void TcfTrkGdbAdapter::handleRunControlTerminate(const tcftrk::TcfTrkCommandResult &)
+{
+    QString msg = QString::fromLatin1("CODA disconnected");
+    const bool emergencyShutdown = m_gdbProc.state() != QProcess::Running;
+    if (emergencyShutdown)
+        msg += QString::fromLatin1(" (emergency shutdown");
+    logMessage(msg);
+    if (emergencyShutdown) {
+        cleanup();
+        m_engine->notifyAdapterShutdownOk();
+    }
+}
+
 void TcfTrkGdbAdapter::gdbSetCurrentThread(const QByteArray &cmd, const char *why)
 {
     // Thread ID from Hg/Hc commands: '-1': All, '0': arbitrary, else hex thread id.
@@ -1155,8 +1173,16 @@ void TcfTrkGdbAdapter::shutdownInferior()
 
 void TcfTrkGdbAdapter::shutdownAdapter()
 {
-    cleanup();
-    m_engine->notifyAdapterShutdownOk();
+    if (m_gdbProc.state() == QProcess::Running) {
+        cleanup();
+        m_engine->notifyAdapterShutdownOk();
+    } else {
+        // Something is wrong, gdb crashed. Kill debuggee (see handleDeleteProcess2)
+        if (m_trkDevice->device()->isOpen()) {
+            logMessage("Emergency shutdown of CODA", LogError);
+            sendRunControlTerminateCommand();
+        }
+    }
 }
 
 void TcfTrkGdbAdapter::trkReloadRegisters()
diff --git a/src/plugins/debugger/gdb/tcftrkgdbadapter.h b/src/plugins/debugger/gdb/tcftrkgdbadapter.h
index 8cbb44e..30c527e 100644
--- a/src/plugins/debugger/gdb/tcftrkgdbadapter.h
+++ b/src/plugins/debugger/gdb/tcftrkgdbadapter.h
@@ -108,6 +108,8 @@ private:
     void interruptInferior();
     void shutdownInferior();
     void shutdownAdapter();
+    void sendRunControlTerminateCommand();
+    void handleRunControlTerminate(const tcftrk::TcfTrkCommandResult &);
     void sendRegistersGetMCommand();
     void handleWriteRegister(const tcftrk::TcfTrkCommandResult &result);
     void reportRegisters();
diff --git a/src/plugins/debugger/gdb/trkgdbadapter.cpp b/src/plugins/debugger/gdb/trkgdbadapter.cpp
index c5790f2..b22457c 100644
--- a/src/plugins/debugger/gdb/trkgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/trkgdbadapter.cpp
@@ -557,10 +557,7 @@ void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
     }
 
     else if (cmd == "k" || cmd.startsWith("vKill")) {
-        // Kill inferior process
-        logMessage(msgGdbPacket(QLatin1String("kill")));
-        sendTrkMessage(0x41, TrkCB(handleDeleteProcess),
-            trkDeleteProcessMessage(), "Delete process");
+        trkKill();
     }
 
     else if (cmd.startsWith('m')) {
@@ -863,6 +860,14 @@ void TrkGdbAdapter::gdbSetCurrentThread(const QByteArray &cmd, const char *why)
     sendGdbServerMessage("OK", message);
 }
 
+void TrkGdbAdapter::trkKill()
+{
+    // Kill inferior process
+    logMessage(msgGdbPacket(QLatin1String("kill")));
+    sendTrkMessage(0x41, TrkCB(handleDeleteProcess),
+        trkDeleteProcessMessage(), "Delete process");
+}
+
 void TrkGdbAdapter::trkContinueAll(const char *why)
 {
     if (why)
@@ -1138,9 +1143,19 @@ void TrkGdbAdapter::handleDeleteProcess(const TrkResult &result)
 void TrkGdbAdapter::handleDeleteProcess2(const TrkResult &result)
 {
     Q_UNUSED(result);
-    logMessage("App TRK disconnected");
-    sendGdbServerAck();
-    sendGdbServerMessage("", "process killed");
+    QString msg = QString::fromLatin1("App TRK disconnected");
+
+    const bool emergencyShutdown = m_gdbProc.state() != QProcess::Running;
+    if (emergencyShutdown)
+        msg += QString::fromLatin1(" (emergency shutdown");
+    logMessage(msg);
+    if (emergencyShutdown) {
+        cleanup();
+        m_engine->notifyAdapterShutdownOk();
+    } else {
+        sendGdbServerAck();
+        sendGdbServerMessage("", "process killed");
+    }
 }
 
 void TrkGdbAdapter::handleReadRegisters(const TrkResult &result)
@@ -1930,8 +1945,16 @@ void TrkGdbAdapter::shutdownInferior()
 
 void TrkGdbAdapter::shutdownAdapter()
 {
-    cleanup();
-    m_engine->notifyAdapterShutdownOk();
+    if (m_gdbProc.state() == QProcess::Running) {
+        cleanup();
+        m_engine->notifyAdapterShutdownOk();
+    } else {
+        // Something is wrong, gdb crashed. Kill debuggee (see handleDeleteProcess2)
+        if (m_trkDevice->isOpen()) {
+            logMessage("Emergency shutdown of TRK", LogError);
+            trkKill();
+        }
+    }
 }
 
 void TrkGdbAdapter::trkReloadRegisters()
diff --git a/src/plugins/debugger/gdb/trkgdbadapter.h b/src/plugins/debugger/gdb/trkgdbadapter.h
index 93fadcc..02c5495 100644
--- a/src/plugins/debugger/gdb/trkgdbadapter.h
+++ b/src/plugins/debugger/gdb/trkgdbadapter.h
@@ -135,6 +135,7 @@ private:
     Q_SLOT void handleTrkResult(const trk::TrkResult &data);
     Q_SLOT void handleTrkError(const QString &msg);
     void trkContinueAll(const char *why);
+    void trkKill();
     void handleTrkContinueNext(const TrkResult &result);
     void trkContinueNext(int threadIndex);
 
