20

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"
        }
    ]
}
2
  • 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) Commented Oct 30, 2019 at 12:05
  • If I'm not mistaken it might be enough to just drop a .natvis next to the source code. Try it! Commented Oct 30, 2019 at 12:24

1 Answer 1

19

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.