Files
qt-creator/src/plugins/debugger/debuggerrunner.cpp

229 lines
7.4 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 15:08:31 +01:00
2008-12-02 12:01:29 +01:00
#include "debuggerrunner.h"
2009-11-09 16:25:24 +01:00
#include <projectexplorer/debugginghelper.h>
2008-12-02 12:01:29 +01:00
#include <projectexplorer/environment.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/buildconfiguration.h>
2008-12-02 12:01:29 +01:00
2008-12-09 15:25:01 +01:00
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
2008-12-09 15:25:01 +01:00
2008-12-02 12:01:29 +01:00
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
2008-12-09 15:25:01 +01:00
#include <QtGui/QTextDocument>
2008-12-02 12:01:29 +01:00
2009-09-11 08:55:16 +02:00
namespace Debugger {
namespace Internal {
2008-12-02 12:01:29 +01:00
using ProjectExplorer::RunConfiguration;
using ProjectExplorer::RunControl;
using ProjectExplorer::LocalApplicationRunConfiguration;
2008-12-02 12:01:29 +01:00
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControlFactory
2008-12-02 12:01:29 +01:00
//
////////////////////////////////////////////////////////////////////////
// A factory to create DebuggerRunControls
DebuggerRunControlFactory::DebuggerRunControlFactory(DebuggerManager *manager)
: m_manager(manager)
2008-12-02 12:01:29 +01:00
{}
bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
2008-12-02 12:01:29 +01:00
{
return mode == ProjectExplorer::Constants::DEBUGMODE
&& qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
2008-12-02 12:01:29 +01:00
}
QString DebuggerRunControlFactory::displayName() const
2008-12-02 12:01:29 +01:00
{
2009-02-27 20:06:08 +01:00
return tr("Debug");
2008-12-02 12:01:29 +01:00
}
RunControl *DebuggerRunControlFactory::create(const DebuggerStartParametersPtr &sp)
{
return new DebuggerRunControl(m_manager, sp);
}
RunControl *DebuggerRunControlFactory::create(RunConfiguration *runConfiguration,
const QString &mode)
2008-12-02 12:01:29 +01:00
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(mode == ProjectExplorer::Constants::DEBUGMODE, return 0);
LocalApplicationRunConfiguration *rc = qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
QTC_ASSERT(rc, return 0);
return new DebuggerRunControl(m_manager, rc);
2008-12-02 12:01:29 +01:00
}
QWidget *DebuggerRunControlFactory::configurationWidget(RunConfiguration *runConfiguration)
2008-12-02 12:01:29 +01:00
{
// NBS TODO: Add GDB-specific configuration widget
Q_UNUSED(runConfiguration)
2008-12-02 12:01:29 +01:00
return 0;
}
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControl
//
////////////////////////////////////////////////////////////////////////
DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager,
LocalApplicationRunConfiguration *runConfiguration)
2009-09-11 08:55:16 +02:00
: RunControl(runConfiguration),
m_startParameters(new DebuggerStartParameters()),
m_manager(manager),
m_running(false)
2008-12-02 12:01:29 +01:00
{
init();
2009-09-11 08:55:16 +02:00
if (!runConfiguration)
return;
m_startParameters->startMode = StartInternal;
m_startParameters->executable = runConfiguration->executable();
m_startParameters->environment = runConfiguration->environment().toStringList();
m_startParameters->workingDir = runConfiguration->workingDirectory();
m_startParameters->processArgs = runConfiguration->commandLineArguments();
2009-09-11 08:55:16 +02:00
switch (m_startParameters->toolChainType) {
case ProjectExplorer::ToolChain::UNKNOWN:
case ProjectExplorer::ToolChain::INVALID:
m_startParameters->toolChainType = runConfiguration->toolChainType();
break;
default:
break;
}
if (runConfiguration->target()->project()) {
m_startParameters->buildDir =
runConfiguration->target()->activeBuildConfiguration()->buildDirectory();
}
2009-09-11 08:55:16 +02:00
m_startParameters->useTerminal =
runConfiguration->runMode() == LocalApplicationRunConfiguration::Console;
m_startParameters->dumperLibrary =
runConfiguration->dumperLibrary();
m_startParameters->dumperLibraryLocations =
runConfiguration->dumperLibraryLocations();
2009-11-09 16:25:24 +01:00
QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(
runConfiguration->environment());
if (!qmakePath.isEmpty()) {
QProcess proc;
QStringList args;
args.append(QLatin1String("-query"));
args.append(QLatin1String("QT_INSTALL_HEADERS"));
proc.start(qmakePath, args);
proc.waitForFinished();
QByteArray ba = proc.readAllStandardOutput().trimmed();
QFileInfo fi(QString::fromLocal8Bit(ba) + "/..");
m_startParameters->qtInstallPath = fi.absoluteFilePath();
}
}
DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager, const DebuggerStartParametersPtr &startParameters)
: RunControl(0),
m_startParameters(startParameters),
m_manager(manager),
m_running(false)
{
init();
if (m_startParameters->environment.empty())
m_startParameters->environment = ProjectExplorer::Environment::Environment().toStringList();
m_startParameters->useTerminal = false;
}
void DebuggerRunControl::init()
{
connect(m_manager, SIGNAL(debuggingFinished()),
this, SLOT(debuggingFinished()),
Qt::QueuedConnection);
connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
this, SLOT(slotAddToOutputWindowInline(QString)),
Qt::QueuedConnection);
connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
this, SLOT(bringApplicationToForeground(qint64)),
Qt::QueuedConnection);
connect(this, SIGNAL(stopRequested()),
m_manager, SLOT(exitDebugger()));
}
void DebuggerRunControl::start()
{
m_running = true;
QString errorMessage;
QString settingsCategory;
QString settingsPage;
if (m_manager->checkDebugConfiguration(startParameters()->toolChainType, &errorMessage,
&settingsCategory, &settingsPage)) {
m_manager->startNewDebugger(m_startParameters);
} else {
error(this, errorMessage);
emit finished();
Core::ICore::instance()->showWarningWithOptions(tr("Debugger"), errorMessage,
QString(),
settingsCategory, settingsPage);
}
2008-12-02 12:01:29 +01:00
}
void DebuggerRunControl::slotAddToOutputWindowInline(const QString &data)
{
emit addToOutputWindowInline(this, data);
2008-12-02 12:01:29 +01:00
}
void DebuggerRunControl::stop()
{
2009-02-16 13:29:57 +01:00
m_running = false;
emit stopRequested();
2008-12-02 12:01:29 +01:00
}
void DebuggerRunControl::debuggingFinished()
{
m_running = false;
emit finished();
}
bool DebuggerRunControl::isRunning() const
{
return m_running;
}
2009-09-11 08:55:16 +02:00
} // namespace Internal
} // namespace Debugger