androiddebugsupport.cpp 6.99 KB
Newer Older
BogDan Vatra's avatar
BogDan Vatra committed
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 BogDan Vatra <bog_dan_ro@yahoo.com>
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
BogDan Vatra's avatar
BogDan Vatra committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/

#include "androiddebugsupport.h"

#include "androiddeploystep.h"
#include "androidglobal.h"
#include "androidrunner.h"
Tobias Hunger's avatar
Tobias Hunger committed
36
#include "androidmanager.h"
BogDan Vatra's avatar
BogDan Vatra committed
37

hjk's avatar
hjk committed
38
#include <debugger/debuggerengine.h>
BogDan Vatra's avatar
BogDan Vatra committed
39
#include <debugger/debuggerplugin.h>
hjk's avatar
hjk committed
40
#include <debugger/debuggerprofileinformation.h>
BogDan Vatra's avatar
BogDan Vatra committed
41
42
43
#include <debugger/debuggerrunner.h>
#include <debugger/debuggerstartparameters.h>

Tobias Hunger's avatar
Tobias Hunger committed
44
#include <projectexplorer/target.h>
BogDan Vatra's avatar
BogDan Vatra committed
45
46
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4nodes.h>
Tobias Hunger's avatar
Tobias Hunger committed
47
48
#include <qt4projectmanager/qt4project.h>
#include <qtsupport/qtprofileinformation.h>
BogDan Vatra's avatar
BogDan Vatra committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

#include <QDir>

using namespace Debugger;
using namespace ProjectExplorer;
using namespace Qt4ProjectManager;

namespace Android {
namespace Internal {

static const char * const qMakeVariables[] = {
         "QT_INSTALL_LIBS",
         "QT_INSTALL_PLUGINS",
         "QT_INSTALL_IMPORTS"
};

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
static QStringList qtSoPaths(QtSupport::BaseQtVersion *qtVersion)
{
    if (!qtVersion)
        return QStringList();

    QSet<QString> paths;
    for (uint i = 0; i < sizeof qMakeVariables / sizeof qMakeVariables[0]; ++i) {
        QString path = qtVersion->qmakeProperty(qMakeVariables[i]);
        if (path.isNull())
            continue;
        QDirIterator it(path, QStringList() << QLatin1String("*.so"), QDir::Files, QDirIterator::Subdirectories);
        while (it.hasNext()) {
            it.next();
            paths.insert(it.fileInfo().absolutePath());
        }
    }
    return paths.toList();
}
BogDan Vatra's avatar
BogDan Vatra committed
83
84
85

RunControl *AndroidDebugSupport::createDebugRunControl(AndroidRunConfiguration *runConfig)
{
86
87
88
    Target *target = runConfig->target();
    Qt4Project *project = static_cast<Qt4Project *>(target->project());

BogDan Vatra's avatar
BogDan Vatra committed
89
90
    DebuggerStartParameters params;
    params.startMode = AttachToRemoteServer;
91
    params.displayName = AndroidManager::packageName(target);
92
    params.remoteSetupNeeded = true;
93
94
95

    if (runConfig->debuggerAspect()->useCppDebugger()) {
        params.languages |= CppLanguage;
96
        Profile *profile = target->profile();
97
98
99
100
        params.sysRoot = SysRootProfileInformation::sysRoot(profile).toString();
        params.debuggerCommand = DebuggerProfileInformation::debuggerCommand(profile).toString();
        if (ToolChain *tc = ToolChainProfileInformation::toolChain(profile))
            params.toolChainAbi = tc->targetAbi();
101
        params.executable = project->rootQt4ProjectNode()->buildDir() + QLatin1String("/app_process");
102
103
        params.remoteChannel = runConfig->remoteChannel();
        params.solibSearchPath.clear();
104
        QList<Qt4ProFileNode *> nodes = project->allProFiles();
105
106
107
        foreach (Qt4ProFileNode *node, nodes)
            if (node->projectType() == ApplicationTemplate)
                params.solibSearchPath.append(node->targetInformation().buildDir);
108
        QtSupport::BaseQtVersion *version = QtSupport::QtProfileInformation::qtVersion(profile);
109
110
111
112
113
114
115
        params.solibSearchPath.append(qtSoPaths(version));
    }
    if (runConfig->debuggerAspect()->useQmlDebugger()) {
        params.languages |= QmlLanguage;
        params.qmlServerAddress = QLatin1String("localhost");
        params.qmlServerPort = runConfig->debuggerAspect()->qmlDebugServerPort();
        //TODO: Not sure if these are the right paths.
116
117
        params.projectSourceDirectory = project->projectDirectory();
        params.projectSourceFiles = project->files(Qt4Project::ExcludeGeneratedFiles);
hjk's avatar
hjk committed
118
        params.projectBuildDirectory = project->rootQt4ProjectNode()->buildDir();
119
    }
BogDan Vatra's avatar
BogDan Vatra committed
120
121
122
123
124
125
126
127
128
129
130

    DebuggerRunControl * const debuggerRunControl
        = DebuggerPlugin::createDebugger(params, runConfig);
    new AndroidDebugSupport(runConfig, debuggerRunControl);
    return debuggerRunControl;
}

AndroidDebugSupport::AndroidDebugSupport(AndroidRunConfiguration *runConfig,
    DebuggerRunControl *runControl)
    : QObject(runControl), m_runControl(runControl),
      m_runner(new AndroidRunner(this, runConfig, true)),
131
      m_gdbServerPort(5039), m_qmlPort(runConfig->debuggerAspect()->qmlDebugServerPort())
BogDan Vatra's avatar
BogDan Vatra committed
132
{
133
134
    Q_ASSERT(runConfig->debuggerAspect()->useCppDebugger() || runConfig->debuggerAspect()->useQmlDebugger());

BogDan Vatra's avatar
BogDan Vatra committed
135
136
137
138
139
140
141
    connect(m_runControl->engine(), SIGNAL(requestRemoteSetup()),
            m_runner, SLOT(start()));
    connect(m_runControl, SIGNAL(finished()),
            m_runner, SLOT(stop()));

    connect(m_runner, SIGNAL(remoteProcessStarted(int,int)),
        SLOT(handleRemoteProcessStarted(int,int)));
Robert Loehning's avatar
Robert Loehning committed
142
143
    connect(m_runner, SIGNAL(remoteProcessFinished(QString)),
        SLOT(handleRemoteProcessFinished(QString)));
BogDan Vatra's avatar
BogDan Vatra committed
144
145
146
147
148
149
150
151
152
153
154

    connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)),
        SLOT(handleRemoteErrorOutput(QByteArray)));
    connect(m_runner, SIGNAL(remoteOutput(QByteArray)),
        SLOT(handleRemoteOutput(QByteArray)));
}

