forked from ayuckhulk/lldb-qt-formatters
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQtFormatters.py
144 lines (128 loc) · 5.93 KB
/
QtFormatters.py
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
import lldb
import sys
import traceback
def __lldb_init_module(debugger, unused):
# types created through the Python code
debugger.HandleCommand('type summary add -x "^QUrl$" -e -F QtFormatters.QUrl_SummaryProvider')
debugger.HandleCommand('type summary add -x "^QString$" -e -F QtFormatters.QString_SummaryProvider')
debugger.HandleCommand('type synthetic add -x "^QList<.+>$" -l QtFormatters.QList_SyntheticProvider')
debugger.HandleCommand('type summary add -x "^QList<.+>$" -e -s "size=${svar%#}"')
debugger.HandleCommand('type synthetic add -x "^QPointer<.+>$" -l QtFormatters.QPointer_SyntheticProvider')
debugger.HandleCommand('type summary add -x "^QPointer<.+>$" -e -s "filled="${svar%#}"')
# summary only types
debugger.HandleCommand('type summary add --summary-string "(w=${var.wd}, h=${var.ht})" QSize')
debugger.HandleCommand('type summary add --summary-string "(w=${var.wd}, h=${var.ht})" QSizeF')
debugger.HandleCommand('type summary add --summary-string "(x=${var.xp}, y=${var.yp})" QPoint')
debugger.HandleCommand('type summary add --summary-string "(x=${var.xp}, y=${var.yp})" QPointF')
debugger.HandleCommand('type summary add --summary-string "(x1=${var.x1}, y1=${var.y1}), size=(w=${var.x2}, h=${var.y2})" QRect')
debugger.HandleCommand('type summary add --summary-string "(xp=${var.xp}, yp=${var.yp}), size=(w=${var.w},h=${var.h})" QRectF')
debugger.HandleCommand('type summary add --summary-string "\{${var.data1%x} - ${var.data2%x} - ${var.data3%x} - ${var.data4[0-7]%x}\}" QUuid')
def printException():
eInfo = sys.exc_info()
print ("Exception:")
print (traceback.print_tb(eInfo[2], 1))
print (eInfo[0], eInfo[1] )
return
def QString_SummaryProvider(valobj, internal_dict):
def make_string_from_pointer_with_offset(F,OFFS,L):
strval = '"'
try:
data_array = F.GetPointeeData(0, L).uint16
for X in range(OFFS, L):
V = data_array[X]
if V == 0:
break
strval += chr(V)
# Ignore index error because if you set breakpoint on a line that constructs a QString
# it has not yet been defined and you end up with an IndexError unable to read data_array
except(IndexError):
pass
except:
printException()
pass
strval = strval + '"'
return strval
#qt5
def qstring_summary(value):
try:
d = value.GetChildMemberWithName('d')
ptr = d.GetChildMemberWithName('ptr')
size = get_max_size(value)
return make_string_from_pointer_with_offset(ptr, 0, size)
except:
printException()
return value
def get_max_size(value):
_max_size_ = None
try:
debugger = value.GetTarget().GetDebugger()
_max_size_ = int(lldb.SBDebugger.GetInternalVariableValue('target.max-string-summary-length', debugger.GetInstanceName()).GetStringAtIndex(0))
except:
_max_size_ = 512
return _max_size_
return qstring_summary(valobj)
def QUrl_SummaryProvider(valobj, internal_dict):
return QString_SummaryProvider(valobj.GetFrame().EvaluateExpression(valobj.GetName() + '.toString(QUrl::ComponentFormattingOption::PrettyDecoded)'), None)
class QList_SyntheticProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
def num_children(self):
result = 0
try:
# d is a QArrayDataPointer, which in turn contains:
# d (QTypedArrayData*)
# ptr (pointer into d's data)
# size (actual number of elements)
# If the QTypedArrayData is null, the other two may be uninitialized/garbage.
d = self.valobj.GetChildMemberWithName('d')
if d.GetChildMemberWithName('d').GetValueAsUnsigned() != 0:
result = d.GetChildMemberWithName('size').GetValueAsUnsigned()
finally:
return result
def get_child_index(self,name):
try:
return int(name.lstrip('[').rstrip(']'))
except:
return None
def get_child_at_index(self,index):
if index < 0:
return None
if index >= self.num_children():
return None
if self.valobj.IsValid() == False:
return None
try:
ptr = self.valobj.GetChildMemberWithName('d').GetChildMemberWithName('ptr')
type = self.valobj.GetType().GetTemplateArgumentType(0)
elementSize = type.GetByteSize()
return ptr.CreateChildAtOffset('[' + str(index) + ']', index * elementSize, type)
except:
return None
class QPointer_SyntheticProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
def num_children(self):
try:
wp = self.valobj.GetChildMemberWithName('wp')
d = wp.GetChildMemberWithName('d')
if d.GetValueAsUnsigned() == 0 or d.GetChildMemberWithName('strongref').GetChildMemberWithName('_q_value').GetValueAsUnsigned() == 0 or wp.GetChildMemberWithName('value').GetValueAsUnsigned() == 0:
return 0
else:
return 1
except:
return 0
def get_child_index(self,name):
return 0
def get_child_at_index(self,index):
if index < 0:
return None
if index >= self.num_children():
return None
if self.valobj.IsValid() == False:
return None
try:
type = self.valobj.GetType().GetTemplateArgumentType(0)
return self.valobj.GetChildMemberWithName('wp').GetChildMemberWithName('value').CreateChildAtOffset('value', 0, type)
except:
printException()
return None