From charlesreid1

Installing

Mac OS X

Install using homebrew:

$ brew install gdb

Then, you have to give gdb permission to control other processes:

$ open /Applications/Utilities/Keychain\ Access.app

Now create a new certificate for gdb by opening the menu item Keychain Access > Certificate Assistant > Create a Certificate

Call it something like gdb-cert

Set Identity Type to Self-Signed Root

Set Certificate Type to Code Signing

Select the "Let me override defaults" option

Most of the other settings can remain the default

Specify the location for the certificate to System (not login)

Now, sign gdb with the certificate:

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

Mac OS X Sierra

Mac OS X Sierra requires one more thing:

$ echo "set startup-with-shell off" >> ~/.gdbinit

Check Code-Signing

To check whether the binary has been correctly signed, run the following command. If the binary has been successfully signed, this will not print anything out.

$ codesign -v `which gdb`

Simple Disassembly Example

Starting with a simple hello world program:

#include <stdio.h>

int main(void) 
{
    printf("Hello world! This is C.\n");
    return 0;
}

Now compile the program with debug flags:

$ gcc -g hello_world.c -o hello_from_c.x

and load it up into gdb:

$ gdb hello_from_c.x

Now you can run the program like normal:

(gdb) run 

and to disassemble the binary into its assembly level instructions,

(gdb) disassemble main

References

Homebrew installation and code-signing steps: https://sourceware.org/gdb/wiki/BuildingOnDarwin#Troubleshooting_code-signing

http://www.ibm.com/developerworks/aix/library/au-gdb.html?ca=dgr-lnxw16GDB2

http://www.ibm.com/developerworks/aix/library/au-unix-strace.html

http://stackoverflow.com/questions/1585308/debugging-disassembled-libraries-with-gdb