Install GDB in macOS Sierra

I found that there was no GDB pre-installed inside the macOS (was called OSX) since very long time ago. So this article is talking about how to install GDB in macOS Sierra.

First, you need to install homebrew

Then, install gdb by typing

brew install gdb

or

sudo brew install gdb

But if you are using gdb right now to debug your code, you will find that the terminal will tell you:

Error message from debugger back end: Unable to find Mach task port for process–id 46234: (os/kern) failure (0x5). (please check gdb is codesigned – see taskgated(8)

That is because you haven’t code-sign your own installed gdb yet, so here are two ways to do it.

  1. Code-sign your own gdb.
  2. Let superuser do the job, so it will jump through this certification.

For the solution two, just type:

sudo gdb

and it will solve your problem.

Also, you can edit your bash profile or zsh profile to add the alias

alias gdb=”sudo gdb”

then there is no need to type sudo every time, but if you want it to be safe, you can do type sudo every time.