debuggerrunner.cpp 22.4 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
hjk's avatar
hjk committed
3
4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** 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 "debuggerinternalconstants.h"
35
#include "debuggercore.h"
36
#include "debuggerengine.h"
37
#include "debuggermainwindow.h"
38
39
#include "debuggerplugin.h"
#include "debuggerstringutils.h"
Friedemann Kleint's avatar
Friedemann Kleint committed
40
#include "debuggerstartparameters.h"
Tobias Hunger's avatar
Tobias Hunger committed
41
#include "debuggerkitinformation.h"
42
#include "lldb/lldbenginehost.h"
43
#include "debuggertooltipmanager.h"
44

Friedemann Kleint's avatar
Friedemann Kleint committed
45
46
#ifdef Q_OS_WIN
#  include "peutils.h"
47
#  include <utils/winutils.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
48
49
#endif

50
#include <projectexplorer/abi.h>
hjk's avatar
hjk committed
51
52
#include <projectexplorer/applicationrunconfiguration.h> // For LocalApplication*
#include <projectexplorer/buildconfiguration.h>
con's avatar
con committed
53
#include <projectexplorer/project.h>
hjk's avatar
hjk committed
54
#include <projectexplorer/projectexplorer.h>
Tobias Hunger's avatar
Tobias Hunger committed
55
#include <projectexplorer/target.h>
56
#include <projectexplorer/taskhub.h>
57
#include <projectexplorer/toolchain.h>
con's avatar
con committed
58

con's avatar
con committed
59
#include <utils/outputformat.h>
60
#include <utils/synchronousprocess.h>
hjk's avatar
hjk committed
61
#include <utils/qtcassert.h>
62
#include <utils/fancymainwindow.h>
63
#include <utils/qtcprocess.h>
64
#include <coreplugin/icore.h>
65
#include <coreplugin/helpmanager.h>
hjk's avatar
hjk committed
66

67
#include <QDir>
68
69
#include <QCheckBox>
#include <QSpinBox>
70
71
#include <QDebug>
#include <QErrorMessage>
72
73
#include <QFormLayout>
#include <QLabel>
74
#include <QPointer>
con's avatar
con committed
75

76
using namespace Debugger::Internal;
hjk's avatar
hjk committed
77
78
using namespace ProjectExplorer;
using namespace Utils;
79

80
81
enum { debug = 0 };

