当前位置:   article > 正文

VSCode远程调试Linux程序

VSCode远程调试Linux程序

VS 安装CodeRunner插件

菜单→添加配置→lunch.json中设置如下:
program填入要调试的文件

{
  "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
          }
      ]
    },
  ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
如果需要sudo权限调试修改如下:
{
  "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
          }
      ]
    },
  ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

新建脚本sudo_gdb

sudo /usr/bin/gdb $@
  • 1

chmod 777 sudo_gdb

路径填在字段miDebuggerPath

调试快捷键

继续 / 暂停 F5
跳过 F10
跳入 F11
跳出 Shift+F11
重启 Ctrl+Shift+F5
停止 Shift+F5

添加终端任务:

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

内容如下:
在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/941585
推荐阅读
相关标签
  

闽ICP备14008679号