debuggerrunner.cpp 20.9 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
31
**
32
**************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34
#include "debuggerrunner.h"
35
#include "debuggerruncontrolfactory.h"
con's avatar
con committed
36

37
#include "debuggeractions.h"
38
#include "debuggercore.h"
39
#include "debuggerengine.h"
40
#include "debuggermainwindow.h"
41 42
#include "debuggerplugin.h"
#include "debuggerstringutils.h"
Friedemann Kleint's avatar
Friedemann Kleint committed
43
#include "debuggerstartparameters.h"
hjk's avatar
hjk committed
44
#include "gdb/gdboptionspage.h"
45
#include "lldb/lldbenginehost.h"
46

Friedemann Kleint's avatar
Friedemann Kleint committed
47 48 49 50
#ifdef Q_OS_WIN
#  include "peutils.h"
#endif

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

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>
hjk's avatar
hjk committed
65

con's avatar
con committed
66
#include <QtCore/QDir>
67
#include <QtGui/QMessageBox>
con's avatar
con committed
68

69
using namespace ProjectExplorer;
70 71
using namespace Debugger::Internal;

72
namespace Debugger {
73
namespace Internal {
74

hjk's avatar
hjk committed
75
bool isCdbEngineEnabled(); // Check the configuration page
76
ConfigurationCheck checkCdbConfiguration(ToolChainType toolChain);
77

78 79 80 81
DebuggerEngine *createCdbEngine(const DebuggerStartParameters &,
    DebuggerEngine *masterEngine, QString *error);
DebuggerEngine *createGdbEngine(const DebuggerStartParameters &,
    DebuggerEngine *masterEngine);
82 83 84
DebuggerEngine *createScriptEngine(const DebuggerStartParameters &);
DebuggerEngine *createPdbEngine(const DebuggerStartParameters &);
DebuggerEngine *createTcfEngine(const DebuggerStartParameters &);
85 86
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &,
    DebuggerEngine *masterEngine);
87
DebuggerEngine *createQmlCppEngine(const DebuggerStartParameters &);
hjk's avatar
hjk committed
88
DebuggerEngine *createLldbEngine(const DebuggerStartParameters &);
89

hjk's avatar
hjk committed
90
extern QString msgNoBinaryForToolChain(int tc);
91 92 93 94 95 96 97

static QString msgEngineNotAvailable(const char *engine)
{
    return DebuggerPlugin::tr("The application requires the debugger engine '%1', "
        "which is disabled.").arg(QLatin1String(engine));
}

98 99
////////////////////////////////////////////////////////////////////////
//
hjk's avatar
hjk committed
100
// DebuggerRunControlPrivate
101 102 103
//
////////////////////////////////////////////////////////////////////////

hjk's avatar
hjk committed
104 105 106 107
class DebuggerRunControlPrivate
{
public:
    DebuggerRunControlPrivate(DebuggerRunControl *parent,
108
        RunConfiguration *runConfiguration);
109

hjk's avatar
hjk committed
110 111 112 113 114 115 116
    DebuggerEngineType engineForExecutable(unsigned enabledEngineTypes,
        const QString &executable);
    DebuggerEngineType engineForMode(unsigned enabledEngineTypes,
        DebuggerStartMode mode);

public:
    DebuggerRunControl *q;
117 118 119 120 121 122 123
    DebuggerEngine *m_engine;
    const QWeakPointer<RunConfiguration> m_myRunConfiguration;
    bool m_running;
    QString m_errorMessage;
    QString m_settingsIdHint;
};

hjk's avatar
hjk committed
124
DebuggerRunControlPrivate::DebuggerRunControlPrivate(DebuggerRunControl *parent,
125
        RunConfiguration *runConfiguration)
hjk's avatar
hjk committed
126 127
    : q(parent)
    , m_engine(0)
128
    , m_myRunConfiguration(runConfiguration)
129
    , m_running(false)
130 131
{
}
132

133 134
// Figure out the debugger type of an executable. Analyze executable
// unless the toolchain provides a hint.
hjk's avatar
hjk committed
135 136
DebuggerEngineType DebuggerRunControlPrivate::engineForExecutable
    (unsigned enabledEngineTypes, const QString &executable)
137
{
138
    if (executable.endsWith(_(".js"))) {
139
        if (enabledEngineTypes & ScriptEngineType)
140
            return ScriptEngineType;
hjk's avatar
hjk committed
141
        m_errorMessage = msgEngineNotAvailable("Script Engine");
142
    }
con's avatar
con committed
143

144
    if (executable.endsWith(_(".py"))) {
145
        if (enabledEngineTypes & PdbEngineType)
146
            return PdbEngineType;
hjk's avatar
hjk committed
147
        m_errorMessage = msgEngineNotAvailable("Pdb Engine");
148
    }
con's avatar
con committed
149

150 151 152
#ifdef Q_OS_WIN
    // A remote executable?
    if (!executable.endsWith(_(".exe")))
Friedemann Kleint's avatar
Friedemann Kleint committed
153
        return GdbEngineType;
154 155 156

    // If a file has PDB files, it has been compiled by VS.
    QStringList pdbFiles;
hjk's avatar
hjk committed
157
    if (!getPDBFiles(executable, &pdbFiles, &m_errorMessage)) {
158
        qWarning("Cannot determine type of executable %s: %s",
hjk's avatar
hjk committed
159
                 qPrintable(executable), qPrintable(m_errorMessage));
Friedemann Kleint's avatar
Friedemann Kleint committed
160
        return NoEngineType;
161 162 163
    }
    if (pdbFiles.empty())
        return GdbEngineType;
164

165
    // We need the CDB debugger in order to be able to debug VS
hjk's avatar
hjk committed
166
    // executables.
167 168 169 170
   ConfigurationCheck check = checkDebugConfiguration(ToolChain_MSVC);
   if (!check) {
        m_errorMessage = check.errorMessage;
        m_settingsIdHint = check.settingsPage;
171 172
        if (enabledEngineTypes & CdbEngineType)
            return CdbEngineType;
hjk's avatar
hjk committed
173
        m_errorMessage = msgEngineNotAvailable("Cdb Engine");
174 175
        return NoEngineType;
    }
176
#else
177
    if (enabledEngineTypes & GdbEngineType)
178
        return GdbEngineType;
hjk's avatar
hjk committed
179
    m_errorMessage = msgEngineNotAvailable("Gdb Engine");
180
#endif
181

182
    return NoEngineType;
183 184
}

185
// Debugger type for mode.
hjk's avatar
hjk committed
186 187
DebuggerEngineType DebuggerRunControlPrivate::engineForMode
    (unsigned enabledEngineTypes, DebuggerStartMode startMode)
188
{
189 190
    if (startMode == AttachTcf)
        return TcfEngineType;
191

192 193
#ifdef Q_OS_WIN
    // Preferably Windows debugger for attaching locally.
194
    if (startMode != AttachToRemote && (enabledEngineTypes & CdbEngineType))
195
        return CdbEngineType;
196
    if (startMode == AttachCrashedExternal) {
197
        m_errorMessage = DebuggerRunControl::tr("There is no debugging engine available for post-mortem debugging.");
198 199
        return NoEngineType;
    }
Friedemann Kleint's avatar
Friedemann Kleint committed
200
    return GdbEngineType;
201 202
#else
    Q_UNUSED(startMode)
203
    Q_UNUSED(enabledEngineTypes)
hjk's avatar
hjk committed
204
    //  >m_errorMessage = msgEngineNotAvailable("Gdb Engine");
205 206
    return GdbEngineType;
#endif
207 208
}

hjk's avatar
hjk committed
209 210 211
} // namespace Internal


