GDB Debugging

GETTING CORE DUMPS FROM Mac OSX:

The most effective method of collecting user-dumps (a core process memory dump file) on the Mac, when a program crashes, is to run the program from the Terminal after configuring the proper core dump settings. 

For a complete and thorough guide to debugging on Mac OS X, it's best to review the Mac Technical Note TN2124 "Mac OS X Debugging Magic" document.

Per the above referenced Apple document:

"You can enable core dumps on a system-wide basis by adding the line limit core unlimited to your /etc/launchd.conf file, creating it if necessary, and then restarting."

I haven't been able to successfully use the launchd.conf file to work for me globally, but that's probably due to some type of error on my part. But what I have been able to get working consistently, is running the program from the Terminal and having it generate the core dump when the program crashes.

Step 1.

From the Terminal, run $ ulimit -c unlimited

Step 2.

Ensure the "/cores" directory is writable for normal users

> From the Terminal, run $ sudo chmod o+w /cores

Step 3.

Run your program via the Terminal

Ensure to navigate into the .app folder to the binary for the program itself. Here is an example of navigating into TextPad's app folder to run the binary:

$ /Applications/TextEdit.app/Contents/MacOS/TextEdit

Step 4.

Reproduce the crash so that the core dump will be generated

Step 5.

Check the /cores directory for the existence of the dump file

(2 core dump files shown in screenshot above)

Now you can debug using GDB!

Step 6.

Load the core dump file via GDB

Note - you can view general info about the core dump file using the "otool" command (example: $ otool -c /cores/core.180).

To load the dump via GDB:

$ gdb -c /cores/core.180

To load the .dSYM symbol file, simply run:

(gdb) add-symbol-file /Users/Kappa/Desktop/APP.app.dSYM

Now you can run your favorite commands to further inspect the process. 

(gdb) info threads

7 "com.apple.CFSocket.private"    0x00007fff856f1e52 in select$DARWIN_EXTSN ()

6                                 0x00007fff856e8f8a in __semwait_signal ()

5                                 0x00007fff856e8f8a in __semwait_signal ()

4                                 0x00007fff856e8f8a in __semwait_signal ()

3                                 0x00007fff856ae2fa in semaphore_timedwait_signal_trap ()

2 "com.apple.libdispatch-manager" 0x00007fff856c712a in kevent ()

* 1 "com.apple.main-thread"         0x00007fff8608ab35 in sqlite3PagerAcquire ()

© MindArray.org 2011