debuggerrunner.cpp 20.8 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 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 35
#include "debuggerrunner.h"

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

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

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

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

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

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

71
namespace Debugger {
hjk's avatar
hjk committed
72 73 74

namespace Cdb {
bool isCdbEngineEnabled(); // Check the configuration page
75 76
ConfigurationCheck checkCdbConfiguration(ToolChainType toolChain);
DebuggerEngine *createCdbEngine(const DebuggerStartParameters &, QString *error);
hjk's avatar
hjk committed
77 78
}

79 80 81 82 83 84 85
namespace Internal {

DebuggerEngine *createGdbEngine(const DebuggerStartParameters &);
DebuggerEngine *createScriptEngine(const DebuggerStartParameters &);
DebuggerEngine *createPdbEngine(const DebuggerStartParameters &);
DebuggerEngine *createTcfEngine(const DebuggerStartParameters &);
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &);
86
DebuggerEngine *createQmlCppEngine(const DebuggerStartParameters &);
hjk's avatar
hjk committed
87
DebuggerEngine *createLldbEngine(const DebuggerStartParameters &);
88

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

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

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

hjk's avatar
hjk committed
103 104 105 106 107
class DebuggerRunControlPrivate
{
public:
    DebuggerRunControlPrivate(DebuggerRunControl *parent,
        RunConfiguration *runConfiguration, unsigned enabledEngines);
108
    unsigned enabledEngines() const;
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
    DebuggerEngine *m_engine;
    const QWeakPointer<RunConfiguration> m_myRunConfiguration;
    bool m_running;
120
    const unsigned m_cmdLineEnabledEngines;
121 122 123 124
    QString m_errorMessage;
    QString m_settingsIdHint;
};

hjk's avatar
hjk committed
125
unsigned DebuggerRunControlPrivate::enabledEngines() const
126 127 128
{
    unsigned rc = m_cmdLineEnabledEngines;
#ifdef CDB_ENABLED
hjk's avatar
hjk committed
129
    if (!isCdbEngineEnabled() && !Cdb::isCdbEngineEnabled())
130 131 132 133 134
        rc &= ~CdbEngineType;
#endif
    return rc;
}

hjk's avatar
hjk committed
135 136 137 138
DebuggerRunControlPrivate::DebuggerRunControlPrivate(DebuggerRunControl *parent,
        RunConfiguration *runConfiguration, unsigned enabledEngines)
    : q(parent)
    , m_engine(0)
139
    , m_myRunConfiguration(runConfiguration)
140
    , m_running(false)
141
    , m_cmdLineEnabledEngines(enabledEngines)
142 143
{
}
144

145 146
// Figure out the debugger type of an executable. Analyze executable
// unless the toolchain provides a hint.
hjk's avatar
hjk committed
147 148
DebuggerEngineType DebuggerRunControlPrivate::engineForExecutable
    (unsigned enabledEngineTypes, const QString &executable)
149
{
150
    if (executable.endsWith(_(".js"))) {
151
        if (enabledEngineTypes & ScriptEngineType)
152
            return ScriptEngineType;
hjk's avatar
hjk committed
153
        m_errorMessage = msgEngineNotAvailable("Script Engine");
154
    }
con's avatar
con committed
155

156
    if (executable.endsWith(_(".py"))) {
157
        if (enabledEngineTypes & PdbEngineType)
158
            return PdbEngineType;
hjk's avatar
hjk committed
159
        m_errorMessage = msgEngineNotAvailable("Pdb Engine");
160
    }
con's avatar
con committed
161

162 163 164
#ifdef Q_OS_WIN
    // A remote executable?
    if (!executable.endsWith(_(".exe")))
Friedemann Kleint's avatar
Friedemann Kleint committed
165
        return GdbEngineType;
166 167 168

    // If a file has PDB files, it has been compiled by VS.
    QStringList pdbFiles;
hjk's avatar
hjk committed
169
    if (!getPDBFiles(executable, &pdbFiles, &m_errorMessage)) {
170
        qWarning("Cannot determine type of executable %s: %s",
hjk's avatar
hjk committed
171
                 qPrintable(executable), qPrintable(m_errorMessage));
Friedemann Kleint's avatar
Friedemann Kleint committed
172
        return NoEngineType;
173 174 175
    }
    if (pdbFiles.empty())
        return GdbEngineType;
176

177
    // We need the CDB debugger in order to be able to debug VS
hjk's avatar
hjk committed
178
    // executables.
179 180 181 182
   ConfigurationCheck check = checkDebugConfiguration(ToolChain_MSVC);
   if (!check) {
        m_errorMessage = check.errorMessage;
        m_settingsIdHint = check.settingsPage;
183 184
        if (enabledEngineTypes & CdbEngineType)
            return CdbEngineType;
hjk's avatar
hjk committed
185
        m_errorMessage = msgEngineNotAvailable("Cdb Engine");
186 187
        return NoEngineType;
    }
188
#else
189
    if (enabledEngineTypes & GdbEngineType)
190
        return GdbEngineType;
hjk's avatar
hjk committed
191
    m_errorMessage = msgEngineNotAvailable("Gdb Engine");
192
#endif
193

194
    return NoEngineType;
195 196
}

197
// Debugger type for mode.
hjk's avatar
hjk committed
198 199
DebuggerEngineType DebuggerRunControlPrivate::engineForMode
    (unsigned enabledEngineTypes, DebuggerStartMode startMode)
200
{
201 202
    if (startMode == AttachTcf)
        return TcfEngineType;
203

204 205
#ifdef Q_OS_WIN
    // Preferably Windows debugger for attaching locally.
206
    if (startMode != AttachToRemote && (enabledEngineTypes & CdbEngineType))
207
        return CdbEngineType;
208
    if (startMode == AttachCrashedExternal) {
209
        m_errorMessage = DebuggerRunControl::tr("There is no debugging engine available for post-mortem debugging.");
210 211
        return NoEngineType;
    }
Friedemann Kleint's avatar
Friedemann Kleint committed
212
    return GdbEngineType;
213 214
#else
    Q_UNUSED(startMode)
215
    Q_UNUSED(enabledEngineTypes)
hjk's avatar
hjk committed
216
    //  >m_errorMessage = msgEngineNotAvailable("Gdb Engine");
217 218
    return GdbEngineType;
#endif
219 220
}

hjk's avatar
hjk committed
221 222 223
} // namespace Internal


