2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
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
|
|
|
|
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 "debuggerstringutils.h"
|
|
|
|
#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
|
|
|
|
#include <projectexplorer/localapplicationrunconfiguration.h> // For LocalApplication*
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2012-08-15 13:21:37 +02:00
|
|
|
#include <projectexplorer/projectexplorer.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>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-12-15 13:06:39 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2009-10-08 17:23:27 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
|
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
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerEngine *createCdbEngine(const DebuggerRunParameters &sp, QString *error);
|
|
|
|
DebuggerEngine *createGdbEngine(const DebuggerRunParameters &sp);
|
|
|
|
DebuggerEngine *createPdbEngine(const DebuggerRunParameters &sp);
|
|
|
|
DebuggerEngine *createQmlEngine(const DebuggerRunParameters &sp);
|
|
|
|
DebuggerEngine *createQmlCppEngine(const DebuggerRunParameters &sp, QString *error);
|
|
|
|
DebuggerEngine *createLldbEngine(const DebuggerRunParameters &sp);
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2014-10-17 12:37:30 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
2011-02-24 16:50:15 +01:00
|
|
|
static const char *engineTypeName(DebuggerEngineType et)
|
|
|
|
{
|
|
|
|
switch (et) {
|
|
|
|
case Debugger::NoEngineType:
|
|
|
|
break;
|
|
|
|
case Debugger::GdbEngineType:
|
2011-03-14 17:34:27 +01:00
|
|
|
return "Gdb engine";
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::CdbEngineType:
|
|
|
|
return "Cdb engine";
|
|
|
|
case Debugger::PdbEngineType:
|
2011-03-14 17:34:27 +01:00
|
|
|
return "Pdb engine";
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::QmlEngineType:
|
|
|
|
return "QML engine";
|
|
|
|
case Debugger::QmlCppEngineType:
|
|
|
|
return "QML C++ engine";
|
|
|
|
case Debugger::LldbEngineType:
|
2013-03-22 10:28:49 +01:00
|
|
|
return "LLDB command line engine";
|
2011-02-24 16:50:15 +01:00
|
|
|
case Debugger::AllEngineTypes:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "No engine";
|
|
|
|
}
|
|
|
|
|
2015-04-22 16:11:00 +02:00
|
|
|
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfig, DebuggerEngine *engine)
|
|
|
|
: RunControl(runConfig, DebugRunMode),
|
2014-10-17 12:37:30 +02:00
|
|
|
m_engine(engine),
|
|
|
|
m_running(false)
|
2009-09-09 18:35:25 +02:00
|
|
|
{
|
2014-05-27 18:50:55 +02:00
|
|
|
setIcon(QLatin1String(ProjectExplorer::Constants::ICON_DEBUG_SMALL));
|
2014-10-17 12:37:30 +02:00
|
|
|
connect(this, &RunControl::finished, this, &DebuggerRunControl::handleFinished);
|
2014-12-12 15:33:16 +01:00
|
|
|
|
|
|
|
connect(engine, &DebuggerEngine::requestRemoteSetup,
|
|
|
|
this, &DebuggerRunControl::requestRemoteSetup);
|
|
|
|
connect(engine, &DebuggerEngine::stateChanged,
|
|
|
|
this, &DebuggerRunControl::stateChanged);
|
|
|
|
connect(engine, &DebuggerEngine::aboutToNotifyInferiorSetupOk,
|
|
|
|
this, &DebuggerRunControl::aboutToNotifyInferiorSetupOk);
|
2010-04-19 14:21:33 +02:00
|
|
|
}
|
|
|
|
|
2010-12-03 16:18:50 +01:00
|
|
|
DebuggerRunControl::~DebuggerRunControl()
|
|
|
|
{
|
|
|
|
disconnect();
|
2014-10-17 12:37:30 +02:00
|
|
|
if (m_engine) {
|
|
|
|
DebuggerEngine *engine = m_engine;
|
|
|
|
m_engine = 0;
|
2010-12-03 16:18:50 +01:00
|
|
|
engine->disconnect();
|
|
|
|
delete engine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
QString DebuggerRunControl::displayName() const
|
2010-06-15 08:22:02 +02:00
|
|
|
{
|
2014-10-17 12:37:30 +02:00
|
|
|
QTC_ASSERT(m_engine, return QString());
|
2015-05-27 13:59:56 +02:00
|
|
|
return m_engine->runParameters().displayName;
|
2010-06-15 08:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void DebuggerRunControl::start()
|
2010-06-15 09:13:22 +02:00
|
|
|
{
|
2014-10-17 12:37:30 +02:00
|
|
|
QTC_ASSERT(m_engine, return);
|
2011-04-18 13:01:12 +02:00
|
|
|
// User canceled input dialog asking for executable when working on library project.
|
2015-05-27 13:59:56 +02:00
|
|
|
if (m_engine->runParameters().startMode == StartInternal
|
|
|
|
&& m_engine->runParameters().executable.isEmpty()) {
|
2013-10-17 13:48:04 +02:00
|
|
|
appendMessage(tr("No executable specified.") + QLatin1Char('\n'), ErrorMessageFormat);
|
2011-04-18 13:01:12 +02:00
|
|
|
emit started();
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
if (m_engine->runParameters().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()) {
|
|
|
|
if (bp.isEnabled() && !m_engine->acceptsBreakpoint(bp))
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 13:04:47 +02:00
|
|
|
Internal::runControlStarted(m_engine);
|
2010-08-27 16:22:51 +02:00
|
|
|
|
2010-09-29 10:32:41 +02:00
|
|
|
// We might get a synchronous startFailed() notification on Windows,
|
|
|
|
// when launching the process fails. Emit a proper finished() sequence.
|
2010-06-16 11:08:54 +02:00
|
|
|
emit started();
|
2014-10-17 12:37:30 +02:00
|
|
|
m_running = true;
|
2010-09-29 10:32:41 +02:00
|
|
|
|
2014-10-17 12:37:30 +02:00
|
|
|
m_engine->startDebugger(this);
|
2010-09-29 10:32:41 +02:00
|
|
|
|
2014-10-17 12:37:30 +02:00
|
|
|
if (m_running)
|
2013-10-17 13:48:04 +02:00
|
|
|
appendMessage(tr("Debugging starts") + QLatin1Char('\n'), NormalMessageFormat);
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void DebuggerRunControl::startFailed()
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2013-10-17 13:48:04 +02:00
|
|
|
appendMessage(tr("Debugging has failed") + QLatin1Char('\n'), NormalMessageFormat);
|
2014-10-17 12:37:30 +02:00
|
|
|
m_running = false;
|
2010-06-16 11:08:54 +02:00
|
|
|
emit finished();
|
2014-10-17 12:37:30 +02:00
|
|
|
m_engine->handleStartFailed();
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2014-12-12 15:33:16 +01:00
|
|
|
void DebuggerRunControl::notifyEngineRemoteServerRunning(const QByteArray &msg, int pid)
|
|
|
|
{
|
|
|
|
m_engine->notifyEngineRemoteServerRunning(msg, pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
|
|
|
|
{
|
|
|
|
m_engine->notifyEngineRemoteSetupFinished(result);
|
|
|
|
}
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void DebuggerRunControl::handleFinished()
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2013-10-17 13:48:04 +02:00
|
|
|
appendMessage(tr("Debugging has finished") + QLatin1Char('\n'), NormalMessageFormat);
|
2014-10-17 12:37:30 +02:00
|
|
|
if (m_engine)
|
|
|
|
m_engine->handleFinished();
|
2014-10-22 13:04:47 +02:00
|
|
|
Internal::runControlFinished(m_engine);
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2011-01-17 13:52:14 +01:00
|
|
|
bool DebuggerRunControl::promptToStop(bool *optionalPrompt) const
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(isRunning(), return true);
|
2010-08-20 14:19:25 +02:00
|
|
|
|
2011-01-17 13:52:14 +01:00
|
|
|
if (optionalPrompt && !*optionalPrompt)
|
|
|
|
return true;
|
|
|
|
|
2010-09-29 12:48:00 +02:00
|
|
|
const QString question = tr("A debugging session is still in progress. "
|
2010-08-20 14:19:25 +02:00
|
|
|
"Terminating the session in the current"
|
|
|
|
" state can leave the target in an inconsistent state."
|
|
|
|
" Would you still like to terminate it?");
|
2011-01-17 13:52:14 +01:00
|
|
|
return showPromptToStopDialog(tr("Close Debugging Session"), question,
|
|
|
|
QString(), QString(), optionalPrompt);
|
2010-08-20 14:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RunControl::StopResult DebuggerRunControl::stop()
|
|
|
|
{
|
2014-10-17 12:37:30 +02:00
|
|
|
QTC_ASSERT(m_engine, return StoppedSynchronously);
|
|
|
|
m_engine->quitDebugger();
|
2010-08-20 14:19:25 +02:00
|
|
|
return AsynchronousStop;
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void DebuggerRunControl::debuggingFinished()
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2014-10-17 12:37:30 +02:00
|
|
|
m_running = false;
|
2010-06-16 11:08:54 +02:00
|
|
|
emit finished();
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2014-12-12 15:33:16 +01:00
|
|
|
void DebuggerRunControl::showMessage(const QString &msg, int channel)
|
|
|
|
{
|
|
|
|
m_engine->showMessage(msg, channel);
|
|
|
|
}
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
bool DebuggerRunControl::isRunning() const
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2014-10-17 12:37:30 +02:00
|
|
|
return m_running;
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2014-12-12 15:33:16 +01:00
|
|
|
DebuggerStartParameters &DebuggerRunControl::startParameters()
|
|
|
|
{
|
2015-05-27 13:59:56 +02:00
|
|
|
return m_engine->runParameters();
|
2014-12-12 15:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::notifyInferiorIll()
|
|
|
|
{
|
|
|
|
m_engine->notifyInferiorIll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::notifyInferiorExited()
|
|
|
|
{
|
|
|
|
m_engine->notifyInferiorExited();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::quitDebugger()
|
|
|
|
{
|
|
|
|
m_engine->quitDebugger();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerRunControl::abortDebugger()
|
2010-06-15 11:42:49 +02:00
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
m_engine->abortDebugger();
|
2010-06-15 11:42:49 +02:00
|
|
|
}
|
|
|
|
|
2010-12-15 09:17:31 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DebuggerRunControlFactory
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-27 22:19:20 +02:00
|
|
|
DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent)
|
|
|
|
: IRunControlFactory(parent)
|
2010-12-15 09:17:31 +01:00
|
|
|
{}
|
|
|
|
|
2015-04-22 16:11:00 +02:00
|
|
|
bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfig, RunMode mode) const
|
2010-12-15 09:17:31 +01:00
|
|
|
{
|
2012-01-10 19:17:24 +01:00
|
|
|
return (mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain)
|
2015-04-22 16:11:00 +02:00
|
|
|
&& qobject_cast<LocalApplicationRunConfiguration *>(runConfig);
|
2010-12-15 09:17:31 +01:00
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
bool fillParametersFromLocalRunConfiguration
|
|
|
|
(DebuggerRunParameters *sp, const RunConfiguration *runConfig, QString *errorMessage)
|
2010-12-15 09:17:31 +01:00
|
|
|
{
|
2015-04-22 16:11:00 +02:00
|
|
|
QTC_ASSERT(runConfig, return false);
|
|
|
|
EnvironmentAspect *environmentAspect = runConfig->extraAspect<EnvironmentAspect>();
|
2014-10-20 14:03:47 +02:00
|
|
|
QTC_ASSERT(environmentAspect, return false);
|
2010-12-15 09:17:31 +01:00
|
|
|
|
2015-04-22 16:11:00 +02:00
|
|
|
Target *target = runConfig->target();
|
2013-08-21 12:48:46 +02:00
|
|
|
Kit *kit = target ? target->kit() : KitManager::defaultKit();
|
2014-10-20 14:03:47 +02:00
|
|
|
if (!fillParametersFromKit(sp, kit, errorMessage))
|
|
|
|
return false;
|
|
|
|
sp->environment = environmentAspect->environment();
|
2011-04-19 11:07:34 +02:00
|
|
|
|
2015-04-22 16:11:00 +02:00
|
|
|
auto rc = qobject_cast<const LocalApplicationRunConfiguration *>(runConfig);
|
|
|
|
QTC_ASSERT(rc, return false);
|
2013-10-23 22:07:46 +03:00
|
|
|
// Normalize to work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch'...)
|
2014-10-20 14:03:47 +02:00
|
|
|
sp->workingDirectory = FileUtils::normalizePathName(rc->workingDirectory());
|
2011-04-19 11:07:34 +02:00
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
sp->executable = rc->executable();
|
|
|
|
if (sp->executable.isEmpty())
|
|
|
|
return false;
|
2013-03-20 13:00:10 +01:00
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
sp->processArgs = rc->commandLineArguments();
|
|
|
|
sp->useTerminal = rc->runMode() == ApplicationLauncher::Console;
|
2010-12-15 09:17:31 +01:00
|
|
|
|
2012-06-28 10:00:04 +02:00
|
|
|
if (target) {
|
|
|
|
if (const Project *project = target->project()) {
|
2014-10-20 14:03:47 +02:00
|
|
|
sp->projectSourceDirectory = project->projectDirectory().toString();
|
2012-06-28 10:00:04 +02:00
|
|
|
if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration())
|
2014-10-20 14:03:47 +02:00
|
|
|
sp->projectBuildDirectory = buildConfig->buildDirectory().toString();
|
|
|
|
sp->projectSourceFiles = project->files(Project::ExcludeGeneratedFiles);
|
2011-02-25 16:03:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 16:11:00 +02:00
|
|
|
DebuggerRunConfigurationAspect *debuggerAspect = runConfig->extraAspect<DebuggerRunConfigurationAspect>();
|
2014-10-20 14:03:47 +02:00
|
|
|
QTC_ASSERT(debuggerAspect, return false);
|
|
|
|
sp->multiProcess = debuggerAspect->useMultiProcess();
|
2012-03-28 09:37:02 +02:00
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
if (debuggerAspect->useCppDebugger())
|
|
|
|
sp->languages |= CppLanguage;
|
2012-02-01 09:03:05 +01:00
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
if (debuggerAspect->useQmlDebugger()) {
|
2015-04-22 16:11:00 +02:00
|
|
|
const IDevice::ConstPtr device = DeviceKitInformation::device(runConfig->target()->kit());
|
2013-03-20 13:00:10 +01:00
|
|
|
QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return sp);
|
2013-04-17 17:45:53 +02:00
|
|
|
QTcpServer server;
|
2013-04-18 10:34:23 +02:00
|
|
|
const bool canListen = server.listen(QHostAddress::LocalHost)
|
|
|
|
|| server.listen(QHostAddress::LocalHostIPv6);
|
2013-04-17 17:45:53 +02:00
|
|
|
if (!canListen) {
|
2013-03-20 13:00:10 +01:00
|
|
|
if (errorMessage)
|
2013-10-17 14:52:10 +02:00
|
|
|
*errorMessage = DebuggerPlugin::tr("Not enough free ports for QML debugging.") + QLatin1Char(' ');
|
2013-03-20 13:00:10 +01:00
|
|
|
return sp;
|
|
|
|
}
|
2014-10-20 14:03:47 +02:00
|
|
|
sp->qmlServerAddress = server.serverAddress().toString();
|
|
|
|
sp->qmlServerPort = server.serverPort();
|
|
|
|
sp->languages |= QmlLanguage;
|
2010-12-15 09:17:31 +01:00
|
|
|
|
2011-02-07 10:55:22 +01:00
|
|
|
// Makes sure that all bindings go through the JavaScript engine, so that
|
|
|
|
// breakpoints are actually hit!
|
2011-02-25 16:03:22 +01:00
|
|
|
const QString optimizerKey = _("QML_DISABLE_OPTIMIZER");
|
2014-10-20 14:03:47 +02:00
|
|
|
if (!sp->environment.hasKey(optimizerKey))
|
|
|
|
sp->environment.set(optimizerKey, _("1"));
|
2011-02-07 10:55:22 +01:00
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
QtcProcess::addArg(&sp->processArgs, QString::fromLatin1("-qmljsdebugger=port:%1,block").arg(sp->qmlServerPort));
|
2010-12-15 09:17:31 +01:00
|
|
|
}
|
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
sp->startMode = StartInternal;
|
2015-04-22 16:11:00 +02:00
|
|
|
sp->displayName = runConfig->displayName();
|
2010-12-15 09:17:31 +01:00
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
return true;
|
2010-12-15 09:17:31 +01:00
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
2010-12-15 09:17:31 +01:00
|
|
|
RunControl *DebuggerRunControlFactory::create
|
2012-09-05 12:42:41 +02:00
|
|
|
(RunConfiguration *runConfiguration, RunMode mode, QString *errorMessage)
|
2010-12-15 09:17:31 +01:00
|
|
|
{
|
2012-01-10 19:17:24 +01:00
|
|
|
QTC_ASSERT(mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain, return 0);
|
2014-10-20 14:03:47 +02:00
|
|
|
|
|
|
|
// We cover only local setup here. Remote setups are handled by the
|
|
|
|
// RunControl factories in the target specific plugins.
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerRunParameters sp;
|
2014-10-20 14:03:47 +02:00
|
|
|
bool res = fillParametersFromLocalRunConfiguration(&sp, runConfiguration, errorMessage);
|
2011-12-20 17:03:10 +01:00
|
|
|
if (sp.startMode == NoStartMode)
|
|
|
|
return 0;
|
2014-10-20 14:03:47 +02:00
|
|
|
|
|
|
|
QTC_ASSERT(res, return 0);
|
|
|
|
|
2012-01-10 19:17:24 +01:00
|
|
|
if (mode == DebugRunModeWithBreakOnMain)
|
2011-05-02 18:22:32 +02:00
|
|
|
sp.breakOnMain = true;
|
2012-08-15 13:21:37 +02:00
|
|
|
|
2015-02-10 13:21:22 +01:00
|
|
|
sp.runConfiguration = runConfiguration;
|
|
|
|
return doCreate(sp, errorMessage);
|
2010-12-15 09:17:31 +01:00
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
IRunConfigurationAspect *DebuggerRunControlFactory::createRunConfigurationAspect(RunConfiguration *rc)
|
|
|
|
{
|
|
|
|
return new DebuggerRunConfigurationAspect(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
DebuggerRunControl *createDebuggerRunControl(const DebuggerStartParameters &sp, QString *errorMessage)
|
|
|
|
{
|
|
|
|
return DebuggerRunControlFactory::doCreate(sp, errorMessage);
|
|
|
|
}
|
|
|
|
|
2012-08-15 13:21:37 +02:00
|
|
|
DebuggerRunControl *DebuggerRunControlFactory::doCreate
|
2015-05-27 13:59:56 +02:00
|
|
|
(const DebuggerStartParameters &sp, QString *errorMessage)
|
2012-08-15 13:21:37 +02:00
|
|
|
{
|
2013-08-15 12:14:46 +02:00
|
|
|
TaskHub::clearTasks(Debugger::Constants::TASK_CATEGORY_DEBUGGER_DEBUGINFO);
|
|
|
|
TaskHub::clearTasks(Debugger::Constants::TASK_CATEGORY_DEBUGGER_RUNTIME);
|
2012-11-02 16:14:43 +01:00
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerRunParameters rp;
|
|
|
|
rp = sp;
|
2014-07-28 14:23:52 +02:00
|
|
|
if (!boolSetting(AutoEnrichParameters)) {
|
2015-05-27 13:59:56 +02:00
|
|
|
const QString sysroot = rp.sysRoot;
|
|
|
|
if (rp.debugInfoLocation.isEmpty())
|
|
|
|
rp.debugInfoLocation = sysroot + QLatin1String("/usr/lib/debug");
|
|
|
|
if (rp.debugSourceLocation.isEmpty()) {
|
2012-08-15 13:21:37 +02:00
|
|
|
QString base = sysroot + QLatin1String("/usr/src/debug/");
|
2015-05-27 13:59:56 +02:00
|
|
|
rp.debugSourceLocation.append(base + QLatin1String("qt5base/src/corelib"));
|
|
|
|
rp.debugSourceLocation.append(base + QLatin1String("qt5base/src/gui"));
|
|
|
|
rp.debugSourceLocation.append(base + QLatin1String("qt5base/src/network"));
|
2012-08-15 13:21:37 +02:00
|
|
|
}
|
2010-12-15 09:34:02 +01:00
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
if (rp.masterEngineType == NoEngineType) {
|
|
|
|
if (rp.executable.endsWith(_(".py"))
|
|
|
|
|| rp.executable == _("/usr/bin/python")
|
|
|
|
|| rp.executable == _("/usr/bin/python3")) {
|
|
|
|
rp.masterEngineType = PdbEngineType;
|
2015-02-10 16:17:57 +01:00
|
|
|
} else {
|
2015-05-27 13:59:56 +02:00
|
|
|
if (RunConfiguration *rc = rp.runConfiguration) {
|
2015-02-10 16:17:57 +01:00
|
|
|
DebuggerRunConfigurationAspect *aspect
|
|
|
|
= rc->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
|
|
|
|
if (const Target *target = rc->target())
|
2015-05-27 13:59:56 +02:00
|
|
|
if (!fillParametersFromKit(&rp, target->kit(), errorMessage))
|
2015-02-10 16:17:57 +01:00
|
|
|
return 0;
|
2015-05-27 13:59:56 +02:00
|
|
|
const bool useCppDebugger = aspect->useCppDebugger() && (rp.languages & CppLanguage);
|
|
|
|
const bool useQmlDebugger = aspect->useQmlDebugger() && (rp.languages & QmlLanguage);
|
2015-02-10 16:17:57 +01:00
|
|
|
if (useQmlDebugger) {
|
2015-03-04 17:50:52 +01:00
|
|
|
if (useCppDebugger)
|
2015-05-27 13:59:56 +02:00
|
|
|
rp.masterEngineType = QmlCppEngineType;
|
2015-03-04 17:50:52 +01:00
|
|
|
else
|
2015-05-27 13:59:56 +02:00
|
|
|
rp.masterEngineType = QmlEngineType;
|
2015-02-10 13:02:46 +01:00
|
|
|
} else {
|
2015-05-27 13:59:56 +02:00
|
|
|
rp.masterEngineType = rp.cppEngineType;
|
2015-02-10 13:02:46 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-05-27 13:59:56 +02:00
|
|
|
rp.masterEngineType = rp.cppEngineType;
|
2015-02-10 13:02:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 12:37:30 +02:00
|
|
|
QString error;
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerEngine *engine = createEngine(rp.masterEngineType, rp, &error);
|
2014-10-17 12:37:30 +02:00
|
|
|
if (!engine) {
|
|
|
|
Core::ICore::showWarningWithOptions(DebuggerRunControl::tr("Debugger"), error);
|
|
|
|
if (errorMessage)
|
|
|
|
*errorMessage = error;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-27 13:59:56 +02:00
|
|
|
return new DebuggerRunControl(rp.runConfiguration, engine);
|
2012-08-15 13:21:37 +02:00
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
namespace Internal {
|
2013-03-26 17:03:57 +01:00
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerRunControl *createAndScheduleRun(const DebuggerRunParameters &rp)
|
2012-08-15 13:21:37 +02:00
|
|
|
{
|
2012-09-05 12:42:41 +02:00
|
|
|
QString errorMessage;
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerRunControl *rc = createDebuggerRunControl(rp, &errorMessage);
|
2012-09-05 12:42:41 +02:00
|
|
|
if (!rc) {
|
2014-09-12 01:08:28 +02:00
|
|
|
ProjectExplorerPlugin::showRunErrorMessage(errorMessage);
|
2012-08-15 13:21:37 +02:00
|
|
|
return 0;
|
2012-09-05 12:42:41 +02:00
|
|
|
}
|
2015-05-27 13:59:56 +02:00
|
|
|
Internal::showMessage(rp.startMessage, 0);
|
2014-09-12 01:08:28 +02:00
|
|
|
ProjectExplorerPlugin::startRunControl(rc, DebugRunMode);
|
2012-08-15 13:21:37 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-10-20 14:03:47 +02:00
|
|
|
static QString executableForPid(qint64 pid)
|
|
|
|
{
|
|
|
|
foreach (const DeviceProcessItem &p, DeviceProcessList::localProcesses())
|
|
|
|
if (p.pid == pid)
|
|
|
|
return p.exe;
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
bool fillParametersFromKit(DebuggerRunParameters *sp, const Kit *kit, QString *errorMessage /* = 0 */)
|
2014-10-20 14:03:47 +02:00
|
|
|
{
|
|
|
|
if (!kit) {
|
|
|
|
// This code can only be reached when starting via the command line
|
|
|
|
// (-debug pid or executable) or attaching from runconfiguration
|
|
|
|
// without specifying a kit. Try to find a kit via ABI.
|
|
|
|
QList<Abi> abis;
|
|
|
|
if (sp->toolChainAbi.isValid()) {
|
|
|
|
abis.push_back(sp->toolChainAbi);
|
|
|
|
} else {
|
|
|
|
// Try via executable.
|
|
|
|
if (sp->executable.isEmpty()
|
|
|
|
&& (sp->startMode == AttachExternal || sp->startMode == AttachCrashedExternal)) {
|
|
|
|
sp->executable = executableForPid(sp->attachPID);
|
|
|
|
}
|
|
|
|
if (!sp->executable.isEmpty())
|
2015-02-03 23:58:49 +02:00
|
|
|
abis = Abi::abisOfBinary(FileName::fromString(sp->executable));
|
2014-10-20 14:03:47 +02:00
|
|
|
}
|
|
|
|
if (!abis.isEmpty()) {
|
|
|
|
// Try exact abis.
|
|
|
|
kit = KitManager::find(std::function<bool (const Kit *)>([abis](const Kit *k) -> bool {
|
|
|
|
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k)) {
|
|
|
|
return abis.contains(tc->targetAbi())
|
|
|
|
&& DebuggerKitInformation::isValidDebugger(k);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
if (!kit) {
|
|
|
|
// Or something compatible.
|
|
|
|
kit = KitManager::find(std::function<bool (const Kit *)>([abis](const Kit *k) -> bool {
|
|
|
|
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k))
|
|
|
|
foreach (const Abi &a, abis)
|
|
|
|
if (a.isCompatibleWith(tc->targetAbi()) && DebuggerKitInformation::isValidDebugger(k))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!kit)
|
|
|
|
kit = KitManager::defaultKit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that debugger and profile are valid
|
|
|
|
if (!kit) {
|
|
|
|
sp->startMode = NoStartMode;
|
|
|
|
if (errorMessage)
|
|
|
|
*errorMessage = DebuggerKitInformation::tr("No kit found.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// validate debugger if C++ debugging is enabled
|
|
|
|
if (sp->languages & CppLanguage) {
|
|
|
|
const QList<Task> tasks = DebuggerKitInformation::validateDebugger(kit);
|
|
|
|
if (!tasks.isEmpty()) {
|
|
|
|
sp->startMode = NoStartMode;
|
|
|
|
if (errorMessage) {
|
|
|
|
foreach (const Task &t, tasks) {
|
|
|
|
if (errorMessage->isEmpty())
|
|
|
|
errorMessage->append(QLatin1Char('\n'));
|
|
|
|
errorMessage->append(t.description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sp->cppEngineType = DebuggerKitInformation::engineType(kit);
|
|
|
|
sp->sysRoot = SysRootKitInformation::sysRoot(kit).toString();
|
|
|
|
sp->debuggerCommand = DebuggerKitInformation::debuggerCommand(kit).toString();
|
|
|
|
|
|
|
|
ToolChain *tc = ToolChainKitInformation::toolChain(kit);
|
|
|
|
if (tc)
|
|
|
|
sp->toolChainAbi = tc->targetAbi();
|
|
|
|
|
|
|
|
sp->device = DeviceKitInformation::device(kit);
|
|
|
|
if (sp->device) {
|
|
|
|
sp->connParams = sp->device->sshParameters();
|
|
|
|
// Could have been set from command line.
|
|
|
|
if (sp->remoteChannel.isEmpty())
|
|
|
|
sp->remoteChannel = sp->connParams.host + QLatin1Char(':') + QString::number(sp->connParams.port);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
DebuggerEngine *createEngine(DebuggerEngineType et,
|
|
|
|
const DebuggerRunParameters &sp, QString *errorMessage)
|
2011-02-24 16:50:15 +01:00
|
|
|
{
|
|
|
|
switch (et) {
|
|
|
|
case GdbEngineType:
|
2012-08-15 14:33:39 +02:00
|
|
|
return createGdbEngine(sp);
|
2011-02-24 16:50:15 +01:00
|
|
|
case CdbEngineType:
|
2012-08-15 14:33:39 +02:00
|
|
|
return createCdbEngine(sp, errorMessage);
|
2011-02-24 16:50:15 +01:00
|
|
|
case PdbEngineType:
|
|
|
|
return createPdbEngine(sp);
|
|
|
|
case QmlEngineType:
|
2012-08-15 14:33:39 +02:00
|
|
|
return createQmlEngine(sp);
|
2011-02-24 16:50:15 +01:00
|
|
|
case LldbEngineType:
|
|
|
|
return createLldbEngine(sp);
|
2012-08-15 13:21:37 +02:00
|
|
|
case QmlCppEngineType:
|
|
|
|
return createQmlCppEngine(sp, errorMessage);
|
2011-04-08 16:04:53 +02:00
|
|
|
default:
|
|
|
|
break;
|
2011-02-24 16:50:15 +01:00
|
|
|
}
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = DebuggerPlugin::tr("Unable to create a debugger engine of the type \"%1\"").
|
2011-02-24 16:50:15 +01:00
|
|
|
arg(_(engineTypeName(et)));
|
2010-12-15 09:17:31 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
} // namespace Internal
|
2009-09-11 08:55:16 +02:00
|
|
|
} // namespace Debugger
|