1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
SPDX-FileCopyrightText: 2009 Niko Sams <niko.sams@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "ivariablecontroller.h"
#include "idebugsession.h"
#include "../../interfaces/icore.h"
#include "../../interfaces/idebugcontroller.h"
#include "../variable/variablecollection.h"
#include <debug.h>
#include "iframestackmodel.h"
namespace KDevelop {
class IVariableControllerPrivate
{
public:
QFlags<IVariableController::UpdateType> autoUpdate;
int activeThread = -1;
int activeFrame = -1;
};
IVariableController::IVariableController(IDebugSession* parent)
: QObject(parent)
, d_ptr(new IVariableControllerPrivate)
{
connect(parent, &IDebugSession::stateChanged,
this, &IVariableController::stateChanged);
}
IVariableController::~IVariableController() = default;
VariableCollection* IVariableController::variableCollection()
{
if (!ICore::self()) return nullptr;
return ICore::self()->debugController()->variableCollection();
}
IDebugSession* IVariableController::session() const
{
return static_cast<IDebugSession*>(parent());
}
void IVariableController::stateChanged(IDebugSession::DebuggerState state)
{
Q_D(IVariableController);
if (!ICore::self() || ICore::self()->shuttingDown()) {
return;
}
if (state == IDebugSession::ActiveState) {
//variables are now outdated, update them
d->activeThread = -1;
d->activeFrame = -1;
} else if (state == IDebugSession::EndedState || state == IDebugSession::NotStartedState) {
// Remove all locals.
const auto locals = variableCollection()->allLocals();
for (Locals* l : locals) {
l->deleteChildren();
l->setHasMore(false);
}
for (int i=0; i < variableCollection()->watches()->childCount(); ++i) {
auto *var = qobject_cast<Variable*>(variableCollection()->watches()->child(i));
if (var) {
var->setInScope(false);
}
}
}
}
void IVariableController::updateIfFrameOrThreadChanged()
{
Q_D(IVariableController);
IFrameStackModel *sm = session()->frameStackModel();
if (sm->currentThread() != d->activeThread || sm->currentFrame() != d->activeFrame) {
variableCollection()->root()->resetChanged();
update();
}
}
void IVariableController::handleEvent(IDebugSession::event_t event)
{
Q_D(IVariableController);
if (!variableCollection()) return;
switch (event) {
case IDebugSession::thread_or_frame_changed:
qCDebug(DEBUGGER) << d->autoUpdate;
if (!(d->autoUpdate & UpdateLocals)) {
const auto locals = variableCollection()->allLocals();
for (Locals* l : locals) {
if (!l->isExpanded() && !l->childCount()) {
l->setHasMore(true);
}
}
}
if (d->autoUpdate != UpdateNone) {
updateIfFrameOrThreadChanged();
}
// update our cache of active thread/frame regardless of d->autoUpdate
// to keep them synced when user currently hides the variable list
d->activeThread = session()->frameStackModel()->currentThread();
d->activeFrame = session()->frameStackModel()->currentFrame();
break;
default:
break;
}
}
void IVariableController::setAutoUpdate(QFlags<UpdateType> autoUpdate)
{
Q_D(IVariableController);
IDebugSession::DebuggerState state = session()->state();
d->autoUpdate = autoUpdate;
qCDebug(DEBUGGER) << d->autoUpdate;
if (d->autoUpdate != UpdateNone && state == IDebugSession::PausedState) {
update();
}
}
QFlags<IVariableController::UpdateType> IVariableController::autoUpdate()
{
Q_D(IVariableController);
return d->autoUpdate;
}
}
|