From 326018c0b3c8480409f04b2fc9c861b7b0146dbb Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 11 Sep 2014 01:47:38 +0000 Subject: [PATCH] utils: Teach lldbDataFormatters how to format ArrayRefs git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217567 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/lldbDataFormatters.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/utils/lldbDataFormatters.py b/utils/lldbDataFormatters.py index 352448d535c..f570fb49f34 100644 --- a/utils/lldbDataFormatters.py +++ b/utils/lldbDataFormatters.py @@ -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: @@ -53,3 +56,33 @@ class SmallVectorSynthProvider: 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