pdbengine.cpp 17.9 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
hjk's avatar
hjk committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://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
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
hjk's avatar
hjk committed
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25 26 27

#include "pdbengine.h"

28 29 30 31 32 33 34 35
#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
36
#include <debugger/threaddata.h>
37

38 39
#include <debugger/breakhandler.h>
#include <debugger/moduleshandler.h>
40
#include <debugger/procinterrupt.h>
41 42 43 44 45
#include <debugger/registerhandler.h>
#include <debugger/stackhandler.h>
#include <debugger/sourceutils.h>
#include <debugger/watchhandler.h>
#include <debugger/watchutils.h>
46

hjk's avatar
hjk committed
47
#include <utils/qtcassert.h>
hjk's avatar
hjk committed
48
#include <utils/qtcprocess.h>
hjk's avatar
hjk committed
49

50
#include <coreplugin/idocument.h>
hjk's avatar
hjk committed
51
#include <coreplugin/icore.h>
52
#include <coreplugin/messagebox.h>
hjk's avatar
hjk committed
53

54 55 56 57 58 59
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QTimer>
#include <QVariant>
60
#include <QJsonArray>
hjk's avatar
hjk committed
61

hjk's avatar
hjk committed
62
using namespace Core;
hjk's avatar
hjk committed
63 64 65 66

