Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 960
Torbjörn Avatar asked Apr 27 '16 07:04

Torbjörn


1 Answers

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

<Type Name="MyData">
    <DisplayString>{data,[length]su}</DisplayString>
</Type>
like image 138
Trasig Torsk Avatar answered Sep 21 '22 00:09

Trasig Torsk