Commit 36ec37b2 authored by hjk's avatar hjk

Debugger: Streamline ramping down

There were only two used target states, and in case of mixed
debugging all parts of the machinery better agree on the
direction. So one bool in the (shared) runTool is sufficient.

Change-Id: Iffbf1651b82dde707cfc37d8da9d3da573b34b76
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 5e84af54
......@@ -838,7 +838,7 @@ void CdbEngine::shutdownEngine()
void CdbEngine::abortDebugger()
{
if (targetState() == DebuggerFinished) {
if (isDying()) {
// We already tried. Try harder.
showMessage("ABORTING DEBUGGER. SECOND TIME.");
m_process.kill();
......@@ -1834,7 +1834,7 @@ unsigned CdbEngine::examineStopReason(const GdbMi &stopReason,
{
// Report stop reason (GDBMI)
unsigned rc = 0;
if (targetState() == DebuggerFinished)
if (isDying())
rc |= StopShutdownInProgress;
if (debug)
qDebug("%s", qPrintable(stopReason.toString(true, 4)));
......
......@@ -348,9 +348,6 @@ public:
// The state we had before something unexpected happend.
DebuggerState m_lastGoodState = DebuggerNotReady;
// The state we are aiming for.
DebuggerState m_targetState = DebuggerNotReady;
// State of RemoteSetup signal/slots.
RemoteSetupState m_remoteSetupState = RemoteSetupNone;
......@@ -451,11 +448,6 @@ void DebuggerEngine::doUpdateLocals(const UpdateParameters &)
{
}
void DebuggerEngine::setTargetState(DebuggerState state)
{
d->m_targetState = state;
}
ModulesHandler *DebuggerEngine::modulesHandler() const
{
return d->m_masterEngine
......@@ -576,7 +568,6 @@ void DebuggerEngine::start()
QTC_ASSERT(state() == DebuggerNotReady || state() == DebuggerFinished,
qDebug() << state());
d->m_lastGoodState = DebuggerNotReady;
d->m_targetState = DebuggerNotReady;
d->m_progress.setProgressValue(200);
d->m_terminal.setup();
......@@ -678,11 +669,6 @@ DebuggerState DebuggerEngine::lastGoodState() const
return d->m_lastGoodState;
}
DebuggerState DebuggerEngine::targetState() const
{
return d->m_targetState;
}
static bool isAllowedTransition(DebuggerState from, DebuggerState to)
{
switch (from) {
......@@ -795,8 +781,10 @@ void DebuggerEngine::notifyEngineSetupOk()
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << this << state());
setState(EngineSetupOk);
d->queueSetupInferior();
if (isMasterEngine() && runTool()) {
runTool()->reportStarted();
d->queueSetupInferior();
}
}
void DebuggerEngine::setupSlaveInferior()
......@@ -1045,7 +1033,6 @@ void DebuggerEnginePrivate::doShutdownInferior()
//QTC_ASSERT(isMasterEngine(), return);
QTC_ASSERT(state() == InferiorShutdownRequested, qDebug() << m_engine << state());
resetLocation();
m_targetState = DebuggerFinished;
m_engine->showMessage("CALL: SHUTDOWN INFERIOR");
m_engine->shutdownInferior();
}
......@@ -1074,7 +1061,7 @@ void DebuggerEngine::notifyInferiorIll()
showMessage("NOTE: INFERIOR ILL");
// This can be issued in almost any state. The inferior could still be
// alive as some previous notifications might have been bogus.
d->m_targetState = DebuggerFinished;
runTool()->startDying();
d->m_lastGoodState = d->m_state;
if (state() == InferiorRunRequested) {
// We asked for running, but did not see a response.
......@@ -1097,7 +1084,7 @@ void DebuggerEnginePrivate::doShutdownEngine()
{
QTC_ASSERT(isMasterEngine(), qDebug() << m_engine; return);
QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << m_engine << state());
m_targetState = DebuggerFinished;
runTool()->startDying();
m_engine->showMessage("CALL: SHUTDOWN ENGINE");
m_engine->shutdownEngine();
}
......@@ -1160,7 +1147,7 @@ void DebuggerEngine::notifyEngineIll()
CALLGRIND_DUMP_STATS;
#endif
showMessage("NOTE: ENGINE ILL ******");
d->m_targetState = DebuggerFinished;
runTool()->startDying();
d->m_lastGoodState = d->m_state;
switch (state()) {
case InferiorRunRequested:
......@@ -1288,12 +1275,6 @@ void DebuggerEngine::setState(DebuggerState state, bool forced)
DebuggerToolTipManager::registerEngine(this);
}
if (state == InferiorUnrunnable || state == InferiorRunOk) {
// FIXME: Called again for combined engine.
if (isMasterEngine() && runTool() && !runTool()->runControl()->isRunning())
runTool()->reportStarted();
}
if (state == DebuggerFinished) {
// Give up ownership on claimed breakpoints.
foreach (Breakpoint bp, breakHandler()->engineBreakpoints(this))
......@@ -1473,7 +1454,8 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
void DebuggerEngine::quitDebugger()
{
showMessage(QString("QUIT DEBUGGER REQUESTED IN STATE %1").arg(state()));
d->m_targetState = DebuggerFinished;
QTC_ASSERT(runTool(), return);
runTool()->startDying();
switch (state()) {
case InferiorStopOk:
case InferiorStopFailed:
......@@ -1768,13 +1750,6 @@ void DebuggerEngine::detachDebugger()
{
}
void DebuggerEngine::exitDebugger()
{
QTC_ASSERT(d->m_state == InferiorStopOk || d->m_state == InferiorUnrunnable
|| d->m_state == InferiorRunOk, qDebug() << d->m_state);
quitDebugger();
}
void DebuggerEngine::executeStep()
{
}
......@@ -1831,7 +1806,7 @@ BreakHandler *DebuggerEngine::breakHandler() const
bool DebuggerEngine::isDying() const
{
return targetState() == DebuggerFinished;
return !runTool() || runTool()->isDying();
}
QString DebuggerEngine::msgStopped(const QString &reason)
......
......@@ -302,7 +302,6 @@ public:
DebuggerState state() const;
DebuggerState lastGoodState() const;
DebuggerState targetState() const;
bool isDying() const;
static QString stateName(int s);
......@@ -319,9 +318,8 @@ public:
virtual void resetLocation();
virtual void gotoLocation(const Internal::Location &location);
Q_SLOT virtual void quitDebugger(); // called by DebuggerRunControl
virtual void exitDebugger(); // called by DebuggerRunControl
virtual void abortDebugger(); // called by DebuggerPlugin
virtual void quitDebugger(); // called when pressing the stop button
virtual void abortDebugger(); // called from the debug menu action
void updateViews();
bool isSlaveEngine() const;
......
......@@ -930,11 +930,10 @@ public:
currentEngine()->watchHandler()->watchVariable(exp);
}
void handleExecExit()
void stopDebugger()
{
QTC_ASSERT(dd->m_currentRunTool, return);
return dd->m_currentRunTool->runControl()->initiateStop();
//currentEngine()->exitDebugger();
dd->m_currentRunTool->runControl()->initiateStop();
}
void handleFrameDown()
......@@ -1416,7 +1415,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
act = m_exitAction = new QAction(tr("Stop Debugger"), this);
act->setIcon(Icons::DEBUG_EXIT_SMALL.icon());
connect(act, &QAction::triggered, this, &DebuggerPluginPrivate::handleExecExit);
connect(act, &QAction::triggered, this, &DebuggerPluginPrivate::stopDebugger);
act = m_interruptAction = new QAction(tr("Interrupt"), this);
act->setIcon(visibleStartIcon(Id(Constants::INTERRUPT), false));
......@@ -2828,10 +2827,8 @@ void DebuggerPluginPrivate::coreShutdown()
{
m_shuttingDown = true;
if (currentEngine()) {
if (currentEngine()->state() != Debugger::DebuggerNotReady) {
currentEngine()->setTargetState(Debugger::DebuggerFinished);
if (currentEngine()->state() != Debugger::DebuggerNotReady)
currentEngine()->abortDebugger();
}
}
}
......@@ -3044,8 +3041,9 @@ void DebuggerPluginPrivate::extensionsInitialized()
DebuggerEngine *currentEngine()
{
QTC_ASSERT(dd->m_currentRunTool, return dd->dummyEngine());
DebuggerEngine *engine = dd->m_currentRunTool->activeEngine();
DebuggerEngine *engine = nullptr;
if (dd->m_currentRunTool)
engine = dd->m_currentRunTool->activeEngine();
return engine ? engine : dd->dummyEngine();
}
......@@ -3369,7 +3367,8 @@ void DebuggerPluginPrivate::updateUiForTarget(Target *target)
void DebuggerPluginPrivate::updateActiveLanguages()
{
QTC_ASSERT(dd->m_currentRunTool, return);
if (!dd->m_currentRunTool)
return;
const DebuggerLanguages languages = dd->m_currentRunTool->runParameters().languages;
// Id perspective = (languages & QmlLanguage) && !(languages & CppLanguage)
// ? QmlPerspectiveId : CppPerspectiveId;
......
......@@ -176,7 +176,8 @@ void DebuggerRunTool::notifyEngineRemoteSetupFinished(const RemoteSetupResult &r
void DebuggerRunTool::stop()
{
m_engine->exitDebugger();
m_isDying = true;
m_engine->quitDebugger();
}
void DebuggerRunTool::onTargetFailure()
......@@ -223,6 +224,7 @@ void DebuggerRunTool::notifyInferiorExited()
void DebuggerRunTool::quitDebugger()
{
m_isDying = true;
m_engine->quitDebugger();
}
......
......@@ -78,6 +78,8 @@ public:
Internal::DebuggerRunParameters &runParameters();
const Internal::DebuggerRunParameters &runParameters() const;
void startDying() { m_isDying = true; }
bool isDying() const { return m_isDying; }
bool isCppDebugging() const { return m_isCppDebugging; }
bool isQmlDebugging() const { return m_isQmlDebugging; }
int portsUsedByDebugger() const;
......@@ -94,6 +96,7 @@ private:
Internal::DebuggerEngine *m_engine = nullptr; // Master engine
Internal::DebuggerRunParameters m_runParameters;
QStringList m_errors;
bool m_isDying = false;
const bool m_isCppDebugging;
const bool m_isQmlDebugging;
};
......
......@@ -272,7 +272,7 @@ QString GdbEngine::errorMessage(QProcess::ProcessError error)
"permissions to invoke the program.\n%2")
.arg(runParameters().debugger.executable, m_gdbProc.errorString());
case QProcess::Crashed:
if (targetState() == DebuggerFinished)
if (isDying())
return tr("The gdb process crashed some time after starting "
"successfully.");
else
......@@ -4085,7 +4085,7 @@ void GdbEngine::handleGdbFinished(int exitCode, QProcess::ExitStatus exitStatus)
void GdbEngine::abortDebugger()
{
if (targetState() == DebuggerFinished) {
if (isDying()) {
// We already tried. Try harder.
showMessage("ABORTING DEBUGGER. SECOND TIME.");
m_gdbProc.kill();
......
......@@ -163,7 +163,7 @@ void LldbEngine::shutdownEngine()
void LldbEngine::abortDebugger()
{
if (targetState() == DebuggerFinished) {
if (isDying()) {
// We already tried. Try harder.
showMessage("ABORTING DEBUGGER. SECOND TIME.");
m_lldbProc.kill();
......
......@@ -68,7 +68,7 @@ QmlCppEngine::QmlCppEngine(DebuggerEngine *cppEngine, bool useTerminal)
m_qmlEngine->setMasterEngine(this);
m_cppEngine = cppEngine;
m_cppEngine->setMasterEngine(this);
setActiveEngine(m_cppEngine);
m_activeEngine = m_cppEngine;
}
QmlCppEngine::~QmlCppEngine()
......@@ -271,11 +271,6 @@ void QmlCppEngine::assignValueInDebugger(WatchItem *item,
void QmlCppEngine::notifyInferiorIll()
{
//This will eventually shutdown the engine
//Set final state to avoid quitDebugger() being called
//after this call
setTargetState(DebuggerFinished);
//Call notifyInferiorIll of cpp engine
//as qml engine will follow state transitions
//of cpp engine
......@@ -378,7 +373,7 @@ void QmlCppEngine::executeDebuggerCommand(const QString &command, DebuggerLangua
void QmlCppEngine::setupEngine()
{
EDEBUG("\nMASTER SETUP ENGINE");
setActiveEngine(m_cppEngine);
m_activeEngine = m_cppEngine;
m_qmlEngine->setupSlaveEngine();
m_cppEngine->setupSlaveEngine();
......@@ -474,6 +469,7 @@ void QmlCppEngine::slaveEngineStateChanged
DebuggerEngine *otherEngine = (slaveEngine == m_cppEngine)
? m_qmlEngine : m_cppEngine;
QTC_ASSERT(otherEngine, return);
QTC_CHECK(otherEngine != slaveEngine);
if (debug) {
......@@ -584,9 +580,11 @@ void QmlCppEngine::slaveEngineStateChanged
if (state() == InferiorRunOk) {
setState(InferiorStopRequested);
} else if (state() == InferiorStopOk) {
notifyInferiorRunRequested();
notifyInferiorRunOk();
setState(InferiorStopRequested);
if (!isDying()) {
notifyInferiorRunRequested();
notifyInferiorRunOk();
setState(InferiorStopRequested);
}
} else if (state() == InferiorRunRequested) {
notifyInferiorRunOk();
setState(InferiorStopRequested);
......@@ -606,7 +604,7 @@ void QmlCppEngine::slaveEngineStateChanged
|| state() == InferiorStopOk, qDebug() << state());
// Just to make sure, we're shutting down anyway ...
setActiveEngine(m_cppEngine);
m_activeEngine = m_cppEngine;
if (state() == InferiorStopRequested)
setState(InferiorStopOk);
......
......@@ -132,9 +132,9 @@ private:
void setActiveEngine(DebuggerEngine *engine);
private:
QmlEngine *m_qmlEngine;
DebuggerEngine *m_cppEngine;
DebuggerEngine *m_activeEngine;
QPointer<QmlEngine> m_qmlEngine;
QPointer<DebuggerEngine> m_cppEngine;
QPointer<DebuggerEngine> m_activeEngine;
};
} // namespace Internal
......
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