2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01: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.
|
2008-12-02 14:17:16 +01: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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2014-10-17 13:40:04 +02:00
|
|
|
#include "debuggerruncontrol.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
#include "analyzer/analyzermanager.h"
|
2017-04-10 13:57:05 +02:00
|
|
|
#include "console/console.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
#include "debuggeractions.h"
|
2010-11-10 11:39:01 +01:00
|
|
|
#include "debuggercore.h"
|
2013-03-22 10:28:49 +01:00
|
|
|
#include "debuggerengine.h"
|
|
|
|
#include "debuggerkitinformation.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
#include "debuggerplugin.h"
|
2013-03-27 13:03:15 +01:00
|
|
|
#include "debuggerrunconfigurationaspect.h"
|
2011-01-10 10:14:23 +01:00
|
|
|
#include "debuggerstartparameters.h"
|
2013-03-22 10:28:49 +01:00
|
|
|
#include "breakhandler.h"
|
2014-02-19 15:35:58 +01:00
|
|
|
#include "shared/peutils.h"
|
2010-06-22 12:28:05 +02:00
|
|
|
|
2012-08-15 13:21:37 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2014-10-20 14:03:47 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
|
|
|
|
#include <projectexplorer/devicesupport/deviceprocesslist.h>
|
|
|
|
#include <projectexplorer/environmentaspect.h> // For the environment
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2012-08-15 13:21:37 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2016-03-25 23:06:17 +01:00
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
2016-01-25 15:00:20 +01:00
|
|
|
#include <projectexplorer/runnables.h>
|
2017-04-11 13:45:37 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2010-02-08 15:50:06 +01:00
|
|
|
#include <projectexplorer/target.h>
|
2012-11-02 16:14:43 +01:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2014-10-20 14:03:47 +02:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-13 16:12:04 +02:00
|
|
|
#include <utils/checkablemessagebox.h>
|
2013-10-23 22:07:46 +03:00
|
|
|
#include <utils/fileutils.h>
|
2017-05-04 12:12:27 +02:00
|
|
|
#include <utils/portlist.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-12-15 13:06:39 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2017-05-04 12:12:27 +02:00
|
|
|
|
2009-10-08 17:23:27 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2015-10-19 12:55:13 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2017-08-21 14:32:15 +02:00
|
|
|
#include <coreplugin/messagebox.h>
|
2015-08-10 17:43:58 +02:00
|
|
|
#include <qmldebug/qmldebugcommandlinearguments.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
2013-04-17 17:45:53 +02:00
|
|
|
#include <QTcpServer>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-06-14 17:23:25 +02:00
|
|
|
using namespace Debugger::Internal;
|
2012-08-09 03:58:37 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
using namespace Utils;
|
2010-06-14 17:23:25 +02:00
|
|
|
|
2011-02-25 09:34:31 +01:00
|
|
|
enum { debug = 0 };
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
namespace Debugger {
|
2011-01-11 11:06:15 +01:00
|
|
|
namespace Internal {
|
2011-01-12 12:10:12 +01:00
|
|
|
|
2017-05-05 14:45:36 +02:00
|
|
|
DebuggerEngine *createCdbEngine(QStringList *error, DebuggerStartMode sm);
|
|
|
|
DebuggerEngine *createGdbEngine(bool useTerminal, DebuggerStartMode sm);
|
|
|
|
DebuggerEngine *createPdbEngine();
|
|
|
|
DebuggerEngine *createQmlEngine(bool useTerminal);
|
|
|
|
DebuggerEngine *createQmlCppEngine(DebuggerEngine *cppEngine, bool useTerminal);
|
|
|
|
DebuggerEngine *createLldbEngine();
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2017-08-21 14:32:15 +02:00
|
|
|
|
|
|
|
class LocalProcessRunner : public RunWorker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LocalProcessRunner(RunControl *runControl, const StandardRunnable &runnable)
|
|
|
|
: RunWorker(runControl), m_runnable(runnable)
|
|
|
|
{
|
|
|
|
connect(&m_proc, &QProcess::errorOccurred,
|
|
|
|
this, &LocalProcessRunner::handleError);
|
|
|
|
connect(&m_proc, &QProcess::readyReadStandardOutput,
|
|
|
|
this, &LocalProcessRunner::handleStandardOutput);
|
|
|
|
connect(&m_proc, &QProcess::readyReadStandardError,
|
|
|
|
this, &LocalProcessRunner::handleStandardError);
|
|
|
|
connect(&m_proc, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
|
|
|
|
this, &LocalProcessRunner::handleFinished);
|
|
|
|
}
|
|
|
|
|
|
|
|
void start() override
|
|
|
|
{
|
|
|
|
m_proc.setCommand(m_runnable.executable, m_runnable.commandLineArguments);
|
|
|
|
m_proc.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void stop() override
|
|
|
|
{
|
|
|
|
m_proc.terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleStandardOutput()
|
|
|
|
{
|
|
|
|
const QByteArray ba = m_proc.readAllStandardOutput();
|
|
|
|
const QString msg = QString::fromLocal8Bit(ba, ba.length());
|
|
|
|
showMessage(msg, LogOutput);
|
|
|
|
showMessage(msg, AppOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleStandardError()
|
|
|
|
{
|
|
|
|
const QByteArray ba = m_proc.readAllStandardError();
|
|
|
|
const QString msg = QString::fromLocal8Bit(ba, ba.length());
|
|
|
|
showMessage(msg, LogOutput);
|
|
|
|
showMessage(msg, AppError);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleFinished()
|
|
|
|
{
|
|
|
|
if (m_proc.exitStatus() == QProcess::NormalExit && m_proc.exitCode() == 0) {
|
|
|
|
// all good.
|
|
|
|
reportDone();
|
|
|
|
} else {
|
|
|
|
reportFailure(tr("Upload failed: %1").arg(m_proc.errorString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleError(QProcess::ProcessError error)
|
|
|
|
{
|
|
|
|
QString msg;
|
|
|
|
switch (error) {
|
|
|
|
case QProcess::FailedToStart:
|
|
|
|
msg = tr("The upload process failed to start. Shell missing?");
|
|
|
|
break;
|
|
|
|
case QProcess::Crashed:
|
|
|
|
msg = tr("The upload process crashed some time after starting "
|
|
|
|
"successfully.");
|
|
|
|
break;
|
|
|
|
case QProcess::Timedout:
|
|
|
|
msg = tr("The last waitFor...() function timed out. "
|
|
|
|
"The state of QProcess is unchanged, and you can try calling "
|
|
|
|
"waitFor...() again.");
|
|
|
|
break;
|
|
|
|
case QProcess::WriteError:
|
|
|
|
msg = tr("An error occurred when attempting to write "
|
|
|
|
"to the upload process. For example, the process may not be running, "
|
|
|
|
"or it may have closed its input channel.");
|
|
|
|
break;
|
|
|
|
case QProcess::ReadError:
|
|
|
|
msg = tr("An error occurred when attempting to read from "
|
|
|
|
"the upload process. For example, the process may not be running.");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msg = tr("An unknown error in the upload process occurred. "
|
|
|
|
"This is the default return value of error().");
|
|
|
|
}
|
|
|
|
|
|
|
|
showMessage(msg, StatusBar);
|
|
|
|
Core::AsynchronousMessageBox::critical(tr("Error"), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
StandardRunnable m_runnable;
|
|
|
|
Utils::QtcProcess m_proc;
|
|
|
|
};
|
|
|
|
|
2014-10-17 12:37:30 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
2015-06-24 08:26:35 +02:00
|
|
|
|
2017-07-07 19:11:32 +02:00
|
|
|
static bool breakOnMainNextTime = false;
|
|
|
|
|
|
|
|
void DebuggerRunTool::setBreakOnMainNextTime()
|
|
|
|
{
|
|
|
|
breakOnMainNextTime = true;
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:46:23 +02:00
|
|
|
void DebuggerRunTool::setStartMode(DebuggerStartMode startMode)
|
|
|
|
{
|
|
|
|
m_runParameters.startMode = startMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::setCloseMode(DebuggerCloseMode closeMode)
|
|
|
|
{
|
|
|
|
m_runParameters.closeMode = closeMode;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:53:31 +02:00
|
|
|
void DebuggerRunTool::setAttachPid(ProcessHandle pid)
|
|
|
|
{
|
|
|
|
m_runParameters.attachPID = pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::setSysRoot(const QString &sysRoot)
|
|
|
|
{
|
|
|
|
m_runParameters.sysRoot = sysRoot;
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:46:23 +02:00
|
|
|
void DebuggerRunTool::setSymbolFile(const QString &symbolFile)
|
|
|
|
{
|
|
|
|
if (symbolFile.isEmpty())
|
|
|
|
reportFailure(tr("Cannot debug: Local executable is not set."));
|
|
|
|
m_runParameters.symbolFile = symbolFile;
|
|
|
|
}
|
|
|
|
|
2017-08-24 17:38:06 +02:00
|
|
|
void DebuggerRunTool::setRemoteChannel(const QString &channel)
|
2017-08-24 15:46:23 +02:00
|
|
|
{
|
|
|
|
m_runParameters.remoteChannel = channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::setUseExtendedRemote(bool on)
|
|
|
|
{
|
|
|
|
m_runParameters.useExtendedRemote = on;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:53:31 +02:00
|
|
|
void DebuggerRunTool::setUseContinueInsteadOfRun(bool on)
|
|
|
|
{
|
|
|
|
m_runParameters.useContinueInsteadOfRun = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::setUseTargetAsync(bool on)
|
|
|
|
{
|
|
|
|
m_runParameters.useTargetAsync = on;
|
|
|
|
}
|
|
|
|
|
2017-08-24 17:38:06 +02:00
|
|
|
void DebuggerRunTool::setContinueAfterAttach(bool on)
|
|
|
|
{
|
|
|
|
m_runParameters.continueAfterAttach = on;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:53:31 +02:00
|
|
|
void DebuggerRunTool::setSkipExecutableValidation(bool on)
|
|
|
|
{
|
|
|
|
m_runParameters.skipExecutableValidation = on;
|
|
|
|
}
|
|
|
|
|
2017-08-25 12:53:44 +02:00
|
|
|
void DebuggerRunTool::setCommandsAfterConnect(const QString &commands)
|
|
|
|
{
|
|
|
|
m_runParameters.commandsAfterConnect = commands;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::setCommandsForReset(const QString &commands)
|
|
|
|
{
|
|
|
|
m_runParameters.commandsForReset = commands;
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:46:23 +02:00
|
|
|
void DebuggerRunTool::setQmlServer(const QUrl &qmlServer)
|
|
|
|
{
|
|
|
|
m_runParameters.qmlServer = qmlServer;
|
|
|
|
}
|
|
|
|
|
2017-08-24 17:38:06 +02:00
|
|
|
void DebuggerRunTool::setIosPlatform(const QString &platform)
|
|
|
|
{
|
|
|
|
m_runParameters.platform = platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::setDeviceSymbolsRoot(const QString &deviceSymbolsRoot)
|
|
|
|
{
|
|
|
|
m_runParameters.deviceSymbolsRoot = deviceSymbolsRoot;
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:17:43 +02:00
|
|
|
void DebuggerRunTool::setNeedFixup(bool on)
|
|
|
|
{
|
|
|
|
m_runParameters.needFixup = on;
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:46:23 +02:00
|
|
|
void DebuggerRunTool::setInferior(const Runnable &runnable)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(runnable.is<StandardRunnable>(), reportFailure(); return);
|
|
|
|
m_runParameters.inferior = runnable.as<StandardRunnable>();
|
|
|
|
}
|
|
|
|
|
2017-08-24 17:38:06 +02:00
|
|
|
void DebuggerRunTool::setInferiorExecutable(const QString &executable)
|
|
|
|
{
|
|
|
|
m_runParameters.inferior.executable = executable;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:04:25 +02:00
|
|
|
void DebuggerRunTool::setRunControlName(const QString &name)
|
|
|
|
{
|
|
|
|
m_runParameters.displayName = name;
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:46:23 +02:00
|
|
|
void DebuggerRunTool::appendInferiorCommandLineArgument(const QString &arg)
|
|
|
|
{
|
|
|
|
if (!m_runParameters.inferior.commandLineArguments.isEmpty())
|
|
|
|
m_runParameters.inferior.commandLineArguments.append(' ');
|
|
|
|
m_runParameters.inferior.commandLineArguments.append(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::prependInferiorCommandLineArgument(const QString &arg)
|
|
|
|
{
|
|
|
|
if (!m_runParameters.inferior.commandLineArguments.isEmpty())
|
|
|
|
m_runParameters.inferior.commandLineArguments.prepend(' ');
|
|
|
|
m_runParameters.inferior.commandLineArguments.prepend(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::addQmlServerInferiorCommandLineArgumentIfNeeded()
|
|
|
|
{
|
|
|
|
if (isQmlDebugging() && isCppDebugging()) {
|
|
|
|
using namespace QmlDebug;
|
|
|
|
int qmlServerPort = m_runParameters.qmlServer.port();
|
|
|
|
QTC_ASSERT(qmlServerPort > 0, reportFailure(); return);
|
|
|
|
QString mode = QString("port:%1").arg(qmlServerPort);
|
|
|
|
QString qmlServerArg = qmlDebugCommandLineArguments(QmlDebuggerServices, mode, true);
|
|
|
|
prependInferiorCommandLineArgument(qmlServerArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:53:31 +02:00
|
|
|
void DebuggerRunTool::addExpectedSignal(const QString &signal)
|
|
|
|
{
|
|
|
|
m_runParameters.expectedSignals.append(signal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::addSearchDirectory(const QString &dir)
|
|
|
|
{
|
|
|
|
m_runParameters.additionalSearchDirectories.append(dir);
|
|
|
|
}
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QLatin1String engineTypeName(DebuggerEngineType et)
|
2011-02-24 16:50:15 +01:00
|
|
|
{
|
|
|
|
switch (et) {
|
|
|
|
case Debugger::NoEngineType:
|
|
|
|
break;
|
|
|
|
case Debugger::GdbEngineType:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("Gdb engine");
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::CdbEngineType:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("Cdb engine");
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::PdbEngineType:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("Pdb engine");
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::QmlEngineType:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("QML engine");
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::QmlCppEngineType:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("QML C++ engine");
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::LldbEngineType:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("LLDB command line engine");
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::AllEngineTypes:
|
|
|
|
break;
|
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("No engine");
|
2011-02-24 16:50:15 +01:00
|
|
|
}
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void DebuggerRunTool::start()
|
2010-06-15 09:13:22 +02:00
|
|
|
{
|
2016-03-17 10:11:38 +01:00
|
|
|
Debugger::Internal::saveModeToRestore();
|
2016-03-02 13:57:37 +01:00
|
|
|
Debugger::selectPerspective(Debugger::Constants::CppPerspectiveId);
|
2015-06-24 08:26:35 +02:00
|
|
|
TaskHub::clearTasks(Debugger::Constants::TASK_CATEGORY_DEBUGGER_DEBUGINFO);
|
|
|
|
TaskHub::clearTasks(Debugger::Constants::TASK_CATEGORY_DEBUGGER_RUNTIME);
|
|
|
|
|
2017-07-05 15:17:38 +02:00
|
|
|
setupEngine();
|
2017-04-21 17:20:57 +02:00
|
|
|
DebuggerEngine *engine = m_engine;
|
2017-05-09 10:25:11 +02:00
|
|
|
|
2017-04-07 10:21:27 +02:00
|
|
|
QTC_ASSERT(engine, return);
|
|
|
|
const DebuggerRunParameters &rp = engine->runParameters();
|
2011-04-18 13:01:12 +02:00
|
|
|
// User canceled input dialog asking for executable when working on library project.
|
2017-04-07 10:21:27 +02:00
|
|
|
if (rp.startMode == StartInternal
|
|
|
|
&& rp.inferior.executable.isEmpty()
|
|
|
|
&& rp.interpreter.isEmpty()) {
|
2017-05-04 12:12:27 +02:00
|
|
|
reportFailure(tr("No executable specified.") + '\n');
|
2011-04-18 13:01:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-07 10:21:27 +02:00
|
|
|
if (rp.startMode == StartInternal) {
|
2014-03-17 18:27:26 +01:00
|
|
|
QStringList unhandledIds;
|
2015-01-10 01:07:01 +01:00
|
|
|
foreach (Breakpoint bp, breakHandler()->allBreakpoints()) {
|
2017-04-07 10:21:27 +02:00
|
|
|
if (bp.isEnabled() && !engine->acceptsBreakpoint(bp))
|
2015-01-10 01:07:01 +01:00
|
|
|
unhandledIds.append(bp.id().toString());
|
2014-03-17 18:27:26 +01:00
|
|
|
}
|
|
|
|
if (!unhandledIds.isEmpty()) {
|
|
|
|
QString warningMessage =
|
|
|
|
DebuggerPlugin::tr("Some breakpoints cannot be handled by the debugger "
|
|
|
|
"languages currently active, and will be ignored.\n"
|
|
|
|
"Affected are breakpoints %1")
|
|
|
|
.arg(unhandledIds.join(QLatin1String(", ")));
|
2011-08-08 15:38:05 +02:00
|
|
|
|
2014-10-22 13:04:47 +02:00
|
|
|
Internal::showMessage(warningMessage, LogWarning);
|
2011-08-08 15:38:05 +02:00
|
|
|
|
2014-03-17 18:27:26 +01:00
|
|
|
static bool checked = true;
|
|
|
|
if (checked)
|
2013-10-16 17:11:39 +02:00
|
|
|
CheckableMessageBox::information(Core::ICore::mainWindow(),
|
2013-09-13 16:12:04 +02:00
|
|
|
tr("Debugger"),
|
|
|
|
warningMessage,
|
|
|
|
tr("&Show this message again."),
|
|
|
|
&checked, QDialogButtonBox::Ok);
|
2011-04-28 14:05:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 16:40:49 +02:00
|
|
|
appendMessage(tr("Debugging starts"), NormalMessageFormat);
|
2017-05-05 14:45:36 +02:00
|
|
|
Internal::runControlStarted(this);
|
2017-04-27 15:39:30 +02:00
|
|
|
engine->start();
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 17:20:57 +02:00
|
|
|
void DebuggerRunTool::startFailed()
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2017-05-23 16:40:49 +02:00
|
|
|
appendMessage(tr("Debugging has failed"), NormalMessageFormat);
|
2017-04-21 17:20:57 +02:00
|
|
|
m_engine->handleStartFailed();
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2017-04-27 09:53:07 +02:00
|
|
|
void DebuggerRunTool::stop()
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2017-05-19 11:54:13 +02:00
|
|
|
m_isDying = true;
|
2017-05-19 14:40:49 +02:00
|
|
|
QTC_ASSERT(m_engine, reportStopped(); return);
|
2017-05-19 11:54:13 +02:00
|
|
|
m_engine->quitDebugger();
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 17:20:57 +02:00
|
|
|
void DebuggerRunTool::debuggingFinished()
|
2014-12-12 15:33:16 +01:00
|
|
|
{
|
2017-05-05 14:45:36 +02:00
|
|
|
appendMessage(tr("Debugging has finished"), NormalMessageFormat);
|
2017-05-23 16:40:49 +02:00
|
|
|
Internal::runControlFinished(this);
|
2017-05-09 10:25:11 +02:00
|
|
|
reportStopped();
|
2014-12-12 15:33:16 +01:00
|
|
|
}
|
|
|
|
|
2017-05-05 14:45:36 +02:00
|
|
|
DebuggerRunParameters &DebuggerRunTool::runParameters()
|
|
|
|
{
|
|
|
|
return m_runParameters;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DebuggerRunParameters &DebuggerRunTool::runParameters() const
|
2014-12-12 15:33:16 +01:00
|
|
|
{
|
2017-05-05 14:45:36 +02:00
|
|
|
return m_runParameters;
|
2014-12-12 15:33:16 +01:00
|
|
|
}
|
|
|
|
|
2017-05-04 12:12:27 +02:00
|
|
|
int DebuggerRunTool::portsUsedByDebugger() const
|
|
|
|
{
|
|
|
|
return isCppDebugging() + isQmlDebugging();
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:53:31 +02:00
|
|
|
void DebuggerRunTool::setSolibSearchPath(const QStringList &list)
|
|
|
|
{
|
|
|
|
m_runParameters.solibSearchPath = list;
|
|
|
|
}
|
|
|
|
|
2017-04-21 17:20:57 +02:00
|
|
|
void DebuggerRunTool::notifyInferiorIll()
|
2014-12-12 15:33:16 +01:00
|
|
|
{
|
2017-04-21 17:20:57 +02:00
|
|
|
m_engine->notifyInferiorIll();
|
2014-12-12 15:33:16 +01:00
|
|
|
}
|
|
|
|
|
2017-04-21 17:20:57 +02:00
|
|
|
void DebuggerRunTool::notifyInferiorExited()
|
2014-12-12 15:33:16 +01:00
|
|
|
{
|
2017-04-21 17:20:57 +02:00
|
|
|
m_engine->notifyInferiorExited();
|
2014-12-12 15:33:16 +01:00
|
|
|
}
|
|
|
|
|
2017-04-21 17:20:57 +02:00
|
|
|
void DebuggerRunTool::quitDebugger()
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2017-05-19 11:54:13 +02:00
|
|
|
m_isDying = true;
|
2017-04-21 17:20:57 +02:00
|
|
|
m_engine->quitDebugger();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::abortDebugger()
|
|
|
|
{
|
|
|
|
m_engine->abortDebugger();
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2015-06-24 08:26:35 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
2010-12-15 09:17:31 +01:00
|
|
|
//
|
2015-06-24 08:26:35 +02:00
|
|
|
// DebuggerRunControlCreator
|
2010-12-15 09:17:31 +01:00
|
|
|
//
|
2015-06-24 08:26:35 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-05-27 16:09:43 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
2016-04-12 16:42:15 +02:00
|
|
|
// Re-used for Combined C++/QML engine.
|
2017-05-05 14:45:36 +02:00
|
|
|
DebuggerEngine *createEngine(DebuggerEngineType cppEngineType,
|
|
|
|
DebuggerEngineType et,
|
|
|
|
DebuggerStartMode sm,
|
|
|
|
bool useTerminal,
|
|
|
|
QStringList *errors)
|
2015-05-27 13:59:56 +02:00
|
|
|
{
|
2017-04-06 20:03:18 +02:00
|
|
|
DebuggerEngine *engine = nullptr;
|
2016-04-12 16:42:15 +02:00
|
|
|
switch (et) {
|
|
|
|
case GdbEngineType:
|
2017-05-05 14:45:36 +02:00
|
|
|
engine = createGdbEngine(useTerminal, sm);
|
2017-04-06 20:03:18 +02:00
|
|
|
break;
|
2016-04-12 16:42:15 +02:00
|
|
|
case CdbEngineType:
|
2017-05-05 14:45:36 +02:00
|
|
|
engine = createCdbEngine(errors, sm);
|
2017-04-06 20:03:18 +02:00
|
|
|
break;
|
2016-04-12 16:42:15 +02:00
|
|
|
case PdbEngineType:
|
2017-05-05 14:45:36 +02:00
|
|
|
engine = createPdbEngine();
|
2017-04-06 20:03:18 +02:00
|
|
|
break;
|
2016-04-12 16:42:15 +02:00
|
|
|
case QmlEngineType:
|
2017-05-05 14:45:36 +02:00
|
|
|
engine = createQmlEngine(useTerminal);
|
2017-04-06 20:03:18 +02:00
|
|
|
break;
|
2016-04-12 16:42:15 +02:00
|
|
|
case LldbEngineType:
|
2017-05-05 14:45:36 +02:00
|
|
|
engine = createLldbEngine();
|
2017-04-06 20:03:18 +02:00
|
|
|
break;
|
2017-05-05 14:45:36 +02:00
|
|
|
case QmlCppEngineType: {
|
|
|
|
DebuggerEngine *cppEngine = createEngine(cppEngineType, cppEngineType, sm, useTerminal, errors);
|
|
|
|
if (cppEngine) {
|
|
|
|
engine = createQmlCppEngine(cppEngine, useTerminal);
|
|
|
|
} else {
|
2017-07-28 09:48:02 +02:00
|
|
|
errors->append(DebuggerPlugin::tr("The debugging engine required for combined "
|
|
|
|
"QML/C++ debugging could not be created: %1"));
|
2017-05-05 14:45:36 +02:00
|
|
|
}
|
2017-04-06 20:03:18 +02:00
|
|
|
break;
|
2017-05-05 14:45:36 +02:00
|
|
|
}
|
2016-04-12 16:42:15 +02:00
|
|
|
default:
|
2017-04-06 20:03:18 +02:00
|
|
|
errors->append(DebuggerPlugin::tr("Unknown debugger type \"%1\"")
|
|
|
|
.arg(engineTypeName(et)));
|
2016-04-12 16:42:15 +02:00
|
|
|
}
|
2017-04-06 20:03:18 +02:00
|
|
|
if (!engine)
|
2017-07-28 09:48:02 +02:00
|
|
|
errors->append(DebuggerPlugin::tr("Unable to create a debugging engine of the type \"%1\"").
|
2017-05-05 14:45:36 +02:00
|
|
|
arg(engineTypeName(et)));
|
2017-04-06 20:03:18 +02:00
|
|
|
return engine;
|
2015-05-27 13:59:56 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 10:10:25 +02:00
|
|
|
static bool fixupParameters(DebuggerRunParameters &rp, RunControl *runControl, QStringList &m_errors)
|
2012-08-15 13:21:37 +02:00
|
|
|
{
|
2017-04-21 10:10:25 +02:00
|
|
|
RunConfiguration *runConfig = runControl->runConfiguration();
|
2017-05-30 15:38:06 +02:00
|
|
|
if (!runConfig)
|
|
|
|
return false;
|
2017-04-11 13:45:37 +02:00
|
|
|
|
|
|
|
const Kit *kit = runConfig->target()->kit();
|
2017-04-06 20:03:18 +02:00
|
|
|
QTC_ASSERT(kit, return false);
|
2016-01-28 17:58:53 +01:00
|
|
|
|
2015-06-24 08:26:35 +02:00
|
|
|
// Extract as much as possible from available RunConfiguration.
|
2017-07-14 00:16:55 +03:00
|
|
|
const Runnable runnable = runConfig->runnable();
|
2017-08-14 17:18:31 +02:00
|
|
|
if (rp.needFixup && runnable.is<StandardRunnable>()) {
|
2017-07-05 18:07:03 +03:00
|
|
|
// FIXME: Needed for core dump which stores the executable in inferior, but not in runConfig
|
|
|
|
// executable.
|
|
|
|
const QString prevExecutable = rp.inferior.executable;
|
2017-07-14 00:16:55 +03:00
|
|
|
rp.inferior = runnable.as<StandardRunnable>();
|
2017-07-05 18:07:03 +03:00
|
|
|
if (rp.inferior.executable.isEmpty())
|
|
|
|
rp.inferior.executable = prevExecutable;
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.useTerminal = rp.inferior.runMode == ApplicationLauncher::Console;
|
2015-06-24 08:26:35 +02:00
|
|
|
// Normalize to work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch'...)
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.inferior.workingDirectory = FileUtils::normalizePathName(rp.inferior.workingDirectory);
|
2010-12-15 09:34:02 +01:00
|
|
|
}
|
|
|
|
|
2015-07-23 11:23:58 +02:00
|
|
|
// We might get an executable from a local PID.
|
2017-08-14 17:18:31 +02:00
|
|
|
if (rp.needFixup && rp.inferior.executable.isEmpty() && rp.attachPID.isValid()) {
|
2017-05-31 13:03:38 +02:00
|
|
|
foreach (const DeviceProcessItem &p, DeviceProcessList::localProcesses()) {
|
|
|
|
if (p.pid == rp.attachPID.pid()) {
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.inferior.executable = p.exe;
|
2017-05-31 13:03:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-09-05 12:42:41 +02:00
|
|
|
}
|
2014-10-20 14:03:47 +02:00
|
|
|
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.macroExpander = kit->macroExpander();
|
2016-05-03 11:49:01 +02:00
|
|
|
if (rp.symbolFile.isEmpty())
|
|
|
|
rp.symbolFile = rp.inferior.executable;
|
2016-03-22 10:47:03 +01:00
|
|
|
|
2016-07-29 15:55:15 +02:00
|
|
|
rp.debugger = DebuggerKitInformation::runnable(kit);
|
|
|
|
const QByteArray envBinary = qgetenv("QTC_DEBUGGER_PATH");
|
|
|
|
if (!envBinary.isEmpty())
|
|
|
|
rp.debugger.executable = QString::fromLocal8Bit(envBinary);
|
|
|
|
|
2017-08-14 17:18:31 +02:00
|
|
|
if (rp.needFixup) {
|
|
|
|
if (auto envAspect = runConfig->extraAspect<EnvironmentAspect>()) {
|
|
|
|
rp.inferior.environment = envAspect->environment(); // Correct.
|
|
|
|
rp.stubEnvironment = rp.inferior.environment; // FIXME: Wrong, but contains DYLD_IMAGE_SUFFIX
|
2016-07-29 15:55:15 +02:00
|
|
|
|
2017-08-14 17:18:31 +02:00
|
|
|
// Copy over DYLD_IMAGE_SUFFIX etc
|
|
|
|
for (auto var : QStringList({"DYLD_IMAGE_SUFFIX", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH"}))
|
|
|
|
if (rp.inferior.environment.hasKey(var))
|
|
|
|
rp.debugger.environment.set(var, rp.inferior.environment.value(var));
|
|
|
|
}
|
2017-05-30 15:38:06 +02:00
|
|
|
}
|
|
|
|
if (Project *project = runConfig->target()->project()) {
|
|
|
|
rp.projectSourceDirectory = project->projectDirectory().toString();
|
|
|
|
rp.projectSourceFiles = project->files(Project::SourceFiles);
|
2015-06-24 08:26:35 +02:00
|
|
|
}
|
|
|
|
|
2016-07-13 10:40:05 +02:00
|
|
|
rp.toolChainAbi = ToolChainKitInformation::targetAbi(kit);
|
2015-06-24 08:26:35 +02:00
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
bool ok = false;
|
|
|
|
int nativeMixedOverride = qgetenv("QTC_DEBUGGER_NATIVE_MIXED").toInt(&ok);
|
|
|
|
if (ok)
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.nativeMixedEnabled = bool(nativeMixedOverride);
|
2015-10-08 16:19:57 +02:00
|
|
|
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.cppEngineType = DebuggerKitInformation::engineType(kit);
|
2016-09-04 19:12:16 +03:00
|
|
|
if (rp.sysRoot.isEmpty())
|
|
|
|
rp.sysRoot = SysRootKitInformation::sysRoot(kit).toString();
|
2015-06-24 08:26:35 +02:00
|
|
|
|
2017-05-30 15:38:06 +02:00
|
|
|
if (rp.displayName.isEmpty())
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.displayName = runConfig->displayName();
|
2015-07-23 11:23:52 +02:00
|
|
|
|
2017-05-30 15:38:06 +02:00
|
|
|
if (runConfig->property("supportsDebugger").toBool()) {
|
2016-04-12 16:42:15 +02:00
|
|
|
QString mainScript = runConfig->property("mainScript").toString();
|
|
|
|
QString interpreter = runConfig->property("interpreter").toString();
|
2016-06-07 17:04:53 +02:00
|
|
|
if (!interpreter.isEmpty() && mainScript.endsWith(".py")) {
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.mainScript = mainScript;
|
|
|
|
rp.interpreter = interpreter;
|
|
|
|
QString args = runConfig->property("arguments").toString();
|
2015-08-25 08:52:45 +02:00
|
|
|
if (!args.isEmpty()) {
|
2016-04-12 16:42:15 +02:00
|
|
|
if (!rp.inferior.commandLineArguments.isEmpty())
|
|
|
|
rp.inferior.commandLineArguments.append(QLatin1Char(' '));
|
|
|
|
rp.inferior.commandLineArguments.append(args);
|
2015-08-25 08:52:45 +02:00
|
|
|
}
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.masterEngineType = PdbEngineType;
|
2015-07-23 11:23:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:25:22 +02:00
|
|
|
if (auto debuggerAspect = runConfig->extraAspect<DebuggerRunConfigurationAspect>()) {
|
2017-05-30 15:38:06 +02:00
|
|
|
rp.multiProcess = debuggerAspect->useMultiProcess();
|
2017-08-09 18:25:22 +02:00
|
|
|
if (rp.languages == NoLanguage) {
|
|
|
|
if (debuggerAspect->useCppDebugger())
|
|
|
|
rp.languages |= CppLanguage;
|
|
|
|
if (debuggerAspect->useQmlDebugger())
|
|
|
|
rp.languages |= QmlLanguage;
|
|
|
|
}
|
2016-03-22 15:36:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This can happen e.g. when started from the command line.
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.languages == NoLanguage)
|
|
|
|
rp.languages = CppLanguage;
|
2016-03-22 15:36:08 +01:00
|
|
|
|
|
|
|
// validate debugger if C++ debugging is enabled
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.languages & CppLanguage) {
|
2016-03-22 16:34:00 +01:00
|
|
|
const QList<Task> tasks = DebuggerKitInformation::validateDebugger(kit);
|
2016-03-22 15:36:08 +01:00
|
|
|
if (!tasks.isEmpty()) {
|
2016-11-09 14:48:08 +01:00
|
|
|
foreach (const Task &t, tasks) {
|
|
|
|
if (t.type == Task::Warning)
|
|
|
|
continue;
|
2017-04-11 13:45:37 +02:00
|
|
|
m_errors.append(t.description);
|
2016-11-09 14:48:08 +01:00
|
|
|
}
|
2017-04-11 13:45:37 +02:00
|
|
|
if (!m_errors.isEmpty())
|
2017-04-06 20:03:18 +02:00
|
|
|
return false;
|
2016-03-22 15:36:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 13:54:52 +02:00
|
|
|
IDevice::ConstPtr device = runControl->device();
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.languages & QmlLanguage) {
|
2017-05-23 13:54:52 +02:00
|
|
|
if (device && device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
2017-08-18 12:23:42 +02:00
|
|
|
if (rp.qmlServer.host().isEmpty() || rp.qmlServer.port() <= 0) {
|
2016-08-03 16:27:22 +02:00
|
|
|
QTcpServer server;
|
|
|
|
const bool canListen = server.listen(QHostAddress::LocalHost)
|
|
|
|
|| server.listen(QHostAddress::LocalHostIPv6);
|
|
|
|
if (!canListen) {
|
2017-04-11 13:45:37 +02:00
|
|
|
m_errors.append(DebuggerPlugin::tr("Not enough free ports for QML debugging.") + ' ');
|
2017-04-06 20:03:18 +02:00
|
|
|
return false;
|
2016-08-03 16:27:22 +02:00
|
|
|
}
|
2017-08-18 12:23:42 +02:00
|
|
|
rp.qmlServer.setHost(server.serverAddress().toString());
|
|
|
|
rp.qmlServer.setPort(server.serverPort());
|
2014-10-20 14:03:47 +02:00
|
|
|
}
|
2016-03-22 15:36:08 +01:00
|
|
|
|
|
|
|
// Makes sure that all bindings go through the JavaScript engine, so that
|
|
|
|
// breakpoints are actually hit!
|
2016-04-12 16:42:15 +02:00
|
|
|
const QString optimizerKey = "QML_DISABLE_OPTIMIZER";
|
|
|
|
if (!rp.inferior.environment.hasKey(optimizerKey))
|
|
|
|
rp.inferior.environment.set(optimizerKey, "1");
|
2014-10-20 14:03:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 08:26:35 +02:00
|
|
|
if (!boolSetting(AutoEnrichParameters)) {
|
2016-04-12 16:42:15 +02:00
|
|
|
const QString sysroot = rp.sysRoot;
|
|
|
|
if (rp.debugInfoLocation.isEmpty())
|
|
|
|
rp.debugInfoLocation = sysroot + "/usr/lib/debug";
|
|
|
|
if (rp.debugSourceLocation.isEmpty()) {
|
|
|
|
QString base = sysroot + "/usr/src/debug/";
|
|
|
|
rp.debugSourceLocation.append(base + "qt5base/src/corelib");
|
|
|
|
rp.debugSourceLocation.append(base + "qt5base/src/gui");
|
|
|
|
rp.debugSourceLocation.append(base + "qt5base/src/network");
|
2015-06-24 08:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.masterEngineType == NoEngineType) {
|
|
|
|
if (rp.languages & QmlLanguage) {
|
2015-11-12 08:07:46 +01:00
|
|
|
QmlDebug::QmlDebugServicesPreset service;
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.languages & CppLanguage) {
|
|
|
|
if (rp.nativeMixedEnabled) {
|
2015-11-12 08:07:46 +01:00
|
|
|
service = QmlDebug::QmlNativeDebuggerServices;
|
2015-10-08 16:19:57 +02:00
|
|
|
} else {
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.masterEngineType = QmlCppEngineType;
|
2015-11-12 08:07:46 +01:00
|
|
|
service = QmlDebug::QmlDebuggerServices;
|
2015-10-08 16:19:57 +02:00
|
|
|
}
|
|
|
|
} else {
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.masterEngineType = QmlEngineType;
|
2015-11-12 08:07:46 +01:00
|
|
|
service = QmlDebug::QmlDebuggerServices;
|
2015-10-08 16:19:57 +02:00
|
|
|
}
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.startMode != AttachExternal && rp.startMode != AttachCrashedExternal) {
|
2017-08-18 12:23:42 +02:00
|
|
|
QString qmlarg = (rp.languages & CppLanguage) && rp.nativeMixedEnabled
|
|
|
|
? QmlDebug::qmlDebugNativeArguments(service, false)
|
|
|
|
: QmlDebug::qmlDebugTcpArguments(service, Port(rp.qmlServer.port()));
|
|
|
|
QtcProcess::addArg(&rp.inferior.commandLineArguments, qmlarg);
|
2016-04-07 11:43:48 +03:00
|
|
|
}
|
2015-06-24 08:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.masterEngineType == NoEngineType)
|
|
|
|
rp.masterEngineType = rp.cppEngineType;
|
2015-06-24 08:26:35 +02:00
|
|
|
|
2016-04-12 16:42:15 +02:00
|
|
|
if (rp.startMode == NoStartMode)
|
|
|
|
rp.startMode = StartInternal;
|
2014-10-20 14:03:47 +02:00
|
|
|
|
2017-07-07 19:11:32 +02:00
|
|
|
if (breakOnMainNextTime) {
|
2016-04-12 16:42:15 +02:00
|
|
|
rp.breakOnMain = true;
|
2017-07-07 19:11:32 +02:00
|
|
|
breakOnMainNextTime = false;
|
|
|
|
}
|
2015-06-24 08:26:35 +02:00
|
|
|
|
2017-09-05 15:32:25 +02:00
|
|
|
if (HostOsInfo::isWindowsHost()) {
|
|
|
|
QtcProcess::SplitError perr;
|
|
|
|
rp.inferior.commandLineArguments =
|
|
|
|
QtcProcess::prepareArgs(rp.inferior.commandLineArguments, &perr,
|
|
|
|
HostOsInfo::hostOs(), nullptr,
|
|
|
|
&rp.inferior.workingDirectory).toWindowsArgs();
|
|
|
|
if (perr != QtcProcess::SplitOk) {
|
|
|
|
// perr == BadQuoting is never returned on Windows
|
|
|
|
// FIXME? QTCREATORBUG-2809
|
|
|
|
m_errors.append(DebuggerPlugin::tr("Debugging complex command lines "
|
|
|
|
"is currently not supported on Windows."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 15:30:12 +02:00
|
|
|
// FIXME: We can't handle terminals yet.
|
|
|
|
if (rp.useTerminal && rp.cppEngineType == LldbEngineType) {
|
|
|
|
qWarning("Run in Terminal is not supported yet with the LLDB backend");
|
|
|
|
m_errors.append(DebuggerPlugin::tr("Run in Terminal is not supported with the LLDB backend."));
|
|
|
|
rp.useTerminal = false;
|
|
|
|
}
|
|
|
|
|
2017-04-06 20:03:18 +02:00
|
|
|
return true;
|
2015-06-24 08:26:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 10:10:25 +02:00
|
|
|
} // Internal
|
|
|
|
|
2017-05-03 12:35:00 +02:00
|
|
|
static DebuggerRunConfigurationAspect *debuggerAspect(const RunControl *runControl)
|
|
|
|
{
|
|
|
|
return runControl->runConfiguration()->extraAspect<DebuggerRunConfigurationAspect>();
|
|
|
|
}
|
|
|
|
|
2017-06-28 14:53:21 +02:00
|
|
|
static bool cppDebugging(const RunControl *runControl)
|
|
|
|
{
|
|
|
|
auto aspect = debuggerAspect(runControl);
|
|
|
|
return aspect ? aspect->useCppDebugger() : true; // For cases like valgrind-with-gdb.
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool qmlDebugging(const RunControl *runControl)
|
|
|
|
{
|
|
|
|
auto aspect = debuggerAspect(runControl);
|
2017-07-14 00:16:33 +03:00
|
|
|
return aspect ? aspect->useQmlDebugger() : false; // For cases like valgrind-with-gdb.
|
2017-06-28 14:53:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-07 10:21:27 +02:00
|
|
|
/// DebuggerRunTool
|
|
|
|
|
2017-05-03 12:35:00 +02:00
|
|
|
DebuggerRunTool::DebuggerRunTool(RunControl *runControl)
|
2017-05-09 10:25:11 +02:00
|
|
|
: RunWorker(runControl),
|
2017-06-28 14:53:21 +02:00
|
|
|
m_isCppDebugging(cppDebugging(runControl)),
|
|
|
|
m_isQmlDebugging(qmlDebugging(runControl))
|
2017-05-03 12:35:00 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
setDisplayName("DebuggerRunTool");
|
2017-07-05 15:17:38 +02:00
|
|
|
runControl->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR);
|
|
|
|
runControl->setPromptToStop([](bool *optionalPrompt) {
|
|
|
|
return RunControl::showPromptToStopDialog(
|
|
|
|
DebuggerRunTool::tr("Close Debugging Session"),
|
|
|
|
DebuggerRunTool::tr("A debugging session is still in progress. "
|
|
|
|
"Terminating the session in the current"
|
|
|
|
" state can leave the target in an inconsistent state."
|
|
|
|
" Would you still like to terminate it?"),
|
|
|
|
QString(), QString(), optionalPrompt);
|
|
|
|
});
|
2017-08-24 15:46:23 +02:00
|
|
|
|
|
|
|
Runnable r = runnable();
|
|
|
|
if (r.is<StandardRunnable>())
|
|
|
|
m_runParameters.inferior = r.as<StandardRunnable>();
|
2017-05-03 12:35:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 17:20:16 +02:00
|
|
|
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerStartParameters &sp)
|
2017-05-03 12:35:00 +02:00
|
|
|
: DebuggerRunTool(runControl)
|
|
|
|
{
|
2017-07-07 17:20:16 +02:00
|
|
|
setStartParameters(sp);
|
2017-05-03 12:35:00 +02:00
|
|
|
}
|
2017-04-21 10:10:25 +02:00
|
|
|
|
2017-07-07 17:20:16 +02:00
|
|
|
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParameters &rp)
|
2017-05-03 12:35:00 +02:00
|
|
|
: DebuggerRunTool(runControl)
|
|
|
|
{
|
2017-07-07 17:20:16 +02:00
|
|
|
setRunParameters(rp);
|
2017-05-03 12:35:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 17:20:16 +02:00
|
|
|
void DebuggerRunTool::setStartParameters(const DebuggerStartParameters &sp)
|
2017-05-03 12:35:00 +02:00
|
|
|
{
|
2017-07-07 17:20:16 +02:00
|
|
|
setRunParameters(sp);
|
2017-05-03 12:35:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 17:20:16 +02:00
|
|
|
void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp)
|
2017-04-07 10:21:27 +02:00
|
|
|
{
|
2017-07-05 15:17:38 +02:00
|
|
|
m_runParameters = rp;
|
2017-08-21 14:32:15 +02:00
|
|
|
|
|
|
|
if (!rp.serverStartScript.isEmpty()) {
|
|
|
|
// Provide script information about the environment
|
|
|
|
StandardRunnable serverStarter;
|
|
|
|
serverStarter.executable = rp.serverStartScript;
|
|
|
|
QtcProcess::addArg(&serverStarter.commandLineArguments, rp.inferior.executable);
|
|
|
|
QtcProcess::addArg(&serverStarter.commandLineArguments, rp.remoteChannel);
|
|
|
|
addStartDependency(new LocalProcessRunner(runControl(), serverStarter));
|
|
|
|
}
|
2017-07-05 15:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunTool::setupEngine()
|
|
|
|
{
|
|
|
|
// QML and/or mixed are not prepared for it.
|
|
|
|
setSupportsReRunning(!(m_runParameters.languages & QmlLanguage));
|
|
|
|
|
2017-05-19 14:40:49 +02:00
|
|
|
// FIXME: Disabled due to Android. Make Android device report available ports instead.
|
|
|
|
// int portsUsed = portsUsedByDebugger();
|
|
|
|
// if (portsUsed > device()->freePorts().count()) {
|
2017-07-05 15:17:38 +02:00
|
|
|
// reportFailure(tr("Cannot debug: Not enough free ports available."));
|
2017-05-19 14:40:49 +02:00
|
|
|
// return;
|
|
|
|
// }
|
2017-05-04 12:12:27 +02:00
|
|
|
|
2017-05-05 14:45:36 +02:00
|
|
|
if (Internal::fixupParameters(m_runParameters, runControl(), m_errors)) {
|
|
|
|
m_engine = createEngine(m_runParameters.cppEngineType,
|
|
|
|
m_runParameters.masterEngineType,
|
|
|
|
m_runParameters.startMode,
|
|
|
|
m_runParameters.useTerminal,
|
|
|
|
&m_errors);
|
2017-04-11 13:45:37 +02:00
|
|
|
if (!m_engine) {
|
2017-07-05 15:17:38 +02:00
|
|
|
reportFailure(m_errors.join('\n'));
|
2017-04-11 13:45:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-05 14:45:36 +02:00
|
|
|
|
|
|
|
Utils::globalMacroExpander()->registerFileVariables(
|
|
|
|
"DebuggedExecutable", tr("Debugged executable"),
|
|
|
|
[this] { return m_runParameters.inferior.executable; }
|
|
|
|
);
|
2017-04-11 13:45:37 +02:00
|
|
|
}
|
|
|
|
|
2017-05-05 14:45:36 +02:00
|
|
|
runControl()->setDisplayName(m_runParameters.displayName);
|
|
|
|
|
2017-04-21 17:20:57 +02:00
|
|
|
m_engine->setRunTool(this);
|
2017-04-10 13:57:05 +02:00
|
|
|
}
|
2017-04-07 10:21:27 +02:00
|
|
|
|
2017-05-05 14:45:36 +02:00
|
|
|
DebuggerEngine *DebuggerRunTool::activeEngine() const
|
|
|
|
{
|
|
|
|
return m_engine ? m_engine->activeEngine() : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:53:31 +02:00
|
|
|
void DebuggerRunTool::addSolibSearchDir(const QString &str)
|
2017-05-04 12:12:27 +02:00
|
|
|
{
|
|
|
|
QString path = str;
|
2017-05-05 14:45:36 +02:00
|
|
|
path.replace("%{sysroot}", m_runParameters.sysRoot);
|
|
|
|
m_runParameters.solibSearchPath.append(path);
|
2017-05-04 12:12:27 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 13:57:05 +02:00
|
|
|
DebuggerRunTool::~DebuggerRunTool()
|
|
|
|
{
|
|
|
|
disconnect();
|
|
|
|
if (m_engine) {
|
|
|
|
DebuggerEngine *engine = m_engine;
|
|
|
|
m_engine = 0;
|
|
|
|
engine->disconnect();
|
|
|
|
delete engine;
|
2017-04-07 10:21:27 +02:00
|
|
|
}
|
2017-04-10 13:57:05 +02:00
|
|
|
}
|
2017-04-07 10:21:27 +02:00
|
|
|
|
2017-04-10 13:57:05 +02:00
|
|
|
void DebuggerRunTool::showMessage(const QString &msg, int channel, int timeout)
|
|
|
|
{
|
|
|
|
if (channel == ConsoleOutput)
|
|
|
|
debuggerConsole()->printItem(ConsoleItem::DefaultType, msg);
|
|
|
|
|
|
|
|
Internal::showMessage(msg, channel, timeout);
|
|
|
|
switch (channel) {
|
|
|
|
case AppOutput:
|
|
|
|
appendMessage(msg, StdOutFormatSameLine);
|
|
|
|
break;
|
|
|
|
case AppError:
|
|
|
|
appendMessage(msg, StdErrFormatSameLine);
|
|
|
|
break;
|
|
|
|
case AppStuff:
|
|
|
|
appendMessage(msg, DebugFormat);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-04-07 10:21:27 +02:00
|
|
|
|
2015-06-24 08:26:35 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Externally visible helper.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-07-07 18:34:05 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
2015-06-24 08:26:35 +02:00
|
|
|
/**
|
|
|
|
* Used for direct "special" starts from actions in the debugger plugin.
|
|
|
|
*/
|
2017-04-11 13:45:37 +02:00
|
|
|
|
|
|
|
class DummyProject : public Project
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DummyProject() : Project(QString(""), FileName::fromString("")) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
RunConfiguration *dummyRunConfigForKit(ProjectExplorer::Kit *kit)
|
2015-06-24 08:26:35 +02:00
|
|
|
{
|
2017-04-06 20:03:18 +02:00
|
|
|
QTC_ASSERT(kit, return nullptr); // Caller needs to look for a suitable kit.
|
2017-04-11 13:45:37 +02:00
|
|
|
Project *project = SessionManager::startupProject();
|
2017-07-20 12:33:08 +03:00
|
|
|
Target *target = project ? project->target(kit) : nullptr;
|
2017-07-26 11:59:12 +03:00
|
|
|
if (!target || !target->activeRunConfiguration()) {
|
2017-04-11 13:45:37 +02:00
|
|
|
project = new DummyProject;
|
|
|
|
target = project->createTarget(kit);
|
2015-06-24 08:26:35 +02:00
|
|
|
}
|
2017-04-11 13:45:37 +02:00
|
|
|
QTC_ASSERT(target, return nullptr);
|
|
|
|
auto runConfig = target->activeRunConfiguration();
|
|
|
|
return runConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunControl *createAndScheduleRun(const DebuggerRunParameters &rp, Kit *kit)
|
|
|
|
{
|
|
|
|
RunConfiguration *runConfig = dummyRunConfigForKit(kit);
|
|
|
|
QTC_ASSERT(runConfig, return nullptr);
|
2017-07-07 19:11:32 +02:00
|
|
|
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE);
|
2017-04-11 13:45:37 +02:00
|
|
|
(void) new DebuggerRunTool(runControl, rp);
|
2017-04-11 14:36:03 +02:00
|
|
|
ProjectExplorerPlugin::startRunControl(runControl);
|
2017-04-11 13:45:37 +02:00
|
|
|
return runControl;
|
2015-06-24 08:26:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-07 10:21:27 +02:00
|
|
|
} // Internal
|
2017-05-09 10:25:11 +02:00
|
|
|
|
|
|
|
// GdbServerPortGatherer
|
|
|
|
|
|
|
|
GdbServerPortsGatherer::GdbServerPortsGatherer(RunControl *runControl)
|
|
|
|
: RunWorker(runControl)
|
|
|
|
{
|
2017-06-14 10:30:03 +02:00
|
|
|
setDisplayName("GdbServerPortsGatherer");
|
2017-07-07 16:40:10 +02:00
|
|
|
|
|
|
|
connect(&m_portsGatherer, &DeviceUsedPortsGatherer::error,
|
|
|
|
this, &RunWorker::reportFailure);
|
|
|
|
connect(&m_portsGatherer, &DeviceUsedPortsGatherer::portListReady,
|
|
|
|
this, &GdbServerPortsGatherer::handlePortListReady);
|
2017-05-09 10:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GdbServerPortsGatherer::~GdbServerPortsGatherer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:46:23 +02:00
|
|
|
QString GdbServerPortsGatherer::gdbServerChannel() const
|
|
|
|
{
|
|
|
|
const QString host = device()->sshParameters().host;
|
|
|
|
return QString("%1:%2").arg(host).arg(m_gdbServerPort.number());
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl GdbServerPortsGatherer::qmlServer() const
|
|
|
|
{
|
|
|
|
QUrl server = device()->toolControlChannel(IDevice::QmlControlChannel);
|
|
|
|
server.setPort(m_qmlServerPort.number());
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void GdbServerPortsGatherer::start()
|
|
|
|
{
|
|
|
|
appendMessage(tr("Checking available ports..."), NormalMessageFormat);
|
|
|
|
m_portsGatherer.start(device());
|
|
|
|
}
|
|
|
|
|
2017-07-07 16:40:10 +02:00
|
|
|
void GdbServerPortsGatherer::handlePortListReady()
|
|
|
|
{
|
|
|
|
Utils::PortList portList = device()->freePorts();
|
|
|
|
appendMessage(tr("Found %1 free ports").arg(portList.count()), NormalMessageFormat);
|
|
|
|
if (m_useGdbServer) {
|
|
|
|
m_gdbServerPort = m_portsGatherer.getNextFreePort(&portList);
|
|
|
|
if (!m_gdbServerPort.isValid()) {
|
|
|
|
reportFailure(tr("Not enough free ports on device for C++ debugging."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_useQmlServer) {
|
|
|
|
m_qmlServerPort = m_portsGatherer.getNextFreePort(&portList);
|
|
|
|
if (!m_qmlServerPort.isValid()) {
|
|
|
|
reportFailure(tr("Not enough free ports on device for QML debugging."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-08-09 09:23:14 +02:00
|
|
|
reportDone();
|
2017-07-07 16:40:10 +02:00
|
|
|
}
|
2017-05-09 10:25:11 +02:00
|
|
|
|
|
|
|
// GdbServerRunner
|
|
|
|
|
2017-07-07 09:46:22 +02:00
|
|
|
GdbServerRunner::GdbServerRunner(RunControl *runControl, GdbServerPortsGatherer *portsGatherer)
|
2017-07-07 15:40:46 +02:00
|
|
|
: SimpleTargetRunner(runControl), m_portsGatherer(portsGatherer)
|
2017-05-09 10:25:11 +02:00
|
|
|
{
|
|
|
|
setDisplayName("GdbServerRunner");
|
|
|
|
}
|
|
|
|
|
|
|
|
GdbServerRunner::~GdbServerRunner()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GdbServerRunner::start()
|
|
|
|
{
|
2017-07-07 09:46:22 +02:00
|
|
|
QTC_ASSERT(m_portsGatherer, reportFailure(); return);
|
2017-05-09 10:25:11 +02:00
|
|
|
|
|
|
|
StandardRunnable r = runnable().as<StandardRunnable>();
|
|
|
|
QStringList args = QtcProcess::splitArgs(r.commandLineArguments, OsTypeLinux);
|
|
|
|
QString command;
|
|
|
|
|
2017-07-07 09:46:22 +02:00
|
|
|
const bool isQmlDebugging = m_portsGatherer->useQmlServer();
|
|
|
|
const bool isCppDebugging = m_portsGatherer->useGdbServer();
|
2017-05-09 10:25:11 +02:00
|
|
|
|
|
|
|
if (isQmlDebugging) {
|
|
|
|
args.prepend(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
|
2017-07-07 09:46:22 +02:00
|
|
|
m_portsGatherer->qmlServerPort()));
|
2017-05-09 10:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isQmlDebugging && !isCppDebugging) {
|
|
|
|
command = r.executable;
|
|
|
|
} else {
|
|
|
|
command = device()->debugServerPath();
|
|
|
|
if (command.isEmpty())
|
|
|
|
command = "gdbserver";
|
|
|
|
args.clear();
|
|
|
|
args.append(QString("--multi"));
|
2017-07-07 09:46:22 +02:00
|
|
|
args.append(QString(":%1").arg(m_portsGatherer->gdbServerPort().number()));
|
2017-05-09 10:25:11 +02:00
|
|
|
}
|
|
|
|
r.executable = command;
|
|
|
|
r.commandLineArguments = QtcProcess::joinArgs(args, OsTypeLinux);
|
|
|
|
|
2017-07-07 15:40:46 +02:00
|
|
|
setRunnable(r);
|
2017-05-09 10:25:11 +02:00
|
|
|
|
2017-07-28 09:48:02 +02:00
|
|
|
appendMessage(tr("Starting gdbserver..."), NormalMessageFormat);
|
2017-05-09 10:25:11 +02:00
|
|
|
|
2017-07-07 15:40:46 +02:00
|
|
|
SimpleTargetRunner::start();
|
2017-05-09 10:25:11 +02:00
|
|
|
}
|
|
|
|
|
2009-09-11 08:55:16 +02:00
|
|
|
} // namespace Debugger
|