[pypy-commit] pypy default: Pretty-print arrays in addition to lists

arigo noreply at buildbot.pypy.org
Mon Apr 20 11:28:10 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r76846:19c8e7f2ca21
Date: 2015-04-20 11:28 +0200
http://bitbucket.org/pypy/pypy/changeset/19c8e7f2ca21/

Log:	Pretty-print arrays in addition to lists

diff --git a/pypy/tool/gdb_pypy.py b/pypy/tool/gdb_pypy.py
--- a/pypy/tool/gdb_pypy.py
+++ b/pypy/tool/gdb_pypy.py
@@ -258,29 +258,37 @@
     def lookup(cls, val, gdb=None):
         t = val.type
         if (is_ptr(t, gdb) and t.target().tag is not None and
-            re.match(r'pypy_list\d*', t.target().tag)):
+            re.match(r'pypy_(list|array)\d*', t.target().tag)):
             return cls(val)
         return None
 
     def to_string(self):
-        length = int(self.val['l_length'])
-        array = self.val['l_items']
-        allocated = int(array['length'])
-        items = array['items']
+        t = self.val.type
+        print(t)
+        if t.target().tag.startswith(r'pypy_array'):
+            length = int(self.val['length'])
+            items = self.val['items']
+            allocstr = ''
+        else:
+            length = int(self.val['l_length'])
+            array = self.val['l_items']
+            allocated = int(array['length'])
+            items = array['items']
+            allocstr = ', alloc=%d' % allocated
         itemlist = []
         for i in range(length):
             item = items[i]
             itemlist.append(str(item))
         str_items = ', '.join(itemlist)
-        return 'r[%s] (len=%d, alloc=%d)' % (str_items, length, allocated)
+        return 'r[%s] (len=%d%s)' % (str_items, length, allocstr)
 
 
 try:
     import gdb
     RPyType() # side effects
-    gdb.pretty_printers += [
+    gdb.pretty_printers = [
         RPyStringPrinter.lookup,
         RPyListPrinter.lookup
-        ]
+        ] + gdb.pretty_printers
 except ImportError:
     pass


More information about the pypy-commit mailing list