VSCode远程调试Linux程序

VS 安装CodeRunner插件

菜单→添加配置→lunch.json中设置如下:

program填入要调试的文件

bash 复制代码
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "gdb renderPng",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/renderPng",
      "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
          }
      ]
    },
  ]
}
如果需要sudo权限调试修改如下:
bash 复制代码
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "gdb renderPng",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/renderPng",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "miDebuggerPath":"/home/pozhu/Desktop/sudo_gdb",
      "setupCommands": [
          {
              "description": "为 gdb 启用整齐打印",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
          },
          {
              "description": "将反汇编风格设置为 Intel",
              "text": "-gdb-set disassembly-flavor intel",
              "ignoreFailures": true
          }
      ]
    },
  ]
}

新建脚本sudo_gdb

bash 复制代码
sudo /usr/bin/gdb $@

chmod 777 sudo_gdb

路径填在字段miDebuggerPath

调试快捷键

继续 / 暂停 F5

跳过 F10

跳入 F11

跳出 Shift+F11

重启 Ctrl+Shift+F5

停止 Shift+F5

添加终端任务:

菜单→终端→添加任务→新建tasks.json

内容如下:

相关推荐
方便面不加香菜3 小时前
Linux--基础IO(一)
linux·运维·服务器
mounter6257 小时前
现代 Linux 内存管理的演进与变革:从传统 LRU 到多代架构 MGLRU
linux·服务器·kernel
赵渝强老师7 小时前
【赵渝强老师】Kubernetes(K8s)中的金丝雀升级
linux·docker·云原生·容器·kubernetes
Qt程序员8 小时前
Linux RCU 原理与应用
linux·c++·内核·linux内核·rcu
The Sheep 20238 小时前
Vue复习
linux·服务器·数据库
兄台の请冷静8 小时前
Linux 安装es
linux·elasticsearch·jenkins
sinat_255487818 小时前
第七部分。介绍MVC(模型-视图-控制器)模式
java·ide·http·tomcat·intellij-idea
fengyehongWorld8 小时前
Linux rg命令
linux
pride.li9 小时前
海思视觉Hi3516CV610--开机自动设置ip
linux·网络·网络协议·tcp/ip
我叫张小白。9 小时前
CentOS 7 安装 Docker并配置镜像加速(完整指南)
linux·docker·centos