ValgrindRunner: Connect to done() signal

Instead of connecting to errorOccurred() and finished() signals.

Change-Id: I8eda3a01d73c87bd2673b40723e563ec3ce3a01c
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-06-16 15:01:14 +02:00
parent 01d3b69719
commit 25b1c59f74
2 changed files with 15 additions and 44 deletions

View File

@@ -50,6 +50,7 @@ public:
bool run(); bool run();
void processStarted(); void processStarted();
void processDone();
void localProcessStarted(); void localProcessStarted();
void remoteProcessStarted(); void remoteProcessStarted();
void findPidProcessDone(); void findPidProcessDone();
@@ -65,7 +66,6 @@ public:
QHostAddress localServerAddress; QHostAddress localServerAddress;
QProcess::ProcessChannelMode channelMode = QProcess::SeparateChannels; QProcess::ProcessChannelMode channelMode = QProcess::SeparateChannels;
bool m_finished = false;
QTcpServer xmlServer; QTcpServer xmlServer;
XmlProtocol::ThreadedParser parser; XmlProtocol::ThreadedParser parser;
@@ -116,12 +116,10 @@ bool ValgrindRunner::Private::run()
// consider appending our options last so they override any interfering user-supplied options // consider appending our options last so they override any interfering user-supplied options
// -q as suggested by valgrind manual // -q as suggested by valgrind manual
connect(&m_valgrindProcess, &QtcProcess::finished,
q, &ValgrindRunner::processFinished);
connect(&m_valgrindProcess, &QtcProcess::started, connect(&m_valgrindProcess, &QtcProcess::started,
this, &ValgrindRunner::Private::processStarted); this, &ValgrindRunner::Private::processStarted);
connect(&m_valgrindProcess, &QtcProcess::errorOccurred, connect(&m_valgrindProcess, &QtcProcess::done,
q, &ValgrindRunner::processError); this, &ValgrindRunner::Private::processDone);
connect(&m_valgrindProcess, &QtcProcess::readyReadStandardOutput, q, [this] { connect(&m_valgrindProcess, &QtcProcess::readyReadStandardOutput, q, [this] {
q->processOutputReceived(QString::fromUtf8(m_valgrindProcess.readAllStandardOutput()), q->processOutputReceived(QString::fromUtf8(m_valgrindProcess.readAllStandardOutput()),
@@ -145,7 +143,6 @@ bool ValgrindRunner::Private::run()
m_valgrindProcess.setWorkingDirectory(m_debuggee.workingDirectory); m_valgrindProcess.setWorkingDirectory(m_debuggee.workingDirectory);
m_valgrindProcess.setEnvironment(m_debuggee.environment); m_valgrindProcess.setEnvironment(m_debuggee.environment);
m_valgrindProcess.start(); m_valgrindProcess.start();
return true; return true;
} }
@@ -157,6 +154,17 @@ void ValgrindRunner::Private::processStarted()
remoteProcessStarted(); remoteProcessStarted();
} }
void ValgrindRunner::Private::processDone()
{
emit q->extraProcessFinished();
if (m_valgrindProcess.result() != ProcessResult::FinishedWithSuccess)
emit q->processErrorReceived(m_valgrindProcess.errorString(), m_valgrindProcess.error());
// make sure we don't wait for the connection anymore
emit q->finished();
}
void ValgrindRunner::Private::localProcessStarted() void ValgrindRunner::Private::localProcessStarted()
{ {
qint64 pid = m_valgrindProcess.processId(); qint64 pid = m_valgrindProcess.processId();
@@ -268,7 +276,7 @@ void ValgrindRunner::setUseTerminal(bool on)
void ValgrindRunner::waitForFinished() const void ValgrindRunner::waitForFinished() const
{ {
if (d->m_finished) if (d->m_valgrindProcess.state() == QProcess::NotRunning)
return; return;
QEventLoop loop; QEventLoop loop;
@@ -281,39 +289,6 @@ bool ValgrindRunner::start()
return d->run(); return d->run();
} }
void ValgrindRunner::processError(QProcess::ProcessError e)
{
if (d->m_finished)
return;
d->m_finished = true;
// make sure we don't wait for the connection anymore
emit processErrorReceived(errorString(), e);
emit finished();
}
void ValgrindRunner::processFinished()
{
emit extraProcessFinished();
if (d->m_finished)
return;
d->m_finished = true;
// make sure we don't wait for the connection anymore
emit finished();
if (d->m_valgrindProcess.exitCode() != 0 || d->m_valgrindProcess.exitStatus() == QProcess::CrashExit)
emit processErrorReceived(errorString(), d->m_valgrindProcess.error());
}
QString ValgrindRunner::errorString() const
{
return d->m_valgrindProcess.errorString();
}
void ValgrindRunner::stop() void ValgrindRunner::stop()
{ {
d->m_valgrindProcess.stop(); d->m_valgrindProcess.stop();

View File

@@ -57,8 +57,6 @@ public:
void waitForFinished() const; void waitForFinished() const;
QString errorString() const;
bool start(); bool start();
void stop(); void stop();
@@ -75,8 +73,6 @@ signals:
private: private:
bool startServers(); bool startServers();
void processError(QProcess::ProcessError);
void processFinished();
void xmlSocketConnected(); void xmlSocketConnected();
void logSocketConnected(); void logSocketConnected();