From b41d3a45ad374df97724a225b8f0ceb936f180e3 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Mon, 27 Jul 2009 15:32:46 +0200
Subject: [PATCH] CDB: Added option for verbose symbol loading, fixed image
 path.

Do not add all image paths (from different projects), keep a
base path and add current.
---
 src/plugins/debugger/cdb/cdbdebugengine.cpp   | 29 ++++++++++++++-----
 src/plugins/debugger/cdb/cdbdebugengine_p.h   |  1 +
 src/plugins/debugger/cdb/cdboptions.cpp       |  9 +++++-
 src/plugins/debugger/cdb/cdboptions.h         |  5 +++-
 src/plugins/debugger/cdb/cdboptionspage.cpp   | 13 +++++++--
 src/plugins/debugger/cdb/cdboptionspage.h     |  1 +
 .../debugger/cdb/cdboptionspagewidget.ui      | 18 +++++++++++-
 7 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/src/plugins/debugger/cdb/cdbdebugengine.cpp b/src/plugins/debugger/cdb/cdbdebugengine.cpp
index b914986a0b4..bccad9cc7a5 100644
--- a/src/plugins/debugger/cdb/cdbdebugengine.cpp
+++ b/src/plugins/debugger/cdb/cdbdebugengine.cpp
@@ -307,6 +307,7 @@ CdbDebugEnginePrivate::CdbDebugEnginePrivate(DebuggerManager *parent,
 
 bool CdbDebugEnginePrivate::init(QString *errorMessage)
 {
+    enum {  bufLen = 10240 };
     // Load the DLL
     DebuggerEngineLibrary lib;
     if (!lib.init(m_options->path, errorMessage))
@@ -343,6 +344,14 @@ bool CdbDebugEnginePrivate::init(QString *errorMessage)
         return false;
     }
 
+    WCHAR buf[bufLen];
+    hr = m_cif.debugSymbols->GetImagePathWide(buf, bufLen, 0);
+    if (FAILED(hr)) {
+        *errorMessage = msgComFailed("GetImagePathWide", hr);
+        return false;
+    }
+    m_baseImagePath = QString::fromUtf16(buf);
+
     hr = lib.debugCreate( __uuidof(IDebugRegisters2), reinterpret_cast<void**>(&m_cif.debugRegisters));
     if (FAILED(hr)) {
         *errorMessage = QString::fromLatin1("Creation of IDebugRegisters2 failed: %1").arg(msgDebugEngineComResult(hr));
@@ -619,16 +628,22 @@ bool CdbDebugEngine::startDebuggerWithExecutable(DebuggerStartMode sm, QString *
 
     const QSharedPointer<DebuggerStartParameters> sp = m_d->m_debuggerManager->startParameters();
     const QString filename(sp->executable);
+    // Set image path
+    const QFileInfo fi(filename);
+    QString imagePath = QDir::toNativeSeparators(fi.absolutePath());
+    if (!m_d->m_baseImagePath.isEmpty()) {
+        imagePath += QLatin1Char(';');
+        imagePath += m_d->m_baseImagePath;
+    }
+    m_d->m_cif.debugSymbols->SetImagePathWide(reinterpret_cast<PCWSTR>(imagePath.utf16()));
     if (debugCDB)
-        qDebug() << Q_FUNC_INFO <<filename;
+        qDebug() << Q_FUNC_INFO <<'\n' << filename << imagePath;
 
-    const QFileInfo fi(filename);
-    m_d->m_cif.debugSymbols->AppendImagePathWide(reinterpret_cast<PCWSTR>(QDir::toNativeSeparators(fi.absolutePath()).utf16()));
-    //m_cif.debugSymbols->SetSymbolOptions(SYMOPT_CASE_INSENSITIVE | SYMOPT_UNDNAME | SYMOPT_DEBUG | SYMOPT_LOAD_LINES | SYMOPT_OMAP_FIND_NEAREST | SYMOPT_AUTO_PUBLICS);
-    m_d->m_cif.debugSymbols->SetSymbolOptions(SYMOPT_CASE_INSENSITIVE | SYMOPT_UNDNAME | SYMOPT_LOAD_LINES | SYMOPT_OMAP_FIND_NEAREST | SYMOPT_AUTO_PUBLICS);
-    //m_cif.debugSymbols->AddSymbolOptions(SYMOPT_CASE_INSENSITIVE | SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_DEBUG | SYMOPT_LOAD_LINES | SYMOPT_OMAP_FIND_NEAREST | SYMOPT_AUTO_PUBLICS | SYMOPT_NO_IMAGE_SEARCH);
+    ULONG symbolOptions = SYMOPT_CASE_INSENSITIVE | SYMOPT_UNDNAME | SYMOPT_LOAD_LINES | SYMOPT_OMAP_FIND_NEAREST | SYMOPT_AUTO_PUBLICS;
+    if (m_d->m_options->verboseSymbolLoading)
+        symbolOptions |= SYMOPT_DEBUG;
+    m_d->m_cif.debugSymbols->SetSymbolOptions(symbolOptions);
 
-    // TODO console
     const QString cmd = Core::Utils::AbstractProcess::createWinCommandline(filename, sp->processArgs);
     if (debugCDB)
         qDebug() << "Starting " << cmd;
diff --git a/src/plugins/debugger/cdb/cdbdebugengine_p.h b/src/plugins/debugger/cdb/cdbdebugengine_p.h
index 53e6737343e..f34077a508c 100644
--- a/src/plugins/debugger/cdb/cdbdebugengine_p.h
+++ b/src/plugins/debugger/cdb/cdbdebugengine_p.h
@@ -157,6 +157,7 @@ struct CdbDebugEnginePrivate
     CdbDebugEventCallback   m_debugEventCallBack;
     CdbDebugOutput          m_debugOutputCallBack;    
     QSharedPointer<CdbDumperHelper> m_dumper;
+    QString                 m_baseImagePath;
 
     CdbDebugEngine* m_engine;
     DebuggerManager *m_debuggerManager;
diff --git a/src/plugins/debugger/cdb/cdboptions.cpp b/src/plugins/debugger/cdb/cdboptions.cpp
index 9cb2af5b4bc..55c6699fabe 100644
--- a/src/plugins/debugger/cdb/cdboptions.cpp
+++ b/src/plugins/debugger/cdb/cdboptions.cpp
@@ -38,18 +38,21 @@ static const char *enabledKeyC = "Enabled";
 static const char *pathKeyC = "Path";
 static const char *symbolPathsKeyC = "SymbolPaths";
 static const char *sourcePathsKeyC = "SourcePaths";
+static const char *verboseSymbolLoadingKeyC = "SymbolPaths";
 
 namespace Debugger {
 namespace Internal {
 
 CdbOptions::CdbOptions() :
-    enabled(false)
+    enabled(false),
+    verboseSymbolLoading(false)
 {
 }
 
 void CdbOptions::clear()
 {
     enabled = false;
+    verboseSymbolLoading = false;
     path.clear();
 }
 
@@ -69,6 +72,7 @@ void CdbOptions::fromSettings(const QSettings *s)
     path = s->value(keyRoot + QLatin1String(pathKeyC), QString()).toString();
     symbolPaths = s->value(keyRoot + QLatin1String(symbolPathsKeyC), QStringList()).toStringList();
     sourcePaths = s->value(keyRoot + QLatin1String(sourcePathsKeyC), QStringList()).toStringList();
+    verboseSymbolLoading = s->value(keyRoot + QLatin1String(verboseSymbolLoadingKeyC), false).toBool();
 }
 
 void CdbOptions::toSettings(QSettings *s) const
@@ -78,6 +82,7 @@ void CdbOptions::toSettings(QSettings *s) const
     s->setValue(QLatin1String(pathKeyC), path);
     s->setValue(QLatin1String(symbolPathsKeyC), symbolPaths);
     s->setValue(QLatin1String(sourcePathsKeyC), sourcePaths);
+    s->setValue(QLatin1String(verboseSymbolLoadingKeyC), verboseSymbolLoading);
     s->endGroup();
 }
 
@@ -128,6 +133,8 @@ unsigned CdbOptions::compare(const CdbOptions &rhs) const
         rc |= InitializationOptionsChanged;
     if (symbolPaths != rhs.symbolPaths || sourcePaths != rhs.sourcePaths)
         rc |= DebuggerPathsChanged;
+    if (verboseSymbolLoading != rhs.verboseSymbolLoading)
+        rc |= SymbolOptionsChanged;
     return rc;
 }
 
diff --git a/src/plugins/debugger/cdb/cdboptions.h b/src/plugins/debugger/cdb/cdboptions.h
index a53c42307e4..b8ab1a1103b 100644
--- a/src/plugins/debugger/cdb/cdboptions.h
+++ b/src/plugins/debugger/cdb/cdboptions.h
@@ -49,7 +49,9 @@ public:
     void toSettings(QSettings *s) const;
 
     // A set of flags for comparison function.
-    enum ChangeFlags { InitializationOptionsChanged = 0x1, DebuggerPathsChanged = 0x2 };
+    enum ChangeFlags { InitializationOptionsChanged = 0x1,
+                       DebuggerPathsChanged = 0x2,
+                       SymbolOptionsChanged = 0x4 };
     unsigned compare(const CdbOptions &s) const;
 
     // Locate the debugging tools
@@ -59,6 +61,7 @@ public:
     QString path;
     QStringList symbolPaths;
     QStringList sourcePaths;
+    bool verboseSymbolLoading;
 };
 
 inline bool operator==(const CdbOptions &s1, const CdbOptions &s2)
diff --git a/src/plugins/debugger/cdb/cdboptionspage.cpp b/src/plugins/debugger/cdb/cdboptionspage.cpp
index bb828fb68bc..91d861dd44f 100644
--- a/src/plugins/debugger/cdb/cdboptionspage.cpp
+++ b/src/plugins/debugger/cdb/cdboptionspage.cpp
@@ -84,6 +84,8 @@ void CdbOptionsPageWidget::setOptions(CdbOptions &o)
     m_ui.cdbPathGroupBox->setChecked(o.enabled);
     m_ui.symbolPathListEditor->setPathList(o.symbolPaths);
     m_ui.sourcePathListEditor->setPathList(o.sourcePaths);
+    m_ui.verboseSymbolLoadingCheckBox->setChecked(o.verboseSymbolLoading);
+
 }
 
 CdbOptions CdbOptionsPageWidget::options() const
@@ -93,6 +95,7 @@ CdbOptions CdbOptionsPageWidget::options() const
     rc.enabled = m_ui.cdbPathGroupBox->isChecked();
     rc.symbolPaths = m_ui.symbolPathListEditor->pathList();
     rc.sourcePaths = m_ui.sourcePathListEditor->pathList();
+    rc.verboseSymbolLoading = m_ui.verboseSymbolLoadingCheckBox->isChecked();
     return rc;
 }
 
@@ -167,11 +170,17 @@ void CdbOptionsPage::apply()
     if (!m_widget)
         return;
     const CdbOptions newOptions = m_widget->options();
-    if (const unsigned changedMask = m_options->compare(newOptions)) {
+    if (unsigned changedMask = m_options->compare(newOptions)) {
         *m_options = newOptions;
         m_options->toSettings(Core::ICore::instance()->settings());
-        if (changedMask & CdbOptions::DebuggerPathsChanged)
+        // Paths changed?
+        if (changedMask & CdbOptions::DebuggerPathsChanged) {
             emit debuggerPathsChanged();
+            changedMask &= ~CdbOptions::DebuggerPathsChanged;
+        }
+        // Remaining options?
+        if (changedMask)
+            emit optionsChanged();
     }
 }
 
diff --git a/src/plugins/debugger/cdb/cdboptionspage.h b/src/plugins/debugger/cdb/cdboptionspage.h
index cc996815f19..f07b7bd17cd 100644
--- a/src/plugins/debugger/cdb/cdboptionspage.h
+++ b/src/plugins/debugger/cdb/cdboptionspage.h
@@ -86,6 +86,7 @@ public:
 
 signals:
     void debuggerPathsChanged();
