iPhone - Debugging EXC_BAD_ACCESS crashes - iphone

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.

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

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.

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

Related

debugging issue with iphone simulator 4.0

Friends,
I am building and debugging my xproj. Now the control is not stopping at the breakpoint i kept in the program but it is stopping at the return statement of operator++() in the stl_iterator.h file. After I press Continue the code is giving expected results but the thing is I cannot see the step by step debugging. Can any one give me clue why it is happening so, always i see the control at same position. I cleaned all targets and tried but no luck.
Active SDK = iphonesimulator4.0, Active Configuration = Build. (I used C++ in the code).
With iphoneSImulator3.1.2, i can able to debug step-by-step for the same code.
Thanks in Advance,
Anil
Sometimes the compiler will optimize your code and make breakpoints move around. Be sure to turn off all optimizations when building for debugging purposes; this should already be set in the “Debug” build setting.

App Quits, No Stacktrace and Intermittent: How to debug? (iOS)

Yesterday I ran into a situation (which I resolved by studying my code a lot) where the app would start and then blow up at some point in the start sequence. This would be a breeze to troubleshoot except that there was no stacktrace whatsoever. Debugging and stepping through line-by-line caused the problem to go away, and it was intermittent anyway.
What kinds of problems cause the iPhone simulator or the device to blow up with no stacktrace? (A shortest example would be great).
What is the best way to debug this type of problem? Line-by-line debugging is out because it causes the problem to resolve.
I have had minor success with creating the breakpoint objc_exception_throw in the debugger. Basically go to your debugger window -> show breakpoints and type in objc_exception_throw where it says Double_Click for Symbol
The good thing about this is it should in theory stop just before it crashes and your method that crashes "could" show up in the debugger in black print (rest is in grey).
That being said I have only had success with it once where all your other ways have failed.
I couldn't really answer your question to number one. The only way I can think of is if your trying to do something that should technically work but the SDK wasn't designed that way and it crashes in some strange part of Apples code. This is all very if the wind is blowing in this direction and this speed it might crash though sorry.

More than just EXC_BAD_ACCESS?

Is there a more detailed error to be found other than the console's EXC_BAD_ACCESS? Where/how can I see it?
When my app crashes, I see the error in thE XCode status bar, but the console shows nothing else. Where do I see more info about what causes the crash?
The application will have a stack trace, typically in the crash logs. Definitely look there for a bit more detail. Look under ~/Library/Logs/CrashReporter for those details. In general, run the application "Console.app" in your Utilities folder, and click on the button "Show Log List". It gives a detailed view into all the logs available that you'd likely want to check out in your system
If it's code you have written, the debugger (gdb) is the "how" to go to look for more detail. That's typically a "you overreleased" some object if you're working in Objective-C. There's a good set of notes on using the technique "NSZombieEnabled" to find what you're blowing up on.

How to debug iPhone app errors that occur before the first line

I have a fairly simple app. It compiles fine. Unfortunately, when I Build and Go, it fails before even the first line of code, thus making it impossible for me to even debug it.
Where do I start? I do have the stack track though.
From the stack trace, it seems your Outlet connections seem messed up in your main XIB file - you could start looking there.
Other than that, you won't be able to debug much, because there's no source code for the iPhone built-in mechanisms, which seem to be failing here (most probably because of something you did in the interface designer/XIBs).
Set a breakpoint at objc_exception_throw, then restart the application. The breakpoints should be kept after the restart, allowing you to see what's wrong.

Debug Iphone Program received signal: "EXC_BAD_ACCESS"

My iphone app randomly received this message. I know certain it is memory release problem. However what is the best way to find which object leads this problem. Here are what I have tried
Use Instrument Leak and
ObjectAllocation Trace. Dont saw any
help to know which object have this
problem
Put NSZombieEnabled=YES and project executive ... Dont saw any
help either
Put NSLog everywhere but the EXE_BAD_ACCESS just appear anywhere.
in the debuger, just saw the code
happened in the assembly. like
objc-msg send.
review code many times and read memory management a lot time
and research online a lot time. but
no surprise.
Is there a completed solution to figure out this problem easily. I am a previous Visual C++ programmer, I deal with memory management with years and it is easy to debug and figure out in Visual C++.
If you couldn't see any helpful debug info, I would suggest you find all the places that you are doing a release. It is most likely the case that you have released something that did not need to be released. Code would help us in tracing the issue with you.
As Juan noted, the first stop is the Debugger - what does the debug window give for a stack trace when the app crashes? You should be able to see the line it crashed on... you said in a comment to one response that you saw the crash happen around the lines:
CGPDFDocumnetRef docA=CGPDFDocumentCreatWithURL(myurl);
CGPDFDocumnetRef docB=CGPDFDocumentCreatWithURL(myurl);
Are you really using the same URL object for both calls? Which line is it exactly?
It could be something around the way you make use of the CGPDFDocumentRef, you can find example code how Apple uses them in the QuartzDemo project, file "QuartzImageDrawing.m" (you can find the demo project from the developer portal or embedded in the iPhone documentation with XCode).
XCode is actually pretty powerful, but it does things differently from other IDE's.
In addition to Erich answer, I'd want to add go backward. Start with the most recently added release and work from there.
I ran in to this and it turned out I was releasing an auto-released object that was returned from a convenience method built in to the Cocoa-Touch framework. My problem was as Erich described -- I released this auto-released object. When the system attempted to release it, the program gave the error you are describing.
Regards,Frank
The best way to know what happend is using the xCode Debbuger, give it a try.
You will also receive the message when you don't pass enough parameters to a variable argument method. For example having a NSLog statement like this: NSLog(#"Hello %#");
To check what the error might be
Use NSZombieEnabled.
To activate the NSZombieEnabled facility in your application:
Choose Project > Edit Active Executable to open the executable Info window.
Click Arguments.
Click the add (+) button in the “Variables to be set in the environment” section.
Enter NSZombieEnabled in the Name column and YES in the Value column.
Make sure that the checkmark for the NSZombieEnabled entry is selected.
found this on iPhoneSDK