2012-04-18 20:30:57 +03:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (c) 2014 BogDan Vatra <bog_dan_ro@yahoo.com>
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-04-18 20:30:57 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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-06-28 10:00:04 +02:00
|
|
|
#include <debugger/debuggerengine.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <debugger/debuggerplugin.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <debugger/debuggerkitinformation.h>
|
2013-03-27 13:03:15 +01:00
|
|
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <debugger/debuggerrunner.h>
|
|
|
|
|
#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
|
|
|
|
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;
|
|
|
|
|
QDirIterator it(path, QStringList() << QLatin1String("*.so"), QDir::Files, QDirIterator::Subdirectories);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
paths.insert(it.fileInfo().absolutePath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return paths.toList();
|
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
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;
|
2012-06-24 19:32:45 -07:00
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
Debugger::DebuggerRunConfigurationAspect *aspect
|
|
|
|
|
= runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
|
2013-03-26 17:03:57 +01:00
|
|
|
if (aspect->useCppDebugger()) {
|
2012-06-24 19:32:45 -07:00
|
|
|
params.languages |= CppLanguage;
|
2012-09-03 18:31:44 +02:00
|
|
|
Kit *kit = target->kit();
|
|
|
|
|
params.sysRoot = SysRootKitInformation::sysRoot(kit).toString();
|
|
|
|
|
params.debuggerCommand = DebuggerKitInformation::debuggerCommand(kit).toString();
|
|
|
|
|
if (ToolChain *tc = ToolChainKitInformation::toolChain(kit))
|
2012-06-24 19:32:45 -07:00
|
|
|
params.toolChainAbi = tc->targetAbi();
|
2014-06-24 16:47:38 +02:00
|
|
|
params.executable = target->activeBuildConfiguration()->buildDirectory().toString() + QLatin1String("/app_process");
|
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));
|
|
|
|
|
}
|
2013-03-26 17:03:57 +01:00
|
|
|
if (aspect->useQmlDebugger()) {
|
2012-06-24 19:32:45 -07:00
|
|
|
params.languages |= QmlLanguage;
|
2013-04-18 10:01:05 +02:00
|
|
|
QTcpServer server;
|
|
|
|
|
QTC_ASSERT(server.listen(QHostAddress::LocalHost)
|
|
|
|
|
|| server.listen(QHostAddress::LocalHostIPv6), return 0);
|
|
|
|
|
params.qmlServerAddress = server.serverAddress().toString();
|
|
|
|
|
params.remoteSetupNeeded = true;
|
2012-06-24 19:32:45 -07:00
|
|
|
//TODO: Not sure if these are the right paths.
|
2014-06-24 16:47:38 +02:00
|
|
|
params.projectSourceDirectory = target->project()->projectDirectory().toString();
|
|
|
|
|
params.projectSourceFiles = target->project()->files(Project::ExcludeGeneratedFiles);
|
|
|
|
|
params.projectBuildDirectory = target->activeBuildConfiguration()->buildDirectory().toString();
|
2012-06-24 19:32:45 -07:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
DebuggerRunControl * const debuggerRunControl
|
2012-09-05 12:42:41 +02:00
|
|
|
= DebuggerPlugin::createDebugger(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_engine(0),
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
connect(m_runControl, SIGNAL(finished()),
|
|
|
|
|
m_runner, SLOT(stop()));
|
|
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
Debugger::DebuggerRunConfigurationAspect *aspect
|
|
|
|
|
= runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
|
2013-03-26 17:03:57 +01:00
|
|
|
Q_ASSERT(aspect->useCppDebugger() || aspect->useQmlDebugger());
|
2013-05-16 22:07:14 +03:00
|
|
|
Q_UNUSED(aspect)
|
2012-06-24 19:32:45 -07:00
|
|
|
|
2014-09-15 15:43:24 +02:00
|
|
|
m_engine = runControl->engine();
|
2013-05-03 12:41:58 +02:00
|
|
|
|
|
|
|
|
if (m_engine) {
|
2014-09-15 15:43:24 +02:00
|
|
|
connect(m_engine, &DebuggerEngine::requestRemoteSetup,
|
|
|
|
|
m_runner, &AndroidRunner::start);
|
|
|
|
|
|
|
|
|
|
// FIXME: Move signal to base class and generalize handling.
|
2013-05-03 12:41:58 +02:00
|
|
|
connect(m_engine, SIGNAL(aboutToNotifyInferiorSetupOk()),
|
|
|
|
|
m_runner, SLOT(handleRemoteDebuggerRunning()));
|
|
|
|
|
}
|
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) {
|
|
|
|
|
QTC_ASSERT(m_engine, return);
|
|
|
|
|
m_engine->notifyEngineRemoteServerRunning(serverChannel, pid);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteProcessStarted,
|
|
|
|
|
this, &AndroidDebugSupport::handleRemoteProcessStarted);
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteProcessFinished,
|
|
|
|
|
[this](const QString &errorMsg) {
|
|
|
|
|
QTC_ASSERT(m_runControl, return);
|
|
|
|
|
m_runControl->showMessage(errorMsg, AppStuff);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteErrorOutput,
|
|
|
|
|
[this](const QByteArray &output) {
|
|
|
|
|
QTC_ASSERT(m_engine, return);
|
|
|
|
|
m_engine->showMessage(QString::fromUtf8(output), AppError);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &AndroidRunner::remoteOutput,
|
|
|
|
|
[this](const QByteArray &output) {
|
|
|
|
|
QTC_ASSERT(m_engine, return);
|
|
|
|
|
m_engine->showMessage(QString::fromUtf8(output), AppOutput);
|
|
|
|
|
});
|
2013-02-27 15:12:36 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
void AndroidDebugSupport::handleRemoteProcessStarted(int gdbServerPort, int qmlPort)
|
|
|
|
|
{
|
2014-09-15 15:43:24 +02:00
|
|
|
disconnect(m_runner, &AndroidRunner::remoteProcessStarted,
|
|
|
|
|
this, &AndroidDebugSupport::handleRemoteProcessStarted);
|
|
|
|
|
QTC_ASSERT(m_engine, return);
|
2014-09-18 19:21:27 +02:00
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = true;
|
|
|
|
|
result.gdbServerPort = gdbServerPort;
|
|
|
|
|
result.qmlServerPort = qmlPort;
|
|
|
|
|
m_engine->notifyEngineRemoteSetupFinished(result);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2012-08-09 01:56:51 +02:00
|
|
|
} // namespace Android
|