Debugging `dockerd` with `dlv`

Hey!

I am trying to understand something inside dockerd using dlv debugger. Unfortunately, every time I am trying to do that I am facing errors. I can’t do dlv exec nor dlv attach.

The following diff shows some changes I applied to make sure that some go optimizations are avoided and debugging is possible:

diff --git i/hack/make/.binary w/hack/make/.binary
index d56e3f3..e6835fa 100644
--- i/hack/make/.binary
+++ w/hack/make/.binary
@@ -84,6 +84,7 @@ hash_files() {
        go build \
                -o "$DEST/$BINARY_FULLNAME" \
                "${BUILDFLAGS[@]}" \
+               -gcflags="all=-N -l" \
                -ldflags "
                $LDFLAGS
                $LDFLAGS_STATIC_DOCKER

I also modified dockerd-rootless.sh to make sure I don’t use plain exec but dlv exec dockerd -- $@. Unfortunately every time I get the following error:

Could not create config directory: mkdir /root/.config: permission denied.could not launch process: could not get .debug_frame section: could not find .debug_frame section

Does anyone have an idea what could be causing it?

INFO:

OS: Fedora 31

go version

go version go1.13.10 linux/amd64
dlv version

Delve Debugger
Version: 1.4.0
Build: $Id: 67422e6f7148fa1efa0eac1423ab5594b223d93b $
docker version

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:27:05 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Found it… It was the presence of -w in the LDFLAGS.