2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2011-03-04 12:15:19 +01:00
|
|
|
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
|
2016-01-15 14:57:40 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
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"
|
2015-06-19 08:34:46 +02:00
|
|
|
#include "memcheckengine.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
|
|
|
|
2015-11-23 16:41:54 +01:00
|
|
|
#include <analyzerbase/analyzericons.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
#include <analyzerbase/analyzermanager.h>
|
2015-06-18 09:35:41 +02:00
|
|
|
#include <analyzerbase/analyzerruncontrol.h>
|
|
|
|
|
#include <analyzerbase/analyzerstartparameters.h>
|
|
|
|
|
#include <analyzerbase/startremotedialog.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
|
|
|
|
2015-06-18 09:35:41 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
|
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;
|
2015-06-17 17:12:36 +02:00
|
|
|
using namespace Core;
|
2015-06-18 09:35:41 +02:00
|
|
|
using namespace ProjectExplorer;
|
2011-07-04 10:50:44 +02:00
|
|
|
|
|
|
|
|
namespace Valgrind {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
static ValgrindGlobalSettings *theGlobalSettings = 0;
|
|
|
|
|
|
2015-06-17 17:12:36 +02:00
|
|
|
class ValgrindOptionsPage : public 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());
|
2015-06-17 17:12:36 +02:00
|
|
|
addAutoReleasedObject(new ValgrindRunControlFactory());
|
2013-08-05 18:00:36 +02:00
|
|
|
|
2015-06-17 17:12:36 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2013-08-08 11:55:54 +02:00
|
|
|
|
2015-06-17 17:12:36 +02:00
|
|
|
void ValgrindPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2016-01-06 11:40:52 +01:00
|
|
|
using namespace std::placeholders;
|
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-06-17 17:12:36 +02:00
|
|
|
auto mcTool = new MemcheckTool(this);
|
2015-02-18 14:35:20 +01:00
|
|
|
auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); };
|
2015-06-17 17:12:36 +02:00
|
|
|
auto cgTool = new CallgrindTool(this);
|
2015-02-18 14:35:20 +01:00
|
|
|
auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); };
|
|
|
|
|
auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp,
|
2016-01-06 11:40:52 +01:00
|
|
|
RunConfiguration *runConfiguration, Core::Id) {
|
2015-02-18 14:35:20 +01:00
|
|
|
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);
|
2016-01-06 11:40:52 +01:00
|
|
|
action->setRunControlCreator(std::bind(&MemcheckTool::createRunControl,
|
|
|
|
|
mcTool, _1, _2, MEMCHECK_RUN_MODE));
|
|
|
|
|
action->setToolMode(DebugMode);
|
2015-06-29 10:36:29 +03:00
|
|
|
action->setRunMode(MEMCHECK_RUN_MODE);
|
2013-08-07 19:47:30 +02:00
|
|
|
action->setText(tr("Valgrind Memory Analyzer"));
|
|
|
|
|
action->setToolTip(memcheckToolTip);
|
2015-06-18 09:35:41 +02:00
|
|
|
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
|
2013-08-07 19:47:30 +02:00
|
|
|
action->setEnabled(false);
|
|
|
|
|
AnalyzerManager::addAction(action);
|
|
|
|
|
|
2016-01-06 11:40:52 +01:00
|
|
|
auto mcgTool = new MemcheckTool(this);
|
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");
|
2015-06-17 17:12:36 +02:00
|
|
|
action->setWidgetCreator([mcgTool] { return mcgTool->createWidgets(); });
|
2016-01-06 11:40:52 +01:00
|
|
|
action->setRunControlCreator(std::bind(&MemcheckTool::createRunControl,
|
|
|
|
|
mcgTool, _1, _2, MEMCHECK_WITH_GDB_RUN_MODE));
|
|
|
|
|
action->setToolMode(DebugMode);
|
2015-06-29 10:36:29 +03:00
|
|
|
action->setRunMode(MEMCHECK_WITH_GDB_RUN_MODE);
|
2015-02-06 15:31:08 +02:00
|
|
|
action->setText(tr("Valgrind Memory Analyzer with GDB"));
|
2015-06-17 17:12:36 +02:00
|
|
|
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."));
|
2015-06-18 09:35:41 +02:00
|
|
|
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
|
2015-02-06 15:31:08 +02:00
|
|
|
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-20 15:10:56 +01:00
|
|
|
action->setToolMode(OptimizedMode);
|
2015-06-29 10:36:29 +03:00
|
|
|
action->setRunMode(CALLGRIND_RUN_MODE);
|
2013-08-07 19:47:30 +02:00
|
|
|
action->setText(tr("Valgrind Function Profiler"));
|
|
|
|
|
action->setToolTip(callgrindToolTip);
|
2015-06-18 09:35:41 +02:00
|
|
|
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
|
2013-08-07 19:47:30 +02:00
|
|
|
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);
|
2015-06-19 08:34:46 +02:00
|
|
|
action->setCustomToolStarter([mcTool] {
|
2016-01-06 11:40:52 +01:00
|
|
|
StartRemoteDialog dlg;
|
|
|
|
|
if (dlg.exec() != QDialog::Accepted)
|
2015-06-19 08:34:46 +02:00
|
|
|
return;
|
2016-01-06 11:40:52 +01:00
|
|
|
AnalyzerStartParameters sp;
|
|
|
|
|
sp.connParams = dlg.sshParams();
|
|
|
|
|
sp.debuggee = dlg.executable();
|
|
|
|
|
sp.debuggeeArgs = dlg.arguments();
|
|
|
|
|
ValgrindRunControl *rc = mcTool->createRunControl(sp, 0, MEMCHECK_RUN_MODE);
|
2015-06-19 08:34:46 +02:00
|
|
|
QTC_ASSERT(rc, return);
|
2016-01-06 11:40:52 +01:00
|
|
|
rc->setDisplayName(dlg.executable());
|
|
|
|
|
rc->setWorkingDirectory(dlg.workingDirectory());
|
2015-06-19 08:34:46 +02:00
|
|
|
rc->setCustomStart();
|
2015-06-29 10:36:29 +03:00
|
|
|
ProjectExplorerPlugin::startRunControl(rc, MEMCHECK_RUN_MODE);
|
2015-06-19 08:34:46 +02:00
|
|
|
});
|
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);
|
2015-06-18 09:35:41 +02:00
|
|
|
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
|
2013-08-07 19:47:30 +02:00
|
|
|
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);
|
2015-06-19 08:34:46 +02:00
|
|
|
action->setCustomToolStarter([cgTool] {
|
2016-01-06 11:40:52 +01:00
|
|
|
StartRemoteDialog dlg;
|
|
|
|
|
if (dlg.exec() != QDialog::Accepted)
|
2015-06-19 08:34:46 +02:00
|
|
|
return;
|
2016-01-06 11:40:52 +01:00
|
|
|
AnalyzerStartParameters sp;
|
|
|
|
|
sp.connParams = dlg.sshParams();
|
|
|
|
|
sp.debuggee = dlg.executable();
|
|
|
|
|
sp.debuggeeArgs = dlg.arguments();
|
2015-06-19 08:34:46 +02:00
|
|
|
ValgrindRunControl *rc = cgTool->createRunControl(sp, 0);
|
|
|
|
|
QTC_ASSERT(rc, return);
|
2016-01-06 11:40:52 +01:00
|
|
|
rc->setDisplayName(dlg.executable());
|
|
|
|
|
rc->setWorkingDirectory(dlg.workingDirectory());
|
2015-06-19 08:34:46 +02:00
|
|
|
rc->setCustomStart();
|
2015-06-29 10:36:29 +03:00
|
|
|
ProjectExplorerPlugin::startRunControl(rc, CALLGRIND_RUN_MODE);
|
2015-06-19 08:34:46 +02:00
|
|
|
});
|
|
|
|
|
|
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);
|
2015-06-18 09:35:41 +02:00
|
|
|
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
|
2013-08-07 19:47:30 +02:00
|
|
|
AnalyzerManager::addAction(action);
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2013-08-08 11:55:54 +02:00
|
|
|
// 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);
|
2015-11-23 16:41:54 +01:00
|
|
|
action->setIcon(Analyzer::Icons::ANALYZER_CONTROL_START.icon());
|
2015-06-17 17:12:36 +02:00
|
|
|
connect(action, &QAction::triggered, cgTool,
|
2015-01-30 11:02:24 +01:00
|
|
|
&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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-17 17:12:36 +02:00
|
|
|
ValgrindGlobalSettings *ValgrindPlugin::globalSettings()
|
|
|
|
|
{
|
|
|
|
|
return theGlobalSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-04 10:50:44 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Valgrind
|