82
namespace Debugger {
83
namespace Internal {
84

85
86
DebuggerEngine *createCdbEngine(const DebuggerStartParameters &sp, QString *error);
DebuggerEngine *createGdbEngine(const DebuggerStartParameters &sp);
hjk's avatar
hjk committed
87
88
DebuggerEngine *createScriptEngine(const DebuggerStartParameters &sp);
DebuggerEngine *createPdbEngine(const DebuggerStartParameters &sp);
89
90
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &sp);
DebuggerEngine *createQmlCppEngine(const DebuggerStartParameters &sp, QString *error);
hjk's avatar
hjk committed
91
DebuggerEngine *createLldbEngine(const DebuggerStartParameters &sp);
92

93
94
95
96
97
98
static const char *engineTypeName(DebuggerEngineType et)
{
    switch (et) {
    case Debugger::NoEngineType:
        break;
    case Debugger::GdbEngineType:
99
        return "Gdb engine";
100
101
102
103
104
    case Debugger::ScriptEngineType:
        return "Script engine";
    case Debugger::CdbEngineType:
        return "Cdb engine";
    case Debugger::PdbEngineType:
105
        return "Pdb engine";
106
107
108
109
110
111
112
113
114
115
116
117
    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";
}

118
119
120
121
122
123
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunConfigWidget
//
////////////////////////////////////////////////////////////////////////

hjk's avatar
hjk committed
124
class DebuggerRunConfigWidget : public RunConfigWidget
125
126
127
128
{
    Q_OBJECT

public:
129
130
    explicit DebuggerRunConfigWidget(RunConfiguration *runConfiguration);
    QString displayName() const { return tr("Debugger Settings"); }
131
132

private slots:
133
134
    void useCppDebuggerToggled(bool on);
    void useQmlDebuggerToggled(bool on);
135
    void qmlDebugServerPortChanged(int port);
136
    void useMultiProcessToggled(bool on);
137
138

public:
139
    DebuggerRunConfigurationAspect *m_aspect; // not owned
140
141
142
143
144
145

    QCheckBox *m_useCppDebugger;
    QCheckBox *m_useQmlDebugger;
    QSpinBox *m_debugServerPort;
    QLabel *m_debugServerPortLabel;
    QLabel *m_qmlDebuggerInfoLabel;
146
    QCheckBox *m_useMultiProcess;
147
148
};

149
DebuggerRunConfigWidget::DebuggerRunConfigWidget(RunConfiguration *runConfiguration)
150
{
151
    m_aspect = runConfiguration->debuggerAspect();
152

153
154
    m_useCppDebugger = new QCheckBox(tr("Enable C++"), this);
    m_useQmlDebugger = new QCheckBox(tr("Enable QML"), this);
155
156
157
158
159

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

160
    m_debugServerPortLabel = new QLabel(tr("Debug port:"), this);
161
162
163
164
165
166
    m_debugServerPortLabel->setBuddy(m_debugServerPort);

    m_qmlDebuggerInfoLabel = new QLabel(tr("<a href=\""
        "qthelp://com.nokia.qtcreator/doc/creator-debugging-qml.html"
        "\">What are the prerequisites?</a>"));

167
168
169
    m_useCppDebugger->setChecked(m_aspect->useCppDebugger());
    m_useQmlDebugger->setChecked(m_aspect->useQmlDebugger());

170
    m_debugServerPort->setValue(m_aspect->qmlDebugServerPort());
171

172
173
174
175
176
177
    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());

178
    connect(m_qmlDebuggerInfoLabel, SIGNAL(linkActivated(QString)),
179
            Core::HelpManager::instance(), SLOT(handleHelpRequest(QString)));
180
    connect(m_useQmlDebugger, SIGNAL(toggled(bool)),
181
182
183
            SLOT(useQmlDebuggerToggled(bool)));
    connect(m_useCppDebugger, SIGNAL(toggled(bool)),
            SLOT(useCppDebuggerToggled(bool)));
184
    connect(m_debugServerPort, SIGNAL(valueChanged(int)),
185
            SLOT(qmlDebugServerPortChanged(int)));
186
187
    connect(m_useMultiProcess, SIGNAL(toggled(bool)),
            SLOT(useMultiProcessToggled(bool)));
188

189
190
191
    if (m_aspect->isDisplaySuppressed())
        hide();

192
    if (m_aspect->areQmlDebuggingOptionsSuppressed()) {
193
194
195
196
        m_debugServerPortLabel->hide();
        m_debugServerPort->hide();
        m_useQmlDebugger->hide();
    }
197

198
199
200
    if (m_aspect->areCppDebuggingOptionsSuppressed())
        m_useCppDebugger->hide();

201
202
203
204
205
    if (m_aspect->isQmlDebuggingSpinboxSuppressed()) {
        m_debugServerPort->hide();
        m_debugServerPortLabel->hide();
    }

206
207
208
209
210
211
212
213
214
215
216
217
    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);
218
    layout->addWidget(m_useMultiProcess);
219
220
221
    setLayout(layout);
}

222
void DebuggerRunConfigWidget::qmlDebugServerPortChanged(int port)
223
{
224
    m_aspect->m_qmlDebugServerPort = port;
225
226
}

227
void DebuggerRunConfigWidget::useCppDebuggerToggled(bool on)
228
{
229
230
    m_aspect->m_useCppDebugger = on;
    if (!on && !m_useQmlDebugger->isChecked())
231
232
233
        m_useQmlDebugger->setChecked(true);
}

