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"
44
#include "lldb/lldbenginehost.h"
45
#include "debuggertooltipmanager.h"
46

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

51
#include <projectexplorer/abi.h>
hjk's avatar
hjk committed
52
#include <projectexplorer/debugginghelper.h>
con's avatar
con committed
53 54
#include <projectexplorer/project.h>
#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
hjk's avatar
hjk committed
76
ConfigurationCheck checkCdbConfiguration(const Abi &abi);
77

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

hjk's avatar
hjk committed
90
extern QString msgNoBinaryForToolChain(const Abi &abi);
91 92 93 94

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

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 171 172 173
    Abi hostAbi = Abi::hostAbi();
    ConfigurationCheck check = checkDebugConfiguration(Abi(hostAbi.architecture(),
                                                           Abi::Windows,
                                                           hostAbi.osFlavor(),
                                                           Abi::Format_PE,
                                                           hostAbi.wordWidth()));
    if (!check) {
174 175
        m_errorMessage = check.errorMessage;
        m_settingsIdHint = check.settingsPage;
176 177
        if (enabledEngineTypes & CdbEngineType)
            return CdbEngineType;
hjk's avatar
hjk committed
178
        m_errorMessage = msgEngineNotAvailable("Cdb Engine");
179 180
        return NoEngineType;
    }
181
#else
182
    if (enabledEngineTypes & GdbEngineType)
183
        return GdbEngineType;
hjk's avatar
hjk committed
184
    m_errorMessage = msgEngineNotAvailable("Gdb Engine");
185
#endif
186

187
    return NoEngineType;
188 189
}

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

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

hjk's avatar
hjk committed
214 215 216
} // namespace Internal


hjk's avatar
hjk committed
217 218 219 220 221 222
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControl
//
////////////////////////////////////////////////////////////////////////

223
static DebuggerEngineType engineForToolChain(const Abi &toolChain)
hjk's avatar
hjk committed
224
{
225 226 227
    switch (toolChain.binaryFormat()) {
    case Abi::Format_ELF:
    case Abi::Format_Mach_O:
228 229 230 231 232
#ifdef WITH_LLDB
            // lldb override
            if (Core::ICore::instance()->settings()->value("LLDB/enabled").toBool())
                return LldbEngineType;
#endif
hjk's avatar
hjk committed
233
            return GdbEngineType;
234 235 236 237 238 239
   case Abi::Format_PE:
        if (toolChain.osFlavor() == Abi::Windows_msys)
            return GdbEngineType;
        return CdbEngineType;
    default:
        break;
hjk's avatar
hjk committed
240 241 242 243
    }
    return NoEngineType;
}

244 245 246 247 248 249 250 251 252 253

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

hjk's avatar
hjk committed
254
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
255
        const DebuggerStartParameters &startParams)
hjk's avatar
hjk committed
256
    : RunControl(runConfiguration, Constants::DEBUGMODE),
257
      d(new DebuggerRunControlPrivate(this, runConfiguration))
