Contents

wsl2搭建vscode+go+debug

wsl1不支持远程调试,必须是wsl2才可以使用

1
2
wsl -l -v
wsl --set-version Ubuntu-20.04 2

https://static.duan1v.top/images/D6opftFzNaZPVuC.png

安装dlv(略)

vscode生成测试文件,并补充完整

  • 打开需要测试的文件,f1或者shift+ctrl+p,键入test,选择如图选项

https://static.duan1v.top/images/hvwF31tAj4VrZ97.png

  • todo部分补充完整

https://static.duan1v.top/images/brA5Tp7jsYkiJ2F.png

配置

  • 生成配置文件

https://static.duan1v.top/images/TeURr51k4f3698y.png

  • 更改配置
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
            "name": "Connect to server",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "remotePath": "/",
            "debugAdapter": "dlv-dap",
            "port": 12345,
            "host": "127.0.0.1"
        }

https://static.duan1v.top/images/PdMsFauTEzyNWmw.png

  • 添加断点,点击debug_test 开始debug

https://static.duan1v.top/images/z5ErMwbBIhYu3UH.png

  • 手动触发

执行命令

1
-> % dlv debug --headless --listen=:12345 --log --api-version=2

点击按钮

https://static.duan1v.top/images/1obgvFEA4jVuZiK.png

coffee