Remote debugging - Unverified breakpoint

前端 未结 2 866
鱼传尺愫
鱼传尺愫 2021-01-14 12:54

Hope I can explain this right.

Update: I can confirm that dlv debug -l 127.0.0.1:2345 does work. Therefore I must be in VsCode launch.json

相关标签:
2条回答
  • 2021-01-14 13:44

    I figured out my problem by adding the "trace" option to the launch.json (in VS Code)

        {
            "name": "Attach remote ",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "remotePath": "/home/me/goprojects/src/github.com/owner/project/package",
            "port": 2345,
            "host": "xxxx.xyz",
            "trace":"log",
    
        }
    

    Doing that revealed in the Debug Console that it was looking for the source file with the wrong path. I realised that remotePath in the launch.json should be (for my setup at least) just /home/me/goprojects/src/github.com/owner/project

    So, try adding trace and scrutinize the Debug Console

    0 讨论(0)
  • 2021-01-14 13:51

    I managed to get delve and vscode with go working for me by using docker-compose.

    I use my Dockerfile to build the app as you do and just override some container attributes in my docker-compose.yml.

    Here's how my docker-compose.yml looks :

    version: '2'
    services:
      my_app:
        build: .
        security_opt:
          - seccomp:unconfined
        entrypoint: dlv debug github.com/my_user/my_app -l 0.0.0.0:2345 --headless=true --log=true -- server
        volumes:
          - .:/opt/go/src/github.com/my_user/my_app
        ports:
          - "2345:2345"
        expose:
          - "2345"
    

    And the launch.json file :

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Remote Docker",
                "type": "go",
                "request": "launch",
                "mode": "remote",
                "remotePath": "/opt/go/src/github.com/my_user/my_app",
                "port": 2345,
                "host": "192.168.99.100",
                "program": "${workspaceRoot}",
                "env": {},
                "args": []
            }
        ]
    }
    

    Note that since I'm on OS X the IP is what my docker-machine ip default prints. You can change it to 127.0.0.1 if this is what your docker-machine ip outputs.

    On docker-compose up, my_app prints :

    my_app_1 | 2016/12/14 12:41:32 server.go:71: Using API v1

    my_app_1 | 2016/12/14 12:41:32 debugger.go:65: launching process with args: [/opt/go/src/github.com/my_user/my_app/debug server]

    my_app_1 | API server listening at: [::]:2345

    And after setting up some breakpoints and attaching the debugger it works.

    Hope this helps!

    0 讨论(0)
提交回复
热议问题