Commit d5f10357 authored by hjk's avatar hjk

debugger: refactoring

Move GdbAdapterState from individual adapters to GdbEngine.
Also, remove some trailing whitespace.
parent 386173d4
......@@ -38,28 +38,6 @@
namespace Debugger {
namespace Internal {
class GdbEngine;
enum GdbAdapterState
{
AdapterNotRunning,
AdapterStarting,
AdapterStarted,
AdapterStartFailed,
InferiorPreparing,
InferiorPrepared,
InferiorPreparationFailed,
InferiorStarting,
InferiorStarted,
InferiorStartFailed,
InferiorShuttingDown,
InferiorShutDown,
InferiorShutdownFailed,
AdapterShuttingDown,
//AdapterShutDown, // use AdapterNotRunning
AdapterShutdownFailed,
};
// AbstractGdbAdapter is inherited by PlainGdbAdapter used for local
// debugging and TrkGdbAdapter used for on-device debugging.
// In the PlainGdbAdapter case it's just a wrapper around a QProcess running
......@@ -71,7 +49,7 @@ class AbstractGdbAdapter : public QObject
public:
AbstractGdbAdapter(GdbEngine *engine, QObject *parent = 0)
: QObject(parent), m_engine(engine), m_state(AdapterNotRunning)
: QObject(parent), m_engine(engine)
{}
virtual QByteArray readAllStandardError() = 0;
......@@ -109,12 +87,9 @@ signals:
void readyReadStandardOutput();
void readyReadStandardError();
public:
GdbAdapterState state() const { return m_state; }
// Called by GdbEngine::handleAsyncOutput
void notifyInferiorExited();
protected:
GdbAdapterState state() const
{ return m_engine->state(); }
void setState(GdbAdapterState state);
const DebuggerStartParameters &startParameters() const
{ return m_engine->startParameters(); }
......@@ -122,7 +97,6 @@ protected:
{ m_engine->debugMessage(msg); }
GdbEngine * const m_engine;
GdbAdapterState m_state;
};
} // namespace Internal
......
......@@ -176,6 +176,7 @@ GdbEngine::GdbEngine(DebuggerManager *parent) :
qq(parent->engineInterface())
{
m_gdbAdapter = 0;
m_state = AdapterNotRunning;
QSharedPointer<TrkOptions> options(new TrkOptions);
options->fromSettings(Core::ICore::instance()->settings());
m_plainAdapter = new PlainGdbAdapter(this);
......@@ -659,7 +660,7 @@ void GdbEngine::interruptInferior()
// debugMessage(_("GDBENGINE INTERRUPT INFERIOR: %1").arg(m_gdbAdapter->state()));
qq->notifyInferiorStopRequested();
if (m_gdbAdapter->state() == AdapterNotRunning) {
if (state() == AdapterNotRunning) {
debugMessage(_("TRYING TO INTERRUPT INFERIOR WITHOUT RUNNING GDB"));
shutdown();
return;
......@@ -725,7 +726,7 @@ void GdbEngine::postCommand(const QString &command, GdbCommandFlags flags,
void GdbEngine::postCommandHelper(const GdbCommand &cmd)
{
if (!stateAcceptsGdbCommands(m_gdbAdapter->state())) {
if (!stateAcceptsGdbCommands(state())) {
PENDING_DEBUG(_("NO GDB PROCESS RUNNING, CMD IGNORED: ") + cmd.command);
debugMessage(_("NO GDB PROCESS RUNNING, CMD IGNORED: ") + cmd.command);
return;
......@@ -759,7 +760,7 @@ void GdbEngine::postCommandHelper(const GdbCommand &cmd)
void GdbEngine::flushCommand(const GdbCommand &cmd0)
{
GdbCommand cmd = cmd0;
if (m_gdbAdapter->state() == AdapterNotRunning) {
if (state() == AdapterNotRunning) {
emit gdbInputAvailable(LogInput, cmd.command);
debugMessage(_("GDB PROCESS NOT RUNNING, PLAIN CMD IGNORED: ") + cmd.command);
return;
......@@ -862,7 +863,7 @@ void GdbEngine::handleResultRecord(const GdbResponse &response)
void GdbEngine::executeDebuggerCommand(const QString &command)
{
if (m_gdbAdapter->state() == AdapterNotRunning) {
if (state() == AdapterNotRunning) {
debugMessage(_("GDB PROCESS NOT RUNNING, PLAIN CMD IGNORED: ") + command);
return;
}
......@@ -1079,7 +1080,9 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data)
if (isExitedReason(reason)) {
// Give adapter a chance to take notice of regular exits.
m_gdbAdapter->notifyInferiorExited();
QTC_ASSERT(state() == InferiorStarted, /**/);
setState(InferiorShuttingDown);
setState(InferiorShutDown);
QString msg;
if (reason == "exited") {
......@@ -4217,10 +4220,6 @@ void GdbEngine::showMessageBox(int icon, const QString &title, const QString &te
m_manager->showMessageBox(icon, title, text);
}
//
// AbstractGdbAdapter
//
static bool isAllowedTransition(int from, int to)
{
return (from == -1)
......@@ -4242,20 +4241,27 @@ static bool isAllowedTransition(int from, int to)
;
}
void AbstractGdbAdapter::setState(GdbAdapterState state)
GdbAdapterState GdbEngine::state() const
{
return m_state;
}
void GdbEngine::setState(GdbAdapterState state)
{
QString msg = _("Adapter state from %1 to state %2.").arg(m_state).arg(state);
if (!isAllowedTransition(m_state, state))
qDebug() << "UNEXPECTED ADAPTER TRANSITION: " << msg;
m_engine->debugMessage(msg);
debugMessage(msg);
m_state = state;
}
void AbstractGdbAdapter::notifyInferiorExited()
//
// AbstractGdbAdapter
//
void AbstractGdbAdapter::setState(GdbAdapterState state)
{
QTC_ASSERT(state() == InferiorStarted, /**/);
setState(InferiorShuttingDown);
setState(InferiorShutDown);
m_engine->setState(state);
}
//
......
......@@ -79,6 +79,26 @@ enum DebuggingHelperState
DebuggingHelperUnavailable,
};
enum GdbAdapterState
{
AdapterNotRunning,
AdapterStarting,
AdapterStarted,
AdapterStartFailed,
InferiorPreparing,
InferiorPrepared,
InferiorPreparationFailed,
InferiorStarting,
InferiorStarted,
InferiorStartFailed,
InferiorShuttingDown,
InferiorShutDown,
InferiorShutdownFailed,
AdapterShuttingDown,
//AdapterShutDown, // use AdapterNotRunning
AdapterShutdownFailed,
};
class GdbEngine : public IDebuggerEngine
{
Q_OBJECT
......@@ -201,7 +221,7 @@ private:
// type and cookie are sender-internal data, opaque for the "event
// queue". resultNeeded == true increments m_pendingResults on
// send and decrements on receipt, effectively preventing
// send and decrements on receipt, effectively preventing
// watch model updates before everything is finished.
void flushCommand(const GdbCommand &cmd);
void postCommand(const QString &command,
......@@ -302,7 +322,7 @@ private:
int m_oldestAcceptableToken;
int m_gdbVersion; // 6.8.0 is 680
int m_gdbBuildVersion; // MAC only?
int m_gdbBuildVersion; // MAC only?
// awful hack to keep track of used files
QMap<QString, QString> m_shortToFullName;
......@@ -331,7 +351,7 @@ private:
//
// Register specific stuff
//
//
Q_SLOT void reloadRegisters();
void setRegisterValue(int nr, const QString &value);
void handleRegisterListNames(const GdbResponse &response);
......@@ -339,12 +359,12 @@ private:
//
// Source file specific stuff
//
//
void reloadSourceFiles();
//
// Stack specific stuff
//
//
void handleStackListFrames(const GdbResponse &response);
void handleStackSelectThread(const GdbResponse &response);
void handleStackListThreads(const GdbResponse &response);
......@@ -354,7 +374,7 @@ private:
//
// Tooltip specific stuff
//
//
void sendToolTipCommand(const QString &command, const QString &cookie);
......@@ -401,15 +421,15 @@ private:
void setLocals(const QList<GdbMi> &locals);
void connectDebuggingHelperActions();
void disconnectDebuggingHelperActions();
bool startModeAllowsDumpers() const;
QString parseDisassembler(const GdbMi &lines);
int m_pendingRequests;
QSet<QString> m_processedNames;
QSet<QString> m_processedNames;
QtDumperHelper m_dumperHelper;
DebuggingHelperState m_debuggingHelperState;
QList<GdbMi> m_currentFunctionArgs;
QString m_currentFrame;
......@@ -436,7 +456,13 @@ private:
PlainGdbAdapter *m_plainAdapter; // owned
RemoteGdbAdapter *m_remoteAdapter; // owned
TrkGdbAdapter *m_trkAdapter; // owned
// State
friend class AbstractGdbAdapter;
GdbAdapterState m_state;
void setState(GdbAdapterState state);
GdbAdapterState state() const;
public:
void showMessageBox(int icon, const QString &title, const QString &text);
void debugMessage(const QString &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