2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-03-04 12:15:18 +01:00
|
|
|
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
|
|
|
|
|
**
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-03-04 12:15:18 +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
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-03-04 12:15:18 +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:18 +01:00
|
|
|
|
|
|
|
|
#include "valgrindengine.h"
|
|
|
|
|
#include "valgrindsettings.h"
|
|
|
|
|
|
|
|
|
|
#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>
|
2013-01-28 12:56:56 +01:00
|
|
|
#include <projectexplorer/localapplicationrunconfiguration.h>
|
2011-05-11 16:26:34 +02:00
|
|
|
#include <analyzerbase/analyzermanager.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QMainWindow>
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
#define VALGRIND_DEBUG_OUTPUT 0
|
|
|
|
|
|
|
|
|
|
using namespace Analyzer;
|
2013-01-10 11:36:15 +01:00
|
|
|
using namespace Core;
|
2011-03-04 12:15:18 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2013-01-10 11:36:15 +01:00
|
|
|
namespace Valgrind {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2011-10-31 18:01:37 +01:00
|
|
|
const int progressMaximum = 1000000;
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
ValgrindRunControl::ValgrindRunControl(const AnalyzerStartParameters &sp,
|
2011-06-30 13:44:22 +02:00
|
|
|
ProjectExplorer::RunConfiguration *runConfiguration)
|
2013-07-30 14:08:01 +02:00
|
|
|
: AnalyzerRunControl(sp, runConfiguration),
|
2011-03-04 12:15:18 +01:00
|
|
|
m_settings(0),
|
2011-05-11 16:26:34 +02:00
|
|
|
m_progress(new QFutureInterface<void>()),
|
|
|
|
|
m_progressWatcher(new QFutureWatcher<void>()),
|
2011-03-04 12:15:18 +01:00
|
|
|
m_isStopping(false)
|
|
|
|
|
{
|
2011-04-04 14:39:28 +02:00
|
|
|
if (runConfiguration)
|
2012-02-23 14:41:28 +01:00
|
|
|
m_settings = runConfiguration->extraAspect<AnalyzerRunConfigurationAspect>();
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2011-04-04 14:39:28 +02:00
|
|
|
if (!m_settings)
|
|
|
|
|
m_settings = AnalyzerGlobalSettings::instance();
|
2011-05-11 16:26:34 +02:00
|
|
|
|
|
|
|
|
connect(m_progressWatcher, SIGNAL(canceled()),
|
|
|
|
|
this, SLOT(handleProgressCanceled()));
|
|
|
|
|
connect(m_progressWatcher, SIGNAL(finished()),
|
|
|
|
|
this, SLOT(handleProgressFinished()));
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
ValgrindRunControl::~ValgrindRunControl()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
delete m_progress;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
bool ValgrindRunControl::startEngine()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
emit starting(this);
|
|
|
|
|
|
2013-01-10 11:36:15 +01:00
|
|
|
FutureProgress *fp = ICore::progressManager()->addTask(m_progress->future(),
|
2012-11-26 15:02:17 +02:00
|
|
|
progressTitle(), QLatin1String("valgrind"));
|
2013-01-10 11:36:15 +01:00
|
|
|
fp->setKeepOnFinish(FutureProgress::HideOnFinish);
|
2011-10-31 18:01:37 +01:00
|
|
|
m_progress->setProgressRange(0, progressMaximum);
|
2011-03-04 12:15:18 +01:00
|
|
|
m_progress->reportStarted();
|
2011-05-11 16:26:34 +02:00
|
|
|
m_progressWatcher->setFuture(m_progress->future());
|
2011-10-31 18:01:37 +01:00
|
|
|
m_progress->setProgressValue(progressMaximum / 10);
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2013-01-10 11:07:58 +01:00
|
|
|
const AnalyzerStartParameters &sp = startParameters();
|
2011-03-04 12:15:18 +01:00
|
|
|
#if VALGRIND_DEBUG_OUTPUT
|
2013-01-10 11:36:15 +01:00
|
|
|
emit outputReceived(tr("Valgrind options: %1").arg(toolArguments().join(QLatin1Char(' '))), DebugFormat);
|
|
|
|
|
emit outputReceived(tr("Working directory: %1").arg(sp.workingDirectory), DebugFormat);
|
|
|
|
|
emit outputReceived(tr("Commandline arguments: %1").arg(sp.debuggeeArgs), DebugFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
2013-07-10 17:39:21 +02:00
|
|
|
ValgrindRunner *run = runner();
|
|
|
|
|
run->setWorkingDirectory(sp.workingDirectory);
|
2011-07-12 16:47:32 +02:00
|
|
|
QString valgrindExe = m_settings->subConfig<ValgrindBaseSettings>()->valgrindExecutable();
|
2011-04-04 14:39:28 +02:00
|
|
|
if (!sp.analyzerCmdPrefix.isEmpty())
|
2012-11-26 15:02:17 +02:00
|
|
|
valgrindExe = sp.analyzerCmdPrefix + QLatin1Char(' ') + valgrindExe;
|
2013-07-10 17:39:21 +02:00
|
|
|
run->setValgrindExecutable(valgrindExe);
|
|
|
|
|
run->setValgrindArguments(toolArguments());
|
|
|
|
|
run->setDebuggeeExecutable(sp.debuggee);
|
|
|
|
|
run->setDebuggeeArguments(sp.debuggeeArgs);
|
|
|
|
|
run->setEnvironment(sp.environment);
|
|
|
|
|
run->setConnectionParameters(sp.connParams);
|
|
|
|
|
run->setStartMode(sp.startMode);
|
|
|
|
|
|
|
|
|
|
connect(run, SIGNAL(processOutputReceived(QByteArray,Utils::OutputFormat)),
|
2011-06-10 16:34:06 +02:00
|
|
|
SLOT(receiveProcessOutput(QByteArray,Utils::OutputFormat)));
|
2013-07-10 17:39:21 +02:00
|
|
|
connect(run, SIGNAL(processErrorReceived(QString,QProcess::ProcessError)),
|
2012-03-05 22:30:59 +01:00
|
|
|
SLOT(receiveProcessError(QString,QProcess::ProcessError)));
|
2013-07-10 17:39:21 +02:00
|
|
|
connect(run, SIGNAL(finished()), SLOT(runnerFinished()));
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2013-07-10 17:39:21 +02:00
|
|
|
if (!run->start()) {
|
2012-01-20 14:19:44 +01:00
|
|
|
m_progress->cancel();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-25 14:49:07 +02:00
|
|
|
return true;
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
void ValgrindRunControl::stopEngine()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
m_isStopping = true;
|
|
|
|
|
runner()->stop();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
QString ValgrindRunControl::executable() const
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2011-04-04 14:39:28 +02:00
|
|
|
return startParameters().debuggee;
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
void ValgrindRunControl::handleProgressCanceled()
|
2011-05-11 16:26:34 +02:00
|
|
|
{
|
2011-07-04 10:50:44 +02:00
|
|
|
AnalyzerManager::stopTool();
|
2012-01-23 10:57:39 +01:00
|
|
|
m_progress->reportCanceled();
|
|
|
|
|
m_progress->reportFinished();
|
2011-05-11 16:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
void ValgrindRunControl::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
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
void ValgrindRunControl::runnerFinished()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2013-07-30 14:08:01 +02:00
|
|
|
appendMessage(tr("** Analyzing finished **\n"), NormalMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
emit finished();
|
|
|
|
|
|
|
|
|
|
m_progress->reportFinished();
|
|
|
|
|
|
2011-06-10 16:34:06 +02:00
|
|
|
disconnect(runner(), SIGNAL(processOutputReceived(QByteArray,Utils::OutputFormat)),
|
|
|
|
|
this, SLOT(receiveProcessOutput(QByteArray,Utils::OutputFormat)));
|
2011-03-04 12:15:18 +01:00
|
|
|
disconnect(runner(), SIGNAL(finished()),
|
|
|
|
|
this, SLOT(runnerFinished()));
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
void ValgrindRunControl::receiveProcessOutput(const QByteArray &output, OutputFormat format)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2011-10-31 18:01:37 +01:00
|
|
|
int progress = m_progress->progressValue();
|
|
|
|
|
if (progress < 5 * progressMaximum / 10)
|
|
|
|
|
progress += progress / 100;
|
|
|
|
|
else if (progress < 9 * progressMaximum / 10)
|
|
|
|
|
progress += progress / 1000;
|
|
|
|
|
m_progress->setProgressValue(progress);
|
2013-07-30 14:08:01 +02:00
|
|
|
appendMessage(QString::fromLocal8Bit(output), format);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
void ValgrindRunControl::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) {
|
2011-07-12 16:47:32 +02:00
|
|
|
const QString &valgrind = m_settings->subConfig<ValgrindBaseSettings>()->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())
|
2013-07-30 14:08:01 +02:00
|
|
|
appendMessage(tr("** Error: \"%1\" could not be started: %2 **\n").arg(valgrind).arg(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
|
2013-07-30 14:08:01 +02:00
|
|
|
appendMessage(tr("** Error: no valgrind executable set **\n"), ErrorMessageFormat);
|
2013-01-10 11:36:15 +01:00
|
|
|
} else if (m_isStopping && error == QProcess::Crashed) { // process gets killed on stop
|
2013-07-30 14:08:01 +02:00
|
|
|
appendMessage(tr("** Process Terminated **\n"), ErrorMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
} else {
|
2013-07-30 14:08:01 +02:00
|
|
|
appendMessage(QString::fromLatin1("** %1 **\n").arg(message), ErrorMessageFormat);
|
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
|