Start a session
dlv debug [<pkg>]
Build and debug a main package
Without a package it builds the one in the current directory.
dlv debug -- <args>
Debug with program arguments
dlv test [<pkg>]
Build and debug a test binary
dlv test -- -test.run <TestName>
Debug a single test
Test flags need the -test. prefix after --.
dlv exec <binary> -- <args>
Debug a prebuilt binary
go build -gcflags="all=-N -l" -o <bin>
Build a debug-friendly binary
dlv attach <pid>
Attach to a running process
Needs ptrace permission (root or kernel.yama.ptrace_scope).
dlv core <binary> <core>
Examine a core dump
dlv debug --build-flags="-tags=<tag>"
Pass flags to go build
dlv debug --wd <dir>
Set the program's working dir
dlv exec <bin> -r stdin:<file>
Redirect a standard stream
dlv attach --waitfor <name>
Attach once a process starts
dlv trace <regex>
Log calls of matching functions
Trace output goes to stderr.
dlv trace --stack <n> <regex>
Log with a stack trace
dlv trace -t <regex>
Trace in a test binary
dlv version
Show Delve version
Breakpoints
break <func>
Break at a function (b)
pkg.(*Type).Method; any unambiguous suffix works.
break <file>:<line>
Break at a line
break <loc> if <cond>
Break when a condition holds
break <name> <loc>
Create a named breakpoint
break /<regex>/
Break on all matching functions
Also matches runtime and stdlib functions.
breakpoints
List breakpoints (bp)
clear <id>
Delete one breakpoint
clearall [<loc>]
Delete all (or matching) breakpoints
toggle <id>
Disable or enable a breakpoint
condition <id> <expr>
Add a condition later (cond)
cond -hitcount <id> > <n>
Stop only after n hits
cond -clear <id>
Remove a condition
on <id> print <expr>
Print a value on each hit
watch -w <expr>
Stop when memory is written
-r for reads, -rw for both.
trace <loc>
Tracepoint: log a hit, keep running
Run control
continue
Run to the next breakpoint (c)
next
Step over the next line (n)
stepout
Run until the function returns (so)
continue <loc>
Run to a location
next <count>
Step over several lines
restart
Restart with the same arguments (r)
rebuild
Rebuild the binary and restart
Only for binaries Delve built itself.
step-instruction
Step one CPU instruction (si)
call <func>(<args>)
Call a function (experimental)
exit
Quit the debugger (q)
exit -d
Detach and leave the process running