This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Improved pretty printing for smart pointers


Hi Jonathan,

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?

Michael


On 04/24/2013 09:48 AM, Jonathan Wakely wrote:
On 24 April 2013 07:08, Michael Marte wrote:
Hello *,

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
pointer.

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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]