From eb701fc7a8cccc0d6d495545d921799de3b5ae43 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Wed, 12 Jan 2011 10:39:33 +0100
Subject: [PATCH] debugger: start on integrated combined c++/qml debugging

---
 share/qtcreator/gdbmacros/dumper.py           | 32 +++++++++++++++++++
 src/plugins/debugger/debuggerplugin.cpp       |  2 ++
 .../debugger/gdb/abstractplaingdbadapter.cpp  |  4 +++
 src/plugins/debugger/gdb/gdbengine.h          |  2 ++
 src/plugins/debugger/qml/qmlcppengine.cpp     | 22 +++++++++++--
 5 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/share/qtcreator/gdbmacros/dumper.py b/share/qtcreator/gdbmacros/dumper.py
index bfd70f3d013..cd2f2bb8a25 100644
--- a/share/qtcreator/gdbmacros/dumper.py
+++ b/share/qtcreator/gdbmacros/dumper.py
@@ -1928,3 +1928,35 @@ class ThreadNamesCommand(gdb.Command):
 ThreadNamesCommand()
 
 
+
+#######################################################################
+#
+# Mixed C++/Qml debugging
+#
+#######################################################################
+
+def qmlb():
+    # gdb.execute(command, to_string=True).split("\n")
+    warm("RUNNING: break -f QScript::FunctionWrapper::proxyCall")
+    output = catchCliOutput("rbreak -f QScript::FunctionWrapper::proxyCall")
+    warn("OUTPUT: %s " % output)
+    bp = output[0]
+    warn("BP: %s " % bp)
+    # BP: ['Breakpoint 3 at 0xf166e7: file .../qscriptfunction.cpp, line 75.\\n'] \n"
+    pos = bp.find(' ') + 1
+    warn("POS: %s " % pos)
+    nr = bp[bp.find(' ') + 1 : bp.find(' at ')]
+    warn("NR: %s " % nr)
+    return bp
+
+
+class SetQmlBreakpoint(gdb.Command):
+    """Set helper breakpoint Script::FunctionWrapper::proxyCall"""
+
+    def __init__(self):
+        super(SetQmlBreakpoint, self).__init__("qmlb", gdb.COMMAND_OBSCURE)
+
+    def invoke(self, arg, from_tty):
+        qmlb()
+
+SetQmlBreakpoint()
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 526791cbf68..04fc250881f 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -1094,6 +1094,7 @@ public slots:
 
     void handleExecStep()
     {
+        qDebug() << "CURRENT: " << currentEngine();
         currentEngine()->resetLocation();
         if (boolSetting(OperateByInstruction))
             currentEngine()->executeStepI();
@@ -1964,6 +1965,7 @@ void DebuggerPluginPrivate::startDebugger(RunControl *rc)
 
 void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine)
 {
+    qDebug() << "CONNECT: " << engine;
     if (!engine)
         engine = dummyEngine();
 
diff --git a/src/plugins/debugger/gdb/abstractplaingdbadapter.cpp b/src/plugins/debugger/gdb/abstractplaingdbadapter.cpp
index dec3f2c4e79..a123dcfef2b 100644
--- a/src/plugins/debugger/gdb/abstractplaingdbadapter.cpp
+++ b/src/plugins/debugger/gdb/abstractplaingdbadapter.cpp
@@ -76,6 +76,10 @@ void AbstractPlainGdbAdapter::handleFileExecAndSymbols(const GdbResponse &respon
             if (m_engine->m_gdbVersion < 70000)
                 m_engine->postCommand("info target", CB(handleInfoTarget));
         }
+        //if (m_engine->isSlaveEngine())
+            //m_engine->postCommand("qmlb", GdbEngine::ConsoleCommand);
+            //m_engine->postCommand("rbreak QScript::FunctionWrapper::proxyCall");
+         //   m_engine->postCommand("-break-insert -f 'myns::QScript::FunctionWrapper::proxyCall'");
         m_engine->handleInferiorPrepared();
     } else {
         QByteArray ba = response.data.findChild("msg").data();
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index 27ca19bfad7..ae0826ad343 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -70,6 +70,7 @@ class CoreGdbAdapter;
 class LocalPlainGdbAdapter;
 class RemoteGdbServerAdapter;
 class TrkGdbAdapter;
+class  QmlCppEngine;
 
 enum DebuggingHelperState
 {
@@ -100,6 +101,7 @@ private:
     friend class RemotePlainGdbAdapter;
     friend class TrkGdbAdapter;
     friend class TcfTrkGdbAdapter;
+    friend class  QmlCppEngine;
 
 private: ////////// General Interface //////////
 
diff --git a/src/plugins/debugger/qml/qmlcppengine.cpp b/src/plugins/debugger/qml/qmlcppengine.cpp
index 33f4a67516b..97ea9b07c76 100644
--- a/src/plugins/debugger/qml/qmlcppengine.cpp
+++ b/src/plugins/debugger/qml/qmlcppengine.cpp
@@ -4,6 +4,8 @@
 #include "debuggermainwindow.h"
 #include "debuggercore.h"
 
+#include "gdb/gdbengine.h"
+
 #include <qmljseditor/qmljseditorconstants.h>
 #include <coreplugin/editormanager/editormanager.h>
 #include <coreplugin/editormanager/ieditor.h>
@@ -23,6 +25,7 @@ DebuggerEngine *createQmlEngine(const DebuggerStartParameters &);
 
 DebuggerEngine *createQmlCppEngine(const DebuggerStartParameters &sp)
 {
+    qDebug() << "CREATING QMLCPPENGINE";
     QmlCppEngine *newEngine = new QmlCppEngine(sp);
     if (newEngine->cppEngine())
         return newEngine;
@@ -119,7 +122,7 @@ void QmlCppEngine::setActiveEngine(DebuggerLanguage language)
     }
     if (previousEngine != d->m_activeEngine) {
         showStatusMessage(tr("%1 debugger activated").arg(engineName));
-        debuggerCore()->displayDebugger(d->m_activeEngine, updateEngine);
+        //debuggerCore()->displayDebugger(d->m_activeEngine, updateEngine);
     }
 }
 
@@ -307,7 +310,18 @@ void QmlCppEngine::detachDebugger()
 
 void QmlCppEngine::executeStep()
 {
-    d->m_activeEngine->executeStep();
+    qDebug() << "CPP ENGINE: " << d->m_cppEngine;
+    if (d->m_activeEngine == d->m_cppEngine) {
+        d->m_cppEngine->executeStep();
+    } else {
+        QByteArray ba =
+            "-break-insert -f 'myns::QScript::FunctionWrapper::proxyCall'";
+        GdbEngine *cppEngine = qobject_cast<GdbEngine *>(d->m_cppEngine);
+        qDebug() << "CPP ENGINE: " << cppEngine << d->m_cppEngine;
+        if (cppEngine)
+            cppEngine->postCommand(ba);
+        d->m_qmlEngine->executeStep();
+    }
 }
 
 void QmlCppEngine::executeStepOut()
@@ -317,12 +331,14 @@ void QmlCppEngine::executeStepOut()
 
 void QmlCppEngine::executeNext()
 {
+    qDebug() << "NEXT";
     d->m_activeEngine->executeNext();
 }
 
 void QmlCppEngine::executeStepI()
 {
-    d->m_activeEngine->executeStepI();
+    qDebug() << "STEP I";
+    d->m_activeEngine->executeStep();
 }
 
 void QmlCppEngine::executeNextI()
-- 
GitLab