我想将VSCode与WSL一起使用进行开发。
我在调试Go应用程序时遇到问题,我不知道为什么。我看不到调用堆栈中的内容,没有变量,也没有显示从断点跳到断点的按钮为灰色。我的DEBUG Console日志是干净的,没有错误(请参阅下面的详细信息),我尝试按照以下文章来设置我的环境:
https://github.com/Microsoft/vscode-go/wiki/GOPATH-in-the-VS-Code-Go-extension
https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code
所以,我详细地做:
首先,我告诉VSCode从当前工作区动态设置我的GOPATH,并通过go.toolsGopath将GooTools安装与我的GOPATH分开。我的settings.json看起来像这样:
{
"go.inferGopath": true,
"go.toolsGopath": "/mnt/c/Users/cloudnaut/gospace/gotools",
}
因此,我的GoTools已安装到/ mnt / c / Users / cloudnaut / gospace / gotools。我还安装了dlv调试器。另外我去的工作目录是
/mnt/c/Users/cloudnaut/gospace/go
它具有通用的go项目结构:
.
├── bin
├── pkg
└── src
└── github.com
└── cloudnaut
└── project1
└── main.go
一切似乎都很好。
Go:Install/Update Tools
安装在我的单独路径中。我的GOPATH结构也可以使用。我使用GO:Current GOPATH
显示我想要的正确的GOPATH,并且go install
还在/ bin中从main.go创建go二进制文件。完美的...现在,我要开始调试。我只是使用一个简单的launch.json文件直接指向我的main.go
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"showLog": true,
"type": "go",
"request": "launch",
"mode": "auto",
"program": "/mnt/c/Users/cloudnaut/gospace/go/src/github.com/cloudnaut/project1/main.go",
"env": {},
"args": []
}
]
}
因此,当我现在开始调试时(设置了断点并显示在BREAKPOINTS下),他在文件夹中创建了
__debug_bin
。但是在我的vscode调试器界面中,没有看到任何变量和stacktrace。问题是,我现在也看到了错误或其他信息。我的带有showLog: true
选项的调试控制台几乎是干净的。它仅包含以下几行:API server listening at: 127.0.0.1:34477
2019-12-19T13:55:52+01:00 info layer=debugger launching process with args: [/mnt/c/Users/cloudnaut/gospace/go/src/github.com/cloudnaut/project1/__debug_bin]
没有其他的。调试器的“逐步/逐步信息/逐步退出”按钮显示为灰色。我只能按暂停,重新启动和停止。
看到:
Picture VS Code Debugger Problem
最佳答案
我针对自己的问题提出了解决方案:
问题是,由于某些不受支持的系统调用,Go dlv调试器无法与WSL 1一起使用。它仅与WSL 2一起使用,仅包含在Microsoft内部人员构建中。
看到:
https://github.com/microsoft/vscode-go/issues/2505
关于debugging - 使用VS Code进行调试不起作用。没有变量,调用堆栈等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59410642/