void AndroidDebugSupport::handleRemoteProcessStarted(int gdbServerPort, int qmlPort)
{
    disconnect(m_runner, SIGNAL(remoteProcessStarted(int,int)),
        this, SLOT(handleRemoteProcessStarted(int,int)));
155
    m_runControl->engine()->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
BogDan Vatra's avatar
BogDan Vatra committed
156
157
158
159
}

void AndroidDebugSupport::handleRemoteProcessFinished(const QString &errorMsg)
{
Robert Loehning's avatar
Robert Loehning committed
160
161
    disconnect(m_runner, SIGNAL(remoteProcessFinished(QString)),
        this,SLOT(handleRemoteProcessFinished(QString)));
162
    m_runControl->engine()->notifyEngineRemoteSetupFailed(errorMsg);
BogDan Vatra's avatar
BogDan Vatra committed
163
164
165
166
}

void AndroidDebugSupport::handleRemoteOutput(const QByteArray &output)
{
167
168
169
170
171
172
    if (m_runControl) {
        if (m_runControl->engine())
            m_runControl->engine()->showMessage(QString::fromUtf8(output), AppOutput);
        else
            m_runControl->showMessage(QString::fromUtf8(output), AppOutput);
    }
BogDan Vatra's avatar
BogDan Vatra committed
173
174
175
176
}

void AndroidDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
{
177
178
179
180
181
182
    if (m_runControl) {
        if (m_runControl->engine())
            m_runControl->engine()->showMessage(QString::fromUtf8(output), AppError);
        else
            m_runControl->showMessage(QString::fromUtf8(output), AppError);
    }
BogDan Vatra's avatar
BogDan Vatra committed
183
184
185
}

} // namespace Internal
hjk's avatar
hjk committed
186
} // namespace Android