【问题标题】:Natvis TreeItems definition not working on map<int,int>Natvis TreeItems 定义不适用于 map<int,int>
【发布时间】:2016-06-24 04:15:24
【问题描述】:

我在使用 Visual Studio 2015 的 natvis 扩展时遇到问题。 在我的努力中,我需要访问地图,但 natvis 的 TreeItems 节点似乎对我不起作用。我实际上正在使用示例代码:

<?xml version="1.0" encoding="utf-8"?> 
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">

  <Type Name="std::map&lt;*&gt;">
    <DisplayString>{{size = {_Mysize}}}</DisplayString>
    <Expand>
      <Item Name="[size]">_Mysize</Item>
      <Item Name="[comp]">comp</Item>
      <TreeItems>
        <Size>_Mysize</Size>
        <HeadPointer>_Myhead-&gt;_Parent</HeadPointer>
        <LeftPointer>_Left</LeftPointer>
        <RightPointer>_Right</RightPointer>
        <ValueNode Condition="!((bool)_Isnil)">_Myval</ValueNode>
      </TreeItems>
    </Expand>
  </Type>
</AutoVisualizer>

但我在地图上收到此错误

Error: Function std::_Tree_comp_alloc<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<int const ,int> >,0> >::_Mysize has no address, possibly due to compiler optimizations.
    Error while evaluating '_Mysize' in the context of type 'Program.exe!std::map<int,int,std::less<int>,std::allocator<std::pair<int const ,int> > >'.

我在调试模式下构建,我仔细检查了优化被禁用 (\Od)

也许 msvc2015 的 natvis 定义已更改,但我找不到任何东西。 也许示例代码不应该工作,但我发现很难从一个不工作的例子开始。

【问题讨论】:

  • 你最终弄明白了吗?我有一个类似的问题。 :)
  • 不,对不起......

标签: c++ visual-studio-2015 natvis


【解决方案1】:

我猜 std::map 的实现已经改变并且 natvis 示例不是最新的。

以下内容在 Visual Studio 2017 上为我工作:

<Type Name="std::map&lt;*&gt;">
    <DisplayString>{{size = {_Mypair._Myval2._Myval2._Mysize}}}</DisplayString>
    <Expand>
      <Item Name="[size]">_Mypair._Myval2._Myval2._Mysize</Item>
      <Item Name="[comp]">_Mypair</Item>
      <Item Name="[first element]">_Mypair._Myval2._Myval2._Myhead</Item>
      <TreeItems>
        <Size>_Mypair._Myval2._Myval2._Mysize</Size>
        <HeadPointer>_Mypair._Myval2._Myval2._Myhead-&gt;_Parent</HeadPointer>
        <LeftPointer>_Left</LeftPointer>
        <RightPointer>_Right</RightPointer>
        <ValueNode Condition="!((bool)_Isnil)">_Myval</ValueNode>
      </TreeItems>
    </Expand>
  </Type>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-11
    • 2022-11-05
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多