Remote debugging - Unverified breakpoint

做~自己de王妃 提交于 2019-12-19 09:56:19

问题


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

Update: removed the panic. There was a different in go versions. Now the debugger in VsCode is just not working, it says "Unverified breakpoint". But it works fine if I use dlv from terminal, if I am in the folder with the code.

I am trying to remote debug with this sample code.

It works with this change.

Do you know what to do? I have tried to change the launch.json to "program": "${workspaceRoot}", to include the path like "program": "${workspaceRoot}/src/app",.

Launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceRoot}",
            "env": {},
            "args": []
        },
        {
            // To remote debug in Docker, run the following before debugging:
            // # docker build -t webapp-go .
            // # docker run -d --name webapp-go --privileged -p 8080:8080 -p 2345:2345 webapp-go
            // # docker run -d --name webapp-go --privileged -p 8080:8080 -p 2345:2345 -v "${PWD%/*}/src/app/":/go/src/app webapp-go
            // And then each time you want to restart debugging:
            // # docker restart
            "name": "Remote debug in Docker",
            "type": "go",
            "request": "launch",
            "mode": "remote",
            "program": "${workspaceRoot}",
            "env": {},
            "args": [],
            "remotePath": "/go/src/app",
            "port": 2345, // Port 
            "host": "127.0.0.1" // Docker IP
/*            "preLaunchTask": "docker" */ 
        }
    ]
}

Dockerfile:

FROM golang:1.6
RUN go get -u -v github.com/derekparker/delve/cmd/dlv
EXPOSE 2345

# RUN mkdir -p /go/src/app
# WORKDIR /go/src/app
# VOLUME ["src/app2"]

VOLUME ["/go/src/app"]
RUN mkdir -p /go/src/app
WORKDIR /go/src/app
COPY src/app /go/src/app

RUN go-wrapper download
RUN go-wrapper install

EXPOSE 8080
CMD ["dlv", "debug", "--headless", "--listen=:2345", "--log"]

回答1:


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




回答2:


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!



来源:https://stackoverflow.com/questions/39456064/remote-debugging-unverified-breakpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!