Delve

Installation on Linux

1
$ mkdir -p $GOPATH/src/github.com/myusername/project && cd "$_"
1
$ go get -u github.com/go-delve/delve/cmd/dlv

Usage

1
$ cat $GOPATH/src/github.com/username/proj/main.go
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main
 
import (
    "fmt"
    "log"
    "net/http"
    "os"
)
 
const port  = "8000"

func main() {
    http.HandleFunc("/hi", hi)

    fmt.Println("runing on port: " + port)
    log.Fatal(http.ListenAndServe(":" + port, nil))
}

func hi(w http.ResponseWriter, r *http.Request) {
    hostName, _ := os.Hostname()
    fmt.Fprintf(w, "HostName: %s", hostName)
}

dlv debug

Compile and begin debugging main package in current directory, or the package specified.

1
$ dlv debug ./main.go
1
(dlv) help
1
(dlv) b main.main
1
(dlv) c
1
(dlv) b main.hi
1
2
(dlv) c
running on port: 8000
1
curl localhost:8000/hi

dlv attach

Attach to running process and begin debugging.

1
2
3
$ go build main.go
$ ./main
$ ps aux|grep main
1
dlv attach pid [executable]
1
(dlv) b /home/ye/go/src/github.com/username/proj/main.go:20
1
curl localhost:8000/hi

Command Line Interface

1
break packageName.funcName

help Prints the help message.

list Show source code.

args Print function arguments.

locals Print local variables.

next Step over to next source line.

step Single step through program.

break Sets a breakpoint.

clear Deletes breakpoint.

clearall Deletes multiple breakpoints.

print Evaluate an expression.

continue Run until breakpoint or program termination.

set Changes the value of a variable.

stack Print stack trace.

trace Set tracepoint.

exit Exit the debugger.

Reference