From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17635 invoked by alias); 12 Dec 2008 23:54:20 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 17606 invoked by uid 306); 12 Dec 2008 23:54:19 -0000 Date: Fri, 12 Dec 2008 23:54:00 -0000 Message-ID: <20081212235419.17591.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: ab8c44cb00aed42589972ef0e0cea4cb9d644fba X-Git-Newrev: c02fba96626764b3be627d97f1697e85e76ff6a3 X-SW-Source: 2008-q4/txt/msg00200.txt.bz2 List-Id: 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 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 + + * 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 * 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 + + * gdb.texinfo (Pretty Printing): Document 'string' hint. + 2008-12-10 Tom Tromey * 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.