目录
1. 用launch.json调试在vscode程序
- 首先在vscode安装cmake tools 和 c/c++插件,cmake 和 gsb
- 在工程里 :新建build文件夹,然后cmake .. 和 make
记得在CMakefiles.txt加上---
调试c文件
set(CMAKE_BUILD_TYPE DEBUG)
set(CMAKE_C_FLAGS "-g")
调试c++文件
set(CMAKE_BUILD_TYPE DEBUG)
set(CMAKE_CXX_FLAGS "-g")
- 创建launch.json(用于调试)主要就是"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": [
{
"type": "cppdbg",
"request": "launch",
"name": "Debug",
"program": "/home/pc123/Public/workspace/mqtt/mqtt-demo/MQTT-C-master/MQTT-C-master/build/simple_publisher",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
然后直接点击调试即可,编译是cmake、make编译出来的
2. 用sudo 权限调试程序
Hi guys,
As a workaround, you can decorate existing gdb binary with a bash script and then use it.
Steps are,
cd /usr/bin
sudo mv gdb gdborig
Now you need to create a bash script named gdb with following content.
sudo vim gdb
Content of the bash is;
#!/bin/sh
sudo gdborig $@
Finally, make the script runnable.
sudo chmod 0755 gdb
Then you should be OK.