diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 904345b0e337c5bc57c834d4dfe190aeae5e42e1..babdbfc7432dd1c0f5ab53c87afc437d18ec0866 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -2721,34 +2721,12 @@ bool DebuggerPlugin::isRegisterViewVisible() const
     return d->m_registerDock->toggleViewAction()->isChecked();
 }
 
-
-//////////////////////////////////////////////////////////////////////
-//
-// Testing
-//
-//////////////////////////////////////////////////////////////////////
-
-/*
-void DebuggerPlugin::runTest(const QString &fileName)
+bool DebuggerPlugin::coreAboutToClose()
 {
-    DebuggerStartParameters sp;
-    sp.executable = fileName;
-    sp.processArgs = QStringList() << "--run-debuggee";
-    sp.workingDirectory.clear();
-    startDebugger(m_debuggerRunControlFactory->create(sp));
-}
-*/
-
-bool DebuggerListener::coreAboutToClose()
-{
-    DebuggerPlugin *plugin = DebuggerPlugin::instance();
-    if (!plugin)
-        return true;
-
     // FIXME: Iterate over all running debuggers.
     // Ask to terminate the session.
     bool cleanTermination = false;
-    switch (plugin->state()) {
+    switch (state()) {
     case DebuggerNotReady:
     case DebuggerFinished:
     case InferiorUnrunnable:
@@ -2784,7 +2762,7 @@ bool DebuggerListener::coreAboutToClose()
            "Terminating the session in the current"
            " state (%1) can leave the target in an inconsistent state."
            " Would you still like to terminate it?")
-        .arg(_(DebuggerEngine::stateName(plugin->state())));
+        .arg(_(DebuggerEngine::stateName(state())));
 
     const QString title
             = QCoreApplication::translate("Debugger::Internal::DebuggerListener",
@@ -2796,11 +2774,34 @@ bool DebuggerListener::coreAboutToClose()
     if (answer != QMessageBox::Yes)
         return false;
 
-    plugin->d->exitDebugger();
+    d->exitDebugger();
     QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
     return true;
 }
 
+//////////////////////////////////////////////////////////////////////
+//
+// Testing
+//
+//////////////////////////////////////////////////////////////////////
+
+/*
+void DebuggerPlugin::runTest(const QString &fileName)
+{
+    DebuggerStartParameters sp;
+    sp.executable = fileName;
+    sp.processArgs = QStringList() << "--run-debuggee";
+    sp.workingDirectory.clear();
+    startDebugger(m_debuggerRunControlFactory->create(sp));
+}
+*/
+
+bool DebuggerListener::coreAboutToClose()
+{
+    DebuggerPlugin *plugin = DebuggerPlugin::instance();
+    return plugin && plugin->coreAboutToClose();
+}
+
 } // namespace Debugger
 
 #include "debuggerplugin.moc"
diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h
index 2cb55de74d5140e5d654ae57584fffdd5ca2c02b..750e293e1c0cf27aeec1cfe9f41d40661a53a7e1 100644
--- a/src/plugins/debugger/debuggerplugin.h
+++ b/src/plugins/debugger/debuggerplugin.h
@@ -73,6 +73,7 @@ public:
     QVariant sessionValue(const QString &name);
     void setSessionValue(const QString &name, const QVariant &value);
     void setConfigValue(const QString &name, const QVariant &value);
+    bool coreAboutToClose();
 
     void resetLocation();
     void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);