pdbengine.cpp 18.2 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>
65
#include <QJsonArray>
hjk's avatar
hjk committed
66

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

namespace Debugger {
namespace Internal {

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

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

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

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

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

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

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

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

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

hjk's avatar
hjk committed
134 135 136 137 138 139 140 141 142 143 144 145
    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
146

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    QByteArray loc;
272 273
    if (bp.type() == BreakpointByFunction)
        loc = bp.functionName().toLatin1();
hjk's avatar
hjk committed
274
    else
275 276
        loc = bp.fileName().toLocal8Bit() + ':'
         + QByteArray::number(bp.lineNumber());
hjk's avatar
hjk committed
277

hjk's avatar
hjk committed
278
    postDirectCommand("break " + loc);
hjk's avatar
hjk committed
279 280
}

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

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

void PdbEngine::loadAllSymbols()
{
}

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

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

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

336 337 338 339 340 341 342 343 344 345 346
void PdbEngine::refreshState(const GdbMi &reportedState)
{
    QByteArray newState = reportedState.data();
    if (newState == "stopped") {
        notifyInferiorSpontaneousStop();
        updateAll();
    } else if (newState == "inferiorexited") {
        notifyInferiorExited();
    }
}

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

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

378
void PdbEngine::assignValueInDebugger(WatchItem *, const QString &expression, const QVariant &value)
379 380 381 382 383 384 385
{
    //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
386 387 388
    updateLocals();
}

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

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

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

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

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

void PdbEngine::readPdbStandardOutput()
{
456
    QByteArray out = m_proc.readAllStandardOutput();
457 458 459 460 461 462 463
    handleOutput(out);
}

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

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

hjk's avatar
hjk committed
477 478
        GdbMi item;
        item.fromString(line);
hjk's avatar
hjk committed
479

480
        showMessage(_(line), LogOutput);
481 482

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

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

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

524
    handler->notifyUpdateFinished();
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546

    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();
        frames.append(frame);
hjk's avatar
hjk committed
547
    }
548 549 550 551 552 553 554 555
    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
556 557 558
}

void PdbEngine::updateAll()
559
{
hjk's avatar
hjk committed
560
    runCommand("stackListFrames");
561
    updateLocals();
562 563 564
}

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

571 572 573 574 575 576 577
    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
578
    cmd.arg("frame", stackHandler()->currentIndex());
579

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

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

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

} // namespace Internal
} // namespace Debugger