[Bug libstdc++/95547] gdb pretty-printing of std::unique_ptr less helpful than it could be

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jun 5 08:32:52 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95547

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to M Welinder from comment #0)
> This is with a fairly old compiler, but same behaviour observed with gcc10.

Old and unsupported, bugs should really be reported for current versions.

As you say, YMMV, other people want more information. And what gets printed in
the backtrace is decided by GDB anyway, not GCC. The pretty printers can't
control eliding the contents of the {...}. When printing the variables
explicitly you get the values you want:

(gdb) p p
$1 = std::optional<int> = {[contained value] = 14}
(gdb) up
(gdb) p p
$2 = std::shared_ptr<int> (use count 1, weak count 0) = {get() = 0x418ee0}
(gdb) up
(gdb) p p
$3 = std::unique_ptr<int> = {get() = 0x418eb0}

Changing those to just print a pointer value would not be an improvement. The
point of the pretty printers is to provide extra information, not be as brief
as the raw format for scalar values.

If you want less verbose output from the printers I suggest you modify
libstdc++-v3/python/libstdcxx/v6/printers.py to add a boolean flag that
switches between different output modes (verbose/concise) so that you can set
that within GDB (maybe in a gdbinit file). You would need to format the
contents as a string, not use the 'children' method to return a child value in
curly braces. Users who don't want the extra info can then disable it.

Or extend GDB itself to support two forms of output, the full one and an
abbreviated one for use in backtraces. Then change the libstdc++ printers to
add an extra method to each printer that returns the abbreviated form.


More information about the Gcc-bugs mailing list