I know the default ArrayItems-Tag can handle matrices, but I find the result insufficient.
Given this example
#include <cstdlib>
#include <cstdio>
struct matrix {
int height;
int width;
double* values;
};
int main() {
double* values = (double*)malloc(5 * 2 * sizeof(double));
for (int i = 0; i < 10; ++i) values[i] = i * 2;
matrix m = { 5, 2, values };
return 0;
}
With this natvis
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="matrix">
<DisplayString>{{Shape [{height} x {width}]}}</DisplayString>
<Expand>
<CustomListItems>
<Variable Name="i" InitialValue="0" />
<Loop>
<Break Condition="i == height" />
<Item>(values + (i * width)), 2</Item>
<Exec>i++</Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
</AutoVisualizer>
Results in this output, which is nearly perfect.
But I cheated in my natvis. I wrote <Item>(values + (i * width)), 2</Item>
The 2 being the width of the row. But if I write width
instead of the 2 it puts out 2 instead of the rows. It apparently prints the value of width
, which is not helpful.
Anyone know how I can make these rows variable sized?
Try [width] nag
:
<Item>(values + (i * width)), [width] nag</Item>
[size]
- expand fixed-size array,na
- "no address" - suppress address,g
- for better view of floating point data.