2013-04-25 16:02:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
2013-04-25 16:02:17 +02: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.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "iosdebugsupport.h"
|
|
|
|
|
|
|
|
|
|
#include "iosrunner.h"
|
|
|
|
|
#include "iosmanager.h"
|
2013-12-10 12:53:20 +01:00
|
|
|
#include "iosdevice.h"
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
#include <debugger/debuggerplugin.h>
|
|
|
|
|
#include <debugger/debuggerkitinformation.h>
|
2014-10-17 13:40:04 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2013-04-25 16:02:17 +02:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
2013-10-10 15:15:49 +02:00
|
|
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
|
|
|
|
#include <projectexplorer/toolchain.h>
|
2013-04-25 16:02:17 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2013-12-10 12:53:20 +01:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2013-04-25 16:02:17 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2013-12-10 12:53:20 +01:00
|
|
|
#include <utils/fileutils.h>
|
2014-04-04 09:43:47 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2015-08-10 10:18:54 +02:00
|
|
|
#include <QDateTime>
|
2013-04-25 16:02:17 +02:00
|
|
|
#include <QDir>
|
2013-10-10 15:15:49 +02:00
|
|
|
#include <QTcpServer>
|
2014-03-25 14:32:36 +01:00
|
|
|
#include <QSettings>
|
2013-10-10 15:15:49 +02:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <fcntl.h>
|
2013-10-29 14:49:47 +01:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <io.h>
|
|
|
|
|
#endif
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace Ios {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
RunControl *IosDebugSupport::createDebugRunControl(IosRunConfiguration *runConfig,
|
|
|
|
|
QString *errorMessage)
|
|
|
|
|
{
|
2013-10-10 15:15:49 +02:00
|
|
|
Target *target = runConfig->target();
|
|
|
|
|
if (!target)
|
|
|
|
|
return 0;
|
2015-02-03 23:49:46 +02:00
|
|
|
IDevice::ConstPtr device = DeviceKitInformation::device(target->kit());
|
2013-10-10 15:15:49 +02:00
|
|
|
if (device.isNull())
|
|
|
|
|
return 0;
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
DebuggerStartParameters params;
|
2013-10-31 10:07:28 +01:00
|
|
|
if (device->type() == Core::Id(Ios::Constants::IOS_DEVICE_TYPE)) {
|
2013-10-10 15:15:49 +02:00
|
|
|
params.startMode = AttachToRemoteProcess;
|
2013-10-31 10:07:28 +01:00
|
|
|
params.platform = QLatin1String("remote-ios");
|
2013-12-10 12:53:20 +01:00
|
|
|
IosDevice::ConstPtr iosDevice = device.dynamicCast<const IosDevice>();
|
|
|
|
|
if (iosDevice.isNull())
|
|
|
|
|
return 0;
|
|
|
|
|
QString osVersion = iosDevice->osVersion();
|
|
|
|
|
Utils::FileName deviceSdk1 = Utils::FileName::fromString(QDir::homePath()
|
|
|
|
|
+ QLatin1String("/Library/Developer/Xcode/iOS DeviceSupport/")
|
|
|
|
|
+ osVersion + QLatin1String("/Symbols"));
|
|
|
|
|
QString deviceSdk;
|
|
|
|
|
if (deviceSdk1.toFileInfo().isDir()) {
|
|
|
|
|
deviceSdk = deviceSdk1.toString();
|
|
|
|
|
} else {
|
|
|
|
|
Utils::FileName deviceSdk2 = IosConfigurations::developerPath()
|
|
|
|
|
.appendPath(QLatin1String("Platforms/iPhoneOS.platform/DeviceSupport/"))
|
|
|
|
|
.appendPath(osVersion).appendPath(QLatin1String("Symbols"));
|
|
|
|
|
if (deviceSdk2.toFileInfo().isDir()) {
|
|
|
|
|
deviceSdk = deviceSdk2.toString();
|
|
|
|
|
} else {
|
|
|
|
|
TaskHub::addTask(Task::Warning, tr(
|
|
|
|
|
"Could not find device specific debug symbols at %1. "
|
|
|
|
|
"Debugging initialization will be slow until you open the Organizer window of "
|
|
|
|
|
"Xcode with the device connected to have the symbols generated.")
|
|
|
|
|
.arg(deviceSdk1.toUserOutput()),
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
params.deviceSymbolsRoot = deviceSdk;
|
2013-10-31 10:07:28 +01:00
|
|
|
} else {
|
2013-10-10 15:15:49 +02:00
|
|
|
params.startMode = AttachExternal;
|
2013-10-31 10:07:28 +01:00
|
|
|
params.platform = QLatin1String("ios-simulator");
|
|
|
|
|
}
|
2014-04-10 11:35:36 +02:00
|
|
|
params.displayName = runConfig->applicationName();
|
2013-04-25 16:02:17 +02:00
|
|
|
params.remoteSetupNeeded = true;
|
2015-06-26 13:06:08 +02:00
|
|
|
params.continueAfterAttach = true;
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2015-06-26 13:06:08 +02:00
|
|
|
auto aspect = runConfig->extraAspect<DebuggerRunConfigurationAspect>();
|
2014-02-25 22:48:19 +01:00
|
|
|
bool cppDebug = aspect->useCppDebugger();
|
|
|
|
|
bool qmlDebug = aspect->useQmlDebugger();
|
|
|
|
|
if (cppDebug) {
|
2016-01-28 10:31:24 +01:00
|
|
|
params.inferior.executable = runConfig->localExecutable().toString();
|
2013-10-29 22:25:41 +01:00
|
|
|
params.remoteChannel = QLatin1String("connect://localhost:0");
|
2014-03-25 14:32:36 +01:00
|
|
|
|
|
|
|
|
Utils::FileName xcodeInfo = IosConfigurations::developerPath().parentDir()
|
|
|
|
|
.appendPath(QLatin1String("Info.plist"));
|
|
|
|
|
bool buggyLldb = false;
|
2014-10-24 13:15:54 +02:00
|
|
|
if (xcodeInfo.exists()) {
|
2014-03-25 14:32:36 +01:00
|
|
|
QSettings settings(xcodeInfo.toString(), QSettings::NativeFormat);
|
|
|
|
|
QStringList version = settings.value(QLatin1String("CFBundleShortVersionString")).toString()
|
|
|
|
|
.split(QLatin1Char('.'));
|
|
|
|
|
if (version.value(0).toInt() == 5 && version.value(1, QString::number(1)).toInt() == 0)
|
|
|
|
|
buggyLldb = true;
|
|
|
|
|
}
|
2014-04-10 11:35:36 +02:00
|
|
|
QString bundlePath = runConfig->bundleDirectory().toString();
|
2014-03-25 14:32:36 +01:00
|
|
|
bundlePath.chop(4);
|
|
|
|
|
Utils::FileName dsymPath = Utils::FileName::fromString(
|
|
|
|
|
bundlePath.append(QLatin1String(".dSYM")));
|
2014-10-24 13:15:54 +02:00
|
|
|
if (!dsymPath.exists()) {
|
2014-03-25 14:32:36 +01:00
|
|
|
if (buggyLldb)
|
|
|
|
|
TaskHub::addTask(Task::Warning,
|
|
|
|
|
tr("Debugging with Xcode 5.0.x can be unreliable without a dSYM. "
|
|
|
|
|
"To create one, add a dsymutil deploystep."),
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
|
|
|
|
|
} else if (dsymPath.toFileInfo().lastModified()
|
2014-04-10 11:35:36 +02:00
|
|
|
< QFileInfo(runConfig->localExecutable().toUserOutput()).lastModified()) {
|
2014-03-25 14:32:36 +01:00
|
|
|
TaskHub::addTask(Task::Warning,
|
|
|
|
|
tr("The dSYM %1 seems to be outdated, it might confuse the debugger.")
|
|
|
|
|
.arg(dsymPath.toUserOutput()),
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
|
|
|
|
|
}
|
2013-10-10 15:15:49 +02:00
|
|
|
}
|
2015-06-26 13:06:08 +02:00
|
|
|
if (qmlDebug && !cppDebug) {
|
|
|
|
|
params.startMode = AttachToRemoteServer;
|
2013-10-10 15:15:49 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-26 13:06:08 +02:00
|
|
|
DebuggerRunControl *debuggerRunControl = createDebuggerRunControl(params, runConfig, errorMessage);
|
2013-10-31 18:11:33 +01:00
|
|
|
if (debuggerRunControl)
|
2014-02-25 22:48:19 +01:00
|
|
|
new IosDebugSupport(runConfig, debuggerRunControl, cppDebug, qmlDebug);
|
2013-04-25 16:02:17 +02:00
|
|
|
return debuggerRunControl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IosDebugSupport::IosDebugSupport(IosRunConfiguration *runConfig,
|
2014-02-25 22:48:19 +01:00
|
|
|
DebuggerRunControl *runControl, bool cppDebug, bool qmlDebug)
|
2013-04-25 16:02:17 +02:00
|
|
|
: QObject(runControl), m_runControl(runControl),
|
2015-08-10 17:43:58 +02:00
|
|
|
m_runner(new IosRunner(this, runConfig, cppDebug, qmlDebug ? QmlDebug::QmlDebuggerServices :
|
|
|
|
|
QmlDebug::NoQmlDebugServices))
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2015-09-11 13:32:45 +02:00
|
|
|
connect(m_runControl, &DebuggerRunControl::requestRemoteSetup,
|
|
|
|
|
m_runner, &IosRunner::start);
|
|
|
|
|
connect(m_runControl, &RunControl::finished,
|
|
|
|
|
m_runner, &IosRunner::stop);
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &IosRunner::gotServerPorts,
|
|
|
|
|
this, &IosDebugSupport::handleServerPorts);
|
|
|
|
|
connect(m_runner, &IosRunner::gotInferiorPid,
|
|
|
|
|
this, &IosDebugSupport::handleGotInferiorPid);
|
|
|
|
|
connect(m_runner, &IosRunner::finished,
|
|
|
|
|
this, &IosDebugSupport::handleRemoteProcessFinished);
|
|
|
|
|
|
|
|
|
|
connect(m_runner, &IosRunner::errorMsg,
|
|
|
|
|
this, &IosDebugSupport::handleRemoteErrorOutput);
|
|
|
|
|
connect(m_runner, &IosRunner::appOutput,
|
|
|
|
|
this, &IosDebugSupport::handleRemoteOutput);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-10 15:15:49 +02:00
|
|
|
IosDebugSupport::~IosDebugSupport()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:43:30 +02:00
|
|
|
void IosDebugSupport::handleServerPorts(Utils::Port gdbServerPort, Utils::Port qmlPort)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2014-09-18 19:21:27 +02:00
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.gdbServerPort = gdbServerPort;
|
|
|
|
|
result.qmlServerPort = qmlPort;
|
2016-04-19 16:43:30 +02:00
|
|
|
result.success = gdbServerPort.isValid()
|
|
|
|
|
|| (m_runner && !m_runner->cppDebug() && qmlPort.isValid());
|
2014-09-18 19:21:27 +02:00
|
|
|
if (!result.success)
|
|
|
|
|
result.reason = tr("Could not get debug server file descriptor.");
|
2014-12-12 15:33:16 +01:00
|
|
|
m_runControl->notifyEngineRemoteSetupFinished(result);
|
2013-10-10 15:15:49 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:43:30 +02:00
|
|
|
void IosDebugSupport::handleGotInferiorPid(qint64 pid, Utils::Port qmlPort)
|
2013-10-10 15:15:49 +02:00
|
|
|
{
|
2014-09-18 19:21:27 +02:00
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.qmlServerPort = qmlPort;
|
2015-09-11 13:13:04 +02:00
|
|
|
result.inferiorPid = pid;
|
2014-09-18 19:21:27 +02:00
|
|
|
result.success = pid > 0;
|
|
|
|
|
if (!result.success)
|
|
|
|
|
result.reason = tr("Got an invalid process id.");
|
2014-12-12 15:33:16 +01:00
|
|
|
m_runControl->notifyEngineRemoteSetupFinished(result);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosDebugSupport::handleRemoteProcessFinished(bool cleanEnd)
|
|
|
|
|
{
|
2014-04-07 16:17:12 +02:00
|
|
|
if (m_runControl) {
|
|
|
|
|
if (!cleanEnd)
|
2014-10-17 13:06:37 +02:00
|
|
|
m_runControl->appendMessage(tr("Run ended with error."), Utils::DebugFormat);
|
2014-04-07 16:17:12 +02:00
|
|
|
else
|
2014-10-17 13:06:37 +02:00
|
|
|
m_runControl->appendMessage(tr("Run ended."), Utils::DebugFormat);
|
2014-12-12 15:33:16 +01:00
|
|
|
m_runControl->abortDebugger();
|
2014-04-07 16:17:12 +02:00
|
|
|
}
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosDebugSupport::handleRemoteOutput(const QString &output)
|
|
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
if (m_runControl)
|
|
|
|
|
m_runControl->showMessage(output, AppOutput);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosDebugSupport::handleRemoteErrorOutput(const QString &output)
|
|
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
if (m_runControl)
|
|
|
|
|
m_runControl->showMessage(output, AppError);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Ios
|