How to attach to a running process with GDB on Mac OSX:
Another useful debugging technique, is to debug a live running application. This may be due to the fact that a certain problem may only arise on specific machines and in that case, you would need to be able to debug that instance of the problem. Fortunately, GDB makes it easy.
Step 1.
Run Activity Monitor from your standard Mac OS X Applications, and locate the process identifier (PID) for the process that you want to attach to and debug...

Step 2.
Then from a Terminal window, run $ gdb attach <PID>
Where <PID> is the PID number you previously located (such as 1798).
(example:$ gdb attach 1798)
GDB should now attach into that process and halt its execution, ready for your first command. Simply type "c" to continue the execution of the program.