258
{
hjk's avatar
hjk committed
259
    connect(this, SIGNAL(finished()), SLOT(handleFinished()));
260

261 262
    // Figure out engine according to toolchain, executable, attach or default.
    DebuggerEngineType engineType = NoEngineType;
263
    DebuggerLanguages activeLangs = debuggerCore()->activeLanguages();
hjk's avatar
hjk committed
264
    DebuggerStartParameters sp = startParams;
265 266
    unsigned enabledEngineTypes = filterEngines(sp.enabledEngines);

267
    if (sp.executable.endsWith(_(".js")))
268 269 270
        engineType = ScriptEngineType;
    else if (sp.executable.endsWith(_(".py")))
        engineType = PdbEngineType;
271
    else {
272
        engineType = engineForToolChain(sp.toolChainAbi);
273 274 275 276 277
        if (engineType == CdbEngineType && !(enabledEngineTypes & CdbEngineType)) {
            d->m_errorMessage = msgEngineNotAvailable("Cdb Engine");
            engineType = NoEngineType;
        }
    }
278

hjk's avatar
hjk committed
279
    // FIXME: Unclean ipc override. Someone please have a better idea.
280
    if (sp.startMode == StartRemoteEngine)
hjk's avatar
hjk committed
281
        // For now thats the only supported IPC engine.
282 283
        engineType = LldbEngineType;

hjk's avatar
hjk committed
284
    // FIXME: 1 of 3 testing hacks.
285
    if (sp.processArgs.startsWith(__("@tcf@ ")))
286 287
        engineType = GdbEngineType;

288 289 290 291
    // Override CDB by gdb if no PDB sections are found in executable
    // (pending proper MinGW/MSys detection).
    if ((engineType == NoEngineType || engineType == CdbEngineType)
         && sp.startMode != AttachToRemote && !sp.executable.isEmpty())
hjk's avatar
hjk committed
292
        engineType = d->engineForExecutable(enabledEngineTypes, sp.executable);
293

294
    if (engineType == NoEngineType)
hjk's avatar
hjk committed
295
        engineType = d->engineForMode(enabledEngineTypes, sp.startMode);
296

297 298
    if ((engineType != QmlEngineType && engineType != NoEngineType)
        && (activeLangs & QmlLanguage)) {
299
        if (activeLangs & CppLanguage) {
300 301 302 303 304 305 306
            sp.cppEngineType = engineType;
            engineType = QmlCppEngineType;
        } else {
            engineType = QmlEngineType;
        }
    }

Friedemann Kleint's avatar
Friedemann Kleint committed
307
    // qDebug() << "USING ENGINE : " << engineType;
308 309 310

    switch (engineType) {
        case GdbEngineType:
311
            d->m_engine = createGdbEngine(sp, 0);
312
            break;
313
        case ScriptEngineType:
hjk's avatar
hjk committed
314
            d->m_engine = createScriptEngine(sp);
315
            break;
316
        case CdbEngineType:
317
            d->m_engine = createCdbEngine(sp, 0, &d->m_errorMessage);
318
            break;
319
        case PdbEngineType:
hjk's avatar
hjk committed
320
            d->m_engine = createPdbEngine(sp);
321
            break;
322
        case TcfEngineType:
hjk's avatar
hjk committed
323
            d->m_engine = createTcfEngine(sp);
324
            break;
325
        case QmlEngineType:
326
            d->m_engine = createQmlEngine(sp, 0);
327
            break;
328
        case QmlCppEngineType:
hjk's avatar
hjk committed
329
            d->m_engine = createQmlCppEngine(sp);
330
            break;
hjk's avatar
hjk committed
331 332
        case LldbEngineType:
            d->m_engine = createLldbEngine(sp);
333 334
        case NoEngineType:
        case AllEngineTypes:
335
            break;
336 337
    }

338 339 340
    if (d->m_engine) {
        DebuggerToolTipManager::instance()->registerEngine(d->m_engine);
    } else {
341 342
        // Could not find anything suitable.
        debuggingFinished();
hjk's avatar
hjk committed
343
        // Create Message box with possibility to go to settings.
344 345
        const QString msg = tr("Cannot debug '%1' (binary format: '%2'): %3")
            .arg(sp.executable, sp.toolChainAbi.toString(), d->m_errorMessage);
346
        Core::ICore::instance()->showWarningWithOptions(tr("Warning"),
347
            msg, QString(), _(Constants::DEBUGGER_SETTINGS_CATEGORY),
hjk's avatar
hjk committed
348
            d->m_settingsIdHint);
349
    }
350 351
}

hjk's avatar
hjk committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
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();
}

368
QString DebuggerRunControl::displayName() const
369
{
370 371
    QTC_ASSERT(d->m_engine, return QString());
    return d->m_engine->startParameters().displayName;
372 373
}

374
void DebuggerRunControl::setCustomEnvironment(Utils::Environment env)
375
{
376
    QTC_ASSERT(d->m_engine, return);
377
    d->m_engine->startParameters().environment = env;
378 379
}

hjk's avatar
hjk committed
380
ConfigurationCheck checkDebugConfiguration(const Abi &abi)
381
{
382
    ConfigurationCheck result;
383

384
    if (!(debuggerCore()->activeLanguages() & CppLanguage))
385
        return result;
386

387 388 389
    if (abi.binaryFormat() == Abi::Format_ELF ||
            abi.binaryFormat() == Abi::Format_Mach_O ||
            (abi.binaryFormat() == Abi::Format_PE && abi.osFlavor() == Abi::Windows_msys)) {
390
        if (debuggerCore()->debuggerForAbi(abi).isEmpty()) {
391
            result.errorMessage = msgNoBinaryForToolChain(abi);
hjk's avatar
hjk committed
392 393
            if (!result.errorMessage.isEmpty())
                result.errorMessage += QLatin1Char('\n');
394
            result.errorMessage += QLatin1Char(' ') + msgEngineNotAvailable("Gdb");
395
            result.settingsPage = _(Constants::DEBUGGER_COMMON_SETTINGS_ID);
hjk's avatar
hjk committed
396
        }
hjk's avatar
hjk committed
397 398
    } else if (abi.binaryFormat() == Abi::Format_PE
                && abi.osFlavor() != Abi::Windows_msys) {
399
        result = checkCdbConfiguration(abi);
400
        if (!result) {
hjk's avatar
hjk committed
401 402
            if (!result.errorMessage.isEmpty())
                result.errorMessage += QLatin1Char('\n');
403
            result.errorMessage += msgEngineNotAvailable("Cdb");
404
            result.settingsPage = _("Cdb");
405 406
        }
    }
hjk's avatar
hjk committed
407

408
    if (!result && !result.settingsPage.isEmpty())
409
        result.settingsCategory = _(Constants::DEBUGGER_SETTINGS_CATEGORY);
410 411

    return result;
412 413
}

414
void DebuggerRunControl::start()
415
{
416
    QTC_ASSERT(d->m_engine, return);
417
    debuggerCore()->runControlStarted(d->m_engine);
418

419 420
    // We might get a synchronous startFailed() notification on Windows,
    // when launching the process fails. Emit a proper finished() sequence.
421
    emit started();
422 423
    d->m_running = true;

424
    d->m_engine->startDebugger(this);
425

426
    if (d->m_running)
427
        appendMessage(tr("Debugging starts"), NormalMessageFormat);
428 429
}

