Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using .natvis file to visualise C++ objects in VS Code

According to this link, .natvis files can be used to visualise native objects. Specifically, I would like to be able to inspect Eigen::Matrix objects using this .natvis file.

However, the link above does not contain any information on how to actually use a .natvis file in VS Code. Is it possible using a custom .natvis file?

Here is my launch.json file for reference:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++-8 build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++-8 build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
like image 290
Toivo Säwén Avatar asked Oct 30 '19 11:10

Toivo Säwén


1 Answers

The launch.json file has has a visualizerFile option:

    {
        "name": "g++-8 build and debug active file",
        "visualizerFile": "${workspaceFolder}/path/to/file.natvis",
        "showDisplayString": true,
        ...
    },

Some more documentation here (see the visualizerFile and showDisplayString table entries): https://docs.microsoft.com/en-us/cpp/build/launch-vs-schema-reference-cpp?view=vs-2019#c-linux-properties

You might also be interested in this issue: https://github.com/Microsoft/vscode-cpptools/issues/925

like image 167
Andres Rodriguez Avatar answered Sep 18 '22 10:09

Andres Rodriguez