VScode 配置 debug环境

首先请阅读官方文档

Debug python

  • 在vscode 中安装好对应的python 插件

运行程序不存在输入参数的时候

  • 当运行python脚本不存在输入参数的时候,可以使用右上角的直接开始debug
  • 然后开始调试即可。

当需要配置输入参数的时候

  • 在当前项目下 .vscode目录 中 添加 .launch.json 文件。

    {
    // 使用 IntelliSense 了解相关属性。
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Python 调试程序: 包含参数的当前文件",
    "type": "debugpy",
    "request": "launch",
    "program": "{file}", "console": "integratedTerminal", "args": [ "-i", "{workspaceFolder}
    ]
    }
    ]
    }

  • 启动lacunch.json 开始调试。

Debug CPP

  • 首先还是安装好对应的插件,本文,使用cmake来管理整个cpp 项目。

  • 关于cmake 管理工程, 使用CMakeLists.txtCMakePresets.json 来搭配使用。 cmake version > 3.27。本文使用CMake Tools 与 搭配 CMakePresets.json 来使用。通过配置来完成传cmake变量,以及控制多线程编译,以及执行target等配置。

  • CMakePresets.json 内容如下。

    {
    "version": 3,
    "configurePresets": [
    {
    "name": "base",
    "hidden": true,
    // "generator": "Ninja",
    "binaryDir": "{sourceDir}/out/build/{presetName}",
    "installDir": "{sourceDir}/out/install/{presetName}"
    },
    {
    "name": "x64-debug",
    "displayName": "x64 Debug",
    "inherits": "base",
    "hidden": true,
    "architecture": {
    "value": "x64",
    "strategy": "external"
    },
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug"
    }
    },
    {
    "name": "x64-release",
    "displayName": "x64 Release",
    "inherits": "x64-debug",
    "hidden": true,
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Release"
    }
    },
    {
    "name": "cuda-debug",
    "displayName": "Cuda x64 Debug",
    "inherits": "x64-debug",
    "cacheVariables": {
    "BACKEND": "ort-cuda"
    }
    },
    {
    "name": "cuda-release",
    "displayName": "Cuda x64 Release",
    "inherits": "x64-release",
    "cacheVariables": {
    "BACKEND": "ort-cuda"
    }
    },
    }
    ]
    "buildPresets": [
    {
    "name": "cuda-release",
    "description": "",
    "displayName": "",
    "jobs": 16,
    "verbose": false,
    "configuration": "Release",
    "targets": [
    "install"
    ],
    "configurePreset": "cuda-release"
    },
    {
    "name": "trt-release",
    "description": "",
    "displayName": "",
    "jobs": 16,
    "verbose": false,
    "configuration": "Release",
    "targets": [
    "install"
    ],
    "configurePreset": "trt-release"
    }
    ]

  • cmake tool 中选择对应的目标,进行预配置,编译以及执行。

当没有传参时,Debug

  • 当没有参数传递的时候,debug,直接使用cmake tool 中的调试开启调试,或者执行 也同理

当存在参数传递时。

  • 配置.vscode 中的 launch.json 文件。

    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "(msvc) Launch",
    "type": "cppvsdbg",
    "request": "launch",
    // Resolved by CMake Tools:
    "program": "{command:cmake.launchTargetPath}", "args": ["{workspaceFolder}\config.txt, "{workspaceFolder}\\model.onnx"], "stopAtEntry": false, "cwd": "{command:cmake.launchTargetDirectory}",
    "environment": [
    {
    // add the directory where our target was built to the PATHs
    // it gets resolved by CMake Tools:
    "name": "PATH",
    "value": "{env:PATH}:{command:cmake.getLaunchTargetDirectory}"
    }
    ],
    "externalConsole": true
    }
    ]
    }

  • 然后按 F5 开始调试。

相关推荐
陈言必行3 天前
Unity 性能优化 之 编辑器创建资源优化( 工作流 | 场景 | 预制体)
unity·编辑器·游戏引擎
CAE虚拟与现实3 天前
VSCode中的下载VSIX是指什么?
ide·vscode·编辑器
路边闲人23 天前
vscode启用GEMINI CODE ASSIST插件
ide·vscode·gemini
小蕾Java3 天前
Java 开发工具,最新2025 IDEA使用(附详细教程)
java·ide·intellij-idea
CAE虚拟与现实3 天前
VSCode官方汉化包
ide·vscode·编辑器·vscode汉化
CAE虚拟与现实3 天前
VSCode创建Python项目和运行py文件
ide·vscode·编辑器
资讯第一线3 天前
《RAD Studio 13.0》 [DELPHI 13.0] [官方原版IOS] 下载
ide
过-眼-云-烟3 天前
新版Android Studio能打包但无法run ‘app‘,编译通过后手机中没有安装,顶部一直转圈
android·ide·android studio
Stardep3 天前
ssh远程连接服务器到vscode上“连接失败”
服务器·vscode·ssh
扯淡的闲人3 天前
多语言编码Agent解决方案(4)-Eclipse插件实现
java·ide·eclipse