Debug with Objective-C

Posted by Daniel Vela on April 08, 2012 · 1 min read

Preprocessor macros for filename, line number and function

NSLog(@"\n Function: %s\n Pretty function: %s\n Line: %d\n File: %s\n Object: %@", __func__, __PRETTY_FUNCTION__, __LINE__, __FILE__, button);

Aditional information

NSLog(@"Current selector: %@", NSStringFromSelector(_cmd));
NSLog(@"Object class: %@", NSStringFromClass([self class]));
NSLog(@"Filename: %@", [[NSString stringWithUTF8String:__FILE__] lasPathComponent]);

Call stack

NSLog(@"Stack trace: %@", [NSThread callStackSymbols]);

In Xcode console write

po [NSThread callStackSymbols]

How to add debug information to a Release version

In buil settings search for “Generate Debug Symbols” and set the checkbox. Also search for “Level of Debug Symbols” set “All symbols”

If Relase build crashes but Debug one not, check the following

Disable “Optimizations” in build setting for release build. Set “None”. Check this link: How to Fix an App that Crashes in Release but not Debug

20110718.34