hjk's avatar
hjk committed
224 225 226 227 228 229
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControl
//
////////////////////////////////////////////////////////////////////////

230
static DebuggerEngineType engineForToolChain(ToolChainType toolChainType)
hjk's avatar
hjk committed
231 232
{
    switch (toolChainType) {
233 234 235 236 237 238 239 240 241 242
        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:
        case ToolChain_GCC_MAEMO:
243 244 245 246 247
#ifdef WITH_LLDB
            // lldb override
            if (Core::ICore::instance()->settings()->value("LLDB/enabled").toBool())
                return LldbEngineType;
#endif
hjk's avatar
hjk committed
248 249
            return GdbEngineType;

250

251 252
        case ToolChain_MSVC:
        case ToolChain_WINCE:
hjk's avatar
hjk committed
253 254
            return CdbEngineType;

255 256 257
        case ToolChain_OTHER:
        case ToolChain_UNKNOWN:
        case ToolChain_INVALID:
hjk's avatar
hjk committed
258 259 260 261 262 263
        default:
            break;
    }
    return NoEngineType;
}

hjk's avatar
hjk committed
264 265 266 267
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
        unsigned enabledEngines, const DebuggerStartParameters &startParams)
    : RunControl(runConfiguration, Constants::DEBUGMODE),
      d(new DebuggerRunControlPrivate(this, runConfiguration, enabledEngines))
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
    const unsigned enabledEngineTypes = d->enabledEngines();
