0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 """
|
77
|
2 LLDB Formatters for LLVM data types.
|
|
3
|
|
4 Load into LLDB with 'command script import /path/to/lldbDataFormatters.py'
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 """
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6
|
77
|
7 def __lldb_init_module(debugger, internal_dict):
|
|
8 debugger.HandleCommand('type category define -e llvm -l c++')
|
|
9 debugger.HandleCommand('type synthetic add -w llvm '
|
|
10 '-l lldbDataFormatters.SmallVectorSynthProvider '
|
|
11 '-x "^llvm::SmallVectorImpl<.+>$"')
|
|
12 debugger.HandleCommand('type synthetic add -w llvm '
|
|
13 '-l lldbDataFormatters.SmallVectorSynthProvider '
|
|
14 '-x "^llvm::SmallVector<.+,.+>$"')
|
83
|
15 debugger.HandleCommand('type synthetic add -w llvm '
|
|
16 '-l lldbDataFormatters.ArrayRefSynthProvider '
|
|
17 '-x "^llvm::ArrayRef<.+>$"')
|
95
|
18 debugger.HandleCommand('type summary add -w llvm '
|
|
19 '-F lldbDataFormatters.OptionalSummaryProvider '
|
|
20 '-x "^llvm::Optional<.+>$"')
|
77
|
21
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 # Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 class SmallVectorSynthProvider:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 def __init__(self, valobj, dict):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 self.valobj = valobj;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 self.update() # initialize this provider
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 def num_children(self):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 begin = self.begin.GetValueAsUnsigned(0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 end = self.end.GetValueAsUnsigned(0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 return (end - begin)/self.type_size
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 def get_child_index(self, name):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 try:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 return int(name.lstrip('[').rstrip(']'))
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 except:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 return -1;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 def get_child_at_index(self, index):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 # Do bounds checking.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 if index < 0:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 return None
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 if index >= self.num_children():
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 return None;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 offset = index * self.type_size
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 return self.begin.CreateChildAtOffset('['+str(index)+']',
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 offset, self.data_type)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 def update(self):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 self.begin = self.valobj.GetChildMemberWithName('BeginX')
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 self.end = self.valobj.GetChildMemberWithName('EndX')
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 the_type = self.valobj.GetType()
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 # If this is a reference type we have to dereference it to get to the
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 # template parameter.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 if the_type.IsReferenceType():
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 the_type = the_type.GetDereferencedType()
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 self.data_type = the_type.GetTemplateArgumentType(0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 self.type_size = self.data_type.GetByteSize()
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 assert self.type_size != 0
|
83
|
62
|
|
63 class ArrayRefSynthProvider:
|
|
64 """ Provider for llvm::ArrayRef """
|
|
65 def __init__(self, valobj, dict):
|
|
66 self.valobj = valobj;
|
|
67 self.update() # initialize this provider
|
|
68
|
|
69 def num_children(self):
|
|
70 return self.length
|
|
71
|
|
72 def get_child_index(self, name):
|
|
73 try:
|
|
74 return int(name.lstrip('[').rstrip(']'))
|
|
75 except:
|
|
76 return -1;
|
|
77
|
|
78 def get_child_at_index(self, index):
|
|
79 if index < 0 or index >= self.num_children():
|
|
80 return None;
|
|
81 offset = index * self.type_size
|
|
82 return self.data.CreateChildAtOffset('[' + str(index) + ']',
|
|
83 offset, self.data_type)
|
|
84
|
|
85 def update(self):
|
|
86 self.data = self.valobj.GetChildMemberWithName('Data')
|
|
87 length_obj = self.valobj.GetChildMemberWithName('Length')
|
|
88 self.length = length_obj.GetValueAsUnsigned(0)
|
|
89 self.data_type = self.data.GetType().GetPointeeType()
|
|
90 self.type_size = self.data_type.GetByteSize()
|
|
91 assert self.type_size != 0
|
95
|
92
|
|
93 def OptionalSummaryProvider(valobj, internal_dict):
|
|
94 if not valobj.GetChildMemberWithName('hasVal').GetValueAsUnsigned(0):
|
|
95 return 'None'
|
|
96 underlying_type = valobj.GetType().GetTemplateArgumentType(0)
|
|
97 storage = valobj.GetChildMemberWithName('storage')
|
|
98 return str(storage.Cast(underlying_type))
|