androiddebugsupport.cpp 7.4 KB
Newer Older
BogDan Vatra's avatar
BogDan Vatra committed
1 2
/**************************************************************************
**
3
** Copyright (c) 2013 BogDan Vatra <bog_dan_ro@yahoo.com>
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
BogDan Vatra's avatar
BogDan Vatra committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
BogDan Vatra's avatar
BogDan Vatra committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
BogDan Vatra's avatar
BogDan Vatra committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** 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.
BogDan Vatra's avatar
BogDan Vatra committed
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
BogDan Vatra's avatar
BogDan Vatra committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
BogDan Vatra's avatar
BogDan Vatra committed
29 30 31 32 33 34

#include "androiddebugsupport.h"

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

hjk's avatar
hjk committed
37
#include <debugger/debuggerengine.h>
BogDan Vatra's avatar
BogDan Vatra committed
38
#include <debugger/debuggerplugin.h>
Tobias Hunger's avatar
Tobias Hunger committed
39
#include <debugger/debuggerkitinformation.h>
40
#include <debugger/debuggerrunconfigurationaspect.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>
45
#include <projectexplorer/toolchain.h>
BogDan Vatra's avatar
BogDan Vatra committed
46 47
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4nodes.h>
Tobias Hunger's avatar
Tobias Hunger committed
48
#include <qt4projectmanager/qt4project.h>
Tobias Hunger's avatar
Tobias Hunger committed
49
#include <qtsupport/qtkitinformation.h>
BogDan Vatra's avatar
BogDan Vatra committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

#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"
};

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
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
84

85
RunControl *AndroidDebugSupport::createDebugRunControl(AndroidRunConfiguration *runConfig, QString *errorMessage)
BogDan Vatra's avatar
BogDan Vatra committed
86
{
87 88 89
    Target *target = runConfig->target();
    Qt4Project *project = static_cast<Qt4Project *>(target->project());

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

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

    DebuggerRunControl * const debuggerRunControl
125
        = DebuggerPlugin::createDebugger(params, runConfig, errorMessage);
BogDan Vatra's avatar
BogDan Vatra committed
126 127 128 129 130 131 132 133
    new AndroidDebugSupport(runConfig, debuggerRunControl);
    return debuggerRunControl;
}

AndroidDebugSupport::AndroidDebugSupport(AndroidRunConfiguration *runConfig,
    DebuggerRunControl *runControl)
    : QObject(runControl), m_runControl(runControl),
      m_runner(new AndroidRunner(this, runConfig, true)),
134 135
      m_gdbServerPort(5039),
      m_qmlPort(0)
BogDan Vatra's avatar
BogDan Vatra committed
136
{
137 138
    Debugger::DebuggerRunConfigurationAspect *aspect
            = runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
139 140
    m_qmlPort = aspect->qmlDebugServerPort();
    Q_ASSERT(aspect->useCppDebugger() || aspect->useQmlDebugger());
141

BogDan Vatra's avatar
BogDan Vatra committed
142 143 144 145 146 147 148
    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
149 150
    connect(m_runner, SIGNAL(remoteProcessFinished(QString)),
        SLOT(handleRemoteProcessFinished(QString)));
BogDan Vatra's avatar
BogDan Vatra committed
151 152 153 154 155 156 157 158 159 160 161

    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)));
162
    m_runControl->engine()->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
BogDan Vatra's avatar
BogDan Vatra committed
163 164 165 166
}

void AndroidDebugSupport::handleRemoteProcessFinished(const QString &errorMsg)
{
BogDan Vatra's avatar
BogDan Vatra committed
167 168
    if (m_runControl)
        m_runControl->showMessage(errorMsg, AppStuff);
BogDan Vatra's avatar
BogDan Vatra committed
169 170 171 172
}

void AndroidDebugSupport::handleRemoteOutput(const QByteArray &output)
{
173 174 175 176 177 178
    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
179 180 181 182
}

void AndroidDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
{
183 184 185 186 187 188
    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
189 190 191
}

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