2012-01-17 15:52:12 +01:00
|
|
|
"""
|
2014-05-28 07:45:17 +02:00
|
|
|
LLDB Formatters for LLVM data types.
|
|
|
|
|
|
|
|
Load into LLDB with 'command script import /path/to/lldbDataFormatters.py'
|
2012-01-17 15:52:12 +01:00
|
|
|
"""
|
|
|
|
|
2021-02-22 06:45:04 +01:00
|
|
|
import lldb
|
|
|
|
|
2014-05-28 07:45:17 +02:00
|
|
|
def __lldb_init_module(debugger, internal_dict):
|
|
|
|
debugger.HandleCommand('type category define -e llvm -l c++')
|
|
|
|
debugger.HandleCommand('type synthetic add -w llvm '
|
|
|
|
'-l lldbDataFormatters.SmallVectorSynthProvider '
|
|
|
|
'-x "^llvm::SmallVectorImpl<.+>$"')
|
|
|
|
debugger.HandleCommand('type synthetic add -w llvm '
|
|
|
|
'-l lldbDataFormatters.SmallVectorSynthProvider '
|
|
|
|
'-x "^llvm::SmallVector<.+,.+>$"')
|
2014-09-11 03:47:38 +02:00
|
|
|
debugger.HandleCommand('type synthetic add -w llvm '
|
|
|
|
'-l lldbDataFormatters.ArrayRefSynthProvider '
|
|
|
|
'-x "^llvm::ArrayRef<.+>$"')
|
2021-02-22 06:45:04 +01:00
|
|
|
debugger.HandleCommand('type synthetic add -w llvm '
|
|
|
|
'-l lldbDataFormatters.OptionalSynthProvider '
|
|
|
|
'-x "^llvm::Optional<.+>$"')
|
2015-02-20 03:55:22 +01:00
|
|
|
debugger.HandleCommand('type summary add -w llvm '
|
|
|
|
'-F lldbDataFormatters.OptionalSummaryProvider '
|
|
|
|
'-x "^llvm::Optional<.+>$"')
|
2019-04-25 02:03:02 +02:00
|
|
|
debugger.HandleCommand('type summary add -w llvm '
|
|
|
|
'-F lldbDataFormatters.SmallStringSummaryProvider '
|
|
|
|
'-x "^llvm::SmallString<.+>$"')
|
2019-08-17 01:47:57 +02:00
|
|
|
debugger.HandleCommand('type summary add -w llvm '
|
|
|
|
'-F lldbDataFormatters.StringRefSummaryProvider '
|
|
|
|
'-x "^llvm::StringRef$"')
|
|
|
|
debugger.HandleCommand('type summary add -w llvm '
|
|
|
|
'-F lldbDataFormatters.ConstStringSummaryProvider '
|
|
|
|
'-x "^lldb_private::ConstString$"')
|
2014-05-28 07:45:17 +02:00
|
|
|
|
2012-01-17 15:52:12 +01:00
|
|
|
# Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
|
|
|
|
class SmallVectorSynthProvider:
|
2021-02-26 16:45:04 +01:00
|
|
|
def __init__(self, valobj, internal_dict):
|
2012-01-17 15:52:12 +01:00
|
|
|
self.valobj = valobj;
|
|
|
|
self.update() # initialize this provider
|
|
|
|
|
|
|
|
def num_children(self):
|
2018-11-06 19:52:30 +01:00
|
|
|
return self.size.GetValueAsUnsigned(0)
|
2012-01-17 15:52:12 +01:00
|
|
|
|
|
|
|
def get_child_index(self, name):
|
|
|
|
try:
|
|
|
|
return int(name.lstrip('[').rstrip(']'))
|
|
|
|
except:
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
def get_child_at_index(self, index):
|
|
|
|
# Do bounds checking.
|
|
|
|
if index < 0:
|
|
|
|
return None
|
|
|
|
if index >= self.num_children():
|
|
|
|
return None;
|
|
|
|
|
|
|
|
offset = index * self.type_size
|
|
|
|
return self.begin.CreateChildAtOffset('['+str(index)+']',
|
|
|
|
offset, self.data_type)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.begin = self.valobj.GetChildMemberWithName('BeginX')
|
2018-11-06 19:52:30 +01:00
|
|
|
self.size = self.valobj.GetChildMemberWithName('Size')
|
2012-11-10 10:45:32 +01:00
|
|
|
the_type = self.valobj.GetType()
|
|
|
|
# If this is a reference type we have to dereference it to get to the
|
|
|
|
# template parameter.
|
|
|
|
if the_type.IsReferenceType():
|
|
|
|
the_type = the_type.GetDereferencedType()
|
|
|
|
|
|
|
|
self.data_type = the_type.GetTemplateArgumentType(0)
|
2012-01-17 15:52:12 +01:00
|
|
|
self.type_size = self.data_type.GetByteSize()
|
2012-11-10 10:45:32 +01:00
|
|
|
assert self.type_size != 0
|
2014-09-11 03:47:38 +02:00
|
|
|
|
|
|
|
class ArrayRefSynthProvider:
|
|
|
|
""" Provider for llvm::ArrayRef """
|
2021-02-26 16:45:04 +01:00
|
|
|
def __init__(self, valobj, internal_dict):
|
2014-09-11 03:47:38 +02:00
|
|
|
self.valobj = valobj;
|
|
|
|
self.update() # initialize this provider
|
|
|
|
|
|
|
|
def num_children(self):
|
|
|
|
return self.length
|
|
|
|
|
|
|
|
def get_child_index(self, name):
|
|
|
|
try:
|
|
|
|
return int(name.lstrip('[').rstrip(']'))
|
|
|
|
except:
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
def get_child_at_index(self, index):
|
|
|
|
if index < 0 or index >= self.num_children():
|
|
|
|
return None;
|
|
|
|
offset = index * self.type_size
|
|
|
|
return self.data.CreateChildAtOffset('[' + str(index) + ']',
|
|
|
|
offset, self.data_type)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.data = self.valobj.GetChildMemberWithName('Data')
|
|
|
|
length_obj = self.valobj.GetChildMemberWithName('Length')
|
|
|
|
self.length = length_obj.GetValueAsUnsigned(0)
|
|
|
|
self.data_type = self.data.GetType().GetPointeeType()
|
|
|
|
self.type_size = self.data_type.GetByteSize()
|
|
|
|
assert self.type_size != 0
|
2015-02-20 03:55:22 +01:00
|
|
|
|
2021-02-22 06:45:04 +01:00
|
|
|
def GetOptionalValue(valobj):
|
2018-07-23 23:59:06 +02:00
|
|
|
storage = valobj.GetChildMemberWithName('Storage')
|
|
|
|
if not storage:
|
|
|
|
storage = valobj
|
|
|
|
|
|
|
|
failure = 2
|
|
|
|
hasVal = storage.GetChildMemberWithName('hasVal').GetValueAsUnsigned(failure)
|
|
|
|
if hasVal == failure:
|
|
|
|
return '<could not read llvm::Optional>'
|
|
|
|
|
|
|
|
if hasVal == 0:
|
2021-02-22 06:45:04 +01:00
|
|
|
return None
|
2018-07-23 23:59:06 +02:00
|
|
|
|
|
|
|
underlying_type = storage.GetType().GetTemplateArgumentType(0)
|
2020-08-27 00:10:31 +02:00
|
|
|
storage = storage.GetChildMemberWithName('value')
|
2021-02-22 06:45:04 +01:00
|
|
|
return storage.Cast(underlying_type)
|
|
|
|
|
|
|
|
def OptionalSummaryProvider(valobj, internal_dict):
|
2021-03-30 00:59:05 +02:00
|
|
|
val = GetOptionalValue(valobj)
|
|
|
|
return val.summary if val else 'None'
|
2021-02-22 06:45:04 +01:00
|
|
|
|
|
|
|
class OptionalSynthProvider:
|
|
|
|
"""Provides deref support to llvm::Optional<T>"""
|
|
|
|
def __init__(self, valobj, internal_dict):
|
|
|
|
self.valobj = valobj
|
|
|
|
|
|
|
|
def num_children(self):
|
|
|
|
return self.valobj.num_children
|
|
|
|
|
|
|
|
def get_child_index(self, name):
|
|
|
|
if name == '$$dereference$$':
|
2021-02-26 17:04:53 +01:00
|
|
|
return self.valobj.num_children
|
2021-02-22 06:45:04 +01:00
|
|
|
return self.valobj.GetIndexOfChildWithName(name)
|
|
|
|
|
|
|
|
def get_child_at_index(self, index):
|
|
|
|
if index < self.valobj.num_children:
|
|
|
|
return self.valobj.GetChildAtIndex(index)
|
|
|
|
return GetOptionalValue(self.valobj) or lldb.SBValue()
|
2019-04-25 02:03:02 +02:00
|
|
|
|
|
|
|
def SmallStringSummaryProvider(valobj, internal_dict):
|
|
|
|
num_elements = valobj.GetNumChildren()
|
|
|
|
res = "\""
|
|
|
|
for i in range(0, num_elements):
|
2020-02-26 01:42:53 +01:00
|
|
|
c = valobj.GetChildAtIndex(i).GetValue()
|
|
|
|
if c:
|
|
|
|
res += c.strip("'")
|
2019-04-25 02:03:02 +02:00
|
|
|
res += "\""
|
|
|
|
return res
|
2019-08-17 01:47:57 +02:00
|
|
|
|
|
|
|
def StringRefSummaryProvider(valobj, internal_dict):
|
|
|
|
if valobj.GetNumChildren() == 2:
|
|
|
|
# StringRef's are also used to point at binary blobs in memory,
|
|
|
|
# so filter out suspiciously long strings.
|
|
|
|
max_length = 256
|
|
|
|
length = valobj.GetChildAtIndex(1).GetValueAsUnsigned(max_length)
|
|
|
|
if length == 0:
|
|
|
|
return "NULL"
|
|
|
|
if length < max_length:
|
|
|
|
return valobj.GetChildAtIndex(0).GetSummary()
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def ConstStringSummaryProvider(valobj, internal_dict):
|
|
|
|
if valobj.GetNumChildren() == 1:
|
|
|
|
return valobj.GetChildAtIndex(0).GetSummary()
|
|
|
|
return ""
|