Skip to main content

Using Delve Debugger

Sources:

Building and Running

After making code changes in /path/to/server, build the binary:

go build -gcflags="all=-N -l" -v

The flags all

Then run server:

./server -stdout -loglevel debug

Attach to Process

On another session, attach debugger:

$GOPATH/bin/dlv attach $(pidof server)

Debugging Code

Breakpoints

Set Breakpoint

break /path/to/module.go:120

List/Clear Breakpoints

breakpoints
clear 1

Control Flow

See what code line we're in

(dlv) l

Continue until breakpoint/exit

(dlv) c

Go To Next Line

(dlv) n

Step Into Function

step

Examine Variables

List local variables

locals
print x