参考:VScode debug ROS cpp程序设置 断点调试_ABC_Orange的博客-CSDN博客_poll failed with error interrupted system call
Get Started with C++ on Linux in Visual Studio Code
使用 vscode 进行ROS的开发与调试_哔哩哔哩_bilibili
VScode官网对以下三个配置文件的说明:
tasks.json (compiler build settings){其实就是将终端需要执行的命令写在这个文件里,然后调用运行这个文件,替代了原有的命令行指令。}
launch.json (debugger settings):{debug调试的配置文件}
c_cpp_properties.json (compiler path and IntelliSense settings){主要作用是指定cpp程序中头文件的路径}
1.tasks.json(就是将相应的命令行指令集成的配置文件)
没有加注释的默认就行,不用管。
{
"version": "2.0.0",
"tasks": [
{
"label": "build", //代表提示的描述性信息
"type": "shell", //可以选择shell或者process,如果是shell代码是在shell里面运行一个命令,如果是process代表作为一个进程来运行
"command": "catkin_make -DCMAKE_BUILD_TYPE=Debug",//这个是我们原本想在shell需要运行的命令,"-DCMAKE_BUILD_TYPE=Debug"表示进入debug模式
"args": [],//如果需要在命令后面加一些后缀,可以写在这里,比如-DCATKIN_WHITELIST_PACKAGES=“pac1;pac2”
"group": {"kind":"build","isDefault":true},//代表将我们定义的这个task添加到build组里面,这样就可以中Ctrl+Shift+B快捷键来找到编译命令,命令名称就是在label里面定义的,如果"isDefault":true那么就代表直接执行command,如果为false还需要在build下拉里面选一下
"presentation": {
"reveal": "always"//可选always或者silence,代表是否输出信息
},
"problemMatcher": "$catkin-gcc"//不是"problemMatcher": "$msCompile",不然后面还得在cpp文件里打补丁"compileCommands": "${workspaceFolder}/build/compile_commands.json"
},
{
"label": "release",
"type": "shell",
"command": "catkin_make -DCMAKE_BUILD_TYPE=Release",//这个是我们原本想在shell需要运行的命令,"-DCMAKE_BUILD_TYPE=Release"表示正常编译
"args": [],
"group": {"kind":"build","isDefault":true},
"presentation": {
"reveal": "always"
},
"problemMatcher": "$catkin-gcc"
},
{
"label": "clean",
"type": "shell",
"command": "catkin_make clean",//"clean"清除之前编译的文件
"args": [],
"group": {"kind":"build","isDefault":true},
"presentation": {
"reveal": "always"
},
"problemMatcher": "$catkin-gcc"
}
]
}
2.launch.json(Debug调试的配置文件)
"在vscode里面已经继承了GDB调试器,点击vscode左侧的debug按钮时会自动生产一个launch.json文件,需要自己 更改该文件中的“program”项 ,更改为编译后的可执行文件的路径下的文件(需要二进制文件),对应ROS通过catkin_make生产可执行文件的路径通常在 /devel/lib/ 下,后面跟上你设置好的package名和可执行文件名,然后需要增加 "preLaunchTask"项,其参数需要与task.json文件中的“label”项设置的名称相同"
{
// 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", // 调试方式,还可以选择attach
"program": "${workspaceFolder}/devel/lib/smart_car/smart_car", //设置要调试的ros节点的路径(完整路径,支持相对路径)
"args": [], // 设置ros节点所需要的参数,没有参数留空即可
"stopAtEntry": false, // 是否停在程序入口点(停在main函数开始)
"cwd": "${workspaceFolder}", // 调试程序时的工作目录
"environment": [],//针对调试的程序,要添加到环境中的环境变量. 例如: [ { "name": "squid", "value": "clam" } ]
"externalConsole": false, //如果设置为true,则为应用程序启动外部控制台。 如果为false,则不会启动控制台,并使用VS Code的内置调试控制台。
"MIMode": "gdb", // VSCode要使用的调试工具
"preLaunchTask": "catkin_make", / 这个重要,需要与task中的label相同
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
3. c_cpp_properties.json
这个文件一般不需要改动,在安装好相应的ROS插件之后,在VScode中打开工作空间的文件夹就会c_cpp_properties.json自动配置好。
具体细节,可参考: