登录
首页 >  Golang >  Go问答

调试 Go 时在 VS Code 中缺少变量和调用堆栈信息

来源:stackoverflow

时间:2024-02-29 08:48:27 118浏览 收藏

有志者,事竟成!如果你在学习Golang,那么本文《调试 Go 时在 VS Code 中缺少变量和调用堆栈信息》,就很适合你!文章讲解的知识点主要包括,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~

问题内容

我想使用 vscode 和 wsl 进行开发。 我在调试 go 应用程序时遇到问题,但我不知道为什么。我没有看到调用堆栈中的内容,没有变量,而且从断点跳转到断点的按钮也是灰色的。我的调试控制台日志很干净,没有错误(请参阅下面的详细信息)我尝试按照这些文章来设置我的环境:

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 调试器。另外,我的 go 工作目录是 /mnt/c/users/cloudnaut/gospace/go

它具有通用的 go 项目结构:

.
├── bin
├── pkg
└── src
    └── github.com
        └── cloudnaut
            └── project1
                └── main.go

一切看起来都很好。 go:安装/更新工具安装在我的单独路径中。我的 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 调试器界面中,我看不到变量和堆栈跟踪。问题是,我现在也看到错误或其他东西。我的调试控制台与 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]

没有别的了。调试器中的“step over/step info/step out”按钮呈灰色。我只能按暂停、重新启动和停止。

参见:

图片vs代码调试器问题


解决方案


我带来了我自己问题的解决方案:

问题在于,由于某些不受支持的系统调用,Go dlv 调试器无法与 WSL 1 一起使用。它仅适用于 WSL 2,仅包含在 Microsoft 内部版本中。

参见: https://github.com/microsoft/vscode-go/issues/2505

理论要掌握,实操不能落!以上关于《调试 Go 时在 VS Code 中缺少变量和调用堆栈信息》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>