forked from qt-creator/qt-creator
Valgrind: Simplify RunControlFactory setup
Change-Id: Ibef142e84ce1d4aca299dd8fa53b1eabcf517100 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -488,10 +488,19 @@ static WorkerFactories &theWorkerFactories()
|
||||
return factories;
|
||||
}
|
||||
|
||||
bool RunControl::WorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
|
||||
{
|
||||
if (runMode != runMode)
|
||||
return false;
|
||||
if (!constraint)
|
||||
return true;
|
||||
return constraint(runConfiguration);
|
||||
}
|
||||
|
||||
bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
|
||||
{
|
||||
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
|
||||
if (factory.runMode == runMode && factory.constraint(runConfiguration))
|
||||
if (factory.canRun(runConfiguration, runMode))
|
||||
return true;
|
||||
};
|
||||
return false;
|
||||
@@ -500,7 +509,7 @@ bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id run
|
||||
RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *)
|
||||
{
|
||||
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
|
||||
if (factory.runMode == runMode && factory.constraint(runConfiguration)) {
|
||||
if (factory.canRun(runConfiguration, runMode)) {
|
||||
auto runControl = new RunControl(runConfiguration, runMode);
|
||||
factory.producer(runControl);
|
||||
return runControl;
|
||||
@@ -758,7 +767,7 @@ RunWorker *RunControl::createWorker(Core::Id id)
|
||||
{
|
||||
auto keys = theWorkerCreators().keys();
|
||||
Q_UNUSED(keys);
|
||||
Producer creator = theWorkerCreators().value(id);
|
||||
WorkerCreator creator = theWorkerCreators().value(id);
|
||||
if (creator)
|
||||
return creator(this);
|
||||
creator = device()->workerCreator(id);
|
||||
@@ -767,10 +776,11 @@ RunWorker *RunControl::createWorker(Core::Id id)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RunControl::Producer RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode)
|
||||
RunControl::WorkerCreator RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode)
|
||||
{
|
||||
for (const auto &factory : theWorkerFactories()) {
|
||||
if (factory.runMode == runMode && factory.constraint(runConfiguration))
|
||||
if (factory.runMode == runMode
|
||||
&& (!factory.constraint || factory.constraint(runConfiguration)))
|
||||
return factory.producer;
|
||||
}
|
||||
return {};
|
||||
|
@@ -478,9 +478,6 @@ public:
|
||||
const QString &cancelButtonText = QString(),
|
||||
bool *prompt = nullptr);
|
||||
|
||||
using WorkerCreator = std::function<RunWorker *(RunControl *)>;
|
||||
static void registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator);
|
||||
RunWorker *workerById(Core::Id id) const;
|
||||
QList<QPointer<RunWorker>> workers() const;
|
||||
|
||||
template <class T> T *worker() const {
|
||||
@@ -495,9 +492,16 @@ public:
|
||||
|
||||
RunWorker *createWorker(Core::Id id);
|
||||
|
||||
using Producer = std::function<RunWorker *(RunControl *)>;
|
||||
using WorkerCreator = std::function<RunWorker *(RunControl *)>;
|
||||
using Constraint = std::function<bool(RunConfiguration *)>;
|
||||
|
||||
static void registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator);
|
||||
|
||||
static void registerWorker(Core::Id runMode, const WorkerCreator &producer,
|
||||
const Constraint &constraint = {})
|
||||
{
|
||||
addWorkerFactory({runMode, constraint, producer});
|
||||
}
|
||||
template <class Worker>
|
||||
static void registerWorker(Core::Id runMode, const Constraint &constraint)
|
||||
{
|
||||
@@ -515,10 +519,12 @@ public:
|
||||
struct WorkerFactory {
|
||||
Core::Id runMode;
|
||||
Constraint constraint;
|
||||
Producer producer;
|
||||
WorkerCreator producer;
|
||||
|
||||
bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const;
|
||||
};
|
||||
|
||||
static Producer producer(RunConfiguration *runConfiguration, Core::Id runMode);
|
||||
static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode);
|
||||
|
||||
signals:
|
||||
void appendMessageRequested(ProjectExplorer::RunControl *runControl,
|
||||
@@ -533,7 +539,6 @@ private:
|
||||
friend class Internal::RunWorkerPrivate;
|
||||
|
||||
static void addWorkerFactory(const WorkerFactory &workerFactory);
|
||||
|
||||
void bringApplicationToForegroundInternal();
|
||||
Internal::RunControlPrivate *d;
|
||||
};
|
||||
|
@@ -41,7 +41,6 @@
|
||||
#include <valgrind/callgrind/callgrindproxymodel.h>
|
||||
#include <valgrind/callgrind/callgrindstackbrowser.h>
|
||||
#include <valgrind/valgrindplugin.h>
|
||||
#include <valgrind/valgrindruncontrolfactory.h>
|
||||
#include <valgrind/valgrindsettings.h>
|
||||
|
||||
#include <debugger/debuggerconstants.h>
|
||||
@@ -99,6 +98,7 @@ using namespace Valgrind::Callgrind;
|
||||
using namespace TextEditor;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
using namespace std::placeholders;
|
||||
|
||||
namespace Valgrind {
|
||||
namespace Internal {
|
||||
@@ -118,7 +118,7 @@ class CallgrindTool : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CallgrindTool(QObject *parent);
|
||||
CallgrindTool();
|
||||
~CallgrindTool();
|
||||
|
||||
ValgrindToolRunner *createRunTool(RunControl *runControl);
|
||||
@@ -222,8 +222,7 @@ public:
|
||||
bool m_toolBusy = false;
|
||||
};
|
||||
|
||||
CallgrindTool::CallgrindTool(QObject *parent)
|
||||
: QObject(parent)
|
||||
CallgrindTool::CallgrindTool()
|
||||
{
|
||||
setObjectName(QLatin1String("CallgrindTool"));
|
||||
|
||||
@@ -251,10 +250,6 @@ CallgrindTool::CallgrindTool(QObject *parent)
|
||||
QString toolTip = tr("Valgrind Function Profiler uses the "
|
||||
"Callgrind tool to record function calls when a program runs.");
|
||||
|
||||
RunControl::registerWorkerCreator(CALLGRIND_RUN_MODE, [this](RunControl *runControl) {
|
||||
return createRunTool(runControl);
|
||||
});
|
||||
|
||||
if (!Utils::HostOsInfo::isWindowsHost()) {
|
||||
auto action = new QAction(tr("Valgrind Function Profiler"), this);
|
||||
action->setToolTip(toolTip);
|
||||
@@ -966,48 +961,20 @@ void CallgrindTool::createTextMarks()
|
||||
}
|
||||
|
||||
|
||||
class CallgrindRunControlFactory : public IRunControlFactory
|
||||
{
|
||||
public:
|
||||
CallgrindRunControlFactory() : m_tool(new CallgrindTool(this)) {}
|
||||
|
||||
bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const override
|
||||
{
|
||||
Q_UNUSED(runConfiguration);
|
||||
return runMode == CALLGRIND_RUN_MODE;
|
||||
}
|
||||
|
||||
RunControl *create(RunConfiguration *runConfiguration, Core::Id runMode, QString *errorMessage) override
|
||||
{
|
||||
Q_UNUSED(errorMessage);
|
||||
auto runControl = new RunControl(runConfiguration, runMode);
|
||||
m_tool->createRunTool(runControl);
|
||||
return runControl;
|
||||
}
|
||||
|
||||
IRunConfigurationAspect *createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc) override
|
||||
{
|
||||
return createValgrindRunConfigurationAspect(rc);
|
||||
}
|
||||
|
||||
public:
|
||||
CallgrindTool *m_tool;
|
||||
};
|
||||
|
||||
|
||||
static CallgrindRunControlFactory *theCallgrindRunControlFactory;
|
||||
static CallgrindTool *theCallgrindTool;
|
||||
|
||||
void initCallgrindTool()
|
||||
{
|
||||
theCallgrindRunControlFactory = new CallgrindRunControlFactory;
|
||||
ExtensionSystem::PluginManager::addObject(theCallgrindRunControlFactory);
|
||||
theCallgrindTool = new CallgrindTool;
|
||||
|
||||
auto producer = std::bind(&CallgrindTool::createRunTool, theCallgrindTool, _1);
|
||||
RunControl::registerWorker(CALLGRIND_RUN_MODE, producer);
|
||||
}
|
||||
|
||||
void destroyCallgrindTool()
|
||||
{
|
||||
ExtensionSystem::PluginManager::removeObject(theCallgrindRunControlFactory);
|
||||
delete theCallgrindRunControlFactory;
|
||||
theCallgrindRunControlFactory = 0;
|
||||
delete theCallgrindTool;
|
||||
theCallgrindTool = nullptr;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -36,7 +36,6 @@
|
||||
#include <debugger/analyzer/startremotedialog.h>
|
||||
|
||||
#include <valgrind/valgrindsettings.h>
|
||||
#include <valgrind/valgrindruncontrolfactory.h>
|
||||
#include <valgrind/xmlprotocol/errorlistmodel.h>
|
||||
#include <valgrind/xmlprotocol/stackmodel.h>
|
||||
#include <valgrind/xmlprotocol/error.h>
|
||||
@@ -241,7 +240,7 @@ class MemcheckTool : public QObject
|
||||
Q_DECLARE_TR_FUNCTIONS(Valgrind::Internal::MemcheckTool)
|
||||
|
||||
public:
|
||||
MemcheckTool(QObject *parent);
|
||||
MemcheckTool();
|
||||
|
||||
RunWorker *createRunWorker(RunControl *runControl);
|
||||
|
||||
@@ -286,8 +285,7 @@ private:
|
||||
bool m_toolBusy = false;
|
||||
};
|
||||
|
||||
MemcheckTool::MemcheckTool(QObject *parent)
|
||||
: QObject(parent)
|
||||
MemcheckTool::MemcheckTool()
|
||||
{
|
||||
m_settings = ValgrindPlugin::globalSettings();
|
||||
|
||||
@@ -393,9 +391,6 @@ MemcheckTool::MemcheckTool(QObject *parent)
|
||||
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
|
||||
QString toolTip = tr("Valgrind Analyze Memory uses the Memcheck tool to find memory leaks.");
|
||||
|
||||
RunControl::registerWorkerCreator(MEMCHECK_RUN_MODE, std::bind(&MemcheckTool::createRunWorker, this, _1));
|
||||
RunControl::registerWorkerCreator(MEMCHECK_WITH_GDB_RUN_MODE, std::bind(&MemcheckTool::createRunWorker, this, _1));
|
||||
|
||||
if (!Utils::HostOsInfo::isWindowsHost()) {
|
||||
action = new QAction(this);
|
||||
action->setText(tr("Valgrind Memory Analyzer"));
|
||||
@@ -711,49 +706,21 @@ void MemcheckTool::setBusyCursor(bool busy)
|
||||
}
|
||||
|
||||
|
||||
class MemcheckRunControlFactory : public IRunControlFactory
|
||||
{
|
||||
public:
|
||||
MemcheckRunControlFactory() : m_tool(new MemcheckTool(this)) {}
|
||||
|
||||
bool canRun(RunConfiguration *runConfiguration, Core::Id mode) const override
|
||||
{
|
||||
Q_UNUSED(runConfiguration);
|
||||
return mode == MEMCHECK_RUN_MODE || mode == MEMCHECK_WITH_GDB_RUN_MODE;
|
||||
}
|
||||
|
||||
RunControl *create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) override
|
||||
{
|
||||
Q_UNUSED(errorMessage);
|
||||
auto runControl = new RunControl(runConfiguration, mode);
|
||||
runControl->createWorker(mode);
|
||||
return runControl;
|
||||
}
|
||||
|
||||
// Do not create an aspect, let the Callgrind tool create one and use that, too.
|
||||
// IRunConfigurationAspect *createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc) override
|
||||
// {
|
||||
// return createValgrindRunConfigurationAspect(rc);
|
||||
// }
|
||||
|
||||
public:
|
||||
MemcheckTool *m_tool;
|
||||
};
|
||||
|
||||
|
||||
static MemcheckRunControlFactory *theMemcheckRunControlFactory;
|
||||
static MemcheckTool *theMemcheckTool;
|
||||
|
||||
void initMemcheckTool()
|
||||
{
|
||||
theMemcheckRunControlFactory = new MemcheckRunControlFactory;
|
||||
ExtensionSystem::PluginManager::addObject(theMemcheckRunControlFactory);
|
||||
theMemcheckTool = new MemcheckTool;
|
||||
|
||||
auto producer = std::bind(&MemcheckTool::createRunWorker, theMemcheckTool, _1);
|
||||
RunControl::registerWorker(MEMCHECK_RUN_MODE, producer);
|
||||
RunControl::registerWorker(MEMCHECK_WITH_GDB_RUN_MODE, producer);
|
||||
}
|
||||
|
||||
void destroyMemcheckTool()
|
||||
{
|
||||
ExtensionSystem::PluginManager::removeObject(theMemcheckRunControlFactory);
|
||||
delete theMemcheckRunControlFactory;
|
||||
theMemcheckRunControlFactory = 0;
|
||||
delete theMemcheckTool;
|
||||
theMemcheckTool = nullptr;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -23,8 +23,7 @@ HEADERS += \
|
||||
memchecktool.h \
|
||||
memcheckengine.h \
|
||||
memcheckerrorview.h \
|
||||
suppressiondialog.h \
|
||||
valgrindruncontrolfactory.h
|
||||
suppressiondialog.h
|
||||
|
||||
SOURCES += \
|
||||
valgrindplugin.cpp \
|
||||
@@ -44,8 +43,7 @@ SOURCES += \
|
||||
memchecktool.cpp \
|
||||
memcheckengine.cpp \
|
||||
memcheckerrorview.cpp \
|
||||
suppressiondialog.cpp \
|
||||
valgrindruncontrolfactory.cpp
|
||||
suppressiondialog.cpp
|
||||
|
||||
FORMS += \
|
||||
valgrindconfigwidget.ui
|
||||
|
@@ -34,7 +34,6 @@ QtcPlugin {
|
||||
"valgrindconfigwidget.cpp", "valgrindconfigwidget.h", "valgrindconfigwidget.ui",
|
||||
"valgrindengine.cpp", "valgrindengine.h",
|
||||
"valgrindplugin.cpp", "valgrindplugin.h",
|
||||
"valgrindruncontrolfactory.cpp", "valgrindruncontrolfactory.h",
|
||||
"valgrindrunner.cpp", "valgrindrunner.h",
|
||||
"valgrindsettings.cpp", "valgrindsettings.h",
|
||||
"workarounds.cpp", "workarounds.h",
|
||||
|
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "callgrindtool.h"
|
||||
#include "memchecktool.h"
|
||||
#include "valgrindruncontrolfactory.h"
|
||||
#include "valgrindsettings.h"
|
||||
#include "valgrindconfigwidget.h"
|
||||
|
||||
@@ -40,6 +39,7 @@
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <debugger/analyzer/analyzerrunconfigwidget.h>
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
|
||||
@@ -88,6 +88,37 @@ private:
|
||||
QPointer<QWidget> m_widget;
|
||||
};
|
||||
|
||||
class ValgrindRunConfigurationAspect : public IRunConfigurationAspect
|
||||
{
|
||||
public:
|
||||
ValgrindRunConfigurationAspect(RunConfiguration *parent)
|
||||
: IRunConfigurationAspect(parent)
|
||||
{
|
||||
setProjectSettings(new ValgrindProjectSettings());
|
||||
setGlobalSettings(ValgrindPlugin::globalSettings());
|
||||
setId(ANALYZER_VALGRIND_SETTINGS);
|
||||
setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindRunConfigurationAspect",
|
||||
"Valgrind Settings"));
|
||||
setUsingGlobalSettings(true);
|
||||
resetProjectToGlobalSettings();
|
||||
setRunConfigWidgetCreator([this] { return new Debugger::AnalyzerRunConfigWidget(this); });
|
||||
}
|
||||
|
||||
ValgrindRunConfigurationAspect *create(RunConfiguration *parent) const override
|
||||
{
|
||||
return new ValgrindRunConfigurationAspect(parent);
|
||||
}
|
||||
};
|
||||
|
||||
class ValgrindRunControlFactory : public IRunControlFactory
|
||||
{
|
||||
public:
|
||||
IRunConfigurationAspect *createRunConfigurationAspect(RunConfiguration *rc) override
|
||||
{
|
||||
return new ValgrindRunConfigurationAspect(rc);
|
||||
}
|
||||
};
|
||||
|
||||
ValgrindPlugin::~ValgrindPlugin()
|
||||
{
|
||||
delete theGlobalSettings;
|
||||
@@ -100,6 +131,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
||||
theGlobalSettings->readSettings();
|
||||
|
||||
addAutoReleasedObject(new ValgrindOptionsPage);
|
||||
addAutoReleasedObject(new ValgrindRunControlFactory);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -1,72 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 Kläralvdalens Datakonsult AB, a KDAB Group company, info@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 "valgrindruncontrolfactory.h"
|
||||
|
||||
#include "valgrindengine.h"
|
||||
#include "valgrindsettings.h"
|
||||
#include "valgrindplugin.h"
|
||||
#include "callgrindtool.h"
|
||||
#include "memchecktool.h"
|
||||
|
||||
#include <debugger/analyzer/analyzermanager.h>
|
||||
#include <debugger/analyzer/analyzerrunconfigwidget.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace Debugger;
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace Valgrind {
|
||||
namespace Internal {
|
||||
|
||||
class ValgrindRunConfigurationAspect : public IRunConfigurationAspect
|
||||
{
|
||||
public:
|
||||
ValgrindRunConfigurationAspect(RunConfiguration *parent)
|
||||
: IRunConfigurationAspect(parent)
|
||||
{
|
||||
setProjectSettings(new ValgrindProjectSettings());
|
||||
setGlobalSettings(ValgrindPlugin::globalSettings());
|
||||
setId(ANALYZER_VALGRIND_SETTINGS);
|
||||
setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindRunConfigurationAspect", "Valgrind Settings"));
|
||||
setUsingGlobalSettings(true);
|
||||
resetProjectToGlobalSettings();
|
||||
setRunConfigWidgetCreator([this] { return new AnalyzerRunConfigWidget(this); });
|
||||
}
|
||||
|
||||
ValgrindRunConfigurationAspect *create(RunConfiguration *parent) const override
|
||||
{
|
||||
return new ValgrindRunConfigurationAspect(parent);
|
||||
}
|
||||
};
|
||||
|
||||
IRunConfigurationAspect *createValgrindRunConfigurationAspect(RunConfiguration *rc)
|
||||
{
|
||||
return new ValgrindRunConfigurationAspect(rc);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Valgrind
|
@@ -1,36 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 Kläralvdalens Datakonsult AB, a KDAB Group company, info@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 <projectexplorer/runconfiguration.h>
|
||||
|
||||
namespace Valgrind {
|
||||
namespace Internal {
|
||||
|
||||
ProjectExplorer::IRunConfigurationAspect *createValgrindRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc);
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Valgrind
|
Reference in New Issue
Block a user