Commit 77e3bfe8 authored by hjk's avatar hjk
Browse files

debugger: structural cleanup remote debugging

Use virtual function instead of if/qobject_cast cascades.
parent 91e6c14f
......@@ -1430,6 +1430,17 @@ void DebuggerEngine::openDisassemblerView(const StackFrame &frame)
agent->setFrame(frame, true, false);
}
void DebuggerEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
Q_UNUSED(gdbServerPort);
Q_UNUSED(qmlPort);
}
void DebuggerEngine::handleRemoteSetupFailed(const QString &message)
{
Q_UNUSED(message);
}
} // namespace Debugger
#include "debuggerengine.moc"
......@@ -35,7 +35,7 @@
#include "moduleshandler.h" // For 'Symbols'
#include "breakpoint.h" // For 'BreakpointId'
#include <coreplugin/ssh/sshconnection.h>
#include <coreplugin/ssh/sshconnection.h>
#include <utils/environment.h>
......@@ -203,6 +203,9 @@ public:
virtual void removeTooltip();
virtual void selectThread(int index);
virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
virtual void handleRemoteSetupFailed(const QString &message);
protected:
friend class Internal::DebuggerPluginPrivate;
virtual void detachDebugger();
......@@ -255,7 +258,7 @@ public:
void breakByFunction(const QString &functionName);
void breakByFunctionMain();
DebuggerState state() const;
DebuggerState lastGoodState() const;
DebuggerState targetState() const;
......@@ -289,6 +292,15 @@ public:
signals:
void stateChanged(const DebuggerState &state);
void updateViewsRequested();
/*
* For "external" clients of a debugger run control that need to do
* further setup before the debugger is started (e.g. Maemo).
* Afterwards, handleSetupDone() or handleSetupFailed() must be called
* to continue or abort debugging, respectively.
* This signal is only emitted if the start parameters indicate that
* a server start script should be used, but none is given.
*/
void requestRemoteSetup();
protected:
// The base notify*() function implementation should be sufficient
......
......@@ -35,12 +35,7 @@
#include "debuggermainwindow.h"
#include "debuggerplugin.h"
#include "debuggerstringutils.h"
#include "gdb/gdbengine.h"
#include "gdb/remotegdbserveradapter.h"
#include "gdb/remoteplaingdbadapter.h"
#include "gdb/gdboptionspage.h"
#include "qml/qmlengine.h"
#include "qml/qmlcppengine.h"
#include "lldb/lldbenginehost.h"
#ifdef Q_OS_WIN
......@@ -269,10 +264,6 @@ public:
DebuggerEngineType engineForMode(unsigned enabledEngineTypes,
DebuggerStartMode mode);
void initGdbEngine(GdbEngine *engine);
GdbEngine *gdbEngine() const;
AbstractGdbAdapter *gdbAdapter() const;
public:
DebuggerRunControl *q;
DebuggerEngine *m_engine;
......@@ -383,38 +374,6 @@ DebuggerEngineType DebuggerRunControlPrivate::engineForMode
#endif
}
void DebuggerRunControlPrivate::initGdbEngine(GdbEngine *engine)
{
QTC_ASSERT(engine, return)
// Forward adapter signals.
AbstractGdbAdapter *adapter = engine->gdbAdapter();
RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter);
RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter);
if (rpga)
q->connect(rpga, SIGNAL(requestSetup()), SIGNAL(engineRequestSetup()));
else if (rgsa)
q->connect(rgsa, SIGNAL(requestSetup()), SIGNAL(engineRequestSetup()));
}
GdbEngine *DebuggerRunControlPrivate::gdbEngine() const
{
QTC_ASSERT(m_engine, return 0);
if (GdbEngine *gdbEngine = qobject_cast<GdbEngine *>(m_engine))
return gdbEngine;
if (QmlCppEngine *qmlEngine = qobject_cast<QmlCppEngine *>(m_engine))
if (GdbEngine *embeddedGdbEngine = qobject_cast<GdbEngine *>(qmlEngine->cppEngine()))
return embeddedGdbEngine;
return 0;
}
AbstractGdbAdapter *DebuggerRunControlPrivate::gdbAdapter() const
{
GdbEngine *engine = gdbEngine();
QTC_ASSERT(engine, return 0)
return engine->gdbAdapter();
}
} // namespace Internal
......@@ -514,7 +473,6 @@ DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
switch (engineType) {
case GdbEngineType:
d->m_engine = createGdbEngine(sp);
d->initGdbEngine(qobject_cast<GdbEngine *>(d->m_engine));
break;
case ScriptEngineType:
d->m_engine = createScriptEngine(sp);
......@@ -534,14 +492,9 @@ DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
break;
case QmlEngineType:
d->m_engine = createQmlEngine(sp);
connect(qobject_cast<QmlEngine *>(d->m_engine),
SIGNAL(remoteStartupRequested()),
SIGNAL(engineRequestSetup()));
break;
case QmlCppEngineType:
d->m_engine = createQmlCppEngine(sp);
if (GdbEngine *embeddedGdbEngine = d->gdbEngine())
d->initGdbEngine(embeddedGdbEngine);
break;
case LldbEngineType:
d->m_engine = createLldbEngine(sp);
......@@ -742,56 +695,6 @@ DebuggerEngine *DebuggerRunControl::engine()
return d->m_engine;
}
void DebuggerRunControl::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
// FIXME: Use virtual functions?
if (QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(d->m_engine)) {
qmlEngine->handleRemoteSetupDone(qmlPort);
return;
}
AbstractGdbAdapter *adapter = d->gdbAdapter();
QTC_ASSERT(adapter, return);
RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter);
if (rpga) {
rpga->handleSetupDone(qmlPort);
return;
}
RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter);
if (rgsa) {
rgsa->handleSetupDone(gdbServerPort, qmlPort);
return;
}
QTC_ASSERT(false, /**/);
}
void DebuggerRunControl::handleRemoteSetupFailed(const QString &message)
{
// FIXME: Use virtual functions?
if (QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(d->m_engine)) {
qmlEngine->handleRemoteSetupFailed(message);
return;
}
AbstractGdbAdapter *adapter = d->gdbAdapter();
QTC_ASSERT(adapter, return);
RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter);
if (rpga) {
rpga->handleSetupFailed(message);
return;
}
RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter);
if (rgsa) {
rgsa->handleSetupFailed(message);
return;
}
QTC_ASSERT(false, /**/);
}
RunConfiguration *DebuggerRunControl::runConfiguration() const
{
return d->m_myRunConfiguration.data();
......
......@@ -106,9 +106,6 @@ public:
void showMessage(const QString &msg, int channel);
void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
void handleRemoteSetupFailed(const QString &message);
static bool checkDebugConfiguration(int toolChain,
QString *errorMessage,
QString *settingsCategory = 0,
......
......@@ -145,5 +145,16 @@ void AbstractGdbAdapter::showMessage(const QString &msg, int channel, int timeou
m_engine->showMessage(msg, channel, timeout);
}
void AbstractGdbAdapter::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
Q_UNUSED(gdbServerPort);
Q_UNUSED(qmlPort);
}
void AbstractGdbAdapter::handleRemoteSetupFailed(const QString &reason)
{
Q_UNUSED(reason);
}
} // namespace Internal
} // namespace Debugger
......@@ -90,6 +90,9 @@ public:
virtual void trkReloadRegisters() {}
virtual void trkReloadThreads() {}
virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
virtual void handleRemoteSetupFailed(const QString &reason);
protected:
DebuggerState state() const;
const DebuggerStartParameters &startParameters() const;
......
......@@ -4398,6 +4398,16 @@ void GdbEngine::removeTooltip()
DebuggerEngine::removeTooltip();
}
void GdbEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
m_gdbAdapter->handleRemoteSetupDone(gdbServerPort, qmlPort);
}
void GdbEngine::handleRemoteSetupFailed(const QString &message)
{
m_gdbAdapter->handleRemoteSetupFailed(message);
}
//
// Factory
//
......
......@@ -127,6 +127,8 @@ private: ////////// Gdb Process Management //////////
const QString &settingsIdHint = QString());
void handleInferiorShutdown(const GdbResponse &response);
void handleGdbExit(const GdbResponse &response);
void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
void handleRemoteSetupFailed(const QString &message);
void handleAdapterStarted();
void defaultInferiorShutdown(const char *cmd);
......
......@@ -96,7 +96,7 @@ void RemoteGdbServerAdapter::startAdapter()
}
if (startParameters().serverStartScript.isEmpty()) {
showMessage(_("No server start script given. "), StatusBar);
emit requestSetup();
m_engine->requestRemoteSetup();
} else {
m_uploadProc.start(_("/bin/sh ") + startParameters().serverStartScript);
m_uploadProc.waitForStarted();
......
......@@ -50,8 +50,7 @@ void RemotePlainGdbAdapter::startAdapter()
{
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
showMessage(QLatin1String("TRYING TO START ADAPTER"));
emit requestSetup();
m_engine->requestRemoteSetup();
}
void RemotePlainGdbAdapter::setupInferior()
......@@ -101,8 +100,9 @@ void RemotePlainGdbAdapter::shutdownAdapter()
m_engine->notifyAdapterShutdownOk();
}
void RemotePlainGdbAdapter::handleSetupDone(int qmlPort)
void RemotePlainGdbAdapter::handleSetupDone(int gdbServerPort, int qmlPort)
{
Q_UNUSED(gdbServerPort);
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
if (qmlPort != -1)
......
......@@ -43,12 +43,9 @@ class RemotePlainGdbAdapter : public AbstractPlainGdbAdapter
public:
friend class RemoteGdbProcess;
explicit RemotePlainGdbAdapter(GdbEngine *engine, QObject *parent = 0);
void handleSetupDone(int qmlPort);
void handleSetupDone(int gdbServerPort, int qmlPort);
void handleSetupFailed(const QString &reason);
signals:
void requestSetup();
private slots:
void handleGdbStarted();
void handleGdbStartFailed();
......
......@@ -634,6 +634,18 @@ void QmlCppEngine::engineStateChanged(const DebuggerState &newState)
}
}
void QmlCppEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
d->m_qmlEngine->handleRemoteSetupDone(gdbServerPort, qmlPort);
d->m_cppEngine->handleRemoteSetupDone(gdbServerPort, qmlPort);
}
void QmlCppEngine::handleRemoteSetupFailed(const QString &message)
{
d->m_qmlEngine->handleRemoteSetupFailed(message);
d->m_cppEngine->handleRemoteSetupFailed(message);
}
DebuggerEngine *QmlCppEngine::cppEngine() const
{
return d->m_cppEngine;
......
......@@ -71,6 +71,8 @@ public:
QAbstractItemModel *sourceFilesModel() const;
DebuggerEngine *cppEngine() const;
virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
virtual void handleRemoteSetupFailed(const QString &message);
protected:
virtual void detachDebugger();
......
......@@ -200,7 +200,7 @@ void QmlEngine::setupInferior()
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
if (startParameters().startMode == AttachToRemote) {
emit remoteStartupRequested();
requestRemoteSetup();
} else {
connect(&d->m_applicationLauncher, SIGNAL(processExited(int)),
SLOT(disconnected()));
......
......@@ -121,7 +121,7 @@ MaemoDebugSupport::MaemoDebugSupport(MaemoRunConfiguration *runConfig,
m_dumperLib(runConfig->dumperLib()),
m_state(Inactive), m_gdbServerPort(-1), m_qmlPort(-1)
{
connect(m_runControl, SIGNAL(engineRequestSetup()), this,
connect(m_runControl->engine(), SIGNAL(requestRemoteSetup()), this,
SLOT(handleAdapterSetupRequested()));
connect(m_runControl, SIGNAL(finished()), this,
SLOT(handleDebuggingFinished()));
......@@ -320,13 +320,13 @@ void MaemoDebugSupport::handleProgressReport(const QString &progressOutput)
void MaemoDebugSupport::handleAdapterSetupFailed(const QString &error)
{
setState(Inactive);
m_runControl->handleRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
m_runControl->engine()->handleRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
}
void MaemoDebugSupport::handleAdapterSetupDone()
{
setState(Debugging);
m_runControl->handleRemoteSetupDone(m_gdbServerPort, m_qmlPort);
m_runControl->engine()->handleRemoteSetupDone(m_gdbServerPort, m_qmlPort);
}
void MaemoDebugSupport::setState(State newState)
......
Supports Markdown
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