Search code examples
c++rustvscode-debugger

How to visualise ndarray Rust in VSCode?


I am using VSCode to develop my rust application which contains lots of NDArray. When I set breakpoint and watch the NDArray variable, it is only showing pointers. I don't know how to view the content. I tried both cppvsdbg & lldb (vscode-codelldb) and both has same issue? Is there any command I can type in debug console to expand the variable?

enter image description here


Solution

  • I am now able to visualise it using below natvis,

    <?xml version="1.0" encoding="utf-8"?>
    <AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <Type Name="ndarray::ArrayBase&lt;*,*&gt;">
          <DisplayString>{{Modified by Selva}}</DisplayString>
          <Expand HideRawView="false">  
                <ArrayItems>  
                      <Direction>Forward</Direction>  
                      <Rank>sizeof(dim.index)/sizeof(*dim.index)</Rank>
                      <Size>(int)dim.index[$i]</Size>  
                      <!-- <Size>$i==0?(int)dim.index[0]:(int)dim.index[1]</Size>   -->
                      <ValuePointer>data.ptr.pointer</ValuePointer>  
                </ArrayItems>  
          </Expand>
    </Type>
    </AutoVisualizer>