2

I have an array (limit_array) which is pointed by a pointer (limit_ptr). For simplicity, here I have given an array of length 10. Using IndexListItems of natvis I can iterate through the value which is pointed by the pointer limit_ptr. But in some cases, I would not like to see all of the values, rather my preference is to observe a range of values (eg: index 4 to 6, that means 3 values). This one is achieved but I cannot change the index value in the debug window. The steps I have followed are given below

Sample code


int main()
{
    uint32_t limit_array[10];
    for(int i = 0; i < 10; i++)
    {
        limit_array[i] = i*5;
    }
    uint32_t *limit_ptr = limit_array;

    return 0;
}

natvis file

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <Type Name="uint32_t *">
      <DisplayString>Would like to observe limited or preferred ranged value</DisplayString>
      <Expand>
        <IndexListItems>
          <Size>10</Size>
          <ValueNode>limit_ptr[$i]</ValueNode>
        </IndexListItems>
      </Expand>
    </Type>
</AutoVisualizer>

Here, in Size tag I have used the length of the array.

The following output I can see in the Debug window enter image description here

What would like to achieve

I have tried to display limited range of values. For example from index 4 to 6 I need to display. Modified natvis file as like as follows:

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <Type Name="uint32_t *">
      <DisplayString>Would like to observe limited or preferred ranged value</DisplayString>
      <Expand>
        <IndexListItems>
          <Size>3</Size>
          <ValueNode>limit_ptr[$i+4]</ValueNode>
        </IndexListItems>
      </Expand>
    </Type>
</AutoVisualizer>

But I have got the output as like as follows where I can see my preferred value 20, 25, 30 but in a wrong index (still in [0] [1] [2]). My desire is to see them in [4] [5] [6].

enter image description here

Is it possible by Natvis to observe at [4] [5] [6] index or it is a default behavior of VSCode Debugger always to display index value 0 even if it points to another index? If there is any workaround to achieve my goal would be great.

user10634362
  • 549
  • 5
  • 21
  • What about using `CustomListItems` instead? It seems you can apply programming logic in those expansions. – Ted Lyngmo Sep 05 '22 at 15:01
  • @TedLyngmo As far I can remember that one uses `Loop`, `Exec` which is not supported by `MIEngine`. This one is stated [here](https://stackoverflow.com/questions/65742034/using-customlistitems-in-vscode-natvis) – user10634362 Sep 05 '22 at 15:13
  • @TedLyngmo Also mentioned by vscode dev team that [Visual Studio MIEngine does not support Loop](https://github.com/microsoft/MIEngine/issues/1095#issuecomment-764961245) – user10634362 Sep 06 '22 at 05:08

0 Answers0