Commit 85243e19 authored by hjk's avatar hjk

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

parent e721b9f7
......@@ -387,7 +387,7 @@ void CdbEngine::startEngine()
warning(QLatin1String("Internal error: Attempt to start debugger while another process is being debugged."));
setState(EngineStartFailed, Q_FUNC_INFO, __LINE__);
setState(DebuggerNotReady, Q_FUNC_INFO, __LINE__);
emit startFailed();
notifyEngineStartFailed();
return;
}
switch (sp.startMode) {
......@@ -396,7 +396,7 @@ void CdbEngine::startEngine()
warning(QLatin1String("Internal error: Mode not supported."));
setState(EngineStartFailed, Q_FUNC_INFO, __LINE__);
setState(DebuggerNotReady, Q_FUNC_INFO, __LINE__);
emit startFailed();
notifyEngineStartFailed();
break;
default:
break;
......@@ -470,11 +470,11 @@ void CdbEngine::startEngine()
if (rc) {
if (needWatchTimer)
m_d->startWatchTimer();
startSuccessful();
notifyEngineStarted();
} else {
warning(errorMessage);
setState(InferiorStartFailed, Q_FUNC_INFO, __LINE__);
startFailed();
notifyEngineStartFailed();
}
}
......
......@@ -608,12 +608,12 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
void DebuggerEngine::startDebugger(DebuggerRunControl *runControl)
{
QTC_ASSERT(runControl, startFailed(); return);
QTC_ASSERT(!d->m_runControl, startFailed(); return);
QTC_ASSERT(runControl, notifyEngineStartFailed(); return);
QTC_ASSERT(!d->m_runControl, notifyEngineStartFailed(); return);
DebuggerEngine *sessionTemplate = plugin()->sessionTemplate();
QTC_ASSERT(sessionTemplate, startFailed(); return);
QTC_ASSERT(sessionTemplate != this, startFailed(); return);
QTC_ASSERT(sessionTemplate, notifyEngineStartFailed(); return);
QTC_ASSERT(sessionTemplate != this, notifyEngineStartFailed(); return);
breakHandler()->initializeFromTemplate(sessionTemplate->breakHandler());
watchHandler()->initializeFromTemplate(sessionTemplate->watchHandler());
......@@ -956,6 +956,18 @@ static bool isAllowedTransition(int from, int to)
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)
{
//qDebug() << "STATUS CHANGE: FROM " << stateName(d->m_state)
......@@ -972,8 +984,16 @@ void DebuggerEngine::setState(DebuggerState state, bool forced)
showMessage(msg, LogDebug);
plugin()->updateState(this);
if (state != oldState && state == DebuggerNotReady)
d->m_runControl->debuggingFinished();
if (state != oldState) {
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
......@@ -1008,18 +1028,6 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state)
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)
{
if (d->m_inferiorPid == pid)
......
......@@ -248,13 +248,13 @@ public slots:
void openFile(const QString &fileName, int lineNumber = -1);
void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);
void gotoLocation(const StackFrame &frame, bool setMarker);
void startSuccessful();
void startFailed();
void raiseApplication();
virtual void quitDebugger() { exitDebugger(); } // called by DebuggerRunControl
protected:
void setState(DebuggerState state, bool forced = false);
void notifyEngineStarted();
void notifyEngineStartFailed();
private:
void executeRunToLine();
......
......@@ -4205,7 +4205,7 @@ void GdbEngine::handleAdapterStartFailed(const QString &msg, const QString &sett
void GdbEngine::handleAdapterStarted()
{
setState(EngineStarted);
notifyEngineStarted();
if (m_progress)
m_progress->setProgressValue(25);
showMessage(_("ADAPTER SUCCESSFULLY STARTED"));
......@@ -4217,7 +4217,6 @@ void GdbEngine::handleAdapterStarted()
void GdbEngine::handleInferiorPrepared()
{
startSuccessful();
const QByteArray qtInstallPath = startParameters().qtInstallPath.toLocal8Bit();
if (!qtInstallPath.isEmpty()) {
QByteArray qtBuildPath;
......
......@@ -148,7 +148,7 @@ void PdbEngine::startEngine()
//showMessage("STARTING " +m_scriptFileName + "FAILED");
showMessage(QString::fromLatin1("Cannot open %1: %2").
arg(m_scriptFileName, scriptFile.errorString()), LogError);
startFailed();
notifyEngineStartFailed();
return;
}
m_pdbProc.disconnect(); // From any previous runs
......@@ -188,9 +188,10 @@ void PdbEngine::startEngine()
Core::ICore::instance()->showWarningWithOptions(title, msg);
}
shutdown();
startFailed();
notifyEngineStartFailed();
return;
}
notifyEngineStarted();
attemptBreakpointSynchronization();
showMessage(_("PDB STARTED, INITIALIZING IT"));
......@@ -199,9 +200,7 @@ void PdbEngine::startEngine()
postCommand("execfile('" + dumperSourcePath + "pdumper.py')",
CB(handleLoadDumper));
setState(EngineStarted);
setState(InferiorStarting);
emit startSuccessful();
showStatusMessage(tr("Running requested..."), 5000);
setState(InferiorRunningRequested);
setState(InferiorRunning);
......
......@@ -251,18 +251,13 @@ void QmlEngine::startEngine()
m_proc.start(sp.executable, sp.processArgs);
if (!m_proc.waitForStarted()) {
setState(EngineStartFailed);
startFailed();
notifyEngineStartFailed();
return;
}
#endif
setState(EngineStarted);
startSuccessful();
setState(InferiorStarting);
notifyEngineStarted();
//m_frameRate = new CanvasFrameRate(0);
//m_frameRate->show();
setState(InferiorRunning);
}
void QmlEngine::setupConnection()
......@@ -300,12 +295,12 @@ void QmlEngine::setupConnection()
if (!m_conn->waitForConnected()) {
qDebug() << "CONNECTION FAILED";
setState(InferiorStartFailed);
startFailed();
notifyEngineStartFailed();
return;
}
#endif
notifyEngineStarted();
qDebug() << "CONNECTION SUCCESSFUL";
setState(InferiorRunningRequested);
setState(InferiorRunning);
......
......@@ -255,9 +255,10 @@ void ScriptEngine::startEngine()
if (!scriptFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
showMessage(QString::fromLatin1("Cannot open %1: %2").
arg(m_scriptFileName, scriptFile.errorString()), LogError);
startFailed();
notifyEngineStartFailed();
return;
}
notifyEngineStarted();
QTextStream stream(&scriptFile);
m_scriptContents = stream.readAll();
scriptFile.close();
......@@ -266,7 +267,6 @@ void ScriptEngine::startEngine()
showStatusMessage(tr("Running requested..."), 5000);
showMessage(QLatin1String("Running: ") + m_scriptFileName, LogMisc);
QTimer::singleShot(0, this, SLOT(runInferior()));
startSuccessful();
}
void ScriptEngine::continueInferior()
......
......@@ -155,8 +155,10 @@ void TcfEngine::socketReadyRead()
void TcfEngine::socketConnected()
{
showStatusMessage("Socket connected.");
m_socket->waitForConnected(2000);
//sendCommand("Locator", "redirect", "ID");
if (m_socket->waitForConnected(2000))
notifyEngineStarted();
else
notifyEngineStartFailed();
}
void TcfEngine::socketDisconnected()
......@@ -211,7 +213,6 @@ void TcfEngine::startEngine()
const quint16 port = sp.remoteChannel.mid(pos + 1).toInt();
//QTimer::singleShot(0, this, SLOT(runInferior()));
m_socket->connectToHost(host, port);
emit startSuccessful();
}
void TcfEngine::continueInferior()
......
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