annotate llvm/utils/lldbDataFormatters.py @ 220:42394fc6a535

Added tag llvm12 for changeset 0572611fdcc8
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:13:43 +0900 (2021-06-15)
parents 0572611fdcc8
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 """
anatofuz
parents:
diff changeset
2 LLDB Formatters for LLVM data types.
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 Load into LLDB with 'command script import /path/to/lldbDataFormatters.py'
anatofuz
parents:
diff changeset
5 """
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 def __lldb_init_module(debugger, internal_dict):
anatofuz
parents:
diff changeset
8 debugger.HandleCommand('type category define -e llvm -l c++')
anatofuz
parents:
diff changeset
9 debugger.HandleCommand('type synthetic add -w llvm '
anatofuz
parents:
diff changeset
10 '-l lldbDataFormatters.SmallVectorSynthProvider '
anatofuz
parents:
diff changeset
11 '-x "^llvm::SmallVectorImpl<.+>$"')
anatofuz
parents:
diff changeset
12 debugger.HandleCommand('type synthetic add -w llvm '
anatofuz
parents:
diff changeset
13 '-l lldbDataFormatters.SmallVectorSynthProvider '
anatofuz
parents:
diff changeset
14 '-x "^llvm::SmallVector<.+,.+>$"')
anatofuz
parents:
diff changeset
15 debugger.HandleCommand('type synthetic add -w llvm '
anatofuz
parents:
diff changeset
16 '-l lldbDataFormatters.ArrayRefSynthProvider '
anatofuz
parents:
diff changeset
17 '-x "^llvm::ArrayRef<.+>$"')
anatofuz
parents:
diff changeset
18 debugger.HandleCommand('type summary add -w llvm '
anatofuz
parents:
diff changeset
19 '-F lldbDataFormatters.OptionalSummaryProvider '
anatofuz
parents:
diff changeset
20 '-x "^llvm::Optional<.+>$"')
anatofuz
parents:
diff changeset
21 debugger.HandleCommand('type summary add -w llvm '
anatofuz
parents:
diff changeset
22 '-F lldbDataFormatters.SmallStringSummaryProvider '
anatofuz
parents:
diff changeset
23 '-x "^llvm::SmallString<.+>$"')
anatofuz
parents:
diff changeset
24 debugger.HandleCommand('type summary add -w llvm '
anatofuz
parents:
diff changeset
25 '-F lldbDataFormatters.StringRefSummaryProvider '
anatofuz
parents:
diff changeset
26 '-x "^llvm::StringRef$"')
anatofuz
parents:
diff changeset
27 debugger.HandleCommand('type summary add -w llvm '
anatofuz
parents:
diff changeset
28 '-F lldbDataFormatters.ConstStringSummaryProvider '
anatofuz
parents:
diff changeset
29 '-x "^lldb_private::ConstString$"')
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 # Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
anatofuz
parents:
diff changeset
32 class SmallVectorSynthProvider:
anatofuz
parents:
diff changeset
33 def __init__(self, valobj, dict):
anatofuz
parents:
diff changeset
34 self.valobj = valobj;
anatofuz
parents:
diff changeset
35 self.update() # initialize this provider
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 def num_children(self):
anatofuz
parents:
diff changeset
38 return self.size.GetValueAsUnsigned(0)
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 def get_child_index(self, name):
anatofuz
parents:
diff changeset
41 try:
anatofuz
parents:
diff changeset
42 return int(name.lstrip('[').rstrip(']'))
anatofuz
parents:
diff changeset
43 except:
anatofuz
parents:
diff changeset
44 return -1;
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 def get_child_at_index(self, index):
anatofuz
parents:
diff changeset
47 # Do bounds checking.
anatofuz
parents:
diff changeset
48 if index < 0:
anatofuz
parents:
diff changeset
49 return None
anatofuz
parents:
diff changeset
50 if index >= self.num_children():
anatofuz
parents:
diff changeset
51 return None;
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 offset = index * self.type_size
anatofuz
parents:
diff changeset
54 return self.begin.CreateChildAtOffset('['+str(index)+']',
anatofuz
parents:
diff changeset
55 offset, self.data_type)
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 def update(self):
anatofuz
parents:
diff changeset
58 self.begin = self.valobj.GetChildMemberWithName('BeginX')
anatofuz
parents:
diff changeset
59 self.size = self.valobj.GetChildMemberWithName('Size')
anatofuz
parents:
diff changeset
60 the_type = self.valobj.GetType()
anatofuz
parents:
diff changeset
61 # If this is a reference type we have to dereference it to get to the
anatofuz
parents:
diff changeset
62 # template parameter.
anatofuz
parents:
diff changeset
63 if the_type.IsReferenceType():
anatofuz
parents:
diff changeset
64 the_type = the_type.GetDereferencedType()
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 self.data_type = the_type.GetTemplateArgumentType(0)
anatofuz
parents:
diff changeset
67 self.type_size = self.data_type.GetByteSize()
anatofuz
parents:
diff changeset
68 assert self.type_size != 0
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 class ArrayRefSynthProvider:
anatofuz
parents:
diff changeset
71 """ Provider for llvm::ArrayRef """
anatofuz
parents:
diff changeset
72 def __init__(self, valobj, dict):
anatofuz
parents:
diff changeset
73 self.valobj = valobj;
anatofuz
parents:
diff changeset
74 self.update() # initialize this provider
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 def num_children(self):
anatofuz
parents:
diff changeset
77 return self.length
anatofuz
parents:
diff changeset
78
anatofuz
parents:
diff changeset
79 def get_child_index(self, name):
anatofuz
parents:
diff changeset
80 try:
anatofuz
parents:
diff changeset
81 return int(name.lstrip('[').rstrip(']'))
anatofuz
parents:
diff changeset
82 except:
anatofuz
parents:
diff changeset
83 return -1;
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 def get_child_at_index(self, index):
anatofuz
parents:
diff changeset
86 if index < 0 or index >= self.num_children():
anatofuz
parents:
diff changeset
87 return None;
anatofuz
parents:
diff changeset
88 offset = index * self.type_size
anatofuz
parents:
diff changeset
89 return self.data.CreateChildAtOffset('[' + str(index) + ']',
anatofuz
parents:
diff changeset
90 offset, self.data_type)
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 def update(self):
anatofuz
parents:
diff changeset
93 self.data = self.valobj.GetChildMemberWithName('Data')
anatofuz
parents:
diff changeset
94 length_obj = self.valobj.GetChildMemberWithName('Length')
anatofuz
parents:
diff changeset
95 self.length = length_obj.GetValueAsUnsigned(0)
anatofuz
parents:
diff changeset
96 self.data_type = self.data.GetType().GetPointeeType()
anatofuz
parents:
diff changeset
97 self.type_size = self.data_type.GetByteSize()
anatofuz
parents:
diff changeset
98 assert self.type_size != 0
anatofuz
parents:
diff changeset
99
anatofuz
parents:
diff changeset
100 def OptionalSummaryProvider(valobj, internal_dict):
anatofuz
parents:
diff changeset
101 storage = valobj.GetChildMemberWithName('Storage')
anatofuz
parents:
diff changeset
102 if not storage:
anatofuz
parents:
diff changeset
103 storage = valobj
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 failure = 2
anatofuz
parents:
diff changeset
106 hasVal = storage.GetChildMemberWithName('hasVal').GetValueAsUnsigned(failure)
anatofuz
parents:
diff changeset
107 if hasVal == failure:
anatofuz
parents:
diff changeset
108 return '<could not read llvm::Optional>'
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 if hasVal == 0:
anatofuz
parents:
diff changeset
111 return 'None'
anatofuz
parents:
diff changeset
112
anatofuz
parents:
diff changeset
113 underlying_type = storage.GetType().GetTemplateArgumentType(0)
anatofuz
parents:
diff changeset
114 storage = storage.GetChildMemberWithName('storage')
anatofuz
parents:
diff changeset
115 return str(storage.Cast(underlying_type))
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 def SmallStringSummaryProvider(valobj, internal_dict):
anatofuz
parents:
diff changeset
118 num_elements = valobj.GetNumChildren()
anatofuz
parents:
diff changeset
119 res = "\""
anatofuz
parents:
diff changeset
120 for i in range(0, num_elements):
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
121 c = valobj.GetChildAtIndex(i).GetValue()
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
122 if c:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
123 res += c.strip("'")
150
anatofuz
parents:
diff changeset
124 res += "\""
anatofuz
parents:
diff changeset
125 return res
anatofuz
parents:
diff changeset
126
anatofuz
parents:
diff changeset
127 def StringRefSummaryProvider(valobj, internal_dict):
anatofuz
parents:
diff changeset
128 if valobj.GetNumChildren() == 2:
anatofuz
parents:
diff changeset
129 # StringRef's are also used to point at binary blobs in memory,
anatofuz
parents:
diff changeset
130 # so filter out suspiciously long strings.
anatofuz
parents:
diff changeset
131 max_length = 256
anatofuz
parents:
diff changeset
132 length = valobj.GetChildAtIndex(1).GetValueAsUnsigned(max_length)
anatofuz
parents:
diff changeset
133 if length == 0:
anatofuz
parents:
diff changeset
134 return "NULL"
anatofuz
parents:
diff changeset
135 if length < max_length:
anatofuz
parents:
diff changeset
136 return valobj.GetChildAtIndex(0).GetSummary()
anatofuz
parents:
diff changeset
137 return ""
anatofuz
parents:
diff changeset
138
anatofuz
parents:
diff changeset
139 def ConstStringSummaryProvider(valobj, internal_dict):
anatofuz
parents:
diff changeset
140 if valobj.GetNumChildren() == 1:
anatofuz
parents:
diff changeset
141 return valobj.GetChildAtIndex(0).GetSummary()
anatofuz
parents:
diff changeset
142 return ""