• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevelop/kdevplatform/debugger

  • extragear
  • kdevelop
  • kdevelop
  • kdevplatform
  • debugger
  • interfaces
ivariablecontroller.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This file is part of KDevelop *
3  * Copyright 2009 Niko Sams <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Library General Public License as *
7  * published by the Free Software Foundation; either version 2 of the *
8  * License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Library General Public *
16  * License along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #include "ivariablecontroller.h"
22 
23 #include "idebugsession.h"
24 #include "../../interfaces/icore.h"
25 #include "../../interfaces/idebugcontroller.h"
26 #include "../variable/variablecollection.h"
27 #include <debug.h>
28 #include "iframestackmodel.h"
29 
30 
31 namespace KDevelop {
32 
33 class IVariableControllerPrivate
34 {
35 public:
36  QFlags<IVariableController::UpdateType> autoUpdate;
37  int activeThread = -1;
38  int activeFrame = -1;
39 };
40 
41 IVariableController::IVariableController(IDebugSession* parent)
42  : QObject(parent)
43  , d_ptr(new IVariableControllerPrivate)
44 {
45  connect(parent, &IDebugSession::stateChanged,
46  this, &IVariableController::stateChanged);
47 }
48 
49 IVariableController::~IVariableController() = default;
50 
51 VariableCollection* IVariableController::variableCollection()
52 {
53  if (!ICore::self()) return nullptr;
54  return ICore::self()->debugController()->variableCollection();
55 }
56 
57 IDebugSession* IVariableController::session() const
58 {
59  return static_cast<IDebugSession*>(parent());
60 }
61 
62 void IVariableController::stateChanged(IDebugSession::DebuggerState state)
63 {
64  Q_D(IVariableController);
65 
66  if (!ICore::self() || ICore::self()->shuttingDown()) {
67  return;
68  }
69 
70  if (state == IDebugSession::ActiveState) {
71  //variables are now outdated, update them
72  d->activeThread = -1;
73  d->activeFrame = -1;
74  } else if (state == IDebugSession::EndedState || state == IDebugSession::NotStartedState) {
75  // Remove all locals.
76  const auto locals = variableCollection()->allLocals();
77  for (Locals* l : locals) {
78  l->deleteChildren();
79  l->setHasMore(false);
80  }
81 
82  for (int i=0; i < variableCollection()->watches()->childCount(); ++i) {
83  auto *var = qobject_cast<Variable*>(variableCollection()->watches()->child(i));
84  if (var) {
85  var->setInScope(false);
86  }
87  }
88  }
89 }
90 
91 void IVariableController::updateIfFrameOrThreadChanged()
92 {
93  Q_D(IVariableController);
94 
95  IFrameStackModel *sm = session()->frameStackModel();
96  if (sm->currentThread() != d->activeThread || sm->currentFrame() != d->activeFrame) {
97  variableCollection()->root()->resetChanged();
98  update();
99  }
100 }
101 
102 void IVariableController::handleEvent(IDebugSession::event_t event)
103 {
104  Q_D(IVariableController);
105 
106  if (!variableCollection()) return;
107 
108  switch (event) {
109  case IDebugSession::thread_or_frame_changed:
110  qCDebug(DEBUGGER) << d->autoUpdate;
111  if (!(d->autoUpdate & UpdateLocals)) {
112  const auto locals = variableCollection()->allLocals();
113  for (Locals* l : locals) {
114  if (!l->isExpanded() && !l->childCount()) {
115  l->setHasMore(true);
116  }
117  }
118  }
119  if (d->autoUpdate != UpdateNone) {
120  updateIfFrameOrThreadChanged();
121  }
122 
123  // update our cache of active thread/frame regardless of d->autoUpdate
124  // to keep them synced when user currently hides the variable list
125  d->activeThread = session()->frameStackModel()->currentThread();
126  d->activeFrame = session()->frameStackModel()->currentFrame();
127  break;
128 
129  default:
130  break;
131  }
132 }
133 
134 void IVariableController::setAutoUpdate(QFlags<UpdateType> autoUpdate)
135 {
136  Q_D(IVariableController);
137 
138  IDebugSession::DebuggerState state = session()->state();
139  d->autoUpdate = autoUpdate;
140  qCDebug(DEBUGGER) << d->autoUpdate;
141  if (d->autoUpdate != UpdateNone && state == IDebugSession::PausedState) {
142  update();
143  }
144 }
145 
146 QFlags<IVariableController::UpdateType> IVariableController::autoUpdate()
147 {
148  Q_D(IVariableController);
149 
150  return d->autoUpdate;
151 }
152 
153 }
154 
KDevelop::VariableCollection::allLocals
QHash< QString, Locals * > allLocals() const
Definition: variablecollection.h:230
iframestackmodel.h
KDevelop::IDebugSession::ActiveState
Definition: idebugsession.h:48
KDevelop::IVariableController::IVariableController
IVariableController(IDebugSession *parent)
Definition: ivariablecontroller.cpp:41
KDevelop::IDebugSession::EndedState
Definition: idebugsession.h:52
KDevelop::Locals
Definition: variablecollection.h:166
KDevelop::IDebugSession::frameStackModel
virtual IFrameStackModel * frameStackModel() const =0
KDevelop::IVariableController::session
IDebugSession * session() const
Convenience function that returns the used DebugSession.
Definition: ivariablecontroller.cpp:57
KDevelop::IVariableController::update
virtual void update()=0
KDevelop::IVariableController::variableCollection
VariableCollection * variableCollection()
Convenience function that returns the VariableCollection.
Definition: ivariablecontroller.cpp:51
KDevelop::IDebugSession::stateChanged
void stateChanged(KDevelop::IDebugSession::DebuggerState state)
KDevelop::IVariableController::setAutoUpdate
void setAutoUpdate(QFlags< UpdateType > autoUpdate)
Definition: ivariablecontroller.cpp:134
KDevelop::IDebugSession::NotStartedState
Definition: idebugsession.h:46
QFlags
KDevelop::VariablesRoot::resetChanged
void resetChanged()
Definition: variablecollection.cpp:414
KDevelop::IDebugSession::event_t
event_t
Definition: idebugsession.h:56
KDevelop::IFrameStackModel::currentThread
virtual int currentThread() const =0
QObject
KDevelop::IVariableController::~IVariableController
~IVariableController() override
KDevelop::IVariableController::handleEvent
virtual void handleEvent(IDebugSession::event_t event)
Definition: ivariablecontroller.cpp:102
KDevelop::IVariableController
Definition: ivariablecontroller.h:42
ivariablecontroller.h
KDevelop::VariableCollection::root
VariablesRoot * root() const
Definition: variablecollection.h:227
KDevelop::TreeItem::childCount
int childCount() const
Definition: treeitem.cpp:153
KDevelop::TreeItem::child
TreeItem * child(int row)
Definition: treeitem.cpp:142
KDevelop::IDebugSession::PausedState
Definition: idebugsession.h:49
KDevelop::IDebugSession::DebuggerState
DebuggerState
Definition: idebugsession.h:45
KDevelop::VariableCollection
Definition: variablecollection.h:213
KDevelop::IDebugSession::state
virtual DebuggerState state() const =0
Current state of the debug session.
KDevelop::IVariableController::UpdateNone
Definition: ivariablecontroller.h:61
KDevelop::IFrameStackModel::currentFrame
virtual int currentFrame() const =0
Return the frame we wish to operate on.
KDevelop::IVariableController::autoUpdate
QFlags< UpdateType > autoUpdate()
Definition: ivariablecontroller.cpp:146
KDevelop::IVariableController::UpdateLocals
Definition: ivariablecontroller.h:62
KDevelop::IDebugSession::thread_or_frame_changed
Definition: idebugsession.h:62
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
KDevelop::IDebugSession
Definition: idebugsession.h:38
idebugsession.h
KDevelop::VariableCollection::watches
Watches * watches() const
Definition: variablecollection.h:228
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Thu Dec 12 2019 03:32:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevelop/kdevplatform/debugger

Skip menu "kdevelop/kdevplatform/debugger"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  •   kdevplatform
  •     debugger
  •     documentation
  •     interfaces
  •     language
  •       assistant
  •       backgroundparser
  •       checks
  •       classmodel
  •       codecompletion
  •       codegen
  •       duchain
  •       editor
  •       highlighting
  •       interfaces
  •       util
  •     outputview
  •     project
  •     serialization
  •     shell
  •     sublime
  •     tests
  •     util
  •     vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal