dlv
Debug Go programs
TLDR
Compile and begin debugging the main package in the current directory (by default, with no arguments)
Compile and begin debugging a specific package
Compile a test binary and begin debugging the compiled program
Connect to a headless debug server
Attach to a running process and begin debugging
Compile and begin tracing a program
SYNOPSIS
dlv [global flags] <command> [<args>]
PARAMETERS
--accept-multiclient
Allow multiple clients to connect.
--api-version=2
Use API version 2 (default: 1).
--build-flags="-gcflags ..."
Build flags for debug/test commands.
--check-go-version=false
Skip Go version compatibility check.
--headless
Run without terminal I/O; use --listen.
--listen=:2345
Listen on address for remote connections.
--log
Enable debug logging.
--log-output=stderr
Log output destination.
--continue
Continue after fatal error for exec.
debug
Compile and debug package (e.g., dlv debug main.go).
exec <binary>
Debug existing binary.
attach <pid>
Attach to running process.
connect <addr>
Connect to headless instance.
version
Print version info.
DESCRIPTION
Delve (dlv) is a powerful, extensible debugger for the Go programming language, designed to overcome limitations of using GDB with Go binaries. It provides a rich command-line interface for debugging Go applications on Linux, supporting features like breakpoints on functions/types/variables, variable inspection with pointer dereferencing, goroutine management, expression evaluation, and integration with Go's race detector.
Key workflows include launching programs with dlv debug, attaching to PIDs via dlv attach, executing binaries with dlv exec, remote debugging, and tracing. It handles Go's runtime intricacies, such as stack traces across goroutines and build modes. Delve supports headless mode for IDE integration (e.g., VS Code, GoLand) and API versions for extensibility.
Built in Go, it's portable across platforms, requiring minimal setup via go install. Ideal for complex concurrent Go apps, it offers commands like next, step, print, goroutines, and config for customization.
CAVEATS
Requires Go binaries with debug info (build with -gcflags=all=-N -l for full features); limited support for optimized code or CGO; not suitable for kernel debugging.
INSTALLATION
go install github.com/go-delve/delve/cmd/dlv@latest
Add $GOPATH/bin or $GOROOT/bin to PATH.
EXAMPLE
dlv debug github.com/user/repo -- --arg1
Then in debugger: break main.main, continue, print x.
IDE INTEGRATION
Supports VS Code (delve extension), GoLand via --listen and --headless.
HISTORY
Delve originated in 2014-2015 from Go team efforts (Alek Si, Dominic Stefan Chinnoty, et al.) to replace GDB's poor Go support. First stable release ~2015; now actively maintained at github.com/go-delve/delve with API v2 in 2019 enhancing headless/IDE use. Widely adopted in Go ecosystem.


