Commit 2a028413 authored by Kai Koehne's avatar Kai Koehne Committed by hjk
Browse files

Debugger: Simplify handling of requestRemoteSetup in QmlCppEngine



Just emit the requestRemoteSetup on your own in QmlCppEngine. Also
properly check the related state transitions in DebuggerEngine.

Change-Id: I15dc4236303911126de7eee63ed996bdd8e5c5a8
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 095946d4
......@@ -137,6 +137,15 @@ QDebug operator<<(QDebug str, const DebuggerStartParameters &sp)
//
//////////////////////////////////////////////////////////////////////
// transitions:
// None->Requested
// Requested->Succeeded
// Requested->Failed
// Requested->Cancelled
enum RemoteSetupState { RemoteSetupNone, RemoteSetupRequested,
RemoteSetupSucceeded, RemoteSetupFailed,
RemoteSetupCancelled };
class DebuggerEnginePrivate : public QObject
{
Q_OBJECT
......@@ -154,6 +163,7 @@ public:
m_state(DebuggerNotReady),
m_lastGoodState(DebuggerNotReady),
m_targetState(DebuggerNotReady),
m_remoteSetupState(RemoteSetupNone),
m_inferiorPid(0),
m_modulesHandler(),
m_registerHandler(),
......@@ -258,9 +268,11 @@ public slots:
public:
DebuggerState state() const { return m_state; }
RemoteSetupState remoteSetupState() const { return m_remoteSetupState; }
bool isMasterEngine() const { return m_engine->isMasterEngine(); }
DebuggerRunControl *runControl() const
{ return m_masterEngine ? m_masterEngine->runControl() : m_runControl; }
void setRemoteSetupState(RemoteSetupState state);
DebuggerEngine *m_engine; // Not owned.
DebuggerEngine *m_masterEngine; // Not owned
......@@ -278,6 +290,9 @@ public:
// The state we are aiming for.
DebuggerState m_targetState;
// State of RemoteSetup signal/slots.
RemoteSetupState m_remoteSetupState;
qint64 m_inferiorPid;
ModulesHandler m_modulesHandler;
......@@ -784,6 +799,13 @@ void DebuggerEnginePrivate::doSetupEngine()
void DebuggerEngine::notifyEngineSetupFailed()
{
showMessage(_("NOTE: ENGINE SETUP FAILED"));
QTC_ASSERT(d->remoteSetupState() == RemoteSetupNone
|| d->remoteSetupState() == RemoteSetupRequested
|| d->remoteSetupState() == RemoteSetupSucceeded,
qDebug() << this << "remoteSetupState" << d->remoteSetupState());
if (d->remoteSetupState() == RemoteSetupRequested)
d->setRemoteSetupState(RemoteSetupCancelled);
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << this << state());
setState(EngineSetupFailed);
if (isMasterEngine() && runControl())
......@@ -794,6 +816,10 @@ void DebuggerEngine::notifyEngineSetupFailed()
void DebuggerEngine::notifyEngineSetupOk()
{
showMessage(_("NOTE: ENGINE SETUP OK"));
QTC_ASSERT(d->remoteSetupState() == RemoteSetupNone
|| d->remoteSetupState() == RemoteSetupSucceeded,
qDebug() << this << "remoteSetupState" << d->remoteSetupState());
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << this << state());
setState(EngineSetupOk);
showMessage(_("QUEUE: SETUP INFERIOR"));
......@@ -869,6 +895,46 @@ void DebuggerEngine::notifyEngineRunFailed()
d->queueShutdownEngine();
}
void DebuggerEngine::notifyEngineRequestRemoteSetup()
{
showMessage(_("NOTE: REQUEST REMOTE SETUP"));
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << this << state());
QTC_ASSERT(d->remoteSetupState() == RemoteSetupNone, qDebug() << this
<< "remoteSetupState" << d->remoteSetupState());
d->setRemoteSetupState(RemoteSetupRequested);
emit requestRemoteSetup();
}
void DebuggerEngine::notifyEngineRemoteSetupDone()
{
showMessage(_("NOTE: REMOTE SETUP DONE"));
QTC_ASSERT(state() == EngineSetupRequested
|| state() == EngineSetupFailed
|| state() == DebuggerFinished, qDebug() << this << state());
QTC_ASSERT(d->remoteSetupState() == RemoteSetupRequested
|| d->remoteSetupState() == RemoteSetupCancelled,
qDebug() << this << "remoteSetupState" << d->remoteSetupState());
if (d->remoteSetupState() == RemoteSetupCancelled)
return;
d->setRemoteSetupState(RemoteSetupSucceeded);
}
void DebuggerEngine::notifyEngineRemoteSetupFailed()
{
showMessage(_("NOTE: REMOTE SETUP FAILED"));
QTC_ASSERT(state() == EngineSetupRequested
|| state() == EngineSetupFailed
|| state() == DebuggerFinished, qDebug() << this << state());
QTC_ASSERT(d->remoteSetupState() == RemoteSetupRequested
|| d->remoteSetupState() == RemoteSetupCancelled,
qDebug() << this << "remoteSetupState" << d->remoteSetupState());
}
void DebuggerEngine::notifyEngineRunAndInferiorRunOk()
{
showMessage(_("NOTE: ENGINE RUN AND INFERIOR RUN OK"));
......@@ -1047,6 +1113,27 @@ void DebuggerEnginePrivate::doFinishDebugger()
m_runControl->debuggingFinished();
}
void DebuggerEnginePrivate::setRemoteSetupState(RemoteSetupState state)
{
bool allowedTransition = true;
if (m_remoteSetupState == RemoteSetupNone) {
if (state == RemoteSetupRequested)
allowedTransition = true;
}
if (m_remoteSetupState == RemoteSetupRequested) {
if (state == RemoteSetupCancelled
|| state == RemoteSetupSucceeded
|| state == RemoteSetupFailed)
allowedTransition = true;
}
if (!allowedTransition)
qDebug() << "*** UNEXPECTED REMOTE SETUP TRANSITION from"
<< m_remoteSetupState << "to" << state;
m_remoteSetupState = state;
}
void DebuggerEngine::notifyEngineIll()
{
showMessage(_("NOTE: ENGINE ILL ******"));
......@@ -1652,15 +1739,13 @@ void DebuggerEngine::openDisassemblerView(const Location &location)
agent->setLocation(location);
}
void DebuggerEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
void DebuggerEngine::handleRemoteSetupDone(int /*gdbServerPort*/,
int /*qmlPort*/)
{
Q_UNUSED(gdbServerPort);
Q_UNUSED(qmlPort);
}
void DebuggerEngine::handleRemoteSetupFailed(const QString &message)
void DebuggerEngine::handleRemoteSetupFailed(const QString &/*message*/)
{
Q_UNUSED(message);
}
bool DebuggerEngine::isStateDebugging() const
......
......@@ -306,6 +306,10 @@ protected:
virtual void notifyEngineSetupFailed();
virtual void notifyEngineRunFailed();
virtual void notifyEngineRequestRemoteSetup();
virtual void notifyEngineRemoteSetupDone();
virtual void notifyEngineRemoteSetupFailed();
virtual void notifyInferiorSetupOk();
virtual void notifyInferiorSetupFailed();
......
......@@ -5018,11 +5018,13 @@ void GdbEngine::resetCommandQueue()
void GdbEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
notifyEngineRemoteSetupDone();
m_gdbAdapter->handleRemoteSetupDone(gdbServerPort, qmlPort);
}
void GdbEngine::handleRemoteSetupFailed(const QString &message)
{
notifyEngineRemoteSetupFailed();
m_gdbAdapter->handleRemoteSetupFailed(message);
}
......
......@@ -96,7 +96,7 @@ void RemoteGdbServerAdapter::startAdapter()
}
}
if (startParameters().requestRemoteSetup)
m_engine->requestRemoteSetup();
m_engine->notifyEngineRequestRemoteSetup();
else
handleSetupDone();
}
......
......@@ -61,7 +61,7 @@ void RemotePlainGdbAdapter::startAdapter()
m_gdbProc.setEnvironment(startParameters().environment.toStringList());
if (startParameters().requestRemoteSetup)
m_engine->requestRemoteSetup();
m_engine->notifyEngineRequestRemoteSetup();
else
handleRemoteSetupDone(startParameters().connParams.port, startParameters().qmlServerPort);
}
......
......@@ -92,7 +92,6 @@ private:
QmlEngine *m_qmlEngine;
DebuggerEngine *m_cppEngine;
DebuggerEngine *m_activeEngine;
QList<DebuggerEngine*> m_enginesAwaitingRemoteSetup;
int m_stackBoundary;
};
......@@ -156,8 +155,6 @@ QmlCppEngine::QmlCppEngine(const DebuggerStartParameters &sp,
d, SLOT(qmlStackChanged()), Qt::QueuedConnection);
connect(d->m_cppEngine, SIGNAL(stackFrameCompleted()), this, SIGNAL(stackFrameCompleted()));
connect(d->m_qmlEngine, SIGNAL(stackFrameCompleted()), this, SIGNAL(stackFrameCompleted()));
connect(d->m_cppEngine, SIGNAL(requestRemoteSetup()), this, SLOT(slaveEngineRequestedRemoteSetup()));
connect(d->m_qmlEngine, SIGNAL(requestRemoteSetup()), this, SLOT(slaveEngineRequestedRemoteSetup()));
}
QmlCppEngine::~QmlCppEngine()
......@@ -438,6 +435,9 @@ void QmlCppEngine::setupEngine()
d->m_stackBoundary = 0;
d->m_qmlEngine->setupSlaveEngine();
d->m_cppEngine->setupSlaveEngine();
if (startParameters().requestRemoteSetup)
notifyEngineRequestRemoteSetup();
}
void QmlCppEngine::notifyEngineRunAndInferiorRunOk()
......@@ -464,19 +464,6 @@ void QmlCppEngine::notifyInferiorShutdownOk()
DebuggerEngine::notifyInferiorShutdownOk();
}
void QmlCppEngine::slaveEngineRequestedRemoteSetup()
{
DebuggerEngine *slaveEngine = qobject_cast<DebuggerEngine*>(sender());
QTC_ASSERT(slaveEngine, return);
bool emitRequest = d->m_enginesAwaitingRemoteSetup.isEmpty();
d->m_enginesAwaitingRemoteSetup << slaveEngine;
if (emitRequest) {
emit requestRemoteSetup();
}
}
void QmlCppEngine::setupInferior()
{
EDEBUG("\nMASTER SETUP INFERIOR");
......@@ -536,10 +523,12 @@ void QmlCppEngine::setState(DebuggerState newState, bool forced)
void QmlCppEngine::slaveEngineStateChanged
(DebuggerEngine *slaveEngine, const DebuggerState newState)
{
if (debug) {
DebuggerEngine *otherEngine = slaveEngine == d->m_cppEngine
? d->m_qmlEngine : d->m_cppEngine;
DebuggerEngine *otherEngine = (slaveEngine == d->m_cppEngine)
? d->m_qmlEngine : d->m_cppEngine;
QTC_CHECK(otherEngine != slaveEngine);
if (debug) {
EDEBUG("GOT SLAVE STATE: " << slaveEngine << newState);
EDEBUG(" OTHER ENGINE: " << otherEngine << otherEngine->state());
EDEBUG(" COMBINED ENGINE: " << this << state() << isDying());
......@@ -789,17 +778,18 @@ void QmlCppEngine::slaveEngineStateChanged
void QmlCppEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
EDEBUG("MASTER REMOTE SETUP DONE");
foreach (DebuggerEngine *slaveEngine, d->m_enginesAwaitingRemoteSetup)
slaveEngine->handleRemoteSetupDone(gdbServerPort, qmlPort);
d->m_enginesAwaitingRemoteSetup.clear();
notifyEngineRemoteSetupDone();
cppEngine()->handleRemoteSetupDone(gdbServerPort, qmlPort);
qmlEngine()->handleRemoteSetupDone(gdbServerPort, qmlPort);
}
void QmlCppEngine::handleRemoteSetupFailed(const QString &message)
{
EDEBUG("MASTER REMOTE SETUP FAILED");
foreach (DebuggerEngine *slaveEngine, d->m_enginesAwaitingRemoteSetup)
slaveEngine->handleRemoteSetupFailed(message);
d->m_enginesAwaitingRemoteSetup.clear();
notifyEngineRemoteSetupFailed();
cppEngine()->handleRemoteSetupFailed(message);
}
void QmlCppEngine::showMessage(const QString &msg, int channel, int timeout) const
......
......@@ -126,9 +126,6 @@ protected:
void notifyEngineRunAndInferiorRunOk();
void notifyInferiorShutdownOk();
private slots:
void slaveEngineRequestedRemoteSetup();
private:
void engineStateChanged(DebuggerState newState);
void setState(DebuggerState newState, bool forced = false);
......
......@@ -406,8 +406,11 @@ void QmlEngine::stopApplicationLauncher()
void QmlEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
Q_UNUSED(gdbServerPort);
if (qmlPort != -1)
startParameters().qmlServerPort = qmlPort;
notifyEngineRemoteSetupDone();
notifyEngineSetupOk();
}
......@@ -416,6 +419,8 @@ void QmlEngine::handleRemoteSetupFailed(const QString &message)
if (isMasterEngine())
QMessageBox::critical(0,tr("Failed to start application"),
tr("Application startup failed: %1").arg(message));
notifyEngineRemoteSetupFailed();
notifyEngineSetupFailed();
}
......@@ -450,7 +455,7 @@ void QmlEngine::setupEngine()
{
if (startParameters().requestRemoteSetup) {
// we need to get the port first
emit requestRemoteSetup();
notifyEngineRequestRemoteSetup();
} else {
d->m_applicationLauncher.setEnvironment(startParameters().environment);
d->m_applicationLauncher.setWorkingDirectory(startParameters().workingDirectory);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment