Maemo: Introduce states to debug support class.

Task-number: QTCREATORBUG-2705
This commit is contained in:
Christian Kandeler
2010-10-29 16:19:56 +02:00
parent 3641c6e0b8
commit aa1456dbe8
2 changed files with 68 additions and 32 deletions

View File

@@ -50,6 +50,8 @@
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
using namespace Core; using namespace Core;
using namespace Debugger; using namespace Debugger;
using namespace Debugger::Internal; using namespace Debugger::Internal;
@@ -116,7 +118,8 @@ MaemoDebugSupport::MaemoDebugSupport(MaemoRunConfiguration *runConfig,
: QObject(runControl), m_runControl(runControl), m_runConfig(runConfig), : QObject(runControl), m_runControl(runControl), m_runConfig(runConfig),
m_deviceConfig(m_runConfig->deviceConfig()), m_deviceConfig(m_runConfig->deviceConfig()),
m_runner(new MaemoSshRunner(this, m_runConfig, true)), m_runner(new MaemoSshRunner(this, m_runConfig, true)),
m_qmlOnlyDebugging(m_runConfig->debuggingType() == MaemoRunConfiguration::DebugQmlOnly) m_qmlOnlyDebugging(m_runConfig->debuggingType() == MaemoRunConfiguration::DebugQmlOnly),
m_state(Inactive)
{ {
connect(m_runControl, SIGNAL(engineRequestSetup()), this, connect(m_runControl, SIGNAL(engineRequestSetup()), this,
SLOT(handleAdapterSetupRequested())); SLOT(handleAdapterSetupRequested()));
@@ -126,17 +129,18 @@ MaemoDebugSupport::MaemoDebugSupport(MaemoRunConfiguration *runConfig,
MaemoDebugSupport::~MaemoDebugSupport() MaemoDebugSupport::~MaemoDebugSupport()
{ {
stopSsh(); setState(Inactive);
} }
void MaemoDebugSupport::handleAdapterSetupRequested() void MaemoDebugSupport::handleAdapterSetupRequested()
{ {
ASSERT_STATE(Inactive);
if (!m_deviceConfig.isValid()) { if (!m_deviceConfig.isValid()) {
handleAdapterSetupFailed(tr("No device configuration set for run configuration.")); handleAdapterSetupFailed(tr("No device configuration set for run configuration."));
return; return;
} }
m_adapterStarted = false; setState(StartingRunner);
m_stopped = false;
m_runControl->showMessage(tr("Preparing remote side ..."), AppStuff); m_runControl->showMessage(tr("Preparing remote side ..."), AppStuff);
disconnect(m_runner, 0, this, 0); disconnect(m_runner, 0, this, 0);
connect(m_runner, SIGNAL(error(QString)), this, connect(m_runner, SIGNAL(error(QString)), this,
@@ -150,19 +154,26 @@ void MaemoDebugSupport::handleAdapterSetupRequested()
void MaemoDebugSupport::handleSshError(const QString &error) void MaemoDebugSupport::handleSshError(const QString &error)
{ {
if (!m_stopped && !m_adapterStarted) if (m_state == Debugging) {
m_runControl->showMessage(tr("SSH connection error: %1").arg(error),
AppError);
} else if (m_state != Inactive) {
handleAdapterSetupFailed(error); handleAdapterSetupFailed(error);
}
} }
void MaemoDebugSupport::startExecution() void MaemoDebugSupport::startExecution()
{ {
if (m_stopped) if (m_state == Inactive)
return; return;
ASSERT_STATE(StartingRunner);
const QString &dumperLib = m_runConfig->dumperLib(); const QString &dumperLib = m_runConfig->dumperLib();
if (!m_qmlOnlyDebugging && !dumperLib.isEmpty() if (!m_qmlOnlyDebugging && !dumperLib.isEmpty()
&& m_runConfig->deployStep()->currentlyNeedsDeployment(m_deviceConfig.server.host, && m_runConfig->deployStep()->currentlyNeedsDeployment(m_deviceConfig.server.host,
MaemoDeployable(dumperLib, uploadDir(m_deviceConfig)))) { MaemoDeployable(dumperLib, uploadDir(m_deviceConfig)))) {
setState(InitializingUploader);
m_uploader = m_runner->connection()->createSftpChannel(); m_uploader = m_runner->connection()->createSftpChannel();
connect(m_uploader.data(), SIGNAL(initialized()), this, connect(m_uploader.data(), SIGNAL(initialized()), this,
SLOT(handleSftpChannelInitialized())); SLOT(handleSftpChannelInitialized()));
@@ -172,15 +183,18 @@ void MaemoDebugSupport::startExecution()
this, SLOT(handleSftpJobFinished(Core::SftpJobId, QString))); this, SLOT(handleSftpJobFinished(Core::SftpJobId, QString)));
m_uploader->initialize(); m_uploader->initialize();
} else { } else {
setState(DumpersUploaded);
startDebugging(); startDebugging();
} }
} }
void MaemoDebugSupport::handleSftpChannelInitialized() void MaemoDebugSupport::handleSftpChannelInitialized()
{ {
if (m_stopped) if (m_state == Inactive)
return; return;
ASSERT_STATE(InitializingUploader);
const QString dumperLib = m_runConfig->dumperLib(); const QString dumperLib = m_runConfig->dumperLib();
const QString fileName = QFileInfo(dumperLib).fileName(); const QString fileName = QFileInfo(dumperLib).fileName();
const QString remoteFilePath = uploadDir(m_deviceConfig) + '/' + fileName; const QString remoteFilePath = uploadDir(m_deviceConfig) + '/' + fileName;
@@ -190,6 +204,7 @@ void MaemoDebugSupport::handleSftpChannelInitialized()
handleAdapterSetupFailed(tr("Upload failed: Could not open file '%1'") handleAdapterSetupFailed(tr("Upload failed: Could not open file '%1'")
.arg(dumperLib)); .arg(dumperLib));
} else { } else {
setState(UploadingDumpers);
m_runControl->showMessage(tr("Started uploading debugging helpers ('%1').") m_runControl->showMessage(tr("Started uploading debugging helpers ('%1').")
.arg(dumperLib), AppStuff); .arg(dumperLib), AppStuff);
} }
@@ -197,18 +212,20 @@ void MaemoDebugSupport::handleSftpChannelInitialized()
void MaemoDebugSupport::handleSftpChannelInitializationFailed(const QString &error) void MaemoDebugSupport::handleSftpChannelInitializationFailed(const QString &error)
{ {
if (m_stopped) if (m_state == Inactive)
return; return;
ASSERT_STATE(InitializingUploader);
handleAdapterSetupFailed(error); handleAdapterSetupFailed(error);
} }
void MaemoDebugSupport::handleSftpJobFinished(Core::SftpJobId job, void MaemoDebugSupport::handleSftpJobFinished(Core::SftpJobId job,
const QString &error) const QString &error)
{ {
if (m_stopped) if (m_state == Inactive)
return; return;
ASSERT_STATE(UploadingDumpers);
if (job != m_uploadJob) { if (job != m_uploadJob) {
qWarning("Warning: Unknown debugging helpers upload job %d finished.", job); qWarning("Warning: Unknown debugging helpers upload job %d finished.", job);
return; return;
@@ -218,6 +235,7 @@ void MaemoDebugSupport::handleSftpJobFinished(Core::SftpJobId job,
handleAdapterSetupFailed(tr("Could not upload debugging helpers: %1.") handleAdapterSetupFailed(tr("Could not upload debugging helpers: %1.")
.arg(error)); .arg(error));
} else { } else {
setState(DumpersUploaded);
m_runConfig->deployStep()->setDeployed(m_deviceConfig.server.host, m_runConfig->deployStep()->setDeployed(m_deviceConfig.server.host,
MaemoDeployable(m_runConfig->dumperLib(), uploadDir(m_deviceConfig))); MaemoDeployable(m_runConfig->dumperLib(), uploadDir(m_deviceConfig)));
m_runControl->showMessage(tr("Finished uploading debugging helpers."), AppStuff); m_runControl->showMessage(tr("Finished uploading debugging helpers."), AppStuff);
@@ -228,9 +246,12 @@ void MaemoDebugSupport::handleSftpJobFinished(Core::SftpJobId job,
void MaemoDebugSupport::startDebugging() void MaemoDebugSupport::startDebugging()
{ {
ASSERT_STATE(DumpersUploaded);
if (useGdb()) { if (useGdb()) {
handleAdapterSetupDone(); handleAdapterSetupDone();
} else { } else {
setState(StartingRemoteProcess);
m_gdbserverOutput.clear(); m_gdbserverOutput.clear();
connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)), this, connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)), this,
SLOT(handleRemoteErrorOutput(QByteArray))); SLOT(handleRemoteErrorOutput(QByteArray)));
@@ -252,19 +273,25 @@ void MaemoDebugSupport::startDebugging()
void MaemoDebugSupport::handleDebuggingFinished() void MaemoDebugSupport::handleDebuggingFinished()
{ {
m_stopped = true; setState(Inactive);
stopSsh();
} }
void MaemoDebugSupport::handleRemoteOutput(const QByteArray &output) void MaemoDebugSupport::handleRemoteOutput(const QByteArray &output)
{ {
m_runControl->showMessage(QString::fromUtf8(output), AppOutput); ASSERT_STATE(QList<State>() << Inactive << Debugging);
if (m_runControl)
m_runControl->showMessage(QString::fromUtf8(output), AppOutput);
} }
void MaemoDebugSupport::handleRemoteErrorOutput(const QByteArray &output) void MaemoDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
{ {
ASSERT_STATE(QList<State>() << Inactive << StartingRemoteProcess << Debugging);
if (!m_runControl)
return;
m_runControl->showMessage(QString::fromUtf8(output), AppOutput); m_runControl->showMessage(QString::fromUtf8(output), AppOutput);
if (!m_adapterStarted && !useGdb() && !m_qmlOnlyDebugging) { if (m_state == StartingRemoteProcess && !m_qmlOnlyDebugging) {
m_gdbserverOutput += output; m_gdbserverOutput += output;
if (m_gdbserverOutput.contains("Listening on port")) { if (m_gdbserverOutput.contains("Listening on port")) {
handleAdapterSetupDone(); handleAdapterSetupDone();
@@ -275,32 +302,36 @@ void MaemoDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
void MaemoDebugSupport::handleProgressReport(const QString &progressOutput) void MaemoDebugSupport::handleProgressReport(const QString &progressOutput)
{ {
m_runControl->showMessage(progressOutput, AppStuff); if (m_runControl)
} m_runControl->showMessage(progressOutput, AppStuff);
void MaemoDebugSupport::stopSsh()
{
//disconnect(m_runner, 0, this, 0);
if (m_uploader) {
disconnect(m_uploader.data(), 0, this, 0);
m_uploader->closeChannel();
}
m_runner->stop();
} }
void MaemoDebugSupport::handleAdapterSetupFailed(const QString &error) void MaemoDebugSupport::handleAdapterSetupFailed(const QString &error)
{ {
setState(Inactive);
m_runControl->handleRemoteSetupFailed(tr("Initial setup failed: %1").arg(error)); m_runControl->handleRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
m_stopped = true;
stopSsh();
} }
void MaemoDebugSupport::handleAdapterSetupDone() void MaemoDebugSupport::handleAdapterSetupDone()
{ {
m_adapterStarted = true; setState(Debugging);
m_runControl->handleRemoteSetupDone(); m_runControl->handleRemoteSetupDone();
} }
void MaemoDebugSupport::setState(State newState)
{
if (m_state == newState)
return;
m_state = newState;
if (m_state == Inactive) {
if (m_uploader) {
disconnect(m_uploader.data(), 0, this, 0);
m_uploader->closeChannel();
}
m_runner->stop();
}
}
int MaemoDebugSupport::gdbServerPort(const MaemoRunConfiguration *rc) int MaemoDebugSupport::gdbServerPort(const MaemoRunConfiguration *rc)
{ {
return rc->freePorts().getNext(); return rc->freePorts().getNext();

View File

@@ -40,6 +40,7 @@
#include <coreplugin/ssh/sftpdefs.h> #include <coreplugin/ssh/sftpdefs.h>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QPointer>
#include <QtCore/QSharedPointer> #include <QtCore/QSharedPointer>
namespace Core { class SftpChannel; } namespace Core { class SftpChannel; }
@@ -81,17 +82,22 @@ private slots:
void handleProgressReport(const QString &progressOutput); void handleProgressReport(const QString &progressOutput);
private: private:
enum State {
Inactive, StartingRunner, InitializingUploader, UploadingDumpers,
DumpersUploaded, StartingRemoteProcess, Debugging
};
static int gdbServerPort(const MaemoRunConfiguration *rc); static int gdbServerPort(const MaemoRunConfiguration *rc);
static int qmlServerPort(const MaemoRunConfiguration *rc); static int qmlServerPort(const MaemoRunConfiguration *rc);
static QString environment(const MaemoRunConfiguration *rc); static QString environment(const MaemoRunConfiguration *rc);
void stopSsh();
void handleAdapterSetupFailed(const QString &error); void handleAdapterSetupFailed(const QString &error);
void handleAdapterSetupDone(); void handleAdapterSetupDone();
void startDebugging(); void startDebugging();
bool useGdb() const; bool useGdb() const;
void setState(State newState);
Debugger::DebuggerRunControl * const m_runControl; const QPointer<Debugger::DebuggerRunControl> m_runControl;
MaemoRunConfiguration * const m_runConfig; MaemoRunConfiguration * const m_runConfig;
const MaemoDeviceConfig m_deviceConfig; const MaemoDeviceConfig m_deviceConfig;
MaemoSshRunner * const m_runner; MaemoSshRunner * const m_runner;
@@ -99,9 +105,8 @@ private:
QSharedPointer<Core::SftpChannel> m_uploader; QSharedPointer<Core::SftpChannel> m_uploader;
Core::SftpJobId m_uploadJob; Core::SftpJobId m_uploadJob;
bool m_adapterStarted;
bool m_stopped;
QByteArray m_gdbserverOutput; QByteArray m_gdbserverOutput;
State m_state;
}; };
} // namespace Internal } // namespace Internal