I am trying to setup a Delve (dlv) debugger for a GO binary that was built with Bazel.
The binary is to be run within Docker. It runs fine on its own.
But when i try to setup Delve ( dlv ) i get the following error:
could not launch process: fork/exec /go/src/my_bin_svc: function not implemented
Here is the description of the system and build tools:
Host system: Mac OS M1
Build tools: Bazel, building for linux-amd64
Runtime: Docker ( Docker version 20.10.17 )
Here is my bazel build command:
bazelisk build -c dbg --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //...
Here is my BUILD file for my specific service that i am targetting:
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "cmd_lib",
srcs = ["main.go"],
importpath = "github.com/xxxxxxxxxx/src/go-grpc-order-svc/cmd",
visibility = ["//visibility:private"],
deps = [
"//pkg/event",
"//pkg/schema",
"//proto/order",
"//src/go-grpc-order-svc/pkg/client",
"//src/go-grpc-order-svc/pkg/config",
"//src/go-grpc-order-svc/pkg/db",
"//src/go-grpc-order-svc/pkg/repository",
"//src/go-grpc-order-svc/pkg/service",
"@com_github_tinrab_retry//:retry",
"@org_golang_google_grpc//:go_default_library",
],
)
go_binary(
name = "cmd",
embed = [":cmd_lib"],
goarch = "amd64",
goos = "linux",
visibility = ["//visibility:public"],
)
Here is my Dockerfile:
FROM golang:1.18-bullseye
ENV GOOS="linux"
ENV APP_HOME /go/src
RUN mkdir -p "$APP_HOME"
WORKDIR "$APP_HOME"
EXPOSE 50053
EXPOSE 8080
EXPOSE 4000
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go install -gcflags="all=-N -l" -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest
ENV GO111MODULE=off
ENTRYPOINT ["/go/bin/linux_amd64/dlv", "--listen=:4000", "--headless=true", "--api-version=2", "--log=true", "exec", "/go/src/my_bin_svc"]
Here is the part of docker-compose to start my service:
my-bin-svc:
build:
dockerfile: src/go-grpc-order-svc/Dockerfile.debug
context: .
volumes:
#- ./bazel-bin/src/go-grpc-order-svc/cmd/cmd_/cmd:/go/src/order_svc
- ./bazel-out/darwin_arm64-dbg/bin/src/go-grpc-order-svc/cmd/cmd_/cmd:/go/src/my_bin_svc
ports:
- "50053:50053"
networks:
- backend
links:
- order-db
depends_on:
- order-db
Now in bazel i have several folders that contain binaries:
bazel-out/darwin_arm64-dbg <--- which if i am not mistaken contains binaries with debugging symbols ( what i need to use with delve ? ). Binaries from here run fine on their own ( without delve ), but give the above error when are given to dlv.
I also have
bazel-bin <--- which contains my linux binaries that run fine on their own, but give the above error when are given to dlv.
I have tried to search for that specific error but so far did not see anything concrete.
Has anyone seen that error and has any idea what this is ?
Thank you, any help is greatly appreciated.
I have tried to use platform specific targets in docker-compose:
platform: linux/amd64
But so far without success.
This is a known issue with debugging in an amd64 container on ARM, and as far as I can see the only workarounds are to either use QEMU emulation or linux/arm64-based images. See also this issue and the original report on the dlv repo. The first link contains some more details on getting it to work