【发布时间】:2020-07-07 12:11:14
【问题描述】:
我正在尝试在 VSCode 中配置调试器
我查看了official documentation 来设置 C/C++ 的 VSCode 调试器,但它不起作用。
文档说明了设置 vscode 调试器的步骤 powershell 在 Windows 中。
但我正在尝试设置 debugger,并使用 git bash 作为我在 windows 中的默认 集成终端。
我已将 git bash 添加为默认终端,但我无法将 debugger 与 git bash 设置为集成 terminal。
默认配置文件:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
属性:
"externalConsole": false
设置为 false 因为我希望 VSCode 使用集成的默认 bash 终端,而不是使用外部终端进行调试。
tasks.json:
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "clang-x86"
}
],
"version": 4
}
settings.json
{
"files.associations": {
"iostream": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
使用上述配置,当我开始调试时,它给了我以下错误:
tasks.json 中的 command 属性似乎不正确, 作为 bash 转换
"C:\MinGW\bin\g++.exe" -> "C:MinGWbing++.exe"
并给出错误:“找不到命令”,因为 bash 中的反斜杠('\')是一个转义字符。
现在将 tasks.json 中的上述路径更改为 bash 样式:
"command": "C:/MinGW/bin/g++.exe"
解决了上述错误,但现在它对变量 ${file} 给出了相同的错误,因为此路径变量被动态设置为当前打开的文件 .cpp。 p>
过去几天我一直在处理这个调试问题,但还没有找到任何解决方法。
如何通过配置文件更改/更新以在VSCode中使用git bash作为默认集成终端调试。
【问题讨论】:
标签: visual-studio-code vscode-settings git-bash vscode-debugger vscode-tasks