public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: tromey@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  archer-tromey-python: gdb
Date: Wed, 22 Oct 2008 18:18:00 -0000	[thread overview]
Message-ID: <20081022181802.31306.qmail@sourceware.org> (raw)

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 <tromey@redhat.com>
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  <tromey@redhat.com>
+
+	* 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  <tromey@redhat.com>
 
 	* 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  <tromey@redhat.com>
+
+	* gdb.texinfo (Pretty Printing): Remove 'header'.
+
 2008-10-20  Tom Tromey  <tromey@redhat.com>
 
 	* 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  <tromey@redhat.com>
 
+	* gdb.python/python-prettyprint.py (ContainerPrinter.to_string):
+	Rename from 'header'.
+
+2008-10-22  Tom Tromey  <tromey@redhat.com>
+
 	* 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.


             reply	other threads:[~2008-10-22 18:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-22 18:18 tromey [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-04-07 20:28 tromey
2009-03-24 17:27 tromey
2009-02-05 19:56 tromey
2008-12-17 23:10 tromey
2008-12-15 22:38 tromey
2008-12-13  0:37 tromey
2008-12-12 23:54 tromey
2008-12-10 15:28 tromey
2008-12-09  0:33 tromey
2008-12-02 21:29 tromey
2008-12-01 19:10 tromey
2008-11-25 21:17 tromey
2008-11-21 18:25 tromey
2008-11-18 18:52 tromey
2008-11-18 15:54 tromey
2008-11-17 15:45 tromey
2008-11-16 22:18 tromey
2008-11-16 16:56 tromey
2008-11-12  1:54 tromey
2008-11-10 14:15 tromey
2008-11-06 21:11 tromey
2008-11-06 19:58 tromey
2008-10-23 22:27 tromey
2008-10-23 21:28 tromey
2008-10-21 18:32 tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081022181802.31306.qmail@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).