The Go Blog

Debugging Go on OS X

10 May 2015

Step 1: Get GDB.

Some of the fancy features Go adds to GDB require GDB >= 7.1. You can check which version you have with `gdb -v`. If it's high enough, skip to the next section. If not, do the following:

1) Follow these instructions: The name doesn't matter really, but gdb_codesign is as good a choice as any.

2) `brew install`.

3) `codesign -s gdb_codesign $(which gdb)`

Step 2: Compile your Go program

You don't really have to do anything special, but if you compile with `-gcflags "-N -l"`, the compiler will omit some optimizations that can make debugging more difficult. Eg:

` $ go build -gcflags "-N -l" main.go `

Step 3: Get the Go source:

There's a bug on OS X that prevents the custom gdb extensions from loading automatically, so you have to source them manually when you start up the debugger. You can put the source wherever you want, but I'll assume you're putting it at ~/src/go:

` mkdir ~/src ; cd ~/src ; hg clone -u tip `

Step 4: Debug!

1) Start the debugger. `gdb ./my_app`

2) Load the extra runtime support: `source ~/src/go/src/pkg/runtime/`

3) Debug. See

Related articles