This project has moved. For the latest updates, please go here.

More pointer-like behaviour for boost::shared_ptr

Nov 13, 2014 at 8:46 AM
Hi,

I'm working on a project that makes extensive use of boost::shared_ptr. We use Visual Studio 2013 and I'm trying out these visualizers to improve the debug experience. The visualization of smart pointer types could be improved.

When I use a smart pointer, its most important feature is that it behaves like a pointer. I care most about where it points, and what it points to. Sometimes I want to see if two pointers are pointing at the same thing. Very often I want to examine the object pointed to. Maybe only once in the last year have I investigated reference counts to find out why an object has not been deleted. The problems I find with this shared_ptr visualizer are: 1) it says "shared_ptr" in the value, but the type field already tells me this. 2) It contains strong and weak reference counts in the value, but these are not important to me. 3) It doesn't give the pointer address in the value, that is important to me. 4) The pointer address is available on expansion, but then needs to be further expanded to get to the object, which is too many clicks.

Here is an alternative shared_ptr visualizer with the following properties: 1) Pointer address and object pointed to are the only things in the value field. 2) The object pointed to is expanded on smart-pointer expansion. 3) The reference counts are also shown in the smart pointer expansion.
<Type Name="boost::shared_ptr&lt;*&gt;">
    <DisplayString Condition="px == 0">empty</DisplayString>
    <DisplayString Condition="px != 0">{px} {*px}</DisplayString>
    <Expand>
        <ExpandedItem>px</ExpandedItem>
        <Item Condition="px != 0" Name="[strong refs]">pn.pi_-&gt;use_count_</Item>
        <Item Condition="px != 0" Name="[weak refs]">pn.pi_-&gt;weak_count_ - 1</Item>
        <Item Condition="px != 0" Name="[deleter and allocator]">*pn.pi_</Item>
    </Expand>
</Type>
Is it possible for the smart pointer visualizers to be switched to something more like this? I find it more useful for day-to-day debugging, and I think many other developers would too.