276
    if (sp.executable.endsWith(_(".js")))
277 278 279
        engineType = ScriptEngineType;
    else if (sp.executable.endsWith(_(".py")))
        engineType = PdbEngineType;
280
    else {
281
        engineType = engineForToolChain(sp.toolChainType);
282 283 284 285 286
        if (engineType == CdbEngineType && !(enabledEngineTypes & CdbEngineType)) {
            d->m_errorMessage = msgEngineNotAvailable("Cdb Engine");
            engineType = NoEngineType;
        }
    }
287

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

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

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

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

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

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

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

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

hjk's avatar
hjk committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
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();
}

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

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

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

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

394
    switch(toolChain) {
395 396 397 398 399 400 401 402
    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
403
        if (debuggerCore()->gdbBinaryForToolChain(toolChain).isEmpty()) {
404 405 406
            result.errorMessage = msgNoBinaryForToolChain(toolChain);
            result.errorMessage += msgEngineNotAvailable("Gdb");
            result.settingsPage = GdbOptionsPage::settingsId();
hjk's avatar
hjk committed
407
        }
408
        break;
409 410 411 412 413
    case ToolChain_MSVC:
        result = Cdb::checkCdbConfiguration(toolChain);
        if (!result) {
            result.errorMessage += msgEngineNotAvailable("Cdb");
            result.settingsPage = QLatin1String("Cdb");
414 415 416
        }
        break;
    }
hjk's avatar
hjk committed
417

418 419 420 421
    if (!result && !result.settingsPage.isEmpty())
        result.settingsCategory = QLatin1String(Constants::DEBUGGER_SETTINGS_CATEGORY);

    return result;
422 423
}

424
void DebuggerRunControl::start()
425
{
426
    QTC_ASSERT(d->m_engine, return);
427
    debuggerCore()->runControlStarted(d->m_engine);
428

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

434
    d->m_engine->startDebugger(this);
435

436
    if (d->m_running)
437
        appendMessage(tr("Debugging starts"), NormalMessageFormat);
438 439
}

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

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

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

471
bool DebuggerRunControl::aboutToStop() const
472
{
473 474
    QTC_ASSERT(isRunning(), return true;)

Jarek Kobus's avatar
Jarek Kobus committed
475
    const QString question = tr("A debugging session is still in progress. "
476 477 478 479 480
            "Terminating the session in the current"
            " state can leave the target in an inconsistent state."
            " Would you still like to terminate it?");

    const QMessageBox::StandardButton answer =
481
            QMessageBox::question(debuggerCore()->mainWindow(),
482 483 484 485 486 487 488
                                  tr("Close Debugging Session"), question,
                                  QMessageBox::Yes|QMessageBox::No);
    return answer == QMessageBox::Yes;
}

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

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

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

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

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

516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 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

////////////////////////////////////////////////////////////////////////
//
// 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
{
    return tr("Debug");
}

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

598 599
        Utils::QtcProcess::addArg(&sp.processArgs, QLatin1String("-qmljsdebugger=port:")
                                  + QString::number(sp.qmlServerPort));
600 601 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
    (const DebuggerStartParameters &sp, RunConfiguration *runConfiguration)
{
634
    ConfigurationCheck check = checkDebugConfiguration(sp.toolChainType);
635

636
    if (!check) {
637
        //appendMessage(errorMessage, true);
638
        Core::ICore::instance()->showWarningWithOptions(tr("Debugger"),
639
            check.errorMessage, QString(), check.settingsCategory, check.settingsPage);
640 641 642
        return 0;
    }

643 644 645 646 647 648 649 650
    DebuggerRunControl *runControl =
        new DebuggerRunControl(runConfiguration, m_enabledEngines, sp);
    if (runControl->d->m_engine)
        return runControl;
    delete runControl;
    return 0;
}

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