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
- Install Xcode and MacPorts, if not already installed.
- Now install the Apple GCC and GDB from MacPorts:
12$ 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 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
- Install Xcode and Homebrew, if not already installed.
- Now install GDB from Homebrew:
12$ 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, 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 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 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
Success!
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.
1 2 3 |
$ 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).
1 |
$ sudo kill -9 56822 |
Now you can finally code sign GDB.
1 2 3 4 |
# 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...):
- 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.
- The procedure is derived from this StackOverflow post and this GDB Wiki page.
- 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.
This was a huge help! Thanks for the detailed procedure.
Kevin
Thanks for the article. I can't get breaks set for a shared library function to work. Have you encountered this problem ?
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. http://stackoverflow.com/questions/19554439/gdb-missing-in-os-x-mavericks
Thanks. This works perfectly for my Mavericks.
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?
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.
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?
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.
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
@jl
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"?
Hi,
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?
@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.
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.
@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!
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?
@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.
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! :-)
I also had a same problem with above that error message.
But, when i did "sudo gdb", it worked.
thank you for this article.
Thanks a lot for this, saved a lot of time trying to google for the fix.
great guide, thanks a lot
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:
http://www.macports.org
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.
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!
Great guide, really, thank you!
I followed your directions step by step. Everything is working well, and the Lazarus IDE now compiles and runs perfectly. Thanks a lot!
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.
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.
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!
Hi !
I already Xcode and Homebrew but step 2 has trouble display "command not found", please help me thank you !
Ensure /usr/local/bin is on your PATH. If you don't know what that means, look up "PATH environment variable."
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!
Finally, this article helps me to debug my code with Mac.
Thank you so much!!
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.
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 !!!!
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.
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.
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!
E
I obtain that error some help?
Error in final launch sequence
Failed to execute MI command:
-exec-run
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!
Many thanks for this very helpful instruction. I missed the signing procedure first but now it works perfectly.
Many regards, Peter
How do you set the path for the gdb debugger? i cannot make it work
thanks
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:
-exec-run
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?
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
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?
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 :(
@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, usewhich gdb-apple
)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)
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
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).
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.
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++.
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.
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
Hi,
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/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: 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!
Hi
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 .
Did you type the command exactly as shown, without the '$' sign? Try
codesign -h
to see what commands are available.Thanks a lot. It worked beautifully!
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.
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.
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
Hey,
Im getting this error after typing this command:
codesign -s gdb-cert $(which gdb-apple)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: 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
Thnxs for the help!!!
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!
I am experiencing the same issue:
My certificate is named
and I followed the above steps perfectly. I am using OS X 10.10. Any ideas?
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.
hey ntraft. do you have any alternatives which i can use as a replacement for apple-gcc42? because osx yosemite doesn't support it
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:
/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_apple-gcc42/apple-gcc42/main.log
To report a bug, follow the instructions in the guide:
http://guide.macports.org/#project.tickets
Error: Processing of port apple-gcc42 failed
There is a patch for Yosemite attached to this ticket that will probably do the trick: https://trac.macports.org/ticket/42796
Thanks, it worked perfectly on Yosemite :)
FYI, I tried the Homebrew version and running it only for command-line usage
Hi, I'm getting an error when I tried to debug with gdb.
When I tried to make a stop in a specific line:
Example:
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.
run
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.
/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.warning:
and continues.......
What can I do?
Thanks!!
Great!! thanks a lot
Very Good! It works perfectly on Yosemite 10.10.1!!!
Thanks, Neil. I'm a fellow c dev who uses Eclipse on OS X. This was a big help.
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).
Super - worked for me too.
Thanks for the big help
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?
Thanks.
Using Yosemite and this works perfectly. This is awesome, thanks for the writeup!!!
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.
@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.*).
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.
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
/Applications/Xcode.app/Contents/Developer
Johns-MacBook-Air:~ John$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --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$
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?
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.
Thanks
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...
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.
thanks,
J
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.
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?
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
Thank you so much! Worked for me using homebrew on Yosemite.
When I entered in Terminal
sudo port install gdb-apple
it returned:
Port gdb-apple not found
@Const: Don't know what to tell you; it's there for me, and it's there on the website: https://www.macports.org/ports.php?by=name&substr=gdb-apple
Did you try
$ sudo port selfupdate
Mavericks install as on the tin. Perfect. Thank you.
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
I'm having this problem after I input $ codesign -s gdb-cert $(which gdb-apple)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: 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
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"
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
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
Password:
Truongs-MacBook-Pro:~ akitathai94$ codesign -s gdb-cert $(which gdb)
gdb-cert: this identity cannot be used for signing code
@Truong A lot of people are having to 'sudo' the codesign command, although I'm not sure why. Can't hurt I guess?
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?
Thanks.
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?
@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:
http://stackoverflow.com/questions/13913818/how-to-get-a-codesigned-gdb-on-osx
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: http://support.apple.com/library/content/dam/edam/applecare/images/en_US/osx/security_preferences_options.png
Or read these pages for more about codesigning and Gatekeeper:
http://support.apple.com/en-us/HT202491
http://stackoverflow.com/questions/21917549/unable-to-codesign-installer-package-with-valid-installer-certificate
Hi,
Does anyone have the same problem?
This is what happen to me when I tried to make a debug with gdb.
Thanks!
warning: `/var/folders/47/t1x21gw91sl4gjgzf2_p27zc0000gn/T//ccWmMizV.o': can't open to read symbols: No such file or directory.
Hi, It works flawlessly. Thank you for the information. I encountered no problems using the Homebrew way in Yosemite.
Thanks a lot! I can confirm that this works using Homebrew in Yosemite . Now I can use omnet++ 4.5 without problems.
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.
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.
Thanks,
It was really helpful
M. Zuchmir
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:
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.
Nicolai
@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...
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,
Nicolai
...sorry, eight combinations:)...
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.
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!
Thanks a lot for your tutorial!
It helped a lot. But now it stopped working, no stepping is working at all!
Thanks. Very helpful.
GDB seem to do a few strange things on eclipse luna
Thank you Neil!
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 :-)
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.
It's
sudo
, without the dollar sign ($).Neil!
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!
Thanks!
-Don
+1 Thank you
!
Thank you, that was really helpful!
Awesome tip! Works with Yosemite as well. thanks a lot. :)
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:
-exec-run
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?
Thanks.
Hi Natasha. You could try the following:
sudo security add-trust -d -p basic -p codeSign -k /Library/Keychains/System.keychain gdb-cert
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 (https://sourceware.org/gdb/wiki/BuildingOnDarwin)
This works perfectly.
Now i don't need any virtual machines anymore
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
Awesome!!
Thanks so much:)
excellent!
thanks a lot
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?
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.
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.
Thanks ntraft.
really appreciate for taking efforts to share.
saved my day.
thanks a lot!
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
https://gist.github.com/ymyzk/10ad2b74af9235eddb2c
Now it works perfectly :D .
Related links:
https://github.com/Homebrew/homebrew-dupes/issues/357
Great resource, thanks!
that worked perfectly, thanks a lot
Thanks for the tutorial . I have the problem that breckpoints not working . Any solution?
Still doesn't work. What did you mean wheb yousaid gdb executable? Can I only compile in certain directories?
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
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?
Thanks,
Ram
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:
-exec-run
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?
Thanks,
Ram
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/com.apple.taskgated.plist has the '-p' option, e.g.
ProgramArguments
/usr/libexec/taskgated
-sp
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
http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/
Enough motivation for me to switch to Brew....
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.
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.
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
Thank you~ It was a great help!!
Now, GDB is working~!!
hi.
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?
Great job, thank you !!!
Omg thank you so much! XD
Works on El Capitan, awesome! Thank you!
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.
Thanks - I will be making a video of this process to help my students :D
Hi. I got here googling information about getting gdb running in Yosemite 10.10.4
I was able to install gdb via brew (GNU gdb (GDB) 7.10.1 is the version installed). I was able to do the signing procedure without errors.
I was able to execute gdb but when I tried to run any app I get the error ": not in executable format: File format not recognized"
I had gdb running flawlessly in my 10.6 install but no luck in 10.10 so far.
Anybody have any suggestions? Thanks!
I have got all this set up and it seems like it should work fine (i.e. no errors or warnings) but when I try to step through my code it gets lost after stepping into certain methods and kicks me out to some anonymous frame "0x1000013ea" instead of my main function. I first suspected that it had to debugger symbols not being present but I checked my compilation calls and they were of the form
g++ -DHAVE_CONFIG_H -I. -I../../src -I.. -DDEBUG -I/usr/local/include -Wall -g3 -O0 -MT .o -MD -MP -MF .deps/.Tpo -c -o .o ../../src/.cpp
so it seems right to my eyes. Do I need to point it to a particular version of the C++ standard library with debug symbols?
I tried the same code compiling with homebrew's g++ (v5.3) and it steps through the code fine but cannot display the variables due to
"Could not find the frame base for ..." errors. (NB: I have found various stack-overflow/mailing list queries about this but no one has an answer so I gave up on compiling with g++). Perhaps my code is picking up a brewed version of of the standard libraries?? I am not sure
Thanks a million I have been trying for six months to get Lazarus and FPC to work never could figure out the dbug.
I am trying to setup GDB on Mac OS X El Capitan. I installed and signed gdb have already set the path in Eclipse (Preference->C/C++->GDB-> /usr/local/bin/gdb). Trying to debug simple hello world program. but its stuck at 96% (at the bottom right). Please refer the
stackoverflow url
http://stackoverflow.com/questions/37760879/mac-c-mars-eclipse-gdb-debug-launching-stuck-at-96?noredirect=1#comment63003068_37760879
Hi Kumar Vishal,
I got the same error as yours, i.e., got stuck on 96%. This is fixed by certifying GDB. You may follow the step by step of this post and the error will go.
However, i am only able to set breakpoints in the main function. All other breakpoints will lead to errors like "Breakpoint installation failed: Cannot access memory at address 0x14d0".
I installed gdb by downloading its tar.gz file from the gnu website.
Hi Ntraft,
Though I am able to start debugging the program from the entrance of main function, but I am not able to set breakpoints outside the main function. Also stepping into functions is also not allowed. Any suggestions? Thanks,
Thank-you very much for the detailed tutorial. It worked. In my case at least, gcc also worked.
Hi Li , as I have mentioned I have already signed the GDB( i.e certified it).
http://stackoverflow.com/questions/37760879/mac-c-mars-eclipse-gdb-debug-launching-stuck-at-96?noredirect=1#comment63003068_37760879
I followed your instructions precisely and have looking everywhere but cannot fix my problem.
Unable to find Mach task port for process-id 4793: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
I get this error message every time no matter what, even after properly codesigning:
Executable=/Library/Keychains/System.keychain
Identifier=System
Format=generic
CodeDirectory v=20100 size=215 flags=0x0(none) hashes=1+4 location=embedded
Signature size=1607
Authority=gdb-cert
Signed Time=Sep 22, 2016, 2:29:41 PM
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=1 size=84
But it still does not work. Any advice?
here 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-darwin16.1.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".
I have alread do all the steps, but when I debug, the console show message.
Error in final launch sequence
Failed to execute MI command:
-exec-run
Error message from debugger back end:
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.
I could not get gdb to run in Eclipse on El Capitan with the MacPorts gdb-apple. Like others, I kept getting the error message:
Unable to find Mach task port for process-id xxxx: (os/kern) failure (0x5).
However, I downloaded MacPorts gdb (8.0.1), code signed it and it is working great!
Thanks so much for the post!
For the code signing, I found I had to use sudo in front of the command:
codesign -s gdb-cert $(which ggdb)
The last step in creating a certificate gives me error: Unknown Error = -2.147.414.007.
Other people are having the same issue, see here: https://gist.github.com/hlissner/898b7dfc0a3b63824a70e15cd0180154.
What to do?
Thanks! I am trying to do this for CodeLite and have managed to install gdb and sign the certificate, but when I debug I get the error string:
"Unable to find Mach task port for process-id 13303: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))"
Even though gdb is codesigned...
Please help!
Thanks! I am trying to do this for CodeLite and have managed to install gdb and sign the certificate, but when I debug I get the error string:
"Unable to find Mach task port for process-id 13303: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))"
Even though gdb is codesigned...
Please help me
Hi Neil,
Thanks for posting this howto.
Your instructions made installing gdb rocks.
Thank you!