环境
win11 + vscode 1.81.0
wsl2
ardupilot
利用gdb工具在vsCode中实现 Ardupilot SITL的断点调试
优点:可在vsCode中实现断点调试。
参考文献:https://ardupilot.org/dev/docs/debugging-with-gdb-using-vscode.html
- 安装gdb工具
打开wsl,进入ardupilot目录
使用vscode中的终端安装:bash sudo apt install gdb
- 设置 SITL:
./waf configure --debug
- 设置 VSCode Debugger
Run ~> Add Configuration ~> 编辑launch.json:
"configurations": [{"name": "(gdb) Attach Copter","type": "cppdbg","request": "attach","program": "${workspaceFolder}/build/sitl/bin/arducopter","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}]},
- 运行仿真SITL:
sim_vehicle.py -v ArduCopter -f quad --console --map -D
- 将代码和运行中的二进制实例进行 attaching:
Run ~> Start Debugging ~> 选择对应的实例,如下图:
- 这样就可以进行断点调试了:
- 可以利用断点调试查看飞控逻辑的控制流、信息流、函数调用逻辑等等…