Site icon Golang Libraries, Apps, Golang Jobs and Go Tutorials

How to do debugging Golang by using Delve

Golang Debugging

Golang is a compiled programming language designed by Rob Pike, Robert Griesemer, and Ken Thompson at Google.

It is a statically typed language that is syntactically similar to C language but offers additional features like garbage collection, structural typing, memory safety, and CSP-style concurrency.

Getting into the Golang debugger tool: Delve

Using the Delve Debugger, you can view, add and change breakpoints in a Go program, navigate the program either line-wise or through breakpoints, inspect variables, functions, and expression values, and finally analyze all the programs in detail.

Let us first install the Delve debugger tool.

Downloading and installing Golang Delve

Go Delve can be downloaded and installed by using the go get command.

Linux, Windows, OSX

Clone the git repository and build:

$ git clone https://github.com/go-delve/delve$ cd delve$ go install github.com/go-delve/delve/cmd/dlv

Alternatively, on Go version 1.16 or later:

# Install the latest release:$ go install github.com/go-delve/delve/cmd/dlv@latest# Install at tree head:$ go install github.com/go-delve/delve/cmd/dlv@master# Install at a specific version or pseudo-version:$ go install github.com/go-delve/delve/cmd/dlv@v1.7.3$ go install github.com/go-delve/delve/cmd/dlv@v1.7.4–0.20211208103735–2f13672765fe

The following elements should already be set up if you have a working Golang installation:

-> go env GOBIN

You can view your Golang environment’s environment variables using the “go env” command. You can run the go env command on the command prompt, the following will the output.

$ go env -w GOBIN=$GOPATH/src/github.com/go-delve/delve/delve/cmd/dlv
Exit mobile version