pdbengine.cpp 18.9 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
hjk's avatar
hjk committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
hjk's avatar
hjk committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
hjk's avatar
hjk committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
hjk's avatar
hjk committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30 31 32

#include "pdbengine.h"

33 34 35 36 37 38 39 40
#include <debugger/debuggeractions.h>
#include <debugger/debuggercore.h>
#include <debugger/debuggerdialogs.h>
#include <debugger/debuggerplugin.h>
#include <debugger/debuggerprotocol.h>
#include <debugger/debuggerstartparameters.h>
#include <debugger/debuggerstringutils.h>
#include <debugger/debuggertooltipmanager.h>
Christian Kandeler's avatar
Christian Kandeler committed
41
#include <debugger/threaddata.h>
42

43 44
#include <debugger/breakhandler.h>
#include <debugger/moduleshandler.h>
45
#include <debugger/procinterrupt.h>
46 47 48 49 50
#include <debugger/registerhandler.h>
#include <debugger/stackhandler.h>
#include <debugger/sourceutils.h>
#include <debugger/watchhandler.h>
#include <debugger/watchutils.h>
51

hjk's avatar
hjk committed
52
#include <utils/qtcassert.h>
hjk's avatar
hjk committed
53
#include <utils/qtcprocess.h>
hjk's avatar
hjk committed
54

55
#include <coreplugin/idocument.h>
hjk's avatar
hjk committed
56
#include <coreplugin/icore.h>
57
#include <coreplugin/messagebox.h>
hjk's avatar
hjk committed
58

59 60 61 62 63 64
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QTimer>
#include <QVariant>
hjk's avatar
hjk committed
65

hjk's avatar
hjk committed
66
using namespace Core;
hjk's avatar
hjk committed
67 68 69 70

namespace Debugger {
namespace Internal {

71
PdbEngine::PdbEngine(const DebuggerRunParameters &startParameters)
72
    : DebuggerEngine(startParameters)
Friedemann Kleint's avatar
Friedemann Kleint committed
73 74 75
{
    setObjectName(QLatin1String("PdbEngine"));
}
hjk's avatar
hjk committed
76

77
void PdbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages languages)
hjk's avatar
hjk committed
78
{
79 80
    if (!(languages & CppLanguage))
        return;
81
    QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
hjk's avatar
hjk committed
82
    if (state() == DebuggerNotReady) {
83
        showMessage(_("PDB PROCESS NOT RUNNING, PLAIN CMD IGNORED: ") + command);
hjk's avatar
hjk committed
84 85
        return;
    }
86
    QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
hjk's avatar
hjk committed
87
    postDirectCommand(command.toLatin1());
88 89 90 91
}

void PdbEngine::postDirectCommand(const QByteArray &command)
{
92
    QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
93
    showMessage(_(command), LogInput);
94
    m_proc.write(command + '\n');
hjk's avatar
hjk committed
95 96
}

97 98
void PdbEngine::runCommand(const DebuggerCommand &cmd)
{
99
    QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
100
    QByteArray command = "qdebug('" + cmd.function + "',{" + cmd.args + "})";
101
    showMessage(_(command), LogInput);
102
    m_proc.write(command + '\n');
103 104
}

hjk's avatar
hjk committed
105
void PdbEngine::shutdownInferior()
hjk's avatar
hjk committed
106
{
hjk's avatar
hjk committed
107 108
    QTC_ASSERT(state() == InferiorShutdownRequested, qDebug() << state());
    notifyInferiorShutdownOk();
hjk's avatar
hjk committed
109 110
}

hjk's avatar
hjk committed
111
void PdbEngine::shutdownEngine()
hjk's avatar
hjk committed
112
{
hjk's avatar
hjk committed
113
    QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state());
114
    m_proc.kill();
hjk's avatar
hjk committed
115 116
}