234
void DebuggerRunConfigWidget::useQmlDebuggerToggled(bool on)
235
{
236
237
    m_debugServerPort->setEnabled(on);
    m_debugServerPortLabel->setEnabled(on);
238

239
    m_aspect->m_useQmlDebugger = on
240
241
            ? DebuggerRunConfigurationAspect::EnableQmlDebugger
            : DebuggerRunConfigurationAspect::DisableQmlDebugger;
242
    if (!on && !m_useCppDebugger->isChecked())
243
244
245
        m_useCppDebugger->setChecked(true);
}

246
247
248
249
250
void DebuggerRunConfigWidget::useMultiProcessToggled(bool on)
{
    m_aspect->m_useMultiProcess = on;
}

251
252
////////////////////////////////////////////////////////////////////////
//
hjk's avatar
hjk committed
253
// DebuggerRunControlPrivate
254
255
256
//
////////////////////////////////////////////////////////////////////////

hjk's avatar
hjk committed
257
258
259
class DebuggerRunControlPrivate
{
public:
260
261
    explicit DebuggerRunControlPrivate(DebuggerRunControl *parent,
                                       RunConfiguration *runConfiguration);
262

hjk's avatar
hjk committed
263
264
public:
    DebuggerRunControl *q;
265
    DebuggerEngine *m_engine;
266
    const QPointer<RunConfiguration> m_myRunConfiguration;
267
268
269
    bool m_running;
};

hjk's avatar
hjk committed
270
DebuggerRunControlPrivate::DebuggerRunControlPrivate(DebuggerRunControl *parent,
271
                                                     RunConfiguration *runConfiguration)
hjk's avatar
hjk committed
272
273
    : q(parent)
    , m_engine(0)
274
    , m_myRunConfiguration(runConfiguration)
275
    , m_running(false)
276
277
{
}
278

hjk's avatar
hjk committed
279
280
} // namespace Internal

hjk's avatar
hjk committed
281
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
hjk's avatar
hjk committed
282
                                       const DebuggerStartParameters &sp)
hjk's avatar
hjk committed
283
    : RunControl(runConfiguration, DebugRunMode),
284
      d(new DebuggerRunControlPrivate(this, runConfiguration))
285
{
hjk's avatar
hjk committed
286
    connect(this, SIGNAL(finished()), SLOT(handleFinished()));
287
288
289
    // Create the engine. Could arguably be moved to the factory, but
    // we still have a derived S60DebugControl. Should rarely fail, though.
    QString errorMessage;
290
    d->m_engine = DebuggerRunControlFactory::createEngine(sp.masterEngineType, sp, &errorMessage);
hjk's avatar
hjk committed
291

292
293
294
    if (d->m_engine) {
        DebuggerToolTipManager::instance()->registerEngine(d->m_engine);
    } else {
295
        debuggingFinished();
hjk's avatar
hjk committed
296
        Core::ICore::showWarningWithOptions(DebuggerRunControl::tr("Debugger"), errorMessage);
297
    }
298
299
}

hjk's avatar
hjk committed
300
301
302
303
304
305
306
307
DebuggerRunControl::~DebuggerRunControl()
{
    disconnect();
    if (DebuggerEngine *engine = d->m_engine) {
        d->m_engine = 0;
        engine->disconnect();
        delete engine;
    }
hjk's avatar
hjk committed
308
    delete d;
hjk's avatar
hjk committed
309
310
311
312
313
314
315
316
}

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

317
QString DebuggerRunControl::displayName() const
318
{
319
320
    QTC_ASSERT(d->m_engine, return QString());
    return d->m_engine->startParameters().displayName;
321
322
}

323
324
QIcon DebuggerRunControl::icon() const
{
325
    return QIcon(QLatin1String(ProjectExplorer::Constants::ICON_DEBUG_SMALL));
326
327
}

hjk's avatar
hjk committed
328
void DebuggerRunControl::setCustomEnvironment(Environment env)
329
{
330
    QTC_ASSERT(d->m_engine, return);
331
    d->m_engine->startParameters().environment = env;
332
333
}

