Valgrind: Split MemCheck and CallGrind factories

The tools are separated everywhere, lumping them into the same
RunControlFactory removes modularity artificially.

Change-Id: I8d9e917bb114a1898a0c293f18d3bf78a52075aa
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2016-03-07 17:33:58 +01:00
parent 494f4a7742
commit d02919d850
11 changed files with 117 additions and 86 deletions

View File

@@ -39,8 +39,8 @@ using namespace Debugger;
using namespace Valgrind; using namespace Valgrind;
using namespace Valgrind::Internal; using namespace Valgrind::Internal;
CallgrindRunControl::CallgrindRunControl(ProjectExplorer::RunConfiguration *runConfiguration) CallgrindRunControl::CallgrindRunControl(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id runMode)
: ValgrindRunControl(runConfiguration, CALLGRIND_RUN_MODE) : ValgrindRunControl(runConfiguration, runMode)
, m_markAsPaused(false) , m_markAsPaused(false)
{ {
connect(&m_runner, &Callgrind::CallgrindRunner::finished, connect(&m_runner, &Callgrind::CallgrindRunner::finished,

View File

@@ -38,7 +38,7 @@ class CallgrindRunControl : public ValgrindRunControl
Q_OBJECT Q_OBJECT
public: public:
CallgrindRunControl(ProjectExplorer::RunConfiguration *runConfiguration); CallgrindRunControl(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id runMode);
void start() override; void start() override;

View File

@@ -41,6 +41,7 @@
#include <valgrind/callgrind/callgrindproxymodel.h> #include <valgrind/callgrind/callgrindproxymodel.h>
#include <valgrind/callgrind/callgrindstackbrowser.h> #include <valgrind/callgrind/callgrindstackbrowser.h>
#include <valgrind/valgrindplugin.h> #include <valgrind/valgrindplugin.h>
#include <valgrind/valgrindruncontrolfactory.h>
#include <valgrind/valgrindsettings.h> #include <valgrind/valgrindsettings.h>
#include <debugger/debuggerconstants.h> #include <debugger/debuggerconstants.h>
@@ -64,6 +65,8 @@
#include <cppeditor/cppeditorconstants.h> #include <cppeditor/cppeditorconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
#include <texteditor/textdocument.h> #include <texteditor/textdocument.h>
@@ -73,9 +76,14 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorericons.h>
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <utils/fancymainwindow.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <QAction> #include <QAction>
#include <QActionGroup> #include <QActionGroup>
#include <QComboBox> #include <QComboBox>
@@ -100,6 +108,16 @@ using namespace Utils;
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
const char CallgrindPerspectiveId[] = "Callgrind.Perspective";
const char CallgrindLocalActionId[] = "Callgrind.Local.Action";
const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action";
const char CallgrindCallersDockId[] = "Callgrind.Callers.Dock";
const char CallgrindCalleesDockId[] = "Callgrind.Callees.Dock";
const char CallgrindFlatDockId[] = "Callgrind.Flat.Dock";
const char CallgrindVisualizationDockId[] = "Callgrind.Visualization.Dock";
const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode";
class CallgrindTool : public QObject class CallgrindTool : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -108,7 +126,7 @@ public:
CallgrindTool(QObject *parent); CallgrindTool(QObject *parent);
~CallgrindTool(); ~CallgrindTool();
ValgrindRunControl *createRunControl(RunConfiguration *runConfiguration); ValgrindRunControl *createRunControl(RunConfiguration *runConfiguration, Id runMode);
void setParseData(ParseData *data); void setParseData(ParseData *data);
CostDelegate::CostFormat costFormat() const; CostDelegate::CostFormat costFormat() const;
@@ -245,7 +263,7 @@ CallgrindTool::CallgrindTool(QObject *parent)
desc.setText(tr("Valgrind Function Profiler")); desc.setText(tr("Valgrind Function Profiler"));
desc.setPerspectiveId(CallgrindPerspectiveId); desc.setPerspectiveId(CallgrindPerspectiveId);
desc.setRunControlCreator([this](RunConfiguration *runConfiguration, Id) { desc.setRunControlCreator([this](RunConfiguration *runConfiguration, Id) {
return createRunControl(runConfiguration); return createRunControl(runConfiguration, CALLGRIND_RUN_MODE);
}); });
desc.setToolMode(OptimizedMode); desc.setToolMode(OptimizedMode);
desc.setRunMode(CALLGRIND_RUN_MODE); desc.setRunMode(CALLGRIND_RUN_MODE);
@@ -259,7 +277,7 @@ CallgrindTool::CallgrindTool(QObject *parent)
StartRemoteDialog dlg; StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted)
return; return;
ValgrindRunControl *rc = createRunControl(runConfig); ValgrindRunControl *rc = createRunControl(runConfig, CALLGRIND_RUN_MODE);
QTC_ASSERT(rc, return); QTC_ASSERT(rc, return);
const auto runnable = dlg.runnable(); const auto runnable = dlg.runnable();
rc->setRunnable(runnable); rc->setRunnable(runnable);
@@ -729,9 +747,9 @@ void CallgrindTool::updateEventCombo()
m_eventCombo->addItem(ParseData::prettyStringForEvent(event)); m_eventCombo->addItem(ParseData::prettyStringForEvent(event));
} }
ValgrindRunControl *CallgrindTool::createRunControl(RunConfiguration *runConfiguration) ValgrindRunControl *CallgrindTool::createRunControl(RunConfiguration *runConfiguration, Id runMode)
{ {
auto runControl = new CallgrindRunControl(runConfiguration); auto runControl = new CallgrindRunControl(runConfiguration, runMode);
connect(runControl, &CallgrindRunControl::parserDataReady, this, &CallgrindTool::takeParserDataFromRunControl); connect(runControl, &CallgrindRunControl::parserDataReady, this, &CallgrindTool::takeParserDataFromRunControl);
connect(runControl, &AnalyzerRunControl::starting, this, &CallgrindTool::engineStarting); connect(runControl, &AnalyzerRunControl::starting, this, &CallgrindTool::engineStarting);
@@ -958,17 +976,47 @@ void CallgrindTool::createTextMarks()
} }
} }
static CallgrindTool *theCallgrindTool;
void initCallgrindTool(QObject *parent) class CallgrindRunControlFactory : public IRunControlFactory
{ {
theCallgrindTool = new CallgrindTool(parent); 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);
return m_tool->createRunControl(runConfiguration, runMode);
}
IRunConfigurationAspect *createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc) override
{
return createValgrindRunConfigurationAspect(rc);
}
public:
CallgrindTool *m_tool;
};
static CallgrindRunControlFactory *theCallgrindRunControlFactory;
void initCallgrindTool()
{
theCallgrindRunControlFactory = new CallgrindRunControlFactory;
ExtensionSystem::PluginManager::addObject(theCallgrindRunControlFactory);
} }
void destroyCallgrindTool() void destroyCallgrindTool()
{ {
delete theCallgrindTool; ExtensionSystem::PluginManager::addObject(theCallgrindRunControlFactory);
theCallgrindTool = 0; delete theCallgrindRunControlFactory;
theCallgrindRunControlFactory = 0;
} }
} // namespace Internal } // namespace Internal

View File

@@ -25,22 +25,10 @@
#pragma once #pragma once
#include <QObject>
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
const char CallgrindPerspectiveId[] = "Callgrind.Perspective"; void initCallgrindTool();
const char CallgrindLocalActionId[] = "Callgrind.Local.Action";
const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action";
const char CallgrindCallersDockId[] = "Callgrind.Callers.Dock";
const char CallgrindCalleesDockId[] = "Callgrind.Callees.Dock";
const char CallgrindFlatDockId[] = "Callgrind.Flat.Dock";
const char CallgrindVisualizationDockId[] = "Callgrind.Visualization.Dock";
const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode";
void initCallgrindTool(QObject *parent);
void destroyCallgrindTool(); void destroyCallgrindTool();
} // namespace Internal } // namespace Internal

View File

@@ -128,8 +128,8 @@ QStringList MemcheckRunControl::suppressionFiles() const
return m_settings->suppressionFiles(); return m_settings->suppressionFiles();
} }
MemcheckWithGdbRunControl::MemcheckWithGdbRunControl(RunConfiguration *runConfiguration) MemcheckWithGdbRunControl::MemcheckWithGdbRunControl(RunConfiguration *runConfiguration, Core::Id runMode)
: MemcheckRunControl(runConfiguration, MEMCHECK_WITH_GDB_RUN_MODE) : MemcheckRunControl(runConfiguration, runMode)
{ {
connect(&m_runner, &Memcheck::MemcheckRunner::started, connect(&m_runner, &Memcheck::MemcheckRunner::started,
this, &MemcheckWithGdbRunControl::startDebugger); this, &MemcheckWithGdbRunControl::startDebugger);

View File

@@ -67,7 +67,8 @@ class MemcheckWithGdbRunControl : public MemcheckRunControl
Q_OBJECT Q_OBJECT
public: public:
MemcheckWithGdbRunControl(ProjectExplorer::RunConfiguration *runConfiguration); MemcheckWithGdbRunControl(ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode);
protected: protected:
QStringList toolArguments() const override; QStringList toolArguments() const override;

View File

@@ -37,6 +37,7 @@
#include <debugger/analyzer/startremotedialog.h> #include <debugger/analyzer/startremotedialog.h>
#include <valgrind/valgrindsettings.h> #include <valgrind/valgrindsettings.h>
#include <valgrind/valgrindruncontrolfactory.h>
#include <valgrind/xmlprotocol/errorlistmodel.h> #include <valgrind/xmlprotocol/errorlistmodel.h>
#include <valgrind/xmlprotocol/stackmodel.h> #include <valgrind/xmlprotocol/stackmodel.h>
#include <valgrind/xmlprotocol/error.h> #include <valgrind/xmlprotocol/error.h>
@@ -94,6 +95,12 @@ using namespace std::placeholders;
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
const char MEMCHECK_RUN_MODE[] = "MemcheckTool.MemcheckRunMode";
const char MEMCHECK_WITH_GDB_RUN_MODE[] = "MemcheckTool.MemcheckWithGdbRunMode";
const char MemcheckPerspectiveId[] = "Memcheck.Perspective";
const char MemcheckErrorDockId[] = "Memcheck.Dock.Error";
static ErrorListModel::RelevantFrameFinder makeFrameFinder(const QStringList &projectFiles) static ErrorListModel::RelevantFrameFinder makeFrameFinder(const QStringList &projectFiles)
{ {
return [projectFiles](const Error &error) { return [projectFiles](const Error &error) {
@@ -234,8 +241,7 @@ class MemcheckTool : public QObject
public: public:
MemcheckTool(QObject *parent); MemcheckTool(QObject *parent);
MemcheckRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration, AnalyzerRunControl *createRunControl(RunConfiguration *runConfiguration, Core::Id runMode);
Core::Id runMode);
private: private:
void updateRunActions(); void updateRunActions();
@@ -414,7 +420,7 @@ MemcheckTool::MemcheckTool(QObject *parent)
StartRemoteDialog dlg; StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted)
return; return;
ValgrindRunControl *rc = createRunControl(runConfig, MEMCHECK_RUN_MODE); AnalyzerRunControl *rc = createRunControl(runConfig, MEMCHECK_RUN_MODE);
QTC_ASSERT(rc, return); QTC_ASSERT(rc, return);
const auto runnable = dlg.runnable(); const auto runnable = dlg.runnable();
rc->setRunnable(runnable); rc->setRunnable(runnable);
@@ -524,8 +530,7 @@ void MemcheckTool::maybeActiveRunConfigurationChanged()
updateFromSettings(); updateFromSettings();
} }
MemcheckRunControl *MemcheckTool::createRunControl(RunConfiguration *runConfiguration, AnalyzerRunControl *MemcheckTool::createRunControl(RunConfiguration *runConfiguration, Core::Id runMode)
Core::Id runMode)
{ {
m_errorModel.setRelevantFrameFinder(makeFrameFinder(runConfiguration m_errorModel.setRelevantFrameFinder(makeFrameFinder(runConfiguration
? runConfiguration->target()->project()->files(Project::AllFiles) : QStringList())); ? runConfiguration->target()->project()->files(Project::AllFiles) : QStringList()));
@@ -534,7 +539,7 @@ MemcheckRunControl *MemcheckTool::createRunControl(RunConfiguration *runConfigur
if (runMode == MEMCHECK_RUN_MODE) if (runMode == MEMCHECK_RUN_MODE)
runControl = new MemcheckRunControl(runConfiguration, runMode); runControl = new MemcheckRunControl(runConfiguration, runMode);
else else
runControl = new MemcheckWithGdbRunControl(runConfiguration); runControl = new MemcheckWithGdbRunControl(runConfiguration, runMode);
connect(runControl, &MemcheckRunControl::starting, connect(runControl, &MemcheckRunControl::starting,
this, [this, runControl]() { engineStarting(runControl); }); this, [this, runControl]() { engineStarting(runControl); });
connect(runControl, &MemcheckRunControl::parserError, this, &MemcheckTool::parserError); connect(runControl, &MemcheckRunControl::parserError, this, &MemcheckTool::parserError);
@@ -685,17 +690,47 @@ void MemcheckTool::setBusyCursor(bool busy)
m_errorView->setCursor(cursor); m_errorView->setCursor(cursor);
} }
static MemcheckTool *theMemcheckTool;
void initMemcheckTool(QObject *parent) class MemcheckRunControlFactory : public IRunControlFactory
{ {
theMemcheckTool = new MemcheckTool(parent); 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);
return m_tool->createRunControl(runConfiguration, mode);
}
IRunConfigurationAspect *createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc) override
{
return createValgrindRunConfigurationAspect(rc);
}
public:
MemcheckTool *m_tool;
};
static MemcheckRunControlFactory *theMemcheckRunControlFactory;
void initMemcheckTool()
{
theMemcheckRunControlFactory = new MemcheckRunControlFactory;
ExtensionSystem::PluginManager::addObject(theMemcheckRunControlFactory);
} }
void destroyMemcheckTool() void destroyMemcheckTool()
{ {
delete theMemcheckTool; ExtensionSystem::PluginManager::addObject(theMemcheckRunControlFactory);
theMemcheckTool = 0; delete theMemcheckRunControlFactory;
theMemcheckRunControlFactory = 0;
} }
} // namespace Internal } // namespace Internal

