debugger: encapsulate part of the startup logic in the base class

This commit is contained in:
hjk
2010-07-08 14:26:35 +02:00
parent e721b9f70f
commit 85243e19a9
8 changed files with 46 additions and 44 deletions

View File

@@ -387,7 +387,7 @@ void CdbEngine::startEngine()
warning(QLatin1String("Internal error: Attempt to start debugger while another process is being debugged.")); warning(QLatin1String("Internal error: Attempt to start debugger while another process is being debugged."));
setState(EngineStartFailed, Q_FUNC_INFO, __LINE__); setState(EngineStartFailed, Q_FUNC_INFO, __LINE__);
setState(DebuggerNotReady, Q_FUNC_INFO, __LINE__); setState(DebuggerNotReady, Q_FUNC_INFO, __LINE__);
emit startFailed(); notifyEngineStartFailed();
return; return;
} }
switch (sp.startMode) { switch (sp.startMode) {
@@ -396,7 +396,7 @@ void CdbEngine::startEngine()
warning(QLatin1String("Internal error: Mode not supported.")); warning(QLatin1String("Internal error: Mode not supported."));
setState(EngineStartFailed, Q_FUNC_INFO, __LINE__); setState(EngineStartFailed, Q_FUNC_INFO, __LINE__);
setState(DebuggerNotReady, Q_FUNC_INFO, __LINE__); setState(DebuggerNotReady, Q_FUNC_INFO, __LINE__);
emit startFailed(); notifyEngineStartFailed();
break; break;
default: default:
break; break;
@@ -470,11 +470,11 @@ void CdbEngine::startEngine()
if (rc) { if (rc) {
if (needWatchTimer) if (needWatchTimer)
m_d->startWatchTimer(); m_d->startWatchTimer();
startSuccessful(); notifyEngineStarted();
} else { } else {
warning(errorMessage); warning(errorMessage);
setState(InferiorStartFailed, Q_FUNC_INFO, __LINE__); setState(InferiorStartFailed, Q_FUNC_INFO, __LINE__);
startFailed(); notifyEngineStartFailed();
} }
} }

View File

@@ -608,12 +608,12 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
void DebuggerEngine::startDebugger(DebuggerRunControl *runControl) void DebuggerEngine::startDebugger(DebuggerRunControl *runControl)
{ {
QTC_ASSERT(runControl, startFailed(); return); QTC_ASSERT(runControl, notifyEngineStartFailed(); return);
QTC_ASSERT(!d->m_runControl, startFailed(); return); QTC_ASSERT(!d->m_runControl, notifyEngineStartFailed(); return);
DebuggerEngine *sessionTemplate = plugin()->sessionTemplate(); DebuggerEngine *sessionTemplate = plugin()->sessionTemplate();
QTC_ASSERT(sessionTemplate, startFailed(); return); QTC_ASSERT(sessionTemplate, notifyEngineStartFailed(); return);
QTC_ASSERT(sessionTemplate != this, startFailed(); return); QTC_ASSERT(sessionTemplate != this, notifyEngineStartFailed(); return);
breakHandler()->initializeFromTemplate(sessionTemplate->breakHandler()); breakHandler()->initializeFromTemplate(sessionTemplate->breakHandler());
watchHandler()->initializeFromTemplate(sessionTemplate->watchHandler()); watchHandler()->initializeFromTemplate(sessionTemplate->watchHandler());
@@ -956,6 +956,18 @@ static bool isAllowedTransition(int from, int to)
return false; return false;
} }
void DebuggerEngine::notifyEngineStarted()
{
QTC_ASSERT(state() == EngineStarting, /**/);
setState(EngineStarted);
}
void DebuggerEngine::notifyEngineStartFailed()
{
QTC_ASSERT(state() == EngineStarting, /**/);
setState(EngineStartFailed);
}
void DebuggerEngine::setState(DebuggerState state, bool forced) void DebuggerEngine::setState(DebuggerState state, bool forced)
{ {
//qDebug() << "STATUS CHANGE: FROM " << stateName(d->m_state) //qDebug() << "STATUS CHANGE: FROM " << stateName(d->m_state)
@@ -972,8 +984,16 @@ void DebuggerEngine::setState(DebuggerState state, bool forced)
showMessage(msg, LogDebug); showMessage(msg, LogDebug);
plugin()->updateState(this); plugin()->updateState(this);
if (state != oldState && state == DebuggerNotReady) if (state != oldState) {
d->m_runControl->debuggingFinished(); if (state == DebuggerNotReady) {
d->m_runControl->debuggingFinished();
} else if (state == EngineStarted) {
d->m_runControl->startSuccessful();
} else if (state == EngineStartFailed) {
d->m_runControl->debuggingFinished();
d->m_runControl->startFailed();
}
}
} }
bool DebuggerEngine::debuggerActionsEnabled() const bool DebuggerEngine::debuggerActionsEnabled() const
@@ -1008,18 +1028,6 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state)
return false; return false;
} }
void DebuggerEngine::startFailed()
{
// The concrete engines themselves are responsible for changing state.
QTC_ASSERT(state() == DebuggerNotReady, setState(DebuggerNotReady));
d->m_runControl->startFailed();
}
void DebuggerEngine::startSuccessful()
{
d->m_runControl->startSuccessful();
}
void DebuggerEngine::notifyInferiorPid(qint64 pid) void DebuggerEngine::notifyInferiorPid(qint64 pid)
{ {
if (d->m_inferiorPid == pid) if (d->m_inferiorPid == pid)

View File

@@ -248,13 +248,13 @@ public slots:
void openFile(const QString &fileName, int lineNumber = -1); void openFile(const QString &fileName, int lineNumber = -1);
void gotoLocation(const QString &fileName, int lineNumber, bool setMarker); void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);
void gotoLocation(const StackFrame &frame, bool setMarker); void gotoLocation(const StackFrame &frame, bool setMarker);
void startSuccessful();
void startFailed();
void raiseApplication(); void raiseApplication();
virtual void quitDebugger() { exitDebugger(); } // called by DebuggerRunControl virtual void quitDebugger() { exitDebugger(); } // called by DebuggerRunControl
protected: protected:
void setState(DebuggerState state, bool forced = false); void setState(DebuggerState state, bool forced = false);
void notifyEngineStarted();
void notifyEngineStartFailed();
private: private:
void executeRunToLine(); void executeRunToLine();

View File

@@ -4205,7 +4205,7 @@ void GdbEngine::handleAdapterStartFailed(const QString &msg, const QString &sett
void GdbEngine::handleAdapterStarted() void GdbEngine::handleAdapterStarted()
{ {
setState(EngineStarted); notifyEngineStarted();
if (m_progress) if (m_progress)
m_progress->setProgressValue(25); m_progress->setProgressValue(25);
showMessage(_("ADAPTER SUCCESSFULLY STARTED")); showMessage(_("ADAPTER SUCCESSFULLY STARTED"));
@@ -4217,7 +4217,6 @@ void GdbEngine::handleAdapterStarted()
void GdbEngine::handleInferiorPrepared() void GdbEngine::handleInferiorPrepared()
{ {
startSuccessful();
const QByteArray qtInstallPath = startParameters().qtInstallPath.toLocal8Bit(); const QByteArray qtInstallPath = startParameters().qtInstallPath.toLocal8Bit();
if (!qtInstallPath.isEmpty()) { if (!qtInstallPath.isEmpty()) {
QByteArray qtBuildPath; QByteArray qtBuildPath;

View File

@@ -148,7 +148,7 @@ void PdbEngine::startEngine()
//showMessage("STARTING " +m_scriptFileName + "FAILED"); //showMessage("STARTING " +m_scriptFileName + "FAILED");
showMessage(QString::fromLatin1("Cannot open %1: %2"). showMessage(QString::fromLatin1("Cannot open %1: %2").
arg(m_scriptFileName, scriptFile.errorString()), LogError); arg(m_scriptFileName, scriptFile.errorString()), LogError);
startFailed(); notifyEngineStartFailed();
return; return;
} }
m_pdbProc.disconnect(); // From any previous runs m_pdbProc.disconnect(); // From any previous runs
@@ -188,9 +188,10 @@ void PdbEngine::startEngine()
Core::ICore::instance()->showWarningWithOptions(title, msg); Core::ICore::instance()->showWarningWithOptions(title, msg);
} }
shutdown(); shutdown();
startFailed(); notifyEngineStartFailed();
return; return;
} }
notifyEngineStarted();
attemptBreakpointSynchronization(); attemptBreakpointSynchronization();
showMessage(_("PDB STARTED, INITIALIZING IT")); showMessage(_("PDB STARTED, INITIALIZING IT"));
@@ -199,9 +200,7 @@ void PdbEngine::startEngine()
postCommand("execfile('" + dumperSourcePath + "pdumper.py')", postCommand("execfile('" + dumperSourcePath + "pdumper.py')",
CB(handleLoadDumper)); CB(handleLoadDumper));
setState(EngineStarted);
setState(InferiorStarting); setState(InferiorStarting);
emit startSuccessful();
showStatusMessage(tr("Running requested..."), 5000); showStatusMessage(tr("Running requested..."), 5000);
setState(InferiorRunningRequested); setState(InferiorRunningRequested);
setState(InferiorRunning); setState(InferiorRunning);

View File

@@ -251,18 +251,13 @@ void QmlEngine::startEngine()
m_proc.start(sp.executable, sp.processArgs); m_proc.start(sp.executable, sp.processArgs);
if (!m_proc.waitForStarted()) { if (!m_proc.waitForStarted()) {
setState(EngineStartFailed); notifyEngineStartFailed();
startFailed();
return; return;
} }
#endif #endif
setState(EngineStarted); notifyEngineStarted();
startSuccessful();
setState(InferiorStarting);
//m_frameRate = new CanvasFrameRate(0); //m_frameRate = new CanvasFrameRate(0);
//m_frameRate->show(); //m_frameRate->show();
setState(InferiorRunning);
} }
void QmlEngine::setupConnection() void QmlEngine::setupConnection()
@@ -300,12 +295,12 @@ void QmlEngine::setupConnection()
if (!m_conn->waitForConnected()) { if (!m_conn->waitForConnected()) {
qDebug() << "CONNECTION FAILED"; qDebug() << "CONNECTION FAILED";
setState(InferiorStartFailed); notifyEngineStartFailed();
startFailed();
return; return;
} }
#endif #endif
notifyEngineStarted();
qDebug() << "CONNECTION SUCCESSFUL"; qDebug() << "CONNECTION SUCCESSFUL";
setState(InferiorRunningRequested); setState(InferiorRunningRequested);
setState(InferiorRunning); setState(InferiorRunning);

