debuggerrunner.cpp 22 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "debuggerrunner.h"
31
#include "debuggerruncontrolfactory.h"
con's avatar
con committed
32

33
#include "debuggeractions.h"
34
#include "debuggercore.h"
35 36
#include "debuggerplugin.h"
#include "debuggerstringutils.h"
Friedemann Kleint's avatar
Friedemann Kleint committed
37
#include "debuggerstartparameters.h"
Tobias Hunger's avatar
Tobias Hunger committed
38
#include "debuggerkitinformation.h"
hjk's avatar
hjk committed
39
#include "lldblib/lldbenginehost.h"
40
#include "debuggertooltipmanager.h"
41

Friedemann Kleint's avatar
Friedemann Kleint committed
42 43
#ifdef Q_OS_WIN
#  include "peutils.h"
44
#  include <utils/winutils.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
45 46
#endif

47
#include <projectexplorer/localapplicationrunconfiguration.h> // For LocalApplication*
hjk's avatar
hjk committed
48
#include <projectexplorer/buildconfiguration.h>
con's avatar
con committed
49
#include <projectexplorer/project.h>
hjk's avatar
hjk committed
50
#include <projectexplorer/projectexplorer.h>
Tobias Hunger's avatar
Tobias Hunger committed
51
#include <projectexplorer/target.h>
52
#include <projectexplorer/taskhub.h>
con's avatar
con committed
53

hjk's avatar
hjk committed
54
#include <utils/qtcassert.h>
55
#include <utils/qtcprocess.h>
56
#include <coreplugin/icore.h>
57
#include <coreplugin/helpmanager.h>
hjk's avatar
hjk committed
58

59 60
#include <QCheckBox>
#include <QSpinBox>
61 62
#include <QDebug>
#include <QErrorMessage>
63 64
#include <QFormLayout>
#include <QLabel>
con's avatar
con committed
65

66
using namespace Debugger::Internal;
hjk's avatar
hjk committed
67 68
using namespace ProjectExplorer;
using namespace Utils;
69

70 71
enum { debug = 0 };

