16

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"
        }
    ]
}
Toivo Säwén
  • 1,905
  • 2
  • 17
  • 33
  • 2
    I don't know for VS Code, but try going to the installation directory of your VS Code, and searching for existing natvis files. Copy your new one into the same directory, restart VS Code, and see if that works. (This works for regular VS) – ChrisMM Oct 30 '19 at 12:05
  • If I'm not mistaken it might be enough to just drop a `.natvis` next to the source code. Try it! – Max Langhof Oct 30 '19 at 12:24

1 Answers1

15

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://learn.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