我正在尝试使用纳维斯来可视化内存内容,它是由指针指向的。我还试图将内存声明为向量。但是每次我面临的问题是,在调试过程中,可视化工具只能显示第一个50 entry。
我在这里举一个极小的例子。假设pointer_array是Foo类的成员。在驱动程序文件中,创建一个大小为5000的array,它由数组指向。我想用变量pointer_array观察数组的值。此外,我还试图了解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;
}下面是我使用过的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>&foo_vec[0]</ValuePointer>
</ArrayItems> -->
</Expand>
</Type>
</AutoVisualizer>在launch.json中,我只添加了以下两行:
"visualizerFile": "${workspaceFolder}/natvis_file/file.natvis",
"showDisplayString": true,为了更好地理解,我在这里给出了输出的截图,在natvis文件中,我使用了IndexListItems,并给出了大小80来查看索引0到79之间的值,但显示的最后一个值来自索引49。

下面显示的是,我给出了size值6,并且natvis完美地显示了从索引0到5的值。

有什么办法可以用Natvis实现所有内存的输入吗?
发布于 2022-08-31 08:09:46
发布于 2022-05-31 10:55:10
根据关于github的这一期的说法,对50的限制是“按设计”的,并且没有改变它的意图。
发布于 2022-05-31 11:29:27
我查看了代码的这个限制。因此,我可以给出一个解决方案--您可以展示容器的一部分。
<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>https://stackoverflow.com/questions/72359355
复制相似问题