Nov 18, 2019

[Go][Delve] Remote debugging command

While debugging, use this argument as in go compile command:
$ go build -gcflags="all=-N -l"  // -N: disable optimizations -l: disable inlining

Delve on remote machine should be the same version of local machine, as well as the go compiler.

Start the process through delve on remote machine
$ dlv --listen=:2345 --headless=true --api-version=2 exec ./application

or attach to the running process on remote machine:
$ dlv --listen=:2345 --headless=true --api-version=2 attach <pid>


Docker run command:
$ dk run --security-opt="apparmor=unconfined" --cap-add=SYS_PTRACE

Docker file:
FROM golang:1.11.5-alpine3.8 AS build-env
 
ENV CGO_ENABLED 0
 
# Allow Go to retreive the dependencies for the build step
RUN apk add --no-cache git
 
WORKDIR /goland-debugging/
ADD . /goland-debugging/
 
RUN go build -o /goland-debugging/srv .
 
# Get Delve from a GOPATH not from a Go Modules project
WORKDIR /go/src/
RUN go get github.com/go-delve/delve/cmd/dlv
 
# final stage
FROM alpine:3.8
 
WORKDIR /
COPY --from=build-env /goland-debugging/srv /
COPY --from=build-env /go/bin/dlv /
 
EXPOSE 8080 40000
 
CMD ["/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "exec", "/srv"]

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.