One minute
Delve - Go Debugger
Introduction
Delve is a powerful debugger for Go(Golang).
Installation
To install latest version of Delve, use the below command
go install github.com/go-delve/delve/cmd/dlv@latest
Make sure that $GOPATH/bin or your Go binary path is in your PATH environment variable.
Quick Usage
You can use delve in many ways, the one I prefer is as below
Start a Program with Delve
You can start a Go program under Delve by running:
dlv debug <program.go>This will compile and run the program in debug mode, allowing you to set breakpoints and interact with it.
Attach to a Running Process
If your Go program is already running, you can attach Delve to it by using the process ID (PID):
dlv attach <pid>
Basic Commands
Once delve is running, you can use the below commands to move around
Set breakpoints
break <function_name>Or for specific lines
break <filename>:<line_number>Run program
continueStep through the code
- Step into function:
step - Step over function:
next - Step out of current function:
stepout
- Step into function:
Inspect variables
- Print variable:
print <variable_name> - Display the value of a variable at a breakpoint.
- Print variable:
List breakpoints
breakpointsExit the debug mode
quit