【问题标题】:Debug C++ Standard Library with Visual Studio Code on macOS在 macOS 上使用 Visual Studio Code 调试 C++ 标准库
【发布时间】:2021-05-11 05:24:03
【问题描述】:

我在 macOS 上使用 Visual Studio CodeMicrosoft C/C++ 扩展 来评估生产环境中的实际可用性和生产力。

在我的场景中,我使用 Clang/LLVM 编译器和 LLDB 调试器。

由于某种未知原因,我无法调试 C++ 标准库。我可以进入我的应用程序中定义的符号,但不能对标准符号做同样的事情,例如std::vector 构造函数。

尚不清楚这是错误的配置还是这些工具的限制。在网上搜索,我注意到 C++ 标准库调试在使用 GNU 工具链的 Linux 上运行良好。

有没有办法使用 LLDB 调试器来调试标准符号?有人在生产中使用这些工具吗?

为了完整起见,它遵循我当前非常简单的配置:

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=c++17",
                "-stdlib=libc++",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/bin/clang++"
        }
    ]
}

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "console": "externalTerminal",
            "MIMode": "lldb",
            "preLaunchTask": "${defaultBuildTask}"
        }
    ]
}

【问题讨论】:

    标签: c++ visual-studio-code vscode-debugger vscode-tasks


    【解决方案1】:

    Microsoft C/C++ 扩展支持团队指出这是由于lldb 的默认配置造成的。其实target.process.thread.step-avoid-regexp默认设置为^std::

    (lldb) settings show target.process.thread.step-avoid-regexp
    target.process.thread.step-avoid-regexp (regex) = ^std::
    

    将此设置更改为"",调试器也可以进入标准模板符号。这可以在launch.json配置文件中添加:

    "setupCommands": [
        {
            "text": "settings set target.process.thread.step-avoid-regexp \"\"",
            "description": "Enable stepping into STL"
        }
    ]
    

    或者,也可以通过将此配置放在主目录的.gdbinit 文件中,在用户级别进行设置:

    settings set target.process.thread.step-avoid-regexp ""
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-16
      • 2015-10-11
      • 1970-01-01
      • 2020-03-30
      • 1970-01-01
      • 2020-02-04
      相关资源
      最近更新 更多