Commit cff3b9e0 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen

centralize some code in AbstractGdbAdapter

parent ccf4fe9a
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "abstractgdbadapter.h"
#include <utils/qtcassert.h>
#include <QtCore/QObject>
#include <QtCore/QProcess>
namespace Debugger {
namespace Internal {
AbstractGdbAdapter::AbstractGdbAdapter(GdbEngine *engine, QObject *parent)
: QObject(parent), m_engine(engine)
{
}
AbstractGdbAdapter::~AbstractGdbAdapter()
{
disconnect();
}
// This cannot be in the c'tor, as it would not connect the "virtual" slots
void AbstractGdbAdapter::commonInit()
{
QTC_ASSERT(state() == DebuggerNotReady, qDebug() << state());
connect(&m_gdbProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(handleGdbError(QProcess::ProcessError)));
connect(&m_gdbProc, SIGNAL(started()),
this, SLOT(handleGdbStarted()));
connect(&m_gdbProc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
connect(&m_gdbProc, SIGNAL(readyReadStandardOutput()),
this, SIGNAL(readyReadStandardOutput()));
connect(&m_gdbProc, SIGNAL(readyReadStandardError()),
this, SIGNAL(readyReadStandardError()));
}
QByteArray AbstractGdbAdapter::readAllStandardOutput()
{
return m_gdbProc.readAllStandardOutput();
}
QByteArray AbstractGdbAdapter::readAllStandardError()
{
return m_gdbProc.readAllStandardError();
}
void AbstractGdbAdapter::write(const QByteArray &data)
{
m_gdbProc.write(data);
}
bool AbstractGdbAdapter::isTrkAdapter() const
{
return false;
}
} // namespace Internal
} // namespace Debugger
......@@ -48,15 +48,13 @@ class AbstractGdbAdapter : public QObject
Q_OBJECT
public:
AbstractGdbAdapter(GdbEngine *engine, QObject *parent = 0)
: QObject(parent), m_engine(engine)
{}
virtual ~AbstractGdbAdapter() { disconnect(); }
AbstractGdbAdapter(GdbEngine *engine, QObject *parent = 0);
virtual ~AbstractGdbAdapter();
virtual QByteArray readAllStandardError() = 0;
virtual QByteArray readAllStandardOutput() = 0;
virtual void write(const QByteArray &data) = 0;
virtual bool isTrkAdapter() const = 0;
QByteArray readAllStandardOutput();
QByteArray readAllStandardError();
virtual void write(const QByteArray &data);
virtual bool isTrkAdapter() const; // isUtterlyBrokenAdapter
virtual void startAdapter() = 0;
virtual void prepareInferior() = 0;
......@@ -83,6 +81,7 @@ signals:
void readyReadStandardError();
protected:
void commonInit();
DebuggerState state() const
{ return m_engine->state(); }
void setState(DebuggerState state)
......@@ -95,6 +94,8 @@ protected:
{ m_engine->showStatusMessage(msg); }
GdbEngine * const m_engine;
QProcess m_gdbProc;
};
} // namespace Internal
......
......@@ -53,17 +53,7 @@ namespace Internal {
AttachGdbAdapter::AttachGdbAdapter(GdbEngine *engine, QObject *parent)
: AbstractGdbAdapter(engine, parent)
{
QTC_ASSERT(state() == DebuggerNotReady, qDebug() << state());
connect(&m_gdbProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(handleGdbError(QProcess::ProcessError)));
connect(&m_gdbProc, SIGNAL(readyReadStandardOutput()),
this, SIGNAL(readyReadStandardOutput()));
connect(&m_gdbProc, SIGNAL(readyReadStandardError()),
this, SIGNAL(readyReadStandardError()));
connect(&m_gdbProc, SIGNAL(started()),
this, SLOT(handleGdbStarted()));
connect(&m_gdbProc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
commonInit();
}
void AttachGdbAdapter::startAdapter()
......
......@@ -52,11 +52,6 @@ class AttachGdbAdapter : public AbstractGdbAdapter
public:
AttachGdbAdapter(GdbEngine *engine, QObject *parent = 0);
private:
QByteArray readAllStandardError() { return m_gdbProc.readAllStandardError(); }
QByteArray readAllStandardOutput() { return m_gdbProc.readAllStandardOutput(); }
void write(const QByteArray &data) { m_gdbProc.write(data, data.size()); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return false; }
void startAdapter();
......@@ -65,6 +60,7 @@ private:
void interruptInferior();
void shutdown();
private:
void handleAttach(const GdbResponse &response);
void handleDetach(const GdbResponse &response);
void handleExit(const GdbResponse &response);
......@@ -72,8 +68,6 @@ private:
Q_SLOT void handleGdbStarted();
Q_SLOT void handleGdbFinished(int, QProcess::ExitStatus);
Q_SLOT void handleGdbError(QProcess::ProcessError error);
QProcess m_gdbProc;
};
} // namespace Internal
......
......@@ -53,17 +53,7 @@ namespace Internal {
CoreGdbAdapter::CoreGdbAdapter(GdbEngine *engine, QObject *parent)
: AbstractGdbAdapter(engine, parent)
{
QTC_ASSERT(state() == DebuggerNotReady, qDebug() << state());
connect(&m_gdbProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(handleGdbError(QProcess::ProcessError)));
connect(&m_gdbProc, SIGNAL(readyReadStandardOutput()),
this, SIGNAL(readyReadStandardOutput()));
connect(&m_gdbProc, SIGNAL(readyReadStandardError()),
this, SIGNAL(readyReadStandardError()));
connect(&m_gdbProc, SIGNAL(started()),
this, SLOT(handleGdbStarted()));
connect(&m_gdbProc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
commonInit();
}
void CoreGdbAdapter::startAdapter()
......
......@@ -52,11 +52,6 @@ class CoreGdbAdapter : public AbstractGdbAdapter
public:
CoreGdbAdapter(GdbEngine *engine, QObject *parent = 0);
private:
QByteArray readAllStandardError() { return m_gdbProc.readAllStandardError(); }
QByteArray readAllStandardOutput() { return m_gdbProc.readAllStandardOutput(); }
void write(const QByteArray &data) { m_gdbProc.write(data, data.size()); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return false; }
void startAdapter();
......@@ -65,6 +60,7 @@ private:
void interruptInferior();
void shutdown();
private:
void handleTargetCore1(const GdbResponse &response);
void handleDetach1(const GdbResponse &response);
void handleFileExecAndSymbols(const GdbResponse &response);
......@@ -75,7 +71,6 @@ private:
Q_SLOT void handleGdbError(QProcess::ProcessError error);
Q_SLOT void handleGdbFinished(int, QProcess::ExitStatus);
QProcess m_gdbProc;
QString m_executable;
};
......
......@@ -26,6 +26,7 @@ SOURCES += \
$$PWD/trkoptions.cpp \
$$PWD/trkoptionswidget.cpp \
$$PWD/trkoptionspage.cpp \
$$PWD/abstractgdbadapter.cpp \
$$PWD/attachgdbadapter.cpp \
$$PWD/coregdbadapter.cpp \
$$PWD/plaingdbadapter.cpp \
......
......@@ -58,17 +58,7 @@ namespace Internal {
PlainGdbAdapter::PlainGdbAdapter(GdbEngine *engine, QObject *parent)
: AbstractGdbAdapter(engine, parent)
{
QTC_ASSERT(state() == DebuggerNotReady, qDebug() << state());
connect(&m_gdbProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(handleGdbError(QProcess::ProcessError)));
connect(&m_gdbProc, SIGNAL(readyReadStandardOutput()),
this, SIGNAL(readyReadStandardOutput()));
connect(&m_gdbProc, SIGNAL(readyReadStandardError()),
this, SIGNAL(readyReadStandardError()));
connect(&m_gdbProc, SIGNAL(started()),
this, SLOT(handleGdbStarted()));
connect(&m_gdbProc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
commonInit();
m_stubProc.setMode(Utils::ConsoleProcess::Debug);
#ifdef Q_OS_UNIX
......
......@@ -55,10 +55,6 @@ class PlainGdbAdapter : public AbstractGdbAdapter
public:
PlainGdbAdapter(GdbEngine *engine, QObject *parent = 0);
QByteArray readAllStandardError() { return m_gdbProc.readAllStandardError(); }
QByteArray readAllStandardOutput() { return m_gdbProc.readAllStandardOutput(); }
void write(const QByteArray &data) { m_gdbProc.write(data, data.size()); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return true; }
void startAdapter();
......@@ -81,7 +77,6 @@ private:
Q_SLOT void stubStarted();
Q_SLOT void stubError(const QString &msg);
QProcess m_gdbProc;
Utils::ConsoleProcess m_stubProc;
OutputCollector m_outputCollector;
};
......
......@@ -54,17 +54,7 @@ namespace Internal {
RemoteGdbAdapter::RemoteGdbAdapter(GdbEngine *engine, QObject *parent)
: AbstractGdbAdapter(engine, parent)
{
QTC_ASSERT(state() == DebuggerNotReady, qDebug() << state());
connect(&m_gdbProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(handleGdbError(QProcess::ProcessError)));
connect(&m_gdbProc, SIGNAL(readyReadStandardOutput()),
this, SIGNAL(readyReadStandardOutput()));
connect(&m_gdbProc, SIGNAL(readyReadStandardError()),
this, SIGNAL(readyReadStandardError()));
connect(&m_gdbProc, SIGNAL(started()),
this, SLOT(handleGdbStarted()));
connect(&m_gdbProc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
commonInit();
connect(&m_uploadProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(uploadProcError(QProcess::ProcessError)));
......
......@@ -52,11 +52,6 @@ class RemoteGdbAdapter : public AbstractGdbAdapter
public:
RemoteGdbAdapter(GdbEngine *engine, QObject *parent = 0);
private:
QByteArray readAllStandardError() { return m_gdbProc.readAllStandardError(); }
QByteArray readAllStandardOutput() { return m_gdbProc.readAllStandardOutput(); }
void write(const QByteArray &data) { m_gdbProc.write(data, data.size()); }
bool isTrkAdapter() const { return false; }
bool dumpersAvailable() const { return true; }
void startAdapter();
......@@ -65,6 +60,7 @@ private:
void interruptInferior();
void shutdown();
private:
Q_SLOT void readUploadStandardOutput();
Q_SLOT void readUploadStandardError();
Q_SLOT void uploadProcError(QProcess::ProcessError error);
......@@ -79,7 +75,6 @@ private:
Q_SLOT void handleGdbError(QProcess::ProcessError error);
Q_SLOT void handleGdbFinished(int, QProcess::ExitStatus);
QProcess m_gdbProc;
QProcess m_uploadProc;
};
......
......@@ -203,16 +203,8 @@ TrkGdbAdapter::TrkGdbAdapter(GdbEngine *engine, const TrkOptionsPtr &options) :
const uid_t portOffset = getuid();
#endif
m_gdbServerName = _("127.0.0.1:%1").arg(2222 + portOffset);
connect(&m_gdbProc, SIGNAL(readyReadStandardError()),
this, SIGNAL(readyReadStandardError()));
connect(&m_gdbProc, SIGNAL(readyReadStandardOutput()),
this, SIGNAL(readyReadStandardOutput()));
connect(&m_gdbProc, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(handleGdbError(QProcess::ProcessError)));
connect(&m_gdbProc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleGdbFinished(int, QProcess::ExitStatus)));
connect(&m_gdbProc, SIGNAL(started()),
this, SLOT(handleGdbStarted()));
commonInit();
connect(&m_gdbProc, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(handleGdbStateChanged(QProcess::ProcessState)));
......@@ -1830,16 +1822,6 @@ void TrkGdbAdapter::handleRfcommStateChanged(QProcess::ProcessState newState)
// AbstractGdbAdapter interface implementation
//
QByteArray TrkGdbAdapter::readAllStandardError()
{
return m_gdbProc.readAllStandardError();
}
QByteArray TrkGdbAdapter::readAllStandardOutput()
{
return m_gdbProc.readAllStandardOutput();
}
void TrkGdbAdapter::write(const QByteArray &data)
{
// Write magic packets directly to TRK.
......@@ -1870,7 +1852,7 @@ void TrkGdbAdapter::write(const QByteArray &data)
trkReadMemoryMessage(m_session.dataseg, 12));
return;
}
m_gdbProc.write(data, data.size());
m_gdbProc.write(data);
}
uint oldPC;
......
......@@ -155,7 +155,6 @@ private:
QString m_gdbServerName; // 127.0.0.1:(2222+uid)
QProcess m_gdbProc;
QProcess m_rfcommProc;
bool m_running;
......
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