hjk's avatar
hjk committed
212 213 214 215 216 217
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControl
//
////////////////////////////////////////////////////////////////////////

218
static DebuggerEngineType engineForToolChain(ToolChainType toolChainType)
hjk's avatar
hjk committed
219 220
{
    switch (toolChainType) {
221 222 223 224 225 226 227 228 229
        case ToolChain_LINUX_ICC:
        case ToolChain_MinGW:
        case ToolChain_GCC:
        case ToolChain_WINSCW: // S60
        case ToolChain_GCCE:
        case ToolChain_RVCT2_ARMV5:
        case ToolChain_RVCT2_ARMV6:
        case ToolChain_RVCT_ARMV5_GNUPOC:
        case ToolChain_GCCE_GNUPOC:
230 231
        case ToolChain_GCC_MAEMO5:
        case ToolChain_GCC_HARMATTAN:
Christian Kandeler's avatar
Christian Kandeler committed
232
        case ToolChain_GCC_MEEGO:
233 234 235 236 237
#ifdef WITH_LLDB
            // lldb override
            if (Core::ICore::instance()->settings()->value("LLDB/enabled").toBool())
                return LldbEngineType;
#endif
hjk's avatar
hjk committed
238 239
            return GdbEngineType;

240

241 242
        case ToolChain_MSVC:
        case ToolChain_WINCE:
hjk's avatar
hjk committed
243 244
            return CdbEngineType;

245 246 247
        case ToolChain_OTHER:
        case ToolChain_UNKNOWN:
        case ToolChain_INVALID:
hjk's avatar
hjk committed
248 249 250 251 252 253
        default:
            break;
    }
    return NoEngineType;
}

