QDeclarativeDebug: Fix QJSDebugService if launched with ',block'
authorKai Koehne <kai.koehne@nokia.com>
Wed, 8 Jun 2011 09:01:26 +0000 (11:01 +0200)
committerKai Koehne <kai.koehne@nokia.com>
Fri, 10 Jun 2011 13:21:55 +0000 (15:21 +0200)
If the debugger is launched in blocking mode the service will be enabled
from the start.

Reviewed-by: Thorbjorn Lindeijer
(cherry picked from commit c038e3505309bb954123493cb5f96c73e114f3d0)

src/declarative/debugger/qjsdebuggeragent.cpp
src/declarative/debugger/qjsdebuggeragent_p.h
src/declarative/debugger/qjsdebugservice.cpp

index 9b76592..dff637b 100644 (file)
@@ -56,7 +56,7 @@ class QJSDebuggerAgentPrivate
 {
 public:
     QJSDebuggerAgentPrivate(QJSDebuggerAgent *q)
-        : q(q), state(NoState)
+        : q(q), state(NoState), isInitialized(false)
     {}
 
     void continueExec();
@@ -79,6 +79,7 @@ public:
     QHash<QString, JSAgentBreakpointData> fileNameToBreakpoints;
     QStringList watchExpressions;
     QSet<qint64> knownObjectIds;
+    bool isInitialized;
 };
 
 namespace {
@@ -252,6 +253,14 @@ QJSDebuggerAgent::~QJSDebuggerAgent()
     delete d;
 }
 
+/*!
+  Indicates whether the agent got the list of breakpoints.
+  */
+bool QJSDebuggerAgent::isInitialized() const
+{
+    return d->isInitialized;
+}
+
 void QJSDebuggerAgent::setBreakpoints(const JSAgentBreakpoints &breakpoints)
 {
     d->breakpoints = breakpoints;
@@ -259,6 +268,8 @@ void QJSDebuggerAgent::setBreakpoints(const JSAgentBreakpoints &breakpoints)
     d->fileNameToBreakpoints.clear();
     foreach (const JSAgentBreakpointData &bp, breakpoints)
         d->fileNameToBreakpoints.insertMulti(fileName(QString::fromUtf8(bp.fileUrl)), bp);
+
+    d->isInitialized = true;
 }
 
 void QJSDebuggerAgent::setWatchExpressions(const QStringList &watchExpressions)
index 5aa3c9c..309588e 100644 (file)
@@ -145,6 +145,8 @@ public:
     QJSDebuggerAgent(QDeclarativeEngine *engine, QObject *parent = 0);
     ~QJSDebuggerAgent();
 
+    bool isInitialized() const;
+
     void setBreakpoints(const JSAgentBreakpoints &);
     void setWatchExpressions(const QStringList &);
 
index 4ce2c90..ad84f65 100644 (file)
@@ -71,6 +71,16 @@ void QJSDebugService::addEngine(QDeclarativeEngine *engine)
     Q_ASSERT(!m_engines.contains(engine));
 
     m_engines.append(engine);
+
+    if (status() == Enabled && !m_engines.isEmpty() && !m_agent) {
+        m_agent = new QJSDebuggerAgent(engine, engine);
+        connect(m_agent, SIGNAL(stopped(bool,QString)),
+                this, SLOT(executionStopped(bool,QString)));
+
+        while (!m_agent->isInitialized()) {
+            waitForMessage();
+        }
+    }
 }
 
 void QJSDebugService::removeEngine(QDeclarativeEngine *engine)