pdbengine.cpp 17.6 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
    QTC_ASSERT(m_proc.state() == QProcess::Running, notifyEngineIll());
hjk's avatar
hjk committed
95 96 97
    QString command = "qdebug('" + cmd.function + "'," + cmd.argsToPython() + ")";
    showMessage(command, LogInput);
    m_proc.write(command.toUtf8() + '\n');
98 99
}

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

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

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

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

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

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

    QStringList args = { bridge, scriptFile.fileName() };
137
    args.append(Utils::QtcProcess::splitArgs(runParameters().inferior.workingDirectory));
hjk's avatar
hjk committed
138
    showMessage("STARTING " + m_interpreter + QLatin1Char(' ') + args.join(QLatin1Char(' ')));
139
    m_proc.setEnvironment(runParameters().debuggerEnvironment.toStringList());
hjk's avatar
hjk committed
140
    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();
hjk's avatar
hjk committed
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
    return fileName.endsWith(".py");
hjk's avatar
hjk committed
259 260
}

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

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

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

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

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

void PdbEngine::loadAllSymbols()
{
}

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

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

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

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

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

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

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

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

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

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

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

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

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

void PdbEngine::readPdbStandardOutput()
{
hjk's avatar
hjk committed
449
    QString out = QString::fromUtf8(m_proc.readAllStandardOutput());
450 451 452
    handleOutput(out);
}

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

hjk's avatar
hjk committed
466
void PdbEngine::handleOutput2(const QString &data)
467
{
hjk's avatar
hjk committed
468
    foreach (QString line, data.split('\n')) {
469

hjk's avatar
hjk committed
470 471
        GdbMi item;
        item.fromString(line);
hjk's avatar
hjk committed
472

hjk's avatar
hjk committed
473
        showMessage(line, LogOutput);
474 475

        if (line.startsWith("stack={")) {
hjk's avatar
hjk committed
476
            refreshStack(item);
hjk's avatar
hjk committed
477
        } else if (line.startsWith("data={")) {
hjk's avatar
hjk committed
478
            refreshLocals(item);
hjk's avatar
hjk committed
479
        } else if (line.startsWith("modules=[")) {
hjk's avatar
hjk committed
480
            refreshModules(item);
hjk's avatar
hjk committed
481
        } else if (line.startsWith("symbols={")) {
hjk's avatar
hjk committed
482
            refreshSymbols(item);
483 484
        } else if (line.startsWith("location={")) {
            refreshLocation(item);
485 486
        } else if (line.startsWith("state=")) {
            refreshState(item);
hjk's avatar
hjk committed
487
        } else if (line.startsWith("Breakpoint")) {
hjk's avatar
hjk committed
488 489
            int pos1 = line.indexOf(" at ");
            QTC_ASSERT(pos1 != -1, continue);
hjk's avatar
hjk committed
490
            QString bpnr = line.mid(11, pos1 - 11);
hjk's avatar
hjk committed
491 492 493 494
            int pos2 = line.lastIndexOf(':');
            QTC_ASSERT(pos2 != -1, continue);
            BreakpointResponse br;
            br.id = BreakpointResponseId(bpnr);
hjk's avatar
hjk committed
495 496
            br.fileName = line.mid(pos1 + 4, pos2 - pos1 - 4);
            br.lineNumber = line.mid(pos2 + 1).toInt();
hjk's avatar
hjk committed
497 498 499 500 501 502
            Breakpoint bp = breakHandler()->findBreakpointByFileAndLine(br.fileName, br.lineNumber, false);
            if (bp.isValid()) {
                bp.setResponse(br);
                QTC_CHECK(!bp.needsChange());
                bp.notifyBreakpointInsertOk();
            }
503
        }
hjk's avatar
hjk committed
504 505
    }
}
hjk's avatar
hjk committed
506

507 508 509 510
void PdbEngine::refreshLocals(const GdbMi &vars)
{
    WatchHandler *handler = watchHandler();
    handler->resetValueCache();
511
    handler->insertItems(vars);
512
    handler->notifyUpdateFinished();
513 514 515 516 517 518 519 520 521 522

    DebuggerToolTipManager::updateEngine(this);
}

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

void PdbEngine::updateAll()
547
{
548
    runCommand({"stackListFrames"});
549
    updateLocals();
550 551 552
}

void PdbEngine::updateLocals()
hjk's avatar
hjk committed
553
{
554 555 556
    DebuggerCommand cmd("updateData");
    cmd.arg("nativeMixed", isNativeMixedActive());
    watchHandler()->appendFormatRequests(&cmd);
hjk's avatar
hjk committed
557
    watchHandler()->appendWatchersAndTooltipRequests(&cmd);
hjk's avatar
hjk committed
558

559 560 561 562 563 564 565
    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
566
    cmd.arg("frame", stackHandler()->currentIndex());
567

568
    watchHandler()->notifyUpdateStarted();
569
    runCommand(cmd);
hjk's avatar
hjk committed
570 571
}

572
bool PdbEngine::hasCapability(unsigned cap) const
hjk's avatar
hjk committed
573
{
hjk's avatar
hjk committed
574 575 576
    return cap & (ReloadModuleCapability
              | BreakConditionCapability
              | ShowModuleSymbolsCapability);
hjk's avatar
hjk committed
577 578
}

579
DebuggerEngine *createPdbEngine(const DebuggerRunParameters &startParameters)
hjk's avatar
hjk committed
580
{
581
    return new PdbEngine(startParameters);
hjk's avatar
hjk committed
582 583 584 585
}

} // namespace Internal
} // namespace Debugger