Skip to content

STL.natvis: add error_code and error_category#3044

Closed
vinniefalco wants to merge 1 commit intomicrosoft:mainfrom
vinniefalco:main
Closed

STL.natvis: add error_code and error_category#3044
vinniefalco wants to merge 1 commit intomicrosoft:mainfrom
vinniefalco:main

Conversation

@vinniefalco
Copy link

Thanks for the low-hanging fruit :)

@vinniefalco vinniefalco requested a review from a team as a code owner August 19, 2022 21:28
@CaseyCarter CaseyCarter added the visualizer How the VS debugger displays STL types label Aug 19, 2022
Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! The checks are failing with:

.\stl\debugger\STL.natvis(1,1): error : Validation failed: file contains 6 lines with trailing whitespace.

@vinniefalco
Copy link
Author

You know...I'm just gonna put this out there... I use the Visual Studio IDE editor exclusively... I will update the pull request.

@CaseyCarter
Copy link
Contributor

For other reviewers: Paste this program

#include <future>
#include <ios>
#include <string>
#include <system_error>

struct my_error_category : public std::error_category {
	const char* name() const noexcept override {
		return "potato";
	}

	std::string message(int) const override {
		return "message goes here";
	}
};

int main() {
	auto& generic_cat = std::generic_category();
	auto& system_cat = std::system_category();
	auto& iostream_cat = std::iostream_category();
	auto& future_cat = std::future_category();
	const auto& my_cat = my_error_category();

	std::error_code generic(42, generic_cat);
	std::error_code system(42, system_cat);
	std::error_code iostream(42, iostream_cat);
	std::error_code future(42, future_cat);
	std::error_code my(42, my_cat);
}

into a VS project. Add a new natvis file with the new visualizers from the PR. Set a breakpoint at the final }, and let it rip.

Comment on lines +26 to +30
<DisplayString Condition="_Addr == 1">[future]</DisplayString>
<DisplayString Condition="_Addr == 3">[generic]</DisplayString>
<DisplayString Condition="_Addr == 5">[iostream]</DisplayString>
<DisplayString Condition="_Addr == 7">[system]</DisplayString>
<DisplayString>@{((uintptr_t)this),x}</DisplayString>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should:

Suggested change
<DisplayString Condition="_Addr == 1">[future]</DisplayString>
<DisplayString Condition="_Addr == 3">[generic]</DisplayString>
<DisplayString Condition="_Addr == 5">[iostream]</DisplayString>
<DisplayString Condition="_Addr == 7">[system]</DisplayString>
<DisplayString>@{((uintptr_t)this),x}</DisplayString>
<DisplayString>[{name(),sb}]</DisplayString>
<Expand>
<Synthetic Name="hint">
<DisplayString>Enable "Allow Function Calls In Value Formatting" if you see "???" here</DisplayString>
</Synthetic>
</Expand>

here. It requires "Allow Function Calls In Value Formatting" to be enabled in the debugger, but produces an identical experience for library-defined and user-defined error_categorys.



<Type Name="std::error_code">
<DisplayString>{_Myval} {*_Mycat}</DisplayString>
Copy link
Contributor

Choose a reason for hiding this comment

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

If we accept the above suggestion, we should also:

Suggested change
<DisplayString>{_Myval} {*_Mycat}</DisplayString>
<DisplayString>{_Myval} {*_Mycat}</DisplayString>
<Expand>
<Synthetic Name="hint">
<DisplayString>Enable "Allow Function Calls In Value Formatting" if you see "???" for the category</DisplayString>
</Synthetic>
</Expand>

for discoverability.

@StephanTLavavej
Copy link
Member

This visualizer needs to be updated now that #3139 has been merged.

@StephanTLavavej
Copy link
Member

Closing as this has been superseded by #3204. Thanks again for looking into this!

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.

3 participants