254 255 256 257 258 259 260 261 262 263

unsigned filterEngines(unsigned enabledEngineTypes)
{
#ifdef CDB_ENABLED
    if (!isCdbEngineEnabled() && !Cdb::isCdbEngineEnabled())
       enabledEngineTypes &= ~CdbEngineType;
#endif
    return enabledEngineTypes;
}

hjk's avatar
hjk committed
264
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
265
        const DebuggerStartParameters &startParams)
hjk's avatar
hjk committed
266
    : RunControl(runConfiguration, Constants::DEBUGMODE),
267
      d(new DebuggerRunControlPrivate(this, runConfiguration))
268
{
hjk's avatar
hjk committed
269
    connect(this, SIGNAL(finished()), SLOT(handleFinished()));
270

271 272
    // Figure out engine according to toolchain, executable, attach or default.
    DebuggerEngineType engineType = NoEngineType;
273
    DebuggerLanguages activeLangs = debuggerCore()->activeLanguages();
hjk's avatar
hjk committed
274
    DebuggerStartParameters sp = startParams;
275 276
    unsigned enabledEngineTypes = filterEngines(sp.enabledEngines);

277
    if (sp.executable.endsWith(_(".js")))
278 279 280
        engineType = ScriptEngineType;
    else if (sp.executable.endsWith(_(".py")))
        engineType = PdbEngineType;
281
    else {
282
        engineType = engineForToolChain(sp.toolChainType);
283 284 285 286 287
        if (engineType == CdbEngineType && !(enabledEngineTypes & CdbEngineType)) {
            d->m_errorMessage = msgEngineNotAvailable("Cdb Engine");
            engineType = NoEngineType;
        }
    }
288

hjk's avatar
hjk committed
289
    // FIXME: Unclean ipc override. Someone please have a better idea.
290
    if (sp.startMode == StartRemoteEngine)
hjk's avatar
hjk committed
291
        // For now thats the only supported IPC engine.
292 293
        engineType = LldbEngineType;

hjk's avatar
hjk committed
294
    // FIXME: 1 of 3 testing hacks.
295
    if (sp.processArgs.startsWith(__("@tcf@ ")))
296 297
        engineType = GdbEngineType;

298 299 300
    if (engineType == NoEngineType
            && sp.startMode != AttachToRemote
            && !sp.executable.isEmpty())
hjk's avatar
hjk committed
301
        engineType = d->engineForExecutable(enabledEngineTypes, sp.executable);
302

303
    if (engineType == NoEngineType)
hjk's avatar
hjk committed
304
        engineType = d->engineForMode(enabledEngineTypes, sp.startMode);
305

306 307
    if ((engineType != QmlEngineType && engineType != NoEngineType)
        && (activeLangs & QmlLanguage)) {
308
        if (activeLangs & CppLanguage) {
309 310 311 312 313 314 315
            sp.cppEngineType = engineType;
            engineType = QmlCppEngineType;
        } else {
            engineType = QmlEngineType;
        }
    }

Friedemann Kleint's avatar
Friedemann Kleint committed
316
    // qDebug() << "USING ENGINE : " << engineType;
317 318 319

    switch (engineType) {
        case GdbEngineType:
320
            d->m_engine = createGdbEngine(sp, 0);
321
            break;
322
        case ScriptEngineType:
hjk's avatar
hjk committed
323
            d->m_engine = createScriptEngine(sp);
324
            break;
325
        case CdbEngineType:
326
            d->m_engine = createCdbEngine(sp, 0, &d->m_errorMessage);
327
            break;
328
        case PdbEngineType:
hjk's avatar
hjk committed
329
            d->m_engine = createPdbEngine(sp);
330
            break;
331
        case TcfEngineType:
hjk's avatar
hjk committed
332
            d->m_engine = createTcfEngine(sp);
333
            break;
334
        case QmlEngineType:
335
            d->m_engine = createQmlEngine(sp, 0);
336
            break;
337
        case QmlCppEngineType:
hjk's avatar
hjk committed
338
            d->m_engine = createQmlCppEngine(sp);
339
            break;
hjk's avatar
hjk committed
340 341
        case LldbEngineType:
            d->m_engine = createLldbEngine(sp);
342 343
        case NoEngineType:
        case AllEngineTypes:
344
            break;
345 346 347 348 349
    }

    if (!d->m_engine) {
        // Could not find anything suitable.
        debuggingFinished();
hjk's avatar
hjk committed
350
        // Create Message box with possibility to go to settings.
351
        QString toolChainName = ToolChain::toolChainName(sp.toolChainType);
352
        const QString msg = tr("Cannot debug '%1' (tool chain: '%2'): %3")
hjk's avatar
hjk committed
353
            .arg(sp.executable, toolChainName, d->m_errorMessage);
354
        Core::ICore::instance()->showWarningWithOptions(tr("Warning"),
hjk's avatar
hjk committed
355 356
            msg, QString(), QLatin1String(Constants::DEBUGGER_SETTINGS_CATEGORY),
            d->m_settingsIdHint);
357
    }
358 359
}

