2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** 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>
|
|
|
|
|
#include <projectexplorer/applicationrunconfiguration.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;
|
2011-04-04 14:39:28 +02:00
|
|
|
using namespace Valgrind::Internal;
|
2011-03-04 12:15:18 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2011-10-31 18:01:37 +01:00
|
|
|
const int progressMaximum = 1000000;
|
|
|
|
|
|
2011-06-30 13:44:22 +02:00
|
|
|
ValgrindEngine::ValgrindEngine(IAnalyzerTool *tool, const AnalyzerStartParameters &sp,
|
|
|
|
|
ProjectExplorer::RunConfiguration *runConfiguration)
|
|
|
|
|
: IAnalyzerEngine(tool, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValgrindEngine::~ValgrindEngine()
|
|
|
|
|
{
|
|
|
|
|
delete m_progress;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-25 14:49:07 +02:00
|
|
|
bool ValgrindEngine::start()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
emit starting(this);
|
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::FutureProgress *fp = Core::ICore::progressManager()->addTask(m_progress->future(),
|
2011-03-04 12:15:18 +01:00
|
|
|
progressTitle(), "valgrind");
|
2011-06-24 16:00:47 +02:00
|
|
|
fp->setKeepOnFinish(Core::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
|
|
|
|
|
|
|
|
#if VALGRIND_DEBUG_OUTPUT
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(tr("Valgrind options: %1").arg(toolArguments().join(" ")), Utils::DebugFormat);
|
|
|
|
|
emit outputReceived(tr("Working directory: %1").arg(m_workingDirectory), Utils::DebugFormat);
|
|
|
|
|
emit outputReceived(tr("Command-line arguments: %1").arg(m_commandLineArguments), Utils::DebugFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
2011-04-04 14:39:28 +02:00
|
|
|
const AnalyzerStartParameters &sp = startParameters();
|
|
|
|
|
runner()->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())
|
|
|
|
|
valgrindExe = sp.analyzerCmdPrefix + ' ' + valgrindExe;
|
|
|
|
|
runner()->setValgrindExecutable(valgrindExe);
|
2011-03-04 12:15:18 +01:00
|
|
|
runner()->setValgrindArguments(toolArguments());
|
2011-04-04 14:39:28 +02:00
|
|
|
runner()->setDebuggeeExecutable(sp.debuggee);
|
|
|
|
|
runner()->setDebuggeeArguments(sp.debuggeeArgs);
|
|
|
|
|
runner()->setEnvironment(sp.environment);
|
2011-10-20 16:07:50 +02:00
|
|
|
runner()->setConnectionParameters(sp.connParams);
|
|
|
|
|
runner()->setStartMode(sp.startMode);
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2011-06-10 16:34:06 +02:00
|
|
|
connect(runner(), SIGNAL(processOutputReceived(QByteArray,Utils::OutputFormat)),
|
|
|
|
|
SLOT(receiveProcessOutput(QByteArray,Utils::OutputFormat)));
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(runner(), SIGNAL(processErrorReceived(QString,QProcess::ProcessError)),
|
|
|
|
|
SLOT(receiveProcessError(QString,QProcess::ProcessError)));
|
2011-03-04 12:15:18 +01:00
|
|
|
connect(runner(), SIGNAL(finished()),
|
|
|
|
|
SLOT(runnerFinished()));
|
|
|
|
|
|
2012-01-20 14:19:44 +01:00
|
|
|
if (!runner()->start()) {
|
|
|
|
|
m_progress->cancel();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-25 14:49:07 +02:00
|
|
|
return true;
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindEngine::stop()
|
|
|
|
|
{
|
|
|
|
|
m_isStopping = true;
|
|
|
|
|
runner()->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ValgrindEngine::executable() const
|
|
|
|
|
{
|
2011-04-04 14:39:28 +02:00
|
|
|
return startParameters().debuggee;
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 16:26:34 +02:00
|
|
|
void ValgrindEngine::handleProgressCanceled()
|
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindEngine::handleProgressFinished()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QApplication::alert(Core::ICore::mainWindow(), 3000);
|
2011-05-11 16:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
void ValgrindEngine::runnerFinished()
|
|
|
|
|
{
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(tr("** Analyzing finished **\n"), Utils::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()));
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-10 16:34:06 +02:00
|
|
|
void ValgrindEngine::receiveProcessOutput(const QByteArray &b, Utils::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);
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(QString::fromLocal8Bit(b), format);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindEngine::receiveProcessError(const QString &error, QProcess::ProcessError e)
|
|
|
|
|
{
|
|
|
|
|
if (e == QProcess::FailedToStart) {
|
2011-07-12 16:47:32 +02:00
|
|
|
const QString &valgrind = m_settings->subConfig<ValgrindBaseSettings>()->valgrindExecutable();
|
2011-03-04 12:15:18 +01:00
|
|
|
if (!valgrind.isEmpty()) {
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(tr("** Error: \"%1\" could not be started: %2 **\n").arg(valgrind).arg(error), Utils::ErrorMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
} else {
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(tr("** Error: no valgrind executable set **\n"), Utils::ErrorMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
} else if (m_isStopping && e == QProcess::Crashed) { // process gets killed on stop
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(tr("** Process Terminated **\n"), Utils::ErrorMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
} else {
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(QString("** %1 **\n").arg(error), Utils::ErrorMessageFormat);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_isStopping)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
///FIXME: get a better API for this into Qt Creator
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<Core::IOutputPane *> panes = ExtensionSystem::PluginManager::getObjects<Core::IOutputPane>();
|
2011-05-11 16:26:34 +02:00
|
|
|
foreach (Core::IOutputPane *pane, panes) {
|
2011-03-04 12:15:18 +01:00
|
|
|
if (pane->displayName() == tr("Application Output")) {
|
2012-09-13 15:50:06 +02:00
|
|
|
pane->popup(Core::IOutputPane::NoModeSwitch);
|
2011-03-04 12:15:18 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|