dongqiu3254 2019-09-13 05:44
浏览 67

调试在命令行中有效,但在UI中未命中断点

I have installed the following in my Windows 10 machine:

  • VS Code - version 1.38.1
  • Golang - version go1.13
  • Delve - version 1.3.0

I have set GOROOT and GOPATH in environment variables. My GOPATH has the following three folders:

  • src
  • bin
  • pkg

Under src, I have created a basic sam-app. It auto-creates main_test.go file. When I do 'debug test', breakpoint is not hitting in UI. Howerver, I am able to debug using dlv in command line.

  • I have tried different configurations in launch.json. None of them worked. In my friend's machine, the UI Debugging works even without configurations

  • In VS Code settings --> node debug --> auto attach --> I have set 'on'

  • I have closed VS Code and re-opened. It did not work

  • I have opened VS Code as Administrator, it did't work either

  • I have uninstalled and reinstalled VS Code

  • I have uninstalled and reinstalled Golang

  • I have installed Go extension in VS Code

    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")
            }
        })
    }
    

I want the breakpoint to be hit, in UI, when I debug main.go or main_test.go.

UPDATE:

After I downgraded my VS Code to 1.30.2 and installed Go extension and Delve, I get the following error when I debug:

"Debug adapter process has terminated unexpectedly (read error)"

  • 写回答

1条回答 默认 最新

  • duanla4959 2019-09-14 11:36
    关注

    I solved it as follows:

    • Deleted the '%USERPROFILE%\.vscode\extensions\ms-vscode.go-0.11.4' folder alone & reinstalled Go extension -- It did NOT work

    • Deleted the entire '%USERPROFILE%\.vscode' folder & reinstalled Go extension -- It worked :)

    Some other extension was erroneous and so the Go debug failed to work. Cleaning all the extensions fixed it.

    Hope, this might be useful to others.

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R