[openturns] 02/04: Add a pretty-printer for gdb

Denis Barbier barbier-guest at moszumanska.debian.org
Sat Feb 22 20:18:46 UTC 2014


This is an automated email from the git hooks/post-receive script.

barbier-guest pushed a commit to branch debian
in repository openturns.

commit 680c736f75cab58add30fbc13d50b8cd03aead99
Author: Denis Barbier <bouzim at gmail.com>
Date:   Sat Feb 1 23:17:06 2014 +0100

    Add a pretty-printer for gdb
---
 debian/libOT-gdb.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 debian/rules        |  2 ++
 2 files changed, 101 insertions(+)

diff --git a/debian/libOT-gdb.py b/debian/libOT-gdb.py
new file mode 100644
index 0000000..71ca794
--- /dev/null
+++ b/debian/libOT-gdb.py
@@ -0,0 +1,99 @@
+
+import gdb
+import re
+
+objfile = gdb.current_objfile() or gdb.objfiles()[0]
+int_ptr  = gdb.lookup_type('int').pointer()
+
+ot_pretty_printers = []
+
+def AddToPrettyPrinter(rx):
+    def class_wrapper(cls):
+        ot_pretty_printers.append( (re.compile(rx), cls) )
+        return cls
+    return class_wrapper
+
+ at AddToPrettyPrinter(r'^OT::PersistentObject$')
+class PersistentObjectPrinter(object):
+    def __init__(self, val):
+        self.val = val
+
+    def to_string(self):
+        name = self.val['p_name_']['ptr_']['ptr_']
+        if name == gdb.Value(0):
+            return "[unnamed]"
+        else:
+            return "[name=%s]" % (str(name.dereference()))
+
+ at AddToPrettyPrinter(r'^OT::Pointer<.*>$')
+class PointerPrinter(object):
+    def __init__(self, val):
+        self.val = val
+
+    def to_string(self):
+        global int_ptr
+
+        pointee = self.val['ptr_']['ptr_']
+        if long(pointee) == 0L:
+            return "NULL"
+        else:
+            atomicVal = self.val['ptr_']['count_']['p_impl_']['use_count_']['val_']
+            # This atomicVal points either to an int or a tbb::atomic<int>
+            # The implementation of tbb::atomic depends on tbb's version, thus it is easier
+            # to dereference it.
+            atomicVal = atomicVal.address.cast(int_ptr).dereference()
+            return "([counter=%s] %s) 0x%x = %s" % (str(atomicVal), str(pointee.type), long(pointee), str(pointee.dereference()))
+
+ at AddToPrettyPrinter(r'^OT::TypedInterfaceObject<.*>$')
+class TypedInterfaceObjectPrinter(object):
+    def __init__(self, val):
+        self.val = val
+        self.template_name = val.type.template_argument(0)
+
+    def to_string(self):
+        return "{ p_implementation_ -> [ %s ] }" % (str(self.val['p_implementation_']))
+
+ at AddToPrettyPrinter(r'^OT::(PersistentCollection<.*>|.*PersistentCollection)$')
+class PersistentCollectionPrinter(object):
+    def __init__(self, val):
+        self.val = val
+
+    def display_hint(self):
+        return 'array'
+
+    def to_string(self):
+        # Dereference PersistentObject
+        name = self.val['p_name_']['ptr_']['ptr_']
+        if long(name) == 0L:
+            decoratedName = "[unnamed]"
+        else:
+            decoratedName = "[name=%s]" % (str(name.dereference()))
+        # Dereference Collection
+        return "%s %s" % (decoratedName, self.val['coll__'])
+
+ at AddToPrettyPrinter(r'^OT::(Collection<.*>|.*Collection)$')
+class CollectionPrinter(object):
+    def __init__(self, val):
+        self.val = val
+
+    def display_hint(self):
+        return 'array'
+
+    def to_string(self):
+        return str(self.val['coll__'])
+
+
+def lookup_function(val):
+    type = val.type
+    if type.code == gdb.TYPE_CODE_REF:
+        type = type.target()
+    type = type.unqualified().strip_typedefs()
+    typename = type.tag
+    if not typename or not typename.startswith('OT::'):
+        return None
+    for regex, pretty_printer in ot_pretty_printers:
+        if regex.search(typename):
+            return pretty_printer(val)
+    return None
+
+objfile.pretty_printers.append(lookup_function)
diff --git a/debian/rules b/debian/rules
index 376da57..dbcf3e8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -93,6 +93,8 @@ override_dh_auto_configure: debian/tmp/usr/lib/R/site-library/rot
 
 override_dh_auto_install: debian/tmp/usr/lib/R/site-library/rot
 	dh_auto_install
+	mkdir -p debian/libopenturns-dbg/usr/lib/debug/usr/lib
+	cp debian/libOT-gdb.py debian/libopenturns-dbg/usr/lib/debug/usr/lib/libOT.so.0.4.0-gdb.py
 ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
 	# CTestTestfile.cmake sets LD_LIBRARY_PATH to find libraries in debian/tmp.
 	# But it overrides current value, which breaks when run by fakeroot.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/openturns.git



More information about the debian-science-commits mailing list