From 14fe0f6ec4c529cecd47da696e8e916f84ddc862 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 3 Feb 2010 16:58:43 -0500 Subject: Make it easy to switch between repr() and pformat() when sending pretty-print data to gdb --- libpython.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'libpython.py') 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*)" -- cgit