How can I track segmentation fault in Cocoa app?
I have a problem with a Cocoa app I'm writing. It has to parse a timestamped file that is updated every hour, and during testing, it will consistently crash at around 11:45 pm due to a segmentation fault. I am guessing that I should send a message about the object that was freed. What tools are provided with Xcode installation to track the distribution of objects and (hopefully) tell me if I am passing a message about an object that has been freed?
I am using Mac OS X 10.5.
source to share
I would recommend the following:
- Use
NSZombieEnabled
to track when messages are sent to freed NSObjects - Use Instruments to track object allocations and / or memory leaks.
source to share
Did you run the program under gdb? This should allow you to check the stack and variables when it's SIGSEGVs.
Use malloc_history to keep track of allocations . This requires setting an environment variable MallocStackLogging
.
source to share
Run it in Xcode debugger (which is the gdb with the GUI on top) and reproduce the crash. Then look at the stack trace.
The exchange of messages with a de-enabled object usually has a top frame in objc_msgSend. The next step is to launch the application with NSZombieEnabled and play the crash; the zombie will identify itself.
source to share