natvis调试自定义可视化

natvis

vs studio的natvis存放在

%VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers

vscode指定natvis

launch.json中指定,"visualizerFile": ""

microsoft官方示例native-debugger-objects-in-natvis

c 复制代码
class CDog
{
public:
   CDog(){m_age = 8; m_weight = 30;}
   long m_age;
   long m_weight;
};
int main()
{
   CDog MyDog;
   printf_s("%d, %d\n", MyDog.m_age, MyDog.m_weight);
   return 0;
}

针对dog类定义dog.natvis文件,内容如下

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="https://schemas.microsoft.com/vstudio/debugger/natvis/2010">
   <Type Name="CDog">
      <DisplayString>{{Age = {m_age} years. Weight = {m_weight} pounds.}}</DisplayString>
   </Type>
</AutoVisualizer>

开发vs studio natvis插件源码,https://github.com/microsoft/ConcordExtensibilitySamples.git,需要安装vs sdk插件扩展,编译生成vsix插件安装包

双击vsix安装,内部实现了natvis代码方式的实现,和拷贝natvis到vs studio指定目录效果一样

linux上使用vscode可以全局搜索stl.natvis,使用visualizerFile配置指定文件


[Visualized View]:Explicit refresh required for visualized expressions

launch.json文件中需要添加"showDisplayString":true,解析错误提示

{ size=-var-create: unable to create variable object }