Commit 405f340e authored by hjk's avatar hjk

debugger: streamline communication between GdbEngine and the adapters

parent 2385e15b
......@@ -85,24 +85,6 @@ public:
virtual void trkReloadRegisters() {}
virtual void trkReloadThreads() {}
signals:
void adapterStarted();
// Something went wrong with the adapter *before* adapterStarted() was emitted.
// Make sure to clean up everything before emitting this signal.
void adapterStartFailed(const QString &msg, const QString &settingsIdHint);
// Something went wrong with the adapter *after* adapterStarted() was emitted.
// Make sure to clean up everything before emitting this signal.
void adapterCrashed(const QString &msg);
// This triggers the initial breakpoint synchronization and causes
// startInferiorPhase2() being called once done.
void inferiorPrepared();
// The adapter is still running just fine, but it failed to acquire a debuggee.
void inferiorStartFailed(const QString &msg);
protected:
DebuggerState state() const
{ return m_engine->state(); }
......
......@@ -69,14 +69,14 @@ void AbstractPlainGdbAdapter::handleFileExecAndSymbols(const GdbResponse &respon
if (m_engine->m_gdbVersion < 70000)
m_engine->postCommand("info target", CB(handleInfoTarget));
}
emit inferiorPrepared();
m_engine->handleInferiorPrepared();
} else {
QByteArray ba = response.data.findChild("msg").data();
QString msg = fromLocalEncoding(ba);
// Extend the message a bit in unknown cases.
if (!ba.endsWith("File format not recognized"))
msg = tr("Starting executable failed:\n") + msg;
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......@@ -100,7 +100,7 @@ void AbstractPlainGdbAdapter::handleExecRun(const GdbResponse &response)
QString msg = fromLocalEncoding(response.data.findChild("msg").data());
//QTC_ASSERT(status() == InferiorRunning, /**/);
//interruptInferior();
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......@@ -118,10 +118,10 @@ void AbstractPlainGdbAdapter::handleInfoTarget(const GdbResponse &response)
m_engine->postCommand("tbreak *0x" + needle.cap(1).toAscii());
// Do nothing here - inferiorPrepared handles the sequencing.
} else {
emit inferiorStartFailed(_("Parsing start address failed"));
m_engine->handleInferiorStartFailed(_("Parsing start address failed"));
}
} else if (response.resultClass == GdbResultError) {
emit inferiorStartFailed(_("Fetching start address failed"));
m_engine->handleInferiorStartFailed(_("Fetching start address failed"));
}
}
......
......@@ -62,7 +62,7 @@ void AttachGdbAdapter::startAdapter()
if (!m_engine->startGdb())
return;
emit adapterStarted();
m_engine->handleAdapterStarted();
}
void AttachGdbAdapter::startInferior()
......@@ -81,11 +81,11 @@ void AttachGdbAdapter::handleAttach(const GdbResponse &response)
setState(InferiorStopped);
showMessage(_("INFERIOR ATTACHED"));
showMessage(msgAttachedToStoppedInferior(), StatusBar);
emit inferiorPrepared();
m_engine->handleInferiorPrepared();
m_engine->updateAll();
} else {
QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data());
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......
......@@ -65,7 +65,7 @@ void CoreGdbAdapter::startAdapter()
if (!m_engine->startGdb())
return;
emit adapterStarted();
m_engine->handleAdapterStarted();
}
void CoreGdbAdapter::startInferior()
......@@ -161,7 +161,7 @@ void CoreGdbAdapter::handleTargetCore(const GdbResponse &response)
} else {
QString msg = tr("Attach to core \"%1\" failed:\n").arg(startParameters().coreFile)
+ QString::fromLocal8Bit(response.data.findChild("msg").data());
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......
......@@ -122,6 +122,7 @@ QByteArray GdbEngine::tooltipIName(const QString &exp)
static bool stateAcceptsGdbCommands(DebuggerState state)
{
switch (state) {
case EngineStarting:
case EngineStarted:
case EngineStartFailed:
case InferiorUnrunnable:
......@@ -138,7 +139,6 @@ static bool stateAcceptsGdbCommands(DebuggerState state)
case InferiorShutdownFailed:
return true;
case DebuggerNotReady:
case EngineStarting:
case InferiorStopFailed:
case EngineShuttingDown:
return false;
......@@ -191,23 +191,6 @@ GdbEngine::GdbEngine(const DebuggerStartParameters &startParameters)
this, SLOT(createFullBacktrace()));
}
void GdbEngine::connectDebuggingHelperActions()
{
connect(theDebuggerAction(UseDebuggingHelpers), SIGNAL(valueChanged(QVariant)),
this, SLOT(setUseDebuggingHelpers(QVariant)));
connect(theDebuggerAction(DebugDebuggingHelpers), SIGNAL(valueChanged(QVariant)),
this, SLOT(setDebugDebuggingHelpersClassic(QVariant)));
connect(theDebuggerAction(RecheckDebuggingHelpers), SIGNAL(triggered()),
this, SLOT(recheckDebuggingHelperAvailabilityClassic()));
}
void GdbEngine::disconnectDebuggingHelperActions()
{
disconnect(theDebuggerAction(UseDebuggingHelpers), 0, this, 0);
disconnect(theDebuggerAction(DebugDebuggingHelpers), 0, this, 0);
disconnect(theDebuggerAction(RecheckDebuggingHelpers), 0, this, 0);
}
DebuggerStartMode GdbEngine::startMode() const
{
return startParameters().startMode;
......@@ -232,20 +215,6 @@ GdbEngine::~GdbEngine()
m_gdbAdapter = 0;
}
void GdbEngine::connectAdapter()
{
connect(m_gdbAdapter, SIGNAL(adapterStarted()),
this, SLOT(handleAdapterStarted()));
connect(m_gdbAdapter, SIGNAL(adapterStartFailed(QString,QString)),
this, SLOT(handleAdapterStartFailed(QString,QString)));
connect(m_gdbAdapter, SIGNAL(inferiorPrepared()),
this, SLOT(handleInferiorPrepared()));
connect(m_gdbAdapter, SIGNAL(inferiorStartFailed(QString)),
this, SLOT(handleInferiorStartFailed(QString)));
connect(m_gdbAdapter, SIGNAL(adapterCrashed(QString)),
this, SLOT(handleAdapterCrashed(QString)));
}
void GdbEngine::initializeVariables()
{
m_debuggingHelperState = DebuggingHelperUninitialized;
......@@ -1723,7 +1692,6 @@ void GdbEngine::detachDebugger()
void GdbEngine::exitDebugger()
{
disconnectDebuggingHelperActions();
shutdown();
}
......@@ -1734,7 +1702,6 @@ void GdbEngine::quitDebugger()
// to force it down. On the other hand, there could be an answer,
// and regular the inferior shutdown procedure could take a while.
// And the RunControl::stop() is called synchroneously.
disconnectDebuggingHelperActions();
shutdown();
initializeVariables();
setState(DebuggerNotReady);
......@@ -1809,10 +1776,15 @@ void GdbEngine::startDebugger()
m_gdbAdapter = createAdapter();
//qDebug() << "CREATED ADAPTER: " << m_gdbAdapter;
connectAdapter();
if (m_gdbAdapter->dumperHandling() != AbstractGdbAdapter::DumperNotAvailable)
connectDebuggingHelperActions();
if (m_gdbAdapter->dumperHandling() != AbstractGdbAdapter::DumperNotAvailable) {
connect(theDebuggerAction(UseDebuggingHelpers), SIGNAL(valueChanged(QVariant)),
this, SLOT(setUseDebuggingHelpers(QVariant)));
connect(theDebuggerAction(DebugDebuggingHelpers), SIGNAL(valueChanged(QVariant)),
this, SLOT(setDebugDebuggingHelpersClassic(QVariant)));
connect(theDebuggerAction(RecheckDebuggingHelpers), SIGNAL(triggered()),
this, SLOT(recheckDebuggingHelperAvailabilityClassic()));
}
m_progress->setProgressValue(20);
QTC_ASSERT(state() == EngineStarting, /**/);
......
......@@ -126,7 +126,6 @@ private: ////////// General State //////////
private: ////////// Gdb Process Management //////////
AbstractGdbAdapter *createAdapter();
void connectAdapter();
bool startGdb(const QStringList &args = QStringList(),
const QString &gdb = QString(),
const QString &settingsIdHint = QString());
......@@ -135,23 +134,30 @@ private: ////////// Gdb Process Management //////////
void handleInferiorShutdown(const GdbResponse &response);
void handleGdbExit(const GdbResponse &response);
private slots:
void handleGdbFinished(int, QProcess::ExitStatus status);
void handleGdbError(QProcess::ProcessError error);
void readGdbStandardOutput();
void readGdbStandardError();
void readDebugeeOutput(const QByteArray &data);
void handleAdapterStarted();
// Something went wrong with the adapter *before* adapterStarted() was emitted.
// Make sure to clean up everything before emitting this signal.
void handleAdapterStartFailed(const QString &msg,
const QString &settingsIdHint = QString());
// This triggers the initial breakpoint synchronization and causes
// startInferiorPhase2() being called once done.
void handleInferiorPrepared();
// The adapter is still running just fine, but it failed to acquire a debuggee.
void handleInferiorStartFailed(const QString &msg);
// Something went wrong with the adapter *after* adapterStarted() was emitted.
// Make sure to clean up everything before emitting this signal.
void handleAdapterCrashed(const QString &msg);
private slots:
void handleGdbFinished(int, QProcess::ExitStatus status);
void handleGdbError(QProcess::ProcessError error);
void readGdbStandardOutput();
void readGdbStandardError();
void readDebugeeOutput(const QByteArray &data);
private:
QTextCodec *m_outputCodec;
QTextCodec::ConverterState m_outputCodecState;
......@@ -505,8 +511,6 @@ private: ////////// View & Data Stuff //////////
void tryLoadDebuggingHelpersClassic();
void tryQueryDebuggingHelpersClassic();
Q_SLOT void recheckDebuggingHelperAvailabilityClassic();
void connectDebuggingHelperActions();
void disconnectDebuggingHelperActions();
Q_SLOT void setDebugDebuggingHelpersClassic(const QVariant &on);
Q_SLOT void setUseDebuggingHelpers(const QVariant &on);
......
......@@ -74,7 +74,7 @@ void LocalPlainGdbAdapter::startAdapter()
QStringList gdbArgs;
if (!m_outputCollector.listen()) {
emit adapterStartFailed(tr("Cannot set up communication with child process: %1")
m_engine->handleAdapterStartFailed(tr("Cannot set up communication with child process: %1")
.arg(m_outputCollector.errorString()), QString());
return;
}
......@@ -90,7 +90,7 @@ void LocalPlainGdbAdapter::startAdapter()
return;
}
emit adapterStarted();
m_engine->handleAdapterStarted();
checkForReleaseBuild();
}
......
......@@ -101,7 +101,7 @@ void RemoteGdbServerAdapter::startAdapter()
// FIXME: cleanup missing
return;
emit adapterStarted();
m_engine->handleAdapterStarted();
}
void RemoteGdbServerAdapter::uploadProcError(QProcess::ProcessError error)
......@@ -202,7 +202,7 @@ void RemoteGdbServerAdapter::handleFileExecAndSymbols(const GdbResponse &respons
} else {
QString msg = tr("Starting remote executable failed:\n");
msg += QString::fromLocal8Bit(response.data.findChild("msg").data());
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......@@ -214,12 +214,12 @@ void RemoteGdbServerAdapter::handleTargetRemote(const GdbResponse &record)
// gdb server will stop the remote application itself.
showMessage(_("INFERIOR STARTED"));
showMessage(msgAttachedToStoppedInferior(), StatusBar);
emit inferiorPrepared();
m_engine->handleInferiorPrepared();
} else {
// 16^error,msg="hd:5555: Connection timed out."
QString msg = msgConnectRemoteServerFailed(
QString::fromLocal8Bit(record.data.findChild("msg").data()));
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......
......@@ -55,7 +55,7 @@ void RemotePlainGdbAdapter::startAdapter()
m_gdbProc.setEnvironment(startParameters().environment);
if (m_engine->startGdb(QStringList(), m_engine->startParameters().debuggerCommand))
emit adapterStarted();
m_engine->handleAdapterStarted();
}
void RemotePlainGdbAdapter::interruptInferior()
......
......@@ -252,13 +252,13 @@ void TcfTrkGdbAdapter::handleTargetRemote(const GdbResponse &record)
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
if (record.resultClass == GdbResultDone) {
setState(InferiorStopped);
emit inferiorPrepared();
m_engine->handleInferiorPrepared();
if (debug)
qDebug() << "handleTargetRemote" << m_session.toString();
} else {
QString msg = tr("Connecting to TRK server adapter failed:\n")
+ QString::fromLocal8Bit(record.data.findChild("msg").data());
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......@@ -324,16 +324,16 @@ void TcfTrkGdbAdapter::startGdb()
cleanup();
return;
}
emit adapterStarted();
m_engine->handleAdapterStarted();
}
void TcfTrkGdbAdapter::tcftrkDeviceError(const QString &errorString)
{
logMessage(errorString);
if (state() == EngineStarting) {
emit adapterStartFailed(errorString, QString());
m_engine->handleAdapterStartFailed(errorString, QString());
} else {
emit adapterCrashed(errorString);
m_engine->handleAdapterCrashed(errorString);
}
}
......@@ -935,16 +935,17 @@ void TcfTrkGdbAdapter::startAdapter()
if (debug)
qDebug() << parameters.processArgs;
// Fixme: 1 of 3 testing hacks.
if (parameters.processArgs.size() >= 5 && parameters.processArgs.at(0) == _("@tcf@")) {
m_remoteExecutable = parameters.processArgs.at(1);
m_uid = parameters.processArgs.at(2).toUInt(0, 16);
m_symbolFile = parameters.processArgs.at(3);
tcfTrkAddress = parameters.processArgs.at(4);
m_remoteArguments.clear();
} else {
emit adapterStartFailed(_("Parameter error"), QString());
if (parameters.processArgs.size() < 5 || parameters.processArgs.at(0) != _("@tcf@")) {
m_engine->handleAdapterStartFailed(_("Parameter error"), QString());
return;
}
m_remoteExecutable = parameters.processArgs.at(1);
m_uid = parameters.processArgs.at(2).toUInt(0, 16);
m_symbolFile = parameters.processArgs.at(3);
tcfTrkAddress = parameters.processArgs.at(4);
m_remoteArguments.clear();
// Unixish gdbs accept only forward slashes
m_symbolFile.replace(QLatin1Char('\\'), QLatin1Char('/'));
// Start
......@@ -960,7 +961,7 @@ void TcfTrkGdbAdapter::startAdapter()
QString msg = QString("Unable to start the gdb server at %1: %2.")
.arg(m_gdbServerName).arg(m_gdbServer->errorString());
logMessage(msg, LogError);
emit adapterStartFailed(msg, QString());
m_engine->handleAdapterStartFailed(msg, QString());
return;
}
......@@ -1004,7 +1005,7 @@ void TcfTrkGdbAdapter::handleCreateProcess(const tcftrk::TcfTrkCommandResult &re
if (!result) {
const QString errorMessage = result.errorString();
logMessage(QString::fromLatin1("Failed to start process: %1").arg(errorMessage), LogError);
emit inferiorStartFailed(result.errorString());
m_engine->handleInferiorStartFailed(result.errorString());
return;
}
QTC_ASSERT(!result.values.isEmpty(), return);
......
......@@ -99,7 +99,7 @@ void TermGdbAdapter::startAdapter()
if (!m_stubProc.start(startParameters().executable,
startParameters().processArgs)) {
// Error message for user is delivered via a signal.
emit adapterStartFailed(QString(), QString());
m_engine->handleAdapterStartFailed(QString(), QString());
return;
}
......@@ -112,7 +112,7 @@ void TermGdbAdapter::startAdapter()
void TermGdbAdapter::handleInferiorStarted()
{
QTC_ASSERT(state() == EngineStarting, qDebug() << state());
emit adapterStarted();
m_engine->handleAdapterStarted();
}
void TermGdbAdapter::startInferior()
......@@ -130,13 +130,13 @@ void TermGdbAdapter::handleStubAttached(const GdbResponse &response)
if (response.resultClass == GdbResultDone) {
setState(InferiorStopped);
showMessage(_("INFERIOR ATTACHED"));
emit inferiorPrepared();
m_engine->handleInferiorPrepared();
#ifdef Q_OS_LINUX
m_engine->postCommand("-stack-list-frames 0 0", CB(handleEntryPoint));
#endif
} else if (response.resultClass == GdbResultError) {
QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data());
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......@@ -174,7 +174,7 @@ void TermGdbAdapter::stubExited()
showMessage(_("STUB EXITED"));
if (state() != EngineStarting // From previous instance
&& state() != EngineShuttingDown && state() != DebuggerNotReady)
emit adapterCrashed(QString());
m_engine->handleAdapterCrashed(QString());
}
} // namespace Internal
......
......@@ -254,7 +254,7 @@ void TrkGdbAdapter::emitDelayedInferiorStartFailed(const QString &msg)
void TrkGdbAdapter::slotEmitDelayedInferiorStartFailed()
{
emit inferiorStartFailed(m_adapterFailMessage);
m_engine->handleInferiorStartFailed(m_adapterFailMessage);
}
......@@ -892,7 +892,7 @@ void TrkGdbAdapter::sendTrkAck(trk::byte token)
void TrkGdbAdapter::handleTrkError(const QString &msg)
{
logMessage("## TRK ERROR: " + msg, LogError);
emit adapterCrashed("TRK problem encountered:\n" + msg);
m_engine->handleAdapterCrashed("TRK problem encountered:\n" + msg);
}
void TrkGdbAdapter::handleTrkResult(const TrkResult &result)
......@@ -1409,7 +1409,7 @@ void TrkGdbAdapter::slotStartGdb()
cleanup();
return;
}
emit adapterStarted();
m_engine->handleAdapterStarted();
}
void TrkGdbAdapter::handleDisconnect(const TrkResult & /*result*/)
......@@ -1440,7 +1440,7 @@ void TrkGdbAdapter::trkDeviceRemoved(const SymbianUtils::SymbianDevice &dev)
if (state() != DebuggerNotReady && !m_trkDevice.isNull() && m_trkDevice->port() == dev.portName()) {
const QString message = QString::fromLatin1("Device '%1' has been disconnected.").arg(dev.friendlyName());
logMessage(message);
emit adapterCrashed(message);
m_engine->handleAdapterCrashed(message);
}
}
......@@ -1509,10 +1509,10 @@ void TrkGdbAdapter::startAdapter()
QString message;
if (!initializeDevice(parameters.remoteChannel, &message)) {
if (message.isEmpty()) {
emit adapterStartFailed(QString(), QString());
m_engine->handleAdapterStartFailed(QString(), QString());
} else {
logMessage(message, LogError);
emit adapterStartFailed(message, QString());
m_engine->handleAdapterStartFailed(message, QString());
}
return;
}
......@@ -1525,7 +1525,7 @@ void TrkGdbAdapter::startAdapter()
QString msg = QString("Unable to start the gdb server at %1: %2.")
.arg(m_gdbServerName).arg(m_gdbServer->errorString());
logMessage(msg, LogError);
emit adapterStartFailed(msg, QString());
m_engine->handleAdapterStartFailed(msg, QString());
return;
}
......@@ -1605,11 +1605,11 @@ void TrkGdbAdapter::handleTargetRemote(const GdbResponse &record)
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
if (record.resultClass == GdbResultDone) {
setState(InferiorStopped);
emit inferiorPrepared();
m_engine->handleInferiorPrepared();
} else {
QString msg = tr("Connecting to TRK server adapter failed:\n")
+ QString::fromLocal8Bit(record.data.findChild("msg").data());
emit inferiorStartFailed(msg);
m_engine->handleInferiorStartFailed(msg);
}
}
......
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