72
namespace Debugger {
73
namespace Internal {
74

75 76
DebuggerEngine *createCdbEngine(const DebuggerStartParameters &sp, QString *error);
DebuggerEngine *createGdbEngine(const DebuggerStartParameters &sp);
hjk's avatar
hjk committed
77 78
DebuggerEngine *createScriptEngine(const DebuggerStartParameters &sp);
DebuggerEngine *createPdbEngine(const DebuggerStartParameters &sp);
79 80
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &sp);
DebuggerEngine *createQmlCppEngine(const DebuggerStartParameters &sp, QString *error);
hjk's avatar
hjk committed
81
DebuggerEngine *createLldbEngine(const DebuggerStartParameters &sp);
82

83 84 85 86 87 88
static const char *engineTypeName(DebuggerEngineType et)
{
    switch (et) {
    case Debugger::NoEngineType:
        break;
    case Debugger::GdbEngineType:
89
        return "Gdb engine";
90 91 92 93 94
    case Debugger::ScriptEngineType:
        return "Script engine";
    case Debugger::CdbEngineType:
        return "Cdb engine";
    case Debugger::PdbEngineType:
95
        return "Pdb engine";
96 97 98 99 100 101 102 103 104 105 106 107
    case Debugger::QmlEngineType:
        return "QML engine";
    case Debugger::QmlCppEngineType:
        return "QML C++ engine";
    case Debugger::LldbEngineType:
        return "LLDB engine";
    case Debugger::AllEngineTypes:
        break;
    }
    return "No engine";
}

108 109 110 111 112 113
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunConfigWidget
//
////////////////////////////////////////////////////////////////////////

hjk's avatar
hjk committed
114
class DebuggerRunConfigWidget : public RunConfigWidget
115 116 117 118
{
    Q_OBJECT

public:
119 120
    explicit DebuggerRunConfigWidget(RunConfiguration *runConfiguration);
    QString displayName() const { return tr("Debugger Settings"); }
121 122

private slots:
123 124
    void useCppDebuggerToggled(bool on);
    void useQmlDebuggerToggled(bool on);
125
    void qmlDebugServerPortChanged(int port);
126
    void useMultiProcessToggled(bool on);
127 128

public:
129
    DebuggerRunConfigurationAspect *m_aspect; // not owned
130 131 132 133 134 135

    QCheckBox *m_useCppDebugger;
    QCheckBox *m_useQmlDebugger;
    QSpinBox *m_debugServerPort;
    QLabel *m_debugServerPortLabel;
    QLabel *m_qmlDebuggerInfoLabel;
136
    QCheckBox *m_useMultiProcess;
137 138
};

139
DebuggerRunConfigWidget::DebuggerRunConfigWidget(RunConfiguration *runConfiguration)
140
{
141
    m_aspect = runConfiguration->debuggerAspect();
142

143 144
    m_useCppDebugger = new QCheckBox(tr("Enable C++"), this);
    m_useQmlDebugger = new QCheckBox(tr("Enable QML"), this);
145 146 147 148 149

    m_debugServerPort = new QSpinBox(this);
    m_debugServerPort->setMinimum(1);
    m_debugServerPort->setMaximum(65535);

150
    m_debugServerPortLabel = new QLabel(tr("Debug port:"), this);
151 152 153
    m_debugServerPortLabel->setBuddy(m_debugServerPort);

    m_qmlDebuggerInfoLabel = new QLabel(tr("<a href=\""
154
        "qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html"
155 156
        "\">What are the prerequisites?</a>"));

157 158 159
    m_useCppDebugger->setChecked(m_aspect->useCppDebugger());
    m_useQmlDebugger->setChecked(m_aspect->useQmlDebugger());

160
    m_debugServerPort->setValue(m_aspect->qmlDebugServerPort());
161

162 163 164 165 166 167
    static const QByteArray env = qgetenv("QTC_DEBUGGER_MULTIPROCESS");
    m_useMultiProcess =
        new QCheckBox(tr("Enable Debugging of Subprocesses"), this);
    m_useMultiProcess->setChecked(m_aspect->useMultiProcess());
    m_useMultiProcess->setVisible(env.toInt());

168
    connect(m_qmlDebuggerInfoLabel, SIGNAL(linkActivated(QString)),
169
            Core::HelpManager::instance(), SLOT(handleHelpRequest(QString)));
170
    connect(m_useQmlDebugger, SIGNAL(toggled(bool)),
171 172 173
            SLOT(useQmlDebuggerToggled(bool)));
    connect(m_useCppDebugger, SIGNAL(toggled(bool)),
            SLOT(useCppDebuggerToggled(bool)));
174
    connect(m_debugServerPort, SIGNAL(valueChanged(int)),
175
            SLOT(qmlDebugServerPortChanged(int)));
176 177
    connect(m_useMultiProcess, SIGNAL(toggled(bool)),
            SLOT(useMultiProcessToggled(bool)));
178

179 180 181
    if (m_aspect->isDisplaySuppressed())
        hide();

182
    if (m_aspect->areQmlDebuggingOptionsSuppressed()) {
183 184 185 186
        m_debugServerPortLabel->hide();
        m_debugServerPort->hide();
        m_useQmlDebugger->hide();
    }
187

188 189 190
    if (m_aspect->areCppDebuggingOptionsSuppressed())
        m_useCppDebugger->hide();

191 192 193 194 195
    if (m_aspect->isQmlDebuggingSpinboxSuppressed()) {
        m_debugServerPort->hide();
        m_debugServerPortLabel->hide();
    }

196 197 198 199 200 201 202 203 204 205 206 207
    QHBoxLayout *qmlLayout = new QHBoxLayout;
    qmlLayout->setMargin(0);
    qmlLayout->addWidget(m_useQmlDebugger);
    qmlLayout->addWidget(m_debugServerPortLabel);
    qmlLayout->addWidget(m_debugServerPort);
    qmlLayout->addWidget(m_qmlDebuggerInfoLabel);
    qmlLayout->addStretch();

    QVBoxLayout *layout = new QVBoxLayout;
    layout->setMargin(0);
    layout->addWidget(m_useCppDebugger);
    layout->addLayout(qmlLayout);
208
    layout->addWidget(m_useMultiProcess);
209 210 211
    setLayout(layout);
}

212
void DebuggerRunConfigWidget::qmlDebugServerPortChanged(int port)
213
{
214
    m_aspect->m_qmlDebugServerPort = port;
215 216
}

217
void DebuggerRunConfigWidget::useCppDebuggerToggled(bool on)
218
{
219 220
    m_aspect->m_useCppDebugger = on;
    if (!on && !m_useQmlDebugger->isChecked())
221 222 223
        m_useQmlDebugger->setChecked(true);
}

224
void DebuggerRunConfigWidget::useQmlDebuggerToggled(bool on)
225
{
226 227
    m_debugServerPort->setEnabled(on);
    m_debugServerPortLabel->setEnabled(on);
228

229
    m_aspect->m_useQmlDebugger = on
230 231
            ? DebuggerRunConfigurationAspect::EnableQmlDebugger
            : DebuggerRunConfigurationAspect::DisableQmlDebugger;
232
    if (!on && !m_useCppDebugger->isChecked())
233 234 235
        m_useCppDebugger->setChecked(true);
}

236 237 238 239 240
void DebuggerRunConfigWidget::useMultiProcessToggled(bool on)
{
    m_aspect->m_useMultiProcess = on;
}

241 242
////////////////////////////////////////////////////////////////////////
//
hjk's avatar
hjk committed
243
// DebuggerRunControlPrivate
244 245 246
//
////////////////////////////////////////////////////////////////////////

hjk's avatar
hjk committed
247 248 249
class DebuggerRunControlPrivate
{
public:
250 251
    explicit DebuggerRunControlPrivate(DebuggerRunControl *parent,
                                       RunConfiguration *runConfiguration);
252

hjk's avatar
hjk committed
253 254
public:
    DebuggerRunControl *q;
255
    DebuggerEngine *m_engine;
256
    const QPointer<RunConfiguration> m_myRunConfiguration;
257 258 259
    bool m_running;
};

hjk's avatar
hjk committed
260
DebuggerRunControlPrivate::DebuggerRunControlPrivate(DebuggerRunControl *parent,
261
                                                     RunConfiguration *runConfiguration)
hjk's avatar
hjk committed
262 263
    : q(parent)
    , m_engine(0)
264
    , m_myRunConfiguration(runConfiguration)
265
    , m_running(false)
266 267
{
}
268

hjk's avatar
hjk committed
269 270
} // namespace Internal

hjk's avatar
hjk committed
271
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
hjk's avatar
hjk committed
272
                                       const DebuggerStartParameters &sp)
hjk's avatar
hjk committed
273
    : RunControl(runConfiguration, DebugRunMode),
274
      d(new DebuggerRunControlPrivate(this, runConfiguration))
275
{
hjk's avatar
hjk committed
276
    connect(this, SIGNAL(finished()), SLOT(handleFinished()));
277 278 279
    // Create the engine. Could arguably be moved to the factory, but
    // we still have a derived S60DebugControl. Should rarely fail, though.
    QString errorMessage;
280
    d->m_engine = DebuggerRunControlFactory::createEngine(sp.masterEngineType, sp, &errorMessage);
hjk's avatar
hjk committed
281

282 283 284
    if (d->m_engine) {
        DebuggerToolTipManager::instance()->registerEngine(d->m_engine);
    } else {
285
        debuggingFinished();
hjk's avatar
hjk committed
286
        Core::ICore::showWarningWithOptions(DebuggerRunControl::tr("Debugger"), errorMessage);
287
    }
288 289
}

hjk's avatar
hjk committed
290 291 292 293 294 295 296 297
DebuggerRunControl::~DebuggerRunControl()
{
    disconnect();
    if (DebuggerEngine *engine = d->m_engine) {
        d->m_engine = 0;
        engine->disconnect();
        delete engine;
    }
hjk's avatar
hjk committed
298
    delete d;
hjk's avatar
hjk committed
299 300 301 302 303 304 305 306
}

