使用vscode连接docker,后参考自动驾驶开发者说|框架|如何用vscode调试apollo? - 知乎进行配置。
- 启动apollo容器,我这里是使用软件包安装,直接aem start即可
- 先使用vscode插件连接到docker
- (这一步我不确定是不是需要)选择Open Container Configuration File
{
"extensions": [
"BazelBuild.vscode-bazel",
"DamianKoper.gdb-debug",
"eamodio.gitlens",
"GitHub.vscode-pull-request-github",
"Gruntfuggly.todo-tree",
"jeff-hykin.better-cpp-syntax",
"mhutchie.git-graph",
"MS-CEINTL.vscode-language-pack-zh-hans",
"ms-vscode-remote.remote-containers",
"ms-vscode-remote.remote-ssh",
"ms-vscode-remote.remote-ssh-edit",
"ms-vscode-remote.remote-wsl",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools-themes",
"ms-vsliveshare.vsliveshare",
"twxs.cmake"
],
"workspaceFolder": "/apollo",
"remoteUser": "ckh",
"remoteEnv": {
"HISTFILE": "/apollo/.dev_bash_hist"
}
}
4.进入容器aem start
5. 使用debug模式编译代码,例如buildtool build --dbg -j 2 -m 0.5 -p modules/planning/
6.在vscode 中配置vscode的调试文件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
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "/opt/apollo/neo/bin/mainboard",
"args": ["-d","/apollo/modules/planning/dag/planning.dag","-p", "planning", "-s"," CYBER_DEFAULT"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
//"sourceFileMap": {
//"proc/self/cwd" : "/apollo_workspace/application-demo"
//},
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
// "preLaunchTask": "C/C++: g++ 生成活动文件",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
7.apollo是通过mainboard调用各个模块。先使用whereis mainboard找到可执行文件的路径。平时使用cyber调用模块cyber_launch start modules/planning/launch/planning.launch后,可用ps aux |grep mainboard查看命令。也可参考技术文档丨使用VSCode构建、调试Apollo项目。
8.可在容器中使用gdb调试,gdb -q --args /opt/apollo/neo/bin/mainboard -d /apollo/modules/planning/dag/planning.dag ,打断点b modules/planning/planning_component.cc:50,然后r,正常调试。
9.或者直接在vscode中打断点调试。
可能出现的问题
- "type": "cppdbg"的类型不受支持,vscode下载 C/C++ Runner.
- docker中未有gdb,sudo apt install gdb
- debug时无法打开文件,在launch.json中设置cwd,或者sourceFileMap解决。参考连接Vscode 附加进程调试_vscode附加到进程_Supreme_Julyan的博客-CSDN博客