Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a visualizer for _Ref_count_obj_alloc3 and _Ref_count_obj2 #2811

Merged
merged 7 commits into from
Jun 25, 2022

Conversation

fsb4000
Copy link
Contributor

@fsb4000 fsb4000 commented Jun 21, 2022

Fixes #2787

test:

#include <memory>

int main() {
	std::allocator<int> alloc{};
	auto ms = std::make_shared<int>();
	auto as = std::allocate_shared<int>(alloc, 10);
        return 0;
}

изображение

Do we need some comments for them like <!-- VC 2019 --> ?

@fsb4000 fsb4000 requested a review from a team as a code owner June 21, 2022 17:18
@StephanTLavavej StephanTLavavej added the visualizer How the VS debugger displays STL types label Jun 21, 2022
@StephanTLavavej StephanTLavavej changed the title add a visializer for _Ref_count_obj_alloc3 and _Ref_count_obj2 add a visualizer for _Ref_count_obj_alloc3 and _Ref_count_obj2 Jun 21, 2022
@StephanTLavavej
Copy link
Member

Programmer-archaeology:

MSVC-PR-179257 "Comply with The Rules for allocator::construct.", merged 2019-05-08, shipped in VS 2019 16.3, introduced _Ref_count_obj2 and _Ref_count_obj_alloc2.

#309, merged 2020-04-08, shipped in VS 2019 16.7, introduced _Ref_count_obj_alloc3.

I don't think we absolutely need version comments, but I wouldn't object to them.

stl/debugger/STL.natvis Outdated Show resolved Hide resolved
@fsb4000
Copy link
Contributor Author

fsb4000 commented Jun 22, 2022

test code:

#include <memory>

template <typename T>
struct stateful_allocator
    : std::allocator<T>
{
    stateful_allocator() {}
    template <typename U> stateful_allocator(stateful_allocator<U> const&) {}

    typedef T value_type;
    template <typename U> struct rebind { typedef stateful_allocator<U> other; };
    T* allocate(size_t n) {
        return static_cast<T*>(operator new(n * sizeof(T)));
    }
    void deallocate(T* p, size_t) { operator delete(p); }
    int state = 0;
};

int main() {
	std::allocator<int> alloc{};
        stateful_allocator<int> salloc{};
	auto ms = std::make_shared<int>();
	auto as = std::allocate_shared<int>(alloc, 10);
        auto as2 = std::allocate_shared<int>(salloc, 10);
	return 0;
}

изображение

@fsb4000
Copy link
Contributor Author

fsb4000 commented Jun 22, 2022

I didn't test _Ref_count_obj_alloc2 but I hope it is correct because _Ref_count_obj_alloc2inherits from _Ebco_base, similar to _Ref_count_obj_alloc3

 class __declspec(empty_bases) _Ref_count_obj_alloc2 : public _Ebco_base<_Alloc>, public _Ref_count_base {
class _Ref_count_obj_alloc3 : public _Ebco_base<_Rebind_alloc_t<_Alloc, _Ty>>, public _Ref_count_base {

stl/debugger/STL.natvis Outdated Show resolved Hide resolved
stl/debugger/STL.natvis Show resolved Hide resolved
to match the rest of our XML formatting.
<Type Name="std::_Ref_count_obj2&lt;*&gt;">
<DisplayString>make_shared</DisplayString>
<Expand>
<Item Condition="_Uses != 0" Name="[original ptr]">($T1 *) &amp;_Storage</Item>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a fixed string to a _Uses == 0 condition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need to show a child item for an empty shared_ptr? (weak_ptrs will display themselves as expired, IIRC)

@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Copy link
Member

I've resolved a trivial merge conflict where #2804 deleted code next to this PR's addition.

@StephanTLavavej StephanTLavavej merged commit ad80eb7 into microsoft:main Jun 25, 2022
@StephanTLavavej
Copy link
Member

Thanks for fixing these important visualizers! 🎉 🚀 😸

@fsb4000 fsb4000 deleted the fix2787 branch June 26, 2022 02:31
fsb4000 added a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
visualizer How the VS debugger displays STL types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STL.natvis: make_shared and allocate_shared are no longer visualized properly
5 participants