From e539f5bda3222c3e626215ecb870c4f49f93aa14 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Thu, 4 Feb 2010 11:36:49 +0100
Subject: [PATCH] debugger: take advantage of the fact that the trkadapter has
 often up-to-date register data

---
 src/plugins/debugger/debuggermanager.h        |  2 ++
 src/plugins/debugger/gdb/abstractgdbadapter.h |  3 ++-
 src/plugins/debugger/gdb/gdbengine.cpp        |  6 +----
 src/plugins/debugger/gdb/trkgdbadapter.cpp    | 26 ++++++++++++++++++-
 src/plugins/debugger/gdb/trkgdbadapter.h      |  1 +
 5 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h
index 953b5d55c0a..35b5b9841d4 100644
--- a/src/plugins/debugger/debuggermanager.h
+++ b/src/plugins/debugger/debuggermanager.h
@@ -96,6 +96,7 @@ class CdbExceptionLoggerEventCallback;
 class GdbEngine;
 class CdbDebugEngine;
 class CdbDebugEnginePrivate;
+class TrkGdbAdapter;
 } // namespace Internal
 
 class DEBUGGER_EXPORT DebuggerStartParameters
@@ -171,6 +172,7 @@ public:
     friend class Internal::ScriptEngine;
     friend class Internal::CdbDebugEngine;
     friend class Internal::CdbDebugEnginePrivate;
+    friend class Internal::TrkGdbAdapter;
 
     DebuggerState state() const;
     QList<Core::IOptionsPage*> initializeEngines(unsigned enabledTypeFlags);
diff --git a/src/plugins/debugger/gdb/abstractgdbadapter.h b/src/plugins/debugger/gdb/abstractgdbadapter.h
index c36be546841..fe418d7976c 100644
--- a/src/plugins/debugger/gdb/abstractgdbadapter.h
+++ b/src/plugins/debugger/gdb/abstractgdbadapter.h
@@ -57,7 +57,8 @@ public:
     virtual ~AbstractGdbAdapter();
 
     virtual void write(const QByteArray &data);
-    virtual bool isTrkAdapter() const; // isUtterlyBrokenAdapter
+    virtual bool isTrkAdapter() const;
+    virtual void trkReloadRegisters() {}
 
     virtual void startAdapter() = 0;
     virtual void startInferior() = 0;
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 8a5f61ed16b..4354b63e472 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -2805,11 +2805,7 @@ void GdbEngine::reloadRegisters()
     }
 
     if (m_gdbAdapter->isTrkAdapter()) {
-        // FIXME: remove that special case. This is only to prevent
-        // gdb from asking for the values of the fixed point registers
-        postCommand("-data-list-register-values x 0 1 2 3 4 5 6 7 8 9 "
-                      "10 11 12 13 14 15 25",
-                    Discardable, CB(handleRegisterListValues));
+        m_gdbAdapter->trkReloadRegisters();
     } else {
         postCommand("-data-list-register-values x",
                     Discardable, CB(handleRegisterListValues));
diff --git a/src/plugins/debugger/gdb/trkgdbadapter.cpp b/src/plugins/debugger/gdb/trkgdbadapter.cpp
index a94ca2d29fe..46106d43529 100644
--- a/src/plugins/debugger/gdb/trkgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/trkgdbadapter.cpp
@@ -28,12 +28,14 @@
 **************************************************************************/
 
 #include "trkgdbadapter.h"
+
 #include "launcher.h"
 #include "trkoptions.h"
 #include "trkoptionspage.h"
 #include "s60debuggerbluetoothstarter.h"
 #include "bluetoothlistener_gui.h"
 
+#include "registerhandler.h"
 #include "debuggeractions.h"
 #include "debuggerstringutils.h"
 #ifndef STANDALONE_RUNNER
@@ -695,7 +697,6 @@ void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
         sendGdbServerAck();
         int pos = cmd.indexOf(',');
         //qDebug() << "SAL: " << cmd << cmd.mid(3, pos - 3) << cmd.mid(pos + 1);
-        bool ok = false;
         m_snapshot.lineFromAddress = cmd.mid(3, pos - 3).toUInt(0, 16);
         m_snapshot.lineToAddress = cmd.mid(pos + 1).toUInt(0, 16);
         //qDebug() << "SAL: " << hexxNumber(m_snapshot.lineFromAddress)
@@ -2112,5 +2113,28 @@ void TrkGdbAdapter::shutdown()
     cleanup();
 }
 
+void TrkGdbAdapter::trkReloadRegisters()
+{
+    // Take advantage of direct access to cached register values.
+    QTC_ASSERT(m_snapshot.registerValid, /**/);
+    RegisterHandler *handler = m_engine->manager()->registerHandler();
+    QList<Register> registers = handler->registers();
+    QTC_ASSERT(registers.size() >= 25, return);
+    for (int i = 0; i < 16; ++i) {
+        Register &reg = registers[i];
+        QString value = hexxNumber(m_snapshot.registers[i]);
+        reg.changed = (value != reg.value);
+        if (reg.changed)
+            reg.value = value;
+    }
+    Register &reg = registers[24];
+    QString value = hexxNumber(m_snapshot.registers[16]);
+    reg.changed = (value != reg.value);
+    if (reg.changed)
+        reg.value = value;
+    handler->setRegisters(registers);
+}
+
+
 } // namespace Internal
 } // namespace Debugger
diff --git a/src/plugins/debugger/gdb/trkgdbadapter.h b/src/plugins/debugger/gdb/trkgdbadapter.h
index 2c88eb36b2b..2ddb6093ef4 100644
--- a/src/plugins/debugger/gdb/trkgdbadapter.h
+++ b/src/plugins/debugger/gdb/trkgdbadapter.h
@@ -145,6 +145,7 @@ public:
     void setVerbose(int verbose);
     void setBufferedMemoryRead(bool b) { m_bufferedMemoryRead = b; }
     trk::Session &session() { return m_session; }
+    void trkReloadRegisters();
 
 signals:
     void output(const QString &msg);
-- 
GitLab