下面提供 vscode 中 python 和 c++ 调试配置的 launch.json (好用,已用好几年,建议收藏)

{
  // 使用 IntelliSense 了解相关属性。 
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "python debug",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "python": "/root/anaconda3/envs/py385/bin/python",
      "justMyCode": true,
      "cwd": "${fileDirname}"
    },
    {
      "name": "gdb debug",
      "type": "cppdbg",
      "request": "launch",
      "program": "/workspace/pro/facedet/build/release/facedet",
      "args": [],
      "miDebuggerPath": "/usr/bin/gdb",
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      // "cwd": "/workspace/pro/",
      "environment":  [],
      "externalConsole": false,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "为 gdb 启用整齐打印",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

若要配置传参,比如 python 调试的时候添加传参 (因为很多 py 脚本执行的时候都喜欢用 --xxx 来传参,这样调试的时候就不方便了),这个时候可以在 launch.json 中添加 args 参数

记录 | vscode pyhton c++调试launch.json配置_launch.json


c++ 同理