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<.+>$"')
24 debugger
.HandleCommand('type summary add -w llvm '
25 '-F lldbDataFormatters.StringRefSummaryProvider '
26 '-x "^llvm::StringRef$"')
27 debugger
.HandleCommand('type summary add -w llvm '
28 '-F lldbDataFormatters.ConstStringSummaryProvider '
29 '-x "^lldb_private::ConstString$"')
31 # Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
32 class SmallVectorSynthProvider
:
33 def __init__(self
, valobj
, dict):
35 self
.update() # initialize this provider
37 def num_children(self
):
38 return self
.size
.GetValueAsUnsigned(0)
40 def get_child_index(self
, name
):
42 return int(name
.lstrip('[').rstrip(']'))
46 def get_child_at_index(self
, index
):
50 if index
>= self
.num_children():
53 offset
= index
* self
.type_size
54 return self
.begin
.CreateChildAtOffset('['+str(index
)+']',
55 offset
, self
.data_type
)
58 self
.begin
= self
.valobj
.GetChildMemberWithName('BeginX')
59 self
.size
= self
.valobj
.GetChildMemberWithName('Size')
60 the_type
= self
.valobj
.GetType()
61 # If this is a reference type we have to dereference it to get to the
63 if the_type
.IsReferenceType():
64 the_type
= the_type
.GetDereferencedType()
66 self
.data_type
= the_type
.GetTemplateArgumentType(0)
67 self
.type_size
= self
.data_type
.GetByteSize()
68 assert self
.type_size
!= 0
70 class ArrayRefSynthProvider
:
71 """ Provider for llvm::ArrayRef """
72 def __init__(self
, valobj
, dict):
74 self
.update() # initialize this provider
76 def num_children(self
):
79 def get_child_index(self
, name
):
81 return int(name
.lstrip('[').rstrip(']'))
85 def get_child_at_index(self
, index
):
86 if index
< 0 or index
>= self
.num_children():
88 offset
= index
* self
.type_size
89 return self
.data
.CreateChildAtOffset('[' + str(index
) + ']',
90 offset
, self
.data_type
)
93 self
.data
= self
.valobj
.GetChildMemberWithName('Data')
94 length_obj
= self
.valobj
.GetChildMemberWithName('Length')
95 self
.length
= length_obj
.GetValueAsUnsigned(0)
96 self
.data_type
= self
.data
.GetType().GetPointeeType()
97 self
.type_size
= self
.data_type
.GetByteSize()
98 assert self
.type_size
!= 0
100 def OptionalSummaryProvider(valobj
, internal_dict
):
101 storage
= valobj
.GetChildMemberWithName('Storage')
106 hasVal
= storage
.GetChildMemberWithName('hasVal').GetValueAsUnsigned(failure
)
107 if hasVal
== failure
:
108 return '<could not read llvm::Optional>'
113 underlying_type
= storage
.GetType().GetTemplateArgumentType(0)
114 storage
= storage
.GetChildMemberWithName('storage')
115 return str(storage
.Cast(underlying_type
))
117 def SmallStringSummaryProvider(valobj
, internal_dict
):
118 num_elements
= valobj
.GetNumChildren()
120 for i
in range(0, num_elements
):
121 res
+= valobj
.GetChildAtIndex(i
).GetValue().strip("'")
125 def StringRefSummaryProvider(valobj
, internal_dict
):
126 if valobj
.GetNumChildren() == 2:
127 # StringRef's are also used to point at binary blobs in memory,
128 # so filter out suspiciously long strings.
130 length
= valobj
.GetChildAtIndex(1).GetValueAsUnsigned(max_length
)
133 if length
< max_length
:
134 return valobj
.GetChildAtIndex(0).GetSummary()
137 def ConstStringSummaryProvider(valobj
, internal_dict
):
138 if valobj
.GetNumChildren() == 1:
139 return valobj
.GetChildAtIndex(0).GetSummary()