OSDN Git Service

Debugger: Handle core shutdown, prompt user to terminate debugging.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 26 Oct 2009 17:05:11 +0000 (18:05 +0100)
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 26 Oct 2009 17:05:22 +0000 (18:05 +0100)
Add a corelistener and trigger on shutdown. Notify about critical
states.
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
src/plugins/debugger/debuggermanager.cpp
src/plugins/debugger/debuggermanager.h
src/plugins/debugger/debuggerplugin.cpp

index 51f7d21..a90cb2b 100644 (file)
@@ -180,7 +180,7 @@ using namespace Debugger::Internal;
 
 static const QString tooltipIName = "tooltip";
 
-static const char *stateName(int s)
+const char *DebuggerManager::stateName(int s)
 {
     #define SN(x) case x: return #x;
     switch (s) {
@@ -1766,7 +1766,7 @@ void DebuggerManager::ensureLogVisible()
 
 QDebug operator<<(QDebug d, DebuggerState state)
 {
-    return d << stateName(state) << '(' << int(state) << ')';
+    return d << DebuggerManager::stateName(state) << '(' << int(state) << ')';
 }
 
 //////////////////////////////////////////////////////////////////////
index b2c5bb9..5e78170 100644 (file)
@@ -241,6 +241,8 @@ public slots:
     void showStatusMessage(const QString &msg, int timeout = -1); // -1 forever
     void clearCppCodeModelSnapshot();
 
+    static const char *stateName(int s);
+
 public slots: // FIXME
     void showDebuggerOutput(const QString &msg)
         { showDebuggerOutput(LogDebug, msg); }
index c0d60ba..9dca44c 100644 (file)
@@ -47,6 +47,7 @@
 #include <coreplugin/editormanager/editormanager.h>
 #include <coreplugin/findplaceholder.h>
 #include <coreplugin/icore.h>
+#include <coreplugin/icorelistener.h>
 #include <coreplugin/messagemanager.h>
 #include <coreplugin/minisplitter.h>
 #include <coreplugin/modemanager.h>
@@ -204,6 +205,60 @@ DebugMode::~DebugMode()
     EditorManager::instance()->setParent(0);
 }
 
+///////////////////////////////////////////////////////////////////////
+//
+// DebuggerListener: Close the debugging session if running.
+//
+///////////////////////////////////////////////////////////////////////
+
+class DebuggerListener : public Core::ICoreListener {
+    Q_OBJECT
+public:
+    explicit DebuggerListener(QObject *parent = 0);
+    virtual bool coreAboutToClose();
+};
+
+DebuggerListener::DebuggerListener(QObject *parent) :
+    Core::ICoreListener(parent)
+{
+}
+
+bool DebuggerListener::coreAboutToClose()
+{
+    DebuggerManager *mgr = DebuggerManager::instance();
+    if (!mgr)
+        return true;
+    // Ask to terminate the session.
+    const QString title = tr("Close Debugging Session");
+    bool cleanTermination = false;
+    switch (mgr->state()) {
+    case DebuggerNotReady:
+        return true;
+    case AdapterStarted:     // Most importantly, terminating a running
+    case AdapterStartFailed: // debuggee can cause problems.
+    case InferiorUnrunnable:
+    case InferiorStartFailed:
+    case InferiorStopped:
+    case InferiorShutDown:
+        cleanTermination = true;
+        break;
+    default:
+        break;
+    }
+    const QString question = cleanTermination ?
+        tr("A debugging session is still in progress. Would you like to terminate it?") :
+        tr("A debugging session is still in progress. Terminating the session in the current"
+           " state (%1) can leave the target in an inconsistent state."
+           " Would you like to terminate it?")
+        .arg(QLatin1String(DebuggerManager::stateName(mgr->state())));
+    QMessageBox::StandardButton answer = QMessageBox::question(0, title, question,
+                                         QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+    if (answer == QMessageBox::No)
+        return false;
+    mgr->exitDebugger();
+    return true;
+}
+
 } // namespace Internal
 } // namespace Debugger
 
@@ -753,7 +808,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
     addAutoReleasedObject(new DebuggingHelperOptionPage);
     foreach (Core::IOptionsPage* op, engineOptionPages)
         addAutoReleasedObject(op);
-
+    addAutoReleasedObject(new DebuggerListener);
     m_locationMark = 0;