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

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.

Related

Unity framework for SwiftUI "Oddly Stepping" error in iOS 16.1

I am using Unity as a library for SwiftUI quite a while now. However when updating to the newest iOS version (16.1) it stopped working. Compiling runs without a problem but during runtime I get an error when Unity is starting:
in:
I even started a completely new project with Unity included to SwiftUI and get the same error. As this is some kind of assembler code and I certainly do not know how to read it I don't really know where I have to start searching.
In the console I get: "warning: UnityFramework was compiled with optimization - stepping may behave oddly; variables may not be available." I tried several ways to turn off optimization as described in related questions which did not work. When unchecking "Debug" in the scheme options the project starts normally
A similar thing happened to me. I'm not entirely sure if it's the same problem but in the console, I got a message saying UnityFramework is running optimized and may behave oddly. Unfortunately, I've tried a couple of ways to disable optimization but I've yet to find a solution.
For now, I'm able to bypass this error by disabling the debugger entirely. In order to do this, you have to go to Product -> Scheme -> Edit Scheme and uncheck debug executable.
I'm not sure if this will work for you but I figured it'd be worth a shot!

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.

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.

EXC_BAD_ACCESS, but with no zombies, and not in debug build configuration

This is driving me nuts. I just uploaded my first app to the App Store for the first time, and of course, now my app is exploding left and right. When I build with release build configuration, I randomly get an EXC_BAD_ACCESS after banging on the app for some variable amount of time. I turned Zombies back on, but the problem doesn't appear to be over-releasing a variable, as I don't get a message about sending a message to a released variable.
The error does always appear in the same spot in my code. It looks like I'm trying to retain a variable that hasn't been initialized properly. I haven't the slightest idea how I could be doing that.
But here's the weird thing: if I build in debug release configuration, IT NEVER CRASHES. I can bang on the thing all day long, and it's rock solid. I build with Release configuration, and it gets all intermittently crashy.
Looking at the Build settings in the two configurations, there aren't that many differences. In debug, the GCC 4.0 Optimization level is "None", while in Release, it's "Fastest, Smallest." If I switch the optimization level in Release to "None," the app behaves itself. Does anyone have a clue what I should be looking for to fix this? Alternately, how many bad things happen if I Distribute with No optimization?
UPDATE:
Dang! I really need a magic debug tool for memory errors. I've been working this problem for the last day or so. I added an exercise method that would reliably generate a crash and started looking for the area of code that was causing it.
The app would usually crash the 3rd-5th time I performed one particular type of operation. The only thing that was different about that type of operation was the value I returned from an accessory method. The accessory method generally returned NSDecimalNumbers with values of 0-3, but there was one special case when I was returning an NSDecimalNumber with a non-integer value. I would test the result of the accessory method looking for the non-integer value. I changed the special case to return an NSDecimalNumber with a value of -1 instead of the non-integer value, and I can no longer make the app crash.
Basically, the only change I made was switching from
[[NSNumber numberWithDouble:num] decimalValue] --> crash
to
[[NSNumber numberWithInteger:num] decimalValue] --> no crash
It's a little but more complicated than that, but not much.
Now, I'm happy that the app no longer crashes but the change I made does not fill me with confidence, as the old bits of code did not appear to be "broken" in any way. So, while my app doesn't crash anymore, it's not because I "fixed" it, I just changed some random thing and now it works. 8^(
UPDATE:
Debugger does not spit out a stack trace as it usually does when a program crashes. When it crashes, the debug console outputs the following:
Loading program into debugger…
[... copyright stuff...]
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols for "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics" (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/...', process 10066.
Re-enabling shared library breakpoint 1
Cannot access memory at address 0x4
Cannot access memory at address 0x4
(gdb)
If only it were as easy as turning on Zombies and you could always find your over-releases... There are lots of these kinds of errors that Zombies can't detect. There is no magic debug tool for memory errors; only careful programming (and there are patterns that make these errors much more uncommon, and much easier to debug when they do occur).
Optimized code can shake free lots of things that don't show up in unoptimized code. It does suggest slightly that it may be a local variable rather than an ivar, but perhaps not. It may just be timing; being faster may make a race condition go the other way more often.
If you can get it to crash, take a look of in the stack trace as a first step of course.
There's nothing deeply wrong with distributing without optimization, but it's just masking the problem. There's a coding error in there. Optimization isn't breaking your code. Your code is broken.
There's a good discussion of debugging memory problems here. The #1 rule is that you must use accessors. They will save you much heartache, so hopefully you already do this. I provide some other pointers in my short discussion of memory management rules.
I'd suggest cranking up the warning level on your compiler and see if anything pops up. Open up your project settings and enable every 'warning' option you can find. Or, find the project setting named Other C Flags and add the flags -Wall -Wextra.
You're going to get a LOT of white noise for things like signed/unsigned mismatches, possible loss of precision, etc., that you can (usually) safely ignore. However, there may be some key warnings that pop up that you definitely should NOT ignore: things like making a pointer from an integer without a cast (or vice-versa). If you're not 100% sure you can ignore the warning, fix the code so the warning goes away.