const DebuggerStartParameters &DebuggerRunControl::startParameters() const
{
    QTC_ASSERT(d->m_engine, return *(new DebuggerStartParameters()));
    return d->m_engine->startParameters();
}

307
QString DebuggerRunControl::displayName() const
308
{
309 310
    QTC_ASSERT(d->m_engine, return QString());
    return d->m_engine->startParameters().displayName;
311 312
}

313 314
QIcon DebuggerRunControl::icon() const
{
315
    return QIcon(QLatin1String(ProjectExplorer::Constants::ICON_DEBUG_SMALL));
316 317
}

hjk's avatar
hjk committed
318
void DebuggerRunControl::setCustomEnvironment(Environment env)
319
{
320
    QTC_ASSERT(d->m_engine, return);
321
    d->m_engine->startParameters().environment = env;
322 323
}

324
void DebuggerRunControl::start()
325
{
326
    QTC_ASSERT(d->m_engine, return);
327 328 329
    // User canceled input dialog asking for executable when working on library project.
    if (d->m_engine->startParameters().startMode == StartInternal
        && d->m_engine->startParameters().executable.isEmpty()) {
hjk's avatar
hjk committed
330
        appendMessage(tr("No executable specified.\n"), ErrorMessageFormat);
331 332 333 334 335
        emit started();
        emit finished();
        return;
    }

336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
    if (d->m_engine->startParameters().startMode == StartInternal) {
        foreach (const BreakpointModelId &id, debuggerCore()->breakHandler()->allBreakpointIds()) {
            if (d->m_engine->breakHandler()->breakpointData(id).enabled
                    && !d->m_engine->acceptsBreakpoint(id)) {

                QString warningMessage =
                        DebuggerPlugin::tr("Some breakpoints cannot be handled by the debugger "
                                           "languages currently active, and will be ignored.");

                debuggerCore()->showMessage(warningMessage, LogWarning);

                QErrorMessage *msgBox = new QErrorMessage(debuggerCore()->mainWindow());
                msgBox->setAttribute(Qt::WA_DeleteOnClose);
                msgBox->showMessage(warningMessage);
                break;
            }
352 353 354
        }
    }

355
    debuggerCore()->runControlStarted(d->m_engine);
356

357 358
    // We might get a synchronous startFailed() notification on Windows,
    // when launching the process fails. Emit a proper finished() sequence.
359
    emit started();
360 361
    d->m_running = true;

362
    d->m_engine->startDebugger(this);
363

364
    if (d->m_running)
hjk's avatar
hjk committed
365
        appendMessage(tr("Debugging starts\n"), NormalMessageFormat);
366 367
}

368
void DebuggerRunControl::startFailed()
369
{
hjk's avatar
hjk committed
370
    appendMessage(tr("Debugging has failed\n"), NormalMessageFormat);
371
    d->m_running = false;
372
    emit finished();
373
    d->m_engine->handleStartFailed();
374 375
}

376
void DebuggerRunControl::handleFinished()
377
{
hjk's avatar
hjk committed
378
    appendMessage(tr("Debugging has finished\n"), NormalMessageFormat);
379 380 381
    if (d->m_engine)
        d->m_engine->handleFinished();
    debuggerCore()->runControlFinished(d->m_engine);
382 383
}

384
void DebuggerRunControl::showMessage(const QString &msg, int channel)
385
{
386 387
    switch (channel) {
        case AppOutput:
hjk's avatar
hjk committed
388
            appendMessage(msg, StdOutFormatSameLine);
389 390
            break;
        case AppError:
hjk's avatar
hjk committed
391
            appendMessage(msg, StdErrFormatSameLine);
392 393
            break;
        case AppStuff:
hjk's avatar
hjk committed
394
            appendMessage(msg, DebugFormat);
395 396
            break;
    }
397 398
}

