diff options
author | Kent Cheung <kent.cheung@arm.com> | 2021-05-13 15:42:20 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-05-14 06:51:21 +0100 |
commit | ecf25064e87a3d2d59871b3ea7126fa0dee0001d (patch) | |
tree | da6aa892b6386531716e8e1b3b33f4168f09d3e4 /gdb/python | |
parent | 64654371d6324794d11131fc95c1bc4caaaf173d (diff) | |
download | binutils-ecf25064e87a3d2d59871b3ea7126fa0dee0001d.zip binutils-ecf25064e87a3d2d59871b3ea7126fa0dee0001d.tar.gz binutils-ecf25064e87a3d2d59871b3ea7126fa0dee0001d.tar.bz2 |
gdb: fix pretty printing max depth behaviour
The 'print max-depth' feature incorrectly causes GDB to skip printing
the string representation of pretty printed variables if the variable
is stored at a nested depth corresponding to the set max-depth value.
This change ensures that it is always printed before checking whether
the maximum print depth has been reached.
Regression tested with GCC 7.3.0 on x86_64, ppc64le, aarch64.
gdb/ChangeLog:
* cp-valprint.c (cp_print_value): Replaced duplicate code.
* guile/scm-pretty-print.c (ppscm_print_children): Check max_depth
just before printing child values.
(gdbscm_apply_val_pretty_printer): Don't check max_depth before
printing string representation.
* python/py-prettyprint.c (print_children): Check max_depth just
before printing child values.
(gdbpy_apply_val_pretty_printer): Don't check max_depth before
printing string representation.
gdb/testsuite/ChangeLog:
* gdb.python/py-format-string.c: Added a variable to test.
* gdb.python/py-format-string.exp: Check string representation is
printed at appropriate max_depth settings.
* gdb.python/py-nested-maps.exp: Likewise.
* gdb.guile/scm-pretty-print.exp: Add additional tests.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-prettyprint.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 7c0fdaa..fef4dcd 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -431,22 +431,29 @@ print_children (PyObject *printer, const char *hint, continue; } - /* Print initial "{". For other elements, there are three - cases: + /* Print initial "=" to separate print_string_repr output and + children. 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) - { - if (is_py_none) - fputs_filtered ("{", stream); - else - fputs_filtered (" = {", stream); - } - + { + if (!is_py_none) + fputs_filtered (" = ", stream); + } else if (! is_map || i % 2 == 0) fputs_filtered (pretty ? "," : ", ", stream); + /* Skip printing children if max_depth has been reached. This check + is performed after print_string_repr and the "=" separator so that + these steps are not skipped if the variable is located within the + permitted depth. */ + if (val_print_check_max_depth (stream, recurse, options, language)) + return; + else if (i == 0) + /* Print initial "{" to bookend children. */ + fputs_filtered ("{", stream); + /* In summary mode, we just want to print "= {...}" if there is a value. */ if (options->summary) @@ -597,9 +604,6 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang, if (printer == Py_None) return EXT_LANG_RC_NOP; - if (val_print_check_max_depth (stream, recurse, options, language)) - return EXT_LANG_RC_OK; - /* If we are printing a map, we want some special formatting. */ gdb::unique_xmalloc_ptr<char> hint (gdbpy_get_display_hint (printer.get ())); |