QmlJSDebugger: Fix crash when stopping debugger

The destructor of QmlAdapter deletes the QDeclarativeDebugConnection,
which in turn results in status changes to the QmLJSInspectorClient. This
again leads to QmlAdapter::logServiceStatusChange() being called for the
already half-destructed object ... break this change by guarding the pointer
to QmlAdapter in QmlJSClientProxy.

Change-Id: I7ae3d45b2146b4f02e3843375ecf276ae75d5ea0
Task-number: QTCREATORBUG-5500
Reviewed-on: http://codereview.qt.nokia.com/2276
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
This commit is contained in:
Kai Koehne
2011-07-27 12:30:34 +02:00
parent 87c072b3ad
commit 33c96800f0
2 changed files with 14 additions and 9 deletions

View File

@@ -65,11 +65,11 @@ ClientProxy::ClientProxy(Debugger::QmlAdapter *adapter, QObject *parent)
void ClientProxy::connectToServer() void ClientProxy::connectToServer()
{ {
m_engineClient = new QDeclarativeEngineDebug(m_adapter->connection(), this); m_engineClient = new QDeclarativeEngineDebug(m_adapter.data()->connection(), this);
connect(m_engineClient, SIGNAL(newObjects()), this, SLOT(newObjects())); connect(m_engineClient, SIGNAL(newObjects()), this, SLOT(newObjects()));
m_inspectorClient = new QmlJSInspectorClient(m_adapter->connection(), this); m_inspectorClient = new QmlJSInspectorClient(m_adapter.data()->connection(), this);
connect(m_inspectorClient, SIGNAL(connectedStatusChanged(QDeclarativeDebugClient::Status)), connect(m_inspectorClient, SIGNAL(connectedStatusChanged(QDeclarativeDebugClient::Status)),
this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status))); this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
@@ -96,7 +96,7 @@ void ClientProxy::connectToServer()
connect(m_inspectorClient, SIGNAL(selectedColorChanged(QColor)), connect(m_inspectorClient, SIGNAL(selectedColorChanged(QColor)),
SIGNAL(selectedColorChanged(QColor))); SIGNAL(selectedColorChanged(QColor)));
connect(m_inspectorClient, SIGNAL(logActivity(QString,QString)), connect(m_inspectorClient, SIGNAL(logActivity(QString,QString)),
m_adapter, SLOT(logServiceActivity(QString,QString))); m_adapter.data(), SLOT(logServiceActivity(QString,QString)));
updateConnected(); updateConnected();
} }
@@ -108,7 +108,8 @@ void ClientProxy::clientStatusChanged(QDeclarativeDebugClient::Status status)
serviceName = client->name(); serviceName = client->name();
} }
m_adapter->logServiceStatusChange(serviceName, status); if (m_adapter)
m_adapter.data()->logServiceStatusChange(serviceName, status);
updateConnected(); updateConnected();
} }
@@ -186,7 +187,8 @@ void ClientProxy::log(LogDirection direction, const QString &message)
} }
msg += message; msg += message;
m_adapter->logServiceActivity("QDeclarativeDebug", msg); if (m_adapter)
m_adapter.data()->logServiceActivity("QDeclarativeDebug", msg);
} }
QList<QDeclarativeDebugObjectReference> QmlJSInspector::Internal::ClientProxy::rootObjectReference() const QList<QDeclarativeDebugObjectReference> QmlJSInspector::Internal::ClientProxy::rootObjectReference() const
@@ -323,13 +325,16 @@ QDeclarativeDebugExpressionQuery *ClientProxy::queryExpressionResult(int objectD
if (!isConnected()) if (!isConnected())
return 0; return 0;
bool block = m_adapter->disableJsDebugging(true); bool block = false;
if (m_adapter)
block = m_adapter.data()->disableJsDebugging(true);
log(LogSend, QString("EVAL_EXPRESSION %1 %2").arg(QString::number(objectDebugId), expr)); log(LogSend, QString("EVAL_EXPRESSION %1 %2").arg(QString::number(objectDebugId), expr));
QDeclarativeDebugExpressionQuery *query QDeclarativeDebugExpressionQuery *query
= m_engineClient->queryExpressionResult(objectDebugId, expr, m_engineClient); = m_engineClient->queryExpressionResult(objectDebugId, expr, m_engineClient);
m_adapter->disableJsDebugging(block); if (m_adapter)
m_adapter.data()->disableJsDebugging(block);
return query; return query;
} }
@@ -662,7 +667,7 @@ void ClientProxy::updateEngineList()
Debugger::QmlAdapter *ClientProxy::qmlAdapter() const Debugger::QmlAdapter *ClientProxy::qmlAdapter() const
{ {
return m_adapter; return m_adapter.data();
} }
bool ClientProxy::isConnected() const bool ClientProxy::isConnected() const

View File

@@ -165,7 +165,7 @@ private:
Q_DISABLE_COPY(ClientProxy) Q_DISABLE_COPY(ClientProxy)
void buildDebugIdHashRecursive(const QDeclarativeDebugObjectReference &ref); void buildDebugIdHashRecursive(const QDeclarativeDebugObjectReference &ref);
Debugger::QmlAdapter *m_adapter; QWeakPointer<Debugger::QmlAdapter> m_adapter;
QDeclarativeEngineDebug *m_engineClient; QDeclarativeEngineDebug *m_engineClient;
QmlJSInspectorClient *m_inspectorClient; QmlJSInspectorClient *m_inspectorClient;