From fd7808a26f48fed539d6b3616749cd883cddb7fb Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Wed, 14 Sep 2011 17:01:57 +0200
Subject: [PATCH] debugger: better remote debugging

Add option to specify location of debug information to dialog.
Default is sysroot + usr/lib/debug.

Change-Id: I8c2ab448f4aba9385da617d23419e521e3ae263c
Reviewed-on: http://codereview.qt-project.org/4919
Reviewed-by: hjk <qthjk@ovi.com>
---
 src/plugins/debugger/debuggerdialogs.cpp      | 12 ++++++++++
 src/plugins/debugger/debuggerdialogs.h        |  3 +++
 src/plugins/debugger/debuggerplugin.cpp       |  5 ++++
 .../debugger/debuggerstartparameters.h        |  1 +
 .../debugger/gdb/remotegdbserveradapter.cpp   | 19 ++++++++-------
 src/plugins/debugger/startremotedialog.ui     | 23 +++++++++++++++----
 6 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/src/plugins/debugger/debuggerdialogs.cpp b/src/plugins/debugger/debuggerdialogs.cpp
index b1babc5ab25..e13502c351f 100644
--- a/src/plugins/debugger/debuggerdialogs.cpp
+++ b/src/plugins/debugger/debuggerdialogs.cpp
@@ -665,6 +665,8 @@ StartRemoteDialog::StartRemoteDialog(QWidget *parent, bool enableStartScript)
     m_ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
     m_ui->debuggerPathChooser->setExpectedKind(PathChooser::File);
     m_ui->debuggerPathChooser->setPromptDialogTitle(tr("Select Debugger"));
+    m_ui->debuginfoPathChooser->setExpectedKind(PathChooser::File);
+    m_ui->debuginfoPathChooser->setPromptDialogTitle(tr("Select Location of Debugging Information"));
     m_ui->executablePathChooser->setExpectedKind(PathChooser::File);
     m_ui->executablePathChooser->setPromptDialogTitle(tr("Select Executable"));
     m_ui->sysrootPathChooser->setPromptDialogTitle(tr("Select Sysroot"));
@@ -720,6 +722,16 @@ QString StartRemoteDialog::debugger() const
     return m_ui->debuggerPathChooser->path();
 }
 
