From 36e6a705052c005529eb8558736e1c9df6865355 Mon Sep 17 00:00:00 2001
From: El Mehdi Fekari <mfekari@rim.com>
Date: Fri, 18 Oct 2013 19:27:31 +0200
Subject: [PATCH] Debugger: Fix the way to register/add new debuggers

DebuggerItemManager::registerDebugger() should return the id
of the added debugger in order to use it when setting a kit's debugger
(addDebugger() creates and adds a copy of the passed
debugger object with a unique id).

The DebuggerKitInformation::setDebugger() method should set only already
existing and registered debuggers.

Task-number: QTCREATORBUG-10436

Change-Id: Icdcd1ed92aafe9eda44abf831aa9983dd6801980
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
---
 src/plugins/android/androidconfigurations.cpp |  3 ++-
 .../debugger/debuggerkitconfigwidget.cpp      | 24 +++++++++----------
 src/plugins/debugger/debuggerkitinformation.h |  6 ++---
 src/plugins/ios/iosconfigurations.cpp         |  3 ++-
 src/plugins/qnx/blackberryconfiguration.cpp   |  4 ++--
 5 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp
index 7538282690e..4b6df3fd5e1 100644
--- a/src/plugins/android/androidconfigurations.cpp
+++ b/src/plugins/android/androidconfigurations.cpp
@@ -867,7 +867,8 @@ void AndroidConfigurations::updateAutomaticKitList()
             debugger.setDisplayName(tr("Android Debugger for %1").arg(tc->displayName()));
             debugger.setAutoDetected(true);
             debugger.setAbi(tc->targetAbi());
-            Debugger::DebuggerKitInformation::setDebugger(newKit, debugger);
+            QVariant id = Debugger::DebuggerItemManager::registerDebugger(debugger);
+            Debugger::DebuggerKitInformation::setDebugger(newKit, id);
 
             AndroidGdbServerKitInformation::setGdbSever(newKit, tc->suggestedGdbServer());
             newKit->makeSticky();
diff --git a/src/plugins/debugger/debuggerkitconfigwidget.cpp b/src/plugins/debugger/debuggerkitconfigwidget.cpp
index ece61bb99e5..9d9f0b23a9a 100644
--- a/src/plugins/debugger/debuggerkitconfigwidget.cpp
+++ b/src/plugins/debugger/debuggerkitconfigwidget.cpp
@@ -345,16 +345,11 @@ QString DebuggerKitInformation::displayString(const Kit *k)
     return binary.isEmpty() ? tr("%1 <None>").arg(name) : tr("%1 using \"%2\"").arg(name, binary);
 }
 
-void DebuggerKitInformation::setDebugger(Kit *k, const DebuggerItem &item)
+void DebuggerKitInformation::setDebugger(Kit *k, const QVariant &id)
 {
     // Only register reasonably complete debuggers.
-    QTC_ASSERT(!item.id().isValid(), return);
-    QTC_ASSERT(!item.command().isEmpty(), return);
-    QTC_ASSERT(!item.displayName().isEmpty(), return);
-    QTC_ASSERT(item.engineType() != NoEngineType, return);
-    // Only set registered/existing debuggers
-    QTC_ASSERT(DebuggerItemManager::findByCommand(item.command()), return);
-    k->setValue(DebuggerKitInformation::id(), item.id());
+    QTC_ASSERT(DebuggerItemManager::findById(id), return);
+    k->setValue(DebuggerKitInformation::id(), id);
 }
 
 Core::Id DebuggerKitInformation::id()
@@ -651,11 +646,12 @@ void DebuggerItemManager::saveDebuggers()
     // Do not save default debuggers as they are set by the SDK.
 }
 
-void DebuggerItemManager::registerDebugger(const DebuggerItem &item)
+QVariant DebuggerItemManager::registerDebugger(const DebuggerItem &item)
 {
     if (findByCommand(item.command()))
-        return;
-    addDebugger(item);
+        return item.id();
+
+    return addDebugger(item);
 }
 
 void DebuggerItemManager::deregisterDebugger(const DebuggerItem &item)
@@ -664,13 +660,17 @@ void DebuggerItemManager::deregisterDebugger(const DebuggerItem &item)
         removeDebugger(item.id());
 }
 
