-
Notifications
You must be signed in to change notification settings - Fork 396
/
Copy pathlldb_formatters.py
389 lines (307 loc) · 12.8 KB
/
lldb_formatters.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
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
# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
import lldb
# HACK: LLDB's python API doesn't afford anything helpful for getting at variadic template parameters.
# We're forced to resort to parsing names as strings.
def templateParams(s):
depth = 0
start = s.find("<") + 1
result = []
for i, c in enumerate(s[start:], start):
if c == "<":
depth += 1
elif c == ">":
if depth == 0:
result.append(s[start:i].strip())
break
depth -= 1
elif c == "," and depth == 0:
result.append(s[start:i].strip())
start = i + 1
return result
def getType(target, typeName):
stars = 0
typeName = typeName.strip()
while typeName.endswith("*"):
stars += 1
typeName = typeName[:-1]
if typeName.startswith("const "):
typeName = typeName[6:]
ty = target.FindFirstType(typeName.strip())
for _ in range(stars):
ty = ty.GetPointerType()
return ty
def luau_variant_summary(valobj, internal_dict, options):
return valobj.GetChildMemberWithName("type").GetSummary()[1:-1]
class LuauVariantSyntheticChildrenProvider:
node_names = ["type", "value"]
def __init__(self, valobj, internal_dict):
self.valobj = valobj
self.type_index = None
self.current_type = None
self.type_params = []
self.stored_value = None
def num_children(self):
return len(self.node_names)
def has_children(self):
return True
def get_child_index(self, name):
try:
return self.node_names.index(name)
except ValueError:
return -1
def get_child_at_index(self, index):
try:
node = self.node_names[index]
except IndexError:
return None
if node == "type":
if self.current_type:
return self.valobj.CreateValueFromExpression(
node, f'(const char*)"{self.current_type.GetDisplayTypeName()}"'
)
else:
return self.valobj.CreateValueFromExpression(
node, '(const char*)"<unknown type>"'
)
elif node == "value":
if self.stored_value is not None:
if self.current_type is not None:
return self.valobj.CreateValueFromData(
node, self.stored_value.GetData(), self.current_type
)
else:
return self.valobj.CreateValueExpression(
node, '(const char*)"<unknown type>"'
)
else:
return self.valobj.CreateValueFromExpression(
node, '(const char*)"<no stored value>"'
)
else:
return None
def update(self):
self.type_index = self.valobj.GetChildMemberWithName(
"typeId"
).GetValueAsSigned()
self.type_params = templateParams(
self.valobj.GetType().GetCanonicalType().GetName()
)
if len(self.type_params) > self.type_index:
self.current_type = getType(
self.valobj.GetTarget(), self.type_params[self.type_index]
)
if self.current_type:
storage = self.valobj.GetChildMemberWithName("storage")
self.stored_value = storage.Cast(self.current_type)
else:
self.stored_value = None
else:
self.current_type = None
self.stored_value = None
return False
class DenseHashTableSyntheticChildrenProvider:
def __init__(self, valobj, internal_dict):
"""this call should initialize the Python object using valobj as the variable to provide synthetic children for"""
self.valobj = valobj
self.update()
def num_children(self):
"""this call should return the number of children that you want your object to have"""
return self.capacity
def get_child_index(self, name):
"""this call should return the index of the synthetic child whose name is given as argument"""
try:
if name.startswith("[") and name.endswith("]"):
return int(name[1:-1])
else:
return -1
except Exception as e:
print("get_child_index exception", e)
return -1
def get_child_at_index(self, index):
"""this call should return a new LLDB SBValue object representing the child at the index given as argument"""
try:
dataMember = self.valobj.GetChildMemberWithName("data")
data = dataMember.GetPointeeData(index)
return self.valobj.CreateValueFromData(
f"[{index}]",
data,
dataMember.Dereference().GetType(),
)
except Exception as e:
print("get_child_at_index error", e)
def update(self):
"""this call should be used to update the internal state of this Python object whenever the state of the variables in LLDB changes.[1]
Also, this method is invoked before any other method in the interface."""
self.capacity = self.valobj.GetChildMemberWithName(
"capacity"
).GetValueAsUnsigned()
def has_children(self):
"""this call should return True if this object might have children, and False if this object can be guaranteed not to have children.[2]"""
return True
class DenseHashMapSyntheticChildrenProvider:
fixed_names = ["count", "capacity"]
max_expand_children = 100
max_expand_capacity = 1000
def __init__(self, valobj, internal_dict):
self.valobj = valobj
self.count = 0
self.capacity = 0
def num_children(self):
return min(self.max_expand_children, self.count) + len(self.fixed_names)
def get_child_index(self, name):
try:
if name in self.fixed_names:
return self.fixed_names.index(name)
return -1
except Exception as e:
print("get_child_index exception", e, name)
return -1
def get_child_at_index(self, index):
try:
if index < len(self.fixed_names):
fixed_name = self.fixed_names[index]
impl_child = self.valobj.GetValueForExpressionPath(
f".impl.{fixed_name}")
return self.valobj.CreateValueFromData(fixed_name, impl_child.GetData(), impl_child.GetType())
else:
index -= len(self.fixed_names)
empty_key_valobj = self.valobj.GetValueForExpressionPath(
f".impl.empty_key")
key_type = empty_key_valobj.GetType().GetCanonicalType().GetName()
skipped = 0
for slot in range(0, min(self.max_expand_capacity, self.capacity)):
slot_pair = self.valobj.GetValueForExpressionPath(
f".impl.data[{slot}]")
slot_key_valobj = slot_pair.GetChildMemberWithName("first")
eq_test_valobj = self.valobj.EvaluateExpression(
f"*(reinterpret_cast<const {key_type}*>({empty_key_valobj.AddressOf().GetValueAsUnsigned()})) == *(reinterpret_cast<const {key_type}*>({slot_key_valobj.AddressOf().GetValueAsUnsigned()}))")
if eq_test_valobj.GetValue() == "true":
continue
# Skip over previous occupied slots.
if index > skipped:
skipped += 1
continue
return self.valobj.CreateValueFromData(f"[{index}]", slot_pair.GetData(), slot_pair.GetType())
except Exception as e:
print("get_child_at_index error", e, index)
def update(self):
try:
self.capacity = self.count = self.valobj.GetValueForExpressionPath(
".impl.capacity").GetValueAsUnsigned()
self.count = self.valobj.GetValueForExpressionPath(
".impl.count").GetValueAsUnsigned()
except Exception as e:
print("update error", e)
def has_children(self):
return True
class DenseHashSetSyntheticChildrenProvider:
fixed_names = ["count", "capacity"]
max_expand_children = 100
max_expand_capacity = 1000
def __init__(self, valobj, internal_dict):
self.valobj = valobj
self.count = 0
self.capacity = 0
def num_children(self):
return min(self.max_expand_children, self.count) + len(self.fixed_names)
def get_child_index(self, name):
try:
if name in self.fixed_names:
return self.fixed_names.index(name)
return -1
except Exception as e:
print("get_child_index exception", e, name)
return -1
def get_child_at_index(self, index):
try:
if index < len(self.fixed_names):
fixed_name = self.fixed_names[index]
impl_child = self.valobj.GetValueForExpressionPath(
f".impl.{fixed_name}")
return self.valobj.CreateValueFromData(fixed_name, impl_child.GetData(), impl_child.GetType())
else:
index -= len(self.fixed_names)
empty_key_valobj = self.valobj.GetValueForExpressionPath(
f".impl.empty_key")
key_type = empty_key_valobj.GetType().GetCanonicalType().GetName()
skipped = 0
for slot in range(0, min(self.max_expand_capacity, self.capacity)):
slot_valobj = self.valobj.GetValueForExpressionPath(
f".impl.data[{slot}]")
eq_test_valobj = self.valobj.EvaluateExpression(
f"*(reinterpret_cast<const {key_type}*>({empty_key_valobj.AddressOf().GetValueAsUnsigned()})) == *(reinterpret_cast<const {key_type}*>({slot_valobj.AddressOf().GetValueAsUnsigned()}))")
if eq_test_valobj.GetValue() == "true":
continue
# Skip over previous occupied slots.
if index > skipped:
skipped += 1
continue
return self.valobj.CreateValueFromData(f"[{index}]", slot_valobj.GetData(), slot_valobj.GetType())
except Exception as e:
print("get_child_at_index error", e, index)
def update(self):
try:
self.capacity = self.count = self.valobj.GetValueForExpressionPath(
".impl.capacity").GetValueAsUnsigned()
self.count = self.valobj.GetValueForExpressionPath(
".impl.count").GetValueAsUnsigned()
except Exception as e:
print("update error", e)
def has_children(self):
return True
def luau_symbol_summary(valobj, internal_dict, options):
local = valobj.GetChildMemberWithName("local")
global_ = valobj.GetChildMemberWithName(
"global").GetChildMemberWithName("value")
if local.GetValueAsUnsigned() != 0:
return f'local {local.GetChildMemberWithName("name").GetChildMemberWithName("value").GetSummary()}'
elif global_.GetValueAsUnsigned() != 0:
return f"global {global_.GetSummary()}"
else:
return "???"
class AstArraySyntheticChildrenProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
def num_children(self):
return self.size
def get_child_index(self, name):
try:
if name.startswith("[") and name.endswith("]"):
return int(name[1:-1])
else:
return -1
except Exception as e:
print("get_child_index error:", e)
def get_child_at_index(self, index):
try:
dataMember = self.valobj.GetChildMemberWithName("data")
data = dataMember.GetPointeeData(index)
return self.valobj.CreateValueFromData(
f"[{index}]", data, dataMember.Dereference().GetType()
)
except Exception as e:
print("get_child_index error:", e)
def update(self):
self.size = self.valobj.GetChildMemberWithName(
"size").GetValueAsUnsigned()
def has_children(self):
return True
def luau_typepath_property_summary(valobj, internal_dict, options):
name = valobj.GetChildMemberWithName("name").GetSummary()
result = "["
read_write = False
try:
fflag_valobj = valobj.GetFrame().GetValueForVariablePath(
"FFlag::LuauSolverV2::value")
read_write = fflag_valobj.GetValue() == "true"
except Exception as e:
print("luau_typepath_property_summary error:", e)
if read_write:
is_read = valobj.GetChildMemberWithName("isRead").GetValue() == "true"
if is_read:
result += "read "
else:
result += "write "
result += name
result += "]"
return result