From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31354 invoked by alias); 22 Oct 2008 18:18:03 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 31321 invoked by uid 306); 22 Oct 2008 18:18:02 -0000 Date: Wed, 22 Oct 2008 18:18:00 -0000 Message-ID: <20081022181802.31306.qmail@sourceware.org> From: tromey@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-tromey-python: gdb X-Git-Refname: refs/heads/archer-tromey-python X-Git-Reftype: branch X-Git-Oldrev: ec3d8bea908d94df0b4222d876ff779add5494af X-Git-Newrev: be28390bda0775ce506162b7adacf2a4f6fb0c41 X-SW-Source: 2008-q4/txt/msg00038.txt.bz2 List-Id: The branch, archer-tromey-python has been updated via be28390bda0775ce506162b7adacf2a4f6fb0c41 (commit) from ec3d8bea908d94df0b4222d876ff779add5494af (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit be28390bda0775ce506162b7adacf2a4f6fb0c41 Author: Tom Tromey Date: Wed Oct 22 12:17:56 2008 -0600 gdb * python/python.c (_initialize_python) <_format_children>: Call to_string, not header. (pretty_print_one_value): Call _format_children if either 'children' to 'to_string' exists. gdb/doc * gdb.texinfo (Pretty Printing): Remove 'header'. gdb/testsuite * gdb.python/python-prettyprint.py (ContainerPrinter.to_string): Rename from 'header'. ----------------------------------------------------------------------- Summary of changes: gdb/ChangeLog | 7 ++++++ gdb/doc/ChangeLog | 4 +++ gdb/doc/gdb.texinfo | 21 +++---------------- gdb/python/python.c | 25 +++++++++++++---------- gdb/testsuite/ChangeLog | 5 ++++ gdb/testsuite/gdb.python/python-prettyprint.py | 2 +- 6 files changed, 35 insertions(+), 29 deletions(-) First 500 lines of diff: diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8c5474a..a8cfa41 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2008-10-22 Tom Tromey + + * python/python.c (_initialize_python) <_format_children>: Call + to_string, not header. + (pretty_print_one_value): Call _format_children if either + 'children' to 'to_string' exists. + 2008-10-21 Tom Tromey * varobj.c (update_dynamic_varobj_children): Copy value when diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 8831116..ab28b52 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2008-10-22 Tom Tromey + + * gdb.texinfo (Pretty Printing): Remove 'header'. + 2008-10-20 Tom Tromey * gdb.texinfo (GDB/MI Miscellaneous Commands): Mention 'python' diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index edbf51e..83c6280 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -17951,17 +17951,6 @@ using Python code. This mechanism works for both MI and the CLI. A pretty-printer is an object that implements a specific interface. There is no predefined base class for pretty-printers. -@c FIXME I think perhaps we should nuke header and just use to_string -@c Investigate. - -@defop Operation {pretty printer} header (self, val) -If this method exists, @value{GDBN} may call it when printing a value -from the CLI. In particular, it will be called if the pretty-printer -does not define the @code{to_string} method. The method must return a -string. This string will be displayed before any children of the -value being printed. -@end defop - @defop Operation {pretty printer} children (self, val) This method is used by both the MI and CLI code. When printing a value, @value{GDBN} will call this method to display the children of @@ -17992,13 +17981,11 @@ This method is used by both the MI and CLI code. When printing a value, @value{GDBN} will call this method to display the string representation of @var{val}, an instance of @code{gdb.Value}. -This method must return a string. - -@c FIXME -- this is where the oddity arises. Don't we do something -@c different for MI? When printing from the CLI, if the @code{to_string} method exists, -then @value{GDBN} will print its result, and will not call -@code{header} and @code{children}. +then @value{GDBN} will prepend its result to the values returned by +@code{children}. + +This method must return a string. @end defop @subsubsection Selecting CLI Pretty-Printers diff --git a/gdb/python/python.c b/gdb/python/python.c index 55de351..3541712 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -687,21 +687,24 @@ pretty_print_one_value (PyObject *func, struct value *value, val_obj = value_to_value_object (value); - /* The function might be an MI-style class with a to_string - method, or it might be an ordinary function. FIXME: should - also check for the 'children' method here. */ - if (PyObject_HasAttr (func, gdbpy_to_string_cst)) - result = PyObject_CallMethodObjArgs (func, gdbpy_to_string_cst, - val_obj, NULL); - else if (children - && PyObject_HasAttr (func, gdbpy_children_cst) - && PyObject_HasAttrString (gdb_module, "_format_children")) + /* The function might be an MI-style class, or it might be an + ordinary function. If CHILDREN is true, the existence of + either the to_string or children methods means to call + _format_children. Otherwise, if we have to_string, call it. + As a last resort, call the object as a function. */ + if (children + && (PyObject_HasAttr (func, gdbpy_children_cst) + || PyObject_HasAttr (func, gdbpy_to_string_cst)) + && PyObject_HasAttrString (gdb_module, "_format_children")) { PyObject *fmt = PyObject_GetAttrString (gdb_module, "_format_children"); result = PyObject_CallFunctionObjArgs (fmt, func, val_obj, NULL); Py_DECREF (fmt); } + else if (PyObject_HasAttr (func, gdbpy_to_string_cst)) + result = PyObject_CallMethodObjArgs (func, gdbpy_to_string_cst, + val_obj, NULL); else result = PyObject_CallFunctionObjArgs (func, val_obj, NULL); if (result) @@ -1047,8 +1050,8 @@ sys.stdout = GdbOutputFile()\n\ PyRun_SimpleString ("\ def _format_children(obj, val):\n\ result = []\n\ - if hasattr(obj, 'header'):\n\ - result.append(obj.header(val))\n\ + if hasattr(obj, 'to_string'):\n\ + result.append(obj.to_string(val))\n\ max = gdb.get_parameter('print elements')\n\ i = 0\n\ for elt in obj.children(val):\n\ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 5d03fb5..66ba18d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2008-10-22 Tom Tromey + * gdb.python/python-prettyprint.py (ContainerPrinter.to_string): + Rename from 'header'. + +2008-10-22 Tom Tromey + * gdb.python/python-prettyprint.py: Add MI pretty printer. * gdb.python/python-mi.exp: New file. * lib/mi-support.exp (mi_child_regexp): New proc. diff --git a/gdb/testsuite/gdb.python/python-prettyprint.py b/gdb/testsuite/gdb.python/python-prettyprint.py index 2c30ef3..abb46d7 100644 --- a/gdb/testsuite/gdb.python/python-prettyprint.py +++ b/gdb/testsuite/gdb.python/python-prettyprint.py @@ -38,7 +38,7 @@ class ContainerPrinter: self.pointer = self.pointer + 1 return ('[%d]' % int (result - self.start), result.dereference()) - def header(self, val): + def to_string(self, val): return 'container %s with %d elements' % (val['name'], val['len']) def children(self, val): hooks/post-receive -- Repository for Project Archer.