2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
#include "androiddebugsupport.h"
|
|
|
|
|
|
|
|
|
|
#include "androidglobal.h"
|
|
|
|
|
#include "androidrunner.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "androidmanager.h"
|
2014-06-24 16:47:38 +02:00
|
|
|
#include "androidqtsupport.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <debugger/debuggerkitinformation.h>
|
2013-03-27 13:03:15 +01:00
|
|
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
2014-10-17 13:40:04 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
|
|
|
|
|
2014-06-24 16:47:38 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2014-06-24 16:47:38 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2016-04-19 14:01:44 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
|
2014-06-24 16:47:38 +02:00
|
|
|
#include <QDirIterator>
|
2013-04-18 10:01:05 +02:00
|
|
|
#include <QTcpServer>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace Android {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
static const char * const qMakeVariables[] = {
|
|
|
|
|
"QT_INSTALL_LIBS",
|
|
|
|
|
"QT_INSTALL_PLUGINS",
|
|
|
|
|
"QT_INSTALL_IMPORTS"
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-14 15:52:17 +02:00
|
|
|
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;
|
2017-02-07 16:59:21 +01:00
|
|
|
QDirIterator it(path, QStringList("*.so"), QDir::Files, QDirIterator::Subdirectories);
|
2012-08-14 15:52:17 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
paths.insert(it.fileInfo().absolutePath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return paths.toList();
|
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2016-01-16 16:32:28 +02:00
|
|
|
static QStringList uniquePaths(const QStringList &files)
|
|
|
|
|
{
|
|
|
|
|
QSet<QString> paths;
|
|
|
|
|
foreach (const QString &file, files)
|
|
|
|
|
paths<<QFileInfo(file).absolutePath();
|
|
|
|
|
return paths.toList();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-04 19:12:16 +03:00
|
|
|
static QString toNdkArch(const QString &arch)
|
|
|
|
|
{
|
|
|
|
|
if (arch == QLatin1String("armeabi-v7a") || arch == QLatin1String("armeabi"))
|
|
|
|
|
return QLatin1String("arch-arm");
|
|
|
|
|
if (arch == QLatin1String("arm64-v8a"))
|
|
|
|
|
return QLatin1String("arch-arm64");
|
|
|
|
|
return QLatin1String("arch-") + arch;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-05 12:42:41 +02:00
|
|
|
RunControl *AndroidDebugSupport::createDebugRunControl(AndroidRunConfiguration *runConfig, QString *errorMessage)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-14 15:52:17 +02:00
|
|
|
Target *target = runConfig->target();
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
DebuggerStartParameters params;
|
|
|
|
|
params.startMode = AttachToRemoteServer;
|
2012-08-14 15:52:17 +02:00
|
|
|
params.displayName = AndroidManager::packageName(target);
|
2012-06-13 11:29:26 +02:00
|
|
|
params.remoteSetupNeeded = true;
|
2016-04-29 16:51:50 +02:00
|
|
|
params.useContinueInsteadOfRun = true;
|
2016-04-19 14:01:44 +02:00
|
|
|
if (!Utils::HostOsInfo::isWindowsHost()) // Workaround for NDK 11c(b?)
|
|
|
|
|
params.useTargetAsync = true;
|
2012-06-24 19:32:45 -07:00
|
|
|
|
2015-06-26 13:06:08 +02:00
|
|
|
auto aspect = runConfig->extraAspect<DebuggerRunConfigurationAspect>();
|
2013-03-26 17:03:57 +01:00
|
|
|
if (aspect->useCppDebugger()) {
|
2012-09-03 18:31:44 +02:00
|
|
|
Kit *kit = target->kit();
|
2016-04-29 16:51:50 +02:00
|
|
|
params.symbolFile = target->activeBuildConfiguration()->buildDirectory().toString()
|
2016-01-28 10:31:24 +01:00
|
|
|
+ QLatin1String("/app_process");
|
2015-03-31 07:55:00 +02:00
|
|
|
params.skipExecutableValidation = true;
|
2012-06-24 19:32:45 -07:00
|
|
|
params.remoteChannel = runConfig->remoteChannel();
|
2014-06-24 16:47:38 +02:00
|
|
|
params.solibSearchPath = AndroidManager::androidQtSupport(target)->soLibSearchPath(target);
|
2012-09-03 18:31:44 +02:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
|
2012-06-24 19:32:45 -07:00
|
|
|
params.solibSearchPath.append(qtSoPaths(version));
|
2016-01-16 16:32:28 +02:00
|
|
|
params.solibSearchPath.append(uniquePaths(AndroidManager::androidQtSupport(target)->androidExtraLibs(target)));
|
2016-09-04 19:12:16 +03:00
|
|
|
params.sysRoot = AndroidConfigurations::currentConfig().ndkLocation().appendPath(QLatin1String("platforms"))
|
|
|
|
|
.appendPath(QLatin1String("android-") + QString::number(AndroidManager::minimumSDK(target)))
|
|
|
|
|
.appendPath(toNdkArch(AndroidManager::targetArch(target))).toString();
|
2012-06-24 19:32:45 -07:00
|
|
|
}
|
2013-03-26 17:03:57 +01:00
|
|
|
if (aspect->useQmlDebugger()) {
|
2013-04-18 10:01:05 +02:00
|
|
|
QTcpServer server;
|
|
|
|
|
QTC_ASSERT(server.listen(QHostAddress::LocalHost)
|
|
|
|
|
|| server.listen(QHostAddress::LocalHostIPv6), return 0);
|
2016-06-13 14:18:50 +02:00
|
|
|
params.qmlServer.host = server.serverAddress().toString();
|
2012-06-24 19:32:45 -07:00
|
|
|
//TODO: Not sure if these are the right paths.
|
2015-04-23 19:05:56 +02:00
|
|
|
Kit *kit = target->kit();
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
|
|
|
|
|
if (version) {
|
2017-01-23 17:40:16 +01:00
|
|
|
const QString qmlQtDir = version->qmakeProperty("QT_INSTALL_QML");
|
2015-04-23 19:05:56 +02:00
|
|
|
params.additionalSearchDirectories = QStringList(qmlQtDir);
|
|
|
|
|
}
|
2012-06-24 19:32:45 -07:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2015-06-26 13:06:08 +02:00
|
|
|
DebuggerRunControl * const debuggerRunControl = createDebuggerRunControl(params, runConfig, errorMessage);
|
2012-04-18 20:30:57 +03:00
|
|
|
new AndroidDebugSupport(runConfig, debuggerRunControl);
|
|
|
|
|
return debuggerRunControl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AndroidDebugSupport::AndroidDebugSupport(AndroidRunConfiguration *runConfig,
|
|
|
|
|
DebuggerRunControl *runControl)
|
2014-09-15 15:43:24 +02:00
|
|
|
: QObject(runControl),
|
|
|
|
|
m_runControl(runControl),
|
|
|
|
|
m_runner(new AndroidRunner(this, runConfig, runControl->runMode()))
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-09-15 15:43:24 +02:00
|
|
|
QTC_ASSERT(runControl, return);
|
|
|
|
|
|
2016-04-19 13:48:28 +02:00
|
|
|
connect(m_runControl, &RunControl::finished,
|
|
|
|
|
m_runner, &AndroidRunner::stop);
|
2012-06-24 19:32:45 -07:00
|
|
|
|
2014-12-12 15:33:16 +01:00
|
|
|
connect(m_runControl, &DebuggerRunControl::requestRemoteSetup,
|
|
|
|
|
m_runner, &AndroidRunner::start);
|
2013-05-03 12:41:58 +02:00
|
|
|
|
2014-12-12 15:33:16 +01:00
|
|
|
// FIXME: Move signal to base class and generalize handling.
|
|
|
|
|
connect(m_runControl, &DebuggerRunControl::aboutToNotifyInferiorSetupOk,
|
2016-08-05 15:40:33 +02:00
|
|
|
m_runner, &AndroidRunner::remoteDebuggerRunning);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2014-09-15 15:43:24 +02:00
|
|
|
connect(m_runner, &AndroidRunner::remoteServerRunning,
|
|
|
|
|
[this](const QByteArray &serverChannel, int pid) {
|
2014-12-12 15:33:16 +01:00
|
|
|
QTC_ASSERT(m_runControl, return);
|
|
|
|
|
m_runControl->notifyEngineRemoteServerRunning(serverChannel, pid);
|
2014-09-15 15:43:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteProcessStarted,
|
|
|
|
|
this, &AndroidDebugSupport::handleRemoteProcessStarted);
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteProcessFinished,
|
|
|
|
|
[this](const QString &errorMsg) {
|
|
|
|
|
QTC_ASSERT(m_runControl, return);
|
2014-10-17 13:06:37 +02:00
|
|
|
m_runControl->appendMessage(errorMsg, Utils::DebugFormat);
|
2014-12-12 15:33:16 +01:00
|
|
|
QMetaObject::invokeMethod(m_runControl, "notifyInferiorExited", Qt::QueuedConnection);
|
2014-09-15 15:43:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteErrorOutput,
|
2015-06-12 15:36:04 +02:00
|
|
|
[this](const QString &output) {
|
2014-12-12 15:33:16 +01:00
|
|
|
QTC_ASSERT(m_runControl, return);
|
2015-06-12 15:36:04 +02:00
|
|
|
m_runControl->showMessage(output, AppError);
|
2014-09-15 15:43:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteOutput,
|
2015-06-12 15:36:04 +02:00
|
|
|
[this](const QString &output) {
|
2014-12-12 15:33:16 +01:00
|
|
|
QTC_ASSERT(m_runControl, return);
|
2015-06-12 15:36:04 +02:00
|
|
|
m_runControl->showMessage(output, AppOutput);
|
2014-09-15 15:43:24 +02:00
|
|
|
});
|
2013-02-27 15:12:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:43:30 +02:00
|
|
|
void AndroidDebugSupport::handleRemoteProcessStarted(Utils::Port gdbServerPort, Utils::Port qmlPort)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-09-15 15:43:24 +02:00
|
|
|
disconnect(m_runner, &AndroidRunner::remoteProcessStarted,
|
|
|
|
|
this, &AndroidDebugSupport::handleRemoteProcessStarted);
|
2014-12-12 15:33:16 +01:00
|
|
|
QTC_ASSERT(m_runControl, return);
|
2014-09-18 19:21:27 +02:00
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = true;
|
|
|
|
|
result.gdbServerPort = gdbServerPort;
|
|
|
|
|
result.qmlServerPort = qmlPort;
|
2014-12-12 15:33:16 +01:00
|
|
|
m_runControl->notifyEngineRemoteSetupFinished(result);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2012-08-09 01:56:51 +02:00
|
|
|
} // namespace Android
|