简体   繁体   English

使用 natvis 扩展 ArrayItems/IndexListItems 的显示范围

[英]Extend display range of ArrayItems/IndexListItems using natvis

I am trying to visualize a memory content using natvis which is pointed by a pointer.我正在尝试使用指针指向的 natvis 可视化memory内容。 I have also tried to declare the memory as a vector.我还尝试将 memory 声明为向量。 But every time the problem I am facing is that, during debugging the visualizer can show only first 50 entry .但是每次我面临的问题是,在调试过程中,可视化器只能显示前50 entry

I am giving here a very minimal example.我在这里给出一个非常简单的例子。 Suppose, the pointer_array is a member of Foo class.假设, pointer_arrayFoo class 的成员。 In the driver file an array of size 5000 is created which is pointed by the array.在驱动程序文件中创建了一个大小为 5000 的array ,该数组由数组指向。 I would like to observe the value of the array with the variable pointer_array .我想用变量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.此外,我试图了解natvis如何与std::vector起反应,这就是为什么还声明了一个向量( foo_vec )作为成员变量的原因。

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.我使用过以下natvis file

<?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:launch.json我只添加了以下两行:

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

For better understanding I am giving here a screenshot of the output where in natvis file I have used IndexListItems and given size 80 to see value from index 0 to 79 but the displayed last value is from index 49.为了更好地理解,我在这里给出了 output 的屏幕截图,其中在 natvis 文件中我使用IndexListItems并给定大小 80 以查看索引 0 到 79 的值,但显示的最后一个值来自索引 49。 错误 natvis 输出

And the following is showing that I have given the size value 6 and natvis perfectly is showing value from index 0 to 5.以下显示我已经给出了size值 6,而 natvis 完美地显示了从索引 0 到 5 的值。 从 vscode 正确输出 natvis

Any workaround to achieve all entry of the memory using Natvis?使用 Natvis 实现 memory 的所有条目的任何解决方法?

根据github 上的这个问题,对 50 的限制是“设计使然”,无意更改它。

I looked at code for this restriction.我查看了此限制的代码 So, I can offer an idea of a solution - you can show a part of the container所以,我可以提供一个解决方案的想法——你可以展示容器的一部分

<IndexListItems>
  <Size>foo_vec.size()</Size>
  <ValueNode>foo_vec[$i]</ValueNode>
</IndexListItems>
<IndexListItems>
  <Size>foo_vec.size()-50</Size>
  <ValueNode>foo_vec[$i+50]</ValueNode>
</IndexListItems>
...
<IndexListItems>
  <Size>foo_vec.size()-4950</Size>
  <ValueNode>foo_vec[$i+4950]</ValueNode>
</IndexListItems>
  • According to this release the problem is solved although there is still bug of displaying more than 1000 value using ArrayItems node.根据此版本,尽管仍然存在使用ArrayItems节点显示超过 1000 个值的错误,但问题已得到解决。 See this issue to get more information.请参阅此问题以获取更多信息。

  • This display range limitation is gone if IndexListItems is used.如果使用IndexListItems ,则此显示范围限制将消失。 Following snippet could be used to see more than 1000 element以下代码段可用于查看超过 1000 个元素

<IndexListItems>
   <Size>5000</Size>
   <ValueNode>pointer_array[$i]</ValueNode>
</IndexListItems> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM