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<.+>$"')
21 debugger
.HandleCommand('type summary add -w llvm '
22 '-F lldbDataFormatters.SmallStringSummaryProvider '
23 '-x "^llvm::SmallString<.+>$"')
25 # Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
26 class SmallVectorSynthProvider
:
27 def __init__(self
, valobj
, dict):
29 self
.update() # initialize this provider
31 def num_children(self
):
32 return self
.size
.GetValueAsUnsigned(0)
34 def get_child_index(self
, name
):
36 return int(name
.lstrip('[').rstrip(']'))
40 def get_child_at_index(self
, index
):
44 if index
>= self
.num_children():
47 offset
= index
* self
.type_size
48 return self
.begin
.CreateChildAtOffset('['+str(index
)+']',
49 offset
, self
.data_type
)
52 self
.begin
= self
.valobj
.GetChildMemberWithName('BeginX')
53 self
.size
= self
.valobj
.GetChildMemberWithName('Size')
54 the_type
= self
.valobj
.GetType()
55 # If this is a reference type we have to dereference it to get to the
57 if the_type
.IsReferenceType():
58 the_type
= the_type
.GetDereferencedType()
60 self
.data_type
= the_type
.GetTemplateArgumentType(0)
61 self
.type_size
= self
.data_type
.GetByteSize()
62 assert self
.type_size
!= 0
64 class ArrayRefSynthProvider
:
65 """ Provider for llvm::ArrayRef """
66 def __init__(self
, valobj
, dict):
68 self
.update() # initialize this provider
70 def num_children(self
):
73 def get_child_index(self
, name
):
75 return int(name
.lstrip('[').rstrip(']'))
79 def get_child_at_index(self
, index
):
80 if index
< 0 or index
>= self
.num_children():
82 offset
= index
* self
.type_size
83 return self
.data
.CreateChildAtOffset('[' + str(index
) + ']',
84 offset
, self
.data_type
)
87 self
.data
= self
.valobj
.GetChildMemberWithName('Data')
88 length_obj
= self
.valobj
.GetChildMemberWithName('Length')
89 self
.length
= length_obj
.GetValueAsUnsigned(0)
90 self
.data_type
= self
.data
.GetType().GetPointeeType()
91 self
.type_size
= self
.data_type
.GetByteSize()
92 assert self
.type_size
!= 0
94 def OptionalSummaryProvider(valobj
, internal_dict
):
95 storage
= valobj
.GetChildMemberWithName('Storage')
100 hasVal
= storage
.GetChildMemberWithName('hasVal').GetValueAsUnsigned(failure
)
101 if hasVal
== failure
:
102 return '<could not read llvm::Optional>'
107 underlying_type
= storage
.GetType().GetTemplateArgumentType(0)
108 storage
= storage
.GetChildMemberWithName('storage')
109 return str(storage
.Cast(underlying_type
))
111 def SmallStringSummaryProvider(valobj
, internal_dict
):
112 num_elements
= valobj
.GetNumChildren()
114 for i
in range(0, num_elements
):
115 res
+= valobj
.GetChildAtIndex(i
).GetValue().strip("'")