From b21742b4641be7895f9ae67372d2c306920daf38 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 21 Sep 2017 12:33:36 +0200 Subject: [PATCH] Valgrind: Merge memcheck{engine,tool}.* files This is purely mechanical in preparation of moving some per-run items from the MemCheckTool singleton to MemCheckToolRunner. Change-Id: I0fcaf6e90b2d63ca8f3c3eb7130ed73ed494f35b Reviewed-by: Christian Stenger --- src/plugins/valgrind/memcheckengine.cpp | 185 --------------------- src/plugins/valgrind/memcheckengine.h | 69 -------- src/plugins/valgrind/memchecktool.cpp | 211 +++++++++++++++++++++--- src/plugins/valgrind/valgrind.pro | 2 - src/plugins/valgrind/valgrind.qbs | 1 - 5 files changed, 191 insertions(+), 277 deletions(-) delete mode 100644 src/plugins/valgrind/memcheckengine.cpp delete mode 100644 src/plugins/valgrind/memcheckengine.h diff --git a/src/plugins/valgrind/memcheckengine.cpp b/src/plugins/valgrind/memcheckengine.cpp deleted file mode 100644 index 8e6202e4d88..00000000000 --- a/src/plugins/valgrind/memcheckengine.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com) -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "memcheckengine.h" -#include "memchecktool.h" -#include "valgrindsettings.h" -#include "xmlprotocol/error.h" -#include "xmlprotocol/status.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include - -using namespace Debugger; -using namespace ProjectExplorer; -using namespace Valgrind::XmlProtocol; - -namespace Valgrind { -namespace Internal { - -class LocalAddressFinder : public RunWorker -{ -public: - LocalAddressFinder(RunControl *runControl, QHostAddress *localServerAddress) - : RunWorker(runControl), connection(device()->sshParameters()) - { - connect(&connection, &QSsh::SshConnection::connected, this, [this, localServerAddress] { - *localServerAddress = connection.connectionInfo().localAddress; - reportStarted(); - }); - connect(&connection, &QSsh::SshConnection::error, this, [this] { - reportFailure(); - }); - } - - void start() override - { - connection.connectToHost(); - } - - QSsh::SshConnection connection; -}; - -MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl, bool withGdb) - : ValgrindToolRunner(runControl), - m_withGdb(withGdb), - m_localServerAddress(QHostAddress::LocalHost) -{ - setDisplayName("MemcheckToolRunner"); - connect(m_runner.parser(), &XmlProtocol::ThreadedParser::error, - this, &MemcheckToolRunner::parserError); - connect(m_runner.parser(), &XmlProtocol::ThreadedParser::suppressionCount, - this, &MemcheckToolRunner::suppressionCount); - - if (withGdb) { - connect(&m_runner, &ValgrindRunner::valgrindStarted, - this, &MemcheckToolRunner::startDebugger); - connect(&m_runner, &ValgrindRunner::logMessageReceived, - this, &MemcheckToolRunner::appendLog); -// m_runner.disableXml(); - } else { - connect(m_runner.parser(), &XmlProtocol::ThreadedParser::internalError, - this, &MemcheckToolRunner::internalParserError); - } - - // We need a real address to connect to from the outside. - if (device()->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) - addStartDependency(new LocalAddressFinder(runControl, &m_localServerAddress)); -} - -QString MemcheckToolRunner::progressTitle() const -{ - return tr("Analyzing Memory"); -} - -void MemcheckToolRunner::start() -{ - m_runner.setLocalServerAddress(m_localServerAddress); - ValgrindToolRunner::start(); -} - -void MemcheckToolRunner::stop() -{ - disconnect(m_runner.parser(), &ThreadedParser::internalError, - this, &MemcheckToolRunner::internalParserError); - ValgrindToolRunner::stop(); -} - -QStringList MemcheckToolRunner::toolArguments() const -{ - QStringList arguments = {"--tool=memcheck", "--gen-suppressions=all"}; - - QTC_ASSERT(m_settings, return arguments); - - if (m_settings->trackOrigins()) - arguments << "--track-origins=yes"; - - if (m_settings->showReachable()) - arguments << "--show-reachable=yes"; - - QString leakCheckValue; - switch (m_settings->leakCheckOnFinish()) { - case ValgrindBaseSettings::LeakCheckOnFinishNo: - leakCheckValue = "no"; - break; - case ValgrindBaseSettings::LeakCheckOnFinishYes: - leakCheckValue = "full"; - break; - case ValgrindBaseSettings::LeakCheckOnFinishSummaryOnly: - default: - leakCheckValue = "summary"; - break; - } - arguments << "--leak-check=" + leakCheckValue; - - foreach (const QString &file, m_settings->suppressionFiles()) - arguments << QString("--suppressions=%1").arg(file); - - arguments << QString("--num-callers=%1").arg(m_settings->numCallers()); - - if (m_withGdb) - arguments << "--vgdb=yes" << "--vgdb-error=0"; - - return arguments; -} - -QStringList MemcheckToolRunner::suppressionFiles() const -{ - return m_settings->suppressionFiles(); -} - -void MemcheckToolRunner::startDebugger(qint64 valgrindPid) -{ - auto debugger = new Debugger::DebuggerRunTool(runControl()); - debugger->setStartMode(Debugger::AttachToRemoteServer); - debugger->setRunControlName(QString("VGdb %1").arg(valgrindPid)); - debugger->setRemoteChannel(QString("| vgdb --pid=%1").arg(valgrindPid)); - debugger->setUseContinueInsteadOfRun(true); - debugger->addExpectedSignal("SIGTRAP"); - - connect(runControl(), &RunControl::stopped, debugger, &RunControl::deleteLater); - - debugger->initiateStart(); -} - -void MemcheckToolRunner::appendLog(const QByteArray &data) -{ - appendMessage(QString::fromUtf8(data), Utils::StdOutFormat); -} - -} // namespace Internal -} // namespace Valgrind diff --git a/src/plugins/valgrind/memcheckengine.h b/src/plugins/valgrind/memcheckengine.h deleted file mode 100644 index 6113390e91c..00000000000 --- a/src/plugins/valgrind/memcheckengine.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com) -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "valgrindengine.h" - -#include "valgrindrunner.h" -#include "xmlprotocol/threadedparser.h" - -#include - -namespace Valgrind { -namespace Internal { - -class MemcheckToolRunner : public ValgrindToolRunner -{ - Q_OBJECT - -public: - explicit MemcheckToolRunner(ProjectExplorer::RunControl *runControl, - bool withGdb = false); - - void start() override; - void stop() override; - - QStringList suppressionFiles() const; - -signals: - void internalParserError(const QString &errorString); - void parserError(const Valgrind::XmlProtocol::Error &error); - void suppressionCount(const QString &name, qint64 count); - -private: - QString progressTitle() const override; - QStringList toolArguments() const override; - - void startDebugger(qint64 valgrindPid); - void appendLog(const QByteArray &data); - - const bool m_withGdb; - QHostAddress m_localServerAddress; -}; - -} // namespace Internal -} // namespace Valgrind diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 917bafa888e..f668ee3a5fb 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -25,36 +25,44 @@ ****************************************************************************/ #include "memchecktool.h" -#include "memcheckengine.h" + #include "memcheckerrorview.h" #include "valgrindsettings.h" #include "valgrindplugin.h" +#include "valgrindengine.h" +#include "valgrindsettings.h" +#include "valgrindrunner.h" +#include "xmlprotocol/error.h" +#include "xmlprotocol/error.h" +#include "xmlprotocol/errorlistmodel.h" +#include "xmlprotocol/frame.h" +#include "xmlprotocol/stack.h" +#include "xmlprotocol/stackmodel.h" +#include "xmlprotocol/status.h" +#include "xmlprotocol/suppression.h" +#include "xmlprotocol/threadedparser.h" + +#include +#include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include #include @@ -67,20 +75,20 @@ #include #include -#include #include #include #include #include #include -#include #include +#include using namespace Core; using namespace Debugger; using namespace ProjectExplorer; using namespace Utils; using namespace Valgrind::XmlProtocol; + using namespace std::placeholders; namespace Valgrind { @@ -92,6 +100,167 @@ const char MEMCHECK_WITH_GDB_RUN_MODE[] = "MemcheckTool.MemcheckWithGdbRunMode"; const char MemcheckPerspectiveId[] = "Memcheck.Perspective"; const char MemcheckErrorDockId[] = "Memcheck.Dock.Error"; + +class MemcheckToolRunner : public ValgrindToolRunner +{ + Q_OBJECT + +public: + explicit MemcheckToolRunner(ProjectExplorer::RunControl *runControl, + bool withGdb = false); + + void start() override; + void stop() override; + + QStringList suppressionFiles() const; + +signals: + void internalParserError(const QString &errorString); + void parserError(const Valgrind::XmlProtocol::Error &error); + void suppressionCount(const QString &name, qint64 count); + +private: + QString progressTitle() const override; + QStringList toolArguments() const override; + + void startDebugger(qint64 valgrindPid); + void appendLog(const QByteArray &data); + + const bool m_withGdb; + QHostAddress m_localServerAddress; +}; + +class LocalAddressFinder : public RunWorker +{ +public: + LocalAddressFinder(RunControl *runControl, QHostAddress *localServerAddress) + : RunWorker(runControl), connection(device()->sshParameters()) + { + connect(&connection, &QSsh::SshConnection::connected, this, [this, localServerAddress] { + *localServerAddress = connection.connectionInfo().localAddress; + reportStarted(); + }); + connect(&connection, &QSsh::SshConnection::error, this, [this] { + reportFailure(); + }); + } + + void start() override + { + connection.connectToHost(); + } + + QSsh::SshConnection connection; +}; + +MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl, bool withGdb) + : ValgrindToolRunner(runControl), + m_withGdb(withGdb), + m_localServerAddress(QHostAddress::LocalHost) +{ + setDisplayName("MemcheckToolRunner"); + connect(m_runner.parser(), &XmlProtocol::ThreadedParser::error, + this, &MemcheckToolRunner::parserError); + connect(m_runner.parser(), &XmlProtocol::ThreadedParser::suppressionCount, + this, &MemcheckToolRunner::suppressionCount); + + if (withGdb) { + connect(&m_runner, &ValgrindRunner::valgrindStarted, + this, &MemcheckToolRunner::startDebugger); + connect(&m_runner, &ValgrindRunner::logMessageReceived, + this, &MemcheckToolRunner::appendLog); +// m_runner.disableXml(); + } else { + connect(m_runner.parser(), &XmlProtocol::ThreadedParser::internalError, + this, &MemcheckToolRunner::internalParserError); + } + + // We need a real address to connect to from the outside. + if (device()->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) + addStartDependency(new LocalAddressFinder(runControl, &m_localServerAddress)); +} + +QString MemcheckToolRunner::progressTitle() const +{ + return tr("Analyzing Memory"); +} + +void MemcheckToolRunner::start() +{ + m_runner.setLocalServerAddress(m_localServerAddress); + ValgrindToolRunner::start(); +} + +void MemcheckToolRunner::stop() +{ + disconnect(m_runner.parser(), &ThreadedParser::internalError, + this, &MemcheckToolRunner::internalParserError); + ValgrindToolRunner::stop(); +} + +QStringList MemcheckToolRunner::toolArguments() const +{ + QStringList arguments = {"--tool=memcheck", "--gen-suppressions=all"}; + + QTC_ASSERT(m_settings, return arguments); + + if (m_settings->trackOrigins()) + arguments << "--track-origins=yes"; + + if (m_settings->showReachable()) + arguments << "--show-reachable=yes"; + + QString leakCheckValue; + switch (m_settings->leakCheckOnFinish()) { + case ValgrindBaseSettings::LeakCheckOnFinishNo: + leakCheckValue = "no"; + break; + case ValgrindBaseSettings::LeakCheckOnFinishYes: + leakCheckValue = "full"; + break; + case ValgrindBaseSettings::LeakCheckOnFinishSummaryOnly: + default: + leakCheckValue = "summary"; + break; + } + arguments << "--leak-check=" + leakCheckValue; + + foreach (const QString &file, m_settings->suppressionFiles()) + arguments << QString("--suppressions=%1").arg(file); + + arguments << QString("--num-callers=%1").arg(m_settings->numCallers()); + + if (m_withGdb) + arguments << "--vgdb=yes" << "--vgdb-error=0"; + + return arguments; +} + +QStringList MemcheckToolRunner::suppressionFiles() const +{ + return m_settings->suppressionFiles(); +} + +void MemcheckToolRunner::startDebugger(qint64 valgrindPid) +{ + auto debugger = new Debugger::DebuggerRunTool(runControl()); + debugger->setStartMode(Debugger::AttachToRemoteServer); + debugger->setRunControlName(QString("VGdb %1").arg(valgrindPid)); + debugger->setRemoteChannel(QString("| vgdb --pid=%1").arg(valgrindPid)); + debugger->setUseContinueInsteadOfRun(true); + debugger->addExpectedSignal("SIGTRAP"); + + connect(runControl(), &RunControl::stopped, debugger, &RunControl::deleteLater); + + debugger->initiateStart(); +} + +void MemcheckToolRunner::appendLog(const QByteArray &data) +{ + appendMessage(QString::fromUtf8(data), Utils::StdOutFormat); +} + + static ErrorListModel::RelevantFrameFinder makeFrameFinder(const QStringList &projectFiles) { return [projectFiles](const Error &error) { @@ -711,3 +880,5 @@ void destroyMemcheckTool() } // namespace Internal } // namespace Valgrind + +#include "memchecktool.moc" diff --git a/src/plugins/valgrind/valgrind.pro b/src/plugins/valgrind/valgrind.pro index 4bbd41fc5c7..216e3568173 100644 --- a/src/plugins/valgrind/valgrind.pro +++ b/src/plugins/valgrind/valgrind.pro @@ -21,7 +21,6 @@ HEADERS += \ workarounds.h \ callgrindtextmark.h \ memchecktool.h \ - memcheckengine.h \ memcheckerrorview.h \ suppressiondialog.h @@ -41,7 +40,6 @@ SOURCES += \ workarounds.cpp \ callgrindtextmark.cpp \ memchecktool.cpp \ - memcheckengine.cpp \ memcheckerrorview.cpp \ suppressiondialog.cpp diff --git a/src/plugins/valgrind/valgrind.qbs b/src/plugins/valgrind/valgrind.qbs index 44814d0ce6f..5b7fb8f040c 100644 --- a/src/plugins/valgrind/valgrind.qbs +++ b/src/plugins/valgrind/valgrind.qbs @@ -27,7 +27,6 @@ QtcPlugin { "callgrindtextmark.cpp", "callgrindtextmark.h", "callgrindtool.cpp", "callgrindtool.h", "callgrindvisualisation.cpp", "callgrindvisualisation.h", - "memcheckengine.cpp", "memcheckengine.h", "memcheckerrorview.cpp", "memcheckerrorview.h", "memchecktool.cpp", "memchecktool.h", "suppressiondialog.cpp", "suppressiondialog.h",