[英]Extend display range of ArrayItems/IndexListItems using natvis
我正在尝试使用指针指向的 natvis 可视化memory内容。 我还尝试将 memory 声明为向量。 但是每次我面临的问题是,在调试过程中,可视化器只能显示前50 entry
。
我在这里给出一个非常简单的例子。 假设, pointer_array
是Foo
class 的成员。 在驱动程序文件中创建了一个大小为 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,
为了更好地理解,我在这里给出了 output 的屏幕截图,其中在 natvis 文件中我使用IndexListItems
并给定大小 80 以查看索引 0 到 79 的值,但显示的最后一个值来自索引 49。
以下显示我已经给出了size
值 6,而 natvis 完美地显示了从索引 0 到 5 的值。
使用 Natvis 实现 memory 的所有条目的任何解决方法?
根据github 上的这个问题,对 50 的限制是“设计使然”,无意更改它。
我查看了此限制的代码。 所以,我可以提供一个解决方案的想法——你可以展示容器的一部分
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.