Valgrind: Clean up tools interface a bit

Mainly move tool specific code from plugin.cpp to *tool.cpp.
Clean up includes etc.

Change-Id: Ic968ead9d93099c59abe9f99a9db529305160f95
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2016-03-02 12:05:30 +01:00
parent c0b9565de7
commit 7a5226aa47
10 changed files with 451 additions and 564 deletions

View File

@@ -36,31 +36,17 @@
namespace Valgrind {
namespace Callgrind {
//BEGIN CallModel::Private
class CallModel::Private
{
public:
Private();
const ParseData *m_data;
const ParseData *m_data = 0;
QVector<const FunctionCall *> m_calls;
int m_event;
const Function *m_function;
int m_event = 0;
const Function *m_function = 0;
};
CallModel::Private::Private()
: m_data(0)
, m_event(0)
, m_function(0)
{
}
//END CallModel::Private
//BEGIN CallModel
CallModel::CallModel(QObject *parent)
: QAbstractItemModel(parent), d(new Private)
CallModel::CallModel()
: d(new Private)
{
}

View File

@@ -43,7 +43,7 @@ class CallModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit CallModel(QObject *parent);
CallModel();
virtual ~CallModel();
void clear();

View File

@@ -41,27 +41,16 @@
namespace Valgrind {
namespace Callgrind {
//BEGIN DataModel::Private
class DataModel::Private
{
public:
Private()
: m_data(0)
, m_event(0)
, m_verboseToolTips(true)
, m_cycleDetection(false)
, m_shortenTemplates(false)
{
}
void updateFunctions();
const ParseData *m_data;
int m_event;
bool m_verboseToolTips;
bool m_cycleDetection;
bool m_shortenTemplates;
const ParseData *m_data = 0;
int m_event = 0;
bool m_verboseToolTips = true;
bool m_cycleDetection = false;
bool m_shortenTemplates = false;
QVector<const Function *> m_functions;
};
@@ -77,10 +66,8 @@ void DataModel::Private::updateFunctions()
}
}
//BEGIN DataModel
DataModel::DataModel(QObject *parent)
: QAbstractItemModel(parent), d(new Private)
DataModel::DataModel()
: d(new Private)
{
}

View File

@@ -41,7 +41,7 @@ class DataModel : public QAbstractItemModel
Q_OBJECT
public:
explicit DataModel(QObject *parent);
DataModel();
virtual ~DataModel();
virtual void setParseData(const ParseData *data);

File diff suppressed because it is too large Load Diff

View File

@@ -28,8 +28,6 @@
#include <QObject>
namespace ProjectExplorer { class RunConfiguration; }
namespace Valgrind {
namespace Internal {
@@ -41,27 +39,10 @@ const char CallgrindCalleesDockId[] = "Callgrind.Callees.Dock";
const char CallgrindFlatDockId[] = "Callgrind.Flat.Dock";
const char CallgrindVisualizationDockId[] = "Callgrind.Visualization.Dock";
class ValgrindRunControl;
const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode";
class CallgrindToolPrivate;
class CallgrindTool : public QObject
{
Q_OBJECT
public:
CallgrindTool(QObject *parent);
~CallgrindTool();
ValgrindRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration);
QWidget *createWidgets();
void handleShowCostsOfFunction();
private:
CallgrindToolPrivate *d;
};
void initCallgrindTool(QObject *parent);
void destroyCallgrindTool();
} // namespace Internal
} // namespace Valgrind

View File

@@ -30,9 +30,11 @@
#include "valgrindsettings.h"
#include "valgrindplugin.h"
#include <debugger/analyzer/analyzermanager.h>
#include <debugger/analyzer/analyzerutils.h>
#include <debugger/analyzer/analyzerconstants.h>
#include <debugger/analyzer/analyzermanager.h>
#include <debugger/analyzer/analyzerstartparameters.h>
#include <debugger/analyzer/analyzerutils.h>
#include <debugger/analyzer/startremotedialog.h>
#include <valgrind/valgrindsettings.h>
#include <valgrind/xmlprotocol/errorlistmodel.h>
@@ -62,26 +64,26 @@
#include <coreplugin/id.h>
#include <utils/fancymainwindow.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <utils/stylehelper.h>
#include <QString>
#include <QLatin1String>
#include <QAction>
#include <QCheckBox>
#include <QComboBox>
#include <QDir>
#include <QDockWidget>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QDockWidget>
#include <QHBoxLayout>
#include <QComboBox>
#include <QLabel>
#include <QSpinBox>
#include <QAction>
#include <QLatin1String>
#include <QMenu>
#include <QSortFilterProxyModel>
#include <QSpinBox>
#include <QString>
#include <QToolButton>
#include <QCheckBox>
#include <utils/stylehelper.h>
using namespace Analyzer;
using namespace ProjectExplorer;
@@ -90,7 +92,23 @@ using namespace Valgrind::XmlProtocol;
namespace Valgrind {
namespace Internal {
// ---------------------------- MemcheckErrorFilterProxyModel
class FrameFinder;
class MemcheckErrorFilterProxyModel : public QSortFilterProxyModel
{
public:
MemcheckErrorFilterProxyModel(QObject *parent = 0);
public:
void setAcceptedKinds(const QList<int> &acceptedKinds);
void setFilterExternalIssues(bool filter);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
private:
QList<int> m_acceptedKinds;
bool m_filterExternalIssues;
};
MemcheckErrorFilterProxyModel::MemcheckErrorFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent),
m_filterExternalIssues(false)
@@ -178,6 +196,56 @@ static void initKindFilterAction(QAction *action, const QVariantList &kinds)
action->setData(kinds);
}
class MemcheckTool : public QObject
{
Q_DECLARE_TR_FUNCTIONS(Valgrind::Internal::MemcheckTool)
public:
MemcheckTool(QObject *parent);
QWidget *createWidgets();
MemcheckRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode);
private:
void settingsDestroyed(QObject *settings);
void maybeActiveRunConfigurationChanged();
void engineStarting(const MemcheckRunControl *engine);
void engineFinished();
void loadingExternalXmlLogFileFinished();
void parserError(const Valgrind::XmlProtocol::Error &error);
void internalParserError(const QString &errorString);
void updateErrorFilter();
void loadExternalXmlLogFile();
void setBusyCursor(bool busy);
void clearErrorView();
void updateFromSettings();
int updateUiAfterFinishedHelper();
private:
ValgrindBaseSettings *m_settings;
QMenu *m_filterMenu;
FrameFinder *m_frameFinder;
Valgrind::XmlProtocol::ErrorListModel *m_errorModel;
MemcheckErrorFilterProxyModel *m_errorProxyModel;
MemcheckErrorView *m_errorView;
QList<QAction *> m_errorFilterActions;
QAction *m_filterProjectAction;
QList<QAction *> m_suppressionActions;
QAction *m_suppressionSeparator;
QAction *m_loadExternalLogFile;
QAction *m_goBack;
QAction *m_goNext;
};
MemcheckTool::MemcheckTool(QObject *parent)
: QObject(parent)
{
@@ -216,6 +284,55 @@ MemcheckTool::MemcheckTool(QObject *parent)
a = new QAction(tr("Invalid Calls to \"free()\""), this);
initKindFilterAction(a, { InvalidFree, MismatchedFree });
m_errorFilterActions.append(a);
using namespace std::placeholders;
AnalyzerManager::registerToolbar(MemcheckPerspectiveId, createWidgets());
ActionDescription desc;
desc.setToolTip(tr("Valgrind Analyze Memory uses the "
"Memcheck tool to find memory leaks."));
if (!Utils::HostOsInfo::isWindowsHost()) {
desc.setText(tr("Valgrind Memory Analyzer"));
desc.setPerspectiveId(MemcheckPerspectiveId);
desc.setRunControlCreator(std::bind(&MemcheckTool::createRunControl, this, _1, _2));
desc.setToolMode(DebugMode);
desc.setRunMode(MEMCHECK_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
AnalyzerManager::registerAction("Memcheck.Local", desc);
desc.setText(tr("Valgrind Memory Analyzer with GDB"));
desc.setToolTip(tr("Valgrind Analyze Memory with GDB uses the "
"Memcheck tool to find memory leaks.\nWhen a problem is detected, "
"the application is interrupted and can be debugged."));
desc.setPerspectiveId(MemcheckPerspectiveId);
desc.setRunControlCreator(std::bind(&MemcheckTool::createRunControl, this, _1, _2));
desc.setToolMode(DebugMode);
desc.setRunMode(MEMCHECK_WITH_GDB_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
AnalyzerManager::registerAction("MemcheckWithGdb.Local", desc);
}
desc.setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
desc.setPerspectiveId(MemcheckPerspectiveId);
desc.setCustomToolStarter([this](ProjectExplorer::RunConfiguration *runConfig) {
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return;
ValgrindRunControl *rc = createRunControl(runConfig, MEMCHECK_RUN_MODE);
QTC_ASSERT(rc, return);
const auto runnable = dlg.runnable();
rc->setRunnable(runnable);
AnalyzerConnection connection;
connection.connParams = dlg.sshParams();
rc->setConnection(connection);
rc->setDisplayName(runnable.executable);
ProjectExplorerPlugin::startRunControl(rc, MEMCHECK_RUN_MODE);
});
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
AnalyzerManager::registerAction("Memcheck.Remote", desc);
}
void MemcheckTool::settingsDestroyed(QObject *settings)
@@ -576,5 +693,18 @@ void MemcheckTool::setBusyCursor(bool busy)
m_errorView->setCursor(cursor);
}
static MemcheckTool *theMemcheckTool;
void initMemcheckTool(QObject *parent)
{
theMemcheckTool = new MemcheckTool(parent);
}
void destroyMemcheckTool()
{
delete theMemcheckTool;
theMemcheckTool = 0;
}
} // namespace Internal
} // namespace Valgrind

