Commit 063d13e0 authored by hjk's avatar hjk

debugger: work on general shutdown handling

parent 6b510cb4
This diff is collapsed.
......@@ -227,6 +227,7 @@ private:
virtual void notifyInferiorRunning() = 0;
virtual void notifyInferiorExited() = 0;
virtual void notifyInferiorPidChanged(qint64) = 0;
virtual void notifyEngineFinished() {} // FIXME: make pure
virtual ModulesHandler *modulesHandler() = 0;
virtual BreakHandler *breakHandler() = 0;
......@@ -374,6 +375,7 @@ private:
void notifyInferiorRunning();
void notifyInferiorExited();
void notifyInferiorPidChanged(qint64);
void notifyEngineFinished();
void cleanupViews();
......@@ -395,9 +397,6 @@ public:
// stuff in this block should be made private by moving it to
// one of the interfaces
int status() const { return m_status; }
// FIXME: hide this in the engines?
//DebuggerStartMode startMode() const;
QList<Symbol> moduleSymbols(const QString &moduleName);
signals:
......
......@@ -453,19 +453,19 @@ void DebuggerPlugin::shutdown()
m_manager = 0;
}
static inline QString msgParameterMissing(const QString &a)
static QString msgParameterMissing(const QString &a)
{
return DebuggerPlugin::tr("Option '%1' is missing the parameter.").arg(a);
}
static inline QString msgInvalidNumericParameter(const QString &a, const QString &number)
static QString msgInvalidNumericParameter(const QString &a, const QString &number)
{
return DebuggerPlugin::tr("The parameter '%1' of option '%2' is not a number.").arg(number, a);
}
// Parse arguments
bool DebuggerPlugin::parseArgument(QStringList::const_iterator &it,
const QStringList::const_iterator& cend,
const QStringList::const_iterator &cend,
QString *errorMessage)
{
const QString &option = *it;
......@@ -529,7 +529,9 @@ bool DebuggerPlugin::parseArguments(const QStringList &args, QString *errorMessa
if (!parseArgument(it, cend, errorMessage))
return false;
if (Debugger::Constants::Internal::debug)
qDebug().nospace() << args << "engines=0x" << QString::number(m_cmdLineEnabledEngines, 16) << " pid" << m_cmdLineAttachPid << '\n';
qDebug().nospace() << args << "engines=0x"
<< QString::number(m_cmdLineEnabledEngines, 16)
<< " pid" << m_cmdLineAttachPid << '\n';
return true;
}
......@@ -537,13 +539,15 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
{
// Do not fail the whole plugin if something goes wrong here
if (!parseArguments(arguments, errorMessage)) {
*errorMessage = tr("Error evaluating command line arguments: %1").arg(*errorMessage);
*errorMessage = tr("Error evaluating command line arguments: %1")
.arg(*errorMessage);
qWarning("%s\n", qPrintable(*errorMessage));
errorMessage->clear();
}
m_manager = new DebuggerManager;
const QList<Core::IOptionsPage *> engineOptionPages = m_manager->initializeEngines(m_cmdLineEnabledEngines);
const QList<Core::IOptionsPage *> engineOptionPages =
m_manager->initializeEngines(m_cmdLineEnabledEngines);
ICore *core = ICore::instance();
QTC_ASSERT(core, return false);
......@@ -889,9 +893,6 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
this, SLOT(activatePreviousMode()));
connect(m_manager, SIGNAL(debugModeRequested()),
this, SLOT(activateDebugMode()));
connect(m_manager, SIGNAL(statusChanged(int)),
this, SLOT(updateActions(int)));
connect(theDebuggerAction(SettingsDialog), SIGNAL(triggered()),
this, SLOT(showSettingsDialog()));
......@@ -1112,7 +1113,7 @@ void DebuggerPlugin::gotoLocation(const StackFrame &frame, bool setMarker)
void DebuggerPlugin::changeStatus(int status)
{
bool startIsContinue = (status == DebuggerInferiorStopped);
const bool startIsContinue = (status == DebuggerInferiorStopped);
ICore *core = ICore::instance();
if (startIsContinue) {
core->addAdditionalContext(m_gdbRunningContext);
......@@ -1121,6 +1122,27 @@ void DebuggerPlugin::changeStatus(int status)
core->removeAdditionalContext(m_gdbRunningContext);
core->updateContext();
}
const bool started = status == DebuggerInferiorRunning
|| status == DebuggerInferiorRunningRequested
|| status == DebuggerInferiorStopRequested
|| status == DebuggerInferiorStopped;
const bool starting = status == DebuggerProcessStartingUp;
//const bool running = status == DebuggerInferiorRunning;
const bool ready = status == DebuggerInferiorStopped
&& m_manager->startParameters()->startMode != AttachCore;
m_startExternalAction->setEnabled(!started && !starting);
m_attachExternalAction->setEnabled(!started && !starting);
#ifdef Q_OS_WIN
m_attachCoreAction->setEnabled(false);
#else
m_attachCoreAction->setEnabled(!started && !starting);
#endif
m_startRemoteAction->setEnabled(!started && !starting);
m_detachAction->setEnabled(ready);
}
void DebuggerPlugin::writeSettings() const
......@@ -1337,29 +1359,6 @@ void DebuggerPlugin::attachRemoteTcf()
runControl->start();
}
void DebuggerPlugin::updateActions(int status)
{
const bool started = status == DebuggerInferiorRunning
|| status == DebuggerInferiorRunningRequested
|| status == DebuggerInferiorStopRequested
|| status == DebuggerInferiorStopped;
const bool starting = status == DebuggerProcessStartingUp;
//const bool running = status == DebuggerInferiorRunning;
const bool ready = status == DebuggerInferiorStopped
&& m_manager->startParameters()->startMode != AttachCore;
m_startExternalAction->setEnabled(!started && !starting);
m_attachExternalAction->setEnabled(!started && !starting);
#ifdef Q_OS_WIN
m_attachCoreAction->setEnabled(false);
#else
m_attachCoreAction->setEnabled(!started && !starting);
#endif
m_startRemoteAction->setEnabled(!started && !starting);
m_detachAction->setEnabled(ready);
}
#include "debuggerplugin.moc"
Q_EXPORT_PLUGIN(DebuggerPlugin)
......@@ -94,7 +94,6 @@ private slots:
void setConfigValue(const QString &name, const QVariant &value);
void requestContextMenu(TextEditor::ITextEditor *editor,
int lineNumber, QMenu *menu);
void updateActions(int status);
void resetLocation();
void gotoLocation(const StackFrame &frame, bool setMarker);
......
......@@ -87,8 +87,7 @@ public:
virtual void interruptInferior() = 0;
virtual void shutdown() = 0;
virtual const DebuggerStartParameters &startParameters() const
{ return m_engine->startParameters(); }
virtual bool dumpersAvailable() const = 0;
signals:
void adapterStarted();
......@@ -111,9 +110,14 @@ signals:
void readyReadStandardError();
public:
virtual GdbAdapterState state() const { return m_state; }
GdbAdapterState state() const { return m_state; }
// Called by GdbEngine::handleAsyncOutput
void notifyInferiorExited();
protected:
virtual void setState(GdbAdapterState state) { m_state = state; }
void setState(GdbAdapterState state);
const DebuggerStartParameters &startParameters() const
{ return m_engine->startParameters(); }
GdbEngine * const m_engine;
GdbAdapterState m_state;
......
......@@ -59,6 +59,7 @@ private:
void setWorkingDirectory(const QString &dir) { m_gdbProc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_gdbProc.setEnvironment(env); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return false; }
void startAdapter();
void prepareInferior();
......
......@@ -59,6 +59,7 @@ private:
void setWorkingDirectory(const QString &dir) { m_gdbProc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_gdbProc.setEnvironment(env); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return false; }
void startAdapter();
void prepareInferior();
......
This diff is collapsed.
......@@ -247,6 +247,7 @@ private slots:
void handleInferiorShutDown();
void handleInferiorShutdownFailed(const QString &msg);
void handleAdapterCrashed();
void handleAdapterShutDown();
void handleAdapterShutdownFailed(const QString &msg);
......@@ -270,9 +271,6 @@ private:
void handleShowVersion(const GdbResultRecord &response, const QVariant &);
void handleQueryPwd(const GdbResultRecord &response, const QVariant &);
void handleQuerySources(const GdbResultRecord &response, const QVariant &);
void handleExit(const GdbResultRecord &, const QVariant &);
//void handleSetTargetAsync(const GdbResultRecord &, const QVariant &);
//void handleTargetRemote(const GdbResultRecord &, const QVariant &);
void handleWatchPoint(const GdbResultRecord &, const QVariant &);
bool showToolTip();
......
......@@ -60,6 +60,7 @@ public:
void setWorkingDirectory(const QString &dir) { m_gdbProc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_gdbProc.setEnvironment(env); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return true; }
void startAdapter();
void prepareInferior();
......
......@@ -59,6 +59,7 @@ private:
void setWorkingDirectory(const QString &dir) { m_gdbProc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_gdbProc.setEnvironment(env); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return true; }
void startAdapter();
void prepareInferior();
......
......@@ -240,7 +240,7 @@ void TrkGdbAdapter::startInferiorEarly()
if (!m_trkDevice.open(device, &errorMessage)) {
logMessage(QString::fromLatin1("Waiting on %1 (%2)").arg(device, errorMessage));
// Do not loop forever
if (m_waitCount++ < (m_options->mode == TrkOptions::BlueTooth ? 3 : 5)) {
if (m_waitCount++ < (m_options->mode == TrkOptions::BlueTooth ? 60 : 5)) {
QTimer::singleShot(1000, this, SLOT(startInferiorEarly()));
} else {
QString msg = QString::fromLatin1("Failed to connect to %1 after "
......@@ -1327,8 +1327,8 @@ void TrkGdbAdapter::handleGdbFinished(int exitCode, QProcess::ExitStatus exitSta
{
logMessage(QString("GDB: ProcessFinished %1 %2")
.arg(exitCode).arg(exitStatus));
//setState(AdapterNotRunning);
//emit adapterShutDown();
setState(AdapterNotRunning);
emit adapterShutDown();
}
void TrkGdbAdapter::handleGdbStarted()
......@@ -1395,14 +1395,12 @@ void TrkGdbAdapter::handleTargetRemote(const GdbResultRecord &record, const QVar
{
QTC_ASSERT(state() == InferiorPreparing, qDebug() << state());
if (record.resultClass == GdbResultDone) {
//postCommand(_("-exec-continue"), CB(handleExecContinue));
setState(InferiorPrepared);
emit inferiorPrepared();
} else if (record.resultClass == GdbResultError) {
// 16^error,msg="hd:5555: Connection timed out."
QString msg = __(record.data.findChild("msg").data());
QString msg1 = tr("Connecting to remote server failed:");
emit inferiorPreparationFailed(msg1 + _c(' ') + msg);
QString msg = tr("Connecting to trk server adapter failed:\n")
+ _(record.data.findChild("msg").data());
emit inferiorPreparationFailed(msg);
}
}
......@@ -1411,14 +1409,17 @@ void TrkGdbAdapter::startInferior()
QTC_ASSERT(state() == InferiorPrepared, qDebug() << state());
setState(InferiorStarting);
m_engine->postCommand(_("-exec-continue"), CB(handleFirstContinue));
// FIXME: Is there a way to properly recognize a successful start?
setState(InferiorStarted);
emit inferiorStarted();
}
void TrkGdbAdapter::handleFirstContinue(const GdbResultRecord &record, const QVariant &)
{
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
//QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
QTC_ASSERT(state() == InferiorStarted, qDebug() << state());
if (record.resultClass == GdbResultDone) {
setState(InferiorStarted);
emit inferiorStarted();
// inferiorStarted already emitted above, see FIXME
} else if (record.resultClass == GdbResultError) {
//QString msg = __(record.data.findChild("msg").data());
QString msg1 = tr("Connecting to remote server failed:");
......@@ -1589,20 +1590,22 @@ void TrkGdbAdapter::setEnvironment(const QStringList &env)
void TrkGdbAdapter::shutdown()
{
qDebug() << "ADAPTER SHUTDOWN " << state();
if (state() == InferiorStarted) {
setState(InferiorShuttingDown);
qDebug() << "kill";
m_engine->postCommand(_("kill"), CB(handleKill));
return;
}
if (state() == InferiorShutDown) {
setState(AdapterShuttingDown);
qDebug() << "gdb-exit";
m_engine->postCommand(_("-gdb-exit"), CB(handleExit));
return;
}
QTC_ASSERT(state() == AdapterNotRunning, qDebug() << state());
emit adapterShutDown();
}
void TrkGdbAdapter::handleKill(const GdbResultRecord &response, const QVariant &)
......@@ -1622,6 +1625,7 @@ void TrkGdbAdapter::handleKill(const GdbResultRecord &response, const QVariant &
void TrkGdbAdapter::handleExit(const GdbResultRecord &response, const QVariant &)
{
if (response.resultClass == GdbResultDone) {
qDebug() << "EXITED, NO MESSAGE...";
// don't set state here, this will be handled in handleGdbFinished()
} else if (response.resultClass == GdbResultError) {
QString msg = tr("Gdb process could not be stopped:\n") +
......
......@@ -114,6 +114,7 @@ public:
void setWorkingDirectory(const QString &dir);
void setEnvironment(const QStringList &env);
bool isTrkAdapter() const { return true; }
bool dumpersAvailable() const { return false; }
void startAdapter();
void prepareInferior();
......
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