From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15338 invoked by alias); 13 Dec 2008 00:37:54 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 15312 invoked by uid 306); 13 Dec 2008 00:37:54 -0000 Date: Sat, 13 Dec 2008 00:37:00 -0000 Message-ID: <20081213003754.15297.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: c02fba96626764b3be627d97f1697e85e76ff6a3 X-Git-Newrev: d14f9aff2d79fcf0a60528377c57a33ce6c966e9 X-SW-Source: 2008-q4/txt/msg00201.txt.bz2 List-Id: The branch, archer-tromey-python has been updated via d14f9aff2d79fcf0a60528377c57a33ce6c966e9 (commit) from c02fba96626764b3be627d97f1697e85e76ff6a3 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit d14f9aff2d79fcf0a60528377c57a33ce6c966e9 Author: Tom Tromey Date: Fri Dec 12 17:37:30 2008 -0700 gdb * python/lib/gdb/libstdcxx/v6/printers.py (StdVectorPrinter.display_hint): Return 'array'. (StdDequePrinter.display_hint): New method. (StdStackOrQueuePrinter.display_hint): Likewise. * python/python.c (print_children): Handle "array" hint. Respect "print elements". gdb/doc * gdb.texinfo (Pretty Printing): Document 'array' hint. ----------------------------------------------------------------------- Summary of changes: gdb/ChangeLog | 9 ++++++ gdb/doc/ChangeLog | 4 +++ gdb/doc/gdb.texinfo | 5 +++ gdb/python/lib/gdb/libstdcxx/v6/printers.py | 10 ++++++- gdb/python/python.c | 38 ++++++++++++++++++++++++--- 5 files changed, 61 insertions(+), 5 deletions(-) First 500 lines of diff: diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6b857e5..1e6ddb5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,6 +1,15 @@ 2008-12-12 Tom Tromey * python/lib/gdb/libstdcxx/v6/printers.py + (StdVectorPrinter.display_hint): Return 'array'. + (StdDequePrinter.display_hint): New method. + (StdStackOrQueuePrinter.display_hint): Likewise. + * python/python.c (print_children): Handle "array" hint. Respect + "print elements". + +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. diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index e194765..651b91d 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,5 +1,9 @@ 2008-12-12 Tom Tromey + * gdb.texinfo (Pretty Printing): Document 'array' hint. + +2008-12-12 Tom Tromey + * gdb.texinfo (Pretty Printing): Document 'string' hint. 2008-12-10 Tom Tromey diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index fd17158..eeaaf61 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18602,6 +18602,11 @@ being printed. Some display hints are predefined by @value{GDBN}: @table @samp +@item array +Indicate that the object being printed is ``array-like''. The CLI +uses this to respect parameters such as @code{set print elements} and +@code{set print array}. + @item map Indicate that the object being printed is ``map-like'', and that the children of this value can be assumed to alternate between keys and diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py index 1ea4dd2..c03c682 100644 --- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py +++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py @@ -143,7 +143,7 @@ class StdVectorPrinter: % (int (finish - start), int (end - start))) def display_hint(self): - return 'whatever' + return 'array' class StdStackOrQueuePrinter: "Print a std::stack or std::queue" @@ -159,6 +159,11 @@ class StdStackOrQueuePrinter: return '%s wrapping: %s' % (self.typename, self.visualizer.to_string()) + def display_hint (self): + if hasattr (self.visualizer, 'display_hint'): + return self.visualizer.display_hint () + return None + class RbtreeIterator: def __init__(self, rbtree): self.size = rbtree['_M_t']['_M_impl']['_M_node_count'] @@ -361,6 +366,9 @@ class StdDequePrinter: return self._iter(start['_M_node'], start['_M_cur'], start['_M_last'], end['_M_cur'], self.buffer_size) + def display_hint (self): + return 'array' + class WideEncoding (gdb.Parameter): """The target wide character set is the encoding used for wchar_t.""" diff --git a/gdb/python/python.c b/gdb/python/python.c index c2d4897..36e8356 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1023,15 +1023,18 @@ print_children (PyObject *printer, const char *hint, const struct value_print_options *options, const struct language_defn *language) { - int is_map, i; + int is_map, is_array, done_flag; + unsigned int i; PyObject *children, *iter; struct cleanup *cleanups; if (! PyObject_HasAttr (printer, gdbpy_children_cst)) return; - /* If we are printing a map, we want some special formatting. */ + /* If we are printing a map or an array, we want some special + formatting. */ is_map = hint && ! strcmp (hint, "map"); + is_array = hint && ! strcmp (hint, "array"); children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst, NULL); @@ -1051,14 +1054,20 @@ print_children (PyObject *printer, const char *hint, } make_cleanup_py_decref (iter); - for (i = 0; ; ++i) + done_flag = 0; + for (i = 0; i < options->print_max; ++i) { PyObject *py_v, *item = PyIter_Next (iter); char *name; struct cleanup *inner_cleanup; if (! item) - break; + { + /* Set a flag so we can know whether we printed all the + available elements. */ + done_flag = 1; + break; + } if (! PyArg_ParseTuple (item, "sO", &name, &py_v)) { @@ -1068,6 +1077,11 @@ print_children (PyObject *printer, const char *hint, } inner_cleanup = make_cleanup_py_decref (item); + /* Print initial "{". For other elements, there are three + cases: + 1. Maps. Print a "," after each value element. + 2. Arrays. Always print a ",". + 3. Other. Always print a ",". */ if (i == 0) fputs_filtered (" = {", stream); else if (! is_map || i % 2 == 0) @@ -1081,6 +1095,13 @@ print_children (PyObject *printer, const char *hint, if (is_map && i % 2 == 0) fputs_filtered ("[", stream); + else if (is_array) + { + /* We print the index, not whatever the child method + returned as the name. */ + if (options->print_array_indexes) + fprintf_filtered (stream, "[%d] = ", i); + } else if (! is_map) { fputs_filtered (name, stream); @@ -1114,6 +1135,15 @@ print_children (PyObject *printer, const char *hint, if (i) { + if (!done_flag) + { + if (options->pretty) + { + fputs_filtered ("\n", stream); + print_spaces_filtered (2 + 2 * recurse, stream); + } + fputs_filtered ("...", stream); + } if (options->pretty) { fputs_filtered ("\n", stream); hooks/post-receive -- Repository for Project Archer.