From 5f53b983ffc2b0169681b8dd49171777fb8fe456 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 17 Jun 2022 15:59:58 +0200 Subject: [PATCH] Valgrind: Simplify pid search in remote setup We have first-hand information nowadays from the process itself. Change-Id: I99cc61b9c8534740b0eb59a8fabed7e648eb2146 Reviewed-by: Reviewed-by: Jarek Kobus --- src/plugins/valgrind/valgrindrunner.cpp | 77 +------------------------ 1 file changed, 3 insertions(+), 74 deletions(-) diff --git a/src/plugins/valgrind/valgrindrunner.cpp b/src/plugins/valgrind/valgrindrunner.cpp index 376cc30927e..73ade61a18f 100644 --- a/src/plugins/valgrind/valgrindrunner.cpp +++ b/src/plugins/valgrind/valgrindrunner.cpp @@ -50,16 +50,11 @@ public: void processStarted(); void processDone(); - void localProcessStarted(); - void remoteProcessStarted(); - void findPidProcessDone(); ValgrindRunner *q; Runnable m_debuggee; QtcProcess m_valgrindProcess; - QtcProcess m_findPID; - CommandLine m_valgrindCommand; QHostAddress localServerAddress; @@ -146,10 +141,8 @@ bool ValgrindRunner::Private::run() void ValgrindRunner::Private::processStarted() { - if (!m_valgrindProcess.commandLine().executable().needsDevice()) - localProcessStarted(); - else - remoteProcessStarted(); + const qint64 pid = m_valgrindProcess.processId(); + emit q->valgrindStarted(pid); } void ValgrindRunner::Private::processDone() @@ -163,70 +156,6 @@ void ValgrindRunner::Private::processDone() emit q->finished(); } -void ValgrindRunner::Private::localProcessStarted() -{ - qint64 pid = m_valgrindProcess.processId(); - emit q->valgrindStarted(pid); -} - -void ValgrindRunner::Private::remoteProcessStarted() -{ - // find out what PID our process has - - // NOTE: valgrind cloaks its name, - // e.g.: valgrind --tool=memcheck foobar - // => ps aux, pidof will see valgrind.bin - // => pkill/killall/top... will see memcheck-amd64-linux or similar - // hence we need to do something more complex... - - // plain path to exe, m_valgrindExe contains e.g. env vars etc. pp. - // FIXME: Really? - const QString proc = m_valgrindCommand.executable().toString().split(' ').last(); - QString procEscaped = proc; - procEscaped.replace("/", "\\\\/"); - - const FilePath debuggee = m_debuggee.command.executable(); - const CommandLine cmd( - debuggee.withNewPath("/bin/sh"), - // sleep required since otherwise we might only match "bash -c..." and not the actual - // valgrind run - QString("-c \"" - "sleep 1; ps ax" // list all processes with aliased name - " | grep '%1.*%2'" // find valgrind process that runs with our exec - " | awk '\\$5 ~ /^%3/" // 5th column must start with valgrind process - " {print \\$1;}'" // print 1st then (with PID) - "\"").arg(proc, debuggee.fileName(), procEscaped), - CommandLine::Raw - ); - - m_findPID.setCommand(cmd); - - connect(&m_findPID, &QtcProcess::done, - this, &ValgrindRunner::Private::findPidProcessDone); - - m_findPID.start(); -} - -void ValgrindRunner::Private::findPidProcessDone() -{ - if (m_findPID.result() != ProcessResult::FinishedWithSuccess) { - emit q->appendMessage(m_findPID.allOutput(), StdErrFormat); - return; - } - QString out = m_findPID.cleanedStdOut(); - if (out.isEmpty()) - return; - bool ok; - const qint64 pid = out.trimmed().toLongLong(&ok); - if (!ok) { -// m_remote.m_errorString = tr("Could not determine remote PID."); -// emit ValgrindRunner::Private::error(QProcess::FailedToStart); -// close(); - } else { - emit q->valgrindStarted(pid); - } -} - ValgrindRunner::ValgrindRunner(QObject *parent) : QObject(parent), d(new Private(this)) { @@ -246,7 +175,7 @@ ValgrindRunner::~ValgrindRunner() d = nullptr; } -void ValgrindRunner::setValgrindCommand(const Utils::CommandLine &command) +void ValgrindRunner::setValgrindCommand(const CommandLine &command) { d->m_valgrindCommand = command; }