debuggerrunner.cpp 7.32 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32 33 34 35 36 37
#include "debuggerrunner.h"

#include "debuggermanager.h"

#include <projectexplorer/environment.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>

hjk's avatar
hjk committed
38
#include <utils/qtcassert.h>
39
#include <coreplugin/icore.h>
hjk's avatar
hjk committed
40

con's avatar
con committed
41 42 43
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
hjk's avatar
hjk committed
44

45
#include <QtGui/QTextDocument>
con's avatar
con committed
46

hjk's avatar
hjk committed
47 48
namespace Debugger {
namespace Internal {
con's avatar
con committed
49 50 51

using ProjectExplorer::RunConfiguration;
using ProjectExplorer::RunControl;
52
using ProjectExplorer::LocalApplicationRunConfiguration;
con's avatar
con committed
53

54 55
DefaultLocalApplicationRunConfiguration::DefaultLocalApplicationRunConfiguration(const QString &executable) :
    ProjectExplorer::LocalApplicationRunConfiguration(0),
56 57 58
    m_executable(executable)
{
}
con's avatar
con committed
59 60 61

////////////////////////////////////////////////////////////////////////
//
62
// DebuggerRunControlFactory
con's avatar
con committed
63 64 65
//
////////////////////////////////////////////////////////////////////////

66
// A factory to create DebuggerRunControls
67
DebuggerRunControlFactory::DebuggerRunControlFactory(DebuggerManager *manager)
68
    : m_manager(manager)
con's avatar
con committed
69 70
{}

71
bool DebuggerRunControlFactory::canRun(const RunConfigurationPtr &runConfiguration, const QString &mode) const
con's avatar
con committed
72
{
73
    return mode == ProjectExplorer::Constants::DEBUGMODE
74
       && !runConfiguration.objectCast<LocalApplicationRunConfiguration>().isNull();
con's avatar
con committed
75 76
}

77
QString DebuggerRunControlFactory::displayName() const
con's avatar
con committed
78
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
79
    return tr("Debug");
con's avatar
con committed
80 81
}

82
RunConfigurationPtr DebuggerRunControlFactory::createDefaultRunConfiguration(const QString &executable)
83
{
84
    return RunConfigurationPtr(new DefaultLocalApplicationRunConfiguration(executable));
85 86
}

87 88 89
RunControl *DebuggerRunControlFactory::create(const RunConfigurationPtr &runConfiguration,
                                              const QString &mode,
                                              const DebuggerStartParametersPtr &sp)
con's avatar
con committed
90
{
hjk's avatar
hjk committed
91
    QTC_ASSERT(mode == ProjectExplorer::Constants::DEBUGMODE, return 0);
92 93
    LocalApplicationRunConfigurationPtr rc =
        runConfiguration.objectCast<LocalApplicationRunConfiguration>();
94
    QTC_ASSERT(!rc.isNull(), return 0);
hjk's avatar
hjk committed
95
    return new DebuggerRunControl(m_manager, sp, rc);
96 97
}

98 99
RunControl *DebuggerRunControlFactory::create(const RunConfigurationPtr &runConfiguration,
                                              const QString &mode)
100
{
hjk's avatar
hjk committed
101
    const DebuggerStartParametersPtr sp(new DebuggerStartParameters);
hjk's avatar
hjk committed
102
    sp->startMode = StartInternal;
103
    return create(runConfiguration, mode, sp);
con's avatar
con committed
104 105
}

106
QWidget *DebuggerRunControlFactory::configurationWidget(const RunConfigurationPtr &runConfiguration)
con's avatar
con committed
107 108
{
    // NBS TODO: Add GDB-specific configuration widget
109
    Q_UNUSED(runConfiguration)
con's avatar
con committed
110 111 112 113 114 115 116 117 118 119 120 121 122
    return 0;
}



////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControl
//
////////////////////////////////////////////////////////////////////////


DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager,
hjk's avatar
hjk committed
123
       const DebuggerStartParametersPtr &startParameters,
124
       QSharedPointer<LocalApplicationRunConfiguration> runConfiguration)
hjk's avatar
hjk committed
125
  : RunControl(runConfiguration),
126 127 128
    m_startParameters(startParameters),
    m_manager(manager),
    m_running(false)
con's avatar
con committed
129 130
{
    connect(m_manager, SIGNAL(debuggingFinished()),
131 132
            this, SLOT(debuggingFinished()),
            Qt::QueuedConnection);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
133
    connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
134 135
            this, SLOT(slotAddToOutputWindowInline(QString)),
            Qt::QueuedConnection);
con's avatar
con committed
136
    connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
137 138
            this, SLOT(bringApplicationToForeground(qint64)),
            Qt::QueuedConnection);
hjk's avatar
hjk committed
139 140
    connect(this, SIGNAL(stopRequested()),
            m_manager, SLOT(exitDebugger()));
hjk's avatar
hjk committed
141 142 143 144 145 146 147 148 149 150 151 152

    if (!runConfiguration)
        return;

    // Enhance parameters by info from the project, but do not clobber
    // arguments given in the dialogs
    if (m_startParameters->executable.isEmpty())
        m_startParameters->executable = runConfiguration->executable();
    if (m_startParameters->environment.empty())
        m_startParameters->environment = runConfiguration->environment().toStringList();
    if (m_startParameters->workingDir.isEmpty())
        m_startParameters->workingDir = runConfiguration->workingDirectory();
153
    if (m_startParameters->startMode != StartExternal)
hjk's avatar
hjk committed
154 155 156 157 158 159 160 161 162 163 164 165
        m_startParameters->processArgs = runConfiguration->commandLineArguments();
    switch (m_startParameters->toolChainType) {
    case ProjectExplorer::ToolChain::UNKNOWN:
    case ProjectExplorer::ToolChain::INVALID:
        m_startParameters->toolChainType = runConfiguration->toolChainType();
        break;
    default:
        break;
    }
    if (const ProjectExplorer::Project *project = runConfiguration->project()) {
        m_startParameters->buildDir =
            project->buildDirectory(project->activeBuildConfiguration());
166
    }
hjk's avatar
hjk committed
167
    m_startParameters->useTerminal =
168
        runConfiguration->runMode() == LocalApplicationRunConfiguration::Console;
hjk's avatar
hjk committed
169 170 171 172
    m_startParameters->dumperLibrary =
        runConfiguration->dumperLibrary();
    m_startParameters->dumperLibraryLocations =
        runConfiguration->dumperLibraryLocations();
173 174 175 176 177
}

void DebuggerRunControl::start()
{
    m_running = true;
178 179 180 181 182 183 184 185 186 187 188 189 190
    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);
    }
con's avatar
con committed
191 192
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
193
void DebuggerRunControl::slotAddToOutputWindowInline(const QString &data)
194
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
195
    emit addToOutputWindowInline(this, data);
con's avatar
con committed
196 197 198 199
}

void DebuggerRunControl::stop()
{
hjk's avatar
hjk committed
200 201
    m_running = false;
    emit stopRequested();
con's avatar
con committed
202 203 204 205 206 207 208 209 210 211 212 213
}

void DebuggerRunControl::debuggingFinished()
{
    m_running = false;
    emit finished();
}

bool DebuggerRunControl::isRunning() const
{
    return m_running;
}
hjk's avatar
hjk committed
214 215 216

} // namespace Internal
} // namespace Debugger