Eclipse debugging with GdB on Mac
With its new OS release, Apple have discontinued the use of GDB in OS x. Since 2005 Apple have steadily been moving away from the GNU toolchain in favor of LLVM. This means is Xcode now uses LLDB instead.
Lldb looks to being a very nice replacement for GDB, and I hope to use it in the future, but currently Xcode are the only Grap Hical front-end that supports it use; Pretty much every other debugging GUI uses GDB under the hood, including Eclipse. So, if you want to debug C + + code in Eclipse CDT on the MAC, you must install Gdb.1
Here are the procedure that worked for ME.2 Others has reported issues with this, so please do let me know in the comments If it doesn ' t work for you.
Known Issues
GDB is not being able to breakpoint inside any template function, though it should is able to step into it. This problem is resolved if you use the MacPorts installation procedure (below) if it is only C2>also compile with Apple ' s GCC.
It is also reported in the comments that it cannot breakpoint into a shared library function. I has not confirmed this issue myself.
Installing GDB
You can install via MacPorts or Homebrew. MacPorts has Apple's official GDB distribution, which is modified for OS x. This was probably the best option (thanks to CC's comment for this tip). However, on my machine The If the program is compiled using Apple's GCC, which is no longer supported by Apple. All things being equal, I vastly prefer to avoid macports altogether. So I installed with Homebrew, despite recommending MacPorts. If you have no preference either to go with MacPorts.
Install with MacPorts
- Install Xcode and MacPorts, if not already installed.
- Now install the Apple GCC and GDB from macports:$ sudo port install Gdb-apple
$ sudo port install apple-gcc42
- For the remainder of the tutorial, use /opt/local/bin/gdb-apple as the GDB executable
- Remember If you want breakpoints in the template functions to work, you'll need to the change your compiler to G++-ap ple-4.2 instead of g++! This can is done with your makefiles or in your IDE settings.
Install with Homebrew
- Install Xcode and Homebrew, if not already installed.
- Now install GDB from homebrew:$ Brew tap Homebrew/dupes
$ brew Install gdb
- For the remainder of the tutorial, use /usr/local/bin/gdb as the GDB executable
If that worked and then lucky you! Getting It compiled is where many people seem to has trouble. Now you just need-to-sign it-give it permission to control OS X processes.
Certifying GDB
Open up the Keychain Access application (/applications/utilities/keychain access.app). Navigate via the menu to Keychain Access > Certificate Assistant > Create Certificate ...
Enter a name for the certificate. For this how-to, I'll call it "Gdb-cert". Set The fields exactly as shown below.
The maximum validity period is a 999 days. I don ' t really want to deal with this again, so I ' m going to max it out.
Keep clicking the "Continue" button until you is asked for a location. Set it to "System". 3
success!
Now make sure the cert are always trusted. Right-click the new certificate and select Get Info. Under the Trust section, set Code Signing to always Trust.
Now the We have a certificate and we need to use it to sign GDB. First, we ' ll restart the taskgatedprocess to make sure it picks up the new certificate. Quit Keychain Access (you must quit Keychain access!) and return to the Terminal for these final commands.
Find the taskgated process.
$PS- e | grep taskgated
56822?? 0:03.11/ usr/libexec/taskgated- s
60944 ttys002 0:00.00 grep --color=auto taskgated
The first number in the above output is the PID. Use this to kill the process (it'll immediately restart itself).
$ sudo kill -9 56822
Now the can finally code sign GDB.
# MacPorts version
$ codesign -S Gdb-cert $(which gdb-apple)
# Homebrew Version
$ codesign -S Gdb-cert $(which gdb)
Now you should is all set! The OS X Keychain may ask for your password the first time you attempt to debug a program, but it should work!
Getting it to work with Eclipse
There ' s one more step for Eclipse users. You need to specify where Eclipse can find the new GDB. Specify the path to GDB in Preferences > C + + > Debug > GDB:
If you already has some debug configurations, you could need to edit them individually to point to the correct place (under Run > Debug configurations ...):
- The CDT developers is planning to support LLDB, but they'll has to write a whole new interface, and I think most of th EM only work on Eclipse in their spare time, so it'll likely be at least some months before lldb support is there.
- The procedure is derived from this StackOverflow post and this GDB Wiki page.
- If you were unable to save it to the System Keychain and then save it to the login keychain. You can later export the cert, and then import it into the System Keychain. I didn ' t has to does this, so comment if you had any problem.
Eclipse debugging with GdB on Mac (GO)