我正在尝试在 VSCode 中配置调试器</strong>
我浏览了 official documentation为 C/C++ 设置 VSCode 调试器,但它不起作用。
Documentation states the steps for setting up vscode debugger for powershell in windows.
但我正在尝试使用 git bash 设置 调试器 作为我在 Windows 中的默认集成终端。
我已将 git bash 添加为默认终端,但我无法将 调试器 与作为集成 终端 的 git bash 一起设置。
默认配置文件:
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。
最近几天我一直在处理这个调试问题,但还没有找到任何解决方法。
我如何通过配置文件更改/更新以在 VSCode 中使用 git bash 作为默认集成终端 调试。
最佳答案
It seems like the command property in tasks.json is incorrect, as bash converts
"C:\MinGW\bin\g++.exe" -> "C:MinGWbing++.exe"
然后尝试类似 cygwin 的路径:
/c/MingW/bin/g++.exe
# or
/C/MingW/bin/g++.exe
然后检查它是否被 git bash session 正确解释。
关于visual-studio-code - 配置 launch.json、task.json 和 settings.json 以在 VS Code 中使用 git bash 作为默认终端进行调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62775004/