My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
import gdb.printing
import re

# just for debugging purposes
def dump(obj):
'''return a printable representation of an object for debugging'''
newobj=obj
if '__dict__' in dir(obj):
newobj=obj.__dict__
if ' object at ' in str(obj) and not newobj.has_key('__type__'):
newobj['__type__']=str(obj)
for attr in newobj:
newobj[attr]=dump(newobj[attr])
return newobj

# Upp::String printer
class UppStringPrinter(object):
"Print an Upp::String"

def __init__(self, val):
self.val = val

def to_string(self):
try:
SMALL = 0
MEDIUM = 31
KIND = 14
SLEN = 15
LLEN = 2
CHR = self.val['chr']
IsSmall = (CHR[KIND] == SMALL)
if(IsSmall):
ptr = CHR
else:
ptr = self.val['ptr']
return '"' + ptr.string() + '"'
except Exception as inst:
return "<can't read string>"

def display_hint(self):
return 'String'

# Upp::String* printer
class UppStringPtrPrinter(object):
"Print an Upp::String *"

def __init__(self, val):
self.val = val

def to_string(self):
return '@' + str(self.val.address) + ': ' + UppStringPrinter(self.val).to_string()

def display_hint(self):
return 'String'

# Upp::Vector printer
class UppVectorPrinter(object):
"Print an Upp::Vector"
class _iterator:
def __init__ (self, val):
self.val = val
self.item = val['vector']
self.finish = self.item + val['items']
self.count = 0

def __iter__(self):
return self

def next(self):
count = self.count
self.count = self.count + 1
if count == 0:
return ('.items', self.val['items'])
if count == 1:
return ('.alloc', self.val['alloc'])
if self.item == self.finish:
raise StopIteration
elt = self.item.dereference()
self.item = self.item + 1
return ('[%d]' % (count-2), elt)

def __init__(self, typename, val):
self.typename = typename
self.val = val

def children(self):
return self._iterator(self.val)

def to_string(self):
start = 0
finish = self.val['items']
end = self.val['alloc']
return ('%s count %d alloc %d'
% (self.typename, int (finish - start), int (end - start)))

def display_hint(self):
return 'array'

# Upp::Array printer
class UppArrayPrinter(object):
"Print an Upp::Array"
class _iterator:
def __init__ (self, val):
self.val = val['vector']
self.item = self.val['vector']
self.finish = self.item + self.val['items']
self.count = 0

def __iter__(self):
return self

def next(self):
count = self.count
self.count = self.count + 1
if count == 0:
return ('.items', self.val['items'])
if count == 1:
return ('.alloc', self.val['alloc'])
if self.item == self.finish:
raise StopIteration
elt = self.item.dereference().dereference()
self.item = self.item + 1
return ('[%d]' % (count-2), elt)

def __init__(self, typename, val):
self.typename = typename
self.val = val

def children(self):
return self._iterator(self.val)

def to_string(self):
start = 0
finish = self.val['vector']['items']
end = self.val['vector']['alloc']
return ('%s count %d alloc %d'
% (self.typename, int (finish - start), int (end - start)))

def display_hint(self):
return 'array'

# Upp::VectorMap and ArrayMap printer
class UppMapPrinter(object):
"Print an Upp::VectorMap or ArrayMap"

def __init__(self, typename, val):
self.typename = typename
self.val = val

def children(self):
return [('.keys', self.val['key']), ('.values', self.val['value'])].__iter__()

def to_string(self):
count = self.val['key']['key']['items']
alloc = self.val['key']['key']['alloc']
return ('%s count %d alloc %d'
% (self.typename, count, alloc))

def display_hint(self):
return 'array'

# Upp::Value printer
class UppValuePrinter(object):

def __init__(self, val):
self.typeIds ={
0:'void',
1:'int',
2:'double',
3:'Upp::String',
4:'Upp::Date',
5:'Upp::Time',
6:'ERROR',
7:'Upp::Value',
8:'Upp::WString',
9:'Upp::ValueArray',
10:'int64',
11:'bool',
12:'Upp::ValueMap'
}
self.val = val

