microsoft / MIEngine

The Visual Studio MI Debug Engine ("MIEngine") provides an open-source Visual Studio Debugger extension that works with MI-enabled debuggers such as gdb and lldb.
MIT License
818 stars 219 forks source link

Natvis framework cannot display more than 50 content during debugging with ArrayItems or IndexListItems #1307

Closed atifkarim closed 2 years ago

atifkarim commented 2 years ago

First all, I will be very sorry if this is not the right place to ask the question related to natvis debugging. If I have chosen the wrong platform to ask the query would be great if anyone can point me the right location (except stackoverflow) will be grateful.

Now the issue. I am trying to visualize a stack of memory content (eg: Value from index 0 to 500 or more. Depends on which size is given by me in <size>size_val</size> field) using natvis which is pointed by a pointer. I have also tried to use std::vector. But every time the problem I am facing is that, during debugging the visualizer can show only first 50 entry (index 0 to 49).

I am giving here a very minimal example. Suppose, the pointer_array is a member of Foo class. In the driver file an array of size 5000 is created which is pointed by the array. I would like to observe the value of the array with the variable pointer_array. Also I have tried to understand how natvis reacts with std::vector and that's why as a member variable a vector (foo_vec) is also declared.

foo.h

#include <iostream>
#include <vector>

class Foo
{
    public:
        Foo(){}

        uint32_t *pointer_array;
        std::vector<uint32_t> foo_vec;
};

main.cpp

#include "foo.h"
# define ARRAY_SIZE 5000

int main()
{
    Foo obj_1;

    uint32_t foo_array[ARRAY_SIZE];
    for(int i = 0; i < ARRAY_SIZE; i++)
    {
        foo_array[i] = i*2;
    }
    obj_1.pointer_array = foo_array;

    for(uint32_t i = 0; i < ARRAY_SIZE; i++)
    {
        obj_1.foo_vec.push_back(i*3);
    }

    return 0;
}

The following natvis file I have used.

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <Type Name="Foo">
        <DisplayString>Testing_Natvis</DisplayString>
        <Expand>
        <ArrayItems>
            <Size>5000</Size>
            <ValuePointer>pointer_array</ValuePointer>
        </ArrayItems>

        <!-- Tested with IndexListItems but failed to fetch all data, still only first 49 entry -->
        <!-- <IndexListItems>
          <Size>5000</Size>
          <ValueNode>pointer_array[$i]</ValueNode>
        </IndexListItems> -->

          <!-- Same result as like as pointer_array. Only first 49 entry is appeared -->
          <!-- <IndexListItems>
            <Size>foo_vec.size()</Size>
            <ValueNode>foo_vec[$i]</ValueNode>
          </IndexListItems> -->

          <!-- <ArrayItems>
            <Size>foo_vec.size()</Size>
            <ValuePointer>&amp;foo_vec[0]</ValuePointer>
        </ArrayItems> -->
        </Expand>
    </Type>
</AutoVisualizer>

In the launch.json I have added extra only the following two lines

"visualizerFile": "${workspaceFolder}/natvis_file/file.natvis",
"showDisplayString": true,

If any workaround is guided to achieve all entry of the memory using Natvis, it would be very beneficial for me.

WardenGnaw commented 2 years ago

Duplicate of https://github.com/microsoft/MIEngine/issues/821