1.在我們的ROS工作空間目錄打開vscode:
code .
2.輸出編譯命令文件:
catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=Yes
3.生成c_cpp_properties.json
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64", "compileCommands": "${workspaceFolder}/build/compile_commands.json"//上面的編譯文件 } ], "version": 4 }
4.生成task.json文件,設置catkin_make
{ "version": "2.0.0", "tasks": [ { "label": "catkin_make", //代表提示的描述性信息 "type": "shell", //可以選擇shell或者process,如果是shell代碼是在shell里面運行一個命令,如果是process代表作為一個進程來運行 "command": "catkin_make",//這個是我們需要運行的命令 "args": [],//如果需要在命令后面加一些后綴,可以寫在這里,比如-DCATKIN_WHITELIST_PACKAGES=“pac1;pac2” "group": {"kind":"build","isDefault":true}, "presentation": { "reveal": "always"//可選always或者silence,代表是否輸出信息 }, "problemMatcher": "$msCompile" }, ] }
5.GDB debug的配置,配置launch.json文件
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", // 配置名稱,將會在調試配置下拉列表中顯示 "type": "cppdbg", // 調試器類型 該值自動生成 "request": "launch", // 調試方式,還可以選擇attach "program": "${workspaceRoot}/devel/lib/waypoint_follower/pure_persuit", //要調試的程序(完整路徑,支持相對路徑) "args": [], // 傳遞給上面程序的參數,沒有參數留空即可 "stopAtEntry": false, // 是否停在程序入口點(停在main函數開始) "cwd": "${workspaceRoot}", // 調試程序時的工作目錄 "environment": [], //針對調試的程序,要添加到環境中的環境變量. 例如: [ { "name": "squid", "value": "clam" } ] "externalConsole": false, //如果設置為true,則為應用程序啟動外部控制台。 如果為false,則不會啟動控制台,並使用VS Code的內置調試控制台。 "MIMode": "gdb", // VSCode要使用的調試工具 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
6.問題
6.1 poll failed with error Interrupted system call
GDB 多線程 (non-stop)
1. 背景
這幾天在擴展 ngx_lua 模塊,但 gdb 定位時,提示:Thread debugging using libthread_db enabled。poll failed with error Interrupted system call。
2. GDB non-stop 配置
把以下3行添加到 ~/.gdbinit 來打開 non-stop 模式
set target-async 1 set pagination off set non-stop on
PS:無 ~/.gdbinit 文件,可以創建此文件,或修改 /etc/gdb 下對應文件
3. 文件更新立即生效
source ~/.gdbinit
https://www.w3cschool.cn/notebook/notebook-ky9l2mtk.html