[英]Debug C++ Standard Library with Visual Studio Code on macOS
I am using Visual Studio Code on macOS with the Microsoft C/C++ Extension to evaluate the real usability and productivity in a production environment.我在 macOS 上使用带有Microsoft C/C++ 扩展的Visual Studio Code来评估生产环境中的实际可用性和生产力。
In my scenario, I am using Clang/LLVM compiler and LLDB debugger.在我的场景中,我使用的是Clang/LLVM编译器和LLDB调试器。
For some unknown reason, I am unable to debug the C++ Standard Library.由于某些未知原因,我无法调试 C++ 标准库。 I can step into symbols defined in my application, but no way do the same with the standard ones, eg std::vector
constructor.我可以进入我的应用程序中定义的符号,但不能对标准符号做同样的事情,例如std::vector
构造函数。
It is unclear whether this is an incorrect configuration or a limitation of these tools.目前尚不清楚这是不正确的配置还是这些工具的限制。 Searching on web I noticed that the C++ standard library debugging definitely works well on Linux using the GNU toolchain.在 web 上搜索时,我注意到 C++ 标准库调试在使用 GNU 工具链的 Linux 上运行良好。
Is there a way to debug standard symbols using LLDB debugger?有没有办法使用LLDB调试器调试标准符号? Does anyone use these tools in production?有人在生产中使用这些工具吗?
For completeness, it follows my current and quite simple configuration:为了完整起见,它遵循我当前且非常简单的配置:
tasks.json
: 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
: 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}"
}
]
}
The Microsoft C/C++ Extension support team points out that this is due to the default configuration of lldb
. Microsoft C/C++ 扩展支持团队指出这是由于lldb
的默认配置。 In fact, target.process.thread.step-avoid-regexp
is set to ^std::
by default:实际上, target.process.thread.step-avoid-regexp
默认设置为^std::
:
(lldb) settings show target.process.thread.step-avoid-regexp
target.process.thread.step-avoid-regexp (regex) = ^std::
Changing this setting to ""
, the debugger is able to step into standard template symbols as well.将此设置更改为""
,调试器也能够进入标准模板符号。 This can be configured in the launch.json
configuration file by adding:这可以在launch.json
配置文件中配置,添加:
"setupCommands": [
{
"text": "settings set target.process.thread.step-avoid-regexp \"\"",
"description": "Enable stepping into STL"
}
]
Alternatively, this can also be set at the user level by placing this configuration in the .gdbinit
file in the home directory:或者,也可以通过将此配置放在主目录的.gdbinit
文件中,在用户级别进行设置:
settings set target.process.thread.step-avoid-regexp ""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.