Valgrind: Dismantle LocalAddressFinder

Change-Id: I00ba9b82a6805d9f649247e79ca44795e799818b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-10-07 14:55:45 +02:00
parent 931f8d84ac
commit e99ee62295

View File

@@ -111,50 +111,7 @@ private:
void appendLog(const QByteArray &data); void appendLog(const QByteArray &data);
const bool m_withGdb; const bool m_withGdb;
QHostAddress m_localServerAddress; std::unique_ptr<Process> m_process;
};
class LocalAddressFinder : public RunWorker
{
public:
LocalAddressFinder(RunControl *runControl, QHostAddress *localServerAddress)
: RunWorker(runControl), m_localServerAddress(localServerAddress) {}
void start() final
{
QTC_ASSERT(!m_process, return);
m_process.reset(new Process);
m_process->setCommand({device()->filePath("echo"), "-n $SSH_CLIENT", CommandLine::Raw});
connect(m_process.get(), &Process::done, this, [this] {
if (m_process->error() != QProcess::UnknownError) {
reportFailure();
return;
}
const QByteArrayList data = m_process->rawStdOut().split(' ');
if (data.size() != 3) {
reportFailure();
return;
}
QHostAddress hostAddress;
if (!hostAddress.setAddress(QString::fromLatin1(data.first()))) {
reportFailure();
return;
}
*m_localServerAddress = hostAddress;
reportStarted();
m_process.release()->deleteLater();
});
m_process->start();
}
void stop() final
{
reportStopped();
}
private:
std::unique_ptr<Process> m_process = nullptr;
QHostAddress *m_localServerAddress = nullptr;
}; };
QString MemcheckToolRunner::progressTitle() const QString MemcheckToolRunner::progressTitle() const
@@ -164,12 +121,35 @@ QString MemcheckToolRunner::progressTitle() const
void MemcheckToolRunner::start() void MemcheckToolRunner::start()
{ {
m_runner.setLocalServerAddress(m_localServerAddress); if (device()->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
m_process.reset(new Process);
m_process->setCommand({device()->filePath("echo"), "-n $SSH_CLIENT", CommandLine::Raw});
connect(m_process.get(), &Process::done, this, [this] {
const ProcessResult result = m_process->result();
const QByteArrayList data = m_process->rawStdOut().split(' ');
m_process.release()->deleteLater();
if (result != ProcessResult::FinishedWithSuccess || data.size() != 3) {
reportFailure();
return;
}
QHostAddress hostAddress;
if (!hostAddress.setAddress(QString::fromLatin1(data.first()))) {
reportFailure();
return;
}
m_runner.setLocalServerAddress(hostAddress);
ValgrindToolRunner::start();
});
m_process->start();
return;
}
m_runner.setLocalServerAddress(QHostAddress::LocalHost);
ValgrindToolRunner::start(); ValgrindToolRunner::start();
} }
void MemcheckToolRunner::stop() void MemcheckToolRunner::stop()
{ {
m_process.reset();
disconnect(&m_runner, &ValgrindProcess::internalError, disconnect(&m_runner, &ValgrindProcess::internalError,
this, &MemcheckToolRunner::internalParserError); this, &MemcheckToolRunner::internalParserError);
ValgrindToolRunner::stop(); ValgrindToolRunner::stop();
@@ -1135,9 +1115,8 @@ void MemcheckTool::setBusyCursor(bool busy)
} }
MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl) MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl)
: ValgrindToolRunner(runControl), : ValgrindToolRunner(runControl)
m_withGdb(runControl->runMode() == MEMCHECK_WITH_GDB_RUN_MODE), , m_withGdb(runControl->runMode() == MEMCHECK_WITH_GDB_RUN_MODE)
m_localServerAddress(QHostAddress::LocalHost)
{ {
setId("MemcheckToolRunner"); setId("MemcheckToolRunner");
connect(&m_runner, &ValgrindProcess::error, this, &MemcheckToolRunner::parserError); connect(&m_runner, &ValgrindProcess::error, this, &MemcheckToolRunner::parserError);
@@ -1152,13 +1131,6 @@ MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl)
this, &MemcheckToolRunner::internalParserError); this, &MemcheckToolRunner::internalParserError);
} }
// We need a real address to connect to from the outside.
if (device()->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
auto *dependentWorker = new LocalAddressFinder(runControl, &m_localServerAddress);
addStartDependency(dependentWorker);
addStopDependency(dependentWorker);
}
dd->setupRunner(this); dd->setupRunner(this);
} }