From 5adb6559e25a075c41a7ab32cc168252c79e4f0a Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Wed, 23 Jun 2010 11:55:35 +0200
Subject: [PATCH] debugger: attempt to fix symbian output connections

---
 src/plugins/debugger/debuggerplugin.cpp       |  8 ++--
 src/plugins/debugger/debuggerplugin.h         |  3 +-
 src/plugins/debugger/debuggerrunner.cpp       |  4 +-
 src/plugins/debugger/debuggerrunner.h         |  3 +-
 .../qt-maemo/maemoruncontrol.cpp              | 14 +++---
 .../qt-s60/s60devicerunconfiguration.cpp      | 48 +++++++++----------
 .../qt-s60/s60devicerunconfiguration.h        |  2 +
 7 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 8e41cfad7f9..dcdb33c6059 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -843,7 +843,7 @@ public slots:
     QVariant configValue(const QString &name) const
         { return settings()->value(name); }
 
-    ProjectExplorer::RunControl *createDebugger(const DebuggerStartParameters &sp);
+    DebuggerRunControl *createDebugger(const DebuggerStartParameters &sp);
     void startDebugger(ProjectExplorer::RunControl *runControl);
 
     void dumpLog();
@@ -1914,7 +1914,7 @@ void DebuggerPluginPrivate::showToolTip(ITextEditor *editor, const QPoint &point
     notifyCurrentEngine(RequestToolTipByExpressionRole, list);
 }
 