430
void DebuggerRunControl::startFailed()
431
{
432
    appendMessage(tr("Debugging has failed"), NormalMessageFormat);
433
    d->m_running = false;
434
    emit finished();
435
    d->m_engine->handleStartFailed();
436 437
}

438
void DebuggerRunControl::handleFinished()
439
{
440
    appendMessage(tr("Debugging has finished"), NormalMessageFormat);
441 442 443
    if (d->m_engine)
        d->m_engine->handleFinished();
    debuggerCore()->runControlFinished(d->m_engine);
444 445
}

446
void DebuggerRunControl::showMessage(const QString &msg, int channel)
447
{
448 449
    switch (channel) {
        case AppOutput:
450
            appendMessage(msg, StdOutFormatSameLine);
451 452
            break;
        case AppError:
453
            appendMessage(msg, StdErrFormatSameLine);
454 455
            break;
        case AppStuff:
456
            appendMessage(msg, NormalMessageFormat);
457 458
            break;
    }
459 460
}

461
bool DebuggerRunControl::promptToStop(bool *optionalPrompt) const
462
{
463 464
    QTC_ASSERT(isRunning(), return true;)

465 466 467
    if (optionalPrompt && !*optionalPrompt)
        return true;

Jarek Kobus's avatar
Jarek Kobus committed
468
    const QString question = tr("A debugging session is still in progress. "
469 470 471
            "Terminating the session in the current"
            " state can leave the target in an inconsistent state."
            " Would you still like to terminate it?");
472 473
    return showPromptToStopDialog(tr("Close Debugging Session"), question,
                                  QString(), QString(), optionalPrompt);
474 475 476 477
}

RunControl::StopResult DebuggerRunControl::stop()
{
478 479
    QTC_ASSERT(d->m_engine, return StoppedSynchronously);
    d->m_engine->quitDebugger();
480
    return AsynchronousStop;
481 482
}

483
void DebuggerRunControl::debuggingFinished()
484
{
485
    d->m_running = false;
486
    emit finished();
487 488
}

489
bool DebuggerRunControl::isRunning() const
490
{
491
    return d->m_running;
492 493
}

494
DebuggerEngine *DebuggerRunControl::engine()
495
{
496 497
    QTC_ASSERT(d->m_engine, /**/);
    return d->m_engine;
498 499
}

500 501 502 503
RunConfiguration *DebuggerRunControl::runConfiguration() const
{
    return d->m_myRunConfiguration.data();
}
504

505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526

////////////////////////////////////////////////////////////////////////
//
// 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
527
    return DebuggerRunControl::tr("Debug");
528 529 530 531 532 533 534
}

// Find Qt installation by running qmake
static inline QString findQtInstallPath(const QString &qmakePath)
{
    QProcess proc;
    QStringList args;
535 536
    args.append(_("-query"));
    args.append(_("QT_INSTALL_HEADERS"));
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
    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();
573
    sp.toolChainAbi = rc->abi();
574 575 576 577 578
    sp.useTerminal = rc->runMode() == LocalApplicationRunConfiguration::Console;
    sp.dumperLibrary = rc->dumperLibrary();
    sp.dumperLibraryLocations = rc->dumperLibraryLocations();

    if (debuggerCore()->isActiveDebugLanguage(QmlLanguage)) {
579
        sp.qmlServerAddress = _("127.0.0.1");
580 581 582 583 584 585 586
        sp.qmlServerPort = runConfiguration->qmlDebugServerPort();

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

587 588
        // Makes sure that all bindings go through the JavaScript engine, so that
        // breakpoints are actually hit!
589 590
        if (!sp.environment.hasKey(_("QML_DISABLE_OPTIMIZER"))) {
            sp.environment.set(_("QML_DISABLE_OPTIMIZER"), _("1"));
591 592
        }

593
        Utils::QtcProcess::addArg(&sp.processArgs, _("-qmljsdebugger=port:")
594
                                  + QString::number(sp.qmlServerPort));
595 596 597 598 599 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
    }

    // 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
627
    (const DebuggerStartParameters &sp0, RunConfiguration *runConfiguration)
628
{
629 630
    DebuggerStartParameters sp = sp0;
    sp.enabledEngines = m_enabledEngines;
631
    ConfigurationCheck check = checkDebugConfiguration(sp.toolChainAbi);
632

633
    if (!check) {
634
        //appendMessage(errorMessage, true);
Friedemann Kleint's avatar
Friedemann Kleint committed
635
        Core::ICore::instance()->showWarningWithOptions(DebuggerRunControl::tr("Debugger"),
636
            check.errorMessage, QString(), check.settingsCategory, check.settingsPage);
637 638 639
        return 0;
    }

640
    DebuggerRunControl *runControl =
641
        new DebuggerRunControl(runConfiguration, sp);
642 643 644 645 646 647
    if (runControl->d->m_engine)
        return runControl;
    delete runControl;
    return 0;
}

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