def to_string(self):
try:
magic = self.val['magic']
except Exception as inst:
return '<value inspectors not supported>'
if magic[0] != 0xc436d851 or magic[1] != 0x72f67c76 or magic[2] != 0x3e5e10fd or magic[3] != 0xc90d370b:
return '<value not initialized>'
typeId = Upp_Value_GetType(self.val)
if typeId == 0:
return '<void>'
elif typeId in (1, 2, 3, 4, 5, 7, 8, 10, 11):
return str(Upp_Value_GetString(self.val))
elif typeId == 6:
return '<ERROR VALUE>'
else:
strVal = str(Upp_Value_GetString(self.val))
if strVal != '':
return strVal
else:
if self.typeIds.has_key(typeId):
return "<unsupported value type '" + self.typeIds[typeId] + "'>"
else:
return "<unsupported value type '" + str(typeId) + "'>"

# Upp::Value* printer
class UppValuePtrPrinter(object):
"Print an Upp::Value *"

def __init__(self, val):
self.val = val

def to_string(self):
return '@' + str(self.val.address) + ': ' + UppValuePrinter(self.val.dereference()).to_string()

def display_hint(self):
return 'String'

# Upp::One<> printer
class UppOnePrinter(object):

def __init__(self, val):
self.val = val

def to_string(self):
return str(self.val['ptr'].dereference())

# Upp::Point printer
class UppPointPrinter(object):
"Print an Upp::Point"

def __init__(self, val):
self.val = val

def to_string(self):
return '(' + str(self.val['x']) + ',' + str(self.val['y']) + ')'

# Upp::Point* printer
class UppPointPtrPrinter(object):
"Print an Upp::Point *"

def __init__(self, val):
self.val = val

def to_string(self):
return '@' + str(self.val.address) + ': ' + UppPointPrinter(self.val).to_string()

# Upp::Size printer
class UppSizePrinter(object):
"Print an Upp::Size"

def __init__(self, val):
self.val = val

def to_string(self):
return '(' + str(self.val['cx']) + ',' + str(self.val['cy']) + ')'

# Upp::Size* printer
class UppSizePtrPrinter(object):
"Print an Upp::Size *"

def __init__(self, val):
self.val = val

def to_string(self):
return '@' + str(self.val.address) + ': ' + UppSizePrinter(self.val).to_string()

# Upp::Rect printer
class UppRectPrinter(object):
"Print an Upp::Rect"

def __init__(self, val):
self.val = val

def to_string(self):
return '[' + str(self.val['left']) + ',' + str(self.val['top']) + '],[' + str(self.val['right']) + ',' + str(self.val['bottom']) + ']'

# Upp::Rect* printer
class UppRectPtrPrinter(object):
"Print an Upp::Rect *"

def __init__(self, val):
self.val = val

def to_string(self):
return '@' + str(self.val.address) + ': ' + UppRectPrinter(self.val).to_string()

def UppLookupFunction(val):
typeStr = str(val.type)

if typeStr == 'Upp::String *':
return UppStringPtrPrinter(val)

if typeStr == 'const Upp::String *':
return UppStringPtrPrinter(val)

if typeStr == 'Upp::String &':
return UppStringPtrPrinter(val.address)

if typeStr == 'const Upp::String &':
return UppStringPtrPrinter(val.address)

if typeStr == 'Upp::String':
return UppStringPrinter(val)

if typeStr == 'const Upp::String':
return UppStringPrinter(val)

##########################################################################
# FOR VALUES -- EXPERIMENTAL
if typeStr == 'Upp::Value *' and Upp_Value_Inspectors:
return UppValuePtrPrinter(val)

if typeStr == 'const Upp::Value *' and Upp_Value_Inspectors:
return UppValuePtrPrinter(val)

if typeStr == 'Upp::Value &' and Upp_Value_Inspectors:
return UppValuePtrPrinter(val.address)

if typeStr == 'const Upp::Value &' and Upp_Value_Inspectors:
return UppValuePtrPrinter(val.address)

if typeStr == 'Upp::Value' and Upp_Value_Inspectors:
return UppValuePrinter(val)

if typeStr == 'const Upp::Value' and Upp_Value_Inspectors:
return UppValuePrinter(val)

##########################################################################
if typeStr == 'Upp::Point' or typeStr == 'Upp::Pointf':
return UppPointPrinter(val)

