This is the mail archive of the
mailing list for the libstdc++ project.
Re: Improved pretty printing for smart pointers
- From: Michael Marte <informarte at freenet dot de>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 24 Apr 2013 10:50:56 +0200
- Subject: Re: Improved pretty printing for smart pointers
- References: <201304240808 dot 07062 dot informarte at freenet dot de> <CAH6eHdSTExTTJqa=JfpkxFshbu0g3Kq53XjS9nJ+-SXkzZD-ng at mail dot gmail dot com>
I know that there are ways to dereference a smart pointer on the gdb
command line. But when using an IDE (like Eclipse CTD, Qt Creator or
kdevelop), the pretty printer, in its current state, is in the way: The
variable view of the debugger will show a message like
"std::shared_ptr (count 1, weak 0) 0x61e1a8"
and then you are stuck because there is no way to inspect the members of
the smart pointer. Of course there are workarounds (like all of the
above mentioned IDEs give access to the gdb command line and both
Eclipse CTD and Qt Creator support user-defined expressions, but
kdevelop does not, as it seems) but these workarounds are tedious and
make the browsing of large data structures painful.
I have not yet submitted a GCC copyright assignment to the FSF. Is this
necessary for a minor addition to an optional add-on?
On 04/24/2013 09:48 AM, Jonathan Wakely wrote:
On 24 April 2013 07:08, Michael Marte wrote:
I found the pretty printers for std::shared_ptr, std::weak_ptr and
std::unique_ptr (as provided by
svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python) not sufficient for
daily use as they only generate a description (including the address of
the pointee) but do not pretty print the pointee itself. This behaviour
implies that one has to copy the address of the pointee, cast it to the
pointee's type, and dereference the result.
Or you just say 'print *ptr' and GDB dereferences it for you, which is
the same as a built-in pointer.
This works for shared_ptr but not currently for unique_ptr, I'm not
sure why, I'll look into that (I also want to improve the output for a
unique_ptr with custom deleter)
For weak_ptr, which has no dereference operator to use but you can say
'print *wptr._M_ptr' (and that works for shared_ptr too)
To improve on the current
state of affairs, I improved the pretty printers to generate children.
For std::shared_ptr and std::weak_ptr, three children are generated,
namely "Use count", "Weak count", and "Managed value". For
std::unique_ptr, one child is generated, namely "Managed value". Using
this solution with an IDE like kdevelop or Eclipse CTD, it only needs
two clicks to see the value managed by a smart pointer.
I haven't checked what the output is, but I'm unsure about making this
change. I like having the smart pointers behave basically like a
built-in pointer. If you want the value you can dereference the
I attached my patch in the hope that you will find it interesting and
that it will be integrated into the suite of GCC STL pretty printers.
Do you have a GCC copyright assignment submitted to the FSF? That is
required before significant patches can be accepted. This might be
small enough to not require it though.