2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
#include "valgrindengine.h"
|
2022-07-08 16:08:27 +02:00
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
#include "valgrindsettings.h"
|
2022-07-08 16:08:27 +02:00
|
|
|
#include "valgrindtr.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
|
|
|
|
2022-05-11 12:58:30 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
|
|
|
|
#include <projectexplorer/kitinformation.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>
|
2018-05-03 18:15:49 +02:00
|
|
|
#include <projectexplorer/runconfigurationaspects.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
|
|
|
|
2022-07-08 16:08:27 +02:00
|
|
|
namespace Valgrind::Internal {
|
2013-01-10 11:36:15 +01:00
|
|
|
|
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
|
|
|
|
2019-08-27 16:44:42 +02:00
|
|
|
m_settings.fromMap(runControl->settingsData(ANALYZER_VALGRIND_SETTINGS));
|
2022-06-16 13:31:25 +02:00
|
|
|
|
2023-04-28 14:34:16 +02:00
|
|
|
connect(&m_runner,
|
|
|
|
|
&ValgrindRunner::appendMessage,
|
|
|
|
|
this,
|
|
|
|
|
[this](const QString &msg, Utils::OutputFormat format) { appendMessage(msg, format); });
|
2022-06-16 13:31:25 +02:00
|
|
|
connect(&m_runner, &ValgrindRunner::valgrindExecuted,
|
|
|
|
|
this, [this](const QString &commandLine) {
|
|
|
|
|
appendMessage(commandLine, NormalMessageFormat);
|
|
|
|
|
});
|
|
|
|
|
connect(&m_runner, &ValgrindRunner::processErrorReceived,
|
|
|
|
|
this, &ValgrindToolRunner::receiveProcessError);
|
|
|
|
|
connect(&m_runner, &ValgrindRunner::finished,
|
|
|
|
|
this, &ValgrindToolRunner::runnerFinished);
|
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);
|
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
|
2022-07-08 16:08:27 +02:00
|
|
|
emit outputReceived(Tr::tr("Valgrind options: %1").arg(toolArguments().join(' ')), LogMessageFormat);
|
|
|
|
|
emit outputReceived(Tr::tr("Working directory: %1").arg(runnable().workingDirectory), LogMessageFormat);
|
|
|
|
|
emit outputReceived(Tr::tr("Command line arguments: %1").arg(runnable().debuggeeArgs), LogMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
2022-05-11 12:58:30 +02:00
|
|
|
|
|
|
|
|
FilePath valgrindExecutable = m_settings.valgrindExecutable.filePath();
|
|
|
|
|
if (IDevice::ConstPtr dev = DeviceKitAspect::device(runControl()->kit()))
|
|
|
|
|
valgrindExecutable = dev->filePath(valgrindExecutable.path());
|
|
|
|
|
|
|
|
|
|
CommandLine valgrind{valgrindExecutable};
|
2021-02-18 14:18:34 +01:00
|
|
|
valgrind.addArgs(m_settings.valgrindArguments.value(), CommandLine::Raw);
|
2019-07-23 08:30:25 +02:00
|
|
|
valgrind.addArgs(genericToolArguments());
|
|
|
|
|
valgrind.addArgs(toolArguments());
|
|
|
|
|
|
|
|
|
|
m_runner.setValgrindCommand(valgrind);
|
2022-05-30 17:18:15 +02:00
|
|
|
m_runner.setDebuggee(runControl()->runnable());
|
2013-07-10 17:39:21 +02:00
|
|
|
|
Avoid some visible uses of RunControl::runConfiguration()
For a long time, probably from the very beginning, a RunControl
was meant to hold (a copy of) data needed for its operation, that was
valid at the time of its construction, to be resilient in cases
where RunConfiguration setting were changed while the RunControl
was running, or to properly re-run with the original settings.
Unfortunately, the task was repetitive, as RunConfiguration
classes had no generic access to properties / "aspects"
and there was was the runConfiguration() accessor (probably
for mostly unrelated reasons in the output pane handling) which
made the idea of just casting that to the original runConfiguration
and access the data directly there appealing, with all the
expected consequences.
This patch here partially addresses the issue by copying some
more of the related data at RunControl construction time and
adjust the using code, avoiding most uses of the runConfiguration()
accessor in a mostly mechanical matter.
Complete removal appears possible, but will be less mechanical
in "difficult" plugins like ios, so this is left for later.
The new accessors in RunControl are very much ad-hoc, leaving
room for improvement, e.g. by consolidating the access to the
run config settings aspects with the other runconfig aspects
or similar. For now the goal is to remove the runConfiguration()
accessor, and to as much as possible fixed data after RunControl
setup is finished.
Next step would be to officially allow construction of RunControls
without a specific RunConfiguration by setting the necessary
data independently, removing the need for the various workarounds
that are currently used for the purpose of faking (parts of) the
effect of the non-existing RunConfiguration or refusing to operate
at all, even if it would be possible.
Change-Id: If8e5596da8422c70e90f97270389adbe6d0b46f2
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2019-03-11 15:42:43 +01:00
|
|
|
if (auto aspect = runControl()->aspect<TerminalAspect>())
|
2022-04-08 11:35:54 +02:00
|
|
|
m_runner.setUseTerminal(aspect->useTerminal);
|
2018-05-03 18:15:49 +02: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
|
|
|
QStringList ValgrindToolRunner::genericToolArguments() const
|
2013-09-06 16:33:48 +02:00
|
|
|
{
|
|
|
|
|
QString smcCheckValue;
|
2019-08-27 16:44:42 +02:00
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
switch (m_settings.selfModifyingCodeDetection.value()) {
|
2013-09-06 16:33:48 +02:00
|
|
|
case ValgrindBaseSettings::DetectSmcNo:
|
2018-12-01 20:56:21 +02:00
|
|
|
smcCheckValue = "none";
|
2013-09-06 16:33:48 +02:00
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::DetectSmcEverywhere:
|
2018-12-01 20:56:21 +02:00
|
|
|
smcCheckValue = "all";
|
2013-09-06 16:33:48 +02:00
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::DetectSmcEverywhereButFile:
|
2018-12-01 20:56:21 +02:00
|
|
|
smcCheckValue = "all-non-file";
|
2013-09-06 16:33:48 +02:00
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::DetectSmcStackOnly:
|
|
|
|
|
default:
|
2018-12-01 20:56:21 +02:00
|
|
|
smcCheckValue = "stack";
|
2013-09-06 16:33:48 +02:00
|
|
|
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
|
|
|
{
|
2020-06-02 09:10:40 +02:00
|
|
|
QApplication::alert(ICore::dialogParent(), 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
|
|
|
{
|
2022-07-08 16:08:27 +02:00
|
|
|
appendMessage(Tr::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-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::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) {
|
2021-02-18 14:18:34 +01:00
|
|
|
const QString valgrind = m_settings.valgrindExecutable.value();
|
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())
|
2022-07-08 16:08:27 +02:00
|
|
|
appendMessage(Tr::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
|
2022-07-08 16:08:27 +02:00
|
|
|
appendMessage(Tr::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
|
2022-07-08 16:08:27 +02:00
|
|
|
appendMessage(Tr::tr("Process terminated."), ErrorMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
} else {
|
2022-07-08 16:08:27 +02:00
|
|
|
appendMessage(Tr::tr("Process exited with return value %1\n").arg(message), NormalMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_isStopping)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-12-01 20:56:21 +02:00
|
|
|
QObject *obj = ExtensionSystem::PluginManager::getObjectByName("AppOutputPane");
|
2018-12-10 08:11:18 +01:00
|
|
|
if (auto pane = qobject_cast<IOutputPane *>(obj))
|
2013-01-10 11:36:15 +01:00
|
|
|
pane->popup(IOutputPane::NoModeSwitch);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
2013-01-10 11:36:15 +01:00
|
|
|
|
2022-07-08 16:08:27 +02:00
|
|
|
} // Valgrid::Internal
|