Skip to content

Commit

Permalink
Simplify the SmallVector pretty printer for LLDB a bit and make it wo…
Browse files Browse the repository at this point in the history
…rk with reference types.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167674 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Nov 10, 2012
1 parent 52ea245 commit 7994959
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions utils/lldbDataFormatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Load into LLDB with:
script import lldbDataFormatters
type synthetic add -x "^llvm::SmallVectorImpl<.+>$" -l lldbDataFormatters.SmallVectorSynthProvider
type synthetic add -x "^llvm::SmallVector<.+,.+>$" -l lldbDataFormatters.SmallVectorSynthProvider
"""

# Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
Expand Down Expand Up @@ -32,22 +33,15 @@ def get_child_at_index(self, index):
return self.begin.CreateChildAtOffset('['+str(index)+']',
offset, self.data_type)

def get_type_from_name(self):
import re
name = self.valobj.GetType().GetName()
# This class works with both SmallVectors and SmallVectorImpls.
res = re.match("^(llvm::)?SmallVectorImpl<(.+)>$", name)
if res:
return res.group(2)
res = re.match("^(llvm::)?SmallVector<(.+), \d+>$", name)
if res:
return res.group(2)
return None

def update(self):
self.begin = self.valobj.GetChildMemberWithName('BeginX')
self.end = self.valobj.GetChildMemberWithName('EndX')
data_type = self.get_type_from_name()
# FIXME: this sometimes returns an invalid type.
self.data_type = self.valobj.GetTarget().FindFirstType(data_type)
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)
self.type_size = self.data_type.GetByteSize()
assert self.type_size != 0

0 comments on commit 7994959

Please sign in to comment.