aboutsummaryrefslogtreecommitdiff
path: root/utils/lldbDataFormatters.py
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2012-01-17 14:52:12 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2012-01-17 14:52:12 +0000
commitf61f22a5d1fffc6b83679f5b666f4afb787f6ae5 (patch)
tree69e201041635cf3dfd45da8660f3b354fbc0cad0 /utils/lldbDataFormatters.py
parent44b920fac47e8047acd0ffdbd3b169b4fdfed06b (diff)
Add an LLDB data formatter script for llvm::SmallVector, maybe this is helpful to someone else.
This lets lldb give sane output for SmallVectors, e.g. Before: (lldb) p sv (llvm::SmallVector<int, 10>) $0 = { (llvm::SmallVectorImpl<int>) llvm::SmallVectorImpl<int> = { (llvm::SmallVectorTemplateBase<int>) llvm::SmallVectorTemplateBase<int> = { (llvm::SmallVectorTemplateCommon<int>) llvm::SmallVectorTemplateCommon<int> = { (llvm::SmallVectorBase) llvm::SmallVectorBase = { (void *) BeginX = 0x00007fff5fbff960 ... } After: (lldb) p sv (llvm::SmallVector<int, 10>) $0 = { (int) [0] = 42 (int) [1] = 23 ... } The script is still a bit rough so expect crashes for vectors of complex types. Synthetic children are _not_ available in xcode 4.2, newer LLDBs should work though. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148308 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/lldbDataFormatters.py')
-rw-r--r--utils/lldbDataFormatters.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/utils/lldbDataFormatters.py b/utils/lldbDataFormatters.py
new file mode 100644
index 0000000000..18b407a02a
--- /dev/null
+++ b/utils/lldbDataFormatters.py
@@ -0,0 +1,53 @@
+"""
+Load into LLDB with:
+script import lldbDataFormatters
+type synthetic add -x "^llvm::SmallVectorImpl<.+>$" -l lldbDataFormatters.SmallVectorSynthProvider
+"""
+
+# Pretty printer for llvm::SmallVector/llvm::SmallVectorImpl
+class SmallVectorSynthProvider:
+ def __init__(self, valobj, dict):
+ self.valobj = valobj;
+ self.update() # initialize this provider
+
+ def num_children(self):
+ begin = self.begin.GetValueAsUnsigned(0)
+ end = self.end.GetValueAsUnsigned(0)
+ return (end - begin)/self.type_size
+
+ 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 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)
+ self.type_size = self.data_type.GetByteSize()