Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 248
Duck Avatar asked Mar 07 '10 01:03

Duck


People also ask

What causes Exc_bad_access?

EXC_BAD_ACCESS is an exception raised as a result of accessing bad memory. We're constantly working with pointers to memory in Swift that link to a specific memory address. An application will crash whenever we try to access a pointer that is invalid or no longer exists.

What does thread 1 Exc_bad_access mean?

EXC_BAD_ACCESS means that message was sent to a point in the memory where there's no instance of a class to execute it. Thus “bad access”. You will get EXC_BAD_ACCESS in 3 cases: An object is not initialized.

What is Exc_bad_access Kern_invalid_address?

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000. This indicates that your app crash because it tried to referenced NULL. Code Block. 0 CoreFoundation …


2 Answers

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.)

like image 98
kennytm Avatar answered Sep 27 '22 21:09

kennytm


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.

like image 43
James Avatar answered Sep 27 '22 21:09

James