*** Please take a look at this post for safer method ***
I have a macbook air (MBA) which I carry around to use at various locations other than my desk at home. Of course I could install Ubuntu on my MBA, but I really like how easy it is to do anything on OS X, so I am keeping it. I also do a lot of software development on my MBA. That being said, it bothers me that by default I cannot run gdb on OS X El Capitan. In this post, I will show how to enable gdb on OS X El Capitan. The credit goes to here.
First, you will need to install gdb. I would use brew. In case you don't have brew installed on the system, follow the instructions here.
$ brew install gdb
When you try to run a program on gdb, you will encounter error similar to below:
Starting program: a.out
Unable to find Mach task port for process-id 627: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
The solution is as follows:
1. Restart OS X. Enter recovery mode by pressing and holding [command + R] until you see Apple logo. See here for more detail.
2. In the recovery mode, choose utilities menu and open up terminal
3. In the terminal, disable system integrity protection (SIP)
$ csrutil disable && reboot
4. Add -p option to /System/Library/LaunchDaemons/com.apple.taskgated.plist file. After your edit, it should read something like (line 22)
5. (Optional) Re-enable SIP by repeating steps 1~3 with the command and reboot.
$ csrutil enable && reboot
6. Add your username to procmod group
$ sudo dseditgroup -o edit -a $USER -t user procmod
7. Locate gdb executable file and run
$ sudo chgrp procmod $(which gdb)
$ sudo chmod g+s $(which gdb)
Please be advised that you will need to reboot your system for the change to take effect.
Now, you should be able to use gdb on Mac OS X!