-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpl.py
108 lines (72 loc) · 3.03 KB
/
pl.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
"""
for docs, see:
https://lldb.llvm.org/use/variable.html
"""
from __future__ import print_function, division
import lldb
class PLUnionProvider(object):
def __init__(self, valobj:lldb.SBValue, dict={}):
self.valobj = valobj
def update(self):
return True
def has_children(self):
return True
def num_children(self):
return 1
def get_child_at_index(self, index):
# if index > 0:
# return None
tag = self.valobj.GetChildAtIndex(0).GetValueAsUnsigned(0)
child = self.valobj.GetChildAtIndex(1).GetChildAtIndex(tag)
return child
def get_child_index(self, name):
return 0
# class PLHashTableProvider(object):
# def __init__(self, valobj:lldb.SBValue, dict={}):
# self.valobj = valobj
# def update(self):
# return True
# def has_children(self):
# return True
# def num_children(self):
# return self.valobj.GetChildAtIndex(3).GetValueAsUnsigned(0)
# def get_child_at_index(self, index):
# # if index > 0:
# # return None
# # tag = self.valobj.GetChildAtIndex(0).GetValueAsUnsigned(0)
# # child = self.valobj.GetChildAtIndex(1).GetChildAtIndex(tag)
# return self.valobj.GetChildAtIndex(1)
# def get_child_index(self, name):
# return 0
class PLArrayProvider(object):
def __init__(self, valobj:lldb.SBValue, dict={}):
self.valobj = valobj
def update(self):
return True
def has_children(self):
return True
def num_children(self):
return self.valobj.GetChildAtIndex(2).GetValueAsUnsigned(0)
def get_child_at_index(self, index):
arr = self.valobj.GetChildMemberWithName('_arr')
if index == 0:
return arr.CreateChildAtOffset("[0]", 0, arr.type.GetPointeeType())
"""
lldb will auto dereference the pointer before get child if the pointee type is not a primitive
so we may not use `GetChildAtIndex` here to get the array element
"""
bytes = lldb.SBType(self.valobj.GetChildMemberWithName('_arr').type.GetPointeeType()).GetByteSize()
return arr.CreateChildAtOffset("[{}]".format(index), index*bytes, arr.type.GetPointeeType())
def get_child_index(self, name):
return -1
def get_summary(valobj:lldb.SBValue,internal_dict,options):
if "NULL" in valobj.__str__():
return '<null>'
s = '{}(Union type)'.format(valobj.type.name.split("::")[1])
return s
def __lldb_init_module(debugger, dict):
debugger.HandleCommand('type summary add -F pl.get_summary -x union::[:<.>,\|]*')
# debugger.HandleCommand('type summary add --summary-string "HashTable" -x HashTable[:<.>,\|]*')
# debugger.HandleCommand('type synthetic add --python-class pl.PLHashTableProvider -x HashTable[:<.>,\|]*')
debugger.HandleCommand('type synthetic add --python-class pl.PLArrayProvider -x \[.+\]*')
debugger.HandleCommand('type synthetic add --python-class pl.PLUnionProvider -x union::[:<.>,\|]*')