debuggerrunner.cpp 5.11 KB
Newer Older
con's avatar
con committed
1
2
3
4
/***************************************************************************
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
7
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
10
11
**
** Non-Open Source Usage
**
con's avatar
con committed
12
13
14
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
15
16
17
18
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
con's avatar
con committed
19
20
21
22
23
24
25
26
27
28
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
29
** rights. These rights are described in the Nokia Qt GPL Exception
30
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
31
32
**
***************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34
35
36
37
38
39
40
41
42
#include "debuggerrunner.h"

#include "debuggermanager.h"

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

hjk's avatar
hjk committed
43
44
#include <utils/qtcassert.h>

con's avatar
con committed
45
46
47
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
hjk's avatar
hjk committed
48

49
#include <QtGui/QTextDocument>
con's avatar
con committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

using namespace Debugger::Internal;

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


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

DebuggerRunner::DebuggerRunner(DebuggerManager *manager)
  : m_manager(manager)
{}

bool DebuggerRunner::canRun(RunConfigurationPtr runConfiguration, const QString &mode)
{
    return mode == ProjectExplorer::Constants::DEBUGMODE 
       && !qSharedPointerCast<ApplicationRunConfiguration>(runConfiguration).isNull();
}

QString DebuggerRunner::displayName() const
{
    return QObject::tr("Debug");
}

RunControl* DebuggerRunner::run(RunConfigurationPtr runConfiguration, const QString &mode)
{
hjk's avatar
hjk committed
81
    QTC_ASSERT(mode == ProjectExplorer::Constants::DEBUGMODE, return 0);
con's avatar
con committed
82
83
    ApplicationRunConfigurationPtr rc =
        qSharedPointerCast<ApplicationRunConfiguration>(runConfiguration);
hjk's avatar
hjk committed
84
    QTC_ASSERT(rc, return 0);
con's avatar
con committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
    //qDebug() << "***** Debugging" << rc->name() << rc->executable();
    return new DebuggerRunControl(m_manager, rc);
}

QWidget *DebuggerRunner::configurationWidget(RunConfigurationPtr runConfiguration)
{
    // NBS TODO: Add GDB-specific configuration widget
    Q_UNUSED(runConfiguration);
    return 0;
}



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


DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager,
        QSharedPointer<ApplicationRunConfiguration> runConfiguration)
  : RunControl(runConfiguration), m_manager(manager), m_running(false)
{
    connect(m_manager, SIGNAL(debuggingFinished()),
110
111
            this, SLOT(debuggingFinished()),
            Qt::QueuedConnection);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
112
    connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
113
114
            this, SLOT(slotAddToOutputWindowInline(QString)),
            Qt::QueuedConnection);
con's avatar
con committed
115
    connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
116
117
            this, SLOT(bringApplicationToForeground(qint64)),
            Qt::QueuedConnection);
con's avatar
con committed
118
119
120
121
122
123
124
}

void DebuggerRunControl::start()
{
    m_running = true;
    ApplicationRunConfigurationPtr rc =
        qSharedPointerCast<ApplicationRunConfiguration>(runConfiguration());
hjk's avatar
hjk committed
125
    QTC_ASSERT(rc, return);
con's avatar
con committed
126
    ProjectExplorer::Project *project = rc->project();
hjk's avatar
hjk committed
127
    QTC_ASSERT(project, return);
con's avatar
con committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

    m_manager->m_executable = rc->executable();
    m_manager->m_environment = rc->environment().toStringList();
    m_manager->m_workingDir = rc->workingDirectory();
    m_manager->m_processArgs = rc->commandLineArguments();
    m_manager->m_buildDir =
        project->buildDirectory(project->activeBuildConfiguration());
    //<daniel> andre: + "\qtc-gdbmacros\"

    //emit addToOutputWindow(this, tr("Debugging %1").arg(m_executable));
    if (m_manager->startNewDebugger(DebuggerManager::startInternal))
        emit started();
    else
        debuggingFinished();
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
144
void DebuggerRunControl::slotAddToOutputWindowInline(const QString &data)
con's avatar
con committed
145
{  
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
146
    emit addToOutputWindowInline(this, data);
con's avatar
con committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
}

void DebuggerRunControl::stop()
{
    m_manager->exitDebugger();
}

void DebuggerRunControl::debuggingFinished()
{
    m_running = false;
    //emit addToOutputWindow(this, tr("Debugging %1 finished").arg(m_executable));
    emit finished();
}

bool DebuggerRunControl::isRunning() const
{
    return m_running;
}