【问题标题】:Debugging works in command line but breakpoint is not hit in UI调试在命令行中工作,但在 UI 中未命中断点
【发布时间】:2020-01-14 23:47:52
【问题描述】:

我在我的 Windows 10 机器上安装了以下内容:

  • VS 代码 - 版本 1.38.1
  • Golang - 版本 go1.13
  • Delve - 1.3.0 版

我在环境变量中设置了 GOROOT 和 GOPATH。我的 GOPATH 有以下三个文件夹:

  • 源代码
  • bin

在 src 下,我创建了一个基本的 sam-app。它自动创建 main_test.go 文件。当我进行“调试测试”时,断点没有在 UI 中命中。但是,我可以在命令行中使用 dlv 进行调试。

  • 我在 launch.json 中尝试了不同的配置。他们都没有工作。在我朋友的机器上,UI Debugging 即使没有配置也可以工作

  • 在 VS Code 设置中 --> 节点调试 --> 自动附加 --> 我已经设置了'on'

  • 我已关闭 VS Code 并重新打开。它没有工作

  • 我已以管理员身份打开 VS Code,它也不起作用

  • 我已经卸载并重新安装了 VS Code

  • 我已经卸载并重新安装了 Golang

  • 我已经在 VS Code 中安装了 Go 扩展

    package main
    
    import (
        "fmt"
        "net/http"
        "net/http/httptest"
        "testing"
    
        "github.com/aws/aws-lambda-go/events"
    )
    
    func TestHandler(t *testing.T) {
        t.Run("Unable to get IP", func(t *testing.T) {
            DefaultHTTPGetAddress = "http://127.0.0.1:12345"
    
            _, err := handler(events.APIGatewayProxyRequest{})
            if err == nil {
                t.Fatal("Error failed to trigger with an invalid request")
            }
        })
    
        t.Run("Non 200 Response", func(t *testing.T) {
            ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                w.WriteHeader(500)
            }))
            defer ts.Close()
    
            DefaultHTTPGetAddress = ts.URL
    
            _, err := handler(events.APIGatewayProxyRequest{})
            if err != nil && err.Error() != ErrNon200Response.Error() {
                t.Fatalf("Error failed to trigger with an invalid HTTP response: %v", err)
            }
        })
    
        t.Run("Unable decode IP", func(t *testing.T) {
            ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                w.WriteHeader(500)
            }))
            defer ts.Close()
    
            DefaultHTTPGetAddress = ts.URL
    
            _, err := handler(events.APIGatewayProxyRequest{})
            if err == nil {
                t.Fatal("Error failed to trigger with an invalid HTTP response")
            }
        })
    
        t.Run("Successful Request", func(t *testing.T) {
            ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                w.WriteHeader(200)
                fmt.Fprintf(w, "127.0.0.1")
            }))
            defer ts.Close()
    
            DefaultHTTPGetAddress = ts.URL
    
            _, err := handler(events.APIGatewayProxyRequest{})
            if err != nil {
                t.Fatal("Everything should be ok")
            }
        })
    }
    

我希望在调试 main.go 或 main_test.go 时在 UI 中触发断点。

更新:

在我将 VS Code 降级到 1.30.2 并安装 Go 扩展和 Delve 后,我在调试时收到以下错误:

“调试适配器进程意外终止(读取错误)”

【问题讨论】:

    标签: unit-testing go visual-studio-code delve


    【解决方案1】:

    我是这样解决的:

    • 单独删除了 '%USERPROFILE%\.vscode\extensions\ms-vscode.go-0.11.4' 文件夹并重新安装了 Go 扩展 -- 没有用

    • 删除了整个 '%USERPROFILE%\.vscode' 文件夹并重新安装了 Go 扩展程序 -- 成功了 :)

    其他一些扩展是错误的,因此 Go 调试失败。清理所有扩展修复它。

    希望,这可能对其他人有用。

    【讨论】:

      猜你喜欢
      • 2011-10-30
      • 2016-10-03
      • 1970-01-01
      • 2010-11-05
      • 1970-01-01
      • 2016-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多