From 99bdc541999bc438ca108676f5e438bd3bc75458 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 2 Oct 2009 12:31:19 +0200
Subject: [PATCH] debugger: small tweaks to gotoLocation()

---
 src/plugins/debugger/debuggeragents.cpp  |  3 +--
 src/plugins/debugger/debuggermanager.cpp |  2 --
 src/plugins/debugger/gdb/gdbengine.cpp   | 29 ++++++++++--------------
 src/plugins/debugger/stackwindow.cpp     |  5 ++--
 4 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/src/plugins/debugger/debuggeragents.cpp b/src/plugins/debugger/debuggeragents.cpp
index 6da7b7c3684..de8a553180d 100644
--- a/src/plugins/debugger/debuggeragents.cpp
+++ b/src/plugins/debugger/debuggeragents.cpp
@@ -224,9 +224,8 @@ void DisassemblerViewAgent::setFrame(const StackFrame &frame)
     if (!frame.function.isEmpty() && frame.function != _("??")) {
         QHash<QString, QString>::ConstIterator it = d->cache.find(frameKey(frame));
         if (it != d->cache.end()) {
-            QString msg = QString::fromLatin1("Use cache dissassembler for %1 in %2")
+            QString msg = _("Use cache dissassembler for '%1' in '%2'")
                 .arg(frame.function).arg(frame.file);
-            qDebug() << msg;
             m_manager->showDebuggerOutput(msg);
             setContents(*it);
             return;
diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp
index efdb4d9b326..7250cdded28 100644
--- a/src/plugins/debugger/debuggermanager.cpp
+++ b/src/plugins/debugger/debuggermanager.cpp
@@ -378,8 +378,6 @@ void DebuggerManager::init()
     QAbstractItemView *stackView =
         qobject_cast<QAbstractItemView *>(d->m_stackWindow);
     stackView->setModel(d->m_stackHandler->stackModel());
-    connect(stackView, SIGNAL(frameActivated(int)),
-        this, SLOT(activateFrame(int)));
     connect(theDebuggerAction(ExpandStack), SIGNAL(triggered()),
         this, SLOT(reloadFullStack()));
     connect(theDebuggerAction(MaximalStackDepth), SIGNAL(triggered()),
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 1eaae95ea27..6a35e3f1e4b 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -1185,7 +1185,7 @@ void GdbEngine::reloadStack()
     // returns with "^error,msg="Previous frame identical to this frame
     // (corrupt stack?)". Might be related to the fact that we can't
     // access the memory belonging to the lower frames. But as we know
-    // this always happens, ask the second time immediately instead
+    // this sometimes happens, ask the second time immediately instead
     // of waiting for the first request to fail.
     if (m_gdbAdapter->isTrkAdapter())
         postCommand(cmd, WatchUpdate, CB(handleStackListFrames), false);
@@ -2299,7 +2299,8 @@ void GdbEngine::handleStackListFrames(const GdbResponse &response)
             }
             #endif
 
-            // Initialize top frame to the first valid frame
+            // Initialize top frame to the first valid frame.
+            // FIXME: Check for QFile(frame.fullname).isReadable()?
             const bool isValid = !frame.file.isEmpty() && !frame.function.isEmpty();
             if (isValid && topFrame == -1)
                 topFrame = i;
@@ -2310,12 +2311,14 @@ void GdbEngine::handleStackListFrames(const GdbResponse &response)
         theDebuggerAction(ExpandStack)->setEnabled(canExpand);
         manager()->stackHandler()->setFrames(stackFrames, canExpand);
 
-        if (topFrame != -1 && topFrame != 0) {
+        if (topFrame != -1 && topFrame != 0
+                && !theDebuggerBoolSetting(OperateByInstruction)) {
             // For topFrame == -1 there is no frame at all, for topFrame == 0
             // we already issued a 'gotoLocation' when reading the *stopped
-            // message.
+            // message. Also, when OperateByInstruction we always want to
+            // use frame #0.
             const StackFrame &frame = manager()->stackHandler()->currentFrame();
-            qDebug() << "GOTO, 2nd try" << frame.toString();
+            qDebug() << "GOTO, 2nd try" << frame.toString() << topFrame;
             gotoLocation(frame, true);
         }
     } else {
@@ -2348,19 +2351,18 @@ void GdbEngine::activateFrame(int frameIndex)
 
     StackHandler *stackHandler = manager()->stackHandler();
     int oldIndex = stackHandler->currentIndex();
-    qDebug() << "ACTIVATE FRAME:" << frameIndex << oldIndex
-        << stackHandler->currentIndex();
 
     if (frameIndex == stackHandler->stackSize()) {
         reloadFullStack();
         return;
     }
+
     QTC_ASSERT(frameIndex < stackHandler->stackSize(), return);
 
     if (oldIndex != frameIndex) {
         setTokenBarrier();
 
-        // Assuming this always succeeds saves a roundtrip.
+        // Assuming the command always succeeds this saves a roundtrip.
         // Otherwise the lines below would need to get triggered
         // after a response to this -stack-select-frame here.
         postCommand(_("-stack-select-frame ") + QString::number(frameIndex));
@@ -2369,12 +2371,7 @@ void GdbEngine::activateFrame(int frameIndex)
         updateLocals();
     }
 
-    const StackFrame &frame = stackHandler->currentFrame();
-
-    if (frame.isUsable())
-        gotoLocation(frame, true);
-    else
-        qDebug() << "FULL NAME NOT USABLE:" << frame.file;
+    gotoLocation(stackHandler->currentFrame(), true);
 }
 
 void GdbEngine::handleStackListThreads(const GdbResponse &response)
@@ -3953,8 +3950,6 @@ void GdbEngine::handleFetchDisassemblerByLine(const GdbResponse &response)
 
     if (response.resultClass == GdbResultDone) {
         GdbMi lines = response.data.findChild("asm_insns");
-        if (!lines.children().isEmpty())
-            qDebug() << "LINES: " << lines.childAt(0).findChild("line").data();
         if (lines.children().isEmpty())
             fetchDisassemblerByAddress(ac.agent, true);
         else if (lines.children().size() == 1
@@ -3986,7 +3981,7 @@ void GdbEngine::handleFetchDisassemblerByAddress1(const GdbResponse &response)
             if (ac.agent->contentsCoversAddress(contents)) {
                 ac.agent->setContents(parseDisassembler(lines));
             } else {
-                qDebug() << "FALL BACK TO NON-MIXED";
+                debugMessage(_("FALL BACK TO NON-MIXED"));
                 fetchDisassemblerByAddress(ac.agent, false);
             }
         }
diff --git a/src/plugins/debugger/stackwindow.cpp b/src/plugins/debugger/stackwindow.cpp
index 9b94856deac..d854a5edaf6 100644
--- a/src/plugins/debugger/stackwindow.cpp
+++ b/src/plugins/debugger/stackwindow.cpp
@@ -80,8 +80,7 @@ void StackWindow::showAddressColumn(bool on)
 
 void StackWindow::rowActivated(const QModelIndex &index)
 {
-    //qDebug() << "ACTIVATED: " << index.row() << index.column();
-    emit frameActivated(index.row());
+    m_manager->activateFrame(index.row());
 }
 
 void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
@@ -115,7 +114,7 @@ void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
 
     menu.addSeparator();
 
-    //menu.addAction(theDebuggerAction(UseTooltipsInStackView));
+    menu.addAction(theDebuggerAction(UseToolTipsInStackView));
     menu.addAction(theDebuggerAction(UseAddressInStackView));
 
     QAction *actAdjust = menu.addAction(tr("Adjust column widths to contents"));
-- 
GitLab