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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
|
/***************************************************************************
begin : Sun Aug 8 1999
copyright : (C) 1999 by John Birch
email : jbb@tdevelop.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _VARIABLEWIDGET_H_
#define _VARIABLEWIDGET_H_
#include "gdbcontroller.h"
#include "mi/gdbmi.h"
#include <klistview.h>
#include <kcombobox.h>
#include <tqwidget.h>
#include <tqtooltip.h>
#include <tqvaluevector.h>
#include <tqdatetime.h>
#include <tqguardedptr.h>
#include <tqmap.h>
#include <vector>
class KLineEdit;
class TDEPopupMenu;
namespace GDBDebugger
{
class TrimmableItem;
class VarFrameRoot;
class WatchRoot;
class VarItem;
class VariableTree;
class DbgController;
class GDBBreakpointWidget;
enum { VarNameCol = 0, ValueCol = 1, VarTypeCol = 2};
enum DataType { typeUnknown, typeValue, typePointer, typeReference,
typeStruct, typeArray, typeTQString, typeWhitespace,
typeName };
class VariableWidget : public TQWidget
{
Q_OBJECT
public:
VariableWidget( GDBController* controller,
GDBBreakpointWidget* breakpointWidget,
TQWidget *parent=0, const char *name=0 );
VariableTree *varTree() const
{ return varTree_; }
protected: // TQWidget overrides
void focusInEvent(TQFocusEvent *e);
public slots:
void slotAddWatchVariable();
void slotAddWatchVariable(const TQString &ident);
void slotEvaluateExpression();
void slotEvaluateExpression(const TQString &ident);
private:
VariableTree *varTree_;
// KLineEdit *watchVarEntry_;
friend class VariableTree;
KHistoryCombo *watchVarEditor_;
};
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
class VariableTree : public TDEListView, public TQToolTip
{
Q_OBJECT
public:
VariableTree(VariableWidget *parent,
GDBController* controller,
GDBBreakpointWidget* breakpointWidget,
const char *name=0 );
virtual ~VariableTree();
TQListViewItem *lastChild() const;
TQListViewItem *findRoot(TQListViewItem *item) const;
VarFrameRoot *findFrame(int frameNo, int threadNo) const;
WatchRoot *findWatch();
// (from TQToolTip) Display a tooltip when the cursor is over an item
virtual void maybeTip(const TQPoint &);
GDBController* controller() const { return controller_; }
signals:
void toggleWatchpoint(const TQString &varName);
public slots:
void slotAddWatchVariable(const TQString& watchVar);
void slotEvaluateExpression(const TQString& expression);
void slotEvent(GDBController::event_t);
void slotItemRenamed(TQListViewItem* item, int col, const TQString& text);
private slots:
void slotContextMenu(TDEListView *, TQListViewItem *item);
void slotVarobjNameChanged(const TQString& from, const TQString& to);
private: // Callbacks for gdb commands;
void argumentsReady(const GDBMI::ResultRecord&);
void localsReady(const GDBMI::ResultRecord&);
void frameIdReady(const TQValueVector<TQString>&);
void handleVarUpdate(const GDBMI::ResultRecord&);
void handleEvaluateExpression(const TQValueVector<TQString>&);
void variablesFetchDone();
void fetchSpecialValuesDone();
/** This is called when address of expression for which
popup is created is known.
If there's no address (for rvalue), does nothing
(leaving "Data breakpoint" item disabled).
Otherwise, enabled that item, and check is we
have data breakpoint for that address already.
*/
void handleAddressComputed(const GDBMI::ResultRecord& r);
private: // helper functions
/** Get (if exists) and create (otherwise) frame root for
the specified frameNo/threadNo combination.
*/
VarFrameRoot* demand_frame_root(int frameNo, int threadNo);
void updateCurrentFrame();
/** Copies the value (second column) of the specified item to
the clipboard.
*/
void copyToClipboard(TQListViewItem*);
private: // TQWidget overrides
void keyPressEvent(TQKeyEvent* e);
private:
GDBController* controller_;
GDBBreakpointWidget* breakpointWidget_;
int activeFlag_;
int iOutRadix;
bool justPaused_;
// Root of all recently printed expressions.
TrimmableItem* recentExpressions_;
VarFrameRoot* currentFrameItem;
TQTime fetch_time;
// Names of locals and arguments as reported by
// gdb.
std::vector<TQString> locals_and_arguments;
TQMap<TQString, VarItem*> varobj2varitem;
TDEPopupMenu* activePopup_;
static const int idToggleWatch = 10;
friend class VarFrameRoot;
friend class VarItem;
friend class WatchRoot;
};
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/** List view item that can 'trim' outdated children.
The instances of this class hold a number of children corresponding
to variables. When program state changes, such as after a step in source,
some variable values can change, and some variables can go out of scope.
We need
- highlight modified variables
- remove gone variables
We could just remove all children and repopulate the list from
the data from debugger, but then we'd loose information about previous
variable values.
So, we first update the values, highlighting the modified variables, and
keeping track which variables were recieved from gdb. After that, the
'trim' method is called, removing all variables which were not recieved
from gdbr.
*/
class TrimmableItem : public TDEListViewItem
{
public:
TrimmableItem(VariableTree *parent);
TrimmableItem(TrimmableItem *parent);
virtual ~TrimmableItem();
TQListViewItem *lastChild() const;
protected:
void paintCell( TQPainter *p, const TQColorGroup &cg,
int column, int width, int align );
};
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
class VarItem : public TQObject,
public TrimmableItem
{
Q_OBJECT
public:
enum format_t { natural, hexadecimal, decimal, character, binary };
/** Creates top-level variable item from the specified expression.
Optionally, alternative display name can be provided.
*/
VarItem( TrimmableItem *parent,
const TQString& expression,
bool frozen = false);
VarItem( TrimmableItem *parent, const GDBMI::Value& varobj,
format_t format, bool baseClassMember);
virtual ~VarItem();
/// Returns the gdb expression for *this.
TQString gdbExpression() const;
/** Returns true is this VarItem should be unconditionally
updated on each step, not matter what's the result of
-var-update command.
*/
bool updateUnconditionally() const;
void updateValue();
void updateSpecialRepresentation(const TQString& s);
/** Creates a fresh gdbs "variable object", if needed.
Preconditions:
- frame id did not change
- this is a root variable
If the current type of expression, or it's address, it different
from it was previously, creates new "variable object" and
fetches new value.
Otherwise, does nothing.
*/
void recreateLocallyMaybe();
/** Tries to create new gdb variable object for this expression.
If successfull, updates all values. Otherwise, makes
itself disabled.
*/
void recreate();
void setOpen(bool open);
void setText (int column, const TQString& text);
/** Mark the variable as alive, or not alive.
Variables that are not alive a shown as "gray",
and nothing can be done about them except for
removing. */
void setAliveRecursively(bool enable);
/** Recursively clears the varobjName_ field, making
*this completely disconnected from gdb.
Automatically makes *this and children disables,
since there's no possible interaction with unhooked
object.
*/
void unhookFromGdb();
// Returns the text to be displayed as tooltip (the value)
TQString tipText() const;
format_t format() const;
void setFormat(format_t f);
format_t formatFromGdbModifier(char c) const;
/** Clears highliting for this variable and
all its children. */
void clearHighlight();
/** Sets new top-level textual value of this variable.
*/
void setValue(const TQString& new_value);
bool isAlive() const;
signals:
/** Emitted whenever the name of varobj associated with *this changes:
- when we've created initial varobj
- when we've changed varobj name as part of 'recreate' method
- when *this is destroyed and no longer uses any varobj.
Either 'from' or 'to' can be empty string.
*/
void varobjNameChange(const TQString& from, const TQString& to);
private:
/** Creates new gdb "variable object". The controller_,
expression_ and format_ member variables should already
be set.
*/
void createVarobj();
/** Precondition: 'name' is a name of existing
gdb variable object.
Effects:
- sets varobjName_ to 'name'
- sets format, if it's not default one
- gets initial value
- if item is open, gets children.
*/
void setVarobjName(const TQString& name);
/** Handle types that require special dispay, such as
TQString. Return true if this is such a type.
The 'originalValueType_' is already initialized
by the time this method is called.
*/
bool handleSpecialTypes();
void paintCell( TQPainter *p, const TQColorGroup &cg,
int column, int width, int align );
void varobjCreated(const GDBMI::ResultRecord& r);
void valueDone(const GDBMI::ResultRecord& r);
void childrenDone(const GDBMI::ResultRecord& r);
void childrenOfFakesDone(const GDBMI::ResultRecord& r);
void handleCurrentAddress(const TQValueVector<TQString>& lines);
void handleType(const TQValueVector<TQString>& lines);
void createChildren(const GDBMI::ResultRecord& r, bool children_of_fake);
/** Called to handle the output of the cli print command.
*/
void handleCliPrint(const TQValueVector<TQString>& lines);
// Assuming 'expression_' is already set, returns the
// displayName to use when showing this to the user.
// This function exists because if we have item with
// gdb expression '$1' and displayName 'P4', we want the child
// to show up as *P4, not as '*$1', so we can't uncondionally
// use expression gdb reports to us.
TQString displayName() const;
VariableTree* varTree() const;
TQString varobjFormatName() const;
private:
// The gdb expression for this varItem relatively to
// parent VarItem.
TQString expression_;
bool highlight_;
GDBController* controller_;
TQString varobjName_;
// the non-cast type of the variable
TQString originalValueType_;
bool oldSpecialRepresentationSet_;
TQString oldSpecialRepresentation_;
format_t format_;
static int varobjIndex;
int numChildren_;
bool childrenFetched_;
TQString currentAddress_;
TQString lastObtainedAddress_;
bool updateUnconditionally_;
bool frozen_;
/* Set to true whan calling createVarobj for the
first time, and to false other time. */
bool initialCreation_;
/* Set if this VarItem corresponds to base class suboject. */
bool baseClassMember_;
bool alive_;
};
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
class VarFrameRoot : public TrimmableItem
{
public:
VarFrameRoot(VariableTree *parent, int frameNo, int threadNo);
virtual ~VarFrameRoot();
void setOpen(bool open);
// Marks the frame as dirty, that is as having
// out of date values. As soon as we try to open
// this item, it will fetch new data.
void setDirty();
void setFrameName(const TQString &frameName)
{ setText(VarNameCol, frameName); setText(ValueCol, ""); }
bool needLocals() const { return needLocals_; }
bool matchDetails(int frameNo, int threadNo);
private:
bool needLocals_;
int frameNo_;
int threadNo_;
// Frame base and code address of the current inner-most
// frame. Needed so that if we can know when 'frame N' no longer
// is the same as 'frame N' when this 'VarFrameRoot' was created.
unsigned long long currentFrameBase;
unsigned long long currentFrameCodeAddress;
friend class VariableTree;
};
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
class WatchRoot : public TrimmableItem
{
public:
WatchRoot(VariableTree *parent);
virtual ~WatchRoot();
};
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
}
#endif
|