如何使用natvis可视化简单的std :: string? [英] How to visualise a simple std::string with natvis?

查看:121
本文介绍了如何使用natvis可视化简单的std :: string?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试时,我无法对VS2015中的基本std:string有一个体面的看法。
我按照此地址上给出的说明进行操作:



我想直接将我的变量 str (而不是非常复杂的树)视为测试值)。您能帮我这个忙吗?

解决方案

我找到了答案,由于一个非常奇怪的原因,我找到了stl.natvis文件在我的VS安装目录中(对我来说, C:\Program Files(x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers )和调试器不会自动识别我添加到项目中的



所以解决方案是添加另一个调试器可视化文件(.natvis)到我的解决方案中(右键单击->添加新项),并复制/粘贴 stl.natvis 文件到这个新文件。重建后,调试器会适当显示标准std:string。



为完整起见,请参见 stl.natvis 的以下部分,该部分涉及Visual Studio的std :: string

 <!-VC 2015-> 
< Type Name = std :: basic_string& lt; char,*& gt;>
< DisplayString Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> {_ Mypair._Myval2._Bx._Buf,na}< / DisplayString>
< DisplayString Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> {_ Mypair._Myval2._Bx._Ptr,na}< / DisplayString>
< StringView Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Buf,na< / StringView>
< StringView Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Ptr,na< / StringView>
< Expand>
< Item Name = [size] ExcludeView = simple> _Mypair._Myval2._Mysize< / Item>
<项目名称= [容量] ExcludeView =简单> _Mypair._Myval2._Myres< / Item>
< Item Name = [allocator] ExcludeView = simple> _Mypair< / Item>
< ArrayItems>
< Size> _Mypair._Myval2._Mysize< / Size>
< ValuePointer Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Buf< / ValuePointer>
< ValuePointer Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Ptr< / ValuePointer>
< / ArrayItems>
< / Expand>
< / Type>

< ;!-VC 2015->
<类型名称= std :: basic_string& lt; wchar_t,*& gt;>
< AlternativeType Name = std :: basic_string& lt; unsigned short,*& gt; />
< AlternativeType Name = std :: basic_string& lt; char16_t,*& gt; />
< DisplayString Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> {_ Mypair._Myval2._Bx._Buf,su}< / DisplayString>
< DisplayString Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> {_ Mypair._Myval2._Bx._Ptr,su}< / DisplayString>
< StringView Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Buf,su< / StringView>
< StringView Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Ptr,su< / StringView>
< Expand>
< Item Name = [size] ExcludeView = simple> _Mypair._Myval2._Mysize< / Item>
<项目名称= [容量] ExcludeView =简单> _Mypair._Myval2._Myres< / Item>
< Item Name = [allocator] ExcludeView = simple> _Mypair< / Item>
< ArrayItems>
< Size> _Mypair._Myval2._Mysize< / Size>
< ValuePointer Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Buf< / ValuePointer>
< ValuePointer Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Ptr< / ValuePointer>
< / ArrayItems>
< / Expand>
< / Type>

<类型名称= std :: basic_string& lt; char32_t,*& gt;>
< DisplayString Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> {_ Mypair._Myval2._Bx._Buf,s32}< / DisplayString>
< DisplayString Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> {_ Mypair._Myval2._Bx._Ptr,s32}< / DisplayString>
< StringView Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Buf,s32< / StringView>
< StringView Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Ptr,s32< / StringView>
< Expand>
< Item Name = [size] ExcludeView = simple> _Mypair._Myval2._Mysize< / Item>
<项目名称= [容量] ExcludeView =简单> _Mypair._Myval2._Myres< / Item>
< Item Name = [allocator] ExcludeView = simple> _Mypair< / Item>
< ArrayItems>
< Size> _Mypair._Myval2._Mysize< / Size>
< ValuePointer Condition = _ Mypair._Myval2._Myres& lt; _Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Buf< / ValuePointer>
< ValuePointer Condition = _ Mypair._Myval2._Myres& gt; = __Mypair._Myval2._BUF_SIZE> _Mypair._Myval2._Bx._Ptr< / ValuePointer>
< / ArrayItems>
< / Expand>
< / Type>






编辑



请参阅下面的最终监视控制台:
(还请注意,您只应复制 stl.natvis 您想要的,似乎完整复制/粘贴不起作用。)




I can't have a decent view of a basic std:string in VS2015 while debugging. I followed the instructions given at this address :https://msdn.microsoft.com/fr-fr/library/jj620914.aspx (that is debugger type set to native mode, and uncheck both Use Managed Compatibility Mode and Use Native Compatibility Mode) . I have also added the stl.nativs file to my solution.

Currently my debugger looks like :

I would like to see as a value directly "test" for my variable str (instead of a very complex tree). Can you help me with this ?

解决方案

I find the answer, for a very strange reason the stl.natvis file that I found in my VS Installation directory ( C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers for me ) and that I have added to my project is not recognised by the debugger automatically.

So the solution was to add another Debugger visualization file (.natvis) to my solution (right click ->add new item ) and to copy/past the content of the stl.natvis file to this new file. After rebuild, the standard std:string is appropriately displayed by the debugger.

For completeness, see below the part of the stl.natvis that deals with std::string for visual studio 2015.

<!-- VC 2015 -->
  <Type Name="std::basic_string&lt;char,*&gt;">
    <DisplayString Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">{_Mypair._Myval2._Bx._Buf,na}</DisplayString>
    <DisplayString Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">{_Mypair._Myval2._Bx._Ptr,na}</DisplayString>
    <StringView Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Buf,na</StringView>
    <StringView Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Ptr,na</StringView>
    <Expand>
      <Item Name="[size]" ExcludeView="simple">_Mypair._Myval2._Mysize</Item>
      <Item Name="[capacity]" ExcludeView="simple">_Mypair._Myval2._Myres</Item>
      <Item Name="[allocator]" ExcludeView="simple">_Mypair</Item>
      <ArrayItems>
        <Size>_Mypair._Myval2._Mysize</Size>
        <ValuePointer Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Buf</ValuePointer>
        <ValuePointer Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Ptr</ValuePointer>
      </ArrayItems>
    </Expand>
  </Type>

  <!-- VC 2015 -->
  <Type Name="std::basic_string&lt;wchar_t,*&gt;">
    <AlternativeType Name="std::basic_string&lt;unsigned short,*&gt;" />
    <AlternativeType Name="std::basic_string&lt;char16_t,*&gt;" />
    <DisplayString Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">{_Mypair._Myval2._Bx._Buf,su}</DisplayString>
    <DisplayString Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">{_Mypair._Myval2._Bx._Ptr,su}</DisplayString>
    <StringView Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Buf,su</StringView>
    <StringView Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Ptr,su</StringView>
    <Expand>
      <Item Name="[size]" ExcludeView="simple">_Mypair._Myval2._Mysize</Item>
      <Item Name="[capacity]" ExcludeView="simple">_Mypair._Myval2._Myres</Item>
      <Item Name="[allocator]" ExcludeView="simple">_Mypair</Item>
      <ArrayItems>
        <Size>_Mypair._Myval2._Mysize</Size>
        <ValuePointer Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Buf</ValuePointer>
        <ValuePointer Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Ptr</ValuePointer>
      </ArrayItems>
    </Expand>
  </Type>

  <Type Name="std::basic_string&lt;char32_t,*&gt;">
    <DisplayString Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">{_Mypair._Myval2._Bx._Buf,s32}</DisplayString>
    <DisplayString Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">{_Mypair._Myval2._Bx._Ptr,s32}</DisplayString>
    <StringView Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Buf,s32</StringView>
    <StringView Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Ptr,s32</StringView>
    <Expand>
      <Item Name="[size]" ExcludeView="simple">_Mypair._Myval2._Mysize</Item>
      <Item Name="[capacity]" ExcludeView="simple">_Mypair._Myval2._Myres</Item>
      <Item Name="[allocator]" ExcludeView="simple">_Mypair</Item>
      <ArrayItems>
        <Size>_Mypair._Myval2._Mysize</Size>
        <ValuePointer Condition="_Mypair._Myval2._Myres &lt; _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Buf</ValuePointer>
        <ValuePointer Condition="_Mypair._Myval2._Myres &gt;= _Mypair._Myval2._BUF_SIZE">_Mypair._Myval2._Bx._Ptr</ValuePointer>
      </ArrayItems>
    </Expand>
  </Type>


Edit

See below the final watch console : (also please note that you should only copy part of the stl.natvis that you want, it seems that a full copy/past does not work.)

这篇关于如何使用natvis可视化简单的std :: string?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