[pypy-commit] pypy default: add a pretty printer for rpython strings
antocuni
noreply at buildbot.pypy.org
Mon Aug 8 17:39:14 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r46374:e7343eafdcb8
Date: 2011-08-08 15:47 +0200
http://bitbucket.org/pypy/pypy/changeset/e7343eafdcb8/
Log: add a pretty printer for rpython strings
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
@@ -121,8 +121,31 @@
typeids[offset] = descr
return typeids
+
+
+class RpyStringPrinter(object):
+
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ chars = self.val['rs_chars']
+ length = int(chars['length'])
+ items = chars['items']
+ res = [chr(items[i]) for i in range(length)]
+ string = ''.join(res)
+ return repr(string) + " (rpy)"
+
+
+def rpy_string_lookup(val):
+ if val.type.tag == 'pypy_rpy_string0':
+ return RpyStringPrinter(val)
+ return None
+
+
try:
import gdb
RPyType() # side effects
+ gdb.pretty_printers.append(rpy_string_lookup)
except ImportError:
pass
diff --git a/pypy/tool/test/test_gdb_pypy.py b/pypy/tool/test/test_gdb_pypy.py
--- a/pypy/tool/test/test_gdb_pypy.py
+++ b/pypy/tool/test/test_gdb_pypy.py
@@ -118,3 +118,18 @@
gdb = FakeGdb(exprs, progspace)
cmd = gdb_pypy.RPyType(gdb)
assert cmd.do_invoke('*myvar', True) == 'GcStruct yyy {}'
+
+def test_pprint_string():
+ d = {'_gcheader': {
+ 'h_tid': 123
+ },
+ 'rs_hash': 456,
+ 'rs_chars': {
+ 'length': 6,
+ 'items': map(ord, 'foobar'),
+ }
+ }
+ string = Value(d)
+ string.type.tag = 'pypy_rpy_string0'
+ printer = gdb_pypy.rpy_string_lookup(string)
+ assert printer.to_string() == "'foobar' (rpy)"
More information about the pypy-commit
mailing list