25

I am a new Mac user and wonder how to install the latest version of GDB (> 7.1). I prefer to use Homebrew, but I could not find GDB listed.

brew install gdb
Error: No available formula for gdb

What is the best way to do it?

When installed Xcode, it may have installed an older version. Currently,

$ which gdb
/usr/bin/gdb

$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Fri Jul  1 10:50:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.

But I need version > 7.1

System version,

Model Name:     MacBook Air
System Version: Mac OS X 10.7.1 (11B2118)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bsr
  • 57,282
  • 86
  • 216
  • 316

3 Answers3

35

Homebrew does not provide gcc and the associated development tool formulas over concerns that custom/non-system compilers could break builds. Two possibilities for easiness:

This is probably the command for you:

brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb
Community
  • 1
  • 1
wkl
  • 77,184
  • 16
  • 165
  • 176
  • thanks for the quick response.. will accept the answer if no other response shortly... thanks again – bsr Dec 01 '11 at 04:20
  • Will this break the existing install of gdb, or can they co-exist? Maybe by installing the alternate version with a different name, if that's possible? – norq Feb 01 '12 at 17:45
  • 3
    @ihatetoregister - If you follow those procedures, they will install gdb and all the other stuff into different directories (`/usr/local`, which is usually used for local installs and isn't subject to system software changes), so you can have `gdb` in the normal path (`/usr/bin`) and separate gcc/gdb in the other locations. You just need to remember that the `PATH` controls which `gdb` would be used if you were executing it. – wkl Feb 01 '12 at 17:58
  • gdb-6.3 doesn't work with emacs's `gdb` mode. I installed gdb-7.5 using your method and it works now:) – RockU Oct 05 '12 at 03:15
  • Note that if you run gdb through Xcode rather than through the command line, DO NOT try to upgrade gdb as described in this answer. I just wasted a bunch of time trying that only to find the gdb Xcode uses is heavily modified to work only with Xcode. The best you can do is upgrade to the latest gdb shipped with Xcode 4.6.3 (which actually works on Mavericks in Xcode 3 whereas Xcode 3's shipped gdb crashes on Mavericks). Xcode 5 and later ship only with lldb. – Winter Dragoness Dec 09 '14 at 19:26
27

Some new users may find themselves in the same situation given the Mac OS X v10.9 (Mavericks) upgrade.

Solution

Install the development tools and Xcode

Then install Homebrew

Then do:

 brew install homebrew/dupes/gdb

You will notice that some applications will not allow you to use the newly added GDB.

This is because it is not signed by Apple any more.

To side step this issue: Follow this; thanks to @andre

I've had some people hit me up on IRC for more detailed instructions for this. I made a post on my site. You can find it here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cripto
  • 3,581
  • 7
  • 41
  • 65
  • Thanks for the link to your post. The only thing is that your codesign line (in your post) does not work (codesign -s 'Name of Certificate' `which gdb`). – rsc Mar 10 '15 at 04:04
  • @RSC did you put the ticks in there before and after which gdb. It's the ticks that share a key with ~ Sorry I'm on my phone and can't find that key on my keyboard right now – Cripto Mar 10 '15 at 04:20
  • I tried, but no joy. And you are actually using 2 different ticks, is that on purpose? – rsc Mar 10 '15 at 04:29
  • @RSC: I just check again. `codesign -s 'Name of Certificate' \`which gdb\`` Can you copy your commands exactly as you have them? including the names you picked for your certificates? – Cripto Mar 10 '15 at 04:33
  • Yes. That worked. So, probably my fault during the copy/paste. If you don't mind, it would be nice to add a note like "Yes, copy 'as is' with these 2 different ticks" to help the dummies ones :) – rsc Mar 10 '15 at 04:37
  • @RSC Glad it worked for you. And I added that. Take a look at it and let me know if its clear. – Cripto Mar 10 '15 at 04:48
  • Perfect. Nice it is dummy-proof. Thanks for the update! – rsc Mar 10 '15 at 05:08
1

This does not directly answer the given question, but if you're like me, what you really want is a simple way to run (something very much like) gdb.

Apple now uses Clang as its compiler, and it turns out that the clang debugger, lldb, is installed along with the other command-line tools. It appears that lldb is designed with a user interface that mimics gdb very closely.

So, the answer to your question may in fact be:

just use lldb!

John Clements
  • 16,895
  • 3
  • 37
  • 52