GDB 不再在 docker 容器内的 VS Code 中遇到断点
GDB is no longer hitting breakpoints in VS Code within docker container
一旦我设置了 launch.json
和 运行 gdb
并在我的代码中成功调试,直到发生某些事情并且所有断点都变成“灰色”并显示以下消息:
“包含该断点的模块尚未加载或无法获取断点地址。”
但是,调试器附加到 运行 程序,我什至可以从 main
开始执行步骤,但仍然没有命中断点...这是用 [=15= 构建的 C++ 项目] 带有 gcc
和 -DCMAKE_BUILD_TYPE=DEBUG
标志。
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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "./MyProject/project",
"args": [],
"stopAtEntry": false,
"cwd": "/home/AA/workspace",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerServerAddress": "/*Cannot write here, but it's fine*/",
"sourceFileMap": {/*Cannot write here, but it*/}
},
]
}
我该如何解决这个问题?
我在其他资源中寻找答案,大多数解决方案都说如果您使用 gcc
编译项目,您应该 -g
选项。这不是我的情况,因为我使用 cmake
但我有一个细节 我在 docker.[=16 中调试了 运行 的代码=]
当您使用来自您用户的 VS 代码文件和来自其他用户的 docker 运行 项目时,您应该在 launch.json
中添加选项 "sourceFileMap": {}
:
"sourceFileMap": {
"/home/user/project/file.hpp" : "/home/YourNameBeyondDocker/project/file.hpp",
...
我在这个选项中添加了错误的路径。当我把它拿出来的时候,我的调试器终于开始打断点了!
一旦我设置了 launch.json
和 运行 gdb
并在我的代码中成功调试,直到发生某些事情并且所有断点都变成“灰色”并显示以下消息:
“包含该断点的模块尚未加载或无法获取断点地址。”
但是,调试器附加到 运行 程序,我什至可以从 main
开始执行步骤,但仍然没有命中断点...这是用 [=15= 构建的 C++ 项目] 带有 gcc
和 -DCMAKE_BUILD_TYPE=DEBUG
标志。
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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "./MyProject/project",
"args": [],
"stopAtEntry": false,
"cwd": "/home/AA/workspace",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerServerAddress": "/*Cannot write here, but it's fine*/",
"sourceFileMap": {/*Cannot write here, but it*/}
},
]
}
我该如何解决这个问题?
我在其他资源中寻找答案,大多数解决方案都说如果您使用 gcc
编译项目,您应该 -g
选项。这不是我的情况,因为我使用 cmake
但我有一个细节 我在 docker.[=16 中调试了 运行 的代码=]
当您使用来自您用户的 VS 代码文件和来自其他用户的 docker 运行 项目时,您应该在 launch.json
中添加选项 "sourceFileMap": {}
:
"sourceFileMap": {
"/home/user/project/file.hpp" : "/home/YourNameBeyondDocker/project/file.hpp",
...
我在这个选项中添加了错误的路径。当我把它拿出来的时候,我的调试器终于开始打断点了!