More than just EXC_BAD_ACCESS? - iphone

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.

Related

XCode 4 - IPhone Dev - Good Debug Tutorial

I'm beginning IPhone development with XCode 4 and Objectiv-C. Since I think strong debug and IDE knowledge is required to master a language, I'm looking for good resources about the debugging process and XCode.
A problem I faced recently was that, an unknownException was being thrown in a sample code and I couldn't know how to debug it, since it crashed right after jumping into my Main. I think with a better configuration, it would have been much easier to debug !
I've already found this resource : https://developer.apple.com/library/ios/navigation/
But I couldn't find something related to debug in there... Did I miss something ?
Andy, this first is about super basic debugging: http://mobile.tutsplus.com/tutorials/iphone/xcode-debugging_iphone-sdk/
And here you can find two excellent tutorials:
http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1
http://www.raywenderlich.com/10505/my-app-crashed-now-what-part-2
Easy to make mistakes in Objective-C...
Not having a view attached to your view controller
Sending a message to a deallocated instance. Turn on NSZombieEnabled.
Forgot to add the Framework (e.g. MapKit)
If the crash isn't fixed at this point. Set a breakpoint in your app delegate and just step through every line until it crashes. Move the breakpoint up, run again, and inspect the values.
Apple has a list of what they consider to be the best debugging tricks for iOS here.
There is also a couple of videos on the developer's site. I can never find out how to make a direct link, but there aren't that many videos, so just search for "debug":
https://developer.apple.com/videos/wwdc/2012/
There is also one from last year:
https://developer.apple.com/videos/wwdc/2011/
Access to the developer site requires registration.
Should you ever consider venturing into OS X territory, then here is the Apple-approved debugging magic.

What commands are valid in "console pane" of Mac's "Instruments" app? (E.g., in Instrument)

I'm running the Mac OS "Instruments" app, using the "Leaks Instrument" to monitor an
iPhone app. The major pane is titled "Leaked Blocks", but if you click on that you
get a choice of three: "Leaked Blocks", "Call Tree", and "Console". Click on "Console".
You now have a blank pane ... click in it and hit .
In my case, I get:
foo (4259) >
which is my app name and, presumably, the PID it's running as.
I can enter commands/text (e.g., ls, help, exit) ... they get echoed after awhile but
nothing else happens.
I.e., it looks like a command prompt, but I can't figure out what kinds of commands
I can give it here! Doesn't seem to accept gdb commands, nor "help". Can't find a
mention of this feature in Apple's documents.
Note that if I select a different instrument, e.g. "Allocations", it also has the
same console pane ... with the same "no effect" when I enter text.
I'm hoping that whatever commands it has are (a) interesting, and (b) useful to me
in debugging a memory leak.
thanks,
Stan
sieler#me.com
Isn't this a console window that lets you see messages printed to the console (NSLog and alike), just like Xcode's one? In Xcode too you can write in that console, to no extent...
indeed the Instruments User Guide states:
Options
Use this menu to specify other runtime options. For example, you can direct the application’s output to the Instruments console or the system console, or discard the output. You can also specify whether the application is launched in 32-bit or 64-bit mode.
did not try it, though...

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

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