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


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]