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,

when the value is structured, kdevelop does not display the value's 
description (as generated by the pretty printer) at all and Eclipse displays 
it somewhere below for the selected variable but it always requires a lot of 
scrolling to get this information into view. (I cannot tell what Qt Creator 
does because it does currently not cooperate with gdb on my system.) Now with 
your proposal to reduce redundancy, use and weak counts will not be displayed 
at all or not in a convienent way. I agree with you that is a shortcoming in 
gdb integration.

There is another problem with pretty printing a smart pointer with a managed 
value: gdb will recursively pretty print the managed value, which might result 
in a string filling several screens. Hence for command-line debugging, the gdb 
pretty printer should probably not recurse at all for smart-pointer types. So 
either we need different pretty printers for console and IDE debugging or we 
have to use the same pretty printer in different ways. (Can recursive pretty 
printing be disabled for selected types?)

Regards,
Michael

On Wednesday 24 April 2013 11:54:27 you wrote:
> On 24 April 2013 09:50, Michael Marte wrote:
> > 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.
> 
> This sounds like a deficiency of those debugger GUIs.
> 
> With your patch I get this in GDB, which is totally redundant:
> 
> (gdb) p sp
> p       sp
> $1 = std::shared_ptr (usecount 1, weakcount 2) to 0x605028 = {Use
> count = 1, Weak count = 2,
>   Managed value = 0x605028}
> (gdb) p wp
> p       wp
> $2 = std::weak_ptr (usecount 1, weakcount 2) to 0x605028 = {Use count
> = 1, Weak count = 2,
>   Managed value = 0x605028}
> (gdb) p wpv
> p       wpv
> $3 = std::weak_ptr (usecount 1, weakcount 2) to 0x605028 = {Use count
> = 1, Weak count = 2,
>   Managed value = 0x605028}
> (gdb) p up
> p       up
> $4 = std::unique_ptr<double> containing 0x605040 = {Managed value =
> 0x605040}
> 
> Why would we want the same information repeated twice?
> 
> I do think changing (count 1, weak 2) to (usecount 1, weakcount 2) is
> an improvement though.  I also have a patch to change shared_ptr to
> shared_ptr<int>, which is more useful.
> 
> Would it work if we changed the output to this?
> 
> $1 = std::shared_ptr<int> (usecount 1, weakcount 2) { 0x605028 }
> $2 = std::weak_ptr<int> (usecount 1, weakcount 2) { 0x605028 }
> $4 = std::unique_ptr<double> { 0x605040 }
> 
> i.e. add the type to the shared/weak ptr, and print only the pointer
> as the child value?
> 
> > I have not yet submitted a GCC copyright assignment to the FSF. Is this
> > necessary for a minor addition to an optional add-on?
> 
> I think your patch might count as minor enough not to require it, but
> in general yes, see http://gcc.gnu.org/contribute.html for more
> details.


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