问题
Every time Xcode crashes it points to this line on main.m
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
I know Xcode 4 debugging stinks compared to 3.x, but how do I make it point to the line where the crash happened.
Please don't:
- Tell me to enable NSZombieEnabled;
- Tell me to add an exception breakpoint to break for all exceptions on Catch or on Throw.
- Tell me Xcode 4.x is better than 3.x for debugging.
All this stuff is useless or barely useless and Xcode continues to crash on the same line on main.m...
Please save me from this.
Thanks.
回答1:
Here's an idea: just one try/catch around your entire app, logging the stack from the exception, not the current stack (i.e. not a breakpoint + inspection):
main.m
int main(int argc, char *argv[])
{
@autoreleasepool {
@try {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
@catch (NSException *exception) {
NSLog(@"%@",[exception callStackSymbols]);
return 1;
}
}
}
My understanding is that the reason we don't have a good method otherwise is that the crash itself does not happen until later in the runloop. I think things like uncaught exceptions, etc. just put the app in a state where it will crash somewhere in Apple's code when the runloop iterates. This is similar to if you ever have crashes in the UI... it doesn't always crash when you set the crappy geometry, it crashes when it tries to use it. For this reason, we need to get the stack from the exception object, not from the current-state when the crash actually occurs.
And I'll add this just because it got me a few times when I thought I had no info available, but I just didn't know Xcode well enough yet (I'm sure it's common knowledge and I was just being silly). Sometimes when I think that all I have is that dreaded top-level scope, all I needed to do was use the little slider at bottom-left (during debug sessions) to see the whole stack. This is often nearly useless, for the reasons mentioned above (it's in another part of the runloop from the problem).
回答2:
Clearly you've done the research and have only come up with those same answers. There's a reason for that; they're really all we have for Xcode 4.x unfortunately, so we can't give you another answer.
All I can suggest is that if you've already done all the aforementioned fixes, and you're using linked frameworks or libraries, these could be the core reason you're not getting an exact line the crash occurs on. Linked libraries are already compiled and can't display the exact line of the crash, but if you can nail down approximately where the error occurs and what library is responsible for it, you can start to zero in on the root cause of the issue and find the offending line.
来源:https://stackoverflow.com/questions/11462939/xcode-4-x-making-it-point-to-the-offending-crashing-line