Skip to content

Instantly share code, notes, and snippets.

@Pallinder
Created September 3, 2013 17:29
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save Pallinder/6426936 to your computer and use it in GitHub Desktop.
Save Pallinder/6426936 to your computer and use it in GitHub Desktop.
Getting golang + mac os x + gdb to play nicely
alias gdbnew='/usr/local/Cellar/gdb/7.6/bin/gdb'
define g
python
import subprocess as p
cmd = ["go", "env", "GOROOT"]
gdb_cmd = "source %s/src/pkg/runtime/runtime-gdb.py" % p.check_output(cmd)[:-1]
gdb.execute(gdb_cmd)
#### Install a new version of gdb (the one that comes with mac os x is too old)
1. Install and get brew
2. brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb
3. Add an alias so it's easier to run, I named it gdbnew (check the .bash_profile file attached for an example)
#### Deal with signing gdb (you can skip this if you feel like running the debug process like root)
1. Start keychain access
2. Keychain access -> Certificate assistance -> Create a certificate
3. Name it whatever you like (I choose gdb)
4. Certificate type should be code signing
5. Check "let me override defaults"
6. Just click continue until you reach the point to select Keychain, select the System keychain
7. type `codesign -s name-of-certificate /path/to/new/gdb` in your console
8. type `sudo chgrp procmod /path/to/new/gbb` in your console
9. type `sudo chmod g+s /usr/local/bin/gdb` in your console
10. Pray to whatever god(s) you may or may not have.
11. Confirm that it works by trying to run the new gdb with a compiled golang binary. (newgdb path-to-binary) if an error similar to `codesign -s gdb-cert /usr/local/bin/gdb /usr/local/bin/gdb: is already signed but it still gives me the error message Unable to find Mach task port for process-id 838: (os/kern) failure (0x5)` pops up, it didnt work. Some people say a restart of the computer might help.
#### Make sure gdb loads the golang scripts
1. Put the the attacked .gdbinit in your homedirectory
2. Launch the new gdb you can now enable the golang specific commands by typing "g" (without the quotes) in gdb
@jppoveda
Copy link

jppoveda commented Nov 2, 2013

Thanks! This was helpful.

@subh007
Copy link

subh007 commented Dec 23, 2014

Thanks for the gist. For the step 11, I faced difficulty because we have to close the keychain and restart the taskgated process. I have updated in the fork, please update that line. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment