3

Arrays and std::vectors (and, supposedly, all standard containers) are browseable in the Visual Studio debugger (you can hover the mouse pointer over them and inspect their contents).

Is there a way to prepare a custom container class, to allow browsing through its internal data the same way as std::vector does?

Spook
  • 25,318
  • 18
  • 90
  • 167

2 Answers2

2

Try to look at file %VSINSTALLDIR%\Common7\Packages\Debugger\autoexp.dat. There is customizable description of expansion rules for different data types.

From this file:

While debugging, Data Tips and items in the Watch and Variable windows are automatically expanded to show their most important elements. The expansion follows the format given by the rules in this file. You can add rules for your types or change the predefined rules.

Similar question

Community
  • 1
  • 1
Mekanik
  • 2,532
  • 1
  • 22
  • 20
2

With modern version of visual studio you can create a .natvis file describing how to read the data structure. See https://learn.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2022

For example, a custom vector type class:

<?xml version="1.0" encoding="utf-8"?>

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="vec&lt;*,*&gt;">
    <DisplayString Condition="m_size == 0">empty</DisplayString>
    <DisplayString>{&amp;m_data[0], [m_size]}</DisplayString>
    <Expand>
      <Item Name="[size]">m_size,d</Item>
      <Item Name="[capacity]">m_capacity,d</Item>
      <ArrayItems>
        <Size>m_size</Size>
        <ValuePointer>&amp;m_data[0]</ValuePointer>
      </ArrayItems>
    </Expand>
  </Type>
</AutoVisualizer>```
manylegged
  • 794
  • 7
  • 14