source: parabix-LLVM/llvm_git/utils/lldbDataFormatters.py @ 4136

Last change on this file since 4136 was 4078, checked in by linmengl, 5 years ago

checkin llvm-meng source

File size: 2.0 KB
Line 
1"""
2LLDB Formatters for LLVM data types.
3
4Load into LLDB with 'command script import /path/to/lldbDataFormatters.py'
5"""
6
7def __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<.+,.+>$"')
15
16# Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
17class SmallVectorSynthProvider:
18    def __init__(self, valobj, dict):
19        self.valobj = valobj;
20        self.update() # initialize this provider
21
22    def num_children(self):
23        begin = self.begin.GetValueAsUnsigned(0)
24        end = self.end.GetValueAsUnsigned(0)
25        return (end - begin)/self.type_size
26
27    def get_child_index(self, name):
28        try:
29            return int(name.lstrip('[').rstrip(']'))
30        except:
31            return -1;
32
33    def get_child_at_index(self, index):
34        # Do bounds checking.
35        if index < 0:
36            return None
37        if index >= self.num_children():
38            return None;
39
40        offset = index * self.type_size
41        return self.begin.CreateChildAtOffset('['+str(index)+']',
42                                              offset, self.data_type)
43
44    def update(self):
45        self.begin = self.valobj.GetChildMemberWithName('BeginX')
46        self.end = self.valobj.GetChildMemberWithName('EndX')
47        the_type = self.valobj.GetType()
48        # If this is a reference type we have to dereference it to get to the
49        # template parameter.
50        if the_type.IsReferenceType():
51            the_type = the_type.GetDereferencedType()
52
53        self.data_type = the_type.GetTemplateArgumentType(0)
54        self.type_size = self.data_type.GetByteSize()
55        assert self.type_size != 0
Note: See TracBrowser for help on using the repository browser.