Embedded Eigen Matrix Debugging Visualizer

Sysprogs forums Forums VisualGDB Embedded Eigen Matrix Debugging Visualizer

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12790
    codex653
    Participant

    Hi,

    I am using the Eigen matrix math library to implement a UKF on my STM32 device in VS2017 with VisualGDB 5.3R5. One of the things I noticed in debug mode (OpenOCD) is that I can only view the first value in my matrix. Eigen stores data in arrays and the matrix class templates store the pointer to the first element in that array. I really need to see the full matrix.  Apparently Visual Studio needs to be told to recognize the data types properly in order to display the full contents of the matrix type: http://eigen.tuxfamily.org/index.php?title=Developer%27s_Corner#Debugging_under_Visual_Studio

    Per the included link, I was able to download the latest eigen.natvis file and properly locate it under my VS2017 install directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Packages\Debugger\Visualizers

    Unfortunately, VisualGDB still does not recognize the matrix data types and does not display the contents of the array in the watch windows. Is there something specific that I need to do to get VisualGDB to recognize the data properly?

    #12792
    support
    Keymaster

    Hi,

    Please try adding the .natvis file directly to your VS project (via right-click->Add->Existing Item). This should help VisualGDB recognize it.

    #12800
    codex653
    Participant

    I have done this, but I still only see the first value in memory. I’ve experiment with the .natvis file a bit and it seems that the XML structure is unable to discern what value is associated with the wildcard character “*” in the DisplayString block. For example, if I have a dynamic [3×3] matrix, the value in the debugger window will read “[ERROR, ERROR] (fixed matrix)”. For whatever reason, the wildcard * is not read into $T2 and $T3, and the matrix is not identified as dynamic. An example of the XML section that gets triggered is shown below:

    <!-- Fixed x Fixed Matrix -->
     <Type Name="Eigen::Matrix&lt;*,*,*,*,*,*&gt;">
     
     <DisplayString>[{$T2},{$T3}] (fixed matrix)</DisplayString>
     <Expand>
     <ArrayItems Condition="Flags%2">
     <!-- row major layout -->
     <Rank>2</Rank>
     <Size>$i==0 ? $T2 : $T3</Size>
     <ValuePointer>m_storage.m_data.array</ValuePointer>
     </ArrayItems>
     <ArrayItems Condition="!(Flags%2)">
     <!-- column major layout -->
     <Direction>Backward</Direction>
     <Rank>2</Rank>
     <Size>$i==0 ? $T2 : $T3</Size>
     <ValuePointer>m_storage.m_data.array</ValuePointer>
     </ArrayItems>
     </Expand>
     </Type>
    • This reply was modified 7 years ago by codex653.
    #12813
    codex653
    Participant

    For anyone coming across this later, I’ve ended up using what I think might be a better option for viewing the full matrix in a manner similar to Matlab. I wrote a quick ‘n dirty function that prints out the contents of a generic Eigen matrix to the VisualGDB provided ARM Semihosting Console. It actually works pretty well! I’d like to still get the .natvis file working, but this is ok for now.

    template <typename T>
     void prettyPrint(T matrix, std::string name)
     {
        size_t num_rows = matrix.rows();
        size_t num_cols = matrix.cols();
    
        //Matrix header name
        printf(name.data());
        printf("Size: [%d,%d]\n", num_rows, num_cols);
    
        //Create column labels
        printf("\t");
        for (size_t col = 0; col < num_cols; col++)
            printf("[%d]\t", col);
        printf("\n\n");
    
    
        //Create row data
        double data = 0.0;
        for (size_t row = 0; row < num_rows; row++)
        {
           printf("[%d]\t", row);
           for (size_t col = 0; col < num_cols; col++)
           {
              data = matrix(row, col);
              printf("%.2f\t", data);
    
           }
           printf("\n\n\n");
        }
    }
    • This reply was modified 7 years ago by codex653.
    • This reply was modified 7 years ago by codex653.
    #12843
    support
    Keymaster

    Hi,

    We have managed to reproduce the problem with the Eigen natvis file. It is caused by VisualGDB not supporting the $Tx syntax and the multi-dimensional ArrayItems.

    We have added support for the $Tx syntax to the upcoming maintenance release, however we currently don’t have any plans for supporting multi-dimensional arrays. As a workaround we would advise creating a basic visualizer using our managed visualizer API described here. It allows using arbitrary logic for analyzing visualized expressions and would support multi-dimensional arrays as well.

    #12845
    codex653
    Participant

    Good to know! I’ll try that out.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.