Torbjörn
Torbjörn

Reputation: 5810

Limit display of char* in natvis file to specific length

I've got a custom data structure holding a char* buffer with two lengths associated: maximum and actual length:

struct MyData {
  char* data;
  int length;
  int capacity;
};

In the Visual Studio (2015) debugger visualizer I only want to display the first length elements of the data buffer and not the (usually uninitialized) remaining elements.

I've the following rule in my custom .natvis file for displaying my custom data structure:

<Type Name="MyData">
  <DisplayString>content="{data,su}" length={length}</DisplayString>
</Type>

Is it possible to only display data as a "su"-encoded string from data[0] to data[length-1]?

Upvotes: 8

Views: 2427

Answers (1)

Trasig Torsk
Trasig Torsk

Reputation: 161

This will limit the length of the string in the debugger:

<Type Name="MyData">
    <DisplayString>{data,[length]su}</DisplayString>
</Type>

Upvotes: 16

Related Questions