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<.+>$"')
|
77
|
18
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 # Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 class SmallVectorSynthProvider:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 def __init__(self, valobj, dict):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 self.valobj = valobj;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 self.update() # initialize this provider
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 def num_children(self):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 begin = self.begin.GetValueAsUnsigned(0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 end = self.end.GetValueAsUnsigned(0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 return (end - begin)/self.type_size
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 def get_child_index(self, name):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 try:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 return int(name.lstrip('[').rstrip(']'))
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 except:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 return -1;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 def get_child_at_index(self, index):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 # Do bounds checking.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 if index < 0:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 return None
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 if index >= self.num_children():
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 return None;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 offset = index * self.type_size
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 return self.begin.CreateChildAtOffset('['+str(index)+']',
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 offset, self.data_type)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 def update(self):
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 self.begin = self.valobj.GetChildMemberWithName('BeginX')
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 self.end = self.valobj.GetChildMemberWithName('EndX')
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 the_type = self.valobj.GetType()
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 # 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
|
52 # template parameter.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 if the_type.IsReferenceType():
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 the_type = the_type.GetDereferencedType()
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 self.data_type = the_type.GetTemplateArgumentType(0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 self.type_size = self.data_type.GetByteSize()
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 assert self.type_size != 0
|
83
|
59
|
|
60 class ArrayRefSynthProvider:
|
|
61 """ Provider for llvm::ArrayRef """
|
|
62 def __init__(self, valobj, dict):
|
|
63 self.valobj = valobj;
|
|
64 self.update() # initialize this provider
|
|
65
|
|
66 def num_children(self):
|
|
67 return self.length
|
|
68
|
|
69 def get_child_index(self, name):
|
|
70 try:
|
|
71 return int(name.lstrip('[').rstrip(']'))
|
|
72 except:
|
|
73 return -1;
|
|
74
|
|
75 def get_child_at_index(self, index):
|
|
76 if index < 0 or index >= self.num_children():
|
|
77 return None;
|
|
78 offset = index * self.type_size
|
|
79 return self.data.CreateChildAtOffset('[' + str(index) + ']',
|
|
80 offset, self.data_type)
|
|
81
|
|
82 def update(self):
|
|
83 self.data = self.valobj.GetChildMemberWithName('Data')
|
|
84 length_obj = self.valobj.GetChildMemberWithName('Length')
|
|
85 self.length = length_obj.GetValueAsUnsigned(0)
|
|
86 self.data_type = self.data.GetType().GetPointeeType()
|
|
87 self.type_size = self.data_type.GetByteSize()
|
|
88 assert self.type_size != 0
|