334
void DebuggerRunControl::start()
335
{
336
    QTC_ASSERT(d->m_engine, return);
337
338
339
    // 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
340
        appendMessage(tr("No executable specified.\n"), ErrorMessageFormat);
341
342
343
344
345
        emit started();
        emit finished();
        return;
    }

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
    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;
            }
362
363
364
        }
    }

365
    debuggerCore()->runControlStarted(d->m_engine);
366

367
368
    // We might get a synchronous startFailed() notification on Windows,
    // when launching the process fails. Emit a proper finished() sequence.
369
    emit started();
370
371
    d->m_running = true;

372
    d->m_engine->startDebugger(this);
373

374
    if (d->m_running)
hjk's avatar
hjk committed
375
        appendMessage(tr("Debugging starts\n"), NormalMessageFormat);
376
377
}

378
void DebuggerRunControl::startFailed()
379
{
hjk's avatar
hjk committed
380
    appendMessage(tr("Debugging has failed\n"), NormalMessageFormat);
381
    d->m_running = false;
382
    emit finished();
383
    d->m_engine->handleStartFailed();
384
385
}

386
void DebuggerRunControl::handleFinished()
387
{
hjk's avatar
hjk committed
388
    appendMessage(tr("Debugging has finished\n"), NormalMessageFormat);
389
390
391
    if (d->m_engine)
        d->m_engine->handleFinished();
    debuggerCore()->runControlFinished(d->m_engine);
392
393
}

394
void DebuggerRunControl::showMessage(const QString &msg, int channel)
395
{
396
397
    switch (channel) {
        case AppOutput:
hjk's avatar
hjk committed
398
            appendMessage(msg, StdOutFormatSameLine);
399
400
            break;
        case AppError:
hjk's avatar
hjk committed
401
            appendMessage(msg, StdErrFormatSameLine);
402
403
            break;
        case AppStuff:
hjk's avatar
hjk committed
404
            appendMessage(msg, DebugFormat);
405
406
            break;
    }
407
408
}

409
bool DebuggerRunControl::promptToStop(bool *optionalPrompt) const
410
{
411
    QTC_ASSERT(isRunning(), return true);
412

413
414
415
    if (optionalPrompt && !*optionalPrompt)
        return true;

Jarek Kobus's avatar
Jarek Kobus committed
416
    const QString question = tr("A debugging session is still in progress. "
417
418
419
            "Terminating the session in the current"
            " state can leave the target in an inconsistent state."
            " Would you still like to terminate it?");
420
421
    return showPromptToStopDialog(tr("Close Debugging Session"), question,
                                  QString(), QString(), optionalPrompt);
422
423
424
425
}

RunControl::StopResult DebuggerRunControl::stop()
{
426
427
    QTC_ASSERT(d->m_engine, return StoppedSynchronously);
    d->m_engine->quitDebugger();
428
    return AsynchronousStop;
429
430
}

431
void DebuggerRunControl::debuggingFinished()
432
{
433
    d->m_running = false;
434
    emit finished();
435
436
}

437
bool DebuggerRunControl::isRunning() const
438
{
439
    return d->m_running;
440
441
}

442
DebuggerEngine *DebuggerRunControl::engine()
443
{
444
    QTC_CHECK(d->m_engine);
445
    return d->m_engine;
446
447
}

448
449
450
451
RunConfiguration *DebuggerRunControl::runConfiguration() const
{
    return d->m_myRunConfiguration.data();
}
452

453
454
455
456
457
458
459

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

460
461
DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent)
    : IRunControlFactory(parent)
462
463
{}

464
bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
465
{
466
    return (mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain)
467
468
469
470
471
            && qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
}

QString DebuggerRunControlFactory::displayName() const
{
hjk's avatar
hjk committed
472
    return DebuggerPlugin::tr("Debug");
473
474
}