View File

@@ -26,19 +26,10 @@
#pragma once #pragma once
#include <QObject>
namespace Valgrind { namespace Valgrind {
const char MEMCHECK_RUN_MODE[] = "MemcheckTool.MemcheckRunMode";
const char MEMCHECK_WITH_GDB_RUN_MODE[] = "MemcheckTool.MemcheckWithGdbRunMode";
const char MemcheckPerspectiveId[] = "Memcheck.Perspective";
const char MemcheckErrorDockId[] = "Memcheck.Dock.Error";
namespace Internal { namespace Internal {
void initMemcheckTool(QObject *parent); void initMemcheckTool();
void destroyMemcheckTool(); void destroyMemcheckTool();
} // namespace Internal } // namespace Internal

View File

@@ -95,15 +95,14 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
theGlobalSettings->readSettings(); theGlobalSettings->readSettings();
addAutoReleasedObject(new ValgrindOptionsPage); addAutoReleasedObject(new ValgrindOptionsPage);
addAutoReleasedObject(new ValgrindRunControlFactory);
return true; return true;
} }
void ValgrindPlugin::extensionsInitialized() void ValgrindPlugin::extensionsInitialized()
{ {
initMemcheckTool(this); initMemcheckTool();
initCallgrindTool(this); initCallgrindTool();
} }
ExtensionSystem::IPlugin::ShutdownFlag ValgrindPlugin::aboutToShutdown() ExtensionSystem::IPlugin::ShutdownFlag ValgrindPlugin::aboutToShutdown()

View File

@@ -42,23 +42,6 @@ using namespace ProjectExplorer;
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
ValgrindRunControlFactory::ValgrindRunControlFactory(QObject *parent) :
IRunControlFactory(parent)
{
}
bool ValgrindRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const
{
Q_UNUSED(runConfiguration);
return mode == CALLGRIND_RUN_MODE || mode == MEMCHECK_RUN_MODE || mode == MEMCHECK_WITH_GDB_RUN_MODE;
}
RunControl *ValgrindRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
{
Q_UNUSED(errorMessage);
return Debugger::createAnalyzerRunControl(runConfiguration, mode);
}
class ValgrindRunConfigurationAspect : public IRunConfigurationAspect class ValgrindRunConfigurationAspect : public IRunConfigurationAspect
{ {
public: public:
@@ -80,7 +63,7 @@ public:
} }
}; };
IRunConfigurationAspect *ValgrindRunControlFactory::createRunConfigurationAspect(RunConfiguration *rc) IRunConfigurationAspect *createValgrindRunConfigurationAspect(RunConfiguration *rc)
{ {
return new ValgrindRunConfigurationAspect(rc); return new ValgrindRunConfigurationAspect(rc);
} }

View File

@@ -30,21 +30,7 @@
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
class ValgrindRunControlFactory : public ProjectExplorer::IRunControlFactory ProjectExplorer::IRunConfigurationAspect *createValgrindRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc);
{
Q_OBJECT
public:
typedef ProjectExplorer::RunConfiguration RunConfiguration;
explicit ValgrindRunControlFactory(QObject *parent = 0);
// IRunControlFactory implementation
bool canRun(RunConfiguration *runConfiguration, Core::Id mode) const override;
ProjectExplorer::RunControl *create(RunConfiguration *runConfiguration, Core::Id mode,
QString *errorMessage) override;
ProjectExplorer::IRunConfigurationAspect *createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc) override;
};
} // namespace Internal } // namespace Internal
} // namespace Valgrind } // namespace Valgrind