From 63eaf1e132286c3e29a16b433bf3d06e7c648324 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Tue, 21 Dec 2010 13:34:59 +0100
Subject: [PATCH] debugger: add an option to load "missing" symbols for current
 stack

---
 src/plugins/debugger/cdb/cdbmodules.cpp  |  5 ++--
 src/plugins/debugger/cdb2/cdbengine2.cpp |  4 +--
 src/plugins/debugger/debuggerengine.cpp  |  4 +++
 src/plugins/debugger/debuggerengine.h    |  1 +
 src/plugins/debugger/gdb/gdbengine.cpp   | 33 +++++++++++++++++++++---
 src/plugins/debugger/gdb/gdbengine.h     |  1 +
 src/plugins/debugger/moduleshandler.cpp  | 12 ++++++---
 src/plugins/debugger/moduleshandler.h    |  4 +--
 src/plugins/debugger/stackwindow.cpp     | 10 ++++++-
 9 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/src/plugins/debugger/cdb/cdbmodules.cpp b/src/plugins/debugger/cdb/cdbmodules.cpp
index 9a7a168109a..0c35165512e 100644
--- a/src/plugins/debugger/cdb/cdbmodules.cpp
+++ b/src/plugins/debugger/cdb/cdbmodules.cpp
@@ -74,13 +74,12 @@ bool getModuleNameList(CIDebugSymbols *syms, QStringList *modules, QString *erro
 static inline void getBasicModuleParameters(const DEBUG_MODULE_PARAMETERS &p,
                                             Module *module)
 {
-    const QString hexPrefix = QLatin1String("0x");
     if ((p.Flags & DEBUG_MODULE_USER_MODE) && (p.SymbolType != DEBUG_SYMTYPE_NONE))
         module->symbolsRead = Module::ReadOk;
     else
         module->symbolsRead = Module::ReadFailed;
-    module->startAddress = hexPrefix + QString::number(p.Base, 16);
-    module->endAddress = hexPrefix + QString::number((p.Base + p.Size), 16);
+    module->startAddress = p.Base;
+    module->endAddress = p.Base + p.Size;
 }
 
 // Get module name by index
diff --git a/src/plugins/debugger/cdb2/cdbengine2.cpp b/src/plugins/debugger/cdb2/cdbengine2.cpp
index d9f24fe9f18..7b3e64baabc 100644
--- a/src/plugins/debugger/cdb2/cdbengine2.cpp
+++ b/src/plugins/debugger/cdb2/cdbengine2.cpp
@@ -1164,8 +1164,8 @@ void CdbEngine::handleModules(const CdbExtensionCommandPtr &reply)
                 Debugger::Internal::Module module;
                 module.moduleName = QString::fromAscii(gdbmiModule.findChild("name").data());
                 module.modulePath = QString::fromAscii(gdbmiModule.findChild("image").data());
-                module.startAddress = QString::fromAscii(gdbmiModule.findChild("start").data());
-                module.endAddress = QString::fromAscii(gdbmiModule.findChild("end").data());
+                module.startAddress = gdbmiModule.findChild("start").data().toULongLong(0, 0);
+                module.endAddress = gdbmiModule.findChild("end").data().toULongLong(0, 0);
                 if (gdbmiModule.findChild("deferred").type() == Debugger::Internal::GdbMi::Invalid)
                     module.symbolsRead = Debugger::Internal::Module::ReadOk;
                 modules.push_back(module);
diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp
index 9fd7b130109..7111809e51c 100644
--- a/src/plugins/debugger/debuggerengine.cpp
+++ b/src/plugins/debugger/debuggerengine.cpp
@@ -1182,6 +1182,10 @@ void DebuggerEngine::loadAllSymbols()
 {
 }
 
+void DebuggerEngine::loadSymbolsForStack()
+{
+}
+
 void DebuggerEngine::requestModuleSymbols(const QString &)
 {
 }
diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h
index b7f788bd50e..df7ce744a69 100644
--- a/src/plugins/debugger/debuggerengine.h
+++ b/src/plugins/debugger/debuggerengine.h
@@ -214,6 +214,7 @@ public:
     virtual void reloadModules();
     virtual void examineModules();
     virtual void loadSymbols(const QString &moduleName);
+    virtual void loadSymbolsForStack();
     virtual void loadAllSymbols();
     virtual void requestModuleSymbols(const QString &moduleName);
 
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index c44f8415f32..729ede4b463 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -2630,6 +2630,30 @@ void GdbEngine::loadAllSymbols()
     updateLocals();
 }
 
