From c3bb0327537bfcf4b5d6a8cb673a6db70c63baa6 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Tue, 29 Sep 2009 13:49:35 +0200
Subject: [PATCH] Trk/S60: Wire debugger parameters.

Remove conditionals from toolchain enumeration, pass parameters to
TrkGdbAdapter, rename function in runconfig, derive symbol
file from local exe file.
---
 src/plugins/debugger/debuggermanager.cpp      |  7 ++++
 src/plugins/debugger/debuggermanager.h        |  1 +
 src/plugins/debugger/gdb/gdbengine.cpp        | 39 ++++++++++++++-----
 src/plugins/debugger/gdb/gdbengine.h          |  1 +
 src/plugins/debugger/gdb/trkgdbadapter.cpp    | 26 ++++++++++---
 src/plugins/debugger/gdb/trkgdbadapter.h      |  2 +
 .../projectexplorer/projectexplorer.pro       |  6 ---
 src/plugins/projectexplorer/toolchain.h       |  4 --
 .../qt-s60/s60devicerunconfiguration.cpp      | 20 ++++++++--
 .../qt-s60/s60devicerunconfiguration.h        |  2 +-
 10 files changed, 77 insertions(+), 31 deletions(-)

diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp
index 27524c49fea..23cecbd53ee 100644
--- a/src/plugins/debugger/debuggermanager.cpp
+++ b/src/plugins/debugger/debuggermanager.cpp
@@ -168,6 +168,7 @@ DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &p)
             << " attachPID=" << p.attachPID << " useTerminal=" << p.useTerminal
             << " remoteChannel=" << p.remoteChannel
             << " remoteArchitecture=" << p.remoteArchitecture
+            << " symbolFileName=" << p.symbolFileName
             << " serverStartScript=" << p.serverStartScript
             << " toolchain=" << p.toolChainType << '\n';
     return str;
@@ -859,6 +860,12 @@ static IDebuggerEngine *debuggerEngineForToolChain(ProjectExplorer::ToolChain::T
     case ProjectExplorer::ToolChain::WINCE:
         rc = winEngine;
         break;
+    case ProjectExplorer::ToolChain::WINSCW: // S60
+    case ProjectExplorer::ToolChain::GCCE:
+    case ProjectExplorer::ToolChain::RVCT_ARMV5:
+    case ProjectExplorer::ToolChain::RVCT_ARMV6:
+        rc = gdbEngine;
+        break;
     case ProjectExplorer::ToolChain::OTHER:
     case ProjectExplorer::ToolChain::UNKNOWN:
     case ProjectExplorer::ToolChain::INVALID:
diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h
index 77e36720971..e077cee67a1 100644
--- a/src/plugins/debugger/debuggermanager.h
+++ b/src/plugins/debugger/debuggermanager.h
@@ -110,6 +110,7 @@ public:
     // for remote debugging
     QString remoteChannel;
     QString remoteArchitecture;
+    QString symbolFileName;
     QString serverStartScript;
     int toolChainType;
 
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 783ac198652..9bdd670a860 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -61,6 +61,7 @@
 #include <utils/qtcassert.h>
 #include <utils/fancymainwindow.h>
 #include <texteditor/itexteditor.h>
+#include <projectexplorer/toolchain.h>
 #include <coreplugin/icore.h>
 
 #include <QtCore/QDebug>
@@ -1511,6 +1512,33 @@ int GdbEngine::currentFrame() const
     return manager()->stackHandler()->currentIndex();
 }
 