if typeStr == 'const Upp::Point' or typeStr == 'const Upp::Pointf':
return UppPointPrinter(val)

if typeStr == 'Upp::Point *' or typeStr == 'Upp::Pointf *':
return UppPointPtrPrinter(val)

if typeStr == 'const Upp::Point *' or typeStr == 'const Upp::Pointf *':
return UppPointPtrPrinter(val)

if typeStr == 'Upp::Size' or typeStr == 'Upp::Sizef':
return UppSizePrinter(val)

if typeStr == 'const Upp::Size' or typeStr == 'const Upp::Sizef':
return UppSizePrinter(val)

if typeStr == 'Upp::Size *' or typeStr == 'Upp::Sizef *':
return UppSizePtrPrinter(val)

if typeStr == 'const Upp::Size *' or typeStr == 'const Upp::Sizef *':
return UppSizePtrPrinter(val)

if typeStr == 'Upp::Rect' or typeStr == 'Upp::Rectf':
return UppRectPrinter(val)

if typeStr == 'const Upp::Rect' or typeStr == 'const Upp::Rectf':
return UppRectPrinter(val)

if typeStr == 'Upp::Rect *' or typeStr == 'Upp::Rectf *':
return UppRectPtrPrinter(val)

if typeStr == 'const Upp::Rect *' or typeStr == 'const Upp::Rectf *':
return UppRectPtrPrinter(val)

lookup_tag = val.type.tag
if lookup_tag == None:
return None

regex = re.compile("^Upp::VectorMap<.*>$")
if regex.match(lookup_tag):
return UppMapPrinter(lookup_tag, val)

regex = re.compile("^Upp::ArrayMap<.*>$")
if regex.match(lookup_tag):
return UppMapPrinter(lookup_tag, val)

regex = re.compile("^Upp::Vector<.*>$")
if regex.match(lookup_tag):
return UppVectorPrinter(lookup_tag, val)

regex = re.compile("^Upp::Array<.*>$")
if regex.match(lookup_tag):
return UppArrayPrinter(lookup_tag, val)

regex = re.compile("^Upp::Index<.*>$")
if regex.match(lookup_tag):
return UppVectorPrinter(lookup_tag, val['key'])

regex = re.compile("^Upp::One<.*>$")
if regex.match(lookup_tag):
return UppOnePrinter(val)

return None

#check if Upp value inspecting support is enabled
Upp_Value_Inspectors = True
try:
Upp_Value_GetType = gdb.parse_and_eval('Upp::_DBG_Value_GetType')
Upp_Value_GetString = gdb.parse_and_eval('Upp::_DBG_Value_AsString')
except Exception as inst:
Upp_Value_Inspectors = False

#check if debug ungrab support is enabled
Upp_Ungrab_Support = True
try:
Upp_Ungrab = gdb.parse_and_eval('Upp::_DBG_Ungrab')
except Exception as inst:
Upp_Ungrab_Support = False

#ungrab mouse at debugger stop, if ungrab helper is available
def stop_handler(event):
if Upp_Ungrab_Support:
Upp_Ungrab()

gdb.events.stop.connect (stop_handler)


gdb.pretty_printers.append(UppLookupFunction)

#a couple of lines to test it quickly on gdb....
#source /home/massimo/sources/upp-svn/uppsrc/ide/Debuggers/PrettyPrinters.py
#python gdb.pretty_printers.remove(UppLookupFunction)

Change log

r4978 by micio on May 20 (5 days ago)   Diff
Ide/Debuggers/Gdb_MI2 : adapted python
Value inspectors to Core changes
Go to: 
Project members, sign in to write a code review

Older revisions

r4965 by micio on May 17, 2012   Diff
Ide/Debuggers/Gdb_MI2 : python side of
safe Value inspectors
r4953 by micio on May 14, 2012   Diff
Ide/Debuggers/Gdb_MI2 : added
workaround for X11 mouse grabbing
problem
Needs support in Upp CtrlCore
r4880 by micio on Apr 29, 2012   Diff
Ide/Debuggers/Gdb_MI2 : fixed pretty
printers for const variants of point,
rect and size
All revisions of this file

File info

Size: 10641 bytes, 424 lines
Powered by Google Project Hosting