View File

@@ -255,9 +255,10 @@ void ScriptEngine::startEngine()
if (!scriptFile.open(QIODevice::ReadOnly|QIODevice::Text)) { if (!scriptFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
showMessage(QString::fromLatin1("Cannot open %1: %2"). showMessage(QString::fromLatin1("Cannot open %1: %2").
arg(m_scriptFileName, scriptFile.errorString()), LogError); arg(m_scriptFileName, scriptFile.errorString()), LogError);
startFailed(); notifyEngineStartFailed();
return; return;
} }
notifyEngineStarted();
QTextStream stream(&scriptFile); QTextStream stream(&scriptFile);
m_scriptContents = stream.readAll(); m_scriptContents = stream.readAll();
scriptFile.close(); scriptFile.close();
@@ -266,7 +267,6 @@ void ScriptEngine::startEngine()
showStatusMessage(tr("Running requested..."), 5000); showStatusMessage(tr("Running requested..."), 5000);
showMessage(QLatin1String("Running: ") + m_scriptFileName, LogMisc); showMessage(QLatin1String("Running: ") + m_scriptFileName, LogMisc);
QTimer::singleShot(0, this, SLOT(runInferior())); QTimer::singleShot(0, this, SLOT(runInferior()));
startSuccessful();
} }
void ScriptEngine::continueInferior() void ScriptEngine::continueInferior()

View File

@@ -155,8 +155,10 @@ void TcfEngine::socketReadyRead()
void TcfEngine::socketConnected() void TcfEngine::socketConnected()
{ {
showStatusMessage("Socket connected."); showStatusMessage("Socket connected.");
m_socket->waitForConnected(2000); if (m_socket->waitForConnected(2000))
//sendCommand("Locator", "redirect", "ID"); notifyEngineStarted();
else
notifyEngineStartFailed();
} }
void TcfEngine::socketDisconnected() void TcfEngine::socketDisconnected()
@@ -211,7 +213,6 @@ void TcfEngine::startEngine()
const quint16 port = sp.remoteChannel.mid(pos + 1).toInt(); const quint16 port = sp.remoteChannel.mid(pos + 1).toInt();
//QTimer::singleShot(0, this, SLOT(runInferior())); //QTimer::singleShot(0, this, SLOT(runInferior()));
m_socket->connectToHost(host, port); m_socket->connectToHost(host, port);
emit startSuccessful();
} }
void TcfEngine::continueInferior() void TcfEngine::continueInferior()