399
bool DebuggerRunControl::promptToStop(bool *optionalPrompt) const
400
{
401
    QTC_ASSERT(isRunning(), return true);
402

403 404 405
    if (optionalPrompt && !*optionalPrompt)
        return true;

Jarek Kobus's avatar
Jarek Kobus committed
406
    const QString question = tr("A debugging session is still in progress. "
407 408 409
            "Terminating the session in the current"
            " state can leave the target in an inconsistent state."
            " Would you still like to terminate it?");
410 411
    return showPromptToStopDialog(tr("Close Debugging Session"), question,
                                  QString(), QString(), optionalPrompt);
412 413 414 415
}

RunControl::StopResult DebuggerRunControl::stop()
{
416 417
    QTC_ASSERT(d->m_engine, return StoppedSynchronously);
    d->m_engine->quitDebugger();
418
    return AsynchronousStop;
419 420
}

421
void DebuggerRunControl::debuggingFinished()
422
{
423
    d->m_running = false;
424
    emit finished();
425 426
}

427
bool DebuggerRunControl::isRunning() const
428
{
429
    return d->m_running;
430 431
}

432
DebuggerEngine *DebuggerRunControl::engine()
433
{
434
    QTC_CHECK(d->m_engine);
435
    return d->m_engine;
436 437
}

438 439 440 441
RunConfiguration *DebuggerRunControl::runConfiguration() const
{
    return d->m_myRunConfiguration.data();
}
442

443 444 445 446 447 448 449

////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControlFactory
//
////////////////////////////////////////////////////////////////////////

450 451
DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent)
    : IRunControlFactory(parent)
452 453
{}

454
bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
455
{
456
    return (mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain)
457 458 459 460 461
            && qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
}

QString DebuggerRunControlFactory::displayName() const
{
hjk's avatar
hjk committed
462
    return DebuggerPlugin::tr("Debug");
463 464
}

465
static DebuggerStartParameters localStartParameters(RunConfiguration *runConfiguration, QString *errorMessage)
466 467 468 469 470 471
{
    DebuggerStartParameters sp;
    QTC_ASSERT(runConfiguration, return sp);
    LocalApplicationRunConfiguration *rc =
            qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
    QTC_ASSERT(rc, return sp);
472 473
    if (!rc->ensureConfigured(errorMessage))
        return sp;
474

hjk's avatar
hjk committed
475
    Target *target = runConfiguration->target();
Tobias Hunger's avatar
Tobias Hunger committed
476
    Kit *kit = target ? target->kit() : KitManager::instance()->defaultKit();
477 478
    if (!fillParameters(&sp, kit, errorMessage))
        return sp;
479 480
    sp.environment = rc->environment();
    sp.workingDirectory = rc->workingDirectory();
481 482 483

#if defined(Q_OS_WIN)
    // Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
hjk's avatar
hjk committed
484
    sp.workingDirectory = normalizePathName(sp.workingDirectory);
485 486
#endif

487
    sp.executable = rc->executable();
488 489 490
    if (sp.executable.isEmpty())
        return sp;
    sp.startMode = StartInternal;
491 492 493 494 495
    sp.processArgs = rc->commandLineArguments();
    sp.useTerminal = rc->runMode() == LocalApplicationRunConfiguration::Console;
    sp.dumperLibrary = rc->dumperLibrary();
    sp.dumperLibraryLocations = rc->dumperLibraryLocations();

hjk's avatar
hjk committed
496 497
    if (target) {
        if (const Project *project = target->project()) {
498
            sp.projectSourceDirectory = project->projectDirectory();
hjk's avatar
hjk committed
499
            if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration())
500 501
                sp.projectBuildDirectory = buildConfig->buildDirectory();
            sp.projectSourceFiles = project->files(Project::ExcludeGeneratedFiles);
502 503 504
        }
    }

505 506 507 508
    DebuggerRunConfigurationAspect *aspect = runConfiguration->debuggerAspect();
    sp.multiProcess = aspect->useMultiProcess();

    if (aspect->useCppDebugger())