+AbstractGdbAdapter *GdbEngine::determineAdapter(const DebuggerStartParametersPtr &sp) const
+{
+    switch (sp->toolChainType) {
+    case ProjectExplorer::ToolChain::WINSCW: // S60
+    case ProjectExplorer::ToolChain::GCCE:
+    case ProjectExplorer::ToolChain::RVCT_ARMV5:
+    case ProjectExplorer::ToolChain::RVCT_ARMV6:
+        return m_trkAdapter;
+    default:
+        break;
+    }
+    // @todo: remove testing hack
+    if (sp->executable.endsWith(_(".sym")))
+        return m_trkAdapter;
+    switch (sp->startMode) {
+    case AttachCore:
+        return m_coreAdapter;
+    case StartRemote:
+        return m_remoteAdapter;
+    case AttachExternal:
+        return m_attachAdapter;
+    default:
+        break;
+    }
+    return m_plainAdapter;
+}
+
 void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp)
 {
     QTC_ASSERT(state() == EngineStarting, qDebug() << state());
@@ -1525,16 +1553,7 @@ void GdbEngine::startDebugger(const DebuggerStartParametersPtr &sp)
     if (m_gdbAdapter)
         disconnectAdapter();
 
-    if (sp->executable.endsWith(_(".sym")))
-        m_gdbAdapter = m_trkAdapter;
-    else if (sp->startMode == AttachCore)
-        m_gdbAdapter = m_coreAdapter;
-    else if (sp->startMode == StartRemote)
-        m_gdbAdapter = m_remoteAdapter;
-    else if (sp->startMode == AttachExternal)
-        m_gdbAdapter = m_attachAdapter;
-    else 
-        m_gdbAdapter = m_plainAdapter;
+    m_gdbAdapter = determineAdapter(sp);
 
     if (startModeAllowsDumpers())
         connectDebuggingHelperActions();
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index 29aa87845f2..3db2d91e1ad 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -395,6 +395,7 @@ private:
     void setLocals(const QList<GdbMi> &locals);
     void connectDebuggingHelperActions();
     void disconnectDebuggingHelperActions();
+    AbstractGdbAdapter *determineAdapter(const DebuggerStartParametersPtr &dp) const;
 
     bool startModeAllowsDumpers() const;
     QString parseDisassembler(const GdbMi &lines);
diff --git a/src/plugins/debugger/gdb/trkgdbadapter.cpp b/src/plugins/debugger/gdb/trkgdbadapter.cpp
index f6587be9289..737cd09fef2 100644
--- a/src/plugins/debugger/gdb/trkgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/trkgdbadapter.cpp
@@ -278,8 +278,7 @@ void TrkGdbAdapter::startInferiorEarly()
     appendByte(&ba, 0); // ?
     appendByte(&ba, 0); // ?
 
-    QByteArray file("C:\\sys\\bin\\filebrowseapp.exe");
-    appendString(&ba, file, TargetByteOrder);
+    appendString(&ba, m_remoteExecutable.toLatin1(), TargetByteOrder);
     sendTrkMessage(0x40, TrkCB(handleCreateProcess), ba); // Create Item
     //sendTrkMessage(TRK_WRITE_QUEUE_NOOP_CODE, TrkCB(startGdbServer));
 }
@@ -1400,6 +1399,17 @@ void TrkGdbAdapter::handleGdbStateChanged(QProcess::ProcessState newState)
 
 void TrkGdbAdapter::startAdapter()
 {
+    // Retrieve parameters
+    const DebuggerStartParameters &parameters = m_engine->startParameters();
+    setOverrideTrkDevice(parameters.remoteChannel);
+    m_remoteExecutable = parameters.executable;
+    m_symbolFile = parameters.symbolFileName;
+    // @todo: testing hack, remove!
+    if (m_remoteExecutable.endsWith(_(".sym"))) {
+        m_symbolFile = m_remoteExecutable;
+        m_remoteExecutable = QLatin1String("C:\\sys\\bin\\filebrowseapp.exe");
+    }
+    // Start
     QTC_ASSERT(state() == EngineStarting, qDebug() << state());
     setState(AdapterStarting);
     debugMessage(_("TRYING TO START ADAPTER"));
@@ -1437,10 +1447,14 @@ void TrkGdbAdapter::prepareInferior()
     // We already started the inferior process during the adapter start.
     // Now make gdb aware of it.
     setState(InferiorPreparing);
-    QString fileName = m_engine->startParameters().executable; 
-    m_engine->postCommand(_("add-symbol-file \"%1\" %2").arg(fileName)
-        .arg(m_session.codeseg));
-    m_engine->postCommand(_("symbol-file \"%1\"").arg(fileName));
+    const QString fileName = m_symbolFile;
+    if (m_symbolFile.isEmpty()) {
+        logMessage(QString::fromLatin1("WARNING: No symbol file available."));
+    } else {
+        m_engine->postCommand(_("add-symbol-file \"%1\" %2").arg(m_symbolFile)
+                              .arg(m_session.codeseg));
+        m_engine->postCommand(_("symbol-file \"%1\"").arg(m_symbolFile));
+    }
     m_engine->postCommand(_("target remote ") + gdbServerName(),
         CB(handleTargetRemote));
 }
diff --git a/src/plugins/debugger/gdb/trkgdbadapter.h b/src/plugins/debugger/gdb/trkgdbadapter.h
index 8706e50a2f0..3529bf33fe1 100644
--- a/src/plugins/debugger/gdb/trkgdbadapter.h
+++ b/src/plugins/debugger/gdb/trkgdbadapter.h
@@ -244,6 +244,8 @@ public:
     Q_SLOT void executeCommand(const QString &msg);
     trk::Session m_session; // global-ish data (process id, target information)
     trk::Snapshot m_snapshot; // local-ish data (memory and registers)
+    QString m_remoteExecutable;
+    QString m_symbolFile;
     int m_verbose;
     bool m_bufferedMemoryRead;
     int m_waitCount;
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index 47204dad280..71b0d544cc3 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -141,9 +141,3 @@ OTHER_FILES += ProjectExplorer.pluginspec
 
 mac:LIBS += -framework Carbon
 