hjk's avatar
hjk committed
117
void PdbEngine::setupEngine()
hjk's avatar
hjk committed
118
{
hjk's avatar
hjk committed
119
    QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
hjk's avatar
hjk committed
120

hjk's avatar
hjk committed
121 122
    m_interpreter = runParameters().interpreter;
    QString bridge = ICore::resourcePath() + QLatin1String("/debugger/pdbbridge.py");
hjk's avatar
hjk committed
123

124
    connect(&m_proc, static_cast<void(QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
125
        this, &PdbEngine::handlePdbError);
126
    connect(&m_proc, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished),
127
        this, &PdbEngine::handlePdbFinished);
128
    connect(&m_proc, &QProcess::readyReadStandardOutput,
129
        this, &PdbEngine::readPdbStandardOutput);
130
    connect(&m_proc, &QProcess::readyReadStandardError,
131 132
        this, &PdbEngine::readPdbStandardError);

hjk's avatar
hjk committed
133 134 135 136 137 138 139 140 141 142 143 144
    QFile scriptFile(runParameters().mainScript);
    if (!scriptFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
        AsynchronousMessageBox::critical(tr("Python Error"),
            _("Cannot open script file %1:\n%2").
               arg(scriptFile.fileName(), scriptFile.errorString()));
        notifyEngineSetupFailed();
    }

    QStringList args = { bridge, scriptFile.fileName() };
    args.append(Utils::QtcProcess::splitArgs(runParameters().processArgs));
    showMessage(_("STARTING ") + m_interpreter + QLatin1Char(' ') + args.join(QLatin1Char(' ')));
    m_proc.start(m_interpreter, args);
hjk's avatar
hjk committed
145

146
    if (!m_proc.waitForStarted()) {
147
        const QString msg = tr("Unable to start pdb \"%1\": %2")
hjk's avatar
hjk committed
148
            .arg(m_interpreter, m_proc.errorString());
149
        notifyEngineSetupFailed();
150
        showMessage(_("ADAPTER START FAILED"));
hjk's avatar
hjk committed
151 152
        if (!msg.isEmpty())
            ICore::showWarningWithOptions(tr("Adapter start failed"), msg);
153
        notifyEngineSetupFailed();
hjk's avatar
hjk committed
154 155
        return;
    }
156
    notifyEngineSetupOk();
hjk's avatar
hjk committed
157 158 159 160
}

void PdbEngine::setupInferior()
{
hjk's avatar
hjk committed
161
    QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
hjk's avatar
hjk committed
162

163
    notifyInferiorSetupOk();
hjk's avatar
hjk committed
164 165
}

hjk's avatar
hjk committed
166
void PdbEngine::runEngine()
hjk's avatar
hjk committed
167
{
168
    QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
hjk's avatar
hjk committed
169
    showStatusMessage(tr("Running requested..."), 5000);
170 171
    attemptBreakpointSynchronization();
    notifyEngineRunAndInferiorStopOk();
hjk's avatar
hjk committed
172 173 174 175
    if (runParameters().breakOnMain)
        updateAll();
    else
        continueInferior();
hjk's avatar
hjk committed
176 177 178 179
}

void PdbEngine::interruptInferior()
{
180 181
    QString error;
    interruptProcess(m_proc.processId(), GdbEngineType, &error);
182
    notifyInferiorStopOk();
hjk's avatar
hjk committed
183 184 185 186
}

void PdbEngine::executeStep()
{
187
    resetLocation();
188 189
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
190
    postDirectCommand("step");
hjk's avatar
hjk committed
191
    updateAll();
hjk's avatar
hjk committed
192 193 194 195
}

void PdbEngine::executeStepI()
{
196
    resetLocation();
197 198
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
199
    postDirectCommand("step");
hjk's avatar
hjk committed
200
    updateAll();
hjk's avatar
hjk committed
201 202 203 204
}

void PdbEngine::executeStepOut()
{
205
    resetLocation();
206 207
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
208
    postDirectCommand("return");
hjk's avatar
hjk committed
209
    updateAll();
hjk's avatar
hjk committed
210 211 212 213
}

void PdbEngine::executeNext()
{
214
    resetLocation();
215 216
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
217
    postDirectCommand("next");
hjk's avatar
hjk committed
218
    updateAll();
hjk's avatar
hjk committed
219 220 221 222
}

void PdbEngine::executeNextI()
{
223
    resetLocation();
224 225
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
226
    postDirectCommand("next");
hjk's avatar
hjk committed
227
    updateAll();
hjk's avatar
hjk committed
228 229 230 231
}

void PdbEngine::continueInferior()
{
232
    resetLocation();
233 234
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
235
    // Callback will be triggered e.g. when breakpoint is hit.
hjk's avatar
hjk committed
236
    postDirectCommand("continue");
hjk's avatar
hjk committed
237
    updateAll();
hjk's avatar
hjk committed
238 239
}

240
void PdbEngine::executeRunToLine(const ContextData &data)
hjk's avatar
hjk committed
241
{
242
    Q_UNUSED(data)
hjk's avatar
hjk committed
243
    QTC_CHECK("FIXME:  PdbEngine::runToLineExec()" && false);
hjk's avatar
hjk committed
244 245 246 247 248
}

