How I can install GDB in NetBeans in Mavericks for debugging?

I have an error when I debug a C program in NetBeans.

GDB has unexpectedly stopped with return 127

Here is a screenshot of the build tools:

Build Tools


Solution 1:

That's what I did to install GDB (under Yosemite):

  1. Install brew: http://brew.sh

  2. Update brew. If you already have installed brew, check for updates. In the terminal:

$ brew update

This step turned out to be decisive for me as, before updating, brew did not find any gdb package:

$ brew install gdb # Error: No available formula for gdb

And after that:

$ brew update
$ brew search | grep gdb # cgdb gdb gdbm pgdbf
  1. Install gdb:

$ brew install gdb
  1. Codesign the binary following these instructions: http://sourceware.org/gdb/wiki/BuildingOnDarwin I copy them here for the sake of completeness and to add some comments:

Creating a certificate

  • 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.

  • If you can't store the certificate in the System keychain, create it in the login keychain, then exported it. You can then imported it into the System keychain.

  • Finally, using the contextual menu for the certificate, select Get Info, open the Trust item, and set Code Signing to Always Trust.

  • You must quit Keychain Access application in order to use the certificate and restart taskgated service by killing the current running taskgated process (comment: for example with sudo pkill taskgated or restarting).

And then

Giving gdb permission to control other processes

If the certificate is known as gdb-cert, just use:

$ codesign -s gdb-cert gdb

Comment: if gdb is not found, then add the path where it was installed. In my case:

$ codesign -s gdb-cert /usr/local/Cellar/gdb/7.10/bin/gdb
  1. Use either gdb or the path where gdb was installed (for example, /usr/local/Cellar/gdb/7.10/bin/gdb) in the menu /Netbeans/Preferences/C/C++/Build Tools field Debugger Command field.