2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-03-04 12:15:19 +01:00
|
|
|
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-03-04 12:15:19 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
#include "valgrindplugin.h"
|
2011-07-04 10:50:44 +02:00
|
|
|
|
|
|
|
|
#include "callgrindtool.h"
|
|
|
|
|
#include "memchecktool.h"
|
2013-07-19 16:08:54 +02:00
|
|
|
#include "valgrindruncontrolfactory.h"
|
2013-08-08 11:55:54 +02:00
|
|
|
#include "valgrindsettings.h"
|
2013-08-12 17:04:10 +02:00
|
|
|
#include "valgrindconfigwidget.h"
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
#include <analyzerbase/analyzermanager.h>
|
2013-08-05 18:00:36 +02:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
#include <coreplugin/dialogs/ioptionspage.h>
|
2013-08-08 11:55:54 +02:00
|
|
|
#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>
|
2013-08-08 17:37:37 +02:00
|
|
|
|
2013-08-08 11:55:54 +02:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
2013-08-05 18:00:36 +02:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
2013-08-08 17:37:37 +02:00
|
|
|
#include <QCoreApplication>
|
2013-12-03 14:17:03 +01:00
|
|
|
#include <QPointer>
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
using namespace Analyzer;
|
2011-07-04 10:50:44 +02:00
|
|
|
|
|
|
|
|
namespace Valgrind {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
static ValgrindGlobalSettings *theGlobalSettings = 0;
|
|
|
|
|
|
|
|
|
|
class ValgrindOptionsPage : public Core::IOptionsPage
|
2013-08-08 11:25:28 +02:00
|
|
|
{
|
2013-08-08 17:37:37 +02:00
|
|
|
public:
|
|
|
|
|
explicit ValgrindOptionsPage()
|
2013-08-08 11:25:28 +02:00
|
|
|
{
|
2013-08-08 17:37:37 +02:00
|
|
|
setId(ANALYZER_VALGRIND_SETTINGS);
|
2013-08-23 16:25:16 +02:00
|
|
|
setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindOptionsPage", "Valgrind"));
|
2013-08-08 17:37:37 +02:00
|
|
|
setCategory("T.Analyzer");
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("Analyzer", "Analyzer"));
|
|
|
|
|
setCategoryIcon(QLatin1String(":/images/analyzer_category.png"));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *widget()
|
|
|
|
|
{
|
|
|
|
|
if (!m_widget)
|
|
|
|
|
m_widget = new ValgrindConfigWidget(theGlobalSettings, 0, true);
|
|
|
|
|
return m_widget;
|
2013-08-08 17:37:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
void apply()
|
|
|
|
|
{
|
2013-08-08 17:37:37 +02:00
|
|
|
theGlobalSettings->writeSettings();
|
2013-08-08 11:25:28 +02:00
|
|
|
}
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
void finish()
|
|
|
|
|
{
|
|
|
|
|
delete m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QPointer<QWidget> m_widget;
|
2013-08-08 11:25:28 +02:00
|
|
|
};
|
|
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
ValgrindPlugin::~ValgrindPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete theGlobalSettings;
|
|
|
|
|
theGlobalSettings = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
bool ValgrindPlugin::initialize(const QStringList &, QString *)
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
2013-08-08 17:37:37 +02:00
|
|
|
theGlobalSettings = new ValgrindGlobalSettings();
|
|
|
|
|
theGlobalSettings->readSettings();
|
|
|
|
|
|
|
|
|
|
addAutoReleasedObject(new ValgrindOptionsPage());
|
2013-08-05 18:00:36 +02:00
|
|
|
|
2013-08-08 11:55:54 +02:00
|
|
|
m_memcheckTool = new MemcheckTool(this);
|
2015-02-06 15:31:08 +02:00
|
|
|
m_memcheckWithGdbTool = new MemcheckWithGdbTool(this);
|
2013-08-08 11:55:54 +02:00
|
|
|
m_callgrindTool = new CallgrindTool(this);
|
|
|
|
|
|
2015-02-18 09:34:50 +01:00
|
|
|
AnalyzerAction *action = 0;
|
2013-08-07 19:47:30 +02:00
|
|
|
|
|
|
|
|
QString callgrindToolTip = tr("Valgrind Function Profile uses the "
|
2015-03-16 11:49:31 +01:00
|
|
|
"Callgrind tool to record function calls when a program runs.");
|
2013-08-07 19:47:30 +02:00
|
|
|
|
|
|
|
|
QString memcheckToolTip = tr("Valgrind Analyze Memory uses the "
|
2015-03-16 11:49:31 +01:00
|
|
|
"Memcheck tool to find memory leaks.");
|
2013-08-07 19:47:30 +02:00
|
|
|
|
2015-02-06 15:31:08 +02:00
|
|
|
QString memcheckWithGdbToolTip = tr(
|
2015-03-16 11:49:31 +01:00
|
|
|
"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.");
|
2015-02-06 15:31:08 +02:00
|
|
|
|
2015-02-18 14:35:20 +01:00
|
|
|
MemcheckTool *mcTool = m_memcheckTool;
|
|
|
|
|
auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); };
|
|
|
|
|
auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp,
|
|
|
|
|
ProjectExplorer::RunConfiguration *runConfiguration) {
|
|
|
|
|
return mcTool->createRunControl(sp, runConfiguration);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MemcheckWithGdbTool *mcgTool = m_memcheckWithGdbTool;
|
|
|
|
|
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 cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp,
|
|
|
|
|
ProjectExplorer::RunConfiguration *runConfiguration) {
|
|
|
|
|
return cgTool->createRunControl(sp, runConfiguration);
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-05 18:18:34 +02:00
|
|
|
if (!Utils::HostOsInfo::isWindowsHost()) {
|
2015-02-18 09:34:50 +01:00
|
|
|
action = new AnalyzerAction(this);
|
2015-02-18 14:35:20 +01:00
|
|
|
action->setActionId("Memcheck.Local");
|
|
|
|
|
action->setToolId("Memcheck");
|
|
|
|
|
action->setWidgetCreator(mcWidgetCreator);
|
|
|
|
|
action->setRunControlCreator(mcRunControlCreator);
|
2015-02-18 18:51:29 +01:00
|
|
|
action->setToolStarter([mcTool] { mcTool->startLocalTool(); });
|
2015-02-18 11:05:22 +01:00
|
|
|
action->setRunMode(ProjectExplorer::MemcheckRunMode);
|
2013-08-07 19:47:30 +02:00
|
|
|
action->setText(tr("Valgrind Memory Analyzer"));
|
|
|
|
|
action->setToolTip(memcheckToolTip);
|
|
|
|
|
action->setMenuGroup(Constants::G_ANALYZER_TOOLS);
|
|
|
|
|
action->setStartMode(StartLocal);
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
AnalyzerManager::addAction(action);
|
|
|
|
|
|
2015-02-18 09:34:50 +01:00
|
|
|
action = new AnalyzerAction(this);
|
2015-02-18 14:35:20 +01:00
|
|
|
action->setActionId("MemcheckWithGdb.Local");
|
|
|
|
|
action->setToolId("MemcheckWithGdb");
|
|
|
|
|
action->setWidgetCreator(mcgWidgetCreator);
|
|
|
|
|
action->setRunControlCreator(mcgRunControlCreator);
|
2015-02-18 18:51:29 +01:00
|
|
|
action->setToolStarter([mcgTool] { mcgTool->startLocalTool(); });
|
2015-02-18 11:05:22 +01:00
|
|
|
action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode);
|
2015-02-06 15:31:08 +02:00
|
|
|
action->setText(tr("Valgrind Memory Analyzer with GDB"));
|
|
|
|
|
action->setToolTip(memcheckWithGdbToolTip);
|
|
|
|
|
action->setMenuGroup(Constants::G_ANALYZER_TOOLS);
|
|
|
|
|
action->setStartMode(StartLocal);
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
AnalyzerManager::addAction(action);
|
|
|
|
|
|
2015-02-18 09:34:50 +01:00
|
|
|
action = new AnalyzerAction(this);
|
2015-02-18 16:43:01 +01:00
|
|
|
action->setActionId(CallgrindLocalActionId);
|
2015-02-18 14:35:20 +01:00
|
|
|
action->setToolId(CallgrindToolId);
|
|
|
|
|
action->setWidgetCreator(cgWidgetCreator);
|
|
|
|
|
action->setRunControlCreator(cgRunControlCreator);
|
2015-02-18 18:51:29 +01:00
|
|
|
action->setToolStarter([cgTool] { cgTool->startLocalTool(); });
|
2015-02-18 11:05:22 +01:00
|
|
|
action->setRunMode(ProjectExplorer::CallgrindRunMode);
|
2013-08-07 19:47:30 +02:00
|
|
|
action->setText(tr("Valgrind Function Profiler"));
|
|
|
|
|
action->setToolTip(callgrindToolTip);
|
|
|
|
|
action->setMenuGroup(Constants::G_ANALYZER_TOOLS);
|
|
|
|
|
action->setStartMode(StartLocal);
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
AnalyzerManager::addAction(action);
|
2013-08-05 18:18:34 +02:00
|
|
|
}
|
2013-08-07 19:47:30 +02:00
|
|
|
|
2015-02-18 09:34:50 +01:00
|
|
|
action = new AnalyzerAction(this);
|
2015-02-18 14:35:20 +01:00
|
|
|
action->setActionId("Memcheck.Remote");
|
|
|
|
|
action->setToolId("Memcheck");
|
|
|
|
|
action->setWidgetCreator(mcWidgetCreator);
|
|
|
|
|
action->setRunControlCreator(mcRunControlCreator);
|
2015-02-18 18:51:29 +01:00
|
|
|
action->setToolStarter([mcTool] { mcTool->startRemoteTool(); });
|
2015-02-18 11:05:22 +01:00
|
|
|
action->setRunMode(ProjectExplorer::MemcheckRunMode);
|
2014-04-25 15:09:22 +02:00
|
|
|
action->setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
|
2013-08-07 19:47:30 +02:00
|
|
|
action->setToolTip(memcheckToolTip);
|
|
|
|
|
action->setMenuGroup(Constants::G_ANALYZER_REMOTE_TOOLS);
|
|
|
|
|
action->setStartMode(StartRemote);
|
|
|
|
|
AnalyzerManager::addAction(action);
|
|
|
|
|
|
2015-02-18 09:34:50 +01:00
|
|
|
action = new AnalyzerAction(this);
|
2015-02-18 16:43:01 +01:00
|
|
|
action->setActionId(CallgrindRemoteActionId);
|
2015-02-18 14:35:20 +01:00
|
|
|
action->setToolId(CallgrindToolId);
|
|
|
|
|
action->setWidgetCreator(cgWidgetCreator);
|
|
|
|
|
action->setRunControlCreator(cgRunControlCreator);
|
2015-02-18 18:51:29 +01:00
|
|
|
action->setToolStarter([cgTool] { cgTool->startRemoteTool(); });
|
2015-02-18 11:05:22 +01:00
|
|
|
action->setRunMode(ProjectExplorer::CallgrindRunMode);
|
2014-04-25 15:09:22 +02:00
|
|
|
action->setText(tr("Valgrind Function Profiler (External Remote Application)"));
|
2013-08-07 19:47:30 +02:00
|
|
|
action->setToolTip(callgrindToolTip);
|
|
|
|
|
action->setMenuGroup(Constants::G_ANALYZER_REMOTE_TOOLS);
|
|
|
|
|
action->setStartMode(StartRemote);
|
|
|
|
|
AnalyzerManager::addAction(action);
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2013-07-19 16:08:54 +02:00
|
|
|
addAutoReleasedObject(new ValgrindRunControlFactory());
|
|
|
|
|
|
2011-06-30 13:44:22 +02:00
|
|
|
return true;
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
ValgrindGlobalSettings *ValgrindPlugin::globalSettings()
|
|
|
|
|
{
|
|
|
|
|
return theGlobalSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 11:55:54 +02:00
|
|
|
void ValgrindPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
using namespace Core;
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
2013-10-09 17:25:21 +02:00
|
|
|
QAction *action = new QAction(tr("Profile Costs of This Function and Its Callees"), this);
|
2013-08-08 11:55:54 +02:00
|
|
|
action->setIcon(QIcon(QLatin1String(Analyzer::Constants::ANALYZER_CONTROL_START_ICON)));
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(action, &QAction::triggered, m_callgrindTool,
|
|
|
|
|
&CallgrindTool::handleShowCostsOfFunction);
|
2013-08-08 11:55:54 +02:00
|
|
|
Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction",
|
|
|
|
|
analyzerContext);
|
|
|
|
|
editorContextMenu->addAction(cmd);
|
|
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
|
|
|
|
cmd->setAttribute(Command::CA_NonConfigurable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-04 10:50:44 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Valgrind
|
|
|
|
|
|