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 [command] [arguments...]
The dlv command operates primarily through subcommands, each performing a distinct debugging action or mode.
PARAMETERS
debug [package]
Compiles the specified Go package (or current directory if none) and initiates a new debugging session on the resulting executable.
test [package]
Compiles and runs the tests for the specified Go package under the debugger, allowing for test-driven debugging.
exec [path_to_binary]
Debugs a pre-compiled Go binary located at the specified path. This command does not recompile the source.
attach [pid]
Attaches the debugger to an already running Go process identified by its Process ID (PID), enabling live debugging.
core [path_to_core_dump] [path_to_binary]
Opens and analyzes a core dump file generated from a crashed Go program, requiring the corresponding executable for symbol resolution.
connect [address]
Connects to a dlv server instance running on a specified network address, facilitating remote debugging.
trace [package]
Traces the execution of a Go program, logging function calls and their arguments without stopping execution by default.
replay [path_to_rr_trace]
Replays an rr (record and replay) trace of a Go program's execution, enabling deterministic debugging of past runs.
run
A convenient shorthand for dlv debug ., compiling and debugging the program in the current directory.
help [command]
Displays help information for a specific dlv subcommand or general usage if no command is specified.
DESCRIPTION
dlv, short for Delve, is a modern, full-featured source-level debugger specifically designed for the Go programming language. Unlike general-purpose debuggers like GDB, Delve is built to understand and interact with Go's unique runtime characteristics, including goroutines, channels, and Go-specific stack traces. It provides essential debugging capabilities such as setting breakpoints, stepping through code, inspecting variables, evaluating expressions, and analyzing the runtime state of Go applications. Delve is an indispensable tool for Go developers to diagnose and resolve issues, whether debugging a crashed process, analyzing a core dump, or interacting with a live running program. It aims to provide a robust and intuitive debugging experience that integrates seamlessly with the Go ecosystem and developer workflows.
CAVEATS
Delve is exclusively designed for debugging Go programs; it is not compatible with applications written in other programming languages. Attaching to a running process (dlv attach) may require elevated privileges, such as root access or the CAP_SYS_PTRACE capability, depending on the system's security configuration. Debugging can introduce some performance overhead, particularly with extensive tracing or a large number of active breakpoints. It also mandates that the Go toolchain be properly installed and configured on the system.
<B>IDE INTEGRATION</B>
Delve is widely adopted and serves as the backend for debugging capabilities in various Go-specific Integrated Development Environments (IDEs) and text editors, including Visual Studio Code (via the official Go extension) and GoLand, providing a seamless graphical debugging experience for developers.
<B>REMOTE DEBUGGING</B>
Delve robustly supports remote debugging scenarios. It can operate in a client-server mode, where a dlv server instance runs on a remote machine hosting the Go application, allowing a local dlv connect client or an IDE to establish a connection and debug the remote process over a network.
HISTORY
Development of Delve commenced around 2015, primarily initiated by Louis Gerbarg and a growing community of contributors. The project arose from the inherent limitations of using general-purpose debuggers like GDB for Go programs, which lacked a deep understanding of Go's unique runtime concepts, such as goroutines, precise stack layouts, and interfaces. Delve was engineered from the ground up to provide a native, efficient, and Go-idiomatic debugging experience. It rapidly gained prominence within the Go community and has since become the de-facto standard debugger, continually evolving to support new Go language features and integrate with modern development workflows.