Monday, January 27, 2014

Netbeans C++ and GDB on Mac OS X Mavericks

I'm starting to use an IDE for the first time since basically high school (I used Visual Studio for a school project briefly but reverted to just using a make file because my Mac is more powerful and new than my PC after only 2 class projects), and I decided to use Netbeans (after some search this seemed to be more appropriate for my small project needs than Xcode).

But lo and behold, Macs/Xcode/Command Line Tools no longer support GDB, and GDB is the "supported" debugger in Netbeans (they have an option for Clang, but I found that out later). So, if you have Mavericks and want to use GDB to debug your C/C++ projects in Netbeans, this is what worked for me!

Install homebrew. You can do this with MacPorts or by just downloading GDB and building it, but I used homebrew cause that's what I had installed.

Download GDB using homebrew. Now, this is the command that you should use (there are many bad links out there): 
>> brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb

Now, basically follow what this link says. I'll write exactly what I did below in any case.

Start Keychain Access application (/Applications/Utilities/Keychain Access.app)

Open menu /Keychain Access/Certificate Assistant/Create a Certificate...

Choose a name (gdb-cert in the example), set Identity Type to Self Signed Root, set Certificate Type to Code Signing and select the Let me override defaults

Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.

In Keychains -> System in the main window, right click on your certificate and select Get Info.

Open the Trust item (down the page), and set Code Signing to Always Trust.

Quit Keychain Access.

Kill all taskgated processes. Note that these need sudo:
>> sudo killall taskgated

Now, find your copy of gdb, if you used homebrew to install version 7.6.2 do this:
>> cd /usr/local/Cellar/gdb/7.6.2/bin

And codesign it:
>> codesign -s gdb-cert gdb

One last step, if you want to actually be able to use gdb in Netbeans and get a debugger is missing or invalid error, go to NetBeans->Preferences->C/C++->Build Tools and set Debugger Command to /usr/local/bin/gdb.