簡體   English   中英

使用 natvis 擴展 ArrayItems/IndexListItems 的顯示范圍

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

我正在嘗試使用指針指向的 natvis 可視化memory內容。 我還嘗試將 memory 聲明為向量。 但是每次我面臨的問題是,在調試過程中,可視化器只能顯示前50 entry

我在這里給出一個非常簡單的例子。 假設, pointer_arrayFoo 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>&amp;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。 錯誤 natvis 輸出

以下顯示我已經給出了size值 6,而 natvis 完美地顯示了從索引 0 到 5 的值。 從 vscode 正確輸出 natvis

使用 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>
  • 根據此版本,盡管仍然存在使用ArrayItems節點顯示超過 1000 個值的錯誤,但問題已得到解決。 請參閱此問題以獲取更多信息。

  • 如果使用IndexListItems ,則此顯示范圍限制將消失。 以下代碼段可用於查看超過 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