void PdbEngine::executeRunToFunction(const QString &functionName)
{
    Q_UNUSED(functionName)
hjk's avatar
hjk committed
249
    QTC_CHECK("FIXME:  PdbEngine::runToFunctionExec()" && false);
hjk's avatar
hjk committed
250 251
}

252
void PdbEngine::executeJumpToLine(const ContextData &data)
hjk's avatar
hjk committed
253
{
254
    Q_UNUSED(data)
hjk's avatar
hjk committed
255
    QTC_CHECK("FIXME:  PdbEngine::jumpToLineExec()" && false);
hjk's avatar
hjk committed
256 257 258 259
}

void PdbEngine::activateFrame(int frameIndex)
{
hjk's avatar
hjk committed
260
    if (state() != InferiorStopOk && state() != InferiorUnrunnable)
hjk's avatar
hjk committed
261 262
        return;

263 264
    StackHandler *handler = stackHandler();
    QTC_ASSERT(frameIndex < handler->stackSize(), return);
hjk's avatar
hjk committed
265
    handler->setCurrentIndex(frameIndex);
266
    gotoLocation(handler->currentFrame());
hjk's avatar
hjk committed
267
    updateLocals();
hjk's avatar
hjk committed
268 269
}

hjk's avatar
hjk committed
270
void PdbEngine::selectThread(ThreadId threadId)
hjk's avatar
hjk committed
271
{
hjk's avatar
hjk committed
272
    Q_UNUSED(threadId)
hjk's avatar
hjk committed
273 274
}

275
bool PdbEngine::acceptsBreakpoint(Breakpoint bp) const
hjk's avatar
hjk committed
276
{
277
    const QString fileName = bp.fileName();
hjk's avatar
hjk committed
278 279 280
    return fileName.endsWith(QLatin1String(".py"));
}

281
void PdbEngine::insertBreakpoint(Breakpoint bp)
hjk's avatar
hjk committed
282
{
283 284
    QTC_CHECK(bp.state() == BreakpointInsertRequested);
    bp.notifyBreakpointInsertProceeding();
hjk's avatar
hjk committed
285 286

    QByteArray loc;
287 288
    if (bp.type() == BreakpointByFunction)
        loc = bp.functionName().toLatin1();
hjk's avatar
hjk committed
289
    else
290 291
        loc = bp.fileName().toLocal8Bit() + ':'
         + QByteArray::number(bp.lineNumber());
hjk's avatar
hjk committed
292

hjk's avatar
hjk committed
293
    postDirectCommand("break " + loc);
hjk's avatar
hjk committed
294 295
}

296
void PdbEngine::removeBreakpoint(Breakpoint bp)
hjk's avatar
hjk committed
297
{
298 299 300 301
    QTC_CHECK(bp.state() == BreakpointRemoveRequested);
    bp.notifyBreakpointRemoveProceeding();
    BreakpointResponse br = bp.response();
    showMessage(_("DELETING BP %1 IN %2").arg(br.id.toString()).arg(bp.fileName()));
hjk's avatar
hjk committed
302
    postDirectCommand("clear " + br.id.toByteArray());
hjk's avatar
hjk committed
303
    // Pretend it succeeds without waiting for response.
304
    bp.notifyBreakpointRemoveOk();
hjk's avatar
hjk committed
305 306
}

hjk's avatar
hjk committed
307 308 309 310 311 312 313 314 315 316 317
void PdbEngine::loadSymbols(const QString &moduleName)
{
    Q_UNUSED(moduleName)
}

void PdbEngine::loadAllSymbols()
{
}

void PdbEngine::reloadModules()
{
hjk's avatar
hjk committed
318
    runCommand("listModules");
hjk's avatar
hjk committed
319 320
}

hjk's avatar
hjk committed
321
void PdbEngine::refreshModules(const GdbMi &modules)
hjk's avatar
hjk committed
322
{
323 324
    ModulesHandler *handler = modulesHandler();
    handler->beginUpdateAll();
hjk's avatar
hjk committed
325
    foreach (const GdbMi &item, modules.children()) {
hjk's avatar
hjk committed
326
        Module module;
327 328
        module.moduleName = _(item["name"].data());
        QString path = _(item["value"].data());
hjk's avatar
hjk committed
329 330 331 332 333 334 335 336 337 338
        int pos = path.indexOf(_("' from '"));
        if (pos != -1) {
            path = path.mid(pos + 8);
            if (path.size() >= 2)
                path.chop(2);
        } else if (path.startsWith(_("<module '"))
                && path.endsWith(_("' (built-in)>"))) {
            path = _("(builtin)");
        }
        module.modulePath = path;
339
        handler->updateModule(module);
hjk's avatar
hjk committed
340
    }
341
    handler->endUpdateAll();
hjk's avatar
hjk committed
342 343
}

