Commit 252fd2e7 authored by hjk's avatar hjk

debugger: refactoring of AbstractGdbAdapter

remove shutdownInferior(), rename shutdownAdapter() into shutdown()
parent 8290563c
......@@ -85,9 +85,8 @@ public:
virtual void startAdapter(const DebuggerStartParametersPtr &sp) = 0;
virtual void prepareInferior() = 0;
virtual void startInferior() = 0;
virtual void shutdownInferior() = 0;
virtual void shutdownAdapter() = 0;
virtual void interruptInferior() = 0;
virtual void shutdown() = 0;
signals:
void adapterStarted();
......
......@@ -228,13 +228,6 @@ void GdbEngine::initializeConnections()
connect(m_gdbAdapter, SIGNAL(adapterCrashed()),
m_manager, SLOT(exitDebugger()));
connect(&m_uploadProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(uploadProcError(QProcess::ProcessError)));
connect(&m_uploadProc, SIGNAL(readyReadStandardOutput()),
this, SLOT(readUploadStandardOutput()));
connect(&m_uploadProc, SIGNAL(readyReadStandardError()),
this, SLOT(readUploadStandardError()));
// Output
connect(&m_outputCollector, SIGNAL(byteDelivery(QByteArray)),
this, SLOT(readDebugeeOutput(QByteArray)));
......@@ -290,8 +283,7 @@ void GdbEngine::initializeVariables()
// FIXME: unhandled:
//m_outputCodecState = QTextCodec::ConverterState();
//QProcess m_gdbAdapter;
//QProcess m_uploadProc;
//m_gdbAdapter;
}
void GdbEngine::gdbProcError(QProcess::ProcessError error)
......@@ -338,55 +330,6 @@ void GdbEngine::gdbProcError(QProcess::ProcessError error)
m_manager->exitDebugger();
}
void GdbEngine::uploadProcError(QProcess::ProcessError error)
{
QString msg;
switch (error) {
case QProcess::FailedToStart:
msg = tr("The upload process failed to start. Either the "
"invoked script '%1' is missing, or you may have insufficient "
"permissions to invoke the program.")
.arg(theDebuggerStringSetting(GdbLocation));
break;
case QProcess::Crashed:
msg = tr("The upload process crashed some time after starting "
"successfully.");
break;
case QProcess::Timedout:
msg = tr("The last waitFor...() function timed out. "
"The state of QProcess is unchanged, and you can try calling "
"waitFor...() again.");
break;
case QProcess::WriteError:
msg = tr("An error occurred when attempting to write "
"to the upload process. For example, the process may not be running, "
"or it may have closed its input channel.");
break;
case QProcess::ReadError:
msg = tr("An error occurred when attempting to read from "
"the upload process. For example, the process may not be running.");
break;
default:
msg = tr("An unknown error in the upload process occurred. "
"This is the default return value of error().");
}
showStatusMessage(msg);
QMessageBox::critical(mainWindow(), tr("Error"), msg);
}
void GdbEngine::readUploadStandardOutput()
{
QByteArray ba = m_uploadProc.readAllStandardOutput();
gdbOutputAvailable(LogOutput, QString::fromLocal8Bit(ba, ba.length()));
}
void GdbEngine::readUploadStandardError()
{
QByteArray ba = m_uploadProc.readAllStandardError();
gdbOutputAvailable(LogError, QString::fromLocal8Bit(ba, ba.length()));
}
#if 0
static void dump(const char *first, const char *middle, const QString & to)
{
......@@ -713,7 +656,7 @@ void GdbEngine::postCommand(const QString &command, GdbCommandFlags flags,
{
GdbCommand cmd;
cmd.command = command;
//cmd.flags = flags;
cmd.flags = flags;
cmd.adapterCallback = callback;
cmd.callbackName = callbackName;
cmd.cookie = cookie;
......@@ -1508,7 +1451,7 @@ void GdbEngine::shutdown()
{
m_outputCollector.shutdown();
initializeVariables();
m_gdbAdapter->shutdownAdapter();
m_gdbAdapter->shutdown();
}
void GdbEngine::detachDebugger()
......@@ -1522,7 +1465,7 @@ void GdbEngine::exitDebugger()
{
m_outputCollector.shutdown();
initializeVariables();
m_gdbAdapter->shutdownAdapter();
m_gdbAdapter->shutdown();
}
void GdbEngine::handleExitHelper(const GdbResultRecord &, const QVariant &)
......
......@@ -229,10 +229,7 @@ private slots:
void gdbProcError(QProcess::ProcessError error);
void readGdbStandardOutput();
void readGdbStandardError();
void readUploadStandardOutput();
void readUploadStandardError();
void readDebugeeOutput(const QByteArray &data);
void uploadProcError(QProcess::ProcessError error);
void emitStartFailed();
void handleAdapterStarted();
......@@ -297,7 +294,6 @@ private:
QByteArray m_inbuffer;
AbstractGdbAdapter *m_gdbAdapter;
QProcess m_uploadProc;
QHash<int, GdbCommand> m_cookieForToken;
QHash<int, QByteArray> m_customOutputForToken;
......
......@@ -158,11 +158,12 @@ void PlainGdbAdapter::handleFileExecAndSymbols(const GdbResultRecord &response,
}
}
void PlainGdbAdapter::startInferior()
void PlainGdbAdapter::handleInfoTarget(const GdbResultRecord &response, const QVariant &)
{
QTC_ASSERT(state() == InferiorPrepared, qDebug() << state());
setState(InferiorStarting);
m_engine->postCommand(_("-exec-run"), CB(handleExecRun));
QTC_ASSERT(state() == AdapterNotRunning, qDebug() << state());
#if defined(Q_OS_MAC)
Q_UNUSED(response)
#else
/*
#ifdef Q_OS_MAC
m_engine->postCommand(_("sharedlibrary apply-load-rules all"));
......@@ -177,14 +178,6 @@ void PlainGdbAdapter::startInferior()
m_engine->postCommand(_("info target"), CB(handleInfoTarget));
#endif
*/
}
void PlainGdbAdapter::handleInfoTarget(const GdbResultRecord &response, const QVariant &)
{
QTC_ASSERT(state() == AdapterNotRunning, qDebug() << state());
#if defined(Q_OS_MAC)
Q_UNUSED(response)
#else
if (response.resultClass == GdbResultDone) {
// [some leading stdout here]
// >&" Entry point: 0x80831f0 0x08048134 - 0x08048147 is .interp\n"
......@@ -241,7 +234,7 @@ void PlainGdbAdapter::interruptInferior()
debugMessage(_("CANNOT INTERRUPT %1").arg(attachedPID));
}
void PlainGdbAdapter::shutdownAdapter()
void PlainGdbAdapter::shutdown()
{
if (state() == InferiorStarted) {
setState(InferiorShuttingDown);
......@@ -281,7 +274,7 @@ void PlainGdbAdapter::handleKill(const GdbResultRecord &response, const QVariant
if (response.resultClass == GdbResultDone) {
setState(InferiorShutDown);
emit inferiorShutDown();
shutdownAdapter(); // re-iterate...
shutdown(); // re-iterate...
} else if (response.resultClass == GdbResultError) {
QString msg = tr("Inferior process could not be stopped:\n") +
__(response.data.findChild("msg").data());
......@@ -308,11 +301,6 @@ void PlainGdbAdapter::handleGdbFinished(int, QProcess::ExitStatus)
emit adapterShutDown();
}
void PlainGdbAdapter::shutdownInferior()
{
m_engine->postCommand(_("kill"));
}
void PlainGdbAdapter::stubStarted()
{
const qint64 attachedPID = m_stubProc.applicationPID();
......
......@@ -63,13 +63,12 @@ public:
void setWorkingDirectory(const QString &dir) { m_gdbProc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_gdbProc.setEnvironment(env); }
bool isAdapter() const { return false; }
void interruptInferior();
void startAdapter(const DebuggerStartParametersPtr &sp);
void prepareInferior();
void startInferior();
void shutdownInferior();
void shutdownAdapter();
void interruptInferior();
void shutdown();
private:
void handleFileExecAndSymbols(const GdbResultRecord &, const QVariant &);
......
......@@ -68,6 +68,13 @@ RemoteGdbAdapter::RemoteGdbAdapter(GdbEngine *engine, QObject *parent)
this, SLOT(handleGdbStarted()));
connect(&m_gdbProc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
connect(&m_uploadProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(uploadProcError(QProcess::ProcessError)));
connect(&m_uploadProc, SIGNAL(readyReadStandardOutput()),
this, SLOT(readUploadStandardOutput()));
connect(&m_uploadProc, SIGNAL(readyReadStandardError()),
this, SLOT(readUploadStandardError()));
}
void RemoteGdbAdapter::startAdapter(const DebuggerStartParametersPtr &sp)
......@@ -105,6 +112,55 @@ void RemoteGdbAdapter::handleGdbStarted()
emit adapterStarted();
}
void RemoteGdbAdapter::uploadProcError(QProcess::ProcessError error)
{
QString msg;
switch (error) {
case QProcess::FailedToStart:
msg = tr("The upload process failed to start. Either the "
"invoked script '%1' is missing, or you may have insufficient "
"permissions to invoke the program.")
.arg(theDebuggerStringSetting(GdbLocation));
break;
case QProcess::Crashed:
msg = tr("The upload process crashed some time after starting "
"successfully.");
break;
case QProcess::Timedout:
msg = tr("The last waitFor...() function timed out. "
"The state of QProcess is unchanged, and you can try calling "
"waitFor...() again.");
break;
case QProcess::WriteError:
msg = tr("An error occurred when attempting to write "
"to the upload process. For example, the process may not be running, "
"or it may have closed its input channel.");
break;
case QProcess::ReadError:
msg = tr("An error occurred when attempting to read from "
"the upload process. For example, the process may not be running.");
break;
default:
msg = tr("An unknown error in the upload process occurred. "
"This is the default return value of error().");
}
m_engine->showStatusMessage(msg);
QMessageBox::critical(m_engine->mainWindow(), tr("Error"), msg);
}
void RemoteGdbAdapter::readUploadStandardOutput()
{
QByteArray ba = m_uploadProc.readAllStandardOutput();
m_engine->gdbOutputAvailable(LogOutput, QString::fromLocal8Bit(ba, ba.length()));
}
void RemoteGdbAdapter::readUploadStandardError()
{
QByteArray ba = m_uploadProc.readAllStandardError();
m_engine->gdbOutputAvailable(LogError, QString::fromLocal8Bit(ba, ba.length()));
}
void RemoteGdbAdapter::prepareInferior()
{
QTC_ASSERT(state() == AdapterStarted, qDebug() << state());
......@@ -173,7 +229,7 @@ void RemoteGdbAdapter::interruptInferior()
debugMessage(_("CANNOT INTERRUPT %1").arg(attachedPID));
}
void RemoteGdbAdapter::shutdownAdapter()
void RemoteGdbAdapter::shutdown()
{
if (state() == InferiorStarted) {
setState(InferiorShuttingDown);
......@@ -187,24 +243,7 @@ void RemoteGdbAdapter::shutdownAdapter()
return;
}
/*
if (state() == InferiorShutdownFailed) {
m_gdbProc.terminate();
// 20s can easily happen when loading webkit debug information
m_gdbProc.waitForFinished(20000);
setState(AdapterShuttingDown);
debugMessage(_("FORCING TERMINATION: %1")
.arg(state()));
if (state() != QProcess::NotRunning) {
debugMessage(_("PROBLEM STOPPING DEBUGGER: STATE %1")
.arg(state()));
m_gdbProc.kill();
}
m_engine->postCommand(_("-gdb-exit"), CB(handleExit));
return;
}
*/
// FIXME: handle other states, too.
QTC_ASSERT(state() == AdapterNotRunning, qDebug() << state());
}
......@@ -213,7 +252,7 @@ void RemoteGdbAdapter::handleKill(const GdbResultRecord &response, const QVarian
if (response.resultClass == GdbResultDone) {
setState(InferiorShutDown);
emit inferiorShutDown();
shutdownAdapter(); // re-iterate...
shutdown(); // re-iterate...
} else if (response.resultClass == GdbResultError) {
QString msg = tr("Inferior process could not be stopped:\n") +
__(response.data.findChild("msg").data());
......@@ -240,10 +279,5 @@ void RemoteGdbAdapter::handleGdbFinished(int, QProcess::ExitStatus)
emit adapterShutDown();
}
void RemoteGdbAdapter::shutdownInferior()
{
m_engine->postCommand(_("kill"));
}
} // namespace Internal
} // namespace Debugger
......@@ -59,13 +59,16 @@ public:
void setWorkingDirectory(const QString &dir) { m_gdbProc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_gdbProc.setEnvironment(env); }
bool isAdapter() const { return false; }
void interruptInferior();
void startAdapter(const DebuggerStartParametersPtr &sp);
void prepareInferior();
void startInferior();
void shutdownInferior();
void shutdownAdapter();
void interruptInferior();
void shutdown();
void readUploadStandardOutput();
void readUploadStandardError();
void uploadProcError(QProcess::ProcessError error);
private:
void handleFileExecAndSymbols(const GdbResultRecord &, const QVariant &);
......@@ -79,6 +82,7 @@ private:
QProcess m_gdbProc;
DebuggerStartParametersPtr m_startParameters;
QProcess m_uploadProc;
};
} // namespace Internal
......
......@@ -1483,7 +1483,7 @@ void TrkGdbAdapter::sendGdbMessage(const QString &msg, GdbCallback callback,
}
//
// GdbProcessBase
// Rfcomm process handling
//
void TrkGdbAdapter::handleRfcommReadyReadStandardError()
......@@ -1523,6 +1523,7 @@ void TrkGdbAdapter::handleRfcommStateChanged(QProcess::ProcessState newState)
// AbstractGdbAdapter interface implementation
//
/*
void TrkGdbAdapter::kill()
{
if (m_options->mode == TrkOptions::BlueTooth
......@@ -1537,7 +1538,6 @@ void TrkGdbAdapter::terminate()
m_gdbProc.terminate();
}
/*
bool TrkGdbAdapter::waitForFinished(int msecs)
{
QByteArray ba;
......@@ -1582,12 +1582,7 @@ void TrkGdbAdapter::setEnvironment(const QStringList &env)
m_gdbProc.setEnvironment(env);
}
void TrkGdbAdapter::shutdownInferior()
{
m_engine->postCommand(_("kill"), CB(handleKill));
}
void TrkGdbAdapter::shutdownAdapter()
void TrkGdbAdapter::shutdown()
{
if (state() == InferiorStarted) {
setState(InferiorShuttingDown);
......@@ -1610,7 +1605,7 @@ void TrkGdbAdapter::handleKill(const GdbResultRecord &response, const QVariant &
if (response.resultClass == GdbResultDone) {
setState(InferiorShutDown);
emit inferiorShutDown();
shutdownAdapter(); // re-iterate...
shutdown(); // re-iterate...
} else if (response.resultClass == GdbResultError) {
QString msg = tr("Inferior process could not be stopped:\n") +
__(response.data.findChild("msg").data());
......
......@@ -109,8 +109,6 @@ public:
//
void start(const QString &program, const QStringList &args,
QIODevice::OpenMode mode = QIODevice::ReadWrite);
void kill();
void terminate();
QString errorString() const;
QByteArray readAllStandardError();
QByteArray readAllStandardOutput();
......@@ -118,16 +116,14 @@ public:
void setWorkingDirectory(const QString &dir);
void setEnvironment(const QStringList &env);
bool isAdapter() const { return true; }
//void attach();
void interruptInferior();
Q_SLOT void startInferiorEarly();
void startAdapter(const DebuggerStartParametersPtr &sp);
void prepareInferior();
void startInferior();
void shutdownInferior();
void shutdownAdapter();
void interruptInferior();
void shutdown();
Q_SLOT void startInferiorEarly();
void handleKill(const GdbResultRecord &, const QVariant &);
void handleExit(const GdbResultRecord &, const QVariant &);
void handleTargetRemote(const GdbResultRecord &, const QVariant &);
......
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