3

I'm having trouble with the natvis extension of visual studio 2015. In my efforts I need to access a map, but the TreeItems node of natvis does not seem to work for me. I'm actually using the sample code:

<?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>

But I get this error on a map<int,int>:

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> > >'.

I'm building in debug mode and I double checked, that optimizations are disabled (\Od)

Maybe the natvis definition for msvc2015 has changed, but I couldn't find anything. Maybe the sample code is not supposed to work, but I find it hard to get things started from a not working example.

xeed
  • 925
  • 8
  • 22

1 Answers1

1

I guess the implementation of std::map has changed and the natvis example is not up-to-date.

The following is working for me on 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>
Heyji
  • 1,113
  • 8
  • 26