Commit e3bd438a authored by hjk's avatar hjk Committed by hjk

debugger: make startGdb response handling asyncronous

This allows adapters to take all responses from the startup commands
into account.

Change-Id: I295cb211a4b69cfb8c59b34030aaee8120ffe98e
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent a7f8c3c8
......@@ -72,6 +72,8 @@ public:
virtual void write(const QByteArray &data);
virtual void startAdapter() = 0;
virtual void handleGdbStartDone() = 0;
virtual void handleGdbStartFailed() = 0;
virtual void setupInferior() = 0;
virtual void runEngine() = 0;
virtual void interruptInferior() = 0;
......
......@@ -63,13 +63,18 @@ void AttachGdbAdapter::startAdapter()
{
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
showMessage(_("TRYING TO START ADAPTER"));
m_engine->startGdb();
}
if (!m_engine->startGdb())
return;
void AttachGdbAdapter::handleGdbStartDone()
{
m_engine->handleAdapterStarted();
}
void AttachGdbAdapter::handleGdbStartFailed()
{
}
void AttachGdbAdapter::setupInferior()
{
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
......
......@@ -56,6 +56,8 @@ private:
DumperHandling dumperHandling() const { return DumperLoadedByGdb; }
void startAdapter();
void handleGdbStartDone();
void handleGdbStartFailed();
void setupInferior();
void runEngine();
void interruptInferior();
......
......@@ -386,13 +386,19 @@ void CodaGdbAdapter::startGdb()
{
QStringList gdbArgs;
gdbArgs.append(_("--nx")); // Do not read .gdbinit file
if (!m_engine->startGdb(gdbArgs)) {
cleanup();
return;
}
m_engine->startGdb(gdbArgs);
}
void CodaGdbAdapter::handleGdbStartDone()
{
m_engine->handleAdapterStarted();
}
void CodaGdbAdapter::handleGdbStartFailed()
{
cleanup();
}
void CodaGdbAdapter::codaDeviceError(const QString &errorString)
{
logMessage(errorString);
......
......@@ -83,7 +83,7 @@ public:
typedef Coda::Callback<const GdbResponse &> GdbCallback;
explicit CodaGdbAdapter(GdbEngine *engine);
virtual ~CodaGdbAdapter();
~CodaGdbAdapter();
void setGdbServerName(const QString &name);
QString gdbServerName() const { return m_gdbServerName; }
......@@ -111,6 +111,8 @@ public:
private:
void setupDeviceSignals();
void startAdapter();
void handleGdbStartDone();
void handleGdbStartFailed();
void setupInferior();
void runEngine();
void interruptInferior();
......
......@@ -78,9 +78,15 @@ void CoreGdbAdapter::startAdapter()
QStringList args;
args.append(_("-ex"));
args.append(_("set auto-solib-add off"));
if (!m_engine->startGdb(args, QString()))
return;
m_engine->startGdb(args);
}
void CoreGdbAdapter::handleGdbStartFailed()
{
}
void CoreGdbAdapter::handleGdbStartDone()
{
//if (m_executable.isEmpty()) {
// showMessageBox(QMessageBox::Warning,
// tr("Error Loading Symbols"),
......
......@@ -56,6 +56,8 @@ private:
DumperHandling dumperHandling() const { return DumperNotAvailable; }
void startAdapter();
void handleGdbStartDone();
void handleGdbStartFailed();
void setupInferior();
void runEngine();
void interruptInferior();
......
......@@ -4747,7 +4747,7 @@ bool checkGdbConfiguration(const DebuggerStartParameters &sp, ConfigurationCheck
// Starting up & shutting down
//
bool GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint)
void GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint)
{
const QByteArray tests = qgetenv("QTC_DEBUGGER_TESTS");
foreach (const QByteArray &test, tests.split(','))
......@@ -4760,10 +4760,11 @@ bool GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint)
const DebuggerStartParameters &sp = startParameters();
m_gdb = gdbBinary(sp);
if (m_gdb.isEmpty()) {
m_gdbAdapter->handleGdbStartFailed();
handleAdapterStartFailed(
msgNoGdbBinaryForToolChain(sp.toolChainAbi),
_(Constants::DEBUGGER_COMMON_SETTINGS_ID));
return false;
return;
}
QStringList gdbArgs;
gdbArgs << _("-i");
......@@ -4785,9 +4786,10 @@ bool GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint)
gdbProc()->start(m_gdb, gdbArgs);
if (!gdbProc()->waitForStarted()) {
m_gdbAdapter->handleGdbStartFailed();
const QString msg = errorMessage(QProcess::FailedToStart);
handleAdapterStartFailed(msg, settingsIdHint);
return false;
return;
}
showMessage(_("GDB STARTED, INITIALIZING IT"));
......@@ -4845,7 +4847,6 @@ bool GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint)
//postCommand(_("handle SIGTERM pass nostop print"));
postCommand("set unwindonsignal on");
postCommand("pwd");
postCommand("set width 0");
postCommand("set height 0");
......@@ -4861,6 +4862,8 @@ bool GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint)
postCommand("maintenance set internal-warning quit no", ConsoleCommand);
postCommand("maintenance set internal-error quit no", ConsoleCommand);
showMessage(_("THE FOLLOWING COMMAND CHECKS AVAILABLE FEATURES. "
"AN ERROR IS EXPECTED."));
postCommand("disassemble 0 0", ConsoleCommand, CB(handleDisassemblerCheck));
if (attemptQuickStart()) {
......@@ -4871,7 +4874,14 @@ bool GdbEngine::startGdb(const QStringList &args, const QString &settingsIdHint)
loadPythonDumpers();
}
return true;
// Dummy command to guarantee a roundtrip before the adapter proceed.
postCommand("pwd", ConsoleCommand, CB(handleGdbStart));
}
void GdbEngine::handleGdbStart(const GdbResponse &response)
{
Q_UNUSED(response);
m_gdbAdapter->handleGdbStartDone();
}
void GdbEngine::loadInitScript()
......
......@@ -249,8 +249,9 @@ private: ////////// General State //////////
private: ////////// Gdb Process Management //////////
AbstractGdbAdapter *createAdapter();
bool startGdb(const QStringList &args = QStringList(),
void startGdb(const QStringList &args = QStringList(),
const QString &settingsIdHint = QString());
void handleGdbStart(const GdbResponse &response);
void handleInferiorShutdown(const GdbResponse &response);
void handleGdbExit(const GdbResponse &response);
void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
......
......@@ -93,14 +93,19 @@ void LocalPlainGdbAdapter::startAdapter()
if (startParameters().environment.size())
m_gdbProc.setEnvironment(startParameters().environment.toStringList());
if (!m_engine->startGdb(gdbArgs)) {
m_outputCollector.shutdown();
return;
}
m_engine->startGdb(gdbArgs);
}
void LocalPlainGdbAdapter::handleGdbStartDone()
{
m_engine->handleAdapterStarted();
}
void LocalPlainGdbAdapter::handleGdbStartFailed()
{
m_outputCollector.shutdown();
}
void LocalPlainGdbAdapter::setupInferior()
{
AbstractPlainGdbAdapter::setupInferior();
......
......@@ -55,6 +55,8 @@ public:
private:
void startAdapter();
void handleGdbStartDone();
void handleGdbStartFailed();
void setupInferior();
void runEngine();
void interruptInferior();
......
......@@ -98,7 +98,7 @@ void RemoteGdbServerAdapter::startAdapter()
if (startParameters().requestRemoteSetup)
m_engine->notifyEngineRequestRemoteSetup();
else
handleSetupDone();
m_engine->startGdb();
}
void RemoteGdbServerAdapter::uploadProcError(QProcess::ProcessError error)
......@@ -155,7 +155,7 @@ void RemoteGdbServerAdapter::uploadProcFinished()
{
if (m_uploadProc.exitStatus() == QProcess::NormalExit
&& m_uploadProc.exitCode() == 0)
handleSetupDone();
m_engine->startGdb();
else
handleRemoteSetupFailed(m_uploadProc.errorString());
}
......@@ -401,13 +401,16 @@ void RemoteGdbServerAdapter::handleRemoteSetupDone(int gdbServerPort, int qmlPor
QString::number(gdbServerPort));
}
}
handleSetupDone();
m_engine->startGdb();
}
void RemoteGdbServerAdapter::handleSetupDone()
void RemoteGdbServerAdapter::handleGdbStartDone()
{
m_engine->handleAdapterStarted();
}
void RemoteGdbServerAdapter::handleGdbStartFailed()
{
if (m_engine->startGdb())
m_engine->handleAdapterStarted();
}
void RemoteGdbServerAdapter::handleRemoteSetupFailed(const QString &reason)
......
......@@ -56,6 +56,8 @@ private:
DumperHandling dumperHandling() const;
void startAdapter();
void handleGdbStartDone();
void handleGdbStartFailed();
void setupInferior();
void runEngine();
void interruptInferior();
......@@ -63,8 +65,6 @@ private:
AbstractGdbProcess *gdbProc() { return &m_gdbProc; }
void handleSetupDone();
signals:
/*
* For "external" clients of a debugger run control that need to do
......
......@@ -47,7 +47,7 @@ RemotePlainGdbAdapter::RemotePlainGdbAdapter(GdbEngine *engine)
{
connect(&m_gdbProc, SIGNAL(started()), this, SLOT(handleGdbStarted()));
connect(&m_gdbProc, SIGNAL(startFailed()), this,
SLOT(handleGdbStartFailed()));
SLOT(handleGdbStartFailed1()));
}
void RemotePlainGdbAdapter::startAdapter()
......@@ -117,11 +117,19 @@ void RemotePlainGdbAdapter::handleRemoteSetupDone(int gdbServerPort, int qmlPort
void RemotePlainGdbAdapter::handleGdbStarted()
{
if (m_engine->startGdb())
m_engine->handleAdapterStarted();
m_engine->startGdb();
}
void RemotePlainGdbAdapter::handleGdbStartDone()
{
m_engine->handleAdapterStarted();
}
void RemotePlainGdbAdapter::handleGdbStartFailed()
{
}
void RemotePlainGdbAdapter::handleGdbStartFailed1()
{
m_engine->handleAdapterStartFailed(m_gdbProc.errorString());
}
......
......@@ -49,10 +49,12 @@ public:
private slots:
void handleGdbStarted();
void handleGdbStartFailed();
void handleGdbStartFailed1();
private:
void startAdapter();
void handleGdbStartDone();
void handleGdbStartFailed();
void setupInferior();
void interruptInferior();
void shutdownAdapter();
......
......@@ -119,10 +119,16 @@ void TermGdbAdapter::startAdapter()
return;
}
if (!m_engine->startGdb()) {
m_stubProc.stop();
return;
}
m_engine->startGdb();
}
void TermGdbAdapter::handleGdbStartDone()
{
}
void TermGdbAdapter::handleGdbStartFailed()
{
m_stubProc.stop();
}
void TermGdbAdapter::handleInferiorSetupOk()
......
......@@ -59,6 +59,8 @@ private:
DumperHandling dumperHandling() const;
void startAdapter();
void handleGdbStartDone();
void handleGdbStartFailed();
void setupInferior();
void runEngine();
void interruptInferior();
......
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