From 038d943f9aa3b0fcc6099ba9bc692b9a7fc97a3f Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 2 Jul 2010 12:20:26 +0200
Subject: [PATCH] debugger: fix shutdown by pressing "[x]" in the output pane

---
 src/plugins/debugger/debuggerengine.cpp |  2 +-
 src/plugins/debugger/debuggerengine.h   |  2 +-
 src/plugins/debugger/debuggerrunner.cpp |  2 +-
 src/plugins/debugger/gdb/gdbengine.cpp  | 17 +++++++++++++++--
 src/plugins/debugger/gdb/gdbengine.h    |  1 +
 5 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp
index 8e286a8ac62..c8379eeb048 100644
--- a/src/plugins/debugger/debuggerengine.cpp
+++ b/src/plugins/debugger/debuggerengine.cpp
@@ -186,7 +186,7 @@ private:
 
 bool CommandHandler::setData(const QModelIndex &, const QVariant &value, int role)
 {
-    QTC_ASSERT(m_engine, return false);
+    QTC_ASSERT(m_engine, qDebug() << value << role; return false);
     m_engine->handleCommand(role, value);
     return true;
 }
diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h
index 51dbfe36246..3249ece97a4 100644
--- a/src/plugins/debugger/debuggerengine.h
+++ b/src/plugins/debugger/debuggerengine.h
@@ -251,7 +251,7 @@ public slots:
     void startSuccessful();
     void startFailed();
     void raiseApplication();
-    void quitDebugger() { exitDebugger(); }
+    virtual void quitDebugger() { exitDebugger(); } // called by DebuggerRunControl
 
 protected:
     void setState(DebuggerState state, bool forced = false);
diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp
index ae212ff8b44..68c3db55c95 100644
--- a/src/plugins/debugger/debuggerrunner.cpp
+++ b/src/plugins/debugger/debuggerrunner.cpp
@@ -510,7 +510,7 @@ void DebuggerRunControl::stop()
 {
     m_running = false;
     QTC_ASSERT(m_engine, return);
-    m_engine->exitDebugger();
+    m_engine->quitDebugger();
 }
 
 void DebuggerRunControl::debuggingFinished()
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 4bd65d1af10..47dffc80f46 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -1620,7 +1620,8 @@ QString GdbEngine::cleanupFullName(const QString &fileName)
 
 void GdbEngine::shutdown()
 {
-    showMessage(_("INITIATE GDBENGINE SHUTDOWN"));
+    showMessage(_("INITIATE GDBENGINE SHUTDOWN IN STATE %1, PROC: %2")
+        .arg(state()).arg(gdbProc()->state()));
     if (m_progress) {
         m_progress->setProgressValue(90);
         m_progress->reportCanceled();
@@ -1726,7 +1727,19 @@ void GdbEngine::exitDebugger()
 {
     disconnectDebuggingHelperActions();
     shutdown();
-    //gdbProc()->kill();
+}
+
+void GdbEngine::quitDebugger()
+{
+    // FIXME: The problem here is that the "kill" send in the shutdown()
+    // procedure might not receive a response anymore.  So we need a way
+    // to force it down. On the other hand, there could be an answer,
+    // and regular the inferior shutdown procedure could take a while.
+    // And the RunControl::stop() is called synchroneously.
+    disconnectDebuggingHelperActions();
+    shutdown();
+    initializeVariables();
+    setState(DebuggerNotReady);
 }
 
 int GdbEngine::currentFrame() const
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index 43e847815d5..9d22e979406 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -108,6 +108,7 @@ private: ////////// General Interface //////////
     virtual void startDebugger();
     virtual unsigned debuggerCapabilities() const;
     virtual void exitDebugger();
+    virtual void quitDebugger();
     virtual void detachDebugger();
     virtual void shutdown();
 
-- 
GitLab