3 script import lldbDataFormatters
4 type synthetic add -x "^llvm::SmallVectorImpl<.+>$" -l lldbDataFormatters.SmallVectorSynthProvider
7 # Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
8 class SmallVectorSynthProvider:
9 def __init__(self, valobj, dict):
11 self.update() # initialize this provider
13 def num_children(self):
14 begin = self.begin.GetValueAsUnsigned(0)
15 end = self.end.GetValueAsUnsigned(0)
16 return (end - begin)/self.type_size
18 def get_child_index(self, name):
20 return int(name.lstrip('[').rstrip(']'))
24 def get_child_at_index(self, index):
28 if index >= self.num_children():
31 offset = index * self.type_size
32 return self.begin.CreateChildAtOffset('['+str(index)+']',
33 offset, self.data_type)
35 def get_type_from_name(self):
37 name = self.valobj.GetType().GetName()
38 # This class works with both SmallVectors and SmallVectorImpls.
39 res = re.match("^(llvm::)?SmallVectorImpl<(.+)>$", name)
42 res = re.match("^(llvm::)?SmallVector<(.+), \d+>$", name)
48 self.begin = self.valobj.GetChildMemberWithName('BeginX')
49 self.end = self.valobj.GetChildMemberWithName('EndX')
50 data_type = self.get_type_from_name()
51 # FIXME: this sometimes returns an invalid type.
52 self.data_type = self.valobj.GetTarget().FindFirstType(data_type)
53 self.type_size = self.data_type.GetByteSize()