Ubuntu22.04+ros-humble
在代码的工作目录下找到 .vscode 目录,新建 launch.json文件(如果存在直接进行修改),
launch.json中的内容如下:
{
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "/home/rocket/robot/src/install/test_cpp/lib/test_cpp/test_cpp",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
],
"version": "2.0.0"
}
其中“program”中的内容为:可执行程序的地址
即:"program": "/home/用户名/工作空间/install/功能包/lib/功能包/可执行文件"
之后便可进行对代码的调试;
若调试时出现加断点后断点出现断点为灰色,且报如下错误:
module containing this breakpoint has not yet loaded or thebreakpoint address could not be obtained
解决方法:
是因为没有编译成debug版本,这时候要在makefile中增加-g选项,如果使用的是cmake,要在cmakelist.txt里面增加如下定义。
add_definitions("-Wall -g")