hjk's avatar
hjk committed
344
void PdbEngine::requestModuleSymbols(const QString &moduleName)
hjk's avatar
hjk committed
345
{
hjk's avatar
hjk committed
346 347 348
    DebuggerCommand cmd("listSymbols");
    cmd.arg("module", moduleName);
    runCommand(cmd);
hjk's avatar
hjk committed
349 350
}

351 352 353 354 355 356 357 358 359 360 361 362 363
void PdbEngine::refreshLocation(const GdbMi &reportedLocation)
{
    StackFrame frame;
    frame.file = reportedLocation["file"].toUtf8();
    frame.line = reportedLocation["line"].toInt();
    if (state() == InferiorRunOk) {
        showMessage(QString::fromLatin1("STOPPED AT: %1:%2").arg(frame.file).arg(frame.line));
        gotoLocation(frame);
        notifyInferiorSpontaneousStop();
        updateAll();
    }
}

hjk's avatar
hjk committed
364
void PdbEngine::refreshSymbols(const GdbMi &symbols)
hjk's avatar
hjk committed
365
{
hjk's avatar
hjk committed
366 367 368
    QString moduleName = symbols["module"].toUtf8();
    Symbols syms;
    foreach (const GdbMi &item, symbols["symbols"].children()) {
hjk's avatar
hjk committed
369
        Symbol symbol;
hjk's avatar
hjk committed
370 371
        symbol.name = item["name"].toUtf8();
        syms.append(symbol);
hjk's avatar
hjk committed
372
    }
hjk's avatar
hjk committed
373
    Internal::showModuleSymbols(moduleName, syms);
hjk's avatar
hjk committed
374
}
hjk's avatar
hjk committed
375

376
bool PdbEngine::canHandleToolTip(const DebuggerToolTipContext &) const
hjk's avatar
hjk committed
377
{
378
    return state() == InferiorStopOk;
hjk's avatar
hjk committed
379 380
}

381
void PdbEngine::assignValueInDebugger(WatchItem *, const QString &expression, const QVariant &value)
382 383 384 385 386 387 388
{
    //DebuggerCommand cmd("assignValue");
    //cmd.arg("expression", expression);
    //cmd.arg("value", value.toString());
    //runCommand(cmd);
    QByteArray exp = expression.toUtf8();
    postDirectCommand("global " + exp + ';' + exp + "=" + value.toString().toUtf8());
hjk's avatar
hjk committed
389 390 391
    updateLocals();
}

hjk's avatar
hjk committed
392
void PdbEngine::updateItem(const QByteArray &iname)
hjk's avatar
hjk committed
393
{
394
    Q_UNUSED(iname);
hjk's avatar
hjk committed
395 396 397 398 399
    updateAll();
}

void PdbEngine::handlePdbError(QProcess::ProcessError error)
{
400
    showMessage(_("HANDLE PDB ERROR"));
hjk's avatar
hjk committed
401 402 403 404 405 406 407 408
    switch (error) {
    case QProcess::Crashed:
        break; // will get a processExited() as well
    // impossible case QProcess::FailedToStart:
    case QProcess::ReadError:
    case QProcess::WriteError:
    case QProcess::Timedout:
    default:
409
        //setState(EngineShutdownRequested, true);
410
        m_proc.kill();
hjk's avatar
hjk committed
411
        AsynchronousMessageBox::critical(tr("Pdb I/O Error"), errorMessage(error));
hjk's avatar
hjk committed
412 413 414 415 416 417 418 419 420
        break;
    }
}

