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
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/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
|
|
|
|
|
** 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.
|
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 "androiddeploystep.h"
|
|
|
|
|
#include "androidglobal.h"
|
|
|
|
|
#include "androidrunner.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "androidmanager.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>
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2013-10-29 16:19:24 +01:00
|
|
|
#include <qmakeprojectmanager/qmakebuildconfiguration.h>
|
|
|
|
|
#include <qmakeprojectmanager/qmakenodes.h>
|
|
|
|
|
#include <qmakeprojectmanager/qmakeproject.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
#include <QDir>
|
2013-04-18 10:01:05 +02:00
|
|
|
#include <QTcpServer>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace ProjectExplorer;
|
2013-10-16 11:02:37 +02:00
|
|
|
using namespace QmakeProjectManager;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
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();
|
2013-10-29 14:22:31 +01:00
|
|
|
QmakeProject *project = static_cast<QmakeProject *>(target->project());
|
2012-08-14 15:52:17 +02:00
|
|
|
|
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();
|
2013-10-29 14:22:31 +01:00
|
|
|
params.executable = project->rootQmakeProjectNode()->buildDir() + QLatin1String("/app_process");
|
2012-06-24 19:32:45 -07:00
|
|
|
params.remoteChannel = runConfig->remoteChannel();
|
|
|
|
|
params.solibSearchPath.clear();
|
2013-10-29 14:22:31 +01:00
|
|
|
QList<QmakeProFileNode *> nodes = project->allProFiles();
|
|
|
|
|
foreach (QmakeProFileNode *node, nodes)
|
2012-06-24 19:32:45 -07:00
|
|
|
if (node->projectType() == ApplicationTemplate)
|
|
|
|
|
params.solibSearchPath.append(node->targetInformation().buildDir);
|
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.
|
2012-08-14 15:52:17 +02:00
|
|
|
params.projectSourceDirectory = project->projectDirectory();
|
2013-10-29 14:22:31 +01:00
|
|
|
params.projectSourceFiles = project->files(QmakeProject::ExcludeGeneratedFiles);
|
|
|
|
|
params.projectBuildDirectory = project->rootQmakeProjectNode()->buildDir();
|
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)
|
2013-05-03 12:41:58 +02:00
|
|
|
: AndroidRunSupport(runConfig, runControl),
|
|
|
|
|
m_engine(0)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
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
|
|
|
|
2013-05-03 12:41:58 +02:00
|
|
|
if (runControl)
|
|
|
|
|
m_engine = runControl->engine();
|
|
|
|
|
|
|
|
|
|
if (m_engine) {
|
|
|
|
|
connect(m_engine, SIGNAL(requestRemoteSetup()),
|
|
|
|
|
m_runner, SLOT(start()));
|
|
|
|
|
connect(m_engine, SIGNAL(aboutToNotifyInferiorSetupOk()),
|
|
|
|
|
m_runner, SLOT(handleRemoteDebuggerRunning()));
|
|
|
|
|
}
|
2013-05-06 14:16:23 +02:00
|
|
|
connect(m_runner, SIGNAL(remoteServerRunning(QByteArray,int)),
|
|
|
|
|
SLOT(handleRemoteServerRunning(QByteArray,int)));
|
|
|
|
|
connect(m_runner, SIGNAL(remoteProcessStarted(int,int)),
|
|
|
|
|
SLOT(handleRemoteProcessStarted(int,int)));
|
2013-05-07 09:58:32 +02:00
|
|
|
connect(m_runner, SIGNAL(remoteProcessFinished(QString)),
|
|
|
|
|
SLOT(handleRemoteProcessFinished(QString)));
|
|
|
|
|
|
|
|
|
|
connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)),
|
|
|
|
|
SLOT(handleRemoteErrorOutput(QByteArray)));
|
|
|
|
|
connect(m_runner, SIGNAL(remoteOutput(QByteArray)),
|
|
|
|
|
SLOT(handleRemoteOutput(QByteArray)));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2013-02-27 15:12:36 +01:00
|
|
|
void AndroidDebugSupport::handleRemoteServerRunning(const QByteArray &serverChannel, int pid)
|
|
|
|
|
{
|
2013-05-03 12:41:58 +02:00
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->notifyEngineRemoteServerRunning(serverChannel, pid);
|
2013-02-27 15:12:36 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
void AndroidDebugSupport::handleRemoteProcessStarted(int gdbServerPort, int qmlPort)
|
|
|
|
|
{
|
|
|
|
|
disconnect(m_runner, SIGNAL(remoteProcessStarted(int,int)),
|
|
|
|
|
this, SLOT(handleRemoteProcessStarted(int,int)));
|
2013-05-03 12:41:58 +02:00
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDebugSupport::handleRemoteProcessFinished(const QString &errorMsg)
|
|
|
|
|
{
|
2013-05-03 12:41:58 +02:00
|
|
|
DebuggerRunControl *runControl = qobject_cast<DebuggerRunControl *>(m_runControl);
|
|
|
|
|
if (runControl)
|
|
|
|
|
runControl->showMessage(errorMsg, AppStuff);
|
|
|
|
|
else
|
|
|
|
|
AndroidRunSupport::handleRemoteProcessFinished(errorMsg);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDebugSupport::handleRemoteOutput(const QByteArray &output)
|
|
|
|
|
{
|
2013-05-03 12:41:58 +02:00
|
|
|
if (m_engine) {
|
|
|
|
|
m_engine->showMessage(QString::fromUtf8(output), AppOutput);
|
|
|
|
|
} else {
|
|
|
|
|
DebuggerRunControl *runControl = qobject_cast<DebuggerRunControl *>(m_runControl);
|
|
|
|
|
if (runControl)
|
|
|
|
|
runControl->showMessage(QString::fromUtf8(output), AppOutput);
|
2012-06-24 19:32:45 -07:00
|
|
|
else
|
2013-05-03 12:41:58 +02:00
|
|
|
AndroidRunSupport::handleRemoteOutput(output);
|
2012-06-24 19:32:45 -07:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
|
|
|
|
|
{
|
2013-05-03 12:41:58 +02:00
|
|
|
if (m_engine) {
|
|
|
|
|
m_engine->showMessage(QString::fromUtf8(output), AppError);
|
|
|
|
|
} else {
|
|
|
|
|
DebuggerRunControl *runControl = qobject_cast<DebuggerRunControl *>(m_runControl);
|
|
|
|
|
if (runControl)
|
|
|
|
|
runControl->showMessage(QString::fromUtf8(output), AppError);
|
2012-06-24 19:32:45 -07:00
|
|
|
else
|
2013-05-03 12:41:58 +02:00
|
|
|
AndroidRunSupport::handleRemoteErrorOutput(output);
|
2012-06-24 19:32:45 -07:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2012-08-09 01:56:51 +02:00
|
|
|
} // namespace Android
|