View File

@@ -27,24 +27,7 @@
#ifndef MEMCHECKTOOL_H
#define MEMCHECKTOOL_H
#include <coreplugin/id.h>
#include <QSortFilterProxyModel>
QT_BEGIN_NAMESPACE
class QModelIndex;
class QAction;
class QMenu;
QT_END_NAMESPACE
namespace Valgrind {
namespace XmlProtocol {
class ErrorListModel;
class Error;
}
}
namespace ProjectExplorer { class RunConfiguration; }
#include <QObject>
namespace Valgrind {
@@ -56,80 +39,8 @@ const char MemcheckErrorDockId[] = "Memcheck.Dock.Error";
namespace Internal {
class FrameFinder;
class MemcheckErrorView;
class MemcheckRunControl;
class ValgrindBaseSettings;
class MemcheckErrorFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
MemcheckErrorFilterProxyModel(QObject *parent = 0);
public slots:
void setAcceptedKinds(const QList<int> &acceptedKinds);
void setFilterExternalIssues(bool filter);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
private:
QList<int> m_acceptedKinds;
bool m_filterExternalIssues;
};
class MemcheckTool : public QObject
{
Q_OBJECT
public:
MemcheckTool(QObject *parent);
QWidget *createWidgets();
MemcheckRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode);
private:
void settingsDestroyed(QObject *settings);
void maybeActiveRunConfigurationChanged();
void engineStarting(const MemcheckRunControl *engine);
void engineFinished();
void loadingExternalXmlLogFileFinished();
void parserError(const Valgrind::XmlProtocol::Error &error);
void internalParserError(const QString &errorString);
void updateErrorFilter();
void loadExternalXmlLogFile();
void setBusyCursor(bool busy);
void clearErrorView();
void updateFromSettings();
int updateUiAfterFinishedHelper();
private:
ValgrindBaseSettings *m_settings;
QMenu *m_filterMenu;
FrameFinder *m_frameFinder;
Valgrind::XmlProtocol::ErrorListModel *m_errorModel;
MemcheckErrorFilterProxyModel *m_errorProxyModel;
MemcheckErrorView *m_errorView;
QList<QAction *> m_errorFilterActions;
QAction *m_filterProjectAction;
QList<QAction *> m_suppressionActions;
QAction *m_suppressionSeparator;
QAction *m_loadExternalLogFile;
QAction *m_goBack;
QAction *m_goNext;
};
void initMemcheckTool(QObject *parent);
void destroyMemcheckTool();
} // namespace Internal
} // namespace Valgrind

