Backend Development 28 min read

Delve Debugger for Go: Installation, Configuration, and Command Guide

Delve, the primary Go debugger, is installed via its official guide, requires disabling inlining with appropriate gcflags, supports flexible location specifications and rich expressions, offers multiple debugging modes (debug, exec, attach, core), configurable settings, runtime commands, breakpoint types, variable and stack inspection, and integrates seamlessly with Goland.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
Delve Debugger for Go: Installation, Configuration, and Command Guide

Delve is the most widely used debugger for Go. This guide introduces how to install Delve, configure it, and use its various commands for debugging Go programs.

1. Installation

Refer to the official installation documentation:

https://github.com/go-delve/delve/tree/master/Documentation/installation

2. Disable Inlining and Optimizations

When debugging with dlv , you must disable compiler inlining and optimizations:

Go 1.10 and later: -gcflags="all=-N -l"

Go before 1.10: -gcflags="-N -l"

3. Location Specification (locspec)

Delve supports several ways to specify a location:

File and line number: list aa/aa.go:15

Package and function: trace content-service/iteminfo.GetItemV2

Absolute/relative line or offset: ./iteminfo/itemv2.go:52

4. Supported Expressions

Delve can evaluate a wide range of expressions, including arithmetic, type conversion, struct/map/array member access, pointer dereference, built‑in functions (e.g., len ), and interface assertions. Example:

p len("abc")

5. Debugging Modes

Delve provides several ways to start a debugging session:

dlv debug : builds and runs the current package. Syntax: dlv debug [package] [flags]

dlv exec : runs an existing binary. Syntax: dlv exec <path/to/binary> [flags]

dlv attach : attaches to a running process. Syntax: dlv attach <pid> [flags]

dlv core : analyzes a core dump. Syntax: dlv core <executable> <core> [flags]

6. Configuration

Delve reads configuration from $HOME/.config/dlv/config.yml . Common options include:

substitute-path:
  - {from: $HOME/go/src/content-service, to: /mnt/code/content_service}
max-string-len: 99999
max-array-values: 99999
aliases:
  command: ["alias"]

Commands to modify configuration at runtime:

config -list
config -save
config max-string-len 9999
config substitute-path <from> <to>

7. Runtime Commands

Key commands for controlling execution:

restart (alias r ): restart the program.

continue (alias c ): run until a breakpoint or program end. Example: (dlv) c main.go:48

next ( n ), step ( s ), step out ( so ): step execution.

8. Breakpoint Management

Delve supports several breakpoint types:

trace : prints a message when hit without stopping execution. Example: trace test api/service/iteminfo.(*ItemInfoServiceImpl).GetItemV2

break (alias b ): stops execution. Example: b test api/service/iteminfo/itemv2.go:51

watch : stops on read/write of a memory location. Example: watch -rw *(*uint8)(0x59d241)

Additional breakpoint commands include condition ( cond ) to add a conditional pause, on to execute actions when a breakpoint hits, clear , toggle , and breakpoints ( bp ) to list them.

9. Variable and Memory Inspection

Useful commands:

print ( p ) – evaluate and print an expression.

args – show function arguments (use -v for verbose).

locals – show local variables (use -v for verbose).

vars – show package‑level variables.

display – automatically print an expression after each stop.

set – modify a variable’s value during debugging.

whatis – show the type of an expression.

examinemem ( x ) – dump memory at a given address.

10. Stack Navigation

Commands for stack inspection:

stack ( bt ) – print call stack, optionally with -full for locals and args.

frame , up , down – move between stack frames.

11. Query Commands

List functions, goroutines, threads, sources, and types:

funcs
goroutines (grs)
threads
sources
types

12. Goland Integration

Goland IDE provides built‑in support for Delve. Debug panels show goroutine and stack information, and you can add evaluate‑and‑log, condition, and watch actions directly from the UI.

13. Summary

This document provides a comprehensive reference for using Delve to debug Go applications, covering installation, compiler flags, location syntax, supported expressions, various debugging modes, configuration, runtime commands, breakpoint types, variable inspection, stack navigation, and IDE integration.

debugginggolangIDE IntegrationGoDebuggerdelvedlv
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.