Cannot run debug Go using VSCode on Mac M1
Asked Answered
R

9

27

I found a topic that encounter the same problem (Can't debug Golang in vscode apple m1) but I'm not sure it's an old solution or not because I'm using the Go version

go1.17.1 darwin/arm64 

with

dlv version 1.7.2 

and

VSCode version 1.60.2 (arm64)

on

Mac M1 BigSur (11.6)

when I run debug (fn+f5) a Debug console shows:

Starting: /Users/username/go/bin/dlv-dap dap --check-go-version=false --listen=127.0.0.1:53115 --log-dest=3 from /Users/username/go/src/project-name
DAP server listening at: 127.0.0.1:53115

and there is a Pop-up error:

Failed to launch: could not launch process: can not run under Rosetta, check that the installed build of Go is right for your CPU architecture

I have tried downgrade go version to 1.16.8 arm64 with dlv 1.6.1 but still got the same error.

I can use go build successfully on both versions.

Ringhals answered 27/9, 2021 at 8:58 Comment(0)
T
30
  1. Ensure your VSCode uses the arm64 version. (it can use a different go version from the system)

  2. Run Go: install/update tools. It will rebuild all tools with the arm64 go version.

Trifocals answered 27/9, 2021 at 22:37 Comment(3)
could you elaborate on this? "Ensure your VSCode uses the arm64 version" ... how?Villada
@PeterMcIntyre what I did is observe the location of the dlv-dap command vscode was using (Note "Starting: /Users/username/go/bin/dlv-dap ..." in the question), then verified this was the same go I had configured in the PATH/command-line using 'which go' (it can be different, AFAIK vscode bases on the GOPATH go env variable). Running "go version" I saw I was using darwin/amd64, NOT ARM. I downloaded the correct version from go.dev/dl and replaced it (by removing the whole 'go' directory and placing the new one in its place)Colostrum
Thanks! Command-Shift-P > "Go: Install/update tools" fixed it for me! Had installed the amd64 instead of arm64 version before and removing and installing the correct version of go wasn't enough as the tools were still for the intel processor!Resolution
H
41

Here is how I resolved this issue.

  1. Uninstall Golang(AMD-64 version).
  2. Install Golang(ARM-64). Confirm it with go env GOARCH
  3. Remove(tools that VS-Code uses) binaries from $GOPATH/bin (Important)
  4. Restart your VS-Code and install tools that VS-Code needed(if not installed vscode will complain and will ask you to install them)

Root cause of the problem: I accidentally installed amd-64 version instead of arm-64 version in my Apple Mac M1.

Thanks to Painhardcore answer for pointing me in right direction.

Hoppe answered 7/3, 2022 at 13:30 Comment(8)
the installed libraries was it for me. I have had both correct packages installed for a bit but I must have installed the wrong Golang for a while early on. I just needed to clear the old binaries and reinstall themMachmeter
thanks, that helped! small note here, as of 1.18 it seems $GOPATH/bin is not in use anymore, rather use ~/go/bin. see https://mcmap.net/q/505100/-gopath-is-empty-gogland-ideSabellian
It felt dangerous to me to remove all binaries in go/bin, but it seems like VSCode re-creates them without problems.Derrickderriey
You can also reinstall the tools that VS Code uses by 1. press F1 and 2. Go: Install/Update Tools 3. Select tools you want to reinstallMerchant
@iamcmnut's comment is gold.Garibold
agreed @Merchant saved me - I did the full reinstall of go - was able to run tests within vscode - but couldn't debug. If I tried to debug - I got that same error "can not run under Rosetta". After reinstall of vs code Go Tools - I was able to debug again. Thanks!Meteoric
Is it worth an update to the instruction not to mention $GOPATH/bin? An unsuspecting person trying sudo rm $GOPATH/bin may have an unpleasant surprise.Neomineomycin
To me I had to re-install any go specific tools or packages after changing the go arch. for eg. I got the discussed error when starting delve, so I reinstalled it as follows. go install github.com/go-delve/delve/cmd/dlv@latestKindred
T
30
  1. Ensure your VSCode uses the arm64 version. (it can use a different go version from the system)

  2. Run Go: install/update tools. It will rebuild all tools with the arm64 go version.

Trifocals answered 27/9, 2021 at 22:37 Comment(3)
could you elaborate on this? "Ensure your VSCode uses the arm64 version" ... how?Villada
@PeterMcIntyre what I did is observe the location of the dlv-dap command vscode was using (Note "Starting: /Users/username/go/bin/dlv-dap ..." in the question), then verified this was the same go I had configured in the PATH/command-line using 'which go' (it can be different, AFAIK vscode bases on the GOPATH go env variable). Running "go version" I saw I was using darwin/amd64, NOT ARM. I downloaded the correct version from go.dev/dl and replaced it (by removing the whole 'go' directory and placing the new one in its place)Colostrum
Thanks! Command-Shift-P > "Go: Install/update tools" fixed it for me! Had installed the amd64 instead of arm64 version before and removing and installing the correct version of go wasn't enough as the tools were still for the intel processor!Resolution
P
9

What worked for me:

  1. Check for "chip" your mac is using, you can check that from "About This Mac" > "Overview" > "Chip"
  2. If Apple chip is used, then download "arm64" type of files, such as "go-darwin-arm64.pkg", "vscode-arm64" etc. You get my point.
  3. If Intel chip is used, then download with "amd" type.
  4. Download and install "DELVE" from https://github.com/go-delve/delve/tree/master/Documentation/installation
  5. Run your debugger.

Let me know, if you want the "launch.json" file config too, to debug.

EDIT 11-04-22

Sharing the launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}/main.go",
            "args": [],
        }
    ]
}
Preparedness answered 9/2, 2022 at 7:47 Comment(2)
Can you post the launch.json please?Recreate
Hi @Ryan, I have shared the launch.json, check for the edit.Preparedness
P
4