+void GdbEngine::loadSymbolsForStack()
+{
+    bool needUpdate = false;
+    const Modules &modules = modulesHandler()->modules();
+    foreach (const StackFrame &frame, stackHandler()->frames()) {
+        if (frame.function == _("??")) {
+            qDebug() << "LOAD FOR " << frame.address;
+            foreach (const Module &module, modules) {
+                if (module.startAddress <= frame.address
+                        && frame.address < module.endAddress) {
+                    postCommand("sharedlibrary "
+                        + dotEscape(module.moduleName.toLocal8Bit()));
+                    needUpdate = true;
+                }
+            }
+        }
+    }
+    if (needUpdate) {
+        reloadModulesInternal();
+        reloadStack(true);
+        updateLocals();
+    }
+}
+
 void GdbEngine::requestModuleSymbols(const QString &moduleName)
 {
     QTemporaryFile tf(QDir::tempPath() + _("/gdbsymbols"));
@@ -2756,12 +2780,13 @@ void GdbEngine::handleModulesList(const GdbResponse &response)
             // shlib-info={...}...
             foreach (const GdbMi &item, response.data.children()) {
                 Module module;
-                module.moduleName = QString::fromLocal8Bit(item.findChild("path").data());
+                module.moduleName =
+                    QString::fromLocal8Bit(item.findChild("path").data());
                 module.symbolsRead = (item.findChild("state").data() == "Y")
                         ? Module::ReadOk : Module::ReadFailed;
-                module.startAddress = _(item.findChild("loaded_addr").data());
-                //: End address of loaded module
-                module.endAddress = tr("<unknown>", "address");
+                module.startAddress =
+                    item.findChild("loaded_addr").data().toULongLong(0, 0);
+                module.endAddress = 0; // FIXME: End address not easily available.
                 modules.append(module);
             }
         }
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index df3268ec887..71d685af3d1 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -377,6 +377,7 @@ private: ////////// View & Data Stuff //////////
     //
     void loadSymbols(const QString &moduleName);
     void loadAllSymbols();
+    void loadSymbolsForStack();
     void requestModuleSymbols(const QString &moduleName);
     void reloadModules();
     void examineModules();
diff --git a/src/plugins/debugger/moduleshandler.cpp b/src/plugins/debugger/moduleshandler.cpp
index bb56cef23bd..9e57c4b3beb 100644
--- a/src/plugins/debugger/moduleshandler.cpp
+++ b/src/plugins/debugger/moduleshandler.cpp
@@ -107,11 +107,17 @@ QVariant ModulesModel::data(const QModelIndex &index, int role) const
             break;
         case 4:
             if (role == Qt::DisplayRole)
-                return module.startAddress;
+                return QString(QLatin1String("0x")
+                            + QString::number(module.startAddress, 16));
             break;
         case 5:
-            if (role == Qt::DisplayRole)
-                return module.endAddress;
+            if (role == Qt::DisplayRole) {
+                if (module.endAddress)
+                    return QString(QLatin1String("0x")
+                                + QString::number(module.endAddress, 16));
+                //: End address of loaded module
+                return tr("<unknown>", "address");
+            }
             break;
     }
     return QVariant();
diff --git a/src/plugins/debugger/moduleshandler.h b/src/plugins/debugger/moduleshandler.h
index 3a9ee655bae..97a49be0b39 100644
--- a/src/plugins/debugger/moduleshandler.h
+++ b/src/plugins/debugger/moduleshandler.h
@@ -90,8 +90,8 @@ public:
     QString modulePath;
     SymbolReadState symbolsRead;
     SymbolType symbolsType;
-    QString startAddress;
-    QString endAddress;
+    quint64 startAddress;
+    quint64 endAddress;
 };
 
 typedef QVector<Module> Modules;
diff --git a/src/plugins/debugger/stackwindow.cpp b/src/plugins/debugger/stackwindow.cpp
index ad97a8c58ef..6c9c5efa7a0 100644
--- a/src/plugins/debugger/stackwindow.cpp
+++ b/src/plugins/debugger/stackwindow.cpp
@@ -143,6 +143,10 @@ void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
         actShowDisassembler->setEnabled(engineCapabilities & DisassemblerCapability);
     }
 
+    QAction *actLoadSymbols = 0;
+    if (engineCapabilities & ShowModuleSymbolsCapability)
+        actLoadSymbols = menu.addAction(tr("Try to Load Unknown Symbols"));
+
     menu.addSeparator();
 #if 0 // @TODO: not implemented
     menu.addAction(debuggerCore()->action(UseToolTipsInStackView));
@@ -162,7 +166,9 @@ void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
 
     QAction *act = menu.exec(ev->globalPos());
 
-    if (act == actCopyContents)
+    if (!act)
+        ;
+    else if (act == actCopyContents)
         copyContentsToClipboard();
     else if (act == actAdjust)
         resizeColumnsToContents();
@@ -172,6 +178,8 @@ void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
         engine->openMemoryView(address);
     else if (act == actShowDisassembler)
         engine->openDisassemblerView(frame);
+    else if (act == actLoadSymbols)
+        engine->loadSymbolsForStack();
 }
 
 void StackWindow::copyContentsToClipboard()
-- 
GitLab