Skip to content

Instantly share code, notes, and snippets.

@ashee
Last active January 5, 2022 20:07
Show Gist options
  • Save ashee/d6d92524a7fccde10f358c4c51973798 to your computer and use it in GitHub Desktop.
Save ashee/d6d92524a7fccde10f358c4c51973798 to your computer and use it in GitHub Desktop.
go debugging in Apple M1

Issue

dlv errors out

$ ~/go/bin/dlv debug ./fdbgrok 
could not launch process: stub exited while waiting for connection: exit status 0

Go env

go env 
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/amitava/Library/Caches/go-build"
GOENV="/Users/amitava/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/amitava/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/amitava/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.17.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.2/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/amitava/prj/fdb-cli/fdbgrok/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sc/dh7gj5050sn5knyx3pgr6xrr0000gn/T/go-build1666671882=/tmp/go-build -gno-record-gcc-switches -fno-common"

Fix

The solution was posted by my friend @StevenACoffman - worked like a charm

What's stopping dlv from working is Apple's debugserver not working. It seems like the debugserver installed by Apple's standalone CommandLineTools package isn't properly signed in some way. There are more details that may be relevant in this issue. I found that all the people for whom debugserver had stopped working shared the following feature:

Reference

$ xcode-select -p
/Library/Developer/CommandLineTools

whereas those for whom it kept working had

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

So I did the following: Uninstall CommandLineTools:

sudo rm -rf /Library/Developer/CommandLineTools

Install Xcode from the App Store Run

xcode-select --install

Open Xcode and accept the prompts to install additional tools And debugging in GoLand works again! (

Works afterwards

$ ~/go/bin/dlv debug main.go
Type 'help' for list of commands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment