Chris G.
Chris G.

Reputation: 25974

golang dlv unable to see source:: no such file or directory

In a docker container:

docker run \
                --rm -it \
                -p 80:80 \
                -p 2345:2345 \
                -v $(pwd)/src:/go/src/ \
                --security-opt="seccomp=unconfined" \
                --privileged \
                --cap-add SYS_PTRACE \
                golang bash

In the container at $GOPATH:

go get -u github.com/derekparker/delve/cmd/dlv

dlv version
Delve Debugger
Version: 1.1.0
Build: $Id: 1990ba12450cab9425a2ae62e6ab988725023d5c 

dlv debug app --headless --listen=0.0.0.0:2345 --api-version=2

In mac terminal at $GOPATH::

dlv version
Delve Debugger
Version: 1.1.0
Build: $Id: 1990ba12450cab9425a2ae62e6ab988725023d5c $

 dlv connect 127.0.0.1:2345

I get the following, but unable to list source?

dlv connect 127.0.0.1:2345
Type 'help' for list of commands.
(dlv) b main.go:29
Breakpoint 1 set at 0x7f584d for main.main.func1() /go/src/app/main.go:29
(dlv) c
> main.main.func1() /go/src/app/main.go:29 (hits goroutine(4):1 total:1) (PC: 0x7f584d)
(dlv) l
> main.main.func1() /go/src/app/main.go:29 (hits goroutine(4):1 total:1) (PC: 0x7f584d)
Command failed: open /go/src/app/main.go: no such file or directory

Note: I am in $GOPATH in both the dlv server and client:

In container:

ls $GOPATH/src/app
layout.html  main.go  mypack

In mac terminal:

ls $GOPATH/src/app
layout.html main.go     mypack

vs code launch.json:

{
    // 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": "Connect to server",
            "type": "go",
            "request": "launch",
            "mode": "remote",
            "remotePath": "${workspaceFolder}",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${workspaceFolder}",
            "env": {},
            "args": [],
            "trace": "verbose"
        },
    ]
}

Upvotes: 3

Views: 6527

Answers (3)

zakaria amine
zakaria amine

Reputation: 3682

I wanted to add to the answers above that you do not necessarily need to create a config.yaml file to set substitute-path, you can also do so from inside dlv shell by running: config substitute-path / /root

Upvotes: 0

Gopi Palamalai
Gopi Palamalai

Reputation: 416

On my Ubuntu 18.04 I see the location of the file as ~/.config/dlv/config.yml. Here is an example:

substitute-path: - {from: /code, to: /home/foo/git/repo}

Upvotes: 2

connorwstein
connorwstein

Reputation: 305

See https://github.com/go-delve/delve/issues/1438. Solution is to put this in $HOME/.dlv/config.yml:

substitute-path: - {from: /, to: /root}

Upvotes: 3

Related Questions