QString PdbEngine::errorMessage(QProcess::ProcessError error) const
{
    switch (error) {
        case QProcess::FailedToStart:
            return tr("The Pdb process failed to start. Either the "
421
                "invoked program \"%1\" is missing, or you may have insufficient "
hjk's avatar
hjk committed
422
                "permissions to invoke the program.")
hjk's avatar
hjk committed
423
                .arg(m_interpreter);
hjk's avatar
hjk committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
        case QProcess::Crashed:
            return tr("The Pdb process crashed some time after starting "
                "successfully.");
        case QProcess::Timedout:
            return tr("The last waitFor...() function timed out. "
                "The state of QProcess is unchanged, and you can try calling "
                "waitFor...() again.");
        case QProcess::WriteError:
            return tr("An error occurred when attempting to write "
                "to the Pdb process. For example, the process may not be running, "
                "or it may have closed its input channel.");
        case QProcess::ReadError:
            return tr("An error occurred when attempting to read from "
                "the Pdb process. For example, the process may not be running.");
        default:
439
            return tr("An unknown error in the Pdb process occurred.") + QLatin1Char(' ');
hjk's avatar
hjk committed
440 441 442 443 444
    }
}

void PdbEngine::handlePdbFinished(int code, QProcess::ExitStatus type)
{
445
    showMessage(_("PDB PROCESS FINISHED, status %1, code %2").arg(type).arg(code));
446
    notifyEngineSpontaneousShutdown();
hjk's avatar
hjk committed
447 448 449 450
}

void PdbEngine::readPdbStandardError()
{
451
    QByteArray err = m_proc.readAllStandardError();
452
    //qWarning() << "Unexpected pdb stderr:" << err;
hjk's avatar
hjk committed
453
    showMessage(_("Unexpected pdb stderr: " + err));
454
    //handleOutput(err);
hjk's avatar
hjk committed
455 456 457 458
}

void PdbEngine::readPdbStandardOutput()
{
459
    QByteArray out = m_proc.readAllStandardOutput();
460 461 462 463 464 465 466
    handleOutput(out);
}

void PdbEngine::handleOutput(const QByteArray &data)
{
    m_inbuffer.append(data);
    while (true) {
467
        int pos = m_inbuffer.indexOf('\n');
468 469 470
        if (pos == -1)
            break;
        QByteArray response = m_inbuffer.left(pos).trimmed();
471
        m_inbuffer = m_inbuffer.mid(pos + 1);
hjk's avatar
hjk committed
472
        handleOutput2(response);
473 474 475 476 477
    }
}

void PdbEngine::handleOutput2(const QByteArray &data)
{
478 479 480
    QByteArray lineContext;
    foreach (QByteArray line, data.split('\n')) {

hjk's avatar
hjk committed
481 482
        GdbMi item;
        item.fromString(line);
hjk's avatar
hjk committed
483

484 485 486
        showMessage(_("LINE: " + line));

        if (line.startsWith("stack={")) {
hjk's avatar
hjk committed
487
            refreshStack(item);
hjk's avatar
hjk committed
488
        } else if (line.startsWith("data={")) {
hjk's avatar
hjk committed
489
            refreshLocals(item);
hjk's avatar
hjk committed
490
        } else if (line.startsWith("modules=[")) {
hjk's avatar
hjk committed
491
            refreshModules(item);
hjk's avatar
hjk committed
492
        } else if (line.startsWith("symbols={")) {
hjk's avatar
hjk committed
493
            refreshSymbols(item);
494 495
        } else if (line.startsWith("location={")) {
            refreshLocation(item);
hjk's avatar
hjk committed
496
        } else if (line.startsWith("Breakpoint")) {
hjk's avatar
hjk committed
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
            int pos1 = line.indexOf(" at ");
            QTC_ASSERT(pos1 != -1, continue);
            QByteArray bpnr = line.mid(11, pos1 - 11);
            int pos2 = line.lastIndexOf(':');
            QTC_ASSERT(pos2 != -1, continue);
            QByteArray fileName = line.mid(pos1 + 4, pos2 - pos1 - 4);
            QByteArray lineNumber = line.mid(pos2 + 1);
            BreakpointResponse br;
            br.id = BreakpointResponseId(bpnr);
            br.fileName = _(fileName);
            br.lineNumber = lineNumber.toInt();
            Breakpoint bp = breakHandler()->findBreakpointByFileAndLine(br.fileName, br.lineNumber, false);
            if (bp.isValid()) {
                bp.setResponse(br);
                QTC_CHECK(!bp.needsChange());
                bp.notifyBreakpointInsertOk();
            }
514
        }
hjk's avatar
hjk committed
515 516
    }
}
hjk's avatar
hjk committed
517

518 519 520 521 522
void PdbEngine::refreshLocals(const GdbMi &vars)
{
    WatchHandler *handler = watchHandler();
    handler->resetValueCache();

523 524
    foreach (const GdbMi &child, vars.children())
        handler->insertItem(new WatchItem(child));
525

526
    handler->notifyUpdateFinished();
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

    DebuggerToolTipManager::updateEngine(this);
}