-void DebuggerItemManager::addDebugger(const DebuggerItem& item0)
+QVariant DebuggerItemManager::addDebugger(const DebuggerItem& item0)
 {
     DebuggerItem item = item0;
+    QTC_ASSERT(!item.command().isEmpty(), return QVariant());
+    QTC_ASSERT(!item.displayName().isEmpty(), return QVariant());
+    QTC_ASSERT(item.engineType() != NoEngineType, return QVariant());
     if (item.id().isNull())
         item.setId(QUuid::createUuid().toString());
     m_debuggers.append(item);
     m_model->addDebugger(item);
+    return item.id();
 }
 
 void DebuggerItemManager::removeDebugger(const QVariant &id)
diff --git a/src/plugins/debugger/debuggerkitinformation.h b/src/plugins/debugger/debuggerkitinformation.h
index de965ca9858..dfdf6350a4e 100644
--- a/src/plugins/debugger/debuggerkitinformation.h
+++ b/src/plugins/debugger/debuggerkitinformation.h
@@ -110,7 +110,7 @@ public:
     static QList<DebuggerItem> debuggers();
     static Debugger::Internal::DebuggerItemModel *model();
 
-    static void registerDebugger(const DebuggerItem &item);
+    static QVariant registerDebugger(const DebuggerItem &item);
     static void deregisterDebugger(const DebuggerItem &item);
 
     static const DebuggerItem *findByCommand(const Utils::FileName &command);
@@ -121,7 +121,7 @@ public:
     static void setItemData(const QVariant &id, const QString& displayName, const Utils::FileName &fileName);
 
     static void removeDebugger(const QVariant &id);
-    static void addDebugger(const DebuggerItem &item);
+    static QVariant addDebugger(const DebuggerItem &item);
 
 public slots:
     void saveDebuggers();
@@ -164,7 +164,7 @@ public:
 
     ItemList toUserOutput(const ProjectExplorer::Kit *k) const;
 
-    static void setDebugger(ProjectExplorer::Kit *k, const DebuggerItem &item);
+    static void setDebugger(ProjectExplorer::Kit *k, const QVariant &id);
 
     static Core::Id id();
     static Utils::FileName debuggerCommand(const ProjectExplorer::Kit *k);
diff --git a/src/plugins/ios/iosconfigurations.cpp b/src/plugins/ios/iosconfigurations.cpp
index 9dac4889b3d..ebfca0293fc 100644
--- a/src/plugins/ios/iosconfigurations.cpp
+++ b/src/plugins/ios/iosconfigurations.cpp
@@ -316,7 +316,8 @@ void IosConfigurations::updateAutomaticKitList()
                 debugger.setDisplayName(tr("IOS Debugger"));
                 debugger.setAutoDetected(true);
                 debugger.setAbi(pToolchain->targetAbi());
-                Debugger::DebuggerKitInformation::setDebugger(newKit, debugger);
+                QVariant id = Debugger::DebuggerItemManager::registerDebugger(debugger);
+                Debugger::DebuggerKitInformation::setDebugger(newKit, id);
 
                 SysRootKitInformation::setSysRoot(newKit, p.sdkPath);
                 // QmakeProjectManager::QmakeKitInformation::setMkspec(newKit,
diff --git a/src/plugins/qnx/blackberryconfiguration.cpp b/src/plugins/qnx/blackberryconfiguration.cpp
index 81f5ed0469d..78b01a30d88 100644
--- a/src/plugins/qnx/blackberryconfiguration.cpp
+++ b/src/plugins/qnx/blackberryconfiguration.cpp
@@ -237,8 +237,8 @@ Kit *BlackBerryConfiguration::createKit(QnxAbstractQtVersion *version, ToolChain
             version->qtVersionString(), version->platformDisplayName(),
             version->archString(), m_targetName));
 
-    DebuggerItemManager::registerDebugger(debugger);
-    DebuggerKitInformation::setDebugger(kit, debugger);
+    QVariant id = DebuggerItemManager::registerDebugger(debugger);
+    DebuggerKitInformation::setDebugger(kit, id);
 
     if (isSimulator)
         QmakeProjectManager::QmakeKitInformation::setMkspec(
-- 
GitLab