Reputation: 11
Say I have a struct
struct Foo
{
void* bar;
const char* barTypeName;
}
bar
is some type erased thing and barTypeName
is a proper C++ type identifier that identifies the actual type of bar
.
I want to visualize this in the Visual Studio debugger, particularly in the Watch window. There's no template involved that can give me the proper type. The type itself is frequently POD and the debugger isn't able to figure out the type automatically.
Question: Is there any way in natvis to tell the debugger the type of bar
so it displays properly in the Watch window?
I stumbled on <MostDerivedType>
in the natvis schema, but it's not documented as far as I can tell and I can't tell if it does what I'm after or not.
I'm happy enough to use <CustomVisualizer>
and implement this in C++ if it provides a way to handle this and natvis does not.
Upvotes: 1
Views: 745
Reputation: 16771
That is quite simple if you are willing to add a DisplayString
for each wrapped POD. If you want a generic solution, that might not be possible.
<Type Name="Foo">
<DisplayString Condition='strcmp(barTypeName,"char")'>{(char)bar}</DisplayString>
<DisplayString Condition='strcmp(barTypeName,"int")'>{(int)bar}</DisplayString>
</Type>
Code for testing:
char c{};
int i{};
Foo fooc{ &c, "char" };
Foo fooi{ &i, "int" };
And this is the result in the VS 2019 (16.11.11) debugger:
Upvotes: 1