Skip to content

Commit

Permalink
utils: Teach lldbDataFormatters how to format ArrayRefs
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217567 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
bogner committed Sep 11, 2014
1 parent 463a096 commit 326018c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions utils/lldbDataFormatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('type synthetic add -w llvm '
'-l lldbDataFormatters.SmallVectorSynthProvider '
'-x "^llvm::SmallVector<.+,.+>$"')
debugger.HandleCommand('type synthetic add -w llvm '
'-l lldbDataFormatters.ArrayRefSynthProvider '
'-x "^llvm::ArrayRef<.+>$"')

# Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
class SmallVectorSynthProvider:
Expand Down Expand Up @@ -53,3 +56,33 @@ def update(self):
self.data_type = the_type.GetTemplateArgumentType(0)
self.type_size = self.data_type.GetByteSize()
assert self.type_size != 0

class ArrayRefSynthProvider:
""" Provider for llvm::ArrayRef """
def __init__(self, valobj, dict):
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

0 comments on commit 326018c

Please sign in to comment.