pdbengine.cpp 17.8 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
#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/debuggertooltipmanager.h>
Christian Kandeler's avatar
Christian Kandeler committed
35
#include <debugger/threaddata.h>
36

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

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

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

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

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

namespace Debugger {
namespace Internal {

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

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

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

92 93
void PdbEngine::runCommand(const DebuggerCommand &cmd)
{
94 95 96 97
    if (state() == EngineSetupRequested) { // cmd has been triggered too early
        showMessage("IGNORED COMMAND: " + cmd.function);
        return;
    }
98
    QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
hjk's avatar
hjk committed
99 100 101
    QString command = "qdebug('" + cmd.function + "'," + cmd.argsToPython() + ")";
    showMessage(command, LogInput);
    m_proc.write(command.toUtf8() + '\n');
102 103
}

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

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

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

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

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

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

    QStringList args = { bridge, scriptFile.fileName() };
141
    args.append(Utils::QtcProcess::splitArgs(runParameters().inferior.workingDirectory));
hjk's avatar
hjk committed
142
    showMessage("STARTING " + m_interpreter + QLatin1Char(' ') + args.join(QLatin1Char(' ')));
143
    m_proc.setEnvironment(runParameters().debugger.environment.toStringList());
hjk's avatar
hjk committed
144
    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();
hjk's avatar
hjk committed
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();
172
    updateAll();
hjk's avatar
hjk committed
173 174 175 176
}

void PdbEngine::interruptInferior()
{
177 178
    QString error;
    interruptProcess(m_proc.processId(), GdbEngineType, &error);
hjk's avatar
hjk committed
179 180 181 182
}

void PdbEngine::executeStep()
{
183 184
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
185
    postDirectCommand("step");
hjk's avatar
hjk committed
186 187 188 189
}

void PdbEngine::executeStepI()
{
190 191
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
192
    postDirectCommand("step");
hjk's avatar
hjk committed
193 194 195 196
}

void PdbEngine::executeStepOut()
{
197 198
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
199
    postDirectCommand("return");
hjk's avatar
hjk committed
200 201 202 203
}

void PdbEngine::executeNext()
{
204 205
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
206
    postDirectCommand("next");
hjk's avatar
hjk committed
207 208 209 210
}

void PdbEngine::executeNextI()
{
211 212
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
hjk's avatar
hjk committed
213
    postDirectCommand("next");
hjk's avatar
hjk committed
214 215 216 217
}

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

224
void PdbEngine::executeRunToLine(const ContextData &data)
hjk's avatar
hjk committed
225
{
226
    Q_UNUSED(data)
hjk's avatar
hjk committed
227
    QTC_CHECK("FIXME:  PdbEngine::runToLineExec()" && false);
hjk's avatar
hjk committed
228 229 230 231 232
}

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

236
void PdbEngine::executeJumpToLine(const ContextData &data)
hjk's avatar
hjk committed
237
{
238
    Q_UNUSED(data)
hjk's avatar
hjk committed
239
    QTC_CHECK("FIXME:  PdbEngine::jumpToLineExec()" && false);
hjk's avatar
hjk committed
240 241 242 243
}

void PdbEngine::activateFrame(int frameIndex)
{
hjk's avatar
hjk committed
244
    if (state() != InferiorStopOk && state() != InferiorUnrunnable)
hjk's avatar
hjk committed
245 246
        return;

247 248
    StackHandler *handler = stackHandler();
    QTC_ASSERT(frameIndex < handler->stackSize(), return);
hjk's avatar
hjk committed
249
    handler->setCurrentIndex(frameIndex);
250
    gotoLocation(handler->currentFrame());
hjk's avatar
hjk committed
251
    updateLocals();
hjk's avatar
hjk committed
252 253
}

hjk's avatar
hjk committed
254
void PdbEngine::selectThread(ThreadId threadId)
hjk's avatar
hjk committed
255
{
hjk's avatar
hjk committed
256
    Q_UNUSED(threadId)
hjk's avatar
hjk committed
257 258
}

259
bool PdbEngine::acceptsBreakpoint(Breakpoint bp) const
hjk's avatar
hjk committed
260
{
261
    const QString fileName = bp.fileName();
hjk's avatar
hjk committed
262
    return fileName.endsWith(".py");
hjk's avatar
hjk committed
263 264
}

265
void PdbEngine::insertBreakpoint(Breakpoint bp)
hjk's avatar
hjk committed
266
{
267 268
    QTC_CHECK(bp.state() == BreakpointInsertRequested);
    bp.notifyBreakpointInsertProceeding();
hjk's avatar
hjk committed
269

hjk's avatar
hjk committed
270
    QString loc;
271
    if (bp.type() == BreakpointByFunction)
hjk's avatar
hjk committed
272
        loc = bp.functionName();
hjk's avatar
hjk committed
273
    else
hjk's avatar
hjk committed
274
        loc = bp.fileName() + ':' + QString::number(bp.lineNumber());
hjk's avatar
hjk committed
275

hjk's avatar
hjk committed
276
    postDirectCommand("break " + loc);
hjk's avatar
hjk committed
277 278
}

279
void PdbEngine::removeBreakpoint(Breakpoint bp)
hjk's avatar
hjk committed
280
{
281 282 283
    QTC_CHECK(bp.state() == BreakpointRemoveRequested);
    bp.notifyBreakpointRemoveProceeding();
    BreakpointResponse br = bp.response();
hjk's avatar
hjk committed
284 285
    showMessage(QString("DELETING BP %1 IN %2").arg(br.id.toString()).arg(bp.fileName()));
    postDirectCommand("clear " + br.id.toString());
hjk's avatar
hjk committed
286
    // Pretend it succeeds without waiting for response.
287
    bp.notifyBreakpointRemoveOk();
hjk's avatar
hjk committed
288 289
}

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

void PdbEngine::loadAllSymbols()
{
}

void PdbEngine::reloadModules()
{
301
    runCommand({"listModules"});
hjk's avatar
hjk committed
302 303
}

hjk's avatar
hjk committed
304
void PdbEngine::refreshModules(const GdbMi &modules)
hjk's avatar
hjk committed
305
{
306 307
    ModulesHandler *handler = modulesHandler();
    handler->beginUpdateAll();
hjk's avatar
hjk committed
308
    foreach (const GdbMi &item, modules.children()) {
hjk's avatar
hjk committed
309
        Module module;
hjk's avatar
hjk committed
310 311 312
        module.moduleName = item["name"].data();
        QString path = item["value"].data();
        int pos = path.indexOf("' from '");
hjk's avatar
hjk committed
313 314 315 316
        if (pos != -1) {
            path = path.mid(pos + 8);
            if (path.size() >= 2)
                path.chop(2);
hjk's avatar
hjk committed
317 318 319
        } else if (path.startsWith("<module '")
                && path.endsWith("' (built-in)>")) {
            path = "(builtin)";
hjk's avatar
hjk committed
320 321
        }
        module.modulePath = path;
322
        handler->updateModule(module);
hjk's avatar
hjk committed
323
    }
324
    handler->endUpdateAll();
hjk's avatar
hjk committed
325 326
}

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

334 335
void PdbEngine::refreshState(const GdbMi &reportedState)
{
hjk's avatar
hjk committed
336
    QString newState = reportedState.data();
337 338 339 340 341 342 343 344
    if (newState == "stopped") {
        notifyInferiorSpontaneousStop();
        updateAll();
    } else if (newState == "inferiorexited") {
        notifyInferiorExited();
    }
}

345 346 347
void PdbEngine::refreshLocation(const GdbMi &reportedLocation)
{
    StackFrame frame;
hjk's avatar
hjk committed
348
    frame.file = reportedLocation["file"].data();
349
    frame.line = reportedLocation["line"].toInt();
350
    frame.usable = QFileInfo(frame.file).isReadable();
351
    if (state() == InferiorRunOk) {
hjk's avatar
hjk committed
352
        showMessage(QString("STOPPED AT: %1:%2").arg(frame.file).arg(frame.line));
353 354 355 356 357 358
        gotoLocation(frame);
        notifyInferiorSpontaneousStop();
        updateAll();
    }
}

hjk's avatar
hjk committed
359
void PdbEngine::refreshSymbols(const GdbMi &symbols)
hjk's avatar
hjk committed
360
{
hjk's avatar
hjk committed
361
    QString moduleName = symbols["module"].data();
hjk's avatar
hjk committed
362 363
    Symbols syms;
    foreach (const GdbMi &item, symbols["symbols"].children()) {
hjk's avatar
hjk committed
364
        Symbol symbol;
hjk's avatar
hjk committed
365
        symbol.name = item["name"].data();
hjk's avatar
hjk committed
366
        syms.append(symbol);
hjk's avatar
hjk committed
367
    }
hjk's avatar
hjk committed
368
    Internal::showModuleSymbols(moduleName, syms);
hjk's avatar
hjk committed
369
}
hjk's avatar
hjk committed
370

371
bool PdbEngine::canHandleToolTip(const DebuggerToolTipContext &) const
hjk's avatar
hjk committed
372
{
373
    return state() == InferiorStopOk;
hjk's avatar
hjk committed
374 375
}

376
void PdbEngine::assignValueInDebugger(WatchItem *, const QString &expression, const QVariant &value)
377 378 379 380 381
{
    //DebuggerCommand cmd("assignValue");
    //cmd.arg("expression", expression);
    //cmd.arg("value", value.toString());
    //runCommand(cmd);
hjk's avatar
hjk committed
382
    postDirectCommand("global " + expression + ';' + expression + "=" + value.toString());
hjk's avatar
hjk committed
383 384 385
    updateLocals();
}

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

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

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

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

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

void PdbEngine::readPdbStandardOutput()
{
hjk's avatar
hjk committed
453
    QString out = QString::fromUtf8(m_proc.readAllStandardOutput());
454 455 456
    handleOutput(out);
}

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

hjk's avatar
hjk committed
470
void PdbEngine::handleOutput2(const QString &data)
471
{
hjk's avatar
hjk committed
472
    foreach (QString line, data.split('\n')) {
473

hjk's avatar
hjk committed
474 475
        GdbMi item;
        item.fromString(line);
hjk's avatar
hjk committed
476

hjk's avatar
hjk committed
477
        showMessage(line, LogOutput);
478 479

        if (line.startsWith("stack={")) {
hjk's avatar
hjk committed
480
            refreshStack(item);
hjk's avatar
hjk committed
481
        } else if (line.startsWith("data={")) {
hjk's avatar
hjk committed
482
            refreshLocals(item);
hjk's avatar
hjk committed
483
        } else if (line.startsWith("modules=[")) {
hjk's avatar
hjk committed
484
            refreshModules(item);
hjk's avatar
hjk committed
485
        } else if (line.startsWith("symbols={")) {
hjk's avatar
hjk committed
486
            refreshSymbols(item);
487 488
        } else if (line.startsWith("location={")) {
            refreshLocation(item);
489 490
        } else if (line.startsWith("state=")) {
            refreshState(item);
hjk's avatar
hjk committed
491
        } else if (line.startsWith("Breakpoint")) {
hjk's avatar
hjk committed
492 493
            int pos1 = line.indexOf(" at ");
            QTC_ASSERT(pos1 != -1, continue);
hjk's avatar
hjk committed
494
            QString bpnr = line.mid(11, pos1 - 11);
hjk's avatar
hjk committed
495 496 497 498
            int pos2 = line.lastIndexOf(':');
            QTC_ASSERT(pos2 != -1, continue);
            BreakpointResponse br;
            br.id = BreakpointResponseId(bpnr);
hjk's avatar
hjk committed
499 500
            br.fileName = line.mid(pos1 + 4, pos2 - pos1 - 4);
            br.lineNumber = line.mid(pos2 + 1).toInt();
hjk's avatar
hjk committed
501 502 503 504 505 506
            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
void PdbEngine::refreshLocals(const GdbMi &vars)
{
    WatchHandler *handler = watchHandler();
    handler->resetValueCache();
515
    handler->insertItems(vars);
516
    handler->notifyUpdateFinished();
517 518 519 520 521 522 523 524 525 526

    DebuggerToolTipManager::updateEngine(this);
}

void PdbEngine::refreshStack(const GdbMi &stack)
{
    StackHandler *handler = stackHandler();
    StackFrames frames;
    foreach (const GdbMi &item, stack["frames"].children()) {
        StackFrame frame;
527
        frame.level = item["level"].data();
hjk's avatar
hjk committed
528 529 530
        frame.file = item["file"].data();
        frame.function = item["function"].data();
        frame.module = item["function"].data();
531
        frame.line = item["line"].toInt();
532
        frame.address = item["address"].toAddress();
533 534 535 536 537 538
        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
539
    }
540 541 542 543 544 545 546 547
    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
548 549 550
}

void PdbEngine::updateAll()
551
{
552
    runCommand({"stackListFrames"});
553
    updateLocals();
554 555 556
}

void PdbEngine::updateLocals()
hjk's avatar
hjk committed
557
{
558 559 560
    DebuggerCommand cmd("updateData");
    cmd.arg("nativeMixed", isNativeMixedActive());
    watchHandler()->appendFormatRequests(&cmd);
hjk's avatar
hjk committed
561
    watchHandler()->appendWatchersAndTooltipRequests(&cmd);
hjk's avatar
hjk committed
562

563 564 565 566 567 568 569
    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
570
    cmd.arg("frame", stackHandler()->currentIndex());
571

572
    watchHandler()->notifyUpdateStarted();
573
    runCommand(cmd);
hjk's avatar
hjk committed
574 575
}

576
bool PdbEngine::hasCapability(unsigned cap) const
hjk's avatar
hjk committed
577
{
hjk's avatar
hjk committed
578 579 580
    return cap & (ReloadModuleCapability
              | BreakConditionCapability
              | ShowModuleSymbolsCapability);
hjk's avatar
hjk committed
581 582
}

583
DebuggerEngine *createPdbEngine(const DebuggerRunParameters &startParameters)
hjk's avatar
hjk committed
584
{
585
    return new PdbEngine(startParameters);
hjk's avatar
hjk committed
586 587 588 589
}

} // namespace Internal
} // namespace Debugger