Valgrind: Reshuffle plugin setup

Straighter code.

Change-Id: Iab8b85dd1442bbdcd0b2db0052de927f4463aeb1
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
This commit is contained in:
hjk
2015-06-17 17:12:36 +02:00
parent 716f43f357
commit 9ba80c699c
2 changed files with 23 additions and 43 deletions

View File

@@ -62,6 +62,7 @@
#include <QPointer> #include <QPointer>
using namespace Analyzer; using namespace Analyzer;
using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace Valgrind { namespace Valgrind {
@@ -69,7 +70,7 @@ namespace Internal {
static ValgrindGlobalSettings *theGlobalSettings = 0; static ValgrindGlobalSettings *theGlobalSettings = 0;
class ValgrindOptionsPage : public Core::IOptionsPage class ValgrindOptionsPage : public IOptionsPage
{ {
public: public:
explicit ValgrindOptionsPage() explicit ValgrindOptionsPage()
@@ -132,11 +133,13 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
theGlobalSettings->readSettings(); theGlobalSettings->readSettings();
addAutoReleasedObject(new ValgrindOptionsPage()); addAutoReleasedObject(new ValgrindOptionsPage());
addAutoReleasedObject(new ValgrindRunControlFactory());
m_memcheckTool = new MemcheckTool(this); return true;
m_memcheckWithGdbTool = new MemcheckWithGdbTool(this); }
m_callgrindTool = new CallgrindTool(this);
void ValgrindPlugin::extensionsInitialized()
{
AnalyzerAction *action = 0; AnalyzerAction *action = 0;
QString callgrindToolTip = tr("Valgrind Function Profile uses the " QString callgrindToolTip = tr("Valgrind Function Profile uses the "
@@ -145,25 +148,14 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
QString memcheckToolTip = tr("Valgrind Analyze Memory uses the " QString memcheckToolTip = tr("Valgrind Analyze Memory uses the "
"Memcheck tool to find memory leaks."); "Memcheck tool to find memory leaks.");
QString memcheckWithGdbToolTip = tr( auto mcTool = new MemcheckTool(this);
"Valgrind Analyze Memory with GDB uses the Memcheck tool to find memory leaks.\n"
"When a problem is detected, the application is interrupted and can be debugged.");
MemcheckTool *mcTool = m_memcheckTool;
auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); }; auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); };
auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp, auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) { ProjectExplorer::RunConfiguration *runConfiguration) {
return mcTool->createRunControl(sp, runConfiguration); return mcTool->createRunControl(sp, runConfiguration);
}; };
MemcheckWithGdbTool *mcgTool = m_memcheckWithGdbTool; auto cgTool = new CallgrindTool(this);
auto mcgWidgetCreator = [mcgTool] { return mcgTool->createWidgets(); };
auto mcgRunControlCreator = [mcgTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) {
return mcgTool->createRunControl(sp, runConfiguration);
};
CallgrindTool *cgTool = m_callgrindTool;
auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); }; auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); };
auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp, auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) { ProjectExplorer::RunConfiguration *runConfiguration) {
@@ -184,15 +176,20 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setEnabled(false); action->setEnabled(false);
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
using namespace std::placeholders;
auto mcgTool = new MemcheckWithGdbTool(this);
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setActionId("MemcheckWithGdb.Local"); action->setActionId("MemcheckWithGdb.Local");
action->setToolId("MemcheckWithGdb"); action->setToolId("MemcheckWithGdb");
action->setWidgetCreator(mcgWidgetCreator); action->setWidgetCreator([mcgTool] { return mcgTool->createWidgets(); });
action->setRunControlCreator(mcgRunControlCreator); action->setRunControlCreator(std::bind(&MemcheckWithGdbTool::createRunControl,
mcgTool, _1, _2));
action->setToolMode(DebugMode); action->setToolMode(DebugMode);
action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode); action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode);
action->setText(tr("Valgrind Memory Analyzer with GDB")); action->setText(tr("Valgrind Memory Analyzer with GDB"));
action->setToolTip(memcheckWithGdbToolTip); action->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."));
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS); action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
action->setEnabled(false); action->setEnabled(false);
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
@@ -237,20 +234,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
action->setUseSpecialStart(); action->setUseSpecialStart();
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
addAutoReleasedObject(new ValgrindRunControlFactory());
return true;
}
ValgrindGlobalSettings *ValgrindPlugin::globalSettings()
{
return theGlobalSettings;
}
void ValgrindPlugin::extensionsInitialized()
{
using namespace Core;
// If there is a CppEditor context menu add our own context menu actions. // If there is a CppEditor context menu add our own context menu actions.
if (ActionContainer *editorContextMenu = if (ActionContainer *editorContextMenu =
ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT)) { ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT)) {
@@ -259,7 +242,7 @@ void ValgrindPlugin::extensionsInitialized()
QAction *action = new QAction(tr("Profile Costs of This Function and Its Callees"), this); QAction *action = new QAction(tr("Profile Costs of This Function and Its Callees"), this);
action->setIcon(QIcon(QLatin1String(Analyzer::Constants::ANALYZER_CONTROL_START_ICON))); action->setIcon(QIcon(QLatin1String(Analyzer::Constants::ANALYZER_CONTROL_START_ICON)));
connect(action, &QAction::triggered, m_callgrindTool, connect(action, &QAction::triggered, cgTool,
&CallgrindTool::handleShowCostsOfFunction); &CallgrindTool::handleShowCostsOfFunction);
Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction", Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction",
analyzerContext); analyzerContext);
@@ -269,5 +252,10 @@ void ValgrindPlugin::extensionsInitialized()
} }
} }
ValgrindGlobalSettings *ValgrindPlugin::globalSettings()
{
return theGlobalSettings;
}
} // namespace Internal } // namespace Internal
} // namespace Valgrind } // namespace Valgrind

View File

@@ -39,9 +39,6 @@ namespace Valgrind {
namespace Internal { namespace Internal {
class ValgrindGlobalSettings; class ValgrindGlobalSettings;
class MemcheckTool;
class MemcheckWithGdbTool;
class CallgrindTool;
class ValgrindPlugin : public ExtensionSystem::IPlugin class ValgrindPlugin : public ExtensionSystem::IPlugin
{ {
@@ -56,11 +53,6 @@ public:
void extensionsInitialized(); void extensionsInitialized();
static ValgrindGlobalSettings *globalSettings(); static ValgrindGlobalSettings *globalSettings();
private:
MemcheckTool *m_memcheckTool;
MemcheckWithGdbTool *m_memcheckWithGdbTool;
CallgrindTool *m_callgrindTool;
}; };
} // namespace Internal } // namespace Internal