how to gdb on mac

How to gdb on Mac

Sadly, gdb is not built-in package for Mac. On Mac, the easiest way to install a package working mainly in CLI such as gdb, gcc, g++, and etc, is to use Brew (Homebrew).

1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

then, use the brew to install the gdb package.

1
brew install gdb

➜ algorithms git:(master) ✗ brew install gdb
Updating Homebrew…
==> Downloading https://homebrew.bintray.com/bottles/gdb-7.12_1.el_capitan.bottle.tar.gz

######################################################################## 100.0%
==> Pouring gdb-7.12_1.el_capitan.bottle.tar.gz
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

https://sourceware.org/gdb/wiki/BuildingOnDarwin

On 10.12 (Sierra) or later with SIP, you need to run this:

echo “set startup-with-shell off” >> ~/.gdbinit
==> Summary
🍺 /usr/local/Cellar/gdb/7.12_1: 49 files, 6.8M

here goes the result!

1
$ sudo gdb

$ gdb

GNU gdb (GDB) 7.12

Copyright (C) 2016 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later >
http://gnu.org/licenses/gpl.html

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-darwin15.6.0”.

Type “show configuration” for configuration details.

For bug reporting instructions, please see:

http://www.gnu.org/software/gdb/bugs/.

Find the GDB manual and other documentation resources online at:

http://www.gnu.org/software/gdb/documentation/.

For help, type “help”.

Type “apropos word” to search for commands related to “word”.

(gdb)

So simple!

  • Just remember that you should run gdb as the super user with “sudo” on mac.
Share Comments