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: Fri, 12 Dec 2008 23:54:00 -0000	[thread overview]
Message-ID: <20081212235419.17591.qmail@sourceware.org> (raw)

The branch, archer-tromey-python has been updated
       via  c02fba96626764b3be627d97f1697e85e76ff6a3 (commit)
      from  ab8c44cb00aed42589972ef0e0cea4cb9d644fba (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c02fba96626764b3be627d97f1697e85e76ff6a3
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Dec 12 16:53:57 2008 -0700

    gdb
    	* python/lib/gdb/libstdcxx/v6/printers.py
    	(StdStringPrinter.display_hint): New method.
    	* python/python.c (apply_val_pretty_printer): Compute printer's
    	hint.
    	(print_string_repr): Add "hint" argument.  Recognize "string"
    	hint.
    	(print_children): Add "hint" argument.
    gdb/doc
    	* gdb.texinfo (Pretty Printing): Document 'string' hint.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                               |   10 ++++++++
 gdb/doc/ChangeLog                           |    4 +++
 gdb/doc/gdb.texinfo                         |   14 +++++++++--
 gdb/python/lib/gdb/libstdcxx/v6/printers.py |    3 ++
 gdb/python/python.c                         |   32 +++++++++++++++-----------
 5 files changed, 46 insertions(+), 17 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ef0bf91..6b857e5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2008-12-12  Tom Tromey  <tromey@redhat.com>
+
+	* python/lib/gdb/libstdcxx/v6/printers.py
+	(StdStringPrinter.display_hint): New method.
+	* python/python.c (apply_val_pretty_printer): Compute printer's
+	hint.
+	(print_string_repr): Add "hint" argument.  Recognize "string"
+	hint.
+	(print_children): Add "hint" argument.
+
 2008-12-10  Tom Tromey  <tromey@redhat.com>
 
 	* python/python.c: Include event-loop.h.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index d35643c..e194765 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-12-12  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Pretty Printing): Document 'string' hint.
+
 2008-12-10  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Basic Python): Document post_event.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ea6698c..fd17158 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18603,9 +18603,17 @@ Some display hints are predefined by @value{GDBN}:
 
 @table @samp
 @item map
-Indicate to the MI consumer that the object being printed is
-``map-like'', and that the children of this value can be assumed to
-alternate between keys and values.
+Indicate that the object being printed is ``map-like'', and that the
+children of this value can be assumed to alternate between keys and
+values.
+
+@item string
+Indicate that the object being printed is ``string-like''.  If the
+printer's @code{to_string} method returns a Python string of some
+kind, then @value{GDBN} will call its internal language-specific
+string-printing function to format the string.  For the CLI this means
+adding quotation marks, possibly escaping some characters, respecting
+@code{set print elements}, and the like.
 @end table
 @end defop
 
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index a7964c5..1ea4dd2 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -393,6 +393,9 @@ class StdStringPrinter:
             encoding = encoding.value
         return self.val['_M_dataplus']['_M_p'].string(encoding)
 
+    def display_hint (self):
+        return 'string'
+
 class Tr1HashtableIterator:
     def __init__ (self, hash):
         self.count = 0
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 1432e5e..c2d4897 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -991,7 +991,8 @@ gdbpy_get_display_hint (PyObject *printer)
 /* Helper for apply_val_pretty_printer which calls to_string and
    formats the result.  */
 static void
-print_string_repr (PyObject *printer, struct ui_file *stream, int recurse,
+print_string_repr (PyObject *printer, const char *hint,
+		   struct ui_file *stream, int recurse,
 		   const struct value_print_options *options,
 		   const struct language_defn *language)
 {
@@ -1001,7 +1002,11 @@ print_string_repr (PyObject *printer, struct ui_file *stream, int recurse,
   output = pretty_print_one_value (printer, &replacement);
   if (output)
     {
-      fputs_filtered (output, stream);
+      if (hint && !strcmp (hint, "string"))
+	LA_PRINT_STRING (stream, (gdb_byte *) output, strlen (output),
+			 1, 0, options);
+      else
+	fputs_filtered (output, stream);
       xfree (output);
     }
   else if (replacement)
@@ -1013,12 +1018,12 @@ print_string_repr (PyObject *printer, struct ui_file *stream, int recurse,
 /* Helper for apply_val_pretty_printer that formats children of the
    printer, if any exist.  */
 static void
-print_children (PyObject *printer, struct ui_file *stream, int recurse,
+print_children (PyObject *printer, const char *hint,
+		struct ui_file *stream, int recurse,
 		const struct value_print_options *options,
 		const struct language_defn *language)
 {
-  char *hint;
-  int is_map = 0, i;
+  int is_map, i;
   PyObject *children, *iter;
   struct cleanup *cleanups;
 
@@ -1026,12 +1031,7 @@ print_children (PyObject *printer, struct ui_file *stream, int recurse,
     return;
 
   /* If we are printing a map, we want some special formatting.  */
-  hint = gdbpy_get_display_hint (printer);
-  if (hint)
-    {
-      is_map = ! strcmp (hint, "map");
-      xfree (hint);
-    }
+  is_map = hint && ! strcmp (hint, "map");
 
   children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
 					 NULL);
@@ -1135,7 +1135,7 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 {
   PyObject *func, *printer;
   struct value *value;
-  char *hint;
+  char *hint = NULL;
   struct cleanup *cleanups;
   int result = 0;
   PyGILState_STATE state;
@@ -1160,11 +1160,15 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
       goto done;
     }
 
+  /* If we are printing a map, we want some special formatting.  */
+  hint = gdbpy_get_display_hint (printer);
+  make_cleanup (free_current_contents, &hint);
+
   make_cleanup_py_decref (printer);
   if (printer != Py_None)
     {
-      print_string_repr (printer, stream, recurse, options, language);
-      print_children (printer, stream, recurse, options, language);
+      print_string_repr (printer, hint, stream, recurse, options, language);
+      print_children (printer, hint, stream, recurse, options, language);
 
       result = 1;
     }


hooks/post-receive
--
Repository for Project Archer.


             reply	other threads:[~2008-12-12 23:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-12 23:54 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-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-22 18:18 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=20081212235419.17591.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).