+void StartRemoteDialog::setDebugInfoLocation(const QString &location)
+{
+    m_ui->debuginfoPathChooser->setPath(location);
+}
+
+QString StartRemoteDialog::debugInfoLocation() const
+{
+    return m_ui->debuginfoPathChooser->path();
+}
+
 void StartRemoteDialog::setRemoteArchitectures(const QStringList &list)
 {
     m_ui->architectureComboBox->clear();
diff --git a/src/plugins/debugger/debuggerdialogs.h b/src/plugins/debugger/debuggerdialogs.h
index 8dd98ec60fe..1f1bf735a28 100644
--- a/src/plugins/debugger/debuggerdialogs.h
+++ b/src/plugins/debugger/debuggerdialogs.h
@@ -210,6 +210,9 @@ public:
     QString debugger() const;
     void setDebugger(const QString &debugger);
 
+    void setDebugInfoLocation(const QString &location);
+    QString debugInfoLocation() const;
+
 private slots:
     void updateState();
 
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 2c06727dd9d..6d27e1f03e1 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -1585,6 +1585,7 @@ bool DebuggerPluginPrivate::queryRemoteParameters(DebuggerStartParameters &sp, b
     dlg.setUseServerStartScript(
             configValue(_("LastUseServerStartScript")).toBool());
     dlg.setSysroot(configValue(_("LastSysroot")).toString());
+    dlg.setDebugInfoLocation(configValue(_("LastDebugInfoLocation")).toString());
     if (dlg.exec() != QDialog::Accepted)
         return false;
     setConfigValue(_("LastRemoteChannel"), dlg.remoteChannel());
@@ -1596,6 +1597,7 @@ bool DebuggerPluginPrivate::queryRemoteParameters(DebuggerStartParameters &sp, b
     setConfigValue(_("LastServerStartScript"), dlg.serverStartScript());
     setConfigValue(_("LastUseServerStartScript"), dlg.useServerStartScript());
     setConfigValue(_("LastSysroot"), dlg.sysroot());
+    setConfigValue(_("LastDebugInfoLocation"), dlg.debugInfoLocation());
     sp.remoteChannel = dlg.remoteChannel();
     sp.remoteArchitecture = dlg.remoteArchitecture();
     sp.gnuTarget = dlg.gnuTarget();
@@ -1609,6 +1611,9 @@ bool DebuggerPluginPrivate::queryRemoteParameters(DebuggerStartParameters &sp, b
     sp.useServerStartScript = dlg.useServerStartScript();
     sp.serverStartScript = dlg.serverStartScript();
     sp.sysroot = dlg.sysroot();
+    sp.debugInfoLocation = dlg.debugInfoLocation();
+    if (sp.debugInfoLocation.isEmpty())
+        sp.debugInfoLocation = sp.sysroot + "/usr/lib/debug";
     return true;
 }
 
diff --git a/src/plugins/debugger/debuggerstartparameters.h b/src/plugins/debugger/debuggerstartparameters.h
index 2ee3f76757f..79d7485e3b0 100644
--- a/src/plugins/debugger/debuggerstartparameters.h
+++ b/src/plugins/debugger/debuggerstartparameters.h
@@ -108,6 +108,7 @@ public:
     bool useServerStartScript;
     QString serverStartScript;
     QString sysroot;
+    QString debugInfoLocation;
     QByteArray remoteDumperLib;
     QByteArray remoteSourcesDir;
     QString remoteMountPoint;
diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
index 525aec35018..b1cf4d01cf1 100644
--- a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
+++ b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
@@ -161,18 +161,19 @@ void RemoteGdbServerAdapter::uploadProcFinished()
 void RemoteGdbServerAdapter::setupInferior()
 {
     QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
+    const DebuggerStartParameters &sp = startParameters();
 
     QString fileName;
-    if (!startParameters().executable.isEmpty()) {
-        QFileInfo fi(startParameters().executable);
+    if (!sp.executable.isEmpty()) {
+        QFileInfo fi(sp.executable);
         fileName = fi.absoluteFilePath();
     }
-    const QByteArray sysroot = startParameters().sysroot.toLocal8Bit();
-    const QByteArray remoteArch = startParameters().remoteArchitecture.toLatin1();
-    const QByteArray gnuTarget = startParameters().gnuTarget.toLatin1();
-    const QByteArray solibPath =
-         QFileInfo(startParameters().dumperLibrary).path().toLocal8Bit();
-    const QString args = startParameters().processArgs;
+    const QByteArray sysroot = sp.sysroot.toLocal8Bit();
+    const QByteArray debugInfoLocation = sp.debugInfoLocation.toLocal8Bit();
+    const QByteArray remoteArch = sp.remoteArchitecture.toLatin1();
+    const QByteArray gnuTarget = sp.gnuTarget.toLatin1();
+    const QByteArray solibPath = QFileInfo(sp.dumperLibrary).path().toLocal8Bit();
+    const QString args = sp.processArgs;
 
     if (!remoteArch.isEmpty())
         m_engine->postCommand("set architecture " + remoteArch);
@@ -180,6 +181,8 @@ void RemoteGdbServerAdapter::setupInferior()
         m_engine->postCommand("set gnutarget " + gnuTarget);
     if (!sysroot.isEmpty())
         m_engine->postCommand("set sysroot " + sysroot);
+    if (!sysroot.isEmpty())
+        m_engine->postCommand("set debug-file-directory " + debugInfoLocation);
     if (!solibPath.isEmpty())
         m_engine->postCommand("set solib-search-path " + solibPath);
     if (!args.isEmpty())
diff --git a/src/plugins/debugger/startremotedialog.ui b/src/plugins/debugger/startremotedialog.ui
index e74cbaf7429..1dabe7c23de 100644
--- a/src/plugins/debugger/startremotedialog.ui
+++ b/src/plugins/debugger/startremotedialog.ui
@@ -107,6 +107,19 @@
       <widget class="Utils::PathChooser" name="sysrootPathChooser"/>
      </item>
      <item row="6" column="0">
+      <widget class="QLabel" name="debuginfoLabel">
+       <property name="text">
+        <string>Location of debugging information:</string>
+       </property>
+       <property name="buddy">
+        <cstring>debuginfoPathChooser</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="6" column="1">
+      <widget class="Utils::PathChooser" name="debuginfoPathChooser"/>
+     </item>
+     <item row="7" column="0">
       <widget class="QLabel" name="overrideStartScriptLabel">
        <property name="text">
         <string>Override host GDB s&amp;tart script:</string>
@@ -116,10 +129,10 @@
        </property>
       </widget>
      </item>
-     <item row="6" column="1">
+     <item row="7" column="1">
       <widget class="Utils::PathChooser" name="overrideStartScriptPathChooser"/>
      </item>
-     <item row="7" column="0">
+     <item row="8" column="0">
       <widget class="QLabel" name="useServerStartScriptLabel">
        <property name="text">
         <string>&amp;Use server start script:</string>
@@ -129,10 +142,10 @@
        </property>
       </widget>
      </item>
-     <item row="7" column="1">
+     <item row="8" column="1">
       <widget class="QCheckBox" name="useServerStartScriptCheckBox"/>
      </item>
-     <item row="8" column="0">
+     <item row="9" column="0">
       <widget class="QLabel" name="serverStartScriptLabel">
        <property name="text">
         <string>&amp;Server start script:</string>
@@ -142,7 +155,7 @@
        </property>
       </widget>
      </item>
-     <item row="8" column="1">
+     <item row="9" column="1">
       <widget class="Utils::PathChooser" name="serverStartScriptPathChooser"/>
      </item>
     </layout>
-- 
GitLab