void PdbEngine::refreshStack(const GdbMi &stack)
{
    StackHandler *handler = stackHandler();
    StackFrames frames;
    foreach (const GdbMi &item, stack["frames"].children()) {
        StackFrame frame;
        frame.level = item["level"].toInt();
        frame.file = item["file"].toUtf8();
        frame.function = item["func"].toUtf8();
        frame.from = item["func"].toUtf8();
        frame.line = item["line"].toInt();
        frame.address = item["addr"].toAddress();
        GdbMi usable = item["usable"];
        if (usable.isValid())
            frame.usable = usable.data().toInt();
        else
            frame.usable = QFileInfo(frame.file).isReadable();
        if (item["language"].data() == "js"
                || frame.file.endsWith(QLatin1String(".js"))
                || frame.file.endsWith(QLatin1String(".qml"))) {
            frame.language = QmlLanguage;
552
            frame.fixQmlFrame(runParameters());
hjk's avatar
hjk committed
553
        }
554
        frames.append(frame);
hjk's avatar
hjk committed
555
    }
556 557 558 559 560 561 562 563
    bool canExpand = stack["hasmore"].toInt();
    //action(ExpandStack)->setEnabled(canExpand);
    handler->setFrames(frames, canExpand);

    int index = stackHandler()->firstUsableIndex();
    handler->setCurrentIndex(index);
    if (index >= 0 && index < handler->stackSize())
        gotoLocation(handler->frameAt(index));
hjk's avatar
hjk committed
564 565 566
}

void PdbEngine::updateAll()
567
{
hjk's avatar
hjk committed
568
    runCommand("stackListFrames");
569
    updateLocals();
570 571 572
}

void PdbEngine::updateLocals()
hjk's avatar
hjk committed
573
{
574 575 576
    DebuggerCommand cmd("updateData");
    cmd.arg("nativeMixed", isNativeMixedActive());
    watchHandler()->appendFormatRequests(&cmd);
hjk's avatar
hjk committed
577

578 579 580 581 582 583 584 585
    const static bool alwaysVerbose = !qgetenv("QTC_DEBUGGER_PYTHON_VERBOSE").isEmpty();
    cmd.arg("passexceptions", alwaysVerbose);
    cmd.arg("fancy", boolSetting(UseDebuggingHelpers));

    cmd.beginList("watchers");

    // Watchers
    QHashIterator<QByteArray, int> it(WatchHandler::watcherNames());
hjk's avatar
hjk committed
586 587
    while (it.hasNext()) {
        it.next();
588 589 590 591
        cmd.beginGroup();
        cmd.arg("iname", "watch." + QByteArray::number(it.value()));
        cmd.arg("exp", it.key().toHex());
        cmd.endGroup();
hjk's avatar
hjk committed
592 593
    }

594 595 596 597 598 599 600
    // Tooltips
    DebuggerToolTipContexts toolTips = DebuggerToolTipManager::pendingTooltips(this);
    foreach (const DebuggerToolTipContext &p, toolTips) {
        cmd.beginGroup();
        cmd.arg("iname", p.iname);
        cmd.arg("exp", p.expression.toLatin1().toHex());
        cmd.endGroup();
hjk's avatar
hjk committed
601
    }
602

603 604 605 606 607
    cmd.endList();

    //cmd.arg("resultvarname", m_resultVarName);
    //m_lastDebuggableCommand = cmd;
    //m_lastDebuggableCommand.args.replace("\"passexceptions\":0", "\"passexceptions\":1");
hjk's avatar
hjk committed
608
    cmd.arg("frame", stackHandler()->currentIndex());
609

610
    watchHandler()->notifyUpdateStarted();
611
    runCommand(cmd);
hjk's avatar
hjk committed
612 613
}

614
bool PdbEngine::hasCapability(unsigned cap) const
hjk's avatar
hjk committed
615
{
hjk's avatar
hjk committed
616 617 618
    return cap & (ReloadModuleCapability
              | BreakConditionCapability
              | ShowModuleSymbolsCapability);
hjk's avatar
hjk committed
619 620
}

621
DebuggerEngine *createPdbEngine(const DebuggerRunParameters &startParameters)
hjk's avatar
hjk committed
622
{
623
    return new PdbEngine(startParameters);
hjk's avatar
hjk committed
624 625 626 627
}

} // namespace Internal
} // namespace Debugger