在win10下使用vscode和winbash调试C代码,这次真的简单能用

以前写过一个很麻烦也不实用的方法。

现在发现vscode本来就支持win10 bash的编译调试。

如下图 添加一个bash on windows launch。

在win10下使用vscode和winbash调试C代码,这次真的简单能用

我生成可用的配置如下

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Bash on Windows Launch",
"type": "cppdbg",
"request": "launch",
"program": "main", /*我的可执行文件*/
"args": [],
"stopAtEntry": true,
"cwd": "/mnt/d/work/main2", /*我的工程路径,代码和可执行文件都在这里*/
"environment": [],
"externalConsole": true, /*F5 后直接端点在main函数*/
"pipeTransport": {
"debuggerPath": "/usr/bin/gdb",
"pipeProgram": "C:\\Windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"], /*这个默认没有,搞了好久试出来*/
"pipeCwd": ""
},
"sourceFileMap": {
"/mnt/d/work/main2": "${workspaceFolder}" /*把linux路径转换成windows,这样code才能找到代码*/
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}


就简单的介绍了,编个linux代码测试方便多了。 希望对大家有帮助