2013-04-25 16:02:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2013-04-25 16:02:17 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** 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.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** 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.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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/debuggerengine.h>
|
|
|
|
|
#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-10-29 16:19:24 +01:00
|
|
|
#include <qmakeprojectmanager/qmakebuildconfiguration.h>
|
|
|
|
|
#include <qmakeprojectmanager/qmakenodes.h>
|
|
|
|
|
#include <qmakeprojectmanager/qmakeproject.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
|
|
|
|
|
|
|
|
#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;
|
2013-10-16 11:02:37 +02:00
|
|
|
using namespace QmakeProjectManager;
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
ProjectExplorer::IDevice::ConstPtr device = DeviceKitInformation::device(target->kit());
|
|
|
|
|
if (device.isNull())
|
|
|
|
|
return 0;
|
2013-10-29 14:22:31 +01:00
|
|
|
QmakeProject *project = static_cast<QmakeProject *>(target->project());
|
2013-12-10 12:53:20 +01:00
|
|
|
Kit *kit = target->kit();
|
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;
|
2013-11-19 10:45:00 +01:00
|
|
|
if (!params.breakOnMain)
|
|
|
|
|
params.continueAfterAttach = true;
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2013-10-10 15:15:49 +02:00
|
|
|
Debugger::DebuggerRunConfigurationAspect *aspect
|
|
|
|
|
= runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
|
2014-02-25 22:48:19 +01:00
|
|
|
bool cppDebug = aspect->useCppDebugger();
|
|
|
|
|
bool qmlDebug = aspect->useQmlDebugger();
|
|
|
|
|
if (cppDebug) {
|
2013-10-10 15:15:49 +02:00
|
|
|
params.languages |= CppLanguage;
|
|
|
|
|
params.sysRoot = SysRootKitInformation::sysRoot(kit).toString();
|
|
|
|
|
params.debuggerCommand = DebuggerKitInformation::debuggerCommand(kit).toString();
|
|
|
|
|
if (ToolChain *tc = ToolChainKitInformation::toolChain(kit))
|
|
|
|
|
params.toolChainAbi = tc->targetAbi();
|
2014-04-10 11:35:36 +02:00
|
|
|
params.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;
|
|
|
|
|
if (xcodeInfo.toFileInfo().exists()) {
|
|
|
|
|
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")));
|
|
|
|
|
if (!dsymPath.toFileInfo().exists()) {
|
|
|
|
|
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
|
|
|
}
|
2014-02-25 22:48:19 +01:00
|
|
|
if (qmlDebug) {
|
2013-10-10 15:15:49 +02:00
|
|
|
params.languages |= QmlLanguage;
|
2014-05-02 12:53:36 +02:00
|
|
|
params.projectSourceDirectory = project->projectDirectory().toString();
|
2013-10-29 14:22:31 +01:00
|
|
|
params.projectSourceFiles = project->files(QmakeProject::ExcludeGeneratedFiles);
|
|
|
|
|
params.projectBuildDirectory = project->rootQmakeProjectNode()->buildDir();
|
2014-02-25 22:48:19 +01:00
|
|
|
if (!cppDebug)
|
|
|
|
|
params.startMode = AttachToRemoteServer;
|
2013-10-10 15:15:49 +02:00
|
|
|
}
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
DebuggerRunControl * const debuggerRunControl
|
2014-10-17 13:40:04 +02:00
|
|
|
= DebuggerRunControlFactory::doCreate(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),
|
2014-02-25 22:48:19 +01:00
|
|
|
m_runner(new IosRunner(this, runConfig, cppDebug, qmlDebug))
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
connect(m_runControl->engine(), SIGNAL(requestRemoteSetup()),
|
|
|
|
|
m_runner, SLOT(start()));
|
|
|
|
|
connect(m_runControl, SIGNAL(finished()),
|
|
|
|
|
m_runner, SLOT(stop()));
|
|
|
|
|
|
2014-02-25 22:48:19 +01:00
|
|
|
connect(m_runner, SIGNAL(gotServerPorts(int,int)),
|
|
|
|
|
SLOT(handleServerPorts(int,int)));
|
|
|
|
|
connect(m_runner, SIGNAL(gotInferiorPid(Q_PID, int)),
|
|
|
|
|
SLOT(handleGotInferiorPid(Q_PID, int)));
|
2013-04-25 16:02:17 +02:00
|
|
|
connect(m_runner, SIGNAL(finished(bool)),
|
|
|
|
|
SLOT(handleRemoteProcessFinished(bool)));
|
|
|
|
|
|
|
|
|
|
connect(m_runner, SIGNAL(errorMsg(QString)),
|
|
|
|
|
SLOT(handleRemoteErrorOutput(QString)));
|
|
|
|
|
connect(m_runner, SIGNAL(appOutput(QString)),
|
|
|
|
|
SLOT(handleRemoteOutput(QString)));
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 15:15:49 +02:00
|
|
|
IosDebugSupport::~IosDebugSupport()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 22:48:19 +01:00
|
|
|
void IosDebugSupport::handleServerPorts(int gdbServerPort, int 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;
|
|
|
|
|
result.success = gdbServerPort > 0 || (m_runner && !m_runner->cppDebug() && qmlPort > 0);
|
|
|
|
|
if (!result.success)
|
|
|
|
|
result.reason = tr("Could not get debug server file descriptor.");
|
|
|
|
|
m_runControl->engine()->notifyEngineRemoteSetupFinished(result);
|
2013-10-10 15:15:49 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-25 22:48:19 +01:00
|
|
|
void IosDebugSupport::handleGotInferiorPid(Q_PID pid, int qmlPort)
|
2013-10-10 15:15:49 +02:00
|
|
|
{
|
2014-09-18 19:21:27 +02:00
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.qmlServerPort = qmlPort;
|
|
|
|
|
result.inferiorPid = int(Utils::qPidToPid(pid));
|
|
|
|
|
result.success = pid > 0;
|
|
|
|
|
if (!result.success)
|
|
|
|
|
result.reason = tr("Got an invalid process id.");
|
|
|
|
|
m_runControl->engine()->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-04-07 16:17:12 +02:00
|
|
|
m_runControl->engine()->abortDebugger();
|
|
|
|
|
}
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosDebugSupport::handleRemoteOutput(const QString &output)
|
|
|
|
|
{
|
|
|
|
|
if (m_runControl) {
|
|
|
|
|
if (m_runControl->engine())
|
|
|
|
|
m_runControl->engine()->showMessage(output, AppOutput);
|
|
|
|
|
else
|
2014-10-17 13:06:37 +02:00
|
|
|
m_runControl->appendMessage(output, Utils::StdOutFormatSameLine);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosDebugSupport::handleRemoteErrorOutput(const QString &output)
|
|
|
|
|
{
|
|
|
|
|
if (m_runControl) {
|
|
|
|
|
if (m_runControl->engine())
|
2014-01-09 15:47:05 +01:00
|
|
|
m_runControl->engine()->showMessage(output, AppError);
|
2013-04-25 16:02:17 +02:00
|
|
|
else
|
2014-10-17 13:06:37 +02:00
|
|
|
m_runControl->appendMessage(output, Utils::StdErrFormatSameLine);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Ios
|