2 LLDB Formatters for LLVM data types.
4 Load into LLDB with 'command script import /path/to/lldbDataFormatters.py'
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<.+,.+>$"')
15 debugger
.HandleCommand('type synthetic add -w llvm '
16 '-l lldbDataFormatters.ArrayRefSynthProvider '
17 '-x "^llvm::ArrayRef<.+>$"')
18 debugger
.HandleCommand('type summary add -w llvm '
19 '-F lldbDataFormatters.OptionalSummaryProvider '
20 '-x "^llvm::Optional<.+>$"')
22 # Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
23 class SmallVectorSynthProvider
:
24 def __init__(self
, valobj
, dict):
26 self
.update() # initialize this provider
28 def num_children(self
):
29 return self
.size
.GetValueAsUnsigned(0)
31 def get_child_index(self
, name
):
33 return int(name
.lstrip('[').rstrip(']'))
37 def get_child_at_index(self
, index
):
41 if index
>= self
.num_children():
44 offset
= index
* self
.type_size
45 return self
.begin
.CreateChildAtOffset('['+str(index
)+']',
46 offset
, self
.data_type
)
49 self
.begin
= self
.valobj
.GetChildMemberWithName('BeginX')
50 self
.size
= self
.valobj
.GetChildMemberWithName('Size')
51 the_type
= self
.valobj
.GetType()
52 # If this is a reference type we have to dereference it to get to the
54 if the_type
.IsReferenceType():
55 the_type
= the_type
.GetDereferencedType()
57 self
.data_type
= the_type
.GetTemplateArgumentType(0)
58 self
.type_size
= self
.data_type
.GetByteSize()
59 assert self
.type_size
!= 0
61 class ArrayRefSynthProvider
:
62 """ Provider for llvm::ArrayRef """
63 def __init__(self
, valobj
, dict):
65 self
.update() # initialize this provider
67 def num_children(self
):
70 def get_child_index(self
, name
):
72 return int(name
.lstrip('[').rstrip(']'))
76 def get_child_at_index(self
, index
):
77 if index
< 0 or index
>= self
.num_children():
79 offset
= index
* self
.type_size
80 return self
.data
.CreateChildAtOffset('[' + str(index
) + ']',
81 offset
, self
.data_type
)
84 self
.data
= self
.valobj
.GetChildMemberWithName('Data')
85 length_obj
= self
.valobj
.GetChildMemberWithName('Length')
86 self
.length
= length_obj
.GetValueAsUnsigned(0)
87 self
.data_type
= self
.data
.GetType().GetPointeeType()
88 self
.type_size
= self
.data_type
.GetByteSize()
89 assert self
.type_size
!= 0
91 def OptionalSummaryProvider(valobj
, internal_dict
):
92 storage
= valobj
.GetChildMemberWithName('Storage')
97 hasVal
= storage
.GetChildMemberWithName('hasVal').GetValueAsUnsigned(failure
)
99 return '<could not read llvm::Optional>'
104 underlying_type
= storage
.GetType().GetTemplateArgumentType(0)
105 storage
= storage
.GetChildMemberWithName('storage')
106 return str(storage
.Cast(underlying_type
))