2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2011-03-04 12:15:19 +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:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-03-04 12:15:19 +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:19 +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:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
#include "memcheckengine.h"
|
2016-01-06 11:40:52 +01:00
|
|
|
#include "memchecktool.h"
|
2015-02-06 15:31:08 +02:00
|
|
|
#include "valgrindprocess.h"
|
2011-07-12 16:47:32 +02:00
|
|
|
#include "valgrindsettings.h"
|
2015-02-06 15:31:08 +02:00
|
|
|
#include "xmlprotocol/error.h"
|
|
|
|
|
#include "xmlprotocol/status.h"
|
|
|
|
|
|
|
|
|
|
#include <debugger/debuggerkitinformation.h>
|
|
|
|
|
#include <debugger/debuggerstartparameters.h>
|
|
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2015-02-06 15:31:08 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
2013-07-30 14:08:01 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2015-02-06 15:31:08 +02:00
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <projectexplorer/toolchain.h>
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
using namespace Debugger;
|
2013-07-30 14:08:01 +02:00
|
|
|
using namespace ProjectExplorer;
|
2011-03-04 12:15:19 +01:00
|
|
|
using namespace Valgrind::XmlProtocol;
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
namespace Valgrind {
|
2011-05-18 17:05:49 +02:00
|
|
|
namespace Internal {
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2016-01-19 09:13:57 +01:00
|
|
|
MemcheckRunControl::MemcheckRunControl(RunConfiguration *runConfiguration, Core::Id runMode)
|
|
|
|
|
: ValgrindRunControl(runConfiguration, runMode)
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(&m_parser, &XmlProtocol::ThreadedParser::error,
|
|
|
|
|
this, &MemcheckRunControl::parserError);
|
|
|
|
|
connect(&m_parser, &XmlProtocol::ThreadedParser::suppressionCount,
|
|
|
|
|
this, &MemcheckRunControl::suppressionCount);
|
|
|
|
|
connect(&m_parser, &XmlProtocol::ThreadedParser::internalError,
|
|
|
|
|
this, &MemcheckRunControl::internalParserError);
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
QString MemcheckRunControl::progressTitle() const
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
|
return tr("Analyzing Memory");
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 15:31:08 +02:00
|
|
|
ValgrindRunner *MemcheckRunControl::runner()
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
|
return &m_runner;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void MemcheckRunControl::start()
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
|
m_runner.setParser(&m_parser);
|
|
|
|
|
|
2013-10-17 13:48:04 +02:00
|
|
|
appendMessage(tr("Analyzing memory of %1").arg(executable()) + QLatin1Char('\n'),
|
2011-06-10 16:34:06 +02:00
|
|
|
Utils::NormalMessageFormat);
|
2016-03-02 13:57:37 +01:00
|
|
|
ValgrindRunControl::start();
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
RunControl::StopResult MemcheckRunControl::stop()
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
2015-02-06 12:39:07 +02:00
|
|
|
disconnect(&m_parser, &ThreadedParser::internalError,
|
|
|
|
|
this, &MemcheckRunControl::internalParserError);
|
2016-03-02 13:57:37 +01:00
|
|
|
return ValgrindRunControl::stop();
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
QStringList MemcheckRunControl::toolArguments() const
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
arguments << QLatin1String("--gen-suppressions=all");
|
|
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
QTC_ASSERT(m_settings, return arguments);
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
if (m_settings->trackOrigins())
|
2011-03-04 12:15:19 +01:00
|
|
|
arguments << QLatin1String("--track-origins=yes");
|
|
|
|
|
|
2013-09-09 11:43:39 +02:00
|
|
|
if (m_settings->showReachable())
|
|
|
|
|
arguments << QLatin1String("--show-reachable=yes");
|
|
|
|
|
|
|
|
|
|
QString leakCheckValue;
|
|
|
|
|
switch (m_settings->leakCheckOnFinish()) {
|
|
|
|
|
case ValgrindBaseSettings::LeakCheckOnFinishNo:
|
|
|
|
|
leakCheckValue = QLatin1String("no");
|
|
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::LeakCheckOnFinishYes:
|
|
|
|
|
leakCheckValue = QLatin1String("full");
|
|
|
|
|
break;
|
|
|
|
|
case ValgrindBaseSettings::LeakCheckOnFinishSummaryOnly:
|
|
|
|
|
default:
|
|
|
|
|
leakCheckValue = QLatin1String("summary");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
arguments << QLatin1String("--leak-check=") + leakCheckValue;
|
|
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
foreach (const QString &file, m_settings->suppressionFiles())
|
2012-11-26 15:02:17 +02:00
|
|
|
arguments << QString::fromLatin1("--suppressions=%1").arg(file);
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
arguments << QString::fromLatin1("--num-callers=%1").arg(m_settings->numCallers());
|
2011-03-04 12:15:19 +01:00
|
|
|
return arguments;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
QStringList MemcheckRunControl::suppressionFiles() const
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
2013-08-08 17:37:37 +02:00
|
|
|
return m_settings->suppressionFiles();
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-07 17:33:58 +01:00
|
|
|
MemcheckWithGdbRunControl::MemcheckWithGdbRunControl(RunConfiguration *runConfiguration, Core::Id runMode)
|
|
|
|
|
: MemcheckRunControl(runConfiguration, runMode)
|
2015-02-06 15:31:08 +02:00
|
|
|
{
|
|
|
|
|
connect(&m_runner, &Memcheck::MemcheckRunner::started,
|
|
|
|
|
this, &MemcheckWithGdbRunControl::startDebugger);
|
|
|
|
|
connect(&m_runner, &Memcheck::MemcheckRunner::logMessageReceived,
|
|
|
|
|
this, &MemcheckWithGdbRunControl::appendLog);
|
|
|
|
|
disconnect(&m_parser, &ThreadedParser::internalError,
|
|
|
|
|
this, &MemcheckRunControl::internalParserError);
|
|
|
|
|
m_runner.disableXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList MemcheckWithGdbRunControl::toolArguments() const
|
|
|
|
|
{
|
|
|
|
|
return MemcheckRunControl::toolArguments()
|
|
|
|
|
<< QLatin1String("--vgdb=yes") << QLatin1String("--vgdb-error=0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MemcheckWithGdbRunControl::startDebugger()
|
|
|
|
|
{
|
|
|
|
|
const qint64 valgrindPid = runner()->valgrindProcess()->pid();
|
|
|
|
|
|
2015-06-26 13:06:08 +02:00
|
|
|
Debugger::DebuggerStartParameters sp;
|
2016-01-28 18:24:08 +01:00
|
|
|
sp.inferior = runnable().as<StandardRunnable>();
|
2015-02-06 15:31:08 +02:00
|
|
|
sp.startMode = Debugger::AttachToRemoteServer;
|
|
|
|
|
sp.displayName = QString::fromLatin1("VGdb %1").arg(valgrindPid);
|
|
|
|
|
sp.remoteChannel = QString::fromLatin1("| vgdb --pid=%1").arg(valgrindPid);
|
|
|
|
|
sp.useContinueInsteadOfRun = true;
|
2015-06-26 13:06:08 +02:00
|
|
|
sp.expectedSignals.append("SIGTRAP");
|
2015-02-06 15:31:08 +02:00
|
|
|
|
|
|
|
|
QString errorMessage;
|
2015-06-26 13:06:08 +02:00
|
|
|
RunControl *gdbRunControl = Debugger::createDebuggerRunControl(sp, runConfiguration(), &errorMessage);
|
2015-02-06 15:31:08 +02:00
|
|
|
QTC_ASSERT(gdbRunControl, return);
|
|
|
|
|
connect(gdbRunControl, &RunControl::finished,
|
|
|
|
|
gdbRunControl, &RunControl::deleteLater);
|
|
|
|
|
gdbRunControl->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MemcheckWithGdbRunControl::appendLog(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
appendMessage(QString::fromUtf8(data), Utils::StdOutFormat);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-18 17:05:49 +02:00
|
|
|
} // namespace Internal
|
2011-05-23 13:50:28 +02:00
|
|
|
} // namespace Valgrind
|