diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 5a7b1b7..2d644b1 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -128,6 +128,7 @@
 #include <QtCore/QTimer>
 #include <QtCore/QVariant>
 #include <QtCore/QtPlugin>
+#include <QtCore/QScopedPointer>
 
 #include <QtGui/QAbstractItemView>
 #include <QtGui/QAction>
@@ -969,6 +970,7 @@ public slots:
 
     void executeDebuggerCommand();
     void scriptExpressionEntered(const QString &expression);
+    void coreShutdown();
 
 public:
     DebuggerState m_state;
@@ -978,7 +980,7 @@ public:
     DebuggerRunControlFactory *m_debuggerRunControlFactory;
 
     QString m_previousMode;
-    TextEditor::BaseTextMark *m_locationMark;
+    QScopedPointer<TextEditor::BaseTextMark> m_locationMark;
     Core::Context m_continuableContext;
     Core::Context m_interruptibleContext;
     Core::Context m_undisturbableContext;
@@ -1043,9 +1045,11 @@ public:
     DebuggerPlugin *m_plugin;
 
     SnapshotHandler *m_snapshotHandler;
+    bool m_shuttingDown;
 };
 
-DebuggerPluginPrivate::DebuggerPluginPrivate(DebuggerPlugin *plugin)
+DebuggerPluginPrivate::DebuggerPluginPrivate(DebuggerPlugin *plugin) :
+    m_shuttingDown(false)
 {
     m_plugin = plugin;
 
@@ -1078,7 +1082,6 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(DebuggerPlugin *plugin)
 
     m_sessionEngine = 0;
     m_debugMode = 0;
-    m_locationMark = 0;
 
     m_continuableContext = Core::Context(0);
     m_interruptibleContext = Core::Context(0);
@@ -1106,6 +1109,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, QString *er
     // FIXME: Move part of this to extensionsInitialized()?
     ICore *core = ICore::instance();
     QTC_ASSERT(core, return false);
+    connect(core, SIGNAL(coreAboutToClose()), this, SLOT(coreShutdown()));
 
     Core::ActionManager *am = core->actionManager();
     QTC_ASSERT(am, return false);
@@ -1609,8 +1613,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, QString *er
         m_plugin->addAutoReleasedObject(op);
     m_plugin->addAutoReleasedObject(new DebuggingHelperOptionPage);
 
-    m_locationMark = 0;
-
     //setSimpleDockWidgetArrangement(Lang_Cpp);
 
     connect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
@@ -2409,12 +2411,14 @@ void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
 
 void DebuggerPluginPrivate::resetLocation()
 {
-    delete m_locationMark;
-    m_locationMark = 0;
+    m_locationMark.reset();
 }
 
 void DebuggerPluginPrivate::gotoLocation(const QString &file, int line, bool setMarker)
 {
+    // CDB might hit on breakpoints while shutting down.
+    QTC_ASSERT(!m_shuttingDown, return; )
+
     bool newEditor = false;
     ITextEditor *editor =
         BaseTextEditor::openEditorAt(file, line, 0, QString(),
@@ -2423,10 +2427,8 @@ void DebuggerPluginPrivate::gotoLocation(const QString &file, int line, bool set
         return;
     if (newEditor)
         editor->setProperty("OpenedByDebugger", true);
-    if (setMarker) {
-        resetLocation();
-        m_locationMark = new LocationMark(file, line);
-    }
+    if (setMarker)
+        m_locationMark.reset(new LocationMark(file, line));
 }
 
 void DebuggerPluginPrivate::onModeChanged(IMode *mode)
@@ -2550,6 +2552,10 @@ void DebuggerPluginPrivate::openMemoryEditor()
         QModelIndex(), dialog.address(), RequestShowMemoryRole);
 }
 
+void DebuggerPluginPrivate::coreShutdown()
+{
+    m_shuttingDown = true;
+}
 
 ///////////////////////////////////////////////////////////////////////
 //
@@ -2583,9 +2589,6 @@ DebuggerPlugin::~DebuggerPlugin()
     delete d->m_debugMode;
     d->m_debugMode = 0;
 
-    delete d->m_locationMark;
-    d->m_locationMark = 0;
-
     removeObject(d->m_uiSwitcher);
     delete d->m_uiSwitcher;
     d->m_uiSwitcher = 0;
@@ -2633,33 +2636,17 @@ QVariant DebuggerPlugin::configValue(const QString &name) const
 void DebuggerPlugin::resetLocation()
 {
     d->resetLocation();
-    //qDebug() << "RESET_LOCATION: current:"  << currentTextEditor();
-    //qDebug() << "RESET_LOCATION: locations:"  << m_locationMark;
-    //qDebug() << "RESET_LOCATION: stored:"  << m_locationMark->editor();
-    delete d->m_locationMark;
-    d->m_locationMark = 0;
 }
 
 void DebuggerPlugin::gotoLocation(const QString &file, int line, bool setMarker)
 {
-    bool newEditor = false;
-    ITextEditor *editor =
-        BaseTextEditor::openEditorAt(file, line, 0, QString(),
-            EditorManager::IgnoreNavigationHistory,
-            &newEditor);
-    if (!editor)
-        return;
-    if (newEditor)
-        editor->setProperty("OpenedByDebugger", true);
-    if (setMarker) {
-        resetLocation();
-        d->m_locationMark = new LocationMark(file, line);
-    }
+    d->gotoLocation(file, line, setMarker);
 }
 
 void DebuggerPlugin::openTextEditor(const QString &titlePattern0,
     const QString &contents)
 {
+    QTC_ASSERT(!d->m_shuttingDown, return; )
     QString titlePattern = titlePattern0;
     EditorManager *editorManager = EditorManager::instance();
     QTC_ASSERT(editorManager, return);
