This is the mail archive of the 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

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:// 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.

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