Skip to content

Debug in Go

This document introduces 3 simple methods to debug Go code.

  1. printf, which allows you to format the numbers, variables, and strings;
  2. print, which only prints the string passed as an argument; and
  3. println, which does the same thing as Print, then adds a new line character (\n) at the end of the string passed to it.
  4. log.Print, which prints the string passed as an argument to the standard output stream.

third-party logging frameworks



When you compile and link your Go programs with the gc toolchain on Linux, macOS, FreeBSD or NetBSD, the resulting binaries contain DWARFv4 debugging information that recent versions (≥7.5) of the GDB debugger can use to inspect a live process or a core dump.

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


Delve is a debugger for the Go programming language.

go get -u
dlv debug

  1. License under CC BY-NC 4.0
  2. Copyright issue feedback, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App