Commit e5e86931 authored by hjk's avatar hjk

Debugger: Merge two remote setup communication paths

Success and failure paths are very similar.

Change-Id: Iebf218f64401884c014f1f7745d504183018addd
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent ea6514b2
......@@ -186,7 +186,11 @@ void AndroidDebugSupport::handleRemoteProcessStarted(int gdbServerPort, int qmlP
disconnect(m_runner, &AndroidRunner::remoteProcessStarted,
this, &AndroidDebugSupport::handleRemoteProcessStarted);
QTC_ASSERT(m_engine, return);
m_engine->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
RemoteSetupResult result;
result.success = true;
result.gdbServerPort = gdbServerPort;
result.qmlServerPort = qmlPort;
m_engine->notifyEngineRemoteSetupFinished(result);
}
} // namespace Internal
......
......@@ -830,10 +830,8 @@ void DebuggerEngine::notifyEngineRemoteServerRunning(const QByteArray &, int /*p
showMessage(_("NOTE: REMOTE SERVER RUNNING IN MULTIMODE"));
}
void DebuggerEngine::notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort)
void DebuggerEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
{
showMessage(_("NOTE: REMOTE SETUP DONE: GDB SERVER PORT: %1 QML PORT %2")
.arg(gdbServerPort).arg(qmlPort));
QTC_ASSERT(state() == EngineSetupRequested
|| state() == EngineSetupFailed
|| state() == DebuggerFinished, qDebug() << this << state());
......@@ -842,22 +840,15 @@ void DebuggerEngine::notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort)
|| d->remoteSetupState() == RemoteSetupCancelled,
qDebug() << this << "remoteSetupState" << d->remoteSetupState());
if (d->remoteSetupState() == RemoteSetupCancelled)
return;
d->setRemoteSetupState(RemoteSetupSucceeded);
}
if (result.success) {
showMessage(_("NOTE: REMOTE SETUP DONE: GDB SERVER PORT: %1 QML PORT %2")
.arg(result.gdbServerPort).arg(result.qmlServerPort));
void DebuggerEngine::notifyEngineRemoteSetupFailed(const QString &message)
{
showMessage(_("NOTE: REMOTE SETUP FAILED: ") + message);
QTC_ASSERT(state() == EngineSetupRequested
|| state() == EngineSetupFailed
|| state() == DebuggerFinished, qDebug() << this << state());
QTC_ASSERT(d->remoteSetupState() == RemoteSetupRequested
|| d->remoteSetupState() == RemoteSetupCancelled,
qDebug() << this << "remoteSetupState" << d->remoteSetupState());
if (d->remoteSetupState() != RemoteSetupCancelled)
d->setRemoteSetupState(RemoteSetupSucceeded);
} else {
showMessage(_("NOTE: REMOTE SETUP FAILED: ") + result.reason);
}
}
void DebuggerEngine::notifyEngineRunOkAndInferiorRunRequested()
......
......@@ -32,6 +32,7 @@
#include "debugger_global.h"
#include "debuggerconstants.h"
#include "debuggerstartparameters.h"
#include "breakpoint.h" // For BreakpointModelId.
#include "threaddata.h" // For ThreadId.
#include "coreplugin/variablemanager.h"
......@@ -278,8 +279,8 @@ signals:
/*
* For "external" clients of a debugger run control that needs to do
* further setup before the debugger is started (e.g. RemoteLinux).
* Afterwards, notifyEngineRemoteSetupDone() or notifyEngineRemoteSetupFailed()
* must be called to continue or abort debugging, respectively.
* Afterwards, notifyEngineRemoteSetupFinished
* must be called to continue or abort debugging.
* This signal is only emitted if the start parameters indicate that
* a server start script should be used, but none is given.
*/
......@@ -296,8 +297,7 @@ protected:
virtual void notifyEngineRequestRemoteSetup();
public:
virtual void notifyEngineRemoteServerRunning(const QByteArray &, int pid);
virtual void notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort);
virtual void notifyEngineRemoteSetupFailed(const QString &message);
virtual void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
protected:
virtual void notifyInferiorSetupOk();
......
......@@ -47,6 +47,26 @@ namespace Debugger {
// Note: This is part of the "soft interface" of the debugger plugin.
// Do not add anything that needs implementation in a .cpp file.
const int InvalidPort = -1;
const int InvalidPid = -1;
class DEBUGGER_EXPORT RemoteSetupResult
{
public:
RemoteSetupResult()
: gdbServerPort(InvalidPort),
qmlServerPort(InvalidPort),
inferiorPid(InvalidPid),
success(false)
{}
int gdbServerPort;
int qmlServerPort;
int inferiorPid;
bool success;
QString reason;
};
class DEBUGGER_EXPORT DebuggerStartParameters
{
public:
......@@ -156,6 +176,7 @@ bool fillParameters(DebuggerStartParameters *sp, const ProjectExplorer::Kit *kit
} // namespace Internal
} // namespace Debugger
Q_DECLARE_METATYPE(Debugger::RemoteSetupResult)
Q_DECLARE_METATYPE(Debugger::DebuggerStartParameters)
#endif // DEBUGGER_DEBUGGERSTARTPARAMETERS_H
......
......@@ -153,10 +153,14 @@ void GdbRemoteServerEngine::readUploadStandardError()
void GdbRemoteServerEngine::uploadProcFinished()
{
if (m_uploadProc.exitStatus() == QProcess::NormalExit
&& m_uploadProc.exitCode() == 0)
&& m_uploadProc.exitCode() == 0) {
startGdb();
else
notifyEngineRemoteSetupFailed(m_uploadProc.errorString());
} else {
RemoteSetupResult result;
result.success = false;
result.reason = m_uploadProc.errorString();
notifyEngineRemoteSetupFinished(result);
}
}
void GdbRemoteServerEngine::setupInferior()
......@@ -475,24 +479,29 @@ void GdbRemoteServerEngine::notifyEngineRemoteServerRunning
startGdb();
}
void GdbRemoteServerEngine::notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort)
void GdbRemoteServerEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
{
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
DebuggerEngine::notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
DebuggerEngine::notifyEngineRemoteSetupFinished(result);
if (!result.success) {
handleAdapterStartFailed(result.reason);
return;
}
DebuggerStartParameters &params = isMasterEngine()
? startParameters() : masterEngine()->startParameters();
if (gdbServerPort != -1) {
if (result.gdbServerPort != -1) {
QString &rc = params.remoteChannel;
const int sepIndex = rc.lastIndexOf(QLatin1Char(':'));
if (sepIndex != -1) {
rc.replace(sepIndex + 1, rc.count() - sepIndex - 1,
QString::number(gdbServerPort));
QString::number(result.gdbServerPort));
}
}
if (qmlPort != -1) {
params.qmlServerPort = qmlPort;
params.processArgs.replace(_("%qml_port%"), QString::number(qmlPort));
if (result.qmlServerPort != -1) {
params.qmlServerPort = result.qmlServerPort;
params.processArgs.replace(_("%qml_port%"), QString::number(result.qmlServerPort));
}
// TODO: Aren't these redundant?
......@@ -503,12 +512,5 @@ void GdbRemoteServerEngine::notifyEngineRemoteSetupDone(int gdbServerPort, int q
startGdb();
}
void GdbRemoteServerEngine::notifyEngineRemoteSetupFailed(const QString &reason)
{
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
DebuggerEngine::notifyEngineRemoteSetupFailed(reason);
handleAdapterStartFailed(reason);
}
} // namespace Internal
} // namespace Debugger
......@@ -74,9 +74,8 @@ private:
Q_SLOT void uploadProcFinished();
Q_SLOT void callTargetRemote();
void notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort);
void notifyEngineRemoteSetupFailed(const QString &reason);
void notifyEngineRemoteServerRunning(const QByteArray &serverChannel, int inferiorPid);
void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
void notifyInferiorSetupOk();
void handleSetTargetAsync(const GdbResponse &response);
......
......@@ -1337,39 +1337,37 @@ DebuggerEngine *createLldbEngine(const DebuggerStartParameters &startParameters)
return new LldbEngine(startParameters);
}
void LldbEngine::notifyEngineRemoteSetupDone(int portOrPid, int qmlPort)
void LldbEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
{
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
DebuggerEngine::notifyEngineRemoteSetupDone(portOrPid, qmlPort);
DebuggerEngine::notifyEngineRemoteSetupFinished(result);
if (qmlPort != -1)
startParameters().qmlServerPort = qmlPort;
if (portOrPid != -1) {
if (!result.success) {
showMessage(_("ADAPTER START FAILED"));
if (!result.reason.isEmpty()) {
const QString title = tr("Adapter start failed");
Core::ICore::showWarningWithOptions(title, result.reason);
}
notifyEngineSetupFailed();
return;
}
if (result.qmlServerPort != InvalidPort)
startParameters().qmlServerPort = result.qmlServerPort;
if (result.inferiorPid != InvalidPid) {
if (startParameters().startMode == AttachExternal) {
startParameters().attachPID = portOrPid;
startParameters().attachPID = result.inferiorPid;
} else {
QString &rc = startParameters().remoteChannel;
const int sepIndex = rc.lastIndexOf(QLatin1Char(':'));
if (sepIndex != -1)
rc.replace(sepIndex + 1, rc.count() - sepIndex - 1,
QString::number(portOrPid));
QString::number(result.inferiorPid));
}
}
startLldb();
}
void LldbEngine::notifyEngineRemoteSetupFailed(const QString &reason)
{
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
DebuggerEngine::notifyEngineRemoteSetupFailed(reason);
showMessage(_("ADAPTER START FAILED"));
if (!reason.isEmpty()) {
const QString title = tr("Adapter start failed");
Core::ICore::showWarningWithOptions(title, reason);
}
notifyEngineSetupFailed();
}
///////////////////////////////////////////////////////////////////////
//
// Command
......
......@@ -196,8 +196,7 @@ private:
void handleUpdateStack(const QByteArray &response);
void handleUpdateThreads(const QByteArray &response);
void notifyEngineRemoteSetupDone(int portOrPid, int qmlPort);
void notifyEngineRemoteSetupFailed(const QString &reason);
void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
void handleChildren(const WatchData &data0, const GdbMi &item,
QList<WatchData> *list);
......
......@@ -744,22 +744,13 @@ void QmlCppEngine::slaveEngineStateChanged
}
}
void QmlCppEngine::notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort)
void QmlCppEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
{
EDEBUG("MASTER REMOTE SETUP DONE");
DebuggerEngine::notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
EDEBUG("MASTER REMOTE SETUP FINISHED");
DebuggerEngine::notifyEngineRemoteSetupFinished(result);
cppEngine()->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
qmlEngine()->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
}
void QmlCppEngine::notifyEngineRemoteSetupFailed(const QString &message)
{
EDEBUG("MASTER REMOTE SETUP FAILED");
DebuggerEngine::notifyEngineRemoteSetupFailed(message);
cppEngine()->notifyEngineRemoteSetupFailed(message);
qmlEngine()->notifyEngineRemoteSetupFailed(message);
cppEngine()->notifyEngineRemoteSetupFinished(result);
qmlEngine()->notifyEngineRemoteSetupFinished(result);
}
void QmlCppEngine::showMessage(const QString &msg, int channel, int timeout) const
......
......@@ -86,8 +86,7 @@ public:
DebuggerEngine *cppEngine() const;
DebuggerEngine *qmlEngine() const;
void notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort);
void notifyEngineRemoteSetupFailed(const QString &message);
void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
void showMessage(const QString &msg, int channel = LogDebug,
int timeout = -1) const;
......
......@@ -614,29 +614,28 @@ void QmlEngine::stopApplicationLauncher()
}
}
void QmlEngine::notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort)
void QmlEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
{
if (qmlPort != -1)
startParameters().qmlServerPort = qmlPort;
DebuggerEngine::notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
notifyEngineSetupOk();
DebuggerEngine::notifyEngineRemoteSetupFinished(result);
// The remote setup can take while especialy with mixed debugging.
// Just waiting for 8 seconds is not enough. Increase the timeout
// to 60 s
// In case we get an output the m_outputParser will start the connection.
m_noDebugOutputTimer.setInterval(60000);
}
if (result.success) {
if (result.qmlServerPort != InvalidPort)
startParameters().qmlServerPort = result.qmlServerPort;
void QmlEngine::notifyEngineRemoteSetupFailed(const QString &message)
{
DebuggerEngine::notifyEngineRemoteSetupFailed(message);
if (isMasterEngine())
QMessageBox::critical(0,tr("Failed to start application"),
tr("Application startup failed: %1").arg(message));
notifyEngineSetupOk();
notifyEngineSetupFailed();
// The remote setup can take while especialy with mixed debugging.
// Just waiting for 8 seconds is not enough. Increase the timeout
// to 60 s
// In case we get an output the m_outputParser will start the connection.
m_noDebugOutputTimer.setInterval(60000);
}
else {
if (isMasterEngine())
QMessageBox::critical(Core::ICore::dialogParent(), tr("Failed to start application"),
tr("Application startup failed: %1").arg(result.reason));
notifyEngineSetupFailed();
}
}
void QmlEngine::notifyEngineRemoteServerRunning(const QByteArray &serverChannel, int pid)
......
......@@ -60,9 +60,8 @@ public:
~QmlEngine();
void notifyInferiorSetupOk();
void notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort);
void notifyEngineRemoteSetupFailed(const QString &message);
void notifyEngineRemoteServerRunning(const QByteArray &, int pid);
void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
bool canDisplayTooltip() const;
......
......@@ -205,23 +205,24 @@ IosDebugSupport::~IosDebugSupport()
void IosDebugSupport::handleServerPorts(int gdbServerPort, int qmlPort)
{
if (gdbServerPort > 0 || (m_runner && !m_runner->cppDebug() && qmlPort > 0)) {
m_runControl->engine()->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
} else {
m_runControl->engine()->notifyEngineRemoteSetupFailed(
tr("Could not get debug server file descriptor."));
}
RemoteSetupResult result;
result.gdbServerPort = gdbServerPort;
result.qmlServerPort = qmlPort;
result.success = gdbServerPort > 0 || (m_runner && !m_runner->cppDebug() && qmlPort > 0);
if (!result.success)
result.reason = tr("Could not get debug server file descriptor.");
m_runControl->engine()->notifyEngineRemoteSetupFinished(result);
}
void IosDebugSupport::handleGotInferiorPid(Q_PID pid, int qmlPort)
{
if (pid > 0) {
//m_runControl->engine()->notifyInferiorPid(pid);
m_runControl->engine()->notifyEngineRemoteSetupDone(int(Utils::qPidToPid(pid)), qmlPort);
} else {
m_runControl->engine()->notifyEngineRemoteSetupFailed(
tr("Got an invalid process id."));
}
RemoteSetupResult result;
result.qmlServerPort = qmlPort;
result.inferiorPid = int(Utils::qPidToPid(pid));
result.success = pid > 0;
if (!result.success)
result.reason = tr("Got an invalid process id.");
m_runControl->engine()->notifyEngineRemoteSetupFinished(result);
}
void IosDebugSupport::handleRemoteProcessFinished(bool cleanEnd)
......
......@@ -71,13 +71,21 @@ void BlackBerryDebugSupport::launchRemoteApplication()
void BlackBerryDebugSupport::handleStarted()
{
m_engine->startParameters().attachPID = m_runner->pid();
m_engine->notifyEngineRemoteSetupDone(8000, -1);
m_engine->startParameters().attachPID = m_runner->pid(); // FIXME: Is that needed?
Debugger::RemoteSetupResult result;
result.success = true;
result.inferiorPid = m_runner->pid();
result.gdbServerPort = 8000;
result.qmlServerPort = Debugger::InvalidPort;
m_engine->notifyEngineRemoteSetupFinished(result);
}
void BlackBerryDebugSupport::handleStartFailed(const QString &message)
{
m_engine->notifyEngineRemoteSetupFailed(message);
Debugger::RemoteSetupResult result;
result.success = false;
result.reason = message;
m_engine->notifyEngineRemoteSetupFinished(result);
}
void BlackBerryDebugSupport::handleDebuggerStateChanged(Debugger::DebuggerState state)
......
......@@ -120,8 +120,13 @@ void QnxDebugSupport::startExecution()
void QnxDebugSupport::handleRemoteProcessStarted()
{
QnxAbstractRunSupport::handleRemoteProcessStarted();
if (m_engine)
m_engine->notifyEngineRemoteSetupDone(m_pdebugPort, m_qmlPort);
if (m_engine) {
Debugger::RemoteSetupResult result;
result.success = true;
result.gdbServerPort = m_pdebugPort;
result.qmlServerPort = m_qmlPort;
m_engine->notifyEngineRemoteSetupFinished(result);
}
}
void QnxDebugSupport::handleRemoteProcessFinished(bool success)
......@@ -134,8 +139,10 @@ void QnxDebugSupport::handleRemoteProcessFinished(bool success)
m_engine->notifyInferiorIll();
} else {
const QString errorMsg = tr("The %1 process closed unexpectedly.").arg(executable());
m_engine->notifyEngineRemoteSetupFailed(errorMsg);
Debugger::RemoteSetupResult result;
result.success = false;
result.reason = tr("The %1 process closed unexpectedly.").arg(executable());
m_engine->notifyEngineRemoteSetupFinished(result);
}
}
......@@ -182,8 +189,12 @@ void QnxDebugSupport::handleError(const QString &error)
}
} else if (state() != Inactive) {
setFinished();
if (m_engine)
m_engine->notifyEngineRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
if (m_engine) {
Debugger::RemoteSetupResult result;
result.success = false;
result.reason = tr("Initial setup failed: %1").arg(error);
m_engine->notifyEngineRemoteSetupFinished(result);
}
}
}
......
......@@ -218,8 +218,11 @@ void LinuxDeviceDebugSupport::handleAppRunnerFinished(bool success)
else if (!success)
d->engine->notifyInferiorIll();
} else if (state() == StartingRunner){
d->engine->notifyEngineRemoteSetupFailed(tr("Debugging failed."));
} else if (state() == StartingRunner) {
RemoteSetupResult result;
result.success = false;
result.reason = tr("Debugging failed.");
d->engine->notifyEngineRemoteSetupFinished(result);
}
reset();
}
......@@ -262,13 +265,22 @@ void LinuxDeviceDebugSupport::handleProgressReport(const QString &progressOutput
void LinuxDeviceDebugSupport::handleAdapterSetupFailed(const QString &error)
{
AbstractRemoteLinuxRunSupport::handleAdapterSetupFailed(error);
d->engine->notifyEngineRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
RemoteSetupResult result;
result.success = false;
result.reason = tr("Initial setup failed: %1").arg(error);
d->engine->notifyEngineRemoteSetupFinished(result);
}
void LinuxDeviceDebugSupport::handleAdapterSetupDone()
{
AbstractRemoteLinuxRunSupport::handleAdapterSetupDone();
d->engine->notifyEngineRemoteSetupDone(d->gdbServerPort, d->qmlPort);
RemoteSetupResult result;
result.success = true;
result.gdbServerPort = d->gdbServerPort;
result.qmlServerPort = d->qmlPort;
d->engine->notifyEngineRemoteSetupFinished(result);
}
void LinuxDeviceDebugSupport::handleRemoteProcessStarted()
......
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