Installing GDB on OS X Mavericks

If you prefer watching videos to reading articles, Cody Henrichsen has created a video walkthrough of this procedure.

With its new OS release, Apple has discontinued the use of GDB in OS X. Since 2005 Apple has steadily been moving away from the GNU toolchain in favor of LLVM. This means that Xcode now uses LLDB instead.

LLDB looks to be a very nice replacement for GDB, and I hope to use it in the future, but currently Xcode is the only graphical front-end that supports its use; pretty much every other debugging GUI uses GDB under the hood, including Eclipse. So, if you want to debug C/C++ code in Eclipse CDT on the Mac, you must install GDB.1

Here is the procedure that worked for me.2 Others have reported issues with this, so please do let me know in the comments if it doesn't work for you.

Known Issues

GDB will not be able to breakpoint inside any template function, though it should be able to step into it. This problem may be resolved if you use the MacPorts installation procedure (below) but it may only work if you also compile with Apple's GCC.

It was also reported in the comments that it cannot breakpoint into a shared library function. I have not confirmed this issue myself.

On OS X Yosemite, the MacPorts version will require some extra hoops to jump through. See below.

Installing GDB

You can install via MacPorts or Homebrew. MacPorts has Apple's official GDB distribution, which is modified for OS X. This is probably the best option (thanks to CC's comment for this tip). However, on my machine this only seems to work 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 way, go with MacPorts.

Update for Yosemite users: I haven't upgraded to Yosemite yet, but some folks have reported problems in the comments below (and for some, it worked fine). It seems that Apple's GDB (the MacPorts install) is currently broken on Yosemite. If you know what you're doing, you can apply the Portfile patch from this ticket. It seems like a bit of a pain, though, so you might switch to plain vanilla GDB, which can be installed with either MacPorts or Homebrew.

Install with MacPorts

  1. Install Xcode and MacPorts, if not already installed.
  2. Now install the Apple GCC and GDB from MacPorts:
    $ sudo port install gdb-apple
    $ sudo port install apple-gcc42
  3. For the remainder of the tutorial, use /opt/local/bin/gdb-apple as the GDB executable
  4. Remember if you want breakpoints in template functions to work, you'll need to change your compiler to g++-apple-4.2 instead of g++! This can be done in your Makefiles or in your IDE settings.

Install with Homebrew

  1. Install Xcode and Homebrew, if not already installed.
  2. Now install GDB from Homebrew:
    $ brew tap homebrew/dupes
    $ brew install gdb
  3. For the remainder of the tutorial, use /usr/local/bin/gdb as the GDB executable

If that worked, then lucky you! Getting it compiled is where many people seem to have trouble. Now you just need to sign it to give it permission to control OS X processes.

Certifying GDB