hjk's avatar
hjk committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
DebuggerRunControl::~DebuggerRunControl()
{
    disconnect();
    if (DebuggerEngine *engine = d->m_engine) {
        d->m_engine = 0;
        engine->disconnect();
        delete engine;
    }
}

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

376
QString DebuggerRunControl::displayName() const
377
{
378 379
    QTC_ASSERT(d->m_engine, return QString());
    return d->m_engine->startParameters().displayName;
380 381
}

382
void DebuggerRunControl::setCustomEnvironment(Utils::Environment env)
383
{
384
    QTC_ASSERT(d->m_engine, return);
385
    d->m_engine->startParameters().environment = env;
386 387
}

388
DEBUGGER_EXPORT ConfigurationCheck checkDebugConfiguration(ToolChainType toolChain)
389
{
390
    ConfigurationCheck result;
391

392
    if (!(debuggerCore()->activeLanguages() & CppLanguage))
393
        return result;
394

395
    switch(toolChain) {
396 397 398 399 400 401 402 403
    case ToolChain_GCC:
    case ToolChain_LINUX_ICC:
    case ToolChain_MinGW:
    case ToolChain_WINCE: // S60
    case ToolChain_WINSCW:
    case ToolChain_GCCE:
    case ToolChain_RVCT2_ARMV5:
    case ToolChain_RVCT2_ARMV6:
hjk's avatar
hjk committed
404
        if (debuggerCore()->gdbBinaryForToolChain(toolChain).isEmpty()) {
405 406 407
            result.errorMessage = msgNoBinaryForToolChain(toolChain);
            result.errorMessage += msgEngineNotAvailable("Gdb");
            result.settingsPage = GdbOptionsPage::settingsId();
hjk's avatar
hjk committed
408
        }
409
        break;
410
    case ToolChain_MSVC:
411
        result = checkCdbConfiguration(toolChain);
412 413 414
        if (!result) {
            result.errorMessage += msgEngineNotAvailable("Cdb");
            result.settingsPage = QLatin1String("Cdb");
415 416
        }
        break;
417 418
    default:
        break;
419
    }
hjk's avatar
hjk committed
420

421 422 423 424
    if (!result && !result.settingsPage.isEmpty())
        result.settingsCategory = QLatin1String(Constants::DEBUGGER_SETTINGS_CATEGORY);

    return result;
425 426
}

