docs/debuginros.md
2024-10-18 10:20:13 +08:00

63 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 在Vscode中调试ROS
## 单节点应用
1. 在编译前在CMakeLists.txt文件中指定Debug编译模式
```cmake
set(CMAKE_BUILD_TYPE Debug)
```
2. 配置launch.json 和tasks.json(在根目录.vscode文件夹中)
```json
// tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "rws build", // 名称自定义要与launch.josn文件要一致 @1
"type": "shell",
"command": "source ${workspaceFolder}/install/setup.sh"
// "command": "colcon build && source ${workspaceFolder}/install/setup.sh"
// 不一定调试都需要重新编译
},
]
}
```
```json
//launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug rws Executable", // 名称自定义
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/install/rws/lib/rws/rws_server", // 编译好的可执行程序所在路径
"cwd": "${workspaceFolder}", // 工作目录,默认即可
"args": [ // 调试阶段需要传递给可执行程序的参数
],
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "rws build", // 这里需要与上面的task.json的名称对应 @1
"miDebuggerPath": "/usr/bin/gdb",
"miDebuggerArgs": "",
},
]
}
```
3. 调试
![image-20240924145117137](/assert/1.png)