If you work on a Mac OS X 10.9 Mavericks or later, you will run into
the problem of Eclipse refusing to interactively debug problems that
otherwise build and run fine:
An attempt to start a debugging session by selecting
Error with command: gdb --version
has occurred.
The problem is caused by Apple switching away from GDB, the GNU debugger, to LLDB, the LLVM debugger, in their Xcode toolchain (along with the transition from GCC to Clang). Unfortunately, Eclipse is not capable of communicating with any debugger other than GDB (yet). Here is a step-by-step guide for installing and configuring GDB.
As with GCC, the easiest way to install GDB is through Homebrew.
In a Terminal window, run the command
brew install gdb
,
and wait for it to complete.
(As usual, it may ask for your password.)
Now, we need to code-sign the GDB executable, so it will be allowed to control other processes, as necessary for a debugger. For that, we will first create a new certificate in Keychain.
Open the Keychain Access application (can be found in Applications/Utilities directory or through Spotlight). Select
in the application menu ( ). An assistant window will appear for guiding you through the process.gdbcert
.
Our new certificate is now ready to be used.
In order to make it immediately available for signing, we need to
restart the Taskgate access-control service.
You can use Activity Monitor to do this (also found in
Applications/Utilities).
Open it and filter the list of processes by typing
taskgated
in the search field in the toolbar.
(If you cannot find it, make sure the menu item is checked.)
There should be exactly one process left in the list. Highlight it, then select
from the menu, and click in the popup prompt. The Taskgate process will be terminated and, consequently, should disappear from the list. In a few seconds, it will be restarted by the system and should reappear in the list. Please wait for this to happen (it may take up to a minute or two, at worst).
Finally, in a Terminal window, run
codesign -s gdbcert /usr/local/bin/gdb
(if you named your certificate differently, replace
gdbcert
with its name here).
Once again, you will be prompted for you username and password.
If the command does not produce any output, then GDB is
successfully signed.
The only thing left to do is to point Eclipse to the GDB executable.
Open /usr/local/bin/gdb
.
If there is no gdb
command, but it will force
the said
settings to appear in the preferences.
This will change the GDB executable for new projects; for all existing
ones (that you are going to use debugging for), you will need to
manually update their debug configurations.
To do that, select
/usr/local/bin/gdb
, and click the
button.
After repeating this change for all listed projects, click .
If the above steps do not solve the issue on your machine, or you encounter a problem while following them, please do not hesitate to come to one of the upcoming common labs for help.