From 7713fc514be691026f3fcdccb1ae26a4811d62ff Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Date: Wed, 28 Oct 2009 22:08:58 +0100
Subject: [PATCH] do not post source & module list query commands too early

if the respective view is enabled, the manager will request the
initial update in some unholy state, probably AdapterStarting -
when gdb isn't up yet.
---
 src/plugins/debugger/gdb/gdbengine.cpp | 27 +++++++++++++++++++-------
 src/plugins/debugger/gdb/gdbengine.h   |  2 ++
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index ed88dcd5764..790f080722e 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -981,7 +981,7 @@ void GdbEngine::handleAqcuiredInferior()
     #endif
 
     // It's nicer to see a bit of the world we live in.
-    reloadModules();
+    reloadModulesInternal();
     attemptBreakpointSynchronization();
 }
 #endif
@@ -1145,9 +1145,9 @@ void GdbEngine::handleStop1(const GdbResponse &response)
 void GdbEngine::handleStop1(const GdbMi &data)
 {
     if (m_modulesListOutdated)
-        reloadModules(); // This is for display only
+        reloadModulesInternal(); // This is for display only
     if (m_sourcesListOutdated)
-        reloadSourceFiles(); // This needs to be done before fullName() may need it
+        reloadSourceFilesInternal(); // This needs to be done before fullName() may need it
 
     QByteArray reason = data.findChild("reason").data();
     if (reason == "breakpoint-hit") {
@@ -1981,7 +1981,7 @@ void GdbEngine::attemptBreakpointSynchronization()
     // For best results, we rely on an up-to-date fullname mapping.
     // The listing completion will retrigger us, so no futher action is needed.
     if (m_sourcesListOutdated) {
-        reloadSourceFiles();
+        reloadSourceFilesInternal();
         return;
     } else if (m_sourcesListUpdating) {
         return;
@@ -2054,13 +2054,13 @@ void GdbEngine::loadSymbols(const QString &moduleName)
 {
     // FIXME: gdb does not understand quoted names here (tested with 6.8)
     postCommand(_("sharedlibrary ") + dotEscape(moduleName));
-    reloadModules();
+    reloadModulesInternal();
 }
 
 void GdbEngine::loadAllSymbols()
 {
     postCommand(_("sharedlibrary .*"));
-    reloadModules();
+    reloadModulesInternal();
 }
 
 QList<Symbol> GdbEngine::moduleSymbols(const QString &moduleName)
@@ -2098,9 +2098,15 @@ QList<Symbol> GdbEngine::moduleSymbols(const QString &moduleName)
 }
 
 void GdbEngine::reloadModules()
+{
+    if (state() == InferiorRunning || state() == InferiorStopped)
+        reloadModulesInternal();
+}
+
+void GdbEngine::reloadModulesInternal()
 {
     m_modulesListOutdated = false;
-    postCommand(_("info shared"), CB(handleModulesList));
+    postCommand(_("info shared"), NeedsStop, CB(handleModulesList));
 }
 
 void GdbEngine::handleModulesList(const GdbResponse &response)
@@ -2157,6 +2163,13 @@ void GdbEngine::handleModulesList(const GdbResponse &response)
 //////////////////////////////////////////////////////////////////////
 
 void GdbEngine::reloadSourceFiles()
+{
+    if ((state() == InferiorRunning || state() == InferiorStopped)
+        && !m_sourcesListUpdating)
+        reloadSourceFilesInternal();
+}
+
+void GdbEngine::reloadSourceFilesInternal()
 {
     m_sourcesListUpdating = true;
     m_sourcesListOutdated = false;
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index ac27201c6bf..c9e20eae299 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -322,6 +322,7 @@ private: ////////// View & Data Stuff //////////
     virtual void loadAllSymbols();
     virtual QList<Symbol> moduleSymbols(const QString &moduleName);
     virtual void reloadModules();
+    void reloadModulesInternal();
     void handleModulesList(const GdbResponse &response);
 
     bool m_modulesListOutdated;
@@ -350,6 +351,7 @@ private: ////////// View & Data Stuff //////////
     // Source file specific stuff
     //
     virtual void reloadSourceFiles();
+    void reloadSourceFilesInternal();
     void handleQuerySources(const GdbResponse &response);
 
     QString fullName(const QString &fileName);
-- 
GitLab