debuggerrunner.cpp 5.33 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
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
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
26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
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
38
#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
39
40
#include <utils/qtcassert.h>

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

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
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
72
    return tr("Debug");
con's avatar
con committed
73
74
75
76
}

RunControl* DebuggerRunner::run(RunConfigurationPtr runConfiguration, const QString &mode)
{
hjk's avatar
hjk committed
77
    QTC_ASSERT(mode == ProjectExplorer::Constants::DEBUGMODE, return 0);
con's avatar
con committed
78
79
    ApplicationRunConfigurationPtr rc =
        qSharedPointerCast<ApplicationRunConfiguration>(runConfiguration);
hjk's avatar
hjk committed
80
    QTC_ASSERT(rc, return 0);
con's avatar
con committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    //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()),
106
107
            this, SLOT(debuggingFinished()),
            Qt::QueuedConnection);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
108
    connect(m_manager, SIGNAL(applicationOutputAvailable(QString)),
109
110
            this, SLOT(slotAddToOutputWindowInline(QString)),
            Qt::QueuedConnection);
con's avatar
con committed
111
    connect(m_manager, SIGNAL(inferiorPidChanged(qint64)),
112
113
            this, SLOT(bringApplicationToForeground(qint64)),
            Qt::QueuedConnection);
hjk's avatar
hjk committed
114
115
    connect(this, SIGNAL(stopRequested()),
            m_manager, SLOT(exitDebugger()));
con's avatar
con committed
116
117
118
119
120
121
122
}

void DebuggerRunControl::start()
{
    m_running = true;
    ApplicationRunConfigurationPtr rc =
        qSharedPointerCast<ApplicationRunConfiguration>(runConfiguration());
hjk's avatar
hjk committed
123
    QTC_ASSERT(rc, return);
con's avatar
con committed
124
    ProjectExplorer::Project *project = rc->project();
hjk's avatar
hjk committed
125
    QTC_ASSERT(project, return);
con's avatar
con committed
126
127
128
129
130

    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();
hjk's avatar
hjk committed
131
    m_manager->m_dumperLib = rc->dumperLibrary();
con's avatar
con committed
132
133
    m_manager->m_buildDir =
        project->buildDirectory(project->activeBuildConfiguration());
134
135
    m_manager->m_useTerminal = rc->runMode() == ApplicationRunConfiguration::Console;

con's avatar
con committed
136
    //emit addToOutputWindow(this, tr("Debugging %1").arg(m_executable));
137
    if (m_manager->startNewDebugger(StartInternal))
con's avatar
con committed
138
139
140
141
142
        emit started();
    else
        debuggingFinished();
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
143
void DebuggerRunControl::slotAddToOutputWindowInline(const QString &data)
con's avatar
con committed
144
{  
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
145
    emit addToOutputWindowInline(this, data);
con's avatar
con committed
146
147
148
149
}

void DebuggerRunControl::stop()
{
hjk's avatar
hjk committed
150
151
152
    //qDebug() << "DebuggerRunControl::stop";
    m_running = false;
    emit stopRequested();
con's avatar
con committed
153
154
155
156
157
}

void DebuggerRunControl::debuggingFinished()
{
    m_running = false;
hjk's avatar
hjk committed
158
    //qDebug() << "DebuggerRunControl::finished";
con's avatar
con committed
159
160
161
162
163
164
    //emit addToOutputWindow(this, tr("Debugging %1 finished").arg(m_executable));
    emit finished();
}

bool DebuggerRunControl::isRunning() const
{
hjk's avatar
hjk committed
165
    //qDebug() << "DebuggerRunControl::isRunning" << m_running;
con's avatar
con committed
166
167
    return m_running;
}