View File

@@ -28,37 +28,20 @@
#include "callgrindtool.h"
#include "memchecktool.h"
#include "memcheckengine.h"
#include "valgrindruncontrolfactory.h"
#include "valgrindsettings.h"
#include "valgrindconfigwidget.h"
#include <debugger/analyzer/analyzericons.h>
#include <debugger/analyzer/analyzermanager.h>
#include <debugger/analyzer/analyzerruncontrol.h>
#include <debugger/analyzer/analyzerstartparameters.h>
#include <debugger/analyzer/startremotedialog.h>
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <utils/hostosinfo.h>
#include <QtPlugin>
#include <QAction>
#include <QCoreApplication>
#include <QPointer>
using namespace Analyzer;
using namespace Core;
using namespace ProjectExplorer;
@@ -108,127 +91,26 @@ ValgrindPlugin::~ValgrindPlugin()
bool ValgrindPlugin::initialize(const QStringList &, QString *)
{
theGlobalSettings = new ValgrindGlobalSettings();
theGlobalSettings = new ValgrindGlobalSettings;
theGlobalSettings->readSettings();
addAutoReleasedObject(new ValgrindOptionsPage());
addAutoReleasedObject(new ValgrindRunControlFactory());
addAutoReleasedObject(new ValgrindOptionsPage);
addAutoReleasedObject(new ValgrindRunControlFactory);
return true;
}
void ValgrindPlugin::extensionsInitialized()
{
using namespace std::placeholders;
initMemcheckTool(this);
initCallgrindTool(this);
}
QString callgrindToolTip = tr("Valgrind Function Profile uses the "
"Callgrind tool to record function calls when a program runs.");
QString memcheckToolTip = tr("Valgrind Analyze Memory uses the "
"Memcheck tool to find memory leaks.");
auto mcTool = new MemcheckTool(this);
auto cgTool = new CallgrindTool(this);
auto cgRunControlCreator = [cgTool](RunConfiguration *runConfiguration, Id) {
return cgTool->createRunControl(runConfiguration);
};
AnalyzerManager::registerToolbar(MemcheckPerspectiveId, mcTool->createWidgets());
AnalyzerManager::registerToolbar(CallgrindPerspectiveId, cgTool->createWidgets());
ActionDescription desc;
if (!Utils::HostOsInfo::isWindowsHost()) {
desc.setText(tr("Valgrind Memory Analyzer"));
desc.setToolTip(memcheckToolTip);
desc.setPerspectiveId(MemcheckPerspectiveId);
desc.setRunControlCreator([mcTool](RunConfiguration *runConfig, Id runMode) {
return mcTool->createRunControl(runConfig, runMode);
});
desc.setToolMode(DebugMode);
desc.setRunMode(MEMCHECK_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
AnalyzerManager::registerAction("Memcheck.Local", desc);
desc.setText(tr("Valgrind Memory Analyzer with GDB"));
desc.setToolTip(tr("Valgrind Analyze Memory with GDB uses the "
"Memcheck tool to find memory leaks.\nWhen a problem is detected, "
"the application is interrupted and can be debugged."));
desc.setPerspectiveId(MemcheckPerspectiveId);
desc.setRunControlCreator([mcTool](RunConfiguration *runConfig, Id runMode) {
return mcTool->createRunControl(runConfig, runMode);
});
desc.setToolMode(DebugMode);
desc.setRunMode(MEMCHECK_WITH_GDB_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
AnalyzerManager::registerAction("MemcheckWithGdb.Local", desc);
desc.setText(tr("Valgrind Function Profiler"));
desc.setToolTip(callgrindToolTip);
desc.setPerspectiveId(CallgrindPerspectiveId);
desc.setRunControlCreator(cgRunControlCreator);
desc.setToolMode(OptimizedMode);
desc.setRunMode(CALLGRIND_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
AnalyzerManager::registerAction(CallgrindLocalActionId, desc);
}
desc.setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
desc.setToolTip(memcheckToolTip);
desc.setPerspectiveId(MemcheckPerspectiveId);
desc.setCustomToolStarter([mcTool](ProjectExplorer::RunConfiguration *runConfig) {
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return;
ValgrindRunControl *rc = mcTool->createRunControl(runConfig, MEMCHECK_RUN_MODE);
QTC_ASSERT(rc, return);
const auto runnable = dlg.runnable();
rc->setRunnable(runnable);
AnalyzerConnection connection;
connection.connParams = dlg.sshParams();
rc->setConnection(connection);
rc->setDisplayName(runnable.executable);
ProjectExplorerPlugin::startRunControl(rc, MEMCHECK_RUN_MODE);
});
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
AnalyzerManager::registerAction("Memcheck.Remote", desc);
desc.setText(tr("Valgrind Function Profiler (External Remote Application)"));
desc.setToolTip(callgrindToolTip);
desc.setPerspectiveId(CallgrindPerspectiveId);
desc.setCustomToolStarter([cgTool](ProjectExplorer::RunConfiguration *runConfig) {
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return;
ValgrindRunControl *rc = cgTool->createRunControl(runConfig);
QTC_ASSERT(rc, return);
const auto runnable = dlg.runnable();
rc->setRunnable(runnable);
AnalyzerConnection connection;
connection.connParams = dlg.sshParams();
rc->setConnection(connection);
rc->setDisplayName(runnable.executable);
ProjectExplorerPlugin::startRunControl(rc, CALLGRIND_RUN_MODE);
});
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
AnalyzerManager::registerAction(CallgrindRemoteActionId, desc);
// If there is a CppEditor context menu add our own context menu actions.
if (ActionContainer *editorContextMenu =
ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT)) {
Context analyzerContext = Context(Analyzer::Constants::C_ANALYZEMODE);
editorContextMenu->addSeparator(analyzerContext);
QAction *action = new QAction(tr("Profile Costs of This Function and Its Callees"), this);
action->setIcon(Analyzer::Icons::ANALYZER_CONTROL_START.icon());
connect(action, &QAction::triggered, cgTool,
&CallgrindTool::handleShowCostsOfFunction);
Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction",
analyzerContext);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
cmd->setAttribute(Command::CA_NonConfigurable);
}
ExtensionSystem::IPlugin::ShutdownFlag ValgrindPlugin::aboutToShutdown()
{
destroyCallgrindTool();
destroyMemcheckTool();
return SynchronousShutdown;
}
ValgrindGlobalSettings *ValgrindPlugin::globalSettings()

View File

@@ -44,8 +44,9 @@ public:
ValgrindPlugin() {}
~ValgrindPlugin();
bool initialize(const QStringList &arguments, QString *errorString);
void extensionsInitialized();
bool initialize(const QStringList &arguments, QString *errorString) override;
void extensionsInitialized() override;
ShutdownFlag aboutToShutdown() override;
static ValgrindGlobalSettings *globalSettings();
};