Open up the Keychain Access application (/Applications/Utilities/Keychain 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 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 are asked for a location. Set it to "System".3




Now make sure the cert is always trusted. Right-click the new certificate and select Get Info. Under the Trust section, set Code Signing to Always Trust.



Now that we have a certificate, we need to use it to sign GDB. First, we'll restart the taskgated process 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 will immediately restart itself).

$ sudo kill -9 56822

Now you 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 be 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/C++ > Debug > GDB:


If you already have some debug configurations, you may need to edit them individually to point to the correct place (under Run > Debug Configurations...):


  1. The CDT developers are planning to support LLDB, but they will have to write a whole new interface, and I think most of them only work on Eclipse in their spare time, so it will likely be at least some months before LLDB support is there.
  2. The procedure is derived from this StackOverflow post and this GDB Wiki page.
  3. If you are unable to save it to the System keychain, then save it to the login keychain. You can later export the cert, and then import it into the System keychain. I didn't have to do this, so comment if you have any problem.
Tagged , , , , , , . Bookmark the permalink.

154 Responses to Installing GDB on OS X Mavericks

  1. Kevin says:

    This was a huge help! Thanks for the detailed procedure.


  2. digitaurus says:

    Thanks for the article. I can't get breaks set for a shared library function to work. Have you encountered this problem ?

  3. ntraft says:

    Sorry, I haven't ever tried that, and am not in a position to at the moment. No one has mentioned that in the StackOverflow post either.

  4. Chul says:

    Thanks. This works perfectly for my Mavericks.

  5. fab says:

    Thanks. I have GDB working now. However, Eclipse allows me to debug but it doesn't allow me to set breakpoints anywhere inside templates functions. Have you guys experienced this before?

  6. ntraft says:

    Uh-oh. Yeah, I just checked, and it's happening to me too. That's a much more serious problem.

    It happens in raw gdb, not just Eclipse, so it's an issue with gdb somehow. It can step into template functions just fine, but not set breakpoints.

    I don't have a solution for this right now.

  7. luxward says:

    Help!!I just followed the step you listed.But I just got the this.
    ps -e | grep taskgated
    1282 ?? 0:00.03 /usr/libexec/taskgated -sp
    sudo kill -9 1282
    codesign -s gdb-cert /usr/local/bin/gdb
    gdb-cert: no identity found
    That is why?

  8. ntraft says:

    In the step where you created your certificate, what name did you give it? I named mine "gdb-cert", but you need to replace that with whatever name you chose.

  9. jl says:

    Hi, I have follow the steps, but when I try to debug some project, eclipse says: "'Launching 'project' has encountered a problem. Error with command: /usr/local/bin/gdb -- version"
    Do you have any idea why is this happening?
    Thank you

  10. ntraft says:

    It means it can't find your gdb. If you go to the terminal and run "/usr/local/bin/gdb --version" do you get some output? What is the result of running "which gdb"?

  11. Nidhi says:

    I followed your instructions to the letter but there were two problems:
    1) Under Preferences > C/C++ > Debug > there is no GDB option. Instead there is a GDB MI option, so I cant set the path there.
    2) I set the path to the debugger under Debug Configurations, but now when I run it on the Device I get the error :
    GdbServerReceiver: run-as: Package xxx is unknown
    NDK: Gdbserver not started properly
    NDK: Launch error: Failed to connect to remote VM

    How do i fix this?

  12. ntraft says:

    @Nidhi: It looks like you're trying to run a remote debugging session on an Android device? I have no experience with that. Seems like more of a problem with gdbserver than with gdb, though, judging from your error message.

  13. joeb says:

    i have it working when logged in directly on the machine but when i ssh into the machine remotely it says:

    Unable to find Mach task port for process-id 33493: (os/kern) failure (0x5).
    (please check gdb is codesigned - see taskgated(8))

    do i need to do something else for it to work on ssh/remote connections?

    any help greatly appreciated.

  14. ntraft says:

    @joeb: Whoa, that's pretty weird! Maybe it has something to do with the user you're logging in as... although I thought that codesigning should mean that any user can use it.

    As a temporary workaround, doing "sudo gdb" may work. Other than that, I got nothing for you. Do post back if you find an answer!

  15. Jordan says:

    I had the same problem as jl who posted:

    "Hi, I have follow the steps, but when I try to debug some project, eclipse says: "'Launching 'project' has encountered a problem. Error with command: /usr/local/bin/gdb -- version"
    Do you have any idea why is this happening?
    Thank you"

    So I followed your instructions:
    Your advice to enter 'which gdb' into the terminal resulted in "/usr/local/bin/gdb"

    When I run '/usr/local/bin/gdb --version', I get a lot of output related to gdb, which makes me think that I do have something there.

    However, I'm still encountering the result: "'Launching 'project' has encountered a problem. Error with command: /usr/local/bin/gdb -- version".

    What am I doing wrong?

  16. ntraft says:

    @Jordan: And you followed my instructions in the "Getting it to work in Eclipse" section? If so, then I'm not sure why it can't be accessed. Maybe it's a permissions issue.

  17. Oliver says:

    Thanks for this article! It helped me alot!
    But I had some problems, too! After following all instructions I got this error message:

    Unable to find Mach task port for process-id 33493: (os/kern) failure (0x5).
    (please check gdb is codesigned - see taskgated(8))

    The solution was NOT to change the settings from 'Getting it to Work with Eclipse'.
    Maybe it makes sense to try running gdb with eclipse first befor changing the settings.
    Thanks alot ntraft! :-)

  18. SoLuna says:

    I also had a same problem with above that error message.

    But, when i did "sudo gdb", it worked.

    thank you for this article.

  19. Manu says:

    Thanks a lot for this, saved a lot of time trying to google for the fix.

  20. M Ch says:

    great guide, thanks a lot

  21. CC says:

    I found a way to get this to work fully with the debugger. And this is the best tutorial I have found with the exception of using a gdb that isn't full feature. Thanks for putting this together!

    To get it to fully work you need to install the Apple version of gdb (gdb-apple) You can download it using Macports.

    First install Macports:

    Then install gdb-apple:
    sudo port install gdb-apple

    Then codesign it. I specified the new directory where it will be stored (/opt/local/bin/gdb-apple) in case you have already gone through this with the other version of gdb.
    codesign -s gdb-cert /opt/local/bin/gdb-apple

    You'll need to update the debug settings in Eclipse to reflect the change of location. And also restart eclipse after you make those location changes before debugging.

    Please update the main body of this tutorial to reflect this if you can. I've had to piece together three or four different tutorials to figure out how to finally get it to work. It took several hours of trial and error and lots of searching. Hoping someone else can confirm this works.

  22. ntraft says:

    Nice find, CC! I had assumed that MacPorts had all the same packages as Homebrew. I'll add that to my to-do list for this weekend!

  23. Anna says:

    Great guide, really, thank you!

  24. Emilio says:

    I followed your directions step by step. Everything is working well, and the Lazarus IDE now compiles and runs perfectly. Thanks a lot!

  25. ntraft says:

    Hey everyone,

    I finally tried CC's solution, and it didn't work. The Apple version has exactly the same problems with templates. YMMV.

    I'll update the post anyway to give an alternative.

  26. Shuai Wang says:

    Thanks for your blog! It helps me a lot.

    I follows the above steps. Now I am facing a problem: when I code sign the gdb-cert, the terminal will show that: this identity cannot be used for signing code.

  27. Shuai Wang says:

    I fixed it!

    The mistake I made is that: I didn't choose "Code Signing" when I apply the "Create Certificate".

    A really helpful blog!
    Thanks again!

  28. ZihYou Liao says:

    Hi !
    I already Xcode and Homebrew but step 2 has trouble display "command not found", please help me thank you !

  29. ntraft says:

    Ensure /usr/local/bin is on your PATH. If you don't know what that means, look up "PATH environment variable."

  30. Dimitar Nedev says:

    Awesome guide!
    Debugging in Eclipse - I've been missing this since I moved to programming in C (and on a Mac). You just made my day.
    Thank you!

  31. Minghung Chang says:

    Finally, this article helps me to debug my code with Mac.
    Thank you so much!!

  32. Geva says:

    It's not obvious when you try to type in the dialog box, but the Certificate Assistant in Keychain Access will actually let you set a validity of up to 20 years for a certificate. So you can type, say '7000' in the time limit field and really not have to worry about this again.

  33. Sheng says:

    Hello! Could you please give me a hand on how to use gdb inside Eclipse? It is working, but always says: "warning: `/var/folders/2d/nlf0cxgs2xjczyvpm5by9fbw0000gn/T/Chello-c758b8.o': can't open to read symbols: No such file or directory." THX a lot !!!!

  34. ntraft says:

    As long as it's working, that's the important thing! The Apple GDB prints out some errors for me, but the normal GDB doesn't. I ignore them.

  35. kwixson says:

    Thanks! Worked for me. I really appreciate the clear, step-by-step instruction. I had no problem following along. Got it working in Eclipse, though Code Blocks (aka C::B) is another matter...but that's a C::B thing. They don't have dev's for OS X and issues aren't being fixed.

  36. Eric says:

    Hi Neil,
    Just wanted to say thanks for posting this howto. Your step-by-step instructions made installing gdb and getting it to work in eclipse a breeze. Thank you! And good luck in achieving your goals to be a computer scientist. You will make a great one!

  37. Adrian says:

    I obtain that error some help?

    Error in final launch sequence
    Failed to execute MI command:

  38. Anonym says:

    Thanks for the detailed instructions. It's very easy to follow. Now I can get gdb up and running just fine.

    Hi Adrian, make sure you did the signing properly.

    Good luck!

  39. Peter says:

    Many thanks for this very helpful instruction. I missed the signing procedure first but now it works perfectly.

    Many regards, Peter

  40. Jose says:

    How do you set the path for the gdb debugger? i cannot make it work


  41. Jose says:

    I did a simple program and compiles and runs but it does not debug... I get this error message:

    Error in final launch sequence
    Failed to execute MI command:
    Error message from debugger back end:
    Unable to find Mach task port for process-id 13832: (os/kern) failure (0x5).
    Unable to find Mach task port for process-id 13832: (os/kern) failure (0x5).

    Can Someone help me please?

  42. Rajesh says:

    Hey, I also got the error "Unable to find Mach task port for process-id 33493: blah blah blah"

    and you know what?

    "sudo gdb" worked for me and i was able to debug my program
    Thanks for the tutorial

  43. Jon says:

    I'm getting stuck at the code signing part. I got the certificate all made up according to the instructions and I killed taskgated, but when I run codesign I get an error "/opt/local/bin/gdb-apple: code failed to satisfy specified code requirement(s)"

    Anyone know how to get it to sign it?

  44. Narimaan says:

    I just can't get this to work right for some reason. I followed this 100% to the letter, installed gdb, got it code signed, SEE that it's listed as installed in my list of ports installed, but for whatever reason, gdb isn't in /usr/local/bin/. Anyone with a similar problem, would appreciate the help, but I guess I'll have to get used to no debugging on Eclipse for a while :(

  45. ntraft says:

    @Narimaan: run the command `which gdb` to find out where it's installed. If you used MacPorts, then it's probably in /opt/local/bin. (if you installed gdb-apple, use `which gdb-apple`)

  46. Narimaan says:

    I just did that, found gdb-apple in the /opt/local/bin/, made sure that that was the path in Eclipse, but still get the standard error of:

    "Error with command: /usr/local/bin/gdb --version
    Cannot run program "/usr/local/bin/gdb": Unknown reason"

    That's a little confusing because it sounds like it's looking somewhere I know gdb isn't, i.e. not in "/usr/local/bin/", so is there someway I can specify installing gdb-apple (or just gdb, I don't really care at this point which one as long as it works) to /usr/local/bin? (If there is a way, Macports' guide isn't noob-friendly enough to make it very clear)

  47. ntraft says:

    Eclipse may have cached the location in your Run Configuration. But you're right, you can fix the problem either way by creating a symbolic link:
    $ ln -s /opt/local/bin/gdb-apple /usr/local/bin/gdb

  48. Narimaan says:

    Ok so I did that, that fixed that specific error. THEN it started saying it couldn't do it because it couldn't find the specific folder "Eclipse" in my documents (I named mine originally "Eclipse Projects"). So I went back, changed my workspace to be in a folder called "Eclipse", redid a simple program I've been using as a guinea pig for getting debug to work, and NOW the error is just flat out:

    "Error with command: gdb --version
    Cannot run program "gdb": Unknown reason"

    Yeah I've got nothing when all it says is "unknown reason", so yeah, if you or anyone knows that specific error ("specific" being used lightly here), I'd love input on it, otherwise don't bother yourselves with it, I've got to find a new platform for coding c++ anyways, seems macs don't get a long with the idea of coding (unless it's to make an iPhone or Mac app, in which Xcode is the farthest thing from noob-friendly).

  49. ntraft says:

    Except notice that now it says "gdb" instead of "/usr/local/bin/gdb", so it lost your preferences when you moved your workspace (you probably forgot to move the .metadata folder). Go back through the last section of my tutorial.

  50. ntraft says:

    It also seems worth noting that C++ and ObjC are unfortunately the worst possible languages for newbies, no matter what your development environment. So if you can avoid them, you should. Even a seasoned programmer like myself is filled with rage and angst by C++.

  51. Narimaan says:

    Hehe oh yeah no I kind of agree with you there, though C++ isn't really that difficult for me to get since the first real coding language I learned was Python and it's pretty similar with differences in just the exact terms. Plus I'm taking a required c++ class right now so I'm just trying to set up a workable IDE outside of school to work on projects with.

  52. Narimaan says:

    And HALLELUJAH I finally fixed it! The last error I got after re-declaring the path was this:

    "Error in final launch sequence
    Failed to execute MI command:
    -environment-cd "/Users/narimaanvalian/Documents/Eclipse/Sample Distance Program"
    Error message from debugger back end:
    /Users/[my username]/Documents/Eclipse/Sample: No such file or directory
    /Users/[my username]/Documents/Eclipse/Sample: No such file or directory"

    So I took the same rout, remade my workspace folder, RENAMED every single possible file, folder, or project to have "_" instead of spaces, and NOW it finally works! Kind of annoying how I can't have spaces in any names now but at least it works! :D

  53. Lena says:


    I have a similar problem with Jon, while running codesign, I get this error message:
    codesign -s gdb-cert /opt/local/bin/gdb-apple
    error: /Applications/ can't create output file: /opt/local/bin/gdb-apple.cstemp (Permission denied)
    /opt/local/bin/gdb-apple: the codesign_allocate helper tool cannot be found or used

    please help!

  54. Kiana Ali Khademi says:

    i followed the above steps but when i try to sign the certificate it told me that -s command not found .what should i do ?please help me .

  55. ntraft says:

    Did you type the command exactly as shown, without the '$' sign? Try `codesign -h` to see what commands are available.

  56. Isaias says:

    Thanks a lot. It worked beautifully!

  57. Bruce Hilbert says:

    I've tried this several times and I get the following error when trying to debug with gdb on the command (I got the same thing in Netbeans. I'm not familiar with Eclipse.)

    args=) at ../main.cpp:13

    Any help would be appreciated.

  58. Bruce Hilbert says:

    Whoops. Goofed the error in the above. Here's what I should have written.

    I've tried this several times and I get the following error when trying to debug with gdb on the command (I got the same thing in Netbeans. I'm not familiar with Eclipse.)

    Could not find the frame base for "main(int, char**)".>,
    args=) at ../main.cpp:13

    Any help would be appreciated.

  59. Bruce Hilbert says:

    Arrgggg. Some sort of cut and paste error. Let see if this works:

    Could not find the frame base for "main(int, char**)".>, args=) at ../main.cpp:13

  60. Sharan says:


    Im getting this error after typing this command:
    codesign -s gdb-cert $(which gdb-apple)

    error: /Applications/ can't create output file: /opt/local/bin/gdb-apple.cstemp (Permission denied)
    /opt/local/bin/gdb-apple: the codesign_allocate helper tool cannot be found or used

  61. Anonymus says:

    Thnxs for the help!!!

  62. Leo says:

    Lena and Sharan

    If you already have not figured out, use the codesign command with sudo (as a superuser) behind it. Then it asks u for a admin user/admin password and then it works!

    Also I had to restart Eclipse.

    Thanks for a great tutorial btw. Helped a lot!

  63. Anonymous says:

    I am experiencing the same issue:

    $ codesign -s gdb-cert $(which gdb)
    gdb-cert: no identity found

    My certificate is named


    and I followed the above steps perfectly. I am using OS X 10.10. Any ideas?

  64. ntraft says:

    It suggests to me that gdb-cert doesn't exist but as you said that shouldn't be the case. I haven't upgraded to 10.10 yet and don't plan to anytime soon after hearing about the wifi issues.

  65. adam says:

    hey ntraft. do you have any alternatives which i can use as a replacement for apple-gcc42? because osx yosemite doesn't support it

  66. adam says:

    Here is the details of errors:

    Warning: The Xcode Command Line Tools don't appear to be installed; most ports will likely fail to build.
    Warning: Install them by running `xcode-select --install'.
    ---> Computing dependencies for apple-gcc42
    ---> Fetching distfiles for apple-gcc42
    Error: apple-gcc42 is not supported on Yosemite or later.
    Error: org.macports.fetch for port apple-gcc42 returned: unsupported platform
    Please see the log file for port apple-gcc42 for details:
    To report a bug, follow the instructions in the guide:
    Error: Processing of port apple-gcc42 failed

  67. ntraft says:

    There is a patch for Yosemite attached to this ticket that will probably do the trick:

  68. Thanks, it worked perfectly on Yosemite :)
    FYI, I tried the Homebrew version and running it only for command-line usage

  69. Juan Carlos Vergara Gallego says:

    Hi, I'm getting an error when I tried to debug with gdb.
    When I tried to make a stop in a specific line:


    gdb borra.out

    GNU gdb (GDB) 7.8.1
    Copyright (C) 2014 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-apple-darwin14.0.0".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    Find the GDB manual and other documentation resources online at:
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from borra.out...
    warning: `/var/folders/47/t1x21gw91sl4gjgzf2_p27zc0000gn/T//ccZcWGDa.o': can't open to read symbols: No such file or directory.
    (no debugging symbols found)...done.

    break 91
    No symbol table is loaded. Use the "file" command.


    Starting program: /Users/admin/Documents/Doctorado/Proposal/Regional/SectorCircular/borra.out
    warning: `/private/tmp/gcc-uQONuD/gcc-4.9.2/build/x86_64-apple-darwin14.0.0/libgfortran/.libs/_abs_c10.o': can't open to read symbols: No such file or directory.
    warning: `/private/tmp/gcc-uQONuD/gcc-4.9.2/build/x86_64-apple-darwin14.0.0/libgfortran/.libs/_abs_c16.o': can't open to read symbols: No such file or directory.
    warning: `/private/tmp/gcc-uQONuD/gcc-4.9.2/build/x86_64-apple-darwin14.0.0/libgfortran/.libs/_abs_c4.o': can't open to read symbols: No such file or directory.

    and continues.......

    What can I do?


  70. jesusv says:

    Great!! thanks a lot

  71. RSilva says:

    Very Good! It works perfectly on Yosemite 10.10.1!!!

  72. Jay Dolan says:

    Thanks, Neil. I'm a fellow c dev who uses Eclipse on OS X. This was a big help.

  73. Enzhou Wang says:

    Thanks a lot! It's really helpful. The only places I had to do a little differently are:
    1. When running codesign, I had to do sudo:
    sudo codesign -s gdb-cert $(which gdb-apple)
    2. When configuring Eclipse, use gdb-apple instead of gdb.
    I'm on Mavericks (10.9.5).

  74. diarmuidcire says:

    Super - worked for me too.
    Thanks for the big help

  75. Rui Santos says:

    I got an error saying
    "Error: apple-gcc42 is not supported on Yosemite or later."
    I downloaded the "Portfile-gdb-apple.diff" but now I don't know what to do with this.
    Can you give me some hints?

  76. RJ Palombo says:

    Using Yosemite and this works perfectly. This is awesome, thanks for the writeup!!!

  77. Jaime says:

    In preferences under debug there is no gdb option. Any idea why? I've gone over the installing above a couple of times and can't figure it out.

  78. ntraft says:

    @Jaime: Use the search in the upper left of the Preferences dialog to be sure you're not missing it. For me, it was installed with the CDT plugin. If I look into "About > Installation Details > Plug-ins" I can see two GDB plugins (plugin ID org.eclipse.cdt.debug.mi.*).

  79. Jaime says:

    Thank you, I have the cdt plugin installed and still no gdb in preferences.
    I even tried reinstalling. Any suggestion would be appreciated. Thanks again.

  80. John says:

    Sorry everyone but Mac Noob here ( only 10 days in )

    The program I want to install says:
    "Make sure you have gdb installed. Test by typing "gdb test" into terminal."

    To which I get:

    Johns-MacBook-Air:~ John$ gdb test
    -bash: gdb: command not found

    I have Installed Xcode and MacPorts, but how do I install the Apple GCC and GDB from MacPorts??

    Where do I enter?:
    $ sudo port install gdb-apple
    $ sudo port install apple-gcc42

    Would someone please explain, probably simple stuff I know but we all had to start somewhere!

    Dunno if this helps at all?:

    Last login: Sun Jan 4 10:28:16 on ttys000
    Johns-MacBook-Air:~ John$ gdb test
    -bash: gdb: command not found
    Johns-MacBook-Air:~ John$ xcode-select -p
    Johns-MacBook-Air:~ John$ gcc --version
    Configured with: --prefix=/Applications/ --with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
    Target: x86_64-apple-darwin13.4.0
    Thread model: posix
    Johns-MacBook-Air:~ John$

  81. ntraft says:

    Hi John.

    On my blog, everything prefaced with a dollar sign '$' are commands that should be entered in the terminal. Does that answer your question?

  82. John says:

    Thanks for the reply Neil.
    Do I enter a command 'one at a time' or paste both in together?

    As a Mac Noob I dont understand how deep I am playing about with the 'bios' .....if at all & don't want my shiny new christmas prezzie to become a brick.


  83. ntraft says:

    One command per dollar sign (notice that your command prompt ends in a dollar sign: 'John$') ... this is intended to mirror that.

    You aren't touching the BIOS, nor even the default software, since gdb doesn't come on your Mac by default. No chance of screwing up the existing software, for once.

    Do note that if you use the Apple version of gdb, your program may not be able to find it since it will be looking for 'gdb', not 'gdb-apple'. But you can remedy this situation by creating a symlink:

    $ ln -s /opt/local/bin/gdb-apple /usr/local/bin/gdb

    It's a little bit disconcerting that you're already installing development tools with such little Unix knowledge. Unless you're a C/C++ developer, I can't imagine what use you would have for gdb or any software that uses gdb... unless you're a self-taught programmer in the Windows ecosystem...

  84. Jaime says:

    I got gdb working in eclipse, but I now have errors warning: Could not open OSO archive file "/BinaryCache/Libsyscall/Libsyscall-2422.115.4~1/Symbols/BuiltProducts/libsystem_kernel.a".........
    I had removed gdb then reinstalled it, I was not getting those errors before.



  85. wuranbo says:

    the above /var/folder guys.I has the same problem.
    I fix it by this;
    1. add `-save-tmp` to the gcc options is the shortest way make things working.
    2. read how to write a more pro makefile.The making is divided to gcc -c -o obj-file, and link the object file by gcc object files.By the first step, we got the obj file which contain the symbols.

  86. Luca says:

    Hi, I'm using Yosemite and I get the error for apple-gcc42, I downloaded "Portfile-gdb-apple.diff" but I don't know what to do with that.

    I continued the tutorial and finished even if I didn't solve the problem above.
    But now I can't find gdb in /usr/local/bin

    What can I do?

  87. ntraft says:

    With the upgrade to Yosemite, installing gdb-apple seems pretty complicated. You might want to try plain old gdb first and see if that works well enough for you:

    $ sudo port install gdb

  88. Karen says:

    Thank you so much! Worked for me using homebrew on Yosemite.

  89. Const says:

    When I entered in Terminal
    sudo port install gdb-apple
    it returned:
    Port gdb-apple not found

  90. ntraft says:

    @Const: Don't know what to tell you; it's there for me, and it's there on the website:

    Did you try
    $ sudo port selfupdate

  91. David Lowe says:

    Mavericks install as on the tin. Perfect. Thank you.

  92. Roland Göttig says:

    Dear Neil,

    I used the Homebrew version to install gdb. It worked perfectly for "Lazarus", the free pascal development suite. :-)

    Many thanks, indeed.
    Now I'll be able to recycle some very old Delphi code.

    Best regards

  93. Aaron says:

    I'm having this problem after I input $ codesign -s gdb-cert $(which gdb-apple)
    error: /Applications/ can't create output file: /opt/local/bin/gdb-apple.cstemp (Permission denied)
    /opt/local/bin/gdb-apple: the codesign_allocate helper tool cannot be found or used

  94. Aaron says:

    ok so I think i figured it out, typing "sudo" before the "codesign -s gdb-cert $(which gdb-apple)"

    however, how can I test if gdb has been successfully installed? entering "gdb test" into terminal gives me this
    "-bash: gdb: command not found"

  95. ntraft says:

    Did you try 'gdb-apple test'? Or, did you make a symlink so it shows up in your $PATH as 'gdb'?

    $ ln -s /opt/local/bin/gdb-apple /opt/local/bin/gdb

  96. Thai Truong says:

    Truongs-MacBook-Pro:~ akitathai94$ ps -e | grep taskgated
    63818 ?? 0:00.03 /usr/libexec/taskgated -s
    63840 ttys000 0:00.00 grep taskgated
    Truongs-MacBook-Pro:~ akitathai94$ sudo kill -9 63818
    Truongs-MacBook-Pro:~ akitathai94$ codesign -s gdb-cert $(which gdb)
    gdb-cert: this identity cannot be used for signing code

  97. ntraft says:

    @Truong A lot of people are having to 'sudo' the codesign command, although I'm not sure why. Can't hurt I guess?

  98. BK says:

    I keep getting this error:
    gdb-cert: this identity cannot be used for signing code
    Even though I run: sudo codesign -s gdb-cert $(which gdb)
    How can i fix this?

  99. Anita Garcia says:

    Thank you for the tutorial! I am still experiencing difficulties. I followed the entire sequence up until
    $ codesign -s gdb-cert $(which gdb)

    It gave me a "Identity cannot be used for signing code"

    -- I tried it again and it said:

    no identity found

    What should I do next?

  100. ntraft says:

    @BK and Anita:

    I just read somewhere that restarting your machine after you create the cert may be required... so make sure you've done that:

    Try adding the -f flag, just in case. But I don't think that matters.

    "No identity found" seems to indicate that you typed the name wrong. "Cannot be used for signing code" seems to indicate that you didn't choose the right certificate type when you created it... but you said you followed the instructions correctly so...

    Other than that, maybe something has changed in the new version of Xcode or Yosemite (if you're running Yosemite)?

    You could also try changing this setting:

    Or read these pages for more about codesigning and Gatekeeper:

  101. Juan Carlos Vergara Gallego says:


    Does anyone have the same problem?

    This is what happen to me when I tried to make a debug with gdb.


    warning: `/var/folders/47/t1x21gw91sl4gjgzf2_p27zc0000gn/T//ccWmMizV.o': can't open to read symbols: No such file or directory.

  102. Paul Matthew says:

    Hi, It works flawlessly. Thank you for the information. I encountered no problems using the Homebrew way in Yosemite.

  103. user786 says:

    Thanks a lot! I can confirm that this works using Homebrew in Yosemite . Now I can use omnet++ 4.5 without problems.

  104. Ankit says:

    for those who got the following error:

    Unable to find Mach task port for process-id 33493: (os/kern) failure (0x5).
    (please check gdb is codesigned - see taskgated(8))

    try re-launching eclipse with sudo access. seems the error pops up because of permission issue. It might be because the installation / set up required sudo access. So, you need to sudo for using gdb.

    to start eclipse via sudo. Go to terminal and type in :
    'sudo open -n /Applications//eclipse.

    Hope that fixes your problem. It did the trick for me.

  105. ntraft says:

    That's the error you get when it's not signed properly. If you wanted to run gdb with sudo, then you wouldn't need to sign it in the first place. Hard to say what went wrong with the signing, though. You may have made a mistake somewhere.

  106. Moyshe Zuchmir says:

    It was really helpful

    M. Zuchmir

  107. nicolai slaatto says:

    Hi and thanks for a very fine tutorial!
    I followed your steps, and everything seems to work, except when debugging. I get the following error message:

  108. nicolai slaatto says:

    Failed to set program arguments, environment or working directory.
    Unable to set working directory:
    Hi and thanks for a very fine tutorial!
    I followed your steps, and everything seems to work, except when debugging. I get the following error message:

    "/Users/nicolaislaatto/Desktop/Dropbox/4_semester/Speciale/espro/eclipse_wdir/HelloFortran": No such file or directory.
    Unable to set working directory: "/Users/nicolaislaatto/Desktop/Dropbox/4_semester/Speciale/espro/eclipse_wdir/HelloFortran": No such file or directory.
    Unable to set working directory: "/Users/nicolaislaatto/Desktop/Dropbox/4_semester/Speciale/espro/eclipse_wdir/HelloFortran": No such file or directory.

    I red about others having the same problem - but they all had spaces in their path - I don't have that, but still it doesn't work.

    Your help is very much appreciated.


  109. ntraft says:

    @Nicolai: Nothing especially jumps out at me. Are you sure the path is correct? Most people have their Dropbox folder in their home folder, not Desktop...

  110. nicolai slaatto says:

    Thanks for the reply!
    - yes, I checked and rechecked it. Also I tried another working directory.

    While setting the Debug Configurations, my dialog looks slightly different:
    I can chose:

    GDB command set: Standard or Standard (Mac OS)
    Verbose console mode: on/off
    Use full file path to set breakpoints: on/off

    I get different errors depending on the six combinations of above choices, but none of them works.

    Im compiling fortran code using
    Eclipse for Parallel Application Developers

    Version: Luna Service Release 1a (4.4.1)
    Build id: 20150109-0600.

    I guess that did not give further clues?

    Kind regards,

  111. nicolai slaatto says:

    ...sorry, eight combinations:)...

  112. ntraft says:

    Yeah, sorry, I don't see anything obvious. I would keep looking at issues with the directory if it were me... does it have the right permissions? What if I moved it somewhere else on my hard drive? Etc.

  113. nicolai slaatto says:

    well, thanks for your time. I tried different places on my HD. I also tried using gdb via the terminal which works!
    although It still give me an error message once i do '(gdb) run':

    Starting program: /Users/.../HelloFortran/a.out
    warning: `/Users/fx/devel/gcc/build_package/ibin/x86_64-apple-darwin13/libgfortran/.libs/_abs_c10.o': can't open to read symbols: No such file or directory.

    and a lot of similar warnings follow. But once they stop I can debug - the problem is of course that my real code is large and for that eclipse would be nice!

  114. Nadia says:

    Thanks a lot for your tutorial!
    It helped a lot. But now it stopped working, no stepping is working at all!

  115. Steve says:

    Thanks. Very helpful.

    GDB seem to do a few strange things on eclipse luna

  116. William says:

    Thank you Neil!

  117. Robert says:

    Thanks a million. By the way, while it is not possible to enter '9999' for the validity period, it is possible to enter a number such as '7399', which will give you about 20 years - better than under 3 years :-)

  118. Andrea says:

    Hello, i have the following error, where am I wrong?
    MacBook-Pro-di-Andrea:~ Andrea$ $sudo port install gdb-apple
    Error: Insufficient privileges to write to MacPorts install prefix.

  119. ntraft says:

    It's `sudo`, without the dollar sign ($).

  120. Don Ashe says:

    I just followed your walkthrough to install gdb on Mavericks for use with Netbeans 7.4 - worked without a hiccup.

    You saved me many hours!


  121. Edoardo says:

    +1 Thank you


  122. Chris Wilson says:

    Thank you, that was really helpful!

  123. Rahul Ghose says:

    Awesome tip! Works with Yosemite as well. thanks a lot. :)

  124. Natasha says:

    Hello Nail,

    First of all, thank you very much for you article. Its helpful in general.
    Unfortunately, in my case it didn't work properly. OS is Maverick.
    1) I followed all the steps regarding gdb installation and certification. I followed the steps even twice to see that there is no mistake, but I'm getting:
    Failed to execute MI command:
    Error message from debugger back end:
    Unable to find Mach task port for process-id 13832: (os/kern) failure (0x5).
    Unable to find Mach task port for process-id 13832: (os/kern) failure (0x5).

    Therefore I have to run eclipse with sudo. Maybe its logged in user related issue...

    2) After I run eclipse with sudo, its starting launching executable but doesn't hit the first breakpoint in main based on the log. And even launch stucks at the end...

    Could you assist?


  125. ntraft says:

    Hi Natasha. You could try the following:

    sudo security add-trust -d -p basic -p codeSign -k /Library/Keychains/System.keychain gdb-cert

  126. Hank O'Brien says:

    So i was having the same issue as joeb (the one with Mach ports), and after looking around i found that if I type the following into terminal, the error goes away and debugging works.

    $ cd /usr/local/bin
    $ codesign -s gdb-cert gdb

    the second line is from the GDB wiki that appears to address this specific problem (

  127. Aschwin van Loon says:

    This works perfectly.
    Now i don't need any virtual machines anymore

  128. harry says:

    this is awesome, i was trying out debugging rust code with gdb and was stuck. If not for the detailed instruction it would have hours of googling. Thanks a lot

  129. a----- says:


  130. Kaspar says:

    Thanks so much:)

  131. esdee says:

    thanks a lot

  132. Thomas says:

    I guess the guide worked for me, but I get a problem with setting the dynamic library path (dyld) in Eclipse.

    Debugging stops in Eclipse with the following message:
    dyld: Library not loaded: libmkl_intel_lp64.dylib

    When use gdb in the terminal, I am able to debug the programm, since I have included all necessary dynamic libraries in my bashrc.

    How can I solve the dyld problem in Eclipse?

  133. Thomas says:

    Wow, after finally posting my question, I found the solution a few minutes later. I just had to add the path DYLD_FALLBACK_LIBRARY_PATH from my bashrc to the environment in the debug configuration of Eclipse. Now debugging finally works on Yosemite.

  134. Thomas says:

    Now my last comment. I wasn't able to debug with gdb-apple from macports. I always got the following error message:
    Error in final launch sequence
    Failed to execute MI command:
    -file-exec-and-symbols ....
    Error message from debugger back end:
    \nError: gdb does not handle things like classes defined inside functions correctly; debug info for 'name' skipped, please use lldb if you need to debug code in this framework.
    \nError: gdb does not handle things like classes defined inside functions correctly; debug info for name' skipped, please use lldb if you need to debug code in this framework.

    After downloading and compiling gdb 7.9 from the official website, the problem is solved and it works in Eclipse Mars as well.

  135. zair says:

    Thanks ntraft.
    really appreciate for taking efforts to share.

    saved my day.

    thanks a lot!

  136. Zheng Rui says:

    For those who has warnings related to "OSO" files (like Jaime above, but mine starts from not finding libcorecrypto_static.a), you may tried to uninstall gdb versions above 7.7. For me i brew install 7.10, and also build 7.8 by myself, both had the same warnings. After i reinstall a 7.7.1 version from

    Now it works perfectly :D .

    Related links:

  137. Christian R. Conrad says:

    Great resource, thanks!

  138. brv says:

    that worked perfectly, thanks a lot

  139. Gino says:

    Thanks for the tutorial . I have the problem that breckpoints not working . Any solution?

  140. Mathias says:

    Still doesn't work. What did you mean wheb yousaid gdb executable? Can I only compile in certain directories?

  141. Phil says:

    Thak you so much - I used the homebrew approach and everything worked right out of the box on El Capitan. This removed my last block and I am very appreciative.

    Best, Phil

  142. Ram says:

    Thanks for your instructions Neil. I followed your instructions for MacPorts on El Capitan. I was able to install and codesign gdb-apple without problems. However, I only seem to be able to run it in sudo mode on the command line. Consequently I cannot run it in eclipse.

    What did I mess up? Is there an easy way to change permissions to avoid this?


  143. Ram says:

    I forgot to add in my previous message:
    When I try to run it in eclipse, the error message is the following:

    Error in final launch sequence
    Failed to execute MI command:
    Error message from debugger back end:
    Unable to find Mach task port for process-id 1376: (os/kern) failure (0x5).
    Unable to find Mach task port for process-id 1376: (os/kern) failure (0x5).

    which suggests to me that gdb-apple has not been codesigned properly. But then, will it run in sudo mode?


  144. Ram says:

    OK. I got to install without problems using Brew.
    The problem is with the installation of gdb-apple using MacPorts. I missed a small, but very important detail in the build of gdb-apple:

    You will need to make sure /System/Library/LaunchDaemons/ has the '-p' option, e.g.


    This plist file CANNOT be directly edited in El Capitan even in sudo mode. You need to disable system integrity protection by rebooting and going into Recovery mode in order to "get permission" to edit it. For more details, see

    Enough motivation for me to switch to Brew....

  145. Paul K says:

    OK. Thanks for this. I managed to get Eclipse to use GNU gdb on Yosemite. I don't like working with either Macports or Homebrew so I did a vanilla source install. The code signing made the difference though I had to restart my Mac in order for taskgated to 'accept' the certificate.

  146. Matthew says:

    I required two modifications to this recipe to get it to work on El Capitan with Eclipse Mars:

    1. Only the Homebrew install worked for me
    2. Process taskgated does not restart by itself. Rebooting starts it.

  147. Emad says:

    Well, first thank you for putting such a helpful article for someone like me who is experimenting with Eclipse on MAC OS X.

    I installed the gdb-apple using the MacPorts route. I had to launch eclipse using sudo. It worked, finally, and I was able to launch GDB.

    However, I still have one problem in examining program variables. I get this message (I click on a variable in my program, then click again in the popup menu)

    1) Failed to execute MI command:
    -var-update 1 var3
    Error message from debugger back end:
    Variable object not found

    2) Failed to execute MI command:
    -var-update 1 var3
    Error message from debugger back end:
    Variable object not found

  148. Lian says:

    Thank you~ It was a great help!!

    Now, GDB is working~!!

  149. Moo says:


    on el capitan, gdb installs fine, but when trying to run it in netbeans I get

    'GDB has unexpectedly stopped with return 127'

    and then gdb does not start

    any ideas?

    any ideas?

  150. Hermann says:

    Great job, thank you !!!

  151. Akanksha says:

    Omg thank you so much! XD

  152. Matt says:

    Works on El Capitan, awesome! Thank you!

  153. siwoojoo says:

    After several attempts of installation and uninstallation of Macports and Homebrew I finally was able to get this going.

    I have El Captian & Eclipse CDT Neon version.

    Macports never really worked & I kept having issues with Homebrew as it never created gdb executable file. I had to uninstall gdb Homebrew and rebooted and re-installed and finally got it working.

    Thank you so much for this post.

  154. cody henrichsen says:

    Thanks - I will be making a video of this process to help my students :D

Leave a Reply

Your email address will not be published. Required fields are marked *