04.09.2022 - Golang/Use Delve on M1 Mac

All posts

Posted On 04.09.2022

Delve is a GDB-alike debugger for Golang, with better support for Go’s data structures and Goroutine.

To install Delve on M1 Mac devices, you first need to install the Go ARM64 version, then install Delve with:

$ go install github.com/go-delve/delve/cmd/dlv@latest

If you use the Go version for Intel chip, your Go programs still compile but Delve won’t work, and you will need to recompile after installing the correct version.

To start debugging a program with Delve, go to your project’s folder and run:

$ dlv debug

From here, you can put a breakpoint at the beginning of the main() function with:

break main.main

The above command means, putting a breakpoint at the beginning of the main function, in the main package. You can also put a breakpoint by line with b <line> command, or a breakpoint at any package’s function with b <package>.<fn>.

Now, you can start the program with the continue (or c) command.

As you step through the code, use the key n to go to the next line, s to step in to a function.

To examine the local variables of scope, use locals command, or print the value of any expression with print <expr> or p <expr> command.