forked from qt-creator/qt-creator
Fix Trk error handling
Do not close a trk device from its read handler, wire messages correctly. TrkDevice: Terminate threads before closing.
This commit is contained in:
@@ -143,7 +143,7 @@ TrkGdbAdapter::TrkGdbAdapter(GdbEngine *engine, const TrkOptionsPtr &options) :
|
||||
|
||||
TrkGdbAdapter::~TrkGdbAdapter()
|
||||
{
|
||||
delete m_gdbServer;
|
||||
cleanup();
|
||||
logMessage("Shutting down.\n");
|
||||
}
|
||||
|
||||
@@ -283,6 +283,17 @@ QByteArray TrkGdbAdapter::trkInterruptMessage()
|
||||
return ba;
|
||||
}
|
||||
|
||||
void TrkGdbAdapter::emitDelayedAdapterStartFailed(const QString &msg)
|
||||
{
|
||||
m_adapterFailMessage = msg;
|
||||
QTimer::singleShot(0, this, SLOT(slotEmitDelayedAdapterStartFailed()));
|
||||
}
|
||||
|
||||
void TrkGdbAdapter::slotEmitDelayedAdapterStartFailed()
|
||||
{
|
||||
emit adapterStartFailed(m_adapterFailMessage);
|
||||
}
|
||||
|
||||
void TrkGdbAdapter::startInferiorEarly()
|
||||
{
|
||||
QTC_ASSERT(state() == AdapterStarting, qDebug() << state());
|
||||
@@ -1063,8 +1074,9 @@ void TrkGdbAdapter::handleCreateProcess(const TrkResult &result)
|
||||
logMessage("ERROR: " + result.errorString());
|
||||
QString msg = _("Cannot start executable \"%1\" on the device:\n%2")
|
||||
.arg(m_remoteExecutable).arg(result.errorString());
|
||||
//m_trkDevice.close();
|
||||
emit adapterStartFailed(msg);
|
||||
// Delay cleanup as not to close a trk device from its read handler,
|
||||
// which blocks.
|
||||
emitDelayedAdapterStartFailed(msg);
|
||||
return;
|
||||
}
|
||||
const char *data = result.data.data();
|
||||
@@ -1470,7 +1482,7 @@ void TrkGdbAdapter::startAdapter()
|
||||
m_remoteExecutable = parameters.executable;
|
||||
m_symbolFile = parameters.symbolFileName;
|
||||
// FIXME: testing hack, remove!
|
||||
if (parameters.processArgs.at(0) == _("@sym@")) {
|
||||
if (parameters.processArgs.size() == 3 && parameters.processArgs.at(0) == _("@sym@")) {
|
||||
m_remoteExecutable = parameters.processArgs.at(1);
|
||||
m_symbolFile = parameters.processArgs.at(2);
|
||||
}
|
||||
@@ -1593,7 +1605,9 @@ void TrkGdbAdapter::startGdb()
|
||||
QString msg = QString("Unable to start the gdb server at %1: %2.")
|
||||
.arg(m_gdbServerName).arg(m_gdbServer->errorString());
|
||||
logMessage(msg);
|
||||
emit adapterStartFailed(msg);
|
||||
// Delay cleanup as not to close a trk device from its read handler,
|
||||
// which blocks.
|
||||
emitDelayedAdapterStartFailed(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1908,11 +1922,19 @@ void TrkGdbAdapter::setEnvironment(const QStringList &env)
|
||||
m_gdbProc.setEnvironment(env);
|
||||
}
|
||||
|
||||
void TrkGdbAdapter::cleanup()
|
||||
{
|
||||
if (m_trkDevice.isOpen())
|
||||
m_trkDevice.close();
|
||||
if (m_gdbServer)
|
||||
delete m_gdbServer;
|
||||
}
|
||||
|
||||
void TrkGdbAdapter::shutdown()
|
||||
{
|
||||
switch (state()) {
|
||||
|
||||
case AdapterStarting:
|
||||
cleanup();
|
||||
setState(DebuggerNotReady);
|
||||
return;
|
||||
|
||||
@@ -1931,10 +1953,7 @@ void TrkGdbAdapter::shutdown()
|
||||
|
||||
case InferiorShutDown:
|
||||
setState(AdapterShuttingDown);
|
||||
//sendTrkMessage(0x02, TrkCB(handleDisconnect));
|
||||
m_trkDevice.close();
|
||||
delete m_gdbServer;
|
||||
m_gdbServer = 0;
|
||||
cleanup();
|
||||
m_engine->postCommand(_("-gdb-exit"), CB(handleExit));
|
||||
return;
|
||||
|
||||
|
||||
@@ -90,8 +90,6 @@ signals:
|
||||
void output(const QString &msg);
|
||||
|
||||
private:
|
||||
friend class RunnerGui;
|
||||
|
||||
const TrkOptionsPtr m_options;
|
||||
QString m_overrideTrkDevice;
|
||||
|
||||
@@ -115,11 +113,15 @@ public:
|
||||
bool isTrkAdapter() const { return true; }
|
||||
bool dumpersAvailable() const { return false; }
|
||||
|
||||
private:
|
||||
void startAdapter();
|
||||
void prepareInferior();
|
||||
void startInferior();
|
||||
void interruptInferior();
|
||||
void shutdown();
|
||||
void cleanup();
|
||||
void emitDelayedAdapterStartFailed(const QString &msg);
|
||||
Q_SLOT void slotEmitDelayedAdapterStartFailed();
|
||||
|
||||
Q_SLOT void startInferiorEarly();
|
||||
void handleKill(const GdbResponse &response);
|
||||
@@ -196,6 +198,7 @@ public:
|
||||
QByteArray trkInterruptMessage();
|
||||
|
||||
trk::TrkDevice m_trkDevice;
|
||||
QString m_adapterFailMessage;
|
||||
|
||||
//
|
||||
// Gdb
|
||||
|
||||
@@ -695,6 +695,11 @@ void S60DeviceRunControlBase::processFailed(const QString &program, QProcess::Pr
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void S60DeviceRunControlBase::printApplicationOutput(const QString &output)
|
||||
{
|
||||
emit addToOutputWindowInline(this, output);
|
||||
}
|
||||
|
||||
// =============== S60DeviceRunControl
|
||||
S60DeviceRunControl::S60DeviceRunControl(const QSharedPointer<ProjectExplorer::RunConfiguration> &runConfiguration) :
|
||||
S60DeviceRunControlBase(runConfiguration)
|
||||
@@ -730,11 +735,6 @@ void S60DeviceRunControl::printRunFailNotice(const QString &errorMessage) {
|
||||
emit addToOutputWindow(this, tr("Could not start application: %1").arg(errorMessage));
|
||||
}
|
||||
|
||||
void S60DeviceRunControl::printApplicationOutput(const QString &output)
|
||||
{
|
||||
emit addToOutputWindowInline(this, output);
|
||||
}
|
||||
|
||||
// ======== S60DeviceDebugRunControl
|
||||
|
||||
S60DeviceDebugRunControl::S60DeviceDebugRunControl(const QSharedPointer<ProjectExplorer::RunConfiguration> &runConfiguration) :
|
||||
@@ -748,7 +748,7 @@ S60DeviceDebugRunControl::S60DeviceDebugRunControl(const QSharedPointer<ProjectE
|
||||
connect(dm, SIGNAL(debuggingFinished()),
|
||||
this, SLOT(debuggingFinished()), Qt::QueuedConnection);
|
||||
connect(dm, SIGNAL(applicationOutputAvailable(QString)),
|
||||
this, SLOT(slotAddToOutputWindow(QString)),
|
||||
this, SLOT(printApplicationOutput(QString)),
|
||||
Qt::QueuedConnection);
|
||||
|
||||
m_startParams->remoteChannel = rc->serialPortName();
|
||||
|
||||
@@ -160,6 +160,9 @@ protected:
|
||||
virtual void handleLauncherFinished() = 0;
|
||||
void processFailed(const QString &program, QProcess::ProcessError errorCode);
|
||||
|
||||
protected slots:
|
||||
void printApplicationOutput(const QString &output);
|
||||
|
||||
private slots:
|
||||
void readStandardError();
|
||||
void readStandardOutput();
|
||||
@@ -208,7 +211,6 @@ private slots:
|
||||
void printStartingNotice();
|
||||
void printRunNotice(uint pid);
|
||||
void printRunFailNotice(const QString &errorMessage);
|
||||
void printApplicationOutput(const QString &output);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -836,6 +836,8 @@ TrkDevice::~TrkDevice()
|
||||
|
||||
bool TrkDevice::open(const QString &port, QString *errorMessage)
|
||||
{
|
||||
if (d->verbose)
|
||||
qDebug() << "Opening" << port << "is open: " << isOpen();
|
||||
close();
|
||||
#ifdef Q_OS_WIN
|
||||
d->deviceContext->device = CreateFile(port.toStdWString().c_str(),
|
||||
@@ -908,6 +910,8 @@ void TrkDevice::close()
|
||||
{
|
||||
if (!isOpen())
|
||||
return;
|
||||
d->readerThread->terminate();
|
||||
d->writerThread->terminate();
|
||||
#ifdef Q_OS_WIN
|
||||
CloseHandle(d->deviceContext->device);
|
||||
d->deviceContext->device = INVALID_HANDLE_VALUE;
|
||||
@@ -917,8 +921,6 @@ void TrkDevice::close()
|
||||
#else
|
||||
d->deviceContext->file.close();
|
||||
#endif
|
||||
d->readerThread->terminate();
|
||||
d->writerThread->terminate();
|
||||
if (d->verbose)
|
||||
emitLogMessage("Close");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user