Sunday, April 24, 2016

How to Enable GDB on Mac OS X El Capitan (NOT RECOMMENDED)

*** I do not recommend the instructions below ***
*** 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:
(gdb) run 
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/ 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!


  1. Great! I was missing the steps #6 and #7 and now it works great.

  2. at step 4 Im getting an error "The authenticated save for this file failed (application code: 20004)". any way around this?

  3. It works! Appreciate your tutorial!

  4. Hi! I'm trying this out on Sierra. Till step 6 I followed you fine, but I don't know what you mean by "locate gdb executable" in step 7. I'm sort of a newb at this. Can you elaborate on what exactly I have to enter in place of (which gdb)? TIA

    1. Type exactly as written, except the first dollar sign. $(whic gdb) is a part of the command to type in

  5. There is a reason why I bought a Mac, it was not to be one of the cool kids that wanted the best of the best. No it was because of the music production I do on it. Hours and hours sitting in front of my Mac copying, pasting, moving, deleting, hour after hour just beating on my Mac in a endless assault to get my work done. That is the key part, my work. I work from home, it is great, but even if it is from home it is still work and it still needs to get done. So my Mac, I have it because it is fast, gets the job done and comes back for more.

    But what happens when it doesn't want to do those things anymore?

    I move around massive amounts of information and yes even on the almighty Mac this can cause a problem after a while. Things fragment, programs get corrupted issues come up. My light speed Mac slows down to a crawl and all of the sudden I simply can not get any work done. Because I work from home there is no IT guy to call and ask to come fix it. No instead I have to figure out what is wrong. I am lucky, I did, but not after trying everything under the sun first and wasting countless hours looking for one program that can do what I needed instead of ten programs. One program to lead them all….okay that was a lame Lord of the rings reference, but that program was/is Detox My Mac. A simple to use program that did not just fix my issues, it put my Mac on overdrive again. A few clicks and my Mac was clean and ready to rock and roll again.

    Read more here:-