drpmazn9021
2019-06-29 19:08 阅读 89
已采纳

无法在Visual Studio代码中调试Go

I have a folder, D:\Data\Git\go\src\demo containing one file, main.go. I have installed go1.12.6 windows/amd64. (I am running Windows 10) I am unable to debug the application - the debugger flashes on the screen then disappears ==> nothing happens ==> even though I have set a breakpoint, it does not break into the code for interactive step-through! I can run the app from the commandline ==> go run main.go (current directory is where main.go is located)

My launch.json looks like this:

{
    // 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",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "env": {},
            "args": []
        }
    ]
}

Here is my app:

package main

import "fmt"

func main() {
    s := []int{2, 3, 5, 7, 11, 13}
    s = s[1:4]
    fmt.Println(s)
}

How do I get to debug in VS Code?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    drqrdkfue521903877 drqrdkfue521903877 2019-07-06 08:28

    Here is the answer:

    Ctrl+Shift+P ==> Open Launch.json ==> Save ==> Voila!

    (It works. I am now able to step through and debug a simple application with one main.go file in Visual Studio Code)

    Note that I have installed all of the dev tools (as per @owlwalks above), as well as dlv (see here: https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code)

    点赞 评论 复制链接分享

相关推荐