-win32:SUPPORT_QT_S60=1
-else:SUPPORT_QT_S60 = $$(QTCREATOR_WITH_S60)
-!isEmpty(SUPPORT_QT_S60) {
-    message("Adding experimental support for Qt/S60 applications.")
-    DEFINES += QTCREATOR_WITH_S60
-}
diff --git a/src/plugins/projectexplorer/toolchain.h b/src/plugins/projectexplorer/toolchain.h
index 41fe8fdc866..b3a11cb7be2 100644
--- a/src/plugins/projectexplorer/toolchain.h
+++ b/src/plugins/projectexplorer/toolchain.h
@@ -79,15 +79,11 @@ public:
         MinGW = 2,
         MSVC = 3,
         WINCE = 4,
-#ifdef QTCREATOR_WITH_S60
         WINSCW = 5,
         GCCE = 6,
         RVCT_ARMV5 = 7,
         RVCT_ARMV6 = 8,
         LAST_VALID = 9,
-#else
-        LAST_VALID = 5,
-#endif
         OTHER = 200,
         UNKNOWN = 201,
         INVALID = 202
diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
index 4599e16dbf4..699d4eaa3ac 100644
--- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
+++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
@@ -197,7 +197,7 @@ QString S60DeviceRunConfiguration::packageFileName() const
 "/S60/devices/S60_3rd_FP2_SDK_v1.1/epoc32/release/gcce/udeb/foo.exe"    - "!:\sys\bin\foo.exe"
 \endcode */
 
-static QString executableFromPkgFile(const QString &pkgFileName, QString *errorMessage)
+static QString localExecutableFromPkgFile(const QString &pkgFileName, QString *errorMessage)
 {
     QFile pkgFile(pkgFileName);
     if (!pkgFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
@@ -214,12 +214,12 @@ static QString executableFromPkgFile(const QString &pkgFileName, QString *errorM
     return QString();
 }
 
-QString S60DeviceRunConfiguration::executableFileName() const
+QString S60DeviceRunConfiguration::localExecutableFileName() const
 {
     const QString pkg = packageFileName();
     if (!pkg.isEmpty()) {
         QString errorMessage;
-        const QString rc = executableFromPkgFile(pkg, &errorMessage);
+        const QString rc = localExecutableFromPkgFile(pkg, &errorMessage);
         if (rc.isEmpty())
             qWarning("%s\n", qPrintable(errorMessage));
         return rc;
@@ -536,7 +536,7 @@ S60DeviceRunControlBase::S60DeviceRunControlBase(const QSharedPointer<RunConfigu
     m_toolsDirectory = S60Manager::instance()->deviceForQtVersion(
             project->qtVersion(project->activeBuildConfiguration())).toolsRoot
             + "/epoc32/tools";
-    m_executableFileName = lsFile(s60runConfig->executableFileName());
+    m_executableFileName = lsFile(s60runConfig->localExecutableFileName());
     m_makesisTool = m_toolsDirectory + "/makesis.exe";
     m_packageFile = QFileInfo(s60runConfig->packageFileName()).fileName();
 }
@@ -770,6 +770,18 @@ void S60DeviceDebugRunControl::initLauncher(const QString &executable, trk::Laun
 {
     // No setting an executable on the launcher causes it to deploy only
     m_startParams->executable = executable;
+    // Prefer the '*.sym' file over the '.exe', which should exist at the same
+    // location in debug builds
+    const QSharedPointer<S60DeviceRunConfiguration> rc = runConfiguration().objectCast<S60DeviceRunConfiguration>();
+    const QString localExecutableFileName = rc->localExecutableFileName();
+    const int lastDotPos = localExecutableFileName.lastIndexOf(QLatin1Char('.'));
+    if (lastDotPos != -1) {
+        m_startParams->symbolFileName = localExecutableFileName.mid(0, lastDotPos) + QLatin1String(".sym");
+        if (!QFileInfo(m_startParams->symbolFileName).isFile()) {
+            m_startParams->symbolFileName.clear();
+            emit addToOutputWindow(this, tr("Warning: Cannot locate the symbol file belonging to %1.").arg(localExecutableFileName));
+        }
+    }
 }
 
 void S60DeviceDebugRunControl::handleLauncherFinished()
diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
index c2da9c62407..c4c3d5496bb 100644
--- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
+++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
@@ -82,7 +82,7 @@ public:
     void setCustomKeyPath(const QString &path);
 
     QString packageFileName() const;
-    QString executableFileName() const;
+    QString localExecutableFileName() const;
 
     ProjectExplorer::ToolChain::ToolChainType toolChainType() const;
 
-- 
GitLab