配置launch.json
首先配置json文件,注意environment是程序需要的某些共享文件库so的目录
program是可执行的gdb程序
{
// 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": "Debug my code",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build_x86/bin/hobot_onl_calib.gdb",
"args": ["/home/siyuan/下载/1v-auto-config/calib-online/config/config-onl-v/global.json","12"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "${workspaceFolder}/build_x86/bin/"
}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
调试
1.vscode调试
配置好如上launch文件后,直接在vscode内部进行调试
2.终端调试
gdb --args ./dir/xxx.gdb argv1 argv2
#直接运行
run
#打断点:1)函数名字打断点 2)文件行数打断点
break Functionname
break xxx/xxx.cpp:233
#运行到断点
run
#步进
step
注意:多线程一般调试会有问题,我们一般利用打印log观察错误
段错误
代码经常会报错,段错误,一般使用gdb运行的话,会具体定位到段错误出错的地方
用gdb跑, 然后发生问题的时候输入bt就能看到代码的堆栈
如上所是,是跟踪光流的函数报错,可能原因是pts为空
ROS GDB调试
rosrun启动
rosrun --prefix 'gdb -ex run --args' vins vins_node 配置文件
roslaunch启动