如何在Visual Studio代码中使用Delve调试器 [英] How to use Delve debugger in Visual Studio Code

查看:189
本文介绍了如何在Visual Studio代码中使用Delve调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为VS代码安装了Go扩展,但无法使其正常工作。

dlv debug可以从终端正常工作。

  dlv debug src / github.com / user / hello 
$ b

launch.json

  {
版本:0.2.0,
配置:[
{
name:Launch,
type:go,
request:launch,
mode:debug,
program:$ {workspaceRoot},
env:{},
args:[]
}
]
}

你知道如何设置它吗?

解决方案

使用Golang在Visual Studio代码中进行调试,请执行以下步骤:

 (注意:对于Windows操作系统,将所有$ GOPATH替换为%GOPATH %)




  • 安装最新版


    I have installed the Go extension for VS Code, but unable to make it work.

    "dlv debug" works alright from the terminal.

    dlv debug src/github.com/user/hello
    

    The launch.json:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "program": "${workspaceRoot}",
                "env": {},
                "args": []
            }
        ]
    }
    

    Do you know how to set it up?

    解决方案

    For using Delve debugger in Visual Studio Code with Golang, do the following steps:

    ( Note: for Windows OS replace all $GOPATH with %GOPATH% )
    

    • Install Latest Golang and set GOROOT and GOPATH
    • Add $GOPATH/bin to your OS PATH environment variable.
    • set environment variable: GO15VENDOREXPERIMENT = 1
    • run: go get github.com/derekparker/delve/cmd/dlv and make sure dlv binary generated in your $GOPATH/bin
    • Install Visual Studio Code
    • Launch VS Code Quick Open (Ctrl+P), paste this command: ext install Go , and press enter.
    • click install Rich Go language support for Visual Studio Code
    • click Enable and restart Visual Studio Code
    • Inside Visual Studio Code Open Folder Ctrl+Shift+E , e.g.: $GOPATH\src\hello\
    • Then Open hello.go from that folder (or make new file Ctrl+N and save it on this folder):

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello World!")
        i := 101
        fmt.Println(i)
    }
    

    • Then Open Debugger Ctrl+Shift+D
    • on this line: i := 101 press F9 to set or toggle beakpoint.
    • Press F5 to start debugging or to Run the application, if asked to select environment: select Go.
    • Press F10 to Step Over.
    • Press F11 to Step Into.
    • Press Shift+F11 to Step Out.
    • Press Shift+F5 to Stop Debugging.
    • Press Ctrl+Shift+F5 to Restart Debugging.

    My launch.json untouched:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "remotePath": "",
                "port": 2345,
                "host": "127.0.0.1",
                "program": "${workspaceRoot}",
                "env": {},
                "args": [],
                "showLog": true
            }
        ]
    }
    

    Result:

    这篇关于如何在Visual Studio代码中使用Delve调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