I try to start with C++, Cmake. Now I find the possibility to customize the debugger view in Visual Studio 2022 with the natvis file. The file is used by the debugger, but actually I don't understand how I can display the item of a containing std::vector and std::map. The objects itself works fine. My goal is to show the Entry class with the childs in the vector and the Lookup with the pairs in the map. I found so far some descriptions how I can display a std::vector<>, but I don't want to change the view for all maps and vectors, instead only for the booth containing in the objects Lookup and Entry. Or more precise, to show the vector entries in the Entry debugger view as if they belong to this object.
How can this handled? My only experience is actually with C# and there this is all done by the debugger itself with reflections. Is its the correct way to write a ITEM for the Lookup to display the map entries nicer, or have I to write an additional entry for the map and vector?
Here are the classes for a nicer display in the debugger:
namespace is myApp
class Domain{
private:
std::string m_domainName;
}
class Entry{
private:
std::string m_rawValue;
std::string m_readableName;
std::vector<Entry *> m_childs;
}
class Lookup{
private:
bool m_initSuccess;
std::map<Domain, Entry> m_database;
}
Expected Debugger view:
Class Lookup:
Lookup: no init -> m_database.size()==0
Lookup: entries: <m_database.size()>
+- init: true
+- [0]: <m_domainName>, childs: <Entry.m_childs.size()> (pair<Domain, Entry> object)
+- [0]: Name: <m_rawValue>: <m_readableName>, Childs: <m_childs.size()> (Entry object)
+- [0]: Name: <m_rawValue>: <m_readableName> (Entry object)
+- [1]: Name: <m_rawValue>: <m_readableName> (Entry object)
+- [1]: Name: <m_rawValue>: <m_readableName>, Childs: <m_childs.size()> (Entry object) (Entry object)
Class Entry:
Entry: <m_rawValue>: <m_readableName>, Childs: <elements in vector>
+- [0]: <m_rawValue>: <m_readableName>
+- [1]: <m_rawValue>: <m_readableName>
and so on. My idea was to create a Natvis like the following:
My Natvis entries:
<Type Name="myApp::Domain">
<DisplayString>Domain: {m_domainName}</DisplayString>
<Expand>
<Item Name="[lDomain]" ExcludeView="simple">m_lowerDomainName</Item>
</Expand>
</Type>
<Type Name="myApp::Entry">
<DisplayString Condition="m_childs.size()==0">Entry: {m_rawValue}: {m_readableName}</DisplayString>
<DisplayString>Entry: {m_rawValue}: {m_readableName}, Childs: {m_childs.size()}</DisplayString>
<Expand>
<Item Name="[Raw]" ExcludeView="simple">m_lowerDomainName</Item>
<Item Name="[Value]" ExcludeView="simple">m_lowerDomainName</Item>
<Item Name="[Childs]" ExcludeView="simple">m_childs.size()</Item>
</Expand>
</Type>
<Type Name="myApp::Lookup">
<DisplayString Condition="m_childs.size()==0">{m_rawValue}: {m_readableName}</DisplayString>
<DisplayString>{m_rawValue}: {m_readableName}, Childs: {m_childs.size()}</DisplayString>
<Expand>
<Item Name="[Raw]" ExcludeView="simple">m_lowerDomainName</Item>
<Item Name="[Value]" ExcludeView="simple">m_lowerDomainName</Item>
<Item Name="[Childs]" ExcludeView="simple">m_childs.size()</Item>
</Expand>
</Type>