475
static DebuggerStartParameters localStartParameters(RunConfiguration *runConfiguration, QString *errorMessage)
476
477
478
479
480
481
{
    DebuggerStartParameters sp;
    QTC_ASSERT(runConfiguration, return sp);
    LocalApplicationRunConfiguration *rc =
            qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
    QTC_ASSERT(rc, return sp);
482
483
    if (!rc->ensureConfigured(errorMessage))
        return sp;
484

hjk's avatar
hjk committed
485
    Target *target = runConfiguration->target();
Tobias Hunger's avatar
Tobias Hunger committed
486
    Kit *kit = target ? target->kit() : KitManager::instance()->defaultKit();
487
488
    if (!fillParameters(&sp, kit, errorMessage))
        return sp;
489
490
    sp.environment = rc->environment();
    sp.workingDirectory = rc->workingDirectory();
491
492
493

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

497
    sp.executable = rc->executable();
498
499
500
    if (sp.executable.isEmpty())
        return sp;
    sp.startMode = StartInternal;
501
502
503
504
505
    sp.processArgs = rc->commandLineArguments();
    sp.useTerminal = rc->runMode() == LocalApplicationRunConfiguration::Console;
    sp.dumperLibrary = rc->dumperLibrary();
    sp.dumperLibraryLocations = rc->dumperLibraryLocations();

hjk's avatar
hjk committed
506
507
    if (target) {
        if (const Project *project = target->project()) {
508
            sp.projectSourceDirectory = project->projectDirectory();
hjk's avatar
hjk committed
509
            if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration())
510
511
                sp.projectBuildDirectory = buildConfig->buildDirectory();
            sp.projectSourceFiles = project->files(Project::ExcludeGeneratedFiles);
512
513
514
        }
    }

515
516
517
518
    DebuggerRunConfigurationAspect *aspect = runConfiguration->debuggerAspect();
    sp.multiProcess = aspect->useMultiProcess();

    if (aspect->useCppDebugger())
519
520
        sp.languages |= CppLanguage;

521
    if (aspect->useQmlDebugger()) {
522
        sp.qmlServerAddress = _("127.0.0.1");
523
        sp.qmlServerPort = aspect->qmlDebugServerPort();
524
        sp.languages |= QmlLanguage;
525

526
527
        // Makes sure that all bindings go through the JavaScript engine, so that
        // breakpoints are actually hit!
528
        const QString optimizerKey = _("QML_DISABLE_OPTIMIZER");
hjk's avatar
hjk committed
529
        if (!sp.environment.hasKey(optimizerKey))
530
            sp.environment.set(optimizerKey, _("1"));
531

hjk's avatar
hjk committed
532
        QtcProcess::addArg(&sp.processArgs, QString::fromLatin1("-qmljsdebugger=port:%1,block").arg(sp.qmlServerPort));
533
534
535
536
537
538
539
540
541
542
543
544
    }

    // 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
545
    (RunConfiguration *runConfiguration, RunMode mode, QString *errorMessage)
546
{
547
    QTC_ASSERT(mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain, return 0);
548
    DebuggerStartParameters sp = localStartParameters(runConfiguration, errorMessage);
549
550
    if (sp.startMode == NoStartMode)
        return 0;
551
    if (mode == DebugRunModeWithBreakOnMain)
552
        sp.breakOnMain = true;
hjk's avatar
hjk committed
553

554
    return doCreate(sp, runConfiguration, errorMessage);
555
556
}

557
static bool fixupEngineTypes(DebuggerStartParameters &sp, RunConfiguration *rc, QString *errorMessage)
hjk's avatar
hjk committed
558
559
{
    if (sp.masterEngineType != NoEngineType)
560
        return true;
hjk's avatar
hjk committed
561
562
563

    if (sp.executable.endsWith(_(".js"))) {
        sp.masterEngineType = ScriptEngineType;
564
        return true;
hjk's avatar
hjk committed
565
566
567
568
    }

    if (sp.executable.endsWith(_(".py"))) {
        sp.masterEngineType = PdbEngineType;
569
        return true;
hjk's avatar
hjk committed
570
571
572
573
    }

    if (rc) {
        DebuggerRunConfigurationAspect *aspect = rc->debuggerAspect();
574
        if (const Target *target = rc->target())
575
576
            if (!fillParameters(&sp, target->kit(), errorMessage))
                return false;
577
578
        const bool useCppDebugger = aspect->useCppDebugger();
        const bool useQmlDebugger = aspect->useQmlDebugger();
hjk's avatar
hjk committed
579
580
581
        if (useQmlDebugger) {
            if (useCppDebugger) {
                sp.masterEngineType = QmlCppEngineType;
582
                sp.firstSlaveEngineType = sp.cppEngineType;
hjk's avatar
hjk committed
583
584
585
586
587
                sp.secondSlaveEngineType = QmlCppEngineType;
            } else {
                sp.masterEngineType = QmlEngineType;
            }
        } else {
588
            sp.masterEngineType = sp.cppEngineType;
hjk's avatar
hjk committed
589
        }
590
        return true;
hjk's avatar
hjk committed
591
    }
592
593
    sp.masterEngineType = sp.cppEngineType;
    return true;
hjk's avatar
hjk committed
594
595
596
}

