vscode在ubuntu调试

目录

1. 用launch.json调试在vscode程序

2. 用sudo 权限调试程序


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.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值