ROS2 CPP 功能包使用 VScode/clion 进行 debug

开启 debug

CMakeLists.txt 添加 target 之前中添加

1
set(CMAKE_BUILD_TYPE Debug)

或者编译选项

1
-DCMAKE_BUILD_TYPE=Debug

编译

1
colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

source install/setup.bash后打开 IDE 进行调试

vscode 配置

task.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
// 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": "${workspaceFolder}/install/${input:package_name}/lib/${input:package_name}/${input:package_executable}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
// {
// "description": "Set Disassembly Flavor to Intel",
// "text": "-gdb-set disassembly-flavor intel",
// "ignoreFailures": true
// }
]
}
],
"inputs": [
{
"id": "package_name",
"type": "promptString",
"description": "ros2 package name",
"default": "cpp_primer_pubsub"//写上要调试的包
},
{
"id": "package_executable",
"type": "promptString",
"description": "ros2 package executable",
"default": "talker"//写上要调试的功能
}
]
}

Clion 配置


参考

https://blog.csdn.net/weixin_41312228/article/details/129847328

https://gist.github.com/JADC362/a4425c2d05cdaadaaa71b697b674425f

https://zhuanlan.zhihu.com/p/364972107