Duck
Duck

Reputation: 36003

iPhone - Debugging EXC_BAD_ACCESS crashes

From times to times, while debugging an Application, I see this error on Xcode:

Program received signal: “EXC_BAD_ACCESS”.

and the debugger does not stop on the problematic line. In fact the debugger just shows me a page with a bunch assembly language code and that's it.

I have to have paranormal powers to figure out where the exact problem is.

Is there a way to force Xcode to give me more "nutritive" error messages – that can detail the problem – and stop on the offending line when such errors occur?

thanks for any help.

Upvotes: 5

Views: 3621

Answers (3)

Lou Franco
Lou Franco

Reputation: 89232

I wrote up a blog that tells you how to use some compiler switches that help a lot in finding crashes that are the result of releasing objects before you are done with them.

http://loufranco.com/blog/files/debugging-memory-iphone.html

Build and Analyze is ok, but not as good as scan-build (which it is based on). Instructions for installing that are here:

http://loufranco.com/blog/files/scan-build-better-than-build-analyze.html

Upvotes: 2

kennytm
kennytm

Reputation: 523694

When the crash happens, open the Debugger in Xcode (Run -> Debugger). There should be 3 to 4 panes like this:

http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeDebugging/art/debugger_disassembly.jpg

On the top-left pane (the "stack trace"), select the topmost row which is not gray.

(Note: Sometimes the stack trace can only find internal functions because of bad memory management triggered in the run loop. Try to Build -> Build and Analyze to eliminate all potential memory management bugs first.)

Upvotes: 6

James
James

Reputation: 5820

You can enable NSZombies see here and I've found a good way to see where the actual problem is, is to run and debug the program with the debugger open.

This way when the program stops executing it more often then shows the line that was executing when the program crashed.

Upvotes: 2

Related Questions