427
void DebuggerRunControl::start()
428
{
429
    QTC_ASSERT(d->m_engine, return);
430
    debuggerCore()->runControlStarted(d->m_engine);
431

432 433
    // We might get a synchronous startFailed() notification on Windows,
    // when launching the process fails. Emit a proper finished() sequence.
434
    emit started();
435 436
    d->m_running = true;

437
    d->m_engine->startDebugger(this);
438

439
    if (d->m_running)
440
        appendMessage(tr("Debugging starts"), NormalMessageFormat);
441 442
}

443
void DebuggerRunControl::startFailed()
444
{
445
    appendMessage(tr("Debugging has failed"), NormalMessageFormat);
446
    d->m_running = false;
447
    emit finished();
448
    d->m_engine->handleStartFailed();
449 450
}

451
void DebuggerRunControl::handleFinished()
452
{
453
    appendMessage(tr("Debugging has finished"), NormalMessageFormat);
454 455 456
    if (d->m_engine)
        d->m_engine->handleFinished();
    debuggerCore()->runControlFinished(d->m_engine);
457 458
}

459
void DebuggerRunControl::showMessage(const QString &msg, int channel)
460
{
461 462
    switch (channel) {
        case AppOutput:
463
            appendMessage(msg, StdOutFormatSameLine);
464 465
            break;
        case AppError:
466
            appendMessage(msg, StdErrFormatSameLine);
467 468
            break;
        case AppStuff:
469
            appendMessage(msg, NormalMessageFormat);
470 471
            break;
    }
472 473
}

474
bool DebuggerRunControl::promptToStop(bool *optionalPrompt) const
475
{
476 477
    QTC_ASSERT(isRunning(), return true;)

478 479 480
    if (optionalPrompt && !*optionalPrompt)
        return true;

Jarek Kobus's avatar
Jarek Kobus committed
481
    const QString question = tr("A debugging session is still in progress. "
482 483 484
            "Terminating the session in the current"
            " state can leave the target in an inconsistent state."
            " Would you still like to terminate it?");
485 486
    return showPromptToStopDialog(tr("Close Debugging Session"), question,
                                  QString(), QString(), optionalPrompt);
487 488 489 490
}

RunControl::StopResult DebuggerRunControl::stop()
{
491 492
    QTC_ASSERT(d->m_engine, return StoppedSynchronously);
    d->m_engine->quitDebugger();
493
    return AsynchronousStop;
494 495
}

496
void DebuggerRunControl::debuggingFinished()
497
{
498
    d->m_running = false;
499
    emit finished();
500 501
}

502
bool DebuggerRunControl::isRunning() const
503
{
504
    return d->m_running;
505 506
}

507
DebuggerEngine *DebuggerRunControl::engine()
508
{
509 510
    QTC_ASSERT(d->m_engine, /**/);
    return d->m_engine;
511 512
}

513 514 515 516
RunConfiguration *DebuggerRunControl::runConfiguration() const
{
    return d->m_myRunConfiguration.data();
}
517

518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539

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

// A factory to create DebuggerRunControls
DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent,
        unsigned enabledEngines)
    : IRunControlFactory(parent), m_enabledEngines(enabledEngines)
{}

bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
{
//    return mode == ProjectExplorer::Constants::DEBUGMODE;
    return mode == Constants::DEBUGMODE
            && qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
}

QString DebuggerRunControlFactory::displayName() const
{
Friedemann Kleint's avatar
Friedemann Kleint committed
540
    return DebuggerRunControl::tr("Debug");
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
}