+    void optionsChanged();
 
 private:
     const QSharedPointer<CdbOptions> m_options;
diff --git a/src/plugins/debugger/cdb/cdboptionspagewidget.ui b/src/plugins/debugger/cdb/cdboptionspagewidget.ui
index 8b1bf10f1c6..b998e7c6f3c 100644
--- a/src/plugins/debugger/cdb/cdboptionspagewidget.ui
+++ b/src/plugins/debugger/cdb/cdboptionspagewidget.ui
@@ -38,7 +38,7 @@
         <item row="0" column="0" colspan="2">
          <widget class="QLabel" name="noteLabel">
           <property name="text">
-           <string extracomment="Placeholder" notr="true">Note: bla, blah</string>
+           <string notr="true" extracomment="Placeholder">Note: bla, blah</string>
           </property>
          </widget>
         </item>
@@ -79,6 +79,22 @@
      </layout>
     </widget>
    </item>
+   <item>
+    <widget class="QGroupBox" name="variousOptionsGroupBox">
+     <property name="title">
+      <string>Other options</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout_3">
+      <item row="0" column="0" colspan="2">
+       <widget class="QCheckBox" name="verboseSymbolLoadingCheckBox">
+        <property name="text">
+         <string>Verbose Symbol Loading</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
    <item>
     <spacer name="verticalSpacer">
      <property name="orientation">
-- 
GitLab