Commit 9e7a4564 authored by hjk's avatar hjk
Browse files

debugger: refactor startup logic

parent f2c7d33f
...@@ -374,7 +374,7 @@ void CdbEngine::startupChecks() ...@@ -374,7 +374,7 @@ void CdbEngine::startupChecks()
syncDebuggerPaths(); syncDebuggerPaths();
} }
void CdbEngine::startEngine() void CdbEngine::setupEngine()
{ {
QTC_ASSERT(state() == EngineStarting, qDebug() << state()); QTC_ASSERT(state() == EngineStarting, qDebug() << state());
const DebuggerStartParameters &sp = startParameters(); const DebuggerStartParameters &sp = startParameters();
...@@ -385,8 +385,6 @@ void CdbEngine::startEngine() ...@@ -385,8 +385,6 @@ void CdbEngine::startEngine()
m_d->checkVersion(); m_d->checkVersion();
if (m_d->m_hDebuggeeProcess) { if (m_d->m_hDebuggeeProcess) {
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(DebuggerNotReady, Q_FUNC_INFO, __LINE__);
notifyEngineStartFailed(); notifyEngineStartFailed();
return; return;
} }
...@@ -394,8 +392,6 @@ void CdbEngine::startEngine() ...@@ -394,8 +392,6 @@ void CdbEngine::startEngine()
case AttachCore: case AttachCore:
case AttachToRemote: case AttachToRemote:
warning(QLatin1String("Internal error: Mode not supported.")); warning(QLatin1String("Internal error: Mode not supported."));
setState(EngineStartFailed, Q_FUNC_INFO, __LINE__);
setState(DebuggerNotReady, Q_FUNC_INFO, __LINE__);
notifyEngineStartFailed(); notifyEngineStartFailed();
break; break;
default: default:
...@@ -404,7 +400,6 @@ void CdbEngine::startEngine() ...@@ -404,7 +400,6 @@ void CdbEngine::startEngine()
m_d->m_mode = sp.startMode; m_d->m_mode = sp.startMode;
m_d->clearDisplay(); m_d->clearDisplay();
m_d->m_inferiorStartupComplete = false; m_d->m_inferiorStartupComplete = false;
setState(EngineStarted, Q_FUNC_INFO, __LINE__);
// Options // Options
QString errorMessage; QString errorMessage;
if (!m_d->setBreakOnThrow(theDebuggerBoolSetting(BreakOnThrow), &errorMessage)) if (!m_d->setBreakOnThrow(theDebuggerBoolSetting(BreakOnThrow), &errorMessage))
...@@ -426,10 +421,19 @@ void CdbEngine::startEngine() ...@@ -426,10 +421,19 @@ void CdbEngine::startEngine()
} }
} }
m_d->m_dumper->reset(dumperLibName, dumperEnabled); m_d->m_dumper->reset(dumperLibName, dumperEnabled);
notifyEngineStartOk();
}
setState(InferiorStarting, Q_FUNC_INFO, __LINE__); void CdbEngine::setupInferior()
showStatusMessage("Starting Debugger", messageTimeOut); {
QTC_ASSERT(state() == InferiorSettingUp, qDebug() << state());
notifyInferiorSetupOk();
}
void CdbEngine::runEngine()
{
QTC_ASSERT(m_state == InferiorSetupOk, qDebug() << m_state);
showStatusMessage("Starting Debugger", messageTimeOut);
bool rc = false; bool rc = false;
bool needWatchTimer = false; bool needWatchTimer = false;
m_d->clearForRun(); m_d->clearForRun();
...@@ -470,11 +474,10 @@ void CdbEngine::startEngine() ...@@ -470,11 +474,10 @@ void CdbEngine::startEngine()
if (rc) { if (rc) {
if (needWatchTimer) if (needWatchTimer)
m_d->startWatchTimer(); m_d->startWatchTimer();
notifyEngineStarted(); notifyInferiorSetupOk();
} else { } else {
warning(errorMessage); warning(errorMessage);
setState(InferiorStartFailed, Q_FUNC_INFO, __LINE__); notifyInferiorSetupFailed();
notifyEngineStartFailed();
} }
} }
......
...@@ -57,7 +57,9 @@ public: ...@@ -57,7 +57,9 @@ public:
virtual void shutdown(); virtual void shutdown();
virtual void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos); virtual void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
virtual void startEngine(); virtual void setupEngine();
virtual void setupInferior();
virtual void runEngine();
virtual void exitDebugger(); virtual void exitDebugger();
virtual void detachDebugger(); virtual void detachDebugger();
virtual void updateWatchData(const WatchData &data); virtual void updateWatchData(const WatchData &data);
......
...@@ -80,13 +80,13 @@ enum DebuggerState ...@@ -80,13 +80,13 @@ enum DebuggerState
DebuggerNotReady, // Debugger not started DebuggerNotReady, // Debugger not started
EngineStarting, // Engine starts EngineStarting, // Engine starts
EngineStarted,
EngineStartFailed, EngineStartFailed,
EngineStarted,
InferiorUnrunnable, // Used in the core dump adapter InferiorUnrunnable, // Used in the core dump adapter
InferiorStarting, InferiorSettingUp,
// InferiorStarted, // Use InferiorRunningRequested or InferiorStopped InferiorSetupFailed,
InferiorStartFailed, InferiorSetupOk,
InferiorRunningRequested, // Debuggee requested to run InferiorRunningRequested, // Debuggee requested to run
InferiorRunningRequested_Kill, // Debuggee requested to run, but want to kill it InferiorRunningRequested_Kill, // Debuggee requested to run, but want to kill it
......
...@@ -146,8 +146,9 @@ const char *DebuggerEngine::stateName(int s) ...@@ -146,8 +146,9 @@ const char *DebuggerEngine::stateName(int s)
SN(EngineStarting) SN(EngineStarting)
SN(EngineStarted) SN(EngineStarted)
SN(EngineStartFailed) SN(EngineStartFailed)
SN(InferiorStarting) SN(InferiorSettingUp)
SN(InferiorStartFailed) SN(InferiorSetupFailed)
SN(InferiorSetupOk)
SN(InferiorRunningRequested) SN(InferiorRunningRequested)
SN(InferiorRunningRequested_Kill) SN(InferiorRunningRequested_Kill)
SN(InferiorRunning) SN(InferiorRunning)
...@@ -224,6 +225,10 @@ public slots: ...@@ -224,6 +225,10 @@ public slots:
void breakpointEnableDisableMarginActionTriggered(); void breakpointEnableDisableMarginActionTriggered();
void handleContextMenuRequest(const QVariant &parameters); void handleContextMenuRequest(const QVariant &parameters);
void doSetupInferior();
void doRunEngine();
void doShutdown();
public: public:
DebuggerEngine *m_engine; // Not owned. DebuggerEngine *m_engine; // Not owned.
DebuggerRunControl *m_runControl; // Not owned. DebuggerRunControl *m_runControl; // Not owned.
...@@ -636,7 +641,7 @@ void DebuggerEngine::startDebugger(DebuggerRunControl *runControl) ...@@ -636,7 +641,7 @@ void DebuggerEngine::startDebugger(DebuggerRunControl *runControl)
->setEnabled(engineCapabilities & DisassemblerCapability); ->setEnabled(engineCapabilities & DisassemblerCapability);
setState(EngineStarting); setState(EngineStarting);
startEngine(); setupEngine();
} }
void DebuggerEngine::breakByFunctionMain() void DebuggerEngine::breakByFunctionMain()
...@@ -910,16 +915,18 @@ static bool isAllowedTransition(int from, int to) ...@@ -910,16 +915,18 @@ static bool isAllowedTransition(int from, int to)
case EngineStarting: case EngineStarting:
return to == EngineStarted || to == EngineStartFailed; return to == EngineStarted || to == EngineStartFailed;
case EngineStarted:
return to == InferiorStarting || to == EngineShuttingDown;
case EngineStartFailed: case EngineStartFailed:
return to == DebuggerNotReady; return to == DebuggerNotReady;
case EngineStarted:
return to == InferiorSettingUp || to == EngineShuttingDown;
case InferiorStarting: case InferiorSettingUp:
return to == InferiorRunningRequested || to == InferiorStopped return to == InferiorSetupOk || to == InferiorSetupFailed;
|| to == InferiorStartFailed || to == InferiorUnrunnable; case InferiorSetupFailed:
case InferiorStartFailed:
return to == EngineShuttingDown; return to == EngineShuttingDown;
case InferiorSetupOk:
return to == InferiorRunningRequested || to == InferiorStopped
|| to == InferiorUnrunnable;
case InferiorRunningRequested: case InferiorRunningRequested:
return to == InferiorRunning || to == InferiorStopped return to == InferiorRunning || to == InferiorStopped
...@@ -956,16 +963,66 @@ static bool isAllowedTransition(int from, int to) ...@@ -956,16 +963,66 @@ static bool isAllowedTransition(int from, int to)
return false; return false;
} }
void DebuggerEngine::notifyEngineStarted() void DebuggerEngine::notifyEngineStartFailed()
{
QTC_ASSERT(state() == EngineStarting, qDebug() << state());
setState(EngineStartFailed);
d->m_runControl->debuggingFinished();
d->m_runControl->startFailed();
QTimer::singleShot(0, this, SLOT(doShutdown()));
}
void DebuggerEngine::notifyEngineStartOk()
{ {
QTC_ASSERT(state() == EngineStarting, /**/); QTC_ASSERT(state() == EngineStarting, qDebug() << state());
setState(EngineStarted); setState(EngineStarted);
d->m_runControl->startSuccessful();
QTimer::singleShot(0, d, SLOT(doSetupInferior()));
} }
void DebuggerEngine::notifyEngineStartFailed() void DebuggerEnginePrivate::doSetupInferior()
{ {
QTC_ASSERT(state() == EngineStarting, /**/); QTC_ASSERT(m_state == EngineStarted, qDebug() << m_state);
setState(EngineStartFailed); m_engine->setState(InferiorSettingUp);
m_engine->setupInferior();
}
// Default implemention, can be overridden.
void DebuggerEngine::setupInferior()
{
QTC_ASSERT(state() == EngineStarted, qDebug() << state());
notifyInferiorSetupOk();
}
void DebuggerEngine::notifyInferiorSetupFailed()
{
QTC_ASSERT(state() == InferiorSettingUp, qDebug() << state());
setState(InferiorSetupFailed);
QTimer::singleShot(0, d, SLOT(doShutdown()));
}
void DebuggerEngine::notifyInferiorSetupOk()
{
QTC_ASSERT(state() == InferiorSettingUp, qDebug() << state());
setState(InferiorSetupOk);
QTimer::singleShot(0, d, SLOT(doRunEngine()));
}
void DebuggerEnginePrivate::doRunEngine()
{
QTC_ASSERT(m_state == InferiorSetupOk, qDebug() << m_state);
m_engine->runEngine();
}
// Default implemention, can be overridden.
void DebuggerEngine::runEngine()
{
QTC_ASSERT(state() == InferiorSetupOk, qDebug() << state());
}
void DebuggerEnginePrivate::doShutdown()
{
m_engine->shutdown();
} }
void DebuggerEngine::setState(DebuggerState state, bool forced) void DebuggerEngine::setState(DebuggerState state, bool forced)
...@@ -987,11 +1044,6 @@ void DebuggerEngine::setState(DebuggerState state, bool forced) ...@@ -987,11 +1044,6 @@ void DebuggerEngine::setState(DebuggerState state, bool forced)
if (state != oldState) { if (state != oldState) {
if (state == DebuggerNotReady) { if (state == DebuggerNotReady) {
d->m_runControl->debuggingFinished(); d->m_runControl->debuggingFinished();
} else if (state == EngineStarted) {
d->m_runControl->startSuccessful();
} else if (state == EngineStartFailed) {
d->m_runControl->debuggingFinished();
d->m_runControl->startFailed();
} }
} }
} }
...@@ -1004,7 +1056,7 @@ bool DebuggerEngine::debuggerActionsEnabled() const ...@@ -1004,7 +1056,7 @@ bool DebuggerEngine::debuggerActionsEnabled() const
bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state) bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state)
{ {
switch (state) { switch (state) {
case InferiorStarting: case InferiorSettingUp:
case InferiorRunningRequested: case InferiorRunningRequested:
case InferiorRunning: case InferiorRunning:
case InferiorUnrunnable: case InferiorUnrunnable:
...@@ -1015,7 +1067,8 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state) ...@@ -1015,7 +1067,8 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state)
case EngineStarting: case EngineStarting:
case EngineStarted: case EngineStarted:
case EngineStartFailed: case EngineStartFailed:
case InferiorStartFailed: case InferiorSetupOk:
case InferiorSetupFailed:
case InferiorRunningRequested_Kill: case InferiorRunningRequested_Kill:
case InferiorStopping_Kill: case InferiorStopping_Kill:
case InferiorStopFailed: case InferiorStopFailed:
...@@ -1023,7 +1076,7 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state) ...@@ -1023,7 +1076,7 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state)
case InferiorShutDown: case InferiorShutDown:
case InferiorShutdownFailed: case InferiorShutdownFailed:
case EngineShuttingDown: case EngineShuttingDown:
break; return false;
} }
return false; return false;
} }
......
...@@ -125,11 +125,48 @@ public: ...@@ -125,11 +125,48 @@ public:
virtual void setToolTipExpression(const QPoint & /* mousePos */, virtual void setToolTipExpression(const QPoint & /* mousePos */,
TextEditor::ITextEditor * /* editor */, int /* cursorPos */) { } TextEditor::ITextEditor * /* editor */, int /* cursorPos */) { }
void initializeFromTemplate(DebuggerEngine *other); void initializeFromTemplate(DebuggerEngine *other);
virtual void updateWatchData(const WatchData & /* data */) { }
void startDebugger(DebuggerRunControl *runControl); void startDebugger(DebuggerRunControl *runControl);
virtual void startEngine() {} virtual bool isSessionEngine() const { return false; }
virtual void watchPoint(const QPoint &) {}
virtual void fetchMemory(MemoryViewAgent *, QObject *,
quint64 addr, quint64 length);
virtual void fetchDisassembler(DisassemblerViewAgent *) {}
virtual void activateFrame(int index) { Q_UNUSED(index); }
virtual void reloadModules() {}
virtual void loadSymbols(const QString &moduleName)
{ Q_UNUSED(moduleName); }
virtual void loadAllSymbols() {}
virtual void requestModuleSymbols(const QString &moduleName)
{ Q_UNUSED(moduleName); }
virtual void reloadRegisters() {}
virtual void reloadSourceFiles() {}
virtual void reloadFullStack() {}
virtual void setRegisterValue(int regnr, const QString &value);
virtual void addOptionPages(QList<Core::IOptionsPage*> *) const {}
virtual unsigned debuggerCapabilities() const { return 0; }
virtual bool isSynchroneous() const { return false; }
virtual QString qtNamespace() const { return QString(); }
virtual void makeSnapshot() {}
virtual void activateSnapshot(int index) { Q_UNUSED(index); }
virtual void attemptBreakpointSynchronization() {}
virtual void selectThread(int index) { Q_UNUSED(index); }
virtual void assignValueInDebugger(const QString &expr, const QString &value)
{ Q_UNUSED(expr); Q_UNUSED(value); }
protected:
virtual void setupEngine() {}
virtual void exitDebugger() {} virtual void exitDebugger() {}
virtual void detachDebugger() {} virtual void detachDebugger() {}
virtual void updateWatchData(const WatchData & /* data */) { }
virtual void executeStep() {} virtual void executeStep() {}
virtual void executeStepOut() {} virtual void executeStepOut() {}
virtual void executeNext() {} virtual void executeNext() {}
...@@ -146,43 +183,11 @@ public: ...@@ -146,43 +183,11 @@ public:
{ Q_UNUSED(functionName); } { Q_UNUSED(functionName); }
virtual void executeJumpToLine(const QString &fileName, int lineNumber) virtual void executeJumpToLine(const QString &fileName, int lineNumber)
{ Q_UNUSED(fileName); Q_UNUSED(lineNumber); } { Q_UNUSED(fileName); Q_UNUSED(lineNumber); }
virtual void assignValueInDebugger(const QString &expr, const QString &value)
{ Q_UNUSED(expr); Q_UNUSED(value); }
virtual void executeDebuggerCommand(const QString &command) virtual void executeDebuggerCommand(const QString &command)
{ Q_UNUSED(command); } { Q_UNUSED(command); }
virtual void activateFrame(int index) { Q_UNUSED(index); }
virtual void frameUp(); virtual void frameUp();
virtual void frameDown(); virtual void frameDown();
virtual void selectThread(int index) { Q_UNUSED(index); }
virtual void makeSnapshot() {}
virtual void activateSnapshot(int index) { Q_UNUSED(index); }
virtual void attemptBreakpointSynchronization() {}
virtual void reloadModules() {}
virtual void loadSymbols(const QString &moduleName)
{ Q_UNUSED(moduleName); }
virtual void loadAllSymbols() {}
virtual void requestModuleSymbols(const QString &moduleName)
{ Q_UNUSED(moduleName); }
virtual void reloadRegisters() {}
virtual void reloadSourceFiles() {}
virtual void reloadFullStack() {}
virtual void watchPoint(const QPoint &) {}
virtual void fetchMemory(MemoryViewAgent *, QObject *,
quint64 addr, quint64 length);
virtual void fetchDisassembler(DisassemblerViewAgent *) {}
virtual void setRegisterValue(int regnr, const QString &value);
virtual void addOptionPages(QList<Core::IOptionsPage*> *) const {}
virtual unsigned debuggerCapabilities() const { return 0; }
virtual bool isSynchroneous() const { return false; }
virtual bool isSessionEngine() const { return false; }
virtual QString qtNamespace() const { return QString(); }
public slots: public slots:
// Convenience // Convenience
...@@ -252,9 +257,15 @@ public slots: ...@@ -252,9 +257,15 @@ public slots:
virtual void quitDebugger() { exitDebugger(); } // called by DebuggerRunControl virtual void quitDebugger() { exitDebugger(); } // called by DebuggerRunControl
protected: protected:
void notifyEngineStarted(); void notifyEngineStartOk();
void notifyEngineStartFailed(); void notifyEngineStartFailed();
void notifyInferiorSetupOk();
void notifyInferiorSetupFailed();
virtual void setupInferior();
virtual void runEngine();
//private: // FIXME. State transitions //private: // FIXME. State transitions
void setState(DebuggerState state, bool forced = false); void setState(DebuggerState state, bool forced = false);
...@@ -264,6 +275,7 @@ private: ...@@ -264,6 +275,7 @@ private:
void executeJumpToLine(); void executeJumpToLine();
void addToWatchWindow(); void addToWatchWindow();
friend class DebuggerEnginePrivate;
DebuggerEnginePrivate *d; DebuggerEnginePrivate *d;
}; };
......
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
// //
// Transitions marked by '---' are done in the individual engines. // Transitions marked by '---' are done in the individual engines.
// Transitions marked by '+-+' are done in the base DebuggerEngine. // Transitions marked by '+-+' are done in the base DebuggerEngine.
// The GdbEngine->startEngine() function is described in more detail below. // The GdbEngine->setupEngine() function is described in more detail below.
// //
// DebuggerNotReady // DebuggerNotReady
// + // +
...@@ -170,7 +170,11 @@ ...@@ -170,7 +170,11 @@
// EngineStarting // EngineStarting
// + // +
// + // +
// (calls *Engine->startEngine()) // (calls *Engine->setupEngine())
// | |
// {notify- {notify-
// Engine- Engine-
// StartOk} StartFailed}
// | | // | |
// | `---> EngineStartFailed // | `---> EngineStartFailed
// | + // | +
...@@ -182,14 +186,18 @@ ...@@ -182,14 +186,18 @@
// + // +
// [calls RunControl->StartSuccessful] // [calls RunControl->StartSuccessful]
// + // +
// (calls *Engine->startInferior()) // (calls *Engine->setupInferior())
// | |
// {notify- {notify-
// Inferior- Inferior-
// SetupOk} SetupFailed}
// | | // | |
// | ` ----> InferiorStartFailed +-+-+-+->. // | ` ----> InferiorSetupFailed +-+-+-+->.
// | + // | +
// v + // v +
// InferiorStarted + // InferiorSetupOk +
// + // + +
// (calls *Engine->runInferior()) + // (calls *Engine->runEngine()) +
// | + // | +
// (core) | (attach) (term) (remote) (script) + // (core) | (attach) (term) (remote) (script) +
// .-----------------<-|->------------------. + // .-----------------<-|->------------------. +
...@@ -219,7 +227,7 @@ ...@@ -219,7 +227,7 @@
// Transitions marked by '---' are done in the individual adapters. // Transitions marked by '---' are done in the individual adapters.
// Transitions marked by '+-+' are done in the GdbEngine. // Transitions marked by '+-+' are done in the GdbEngine.
// GdbEngine::startEngine() // GdbEngine::setupEngine()
// + // +
// + // +
// (calls *Adapter->startAdapter()) // (calls *Adapter->startAdapter())
...@@ -2681,7 +2689,7 @@ bool DebuggerListener::coreAboutToClose() ...@@ -2681,7 +2689,7 @@ bool DebuggerListener::coreAboutToClose()
case EngineStarted: // Most importantly, terminating a running case EngineStarted: // Most importantly, terminating a running
case EngineStartFailed: // debuggee can cause problems. case EngineStartFailed: // debuggee can cause problems.
case InferiorUnrunnable: case InferiorUnrunnable:
case InferiorStartFailed: case InferiorSetupFailed:
case InferiorStopped: case InferiorStopped:
case InferiorShutDown: case InferiorShutDown:
cleanTermination = true; cleanTermination = true;
......
...@@ -52,7 +52,7 @@ void AbstractGdbAdapter::shutdown() ...@@ -52,7 +52,7 @@ void AbstractGdbAdapter::shutdown()
{ {
} }
void AbstractGdbAdapter::startInferiorPhase2() void AbstractGdbAdapter::runAdapter()
{ {
qDebug() << "START INFERIOR PHASE 2"; qDebug() << "START INFERIOR PH