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.

+2


source to share


5 answers


I would recommend the following:



+9


source


The way I do it, use a command line tool called gdb

. Here is a tutorial on how to use it. You will need to learn some of these commands, but once you do, it's almost fun.



Note: gbd

can be used in C, C ++ and Objective-C programs.

0


source


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

.

0


source


Quick point: Using freed memory usually results in an exception EXC_BAD_ACCESS

. If this is the cause of the failure that you are seeing, then you are correct in assuming that it is a release issue.

0


source


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.

0


source







All Articles