Sunday, 12 July 2015

VS visualizers and usertype.dat

User type keywords

In Visual Studio you can define custom keywords:
usertype.dat next to the devenv.exe
Example content:
Vec3
Vec4
Rectangle
etc...
One line one word, so simple.
-------------------------------------------------------------------------------------------------------------------
Now about the visualizers

You have to place visualizer files under:
c:\Users\YourName\Documents\Visual Studio 2013\Visualizers\

e.g.:
example.natvis

To enable natvis debugger

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Debugger]
"EnableNatvisDiagnostics"=dword:00000001

Later I will describe it.

Example:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="Rectangle">
    <DisplayString>A rectangle with height = {height} {width} </DisplayString>
    <Expand>
      <Item Name="height">height</Item>
      <Item Name="width">width</Item>
      <Item Name="area">height * width</Item>
      <Item Name="macik">macik</Item>
      <ExpandedItem>macik</ExpandedItem>

        <Synthetic Name="Am I a square?" Condition="height==width">
          <DisplayString>Yes I am. </DisplayString>
        </Synthetic>
        <Synthetic Name="Am I a square?" Condition="height!=width">
          <DisplayString>No I am not.</DisplayString>
        </Synthetic>

    </Expand>
  </Type>


  <Type Name="Rectangle2">
    <DisplayString Condition="height == 4">negy = {height} {width} </DisplayString>
    <DisplayString Condition="height == 3">harom</DisplayString>
    <Expand>
      <Item Name="height">height</Item>
      <Item Name="width">width</Item>
      <Item Name="area">height * width</Item>
    </Expand>
  </Type>


  <Type Name="std::vector&lt;*&gt;">
    <Expand>
      <Item Name="[size]">_Mylast - _Myfirst</Item>
<!--      <Item Name="[capacity]">(_Myend - _Myfirst)</Item>-->
      <ArrayItems>
        <Size>_Mylast - _Myfirst</Size>
        <ValuePointer>_Myfirst</ValuePointer>
      </ArrayItems>
    </Expand>
  </Type>


</AutoVisualizer>

Friday, 10 July 2015

Run as administrator Windows from command line

You can do it with the followings:

"runas.exe /savecred /user:administrator cmd"