在docker容器中:
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在$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在mac终端的$GOPATH::
dlv version
Delve Debugger
Version: 1.1.0
Build: $Id: 1990ba12450cab9425a2ae62e6ab988725023d5c $
dlv connect 127.0.0.1:2345我得到了以下信息,但无法列出源代码?
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注意:我在dlv服务器和客户端都在$GOPATH中:
在容器中:
ls $GOPATH/src/app
layout.html main.go mypack在mac终端中:
ls $GOPATH/src/app
layout.html main.go mypackvs代码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"
},
]
}发布于 2019-01-11 06:24:07
参见https://github.com/go-delve/delve/issues/1438。解决方案是将其放在$HOME/.dlv/config.yml中:
替换路径:-{从: /,到: /root}
发布于 2019-08-15 04:44:14
在我的Ubuntu18.04上,我看到这个文件的位置是~/.config/dlv/config.yml。下面是一个示例:
substitute-path: - {from: /code, to: /home/foo/git/repo}
https://stackoverflow.com/questions/53621853
复制相似问题