This answer worked for me. Installed ARM64 and tried again.

https://github.com/go-delve/delve/issues/2604#issuecomment-1069740132

Percaline answered 27/7, 2022 at 10:24 Comment(2)
This helped me resolve it after so much effort. ThanksAsher
My issue was that I didn't install gdlv, but with your help it worked!Padnag
M
3

✅ SOLUTION ✅

The issue is that you had installed the non-M1 version of GoLang and/or VSCode. There are versions for Intel and Apple chips of both Go and VSCode. You need both to be the arm64 (Apple Silicon) version

If you didn't install both GoLang and VSCode using the arm64 distribution then that is where the problem is.

To fix this issue:

  • Completely remove GoLang and VSCode from your system:
    • Remove GoLang completely:
      • sudo rm -rf /usr/local/go
      • sudo rm /etc/paths.d/go
      • sudo rm -rf ~/donald/go (replace donald with your own account name)
        • (removing this is the 🔑 to fixing your issue)
    • Remove VSCode completely:
      • rm -fr ~/Library/Preferences/com.microsoft.VSCode.helper.plist
      • rm -fr ~/Library/Preferences/com.microsoft.VSCode.plist
      • rm -fr ~/Library/Caches/com.microsoft.VSCode
      • rm -fr ~/Library/Caches/com.microsoft.VSCode.ShipIt/
      • rm -fr ~/Library/Application\ Support/Code/
      • rm -fr ~/Library/Saved\ Application\ State/com.microsoft.VSCode.savedState/
      • rm -fr ~/.vscode/
  • Download the arm64 version of each GoLang and VSCode.
  • Install GoLang
  • Install VSCode
  • Open VSCode.
  • Install the Go extension
  • Open a GoLang project/directory.
  • It will ask you to install the Go tools (like 8 or so tools). Just click "Install All"
    Installing 8 tools at /Users/donald/go/bin in module mode.
    gotests
    gomodifytags
    impl
    goplay
    dlv
    staticcheck
    gopls
    go-outline
    
  • Open a .go file that you want to run.
  • Run it using VS Code.

That's it! You should be good to go now 👍

Mussolini answered 14/3, 2023 at 20:24 Comment(0)
E
1

Download and install DELVE from https://github.com/go-delve/delve/tree/master/Documentation/installation

It worked for me

Epaminondas answered 13/6, 2022 at 7:2 Comment(0)
M
1

Writing this so that anyone facing same problem while migrating to M1 mac can get all the required information at one place.

I faced this issue after migrating data from my intel mac to M1(using Apple Migration Assistant). So basically, the go binaries and vscode for amd64 were copied to M1 mac(arm64)

Hence, i had to uninstall (removed all go related files i.e located at /home/<my_user>/go and go executables located at /usr/local/go) and reinstall go and vscode for arm64.

Post that, i was getting the error could not launch process: EOF while running the debugger in vscode using delve, to solve that i referred to this github thread - https://github.com/go-delve/delve/issues/2794

and performed below steps:

sudo rm -rf /Library/Developer/CommandLineTools

xcode-select --install

After that, i was able to use delve to debug code in vscode

Muriah answered 16/10, 2022 at 6:12 Comment(0)
M
0

The main Go install page (https://go.dev/doc/install) offers you a "download" button which is AMD64. You have to go here: https://go.dev/dl/

and select the correct architecture. Once you've done that you need to uninstall as already mentioned by @prakash-p.

And then you'll also need to reinstall go tools in vs code as mentioned by @iamcmnut

Meteoric answered 10/3, 2023 at 14:5 Comment(0)
K
0

Here is what works for me. After uninstall and install arm64 version of Go and Vscode :

rm  $GOPATH/bin/dlv
rm $GOPATH/bin/gopls
rm $GOPATH/bin/gotests

I restart Vscode and install the missing packages.

Kruller answered 28/6, 2024 at 13:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.