【问题标题】:Using .natvis file to visualise C++ objects in VS Code使用 .natvis 文件在 VS Code 中可视化 C++ 对象
【发布时间】:2020-02-25 17:24:29
【问题描述】:

根据this link,.natvis 文件可用于可视化原生对象。具体来说,我希望能够使用this .natvis file 检查Eigen::Matrix 对象。

但是,上面的链接不包含有关如何在 VS Code 中实际使用 .natvis 文件的任何信息。是否可以使用自定义 .natvis 文件?

这是我的launch.json文件供参考:

{
    // 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"
        }
    ]
}

【问题讨论】:

  • 我不知道VS Code,但是尝试进入VS Code的安装目录,并搜索现有的natvis文件。将新的复制到同一目录,重新启动 VS Code,看看是否有效。 (这适用于常规 VS)
  • 如果我没记错的话,只需在源代码旁边放一个.natvis 就足够了。试试看!

标签: c++ ubuntu visual-studio-code g++ natvis


【解决方案1】:

launch.json 文件有一个 visualizerFile 选项:

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

这里有一些更多的文档(请参阅 VisualizerFile 和 showDisplayString 表条目): https://docs.microsoft.com/en-us/cpp/build/launch-vs-schema-reference-cpp?view=vs-2019#c-linux-properties

您可能也对此问题感兴趣: https://github.com/Microsoft/vscode-cpptools/issues/925

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 2019-05-03
    • 2021-06-10
    • 2021-04-24
    相关资源
    最近更新 更多