509 510
        sp.languages |= CppLanguage;

511
    if (aspect->useQmlDebugger()) {
512
        sp.qmlServerAddress = _("127.0.0.1");
513
        sp.qmlServerPort = aspect->qmlDebugServerPort();
514
        sp.languages |= QmlLanguage;
515

516 517
        // Makes sure that all bindings go through the JavaScript engine, so that
        // breakpoints are actually hit!
518
        const QString optimizerKey = _("QML_DISABLE_OPTIMIZER");
hjk's avatar
hjk committed
519
        if (!sp.environment.hasKey(optimizerKey))
520
            sp.environment.set(optimizerKey, _("1"));
521

hjk's avatar
hjk committed
522
        QtcProcess::addArg(&sp.processArgs, QString::fromLatin1("-qmljsdebugger=port:%1,block").arg(sp.qmlServerPort));
523 524 525 526 527 528 529 530 531 532 533 534
    }

    // FIXME: If it's not yet build this will be empty and not filled
    // when rebuild as the runConfiguration is not stored and therefore
    // cannot be used to retrieve the dumper location.
    //qDebug() << "DUMPER: " << sp.dumperLibrary << sp.dumperLibraryLocations;
    sp.displayName = rc->displayName();

    return sp;
}

RunControl *DebuggerRunControlFactory::create
535
    (RunConfiguration *runConfiguration, RunMode mode, QString *errorMessage)
536
{
537
    QTC_ASSERT(mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain, return 0);
538
    DebuggerStartParameters sp = localStartParameters(runConfiguration, errorMessage);
539 540
    if (sp.startMode == NoStartMode)
        return 0;
541
    if (mode == DebugRunModeWithBreakOnMain)
542
        sp.breakOnMain = true;
hjk's avatar
hjk committed
543

544
    return doCreate(sp, runConfiguration, errorMessage);
545 546
}

547
static bool fixupEngineTypes(DebuggerStartParameters &sp, RunConfiguration *rc, QString *errorMessage)
hjk's avatar
hjk committed
548 549
{
    if (sp.masterEngineType != NoEngineType)
550
        return true;
hjk's avatar
hjk committed
551 552 553

    if (sp.executable.endsWith(_(".js"))) {
        sp.masterEngineType = ScriptEngineType;
554
        return true;
hjk's avatar
hjk committed
555 556 557 558
    }

    if (sp.executable.endsWith(_(".py"))) {
        sp.masterEngineType = PdbEngineType;
559
        return true;
hjk's avatar
hjk committed
560 561 562 563
    }

    if (rc) {
        DebuggerRunConfigurationAspect *aspect = rc->debuggerAspect();
564
        if (const Target *target = rc->target())
565 566
            if (!fillParameters(&sp, target->kit(), errorMessage))
                return false;
567 568
        const bool useCppDebugger = aspect->useCppDebugger();
        const bool useQmlDebugger = aspect->useQmlDebugger();
hjk's avatar
hjk committed
569 570 571
        if (useQmlDebugger) {
            if (useCppDebugger) {
                sp.masterEngineType = QmlCppEngineType;
572
                sp.firstSlaveEngineType = sp.cppEngineType;
hjk's avatar
hjk committed
573 574 575 576 577
                sp.secondSlaveEngineType = QmlCppEngineType;
            } else {
                sp.masterEngineType = QmlEngineType;
            }
        } else {
578
            sp.masterEngineType = sp.cppEngineType;
hjk's avatar
hjk committed
579
        }
580
        return true;
hjk's avatar
hjk committed
581
    }
582 583
    sp.masterEngineType = sp.cppEngineType;
    return true;
hjk's avatar
hjk committed
584 585 586
}

DebuggerRunControl *DebuggerRunControlFactory::doCreate
587
    (const DebuggerStartParameters &sp0, RunConfiguration *rc, QString *errorMessage)