DebuggerRunControl *DebuggerRunControlFactory::doCreate
597
    (const DebuggerStartParameters &sp0, RunConfiguration *rc, QString *errorMessage)
hjk's avatar
hjk committed
598
{
599
    Q_UNUSED(errorMessage);
600
601
602
603
604
605

    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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
    DebuggerStartParameters sp = sp0;
    if (!debuggerCore()->boolSetting(AutoEnrichParameters)) {
        const QString sysroot = sp.sysRoot;
        if (sp.debugInfoLocation.isEmpty()) {
            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"));
        }
620
621
    }

622
    if (!fixupEngineTypes(sp, rc, errorMessage))
hjk's avatar
hjk committed
623
624
625
626
627
628
629
630
        return 0;

    return new DebuggerRunControl(rc, sp);
}

DebuggerRunControl *DebuggerRunControlFactory::createAndScheduleRun
    (const DebuggerStartParameters &sp, RunConfiguration *runConfiguration)
{
631
    QString errorMessage;
632
633
634
    if (runConfiguration && !runConfiguration->ensureConfigured(&errorMessage))
        ProjectExplorer::ProjectExplorerPlugin::showRunErrorMessage(errorMessage);

635
636
637
    DebuggerRunControl *rc = doCreate(sp, runConfiguration, &errorMessage);
    if (!rc) {
        ProjectExplorer::ProjectExplorerPlugin::showRunErrorMessage(errorMessage);
hjk's avatar
hjk committed
638
        return 0;
639
    }
hjk's avatar
hjk committed
640
641
642
643
644
645
646
647
648
    debuggerCore()->showMessage(sp.startMessage, 0);
    ProjectExplorerPlugin::instance()->startRunControl(rc, DebugRunMode);
    return rc;
}

RunConfigWidget *DebuggerRunControlFactory::createConfigurationWidget
    (RunConfiguration *runConfiguration)
{
    return new DebuggerRunConfigWidget(runConfiguration);
649
650
}

651
652
DebuggerEngine *DebuggerRunControlFactory::createEngine(DebuggerEngineType et,
    const DebuggerStartParameters &sp, QString *errorMessage)
653
654
655
{
    switch (et) {
    case GdbEngineType:
656
        return createGdbEngine(sp);
657
658
659
    case ScriptEngineType:
        return createScriptEngine(sp);
    case CdbEngineType:
660
        return createCdbEngine(sp, errorMessage);
661
662
663
    case PdbEngineType:
        return createPdbEngine(sp);
    case QmlEngineType:
664
        return createQmlEngine(sp);
665
666
    case LldbEngineType:
        return createLldbEngine(sp);
hjk's avatar
hjk committed
667
668
    case QmlCppEngineType:
        return createQmlCppEngine(sp, errorMessage);
669
670
    default:
        break;
671
    }
hjk's avatar
hjk committed
672
    *errorMessage = DebuggerPlugin::tr("Unable to create a debugger engine of the type '%1'").
673
                    arg(_(engineTypeName(et)));
674
675
676
    return 0;
}

hjk's avatar
hjk committed
677
} // namespace Debugger
678
679

#include "debuggerrunner.moc"