2011-03-04 12:15:18 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-03-04 12:15:18 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-03-04 12:15:18 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
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>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
|
#include <QtGui/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-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)
|
|
|
|
|
m_settings = runConfiguration->extraAspect<AnalyzerProjectSettings>();
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindEngine::start()
|
|
|
|
|
{
|
|
|
|
|
emit starting(this);
|
|
|
|
|
|
2011-04-04 14:39:28 +02:00
|
|
|
Core::FutureProgress *fp = Core::ICore::instance()->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-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-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-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)));
|
2011-03-04 12:15:18 +01:00
|
|
|
connect(runner(), SIGNAL(processErrorReceived(QString, QProcess::ProcessError)),
|
|
|
|
|
SLOT(receiveProcessError(QString, QProcess::ProcessError)));
|
|
|
|
|
connect(runner(), SIGNAL(finished()),
|
|
|
|
|
SLOT(runnerFinished()));
|
|
|
|
|
|
2011-04-04 14:39:28 +02:00
|
|
|
if (sp.startMode == StartRemote)
|
|
|
|
|
runner()->startRemotely(sp.connParams);
|
|
|
|
|
else
|
|
|
|
|
runner()->start();
|
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();
|
2011-05-11 16:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindEngine::handleProgressFinished()
|
|
|
|
|
{
|
|
|
|
|
QApplication::alert(Core::ICore::instance()->mainWindow(), 3000);
|
|
|
|
|
}
|
|
|
|
|
|
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-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
|
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
2011-05-20 09:12:34 +02:00
|
|
|
QList<Core::IOutputPane *> panes = pm->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")) {
|
|
|
|
|
pane->popup(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|