diff options
author | David Malcolm <dmalcolm@redhat.com> | 2010-02-03 16:58:43 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2010-02-03 16:58:43 -0500 |
commit | 14fe0f6ec4c529cecd47da696e8e916f84ddc862 (patch) | |
tree | 7db65a44bb765b79e054ac3c26ecbe920e58a98d | |
parent | 5e921ad97097af6a01a93feacc40c661bbb3d96d (diff) | |
download | libpython-14fe0f6ec4c529cecd47da696e8e916f84ddc862.tar.gz libpython-14fe0f6ec4c529cecd47da696e8e916f84ddc862.tar.xz libpython-14fe0f6ec4c529cecd47da696e8e916f84ddc862.zip |
Make it easy to switch between repr() and pformat() when sending pretty-print data to gdb
-rw-r--r-- | libpython.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/libpython.py b/libpython.py index b04f522..c42e0fd 100644 --- a/libpython.py +++ b/libpython.py @@ -219,6 +219,15 @@ class PyTypeObjectPtr(PyObjectPtr): def int_from_int(gdbval): return int(str(gdbval)) +def stringify(val): + # TODO: repr() puts everything on one line; pformat can be nicer, but + # can lead to v.long results; this function isolates the choice + if True: + return repr(val) + else: + from pprint import pformat + return pformat(val) + class FrameInfo: ''' Class representing all of the information we can scrape about a @@ -249,7 +258,7 @@ class FrameInfo: % (self.co_filename, self.f_lineno, self.co_name, - ', '.join(['%s=%s' % (k, repr(v)) for k, v in self.locals])) + ', '.join(['%s=%s' % (k, stringify(v)) for k, v in self.locals])) ) @@ -293,7 +302,7 @@ class PyObjectPtrPrinter: def to_string (self): proxyval = PyObjectPtr.from_pyobject_ptr(self.gdbval).proxyval() - return repr(proxyval) + return stringify(proxyval) class PyFrameObjectPtrPrinter(PyObjectPtrPrinter): "Prints a (PyFrameObject*)" |