Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run debug Go using VSCode on Mac M1

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.

like image 590
cross_knight Avatar asked Sep 27 '21 08:09

cross_knight


People also ask

Is VS Code compatible with M1 Mac?

Users on Macs with M1 chips can now use VS Code without emulation with Rosetta, and will notice better performance and longer battery life when running VS Code.

How do I run a debugger code in Visual Studio for Mac?

While selecting the . vscode on the left-navigation pane of the Explorer (Command+shift+e), enter Command+shift+d to enter into the “run and debug” set-up. Click on “create a launch.

How do I enable debug mode in VS Code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


Video Answer


1 Answers

  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.

like image 58
Painhardcore Avatar answered Sep 23 '22 00:09

Painhardcore