debuggerrunner.cpp 21.3 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
#include "debuggertooltipmanager.h"
47

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

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

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

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

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

73
namespace Debugger {
74
namespace Internal {
75

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

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

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

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

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

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

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

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

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

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

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

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

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

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

183
    return NoEngineType;
184 185
}

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

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

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


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

219
static DebuggerEngineType engineForToolChain(ToolChainType toolChainType)
hjk's avatar
hjk committed
220 221
{
    switch (toolChainType) {
222 223 224 225 226 227 228 229 230
        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:
231 232
        case ToolChain_GCC_MAEMO5:
        case ToolChain_GCC_HARMATTAN:
Christian Kandeler's avatar
Christian Kandeler committed
233
        case ToolChain_GCC_MEEGO:
234 235 236 237 238
#ifdef WITH_LLDB
            // lldb override
            if (Core::ICore::instance()->settings()->value("LLDB/enabled").toBool())
                return LldbEngineType;
#endif
hjk's avatar
hjk committed
239 240
            return GdbEngineType;

241

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

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

255 256 257 258 259 260 261 262 263 264

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

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

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

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

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

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

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

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

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

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

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

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

hjk's avatar
hjk committed
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
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();
}

379
QString DebuggerRunControl::displayName() const
380
{
381 382
    QTC_ASSERT(d->m_engine, return QString());
    return d->m_engine->startParameters().displayName;
383 384
}

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

391
DEBUGGER_EXPORT ConfigurationCheck checkDebugConfiguration(ToolChainType toolChain)
392
{
393
    ConfigurationCheck result;
394

395
    if (!(debuggerCore()->activeLanguages() & CppLanguage))
396
        return result;
397

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

424 425 426 427
    if (!result && !result.settingsPage.isEmpty())
        result.settingsCategory = QLatin1String(Constants::DEBUGGER_SETTINGS_CATEGORY);

    return result;
428 429
}

430
void DebuggerRunControl::start()
431
{
432
    QTC_ASSERT(d->m_engine, return);
433
    debuggerCore()->runControlStarted(d->m_engine);
434

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

440
    d->m_engine->startDebugger(this);
441

442
    if (d->m_running)
443
        appendMessage(tr("Debugging starts"), NormalMessageFormat);
444 445
}

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

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

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

477
bool DebuggerRunControl::promptToStop(bool *optionalPrompt) const
478
{
479 480
    QTC_ASSERT(isRunning(), return true;)

481 482 483
    if (optionalPrompt && !*optionalPrompt)
        return true;

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

RunControl::StopResult DebuggerRunControl::stop()
{
494 495
    QTC_ASSERT(d->m_engine, return StoppedSynchronously);
    d->m_engine->quitDebugger();
496
    return AsynchronousStop;
497 498
}

499
void DebuggerRunControl::debuggingFinished()
500
{
501
    d->m_running = false;
502
    emit finished();
503 504
}

505
bool DebuggerRunControl::isRunning() const
506
{
507
    return d->m_running;
508 509
}

510
DebuggerEngine *DebuggerRunControl::engine()
511
{
512 513
    QTC_ASSERT(d->m_engine, /**/);
    return d->m_engine;
514 515
}

516 517 518 519
RunConfiguration *DebuggerRunControl::runConfiguration() const
{
    return d->m_myRunConfiguration.data();
}
520

521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542

////////////////////////////////////////////////////////////////////////
//
// 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
543
    return DebuggerRunControl::tr("Debug");
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 600 601 602
}

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

603 604 605 606 607 608
        // Makes sure that all bindings go through the JavaScript engine, so that
        // breakpoints are actually hit!
        if (!sp.environment.hasKey(QLatin1String("QML_DISABLE_OPTIMIZER"))) {
            sp.environment.set(QLatin1String("QML_DISABLE_OPTIMIZER"), QLatin1String("1"));
        }

609 610
        Utils::QtcProcess::addArg(&sp.processArgs, QLatin1String("-qmljsdebugger=port:")
                                  + QString::number(sp.qmlServerPort));
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
    }

    // 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
643
    (const DebuggerStartParameters &sp0, RunConfiguration *runConfiguration)
644
{
645 646
    DebuggerStartParameters sp = sp0;
    sp.enabledEngines = m_enabledEngines;
647
    ConfigurationCheck check = checkDebugConfiguration(sp.toolChainType);
648

649
    if (!check) {
650
        //appendMessage(errorMessage, true);
Friedemann Kleint's avatar
Friedemann Kleint committed
651
        Core::ICore::instance()->showWarningWithOptions(DebuggerRunControl::tr("Debugger"),
652
            check.errorMessage, QString(), check.settingsCategory, check.settingsPage);
653 654 655
        return 0;
    }

656
    DebuggerRunControl *runControl =
657
        new DebuggerRunControl(runConfiguration, sp);
658 659 660 661 662 663
    if (runControl->d->m_engine)
        return runControl;
    delete runControl;
    return 0;
}

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