namespace Debugger {
namespace Internal {

67
PdbEngine::PdbEngine(const DebuggerRunParameters &startParameters)
68
    : DebuggerEngine(startParameters)
Friedemann Kleint's avatar
Friedemann Kleint committed
69 70 71
{
    setObjectName(QLatin1String("PdbEngine"));
}
hjk's avatar
hjk committed
72

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

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

93 94
void PdbEngine::runCommand(const DebuggerCommand &cmd)
{
95
    QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
96
    QByteArray command = "qdebug('" + cmd.function + "'," + cmd.argsToPython() + ")";
97
    showMessage(_(command), LogInput);
98
    m_proc.write(command + '\n');
99 100
}

hjk's avatar
hjk committed
101
void PdbEngine::shutdownInferior()
hjk's avatar
hjk committed
102
{
hjk's avatar
hjk committed
103 104
    QTC_ASSERT(state() == InferiorShutdownRequested, qDebug() << state());
    notifyInferiorShutdownOk();
hjk's avatar
hjk committed
105 106
}

hjk's avatar
hjk committed
107
void PdbEngine::shutdownEngine()
hjk's avatar
hjk committed
108
{
hjk's avatar
hjk committed
109
    QTC_ASSERT(state() == EngineShutdownRequested, qDebug() << state());
110
    m_proc.kill();
hjk's avatar
hjk committed
111 112
}

hjk's avatar
hjk committed
113
void PdbEngine::setupEngine()
hjk's avatar
hjk committed
114
{
hjk's avatar
hjk committed
115
    QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
hjk's avatar
hjk committed
116

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

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

hjk's avatar
hjk committed
129 130 131 132 133 134 135 136 137 138 139 140
    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
141

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

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

159
    notifyInferiorSetupOk();
hjk's avatar
hjk committed
160 161
}

hjk's avatar
hjk committed
162
void PdbEngine::runEngine()
hjk's avatar
hjk committed
163
{
164
    QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
hjk's avatar
hjk committed
165
    showStatusMessage(tr("Running requested..."), 5000);
166 167
    attemptBreakpointSynchronization();
    notifyEngineRunAndInferiorStopOk();
168
    updateAll();
hjk's avatar
hjk committed
169 170 171 172
}

void PdbEngine::interruptInferior()
{
173 174
    QString error;
    interruptProcess(m_proc.processId(), GdbEngineType, &error);
hjk's avatar
hjk committed
175 176 177 178
}

void PdbEngine::executeStep()
{
179 180
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
181
    postDirectCommand("step");
hjk's avatar
hjk committed
182 183 184 185
}

void PdbEngine::executeStepI()
{
186 187
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
188
    postDirectCommand("step");
hjk's avatar
hjk committed
189 190 191 192
}

void PdbEngine::executeStepOut()
{
193 194
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
195
    postDirectCommand("return");
hjk's avatar
hjk committed
196 197 198 199
}

void PdbEngine::executeNext()
{
200 201
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
202
    postDirectCommand("next");
hjk's avatar
hjk committed
203 204 205 206
}

void PdbEngine::executeNextI()
{
207 208
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
209
    postDirectCommand("next");
hjk's avatar
hjk committed
210 211 212 213
}

void PdbEngine::continueInferior()
{
214 215
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
216
    // Callback will be triggered e.g. when breakpoint is hit.
hjk's avatar
hjk committed
217
    postDirectCommand("continue");
hjk's avatar
hjk committed
218 219
}

220
void PdbEngine::executeRunToLine(const ContextData &data)
hjk's avatar
hjk committed
221
{
222
    Q_UNUSED(data)
hjk's avatar
hjk committed
223
    QTC_CHECK("FIXME:  PdbEngine::runToLineExec()" && false);
hjk's avatar
hjk committed
224 225 226 227 228
}

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

232
void PdbEngine::executeJumpToLine(const ContextData &data)
hjk's avatar
hjk committed
233
{
234
    Q_UNUSED(data)
hjk's avatar
hjk committed
235
    QTC_CHECK("FIXME:  PdbEngine::jumpToLineExec()" && false);
hjk's avatar
hjk committed
236 237 238 239
}

void PdbEngine::activateFrame(int frameIndex)
{
hjk's avatar
hjk committed
240
    if (state() != InferiorStopOk && state() != InferiorUnrunnable)
hjk's avatar
hjk committed
241 242
        return;

243 244
    StackHandler *handler = stackHandler();
    QTC_ASSERT(frameIndex < handler->stackSize(), return);
hjk's avatar
hjk committed
245
    handler->setCurrentIndex(frameIndex);
246
    gotoLocation(handler->currentFrame());
hjk's avatar
hjk committed
247
    updateLocals();
hjk's avatar
hjk committed
248 249
}

hjk's avatar
hjk committed
250
void PdbEngine::selectThread(ThreadId threadId)
hjk's avatar
hjk committed
251
{
hjk's avatar
hjk committed
252
    Q_UNUSED(threadId)
hjk's avatar
hjk committed
253 254
}

255
bool PdbEngine::acceptsBreakpoint(Breakpoint bp) const
hjk's avatar
hjk committed
256
{
257
    const QString fileName = bp.fileName();
hjk's avatar
hjk committed
258 259 260
    return fileName.endsWith(QLatin1String(".py"));
}

261
void PdbEngine::insertBreakpoint(Breakpoint bp)
hjk's avatar
hjk committed
262
{
263 264
    QTC_CHECK(bp.state() == BreakpointInsertRequested);
    bp.notifyBreakpointInsertProceeding();
hjk's avatar
hjk committed
265 266

    QByteArray loc;
267 268
    if (bp.type() == BreakpointByFunction)
        loc = bp.functionName().toLatin1();
hjk's avatar
hjk committed
269
    else
270 271
        loc = bp.fileName().toLocal8Bit() + ':'
         + QByteArray::number(bp.lineNumber());
hjk's avatar
hjk committed
272

hjk's avatar
hjk committed
273
    postDirectCommand("break " + loc);
hjk's avatar
hjk committed
274 275
}

276
void PdbEngine::removeBreakpoint(Breakpoint bp)
hjk's avatar
hjk committed
277
{
278 279 280 281
    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
282
    postDirectCommand("clear " + br.id.toByteArray());
hjk's avatar
hjk committed
283
    // Pretend it succeeds without waiting for response.
284
    bp.notifyBreakpointRemoveOk();
hjk's avatar
hjk committed
285 286
}

hjk's avatar
hjk committed
287 288 289 290 291 292 293 294 295 296 297
void PdbEngine::loadSymbols(const QString &moduleName)
{
    Q_UNUSED(moduleName)
}

void PdbEngine::loadAllSymbols()
{
}

void PdbEngine::reloadModules()
{
298
    runCommand({"listModules"});
hjk's avatar
hjk committed
299 300
}

hjk's avatar
hjk committed
301
void PdbEngine::refreshModules(const GdbMi &modules)
hjk's avatar
hjk committed
302
{
303 304
    ModulesHandler *handler = modulesHandler();
    handler->beginUpdateAll();
hjk's avatar
hjk committed
305
    foreach (const GdbMi &item, modules.children()) {
hjk's avatar
hjk committed
306
        Module module;
307 308
        module.moduleName = _(item["name"].data());
        QString path = _(item["value"].data());
hjk's avatar
hjk committed
309 310 311 312 313 314 315 316 317 318
        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;
319
        handler->updateModule(module);
hjk's avatar
hjk committed
320
    }
321
    handler->endUpdateAll();
hjk's avatar
hjk committed
322 323
}

hjk's avatar
hjk committed
324
void PdbEngine::requestModuleSymbols(const QString &moduleName)
hjk's avatar
hjk committed
325
{
hjk's avatar
hjk committed
326 327 328
    DebuggerCommand cmd("listSymbols");
    cmd.arg("module", moduleName);
    runCommand(cmd);
hjk's avatar
hjk committed
329 330
}

331 332 333 334 335 336 337 338 339 340 341
void PdbEngine::refreshState(const GdbMi &reportedState)
{
    QByteArray newState = reportedState.data();
    if (newState == "stopped") {
        notifyInferiorSpontaneousStop();
        updateAll();
    } else if (newState == "inferiorexited") {
        notifyInferiorExited();
    }
}

342 343 344 345 346
void PdbEngine::refreshLocation(const GdbMi &reportedLocation)
{
    StackFrame frame;
    frame.file = reportedLocation["file"].toUtf8();
    frame.line = reportedLocation["line"].toInt();
347
    frame.usable = QFileInfo(frame.file).isReadable();
348 349 350 351 352 353 354 355
    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
356
void PdbEngine::refreshSymbols(const GdbMi &symbols)
hjk's avatar
hjk committed
357
{
hjk's avatar
hjk committed
358 359 360
    QString moduleName = symbols["module"].toUtf8();
    Symbols syms;
    foreach (const GdbMi &item, symbols["symbols"].children()) {
hjk's avatar
hjk committed
361
        Symbol symbol;
hjk's avatar
hjk committed
362 363
        symbol.name = item["name"].toUtf8();
        syms.append(symbol);
hjk's avatar
hjk committed
364
    }
hjk's avatar
hjk committed
365
    Internal::showModuleSymbols(moduleName, syms);
hjk's avatar
hjk committed
366
}
hjk's avatar
hjk committed
367

368
bool PdbEngine::canHandleToolTip(const DebuggerToolTipContext &) const
hjk's avatar
hjk committed
369
{
370
    return state() == InferiorStopOk;
hjk's avatar
hjk committed
371 372
}

373
void PdbEngine::assignValueInDebugger(WatchItem *, const QString &expression, const QVariant &value)
374 375 376 377 378 379 380
{
    //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
381 382 383
    updateLocals();
}

hjk's avatar
hjk committed
384
void PdbEngine::updateItem(const QByteArray &iname)
hjk's avatar
hjk committed
385
{
386
    Q_UNUSED(iname);
hjk's avatar
hjk committed
387 388 389 390 391
    updateAll();
}

void PdbEngine::handlePdbError(QProcess::ProcessError error)
{
392
    showMessage(_("HANDLE PDB ERROR"));
hjk's avatar
hjk committed
393 394 395 396 397 398 399 400
    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:
401
        //setState(EngineShutdownRequested, true);
402
        m_proc.kill();
hjk's avatar
hjk committed
403
        AsynchronousMessageBox::critical(tr("Pdb I/O Error"), errorMessage(error));
hjk's avatar
hjk committed
404 405 406 407 408 409 410 411 412
        break;
    }
}

QString PdbEngine::errorMessage(QProcess::ProcessError error) const
{
    switch (error) {
        case QProcess::FailedToStart:
            return tr("The Pdb process failed to start. Either the "
413
                "invoked program \"%1\" is missing, or you may have insufficient "
hjk's avatar
hjk committed
414
                "permissions to invoke the program.")
hjk's avatar
hjk committed
415
                .arg(m_interpreter);
hjk's avatar
hjk committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
        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:
431
            return tr("An unknown error in the Pdb process occurred.") + QLatin1Char(' ');
hjk's avatar
hjk committed
432 433 434 435 436
    }
}

void PdbEngine::handlePdbFinished(int code, QProcess::ExitStatus type)
{
437
    showMessage(_("PDB PROCESS FINISHED, status %1, code %2").arg(type).arg(code));
438
    notifyEngineSpontaneousShutdown();
hjk's avatar
hjk committed
439 440 441 442
}

void PdbEngine::readPdbStandardError()
{
443
    QByteArray err = m_proc.readAllStandardError();
444
    //qWarning() << "Unexpected pdb stderr:" << err;
hjk's avatar
hjk committed
445
    showMessage(_("Unexpected pdb stderr: " + err));
446
    //handleOutput(err);
hjk's avatar
hjk committed
447 448 449 450
}

void PdbEngine::readPdbStandardOutput()
{
451
    QByteArray out = m_proc.readAllStandardOutput();
452 453 454 455 456 457 458
    handleOutput(out);
}

void PdbEngine::handleOutput(const QByteArray &data)
{
    m_inbuffer.append(data);
    while (true) {
459
        int pos = m_inbuffer.indexOf('\n');
460 461 462
        if (pos == -1)
            break;
        QByteArray response = m_inbuffer.left(pos).trimmed();
463
        m_inbuffer = m_inbuffer.mid(pos + 1);
hjk's avatar
hjk committed
464
        handleOutput2(response);
465 466 467 468 469
    }
}

void PdbEngine::handleOutput2(const QByteArray &data)
{
470 471
    foreach (QByteArray line, data.split('\n')) {

hjk's avatar
hjk committed
472 473
        GdbMi item;
        item.fromString(line);
hjk's avatar
hjk committed
474

475
        showMessage(_(line), LogOutput);
476 477

        if (line.startsWith("stack={")) {
hjk's avatar
hjk committed
478
            refreshStack(item);
hjk's avatar
hjk committed
479
        } else if (line.startsWith("data={")) {
hjk's avatar
hjk committed
480
            refreshLocals(item);
hjk's avatar
hjk committed
481
        } else if (line.startsWith("modules=[")) {
hjk's avatar
hjk committed
482
            refreshModules(item);
hjk's avatar
hjk committed
483
        } else if (line.startsWith("symbols={")) {
hjk's avatar
hjk committed
484
            refreshSymbols(item);
485 486
        } else if (line.startsWith("location={")) {
            refreshLocation(item);
487 488
        } else if (line.startsWith("state=")) {
            refreshState(item);
hjk's avatar
hjk committed
489
        } else if (line.startsWith("Breakpoint")) {
hjk's avatar
hjk committed
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
            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();
            }
507
        }
hjk's avatar
hjk committed
508 509
    }
}
hjk's avatar
hjk committed
510

511 512 513 514 515
void PdbEngine::refreshLocals(const GdbMi &vars)
{
    WatchHandler *handler = watchHandler();
    handler->resetValueCache();

hjk's avatar
hjk committed
516 517 518 519 520
    foreach (const GdbMi &child, vars.children()) {
        WatchItem *item = new WatchItem;
        item->parse(child);
        handler->insertItem(item);
    }
521

522
    handler->notifyUpdateFinished();
523 524 525 526 527 528 529 530 531 532

    DebuggerToolTipManager::updateEngine(this);
}

void PdbEngine::refreshStack(const GdbMi &stack)
{
    StackHandler *handler = stackHandler();
    StackFrames frames;
    foreach (const GdbMi &item, stack["frames"].children()) {
        StackFrame frame;
533
        frame.level = item["level"].data();
534
        frame.file = item["file"].toUtf8();
535 536
        frame.function = item["function"].toUtf8();
        frame.module = item["function"].toUtf8();
537
        frame.line = item["line"].toInt();
538
        frame.address = item["address"].toAddress();
539 540 541 542 543 544
        GdbMi usable = item["usable"];
        if (usable.isValid())
            frame.usable = usable.data().toInt();
        else
            frame.usable = QFileInfo(frame.file).isReadable();
        frames.append(frame);
hjk's avatar
hjk committed
545
    }
546 547 548 549 550 551 552 553
    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
554 555 556
}

void PdbEngine::updateAll()
557
{
558
    runCommand({"stackListFrames"});
559
    updateLocals();
560 561 562
}

void PdbEngine::updateLocals()
hjk's avatar
hjk committed
563
{
564 565 566
    DebuggerCommand cmd("updateData");
    cmd.arg("nativeMixed", isNativeMixedActive());
    watchHandler()->appendFormatRequests(&cmd);
hjk's avatar
hjk committed
567
    watchHandler()->appendWatchersAndTooltipRequests(&cmd);
hjk's avatar
hjk committed
568

569 570 571 572 573 574 575
    const static bool alwaysVerbose = !qgetenv("QTC_DEBUGGER_PYTHON_VERBOSE").isEmpty();
    cmd.arg("passexceptions", alwaysVerbose);
    cmd.arg("fancy", boolSetting(UseDebuggingHelpers));

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

578
    watchHandler()->notifyUpdateStarted();
579
    runCommand(cmd);
hjk's avatar
hjk committed
580 581
}

582
bool PdbEngine::hasCapability(unsigned cap) const
hjk's avatar
hjk committed
583
{
hjk's avatar
hjk committed
584 585 586
    return cap & (ReloadModuleCapability
              | BreakConditionCapability
              | ShowModuleSymbolsCapability);
hjk's avatar
hjk committed
587 588
}

589
DebuggerEngine *createPdbEngine(const DebuggerRunParameters &startParameters)
hjk's avatar
hjk committed
590
{
591
    return new PdbEngine(startParameters);
hjk's avatar
hjk committed
592 593 594 595
}

} // namespace Internal
} // namespace Debugger