Sto imparando l'applicazione di debug Golang in Docker. Ho successo con il dlv connect
in shell. Potrei aggiungere il punto di rottura, continuare, dopo … posso fare notare in VSCode, ma aspettare per halting
.
Faccio clic su sinistra in function principale, fino a un punto rosso. Quindi fare clic sul button verde, che piace come "play". Programma in corsa contenitore, ma non può fermarsi sulla function principale.
Ho usato VSCode in modo sbagliato? Ho bisogno del tuo aiuto. Grazie.
#Dockerfile FROM supinf/go:1.8-builder RUN apk --no-cache add tini \ && apk --no-cache add --virtual build-dependencies git \ # Compile delve && go get github.com/derekparker/delve/cmd/dlv \ && cd $GOPATH/src/github.com/derekparker/delve \ && go install github.com/derekparker/delve/cmd/dlv \ # Clean up && apk del --purge -r build-dependencies \ && rm -rf /go/src/* ENTRYPOINT ["/sbin/tini", "--"] CMD ["dlv", "-h"]
docker build -t mydelve .
package main import ( "fmt" "sync" "time" ) func dostuff(wg *sync.WaitGroup, i int) { fmt.Printf("goroutine id %d\n", i) time.Sleep(60 * time.Second) fmt.Printf("end goroutine id %d\n", i) wg.Done() } func main() { var wg sync.WaitGroup workers := 10 wg.Add(workers) for i := 0; i < workers; i++ { go dostuff(&wg, i) } wg.Wait() }
docker run --rm -p 2345:2345 -v $GOPATH/src:/go/src -w /go/src/test/dlv --security-opt seccomp=unborderd mydelve dlv debug --headless --listen=:2345 --log`
dlv connect 127.0.0.1:2345 --wd . --log
Funziona.
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "Remote", "type": "go", "request": "launch", "mode": "remote", "program": "${fileDirname}", "port": 2345, "host": "127.0.0.1", "env": {}, "args": [] } ] }
Registri in contenitore
$ docker run --rm -p 2345:2345 -v $GOPATH/src:/go/src -w /go/src/test/dlv --security-opt seccomp=unborderd mydelve dlv debug --headless --listen=:2345 --log 2017/05/22 09:07:56 server.go:73: Using API v1 2017/05/22 09:07:56 debugger.go:97: launching process with args: [/go/src/test/dlv/debug] API server listening at: [::]:2345 2017/05/22 09:08:00 debugger.go:505: continuing goroutine id 3 goroutine id 9 goroutine id 4 goroutine id 5 goroutine id 6 goroutine id 7 goroutine id 8 goroutine id 1 goroutine id 0 goroutine id 2 end goroutine id 6 end goroutine id 3 end goroutine id 9 end goroutine id 4 end goroutine id 5 end goroutine id 8 end goroutine id 7 end goroutine id 1 end goroutine id 0 end goroutine id 2 2017/05/22 09:08:10 debugger.go:496: halting