// Find Qt installation by running qmake
static inline QString findQtInstallPath(const QString &qmakePath)
{
    QProcess proc;
    QStringList args;
    args.append(QLatin1String("-query"));
    args.append(QLatin1String("QT_INSTALL_HEADERS"));
    proc.start(qmakePath, args);
    if (!proc.waitForStarted()) {
        qWarning("%s: Cannot start '%s': %s", Q_FUNC_INFO, qPrintable(qmakePath),
           qPrintable(proc.errorString()));
        return QString();
    }
    proc.closeWriteChannel();
    if (!proc.waitForFinished()) {
        Utils::SynchronousProcess::stopProcess(proc);
        qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(qmakePath));
        return QString();
    }
    if (proc.exitStatus() != QProcess::NormalExit) {
        qWarning("%s: '%s' crashed.", Q_FUNC_INFO, qPrintable(qmakePath));
        return QString();
    }
    const QByteArray ba = proc.readAllStandardOutput().trimmed();
    QDir dir(QString::fromLocal8Bit(ba));
    if (dir.exists() && dir.cdUp())
        return dir.absolutePath();
    return QString();
}

static DebuggerStartParameters localStartParameters(RunConfiguration *runConfiguration)
{
    DebuggerStartParameters sp;
    QTC_ASSERT(runConfiguration, return sp);
    LocalApplicationRunConfiguration *rc =
            qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
    QTC_ASSERT(rc, return sp);

    sp.startMode = StartInternal;
    sp.environment = rc->environment();
    sp.workingDirectory = rc->workingDirectory();
    sp.executable = rc->executable();
    sp.processArgs = rc->commandLineArguments();
    sp.toolChainType = rc->toolChainType();
    sp.useTerminal = rc->runMode() == LocalApplicationRunConfiguration::Console;
    sp.dumperLibrary = rc->dumperLibrary();
    sp.dumperLibraryLocations = rc->dumperLibraryLocations();

    if (debuggerCore()->isActiveDebugLanguage(QmlLanguage)) {
        sp.qmlServerAddress = QLatin1String("127.0.0.1");
        sp.qmlServerPort = runConfiguration->qmlDebugServerPort();

        sp.projectDir = runConfiguration->target()->project()->projectDirectory();
        if (runConfiguration->target()->activeBuildConfiguration())
            sp.projectBuildDir = runConfiguration->target()
                ->activeBuildConfiguration()->buildDirectory();

600 601
        Utils::QtcProcess::addArg(&sp.processArgs, QLatin1String("-qmljsdebugger=port:")
                                  + QString::number(sp.qmlServerPort));
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
    }

    // 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();

    // Find qtInstallPath.
    QString qmakePath = DebuggingHelperLibrary::findSystemQt(rc->environment());
    if (!qmakePath.isEmpty())
        sp.qtInstallPath = findQtInstallPath(qmakePath);
    return sp;
}

RunControl *DebuggerRunControlFactory::create
    (RunConfiguration *runConfiguration, const QString &mode)
{
    QTC_ASSERT(mode == Constants::DEBUGMODE, return 0);
    DebuggerStartParameters sp = localStartParameters(runConfiguration);
    return create(sp, runConfiguration);
}

QWidget *DebuggerRunControlFactory::createConfigurationWidget
    (RunConfiguration *runConfiguration)
{
    // NBS TODO: Add GDB-specific configuration widget
    Q_UNUSED(runConfiguration)
    return 0;
}

DebuggerRunControl *DebuggerRunControlFactory::create
634
    (const DebuggerStartParameters &sp0, RunConfiguration *runConfiguration)
635
{
636 637
    DebuggerStartParameters sp = sp0;
    sp.enabledEngines = m_enabledEngines;
638
    ConfigurationCheck check = checkDebugConfiguration(sp.toolChainType);
639

640
    if (!check) {
641
        //appendMessage(errorMessage, true);
Friedemann Kleint's avatar
Friedemann Kleint committed
642
        Core::ICore::instance()->showWarningWithOptions(DebuggerRunControl::tr("Debugger"),
643
            check.errorMessage, QString(), check.settingsCategory, check.settingsPage);
644 645 646
        return 0;
    }

647
    DebuggerRunControl *runControl =
648
        new DebuggerRunControl(runConfiguration, sp);
649 650 651 652 653 654
    if (runControl->d->m_engine)
        return runControl;
    delete runControl;
    return 0;
}

hjk's avatar
hjk committed
655
} // namespace Debugger