[英]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.