2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "debuggerrunner.h"
|
|
|
|
|
|
|
|
#include "debuggermanager.h"
|
|
|
|
|
|
|
|
#include <projectexplorer/applicationrunconfiguration.h>
|
|
|
|
#include <projectexplorer/environment.h>
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
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
|
|
|
|
2008-12-03 10:55:18 +01:00
|
|
|
#include <QtGui/QTextDocument>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
using namespace Debugger::Internal;
|
|
|
|
|
|
|
|
using ProjectExplorer::RunConfiguration;
|
|
|
|
using ProjectExplorer::RunControl;
|
|
|
|
using ProjectExplorer::ApplicationRunConfiguration;
|
|
|
|
|
2009-07-28 09:10:35 +02:00
|
|
|
// A default run configuration for external executables or attaching to
|
|
|
|
// running processes by id.
|
|
|
|
class DefaultApplicationRunConfiguration : public ProjectExplorer::ApplicationRunConfiguration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit DefaultApplicationRunConfiguration(const QString &executable = QString());
|
|
|
|
|
|
|
|
virtual QString executable() const { return m_executable; }
|
|
|
|
virtual RunMode runMode() const { return Gui; }
|
|
|
|
virtual QString workingDirectory() const { return QString(); }
|
|
|
|
virtual QStringList commandLineArguments() const { return QStringList(); }
|
|
|
|
virtual ProjectExplorer::Environment environment() const
|
|
|
|
{ return ProjectExplorer::Environment(); }
|
|
|
|
virtual QString dumperLibrary() const { return QString(); }
|
|
|
|
virtual QStringList dumperLibraryLocations() const { return QStringList(); }
|
|
|
|
virtual ProjectExplorer::ToolChain::ToolChainType toolChainType() const
|
|
|
|
{ return ProjectExplorer::ToolChain::UNKNOWN; }
|
|
|
|
virtual QWidget *configurationWidget() { return 0; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const QString m_executable;
|
|
|
|
};
|
|
|
|
|
|
|
|
DefaultApplicationRunConfiguration::DefaultApplicationRunConfiguration(const QString &executable) :
|
|
|
|
ProjectExplorer::ApplicationRunConfiguration(0),
|
|
|
|
m_executable(executable)
|
|
|
|
{
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DebuggerRunner
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-05-05 17:48:54 +02:00
|
|
|
// A factory to create DebuggerRunControls
|
2009-06-30 13:19:17 +02:00
|
|
|
DebuggerRunner::DebuggerRunner(DebuggerManager *manager)
|
|
|
|
: m_manager(manager)
|
2008-12-02 12:01:29 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool DebuggerRunner::canRun(RunConfigurationPtr runConfiguration, const QString &mode)
|
|
|
|
{
|
2009-05-25 16:22:11 +02:00
|
|
|
return mode == ProjectExplorer::Constants::DEBUGMODE
|
2009-06-15 19:08:59 +02:00
|
|
|
&& !runConfiguration.dynamicCast<ApplicationRunConfiguration>().isNull();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString DebuggerRunner::displayName() const
|
|
|
|
{
|
2009-02-27 20:06:08 +01:00
|
|
|
return tr("Debug");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2009-07-28 09:10:35 +02:00
|
|
|
RunConfigurationPtr DebuggerRunner::createDefaultRunConfiguration(const QString &executable)
|
|
|
|
{
|
|
|
|
return RunConfigurationPtr(new DefaultApplicationRunConfiguration(executable));
|
|
|
|
}
|
|
|
|
|
2009-06-30 13:19:17 +02:00
|
|
|
RunControl *DebuggerRunner::run(RunConfigurationPtr runConfiguration,
|
2009-05-25 16:22:11 +02:00
|
|
|
const QString &mode,
|
|
|
|
const QSharedPointer<DebuggerStartParameters> &sp,
|
|
|
|
DebuggerStartMode startMode)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(mode == ProjectExplorer::Constants::DEBUGMODE, return 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
ApplicationRunConfigurationPtr rc =
|
2009-06-15 19:08:59 +02:00
|
|
|
runConfiguration.dynamicCast<ApplicationRunConfiguration>();
|
2009-06-30 13:19:17 +02:00
|
|
|
QTC_ASSERT(!rc.isNull(), return 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
//qDebug() << "***** Debugging" << rc->name() << rc->executable();
|
2009-05-25 16:22:11 +02:00
|
|
|
DebuggerRunControl *runControl = new DebuggerRunControl(m_manager, startMode, sp, rc);
|
2009-05-05 17:48:54 +02:00
|
|
|
return runControl;
|
|
|
|
}
|
|
|
|
|
2009-06-30 13:19:17 +02:00
|
|
|
RunControl *DebuggerRunner::run(RunConfigurationPtr runConfiguration,
|
2009-05-05 17:48:54 +02:00
|
|
|
const QString &mode)
|
|
|
|
{
|
2009-05-25 16:22:11 +02:00
|
|
|
const QSharedPointer<DebuggerStartParameters> sp(new DebuggerStartParameters);
|
|
|
|
return run(runConfiguration, mode, sp, StartInternal);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *DebuggerRunner::configurationWidget(RunConfigurationPtr runConfiguration)
|
|
|
|
{
|
|
|
|
// NBS TODO: Add GDB-specific configuration widget
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(runConfiguration)
|
2008-12-02 12:01:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DebuggerRunControl
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager,
|
2009-05-25 16:22:11 +02:00
|
|
|
DebuggerStartMode mode,
|
|
|
|
const QSharedPointer<DebuggerStartParameters> &startParameters,
|
|
|
|
QSharedPointer<ApplicationRunConfiguration> runConfiguration) :
|
|
|
|
RunControl(runConfiguration),
|
|
|
|
m_mode(mode),
|
|
|
|
m_startParameters(startParameters),
|
|
|
|
m_manager(manager),
|
|
|
|
m_running(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
connect(m_manager, SIGNAL(debuggingFinished()),
|
2009-02-13 13:50:50 +01:00
|
|
|
this, SLOT(debuggingFinished()),
|
|
|
|
Qt::QueuedConnection);
|
2009-01-15 14:30:49 +01:00
|
|
|
connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
|
2009-02-13 13:50:50 +01:00
|
|
|
this, SLOT(slotAddToOutputWindowInline(QString)),
|
|
|
|
Qt::QueuedConnection);
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
|
2009-02-13 13:50:50 +01:00
|
|
|
this, SLOT(bringApplicationToForeground(qint64)),
|
|
|
|
Qt::QueuedConnection);
|
2009-02-16 13:29:57 +01:00
|
|
|
connect(this, SIGNAL(stopRequested()),
|
|
|
|
m_manager, SLOT(exitDebugger()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::start()
|
|
|
|
{
|
|
|
|
m_running = true;
|
|
|
|
ApplicationRunConfigurationPtr rc =
|
2009-06-15 19:08:59 +02:00
|
|
|
runConfiguration().dynamicCast<ApplicationRunConfiguration>();
|
2009-05-05 17:48:54 +02:00
|
|
|
if (rc) {
|
2009-05-25 16:22:11 +02:00
|
|
|
// Enhance parameters by info from the project, but do not clobber
|
|
|
|
// arguments given in the dialogs
|
|
|
|
if (m_startParameters->executable.isEmpty())
|
|
|
|
m_startParameters->executable = rc->executable();
|
|
|
|
if (m_startParameters->environment.empty())
|
|
|
|
m_startParameters->environment = rc->environment().toStringList();
|
|
|
|
if (m_startParameters->workingDir.isEmpty())
|
|
|
|
m_startParameters->workingDir = rc->workingDirectory();
|
|
|
|
if (m_mode != StartExternal)
|
|
|
|
m_startParameters->processArgs = rc->commandLineArguments();
|
2009-06-22 12:59:27 +02:00
|
|
|
switch (m_startParameters->toolChainType) {
|
|
|
|
case ProjectExplorer::ToolChain::UNKNOWN:
|
|
|
|
case ProjectExplorer::ToolChain::INVALID:
|
|
|
|
m_startParameters->toolChainType = rc->toolChainType();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-05-25 16:22:11 +02:00
|
|
|
m_manager->setQtDumperLibraryName(rc->dumperLibrary());
|
2009-07-15 17:41:45 +02:00
|
|
|
m_manager->setQtDumperLibraryLocations(rc->dumperLibraryLocations());
|
2009-05-25 16:22:11 +02:00
|
|
|
if (const ProjectExplorer::Project *project = rc->project()) {
|
|
|
|
m_startParameters->buildDir = project->buildDirectory(project->activeBuildConfiguration());
|
2009-05-05 17:48:54 +02:00
|
|
|
}
|
2009-05-25 16:22:11 +02:00
|
|
|
m_startParameters->useTerminal = rc->runMode() == ApplicationRunConfiguration::Console;
|
2009-05-05 17:48:54 +02:00
|
|
|
}
|
2009-02-20 12:33:16 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
//emit addToOutputWindow(this, tr("Debugging %1").arg(m_executable));
|
2009-05-25 16:22:11 +02:00
|
|
|
m_manager->startNewDebugger(this, m_startParameters);
|
2009-05-05 17:48:54 +02:00
|
|
|
emit started();
|
|
|
|
//debuggingFinished();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2009-01-15 14:30:49 +01:00
|
|
|
void DebuggerRunControl::slotAddToOutputWindowInline(const QString &data)
|
2009-05-25 16:22:11 +02:00
|
|
|
{
|
2009-01-15 14:30:49 +01:00
|
|
|
emit addToOutputWindowInline(this, data);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::stop()
|
|
|
|
{
|
2009-02-16 13:29:57 +01:00
|
|
|
//qDebug() << "DebuggerRunControl::stop";
|
|
|
|
m_running = false;
|
|
|
|
emit stopRequested();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::debuggingFinished()
|
|
|
|
{
|
|
|
|
m_running = false;
|
2009-02-16 13:29:57 +01:00
|
|
|
//qDebug() << "DebuggerRunControl::finished";
|
2008-12-02 12:01:29 +01:00
|
|
|
//emit addToOutputWindow(this, tr("Debugging %1 finished").arg(m_executable));
|
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DebuggerRunControl::isRunning() const
|
|
|
|
{
|
2009-02-16 13:29:57 +01:00
|
|
|
//qDebug() << "DebuggerRunControl::isRunning" << m_running;
|
2008-12-02 12:01:29 +01:00
|
|
|
return m_running;
|
|
|
|
}
|