-ProjectExplorer::RunControl *
+DebuggerRunControl *
 DebuggerPluginPrivate::createDebugger(const DebuggerStartParameters &sp)
 {
     return m_debuggerRunControlFactory->create(sp);
@@ -1922,8 +1922,8 @@ DebuggerPluginPrivate::createDebugger(const DebuggerStartParameters &sp)
 
 void DebuggerPluginPrivate::startDebugger(ProjectExplorer::RunControl *rc)
 {
+    QTC_ASSERT(rc, return);
     DebuggerRunControl *runControl = qobject_cast<DebuggerRunControl *>(rc);
-    qDebug() << "START DEBUGGER: " << runControl << rc;
     QTC_ASSERT(runControl, return);
     activateDebugMode();
     connectEngine(runControl->engine());
@@ -2576,7 +2576,7 @@ QWidget *DebuggerPlugin::mainWindow() const
     return d->m_uiSwitcher->mainWindow();
 }
 
-ProjectExplorer::RunControl *
+DebuggerRunControl *
 DebuggerPlugin::createDebugger(const DebuggerStartParameters &sp)
 {
     return instance()->d->createDebugger(sp);
diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h
index 1a502459736..61e87d7ebbe 100644
--- a/src/plugins/debugger/debuggerplugin.h
+++ b/src/plugins/debugger/debuggerplugin.h
@@ -83,8 +83,7 @@ public:
     void readSettings();
     void writeSettings() const;
 
-    static ProjectExplorer::RunControl *createDebugger
-        (const DebuggerStartParameters &sp);
+    static DebuggerRunControl *createDebugger(const DebuggerStartParameters &sp);
     static void startDebugger(ProjectExplorer::RunControl *runControl);
 
     QMessageBox *showMessageBox(int icon, const QString &title,
diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp
index 61afe22be23..9c38c145008 100644
--- a/src/plugins/debugger/debuggerrunner.cpp
+++ b/src/plugins/debugger/debuggerrunner.cpp
@@ -171,7 +171,7 @@ RunControl *DebuggerRunControlFactory::create
     return create(sp, runConfiguration);
 }
 
-RunControl *DebuggerRunControlFactory::create(const DebuggerStartParameters &sp,
+DebuggerRunControl *DebuggerRunControlFactory::create(const DebuggerStartParameters &sp,
     RunConfiguration *runConfiguration)
 {
     DebuggerRunControl *runControl = new DebuggerRunControl(runConfiguration);
@@ -369,7 +369,7 @@ void DebuggerRunControl::createEngine(const DebuggerStartParameters &sp)
             break;
         default: {
             // Could not find anything suitable.
-            emit debuggingFinished();
+            debuggingFinished();
             // Create Message box with possibility to go to settings
             const QString msg = tr("Cannot debug '%1' (tool chain: '%2'): %3")
                 .arg(sp.executable, toolChainName(sp.toolChainType), m_errorMessage);
diff --git a/src/plugins/debugger/debuggerrunner.h b/src/plugins/debugger/debuggerrunner.h
index 99938b09147..cd32082a026 100644
--- a/src/plugins/debugger/debuggerrunner.h
+++ b/src/plugins/debugger/debuggerrunner.h
@@ -42,6 +42,7 @@ class Environment;
 
 namespace Debugger {
 
+class DebuggerRunControl;
 class DebuggerStartParameters;
 
 namespace Internal {
@@ -69,7 +70,7 @@ public:
 
     // This is used by the "Non-Standard" scenarios, e.g. Attach to Core.
     // FIXME: What to do in case of a 0 runConfiguration?
-    ProjectExplorer::RunControl *create(const DebuggerStartParameters &sp,
+    DebuggerRunControl *create(const DebuggerStartParameters &sp,
         ProjectExplorer::RunConfiguration *runConfiguration = 0);
 
 private:
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp
index 921efa52d93..93e059d02c5 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp
@@ -64,6 +64,7 @@ namespace Internal {
 
 using ProjectExplorer::RunConfiguration;
 using ProjectExplorer::ToolChain;
+using namespace Debugger;
 
 AbstractMaemoRunControl::AbstractMaemoRunControl(RunConfiguration *rc, QString mode)
     : RunControl(rc, mode)
@@ -383,17 +384,17 @@ void MaemoRunControl::handleRemoteOutput(const QString &output)
 MaemoDebugRunControl::MaemoDebugRunControl(RunConfiguration *runConfiguration)
     : AbstractMaemoRunControl(runConfiguration, ProjectExplorer::Constants::DEBUGMODE)
     , m_debuggerRunControl(0)
-    , m_startParams(new Debugger::DebuggerStartParameters)
+    , m_startParams(new DebuggerStartParameters)
 {
 #ifdef USE_GDBSERVER
-    m_startParams->startMode = Debugger::AttachToRemote;
+    m_startParams->startMode = AttachToRemote;
     m_startParams->executable = executableOnHost();
     m_startParams->debuggerCommand = m_runConfig->gdbCmd();
     m_startParams->remoteChannel
         = m_devConfig.server.host % QLatin1Char(':') % gdbServerPort();
     m_startParams->remoteArchitecture = QLatin1String("arm");
 #else
-    m_startParams->startMode = Debugger::StartRemoteGdb;
+    m_startParams->startMode = StartRemoteGdb;
     m_startParams->executable = executableFilePathOnTarget();
     m_startParams->debuggerCommand = QLatin1String("/usr/bin/gdb");
     m_startParams->sshserver = m_devConfig.server;
@@ -405,8 +406,7 @@ MaemoDebugRunControl::MaemoDebugRunControl(RunConfiguration *runConfiguration)
     m_startParams->remoteDumperLib = remoteDir().toUtf8() + '/'
         + QFileInfo(m_runConfig->dumperLib()).fileName().toUtf8();
 
-    m_debuggerRunControl = qobject_cast<Debugger::DebuggerRunControl *>
-        (Debugger::DebuggerPlugin::createDebugger(*m_startParams.data()));
+    m_debuggerRunControl = DebuggerPlugin::createDebugger(*m_startParams.data());
     connect(m_debuggerRunControl, SIGNAL(finished()), this,
         SLOT(debuggingFinished()), Qt::QueuedConnection);
 }
@@ -453,7 +453,7 @@ void MaemoDebugRunControl::handleRemoteOutput(const QString &output)
 
 void MaemoDebugRunControl::startDebugging()
 {
-    Debugger::DebuggerPlugin::startDebugger(m_debuggerRunControl);
+    DebuggerPlugin::startDebugger(m_debuggerRunControl);
 }
 
 void MaemoDebugRunControl::stopInternal()
@@ -464,7 +464,7 @@ void MaemoDebugRunControl::stopInternal()
 bool MaemoDebugRunControl::isRunning() const
 {
     return AbstractMaemoRunControl::isRunning()
-        || m_debuggerRunControl->state() != Debugger::DebuggerNotReady;
+        || m_debuggerRunControl->state() != DebuggerNotReady;
 }
 
 void MaemoDebugRunControl::debuggingFinished()
diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
index b4d377a123f..2bd0d8d2d8b 100644
--- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
+++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
@@ -886,20 +886,13 @@ void S60DeviceRunControl::printRunFailNotice(const QString &errorMessage) {
 
 // ======== S60DeviceDebugRunControl
 
-S60DeviceDebugRunControl::S60DeviceDebugRunControl(S60DeviceRunConfiguration *runConfiguration, QString mode) :
-    S60DeviceRunControlBase(runConfiguration, mode),
-    m_startParams(new Debugger::DebuggerStartParameters)
+S60DeviceDebugRunControl::S60DeviceDebugRunControl(S60DeviceRunConfiguration *rc, QString mode) :
+    S60DeviceRunControlBase(rc, mode),
+    m_startParams(new Debugger::DebuggerStartParameters),
+    m_debuggerRunControl(0)
 {
     setReleaseDeviceAfterLauncherFinish(true); // Debugger controls device after install
-    Debugger::DebuggerPlugin *dm = Debugger::DebuggerPlugin::instance();
-    S60DeviceRunConfiguration *rc = qobject_cast<S60DeviceRunConfiguration *>(runConfiguration);
-    QTC_ASSERT(dm && rc, return);
-
-    connect(dm, SIGNAL(debuggingFinished()),
-            this, SLOT(debuggingFinished()), Qt::QueuedConnection);
-    connect(dm, SIGNAL(applicationOutputAvailable(QString, bool)),
-            this, SLOT(printApplicationOutput(QString, bool)),
-            Qt::QueuedConnection);
+    QTC_ASSERT(rc, return);
 
     m_startParams->remoteChannel = rc->serialPortName();
     m_startParams->processArgs = rc->commandLineArguments();
@@ -913,19 +906,17 @@ S60DeviceDebugRunControl::S60DeviceDebugRunControl(S60DeviceRunConfiguration *ru
     }
 }
 
-void S60DeviceDebugRunControl::stop()
+S60DeviceDebugRunControl::~S60DeviceDebugRunControl()
 {
-    S60DeviceRunControlBase::stop();
-    Debugger::DebuggerPlugin *dm = Debugger::DebuggerPlugin::instance();
-    QTC_ASSERT(dm, return)
-    // FIXME: ABC: that should use the RunControl present in
-    // handleLauncherFinished
-    if (dm->state() == Debugger::DebuggerNotReady)
-        dm->exitDebugger();
+    // FIXME: Needed? m_debuggerRunControl->deleteLater(); 
 }
 
-S60DeviceDebugRunControl::~S60DeviceDebugRunControl()
+void S60DeviceDebugRunControl::stop()
 {
+    S60DeviceRunControlBase::stop();
+    QTC_ASSERT(m_debuggerRunControl, return)
+    if (m_debuggerRunControl->state() == Debugger::DebuggerNotReady)
+        m_debuggerRunControl->stop();
 }
 
 void S60DeviceDebugRunControl::initLauncher(const QString &executable, trk::Launcher *launcher)
@@ -949,9 +940,18 @@ void S60DeviceDebugRunControl::handleLauncherFinished()
 {
     using namespace Debugger;
     emit appendMessage(this, tr("Launching debugger..."), false);
-    ProjectExplorer::RunControl *rc
-        = DebuggerPlugin::createDebugger(*m_startParams.data());
-    DebuggerPlugin::startDebugger(rc);
+    QTC_ASSERT(m_debuggerRunControl == 0, /* Should happen only once. */);
+    m_debuggerRunControl = DebuggerPlugin::createDebugger(*m_startParams.data());
+    connect(m_debuggerRunControl,
+            SIGNAL(finished()),
+            SLOT(debuggingFinished()),
+            Qt::QueuedConnection);
+    connect(m_debuggerRunControl,
+            SIGNAL(addToOutputWindowInline(ProjectExplorer::RunControl,QString,bool)),
+            SIGNAL(addToOutputWindowInline(ProjectExplorer::RunControl,QString,bool)),
+            Qt::QueuedConnection);
+
+    DebuggerPlugin::startDebugger(m_debuggerRunControl);
 }
 
 void S60DeviceDebugRunControl::debuggingFinished()
diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
index f37e67e99c9..a1cb5d45906 100644
--- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
+++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
@@ -45,6 +45,7 @@ QT_END_NAMESPACE
 
 namespace Debugger {
 class DebuggerStartParameters;
+class DebuggerRunControl;
 }
 
 namespace SymbianUtils {
@@ -245,6 +246,7 @@ private slots:
     void debuggingFinished();
 private:
     QSharedPointer<Debugger::DebuggerStartParameters> m_startParams;
+    Debugger::DebuggerRunControl *m_debuggerRunControl;
     QString m_localExecutableFileName;
 };
 
-- 
GitLab