2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2011-03-04 12:15:18 +01:00
|
|
|
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
|
2016-01-15 14:57:40 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-03-04 12:15:18 +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:18 +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:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
#include "valgrindengine.h"
|
|
|
|
|
#include "valgrindsettings.h"
|
2013-08-08 17:37:37 +02:00
|
|
|
#include "valgrindplugin.h"
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2016-02-24 14:42:52 +01:00
|
|
|
#include <debugger/analyzer/analyzermanager.h>
|
2016-01-28 18:24:08 +01:00
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/ioutputpane.h>
|
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2011-03-04 16:00:02 +01:00
|
|
|
#include <coreplugin/progressmanager/futureprogress.h>
|
2011-03-04 12:15:18 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2016-05-30 16:56:46 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
2013-08-08 17:37:37 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2011-05-11 16:26:34 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
#define VALGRIND_DEBUG_OUTPUT 0
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
using namespace Debugger;
|
2013-01-10 11:36:15 +01:00
|
|
|
using namespace Core;
|
2011-03-04 12:15:18 +01:00
|
|
|
using namespace Utils;
|
2013-08-08 17:37:37 +02:00
|
|
|
using namespace ProjectExplorer;
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2013-01-10 11:36:15 +01:00
|
|
|
namespace Valgrind {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
ValgrindToolRunner::ValgrindToolRunner(RunControl *runControl)
|
2017-05-09 10:25:11 +02:00
|
|
|
: RunWorker(runControl)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2017-04-27 17:23:28 +02:00
|
|
|
runControl->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL_TOOLBAR);
|
2017-07-05 15:17:38 +02:00
|
|
|
setSupportsReRunning(false);
|
2015-06-19 08:34:46 +02:00
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
if (IRunConfigurationAspect *aspect = runControl->runConfiguration()->extraAspect(ANALYZER_VALGRIND_SETTINGS))
|
|
|
|
|
m_settings = qobject_cast<ValgrindBaseSettings *>(aspect->currentSettings());
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
if (!m_settings)
|
|
|
|
|
m_settings = ValgrindPlugin::globalSettings();
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void ValgrindToolRunner::start()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2014-05-05 14:23:37 +02:00
|
|
|
FutureProgress *fp = ProgressManager::addTimedTask(m_progress, progressTitle(), "valgrind", 100);
|
2013-01-10 11:36:15 +01:00
|
|
|
fp->setKeepOnFinish(FutureProgress::HideOnFinish);
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(fp, &FutureProgress::canceled,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &ValgrindToolRunner::handleProgressCanceled);
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(fp, &FutureProgress::finished,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &ValgrindToolRunner::handleProgressFinished);
|
2014-05-30 14:25:58 +02:00
|
|
|
m_progress.reportStarted();
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
#if VALGRIND_DEBUG_OUTPUT
|
2014-08-29 14:00:18 +02:00
|
|
|
emit outputReceived(tr("Valgrind options: %1").arg(toolArguments().join(QLatin1Char(' '))), DebugFormat);
|
2016-01-18 17:49:29 +01:00
|
|
|
emit outputReceived(tr("Working directory: %1").arg(runnable().workingDirectory), DebugFormat);
|
|
|
|
|
emit outputReceived(tr("Command line arguments: %1").arg(runnable().debuggeeArgs), DebugFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
2017-06-21 09:15:33 +02:00
|
|
|
m_runner.setValgrindExecutable(m_settings->valgrindExecutable());
|
|
|
|
|
m_runner.setValgrindArguments(genericToolArguments() + toolArguments());
|
|
|
|
|
m_runner.setDevice(device());
|
|
|
|
|
QTC_ASSERT(runnable().is<StandardRunnable>(), reportFailure());
|
|
|
|
|
m_runner.setDebuggee(runnable().as<StandardRunnable>());
|
2013-07-10 17:39:21 +02:00
|
|
|
|
2017-06-21 09:15:33 +02:00
|
|
|
connect(&m_runner, &ValgrindRunner::processOutputReceived,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &ValgrindToolRunner::receiveProcessOutput);
|
2018-01-24 15:09:50 +02:00
|
|
|
connect(&m_runner, &ValgrindRunner::valgrindExecuted,
|
|
|
|
|
this, [this](const QString &commandLine) {
|
|
|
|
|
appendMessage(commandLine, NormalMessageFormat);
|
|
|
|
|
});
|
2017-06-21 09:15:33 +02:00
|
|
|
connect(&m_runner, &ValgrindRunner::processErrorReceived,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &ValgrindToolRunner::receiveProcessError);
|
2017-06-21 09:15:33 +02:00
|
|
|
connect(&m_runner, &ValgrindRunner::finished,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &ValgrindToolRunner::runnerFinished);
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2017-06-21 09:15:33 +02:00
|
|
|
if (!m_runner.start()) {
|
2014-05-30 14:25:58 +02:00
|
|
|
m_progress.cancel();
|
2017-04-27 17:23:28 +02:00
|
|
|
reportFailure();
|
2016-03-02 13:57:37 +01:00
|
|
|
return;
|
2012-01-20 14:19:44 +01:00
|
|
|
}
|
2017-04-27 17:23:28 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
reportStarted();
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void ValgrindToolRunner::stop()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
m_isStopping = true;
|
2017-06-21 09:15:33 +02:00
|
|
|
m_runner.stop();
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
QString ValgrindToolRunner::executable() const
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2017-06-21 09:15:33 +02:00
|
|
|
QTC_ASSERT(runnable().is<StandardRunnable>(), return QString());
|
|
|
|
|
return runnable().as<StandardRunnable>().executable;
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
QStringList ValgrindToolRunner::genericToolArguments() const
|
2013-09-06 16:33:48 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_settings, return QStringList());
|
|
|
|
|
QString smcCheckValue;
|
|
|
|
|
switch (m_settings->selfModifyingCodeDetection()) {
|
|
|
|
|
case ValgrindBaseSettings::DetectSmcNo:
|
|
|
|
|
smcCheckValue = QLatin1String("none");
|
|
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::DetectSmcEverywhere:
|
|
|
|
|
smcCheckValue = QLatin1String("all");
|
|
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::DetectSmcEverywhereButFile:
|
|
|
|
|
smcCheckValue = QLatin1String("all-non-file");
|
|
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::DetectSmcStackOnly:
|
|
|
|
|
default:
|
|
|
|
|
smcCheckValue = QLatin1String("stack");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-06-21 09:15:33 +02:00
|
|
|
return {"--smc-check=" + smcCheckValue};
|
2013-09-06 16:33:48 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void ValgrindToolRunner::handleProgressCanceled()
|
2011-05-11 16:26:34 +02:00
|
|
|
{
|
2014-05-30 14:25:58 +02:00
|
|
|
m_progress.reportCanceled();
|
|
|
|
|
m_progress.reportFinished();
|
2011-05-11 16:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void ValgrindToolRunner::handleProgressFinished()
|
2011-05-11 16:26:34 +02:00
|
|
|
{
|
2013-01-10 11:36:15 +01:00
|
|
|
QApplication::alert(ICore::mainWindow(), 3000);
|
2011-05-11 16:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void ValgrindToolRunner::runnerFinished()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2017-06-21 09:15:33 +02:00
|
|
|
appendMessage(tr("Analyzing finished."), NormalMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2014-05-30 14:25:58 +02:00
|
|
|
m_progress.reportFinished();
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2017-06-21 09:15:33 +02:00
|
|
|
disconnect(&m_runner, &ValgrindRunner::processOutputReceived,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &ValgrindToolRunner::receiveProcessOutput);
|
2017-06-21 09:15:33 +02:00
|
|
|
disconnect(&m_runner, &ValgrindRunner::finished,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &ValgrindToolRunner::runnerFinished);
|
|
|
|
|
|
2017-05-16 07:53:03 +02:00
|
|
|
reportStopped();
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void ValgrindToolRunner::receiveProcessOutput(const QString &output, OutputFormat format)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2014-05-04 23:06:26 +03:00
|
|
|
appendMessage(output, format);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void ValgrindToolRunner::receiveProcessError(const QString &message, QProcess::ProcessError error)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2013-01-10 11:36:15 +01:00
|
|
|
if (error == QProcess::FailedToStart) {
|
2013-08-08 17:37:37 +02:00
|
|
|
const QString valgrind = m_settings->valgrindExecutable();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!valgrind.isEmpty())
|
2017-06-21 09:15:33 +02:00
|
|
|
appendMessage(tr("Error: \"%1\" could not be started: %2").arg(valgrind, message), ErrorMessageFormat);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2017-06-21 09:15:33 +02:00
|
|
|
appendMessage(tr("Error: no Valgrind executable set."), ErrorMessageFormat);
|
2013-01-10 11:36:15 +01:00
|
|
|
} else if (m_isStopping && error == QProcess::Crashed) { // process gets killed on stop
|
2017-06-21 09:15:33 +02:00
|
|
|
appendMessage(tr("Process terminated."), ErrorMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
} else {
|
2017-02-06 17:57:25 +01:00
|
|
|
appendMessage(tr("Process exited with return value %1\n").arg(message), NormalMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_isStopping)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-01-10 11:36:15 +01:00
|
|
|
QObject *obj = ExtensionSystem::PluginManager::getObjectByName(QLatin1String("AppOutputPane"));
|
|
|
|
|
if (IOutputPane *pane = qobject_cast<IOutputPane *>(obj))
|
|
|
|
|
pane->popup(IOutputPane::NoModeSwitch);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
2013-01-10 11:36:15 +01:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namepsace Valgrind
|