debuggerrunner.cpp 7.24 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
39
#include <utils/qtcassert.h>

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

44
#include <QtGui/QTextDocument>
con's avatar
con committed
45
46
47
48
49
50
51

using namespace Debugger::Internal;

using ProjectExplorer::RunConfiguration;
using ProjectExplorer::RunControl;
using ProjectExplorer::ApplicationRunConfiguration;

52
53
54
55
56
DefaultApplicationRunConfiguration::DefaultApplicationRunConfiguration(const QString &executable) :
    ProjectExplorer::ApplicationRunConfiguration(0),
    m_executable(executable)
{
}
con's avatar
con committed
57
58
59
60
61
62
63

////////////////////////////////////////////////////////////////////////
//
// DebuggerRunner
//
////////////////////////////////////////////////////////////////////////

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

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

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

80
81
82
83
84
RunConfigurationPtr DebuggerRunner::createDefaultRunConfiguration(const QString &executable)
{
    return RunConfigurationPtr(new DefaultApplicationRunConfiguration(executable));
}

85
RunControl *DebuggerRunner::run(RunConfigurationPtr runConfiguration,
86
87
88
                                const QString &mode,
                                const QSharedPointer<DebuggerStartParameters> &sp,
                                DebuggerStartMode startMode)
con's avatar
con committed
89
{
hjk's avatar
hjk committed
90
    QTC_ASSERT(mode == ProjectExplorer::Constants::DEBUGMODE, return 0);
con's avatar
con committed
91
    ApplicationRunConfigurationPtr rc =
dt's avatar
dt committed
92
        runConfiguration.objectCast<ApplicationRunConfiguration>();
93
    QTC_ASSERT(!rc.isNull(), return 0);
con's avatar
con committed
94
    //qDebug() << "***** Debugging" << rc->name() << rc->executable();
95
    DebuggerRunControl *runControl = new DebuggerRunControl(m_manager, startMode, sp, rc);
96
97
98
    return runControl;
}

99
RunControl *DebuggerRunner::run(RunConfigurationPtr runConfiguration,
100
101
    const QString &mode)
{
102
103
    const QSharedPointer<DebuggerStartParameters> sp(new DebuggerStartParameters);
    return run(runConfiguration, mode, sp, StartInternal);
con's avatar
con committed
104
105
106
107
108
}

QWidget *DebuggerRunner::configurationWidget(RunConfigurationPtr runConfiguration)
{
    // 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,
123
124
125
126
127
128
129
130
                                       DebuggerStartMode mode,
                                       const QSharedPointer<DebuggerStartParameters> &startParameters,
                                       QSharedPointer<ApplicationRunConfiguration> runConfiguration) :
    RunControl(runConfiguration),
    m_mode(mode),
    m_startParameters(startParameters),
    m_manager(manager),
    m_running(false)
con's avatar
con committed
131
132
{
    connect(m_manager, SIGNAL(debuggingFinished()),
133
134
            this, SLOT(debuggingFinished()),
            Qt::QueuedConnection);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
135
    connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
136
137
            this, SLOT(slotAddToOutputWindowInline(QString)),
            Qt::QueuedConnection);
con's avatar
con committed
138
    connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
139
140
            this, SLOT(bringApplicationToForeground(qint64)),
            Qt::QueuedConnection);
hjk's avatar
hjk committed
141
142
    connect(this, SIGNAL(stopRequested()),
            m_manager, SLOT(exitDebugger()));
143
    if (runConfiguration) {
144
145
146
        // Enhance parameters by info from the project, but do not clobber
        // arguments given in the dialogs
        if (m_startParameters->executable.isEmpty())
147
            m_startParameters->executable = runConfiguration->executable();
148
        if (m_startParameters->environment.empty())
149
            m_startParameters->environment = runConfiguration->environment().toStringList();
150
        if (m_startParameters->workingDir.isEmpty())
151
            m_startParameters->workingDir = runConfiguration->workingDirectory();
152
        if (m_mode != StartExternal)
153
            m_startParameters->processArgs = runConfiguration->commandLineArguments();
154
155
156
        switch (m_startParameters->toolChainType) {
        case ProjectExplorer::ToolChain::UNKNOWN:
        case ProjectExplorer::ToolChain::INVALID:
157
            m_startParameters->toolChainType = runConfiguration->toolChainType();
158
159
160
161
            break;
        default:
            break;
        }
162
        if (const ProjectExplorer::Project *project = runConfiguration->project()) {
163
            m_startParameters->buildDir = project->buildDirectory(project->activeBuildConfiguration());
164
        }
165
166
167
        m_startParameters->useTerminal = runConfiguration->runMode() == ApplicationRunConfiguration::Console;
        m_dumperLibrary = runConfiguration->dumperLibrary();
        m_dumperLibraryLocations = runConfiguration->dumperLibraryLocations();
168
    }
169
170
171
172
173
174
175
}

void DebuggerRunControl::start()
{
    m_running = true;
    m_manager->setQtDumperLibraryName(m_dumperLibrary);
    m_manager->setQtDumperLibraryLocations(m_dumperLibraryLocations);
176

con's avatar
con committed
177
    //emit addToOutputWindow(this, tr("Debugging %1").arg(m_executable));
178
    m_manager->startNewDebugger(this, m_startParameters);
179
180
    emit started();
    //debuggingFinished();
con's avatar
con committed
181
182
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
183
void DebuggerRunControl::slotAddToOutputWindowInline(const QString &data)
184
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
185
    emit addToOutputWindowInline(this, data);
con's avatar
con committed
186
187
188
189
}

void DebuggerRunControl::stop()
{
hjk's avatar
hjk committed
190
191
192
    //qDebug() << "DebuggerRunControl::stop";
    m_running = false;
    emit stopRequested();
con's avatar
con committed
193
194
195
196
197
}

void DebuggerRunControl::debuggingFinished()
{
    m_running = false;
hjk's avatar
hjk committed
198
    //qDebug() << "DebuggerRunControl::finished";
con's avatar
con committed
199
200
201
202
203
204
    //emit addToOutputWindow(this, tr("Debugging %1 finished").arg(m_executable));
    emit finished();
}

bool DebuggerRunControl::isRunning() const
{
hjk's avatar
hjk committed
205
    //qDebug() << "DebuggerRunControl::isRunning" << m_running;
con's avatar
con committed
206
207
    return m_running;
}