hjk's avatar
hjk committed
588
{
589 590 591 592 593
    TaskHub *th = ProjectExplorerPlugin::instance()->taskHub();
    th->clearTasks(Core::Id(Debugger::Constants::TASK_CATEGORY_DEBUGGER_DEBUGINFO));
    th->clearTasks(Core::Id(Debugger::Constants::TASK_CATEGORY_DEBUGGER_TEST));
    th->clearTasks(Core::Id(Debugger::Constants::TASK_CATEGORY_DEBUGGER_RUNTIME));

hjk's avatar
hjk committed
594 595 596
    DebuggerStartParameters sp = sp0;
    if (!debuggerCore()->boolSetting(AutoEnrichParameters)) {
        const QString sysroot = sp.sysRoot;
597
        if (sp.debugInfoLocation.isEmpty())
hjk's avatar
hjk committed
598 599 600 601 602 603 604 605 606
            sp.debugInfoLocation = sysroot + QLatin1String("/usr/lib/debug");
        if (sp.debugSourceLocation.isEmpty()) {
            QString base = sysroot + QLatin1String("/usr/src/debug/");
            sp.debugSourceLocation.append(base + QLatin1String("qt5base/src/corelib"));
            sp.debugSourceLocation.append(base + QLatin1String("qt5base/src/gui"));
            sp.debugSourceLocation.append(base + QLatin1String("qt5base/src/network"));
            sp.debugSourceLocation.append(base + QLatin1String("qt5base/src/v8"));
            sp.debugSourceLocation.append(base + QLatin1String("qt5declarative/src/qml"));
        }
607 608
    }

609
    if (!fixupEngineTypes(sp, rc, errorMessage))
hjk's avatar
hjk committed
610 611 612 613 614 615 616 617
        return 0;

    return new DebuggerRunControl(rc, sp);
}

DebuggerRunControl *DebuggerRunControlFactory::createAndScheduleRun
    (const DebuggerStartParameters &sp, RunConfiguration *runConfiguration)
{
618
    QString errorMessage;
619 620 621
    if (runConfiguration && !runConfiguration->ensureConfigured(&errorMessage))
        ProjectExplorer::ProjectExplorerPlugin::showRunErrorMessage(errorMessage);

622 623 624
    DebuggerRunControl *rc = doCreate(sp, runConfiguration, &errorMessage);
    if (!rc) {
        ProjectExplorer::ProjectExplorerPlugin::showRunErrorMessage(errorMessage);
hjk's avatar
hjk committed
625
        return 0;
626
    }
hjk's avatar
hjk committed
627 628 629 630 631 632 633 634 635
    debuggerCore()->showMessage(sp.startMessage, 0);
    ProjectExplorerPlugin::instance()->startRunControl(rc, DebugRunMode);
    return rc;
}

RunConfigWidget *DebuggerRunControlFactory::createConfigurationWidget
    (RunConfiguration *runConfiguration)
{
    return new DebuggerRunConfigWidget(runConfiguration);
636 637
}

638 639
DebuggerEngine *DebuggerRunControlFactory::createEngine(DebuggerEngineType et,
    const DebuggerStartParameters &sp, QString *errorMessage)
640 641 642
{
    switch (et) {
    case GdbEngineType:
643
        return createGdbEngine(sp);
644 645 646
    case ScriptEngineType:
        return createScriptEngine(sp);
    case CdbEngineType:
647
        return createCdbEngine(sp, errorMessage);
648 649 650
    case PdbEngineType:
        return createPdbEngine(sp);
    case QmlEngineType:
651
        return createQmlEngine(sp);
652 653
    case LldbEngineType:
        return createLldbEngine(sp);
hjk's avatar
hjk committed
654 655
    case QmlCppEngineType:
        return createQmlCppEngine(sp, errorMessage);
656 657
    default:
        break;
658
    }
hjk's avatar
hjk committed
659
    *errorMessage = DebuggerPlugin::tr("Unable to create a debugger engine of the type '%1'").
660
                    arg(_(engineTypeName(et)));
661 662 663
    return 0;
}

hjk's avatar
hjk committed
664
} // namespace Debugger
665 666

#include "debuggerrunner.moc"