ValgrindRunner: Add valgrindCommand() helper

Change-Id: I8c480911a13aa80b2d58e49c6b03da55b37090a6
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-08-16 15:20:39 +02:00
parent 62ed7f7c39
commit 3ca0a9d23c

View File

@@ -22,6 +22,40 @@ using namespace Valgrind::XmlProtocol;
namespace Valgrind {
static CommandLine valgrindCommand(const CommandLine &command,
const QTcpServer &xmlServer,
const QTcpServer &logServer)
{
CommandLine cmd = command;
cmd.addArg("--child-silent-after-fork=yes");
// Workaround for valgrind bug when running vgdb with xml output
// https://bugs.kde.org/show_bug.cgi?id=343902
bool enableXml = true;
auto handleSocketParameter = [&enableXml, &cmd](const QString &prefix,
const QTcpServer &tcpServer)
{
QHostAddress serverAddress = tcpServer.serverAddress();
if (serverAddress.protocol() != QAbstractSocket::IPv4Protocol) {
// Report will end up in the Application Output pane, i.e. not have
// clickable items, but that's better than nothing.
qWarning("Need IPv4 for valgrind");
enableXml = false;
} else {
cmd.addArg(QString("%1=%2:%3").arg(prefix).arg(serverAddress.toString())
.arg(tcpServer.serverPort()));
}
};
handleSocketParameter("--xml-socket", xmlServer);
handleSocketParameter("--log-socket", logServer);
if (enableXml)
cmd.addArg("--xml=yes");
return cmd;
}
class ValgrindRunner::Private : public QObject
{
public:
@@ -133,32 +167,7 @@ bool ValgrindRunner::Private::run()
if (!m_localServerAddress.isNull()) {
if (!startServers())
return false;
cmd.addArg("--child-silent-after-fork=yes");
// Workaround for valgrind bug when running vgdb with xml output
// https://bugs.kde.org/show_bug.cgi?id=343902
bool enableXml = true;
auto handleSocketParameter = [&enableXml, &cmd](const QString &prefix, const QTcpServer &tcpServer)
{
QHostAddress serverAddress = tcpServer.serverAddress();
if (serverAddress.protocol() != QAbstractSocket::IPv4Protocol) {
// Report will end up in the Application Output pane, i.e. not have
// clickable items, but that's better than nothing.
qWarning("Need IPv4 for valgrind");
enableXml = false;
} else {
cmd.addArg(QString("%1=%2:%3").arg(prefix).arg(serverAddress.toString())
.arg(tcpServer.serverPort()));
}
};
handleSocketParameter("--xml-socket", m_xmlServer);
handleSocketParameter("--log-socket", m_logServer);
if (enableXml)
cmd.addArg("--xml=yes");
cmd = valgrindCommand(cmd, m_xmlServer, m_logServer);
}
setupValgrindProcess(&m_process, cmd);
m_process.start();